From 496c2223e35ace4a376cc84d8eea529aa3138352 Mon Sep 17 00:00:00 2001 From: sbh Date: Thu, 9 Oct 2014 14:15:05 +0400 Subject: [PATCH] GUI part of "group" creation functionality --- src/Config/Config_Keywords.h | 2 + src/FeaturesPlugin/CMakeLists.txt | 3 + src/FeaturesPlugin/FeaturesPlugin_Group.cpp | 32 +++++++ src/FeaturesPlugin/FeaturesPlugin_Group.h | 58 ++++++++++++ src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 18 ++-- src/FeaturesPlugin/group_widget.xml | 15 +++ src/FeaturesPlugin/plugin-Features.xml | 8 ++ src/ModuleBase/CMakeLists.txt | 4 + src/ModuleBase/ModuleBase_WidgetFactory.cpp | 24 +++++ src/ModuleBase/ModuleBase_WidgetFactory.h | 3 + src/ModuleBase/ModuleBase_WidgetLineEdit.cpp | 93 +++++++++++++++++++ src/ModuleBase/ModuleBase_WidgetLineEdit.h | 52 +++++++++++ .../ModuleBase_WidgetMultiSelector.cpp | 89 ++++++++++++++++++ .../ModuleBase_WidgetMultiSelector.h | 51 ++++++++++ .../ModuleBase_WidgetShapeSelector.cpp | 5 +- .../ModuleBase_WidgetShapeSelector.h | 4 +- 16 files changed, 451 insertions(+), 10 deletions(-) create mode 100644 src/FeaturesPlugin/FeaturesPlugin_Group.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_Group.h create mode 100644 src/FeaturesPlugin/group_widget.xml create mode 100644 src/ModuleBase/ModuleBase_WidgetLineEdit.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetLineEdit.h create mode 100644 src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetMultiSelector.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 87be5d399..5a4eb4683 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -20,6 +20,8 @@ const static char* NODE_VALIDATOR = "validator"; //Widgets const static char* WDG_DOUBLEVALUE = "doublevalue"; const static char* WDG_BOOLVALUE = "boolvalue"; +const static char* WDG_STRINGVALUE = "stringvalue"; +const static char* WDG_MULTISELECTOR = "multi_selector"; //Widget containers const static char* WDG_INFO = "label"; const static char* WDG_GROUP = "groupbox"; diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 024b9593b..4d2b643d5 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -5,18 +5,21 @@ SET(PROJECT_HEADERS FeaturesPlugin_Plugin.h FeaturesPlugin_Extrusion.h FeaturesPlugin_Boolean.h + FeaturesPlugin_Group.h ) SET(PROJECT_SOURCES FeaturesPlugin_Plugin.cpp FeaturesPlugin_Extrusion.cpp FeaturesPlugin_Boolean.cpp + FeaturesPlugin_Group.cpp ) SET(XML_RESOURCES plugin-Features.xml extrusion_widget.xml boolean_widget.xml + group_widget.xml ) INCLUDE_DIRECTORIES( diff --git a/src/FeaturesPlugin/FeaturesPlugin_Group.cpp b/src/FeaturesPlugin/FeaturesPlugin_Group.cpp new file mode 100644 index 000000000..3a9a07a15 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_Group.cpp @@ -0,0 +1,32 @@ +// File: FeaturesPlugin_Group.cpp +// Created: 08 Oct 2014 +// Author: Sergey BELASH + +#include "FeaturesPlugin_Group.h" + +#include +#include +#include +#include + +using namespace std; + +FeaturesPlugin_Group::FeaturesPlugin_Group() +{ +} + +void FeaturesPlugin_Group::initAttributes() +{ + data()->addAttribute(FeaturesPlugin_Group::NAME_ID(), ModelAPI_AttributeString::type()); + data()->addAttribute(FeaturesPlugin_Group::TYPE_ID(), ModelAPI_AttributeInteger::type()); + data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeString::type()); +} + +void FeaturesPlugin_Group::execute() +{ + AttributeIntegerPtr aTypeAttr = boost::dynamic_pointer_cast( + data()->attribute(FeaturesPlugin_Group::TYPE_ID())); + if (!aTypeAttr) + return; + int aType = aTypeAttr->value(); +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Group.h b/src/FeaturesPlugin/FeaturesPlugin_Group.h new file mode 100644 index 000000000..12d298704 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_Group.h @@ -0,0 +1,58 @@ +// File: FeaturesPlugin_Group.h +// Created: 08 Oct 2014 +// Author: Sergey BELASH + +#ifndef FEATURESPLUGIN_GROUP_H_ +#define FEATURESPLUGIN_GROUP_H_ + +#include "FeaturesPlugin.h" +#include +#include + +class FeaturesPlugin_Group : public ModelAPI_Feature +{ + public: + /// Extrusion kind + inline static const std::string& ID() + { + static const std::string MY_GROUP_ID("Group"); + return MY_GROUP_ID; + } + /// attribute name of group type + inline static const std::string& NAME_ID() + { + static const std::string MY_GROUP_NAME_ID("group_name"); + return MY_GROUP_NAME_ID; + } + /// attribute name of group type + inline static const std::string& TYPE_ID() + { + static const std::string MY_GROUP_TYPE_ID("group_type"); + return MY_GROUP_TYPE_ID; + } + /// attribute name of selected entities list + inline static const std::string& LIST_ID() + { + static const std::string MY_GROUP_LIST_ID("group_list"); + return MY_GROUP_LIST_ID; + } + + /// Returns the kind of a feature + FEATURESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = FeaturesPlugin_Group::ID(); + return MY_KIND; + } + + /// Creates a new part document if needed + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation + FeaturesPlugin_Group(); + +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index c43cd7a52..32c95813f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -1,9 +1,14 @@ -#include "FeaturesPlugin_Plugin.h" -#include "FeaturesPlugin_Extrusion.h" -#include "FeaturesPlugin_Boolean.h" +#include + +#include +#include +#include #include -#include + +#include + +#include using namespace std; @@ -20,9 +25,10 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID) { if (theFeatureID == FeaturesPlugin_Extrusion::ID()) { return FeaturePtr(new FeaturesPlugin_Extrusion); - } else - if (theFeatureID == FeaturesPlugin_Boolean::ID()) { + } else if (theFeatureID == FeaturesPlugin_Boolean::ID()) { return FeaturePtr(new FeaturesPlugin_Boolean); + } else if (theFeatureID == FeaturesPlugin_Group::ID()) { + return FeaturePtr(new FeaturesPlugin_Group); } // feature of such kind is not found return FeaturePtr(); diff --git a/src/FeaturesPlugin/group_widget.xml b/src/FeaturesPlugin/group_widget.xml new file mode 100644 index 000000000..7b45d68f5 --- /dev/null +++ b/src/FeaturesPlugin/group_widget.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 1088f2425..bcd23c7e1 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -8,5 +8,13 @@ + + + + + diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 1e49aef44..4a778cb41 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -30,6 +30,8 @@ SET(PROJECT_HEADERS ModuleBase_DoubleSpinBox.h ModuleBase_IPropertyPanel.h ModuleBase_IViewer.h + ModuleBase_WidgetLineEdit.h + ModuleBase_WidgetMultiSelector.h ) SET(PROJECT_SOURCES @@ -53,6 +55,8 @@ SET(PROJECT_SOURCES ModuleBase_WidgetChoice.cpp ModuleBase_WidgetFileSelector.cpp ModuleBase_DoubleSpinBox.cpp + ModuleBase_WidgetLineEdit.cpp + ModuleBase_WidgetMultiSelector.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 9ce1c133f..c7f0c609c 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -156,6 +158,12 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType } else if (theType == WDG_CHOICE) { result = choiceControl(theParent); + } else if (theType == WDG_STRINGVALUE) { + result = lineEditControl(theParent); + + } else if (theType == WDG_MULTISELECTOR) { + result = multiSelectorControl(theParent); + } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { result = createContainer(theType, theParent); } else { @@ -279,6 +287,22 @@ QWidget* ModuleBase_WidgetFactory::choiceControl(QWidget* theParent) return aChoiceWgt->getControl(); } +QWidget* ModuleBase_WidgetFactory::lineEditControl(QWidget* theParent) +{ + ModuleBase_WidgetLineEdit* aLineEditWgt = + new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId); + myModelWidgets.append(aLineEditWgt); + return aLineEditWgt->getControl(); +} + +QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent) +{ + ModuleBase_WidgetMultiSelector* aMultiselectorWgt = + new ModuleBase_WidgetMultiSelector(theParent, myWidgetApi,myParentId); + myModelWidgets.append(aMultiselectorWgt); + return aMultiselectorWgt->getControl(); +} + QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const { return QString::fromStdString(theStdString); diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index 6ea4debf3..fd267d418 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -48,6 +48,9 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory QWidget* point2dDistanceControl(QWidget* theParent); QWidget* fileSelectorControl(QWidget* theParent); QWidget* choiceControl(QWidget* theParent); + QWidget* lineEditControl(QWidget* theParent); + QWidget* multiSelectorControl(QWidget* theParent); + QString qs(const std::string& theStdString) const; diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp new file mode 100644 index 000000000..bf311c59f --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp @@ -0,0 +1,93 @@ +/* + * ModuleBase_WidgetLineEdit.cpp + * + * Created on: Aug 28, 2014 + * Author: sbh + */ + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +ModuleBase_WidgetLineEdit::ModuleBase_WidgetLineEdit(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId) +{ + myMainWidget = new QWidget(theParent); + QHBoxLayout* aMainLay = new QHBoxLayout(myMainWidget); + ModuleBase_Tools::adjustMargins(aMainLay); + QString aTitle = QString::fromStdString(theData->widgetLabel()); + QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget); + aMainLay->addWidget(aTitleLabel); + myLineEdit = new QLineEdit(myMainWidget); + aMainLay->addWidget(myLineEdit); + myLineEdit->setMinimumHeight(20); + myMainWidget->setLayout(aMainLay); + + connect(myLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged())); +} + +ModuleBase_WidgetLineEdit::~ModuleBase_WidgetLineEdit() +{ +} + +bool ModuleBase_WidgetLineEdit::storeValue() const +{ + // A rare case when plugin was not loaded. + if(!myFeature) + return false; + DataPtr aData = myFeature->data(); + AttributeStringPtr aStringAttr = aData->string(attributeID()); + QString aWidgetValue = myLineEdit->text(); + aStringAttr->setValue(aWidgetValue.toStdString()); + updateObject(myFeature); + return true; +} + +bool ModuleBase_WidgetLineEdit::restoreValue() +{ + // A rare case when plugin was not loaded. + if(!myFeature) + return false; + DataPtr aData = myFeature->data(); + AttributeStringPtr aStringAttr = aData->string(attributeID()); + + bool isBlocked = myLineEdit->blockSignals(true); + myLineEdit->setText(QString::fromStdString(aStringAttr->value())); + myLineEdit->blockSignals(isBlocked); + + return true; +} + +QWidget* ModuleBase_WidgetLineEdit::getControl() const +{ + return myMainWidget; +} + +QList ModuleBase_WidgetLineEdit::getControls() const +{ + QList result; + result << myLineEdit; + return result; +} + +void ModuleBase_WidgetLineEdit::onTextChanged() +{ + storeValue(); +} diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.h b/src/ModuleBase/ModuleBase_WidgetLineEdit.h new file mode 100644 index 000000000..92eff3459 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetLineEdit.h @@ -0,0 +1,52 @@ +/* + * ModuleBase_WidgetLineEdit.h + * + * Created on: Oct 8, 2014 + * Author: sbh + */ + +#ifndef MODULEBASE_WIDGETLINEEDIT_H_ +#define MODULEBASE_WIDGETLINEEDIT_H_ + +#include +#include + +#include +#include +#include + +class QWidget; +class QLineEdit; + +class MODULEBASE_EXPORT ModuleBase_WidgetLineEdit : public ModuleBase_ModelWidget +{ + Q_OBJECT + public: + ModuleBase_WidgetLineEdit(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId); + virtual ~ModuleBase_WidgetLineEdit(); + + /// Saves the internal parameters to the given feature + /// \param theObject a model feature to be changed + virtual bool storeValue() const; + + virtual bool restoreValue(); + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const; + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + public slots: + void onTextChanged(); + + private: + QLineEdit* myLineEdit; + QWidget* myMainWidget; +}; + +#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp new file mode 100644 index 000000000..4ee9a4b25 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -0,0 +1,89 @@ +/* + * ModuleBase_WidgetMultiSelector.cpp + * + * Created on: Aug 28, 2014 + * Author: sbh + */ + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId) +{ + myMainWidget = new QWidget(theParent); + QVBoxLayout* aMainLay = new QVBoxLayout(myMainWidget); + ModuleBase_Tools::adjustMargins(aMainLay); + QString aTitle = QString::fromStdString(theData->widgetLabel()); + QLabel* aTitleLabel = new QLabel(aTitle, myMainWidget); + aMainLay->addWidget(aTitleLabel); + myListControl = new QTextEdit(myMainWidget); + myListControl->setReadOnly(true); + aMainLay->addWidget(myListControl); + myListControl->setMinimumHeight(20); + myMainWidget->setLayout(aMainLay); + + connect(myListControl, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged())); +} + +ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector() +{ +} + +bool ModuleBase_WidgetMultiSelector::storeValue() const +{ + // A rare case when plugin was not loaded. + if(!myFeature) + return false; + DataPtr aData = myFeature->data(); + AttributeStringPtr aStringAttr = aData->string(attributeID()); + QString aWidgetValue = myListControl->toPlainText(); + aStringAttr->setValue(aWidgetValue.toStdString()); + updateObject(myFeature); + return true; +} + +bool ModuleBase_WidgetMultiSelector::restoreValue() +{ + // A rare case when plugin was not loaded. + if(!myFeature) + return false; + DataPtr aData = myFeature->data(); + AttributeStringPtr aStringAttr = aData->string(attributeID()); + + bool isBlocked = myListControl->blockSignals(true); + myListControl->setText(QString::fromStdString(aStringAttr->value())); + myListControl->blockSignals(isBlocked); + + return true; +} + +QWidget* ModuleBase_WidgetMultiSelector::getControl() const +{ + return myMainWidget; +} + +QList ModuleBase_WidgetMultiSelector::getControls() const +{ + QList result; + result << myListControl; + return result; +} diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h new file mode 100644 index 000000000..d631f35ef --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -0,0 +1,51 @@ +/* + * ModuleBase_WidgetMultiSelector.h + * + * Created on: Oct 8, 2014 + * Author: sbh + */ + +#ifndef MODULEBASE_WIDGETMULTISELECTOR_H_ +#define MODULEBASE_WIDGETMULTISELECTOR_H_ + +#include +#include + +#include +#include +#include + +class QWidget; +class QTextEdit; + +class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget +{ + Q_OBJECT + public: + ModuleBase_WidgetMultiSelector(QWidget* theParent, + const Config_WidgetAPI* theData, + const std::string& theParentId); + virtual ~ModuleBase_WidgetMultiSelector(); + + /// Saves the internal parameters to the given feature + /// \param theObject a model feature to be changed + virtual bool storeValue() const; + + virtual bool restoreValue(); + + /// Returns the internal parent wiget control, that can be shown anywhere + /// \returns the widget + QWidget* getControl() const; + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + //public slots: + + private: + QTextEdit* myListControl; + QWidget* myMainWidget; +}; + +#endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 3fb534b36..c800f9a7d 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -49,8 +49,9 @@ TopAbs_ShapeEnum ModuleBase_WidgetShapeSelector::shapeType(const QString& theTyp MyShapeTypes["shell"] = TopAbs_SHELL; MyShapeTypes["solid"] = TopAbs_SOLID; } - if (MyShapeTypes.contains(theType)) - return MyShapeTypes[theType]; + QString aType = theType.toLower(); + if (MyShapeTypes.contains(aType)) + return MyShapeTypes[aType]; throw std::invalid_argument("Shape type defined in XML is not implemented!"); } diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index c1decfa56..744612270 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -26,6 +26,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_Model { Q_OBJECT public: + static TopAbs_ShapeEnum shapeType(const QString& theType); + ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId); @@ -79,8 +81,6 @@ private: // Set the given object as a value of the widget void setObject(ObjectPtr theObj); - static TopAbs_ShapeEnum shapeType(const QString& theType); - QWidget* myContainer; QLabel* myLabel; QLineEdit* myTextLine; -- 2.39.2