]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 07:21:45 +0000 (11:21 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 07:21:45 +0000 (11:21 +0400)
Widget controls for a constraint filling.

13 files changed:
src/Config/CMakeLists.txt
src/Config/Config_Keywords.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetFactory.h
src/ModuleBase/ModuleBase_WidgetFeature.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetFeature.h [new file with mode: 0644]
src/PartSet/PartSet_ConstraintDistancePrs.cpp
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/PartSet/PartSet_OperationFeatureCreate.h
src/SketchPlugin/SketchPlugin_Constraint.h
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/plugin-Sketch.xml

index ebb5efb695ee3c638bf152f765af59f9ee65c266..2e826fc24573c1fd7d81786dfab9ed2bec2c2292 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
   Config_XMLReader.h
   Config_ModuleReader.h
   Config_FeatureReader.h
+  Config_Keywords.h
   Config_WidgetAPI.h
   Config_WidgetReader.h
   Config_PointerMessage.h
index 125faa57a0879e241a273c5f94d7c27a79adee24..0d16ad4321ad648738a79fc89a13046f39e7b1b3 100644 (file)
@@ -32,6 +32,8 @@ const static char* WDG_SELECTOR = "selector";
 //Specific widget containers
 const static char* WDG_POINT_SELECTOR = "point_selector";
 
+const static char* WDG_FEATURE_SELECTOR = "feature_selector";
+
 const static char* _ID = "id";
 //const static char* WORKBENCH_ID = "id";
 //const static char* GROUP_ID = "id";
index 3a66ec0d57a0aa1eb1faf4198bd58e1db5d6fa3d..b617a50628ed4c310002de87182b9138a0d0f23c 100644 (file)
@@ -10,6 +10,7 @@ SET(PROJECT_HEADERS
        ModuleBase_WidgetBoolValue.h
        ModuleBase_WidgetDoubleValue.h
        ModuleBase_WidgetFactory.h
+       ModuleBase_WidgetFeature.h
        ModuleBase_WidgetPoint2D.h
        ModuleBase_WidgetSwitch.h
        ModuleBase_WidgetSelector.h
@@ -24,6 +25,7 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetBoolValue.cpp
        ModuleBase_WidgetDoubleValue.cpp
        ModuleBase_WidgetFactory.cpp
+       ModuleBase_WidgetFeature.cpp
        ModuleBase_WidgetPoint2D.cpp
        ModuleBase_WidgetSwitch.cpp
        ModuleBase_WidgetSelector.cpp
index e83cd01fc642a6c637fe7d3c2609e613a138ebfe..1c372fd670b897986767d3b7caf24ce135fc50a9 100644 (file)
@@ -10,6 +10,7 @@
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetPoint2D.h>
+#include <ModuleBase_WidgetFeature.h>
 #include <ModuleBase_WidgetSwitch.h>
 #include <ModuleBase_WidgetSelector.h>
 #include <ModuleBase_WidgetDoubleValue.h>
@@ -119,7 +120,11 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
   } else if (theType == WDG_POINT_SELECTOR) {
     result = pointSelectorControl(theParent);
 
-  } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
+  } else if (theType == WDG_FEATURE_SELECTOR) {
+    result = featureSelectorControl(theParent);
+
+  }
+  else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
     result = createContainer(theType, theParent);
   }
 #ifdef _DEBUG
@@ -163,6 +168,13 @@ QWidget* ModuleBase_WidgetFactory::pointSelectorControl(QWidget* theParent)
   return aWidget->getControl();
 }
 
+QWidget* ModuleBase_WidgetFactory::featureSelectorControl(QWidget* theParent)
+{
+  ModuleBase_WidgetFeature* aWidget = new ModuleBase_WidgetFeature(theParent, myWidgetApi);
+  myModelWidgets.append(aWidget);
+  return aWidget->getControl();
+}
+
 QString ModuleBase_WidgetFactory::qs(const std::string& theStdString) const
 {
   return QString::fromStdString(theStdString);
index aa7f6da76747bbc3a30c33c6b14408ce089e24e3..e2162872cdce5d040f655feff688a0e94aa03227 100644 (file)
@@ -38,6 +38,7 @@ protected:
   QWidget* labelControl(QWidget* theParent);
   QWidget* doubleSpinBoxControl(QWidget* theParent);
   QWidget* pointSelectorControl(QWidget* theParent);
+  QWidget* featureSelectorControl(QWidget* theParent);
   QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
   QWidget* selectorControl(QWidget* theParent);
   QWidget* booleanControl(QWidget* theParent);
diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.cpp b/src/ModuleBase/ModuleBase_WidgetFeature.cpp
new file mode 100644 (file)
index 0000000..dd33700
--- /dev/null
@@ -0,0 +1,80 @@
+// File:        ModuleBase_WidgetFeature.cpp
+// Created:     25 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <ModuleBase_WidgetFeature.h>
+
+#include <Config_Keywords.h>
+#include <Config_WidgetAPI.h>
+
+#include <Events_Loop.h>
+#include <Model_Events.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeRefAttr.h>
+
+#include <QWidget>
+
+ModuleBase_WidgetFeature::ModuleBase_WidgetFeature(QWidget* theParent,
+                                                   const Config_WidgetAPI* theData)
+: ModuleBase_ModelWidget(theParent, theData)
+{
+  QString aKinds = QString::fromStdString(theData->getProperty(FEATURE_KEYSEQUENCE));
+  myFeatureKinds = aKinds.split(" ");
+}
+
+ModuleBase_WidgetFeature::~ModuleBase_WidgetFeature()
+{
+}
+
+bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature)
+{
+  if (!theFeature && myFeatureKinds.contains(theFeature->getKind().c_str()))
+    return false;
+
+  //bool isBlocked = this->blockSignals(true);
+  myFeature = theFeature;
+  //this->blockSignals(isBlocked);
+  emit valuesChanged();
+  return true;
+}
+
+bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const
+{
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
+
+  ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
+  //bool isBlocked = that->blockSignals(true);
+  aRef->setFeature(myFeature);
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+  //that->blockSignals(isBlocked);
+
+  return true;
+}
+
+bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
+
+  //bool isBlocked = this->blockSignals(true);
+  myFeature = aRef->feature();
+  //this->blockSignals(isBlocked);
+  return true;
+}
+
+QWidget* ModuleBase_WidgetFeature::getControl() const
+{
+  return 0;
+}
+
+QList<QWidget*> ModuleBase_WidgetFeature::getControls() const
+{
+  QList<QWidget*> aControls;
+  return aControls;
+}
diff --git a/src/ModuleBase/ModuleBase_WidgetFeature.h b/src/ModuleBase/ModuleBase_WidgetFeature.h
new file mode 100644 (file)
index 0000000..a429421
--- /dev/null
@@ -0,0 +1,55 @@
+// File:        ModuleBase_WidgetFeature.h
+// Created:     25 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_WidgetFeature_H
+#define ModuleBase_WidgetFeature_H
+
+#include <ModuleBase.h>
+#include "ModuleBase_ModelWidget.h"
+
+#include <QObject>
+#include <QStringList>
+
+class ModelAPI_Feature;
+
+/**\class ModuleBase_WidgetFeature
+ * \ingroup GUI
+ * \brief Custom widget. An abstract class to be redefined to fill with some GUI controls
+ */
+class MODULEBASE_EXPORT ModuleBase_WidgetFeature : public ModuleBase_ModelWidget
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \theParent the parent object
+  /// \theParent the parent object
+  /// \theData the widget configuation. The attribute of the model widget is obtained from
+  ModuleBase_WidgetFeature(QWidget* theParent, const Config_WidgetAPI* theData);
+  /// Destructor
+  virtual ~ModuleBase_WidgetFeature();
+
+  /// Fill the widget values by given point
+  /// \param thePoint the point
+  bool setFeature(const FeaturePtr& theFeature);
+
+  /// Saves the internal parameters to the given feature
+  /// \param theFeature a model feature to be changed
+  virtual bool storeValue(FeaturePtr theFeature) const;
+
+  virtual bool restoreValue(FeaturePtr theFeature);
+
+  /// 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<QWidget*> getControls() const;
+
+private:
+  FeaturePtr myFeature; ///< the current widget feature
+  QStringList myFeatureKinds; ///< the kinds of possible features
+};
+
+#endif
index 6bd7510c9b29c1d4841b0dc500a9ba7c1807d10d..661061efd2da5e47baa6aba2c3459ec541d0c244 100644 (file)
@@ -87,25 +87,11 @@ PartSet_SelectionMode PartSet_ConstraintDistancePrs::setPoint(double theX, doubl
   switch (theMode)
   {
     case SM_LastPoint: {
-      boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(feature(),
-                                                                        CONSTRAINT_ATTR_ENTITY_A);
-      boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(feature(),
-                                                                        CONSTRAINT_ATTR_ENTITY_B);
-
-      boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
-                                                             (new GeomAPI_Pnt2d(theX, theY));
-      boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
-                                        (new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(),
-                                                           aPoint_B->x(), aPoint_B->y()));
-      boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
-      double aDistance = aPoint->distance(aResult);
-
-      if (!aFeatureLin->isRight(aPoint))
-        aDistance = -aDistance;
-
-      AttributeDoublePtr aFlyoutAttr = boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>
-                                      (feature()->data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-      aFlyoutAttr->setValue(aDistance);
+      boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = 
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(feature()->data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+      aFlyOutAttr->setValue(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
+
+      boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
 
       aMode = SM_DonePoint;
     }
@@ -131,14 +117,21 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation(
   if (!aPoint_A || !aPoint_B)
     return anAIS;
 
+  // fly out calculation
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-  double aFlyout = aFlyoutAttr->value();
+  boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+  boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
 
-  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
-  double aValue = aValueAttr->value();
+  boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
+                                    (new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(),
+                                                        aPoint_B->x(), aPoint_B->y()));
+  boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aFlyOutPnt);
+  double aDistance = aFlyOutPnt->distance(aResult);
+
+  if (!aFeatureLin->isRight(aFlyOutPnt))
+    aDistance = -aDistance;
+  double aFlyout = aDistance;
 
   gp_Pnt aPoint1, aPoint2;
   PartSet_Tools::convertTo3D(aPoint_A->x(), aPoint_A->y(), theSketch, aPoint1);
@@ -152,6 +145,14 @@ Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation(
     aP2 = aPoint1;
   }
 
+  // value calculation
+  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
+         boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+  double aValue = aValueAttr->value();
+  if (aValue == 0) { // TODO! the default value
+    aValue = aP1.Distance(aP2);
+  }
+
   if (anAIS.IsNull())
   {
     Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension(aP1, aP2, aPlane);
index a203988975c08c38855ac33c5aed87d89bba8fb0..a318a128085fe285a719288dcd83c9d7edcb1e1a 100644 (file)
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Arc.h>
+#include <SketchPlugin_ConstraintDistance.h>
 
 #include <GeomAPI_Pnt2d.h>
 
 #include <ModuleBase_OperationDescription.h>
 #include <ModuleBase_WidgetPoint2D.h>
+#include <ModuleBase_WidgetFeature.h>
 
 #include <XGUI_ViewerPrs.h>
 #include <XGUI_Constants.h>
@@ -40,7 +42,7 @@ using namespace std;
 
 PartSet_OperationFeatureCreate::PartSet_OperationFeatureCreate(const QString& theId,
                                                                QObject* theParent,
-                                                               FeaturePtr theFeature)
+                                                                 FeaturePtr theFeature)
 : PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature), myActiveWidget(0)
 {
 }
@@ -51,7 +53,8 @@ PartSet_OperationFeatureCreate::~PartSet_OperationFeatureCreate()
 
 bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId)
 {
-  return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*|| theId == SKETCH_CIRCLE_KIND ||
+  return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND /*||
+         theId == SKETCH_CONSTRAINT_DISTANCE_KIND/*|| theId == SKETCH_CIRCLE_KIND ||
          theId == SKETCH_ARC_KIND*/;
 }
 
@@ -143,7 +146,17 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle
       anArcPrs->projectPointOnFeature(feature(), sketch(), aPoint, theView, aX, anY);
     }
   }*/
-  setWidgetPoint(aX, anY);
+  bool isApplyed = false;
+  if (isPointWidget())
+    isApplyed = setWidgetPoint(aX, anY);
+  else {
+    if (!theSelected.empty()) {
+      XGUI_ViewerPrs aPrs = theSelected.front();
+      FeaturePtr aFeature = aPrs.feature();
+      if (aFeature)
+        isApplyed = setWidgetFeature(aFeature);
+    }
+  }
   flushUpdated();
   emit activateNextWidget(myActiveWidget);
 }
@@ -281,8 +294,26 @@ FeaturePtr PartSet_OperationFeatureCreate::createFeature(const bool theFlushMess
   }
 }*/
 
-void PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY)
+bool PartSet_OperationFeatureCreate::isPointWidget() const
+{
+  return dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
+}
+
+bool PartSet_OperationFeatureCreate::setWidgetPoint(double theX, double theY)
 {
   ModuleBase_WidgetPoint2D* aWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(myActiveWidget);
+  if (!aWidget)
+    return false;
+
   aWidget->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
-}
\ No newline at end of file
+  return true;
+}
+
+bool PartSet_OperationFeatureCreate::setWidgetFeature(const FeaturePtr& theFeature)
+{
+  ModuleBase_WidgetFeature* aWidget = dynamic_cast<ModuleBase_WidgetFeature*>(myActiveWidget);
+  if (!aWidget)
+    return false;
+
+  return aWidget->setFeature(theFeature);
+}
index 519c45e2f6774554ee07f95a0074775ca23676bf..606bdc3bfefa98b7e5a45fa9d751076a1f104f84 100644 (file)
@@ -120,10 +120,20 @@ protected:
   //void setPointSelectionMode(const PartSet_SelectionMode& theMode,
   //                           const bool isToEmitSignal = true);
 
-  /// Set the widget point
+  /// Returns true if the active widget is the point selector widget
+  /// \return the boolean value
+  bool isPointWidget() const;
+
+  /// Set the point to the active widget
   /// \param theX the horizontal coordinate
   /// \param theY the vertical coordinate
-  void setWidgetPoint(double theX, double theY);
+  /// \return true if the point is set
+  bool setWidgetPoint(double theX, double theY);
+
+  /// Set the feature to the active widget
+  /// \param theFeature a feature
+  /// \return true if the feature is set
+  bool setWidgetFeature(const FeaturePtr& theFeature);
 
 private:
   //boost::shared_ptr<PartSet_FeaturePrs> myFeaturePrs; ///< the feature presentation
index fbc182c64445752fb27cb0c985e2a5973ba47119..dbb66522a715558218f6eeabd0c723d9c9d3d046 100644 (file)
@@ -26,6 +26,8 @@
  */
 /// The value parameter for the constraint
 const std::string CONSTRAINT_ATTR_VALUE("ConstraintValue");
+/// The 2D value parameter for the constraint
+const std::string CONSTRAINT_ATTR_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
 /// The value parameter for the constraint
 const std::string CONSTRAINT_ATTR_FLYOUT_VALUE("ConstraintFlyoutValue");
 /// First entity for the constraint
index 52c58e14603aa78092e6a32c288e8fd4be72b005..afb764a5dcfcc3654075ebf5847136f9b77e1a2c 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "SketchPlugin_ConstraintDistance.h"
 
+#include "GeomDataAPI_Point2D.h"
+
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 #include <SketchPlugin_Point.h>
@@ -15,7 +17,7 @@ SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
 void SketchPlugin_ConstraintDistance::initAttributes()
 {
   data()->addAttribute(CONSTRAINT_ATTR_VALUE,    ModelAPI_AttributeDouble::type());
-  data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
+  data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type());
 }
index 5968793236ddca565cd2db78f75d217ccfac293f..f1d354e4601378786820f5584759b0e6318e1ed6 100644 (file)
       <feature id="SketchConstraintCoincidence" title="Points coincidence" tooltip="Create constraint for the coincidence of two points" internal="1"/>
       <feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object">
         <label title="Select point and another feature (point or point on line) between which to calculate distance" tooltip="Select point and another feature (point or point on line) between which to calculate distance"/>
+        <feature_selector id="ConstraintEntityA" keysequence="SketchPoint"/>
+        <feature_selector id="ConstraintEntityB" keysequence="SketchPoint"/>
+        <point_selector id="ConstraintFlyoutValuePnt" title="Flyout point" tooltip="Flyout"/>
+        <doublevalue id="ConstraintValue" label="Value:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Constraint value"/>
       </feature>
       <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment">
         <label title="Select a line entity on which to calculate lenght" tooltip="Select a line entity on which to calculate lenght"/>