]> 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 13:23:48 +0000 (17:23 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 5 Jun 2014 13:23:48 +0000 (17:23 +0400)
Circle draft creation.

src/PartSet/CMakeLists.txt
src/PartSet/PartSet_FeatureCirclePrs.cpp [new file with mode: 0644]
src/PartSet/PartSet_FeatureCirclePrs.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationCreateFeature.cpp
src/PartSet/PartSet_OperationCreateFeature.h
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/radius.png [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml

index f8629de870fdbcb268184c21258f30c65a19810e..a1c50ac6604f75f4e672a8053519ea02dd043504 100644 (file)
@@ -5,6 +5,7 @@ SET(CMAKE_AUTOMOC ON)
 SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Constants.h
+       PartSet_FeatureCirclePrs.h
        PartSet_FeaturePrs.h
        PartSet_FeatureLinePrs.h
        PartSet_FeaturePointPrs.h
@@ -22,6 +23,7 @@ SET(PROJECT_HEADERS
 
 SET(PROJECT_SOURCES
        PartSet_FeaturePrs.cpp
+       PartSet_FeatureCirclePrs.cpp
        PartSet_FeatureLinePrs.cpp
        PartSet_FeaturePointPrs.cpp
        PartSet_Listener.cpp
diff --git a/src/PartSet/PartSet_FeatureCirclePrs.cpp b/src/PartSet/PartSet_FeatureCirclePrs.cpp
new file mode 100644 (file)
index 0000000..48342d9
--- /dev/null
@@ -0,0 +1,118 @@
+// File:        PartSet_FeaturePrs.h
+// Created:     04 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_FeatureCirclePrs.h>
+#include <PartSet_Tools.h>
+
+#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <GeomDataAPI_Point2D.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+
+#include <Precision.hxx>
+
+using namespace std;
+
+PartSet_FeatureCirclePrs::PartSet_FeatureCirclePrs(FeaturePtr theSketch)
+: PartSet_FeaturePrs(theSketch)
+{
+}
+
+void PartSet_FeatureCirclePrs::initFeature(FeaturePtr theFeature)
+{
+  if (feature() && theFeature)
+  {
+    // use the last point of the previous feature as the first of the new one
+    boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+    boost::shared_ptr<GeomDataAPI_Point2D> anInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                                  (aData->attribute(LINE_ATTR_END));
+    PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START);
+    PartSet_Tools::setFeaturePoint(feature(), anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END);
+
+    aData = feature()->data();
+    boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                                 (aData->attribute(LINE_ATTR_START));
+    PartSet_Tools::createConstraint(sketch(), anInitPoint, aPoint);
+  }
+}
+
+PartSet_SelectionMode PartSet_FeatureCirclePrs::setPoint(double theX, double theY,
+                                                       const PartSet_SelectionMode& theMode)
+{
+  PartSet_SelectionMode aMode = theMode;
+  switch (theMode)
+  {
+    case SM_FirstPoint: {
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_START);
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+      aMode = SM_SecondPoint;
+    }
+    break;
+    case SM_SecondPoint: {
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+      aMode = SM_DonePoint;
+   }
+    break;
+    default:
+      break;
+  }
+  return aMode;
+}
+
+std::string PartSet_FeatureCirclePrs::getAttribute(const PartSet_SelectionMode& theMode) const
+{
+  std::string aAttribute;
+  switch (theMode)
+  {
+    case SM_FirstPoint:
+      aAttribute = LINE_ATTR_START;
+    break;
+    case SM_SecondPoint:
+      aAttribute = LINE_ATTR_END;
+    break;
+    default:
+    break;
+  }
+  return aAttribute;
+}
+
+PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& theAttribute) const
+{
+  PartSet_SelectionMode aMode;
+
+  if (theAttribute == LINE_ATTR_START)
+    aMode = SM_SecondPoint;
+  else if (theAttribute == LINE_ATTR_END)
+    aMode = SM_DonePoint;
+  return aMode;
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
+                                                     (const PartSet_SelectionMode& theMode)
+{
+  std::string aPointArg;
+  switch (theMode)
+  {
+    case SM_FirstPoint:
+      aPointArg = LINE_ATTR_START;
+      break;
+    case SM_SecondPoint:
+      aPointArg = LINE_ATTR_END;
+      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;
+}
diff --git a/src/PartSet/PartSet_FeatureCirclePrs.h b/src/PartSet/PartSet_FeatureCirclePrs.h
new file mode 100644 (file)
index 0000000..1e4e680
--- /dev/null
@@ -0,0 +1,57 @@
+// File:        PartSet_FeatureCirclePrs.h
+// Created:     04 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_FeatureCirclePrs_H
+#define PartSet_FeatureCirclePrs_H
+
+#include "PartSet.h"
+
+#include "PartSet_FeaturePrs.h"
+#include "PartSet_Constants.h"
+
+class GeomDataAPI_Point2D;
+
+/*!
+ \class PartSet_FeatureCirclePrs
+ * \brief The abstract class to define the specific feature manipulation. It is created for
+ * the feature create operation to move out the feature properties set and use one operation
+ * for any type of features.
+*/
+class PARTSET_EXPORT PartSet_FeatureCirclePrs : public PartSet_FeaturePrs
+{
+public:
+  /// Constructor
+  /// \param theSketch the sketch feature
+  PartSet_FeatureCirclePrs(FeaturePtr theSketch);
+  /// Destructor
+  virtual ~PartSet_FeatureCirclePrs() {};
+
+  /// 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 9302a0618927474fbb16207ebbf9cd76acc0c0a6..7d5751707a40a97f613130f259a244ecddf58538 100644 (file)
@@ -26,7 +26,6 @@
 #include <XGUI_Tools.h>
 
 #include <SketchPlugin_Line.h>
-#include <SketchPlugin_Point.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -330,7 +329,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 || theCmdId == SKETCH_POINT_KIND)
+    if (PartSet_OperationCreateFeature::canProcessKind(theCmdId))
       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 06931c524967ad4daef05d89ae88135ff970ffe9..7905f6a019ce9cf57343325fec236529db54e10e 100644 (file)
@@ -6,11 +6,14 @@
 
 #include <PartSet_Tools.h>
 #include <PartSet_OperationSketch.h>
-#include <PartSet_FeatureLinePrs.h>
 #include <PartSet_FeaturePointPrs.h>
+#include <PartSet_FeatureLinePrs.h>
+#include <PartSet_FeatureCirclePrs.h>
 
 #include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Point.h>
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Circle.h>
 
 #include <ModuleBase_OperationDescription.h>
 
@@ -36,11 +39,16 @@ PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& th
 : PartSet_OperationSketchBase(theId, theParent),
   myPointSelectionMode(SM_FirstPoint)
 {
-  if (theId.toStdString() == SKETCH_LINE_KIND) {
+  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 {
-    myFeaturePrs = new PartSet_FeaturePointPrs(theFeature);
+  else if (aKind == SKETCH_CIRCLE_KIND) {
+    myFeaturePrs = new PartSet_FeatureCirclePrs(theFeature);
   }
 }
 
@@ -49,6 +57,11 @@ PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
   delete myFeaturePrs;
 }
 
+bool PartSet_OperationCreateFeature::canProcessKind(const std::string& theId)
+{
+  return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND;
+}
+
 bool PartSet_OperationCreateFeature::canBeCommitted() const
 {
   return myPointSelectionMode == SM_DonePoint;
index acea5a01e8a4b8479d926cc5970cc77f30b5b67f..1eb352dd10f5eb369a49df4374053444fbb1fdda 100644 (file)
@@ -26,6 +26,10 @@ class PARTSET_EXPORT PartSet_OperationCreateFeature : public PartSet_OperationSk
   Q_OBJECT
 
 public:
+  /// Returns true if the feature with the given kind can be created by this operation
+  /// \param theId the feature kind
+  /// \return the boolean result
+  static bool canProcessKind(const std::string& theId);
 
 public:
   /// Constructor
index 89a8e5735c3afc339c6ed105555f5f616c70262d..0d9550b91f479f1eec63f95b429ac67f147aa4ad 100644 (file)
@@ -15,5 +15,6 @@
      <file>icons/sketch.png</file>
      <file>icons/hand_point.png</file>
      <file>icons/dimension_v.png</file>
+     <file>icons/radius.png</file>
  </qresource>
  </RCC>
diff --git a/src/PartSet/icons/radius.png b/src/PartSet/icons/radius.png
new file mode 100644 (file)
index 0000000..6213de3
Binary files /dev/null and b/src/PartSet/icons/radius.png differ
index e9e8a7105f9861369813dfb2637205ca212ef650..f5d7507d3fb82a5b5fa0cfc820c44ebeb808b46e 100644 (file)
@@ -1,7 +1,7 @@
 <plugin>
   <workbench id="Sketch">
     <group id="Basic">
-      <feature id="Sketch" nested="SketchLine SketchPoint SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+      <feature id="Sketch" nested="SketchPoint SketchLine SketchCircle 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>
@@ -12,8 +12,9 @@
         <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"/>
       </feature>
-      <feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon="" internal="1">
+      <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"/>
       </feature>
       <feature id="SketchArc" title="Arc" tooltip="Create a new arc of a circle" icon="" internal="1">
         <point_selector id="ArcCenter" title="Center" tooltip="Center of the arc"/>