From 0951dd3a93f5370e1b42aef86cccbe0aaa8df0a6 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 25 Apr 2014 17:57:22 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Line feature realization: 1. Create operation 2. Create point widget 3. Move widgets to ModuleBase --- src/Config/Config_Keywords.h | 3 + src/ModuleBase/CMakeLists.txt | 14 +++- src/ModuleBase/ModuleBase_Operation.cpp | 25 +++++++ src/ModuleBase/ModuleBase_Operation.h | 3 + src/ModuleBase/ModuleBase_WidgetCustom.h | 41 +++++++++++ .../ModuleBase_WidgetFactory.cpp} | 53 +++++++++----- .../ModuleBase_WidgetFactory.h} | 20 +++--- src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 72 +++++++++++++++++++ src/ModuleBase/ModuleBase_WidgetPoint2D.h | 50 +++++++++++++ .../ModuleBase_WidgetSwitch.cpp} | 38 +++++----- .../ModuleBase_WidgetSwitch.h} | 16 ++--- src/PartSet/CMakeLists.txt | 4 +- src/PartSet/PartSet_Module.cpp | 11 ++- src/PartSet/PartSet_OperationSketch.cpp | 3 +- src/PartSet/PartSet_OperationSketchLine.cpp | 52 ++++++++++++++ src/PartSet/PartSet_OperationSketchLine.h | 51 +++++++++++++ src/SketchPlugin/SketchPlugin_Line.h | 5 ++ src/SketchPlugin/SketchPlugin_Plugin.cpp | 7 +- src/SketchPlugin/plugin-Sketch.xml | 6 +- src/XGUI/CMakeLists.txt | 4 -- src/XGUI/XGUI_Workshop.cpp | 4 +- 21 files changed, 415 insertions(+), 67 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_WidgetCustom.h rename src/{XGUI/XGUI_WidgetFactory.cpp => ModuleBase/ModuleBase_WidgetFactory.cpp} (71%) rename src/{XGUI/XGUI_WidgetFactory.h => ModuleBase/ModuleBase_WidgetFactory.h} (59%) create mode 100644 src/ModuleBase/ModuleBase_WidgetPoint2D.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetPoint2D.h rename src/{XGUI/XGUI_SwitchWidget.cpp => ModuleBase/ModuleBase_WidgetSwitch.cpp} (59%) rename src/{XGUI/XGUI_SwitchWidget.h => ModuleBase/ModuleBase_WidgetSwitch.h} (74%) create mode 100644 src/PartSet/PartSet_OperationSketchLine.cpp create mode 100644 src/PartSet/PartSet_OperationSketchLine.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 6c8f91835..61f09f5c3 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -27,6 +27,9 @@ const static char* WDG_TOOLBOX_BOX = "box"; const static char* WDG_SWITCH = "switch"; const static char* WDG_SWITCH_CASE = "case"; +//Specific widget containers +const static char* WDG_POINT_SELECTOR = "point_selector"; + const static char* _ID = "id"; //const static char* WORKBENCH_ID = "id"; //const static char* GROUP_ID = "id"; diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index fcd731c9e..116353000 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -5,14 +5,22 @@ SET(PROJECT_HEADERS ModuleBase.h ModuleBase_Operation.h ModuleBase_PropPanelOperation.h + ModuleBase_WidgetCustom.h + ModuleBase_WidgetFactory.h + ModuleBase_WidgetPoint2D.h + ModuleBase_WidgetSwitch.h ) SET(PROJECT_SOURCES ModuleBase_Operation.cpp ModuleBase_PropPanelOperation.cpp + ModuleBase_WidgetFactory.cpp + ModuleBase_WidgetPoint2D.cpp + ModuleBase_WidgetSwitch.cpp ) SET(PROJECT_LIBRARIES + Config ModelAPI ${QT_LIBRARIES} ) @@ -27,7 +35,11 @@ SET(PROJECT_AUTOMOC SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESOURCES} ${QM_RESOURCES}) #SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES}) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/ModelAPI) +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/Config + ${CMAKE_SOURCE_DIR}/src/ModelAPI + ${CMAKE_SOURCE_DIR}/src/GeomDataAPI +) ADD_DEFINITIONS(-DMODULEBASE_EXPORTS) ADD_LIBRARY(ModuleBase SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 76459c132..519efbf13 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -7,6 +7,8 @@ #include "ModuleBase_Operation.h" +#include "ModuleBase_WidgetCustom.h" + #include #include #include @@ -14,6 +16,8 @@ #include #include +#include + #ifdef _DEBUG #include #endif @@ -264,6 +268,27 @@ void ModuleBase_Operation::storeReal(double theValue) aReal->setValue(theValue); } +/*! + * \brief Stores a real value in model. + * \param theValue - to store + * + * Public slot. Passes theValue into the model. + */ +void ModuleBase_Operation::storeCustomValue() +{ + if(!myFeature){ + #ifdef _DEBUG + qDebug() << "ModuleBase_Operation::storeCustom: " << + "trying to store value without opening a transaction."; + #endif + return; + } + + ModuleBase_WidgetCustom* aCustom = dynamic_cast(sender()); + if (aCustom) + aCustom->store(myFeature); +} + /*! * \brief Verifies whether operator is ready to start. * \return TRUE if operation is ready to start diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 75724ea34..818476d6f 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -111,6 +111,9 @@ public slots: // Data model operations. void storeReal(double); + // Data model operations. + void storeCustomValue(); + protected: virtual bool isReadyToStart() const; diff --git a/src/ModuleBase/ModuleBase_WidgetCustom.h b/src/ModuleBase/ModuleBase_WidgetCustom.h new file mode 100644 index 000000000..471d3f5ca --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetCustom.h @@ -0,0 +1,41 @@ +// File: ModuleBase_WidgetCustom.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetCustom_H +#define ModuleBase_WidgetCustom_H + +#include + +#include + +#include + +class ModelAPI_Feature; + +/**\class ModuleBase_WidgetCustom + * \ingroup GUI + * \brief An abstract custom widget class. This class realization is assumed to create some controls. + * The controls values modification should send signal about values change. Method store is used to fill + * the feature with the + */ +class MODULEBASE_EXPORT ModuleBase_WidgetCustom : public QObject +{ + Q_OBJECT +public: + /// Constructor + /// \theParent the parent object + ModuleBase_WidgetCustom(QObject* theParent) :QObject(theParent) {}; + /// Destructor + virtual ~ModuleBase_WidgetCustom() {}; + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual void store(boost::shared_ptr theFeature) = 0; + +signals: + /// The signal about widget values changed + void valuesChanged(); +}; + +#endif diff --git a/src/XGUI/XGUI_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp similarity index 71% rename from src/XGUI/XGUI_WidgetFactory.cpp rename to src/ModuleBase/ModuleBase_WidgetFactory.cpp index 17c3ab6c3..d902d0eef 100644 --- a/src/XGUI/XGUI_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -1,20 +1,22 @@ /* - * XGUI_WidgetFactory.cpp + * ModuleBase_WidgetFactory.cpp * * Created on: Apr 3, 2014 * Author: sbh */ -#include +#include -#include +#include #include +#include #include #include #include #include +#include #include #include #include @@ -29,18 +31,18 @@ #include #include -XGUI_WidgetFactory::XGUI_WidgetFactory(ModuleBase_PropPanelOperation* theOperation) +ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(ModuleBase_PropPanelOperation* theOperation) : myOperation(theOperation) { QString aXml = myOperation->xmlRepresentation(); myWidgetApi = new Config_WidgetAPI(aXml.toStdString()); } -XGUI_WidgetFactory::~XGUI_WidgetFactory() +ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory() { } -void XGUI_WidgetFactory::createWidget(QWidget* theParent) +void ModuleBase_WidgetFactory::createWidget(QWidget* theParent) { if (!myWidgetApi->toChildWidget()) return; @@ -70,7 +72,7 @@ void XGUI_WidgetFactory::createWidget(QWidget* theParent) QWidget* aPage = new QWidget(aWidget); createWidget(aPage); if (aWdgType == WDG_SWITCH) { - XGUI_SwitchWidget* aSwitch = qobject_cast(aWidget); + ModuleBase_WidgetSwitch* aSwitch = qobject_cast(aWidget); aSwitch->addPage(aPage, aPageName); } else if (aWdgType == WDG_TOOLBOX){ QToolBox* aToolbox = qobject_cast(aWidget); @@ -82,7 +84,7 @@ void XGUI_WidgetFactory::createWidget(QWidget* theParent) theParent->setLayout(aWidgetLay); } -QWidget* XGUI_WidgetFactory::labelControl(QWidget* theParent) +QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent) { QWidget* result = new QWidget(theParent); QVBoxLayout* aLabelLay = new QVBoxLayout(result); @@ -95,23 +97,27 @@ QWidget* XGUI_WidgetFactory::labelControl(QWidget* theParent) return result; } -QWidget* XGUI_WidgetFactory::createWidgetByType(const std::string& theType, QWidget* theParent) +QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType, QWidget* theParent) { QWidget* result = NULL; if (theType == WDG_DOUBLEVALUE) { result = doubleSpinBoxControl(); } else if (theType == WDG_INFO) { result = labelControl(theParent); - } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { + } + else if (theType == WDG_POINT_SELECTOR) { + result = pointSelectorControl(theParent); + } + else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { result = createContainer(theType, theParent); } #ifdef _DEBUG - else { qDebug() << "XGUI_WidgetFactory::fillWidget: find bad widget type"; } + else { qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad widget type"; } #endif return result; } -QWidget* XGUI_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent) +QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent) { QWidget* result = NULL; if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) { @@ -121,17 +127,17 @@ QWidget* XGUI_WidgetFactory::createContainer(const std::string& theType, QWidget } else if (theType == WDG_TOOLBOX) { result = new QToolBox(theParent); } else if (theType == WDG_SWITCH) { - result = new XGUI_SwitchWidget(theParent); + result = new ModuleBase_WidgetSwitch(theParent); } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) { result = NULL; } #ifdef _DEBUG - else { qDebug() << "XGUI_WidgetFactory::fillWidget: find bad container type"; } + else { qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad container type"; } #endif return result; } -QWidget* XGUI_WidgetFactory::doubleSpinBoxControl() +QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl() { QWidget* result = new QWidget(); QHBoxLayout* aControlLay = new QHBoxLayout(result); @@ -179,17 +185,30 @@ QWidget* XGUI_WidgetFactory::doubleSpinBoxControl() return result; } -bool XGUI_WidgetFactory::connectWidget(QWidget* theWidget, const QString& theType) +QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent) +{ + ModuleBase_WidgetPoint2D* aWidget = new ModuleBase_WidgetPoint2D(theParent, + qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME)), myWidgetApi->widgetId()); + connectWidget(aWidget, WDG_POINT_SELECTOR); + return aWidget->getControl(); +} + +bool ModuleBase_WidgetFactory::connectWidget(QObject* theWidget, const QString& theType) { bool result = false; if (theType == WDG_DOUBLEVALUE) { result = QObject::connect(theWidget, SIGNAL(valueChanged(double)), myOperation, SLOT(storeReal(double))); } + if (theType == WDG_POINT_SELECTOR) { + ModuleBase_WidgetCustom* aCustom = dynamic_cast(theWidget); + result = QObject::connect(aCustom, SIGNAL(valuesChanged()), + myOperation, SLOT(storeCustomValue())); + } return result; } -QString XGUI_WidgetFactory::qs(const std::string& theStdString) const +QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const { return QString::fromStdString(theStdString); } diff --git a/src/XGUI/XGUI_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h similarity index 59% rename from src/XGUI/XGUI_WidgetFactory.h rename to src/ModuleBase/ModuleBase_WidgetFactory.h index d83d8fbb4..404bcc057 100644 --- a/src/XGUI/XGUI_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -1,25 +1,26 @@ /* - * XGUI_WidgetFactory.h + * ModuleBase_WidgetFactory.h * * Created on: Apr 3, 2014 * Author: sbh */ -#ifndef XGUI_WIDGETFACTORY_H_ -#define XGUI_WIDGETFACTORY_H_ +#ifndef ModuleBase_WidgetFactory_H_ +#define ModuleBase_WidgetFactory_H_ -#include "XGUI.h" +#include #include +class QObject; class QWidget; class Config_WidgetAPI; class ModuleBase_PropPanelOperation; -class XGUI_EXPORT XGUI_WidgetFactory +class MODULEBASE_EXPORT ModuleBase_WidgetFactory { public: - XGUI_WidgetFactory(ModuleBase_PropPanelOperation*); - virtual ~XGUI_WidgetFactory(); + ModuleBase_WidgetFactory(ModuleBase_PropPanelOperation*); + virtual ~ModuleBase_WidgetFactory(); void createWidget(QWidget* theParent); @@ -28,9 +29,10 @@ protected: QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL); QWidget* labelControl(QWidget* theParent); QWidget* doubleSpinBoxControl(); + QWidget* pointSelectorControl(QWidget* theParent); QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL); - bool connectWidget(QWidget*, const QString&); + bool connectWidget(QObject*, const QString&); QString qs(const std::string& theStdString) const; private: @@ -40,4 +42,4 @@ private: }; -#endif /* XGUI_WIDGETFACTORY_H_ */ +#endif /* ModuleBase_WidgetFactory_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp new file mode 100644 index 000000000..9cd0a47c9 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -0,0 +1,72 @@ +// File: ModuleBase_WidgetPoint2D.cpp +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +ModuleBase_WidgetPoint2D::ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle, + const std::string& theFeatureAttributeID) +: ModuleBase_WidgetCustom(theParent), myFeatureAttributeID(theFeatureAttributeID) +{ + myGroupBox = new QGroupBox(theTitle, theParent); + QGridLayout* aGroupLay = new QGridLayout(myGroupBox); + aGroupLay->setContentsMargins(0, 0, 0, 0); + aGroupLay->setColumnStretch(1, 1); + { + QLabel* aLabel = new QLabel(myGroupBox); + aLabel->setText("X"); + aLabel->setPixmap(QPixmap(":pictures/x_point.png")); + aGroupLay->addWidget(aLabel, 0, 0); + + myXSpin = new QDoubleSpinBox(myGroupBox); + myXSpin->setMinimum(-DBL_MAX); + myXSpin->setMaximum(DBL_MAX); + myXSpin->setToolTip("X"); + aGroupLay->addWidget(myXSpin, 0, 1); + + connect(myXSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); + } + { + QLabel* aLabel = new QLabel(myGroupBox); + aLabel->setText("Y"); + aLabel->setPixmap(QPixmap(":pictures/y_point.png")); + aGroupLay->addWidget(aLabel, 1, 0); + + myYSpin = new QDoubleSpinBox(myGroupBox); + myYSpin->setMinimum(-DBL_MAX); + myYSpin->setMaximum(DBL_MAX); + myYSpin->setToolTip("X"); + aGroupLay->addWidget(myYSpin, 1, 1); + + connect(myYSpin, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged())); + } +} + +ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() +{ +} + +void ModuleBase_WidgetPoint2D::store(boost::shared_ptr theFeature) +{ + boost::shared_ptr aData = theFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); + + aPoint->setValue(myXSpin->value(), myYSpin->value()); +} + +QWidget* ModuleBase_WidgetPoint2D::getControl() const +{ + return myGroupBox; +} diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.h b/src/ModuleBase/ModuleBase_WidgetPoint2D.h new file mode 100644 index 000000000..a973ef693 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.h @@ -0,0 +1,50 @@ +// File: ModuleBase_WidgetPoint2D.h +// Created: 25 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef ModuleBase_WidgetPoint2D_H +#define ModuleBase_WidgetPoint2D_H + +#include +#include "ModuleBase_WidgetCustom.h" + +#include + +class ModelAPI_Feature; + +class QGroupBox; +class QDoubleSpinBox; + +/**\class ModuleBase_WidgetPoint2D + * \ingroup GUI + * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls + */ +class MODULEBASE_EXPORT ModuleBase_WidgetPoint2D : public ModuleBase_WidgetCustom +{ + Q_OBJECT +public: + /// Constructor + /// \theParent the parent object + /// \theTitle the group box title + /// \theFeatureAttributeID the identifier of the feature attribute + ModuleBase_WidgetPoint2D(QWidget* theParent, QString theTitle, + const std::string& theFeatureAttributeID); + /// Destructor + virtual ~ModuleBase_WidgetPoint2D(); + + /// Saves the internal parameters to the given feature + /// \param theFeature a model feature to be changed + virtual void store(boost::shared_ptr theFeature); + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const; + +private: + std::string myFeatureAttributeID; ///< the identifier of the feature attribute + QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets + QDoubleSpinBox* myXSpin; ///< the spin box for the X coordinate + QDoubleSpinBox* myYSpin; ///< the spin box for the Y coordinate +}; + +#endif diff --git a/src/XGUI/XGUI_SwitchWidget.cpp b/src/ModuleBase/ModuleBase_WidgetSwitch.cpp similarity index 59% rename from src/XGUI/XGUI_SwitchWidget.cpp rename to src/ModuleBase/ModuleBase_WidgetSwitch.cpp index bfa71fe11..3024f1166 100644 --- a/src/XGUI/XGUI_SwitchWidget.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSwitch.cpp @@ -1,17 +1,17 @@ /* - * XGUI_SwitchWidget.cpp + * ModuleBase_WidgetSwitch.cpp * * Created on: Apr 16, 2014 * Author: sbh */ -#include +#include #include #include #include -XGUI_SwitchWidget::XGUI_SwitchWidget(QWidget* parent) +ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* parent) : QFrame(parent) { myMainLay = new QVBoxLayout(this); @@ -27,37 +27,37 @@ XGUI_SwitchWidget::XGUI_SwitchWidget(QWidget* parent) } -XGUI_SwitchWidget::~XGUI_SwitchWidget() +ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch() { } -int XGUI_SwitchWidget::addPage(QWidget* theWidget, const QString& theName) +int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName) { return insertPage(count(), theWidget, theName); } -int XGUI_SwitchWidget::count() const +int ModuleBase_WidgetSwitch::count() const { return myCombo->count(); } -int XGUI_SwitchWidget::currentIndex() const +int ModuleBase_WidgetSwitch::currentIndex() const { return myCombo->currentIndex(); } -QWidget* XGUI_SwitchWidget::currentWidget() const +QWidget* ModuleBase_WidgetSwitch::currentWidget() const { int idx = currentIndex(); return myCases[idx]; } -int XGUI_SwitchWidget::indexOf(QWidget* theWidget) const +int ModuleBase_WidgetSwitch::indexOf(QWidget* theWidget) const { return myCases.indexOf(theWidget); } -int XGUI_SwitchWidget::insertPage(int theIndex, QWidget* theWidget, const QString& theName) +int ModuleBase_WidgetSwitch::insertPage(int theIndex, QWidget* theWidget, const QString& theName) { int index = theIndex < count() ? theIndex : count(); if(count() == 0) @@ -69,22 +69,22 @@ int XGUI_SwitchWidget::insertPage(int theIndex, QWidget* theWidget, const QStrin return index; } -bool XGUI_SwitchWidget::isPageEnabled(int index) const +bool ModuleBase_WidgetSwitch::isPageEnabled(int index) const { return myCases[index]->isEnabled(); } -QString XGUI_SwitchWidget::pageText(int index) const +QString ModuleBase_WidgetSwitch::pageText(int index) const { return myCombo->itemText(index); } -QString XGUI_SwitchWidget::pageToolTip(int index) const +QString ModuleBase_WidgetSwitch::pageToolTip(int index) const { return myCases[index]->toolTip(); } -void XGUI_SwitchWidget::removePage(int index) +void ModuleBase_WidgetSwitch::removePage(int index) { myCombo->removeItem(index); myCases.removeAt(index); @@ -93,28 +93,28 @@ void XGUI_SwitchWidget::removePage(int index) } } -void XGUI_SwitchWidget::setPageEnabled(int index, bool enabled) +void ModuleBase_WidgetSwitch::setPageEnabled(int index, bool enabled) { myCases[index]->setEnabled(enabled); } -void XGUI_SwitchWidget::setPageName(int index, const QString& theName) +void ModuleBase_WidgetSwitch::setPageName(int index, const QString& theName) { myCombo->setItemText(index, theName); } -void XGUI_SwitchWidget::setPageToolTip(int index, const QString& toolTip) +void ModuleBase_WidgetSwitch::setPageToolTip(int index, const QString& toolTip) { myCases[index]->setToolTip(toolTip); } -void XGUI_SwitchWidget::setCurrentIndex(int index) +void ModuleBase_WidgetSwitch::setCurrentIndex(int index) { myCombo->setCurrentIndex(index); refresh(); } -void XGUI_SwitchWidget::refresh() +void ModuleBase_WidgetSwitch::refresh() { foreach(QWidget* eachWidget, myCases) { eachWidget->setVisible(false); diff --git a/src/XGUI/XGUI_SwitchWidget.h b/src/ModuleBase/ModuleBase_WidgetSwitch.h similarity index 74% rename from src/XGUI/XGUI_SwitchWidget.h rename to src/ModuleBase/ModuleBase_WidgetSwitch.h index 0fa6fcca3..08ce3bc71 100644 --- a/src/XGUI/XGUI_SwitchWidget.h +++ b/src/ModuleBase/ModuleBase_WidgetSwitch.h @@ -1,25 +1,25 @@ /* - * XGUI_SwitchWidget.h + * ModuleBase_WidgetSwitch.h * * Created on: Apr 16, 2014 * Author: sbh */ -#ifndef XGUI_SWITCHWIDGET_H_ -#define XGUI_SWITCHWIDGET_H_ +#ifndef ModuleBase_WidgetSwitch_H_ +#define ModuleBase_WidgetSwitch_H_ -#include +#include #include class QComboBox; class QVBoxLayout; -class XGUI_EXPORT XGUI_SwitchWidget: public QFrame +class MODULEBASE_EXPORT ModuleBase_WidgetSwitch: public QFrame { Q_OBJECT public: - XGUI_SwitchWidget(QWidget* parent = NULL); - virtual ~XGUI_SwitchWidget(); + ModuleBase_WidgetSwitch(QWidget* parent = NULL); + virtual ~ModuleBase_WidgetSwitch(); int addPage(QWidget * theWidget, const QString & theName); int count() const; @@ -50,4 +50,4 @@ private: QWidgetList myCases; }; -#endif /* XGUI_SWITCHWIDGET_H_ */ +#endif /* ModuleBase_WidgetSwitch_H_ */ diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index f8ce75a92..5a999aaba 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -7,13 +7,15 @@ SET(PROJECT_HEADERS PartSet.h PartSet_Module.h PartSet_OperationSketchBase.h - PartSet_OperationSketch.h + PartSet_OperationSketch.h + PartSet_OperationSketchLine.h ) SET(PROJECT_SOURCES PartSet_Module.cpp PartSet_OperationSketchBase.cpp PartSet_OperationSketch.cpp + PartSet_OperationSketchLine.cpp ) SET(PROJECT_RESOURCES diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 71d0987a4..c76792ca1 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,5 +1,6 @@ #include #include +#include #include @@ -80,7 +81,15 @@ void PartSet_Module::onFeatureTriggered() ModuleBase_PropPanelOperation* aPartSetOp; if (aCmdId == "Sketch" ) { aPartSetOp = new PartSet_OperationSketch(aCmdId, this); - } else { + } + else if(aCmdId == "SketchLine") { + ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); + boost::shared_ptr aSketchFeature; + if (anOperation) + aSketchFeature = anOperation->feature(); + aPartSetOp = new PartSet_OperationSketchLine(aCmdId, this, aSketchFeature); + } + else { aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this); } aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg)); diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index c343503e2..7eca33e43 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -82,5 +82,6 @@ void PartSet_OperationSketch::setSelectedShapes(const NCollection_List aDir = aPlane->direction(); emit viewerProjectionChange(aDir->x(), aDir->y(), aDir->z()); - commit(); + //commit(); + //SketchPlugin_Sketch::setActive(myFeature); } diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp new file mode 100644 index 000000000..7a5a78196 --- /dev/null +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -0,0 +1,52 @@ +// File: PartSet_OperationSketchLine.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include + +#ifdef _DEBUG +#include +#endif + +using namespace std; + +PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId, + QObject* theParent, + boost::shared_ptr theFeature) +: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature) +{ +} + +PartSet_OperationSketchLine::~PartSet_OperationSketchLine() +{ +} + +bool PartSet_OperationSketchLine::isPerformedImmediately() const +{ + return false; +} + +int PartSet_OperationSketchLine::getSelectionMode() const +{ + return TopAbs_FACE; +} + +void PartSet_OperationSketchLine::setSelectedShapes(const NCollection_List& theList) +{ + if (theList.IsEmpty()) + return; +} + +void PartSet_OperationSketchLine::startOperation() +{ + PartSet_OperationSketchBase::startOperation(); + + if (mySketch) { + boost::shared_ptr aFeature = + boost::dynamic_pointer_cast(mySketch); + + aFeature->addSub(feature()); + } +} diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h new file mode 100644 index 000000000..7c228af06 --- /dev/null +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -0,0 +1,51 @@ +// File: PartSet_OperationSketchLine.h +// Created: 20 Apr 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_OperationSketchLine_H +#define PartSet_OperationSketchLine_H + +#include "PartSet.h" + +#include +#include + +/*! + \class PartSet_OperationSketchLine + * \brief The operation for the sketch feature creation +*/ +class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase +{ + Q_OBJECT +public: + /// Constructor + /// \param theId the feature identifier + /// \param theParent the operation parent + /// \param theFeature the parent feature + PartSet_OperationSketchLine(const QString& theId, QObject* theParent, + boost::shared_ptr theSketchFeature); + /// Destructor + virtual ~PartSet_OperationSketchLine(); + + /// The sketch can not be created immediately, firstly a plane should be set + virtual bool isPerformedImmediately() const; + + /// Returns the operation local selection mode + /// \return the selection mode + virtual int getSelectionMode() const; + + /// Gives the current selected objects to be processed by the operation + /// \param theList a list of interactive selected shapes + virtual void setSelectedShapes(const NCollection_List& theList); + +protected: + /// \brief Virtual method called when operation is started + /// Virtual method called when operation started (see start() method for more description) + /// After the parent operation body perform, set sketch feature to the created line feature + virtual void startOperation(); + +private: + boost::shared_ptr mySketch; ///< the sketch feature +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index 9d0ae5092..7877a7191 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -38,6 +38,11 @@ public: /// Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& preview(); + /// Adds sub-feature of the higher level feature (sub-element of the sketch) + /// \param theFeature sub-feature + SKETCHPLUGIN_EXPORT virtual const void addSub( + const boost::shared_ptr& theFeature) {}; + /// Use plugin manager for features creation SketchPlugin_Line(); }; diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 114940981..ab95647ee 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -1,5 +1,6 @@ #include "SketchPlugin_Plugin.h" #include "SketchPlugin_Sketch.h" +#include "SketchPlugin_Line.h" #include #include @@ -19,9 +20,9 @@ boost::shared_ptr SketchPlugin_Plugin::createFeature(string th if (theFeatureID == "Sketch") { return boost::shared_ptr(new SketchPlugin_Sketch); } - /*else if (theFeatureID == "Point") { - return shared_ptr(new SketchPlugin_Point); - }*/ + else if (theFeatureID == "SketchLine") { + return boost::shared_ptr(new SketchPlugin_Line); + } // feature of such kind is not found return boost::shared_ptr(); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 09ac545be..489bf53e6 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -2,9 +2,13 @@ - + + + + diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index a246e4060..106d695b7 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -19,14 +19,12 @@ SET(PROJECT_HEADERS XGUI_RubberBand.h XGUI_Constants.h XGUI_ViewBackground.h - XGUI_WidgetFactory.h XGUI_DocumentDataModel.h XGUI_PartDataModel.h XGUI_ObjectsBrowser.h XGUI_OperationMgr.h XGUI_DataTreeModel.h XGUI_SelectionMgr.h - XGUI_SwitchWidget.h ) SET(PROJECT_AUTOMOC @@ -47,13 +45,11 @@ SET(PROJECT_SOURCES XGUI_Viewer.cpp XGUI_RubberBand.cpp XGUI_ViewBackground.cpp - XGUI_WidgetFactory.cpp XGUI_DocumentDataModel.cpp XGUI_PartDataModel.cpp XGUI_ObjectsBrowser.cpp XGUI_OperationMgr.cpp XGUI_SelectionMgr.cpp - XGUI_SwitchWidget.cpp ) SET(PROJECT_RESOURCES diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index cbc3ce146..6518d05e7 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -8,7 +8,7 @@ #include "XGUI_Workbench.h" #include "XGUI_Workshop.h" #include "XGUI_Viewer.h" -#include "XGUI_WidgetFactory.h" +#include "ModuleBase_WidgetFactory.h" #include "XGUI_SelectionMgr.h" #include "XGUI_ObjectsBrowser.h" #include "XGUI_Displayer.h" @@ -187,7 +187,7 @@ void XGUI_Workshop::onOperationStarted() myMainWindow->showPropertyPanel(); - XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aOperation); + ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation); aFactory.createWidget(aPropWidget); myMainWindow->setPropertyPannelTitle(aOperation->description()); } -- 2.39.2