Salome HOME
#1802 Crash when I create a circle on projected axis
[modules/shaper.git] / src / SketchAPI / SketchAPI_Line.cpp
index f36c91c88268dea56f0577bbba4c5855394c1ae9..1e5a2da04fc01a250631b6940ea62338ae6df9c1 100644 (file)
@@ -9,12 +9,13 @@
 //--------------------------------------------------------------------------------------
 #include <GeomAPI_Pnt2d.h>
 //--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
 //--------------------------------------------------------------------------------------
 SketchAPI_Line::SketchAPI_Line(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
-: ModelHighAPI_Interface(theFeature)
+: SketchAPI_SketchEntity(theFeature)
 {
   initialize();
 }
@@ -22,7 +23,7 @@ SketchAPI_Line::SketchAPI_Line(
 SketchAPI_Line::SketchAPI_Line(
     const std::shared_ptr<ModelAPI_Feature> & theFeature,
     double theX1, double theY1, double theX2, double theY2)
-: ModelHighAPI_Interface(theFeature)
+: SketchAPI_SketchEntity(theFeature)
 {
   if (initialize()) {
     setByCoordinates(theX1, theY1, theX2, theY2);
@@ -33,7 +34,7 @@ SketchAPI_Line::SketchAPI_Line(
     const std::shared_ptr<ModelAPI_Feature> & theFeature,
     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
-: ModelHighAPI_Interface(theFeature)
+: SketchAPI_SketchEntity(theFeature)
 {
   if (initialize()) {
     setByPoints(theStartPoint, theEndPoint);
@@ -43,7 +44,7 @@ SketchAPI_Line::SketchAPI_Line(
 SketchAPI_Line::SketchAPI_Line(
     const std::shared_ptr<ModelAPI_Feature> & theFeature,
     const ModelHighAPI_Selection & theExternal )
-: ModelHighAPI_Interface(theFeature)
+: SketchAPI_SketchEntity(theFeature)
 {
   if (initialize()) {
     setByExternal(theExternal);
@@ -53,7 +54,7 @@ SketchAPI_Line::SketchAPI_Line(
 SketchAPI_Line::SketchAPI_Line(
     const std::shared_ptr<ModelAPI_Feature> & theFeature,
     const std::string & theExternalName )
-: ModelHighAPI_Interface(theFeature)
+: SketchAPI_SketchEntity(theFeature)
 {
   if (initialize()) {
     setByExternalName(theExternalName);
@@ -127,3 +128,23 @@ void SketchAPI_Line::setEndPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint
 
 //--------------------------------------------------------------------------------------
 
+void SketchAPI_Line::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()) {
+    // line is external
+    theDumper << aBase << " = " << aSketchName << ".addLine(" << anExternal << ")" << std::endl;
+  } else {
+    // segment given by its points
+    theDumper << aBase << " = " << aSketchName << ".addLine("
+              << startPoint() << ", " << endPoint() << ")" << std::endl;
+  }
+  // dump "auxiliary" flag if necessary
+  SketchAPI_SketchEntity::dump(theDumper);
+}