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";
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}
)
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})
#include "ModuleBase_Operation.h"
+#include "ModuleBase_WidgetCustom.h"
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
+#include <GeomDataAPI_Point2D.h>
+
#ifdef _DEBUG
#include <QDebug>
#endif
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<ModuleBase_WidgetCustom*>(sender());
+ if (aCustom)
+ aCustom->store(myFeature);
+}
+
/*!
* \brief Verifies whether operator is ready to start.
* \return TRUE if operation is ready to start
// Data model operations.
void storeReal(double);
+ // Data model operations.
+ void storeCustomValue();
+
protected:
virtual bool isReadyToStart() const;
--- /dev/null
+// File: ModuleBase_WidgetCustom.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetCustom_H
+#define ModuleBase_WidgetCustom_H
+
+#include <ModuleBase.h>
+
+#include <QObject>
+
+#include <boost/shared_ptr.hpp>
+
+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<ModelAPI_Feature> theFeature) = 0;
+
+signals:
+ /// The signal about widget values changed
+ void valuesChanged();
+};
+
+#endif
--- /dev/null
+/*
+ * ModuleBase_WidgetFactory.cpp
+ *
+ * Created on: Apr 3, 2014
+ * Author: sbh
+ */
+
+#include <ModuleBase_WidgetFactory.h>
+
+#include <ModuleBase_WidgetSwitch.h>
+
+#include <ModuleBase_PropPanelOperation.h>
+#include <ModuleBase_WidgetPoint2D.h>
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <QWidget>
+#include <QHBoxLayout>
+#include <QGridLayout>
+#include <QSpinBox>
+#include <QMetaProperty>
+#include <QLabel>
+#include <QPixmap>
+#include <QGroupBox>
+#include <QToolBox>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+#include <cfloat>
+#include <climits>
+
+ModuleBase_WidgetFactory::ModuleBase_WidgetFactory(ModuleBase_PropPanelOperation* theOperation)
+ : myOperation(theOperation)
+{
+ QString aXml = myOperation->xmlRepresentation();
+ myWidgetApi = new Config_WidgetAPI(aXml.toStdString());
+}
+
+ModuleBase_WidgetFactory::~ModuleBase_WidgetFactory()
+{
+}
+
+void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
+{
+ if (!myWidgetApi->toChildWidget())
+ return;
+
+ QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
+ aWidgetLay->setContentsMargins(2, 2, 2, 2);
+ do { //Iterate over each node
+ std::string aWdgType = myWidgetApi->widgetType();
+ //Create a widget (doublevalue, groupbox, toolbox, etc.
+ QWidget* aWidget = createWidgetByType(aWdgType, theParent);
+ if (aWidget) {
+ aWidgetLay->addWidget(aWidget);
+ }
+ if (myWidgetApi->isContainerWidget()) {
+ //if current widget is groupbox (container) process it's children recursively
+ QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
+ createWidget(aWidget);
+ QGroupBox* aGrBox = qobject_cast<QGroupBox*>(aWidget);
+ aGrBox->setTitle(aGroupName);
+ }
+ if (myWidgetApi->isPagedWidget()) {
+ //If current widget is toolbox or switch-casebox then fetch all
+ //it's pages recursively and setup into the widget.
+ myWidgetApi->toChildWidget();
+ do {
+ QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
+ QWidget* aPage = new QWidget(aWidget);
+ createWidget(aPage);
+ if (aWdgType == WDG_SWITCH) {
+ ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
+ aSwitch->addPage(aPage, aPageName);
+ } else if (aWdgType == WDG_TOOLBOX){
+ QToolBox* aToolbox = qobject_cast<QToolBox*>(aWidget);
+ aToolbox->addItem(aPage, aPageName);
+ }
+ } while(myWidgetApi->toNextWidget());
+ }
+ } while(myWidgetApi->toNextWidget());
+ theParent->setLayout(aWidgetLay);
+}
+
+QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent)
+{
+ QWidget* result = new QWidget(theParent);
+ QVBoxLayout* aLabelLay = new QVBoxLayout(result);
+ QLabel* aLabel = new QLabel(result);
+ aLabel->setText(qs(myWidgetApi->getProperty(INFO_WDG_TEXT)));
+ aLabel->setToolTip(qs(myWidgetApi->getProperty(INFO_WDG_TOOLTIP)));
+ aLabelLay->addWidget(aLabel);
+ aLabelLay->addStretch(1);
+ result->setLayout(aLabelLay);
+ return result;
+}
+
+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 (theType == WDG_POINT_SELECTOR) {
+ result = pointSelectorControl(theParent);
+ }
+ else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
+ result = createContainer(theType, theParent);
+ }
+#ifdef _DEBUG
+ else { qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad widget type"; }
+#endif
+ return result;
+}
+
+QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent)
+{
+ QWidget* result = NULL;
+ if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) {
+ QGroupBox* aGroupBox = new QGroupBox(theParent);
+ aGroupBox->setCheckable(theType == WDG_CHECK_GROUP);
+ result = aGroupBox;
+ } else if (theType == WDG_TOOLBOX) {
+ result = new QToolBox(theParent);
+ } else if (theType == WDG_SWITCH) {
+ result = new ModuleBase_WidgetSwitch(theParent);
+ } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
+ result = NULL;
+ }
+#ifdef _DEBUG
+ else { qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad container type"; }
+#endif
+ return result;
+}
+
+QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl()
+{
+ QWidget* result = new QWidget();
+ QHBoxLayout* aControlLay = new QHBoxLayout(result);
+ aControlLay->setContentsMargins(0, 0, 0, 0);
+ QString aLabelText = qs(myWidgetApi->widgetLabel());
+ QString aLabelIcon = qs(myWidgetApi->widgetIcon());
+ QLabel* aLabel = new QLabel(aLabelText);
+ aLabel->setPixmap(QPixmap(aLabelIcon));
+
+ aControlLay->addWidget(aLabel);
+ QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
+ QString anObjName = QString::fromStdString(myWidgetApi->widgetId());
+ aBox->setObjectName(anObjName);
+ bool isOk = false;
+ std::string aProp = myWidgetApi->getProperty(DOUBLE_WDG_MIN);
+ double aMinVal = qs(aProp).toDouble(&isOk);
+ if (isOk) {
+ aBox->setMinimum(aMinVal);
+ } else {
+ aBox->setMinimum(-DBL_MAX);
+ }
+ aProp = myWidgetApi->getProperty(DOUBLE_WDG_MAX);
+ double aMaxVal = qs(aProp).toDouble(&isOk);
+ if (isOk) {
+ aBox->setMaximum(aMaxVal);
+ } else {
+ aBox->setMaximum(DBL_MAX);
+ }
+ aProp = myWidgetApi->getProperty(DOUBLE_WDG_STEP);
+ double aStepVal = qs(aProp).toDouble(&isOk);
+ if (isOk) {
+ aBox->setSingleStep(aStepVal);
+ }
+ aProp = myWidgetApi->getProperty(DOUBLE_WDG_DFLT);
+ double aDefVal = qs(aProp).toDouble(&isOk);
+ if (isOk) {
+ aBox->setValue(aDefVal);
+ }
+ QString aTTip = qs(myWidgetApi->widgetTooltip());
+ aBox->setToolTip(aTTip);
+ aControlLay->addWidget(aBox);
+ aControlLay->setStretch(1, 1);
+ result->setLayout(aControlLay);
+ connectWidget(aBox, WDG_DOUBLEVALUE);
+ return result;
+}
+
+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<ModuleBase_WidgetCustom*>(theWidget);
+ result = QObject::connect(aCustom, SIGNAL(valuesChanged()),
+ myOperation, SLOT(storeCustomValue()));
+ }
+ return result;
+}
+
+QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
+{
+ return QString::fromStdString(theStdString);
+}
--- /dev/null
+/*
+ * ModuleBase_WidgetFactory.h
+ *
+ * Created on: Apr 3, 2014
+ * Author: sbh
+ */
+
+#ifndef ModuleBase_WidgetFactory_H_
+#define ModuleBase_WidgetFactory_H_
+
+#include <ModuleBase.h>
+#include <QString>
+
+class QObject;
+class QWidget;
+class Config_WidgetAPI;
+class ModuleBase_PropPanelOperation;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetFactory
+{
+public:
+ ModuleBase_WidgetFactory(ModuleBase_PropPanelOperation*);
+ virtual ~ModuleBase_WidgetFactory();
+
+ void createWidget(QWidget* theParent);
+
+protected:
+ //Widgets
+ 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(QObject*, const QString&);
+ QString qs(const std::string& theStdString) const;
+
+private:
+ Config_WidgetAPI* myWidgetApi;
+ ModuleBase_PropPanelOperation* myOperation;
+
+
+};
+
+#endif /* ModuleBase_WidgetFactory_H_ */
--- /dev/null
+// File: ModuleBase_WidgetPoint2D.cpp
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetPoint2D.h>
+
+#include <Config_Keywords.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <QGroupBox>
+#include <QGridLayout>
+#include <QDoubleSpinBox>
+#include <QLabel>
+
+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<ModelAPI_Feature> theFeature)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
+
+ aPoint->setValue(myXSpin->value(), myYSpin->value());
+}
+
+QWidget* ModuleBase_WidgetPoint2D::getControl() const
+{
+ return myGroupBox;
+}
--- /dev/null
+// File: ModuleBase_WidgetPoint2D.h
+// Created: 25 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetPoint2D_H
+#define ModuleBase_WidgetPoint2D_H
+
+#include <ModuleBase.h>
+#include "ModuleBase_WidgetCustom.h"
+
+#include <QObject>
+
+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<ModelAPI_Feature> 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
--- /dev/null
+/*
+ * ModuleBase_WidgetSwitch.cpp
+ *
+ * Created on: Apr 16, 2014
+ * Author: sbh
+ */
+
+#include <ModuleBase_WidgetSwitch.h>
+
+#include <QComboBox>
+#include <QVBoxLayout>
+#include <QSpacerItem>
+
+ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* parent)
+: QFrame(parent)
+{
+ myMainLay = new QVBoxLayout(this);
+ myMainLay->setContentsMargins(2, 4, 2, 2);
+ myCombo = new QComboBox(this);
+ myCombo->hide();
+ myMainLay->addWidget(myCombo);
+ this->setFrameShape(QFrame::StyledPanel);
+ connect(myCombo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(setCurrentIndex(int)));
+ connect(myCombo, SIGNAL(currentIndexChanged(int)),
+ this, SIGNAL(currentPageChanged(int)));
+
+}
+
+ModuleBase_WidgetSwitch::~ModuleBase_WidgetSwitch()
+{
+}
+
+int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
+{
+ return insertPage(count(), theWidget, theName);
+}
+
+int ModuleBase_WidgetSwitch::count() const
+{
+ return myCombo->count();
+}
+
+int ModuleBase_WidgetSwitch::currentIndex() const
+{
+ return myCombo->currentIndex();
+}
+
+QWidget* ModuleBase_WidgetSwitch::currentWidget() const
+{
+ int idx = currentIndex();
+ return myCases[idx];
+}
+
+int ModuleBase_WidgetSwitch::indexOf(QWidget* theWidget) const
+{
+ return myCases.indexOf(theWidget);
+}
+
+int ModuleBase_WidgetSwitch::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
+{
+ int index = theIndex < count() ? theIndex : count();
+ if(count() == 0)
+ myCombo->show();
+ myCombo->insertItem(index, theName);
+ myCases.insert(index, theWidget);
+ myMainLay->addWidget(theWidget);
+ setCurrentIndex(theIndex);
+ return index;
+}
+
+bool ModuleBase_WidgetSwitch::isPageEnabled(int index) const
+{
+ return myCases[index]->isEnabled();
+}
+
+QString ModuleBase_WidgetSwitch::pageText(int index) const
+{
+ return myCombo->itemText(index);
+}
+
+QString ModuleBase_WidgetSwitch::pageToolTip(int index) const
+{
+ return myCases[index]->toolTip();
+}
+
+void ModuleBase_WidgetSwitch::removePage(int index)
+{
+ myCombo->removeItem(index);
+ myCases.removeAt(index);
+ if (count() == 0) {
+ myCombo->hide();
+ }
+}
+
+void ModuleBase_WidgetSwitch::setPageEnabled(int index, bool enabled)
+{
+ myCases[index]->setEnabled(enabled);
+}
+
+void ModuleBase_WidgetSwitch::setPageName(int index, const QString& theName)
+{
+ myCombo->setItemText(index, theName);
+}
+
+void ModuleBase_WidgetSwitch::setPageToolTip(int index, const QString& toolTip)
+{
+ myCases[index]->setToolTip(toolTip);
+}
+
+void ModuleBase_WidgetSwitch::setCurrentIndex(int index)
+{
+ myCombo->setCurrentIndex(index);
+ refresh();
+}
+
+void ModuleBase_WidgetSwitch::refresh()
+{
+ foreach(QWidget* eachWidget, myCases) {
+ eachWidget->setVisible(false);
+ }
+ if(currentIndex() >= myCases.count())
+ return;
+ myCases[currentIndex()]->setVisible(true);
+}
--- /dev/null
+/*
+ * ModuleBase_WidgetSwitch.h
+ *
+ * Created on: Apr 16, 2014
+ * Author: sbh
+ */
+
+#ifndef ModuleBase_WidgetSwitch_H_
+#define ModuleBase_WidgetSwitch_H_
+
+#include <ModuleBase.h>
+#include <QFrame>
+
+class QComboBox;
+class QVBoxLayout;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetSwitch: public QFrame
+{
+ Q_OBJECT
+public:
+ ModuleBase_WidgetSwitch(QWidget* parent = NULL);
+ virtual ~ModuleBase_WidgetSwitch();
+
+ int addPage(QWidget * theWidget, const QString & theName);
+ int count() const;
+ int currentIndex() const;
+ QWidget * currentWidget() const;
+ int indexOf(QWidget * theWidget) const;
+ int insertPage(int index, QWidget * theWidget, const QString & theName);
+ bool isPageEnabled(int index) const;
+ QString pageText(int index) const;
+ QString pageToolTip(int index) const;
+ void removePage(int index);
+ void setPageEnabled(int index, bool enabled);
+ void setPageName(int index, const QString & text);
+ void setPageToolTip(int index, const QString & toolTip);
+
+public slots:
+ void setCurrentIndex(int index);
+
+signals:
+ void currentPageChanged(int);
+
+protected:
+ void refresh();
+
+private:
+ QVBoxLayout* myMainLay;
+ QComboBox* myCombo;
+ QWidgetList myCases;
+};
+
+#endif /* ModuleBase_WidgetSwitch_H_ */
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
#include <PartSet_Module.h>
#include <PartSet_OperationSketch.h>
+#include <PartSet_OperationSketchLine.h>
#include <ModuleBase_Operation.h>
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<ModelAPI_Feature> 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));
boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
emit viewerProjectionChange(aDir->x(), aDir->y(), aDir->z());
- commit();
+ //commit();
+ //SketchPlugin_Sketch::setActive(myFeature);
}
--- /dev/null
+// File: PartSet_OperationSketchLine.h
+// Created: 20 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_OperationSketchLine.h>
+
+#include <SketchPlugin_Feature.h>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+using namespace std;
+
+PartSet_OperationSketchLine::PartSet_OperationSketchLine(const QString& theId,
+ QObject* theParent,
+ boost::shared_ptr<ModelAPI_Feature> 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<TopoDS_Shape>& theList)
+{
+ if (theList.IsEmpty())
+ return;
+}
+
+void PartSet_OperationSketchLine::startOperation()
+{
+ PartSet_OperationSketchBase::startOperation();
+
+ if (mySketch) {
+ boost::shared_ptr<SketchPlugin_Feature> aFeature =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+
+ aFeature->addSub(feature());
+ }
+}
--- /dev/null
+// File: PartSet_OperationSketchLine.h
+// Created: 20 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_OperationSketchLine_H
+#define PartSet_OperationSketchLine_H
+
+#include "PartSet.h"
+
+#include <PartSet_OperationSketchBase.h>
+#include <QObject>
+
+/*!
+ \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<ModelAPI_Feature> 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<TopoDS_Shape>& 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<ModelAPI_Feature> mySketch; ///< the sketch feature
+};
+
+#endif
/// Returns the sketch preview
SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& 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<ModelAPI_Feature>& theFeature) {};
+
/// Use plugin manager for features creation
SketchPlugin_Line();
};
#include "SketchPlugin_Plugin.h"
#include "SketchPlugin_Sketch.h"
+#include "SketchPlugin_Line.h"
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
if (theFeatureID == "Sketch") {
return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_Sketch);
}
- /*else if (theFeatureID == "Point") {
- return shared_ptr<ModelAPI_Feature>(new SketchPlugin_Point);
- }*/
+ else if (theFeatureID == "SketchLine") {
+ return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_Line);
+ }
// feature of such kind is not found
return boost::shared_ptr<ModelAPI_Feature>();
}
<workbench id="Sketch">
<group id="Basic">
<feature id="Sketch" text="New sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
- <label text="Natasha, please provide a text for the label" tooltip="Natasha, please provide a text for the tooltip"/>
+ <label text="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/>
<!--icon=":pictures/x_point.png"-->
</feature>
+ <feature id="SketchLine" text="Line" tooltip="Create a new line" icon=":icons/line.png">
+ <point_selector id="StartPoint" title="Start point" tooltip="Start point of the line"/>
+ <point_selector id="EndPoint" title="End point" tooltip="End point of the line"/>
+ </feature>
</group>
</workbench>
</plugin>
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
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
+++ /dev/null
-/*
- * XGUI_SwitchWidget.cpp
- *
- * Created on: Apr 16, 2014
- * Author: sbh
- */
-
-#include <XGUI_SwitchWidget.h>
-
-#include <QComboBox>
-#include <QVBoxLayout>
-#include <QSpacerItem>
-
-XGUI_SwitchWidget::XGUI_SwitchWidget(QWidget* parent)
-: QFrame(parent)
-{
- myMainLay = new QVBoxLayout(this);
- myMainLay->setContentsMargins(2, 4, 2, 2);
- myCombo = new QComboBox(this);
- myCombo->hide();
- myMainLay->addWidget(myCombo);
- this->setFrameShape(QFrame::StyledPanel);
- connect(myCombo, SIGNAL(currentIndexChanged(int)),
- this, SLOT(setCurrentIndex(int)));
- connect(myCombo, SIGNAL(currentIndexChanged(int)),
- this, SIGNAL(currentPageChanged(int)));
-
-}
-
-XGUI_SwitchWidget::~XGUI_SwitchWidget()
-{
-}
-
-int XGUI_SwitchWidget::addPage(QWidget* theWidget, const QString& theName)
-{
- return insertPage(count(), theWidget, theName);
-}
-
-int XGUI_SwitchWidget::count() const
-{
- return myCombo->count();
-}
-
-int XGUI_SwitchWidget::currentIndex() const
-{
- return myCombo->currentIndex();
-}
-
-QWidget* XGUI_SwitchWidget::currentWidget() const
-{
- int idx = currentIndex();
- return myCases[idx];
-}
-
-int XGUI_SwitchWidget::indexOf(QWidget* theWidget) const
-{
- return myCases.indexOf(theWidget);
-}
-
-int XGUI_SwitchWidget::insertPage(int theIndex, QWidget* theWidget, const QString& theName)
-{
- int index = theIndex < count() ? theIndex : count();
- if(count() == 0)
- myCombo->show();
- myCombo->insertItem(index, theName);
- myCases.insert(index, theWidget);
- myMainLay->addWidget(theWidget);
- setCurrentIndex(theIndex);
- return index;
-}
-
-bool XGUI_SwitchWidget::isPageEnabled(int index) const
-{
- return myCases[index]->isEnabled();
-}
-
-QString XGUI_SwitchWidget::pageText(int index) const
-{
- return myCombo->itemText(index);
-}
-
-QString XGUI_SwitchWidget::pageToolTip(int index) const
-{
- return myCases[index]->toolTip();
-}
-
-void XGUI_SwitchWidget::removePage(int index)
-{
- myCombo->removeItem(index);
- myCases.removeAt(index);
- if (count() == 0) {
- myCombo->hide();
- }
-}
-
-void XGUI_SwitchWidget::setPageEnabled(int index, bool enabled)
-{
- myCases[index]->setEnabled(enabled);
-}
-
-void XGUI_SwitchWidget::setPageName(int index, const QString& theName)
-{
- myCombo->setItemText(index, theName);
-}
-
-void XGUI_SwitchWidget::setPageToolTip(int index, const QString& toolTip)
-{
- myCases[index]->setToolTip(toolTip);
-}
-
-void XGUI_SwitchWidget::setCurrentIndex(int index)
-{
- myCombo->setCurrentIndex(index);
- refresh();
-}
-
-void XGUI_SwitchWidget::refresh()
-{
- foreach(QWidget* eachWidget, myCases) {
- eachWidget->setVisible(false);
- }
- if(currentIndex() >= myCases.count())
- return;
- myCases[currentIndex()]->setVisible(true);
-}
+++ /dev/null
-/*
- * XGUI_SwitchWidget.h
- *
- * Created on: Apr 16, 2014
- * Author: sbh
- */
-
-#ifndef XGUI_SWITCHWIDGET_H_
-#define XGUI_SWITCHWIDGET_H_
-
-#include <XGUI.h>
-#include <QFrame>
-
-class QComboBox;
-class QVBoxLayout;
-
-class XGUI_EXPORT XGUI_SwitchWidget: public QFrame
-{
- Q_OBJECT
-public:
- XGUI_SwitchWidget(QWidget* parent = NULL);
- virtual ~XGUI_SwitchWidget();
-
- int addPage(QWidget * theWidget, const QString & theName);
- int count() const;
- int currentIndex() const;
- QWidget * currentWidget() const;
- int indexOf(QWidget * theWidget) const;
- int insertPage(int index, QWidget * theWidget, const QString & theName);
- bool isPageEnabled(int index) const;
- QString pageText(int index) const;
- QString pageToolTip(int index) const;
- void removePage(int index);
- void setPageEnabled(int index, bool enabled);
- void setPageName(int index, const QString & text);
- void setPageToolTip(int index, const QString & toolTip);
-
-public slots:
- void setCurrentIndex(int index);
-
-signals:
- void currentPageChanged(int);
-
-protected:
- void refresh();
-
-private:
- QVBoxLayout* myMainLay;
- QComboBox* myCombo;
- QWidgetList myCases;
-};
-
-#endif /* XGUI_SWITCHWIDGET_H_ */
+++ /dev/null
-/*
- * XGUI_WidgetFactory.cpp
- *
- * Created on: Apr 3, 2014
- * Author: sbh
- */
-
-#include <XGUI_WidgetFactory.h>
-
-#include <XGUI_SwitchWidget.h>
-
-#include <ModuleBase_PropPanelOperation.h>
-#include <Config_Keywords.h>
-#include <Config_WidgetAPI.h>
-
-#include <QWidget>
-#include <QHBoxLayout>
-#include <QSpinBox>
-#include <QMetaProperty>
-#include <QLabel>
-#include <QPixmap>
-#include <QGroupBox>
-#include <QToolBox>
-
-#ifdef _DEBUG
-#include <QDebug>
-#endif
-
-#include <cfloat>
-#include <climits>
-
-XGUI_WidgetFactory::XGUI_WidgetFactory(ModuleBase_PropPanelOperation* theOperation)
- : myOperation(theOperation)
-{
- QString aXml = myOperation->xmlRepresentation();
- myWidgetApi = new Config_WidgetAPI(aXml.toStdString());
-}
-
-XGUI_WidgetFactory::~XGUI_WidgetFactory()
-{
-}
-
-void XGUI_WidgetFactory::createWidget(QWidget* theParent)
-{
- if (!myWidgetApi->toChildWidget())
- return;
-
- QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
- aWidgetLay->setContentsMargins(2, 2, 2, 2);
- do { //Iterate over each node
- std::string aWdgType = myWidgetApi->widgetType();
- //Create a widget (doublevalue, groupbox, toolbox, etc.
- QWidget* aWidget = createWidgetByType(aWdgType, theParent);
- if (aWidget) {
- aWidgetLay->addWidget(aWidget);
- }
- if (myWidgetApi->isContainerWidget()) {
- //if current widget is groupbox (container) process it's children recursively
- QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
- createWidget(aWidget);
- QGroupBox* aGrBox = qobject_cast<QGroupBox*>(aWidget);
- aGrBox->setTitle(aGroupName);
- }
- if (myWidgetApi->isPagedWidget()) {
- //If current widget is toolbox or switch-casebox then fetch all
- //it's pages recursively and setup into the widget.
- myWidgetApi->toChildWidget();
- do {
- QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
- QWidget* aPage = new QWidget(aWidget);
- createWidget(aPage);
- if (aWdgType == WDG_SWITCH) {
- XGUI_SwitchWidget* aSwitch = qobject_cast<XGUI_SwitchWidget*>(aWidget);
- aSwitch->addPage(aPage, aPageName);
- } else if (aWdgType == WDG_TOOLBOX){
- QToolBox* aToolbox = qobject_cast<QToolBox*>(aWidget);
- aToolbox->addItem(aPage, aPageName);
- }
- } while(myWidgetApi->toNextWidget());
- }
- } while(myWidgetApi->toNextWidget());
- theParent->setLayout(aWidgetLay);
-}
-
-QWidget* XGUI_WidgetFactory::labelControl(QWidget* theParent)
-{
- QWidget* result = new QWidget(theParent);
- QVBoxLayout* aLabelLay = new QVBoxLayout(result);
- QLabel* aLabel = new QLabel(result);
- aLabel->setText(qs(myWidgetApi->getProperty(INFO_WDG_TEXT)));
- aLabel->setToolTip(qs(myWidgetApi->getProperty(INFO_WDG_TOOLTIP)));
- aLabelLay->addWidget(aLabel);
- aLabelLay->addStretch(1);
- result->setLayout(aLabelLay);
- return result;
-}
-
-QWidget* XGUI_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()) {
- result = createContainer(theType, theParent);
- }
-#ifdef _DEBUG
- else { qDebug() << "XGUI_WidgetFactory::fillWidget: find bad widget type"; }
-#endif
- return result;
-}
-
-QWidget* XGUI_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent)
-{
- QWidget* result = NULL;
- if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) {
- QGroupBox* aGroupBox = new QGroupBox(theParent);
- aGroupBox->setCheckable(theType == WDG_CHECK_GROUP);
- result = aGroupBox;
- } else if (theType == WDG_TOOLBOX) {
- result = new QToolBox(theParent);
- } else if (theType == WDG_SWITCH) {
- result = new XGUI_SwitchWidget(theParent);
- } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
- result = NULL;
- }
-#ifdef _DEBUG
- else { qDebug() << "XGUI_WidgetFactory::fillWidget: find bad container type"; }
-#endif
- return result;
-}
-
-QWidget* XGUI_WidgetFactory::doubleSpinBoxControl()
-{
- QWidget* result = new QWidget();
- QHBoxLayout* aControlLay = new QHBoxLayout(result);
- aControlLay->setContentsMargins(0, 0, 0, 0);
- QString aLabelText = qs(myWidgetApi->widgetLabel());
- QString aLabelIcon = qs(myWidgetApi->widgetIcon());
- QLabel* aLabel = new QLabel(aLabelText);
- aLabel->setPixmap(QPixmap(aLabelIcon));
-
- aControlLay->addWidget(aLabel);
- QDoubleSpinBox* aBox = new QDoubleSpinBox(result);
- QString anObjName = QString::fromStdString(myWidgetApi->widgetId());
- aBox->setObjectName(anObjName);
- bool isOk = false;
- std::string aProp = myWidgetApi->getProperty(DOUBLE_WDG_MIN);
- double aMinVal = qs(aProp).toDouble(&isOk);
- if (isOk) {
- aBox->setMinimum(aMinVal);
- } else {
- aBox->setMinimum(-DBL_MAX);
- }
- aProp = myWidgetApi->getProperty(DOUBLE_WDG_MAX);
- double aMaxVal = qs(aProp).toDouble(&isOk);
- if (isOk) {
- aBox->setMaximum(aMaxVal);
- } else {
- aBox->setMaximum(DBL_MAX);
- }
- aProp = myWidgetApi->getProperty(DOUBLE_WDG_STEP);
- double aStepVal = qs(aProp).toDouble(&isOk);
- if (isOk) {
- aBox->setSingleStep(aStepVal);
- }
- aProp = myWidgetApi->getProperty(DOUBLE_WDG_DFLT);
- double aDefVal = qs(aProp).toDouble(&isOk);
- if (isOk) {
- aBox->setValue(aDefVal);
- }
- QString aTTip = qs(myWidgetApi->widgetTooltip());
- aBox->setToolTip(aTTip);
- aControlLay->addWidget(aBox);
- aControlLay->setStretch(1, 1);
- result->setLayout(aControlLay);
- connectWidget(aBox, WDG_DOUBLEVALUE);
- return result;
-}
-
-bool XGUI_WidgetFactory::connectWidget(QWidget* theWidget, const QString& theType)
-{
- bool result = false;
- if (theType == WDG_DOUBLEVALUE) {
- result = QObject::connect(theWidget, SIGNAL(valueChanged(double)),
- myOperation, SLOT(storeReal(double)));
- }
- return result;
-}
-
-QString XGUI_WidgetFactory::qs(const std::string& theStdString) const
-{
- return QString::fromStdString(theStdString);
-}
+++ /dev/null
-/*
- * XGUI_WidgetFactory.h
- *
- * Created on: Apr 3, 2014
- * Author: sbh
- */
-
-#ifndef XGUI_WIDGETFACTORY_H_
-#define XGUI_WIDGETFACTORY_H_
-
-#include "XGUI.h"
-#include <QString>
-
-class QWidget;
-class Config_WidgetAPI;
-class ModuleBase_PropPanelOperation;
-
-class XGUI_EXPORT XGUI_WidgetFactory
-{
-public:
- XGUI_WidgetFactory(ModuleBase_PropPanelOperation*);
- virtual ~XGUI_WidgetFactory();
-
- void createWidget(QWidget* theParent);
-
-protected:
- //Widgets
- QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL);
- QWidget* labelControl(QWidget* theParent);
- QWidget* doubleSpinBoxControl();
- QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
-
- bool connectWidget(QWidget*, const QString&);
- QString qs(const std::string& theStdString) const;
-
-private:
- Config_WidgetAPI* myWidgetApi;
- ModuleBase_PropPanelOperation* myOperation;
-
-
-};
-
-#endif /* XGUI_WIDGETFACTORY_H_ */
#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"
myMainWindow->showPropertyPanel();
- XGUI_WidgetFactory aFactory = XGUI_WidgetFactory(aOperation);
+ ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation);
aFactory.createWidget(aPropWidget);
myMainWindow->setPropertyPannelTitle(aOperation->description());
}