]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Tue, 13 May 2014 12:27:26 +0000 (16:27 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 13 May 2014 12:27:26 +0000 (16:27 +0400)
Create constraint on selected point. Search features contained this point and create constraints with them.

src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h

index 9235348a7f68f2fdbf6bac9dd651800fdde95f1f..6baec986ba39e33eafc782d074e307fd88eb242d 100644 (file)
@@ -7,10 +7,13 @@
 #include <PartSet_Tools.h>
 
 #include <SketchPlugin_Feature.h>
+#include <SketchPlugin_Sketch.h>
+
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
 
 #include <SketchPlugin_Constraint.h>
 
@@ -53,7 +56,13 @@ bool PartSet_OperationSketchLine::isGranted() const
 
 std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
 {
-  return std::list<int>();
+  std::list<int> aModes;
+  if (theFeature != feature())
+  {
+    aModes.push_back(TopAbs_VERTEX);
+    aModes.push_back(TopAbs_EDGE);
+  }
+  return aModes;
 }
 
 void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature)
@@ -84,6 +93,8 @@ void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3
         if (!aVertex.IsNull()) {
           aPoint = BRep_Tool::Pnt(aVertex);
           PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+
+          setConstraints(aX, anY);
         }
       }
       else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
@@ -197,7 +208,7 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
                                                                 (aData->attribute(LINE_ATTR_START));
     aPoint->setValue(myInitPoint->x(), myInitPoint->y());
 
-    //createConstraint(myInitPoint, aPoint);
+    createConstraint(myInitPoint, aPoint);
   }
 
   emit featureConstructed(aNewFeature, FM_Activation);
@@ -224,6 +235,37 @@ void PartSet_OperationSketchLine::createConstraint(boost::shared_ptr<GeomDataAPI
     aFeature->execute();
 }
 
+void PartSet_OperationSketchLine::setConstraints(double theX, double theY)
+{
+  std::string aPointArg;
+  switch (myPointSelectionMode)
+  {
+    case SM_FirstPoint:
+      aPointArg = LINE_ATTR_START;
+      break;
+    case SM_SecondPoint:
+      aPointArg = LINE_ATTR_END;
+      break;
+  }
+
+  boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                              (aData->attribute(aPointArg));
+  aData = mySketch->data();
+  boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
+        boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
+
+  std::list<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aRefList->list();
+  std::list<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
+                                                                  aLast = aFeatures.end();
+  for (; anIt != aLast; anIt++) {
+    boost::shared_ptr<ModelAPI_Feature> aFeature = *anIt;
+    boost::shared_ptr<GeomDataAPI_Point2D> aFPoint = findLinePoint(aFeature, theX, theY);
+    if (aFPoint)
+      createConstraint(aFPoint, aPoint);
+  }
+}
+
 void PartSet_OperationSketchLine::getLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
                                                const std::string& theAttribute,
                                                double& theX, double& theY)
@@ -237,6 +279,27 @@ void PartSet_OperationSketchLine::getLinePoint(boost::shared_ptr<ModelAPI_Featur
   theY = aPoint->y();
 }
 
+boost::shared_ptr<GeomDataAPI_Point2D> PartSet_OperationSketchLine::findLinePoint(
+                                               boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                               double theX, double theY)
+{
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint2D;
+  if (!theFeature)
+    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_OperationSketchLine::setLinePoint(double theX, double theY,
                                                const std::string& theAttribute)
 {
index d92224aaab9621a1a760f4f608dd55253cc40d31..c06462d7a50be8d57ca010e09198db29aad83824 100644 (file)
@@ -88,6 +88,10 @@ protected:
   void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
                         boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
 
+  /// Creates constrains of the current 
+  /// \param theX the horizontal coordnate of the point
+  /// \param theY the vertical coordnate of the point
+  void setConstraints(double theX, double theY);
 protected:
   /// \brief Get the line point 2d coordinates.
   /// \param theFeature the line feature
@@ -96,6 +100,13 @@ protected:
   /// \param theY the vertical coordinate
   void getLinePoint(boost::shared_ptr<ModelAPI_Feature> 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(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                                       double theX, double theY);
+
   /// \brief Save the point to the line.
   /// \param theX the horizontal coordinate
   /// \param theY the vertical coordinate