]> 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 11:37:24 +0000 (15:37 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 5 Jun 2014 11:37:24 +0000 (15:37 +0400)
Move all line specific information to FeatureLinePrs. Prepare FeaturePointPrs for the point feature.

12 files changed:
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_FeatureLinePrs.cpp [new file with mode: 0644]
src/PartSet/PartSet_FeatureLinePrs.h [new file with mode: 0644]
src/PartSet/PartSet_FeaturePointPrs.cpp [new file with mode: 0644]
src/PartSet/PartSet_FeaturePointPrs.h [new file with mode: 0644]
src/PartSet/PartSet_FeaturePrs.cpp
src/PartSet/PartSet_FeaturePrs.h
src/PartSet/PartSet_OperationConstraint.cpp
src/PartSet/PartSet_OperationCreateFeature.cpp
src/PartSet/PartSet_TestOCC.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h

index fe69c3399ad643009c59053c863665e4c553f630..f8629de870fdbcb268184c21258f30c65a19810e 100644 (file)
@@ -6,6 +6,8 @@ SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Constants.h
        PartSet_FeaturePrs.h
+       PartSet_FeatureLinePrs.h
+       PartSet_FeaturePointPrs.h
        PartSet_Listener.h
        PartSet_Module.h
        PartSet_OperationConstraint.h
@@ -20,6 +22,8 @@ SET(PROJECT_HEADERS
 
 SET(PROJECT_SOURCES
        PartSet_FeaturePrs.cpp
+       PartSet_FeatureLinePrs.cpp
+       PartSet_FeaturePointPrs.cpp
        PartSet_Listener.cpp
        PartSet_Module.cpp
        PartSet_OperationConstraint.cpp
diff --git a/src/PartSet/PartSet_FeatureLinePrs.cpp b/src/PartSet/PartSet_FeatureLinePrs.cpp
new file mode 100644 (file)
index 0000000..5e67aae
--- /dev/null
@@ -0,0 +1,118 @@
+// File:        PartSet_FeaturePrs.h
+// Created:     04 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_FeatureLinePrs.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_FeatureLinePrs::PartSet_FeatureLinePrs(FeaturePtr theSketch)
+: PartSet_FeaturePrs(theSketch)
+{
+}
+
+void PartSet_FeatureLinePrs::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_FeatureLinePrs::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_FeatureLinePrs::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_FeatureLinePrs::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_FeatureLinePrs::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_FeatureLinePrs.h b/src/PartSet/PartSet_FeatureLinePrs.h
new file mode 100644 (file)
index 0000000..a2ff5bb
--- /dev/null
@@ -0,0 +1,57 @@
+// File:        PartSet_FeatureLinePrs.h
+// Created:     04 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_FeatureLinePrs_H
+#define PartSet_FeatureLinePrs_H
+
+#include "PartSet.h"
+
+#include "PartSet_FeaturePrs.h"
+#include "PartSet_Constants.h"
+
+class GeomDataAPI_Point2D;
+
+/*!
+ \class PartSet_FeatureLinePrs
+ * \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_FeatureLinePrs : public PartSet_FeaturePrs
+{
+public:
+  /// Constructor
+  /// \param theSketch the sketch feature
+  PartSet_FeatureLinePrs(FeaturePtr theSketch);
+  /// Destructor
+  virtual ~PartSet_FeatureLinePrs() {};
+
+  /// 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
diff --git a/src/PartSet/PartSet_FeaturePointPrs.cpp b/src/PartSet/PartSet_FeaturePointPrs.cpp
new file mode 100644 (file)
index 0000000..18db26a
--- /dev/null
@@ -0,0 +1,31 @@
+// File:        PartSet_FeaturePointPrs.h
+// Created:     04 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#include <PartSet_FeaturePointPrs.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_FeaturePointPrs::PartSet_FeaturePointPrs(FeaturePtr theFeature)
+{
+}
+
+PartSet_FeaturePointPrs::~PartSet_FeaturePointPrs()
+{
+}
diff --git a/src/PartSet/PartSet_FeaturePointPrs.h b/src/PartSet/PartSet_FeaturePointPrs.h
new file mode 100644 (file)
index 0000000..b43de80
--- /dev/null
@@ -0,0 +1,30 @@
+// File:        PartSet_FeaturePointPrs.h
+// Created:     04 Jun 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_FeaturePointPrs_H
+#define PartSet_FeaturePointPrs_H
+
+#include "PartSet.h"
+
+#include "PartSet_Constants.h"
+
+class GeomDataAPI_Point2D;
+
+/*!
+ \class PartSet_FeaturePointPrs
+ * \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_FeaturePointPrs
+{
+public:
+  /// Constructor
+  /// \param theSketch the sketch feature
+  PartSet_FeaturePointPrs(FeaturePtr theSketch);
+  /// Destructor
+  virtual ~PartSet_FeaturePointPrs();
+};
+
+#endif
index 434dd94e4da34223312531e8f51e2c34e150cb09..4712baf3a09821f0e6e7afe9db177d098fb6469d 100644 (file)
@@ -3,12 +3,10 @@
 // Author:      Natalia ERMOLAEVA
 
 #include <PartSet_FeaturePrs.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>
 
@@ -33,192 +31,40 @@ PartSet_FeaturePrs::~PartSet_FeaturePrs()
 void PartSet_FeaturePrs::init(FeaturePtr theFeature, FeaturePtr theSourceFeature)
 {
   myFeature = theFeature;
-  if (theSourceFeature)
-  {
-    // use the last point of the previous feature as the first of the new one
-    boost::shared_ptr<ModelAPI_Data> aData = theSourceFeature->data();
-    boost::shared_ptr<GeomDataAPI_Point2D> anInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                                                  (aData->attribute(LINE_ATTR_END));
-    setLinePoint(theFeature, anInitPoint->x(), anInitPoint->y(), LINE_ATTR_START);
-    setLinePoint(theFeature, anInitPoint->x(), anInitPoint->y(), LINE_ATTR_END);
-
-    aData = theFeature->data();
-    boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                                                 (aData->attribute(LINE_ATTR_START));
-    createConstraint(anInitPoint, aPoint);
+  if (theSourceFeature) {
+    initFeature(theSourceFeature);
   }
 }
 
-boost::shared_ptr<ModelAPI_Document> PartSet_FeaturePrs::document() const
-{
-  return ModelAPI_PluginManager::get()->rootDocument();
-}
-
 FeaturePtr PartSet_FeaturePrs::sketch() const
 {
   return mySketch;
 }
 
-PartSet_SelectionMode PartSet_FeaturePrs::setPoint(double theX, double theY,
-                                                   const PartSet_SelectionMode& theMode)
-{
-  PartSet_SelectionMode aMode = theMode;
-  switch (theMode)
-  {
-    case SM_FirstPoint: {
-      setLinePoint(feature(), theX, theY, LINE_ATTR_START);
-      setLinePoint(feature(), theX, theY, LINE_ATTR_END);
-      aMode = SM_SecondPoint;
-    }
-    break;
-    case SM_SecondPoint: {
-      setLinePoint(feature(), theX, theY, LINE_ATTR_END);
-      aMode = SM_DonePoint;
-   }
-    break;
-    default:
-      break;
-  }
-  return aMode;
-}
-
 FeaturePtr PartSet_FeaturePrs::feature() const
 {
   return myFeature;
 }
 
-void PartSet_FeaturePrs::createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
-                                          boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
-{
-  boost::shared_ptr<ModelAPI_Document> aDoc = document();
-  FeaturePtr aFeature = aDoc->addFeature(SKETCH_CONSTRAINT_COINCIDENCE_KIND);
-
-  if (sketch()) {
-    boost::shared_ptr<SketchPlugin_Feature> aSketch = 
-                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
-    aSketch->addSub(aFeature);
-  }
-
-  boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
-
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 =
-        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
-  aRef1->setAttr(thePoint1);
-
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 =
-        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
-  aRef2->setAttr(thePoint2);
-
-  if (aFeature) // TODO: generate an error if feature was not created
-    aFeature->execute();
-}
-
 void PartSet_FeaturePrs::setConstraints(double theX, double theY,
                                         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;
-  }
+  // find a feature point by the selection mode
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = featurePoint(theMode);
 
-  FeaturePtr aSkFeature = feature();
-
-  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                                              (aData->attribute(aPointArg));
-  aData = sketch()->data();
+  // 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++) {
+  std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+  for (; anIt != aLast; anIt++)
+  {
     FeaturePtr aFeature = *anIt;
-    boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = findLinePoint(aFeature, theX, theY);
+    boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = PartSet_Tools::findPoint(aFeature, theX, theY);
     if (aFPoint)
-      createConstraint(aFPoint, aPoint);
+      PartSet_Tools::createConstraint(sketch(), aFPoint, aPoint);
   }
 }
-
-std::string PartSet_FeaturePrs::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_FeaturePrs::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;
-}
-
-void PartSet_FeaturePrs::getLinePoint(FeaturePtr theFeature,
-                                               const std::string& theAttribute,
-                                               double& theX, double& theY)
-{
-  if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
-    return;
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
-  theX = aPoint->x();
-  theY = aPoint->y();
-}
-
-boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeaturePrs::findLinePoint(
-                                               FeaturePtr theFeature,
-                                               double theX, double theY)
-{
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
-  if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
-    return aPoint2D;
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
-  if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
-    aPoint2D = aPoint;
-  else {
-    aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-    if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
-      aPoint2D = aPoint;
-  }
-  return aPoint2D;
-}
-
-void PartSet_FeaturePrs::setLinePoint(FeaturePtr theFeature,
-                                               double theX, double theY,
-                                               const std::string& theAttribute)
-{
-  if (!theFeature)
-    return;
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
-  aPoint->setValue(theX, theY);
-}
index 0a285f522e2d4b7d5bb7b9963e215f7d894014c2..4a602d2248ed627919abb6c4efe300aed9362bbb 100644 (file)
@@ -30,7 +30,7 @@ public:
   /// Saves the fiature as the presentation internal feature
   /// \param theFeature the presentation feature
   /// \param theSourceFeature the feature, which attributes are used to initialize the feature
-  virtual void init(FeaturePtr theFeature, FeaturePtr theSourceFeature);
+  void init(FeaturePtr theFeature, FeaturePtr theSourceFeature);
 
   /// Returns the operation sketch feature
   /// \returns the sketch instance
@@ -41,58 +41,36 @@ public:
   /// \param theY the 2D point vertical coordinate
   /// \param theMode the selection mode
   /// \return the new selection mode
-  PartSet_SelectionMode setPoint(double theX, double theY, const PartSet_SelectionMode& theMode);
-
-  /// 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);
+  virtual PartSet_SelectionMode setPoint(double theX, double theY,
+                                         const PartSet_SelectionMode& theMode) = 0;
 
   /// Returns the feature attribute name for the selection mode
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
-  std::string getAttribute(const PartSet_SelectionMode& theMode) const;
+  virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const = 0;
 
   /// Returns the next selection mode after the attribute
   /// \param theAttribute the feature attribute name
   /// \return next attribute selection mode
-  PartSet_SelectionMode getNextMode(const std::string& theAttribute) const;
+  virtual PartSet_SelectionMode getNextMode(const std::string& theAttribute) const = 0;
 
-  /// \brief Save the point to the line.
-  /// \param theFeature the line feature
-  /// \param theX the horizontal coordinate
-  /// \param theY the vertical coordinate
-  /// \param theAttribute the start or end attribute of the line
-  static void setLinePoint(FeaturePtr, double theX, double theY,
-                           const std::string& theAttribute);
+  /// 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 pointer to the root document.
-  boost::shared_ptr<ModelAPI_Document> document() const;
-
-    /// Returns the operation feature
+  /// Returns the operation feature
   /// \return the feature
   FeaturePtr feature() const;
 
-  /// Creates a constraint on two points
-  /// \param thePoint1 the first point
-  /// \param thePoint1 the second point
-  void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
-                        boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
-
-  /// \brief Get the line point 2d coordinates.
-  /// \param theFeature the line feature
-  /// \param theAttribute the start or end attribute of the line
-  /// \param theX the horizontal coordinate
-  /// \param theY the vertical coordinate
-  void getLinePoint(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
-  /// \param theY the vertical point coordinate
-  boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(FeaturePtr theFeature,
-                                                       double theX, double theY);
+  /// Initializes current feature by the given
+  /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
+  virtual void initFeature(FeaturePtr theSourceFeature) = 0;
+
+  /// 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) = 0;
 
 private:
   FeaturePtr mySketch; ///< the sketch of the feature
index 6c65c0eaca5da203065b6de115fd3c6596270868..447f7a4d30b34bb094e5d087dc81876a627b4c3a 100644 (file)
@@ -124,8 +124,8 @@ void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3
         if (aFeature) {
           double X0, X1, X2, X3;
           double Y0, Y1, Y2, Y3;
-          getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
-          getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
+          PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
+          PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
           PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1);
 
           switch (myPointSelectionMode) {
@@ -133,7 +133,7 @@ void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3
               PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
             break;
             case SM_SecondPoint: {
-              getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+              PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
               PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
             }
             break;
@@ -242,7 +242,7 @@ FeaturePtr PartSet_OperationConstraint::createFeature(const bool theFlushMessage
     boost::shared_ptr<ModelAPI_Data> aData = aNewFeature->data();
     boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
                                                                 (aData->attribute(LINE_ATTR_START));
-    createConstraint(myInitPoint, aPoint);
+    PartSet_Tools::createConstraint(myInitPoint, aPoint);
   }*/
 
   emit featureConstructed(aNewFeature, FM_Activation);
index 1d904459278e0cee954b0311956c8dd0aa3b684a..60a5ded04067ef9dd7d777d5b865931e0b2441b6 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <PartSet_Tools.h>
 #include <PartSet_OperationSketch.h>
-#include <PartSet_FeaturePrs.h>
+#include <PartSet_FeatureLinePrs.h>
 
 #include <SketchPlugin_Feature.h>
 
@@ -34,7 +34,7 @@ PartSet_OperationCreateFeature::PartSet_OperationCreateFeature(const QString& th
 : PartSet_OperationSketchBase(theId, theParent),
   myPointSelectionMode(SM_FirstPoint)
 {
-  myFeaturePrs = new PartSet_FeaturePrs(theFeature);
+  myFeaturePrs = new PartSet_FeatureLinePrs(theFeature);
 }
 
 PartSet_OperationCreateFeature::~PartSet_OperationCreateFeature()
@@ -110,14 +110,17 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
           myFeaturePrs->setConstraints(aX, anY, myPointSelectionMode);
         }
       }
-      /*else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
+      else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
       {
+        PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
+        isFoundPoint = true;
+        /*
         FeaturePtr aFeature = aPrs.feature();
         if (aFeature) {
           double X0, X1, X2, X3;
           double Y0, Y1, Y2, Y3;
-          getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
-          getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
+          PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
+          PartSet_Tools::getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
           PartSet_Tools::convertTo2D(aPoint, sketch(), theView, X1, Y1);
 
           switch (myPointSelectionMode) {
@@ -125,7 +128,7 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
               PartSet_Tools::projectPointOnLine(X2, Y2, X3, Y3, X1, Y1, aX, anY);
             break;
             case SM_SecondPoint: {
-              getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
+              PartSet_Tools::getLinePoint(feature(), LINE_ATTR_START, X0, Y0);
               PartSet_Tools::intersectLines(X0, Y0, X1, Y1, X2, Y2, X3, Y3, aX, anY);
             }
             break;
@@ -134,7 +137,8 @@ void PartSet_OperationCreateFeature::mouseReleased(QMouseEvent* theEvent, Handle
           }
           isFoundPoint = true;
         }
-      }*/
+        */
+      }
     }
   }
 
index ef0ea9a751c6a52df8850d1fd16c5a85c08cd61a..9de46957036ce667977f75df99f1c8b66c18f65e 100644 (file)
@@ -11,6 +11,7 @@
 #include <XGUI_ViewerProxy.h>
 #include <PartSet_FeaturePrs.h>
 #include <PartSet_Presentation.h>
+#include <PartSet_Tools.h>
 #include <PartSet_OperationSketchBase.h>
 
 #include <ModelAPI_Feature.h>
@@ -141,8 +142,8 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
                         boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPreviewOp->sketch());
     aSketch->addSub(aFeature);
 
-    PartSet_FeaturePrs::setLinePoint(aFeature, 100, 100, LINE_ATTR_START);
-    PartSet_FeaturePrs::setLinePoint(aFeature, 150, 300, LINE_ATTR_END);
+    PartSet_Tools::setFeaturePoint(aFeature, 100, 100, LINE_ATTR_START);
+    PartSet_Tools::setFeaturePoint(aFeature, 150, 300, LINE_ATTR_END);
 
     boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
 
@@ -163,8 +164,8 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
     /*double aDelta = -200;
     for (int i = 0; i < 20; i++) {
       aDelta = aDelta - i*2;
-      PartSet_FeaturePrs::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
-      PartSet_FeaturePrs::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
+      PartSet_Tools::setFeaturePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
+      PartSet_Tools::setFeaturePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
 
       boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
       Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
@@ -199,8 +200,8 @@ void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop)
 
   myTestDelta = myTestDelta - 50;
   double aDelta = myTestDelta;
-  PartSet_FeaturePrs::setLinePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
-  PartSet_FeaturePrs::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
+  PartSet_Tools::setFeaturePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
+  PartSet_Tools::setFeaturePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
   boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
 
   Handle(AIS_InteractiveObject) aPrevAIS;
index ae51d7b20a6d788ba94f9861169852ba8fe787e1..265a3b26bfd3dfb52dc09a7a5b161014f022e65c 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Document.h>
 
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_XYZ.h>
 
+#include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_Constraint.h>
 
 #include <XGUI_ViewerPrs.h>
 
@@ -216,3 +220,82 @@ double PartSet_Tools::distanceToPoint(FeaturePtr theFeature,
 
   return aDelta;
 }
+
+boost::shared_ptr<ModelAPI_Document> PartSet_Tools::document()
+{
+  return ModelAPI_PluginManager::get()->rootDocument();
+}
+
+void PartSet_Tools::setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
+                                    const std::string& theAttribute)
+{
+  if (!theFeature)
+    return;
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+  if (aPoint)
+    aPoint->setValue(theX, theY);
+}
+
+void PartSet_Tools::createConstraint(FeaturePtr theSketch,
+                                     boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
+                                     boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
+{
+  boost::shared_ptr<ModelAPI_Document> aDoc = document();
+  FeaturePtr aFeature = aDoc->addFeature(SKETCH_CONSTRAINT_COINCIDENCE_KIND);
+
+  if (theSketch) {
+    boost::shared_ptr<SketchPlugin_Feature> aSketch = 
+                           boost::dynamic_pointer_cast<SketchPlugin_Feature>(theSketch);
+    aSketch->addSub(aFeature);
+  }
+
+  boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  aRef1->setAttr(thePoint1);
+
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+  aRef2->setAttr(thePoint2);
+
+  if (aFeature) // TODO: generate an error if feature was not created
+    aFeature->execute();
+}
+
+void PartSet_Tools::getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
+                                 double& theX, double& theY)
+{
+  if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+    return;
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+  theX = aPoint->x();
+  theY = aPoint->y();
+}
+
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::findPoint(FeaturePtr theFeature,
+                                                                double theX, double theY)
+{
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
+  if (!theFeature)
+    return aPoint2D;
+
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  if (theFeature->getKind() == SKETCH_LINE_KIND)
+  {
+    boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+          boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+    if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+      aPoint2D = aPoint;
+    else {
+      aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+      if (fabs(aPoint->x() - theX) < Precision::Confusion() && fabs(aPoint->y() - theY) < Precision::Confusion() )
+        aPoint2D = aPoint;
+    }
+  }
+  return aPoint2D;
+}
index c8fa3066094b9a748b11716dfd5b6e9251ad1a88..ac55abbb26ed35b40af1ed95694ac2ba922f3fc8 100644 (file)
@@ -19,6 +19,7 @@
 
 class Handle_V3d_View;
 class XGUI_ViewerPrs;
+class GeomDataAPI_Point2D;
 
 /*!
  \class PartSet_Tools
@@ -45,8 +46,7 @@ public:
   /// \param theY the Y coordinate
   /// \param theSketch the sketch feature
   /// \param thePoint the 3D point in the viewer
-  static void convertTo3D(const double theX, const double theY,
-                          FeaturePtr theSketch,
+  static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
                           gp_Pnt& thePoint);
 
   /// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3),
@@ -80,16 +80,46 @@ public:
   /// \param theView a 3D view
   /// \param theSketch the sketch feature
   /// \param theFeatures the list of selected presentations
-  static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView,
-                                                     FeaturePtr theSketch,
-                                                     const std::list<XGUI_ViewerPrs>& theFeatures);
+  static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
+                                   const std::list<XGUI_ViewerPrs>& theFeatures);
+
+  /// Returns pointer to the root document.
+  static boost::shared_ptr<ModelAPI_Document> document();
+
+  /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
+  /// \param theFeature the feature
+  /// \param theX the horizontal coordinate
+  /// \param theY the vertical coordinate
+  /// \param theAttribute the feature attribute
+  static void setFeaturePoint(FeaturePtr, double theX, double theY, const std::string& theAttribute);
+
+    /// Creates a constraint on two points
+  /// \param thePoint1 the first point
+  /// \param thePoint1 the second point
+  static void createConstraint(FeaturePtr theSketch,
+                               boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
+                               boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
+
+  /// \brief Get the line point 2d coordinates.
+  /// \param theFeature the line feature
+  /// \param theAttribute the start or end attribute of the line
+  /// \param theX the horizontal coordinate
+  /// \param theY the vertical coordinate
+  static void getLinePoint(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
+  /// \param theY the vertical point coordinate
+  static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
+                                                          double theY);
+
 private:
   /// Return the distance between the feature and the point
   /// \param theFeature feature object
   /// \param theX the horizontal coordinate of the point
   /// \param theX the vertical coordinate of the point
-  static double distanceToPoint(FeaturePtr theFeature,
-                                double theX, double theY);
+  static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
 };
 
 #endif