Salome HOME
Issue #2209 : New option of creation of construction points
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.cpp
index 2656c55dc23528881c5478826f72b9b76ec86ae2..48222cfc4e3c5384f6452d83744718b1778d0e0e 100644 (file)
@@ -56,7 +56,7 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feat
   if(initialize()) {
     setByDistanceOnEdge(theEdge, theDistanceValue, theDistancePercent, theReverse);
   }
-}
+}*/
 
 //==================================================================================================
 ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
@@ -67,19 +67,19 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feat
   if(initialize()) {
     GeomAPI_Shape::ShapeType aType1 = getShapeType(theObject1);
     GeomAPI_Shape::ShapeType aType2 = getShapeType(theObject2);
-
+    /*
     if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
       // If first object is vertex and second object is face then set by projection.
       setByProjection(theObject1, theObject2);
     } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
       // If both objects are edges then set by lines intersection.
       setByLinesIntersection(theObject1, theObject2);
-    } else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
+    } else */if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
       // If first object is edge and second object is face then set by line and plane intersection.
       setByLineAndPlaneIntersection(theObject1, theObject2);
     }
   }
-}*/
+}
 
 //==================================================================================================
 ConstructionAPI_Point::~ConstructionAPI_Point()
@@ -96,6 +96,7 @@ void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX,
   fillAttribute(theX, myx);
   fillAttribute(theY, myy);
   fillAttribute(theZ, myz);
+  fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod);
 
   execute(false);
 }
@@ -135,32 +136,40 @@ void ConstructionAPI_Point::setByLinesIntersection(const ModelHighAPI_Selection&
   fillAttribute(theEdge2, mysecondLine);
 
   execute();
-}
+}*/
 
 //==================================================================================================
 void ConstructionAPI_Point::setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge,
                                                           const ModelHighAPI_Selection& theFace)
 {
-  fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
+  fillAttribute(
+    ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION(), mycreationMethod);
   fillAttribute(theEdge, myintersectionLine);
   fillAttribute(theFace, myintersectionPlane);
-
+  fillAttribute("", useOffset()); // not used by default
   execute();
-}*/
+}
 
 //==================================================================================================
 void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
 {
-  // TODO: all types of points
-
   FeaturePtr aBase = feature();
   const std::string& aDocName = theDumper.name(aBase->document());
-
-  AttributeDoublePtr anAttrX = aBase->real(ConstructionPlugin_Point::X());
-  AttributeDoublePtr anAttrY = aBase->real(ConstructionPlugin_Point::Y());
-  AttributeDoublePtr anAttrZ = aBase->real(ConstructionPlugin_Point::Z());
-  theDumper << aBase << " = model.addPoint(" << aDocName << ", "
-            << anAttrX << ", " << anAttrY << ", " << anAttrZ << ")" << std::endl;
+  const std::string& aMeth = creationMethod()->value();
+
+  // common part
+  theDumper << aBase << " = model.addPoint(" << aDocName << ", ";
+
+  if (aMeth == "" || // default is XYZ
+      aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) {
+    theDumper << x() << ", " << y() << ", " << z() << ")" << std::endl;
+  } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
+    theDumper << intersectionLine() << ", " <<intersectionPlane() ;
+    if (!useOffset()->value().empty()) { // call method with defined offset
+      theDumper << ", " << offset() << ", " << reverseOffset();
+    }
+    theDumper << ")" << std::endl;
+  }
 }
 
 //==================================================================================================
@@ -180,17 +189,32 @@ PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
                   const bool theDistancePercent,
                   const bool theReverse)
 {
-  // TODO(spo): check that thePart is not empty
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
   return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
-}
+}*/
 
 //==================================================================================================
 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
                   const ModelHighAPI_Selection& theObject1,
                   const ModelHighAPI_Selection& theObject2)
 {
-  // TODO(spo): check that thePart is not empty
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
   return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
-}*/
+}
+
+//==================================================================================================
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+                  const ModelHighAPI_Selection& theObject1,
+                  const ModelHighAPI_Selection& theObject2,
+                  const ModelHighAPI_Double& theDistanceValue,
+                  const bool theReverse)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
+  PointPtr anAPI(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
+
+  fillAttribute(ConstructionPlugin_Point::USE_OFFSET(), anAPI->useOffset());
+  fillAttribute(theDistanceValue, anAPI->offset());
+  fillAttribute(theReverse, anAPI->reverseOffset());
+
+  return anAPI;
+}