]> 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>
Thu, 5 Jun 2014 12:24:28 +0000 (16:24 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 5 Jun 2014 12:24:28 +0000 (16:24 +0400)
Point feature creation is finished. Constraint for the point is available between two points or a point and a line point.

src/PartSet/PartSet_FeaturePointPrs.cpp
src/PartSet/PartSet_FeaturePointPrs.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationCreateFeature.cpp
src/PartSet/PartSet_OperationCreateFeature.h
src/PartSet/PartSet_Tools.cpp
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/plugin-Sketch.xml

index 18db26a09ecbd5687c2851c4711bda00055640bd..ac695dada8c7abc016474c7ffd50cc8376a1530d 100644 (file)
@@ -1,4 +1,4 @@
-// File:        PartSet_FeaturePointPrs.h
+// File:        PartSet_FeaturePrs.h
 // Created:     04 Jun 2014
 // Author:      Natalia ERMOLAEVA
 
@@ -7,9 +7,7 @@
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Point.h>
 
 #include <GeomDataAPI_Point2D.h>
 
 
 using namespace std;
 
-PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theFeature)
+PartSet_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theSketch)
+: PartSet_FeaturePrs(theSketch)
 {
 }
 
-PartSet_FeaturePointPrs::~PartSet_FeaturePointPrs()
+void PartSet_FeaturePointPrs::initFeature(FeaturePtr theFeature)
 {
 }
+
+PartSet_SelectionMode PartSet_FeaturePointPrs::setPoint(double theX, double theY,
+                                                       const PartSet_SelectionMode& theMode)
+{
+  PartSet_SelectionMode aMode = theMode;
+  switch (theMode)
+  {
+    case SM_FirstPoint: {
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, POINT_ATTR_COORD);
+      aMode = SM_DonePoint;
+    }
+    break;
+    default:
+      break;
+  }
+  return aMode;
+}
+
+std::string PartSet_FeaturePointPrs::getAttribute(const PartSet_SelectionMode& theMode) const
+{
+  std::string aAttribute;
+  switch (theMode)
+  {
+    case SM_FirstPoint:
+      aAttribute = POINT_ATTR_COORD;
+    break;
+    default:
+    break;
+  }
+  return aAttribute;
+}
+
+PartSet_SelectionMode PartSet_FeaturePointPrs::getNextMode(const std::string& theAttribute) const
+{
+  PartSet_SelectionMode aMode;
+
+  if (theAttribute == POINT_ATTR_COORD)
+    aMode = SM_DonePoint;
+  return aMode;
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePointPrs::featurePoint
+                                                     (const PartSet_SelectionMode& theMode)
+{
+  std::string aPointArg;
+  switch (theMode)
+  {
+    case SM_FirstPoint:
+      aPointArg = POINT_ATTR_COORD;
+      break;
+    default:
+      break;
+  }
+  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                              (aData->attribute(aPointArg));
+  return aPoint;
+}
index b43de80ed2e1b586449c9928616ddb65d26e4963..d06b3c7345a71dd8db687b7359ac2c5b4f927908 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "PartSet.h"
 
+#include "PartSet_FeaturePrs.h"
 #include "PartSet_Constants.h"
 
 class GeomDataAPI_Point2D;
@@ -17,14 +18,40 @@ class GeomDataAPI_Point2D;
  * the feature create operation to move out the feature properties set and use one operation
  * for any type of features.
 */
-class PARTSET_EXPORT PartSet_FeaturePointPrs
+class PARTSET_EXPORT PartSet_FeaturePointPrs : public PartSet_FeaturePrs
 {
 public:
   /// Constructor
   /// \param theSketch the sketch feature
   PartSet_FeaturePointPrs(FeaturePtr theSketch);
   /// Destructor
-  virtual ~PartSet_FeaturePointPrs();
+  virtual ~PartSet_FeaturePointPrs() {};
+
+  /// Sets the point to the feature in an attribute depending on the selection mode
+  /// \param theX the 2D point horizontal coordinate
+  /// \param theY the 2D point vertical coordinate
+  /// \param theMode the selection mode
+  /// \return the new selection mode
+  virtual PartSet_SelectionMode setPoint(double theX, double theY,
+                                         const PartSet_SelectionMode& theMode);
+
+  /// Returns the feature attribute name for the selection mode
+  /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+  virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const;
+
+  /// Returns the next selection mode after the attribute
+  /// \param theAttribute the feature attribute name
+  /// \return next attribute selection mode
+  virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+
+protected:
+  /// Initializes current feature by the given
+  /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
+  virtual void initFeature(FeaturePtr theSourceFeature);
+
+  /// Returns the feature point in the selection mode position.
+  /// \param theMode the current operation selection mode. The feature attribute depends on the mode
+  virtual boost::shared_ptr<GeomDataAPI_Point2D> featurePoint(const PartSet_SelectionMode& theMode);
 };
 
 #endif
index 83b8fbe74ab40321632a651a6168b242d1f559c5..9302a0618927474fbb16207ebbf9cd76acc0c0a6 100644 (file)
@@ -25,6 +25,9 @@
 #include <XGUI_PropertyPanel.h>
 #include <XGUI_Tools.h>
 
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
+
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
 #include <Config_WidgetReader.h>
@@ -327,7 +330,7 @@ ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdI
     PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
     if (aPrevOp)
       aSketch = aPrevOp->sketch();
-    if (theCmdId == SKETCH_LINE_KIND)
+    if (theCmdId == SKETCH_LINE_KIND || theCmdId == SKETCH_POINT_KIND)
       anOperation = new PartSet_OperationCreateFeature(theCmdId.c_str(), this, aSketch);
     else if (theCmdId == PartSet_OperationEditLine::Type())
       anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
index 60a5ded04067ef9dd7d777d5b865931e0b2441b6..06931c524967ad4daef05d89ae88135ff970ffe9 100644 (file)
@@ -7,8 +7,10 @@
 #include <PartSet_Tools.h>
 #include <PartSet_OperationSketch.h>
 #include <PartSet_FeatureLinePrs.h>
+#include <PartSet_FeaturePointPrs.h>
 
 #include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Line.h>
 
 #include <ModuleBase_OperationDescription.h>
 
 using namespace std;
 
 PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& theId,
-                                                 QObject* theParent,
-                                              FeaturePtr theFeature)
+                                                               QObject* theParent,
+                                                               FeaturePtr theFeature)
 : PartSet_OperationSketchBase(theId, theParent),
   myPointSelectionMode(SM_FirstPoint)
 {
-  myFeaturePrs = new PartSet_FeatureLinePrs(theFeature);
+  if (theId.toStdString() == SKETCH_LINE_KIND) {
+    myFeaturePrs = new PartSet_FeatureLinePrs(theFeature);
+  }
+  else {
+    myFeaturePrs = new PartSet_FeaturePointPrs(theFeature);
+  }
 }
 
 PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
index e53bf9b8411cf9afbec026975257cc994b870992..acea5a01e8a4b8479d926cc5970cc77f30b5b67f 100644 (file)
@@ -10,8 +10,6 @@
 #include <PartSet_OperationSketchBase.h>
 #include <PartSet_Constants.h>
 
-#include <SketchPlugin_Line.h>
-
 #include <QObject>
 
 class PartSet_FeaturePrs;
index 265a3b26bfd3dfb52dc09a7a5b161014f022e65c..3e8c921b237c1a9724e86387e0b51b846a6495d2 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Point.h>
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_Constraint.h>
@@ -297,5 +298,12 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findPoint(FeaturePtr theFe
         aPoint2D = aPoint;
     }
   }
+  else if (theFeature->getKind() == SKETCH_POINT_KIND)
+  {
+    boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+          boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(POINT_ATTR_COORD));
+    if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+      aPoint2D = aPoint;
+  }
   return aPoint2D;
 }
index 1d9601a8383694fca1691fb8bdd228a2e6b16dbc..63cf747a21c43b0a05195795a76a424e386396b6 100644 (file)
@@ -6,6 +6,7 @@
 #include "SketchPlugin_Sketch.h"
 #include <ModelAPI_Data.h>
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_PointBuilder.h>
 
 using namespace std;
 
@@ -30,8 +31,8 @@ const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Point::preview()
     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(POINT_ATTR_COORD));
   boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
   // make a visible point
-  //boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
-  //setPreview(anEdge);
+  boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
+  setPreview(aPointShape);
 
   return getPreview();
 }
index be4bb9e41e9cbf1addcf90f3259d3ad00e647871..e9e8a7105f9861369813dfb2637205ca212ef650 100644 (file)
@@ -1,11 +1,13 @@
 <plugin>
   <workbench id="Sketch">
     <group id="Basic">
-      <feature id="Sketch" nested="SketchLine SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+      <feature id="Sketch" nested="SketchLine SketchPoint SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
         <label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/> 
       <!--icon=":pictures/x_point.png"-->
       </feature>
-      <feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png" internal="1"/>
+      <feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">
+        <point_selector id="PointCoordindates" title="Point" tooltip="Point"/>
+      </feature>
       <feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
         <point_selector id="StartPoint" title="Start point" tooltip="Start point of the line"/>
         <point_selector id="EndPoint" title="End point" tooltip="End point of the line"/>