]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2024: Redesign of circle and arc of circle
authordbv <dbv@opencascade.com>
Fri, 24 Mar 2017 14:04:06 +0000 (17:04 +0300)
committerdbv <dbv@opencascade.com>
Mon, 27 Mar 2017 06:56:56 +0000 (09:56 +0300)
Redesigned "real" arc feature.

src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_MacroArc.cpp

index e752c7be1f45e5a92b2b6cb08a3b8a623173cea3..9ebf16eb34205e343f114a511be0a5eb0e9ba60f 100644 (file)
@@ -192,13 +192,52 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID)
         aCirc->parameter(anEdge->lastPoint(), paramTolerance, anEndParam);
         aWasBlocked = data()->blockSendAttributeUpdated(true);
         if(aStartParam < aMidParam && aMidParam < anEndParam) {
-          setReversed(true);
-        } else {
           setReversed(false);
+        } else {
+          setReversed(true);
         }
         data()->blockSendAttributeUpdated(aWasBlocked, false);
       }
     }
+  } else if(theID == CENTER_ID() || theID == START_ID() || theID == END_ID()) {
+    if(!aCenterAttr->isInitialized()
+      || !aStartAttr->isInitialized()
+      || !anEndAttr->isInitialized()) {
+      return;
+    }
+    std::shared_ptr<GeomAPI_Pnt2d> aCenter = aCenterAttr->pnt();
+    std::shared_ptr<GeomAPI_Pnt2d> aStart = aStartAttr->pnt();
+    std::shared_ptr<GeomAPI_Pnt2d> anEnd = anEndAttr->pnt();
+    double aRadius = aCenter->distance(aStart);
+    if (aRadius < tolerance)
+      return;
+    std::shared_ptr<GeomAPI_Circ2d> aCircleForArc(new GeomAPI_Circ2d(aCenter, aStart));
+
+    bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+    // The Arc end point is projected
+    // on the circle formed by center and start points
+    std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEnd);
+    if (aProjection && anEnd->distance(aProjection) > tolerance) {
+      anEndAttr->setValue(aProjection);
+      anEnd = aProjection;
+    }
+    data()->blockSendAttributeUpdated(aWasBlocked, false);
+
+    double aParameterNew = 0.0;
+    if(aCircleForArc->parameter(anEnd, paramTolerance, aParameterNew)) {
+      bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+      if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) {
+        if(!boolean(REVERSED_ID())->value()) {
+          boolean(REVERSED_ID())->setValue(true);
+        }
+      } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) {
+        if(boolean(REVERSED_ID())->value()) {
+          boolean(REVERSED_ID())->setValue(false);
+        }
+      }
+      data()->blockSendAttributeUpdated(aWasBlocked, false);
+    }
+    myParamBefore = aParameterNew;
   }
 
   double aRadius = 0;
index a5572566b87f60e636ad5b002554cc4f40c2ff18..6528ca24700a6a5e2f9188f3079b8dee232fa154 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "SketchPlugin_MacroArc.h"
 
+#include "SketchPlugin_Arc.h"
 #include "SketchPlugin_Sketch.h"
 #include "SketchPlugin_Tools.h"
 
@@ -333,4 +334,61 @@ AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
 
 void SketchPlugin_MacroArc::execute()
 {
+  // Create arc feature.
+  FeaturePtr anArcFeature = sketch()->addFeature(SketchPlugin_Arc::ID());
+  std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenter);
+  std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      anArcFeature->attribute(SketchPlugin_Arc::START_ID()))->setValue(myStart);
+  std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      anArcFeature->attribute(SketchPlugin_Arc::END_ID()))->setValue(myEnd);
+  anArcFeature->boolean(SketchPlugin_Arc::REVERSED_ID())
+    ->setValue(boolean(REVERSED_ID())->value());
+  anArcFeature->execute();
+
+  myCenter.reset();
+  myStart.reset();
+  myEnd.reset();
+
+  // Create constraints.
+  std::string anArcType = string(ARC_TYPE())->value();
+  if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
+    SketchPlugin_Tools::createConstraint(this,
+                                         CENTER_POINT_REF_ID(),
+                                         anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
+                                         ObjectPtr(),
+                                         false);
+    SketchPlugin_Tools::createConstraint(this,
+                                         START_POINT_REF_ID(),
+                                         anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
+                                         ObjectPtr(),
+                                         false);
+    SketchPlugin_Tools::createConstraint(this,
+                                         END_POINT_REF_ID(),
+                                         anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
+                                         ObjectPtr(),
+                                         false);
+  } else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) {
+    SketchPlugin_Tools::createConstraint(this,
+                                         START_POINT_REF_ID(),
+                                         anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
+                                         ObjectPtr(),
+                                         false);
+    SketchPlugin_Tools::createConstraint(this,
+                                         END_POINT_REF_ID(),
+                                         anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
+                                         ObjectPtr(),
+                                         false);
+    SketchPlugin_Tools::createConstraint(this,
+                                         PASSED_POINT_REF_ID(),
+                                         AttributePtr(),
+                                         anArcFeature->lastResult(),
+                                         true);
+  } else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
+    SketchPlugin_Tools::createConstraint(this,
+                                         END_POINT_REF_ID(),
+                                         anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
+                                         ObjectPtr(),
+                                         false);
+  }
 }