Salome HOME
Issue #2024: Redesign of circle and arc of circle
authordbv <dbv@opencascade.com>
Thu, 23 Mar 2017 14:44:10 +0000 (17:44 +0300)
committerdbv <dbv@opencascade.com>
Mon, 27 Mar 2017 06:56:54 +0000 (09:56 +0300)
Initial arc redesign commit.

src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_MacroArc.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_MacroArc.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_MacroCircle.cpp
src/SketchPlugin/SketchPlugin_MacroCircle.h
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Tools.cpp
src/SketchPlugin/SketchPlugin_Tools.h
src/SketchPlugin/plugin-Sketch.xml

index 614dd0d299401bda5ddd0d84e89d3af0566e41ee..c264c51926b6de6746a9644264358a67e4d6ec46 100644 (file)
@@ -30,6 +30,7 @@ SET(PROJECT_HEADERS
     SketchPlugin_Feature.h
     SketchPlugin_IntersectionPoint.h
     SketchPlugin_Line.h
+    SketchPlugin_MacroArc.h
     SketchPlugin_MacroCircle.h
     SketchPlugin_MultiRotation.h
     SketchPlugin_MultiTranslation.h
@@ -69,6 +70,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_Feature.cpp
     SketchPlugin_IntersectionPoint.cpp
     SketchPlugin_Line.cpp
+    SketchPlugin_MacroArc.cpp
     SketchPlugin_MacroCircle.cpp
     SketchPlugin_MultiRotation.cpp
     SketchPlugin_MultiTranslation.cpp
diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.cpp b/src/SketchPlugin/SketchPlugin_MacroArc.cpp
new file mode 100644 (file)
index 0000000..3813264
--- /dev/null
@@ -0,0 +1,333 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchPlugin_MacroArc.cpp
+// Created:     26 Apr 2014
+// Author:      Artem ZHIDKOV
+
+#include "SketchPlugin_MacroArc.h"
+
+#include "SketchPlugin_Sketch.h"
+#include "SketchPlugin_Tools.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_XY.h>
+
+#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+// for sqrt on Linux
+#include <math.h>
+
+const double tolerance = 1e-7;
+const double paramTolerance = 1.e-4;
+const double PI = 3.141592653589793238463;
+
+
+SketchPlugin_MacroArc::SketchPlugin_MacroArc()
+: SketchPlugin_SketchEntity(),
+  myIsInversed(false),
+  myParamBefore(0.0)
+{
+}
+
+void SketchPlugin_MacroArc::initAttributes()
+{
+  data()->addAttribute(ARC_TYPE(), ModelAPI_AttributeString::typeId());
+
+  data()->addAttribute(CENTER_POINT_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(START_POINT_1_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(END_POINT_1_ID(), GeomDataAPI_Point2D::typeId());
+
+  data()->addAttribute(START_POINT_2_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(END_POINT_2_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId());
+
+  data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(END_POINT_3_ID(), GeomDataAPI_Point2D::typeId());
+
+  data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
+
+  data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
+
+  data()->addAttribute(CENTER_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(START_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(END_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(PASSED_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), START_POINT_REF_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), END_POINT_REF_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID());
+}
+
+void SketchPlugin_MacroArc::attributeChanged(const std::string& theID)
+{
+  std::string anArcType = string(ARC_TYPE())->value();
+
+  // If arc type switched reset according attributes.
+  if(theID == ARC_TYPE()) {
+    std::string aType = string(ARC_TYPE())->value();
+    if(aType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
+      SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_REF_ID());
+      SketchPlugin_Tools::resetAttribute(this, START_POINT_1_ID());
+      SketchPlugin_Tools::resetAttribute(this, START_POINT_REF_ID());
+      SketchPlugin_Tools::resetAttribute(this, END_POINT_1_ID());
+      SketchPlugin_Tools::resetAttribute(this, END_POINT_REF_ID());
+    } else if(aType == ARC_TYPE_BY_THREE_POINTS()) {
+      SketchPlugin_Tools::resetAttribute(this, START_POINT_2_ID());
+      SketchPlugin_Tools::resetAttribute(this, START_POINT_REF_ID());
+      SketchPlugin_Tools::resetAttribute(this, END_POINT_2_ID());
+      SketchPlugin_Tools::resetAttribute(this, END_POINT_REF_ID());
+      SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_REF_ID());
+    } else if(aType == ARC_TYPE_BY_TANGENT_EDGE()) {
+      SketchPlugin_Tools::resetAttribute(this, TANGENT_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, END_POINT_3_ID());
+      SketchPlugin_Tools::resetAttribute(this, END_POINT_REF_ID());
+    }
+
+    myCenter.reset();
+    myStart.reset();
+    myEnd.reset();
+    myIsInversed = false;
+    myParamBefore = 0.0;
+  } else if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
+    std::shared_ptr<GeomDataAPI_Point2D> aCenterPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_POINT_ID()));
+    if(!aCenterPointAttr->isInitialized()) {
+      return;
+    }
+    std::shared_ptr<GeomDataAPI_Point2D> aStartPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_1_ID()));
+    if(!aStartPointAttr->isInitialized()) {
+      return;
+    }
+
+    myCenter = aCenterPointAttr->pnt();
+    myStart = aStartPointAttr->pnt();
+    myEnd = myStart;
+
+    std::shared_ptr<GeomDataAPI_Point2D> anEndPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_1_ID()));
+    if(anEndPointAttr->isInitialized()) {
+      // End point should be a projection on circle.
+      GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
+      std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc.project(anEndPointAttr->pnt());
+      if(aProjection.get()) {
+        bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+        anEndPointAttr->setValue(aProjection);
+        data()->blockSendAttributeUpdated(aWasBlocked, false);
+      }
+      myEnd = anEndPointAttr->pnt();
+
+      double aParameterNew = 0.0;
+      if(aCircleForArc.parameter(myEnd, paramTolerance, aParameterNew)) {
+        if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) {
+          myIsInversed = true;
+        } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) {
+          myIsInversed = false;
+        }
+      }
+      myParamBefore = aParameterNew;
+    }
+  } else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) {
+    std::shared_ptr<GeomDataAPI_Point2D> aStartPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_2_ID()));
+    if(!aStartPointAttr->isInitialized()) {
+      return;
+    }
+    std::shared_ptr<GeomDataAPI_Point2D> anEndPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_2_ID()));
+    if(!anEndPointAttr->isInitialized()) {
+      return;
+    }
+
+    myStart = aStartPointAttr->pnt();
+    myEnd = anEndPointAttr->pnt();
+
+    std::shared_ptr<GeomDataAPI_Point2D> aPassedPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
+    if(aPassedPointAttr->isInitialized()) {
+      std::shared_ptr<GeomAPI_Pnt2d> aPassed = aPassedPointAttr->pnt();
+      GeomAPI_Circ2d aCircle(myStart, myEnd, aPassed);
+      myCenter = aCircle.center();
+      aCircle = GeomAPI_Circ2d(myCenter, myStart);
+      double anEndParam, aPassedParam;
+      aCircle.parameter(myEnd, paramTolerance, anEndParam);
+      aCircle.parameter(aPassed, paramTolerance, aPassedParam);
+      if(aPassedParam > anEndParam) {
+        myIsInversed = true;
+      } else {
+        myIsInversed = false;
+      }
+    } else {
+      std::shared_ptr<GeomAPI_XY> aDir = myEnd->xy()->decreased(myStart->xy())->multiplied(0.5);
+      double x = aDir->x();
+      double y = aDir->y();
+      aDir->setX(x - y);
+      aDir->setY(y + x);
+      myCenter.reset(new GeomAPI_Pnt2d(myStart->xy()->added(aDir)));
+    }
+  } else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
+    AttributeRefAttrPtr aTangentAttr = refattr(TANGENT_POINT_ID());
+    if(!aTangentAttr->isInitialized()) {
+      return;
+    }
+    std::shared_ptr<GeomDataAPI_Point2D> aTangentPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aTangentAttr->attr());
+    if(!aTangentPointAttr->isInitialized()) {
+      return;
+    }
+    std::shared_ptr<GeomDataAPI_Point2D> anEndPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_3_ID()));
+    if(!anEndPointAttr->isInitialized()) {
+      return;
+    }
+
+    myStart = aTangentPointAttr->pnt();
+    myEnd = anEndPointAttr->pnt();
+
+    if(myStart->isEqual(myEnd)) {
+      return;
+    }
+
+    SketchPlugin_Sketch* aSketch = sketch();
+    if(!aSketch) {
+      return;
+    }
+
+    std::shared_ptr<GeomAPI_Dir2d> anOrthoDir;
+    FeaturePtr aTangFeature = ModelAPI_Feature::feature(aTangentPointAttr->owner());
+    std::shared_ptr<GeomAPI_Edge> aTangEdge =
+      std::dynamic_pointer_cast<GeomAPI_Edge>(aTangFeature->lastResult()->shape());
+    if(aTangEdge->isLine()) {
+      std::shared_ptr<GeomAPI_Dir> aDir = aTangEdge->line()->direction();
+      std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aDir->x(), aDir->y(), aDir->z()));
+      std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aSketch->to2D(aPnt);
+      anOrthoDir = std::shared_ptr<GeomAPI_Dir2d>(new GeomAPI_Dir2d(-aPnt2d->y(), aPnt2d->x()));
+    }
+    else if (aTangEdge->isArc()) {
+      std::shared_ptr<GeomAPI_Pnt> aCenter = aTangEdge->circle()->center();
+      std::shared_ptr<GeomAPI_Pnt2d> aCenter2d = aSketch->to2D(aCenter);
+      anOrthoDir = std::shared_ptr<GeomAPI_Dir2d>(
+          new GeomAPI_Dir2d(myStart->xy()->decreased(aCenter2d->xy())));
+    }
+
+    // compute parameters of the middle perpendicular
+    std::shared_ptr<GeomAPI_XY> aEndPntCoord = myEnd->xy();
+    std::shared_ptr<GeomAPI_XY> aTempDir = aEndPntCoord->decreased(myStart->xy());
+    std::shared_ptr<GeomAPI_Dir2d> aMidDir(new GeomAPI_Dir2d(-aTempDir->y(), aTempDir->x()));
+    std::shared_ptr<GeomAPI_Pnt2d> aMidPnt(
+        new GeomAPI_Pnt2d(aEndPntCoord->added(myStart->xy())->multiplied(0.5)));
+
+    // compute center of arc by calculating intersection of
+    // orthogonal line and middle perpendicular
+    std::shared_ptr<GeomAPI_Lin2d> anOrthoLine(new GeomAPI_Lin2d(myStart, anOrthoDir));
+    std::shared_ptr<GeomAPI_Lin2d> aMiddleLine(new GeomAPI_Lin2d(aMidPnt, aMidDir));
+    std::shared_ptr<GeomAPI_Pnt2d> aCenter = anOrthoLine->intersect(aMiddleLine);
+    if(aCenter) {
+      myCenter = aCenter;
+    }
+
+    GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
+    double aParameterNew = 0.0;
+    if(aCircleForArc.parameter(myEnd, paramTolerance, aParameterNew)) {
+      if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) {
+        if(!myIsInversed) {
+          myIsInversed = true;
+        }
+      } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) {
+        if(myIsInversed) {
+          myIsInversed = false;
+        }
+      }
+    }
+    myParamBefore = aParameterNew;
+  }
+
+  double aRadius = 0;
+  double anAngle = 0;
+  if(myCenter.get() && myStart.get()) {
+    aRadius = myCenter->distance(myStart);
+    if(myEnd.get()) {
+      if(myStart->isEqual(myEnd)) {
+        anAngle = 360;
+      } else {
+        GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
+        double aStartParam, anEndParam;
+        aCircleForArc.parameter(myStart, paramTolerance, aStartParam);
+        aCircleForArc.parameter(myEnd, paramTolerance, anEndParam);
+        anAngle = (anEndParam - aStartParam) / PI * 180.0;
+        if(myIsInversed) anAngle = 360.0 - anAngle;
+      }
+    }
+  }
+
+  bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+  real(RADIUS_ID())->setValue(aRadius);
+  real(ANGLE_ID())->setValue(anAngle);
+  data()->blockSendAttributeUpdated(aWasBlocked, false);
+}
+
+AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
+{
+  if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
+    return AISObjectPtr();
+  }
+
+  SketchPlugin_Sketch* aSketch = sketch();
+  if(!aSketch) {
+    return AISObjectPtr();
+  }
+
+  std::shared_ptr<GeomAPI_Pnt> aStart = aSketch->to3D(myStart->x(), myStart->y());
+  std::shared_ptr<GeomAPI_Pnt> anEnd = aSketch->to3D(myEnd->x(), myEnd->y());
+  std::shared_ptr<GeomAPI_Pnt> aCenter = aSketch->to3D(myCenter->x(), myCenter->y());;
+
+  std::shared_ptr<GeomDataAPI_Dir> aNDir =
+      std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+          aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+  std::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+  GeomShapePtr anArcShape = myIsInversed ?
+      GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal)
+    : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal);
+  GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
+
+  if(!anArcShape.get() || !aCenterPointShape.get()) {
+    return AISObjectPtr();
+  }
+
+  std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
+  aShapes.push_back(anArcShape);
+  aShapes.push_back(aCenterPointShape);
+
+  std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+  AISObjectPtr anAIS = thePrevious;
+  if(!anAIS.get()) {
+    anAIS.reset(new GeomAPI_AISObject());
+  }
+  anAIS->createShape(aCompound);
+  return anAIS;
+}
+
+void SketchPlugin_MacroArc::execute()
+{
+}
diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.h b/src/SketchPlugin/SketchPlugin_MacroArc.h
new file mode 100644 (file)
index 0000000..a082c64
--- /dev/null
@@ -0,0 +1,194 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchPlugin_MacroArc.h
+// Created:     26 May 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef SketchPlugin_MacroArc_H_
+#define SketchPlugin_MacroArc_H_
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_SketchEntity.h>
+#include <SketchPlugin_Sketch.h>
+#include <GeomAPI_IPresentable.h>
+
+/**\class SketchPlugin_MacroArc
+ * \ingroup Plugins
+ * \brief Feature for creation of the new arc of circle in PartSet.
+ * The visualization of this object is separated in two parts. The first one is an AIS object
+ * calculated when there is non-initialized attributes of the arc. The second is a result and
+ * it is calculated if all attributes are initialized.
+ */
+class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity,
+                             public GeomAPI_IPresentable
+{
+ public:
+  /// Arc feature kind
+  inline static const std::string& ID()
+  {
+    static const std::string ID("SketchMacroArc");
+    return ID;
+  }
+
+  inline static const std::string& ARC_TYPE()
+  {
+    static const std::string ID("arc_type");
+    return ID;
+  }
+
+  static const std::string& ARC_TYPE_BY_CENTER_AND_POINTS()
+  {
+    static const std::string ID("by_center_and_points");
+    return ID;
+  }
+  static const std::string& ARC_TYPE_BY_THREE_POINTS()
+  {
+    static const std::string ID("by_three_points");
+    return ID;
+  }
+
+  inline static const std::string& ARC_TYPE_BY_TANGENT_EDGE()
+  {
+    static const std::string ID("by_tangent_edge");
+    return ID;
+  }
+
+  /// Central 2D point of the circle which contains the arc
+  inline static const std::string& CENTER_POINT_ID()
+  {
+    static const std::string ID = "center_point";
+    return ID;
+  }
+
+  inline static const std::string& CENTER_POINT_REF_ID()
+  {
+    static const std::string ID = "center_point_ref";
+    return ID;
+  }
+
+  /// Start 2D point of the arc
+  inline static const std::string& START_POINT_1_ID()
+  {
+    static const std::string ID = "start_point_1";
+    return ID;
+  }
+
+  /// Start 2D point of the arc
+  inline static const std::string& START_POINT_2_ID()
+  {
+    static const std::string ID = "start_point_2";
+    return ID;
+  }
+
+  inline static const std::string& START_POINT_REF_ID()
+  {
+    static const std::string ID = "start_point_ref";
+    return ID;
+  }
+
+  /// End 2D point of the arc
+  inline static const std::string& END_POINT_1_ID()
+  {
+    static const std::string ID = "end_point_1";
+    return ID;
+  }
+
+  /// End 2D point of the arc
+  inline static const std::string& END_POINT_2_ID()
+  {
+    static const std::string ID = "end_point_2";
+    return ID;
+  }
+
+  /// End 2D point of the arc
+  inline static const std::string& END_POINT_3_ID()
+  {
+    static const std::string ID = "end_point_3";
+    return ID;
+  }
+
+  inline static const std::string& END_POINT_REF_ID()
+  {
+    static const std::string ID = "end_point_ref";
+    return ID;
+  }
+
+  /// Passed point of the arc.
+  static const std::string& PASSED_POINT_ID()
+  {
+    static const std::string ID("passed_point");
+    return ID;
+  }
+
+  static const std::string& PASSED_POINT_REF_ID()
+  {
+    static const std::string ID("passed_point_ref");
+    return ID;
+  }
+
+  static const std::string& TANGENT_POINT_ID()
+  {
+    static const std::string ID("tangent_point");
+    return ID;
+  }
+
+  /// Arc radius.
+  static const std::string& RADIUS_ID()
+  {
+    static const std::string ID("radius");
+    return ID;
+  }
+
+  /// Arc angle.
+  static const std::string& ANGLE_ID()
+  {
+    static const std::string ID("angle");
+    return ID;
+  }
+
+  /// Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = SketchPlugin_MacroArc::ID();
+    return MY_KIND;
+  }
+
+  /// \brief Request for initialization of data model of the feature: adding all attributes.
+  SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+  /// Returns the AIS preview
+  virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+  /// Creates an arc-shape
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// Moves the feature
+  /// \param theDeltaX the delta for X coordinate is moved
+  /// \param theDeltaY the delta for Y coordinate is moved
+  SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
+  {
+  };
+
+  /// Reimplemented from ModelAPI_Feature::isMacro().
+  SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
+
+  SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
+
+  /// Use plugin manager for features creation.
+  SketchPlugin_MacroArc();
+
+private:
+  std::shared_ptr<GeomAPI_Pnt2d> myCenter;
+  std::shared_ptr<GeomAPI_Pnt2d> myStart;
+  std::shared_ptr<GeomAPI_Pnt2d> myEnd;
+
+  /// To define in which direction draw arc.
+  bool myIsInversed;
+  double myParamBefore;
+};
+
+#endif
index 375fec58813de9bd1457a0d19192ca2d23130620..b545ccdd24a2ee61bc45c4c6306118f9ec002408 100644 (file)
@@ -7,29 +7,27 @@
 #include "SketchPlugin_MacroCircle.h"
 
 #include "SketchPlugin_Circle.h"
-//#include "SketchPlugin_ConstraintCoincidence.h"
 #include "SketchPlugin_Point.h"
 #include "SketchPlugin_Tools.h"
 
-#include <ModelAPI_Data.h>
-#include <ModelAPI_Events.h>
-#include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_AttributeSelection.h>
-#include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <GeomDataAPI_Dir.h>
+#include <GeomDataAPI_Point2D.h>
 
+#include <GeomAPI_Circ2d.h>
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Circ.h>
 #include <GeomAPI_Vertex.h>
 #include <GeomAPI_XY.h>
-#include <GeomDataAPI_Point2D.h>
-#include <GeomDataAPI_Dir.h>
-#include <GeomAlgoAPI_PointBuilder.h>
-#include <GeomAlgoAPI_EdgeBuilder.h>
+
 #include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_PointBuilder.h>
 
 
 const double tolerance = 1e-7;
@@ -38,9 +36,9 @@ namespace {
   static const std::string& POINT_ID(int theIndex)
   {
     switch (theIndex) {
-    case 1: return SketchPlugin_MacroCircle::FIRST_POINT_ID();
-    case 2: return SketchPlugin_MacroCircle::SECOND_POINT_ID();
-    case 3: return SketchPlugin_MacroCircle::THIRD_POINT_ID();
+      case 1: return SketchPlugin_MacroCircle::FIRST_POINT_ID();
+      case 2: return SketchPlugin_MacroCircle::SECOND_POINT_ID();
+      case 3: return SketchPlugin_MacroCircle::THIRD_POINT_ID();
     }
 
     static const std::string DUMMY;
@@ -241,12 +239,17 @@ void SketchPlugin_MacroCircle::attributeChanged(const std::string& theID) {
   if(theID == CIRCLE_TYPE()) {
     std::string aType = string(CIRCLE_TYPE())->value();
     if(aType == CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()) {
-      resetAttribute(CENTER_POINT_ID());
-      resetAttribute(PASSED_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_REF_ID());
+      SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_REF_ID());
     } else if(aType == CIRCLE_TYPE_BY_THREE_POINTS()) {
-      resetAttribute(FIRST_POINT_ID());
-      resetAttribute(SECOND_POINT_ID());
-      resetAttribute(THIRD_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, FIRST_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, FIRST_POINT_REF_ID());
+      SketchPlugin_Tools::resetAttribute(this, SECOND_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, SECOND_POINT_REF_ID());
+      SketchPlugin_Tools::resetAttribute(this, THIRD_POINT_ID());
+      SketchPlugin_Tools::resetAttribute(this, THIRD_POINT_REF_ID());
     }
     myCenter.reset();
     myRadius = 0;
@@ -296,11 +299,3 @@ void SketchPlugin_MacroCircle::attributeChanged(const std::string& theID) {
   aRadiusAttr->setValue(myRadius);
   data()->blockSendAttributeUpdated(aWasBlocked, false);
 }
-
-void SketchPlugin_MacroCircle::resetAttribute(const std::string& theId)
-{
-  AttributePtr anAttr = attribute(theId);
-  if(anAttr.get()) {
-    anAttr->reset();
-  }
-}
index bc387acd518e7703401f9372f2f7af52163cf2bc..05a2d301be328860fe5d3f17d16c87d1a08b38ca 100644 (file)
@@ -163,8 +163,6 @@ class SketchPlugin_MacroCircle: public SketchPlugin_SketchEntity,
   SketchPlugin_MacroCircle();
 
 private:
-  void resetAttribute(const std::string& theId);
-
   void createCircleByCenterAndPassed();
   void createCircleByThreePoints();
 
index 6a4cde08443c45efdda04fa2f62fe09518a870da..53d44428de64414af073947042c166f45d713265 100644 (file)
@@ -25,6 +25,7 @@
 #include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_ConstraintTangent.h>
 #include <SketchPlugin_ConstraintVertical.h>
+#include <SketchPlugin_MacroArc.h>
 #include <SketchPlugin_MacroCircle.h>
 #include <SketchPlugin_MultiRotation.h>
 #include <SketchPlugin_MultiTranslation.h>
@@ -180,6 +181,8 @@ FeaturePtr SketchPlugin_Plugin::createFeature(std::string theFeatureID)
     return FeaturePtr(new SketchPlugin_ConstraintAngle);
   } else if (theFeatureID == SketchPlugin_Trim::ID()) {
     return FeaturePtr(new SketchPlugin_Trim);
+  } else if (theFeatureID == SketchPlugin_MacroArc::ID()) {
+    return FeaturePtr(new SketchPlugin_MacroArc);
   } else if (theFeatureID == SketchPlugin_MacroCircle::ID()) {
     return FeaturePtr(new SketchPlugin_MacroCircle);
   }
@@ -245,6 +248,7 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
       aMsg->setState(SketchPlugin_MultiRotation::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_MultiTranslation::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_Trim::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_MacroArc::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_MacroCircle::ID(), aHasSketchPlane);
       // SketchRectangle is a python feature, so its ID is passed just as a string
       aMsg->setState("SketchRectangle", aHasSketchPlane);
index 7af4e9af143df71707fe878f76cca26b35123b27..9a4d82f848e9d425223463ff6634d38b178fdb02 100644 (file)
@@ -106,6 +106,15 @@ void findCoincidences(const FeaturePtr theStartCoin,
   }
 }
 
+void resetAttribute(SketchPlugin_Feature* theFeature,
+                    const std::string& theId)
+{
+  AttributePtr anAttr = theFeature->attribute(theId);
+  if(anAttr.get()) {
+    anAttr->reset();
+  }
+}
+
 void createConstraint(SketchPlugin_Feature* theFeature,
                       const std::string& theId,
                       const AttributePtr theAttr,
index ef26d67c0560f73d29f8d3e9d025bd9bc1d1b53b..6d588b5d38df180f214ada1aa0801d7d8bb88920 100644 (file)
@@ -31,6 +31,8 @@ void findCoincidences(const FeaturePtr theStartCoin,
                       const std::string& theAttr,
                       std::set<FeaturePtr>& theList);
 
+void resetAttribute(SketchPlugin_Feature* theFeature, const std::string& theId);
+
 /// Creates coincidence or tangent constraint.
 /// \param[in] theFeature to get selected attribute or object
 /// \param[in] theId ID of attribute where selection is.
index e2492432ad546b74767f4ff964ede119dd1cdffd..cf97eaa2110ee81ef8939f8c5f2c86c3b15804a9 100644 (file)
@@ -6,7 +6,7 @@
       <feature
         id="Sketch"
         nested="SketchPoint SketchIntersectionPoint SketchLine
-                SketchCircle SketchMacroCircle SketchArc
+                SketchCircle SketchMacroCircle SketchArc SketchMacroArc
                 SketchRectangle
                 SketchProjection
                 SketchConstraintLength SketchConstraintRadius SketchConstraintDistance
@@ -36,7 +36,7 @@
                                  enable_value="enable_by_preferences"/>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
-      
+
       <!-- SketchLine -->
       <feature id="SketchLine" title="Line" tooltip="Create line" icon="icons/Sketch/line.png">
         <sketch-2dpoint_selector id="StartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates"
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
 
+      <!-- SketchMacroArc -->
+      <feature
+        id="SketchMacroArc"
+        title="Arc"
+        tooltip="Create arc"
+        icon="icons/Sketch/arc.png">
+        <toolbox id="arc_type">
+          <box id="by_center_and_points"
+               icon="icons/Sketch/arc_base_32x32.png"
+               title="Center and two points">
+            <sketch-2dpoint_selector id="center_point"
+                                     reference_attribute="center_point_ref"
+                                     title="Center point"
+                                     tooltip="Center of a circle"
+                                     accept_expressions="0"
+                                     enable_value="enable_by_preferences" />
+            <sketch-2dpoint_selector id="start_point_1"
+                                     reference_attribute="start_point_ref"
+                                     title="Start point"
+                                     tooltip="Start point"
+                                     accept_expressions="0"
+                                     enable_value="enable_by_preferences"/>
+            <sketch-2dpoint_selector id="end_point_1"
+                                     reference_attribute="end_point_ref"
+                                     title="End point"
+                                     tooltip="End point"
+                                     accept_expressions="0"
+                                     enable_value="enable_by_preferences"/>
+            <validator id="GeomValidators_Different" parameters="center_point,start_point_1,end_point_1"/>
+          </box>
+          <box id="by_three_points"
+               icon="icons/Sketch/arc_3pt_32x32.png"
+               title="Three points on arc">
+            <sketch-2dpoint_selector id="start_point_2"
+                                     reference_attribute="start_point_ref"
+                                     title="Start point"
+                                     tooltip="Start point"
+                                     accept_expressions="0"
+                                     enable_value="enable_by_preferences"/>
+            <sketch-2dpoint_selector id="end_point_2"
+                                     reference_attribute="end_point_ref"
+                                     title="End point"
+                                     tooltip="End point"
+                                     accept_expressions="0"
+                                     enable_value="enable_by_preferences"/>
+            <sketch-2dpoint_selector id="passed_point"
+                                     reference_attribute="passed_point_ref"
+                                     title="Passed point"
+                                     tooltip="Passed point"
+                                     accept_expressions="0"
+                                     enable_value="enable_by_preferences"/>
+            <validator id="GeomValidators_Different" parameters="start_point_2,end_point_2,passed_point"/>
+          </box>
+          <box id="by_tangent_edge"
+               icon="icons/Sketch/arc_tang_32x32.png"
+               title="Tangent with edge">
+            <sketch_shape_selector id="tangent_point"
+                                   label="Tangent point"
+                                   tooltip="Select point on line"
+                                   shape_types="vertex">
+              <!--<validator id="SketchPlugin_ArcTangentPoint"/>-->
+            </sketch_shape_selector>
+            <sketch-2dpoint_selector id="end_point_3"
+                                     reference_attribute="end_point_ref"
+                                     title="End point"
+                                     tooltip="End point"
+                                     accept_expressions="0"
+                                     enable_value="enable_by_preferences"/>
+          </box>
+        </toolbox>
+        <labelvalue id="radius"
+                    icon="icons/Sketch/radius.png"
+                    label="Radius:"
+                    tooltip="Set radius"
+                    accept_expressions="0"
+                    min="0"
+                    default="0"
+                    obligatory="0"
+                    enable_value="enable_by_preferences">
+        </labelvalue>
+        <labelvalue id="angle"
+                    icon="icons/Sketch/angle.png"
+                    label="Angle:"
+                    tooltip="Set angle"
+                    default="0"
+                    use_reset="false"
+                    obligatory="0"
+                    enable_value="enable_by_preferences"/>
+        <boolvalue id="Auxiliary"
+                   label="Auxiliary"
+                   tooltip="Construction element"
+                   default="false"
+                   obligatory="0"/>
+      </feature>
+
       <!--  SketchFillet  -->
       <feature id="SketchFillet"
                title="Fillet"
           <validator id="PartSet_DifferentObjects"/>
           <validator id="GeomValidators_ShapeType" parameters="vertex,line"/>
         </sketch_shape_selector>
-        <sketch_shape_selector 
-          id="ConstraintEntityB" 
-          label="Second object" 
-          tooltip="Select point, line end point, line, center of circle or arc." 
+        <sketch_shape_selector
+          id="ConstraintEntityB"
+          label="Second object"
+          tooltip="Select point, line end point, line, center of circle or arc."
           shape_types="edge vertex">
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
           <validator id="GeomValidators_ShapeType" parameters="vertex,line"/>
         </sketch_shape_selector>
         <sketch-2dpoint_flyout_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
-        
+
         <doublevalue_editor label="Value" tooltip="Distance" id="ConstraintValue" default="computed" min="0">
           <validator id="GeomValidators_Positive"/>
         </doublevalue_editor>
-        
+
         <validator id="PartSet_DistanceSelection"/>
       </feature>
-      
-    <!--  SketchConstraintLength  -->      
+
+    <!--  SketchConstraintLength  -->
       <feature id="SketchConstraintLength" title="Length" tooltip="Set fixed length of a line segment" icon="icons/Sketch/length.png">
         <label title="Select a line on which to calculate length" tooltip="Select a line on which to calculate length"/>
         <shape_selector id="ConstraintEntityA" label="Line" tooltip="Select a line" shape_types="edge" >
       <!--  SketchConstraintParallel  -->
       <feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines"
                icon="icons/Sketch/parallel.png">
-        <sketch_shape_selector id="ConstraintEntityA" 
+        <sketch_shape_selector id="ConstraintEntityA"
             label="First line" tooltip="Select a line" shape_types="edge">
           <validator id="GeomValidators_ShapeType" parameters="line"/>
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
         </sketch_shape_selector>
-        
-        <sketch_shape_selector id="ConstraintEntityB" label="Second line" tooltip="Select a line" 
+
+        <sketch_shape_selector id="ConstraintEntityB" label="Second line" tooltip="Select a line"
             shape_types="edge">
             <validator id="GeomValidators_ShapeType" parameters="line"/>
             <validator id="PartSet_DifferentObjects"/>
         </sketch_shape_selector>
         <validator id="PartSet_ParallelSelection"/>
       </feature>
-      
+
     <!--  SketchConstraintPerpendicular  -->
-      <feature id="SketchConstraintPerpendicular" title="Perpendicular" 
-        tooltip="Create constraint defining two perpendicular lines" 
+      <feature id="SketchConstraintPerpendicular" title="Perpendicular"
+        tooltip="Create constraint defining two perpendicular lines"
         icon="icons/Sketch/perpendicular.png">
-        <sketch_shape_selector id="ConstraintEntityA" 
-            label="First line" tooltip="Select a line" 
+        <sketch_shape_selector id="ConstraintEntityA"
+            label="First line" tooltip="Select a line"
             shape_types="edge">
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
             <validator id="GeomValidators_ShapeType" parameters="line"/>
         </sketch_shape_selector>
-        
-        <sketch_shape_selector id="ConstraintEntityB" 
-            label="Second line" tooltip="Select a line" 
+
+        <sketch_shape_selector id="ConstraintEntityB"
+            label="Second line" tooltip="Select a line"
             shape_types="edge">
             <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
       <feature id="SketchConstraintEqual" title="Equal"
         tooltip="Create constraint defining equal lengths of two lines or line and arc or equal radii of two arcs or two circles or arc and circle"
         icon="icons/Sketch/equal.png">
-        <sketch_shape_selector id="ConstraintEntityA" 
+        <sketch_shape_selector id="ConstraintEntityA"
             label="First object" tooltip="Select line, circle or arc" shape_types="edge">
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
         </sketch_shape_selector>
-        
+
         <sketch_shape_selector id="ConstraintEntityB"
             label="Second object" tooltip="Select line, circle or arc" shape_types="edge">
           <validator id="SketchPlugin_EqualAttr" parameters="ConstraintEntityA"/>
         </sketch_shape_selector>
         <validator id="PartSet_EqualSelection"/>
       </feature>
-      
+
     <!--  SketchConstraintCollinear  -->
       <feature id="SketchConstraintCollinear" title="Collinear" tooltip="Create constraint defining collinearity of two lines" icon="icons/Sketch/collinear.png">
-        <sketch_shape_selector id="ConstraintEntityA" 
+        <sketch_shape_selector id="ConstraintEntityA"
             label="First line" tooltip="Select a line" shape_types="edge">
           <validator id="GeomValidators_ShapeType" parameters="line"/>
           <validator id="PartSet_DifferentObjects"/>
         </sketch_shape_selector>
-        
+
         <sketch_shape_selector id="ConstraintEntityB"
             label="Second line" tooltip="Select a line" shape_types="edge">
           <validator id="GeomValidators_ShapeType" parameters="line"/>
         </sketch_shape_selector>
         <validator id="PartSet_CollinearSelection"/>
       </feature>
-         
+
     </group>
-    
+
   </workbench>
 </plugin>