]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Point2d Distance widget added
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 24 Jun 2014 07:53:09 +0000 (11:53 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 24 Jun 2014 07:53:09 +0000 (11:53 +0400)
src/Config/Config_Keywords.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetDoubleValue.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml

index 125faa57a0879e241a273c5f94d7c27a79adee24..050a947fe275ad2068099dbfc55803f3169515c4 100644 (file)
@@ -31,6 +31,7 @@ const static char* WDG_SELECTOR = "selector";
 
 //Specific widget containers
 const static char* WDG_POINT_SELECTOR = "point_selector";
+const static char* WDG_POINT2D_DISTANCE = "point2ddistance";
 
 const static char* _ID = "id";
 //const static char* WORKBENCH_ID = "id";
index b56c217912ed10bb62d52ebd8cbf69d9b73832f6..e70f413c146a47f19979a19963e69096bac3683a 100644 (file)
@@ -14,6 +14,7 @@ SET(PROJECT_HEADERS
        ModuleBase_WidgetSwitch.h
        ModuleBase_WidgetSelector.h
        ModuleBase_IWorkshop.h
+       ModuleBase_WidgetPoint2dDistance.h
 )
 
 SET(PROJECT_SOURCES
@@ -27,11 +28,13 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetPoint2D.cpp
        ModuleBase_WidgetSwitch.cpp
        ModuleBase_WidgetSelector.cpp
+       ModuleBase_WidgetPoint2dDistance.cpp
 )
 
 SET(PROJECT_LIBRARIES
     Config
     ModelAPI
+       GeomAPI
     ${QT_LIBRARIES}
        ${CAS_VIEWER}
        ${CAS_KERNEL}
index 70f6de58ce510344ae127d927bd18313b9a0c578..2a5b6c2a1c28b63db3ccc283774c8a347f3b6f7f 100644 (file)
@@ -43,7 +43,7 @@ public:
   /// \param theEvent the processed event
   virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
 
-private:
+protected:
   QWidget*     myContainer;
   QLabel*      myLabel;
   QDoubleSpinBox* mySpinBox;
index e83cd01fc642a6c637fe7d3c2609e613a138ebfe..89b82bef47bef6dc332a5c99967d79680a301d7e 100644 (file)
@@ -14,6 +14,7 @@
 #include <ModuleBase_WidgetSelector.h>
 #include <ModuleBase_WidgetDoubleValue.h>
 #include <ModuleBase_WidgetBoolValue.h>
+#include <ModuleBase_WidgetPoint2dDistance.h>
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
@@ -119,6 +120,9 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
   } else if (theType == WDG_POINT_SELECTOR) {
     result = pointSelectorControl(theParent);
 
+  } else if (theType == WDG_POINT2D_DISTANCE) {
+    result = point2dDistanceControl(theParent);
+
   } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
     result = createContainer(theType, theParent);
   }
@@ -183,4 +187,13 @@ QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent)
   myModelWidgets.append(aBoolWgt);
 
   return aBoolWgt->getControl();
+}
+
+
+QWidget* ModuleBase_WidgetFactory::point2dDistanceControl(QWidget* theParent)
+{
+  ModuleBase_WidgetPoint2dDistance* aDistWgt = new ModuleBase_WidgetPoint2dDistance(theParent, myWidgetApi);
+  myModelWidgets.append(aDistWgt);
+
+  return aDistWgt->getControl();
 }
\ No newline at end of file
index aa7f6da76747bbc3a30c33c6b14408ce089e24e3..f8f67a6e4afb9b488cbeefdd150376d07f90120b 100644 (file)
@@ -41,6 +41,7 @@ protected:
   QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
   QWidget* selectorControl(QWidget* theParent);
   QWidget* booleanControl(QWidget* theParent);
+  QWidget* point2dDistanceControl(QWidget* theParent);
 
   QString qs(const std::string& theStdString) const;
 
diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.cpp
new file mode 100644 (file)
index 0000000..53ebdea
--- /dev/null
@@ -0,0 +1,37 @@
+// File:        ModuleBase_WidgetPoint2dDistance.h
+// Created:     23 June 2014
+// Author:      Vitaly Smetannikov
+
+#include "ModuleBase_WidgetPoint2dDistance.h"
+
+#include <GeomAPI_Pnt2d.h>
+#include <Config_WidgetAPI.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDouble.h>
+
+#include <QDoubleSpinBox>
+
+ModuleBase_WidgetPoint2dDistance::ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData)
+  : ModuleBase_WidgetDoubleValue(theParent, theData)
+{
+  myFirstPntName = theData->getProperty("first_point");
+}
+
+ModuleBase_WidgetPoint2dDistance::~ModuleBase_WidgetPoint2dDistance()
+{
+}
+
+void ModuleBase_WidgetPoint2dDistance::setPoint(FeaturePtr theFeature, const boost::shared_ptr<GeomAPI_Pnt2d>& thePnt)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                              (aData->attribute(myFirstPntName));
+  double aRadius = thePnt->distance(aPoint->pnt());
+  AttributeDoublePtr aReal = aData->real(attributeID());
+  if (aReal && aReal->value() != mySpinBox->value()) {
+    aReal->setValue(aRadius);
+    mySpinBox->setValue(aRadius);
+  }
+}
\ No newline at end of file
diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h b/src/ModuleBase/ModuleBase_WidgetPoint2dDistance.h
new file mode 100644 (file)
index 0000000..a078b9b
--- /dev/null
@@ -0,0 +1,33 @@
+// File:        ModuleBase_WidgetPoint2dDistance.h
+// Created:     23 June 2014
+// Author:      Vitaly Smetannikov
+
+
+#ifndef ModuleBase_WidgetPoint2dDistance_H
+#define ModuleBase_WidgetPoint2dDistance_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_WidgetDoubleValue.h"
+
+class GeomAPI_Pnt2d;
+
+class MODULEBASE_EXPORT ModuleBase_WidgetPoint2dDistance: public ModuleBase_WidgetDoubleValue
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \theParent the parent object
+  /// \theData the widget configuation. The attribute of the model widget is obtained from
+  ModuleBase_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData);
+
+  virtual ~ModuleBase_WidgetPoint2dDistance();
+
+  /// Set the second point which defines a value in the widget as a distance with a first point defined by feature
+  void setPoint(FeaturePtr theFeature, const boost::shared_ptr<GeomAPI_Pnt2d>& thePnt);
+
+private:
+  std::string myFirstPntName;
+};
+
+
+#endif
\ No newline at end of file
index 5968793236ddca565cd2db78f75d217ccfac293f..d81f6906f9965378d54057367e103e30ef68edd1 100644 (file)
@@ -14,7 +14,7 @@
       </feature>
       <feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon="">
         <point_selector id="CircleCenter" title="Center" tooltip="Center of the circle"/>
-        <doublevalue id="CircleRadius" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius"/>
+        <point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius"/>
       </feature>
       <feature id="SketchArc" title="Arc" tooltip="Create a new arc of a circle" icon="">
         <point_selector id="ArcCenter" title="Center" tooltip="Center of the arc"/>