]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2024: Redesign of circle and arc of circle
authordbv <dbv@opencascade.com>
Mon, 20 Mar 2017 07:29:31 +0000 (10:29 +0300)
committerdbv <dbv@opencascade.com>
Mon, 27 Mar 2017 06:56:51 +0000 (09:56 +0300)
Redesigned circle creation. Now Circle feature is a macro which creates Circle feature with center and radius attributes.

28 files changed:
src/GeomData/GeomData_Point2D.cpp
src/GeomData/GeomData_Point2D.h
src/Model/Model_AttributeDouble.cpp
src/Model/Model_AttributeDouble.h
src/ModelAPI/ModelAPI_Attribute.cpp
src/ModelAPI/ModelAPI_Attribute.h
src/ModelAPI/ModelAPI_Expression.h
src/PartSet/PartSet_SketcherReetntrantMgr.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Circle.cpp
src/SketchAPI/SketchAPI_Circle.h
src/SketchAPI/SketchAPI_MacroCircle.cpp [new file with mode: 0644]
src/SketchAPI/SketchAPI_MacroCircle.h [new file with mode: 0644]
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchAPI/SketchAPI_swig.h
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/SketchPlugin_MacroCircle.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_MacroCircle.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Tools.cpp
src/SketchPlugin/SketchPlugin_Tools.h
src/SketchPlugin/SketchPlugin_msg_en.ts
src/SketchPlugin/plugin-Sketch.xml

index 30b47115db5de6be77771f18910dac0cb8c6b8c6..ced572f4eb014f1cb9742b009fa7b4b47587e812 100644 (file)
@@ -29,6 +29,14 @@ void GeomData_Point2D::reinit()
   }
 }
 
+void GeomData_Point2D::reset()
+{
+  myIsInitialized = false;
+  for(int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
+    myExpression[aComponent]->reset();
+  }
+}
+
 void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
 {
   if (!myIsInitialized || x() != theX || y() != theY) {
index a4864c6c45a52e7c6998b5c39286122bdc7211be..3bb62e8a02cd1b7a1d47d38cd2978e99d8be41d7 100644 (file)
@@ -72,6 +72,9 @@ class GeomData_Point2D : public GeomDataAPI_Point2D
   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
   virtual void reinit();
 
+  /// Resets attribute to deafult state.
+  virtual void reset();
+
   friend class Model_Data;
 };
 
index 4efa7bedc3a244432963aa536f4e794ab4f5c01b..1e942faa6b8c630ff30390e8c75b2b5c672bb55e 100644 (file)
@@ -24,6 +24,12 @@ void Model_AttributeDouble::reinit()
   myIsInitialized = myExpression->isInitialized();
 }
 
+void Model_AttributeDouble::reset()
+{
+  myExpression->reset();
+  myIsInitialized = false;
+}
+
 void Model_AttributeDouble::setCalculatedValue(const double theValue)
 {
   if (!myIsInitialized || value() != theValue) {
index 883b9b545c81c5d298cdb13c2e3c6c8223f86f73..17b82ea654cdee5352b0b346a1c240d430b4871b 100644 (file)
@@ -63,6 +63,9 @@ class Model_AttributeDouble : public ModelAPI_AttributeDouble
   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
   virtual void reinit();
 
+  /// Resets attribute to deafult state.
+  virtual void reset();
+
   friend class Model_Data;
 };
 
index 97373a087e11705e2c1eb7ad23f4f3bc0ef11d95..69465bf6160e38e08780489ddde7d6249274c2cf 100644 (file)
@@ -85,3 +85,5 @@ void ModelAPI_Attribute::setID(const std::string theID)
 }
 
 void ModelAPI_Attribute::reinit() {}
+
+void ModelAPI_Attribute::reset() {}
index 1ea1523b74c9304f4d05cc3b4965cf52d8eea40d..ba23fe9e7175eed57f567eefebc20e6731932b1f 100644 (file)
@@ -73,6 +73,9 @@ class ModelAPI_Attribute
   /// ID of the attribute in Data
   MODELAPI_EXPORT const std::string& id() const;
 
+  /// Resets attribute to deafult state.
+  MODELAPI_EXPORT virtual void reset();
+
  protected:
   /// Objects are created for features automatically
   MODELAPI_EXPORT ModelAPI_Attribute();
index fd00670cc7618efe8a9260f50b4ff010fde77013..769a4eebc42d275890a94813ba09f5418e02a7ee 100644 (file)
@@ -62,6 +62,10 @@ class ModelAPI_Expression
   MODELAPI_EXPORT ModelAPI_Expression();
   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
   MODELAPI_EXPORT virtual void reinit() = 0;
+  /// Resets attribute to deafult state.
+  MODELAPI_EXPORT virtual void reset() {
+    myIsInitialized = false;
+  };
 
   bool myIsInitialized; ///< is some value assigned to this attribute
 
index 3cbc1cc5dad9bc65588d5995c4c64361e0dd81db..36ae785138e08fab64f625e3427312b1452f81bc 100755 (executable)
@@ -26,7 +26,7 @@
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Arc.h>
-#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_MacroCircle.h>
 #include <SketchPlugin_Point.h>
 
 #include <XGUI_Workshop.h>
@@ -599,9 +599,9 @@ bool PartSet_SketcherReetntrantMgr::copyReetntrantAttributes(const FeaturePtr& t
                                                  aSFData->attribute(SketchPlugin_Line::END_ID()));
     aNPoint->setValue(aSPoint->x(), aSPoint->y());
   }
-  else if (aFeatureKind == SketchPlugin_Circle::ID()) {
+  else if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
     // set circle type
-    std::string aTypeAttributeId = SketchPlugin_Circle::CIRCLE_TYPE();
+    std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
     AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
     AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
     aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
index 03995e89709e89d76c905ddb4485a628633197e9..2a8d1a0aa718e4e2de3a7de1f9d1ca3414d178e0 100644 (file)
@@ -67,6 +67,8 @@ const double MaxCoordinate = 1e12;
 
 static QStringList MyFeaturesForCoincedence;
 
+#define DEBUG_SELECTION
+
 PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
                                              ModuleBase_IWorkshop* theWorkshop,
                                              const Config_WidgetAPI* theData)
@@ -572,7 +574,9 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
         bool isAuxiliaryFeature = false;
         if (getPoint2d(aView, aShape, aX, aY)) {
           setPoint(aX, aY);
+#ifndef DEBUG_SELECTION
           feature()->execute();
+#endif
 
           setConstraintToPoint(aX, aY);
         }
@@ -780,7 +784,11 @@ bool PartSet_WidgetPoint2D::shapeContainsPoint(const GeomShapePtr& theShape,
     if (aVertex.get())
       aContainPoint = aPoint->isEqual(aVertex->point());
   }
+#ifdef DEBUG_SELECTION
+  return true;
+#else
   return aContainPoint;
+#endif
 }
 
 AttributeRefAttrPtr PartSet_WidgetPoint2D::attributeRefAttr() const
index 18db87fc55a7507001a22d4a3a258095c5a5bb9b..0b8b8914a08eb9939bc1c65699557f0440b74cb2 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
   SketchAPI_Constraint.h
   SketchAPI_IntersectionPoint.h
   SketchAPI_Line.h
+  SketchAPI_MacroCircle.h
   SketchAPI_Mirror.h
   SketchAPI_Sketch.h
   SketchAPI_SketchEntity.h
@@ -25,6 +26,7 @@ SET(PROJECT_SOURCES
   SketchAPI_Constraint.cpp
   SketchAPI_IntersectionPoint.cpp
   SketchAPI_Line.cpp
+  SketchAPI_MacroCircle.cpp
   SketchAPI_Mirror.cpp
   SketchAPI_Sketch.cpp
   SketchAPI_SketchEntity.cpp
index 6bc6cf6c6b70944141455230c252e9615fededaa..c5ceee14d12f040edfa6c2e294960b48d19cceee 100644 (file)
@@ -27,6 +27,7 @@
 // shared pointers
 %shared_ptr(SketchAPI_Arc)
 %shared_ptr(SketchAPI_Circle)
+%shared_ptr(SketchAPI_MacroCircle)
 %shared_ptr(SketchAPI_Constraint)
 %shared_ptr(SketchAPI_IntersectionPoint)
 %shared_ptr(SketchAPI_Line)
 %include "SketchAPI_IntersectionPoint.h"
 %include "SketchAPI_Line.h"
 %include "SketchAPI_Circle.h"
+%include "SketchAPI_MacroCircle.h"
 %include "SketchAPI_Arc.h"
 %include "SketchAPI_Projection.h"
 %include "SketchAPI_Mirror.h"
index 9cac0bd31cbf58bee789d7d87dd9fe9d78f92ba7..ddb26aef5fae0fd0f42914abcff005accd82336e 100644 (file)
@@ -43,30 +43,6 @@ SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theF
   }
 }
 
-//==================================================================================================
-SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                                   double theX1, double theY1,
-                                   double theX2, double theY2,
-                                   double theX3, double theY3)
-: SketchAPI_SketchEntity(theFeature)
-{
-  if (initialize()) {
-    setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3);
-  }
-}
-
-//==================================================================================================
-SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
-                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
-                                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
-: SketchAPI_SketchEntity(theFeature)
-{
-  if (initialize()) {
-    setByThreePoints(thePoint1, thePoint2, thePoint3);
-  }
-}
-
 //==================================================================================================
 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                    const ModelHighAPI_Selection& theExternal)
@@ -96,7 +72,6 @@ SketchAPI_Circle::~SketchAPI_Circle()
 //==================================================================================================
 void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
 {
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
   fillAttribute(center(), theCenterX, theCenterY);
   fillAttribute(theRadius, myradius);
 
@@ -107,39 +82,12 @@ void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY
 void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                                             double theRadius)
 {
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
   fillAttribute(theCenter, mycenter);
   fillAttribute(theRadius, myradius);
 
   execute();
 }
 
-//==================================================================================================
-void SketchAPI_Circle::setByThreePoints(double theX1, double theY1,
-                                        double theX2, double theY2,
-                                        double theX3, double theY3)
-{
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
-  fillAttribute(firstPoint(), theX1, theY1);
-  fillAttribute(secondPoint(), theX2, theY2);
-  fillAttribute(thirdPoint(), theX3, theY3);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
-                                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
-                                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
-{
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
-  fillAttribute(thePoint1, myfirstPoint);
-  fillAttribute(thePoint2, mysecondPoint);
-  fillAttribute(thePoint3, mythirdPoint);
-
-  execute();
-}
-
 //==================================================================================================
 void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
 {
@@ -159,7 +107,6 @@ void SketchAPI_Circle::setByExternalName(const std::string & theExternalName)
 //==================================================================================================
 void SketchAPI_Circle::setCenter(double theX, double theY)
 {
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
   fillAttribute(center(), theX, theY);
 
   execute();
@@ -168,7 +115,6 @@ void SketchAPI_Circle::setCenter(double theX, double theY)
 //==================================================================================================
 void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
 {
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
   fillAttribute(theCenter, mycenter);
 
   execute();
@@ -177,66 +123,11 @@ void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCente
 //==================================================================================================
 void SketchAPI_Circle::setRadius(double theRadius)
 {
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
   fillAttribute(ModelHighAPI_Double(theRadius), myradius);
 
   execute();
 }
 
-//==================================================================================================
-void SketchAPI_Circle::setFirstPoint(double theX, double theY)
-{
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
-  fillAttribute(firstPoint(), theX, theY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
-  fillAttribute(thePoint, myfirstPoint);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setSecondPoint(double theX, double theY)
-{
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
-  fillAttribute(secondPoint(), theX, theY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
-  fillAttribute(thePoint, mysecondPoint);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setThirdPoint(double theX, double theY)
-{
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
-  fillAttribute(thirdPoint(), theX, theY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
-  fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
-  fillAttribute(thePoint, mythirdPoint);
-
-  execute();
-}
-
 //==================================================================================================
 void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
 {
@@ -251,16 +142,9 @@ void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
     // circle is external
     theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
   } else {
-    AttributeStringPtr aType = circleType();
-    if (aType->value() == SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS()) {
-      // circle given by center and radius
-      theDumper << aBase << " = " << aSketchName << ".addCircle("
-                << center() << ", " << radius() << ")" << std::endl;
-    } else {
-      // circle given by three points
-      theDumper << aBase << " = " << aSketchName << ".addCircle(" << firstPoint() << ", "
-                << secondPoint() << ", " << thirdPoint() << ")" << std::endl;
-    }
+    // circle given by center and radius
+    theDumper << aBase << " = " << aSketchName << ".addCircle("
+              << center() << ", " << radius() << ")" << std::endl;
   }
   // dump "auxiliary" flag if necessary
   SketchAPI_SketchEntity::dump(theDumper);
index 99e0aefc1cda80d628bd9c3191f34c1bdf5ebce5..fe5e5f473c1b1188eeb96c663c90d01649f932a7 100644 (file)
@@ -37,20 +37,6 @@ public:
                    const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                    double theRadius);
 
-  /// Constructor with values.
-  SKETCHAPI_EXPORT
-  SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                   double theX1, double theY1,
-                   double theX2, double theY2,
-                   double theX3, double theY3);
-
-  /// Constructor with values.
-  SKETCHAPI_EXPORT
-  SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
-                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
-                   const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
-
   /// Constructor with values.
   SKETCHAPI_EXPORT
   SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
@@ -65,19 +51,11 @@ public:
   SKETCHAPI_EXPORT
   virtual ~SketchAPI_Circle();
 
-  INTERFACE_7(SketchPlugin_Circle::ID(),
-              circleType, SketchPlugin_Circle::CIRCLE_TYPE(),
-              ModelAPI_AttributeString, /** Circle type */,
+  INTERFACE_3(SketchPlugin_Circle::ID(),
               center, SketchPlugin_Circle::CENTER_ID(),
               GeomDataAPI_Point2D, /** Center point */,
               radius, SketchPlugin_Circle::RADIUS_ID(),
               ModelAPI_AttributeDouble, /** Radius */,
-              firstPoint, SketchPlugin_Circle::FIRST_POINT_ID(),
-              GeomDataAPI_Point2D, /** First point */,
-              secondPoint, SketchPlugin_Circle::SECOND_POINT_ID(),
-              GeomDataAPI_Point2D, /** Second point */,
-              thirdPoint, SketchPlugin_Circle::THIRD_POINT_ID(),
-              GeomDataAPI_Point2D, /** Third point */,
               external, SketchPlugin_Circle::EXTERNAL_ID(),
               ModelAPI_AttributeSelection, /** External */)
 
@@ -89,18 +67,6 @@ public:
   SKETCHAPI_EXPORT
   void setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter, double theRadius);
 
-  /// Set by three points.
-  SKETCHAPI_EXPORT
-  void setByThreePoints(double theX1, double theY1,
-                        double theX2, double theY2,
-                        double theX3, double theY3);
-
-  /// Set by three points.
-  SKETCHAPI_EXPORT
-  void setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
-                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
-                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
-
   /// Set by external.
   SKETCHAPI_EXPORT
   void setByExternal(const ModelHighAPI_Selection& theExternal);
@@ -121,30 +87,6 @@ public:
   SKETCHAPI_EXPORT
   void setRadius(double theRadius);
 
-  /// Set first point.
-  SKETCHAPI_EXPORT
-  void setFirstPoint(double theX, double theY);
-
-  /// Set first point.
-  SKETCHAPI_EXPORT
-  void setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
-  /// Set second point.
-  SKETCHAPI_EXPORT
-  void setSecondPoint(double theX, double theY);
-
-  /// Set second point.
-  SKETCHAPI_EXPORT
-  void setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
-  /// Set third point.
-  SKETCHAPI_EXPORT
-  void setThirdPoint(double theX, double theY);
-
-  /// Set third point.
-  SKETCHAPI_EXPORT
-  void setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
   /// Dump wrapped feature
   SKETCHAPI_EXPORT
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
diff --git a/src/SketchAPI/SketchAPI_MacroCircle.cpp b/src/SketchAPI/SketchAPI_MacroCircle.cpp
new file mode 100644 (file)
index 0000000..e326efb
--- /dev/null
@@ -0,0 +1,215 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchAPI_MacroCircle.cpp
+// Created:     09 June 2016
+// Author:      Dmitry Bobylev
+
+#include "SketchAPI_MacroCircle.h"
+
+#include <GeomAPI_Pnt2d.h>
+
+#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+  initialize();
+}
+
+//==================================================================================================
+SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                             double theCenterX,
+                                             double theCenterY,
+                                             double thePassedX,
+                                             double thePassedY)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if(initialize()) {
+    setByCenterAndPassedPoints(theCenterX, theCenterY, thePassedX, thePassedY);
+  }
+}
+
+//==================================================================================================
+SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                             const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+                                             const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if(initialize()) {
+    setByCenterAndPassedPoints(theCenterPoint, thePassedPoint);
+  }
+}
+
+//==================================================================================================
+SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                             double theX1, double theY1,
+                                             double theX2, double theY2,
+                                             double theX3, double theY3)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if(initialize()) {
+    setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3);
+  }
+}
+
+//==================================================================================================
+SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                             const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                                             const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                                             const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if(initialize()) {
+    setByThreePoints(thePoint1, thePoint2, thePoint3);
+  }
+}
+
+//==================================================================================================
+SketchAPI_MacroCircle::~SketchAPI_MacroCircle()
+{
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setByCenterAndPassedPoints(double theCenterX,
+                                                       double theCenterY,
+                                                       double thePassedX,
+                                                       double thePassedY)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+  fillAttribute(centerPoint(), theCenterX, theCenterY);
+  fillAttribute(passedPoint(), thePassedX, thePassedY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setByCenterAndPassedPoints(
+    const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+  fillAttribute(theCenterPoint, mycenterPoint);
+  fillAttribute(thePassedPoint, mypassedPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setByThreePoints(double theX1, double theY1,
+                                             double theX2, double theY2,
+                                             double theX3, double theY3)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+  fillAttribute(firstPoint(), theX1, theY1);
+  fillAttribute(secondPoint(), theX2, theY2);
+  fillAttribute(thirdPoint(), theX3, theY3);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                                             const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                                             const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+  fillAttribute(thePoint1, myfirstPoint);
+  fillAttribute(thePoint2, mysecondPoint);
+  fillAttribute(thePoint3, mythirdPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setCenterPoint(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+  fillAttribute(centerPoint(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setCenterPoint(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+  fillAttribute(theCenterPoint, mycenterPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setPassedPoint(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+  fillAttribute(passedPoint(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setPassedPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+  fillAttribute(thePassedPoint, mypassedPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setFirstPoint(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+  fillAttribute(firstPoint(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+  fillAttribute(thePoint, myfirstPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setSecondPoint(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+  fillAttribute(secondPoint(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+  fillAttribute(thePoint, mysecondPoint);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setThirdPoint(double theX, double theY)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+  fillAttribute(thirdPoint(), theX, theY);
+
+  execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+  fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+  fillAttribute(thePoint, mythirdPoint);
+
+  execute();
+}
diff --git a/src/SketchAPI/SketchAPI_MacroCircle.h b/src/SketchAPI/SketchAPI_MacroCircle.h
new file mode 100644 (file)
index 0000000..ccf1f74
--- /dev/null
@@ -0,0 +1,139 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchAPI_MacroCircle.h
+// Created:     09 June 2016
+// Author:      Dmitry Bobylev
+
+#ifndef SketchAPI_MacroCircle_H_
+#define SketchAPI_MacroCircle_H_
+
+#include "SketchAPI.h"
+#include "SketchAPI_SketchEntity.h"
+
+#include <SketchPlugin_MacroCircle.h>
+
+class ModelHighAPI_Selection;
+
+/// \class SketchAPI_MacroCircle
+/// \ingroup CPPHighAPI
+/// \brief Interface for Circle feature.
+class SketchAPI_MacroCircle: public SketchAPI_SketchEntity
+{
+public:
+  /// Constructor without values.
+  SKETCHAPI_EXPORT
+  explicit SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                        double theCenterX,
+                        double theCenterY,
+                        double thePassedX,
+                        double thePassedY);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                        double theX1, double theY1,
+                        double theX2, double theY2,
+                        double theX3, double theY3);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
+
+  /// Destructor.
+  SKETCHAPI_EXPORT
+  virtual ~SketchAPI_MacroCircle();
+
+  INTERFACE_6(SketchPlugin_MacroCircle::ID(),
+              circleType, SketchPlugin_MacroCircle::CIRCLE_TYPE(),
+              ModelAPI_AttributeString, /** Circle type */,
+              centerPoint, SketchPlugin_MacroCircle::CENTER_POINT_ID(),
+              GeomDataAPI_Point2D, /** Center point */,
+              passedPoint, SketchPlugin_MacroCircle::PASSED_POINT_ID(),
+              GeomDataAPI_Point2D, /** Passed point */,
+              firstPoint, SketchPlugin_MacroCircle::FIRST_POINT_ID(),
+              GeomDataAPI_Point2D, /** First point */,
+              secondPoint, SketchPlugin_MacroCircle::SECOND_POINT_ID(),
+              GeomDataAPI_Point2D, /** Second point */,
+              thirdPoint, SketchPlugin_MacroCircle::THIRD_POINT_ID(),
+              GeomDataAPI_Point2D, /** Third point */)
+
+  /// Set by center and passed points.
+  SKETCHAPI_EXPORT
+  void setByCenterAndPassedPoints(double theCenterX, double theCenterY,
+                                  double thePassedX, double thePassedY);
+
+  /// Set by center and passed points.
+  SKETCHAPI_EXPORT
+  void setByCenterAndPassedPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+                                  const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+
+  /// Set by three points.
+  SKETCHAPI_EXPORT
+  void setByThreePoints(double theX1, double theY1,
+                        double theX2, double theY2,
+                        double theX3, double theY3);
+
+  /// Set by three points.
+  SKETCHAPI_EXPORT
+  void setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
+
+  /// Set center point.
+  SKETCHAPI_EXPORT
+  void setCenterPoint(double theX, double theY);
+
+  /// Set center point.
+  SKETCHAPI_EXPORT
+  void setCenterPoint(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint);
+
+  /// Set passed point.
+  SKETCHAPI_EXPORT
+  void setPassedPoint(double theX, double theY);
+
+  /// Set passed point.
+  SKETCHAPI_EXPORT
+  void setPassedPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+
+  /// Set first point.
+  SKETCHAPI_EXPORT
+  void setFirstPoint(double theX, double theY);
+
+  /// Set first point.
+  SKETCHAPI_EXPORT
+  void setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+  /// Set second point.
+  SKETCHAPI_EXPORT
+  void setSecondPoint(double theX, double theY);
+
+  /// Set second point.
+  SKETCHAPI_EXPORT
+  void setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+  /// Set third point.
+  SKETCHAPI_EXPORT
+  void setThirdPoint(double theX, double theY);
+
+  /// Set third point.
+  SKETCHAPI_EXPORT
+  void setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+};
+
+/// Pointer on Circle object.
+typedef std::shared_ptr<SketchAPI_MacroCircle> MacroCirclePtr;
+
+#endif // SketchAPI_MacroCircle_H_
index 11c22f0ae8764b55ca27984a83c510e72e76e24d..e126efdfa69c7812e413f467d299b58f9ff558d1 100644 (file)
@@ -42,6 +42,7 @@
 #include "SketchAPI_Circle.h"
 #include "SketchAPI_IntersectionPoint.h"
 #include "SketchAPI_Line.h"
+#include "SketchAPI_MacroCircle.h"
 #include "SketchAPI_Mirror.h"
 #include "SketchAPI_Point.h"
 #include "SketchAPI_Projection.h"
@@ -294,23 +295,45 @@ std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
   return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
 }
 
-std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
-                                                              double theX2, double theY2,
-                                                              double theX3, double theY3)
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
+                                                                   double theCenterY,
+                                                                   double thePassedX,
+                                                                   double thePassedY)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Circle::ID());
-  return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
+  return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
+                                                            thePassedX, thePassedY));
 }
 
-std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
-                                                const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
-                                                const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
-                                                const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
+    const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+  return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
+}
+
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
+                                                                   double theX2, double theY2,
+                                                                   double theX3, double theY3)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+  return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
+                                                            theX2, theY2,
+                                                            theX3, theY3));
+}
+
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
+    const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+    const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+    const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Circle::ID());
-  return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
+  return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
 }
 
 std::shared_ptr<SketchAPI_Circle>
index 792a8ee79845a6281488d53c9dc04a9c9e92d15c..7e7082c14d1cad5821247fad6bbd9505520bae0d 100644 (file)
@@ -28,6 +28,7 @@ class ModelHighAPI_Reference;
 class ModelHighAPI_Selection;
 class SketchAPI_Arc;
 class SketchAPI_Circle;
+class SketchAPI_MacroCircle;
 class SketchAPI_IntersectionPoint;
 class SketchAPI_Line;
 class SketchAPI_Mirror;
@@ -154,13 +155,23 @@ public:
       double theRadius);
   /// Add circle
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Circle> addCircle(
+  std::shared_ptr<SketchAPI_MacroCircle> addCircle(
+      double theCenterX, double theCenterY,
+      double thePassedX, double thePassedY);
+  /// Add circle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroCircle> addCircle(
+      const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+      const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+  /// Add circle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroCircle> addCircle(
       double theX1, double theY1,
       double theX2, double theY2,
       double theX3, double theY3);
   /// Add circle
   SKETCHAPI_EXPORT
-  std::shared_ptr<SketchAPI_Circle> addCircle(
+  std::shared_ptr<SketchAPI_MacroCircle> addCircle(
       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
       const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
index c1695defaf3fa42a2b05fe3e70f43dd676fe5ccf..0bc5da6766c0c518811fc092018a55cf298cd584 100644 (file)
@@ -12,6 +12,7 @@
   #include "SketchAPI.h"
   #include "SketchAPI_Arc.h"
   #include "SketchAPI_Circle.h"
+  #include "SketchAPI_MacroCircle.h"
   #include "SketchAPI_Constraint.h"
   #include "SketchAPI_IntersectionPoint.h"
   #include "SketchAPI_Line.h"
index f8049d394ab474a16080d2d9ae7fc8f21511390d..5cc31d85b5e58bd6db561d93fcf8db1265b7736c 100644 (file)
@@ -30,6 +30,7 @@ SET(PROJECT_HEADERS
     SketchPlugin_Feature.h
     SketchPlugin_IntersectionPoint.h
     SketchPlugin_Line.h
+    SketchPlugin_MacroCircle.h
     SketchPlugin_MultiRotation.h
     SketchPlugin_MultiTranslation.h
     SketchPlugin_Plugin.h
@@ -68,6 +69,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_Feature.cpp
     SketchPlugin_IntersectionPoint.cpp
     SketchPlugin_Line.cpp
+    SketchPlugin_MacroCircle.cpp
     SketchPlugin_MultiRotation.cpp
     SketchPlugin_MultiTranslation.cpp
     SketchPlugin_Plugin.cpp
index 435a071cb63a4349102bbd968d94cd7640279a4a..e5cc000b24afefe3718956a9b6135fa2679d82ba 100644 (file)
 
 const double tolerance = 1e-7;
 
-namespace {
-  static const std::string& POINT_ID(int theIndex)
-  {
-    switch (theIndex) {
-    case 1: return SketchPlugin_Circle::FIRST_POINT_ID();
-    case 2: return SketchPlugin_Circle::SECOND_POINT_ID();
-    case 3: return SketchPlugin_Circle::THIRD_POINT_ID();
-    }
-
-    static const std::string DUMMY;
-    return DUMMY;
-  }
-}
-
 
 SketchPlugin_Circle::SketchPlugin_Circle()
-    : SketchPlugin_SketchEntity()
+: SketchPlugin_SketchEntity()
 {
 }
 
@@ -53,137 +39,61 @@ void SketchPlugin_Circle::initDerivedClassAttributes()
 {
   data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
+
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
-
-  data()->addAttribute(CIRCLE_TYPE(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(FIRST_POINT_ID(), GeomDataAPI_Point2D::typeId());
-  data()->addAttribute(SECOND_POINT_ID(), GeomDataAPI_Point2D::typeId());
-  data()->addAttribute(THIRD_POINT_ID(), GeomDataAPI_Point2D::typeId());
-  std::dynamic_pointer_cast<ModelAPI_AttributeString>(
-      data()->attribute(CIRCLE_TYPE()))->setValue(CIRCLE_TYPE_CENTER_AND_RADIUS());
 }
 
 void SketchPlugin_Circle::execute()
 {
   SketchPlugin_Sketch* aSketch = sketch();
-  if (aSketch) {
-    std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
-
-    // compute a circle point in 3D view
-    std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
-        GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
-    AttributeDoublePtr aRadiusAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(RADIUS_ID()));
-    if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) {
-      std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
-      //std::cout<<"Execute circle "<<aCenter->x()<<" "<<aCenter->y()<<" "<<aCenter->z()<<std::endl;
-      // make a visible point
-      SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0);
-
-      // make a visible circle
-      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(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
-      // compute the circle radius
-      double aRadius = aRadiusAttr->value();
-
-      std::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(
-        aCenter, aNormal, aRadius);
-      aShapes.push_back(aCircleShape);
-      std::shared_ptr<ModelAPI_ResultConstruction> aConstr2 = document()->createConstruction(
-        data(), 1);
-      aConstr2->setShape(aCircleShape);
-      aConstr2->setIsInHistory(false);
-      setResult(aConstr2, 1);
-    }
+  if(!aSketch) {
+    return;
   }
-}
 
-AISObjectPtr SketchPlugin_Circle::getAISObject(AISObjectPtr thePrevious)
-{
-  SketchPlugin_Sketch* aSketch = sketch();
-  if (aSketch && !isFeatureValid()) {
-    // compute a circle point in 3D view
-    std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
-        GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
-    AttributeDoublePtr aRadiusAttr =
-        std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(attribute(RADIUS_ID()));
-    if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) {
-        std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+  // Compute a circle in 3D view.
+  std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+  AttributeDoublePtr aRadiusAttr = real(RADIUS_ID());
+  if(!aCenterAttr->isInitialized() || !aRadiusAttr->isInitialized()) {
+    return;
+  }
 
-        // make a visible circle
-        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();
+  double aRadius = aRadiusAttr->value();
+  if(aRadius < tolerance) {
+    return;
+  }
 
-        double aRadius = aRadiusAttr->value();
-        std::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(
-            aCenter, aNormal, aRadius);
-        if (aCircleShape && aRadius != 0) {
-          std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
-          // make a visible point
-          std::shared_ptr<GeomAPI_Shape> aCenterPointShape =
-            GeomAlgoAPI_PointBuilder::vertex(aCenter);
-          aShapes.push_back(aCenterPointShape);
-          aShapes.push_back(aCircleShape);
+  // Make a visible point.
+  SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0);
 
-          std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
-          AISObjectPtr anAIS = thePrevious;
-          if (!anAIS)
-            anAIS = AISObjectPtr(new GeomAPI_AISObject);
-          anAIS->createShape(aCompound);
-          anAIS->setWidth(3);
-          return anAIS;
-        }
-    }
-  }
-  return AISObjectPtr();
-}
+  // Make a visible circle.
+  std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->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(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
 
-bool SketchPlugin_Circle::isFeatureValid()
-{
-  std::shared_ptr<GeomDataAPI_Point2D> aCenter =
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
-  bool aValid = aCenter->isInitialized();
+  std::shared_ptr<GeomAPI_Shape> aCircleShape =
+      GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius);
 
-  std::string aType = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
-                                         data()->attribute(CIRCLE_TYPE()))->value();
-  if (aType == CIRCLE_TYPE_THREE_POINTS()) {
-    std::shared_ptr<GeomDataAPI_Point2D> aFirstPnt =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(FIRST_POINT_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aSecondPnt =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SECOND_POINT_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aThirdPnt =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(THIRD_POINT_ID()));
-    aValid = aValid &&
-             aFirstPnt->isInitialized() &&
-             aSecondPnt->isInitialized() &&
-             aThirdPnt->isInitialized();
-  }
-  return aValid;
+  std::shared_ptr<ModelAPI_ResultConstruction> aResult = document()->createConstruction(data(), 1);
+  aResult->setShape(aCircleShape);
+  aResult->setIsInHistory(false);
+  setResult(aResult, 1);
 }
 
 void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY)
 {
   std::shared_ptr<ModelAPI_Data> aData = data();
-  if (!aData->isValid())
+  if(!aData->isValid()) {
     return;
+  }
 
   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       aData->attribute(CENTER_ID()));
-  if (aPoint->isInitialized())
-    aPoint->move(theDeltaX, theDeltaY);
-
-  aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(FIRST_POINT_ID()));
-  if (aPoint->isInitialized())
-    aPoint->move(theDeltaX, theDeltaY);
-  aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SECOND_POINT_ID()));
-  if (aPoint->isInitialized())
-    aPoint->move(theDeltaX, theDeltaY);
-  aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(THIRD_POINT_ID()));
-  if (aPoint->isInitialized())
+  if(aPoint->isInitialized()) {
     aPoint->move(theDeltaX, theDeltaY);
+  }
 }
 
 bool SketchPlugin_Circle::isFixed() {
@@ -210,92 +120,4 @@ void SketchPlugin_Circle::attributeChanged(const std::string& theID) {
       real(RADIUS_ID())->setValue(aCirc->radius());
     }
   }
-  else if (theID == CENTER_ID() || theID == RADIUS_ID()) {
-    std::string aType = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
-      data()->attribute(CIRCLE_TYPE()))->value();
-    if (aType == CIRCLE_TYPE_THREE_POINTS() && lastResult())  // adjust data from the solver
-      adjustThreePoints();
-  } else if (theID == FIRST_POINT_ID() || theID == SECOND_POINT_ID() || theID == THIRD_POINT_ID()) {
-    // support the center and radius attributes enev in other mode: solver uses them
-    std::string aType = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
-      data()->attribute(CIRCLE_TYPE()))->value();
-    if (aType == CIRCLE_TYPE_CENTER_AND_RADIUS())
-      return;
-    bool aWasBlocked = data()->blockSendAttributeUpdated(true); // to modify two attributes at once
-    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();
-    }
-
-    std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
-        GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
-    AttributeDoublePtr aRadiusAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(RADIUS_ID()));
-
-    if (aNbInitialized == 1)
-      aCenterAttr->setValue(aPoints[0]->x(), aPoints[0]->y());
-    else if (aNbInitialized == 2) {
-      std::shared_ptr<GeomAPI_XY> aCoord =
-          aPoints[0]->xy()->added(aPoints[1]->xy())->multiplied(0.5);
-      double aRadius = aPoints[0]->distance(aPoints[1]) * 0.5;
-      aCenterAttr->setValue(aCoord->x(), aCoord->y());
-      aRadiusAttr->setValue(aRadius);
-    } 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) {
-        double aRadius = aCircle->radius();
-        aCenterAttr->setValue(aCenter->x(), aCenter->y());
-        aRadiusAttr->setValue(aRadius);
-      }
-    }
-    data()->blockSendAttributeUpdated(aWasBlocked, false);
-
-  } else if (theID == CIRCLE_TYPE()) { // if switched to 3 points mode, adjust the needed attributes
-    std::string aType = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
-      data()->attribute(CIRCLE_TYPE()))->value();
-    if (aType == CIRCLE_TYPE_THREE_POINTS()) {
-      adjustThreePoints();
-    }
-  }
-}
-
-void SketchPlugin_Circle::adjustThreePoints()
-{
-  std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
-  if (!aCenterAttr->isInitialized())
-    return;
-  AttributeDoublePtr aRadiusAttr =
-    std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(attribute(RADIUS_ID()));
-  if (!aRadiusAttr->isInitialized())
-    return;
-
-  bool aWasBlocked = data()->blockSendAttributeUpdated(true);
-  std::shared_ptr<GeomDataAPI_Point2D> aFirstPnt =
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(FIRST_POINT_ID()));
-  std::shared_ptr<GeomDataAPI_Point2D> aSecondPnt =
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SECOND_POINT_ID()));
-  std::shared_ptr<GeomDataAPI_Point2D> aThirdPnt =
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(THIRD_POINT_ID()));
-  double aRadius = aRadiusAttr->value();
-
-  bool isInitialized = aFirstPnt->isInitialized() &&
-      aSecondPnt->isInitialized() && aThirdPnt->isInitialized();
-
-  if (!isInitialized ||
-      fabs(aFirstPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance ||
-      fabs(aSecondPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance ||
-      fabs(aThirdPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance) {
-    aFirstPnt->setValue(aCenterAttr->x() + aRadius, aCenterAttr->y());
-    aSecondPnt->setValue(aCenterAttr->x(), aCenterAttr->y() + aRadius);
-    aThirdPnt->setValue(aCenterAttr->x() - aRadius, aCenterAttr->y());
-  }
-  data()->blockSendAttributeUpdated(aWasBlocked, false);
 }
index e183384d83d15b3388c65c5e8c4b57dd2b42cc5b..df577cda870313f2814807e53458e4d7249155ab 100644 (file)
 #include "SketchPlugin.h"
 #include <SketchPlugin_SketchEntity.h>
 #include <SketchPlugin_Sketch.h>
-#include <GeomAPI_IPresentable.h>
 
 /**\class SketchPlugin_Circle
  * \ingroup Plugins
- * \brief Feature for creation of the new circle in PartSet.
+ * \brief Feature for creation of the new circle in Sketch.
  */
-class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPresentable
+class SketchPlugin_Circle: public SketchPlugin_SketchEntity
 {
  public:
   /// Circle feature kind
   inline static const std::string& ID()
   {
-    static const std::string MY_CIRCLE_ID("SketchCircle");
-    return MY_CIRCLE_ID;
-  }
-
-  inline static const std::string& CIRCLE_TYPE()
-  {
-    static const std::string TYPE("CircleType");
-    return TYPE;
-  }
-
-  /// Creation method by center and radius.
-  inline static const std::string& CIRCLE_TYPE_CENTER_AND_RADIUS()
-  {
-    static const std::string TYPE("CenterRadius");
-    return TYPE;
-  }
-
-  /// Creation method by three points.
-  inline static const std::string& CIRCLE_TYPE_THREE_POINTS()
-  {
-    static const std::string TYPE("ThreePoints");
-    return TYPE;
+    static const std::string ID("SketchCircle");
+    return ID;
   }
 
   /// 2D point - center of the circle
   inline static const std::string& CENTER_ID()
   {
-    static const std::string MY_CIRCLE_CENTER_ID("CircleCenter");
-    return MY_CIRCLE_CENTER_ID;
+    static const std::string ID("circle_center");
+    return ID;
   }
 
   /// Radius of the circle
   inline static const std::string& RADIUS_ID()
   {
-    static const std::string MY_CIRCLE_RADIUS_ID("CircleRadius");
-    return MY_CIRCLE_RADIUS_ID;
-  }
-
-  /// First point id.
-  inline static const std::string& FIRST_POINT_ID()
-  {
-    static const std::string FIRST_PNT("FirstPoint");
-    return FIRST_PNT;
-  }
-
-  /// Second point id.
-  inline static const std::string& SECOND_POINT_ID()
-  {
-    static const std::string SECOND_PNT("SecondPoint");
-    return SECOND_PNT;
-  }
-
-  /// Third point id.
-  inline static const std::string& THIRD_POINT_ID()
-  {
-    static const std::string THIRD_PNT("ThirdPoint");
-    return THIRD_PNT;
+    static const std::string ID("circle_radius");
+    return ID;
   }
 
   /// Returns the kind of a feature
@@ -91,39 +49,23 @@ class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPr
   /// Returns true is sketch element is under the rigid constraint
   SKETCHPLUGIN_EXPORT virtual bool isFixed();
 
+  /// Called on change of any argument-attribute of this object
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
-  /// Adds sub-feature of the higher level feature (sub-element of the sketch)
-  /// \param theFeature sub-feature
-  SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature)
-  {
-  }
-
   /// 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);
 
-  /// Called on change of any argument-attribute of this object
-  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-
-  /// Returns the AIS preview
-  virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
-
   /// Use plugin manager for features creation
   SketchPlugin_Circle();
 
 protected:
   /// \brief Initializes attributes of derived class.
   virtual void initDerivedClassAttributes();
-
-private:
-  /// Returns true if all obligatory attributes are initialized
-  bool isFeatureValid();
-
-  /// Update coordinates of representation by three points
-  void adjustThreePoints();
 };
 
 #endif
diff --git a/src/SketchPlugin/SketchPlugin_MacroCircle.cpp b/src/SketchPlugin/SketchPlugin_MacroCircle.cpp
new file mode 100644 (file)
index 0000000..89d1373
--- /dev/null
@@ -0,0 +1,209 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchPlugin_MacroCircle.cpp
+// Created:     26 May 2014
+// Author:      Artem ZHIDKOV
+
+#include "SketchPlugin_MacroCircle.h"
+
+#include "SketchPlugin_Circle.h"
+#include "SketchPlugin_ConstraintCoincidence.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 <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Circ2d.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>
+
+
+const double tolerance = 1e-7;
+
+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();
+    }
+
+    static const std::string DUMMY;
+    return DUMMY;
+  }
+}
+
+
+SketchPlugin_MacroCircle::SketchPlugin_MacroCircle()
+: SketchPlugin_SketchEntity(),
+myRadius(0)
+{
+}
+
+void SketchPlugin_MacroCircle::initAttributes()
+{
+  data()->addAttribute(CIRCLE_TYPE(), ModelAPI_AttributeString::typeId());
+
+  data()->addAttribute(CENTER_POINT_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(CENTER_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(PASSED_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
+
+  data()->addAttribute(FIRST_POINT_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(SECOND_POINT_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(THIRD_POINT_ID(), GeomDataAPI_Point2D::typeId());
+
+  data()->addAttribute(CIRCLE_RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID());
+}
+
+void SketchPlugin_MacroCircle::execute()
+{
+  // Create circle feature.
+  FeaturePtr aCircleFeature = sketch()->addFeature(SketchPlugin_Circle::ID());
+  std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->setValue(myCenter->x(),
+                                                                             myCenter->y());
+  aCircleFeature->real(SketchPlugin_Circle::RADIUS_ID())->setValue(myRadius);
+  aCircleFeature->boolean(SketchPlugin_Circle::AUXILIARY_ID())
+                ->setValue(boolean(AUXILIARY_ID())->value());
+  aCircleFeature->execute();
+
+  myCenter.reset();
+  myRadius = 0;
+
+  // Create constraints.
+  SketchPlugin_Tools::createConstraint(this,
+                                       CENTER_POINT_REF_ID(),
+                                       aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()),
+                                       NULL,
+                                       false);
+  SketchPlugin_Tools::createConstraint(this,
+                                       PASSED_POINT_REF_ID(),
+                                       NULL,
+                                       aCircleFeature->lastResult(),
+                                       true);
+}
+
+AISObjectPtr SketchPlugin_MacroCircle::getAISObject(AISObjectPtr thePrevious)
+{
+  if(!myCenter.get() || myRadius < tolerance) {
+    return AISObjectPtr();
+  }
+
+  SketchPlugin_Sketch* aSketch = sketch();
+  if(!aSketch) {
+    return AISObjectPtr();
+  }
+
+  // Compute a circle in 3D view.
+  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 aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, myRadius);
+  GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
+  if(!aCircleShape.get() || !aCenterPointShape.get()) {
+    return AISObjectPtr();
+  }
+
+  std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
+  aShapes.push_back(aCircleShape);
+  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_MacroCircle::attributeChanged(const std::string& theID) {
+  // If circle type switched reset according attributes.
+  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());
+    } else if(aType == CIRCLE_TYPE_BY_THREE_POINTS()) {
+      resetAttribute(FIRST_POINT_ID());
+      resetAttribute(SECOND_POINT_ID());
+      resetAttribute(THIRD_POINT_ID());
+    }
+    myCenter.reset();
+    myRadius = 0;
+  } else if(theID == CENTER_POINT_ID() || theID == PASSED_POINT_ID()) {
+    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> aPassedPointAttr =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
+    if(!aPassedPointAttr->isInitialized()) {
+      return;
+    }
+
+    myCenter = aCenterPointAttr->pnt();
+    myRadius = myCenter->distance(aPassedPointAttr->pnt());
+  } else if(theID == FIRST_POINT_ID() || theID == SECOND_POINT_ID() || theID == THIRD_POINT_ID()) {
+    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) {
+      return;
+    } else if(aNbInitialized == 2) {
+      std::shared_ptr<GeomAPI_XY> aCenterXY =
+          aPoints[0]->xy()->added(aPoints[1]->xy())->multiplied(0.5);
+      myCenter.reset(new GeomAPI_Pnt2d(aCenterXY->x(), aCenterXY->y()));
+      myRadius = aPoints[0]->distance(aPoints[1]) * 0.5;
+    } else {
+      std::shared_ptr<GeomAPI_Circ2d> aCircle(
+          new GeomAPI_Circ2d(aPoints[0], aPoints[1], aPoints[2]));
+      myCenter = aCircle->center();
+      if(myCenter.get()) {
+        myRadius = aCircle->radius();
+      }
+    }
+  }
+
+  AttributeDoublePtr aRadiusAttr = real(CIRCLE_RADIUS_ID());
+  bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+  aRadiusAttr->setValue(myRadius);
+  data()->blockSendAttributeUpdated(aWasBlocked, false);
+}
+
+void SketchPlugin_MacroCircle::resetAttribute(const std::string& theId)
+{
+  AttributePtr anAttr = attribute(theId);
+  if(anAttr.get()) {
+    anAttr->reset();
+  }
+}
diff --git a/src/SketchPlugin/SketchPlugin_MacroCircle.h b/src/SketchPlugin/SketchPlugin_MacroCircle.h
new file mode 100644 (file)
index 0000000..4ea0ecc
--- /dev/null
@@ -0,0 +1,151 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        SketchPlugin_MacroCircle.h
+// Created:     26 May 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef SketchPlugin_MacroCircle_H_
+#define SketchPlugin_MacroCircle_H_
+
+#include "SketchPlugin.h"
+
+#include "SketchPlugin_Sketch.h"
+#include "SketchPlugin_SketchEntity.h"
+
+#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_Pnt2d.h>
+
+/**\class SketchPlugin_MacroCircle
+ * \ingroup Plugins
+ * \brief Feature for creation of the new circle in Sketch.
+ */
+class SketchPlugin_MacroCircle: public SketchPlugin_SketchEntity,
+                                public GeomAPI_IPresentable
+{
+ public:
+  /// Circle feature kind
+  inline static const std::string& ID()
+  {
+    static const std::string ID("SketchMacroCircle");
+    return ID;
+  }
+
+  inline static const std::string& CIRCLE_TYPE()
+  {
+    static const std::string ID("circle_type");
+    return ID;
+  }
+
+  /// Creation method by center and passed point.
+  inline static const std::string& CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()
+  {
+    static const std::string ID("circle_type_by_center_and_passed_points");
+    return ID;
+  }
+
+  /// Creation method by three points.
+  inline static const std::string& CIRCLE_TYPE_BY_THREE_POINTS()
+  {
+    static const std::string ID("circle_type_by_three_points");
+    return ID;
+  }
+
+  /// 2D point - center of the circle.
+  inline static const std::string& CENTER_POINT_ID()
+  {
+    static const std::string ID("center_point");
+    return ID;
+  }
+
+  /// Reference for center point selection.
+  inline static const std::string& CENTER_POINT_REF_ID()
+  {
+    static const std::string ID("center_point_ref");
+    return ID;
+  }
+
+  /// 2D point - passed point of the circle
+  inline static const std::string& PASSED_POINT_ID()
+  {
+    static const std::string ID("passed_point");
+    return ID;
+  }
+
+  /// Reference for passed point selection.
+  inline static const std::string& PASSED_POINT_REF_ID()
+  {
+    static const std::string ID("passed_point_ref");
+    return ID;
+  }
+
+  /// First point id.
+  inline static const std::string& FIRST_POINT_ID()
+  {
+    static const std::string ID("first_point");
+    return ID;
+  }
+
+  /// Second point id.
+  inline static const std::string& SECOND_POINT_ID()
+  {
+    static const std::string ID("second_point");
+    return ID;
+  }
+
+  /// Third point id.
+  inline static const std::string& THIRD_POINT_ID()
+  {
+    static const std::string ID("third_point");
+    return ID;
+  }
+
+  /// Radius of the circle
+  inline static const std::string& CIRCLE_RADIUS_ID()
+  {
+    static const std::string ID("circle_radius");
+    return ID;
+  }
+
+  /// Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = SketchPlugin_MacroCircle::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
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+  /// Returns the AIS preview
+  virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+  /// Creates a new part document if needed
+  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().
+  /// \returns true
+  SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
+
+  SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
+
+  /// Use plugin manager for features creation
+  SketchPlugin_MacroCircle();
+
+private:
+  void resetAttribute(const std::string& theId);
+
+private:
+  std::shared_ptr<GeomAPI_Pnt2d> myCenter;
+  double myRadius;
+};
+
+#endif
index 80df2df05e9bcd9561e1f79b3ad895fec25c934c..6a4cde08443c45efdda04fa2f62fe09518a870da 100644 (file)
@@ -25,6 +25,7 @@
 #include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_ConstraintTangent.h>
 #include <SketchPlugin_ConstraintVertical.h>
+#include <SketchPlugin_MacroCircle.h>
 #include <SketchPlugin_MultiRotation.h>
 #include <SketchPlugin_MultiTranslation.h>
 #include <SketchPlugin_Trim.h>
@@ -179,6 +180,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_MacroCircle::ID()) {
+    return FeaturePtr(new SketchPlugin_MacroCircle);
   }
   // feature of such kind is not found
   return FeaturePtr();
@@ -242,6 +245,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_MacroCircle::ID(), aHasSketchPlane);
       // SketchRectangle is a python feature, so its ID is passed just as a string
       aMsg->setState("SketchRectangle", aHasSketchPlane);
     }
index bbe2969817513dd4a31bf352e794950d47a9a247..7af4e9af143df71707fe878f76cca26b35123b27 100644 (file)
@@ -6,12 +6,17 @@
 
 #include "SketchPlugin_Tools.h"
 
+#include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_ConstraintTangent.h"
+#include "SketchPlugin_Point.h"
+#include "SketchPlugin_SketchEntity.h"
+
+#include <SketcherPrs_Tools.h>
+
+#include <ModelAPI_AttributeDouble.h>
+
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Point2D.h>
-#include <ModelAPI_AttributeDouble.h>
-#include <SketcherPrs_Tools.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_SketchEntity.h>
 
 namespace SketchPlugin_Tools {
 
@@ -101,4 +106,43 @@ void findCoincidences(const FeaturePtr theStartCoin,
   }
 }
 
+void createConstraint(SketchPlugin_Feature* theFeature,
+                      const std::string& theId,
+                      const AttributePtr theAttr,
+                      const ObjectPtr theObject,
+                      const bool theIsCanBeTangent)
+{
+  AttributeRefAttrPtr aRefAttr = theFeature->refattr(theId);
+  if(aRefAttr.get() && aRefAttr->isInitialized()) {
+    FeaturePtr aConstraint;
+    if(!theIsCanBeTangent) {
+      aConstraint = theFeature->sketch()
+                              ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+    } else {
+      if(aRefAttr->isObject()) {
+        ObjectPtr anObject = aRefAttr->object();
+        FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+        if(aFeature->getKind() == SketchPlugin_Point::ID()) {
+          aConstraint = theFeature->sketch()
+                                  ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+        } else {
+          aConstraint = theFeature->sketch()
+                                  ->addFeature(SketchPlugin_ConstraintTangent::ID());
+        }
+      } else {
+        aConstraint = theFeature->sketch()
+                                ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+      }
+    }
+    AttributeRefAttrPtr aRefAttrA = aConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
+    aRefAttr->isObject() ? aRefAttrA->setObject(aRefAttr->object())
+                         : aRefAttrA->setAttr(aRefAttr->attr());
+    AttributeRefAttrPtr aRefAttrB = aConstraint->refattr(SketchPlugin_Constraint::ENTITY_B());
+    if(theObject.get()) {
+      aRefAttrB->setObject(theObject);
+    } else if(theAttr.get()) {
+      aRefAttrB->setAttr(theAttr);
+    }
+  }
+}
 } // namespace SketchPlugin_Tools
index 61cf44acf4da5a23b68d655ecf1f81ef74fa91cc..ef26d67c0560f73d29f8d3e9d025bd9bc1d1b53b 100644 (file)
@@ -12,6 +12,8 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Attribute.h>
 
+class SketchPlugin_Feature;
+
 namespace SketchPlugin_Tools {
 
 /// Clears text expressions for all attributes of the feature
@@ -28,6 +30,18 @@ std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(const FeaturePtr theStartCoin
 void findCoincidences(const FeaturePtr theStartCoin,
                       const std::string& theAttr,
                       std::set<FeaturePtr>& theList);
+
+/// Creates coincidence or tangent constraint.
+/// \param[in] theFeature to get selected attribute or object
+/// \param[in] theId ID of attribute where selection is.
+/// \param[in] theObject object for constraint
+/// \param[in] theIsCanBeTangent if true constraint can be tangent or coincidence, depending on
+///                              the selection in the attribute with passed ID.
+void createConstraint(SketchPlugin_Feature* theFeature,
+                      const std::string& theId,
+                      const AttributePtr theAttr,
+                      const ObjectPtr theObject,
+                      const bool theIsCanBeTangent);
 }; // namespace SketchPlugin_Tools
 
 #endif // SKETCHPLUGIN_TOOLS_H_
\ No newline at end of file
index f7d332f696ebfe9d5b65994a4e64ec465a8fc33a..994eba6d54054f0e63cb76dbd7b58813d16ada5a 100755 (executable)
   </context>
   
   <context>
-    <name>SketchCircle:CircleRadius:GeomValidators_Positive</name>
+    <name>SketchMacroCircle:CircleRadius:GeomValidators_Positive</name>
     <message>
       <source>Double is not positive.</source>
       <translation>Radius value is not positive</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:Model_FeatureValidator</name>
+    <name>SketchMacroCircle:Model_FeatureValidator</name>
     <message>
       <source>Attribute "CircleCenter" is not initialized.</source>
       <translation>A center point is not selected</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:Model_FeatureValidator</name>
+    <name>SketchMacroCircle:Model_FeatureValidator</name>
     <message>
       <source>Attribute "FirstPoint" is not initialized.</source>
       <translation>A first point is not selected</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:Model_FeatureValidator</name>
+    <name>SketchMacroCircle:Model_FeatureValidator</name>
     <message>
       <source>Attribute "SecondPoint" is not initialized.</source>
       <translation>A second point is not selected</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:Model_FeatureValidator</name>
+    <name>SketchMacroCircle:Model_FeatureValidator</name>
     <message>
       <source>Attribute "ThirdPoint" is not initialized.</source>
       <translation>A third point is not selected</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:CircleCenter</name>
+    <name>SketchMacroCircle:CircleCenter</name>
     <message>
       <source>Attribute "CircleCenter" is locked by modification value in the viewer.</source>
       <translation>Select a center point</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:FirstPoint</name>
+    <name>SketchMacroCircle:FirstPoint</name>
     <message>
       <source>Attribute "FirstPoint" is locked by modification value in the viewer.</source>
       <translation>Select a center point</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:SecondPoint</name>
+    <name>SketchMacroCircle:SecondPoint</name>
     <message>
       <source>Attribute "SecondPoint" is locked by modification value in the viewer.</source>
       <translation>Select a center point</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:ThirdPoint</name>
+    <name>SketchMacroCircle:ThirdPoint</name>
     <message>
       <source>Attribute "ThirdPoint" is locked by modification value in the viewer.</source>
       <translation>Select a center point</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:CircleRadius</name>
+    <name>SketchMacroCircle:CircleRadius</name>
     <message>
       <source>Attribute "CircleRadius" is locked by modification value in the viewer.</source>
       <translation>Select a radius distance</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:CircleRadius:GeomValidators_Positive</name>
+    <name>SketchMacroCircle:CircleRadius:GeomValidators_Positive</name>
     <message>
       <source>Integer is not initialized.</source>
       <translation>Integer radius is not initialized</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:CircleRadius:GeomValidators_Positive</name>
+    <name>SketchMacroCircle:CircleRadius:GeomValidators_Positive</name>
     <message>
       <source>Integer is not positive.</source>
       <translation>Integer radius must be set</translation>
     </message>
   </context>
   <context>
-    <name>SketchCircle:Model_FeatureValidator</name>
+    <name>SketchMacroCircle:Model_FeatureValidator</name>
     <message>
       <source>Attribute "CircleRadius" is not initialized.</source>
       <translation>Set the circle radius</translation>
index 44f52eefb12c14240b4194801bb66f704fbc6ccd..57c00874adc192814b7e39373ce3f847ff91e619 100644 (file)
@@ -5,7 +5,8 @@
     <group id="Linear geometry">
       <feature
         id="Sketch"
-        nested="SketchPoint SketchIntersectionPoint SketchLine SketchCircle SketchArc
+        nested="SketchPoint SketchIntersectionPoint SketchLine
+                SketchCircle SketchMacroCircle SketchArc
                 SketchRectangle
                 SketchProjection
                 SketchConstraintLength SketchConstraintRadius SketchConstraintDistance
       </feature>
     </group>
     <group id="Circular geometry">
-      <!-- SketchCircle -->
-      <feature 
-        id="SketchCircle"
-        title="Circle"
-        tooltip="Create circle"
-        icon="icons/Sketch/circle.png">
-        <toolbox id="CircleType">
-          <box id="CenterRadius" title="Center and radius" icon="icons/Sketch/circle_pt_rad_32x32.png">
-            <sketch-2dpoint_selector id="CircleCenter" accept_expressions="0" title="Center" tooltip="Center coordinates"
+      <!-- SketchCircle is a hidden feature. It is created inside SketchMacroCircle. -->
+      <feature id="SketchCircle"
+               title="Circle"
+               tooltip="Create circle"
+               icon="icons/Sketch/circle.png"
+               internal="1">
+        <sketch-2dpoint_selector id="circle_center"
+                                 title="Center"
+                                 tooltip="Center coordinates"
+                                 accept_expressions="0"
+                                 enable_value="enable_by_preferences"/>
+        <labelvalue id="circle_radius"
+                    icon="icons/Sketch/radius.png"
+                    label="Radius:"
+                    tooltip="Set radius"
+                    default="computed"
+                    accept_expressions="0"
+                    enable_value="enable_by_preferences">
+        </labelvalue>
+        <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+      </feature>
+      <!-- SketchMacroCircle -->
+      <feature id="SketchMacroCircle"
+               icon="icons/Sketch/circle.png"
+               title="Circle"
+               tooltip="Create circle">
+        <toolbox id="circle_type">
+          <box id="circle_type_by_center_and_passed_points"
+               icon="icons/Sketch/circle_pt_rad_32x32.png"
+               title="Center and passed points">
+            <sketch-2dpoint_selector id="center_point"
+                                     reference_attribute="center_point_ref"
+                                     title="Center point"
+                                     tooltip="Center point coordinates"
+                                     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 coordinates"
+                                     accept_expressions="0"
                                      enable_value="enable_by_preferences"/>
           </box>
-          <box id="ThreePoints" title="Three points" icon="icons/Sketch/circle_3pt_32x32.png">
-            <sketch-2dpoint_selector id="FirstPoint" accept_expressions="0" title="First point" tooltip="First point"
+          <box id="circle_type_by_three_points"
+               icon="icons/Sketch/circle_3pt_32x32.png"
+               title="Three points">
+            <sketch-2dpoint_selector id="first_point"
+                                     title="First point"
+                                     tooltip="First point"
+                                     accept_expressions="0"
                                      enable_value="enable_by_preferences"/>
-            <sketch-2dpoint_selector id="SecondPoint" accept_expressions="0" title="Second point" tooltip="Second point"
+            <sketch-2dpoint_selector id="second_point"
+                                     title="Second point"
+                                     tooltip="Second point"
+                                     accept_expressions="0"
                                      enable_value="enable_by_preferences"/>
-            <sketch-2dpoint_selector id="ThirdPoint" accept_expressions="0" title="Third point" tooltip="Third point"
+            <sketch-2dpoint_selector id="third_point"
+                                     title="Third point"
+                                     tooltip="Third point"
+                                     accept_expressions="0"
                                      enable_value="enable_by_preferences"/>
           </box>
         </toolbox>
-        <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0"
-                         default="0" icon="icons/Sketch/radius.png" tooltip="Set radius"
-                         enable_value="enable_by_preferences">
+        <labelvalue id="circle_radius"
+                    icon="icons/Sketch/radius.png"
+                    label="Radius:"
+                    tooltip="Set radius"
+                    default="computed"
+                    accept_expressions="0"
+                    obligatory="0"
+                    enable_value="enable_by_preferences">
           <validator id="GeomValidators_Positive"/>
-        </point2ddistance>
-        <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+        </labelvalue>
+        <boolvalue id="Auxiliary"
+                   tooltip="Construction element"
+                   label="Auxiliary"
+                   default="false"
+                   obligatory="0"/>
       </feature>
 
       <!-- SketchArc -->