Salome HOME
Implementation of point 2.3.1 of CEA specification
authorvsv <vsv@opencascade.com>
Thu, 28 Jun 2018 10:13:23 +0000 (13:13 +0300)
committervsv <vsv@opencascade.com>
Mon, 2 Jul 2018 07:22:04 +0000 (10:22 +0300)
14 files changed:
src/Config/Config_Keywords.h
src/ConstructionAPI/ConstructionAPI_Point.cpp
src/ConstructionAPI/ConstructionAPI_Point.h
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.h
src/ConstructionPlugin/point_widget.xml
src/InitializationPlugin/InitializationPlugin_Plugin.cpp
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ParamSpinBox.cpp
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetPointInput.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetPointInput.h [new file with mode: 0644]
src/XGUI/pictures/z_size.png

index db42211672c32216c5968324ce97333d1866b55d..938749424e99eefd2cbf64e33f4c34bf5e9240f2 100644 (file)
@@ -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";
index 8f8a45342add6858992f4cf20ad8d0b20f0ca786..7d536c9fd01ae0d093a4ed35dbabb837c6e41afe 100644 (file)
@@ -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())
index 03eea708e17cbb689dbc6da8e711597e2012f391..e02de26f076b32076e3e2152f466746507886369 100644 (file)
@@ -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(),
index 7985e93372279036207c59ab89326de221aead64..a9705702fbfe2c6eea3ec2c75730ae996a306e57 100644 (file)
@@ -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
 )
 
 
index 43b222fb4952eb2dd0b6ee8d37df31a5a1274845..03c12caff77e0acd965610dd9381c15543e3dd2c 100644 (file)
@@ -30,6 +30,8 @@
 #include <GeomAlgoAPI_ShapeTools.h>
 
 #include <GeomAPI_Circ.h>
+#include <GeomDataAPI_Point.h>
+
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Vertex.h>
@@ -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<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
 {
-  return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
-                                          real(Y())->value(),
-                                          real(Z())->value());
+  AttributePointPtr aPoint =
+    std::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(point3d()));
+  return GeomAlgoAPI_PointBuilder::vertex(aPoint->x(), aPoint->y(), aPoint->z());
 }
 
 //==================================================================================================
index be2892ac7e547c3b95fd8731b008720c2fe16db5..e04696cbcde36535f002c1f9ea813852e0639606 100644 (file)
@@ -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.
index 498f49bc99c23ea60e709055685b3c791dc97c0c..d82ab6c45f78eeff6da38dbac4aa1ec1aa661fee 100644 (file)
@@ -25,21 +25,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
          title="By X, Y, Z"
          tooltip="Point at a given distance from the origin."
          icon="icons/Construction/point_by_xyz_32x32.png">
-      <doublevalue id="x"
-                   label="X "
-                   tooltip="X coordinate."
-                   icon="icons/Construction/x_size.png"
-                   default="0"/>
-      <doublevalue id="y"
-                   label="Y "
-                   tooltip="Y coordinate."
-                   icon="icons/Construction/y_size.png"
-                   default="0"/>
-      <doublevalue id="z"
-                   label="Z "
-                   tooltip="Z coordinate."
-                   icon="icons/Construction/z_size.png"
-                   default="0"/>
+      <point_input id="point3d"/>
     </box>
     <box id="by_distance_on_edge"
          title="By distance on edge"
index 5d4781494052ee0537e05832c291c8482f9b5397..c71d8f767d143d3cb01995937782b7718d769093 100644 (file)
@@ -30,6 +30,8 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Result.h>
 
+#include <GeomDataAPI_Point.h>
+
 #include <Events_Message.h>
 #include <Events_InfoMessage.h>
 
@@ -137,10 +139,9 @@ FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const st
                                                     double theX, double theY, double theZ)
 {
   std::shared_ptr<ModelAPI_Feature> 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<GeomDataAPI_Point>
+    (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
index 357f85b549f752b16fbb057dd4ceaeb847fa4a0e..4b1a7117d991496f04d0b66124ac8de356802aea 100644 (file)
@@ -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
index 08d373d5d39d8522300b2c708d1c5d579367ca33..fd3fec22a60d17f5b675dc0fda345bb571b86eab 100644 (file)
@@ -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();
 }
 
index afc886b8faffd595c04e6d89ab3fe9362e19ea06..80f8419d165714565bf6966bd8d4d97a06394f3d 100644 (file)
@@ -50,6 +50,7 @@
 #include <ModuleBase_WidgetExprEditor.h>
 #include <ModuleBase_WidgetCreatorFactory.h>
 #include <ModuleBase_WidgetAction.h>
+#include <ModuleBase_WidgetPointInput.h>
 
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
@@ -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 (file)
index 0000000..1c41a1a
--- /dev/null
@@ -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<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "ModuleBase_WidgetPointInput.h"
+#include "ModuleBase_Tools.h"
+#include "ModuleBase_ParamSpinBox.h"
+#include "ModuleBase_ViewerPrs.h"
+
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Pnt.h>
+
+#include <GeomDataAPI_Point.h>
+
+#include <Config_WidgetAPI.h>
+#include <Config_Keywords.h>
+
+#include <QFormLayout>
+#include <QLabel>
+
+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<QWidget*> ModuleBase_WidgetPointInput::getControls() const
+{
+  QList<QWidget*> aList;
+  aList.append(myXSpin);
+  aList.append(myYSpin);
+  aList.append(myZSpin);
+  return aList;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetPointInput::storeValueCustom()
+{
+  AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(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<GeomDataAPI_Point>(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<ModuleBase_ViewerPrs>& 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 (file)
index 0000000..e9cd0f3
--- /dev/null
@@ -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<mailto: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<QWidget*> 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<ModuleBase_ViewerPrs>& 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
index 69d673502c71530f1a8a63c2eb4b7871a8e297a2..c1f108aaac19e04e93a20db8c34a1f4a490ed033 100644 (file)
Binary files a/src/XGUI/pictures/z_size.png and b/src/XGUI/pictures/z_size.png differ