From: vsv Date: Mon, 2 Jun 2014 07:53:52 +0000 (+0400) Subject: Prepare extrusion feature X-Git-Tag: V_0.4.4~337 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fb0d3e35664d7c763e83a17e42abdbf235eb3fda;p=modules%2Fshaper.git Prepare extrusion feature --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 2056a658b..125faa57a 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -18,6 +18,7 @@ const static char* NODE_SOURCE = "source"; //Widgets const static char* WDG_DOUBLEVALUE = "doublevalue"; +const static char* WDG_BOOLVALUE = "boolvalue"; //Widget containers const static char* WDG_INFO = "label"; const static char* WDG_GROUP = "groupbox"; @@ -26,6 +27,7 @@ const static char* WDG_TOOLBOX = "toolbox"; const static char* WDG_TOOLBOX_BOX = "box"; const static char* WDG_SWITCH = "switch"; const static char* WDG_SWITCH_CASE = "case"; +const static char* WDG_SELECTOR = "selector"; //Specific widget containers const static char* WDG_POINT_SELECTOR = "point_selector"; diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index 7fe6d649c..ab3491914 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -4,11 +4,13 @@ SET(PROJECT_HEADERS ConstructionPlugin.h ConstructionPlugin_Plugin.h ConstructionPlugin_Point.h + ConstructionPlugin_Extrusion.h ) SET(PROJECT_SOURCES ConstructionPlugin_Plugin.cpp ConstructionPlugin_Point.cpp + ConstructionPlugin_Extrusion.cpp ) ADD_DEFINITIONS(-DCONSTRUCTIONPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) @@ -22,6 +24,7 @@ INCLUDE_DIRECTORIES( SET(XML_RESOURCES plugin-Construction.xml point_widget.xml + extrusion_widget.xml ) INSTALL(TARGETS ConstructionPlugin DESTINATION plugins) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Extrusion.cpp b/src/ConstructionPlugin/ConstructionPlugin_Extrusion.cpp new file mode 100644 index 000000000..8b5dc2d60 --- /dev/null +++ b/src/ConstructionPlugin/ConstructionPlugin_Extrusion.cpp @@ -0,0 +1,33 @@ +// File: ConstructionPlugin_Extrusion.cpp +// Created: 30 May 2014 +// Author: Vitaly SMETANNIKOV + +#include "ConstructionPlugin_Extrusion.h" +#include +#include +#include +#include +#include +#include + +using namespace std; + +ConstructionPlugin_Extrusion::ConstructionPlugin_Extrusion() +{ +} + +void ConstructionPlugin_Extrusion::initAttributes() +{ + data()->addAttribute(EXTRUSION_FACE, ModelAPI_AttributeReference::type()); + data()->addAttribute(EXTRUSION_SIZE, ModelAPI_AttributeDouble::type()); + data()->addAttribute(EXTRUSION_REVERCE, ModelAPI_AttributeBoolean::type()); +} + +// this is for debug only +#include +void ConstructionPlugin_Extrusion::execute() +{ + // TODO: create a real shape for the point using OCC layer + //cout<<"X="<real(POINT_ATTR_X)->value()<<" Y="<real(POINT_ATTR_Y)->value() + // <<" Z="<real(POINT_ATTR_Z)->value()< + +/// attribute name of referenced face +const std::string EXTRUSION_FACE = "extrusion_select_face"; + +/// attribute name of extrusion size +const std::string EXTRUSION_SIZE = "extrusion_size"; + +/// attribute name of reverce direction +const std::string EXTRUSION_REVERCE = "extrusion_reverse"; + + +class ConstructionPlugin_Extrusion: public ModelAPI_Feature +{ +public: + /// Returns the kind of a feature + CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind() + { static std::string MY_KIND = "Extrusion"; return MY_KIND; } + + /// Returns to which group in the document must be added feature + CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup() + { static std::string MY_GROUP = "Construction"; return MY_GROUP; } + + /// Creates a new part document if needed + CONSTRUCTIONPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + CONSTRUCTIONPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation + ConstructionPlugin_Extrusion(); +}; + +#endif diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 5c1f39f2f..a825c5608 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -1,5 +1,7 @@ #include "ConstructionPlugin_Plugin.h" #include "ConstructionPlugin_Point.h" +#include "ConstructionPlugin_Extrusion.h" + #include #include @@ -18,6 +20,8 @@ boost::shared_ptr ConstructionPlugin_Plugin::createFeature(str { if (theFeatureID == "Point") { return boost::shared_ptr(new ConstructionPlugin_Point); + } else if (theFeatureID == "Extrusion") { + return boost::shared_ptr(new ConstructionPlugin_Extrusion); } // feature of such kind is not found return boost::shared_ptr(); diff --git a/src/ConstructionPlugin/extrusion_widget.xml b/src/ConstructionPlugin/extrusion_widget.xml new file mode 100644 index 000000000..52cf8622f --- /dev/null +++ b/src/ConstructionPlugin/extrusion_widget.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/src/ConstructionPlugin/plugin-Construction.xml b/src/ConstructionPlugin/plugin-Construction.xml index 8e8699687..4736d36cf 100644 --- a/src/ConstructionPlugin/plugin-Construction.xml +++ b/src/ConstructionPlugin/plugin-Construction.xml @@ -6,6 +6,9 @@ + + + - + diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 5db73c347..9da38b914 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -13,6 +13,7 @@ SET(PROJECT_HEADERS Model_AttributeReference.h Model_AttributeRefAttr.h Model_AttributeRefList.h + Model_AttributeBoolean.h Model_Events.h ) @@ -27,6 +28,7 @@ SET(PROJECT_SOURCES Model_AttributeReference.cpp Model_AttributeRefAttr.cpp Model_AttributeRefList.cpp + Model_AttributeBoolean.cpp Model_Events.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/Model/Model_AttributeBoolean.cpp b/src/Model/Model_AttributeBoolean.cpp new file mode 100644 index 000000000..d3c0d6bc5 --- /dev/null +++ b/src/Model/Model_AttributeBoolean.cpp @@ -0,0 +1,33 @@ +// File: Model_AttributeBoolean.cpp +// Created: 2 june 2014 +// Author: Vitaly Smetannikov + +#include "Model_AttributeBoolean.h" +#include "Model_Events.h" +#include + +using namespace std; + +void Model_AttributeBoolean::setValue(bool theValue) +{ + if (myBool->Get() != theValue) { + myBool->Set(theValue? 1 : 0); + static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED); + Model_FeatureUpdatedMessage aMsg(owner(), anEvent); + Events_Loop::loop()->send(aMsg); + } +} + +bool Model_AttributeBoolean::value() +{ + return (myBool->Get() == 1)? true : false; +} + +Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel) +{ + // check the attribute could be already presented in this doc (after load document) + if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myBool)) { + // create attribute: not initialized by value yet, just zero + myBool = TDataStd_Integer::Set(theLabel, 0); + } +} diff --git a/src/Model/Model_AttributeBoolean.h b/src/Model/Model_AttributeBoolean.h new file mode 100644 index 000000000..331fa139c --- /dev/null +++ b/src/Model/Model_AttributeBoolean.h @@ -0,0 +1,35 @@ +// File: Model_AttributeBoolean.h +// Created: 2 june 2014 +// Author: Vitaly Smetannikov + +#ifndef Model_AttributeBoolean_HeaderFile +#define Model_AttributeBoolean_HeaderFile + +#include "Model.h" +#include "ModelAPI_AttributeBoolean.h" +#include +#include + +/**\class Model_AttributeDouble + * \ingroup DataModel + * \brief Attribute that contains real value with double precision. + */ + +class Model_AttributeBoolean : public ModelAPI_AttributeBoolean +{ + Handle_TDataStd_Integer myBool; ///< double is Real attribute +public: + /// Defines the double value + MODEL_EXPORT virtual void setValue(bool theValue); + + /// Returns the double value + MODEL_EXPORT virtual bool value(); + +protected: + /// Initializes attibutes + Model_AttributeBoolean(TDF_Label& theLabel); + + friend class Model_Data; +}; + +#endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 49757f69f..981d5567d 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -16,6 +16,7 @@ SET(PROJECT_HEADERS ModelAPI_AttributeReference.h ModelAPI_AttributeRefAttr.h ModelAPI_AttributeRefList.h + ModelAPI_AttributeBoolean.h ) SET(PROJECT_SOURCES diff --git a/src/ModelAPI/ModelAPI_AttributeBoolean.h b/src/ModelAPI/ModelAPI_AttributeBoolean.h new file mode 100644 index 000000000..038b93f6c --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeBoolean.h @@ -0,0 +1,38 @@ +// File: ModelAPI_AttributeBoolean.h +// Created: 2 june 2014 +// Author: Vitaly Smetannikov + +#ifndef ModelAPI_AttributeBoolean_HeaderFile +#define ModelAPI_AttributeBoolean_HeaderFile + +#include "ModelAPI_Attribute.h" + +/**\class ModelAPI_AttributeBoolean + * \ingroup DataModel + * \brief Attribute that contains boolean value. + */ + +class ModelAPI_AttributeBoolean : public ModelAPI_Attribute +{ +public: + /// Defines the double value + MODELAPI_EXPORT virtual void setValue(bool theValue) = 0; + + /// Returns the double value + MODELAPI_EXPORT virtual bool value() = 0; + + /// Returns the type of this class of attributes + MODELAPI_EXPORT static std::string type() {return "Boolean";} + + /// Returns the type of this class of attributes, not static method + MODELAPI_EXPORT virtual std::string attributeType() {return type();} + + /// To virtually destroy the fields of successors + MODELAPI_EXPORT virtual ~ModelAPI_AttributeBoolean() {} + +protected: + /// Objects are created for features automatically + MODELAPI_EXPORT ModelAPI_AttributeBoolean() {} +}; + +#endif diff --git a/src/ModelAPI/ModelAPI_PluginManager.cpp b/src/ModelAPI/ModelAPI_PluginManager.cpp index eb79b9d03..4cf100d5c 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.cpp +++ b/src/ModelAPI/ModelAPI_PluginManager.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index e5212c7e8..1ef8c83d8 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include #ifdef _DEBUG #include @@ -104,13 +107,20 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType QWidget* result = NULL; if (theType == WDG_DOUBLEVALUE) { result = doubleSpinBoxControl(); + } else if (theType == WDG_INFO) { result = labelControl(theParent); - } - else if (theType == WDG_POINT_SELECTOR) { + + } else if (theType == WDG_SELECTOR) { + result = selectorControl(theParent); + + } else if (theType == WDG_BOOLVALUE) { + result = booleanControl(theParent); + + } else if (theType == WDG_POINT_SELECTOR) { result = pointSelectorControl(theParent); - } - else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { + + } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) { result = createContainer(theType, theParent); } #ifdef _DEBUG @@ -215,3 +225,44 @@ QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const { return QString::fromStdString(theStdString); } + + +QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent) +{ + QWidget* aRes = new QWidget(); + QHBoxLayout* aLayout = new QHBoxLayout(aRes); + + aLayout->setContentsMargins(0, 0, 0, 0); + QString aLabelText = qs(myWidgetApi->widgetLabel()); + QString aLabelIcon = qs(myWidgetApi->widgetIcon()); + QLabel* aLabel = new QLabel(aLabelText, aRes); + aLabel->setPixmap(QPixmap(aLabelIcon)); + + aLayout->addWidget(aLabel); + + QLineEdit* aTextLine = new QLineEdit(aRes); + aTextLine->setReadOnly(true); + + aLayout->addWidget(aTextLine); + + QToolButton* aActivateBtn = new QToolButton(aRes); + aActivateBtn->setIcon(QIcon(":icons/hand_point.png")); + aActivateBtn->setCheckable(true); + + aLayout->addWidget(aActivateBtn); + + return aRes; +} + + +QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent) +{ + QString aText = qs(myWidgetApi->widgetLabel()); + QString aToolTip = qs(myWidgetApi->widgetTooltip()); + QString aDefault = qs(myWidgetApi->getProperty("default")); + + QCheckBox* aRes = new QCheckBox(aText, theParent); + aRes->setToolTip(aToolTip); + aRes->setChecked(aDefault == "true"); + return aRes; +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index bf765824f..f0303cdae 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -39,6 +39,8 @@ protected: QWidget* doubleSpinBoxControl(); QWidget* pointSelectorControl(QWidget* theParent); QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL); + QWidget* selectorControl(QWidget* theParent); + QWidget* booleanControl(QWidget* theParent); bool connectWidget(QObject*, const QString&); QString qs(const std::string& theStdString) const; diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index f3300ede5..89a8e5735 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -13,5 +13,7 @@ icons/import.png icons/line.png icons/sketch.png + icons/hand_point.png + icons/dimension_v.png diff --git a/src/PartSet/icons/dimension_v.png b/src/PartSet/icons/dimension_v.png new file mode 100644 index 000000000..6213de3e4 Binary files /dev/null and b/src/PartSet/icons/dimension_v.png differ diff --git a/src/PartSet/icons/hand_point.png b/src/PartSet/icons/hand_point.png new file mode 100644 index 000000000..31c4813b0 Binary files /dev/null and b/src/PartSet/icons/hand_point.png differ