]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PartSet/PartSet_FeatureCirclePrs.cpp
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_FeatureCirclePrs.cpp
index 48342d9a60821e8183802c25d97d868ef6450d1f..d825fdd583a5d4d5baf6e07ff9ab5fda031f1fe9 100644 (file)
@@ -7,11 +7,10 @@
 
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Constraint.h>
+#include <SketchPlugin_Circle.h>
 
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
@@ -27,38 +26,25 @@ PartSet_FeatureCirclePrs::PartSet_FeatureCirclePrs(FeaturePtr 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)
+                                                         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);
+      PartSet_Tools::setFeaturePoint(feature(), theX, theY, CIRCLE_ATTR_CENTER);
       aMode = SM_SecondPoint;
     }
     break;
     case SM_SecondPoint: {
-      PartSet_Tools::setFeaturePoint(feature(), theX, theY, LINE_ATTR_END);
+      boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+      boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                                                  (aData->attribute(CIRCLE_ATTR_CENTER));
+      boost::shared_ptr<GeomAPI_Pnt2d> aCoordPoint(new GeomAPI_Pnt2d(theX, theY));
+      double aRadius = aCoordPoint->distance(aPoint->pnt());
+      PartSet_Tools::setFeatureValue(feature(), aRadius, CIRCLE_ATTR_RADIUS);
+
       aMode = SM_DonePoint;
    }
     break;
@@ -74,10 +60,10 @@ std::string PartSet_FeatureCirclePrs::getAttribute(const PartSet_SelectionMode&
   switch (theMode)
   {
     case SM_FirstPoint:
-      aAttribute = LINE_ATTR_START;
+      aAttribute = CIRCLE_ATTR_CENTER;
     break;
     case SM_SecondPoint:
-      aAttribute = LINE_ATTR_END;
+      aAttribute = CIRCLE_ATTR_RADIUS;
     break;
     default:
     break;
@@ -89,9 +75,9 @@ PartSet_SelectionMode PartSet_FeatureCirclePrs::getNextMode(const std::string& t
 {
   PartSet_SelectionMode aMode;
 
-  if (theAttribute == LINE_ATTR_START)
+  if (theAttribute == CIRCLE_ATTR_CENTER)
     aMode = SM_SecondPoint;
-  else if (theAttribute == LINE_ATTR_END)
+  else if (theAttribute == CIRCLE_ATTR_RADIUS)
     aMode = SM_DonePoint;
   return aMode;
 }
@@ -103,10 +89,7 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureCirclePrs::featurePoint
   switch (theMode)
   {
     case SM_FirstPoint:
-      aPointArg = LINE_ATTR_START;
-      break;
-    case SM_SecondPoint:
-      aPointArg = LINE_ATTR_END;
+      aPointArg = CIRCLE_ATTR_CENTER;
       break;
     default:
       break;