]> 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>
Mon, 23 Jun 2014 18:42:45 +0000 (22:42 +0400)
committernds <natalia.donis@opencascade.com>
Mon, 23 Jun 2014 18:42:45 +0000 (22:42 +0400)
Move setConstraint method to the feature.

src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/PartSet/PartSet_FeaturePrs.cpp
src/PartSet/PartSet_FeaturePrs.h
src/PartSet/PartSet_OperationCreateFeature.cpp
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h

index dbac446a1adcfc19a752cfa477488e2147f4f7eb..a15c0edcc299c0478c39a8ca66bb49b905f5cb86 100644 (file)
@@ -36,8 +36,3 @@ std::string ModuleBase_ModelWidget::attributeID() const
 {
   return myAttributeID;
 }
-
-void ModuleBase_ModelWidget::setHasDefaultValue(const bool& theHasDefaultValue)
-{
-  myHasDefaultValue = theHasDefaultValue;
-}
index 0f2cd543f8f3424cd0fe73b05652a039c3d11227..b7b3de3b89d9e613abfc1070d8467a9f2badd95f 100644 (file)
@@ -58,6 +58,10 @@ public:
   /// \return a boolean value
   bool hasDefaultValue() const { return myHasDefaultValue; }
 
+  /// Returns the attribute name
+  /// \returns the string value
+  std::string attributeID() const;
+
 signals:
   /// The signal about widget values changed
   void valuesChanged();
@@ -67,16 +71,9 @@ signals:
   void keyReleased(const std::string& theAttributeName, QKeyEvent* theEvent);
 
 protected:
-  /// Returns the attribute name
-  /// \returns the string value
-  std::string attributeID() const;
-
-  /// Sets the has default value state to the widget
-  /// \param theHasDefaultValue the boolean value
-  void setHasDefaultValue(const bool& theHasDefaultValue);
+  bool myHasDefaultValue; /// the boolean state whether the control has a default value
 
 private:
-  bool myHasDefaultValue; /// the boolean state whether the control has a default value
   std::string myAttributeID; /// the attribute name of the model feature
 };
 
index aac859c49515f8be1d024e298783868cef4f2bcd..36ebe04f19e922ea3335fc2633f351b97f9b6586 100644 (file)
@@ -67,7 +67,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent, c
 
   aProp = theData->getProperty(DOUBLE_WDG_DFLT);
   double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
-  setHasDefaultValue(isOk);
+  myHasDefaultValue = isOk;
   if (isOk) {
     mySpinBox->setValue(aDefVal);
   }
index 7e9d12f020aab2d827d7a4f75cc4a2cb4a966773..dfbad61ab64455d487a0bb478edcbcde8330a91d 100644 (file)
@@ -48,26 +48,3 @@ PartSet_SelectionMode PartSet_FeaturePrs::setFeature(FeaturePtr theFeature,
 {
   return SM_FirstPoint;
 }
-
-void PartSet_FeaturePrs::setConstraints(double theX, double theY,
-                                        const PartSet_SelectionMode& theMode)
-{
-  // find a feature point by the selection mode
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
-
-  // get all sketch features. If the point with the given coordinates belong to any sketch feature,
-  // the constraint is created between the feature point and the found sketch point
-  boost::shared_ptr<ModelAPI_Data> aData = sketch()->data();
-  boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
-        boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
-
-  std::list<FeaturePtr > aFeatures = aRefList->list();
-  std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
-  for (; anIt != aLast; anIt++)
-  {
-    FeaturePtr aFeature = *anIt;
-    boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY);
-    if (aFPoint)
-      PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint);
-  }
-}
index eeaa0b85187d82622f0c8a9eb42ebaac2728a3c4..87fd3693bc3b4280882fc82e415aeb58194a3a24 100644 (file)
@@ -66,12 +66,6 @@ public:
   virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
                                                            double theY) = 0;
 
-  /// Creates constrains of the current 
-  /// \param theX the horizontal coordnate of the point
-  /// \param theY the vertical coordnate of the point
-  /// \param theMode the current operation selection mode. The feature attribute depends on the mode
-  void setConstraints(double theX, double theY, const PartSet_SelectionMode& theMode);
-
 protected:
   /// Returns the operation feature
   /// \return the feature
index da80e62b294c763fa2187736701925d05d5ea390..5fa63f4fa64d5028b22fd10909420ec3a7716309 100644 (file)
@@ -117,7 +117,7 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
           aPoint = BRep_Tool::Pnt(aVertex);
           PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
 
-          myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode);
+          //myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode);
         }
       }
       else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
index 0830639a7740af177cf14213ff3dd2b6fc3221d7..a203988975c08c38855ac33c5aed87d89bba8fb0 100644 (file)
@@ -117,7 +117,8 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle
           aPoint = BRep_Tool::Pnt(aVertex);
           PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
 
-          //myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode);
+          PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(),
+                                        aX, anY);
         }
       }
       else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
@@ -190,6 +191,7 @@ void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* t
     // TODO: to be realized in the custom point selector. The last point values of the init feature
     // should be to to the start point of a new feature
     //myActiveWidget->init(myInitFeature);
+    //PartSet_FeatureLinePrs::setFeature(myInitFeature, SM_FirstPoint);
     myInitFeature = FeaturePtr();
     emit activateNextWidget(myActiveWidget);
   }
index 8d1329046f89eca5481f2a05b29576a091d15350..17f5be33b69f38b28bbbe07c0dacc1a483517f83 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Document.h>
 
 #include <GeomDataAPI_Point.h>
@@ -300,6 +301,33 @@ void PartSet_Tools::createConstraint(FeaturePtr theSketch,
     aFeature->execute();
 }
 
+void PartSet_Tools::setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
+                                   const std::string& theAttribute, double theX, double theY)
+{
+  // find a feature point by the selection mode
+  //boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->data()->attribute(theAttribute));
+  if (!aPoint)
+    return;
+
+  // get all sketch features. If the point with the given coordinates belong to any sketch feature,
+  // the constraint is created between the feature point and the found sketch point
+  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+  boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
+
+  std::list<FeaturePtr > aFeatures = aRefList->list();
+  std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+  for (; anIt != aLast; anIt++)
+  {
+    FeaturePtr aFeature = *anIt;
+    boost::shared_ptr<GeomDataAPI_Point2D> aFPoint;// = aFeature->findPoint(theX, theY);
+    if (aFPoint)
+      PartSet_Tools::createConstraint(theSketch, aFPoint, aPoint);
+  }
+}
+
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findPoint(FeaturePtr theFeature,
                                                                 double theX, double theY)
 {
@@ -355,4 +383,4 @@ bool PartSet_Tools::isConstraintFeature(const std::string& theKind)
   return theKind == PartSet_ConstraintLengthPrs::getKind() ||
          theKind == PartSet_ConstraintDistancePrs::getKind() ||
          theKind == PartSet_ConstraintRadiusPrs::getKind();
-}
\ No newline at end of file
+}
index f4e4ae62b565619c2204687648ff2d4da5318420..7f407ac8c5427a37e32a8d0acf810593d5379389 100644 (file)
@@ -110,6 +110,15 @@ public:
                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
 
+  /// Creates constrains of the current 
+  /// \param theSketch a sketch feature
+  /// \param theFeature a source feature
+  /// \param theAttribute a name of the requried attribute attribute
+  /// \param theX the horizontal coordnate of the point
+  /// \param theY the vertical coordnate of the point
+  static void setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
+                             const std::string& theAttribute, double theX, double theY);
+
   /// Find a point in the line with given coordinates
   /// \param theFeature the line feature
   /// \param theX the horizontal point coordinate