]> 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, 10 Jun 2014 12:28:21 +0000 (16:28 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 10 Jun 2014 12:28:21 +0000 (16:28 +0400)
Edit feature: creation a specific presentation in the tools in order to use it in the edit operation.

src/PartSet/PartSet_FeatureArcPrs.cpp
src/PartSet/PartSet_FeatureArcPrs.h
src/PartSet/PartSet_OperationCreateFeature.cpp
src/PartSet/PartSet_OperationCreateFeature.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h

index 97af28864808bec64eb31ed4f435a80f36634151..b742b64d7b67277691f068384f0a4bf7623f9946 100644 (file)
@@ -29,6 +29,11 @@ PartSet_FeatureArcPrs::PartSet_FeatureArcPrs(FeaturePtr theSketch)
 {
 }
 
+std::string PartSet_FeatureArcPrs::getKind()
+{
+  return SKETCH_ARC_KIND;
+}
+
 PartSet_SelectionMode PartSet_FeatureArcPrs::setPoint(double theX, double theY,
                                                        const PartSet_SelectionMode& theMode)
 {
index a02029e7fec24b79fe726c3c34b97394dadc4026..dc8a91bfab93a74d5c7eb3b4addf4c45bebb70b5 100644 (file)
@@ -24,6 +24,10 @@ class Handle_V3d_View;
 class PARTSET_EXPORT PartSet_FeatureArcPrs : public PartSet_FeaturePrs
 {
 public:
+  /// Returns the feature type processed by this presentation
+  /// \return the feature kind
+  static std::string getKind();
+
   /// Constructor
   /// \param theSketch the sketch feature
   PartSet_FeatureArcPrs(FeaturePtr theSketch);
index e9257138215714e2f3b863c02793d588916155f2..2bfca9f7c0ece4001509d390dce12756fab94b81 100644 (file)
@@ -42,24 +42,11 @@ PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& th
   myPointSelectionMode(SM_FirstPoint)
 {
   std::string aKind = theId.toStdString();
-
-  if (aKind == SKETCH_POINT_KIND) {
-    myFeaturePrs = new PartSet_FeaturePointPrs(theFeature);
-  }
-  if (aKind == SKETCH_LINE_KIND) {
-    myFeaturePrs = new PartSet_FeatureLinePrs(theFeature);
-  }
-  else if (aKind == SKETCH_CIRCLE_KIND) {
-    myFeaturePrs = new PartSet_FeatureCirclePrs(theFeature);
-  }
-  else if (aKind == SKETCH_ARC_KIND) {
-    myFeaturePrs = new PartSet_FeatureArcPrs(theFeature);
-  }
+  myFeaturePrs = PartSet_Tools::createFeaturePrs(aKind, theFeature);
 }
 
 PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
 {
-  delete myFeaturePrs;
 }
 
 bool PartSet_OperationCreateFeature::canProcessKind(const std::string& theId)
@@ -138,7 +125,8 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
         PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
         // move to selected line
         if (feature()->getKind() == SKETCH_LINE_KIND) {
-          PartSet_FeatureLinePrs* aLinePrs = dynamic_cast<PartSet_FeatureLinePrs*>(myFeaturePrs);
+          boost::shared_ptr<PartSet_FeatureLinePrs> aLinePrs =
+                                 boost::dynamic_pointer_cast<PartSet_FeatureLinePrs>(myFeaturePrs);
           if (aLinePrs) {
             FeaturePtr aFeature = aPrs.feature();
             aLinePrs->projectPointOnLine(aFeature, myPointSelectionMode, aPoint, theView, aX, anY);
@@ -154,7 +142,8 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
     case SM_SecondPoint:
     case SM_ThirdPoint: {
       if (feature()->getKind() == SKETCH_ARC_KIND) {
-        PartSet_FeatureArcPrs* anArcPrs = dynamic_cast<PartSet_FeatureArcPrs*>(myFeaturePrs);
+        boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
+                                 boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
         if (anArcPrs) {
           anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
         }
@@ -182,7 +171,8 @@ void PartSet_OperationCreateFeature::mouseMoved(QMouseEvent* theEvent, Handle(V3
       PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
       if (myPointSelectionMode == SM_ThirdPoint) {
         if (feature()->getKind() == SKETCH_ARC_KIND) {
-          PartSet_FeatureArcPrs* anArcPrs = dynamic_cast<PartSet_FeatureArcPrs*>(myFeaturePrs);
+          boost::shared_ptr<PartSet_FeatureArcPrs> anArcPrs =
+                                 boost::dynamic_pointer_cast<PartSet_FeatureArcPrs>(myFeaturePrs);
           if (anArcPrs) {
             anArcPrs->projectPointOnArc(aPoint, theView, aX, anY);
           }
index 1eb352dd10f5eb369a49df4374053444fbb1fdda..e35f5f88dc9800815bbfef35e5d333d17868dff7 100644 (file)
@@ -116,7 +116,7 @@ protected:
                              const bool isToEmitSignal = true);
 
 private:
-  PartSet_FeaturePrs* myFeaturePrs; ///< the feature presentation
+  boost::shared_ptr<PartSet_FeaturePrs> myFeaturePrs; ///< the feature presentation
   FeaturePtr myInitFeature; ///< the initial feature
   PartSet_SelectionMode myPointSelectionMode; ///< point selection mode
 };
index 4a483de029d6caa805796fc62ebeeed74332f24f..bc73da323c6f1de6ecb374c0e16b759164b440a0 100644 (file)
@@ -23,6 +23,7 @@
 #include <PartSet_FeatureLinePrs.h>
 #include <PartSet_FeaturePointPrs.h>
 #include <PartSet_FeatureCirclePrs.h>
+#include <PartSet_FeatureArcPrs.h>
 
 #include <XGUI_ViewerPrs.h>
 
@@ -174,6 +175,30 @@ void PartSet_Tools::projectPointOnLine(double theX1, double theY1, double theX2,
   }
 }
 
+boost::shared_ptr<PartSet_FeaturePrs> PartSet_Tools::createFeaturePrs(const std::string& theKind,
+                                                                      FeaturePtr theSketch,
+                                                                      FeaturePtr theFeature)
+{
+  PartSet_FeaturePrs* aFeaturePrs;
+
+  if (theKind == PartSet_FeaturePointPrs::getKind()) {
+    aFeaturePrs = new PartSet_FeaturePointPrs(theSketch);
+  }
+  else if (theKind == PartSet_FeatureLinePrs::getKind()) {
+    aFeaturePrs = new PartSet_FeatureLinePrs(theSketch);
+  }
+  else if (theKind == PartSet_FeatureCirclePrs::getKind()) {
+    aFeaturePrs = new PartSet_FeatureCirclePrs(theSketch);
+  }
+  else if (theKind == PartSet_FeatureArcPrs::getKind()) {
+    aFeaturePrs = new PartSet_FeatureArcPrs(theSketch);
+  }
+  if (theFeature)
+    aFeaturePrs->init(theFeature, FeaturePtr());
+
+  return boost::shared_ptr<PartSet_FeaturePrs>(aFeaturePrs);
+}
+
 FeaturePtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
                                          FeaturePtr theSketch,
                                          const std::list<XGUI_ViewerPrs>& theFeatures)
index 30c8fa40167ac47816e8d0d17548874c7e3a0eb4..4dd228226bf3fb886c7e1319e90f1b8be01dc38a 100644 (file)
@@ -20,6 +20,7 @@
 class Handle_V3d_View;
 class XGUI_ViewerPrs;
 class GeomDataAPI_Point2D;
+class PartSet_FeaturePrs;
 
 /*!
  \class PartSet_Tools
@@ -75,6 +76,15 @@ public:
   static void projectPointOnLine(double theX1, double theY1, double theX2, double theY2,
                                  double thePointX, double thePointY, double& theX, double& theY);
 
+  /// Creates the feature presentation
+  /// \param theKind a feature kind
+  /// \param theSketch the sketch of the feature
+  /// \param theFeature the feature
+  static boost::shared_ptr<PartSet_FeaturePrs> createFeaturePrs(const std::string& theKind,
+                                                                FeaturePtr theSketch,
+                                                                FeaturePtr theFeature = FeaturePtr());
+
+
   /// Returns a feature that is under the mouse point
   /// \param thePoint a screen point
   /// \param theView a 3D view