Salome HOME
Issue #1834: Fix length of lines
[modules/shaper.git] / src / SketchAPI / SketchAPI_Arc.cpp
index 438c28d9ff094c2e7208ce93e499adfd444228ce..8428bf78431237a6bf20aea7d8979a1f22dbf6be 100644 (file)
@@ -9,17 +9,18 @@
 #include <GeomAPI_Pnt2d.h>
 
 #include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
 : SketchAPI_SketchEntity(theFeature)
 {
   initialize();
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              double theCenterX, double theCenterY,
                              double theStartX, double theStartY,
@@ -28,11 +29,12 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
 : SketchAPI_SketchEntity(theFeature)
 {
   if(initialize()) {
-    setByCenterStartEnd(theCenterX, theCenterY, theStartX, theStartY, theEndX, theEndY, theInversed);
+    setByCenterStartEnd(theCenterX, theCenterY, theStartX, 
+                        theStartY, theEndX, theEndY, theInversed);
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
@@ -45,7 +47,7 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              double theStartX, double theStartY,
                              double theEndX, double theEndY,
@@ -57,7 +59,7 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//===============================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
@@ -69,7 +71,7 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const ModelHighAPI_RefAttr& theTangentPoint,
                              double theEndX, double theEndY,
@@ -81,7 +83,7 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const ModelHighAPI_RefAttr& theTangentPoint,
                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
@@ -93,7 +95,7 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const ModelHighAPI_Selection& theExternal)
 : SketchAPI_SketchEntity(theFeature)
@@ -103,7 +105,7 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const std::string& theExternalName)
 : SketchAPI_SketchEntity(theFeature)
@@ -113,13 +115,13 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::~SketchAPI_Arc()
 {
 
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
                                         double theStartX, double theStartY,
                                         double theEndX, double theEndY,
@@ -134,7 +136,7 @@ void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
   execute();
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
@@ -149,7 +151,7 @@ void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& th
   execute();
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByStartEndPassed(double theStartX, double theStartY,
                                         double theEndX, double theEndY,
                                         double thePassedX, double thePassedY)
@@ -162,7 +164,7 @@ void SketchAPI_Arc::setByStartEndPassed(double theStartX, double theStartY,
   execute();
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByStartEndPassed(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
@@ -175,7 +177,7 @@ void SketchAPI_Arc::setByStartEndPassed(const std::shared_ptr<GeomAPI_Pnt2d>& th
   execute();
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
                                  double theEndX, double theEndY,
                                  bool theInversed)
@@ -188,7 +190,7 @@ void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
   execute();
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
                                  const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
                                  bool theInversed)
@@ -201,7 +203,7 @@ void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
   execute();
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
 {
   fillAttribute(theExternal, external());
@@ -209,7 +211,7 @@ void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
   execute();
 }
 
-//==================================================================================================
+//===============================================================================================
 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
 {
   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
@@ -217,7 +219,7 @@ void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
   execute();
 }
 
-//==================================================================================================
+//===============================================================================================
 void SketchAPI_Arc::setRadius(double theRadius)
 {
   fillAttribute(ModelHighAPI_Double(theRadius), myradius);
@@ -225,10 +227,44 @@ void SketchAPI_Arc::setRadius(double theRadius)
   execute();
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setAngle(double theAngle)
 {
   fillAttribute(ModelHighAPI_Double(theAngle), myangle);
 
   execute();
 }
+
+//================================================================================================
+void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  if (isCopy())
+    return; // no need to dump copied feature
+
+  FeaturePtr aBase = feature();
+  const std::string& aSketchName = theDumper.parentName(aBase);
+
+  AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+  if (anExternal->context()) {
+    // arc is external
+    theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
+  } else {
+    AttributeStringPtr aType = arcType();
+    if (aType->value() == SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()) {
+      // arc given by center and start, end points
+      theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
+                << startPoint() << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
+    } else if (aType->value() == SketchPlugin_Arc::ARC_TYPE_THREE_POINTS()) {
+      // arc given by three points
+      theDumper << aBase << " = " << aSketchName << ".addArc(" << startPoint() << ", "
+                << endPoint() << ", " << passedPoint() << ")" << std::endl;
+    } else {
+      // tangent arc
+      AttributeRefAttrPtr aTangentPoint = tangentPoint();
+      theDumper << aBase << " = " << aSketchName << ".addArc("
+                << aTangentPoint << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
+    }
+  }
+  // dump "auxiliary" flag if necessary
+  SketchAPI_SketchEntity::dump(theDumper);
+}