From 3beaa81304f886ba80f2bf9b59886ecdf48bfdf9 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 28 Jun 2018 13:13:23 +0300 Subject: [PATCH] Implementation of point 2.3.1 of CEA specification --- src/Config/Config_Keywords.h | 1 + src/ConstructionAPI/ConstructionAPI_Point.cpp | 11 +- src/ConstructionAPI/ConstructionAPI_Point.h | 6 +- src/ConstructionPlugin/CMakeLists.txt | 2 + .../ConstructionPlugin_Point.cpp | 12 +- .../ConstructionPlugin_Point.h | 21 +-- src/ConstructionPlugin/point_widget.xml | 16 +- .../InitializationPlugin_Plugin.cpp | 9 +- src/ModuleBase/CMakeLists.txt | 3 + src/ModuleBase/ModuleBase_ParamSpinBox.cpp | 1 + src/ModuleBase/ModuleBase_WidgetFactory.cpp | 3 + .../ModuleBase_WidgetPointInput.cpp | 160 ++++++++++++++++++ src/ModuleBase/ModuleBase_WidgetPointInput.h | 78 +++++++++ src/XGUI/pictures/z_size.png | Bin 508 -> 462 bytes 14 files changed, 272 insertions(+), 51 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_WidgetPointInput.cpp create mode 100644 src/ModuleBase/ModuleBase_WidgetPointInput.h diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index db4221167..938749424 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -52,6 +52,7 @@ const static char* WDG_FILE_SELECTOR= "file_selector"; const static char* WDG_EXPR_EDITOR = "expr_editor"; const static char* WDG_PLACE_HOLDER = "placeholder"; const static char* WDG_ACTION = "action"; +const static char* WDG_POINT_INPUT = "point_input"; // Containers const static char* WDG_GROUP = "groupbox"; diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index 8f8a45342..7d536c9fd 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -132,9 +132,12 @@ void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX, const ModelHighAPI_Double& theZ) { //fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod); - fillAttribute(theX, myx); - fillAttribute(theY, myy); - fillAttribute(theZ, myz); + + // TODO: Fill point attribute + //fillAttribute(theX, myx); + //fillAttribute(theY, myy); + //fillAttribute(theZ, myz); + fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod); execute(false); @@ -262,7 +265,7 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const if (aMeth == "" || // default is XYZ aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) { - theDumper << x() << ", " << y() << ", " << z(); + theDumper << point() << ")" << std::endl; } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) { const std::string anIntersectionType = intersectionType()->value(); if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES()) diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h index 03eea708e..e02de26f0 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.h +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -80,10 +80,8 @@ public: CONSTRUCTIONAPI_EXPORT virtual ~ConstructionAPI_Point(); - INTERFACE_27(ConstructionPlugin_Point::ID(), - x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */, - y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */, - z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */, + INTERFACE_25(ConstructionPlugin_Point::ID(), + point, ConstructionPlugin_Point::point3d(), GeomDataAPI_Point, /** Point attribute */, creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, intersectionType, ConstructionPlugin_Point::INTERSECTION_TYPE(), diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index 7985e9337..a9705702f 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -54,6 +54,7 @@ SET(PROJECT_LIBRARIES ModelAPI GeomAPI GeomAlgoAPI + GeomDataAPI ) SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES}) @@ -72,6 +73,7 @@ INCLUDE_DIRECTORIES( ../GeomAPI ../GeomAlgoAPI ../Events + ../GeomDataAPI ) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 43b222fb4..03c12caff 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include #include @@ -50,9 +52,7 @@ const std::string& ConstructionPlugin_Point::getKind() //================================================================================================== void ConstructionPlugin_Point::initAttributes() { - data()->addAttribute(X(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(Y(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(Z(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(point3d(), GeomDataAPI_Point::typeId()); data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); @@ -161,9 +161,9 @@ bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult, //================================================================================================== std::shared_ptr ConstructionPlugin_Point::createByXYZ() { - return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(), - real(Y())->value(), - real(Z())->value()); + AttributePointPtr aPoint = + std::dynamic_pointer_cast(data()->attribute(point3d())); + return GeomAlgoAPI_PointBuilder::vertex(aPoint->x(), aPoint->y(), aPoint->z()); } //================================================================================================== diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index be2892ac7..e04696cbc 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -89,25 +89,10 @@ public: return MY_CREATION_METHOD_ID; } - /// Attribute name for X coordinate. - inline static const std::string& X() + inline static const std::string& point3d() { - static const std::string POINT_ATTR_X("x"); - return POINT_ATTR_X; - } - - /// Attribute name for Y coordinate. - inline static const std::string& Y() - { - static const std::string POINT_ATTR_Y("y"); - return POINT_ATTR_Y; - } - - /// Attribute name for Z coordinate. - inline static const std::string& Z() - { - static const std::string POINT_ATTR_Z("z"); - return POINT_ATTR_Z; + static const std::string POINT_ATTR("point3d"); + return POINT_ATTR; } /// Attribute name for selected edge. diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml index 498f49bc9..d82ab6c45 100644 --- a/src/ConstructionPlugin/point_widget.xml +++ b/src/ConstructionPlugin/point_widget.xml @@ -25,21 +25,7 @@ email : webmaster.salome@opencascade.com - - - + #include +#include + #include #include @@ -137,10 +139,9 @@ FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const st double theX, double theY, double theZ) { std::shared_ptr aPoint = theDoc->addFeature("Point"); - //aPoint->string("creation_method")->setValue("by_xyz"); - aPoint->real("x")->setValue(theX); - aPoint->real("y")->setValue(theY); - aPoint->real("z")->setValue(theZ); + AttributePointPtr aPointAttr = std::dynamic_pointer_cast + (aPoint->data()->attribute("point3d")); + aPointAttr->setValue(theX, theY, theZ); aPoint->string("creation_method")->setValue("by_xyz"); aPoint->data()->setName(theName); // don't show automatically created feature in the features history diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 357f85b54..4b1a7117d 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -102,6 +102,7 @@ SET(PROJECT_HEADERS ModuleBase_ChoiceCtrl.h ModuleBase_WidgetNameEdit.h ModuleBase_WidgetRadiobox.h + ModuleBase_WidgetPointInput.h ) SET(PROJECT_MOC_HEADERS @@ -150,6 +151,7 @@ SET(PROJECT_MOC_HEADERS ModuleBase_ChoiceCtrl.h ModuleBase_WidgetNameEdit.h ModuleBase_WidgetRadiobox.h + ModuleBase_WidgetPointInput.h ) SET(PROJECT_SOURCES @@ -217,6 +219,7 @@ SET(PROJECT_SOURCES ModuleBase_ChoiceCtrl.cpp ModuleBase_WidgetNameEdit.cpp ModuleBase_WidgetRadiobox.cpp + ModuleBase_WidgetPointInput.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index 08d373d5d..fd3fec22a 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -151,6 +151,7 @@ void ModuleBase_ParamSpinBox::setValue(double value) double ModuleBase_ParamSpinBox::value() const { + std::string aa = lineEdit()->text().toStdString(); return lineEdit()->text().toDouble(); } diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index afc886b8f..80f8419d1 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -341,6 +342,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std:: result = NULL; } else if (theType == WDG_ACTION) { result = new ModuleBase_WidgetAction(theParent, myWidgetApi); + } else if (theType == WDG_POINT_INPUT) { + result = new ModuleBase_WidgetPointInput(theParent, myWorkshop, myWidgetApi); } else { result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi); if (!result) diff --git a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp new file mode 100644 index 000000000..1c41a1ab5 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp @@ -0,0 +1,160 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#include "ModuleBase_WidgetPointInput.h" +#include "ModuleBase_Tools.h" +#include "ModuleBase_ParamSpinBox.h" +#include "ModuleBase_ViewerPrs.h" + +#include +#include + +#include + +#include +#include + +#include +#include + +ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData) + : ModuleBase_WidgetSelector(theParent, theWorkshop, theData) +{ + bool aAcceptVariables = theData->getBooleanAttribute(DOUBLE_WDG_ACCEPT_EXPRESSIONS, true); + + QFormLayout* aMainlayout = new QFormLayout(this); + ModuleBase_Tools::adjustMargins(aMainlayout); + + myXSpin = new ModuleBase_ParamSpinBox(this); + myXSpin->setAcceptVariables(aAcceptVariables); + myXSpin->setToolTip("X coordinate"); + myXSpin->setValue(0); + QLabel* aXLbl = new QLabel(this); + aXLbl->setPixmap(QPixmap(":pictures/x_size.png")); + aMainlayout->addRow(aXLbl, myXSpin); + + myYSpin = new ModuleBase_ParamSpinBox(this); + myYSpin->setAcceptVariables(aAcceptVariables); + myYSpin->setToolTip("Y coordinate"); + myYSpin->setValue(0); + QLabel* aYLbl = new QLabel(this); + aYLbl->setPixmap(QPixmap(":pictures/y_size.png")); + aMainlayout->addRow(aYLbl, myYSpin); + + myZSpin = new ModuleBase_ParamSpinBox(this); + myZSpin->setAcceptVariables(aAcceptVariables); + myZSpin->setToolTip("Z coordinate"); + myZSpin->setValue(0); + QLabel* aZLbl = new QLabel(this); + aZLbl->setPixmap(QPixmap(":pictures/z_size.png")); + aMainlayout->addRow(aZLbl, myZSpin); +} + +ModuleBase_WidgetPointInput::~ModuleBase_WidgetPointInput() +{ + +} + + +//******************************************************************** +QList ModuleBase_WidgetPointInput::getControls() const +{ + QList aList; + aList.append(myXSpin); + aList.append(myYSpin); + aList.append(myZSpin); + return aList; +} + +//******************************************************************** +bool ModuleBase_WidgetPointInput::storeValueCustom() +{ + AttributePointPtr aAttr = std::dynamic_pointer_cast(attribute()); + if (aAttr.get()) { + if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) { + aAttr->setText(myXSpin->text().toStdString(), + myYSpin->text().toStdString(), myZSpin->text().toStdString()); + } else { + aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value()); + } + return true; + } + return false; +} + +//******************************************************************** +bool ModuleBase_WidgetPointInput::restoreValueCustom() +{ + AttributePointPtr aAttr = std::dynamic_pointer_cast(attribute()); + if (aAttr.get()) { + std::string aXText = aAttr->textX(); + if (aXText.empty()) { + myXSpin->setValue(aAttr->x()); + } else { + myXSpin->setText(aXText.c_str()); + } + std::string aYText = aAttr->textY(); + if (aYText.empty()) { + myYSpin->setValue(aAttr->y()); + } else { + myYSpin->setText(aYText.c_str()); + } + std::string aZText = aAttr->textZ(); + if (aZText.empty()) { + myZSpin->setValue(aAttr->z()); + } else { + myZSpin->setText(aZText.c_str()); + } + return true; + } + return false; +} + +//******************************************************************** +void ModuleBase_WidgetPointInput::selectionModes(int& theModuleSelectionModes, QIntList& theModes) +{ + theModuleSelectionModes = -1; + theModes << TopAbs_VERTEX; +} + +//******************************************************************** +QIntList ModuleBase_WidgetPointInput::shapeTypes() const +{ + QIntList aList; + aList << TopAbs_VERTEX; + return aList; +} + +//******************************************************************** +bool ModuleBase_WidgetPointInput +::setSelectionCustom(const std::shared_ptr& thePrs) +{ + GeomShapePtr aShape = thePrs->shape(); + if (aShape->isVertex()) { + GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape)); + GeomPointPtr aPnt = aVertex->point(); + myXSpin->setValue(aPnt->x()); + myYSpin->setValue(aPnt->y()); + myZSpin->setValue(aPnt->z()); + return true; + } + return false; +} diff --git a/src/ModuleBase/ModuleBase_WidgetPointInput.h b/src/ModuleBase/ModuleBase_WidgetPointInput.h new file mode 100644 index 000000000..e9cd0f3e1 --- /dev/null +++ b/src/ModuleBase/ModuleBase_WidgetPointInput.h @@ -0,0 +1,78 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#ifndef ModuleBase_WidgetPointInput_H +#define ModuleBase_WidgetPointInput_H + +#include "ModuleBase.h" +#include "ModuleBase_WidgetSelector.h" + +class ModuleBase_ParamSpinBox; + +class MODULEBASE_EXPORT ModuleBase_WidgetPointInput : public ModuleBase_WidgetSelector +{ + Q_OBJECT +public: + /// Constructor + /// \param theParent the parent object + /// \param theWorkshop a current workshop + /// \param theData the widget configuation. The attribute of the model widget is obtained from + ModuleBase_WidgetPointInput(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData); + + /// Destructor + virtual ~ModuleBase_WidgetPointInput(); + + /// Returns list of widget controls + /// \return a control list + virtual QList getControls() const; + + /// Saves the internal parameters to the given feature + /// \return True in success + virtual bool storeValueCustom(); + + /// Restore value from attribute data to the widget's control + virtual bool restoreValueCustom(); + + /// Defines if it is supposed that the widget should interact with the viewer. + virtual bool isViewerSelector() { return true; } + + /// Fills given container with selection modes if the widget has it + /// \param [out] theModuleSelectionModes module additional modes, -1 means all default modes + /// \param [out] theModes a container of modes + virtual void selectionModes(int& theModuleSelectionModes, QIntList& theModes); + + /// Fills the attribute with the value of the selected owner + /// \param thePrs a selected owner + virtual bool setSelectionCustom(const std::shared_ptr& thePrs); + +protected: + /// Retunrs a list of possible shape types + /// \return a list of shapes + virtual QIntList shapeTypes() const; + +protected: + ModuleBase_ParamSpinBox* myXSpin; + ModuleBase_ParamSpinBox* myYSpin; + ModuleBase_ParamSpinBox* myZSpin; +}; + + +#endif \ No newline at end of file diff --git a/src/XGUI/pictures/z_size.png b/src/XGUI/pictures/z_size.png index 69d673502c71530f1a8a63c2eb4b7871a8e297a2..c1f108aaac19e04e93a20db8c34a1f4a490ed033 100644 GIT binary patch delta 436 zcmV;l0Zab;1I`1GB!2;OQb$4nuFf3k00004XF*Lt006O%3;baP00009a7bBm000fv z000fv0g!KboB#j-7<5HgbW?9;ba!ELWdLwtX>N2bZe?^JG%heMIczh2P5=M_KS@ME zR5(v#5OeX56LSeT2gF~1__nxfK->TS{~3tI4B{>U1wf52fq(cv$PgfZG6MqxBR0j@ zFqjZ^4)lN;umdhZEWl@gxSJcdh@+pnsB5sQsJowvm{WkVxSOw{q*IVQLue>7SP@PG zfC_+onAb3{s7t^pf(8J?VeI{)cF zAx5wSF$Rdb`G45~>!f8NgC>xOf2P%#QgTn!j0mjCxV$K2gfeJqYqwJBGYrtbM zm%t}LHP3+fDNs)yUIU25V1gn8fSPiE_z@6;63BZXo-GK(OxP4-!yp4dxe@4BumR73 em;?j00005lf7ycQ51#0 zb!G;^ALI%dh^EdP^5*SE4++6A1W<&*{Q@|PE7%+}GAxWbG zWSg?OFfI8B&>yb$rbi6}g#T&&lk!wiv$NUQm)%!_je2eAqHP0cVIh<+-`ugoyCh)z zQ!~*7rhuuk>VMvqbj`NQ_19x4%uD`|93kerZQY>xvYNRkNiok`UrB)XvbH_|wt=f< z)x95oe9sQ@F*$;ZC^Z3KJ4$oGehj*j=SPn3=k4?@#G-u<{%c8w0{8|z0B#Ofd+}dz*#8ST(4Mk0O6ahD Y0d