]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Creating an arc by 3 points and a tangent arc
authorazv <azv@opencascade.com>
Wed, 3 Feb 2016 08:36:11 +0000 (11:36 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:35 +0000 (17:04 +0300)
19 files changed:
src/GeomAPI/GeomAPI_Dir.cpp
src/GeomAPI/GeomAPI_Dir.h
src/GeomAPI/GeomAPI_Dir2d.cpp
src/GeomAPI/GeomAPI_Dir2d.h
src/GeomAPI/GeomAPI_Lin.cpp
src/GeomAPI/GeomAPI_Lin.h
src/GeomAPI/GeomAPI_Lin2d.cpp
src/GeomAPI/GeomAPI_Lin2d.h
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/arc_3pt_32x32.png [new file with mode: 0644]
src/PartSet/icons/arc_base_32x32.png [new file with mode: 0644]
src/PartSet/icons/arc_tang_32x32.png [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Arc.h
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_ConstraintMulti.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index 3174cea0ee8f6fe056534d21ccac6885a0116e69..6f57e76815be685afaf7de7fdd399aaceead0348 100644 (file)
@@ -41,6 +41,11 @@ const std::shared_ptr<GeomAPI_XYZ> GeomAPI_Dir::xyz()
   return std::shared_ptr<GeomAPI_XYZ>(new GeomAPI_XYZ(MY_DIR->X(), MY_DIR->Y(), MY_DIR->Z()));
 }
 
+void GeomAPI_Dir::reverse()
+{
+  MY_DIR->Reverse();
+}
+
 double GeomAPI_Dir::dot(const std::shared_ptr<GeomAPI_Dir>& theArg) const
 {
   return MY_DIR->Dot(theArg->impl<gp_Dir>());
index 4c4c007af06c85afaae77036e92a29545423996f..a3e49f90760d12dca01f62e7ffeb3443d81375b4 100644 (file)
@@ -41,6 +41,9 @@ class GeomAPI_Dir : public GeomAPI_Interface
   GEOMAPI_EXPORT 
   const std::shared_ptr<GeomAPI_XYZ> xyz();
 
+  /// inverses the direction
+  GEOMAPI_EXPORT void reverse();
+
   /// result is a scalar product of directions
   GEOMAPI_EXPORT 
   double dot(const std::shared_ptr<GeomAPI_Dir>& theArg) const;
index 4cb8149a3999d46e55c58e674aff32820fe3523e..1e5332d3147b09b4981f185dec6c3077ffb17b20 100644 (file)
@@ -36,6 +36,11 @@ const std::shared_ptr<GeomAPI_XY> GeomAPI_Dir2d::xy()
   return std::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(MY_DIR->X(), MY_DIR->Y()));
 }
 
+void GeomAPI_Dir2d::reverse()
+{
+  MY_DIR->Reverse();
+}
+
 double GeomAPI_Dir2d::dot(const std::shared_ptr<GeomAPI_Dir2d>& theArg) const
 {
   return MY_DIR->Dot(theArg->impl<gp_Dir2d>());
index aafe267ce2b9c7d35ce04ae47345df6ed0eed38e..2e8cc227edcd8b3dee098e78d33de18f7322118b 100644 (file)
@@ -38,6 +38,9 @@ class GeomAPI_Dir2d : public GeomAPI_Interface
   GEOMAPI_EXPORT 
   const std::shared_ptr<GeomAPI_XY> xy();
 
+  /// inverses the direction
+  GEOMAPI_EXPORT void reverse();
+
   /// result is a scalar product of directions
   GEOMAPI_EXPORT 
   double dot(const std::shared_ptr<GeomAPI_Dir2d>& theArg) const;
index dba5834abc1b7cb596f0cd088ddb4d954480f437..a9fe074d086af9cb2df9e840bde3c8aa070163bb 100644 (file)
@@ -43,6 +43,15 @@ GeomAPI_Lin::GeomAPI_Lin(const std::shared_ptr<GeomAPI_Pnt>& theStart,
 {
 }
 
+GeomAPI_Lin::GeomAPI_Lin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                         const std::shared_ptr<GeomAPI_Dir>& theDirection)
+    : GeomAPI_Interface(newLine(theOrigin->x(), theOrigin->y(), theOrigin->z(),
+                                theOrigin->x() + theDirection->x(),
+                                theOrigin->y() + theDirection->y(),
+                                theOrigin->z() + theDirection->z()))
+{
+}
+
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::location()
 {
   gp_Pnt aLoc = impl<gp_Lin>().Location();
index b9323c85660982d09908406dd994bc2d851da98b..6f67109848906352f76a302c25ed893476b80653 100644 (file)
@@ -29,6 +29,10 @@ class GeomAPI_Lin : public GeomAPI_Interface
   GEOMAPI_EXPORT 
   GeomAPI_Lin(const std::shared_ptr<GeomAPI_Pnt>& theStart,
               const std::shared_ptr<GeomAPI_Pnt>& theEnd);
+  /// Creation of line defined by origin and direction
+  GEOMAPI_EXPORT
+  GeomAPI_Lin(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
+              const std::shared_ptr<GeomAPI_Dir>& theDirection);
 
   /// Returns point on the line (first point)
   GEOMAPI_EXPORT 
index 6b53b8fdc8abbee47052c4ad5d4b75e32e18e020..2d97bd6c8747d49e9af1346e2397eef2f003a089 100644 (file)
@@ -25,6 +25,7 @@ static gp_Lin2d* newLine2d(const double theStartX, const double theStartY, const
   return new gp_Lin2d(aStart, gp_Dir2d(aDir));
 }
 
+
 GeomAPI_Lin2d::GeomAPI_Lin2d(const double theStartX, const double theStartY, const double theEndX,
                              const double theEndY)
     : GeomAPI_Interface(newLine2d(theStartX, theStartY, theEndX, theEndY))
@@ -37,6 +38,14 @@ GeomAPI_Lin2d::GeomAPI_Lin2d(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
 {
 }
 
+GeomAPI_Lin2d::GeomAPI_Lin2d(const std::shared_ptr<GeomAPI_Pnt2d>& theOrigin,
+                             const std::shared_ptr<GeomAPI_Dir2d>& theDirection)
+    : GeomAPI_Interface(newLine2d(theOrigin->x(), theOrigin->y(),
+        theOrigin->x() + theDirection->x(), theOrigin->y() + theDirection->y()))
+{
+}
+
+
 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Lin2d::location()
 {
   gp_Pnt2d aLoc = impl<gp_Lin2d>().Location();
index e5556ec9f058fe99044f43531f65ca6aad3287b8..7aef4793773b048eb126e8bc9ab98cd2d163073b 100644 (file)
@@ -29,6 +29,10 @@ class GeomAPI_Lin2d : public GeomAPI_Interface
   GEOMAPI_EXPORT 
   GeomAPI_Lin2d(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
                 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd);
+  /// Creation of line defined by origin and direction
+  GEOMAPI_EXPORT
+  GeomAPI_Lin2d(const std::shared_ptr<GeomAPI_Pnt2d>& theOrigin,
+                const std::shared_ptr<GeomAPI_Dir2d>& theDirection);
 
   /// Returns point on the line (first point)
   GEOMAPI_EXPORT 
index c6e6324206d7289e84130740c7041a905fa33c8f..368893c2bdcac0ee83ef316aaab0b97ea90e4ded 100644 (file)
@@ -5,6 +5,9 @@
      <file>icons/angle_up.png</file>
      <file>icons/angle_down.png</file>
      <file>icons/arc.png</file>
+     <file>icons/arc_base_32x32.png</file>
+     <file>icons/arc_3pt_32x32.png</file>
+     <file>icons/arc_tang_32x32.png</file>
      <file>icons/circle.png</file>
      <file>icons/circle_pt_rad_32x32.png</file>
      <file>icons/circle_3pt_32x32.png</file>
diff --git a/src/PartSet/icons/arc_3pt_32x32.png b/src/PartSet/icons/arc_3pt_32x32.png
new file mode 100644 (file)
index 0000000..584fa59
Binary files /dev/null and b/src/PartSet/icons/arc_3pt_32x32.png differ
diff --git a/src/PartSet/icons/arc_base_32x32.png b/src/PartSet/icons/arc_base_32x32.png
new file mode 100644 (file)
index 0000000..c36df30
Binary files /dev/null and b/src/PartSet/icons/arc_base_32x32.png differ
diff --git a/src/PartSet/icons/arc_tang_32x32.png b/src/PartSet/icons/arc_tang_32x32.png
new file mode 100644 (file)
index 0000000..cfec981
Binary files /dev/null and b/src/PartSet/icons/arc_tang_32x32.png differ
index 9ec13a3205a7edc0473ef56d2d3b553743768c5c..b9c73ef85ebcac8b00fe9e58b0ad2c7d41caa52d 100644 (file)
@@ -6,16 +6,29 @@
 
 #include "SketchPlugin_Arc.h"
 #include "SketchPlugin_Sketch.h"
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintTangent.h>
+
+#include <Events_Loop.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Events.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
 
 #include <GeomAPI_Ax2.h>
 #include <GeomAPI_Circ2d.h>
 #include <GeomAPI_Circ.h>
+#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Lin.h>
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
 #include <GeomAlgoAPI_PointBuilder.h>
@@ -28,6 +41,63 @@ const double tolerance = 1e-7;
 const double paramTolerance = 1.e-4;
 const double PI =3.141592653589793238463;
 
+namespace {
+  static const std::string& ARC_TYPE()
+  {
+    static const std::string TYPE("ArcType");
+    return TYPE;
+  }
+  static const std::string& ARC_TYPE_CENTER_START_END()
+  {
+    static const std::string TYPE("CenterStartEnd");
+    return TYPE;
+  }
+  static const std::string& ARC_TYPE_THREE_POINTS()
+  {
+    static const std::string TYPE("ThreePoints");
+    return TYPE;
+  }
+  static const std::string& ARC_TYPE_TANGENT()
+  {
+    static const std::string TYPE("Tangent");
+    return TYPE;
+  }
+
+  static const std::string& PASSED_POINT_ID()
+  {
+    static const std::string PASSED_PNT("ArcPassedPoint");
+    return PASSED_PNT;
+  }
+  static const std::string& TANGENT_POINT_ID()
+  {
+    static const std::string TANGENT_PNT("ArcTangentPoint");
+    return TANGENT_PNT;
+  }
+  static const std::string& RADIUS_ID()
+  {
+    static const std::string RADIUS("ArcRadius");
+    return RADIUS;
+  }
+  static const std::string& ANGLE_ID()
+  {
+    static const std::string ANGLE("ArcAngle");
+    return ANGLE;
+  }
+
+  static const std::string& POINT_ID(int theIndex)
+  {
+    switch (theIndex) {
+    case 1: return SketchPlugin_Arc::START_ID();
+    case 2: return SketchPlugin_Arc::END_ID();
+    case 3: return PASSED_POINT_ID();
+    }
+
+    static const std::string DUMMY;
+    return DUMMY;
+  }
+}
+
+
 
 SketchPlugin_Arc::SketchPlugin_Arc()
     : SketchPlugin_SketchEntity()
@@ -61,6 +131,15 @@ void SketchPlugin_Arc::initDerivedClassAttributes()
     myXEndBefore = anEndAttr->x();
     myYEndBefore = anEndAttr->y();
   }
+
+  data()->addAttribute(ARC_TYPE(), ModelAPI_AttributeString::typeId());
+  std::dynamic_pointer_cast<ModelAPI_AttributeString>(
+      data()->attribute(ARC_TYPE()))->setValue(ARC_TYPE_CENTER_START_END());
+
+  data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
 }
 
 void SketchPlugin_Arc::execute()
@@ -69,6 +148,9 @@ void SketchPlugin_Arc::execute()
   // result for the arc is set only when all obligatory attributes are initialized,
   // otherwise AIS object is used to visualize the arc's preview
   if (aSketch && isFeatureValid()) {
+    ResultPtr aLastResult = lastResult();
+    bool hasResult = aLastResult && aLastResult.get();
+
     // compute a circle point in 3D view
     std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
         GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
@@ -132,6 +214,11 @@ void SketchPlugin_Arc::execute()
       aConstr2->setIsInHistory(false);
       setResult(aConstr2, 1);
     }
+
+    AttributeRefAttrPtr aTangentPoint = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        attribute(TANGENT_POINT_ID()));
+    if (!hasResult && aTangentPoint->attr())
+      tangencyArcConstraints();
   }
 }
 
@@ -149,6 +236,11 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
 
         std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
             GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
+        std::shared_ptr<GeomDataAPI_Point2D> aEndAttr = std::dynamic_pointer_cast<
+            GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
+        AttributeStringPtr aTypeAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
+            data()->attribute(ARC_TYPE()));
+
         if (aStartAttr->isInitialized()) {
           // make a visible circle
           std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
@@ -157,8 +249,12 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
           if (aHasPlane) {
             std::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
             std::shared_ptr<GeomAPI_Pnt> aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+            std::shared_ptr<GeomAPI_Pnt> aEndPoint = aStartPoint;
+            if (aTypeAttr && aTypeAttr->isInitialized() &&
+                aTypeAttr->value() == ARC_TYPE_THREE_POINTS() && aEndAttr->isInitialized())
+              aEndPoint = aSketch->to3D(aEndAttr->x(), aEndAttr->y());
             std::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
-                                                            aCenter, aStartPoint, aStartPoint, aNormal);
+                                                            aCenter, aStartPoint, aEndPoint, aNormal);
             if (aCircleShape) {
               std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
               // make a visible point
@@ -191,6 +287,8 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
   if (!aData->isValid())
     return;
 
+  aData->blockSendAttributeUpdated(true);
+
   myStartUpdate = true;
   myEndUpdate = true;
   std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
@@ -206,6 +304,11 @@ void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
   std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(SketchPlugin_Arc::CENTER_ID()));
   aPoint1->move(theDeltaX, theDeltaY);
+
+  std::shared_ptr<GeomDataAPI_Point2D> aPassedPoint =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(PASSED_POINT_ID()));
+  aPassedPoint->move(theDeltaX, theDeltaY);
+  aData->blockSendAttributeUpdated(false);
 }
 
 bool SketchPlugin_Arc::isFixed() {
@@ -214,16 +317,108 @@ bool SketchPlugin_Arc::isFixed() {
 
 bool SketchPlugin_Arc::isFeatureValid()
 {
+  AttributeStringPtr anArcTypeAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeString>(data()->attribute(ARC_TYPE()));
+  if (!anArcTypeAttr)
+    return false;
+  std::string anArcType = anArcTypeAttr->value();
+
   std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID()));
   std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
   std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aPassedAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(PASSED_POINT_ID()));
 
-  return aCenterAttr->isInitialized() && aStartAttr->isInitialized() && anEndAttr->isInitialized();
+  bool isValid = false;
+  if (anArcType == ARC_TYPE_THREE_POINTS())
+    isValid = aStartAttr->isInitialized() && anEndAttr->isInitialized() && aPassedAttr->isInitialized();
+  else
+    isValid = aCenterAttr->isInitialized() && aStartAttr->isInitialized() && anEndAttr->isInitialized();
+
+  return isValid;
 }
 
+static inline void adjustPeriod(double& theParam)
+{
+  static const double PERIOD = 2.0 * PI;
+  while (theParam < 0.0) theParam += PERIOD;
+  while (theParam >= PERIOD) theParam -= PERIOD;
+}
+
+static inline void calculateArcAngleRadius(
+    const std::shared_ptr<GeomAPI_Circ2d>& theCircle,
+    const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+    AttributeDoublePtr theAngleAttr,
+    AttributeDoublePtr theRadiusAttr)
+{
+  double aStartParam, aEndParam, aPassedParam;
+  theCircle->parameter(theStartPoint, paramTolerance, aStartParam);
+  theCircle->parameter(theEndPoint, paramTolerance, aEndParam);
+  theCircle->parameter(thePassedPoint, paramTolerance, aPassedParam);
+  adjustPeriod(aStartParam);
+  adjustPeriod(aEndParam);
+  adjustPeriod(aPassedParam);
+
+  if (aPassedParam >= aStartParam && aPassedParam <= aEndParam)
+    theAngleAttr->setValue((aEndParam - aStartParam) * 180.0 / PI);
+  else
+    theAngleAttr->setValue((aEndParam - aStartParam - 2.0 * PI) * 180.0 / PI);
+  theRadiusAttr->setValue(theCircle->radius());
+}
+
+static inline void calculatePassedPoint(
+    const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+    const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint,
+    bool theArcReversed,
+    std::shared_ptr<GeomDataAPI_Point2D> thePassedPoint)
+{
+  std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(
+      theStartPoint->xy()->decreased(theCenter->xy())));
+  std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(
+      theEndPoint->xy()->decreased(theCenter->xy())));
+  std::shared_ptr<GeomAPI_Dir2d> aMidDir(new GeomAPI_Dir2d(
+      aStartDir->xy()->added(aEndDir->xy())));
+  if ((aStartDir->cross(aMidDir) > 0) ^ !theArcReversed)
+    aMidDir->reverse();
+
+  double aRadius = theCenter->distance(theStartPoint);
+  std::shared_ptr<GeomAPI_XY> aPassedPnt = theCenter->xy()->added( aMidDir->xy()->multiplied(aRadius) );
+  thePassedPoint->setValue(aPassedPnt->x(), aPassedPnt->y());
+}
+
+void SketchPlugin_Arc::updateDependentAttributes()
+{
+  data()->blockSendAttributeUpdated(true);
+
+  std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(START_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(END_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aPassedPoint =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
+  AttributeDoublePtr aRadiusAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+      data()->attribute(RADIUS_ID()));
+  AttributeDoublePtr anAngleAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+      data()->attribute(ANGLE_ID()));
+
+  calculatePassedPoint(aCenterAttr->pnt(), aStartAttr->pnt(), anEndAttr->pnt(),
+                       isReversed(), aPassedPoint);
+  std::shared_ptr<GeomAPI_Circ2d> aCircle(
+      new GeomAPI_Circ2d(aStartAttr->pnt(), anEndAttr->pnt(), aPassedPoint->pnt()));
+  calculateArcAngleRadius(aCircle, aStartAttr->pnt(), anEndAttr->pnt(), aPassedPoint->pnt(),
+                          anAngleAttr, aRadiusAttr);
+  data()->blockSendAttributeUpdated(false);
+}
+
+
 void SketchPlugin_Arc::attributeChanged(const std::string& theID)
 {
   std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
@@ -247,19 +442,199 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID)
     }
     return;
   }
-  if (!isFeatureValid())
+
+  AttributeDoublePtr aRadiusAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+      data()->attribute(RADIUS_ID()));
+  AttributeDoublePtr anAngleAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+      data()->attribute(ANGLE_ID()));
+
+  if (theID == RADIUS_ID()) {
+    if (!aStartAttr->isInitialized() || !anEndAttr->isInitialized())
+      return;
+    // move center and passed point
+    std::shared_ptr<GeomAPI_Pnt2d> aStartPnt = aStartAttr->pnt();
+    std::shared_ptr<GeomAPI_Pnt2d> aEndPnt = anEndAttr->pnt();
+    double aDist = aStartPnt->distance(aEndPnt);
+    if (fabs(aDist) < tolerance)
+      return;
+    std::shared_ptr<GeomAPI_XY> aDir = aEndPnt->xy()->decreased(aStartPnt->xy());
+    std::shared_ptr<GeomAPI_Dir2d> aMidPerpDir(new GeomAPI_Dir2d(-aDir->y(), aDir->x()));
+    std::shared_ptr<GeomAPI_XY> aMidPnt = aStartPnt->xy()->added(aEndPnt->xy())->multiplied(0.5);
+
+    double anAngle = anAngleAttr->value() * PI / 180.0;
+    adjustPeriod(anAngle);
+    if (anAngle > PI)
+      aMidPerpDir->reverse();
+
+    double aRadius = aRadiusAttr->value();
+    aDist = sqrt(aRadius * aRadius - aDist * aDist / 4.0);
+
+    std::shared_ptr<GeomAPI_XY> aCenter = aMidPnt->added(aMidPerpDir->xy()->multiplied(aDist));
+
+    data()->blockSendAttributeUpdated(true);
+    aCenterAttr->setValue(aCenter->x(), aCenter->y());
+    updateDependentAttributes();
+    data()->blockSendAttributeUpdated(false);
     return;
+  }
+  if (theID == ANGLE_ID()) {
+    if (!aStartAttr->isInitialized() || !aCenterAttr->isInitialized())
+      return;
+    data()->blockSendAttributeUpdated(true);
+    // move end point and passed point
+    std::shared_ptr<GeomAPI_XY> aCenter = aCenterAttr->pnt()->xy();
+    double anAngle = anAngleAttr->value() * PI / 180.0;
+    double sinA = sin(anAngle);
+    double cosA = cos(anAngle);
+    std::shared_ptr<GeomAPI_XY> aStartDir = aStartAttr->pnt()->xy()->decreased(aCenter);
+    std::shared_ptr<GeomAPI_XY> aDir(new GeomAPI_XY(
+        aStartDir->x() * cosA - aStartDir->y() * sinA,
+        aStartDir->x() * sinA + aStartDir->y() * cosA));
+    anEndAttr->setValue(aCenter->x() + aDir->x(), aCenter->y() + aDir->y());
 
-  // update the points in accordance to the changed point changes
-  if (theID == CENTER_ID() && !myEndUpdate) {
-    myEndUpdate = true;
+    anAngle /= 2.0;
+    sinA = sin(anAngle);
+    cosA = cos(anAngle);
+    aDir = std::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(
+        aStartDir->x() * cosA - aStartDir->y() * sinA,
+        aStartDir->x() * sinA + aStartDir->y() * cosA));
+    std::shared_ptr<GeomDataAPI_Point2D> aPassedPoint =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
+    aPassedPoint->setValue(aCenter->x() + aDir->x(), aCenter->y() + aDir->y());
+
+    std::shared_ptr<GeomAPI_Circ2d> aCircle(
+        new GeomAPI_Circ2d(aStartAttr->pnt(), anEndAttr->pnt(), aPassedPoint->pnt()));
+    calculateArcAngleRadius(aCircle, aStartAttr->pnt(), anEndAttr->pnt(), aPassedPoint->pnt(),
+                            anAngleAttr, aRadiusAttr);
+    data()->blockSendAttributeUpdated(false);
+    return;
+  }
+
+  if (theID == CENTER_ID()) {
+    if (!isFeatureValid())
+      return;
+    data()->blockSendAttributeUpdated(true);
     // compute and change the arc end point
     std::shared_ptr<GeomAPI_Circ2d> aCircleForArc(
         new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt()));
     std::shared_ptr<GeomAPI_Pnt2d> aProjection = aCircleForArc->project(anEndAttr->pnt());
     if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance)
       anEndAttr->setValue(aProjection);
-    myEndUpdate = false;
+    updateDependentAttributes();
+    data()->blockSendAttributeUpdated(false);
+    return;
+  }
+
+  AttributeStringPtr aTypeAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeString>(attribute(ARC_TYPE()));
+  if (!aTypeAttr)
+    return;
+  std::string anArcType = aTypeAttr->value();
+
+  // update the points in accordance to the changed point changes
+  if (anArcType == ARC_TYPE_CENTER_START_END()) {
+    if (!isFeatureValid())
+      return;
+    updateDependentAttributes();
+  }
+  else if (anArcType == ARC_TYPE_THREE_POINTS() &&
+          (theID == START_ID() || theID == END_ID() || theID == PASSED_POINT_ID())) {
+    data()->blockSendAttributeUpdated(true);
+
+    std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
+    int aNbInitialized = 0;
+    for (int i = 1; i <= 3; ++i) {
+      std::shared_ptr<GeomDataAPI_Point2D> aCurPnt =
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(POINT_ID(i)));
+      if (aCurPnt->isInitialized())
+        aPoints[aNbInitialized++] = aCurPnt->pnt();
+    }
+
+    if (aNbInitialized == 1)
+      aCenterAttr->setValue(aPoints[0]->x(), aPoints[0]->y());
+    else if (aNbInitialized == 2) {
+      // calculate center point, which gives a quarter of circle for the given start and end points
+      std::shared_ptr<GeomAPI_Pnt2d> aStartPnt = aPoints[0];
+      std::shared_ptr<GeomAPI_Pnt2d> aEndPnt = aPoints[1];
+      std::shared_ptr<GeomAPI_XY> aDir = aEndPnt->xy()->decreased(aStartPnt->xy())->multiplied(0.5);
+      double x = aDir->x();
+      double y = aDir->y();
+      aDir->setX(x - y);
+      aDir->setY(y + x);
+      std::shared_ptr<GeomAPI_XY> aCenter = aStartPnt->xy()->added(aDir);
+      double aRadius = sqrt(aDir->dot(aDir));
+
+      aCenterAttr->setValue(aCenter->x(), aCenter->y());
+      aRadiusAttr->setValue(aRadius);
+      anAngleAttr->setValue(90.0);
+    }
+    else {
+      std::shared_ptr<GeomAPI_Circ2d> aCircle(
+          new GeomAPI_Circ2d(aPoints[0], aPoints[1], aPoints[2]));
+
+      std::shared_ptr<GeomAPI_Pnt2d> aCenter = aCircle->center();
+      if (aCenter) {
+        aCenterAttr->setValue(aCenter);
+        if (theID == START_ID() || theID == END_ID())
+          updateDependentAttributes();
+        else
+          calculateArcAngleRadius(aCircle, aPoints[0], aPoints[1], aPoints[2],
+                                  anAngleAttr, aRadiusAttr);
+      }
+    }
+
+    data()->blockSendAttributeUpdated(false);
+  }
+  else if (anArcType == ARC_TYPE_TANGENT() && (theID == TANGENT_POINT_ID() || theID == END_ID())) {
+    SketchPlugin_Sketch* aSketch = sketch();
+    AttributeRefAttrPtr aTangPtAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        data()->attribute(TANGENT_POINT_ID()));
+
+    if (aTangPtAttr->isInitialized() && anEndAttr->isInitialized()) {
+      data()->blockSendAttributeUpdated(true);
+      // compute orthogonal direction
+      std::shared_ptr<GeomAPI_Dir2d> anOrthoDir;
+      std::shared_ptr<GeomDataAPI_Point2D> aTangentPoint =
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aTangPtAttr->attr());
+      std::shared_ptr<GeomAPI_Pnt2d> aTangPnt2d = aTangentPoint->pnt();
+      FeaturePtr aTangFeature = ModelAPI_Feature::feature(aTangentPoint->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(aTangPnt2d->xy()->decreased(aCenter2d->xy())));
+      }
+
+      // compute parameters of the middle perpendicular
+      std::shared_ptr<GeomAPI_XY> aEndPntCoord = anEndAttr->pnt()->xy();
+      std::shared_ptr<GeomAPI_XY> aTempDir = aEndPntCoord->decreased(aTangPnt2d->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(aTangPnt2d->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(aTangPnt2d, anOrthoDir));
+      std::shared_ptr<GeomAPI_Lin2d> aMiddleLine(new GeomAPI_Lin2d(aMidPnt, aMidDir));
+      std::shared_ptr<GeomAPI_Pnt2d> aCenter = anOrthoLine->intersect(aMiddleLine);
+      if (aCenter) {
+        aCenterAttr->setValue(aCenter);
+        aStartAttr->setValue(aTangPnt2d);
+        updateDependentAttributes();
+      }
+
+      data()->blockSendAttributeUpdated(false);
+
+      if (theID == TANGENT_POINT_ID())
+        tangencyArcConstraints();
+    }
   }
 }
 
@@ -273,3 +648,147 @@ bool SketchPlugin_Arc::isReversed()
 {
   return std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(attribute(INVERSED_ID()))->value();
 }
+
+void SketchPlugin_Arc::tangencyArcConstraints()
+{
+  if (!lastResult())
+    return;
+
+  std::shared_ptr<GeomDataAPI_Point2D> aStartAttr =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_ID()));
+  AttributeRefAttrPtr aTangPtAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+      attribute(TANGENT_POINT_ID()));
+  if (!aTangPtAttr->attr())
+    return;
+
+  FeaturePtr aFeature = ModelAPI_Feature::feature(aStartAttr->owner());
+  ObjectPtr aThisArc = aFeature->lastResult();
+  aFeature = ModelAPI_Feature::feature(aTangPtAttr->attr()->owner());
+  ObjectPtr aTangFeature = aFeature->lastResult();
+
+  // trying to find constraints to fix the tangency of the arc
+  std::set<FeaturePtr> aCoincidence;
+  std::set<FeaturePtr> aTangency;
+
+  AttributeRefAttrPtr aRefAttrA, aRefAttrB;
+  std::set<AttributePtr> aRefs = data()->refsToMe();
+  const std::set<AttributePtr>& aRefsToResult = lastResult()->data()->refsToMe();
+  aRefs.insert(aRefsToResult.begin(), aRefsToResult.end());
+  std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin();
+  for (; aRefIt != aRefs.end(); ++aRefIt) {
+    FeaturePtr aConstrFeature = ModelAPI_Feature::feature((*aRefIt)->owner());
+    if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+      aRefAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+          aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+      aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+          aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+      if ((aRefAttrA && aRefAttrA->attr() == aStartAttr) ||
+          (aRefAttrB && aRefAttrB->attr() == aStartAttr))
+        aCoincidence.insert(aConstrFeature);
+    }
+    else if (aConstrFeature->getKind() == SketchPlugin_ConstraintTangent::ID()) {
+      aRefAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+          aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+      aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+          aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+      if ((aRefAttrA && aRefAttrA->object() == aThisArc) ||
+          (aRefAttrB && aRefAttrB->object() == aThisArc))
+        aTangency.insert(aConstrFeature);
+    }
+  }
+  // search applicable pair of constraints
+  bool isFound = false;
+  FeaturePtr aPrevCoincidence, aPrevTangency;
+  std::set<FeaturePtr>::const_iterator aCIt, aTIt;
+  for (aCIt = aCoincidence.begin(); aCIt != aCoincidence.end() && !isFound; ++aCIt) {
+    aRefAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        (*aCIt)->attribute(SketchPlugin_Constraint::ENTITY_A()));
+    aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        (*aCIt)->attribute(SketchPlugin_Constraint::ENTITY_B()));
+    AttributePtr anOtherPoint =
+        aRefAttrA->attr() == aStartAttr ? aRefAttrB->attr() : aRefAttrA->attr();
+    for (aTIt = aTangency.begin(); aTIt != aTangency.end() && !isFound; ++aTIt) {
+      aRefAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+          (*aTIt)->attribute(SketchPlugin_Constraint::ENTITY_A()));
+      aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+          (*aTIt)->attribute(SketchPlugin_Constraint::ENTITY_B()));
+      ObjectPtr anOtherObject = aRefAttrA->object() == aThisArc ?
+          aRefAttrB->object() : aRefAttrA->object();
+      if (anOtherPoint->owner() == anOtherObject) {
+        isFound = true;
+        aPrevCoincidence = *aCIt;
+        aPrevTangency = *aTIt;
+      }
+    }
+  }
+
+  if (isFound) {
+    // update previous constraints
+    aRefAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aPrevCoincidence->attribute(SketchPlugin_Constraint::ENTITY_A()));
+    aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aPrevCoincidence->attribute(SketchPlugin_Constraint::ENTITY_B()));
+    if (aRefAttrA->attr() == aStartAttr)
+      aRefAttrB->setAttr(aTangPtAttr->attr());
+    else
+      aRefAttrA->setAttr(aTangPtAttr->attr());
+
+    aRefAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aPrevTangency->attribute(SketchPlugin_Constraint::ENTITY_A()));
+    aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aPrevTangency->attribute(SketchPlugin_Constraint::ENTITY_B()));
+    if (aRefAttrA->object() == aThisArc)
+      aRefAttrB->setObject(aTangFeature);
+    else
+      aRefAttrA->setObject(aTangFeature);
+  } else {
+    // Wait all constraints being removed, then send update events
+    static Events_ID aDeleteEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
+    bool isDeleteFlushed = Events_Loop::loop()->isFlushed(aDeleteEvent);
+    if (isDeleteFlushed)
+      Events_Loop::loop()->setFlushed(aDeleteEvent, false);
+    // Remove all obtained constraints which use current arc, because
+    // there is no information which of them were used to build tangency arc.
+    DocumentPtr aDoc = sketch()->document();
+    for (aCIt = aCoincidence.begin(); aCIt != aCoincidence.end(); ++aCIt)
+      aDoc->removeFeature(*aCIt);
+    for (aTIt = aTangency.begin(); aTIt != aTangency.end(); ++aTIt)
+      aDoc->removeFeature(*aTIt);
+    // Send events to update the sub-features by the solver.
+    if (isDeleteFlushed)
+      Events_Loop::loop()->setFlushed(aDeleteEvent, true);
+    else
+      Events_Loop::loop()->flush(aDeleteEvent);
+
+    // Wait all constraints being created, then send update events
+    static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+    bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
+    if (isUpdateFlushed)
+      Events_Loop::loop()->setFlushed(anUpdateEvent, false);
+
+    // Create new constraints
+    FeaturePtr aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+    aRefAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
+    aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
+    aRefAttrA->setAttr(aStartAttr);
+    aRefAttrB->setAttr(aTangPtAttr->attr());
+    aConstraint->execute();
+    ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
+
+    aConstraint = sketch()->addFeature(SketchPlugin_ConstraintTangent::ID());
+    aRefAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
+    aRefAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
+    aRefAttrA->setObject(aThisArc);
+    aRefAttrB->setObject(aTangFeature);
+    aConstraint->execute();
+    ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
+
+    // Send events to update the sub-features by the solver.
+    if(isUpdateFlushed)
+      Events_Loop::loop()->setFlushed(anUpdateEvent, true);
+  }
+}
index 296b849bc0bebb6204d094c1aec97b784095c37a..2bd7c0c44ab7a918cc71d019af17cb03617befcb 100644 (file)
@@ -105,6 +105,12 @@ protected:
 private:
   /// Returns true if all obligatory attributes are initialized
   bool isFeatureValid();
+
+  /// Update attributes like passed point, radius and angle of the arc
+  void updateDependentAttributes();
+
+  /// Compose constraints to build tangency arc
+  void tangencyArcConstraints();
 };
 
 #endif
index ea819628e51eae8e7778effaa5f9b71a8169d6e4..f252df658aec33b08ba84de96b6d1de0512e733f 100644 (file)
@@ -30,12 +30,12 @@ namespace {
     static const std::string TYPE("CircleType");
     return TYPE;
   }
-  static const std::string CIRCLE_TYPE_CENTER_AND_RADIUS()
+  static const std::string& CIRCLE_TYPE_CENTER_AND_RADIUS()
   {
     static const std::string TYPE("CenterRadius");
     return TYPE;
   }
-  static const std::string CIRCLE_TYPE_THREE_POINTS()
+  static const std::string& CIRCLE_TYPE_THREE_POINTS()
   {
     static const std::string TYPE("ThreePoints");
     return TYPE;
index 46bbf6a6629977e6169a4ba634874da87500fd82..9ac7fec38ced2bf36cc5332a4b84f87460046722 100755 (executable)
@@ -125,6 +125,8 @@ static bool hasCoincidentPoint(FeaturePtr theFeature1, FeaturePtr theFeature2)
       anAttr = aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_B());
 
     aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
+    if (!aRefAttr)
+      continue;
     anAttr = aRefAttr->attr();
     for (std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
          anIt != anAttrList.end(); ++anIt)
index 98d339bc8bfc05642fd741c4818c46c4f16bf92a..68e7e32f0a9b8753f46e8c1cb8dc29600cf2c235 100644 (file)
             <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set radius">
               <validator id="GeomValidators_Positive"/>
             </point2ddistance>
+            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
           </box>
-          <box id="ThreePoints" title="Tree points" icon=":icons/circle_3pt_32x32.png">
+          <box id="ThreePoints" title="Three points" icon=":icons/circle_3pt_32x32.png">
             <sketch-2dpoint_selector id="FirstPoint" accept_expressions="0" title="First point" tooltip="First point"/>
             <sketch-2dpoint_selector id="SecondPoint" accept_expressions="0" title="Second point" tooltip="Second point"/>
             <sketch-2dpoint_selector id="ThirdPoint" accept_expressions="0" title="Third point" tooltip="Third point"/>
+            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
           </box>
         </toolbox>
-        <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
 
-      <feature id="SketchArc" title="Arc" tooltip="Create arc" icon=":icons/arc.png">
-        <sketch-2dpoint_selector id="ArcCenter" accept_expressions="0" title="Center" tooltip="Center of a circle"/>
-        <sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"/>
-        <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
-        <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
-        <validator id="GeomValidators_Different" parameters="ArcCenter,ArcStartPoint,ArcEndPoint"/>
+      <!-- SketchArc -->
+      <feature
+        id="SketchArc"
+        title="Arc"
+        tooltip="Create arc"
+        icon=":icons/arc.png">
+        <toolbox id="ArcType">
+          <box id="CenterStartEnd" title="Center and two points" icon=":icons/arc_base_32x32.png">
+            <sketch-2dpoint_selector id="ArcCenter" accept_expressions="0" title="Center" tooltip="Center of a circle"/>
+            <sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"/>
+            <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
+            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+            <validator id="GeomValidators_Different" parameters="ArcCenter,ArcStartPoint,ArcEndPoint"/>
+          </box>
+          <box id="ThreePoints" title="Three points on arc" icon=":icons/arc_3pt_32x32.png">
+            <sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"/>
+            <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
+            <sketch-2dpoint_selector id="ArcPassedPoint" accept_expressions="0" title="Passed point" tooltip="Passed point"/>
+            <doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon=":icons/radius.png" tooltip="Set radius" obligatory="1">
+              <validator id="GeomValidators_Positive"/>
+            </doublevalue>
+            <doublevalue id="ArcAngle" label="Angle:" icon=":icons/angle.png" tooltip="Set angle" default="90" use_reset="false" obligatory="1"/>
+            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+            <validator id="GeomValidators_Different" parameters="ArcStartPoint,ArcEndPoint,ArcPassedPoint"/>
+          </box>
+          <box id="Tangent" title="Tangent with edge" icon=":icons/arc_tang_32x32.png">
+            <sketch_shape_selector id="ArcTangentPoint" label="Start point" tooltip="Select point on line" shape_types="vertex" />
+            <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"/>
+            <doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon=":icons/radius.png" tooltip="Set radius" obligatory="1">
+              <validator id="GeomValidators_Positive"/>
+            </doublevalue>
+            <doublevalue id="ArcAngle" label="Angle:" icon=":icons/angle.png" tooltip="Set angle" default="90" use_reset="false" obligatory="1"/>
+            <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+          </box>
+        </toolbox>
       </feature>
+
       <!--  SketchConstraintFillet  -->
       <feature id="SketchConstraintFillet" title="Fillet" tooltip="Create constraint defining fillet between two objects" icon=":icons/fillet.png">
         <!--<sketch_shape_selector id="ConstraintEntityA"
         <validator id="PartSet_PerpendicularSelection"/>
       </feature>
 
-      <!--  SketchConstraintCoincedence  -->
+      <!--  SketchConstraintCoincidence  -->
       <feature id="SketchConstraintCoincidence" title="Coincident" tooltip="Create constraint for the coincidence of two points or point on line or circle" icon=":icons/coincedence.png">
         <sketch_shape_selector id="ConstraintEntityA" label="First object" tooltip="Select a first object" shape_types="vertex edge">
           <validator id="PartSet_DifferentObjects"/>
index 96fa9ea2f8f3e2ab7eebc2feb1a2c33f3680aaf0..404c5df7fb455fc6d0707e592d7ae33f00bc5450 100644 (file)
@@ -7,7 +7,9 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
 
 void SketchSolver_ConstraintMulti::getEntities(std::list<EntityWrapperPtr>& theEntities)
 {
@@ -155,8 +157,10 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
       } else if (aFeature->getKind() == SketchPlugin_Line::ID()) {
         aPoints.push_back(aFeature->attribute(SketchPlugin_Line::START_ID()));
         aPoints.push_back(aFeature->attribute(SketchPlugin_Line::END_ID()));
-      } else
-        aPoints = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+      } else if (aFeature->getKind() == SketchPlugin_Circle::ID())
+        aPoints.push_back(aFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
+      else if (aFeature->getKind() == SketchPlugin_Point::ID())
+        aPoints.push_back(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
 
       std::list<AttributePtr>::iterator aPtIt = aPoints.begin();
       for (aXIt = aX.begin(), aYIt = aY.begin(); aPtIt != aPoints.end(); ++aXIt, ++aYIt, ++aPtIt) {
index 8370549174a16d7acc09de33e539a67599f88123..e149fe03da081d072561403f4bd2fa3c2b9a05bc 100644 (file)
@@ -12,6 +12,8 @@
 #include <ModelAPI_AttributeRefList.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
 #include <SketchPlugin_ConstraintRigid.h>
 
 
@@ -80,6 +82,25 @@ void SketchSolver_Storage::addConstraint(
     theConstraint->data()->blockSendAttributeUpdated(myEventsBlocked);
 }
 
+static std::list<AttributePtr> pointAttributes(FeaturePtr theFeature)
+{
+  std::list<AttributePtr> aPoints;
+  if (theFeature->getKind() == SketchPlugin_Arc::ID()) {
+    aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
+    aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::START_ID()));
+    aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::END_ID()));
+  }
+  else if (theFeature->getKind() == SketchPlugin_Circle::ID())
+    aPoints.push_back(theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
+  else if (theFeature->getKind() == SketchPlugin_Line::ID()) {
+    aPoints.push_back(theFeature->attribute(SketchPlugin_Line::START_ID()));
+    aPoints.push_back(theFeature->attribute(SketchPlugin_Line::END_ID()));
+  }
+  else if (theFeature->getKind() == SketchPlugin_Point::ID())
+    aPoints.push_back(theFeature->attribute(SketchPlugin_Point::ID()));
+  return aPoints;
+}
+
 void SketchSolver_Storage::addEntity(FeaturePtr       theFeature,
                                      EntityWrapperPtr theSolverEntity)
 {
@@ -90,8 +111,7 @@ void SketchSolver_Storage::addEntity(FeaturePtr       theFeature,
 
   if (!theSolverEntity) {
     // feature links to the empty entity, add its attributes
-    std::list<AttributePtr> aPntAttrs =
-        theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+    std::list<AttributePtr> aPntAttrs = pointAttributes(theFeature);
     std::list<AttributePtr>::const_iterator anAttrIt = aPntAttrs.begin();
     for (; anAttrIt != aPntAttrs.end(); ++anAttrIt)
       addEntity(*anAttrIt, EntityWrapperPtr());
@@ -131,8 +151,7 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup
     // Reserve the feature in the map of features (do not want to add several copies of it)
     myFeatureMap[theFeature] = aRelated;
     // Firstly, create/update its attributes
-    std::list<AttributePtr> anAttrs =
-        theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+    std::list<AttributePtr> anAttrs = pointAttributes(theFeature);
     std::list<AttributePtr>::const_iterator anIt = anAttrs.begin();
     for (; anIt != anAttrs.end(); ++anIt) {
       isUpdated = update(*anIt, theGroup) || isUpdated;
@@ -335,7 +354,7 @@ bool SketchSolver_Storage::isUsed(FeaturePtr theFeature) const
       if (::isUsed(*aCWIt, theFeature))
         return true;
   // check attributes
-  std::list<AttributePtr> anAttrList = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+  std::list<AttributePtr> anAttrList = pointAttributes(theFeature);
   std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
   for (; anIt != anAttrList.end(); ++anIt)
     if (isUsed(*anIt))