Salome HOME
2.3.2 Point creation: on a line
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Point.cpp
index f08cd5fa42661a5d97b3d325f02e52af0fa71928..2081f4ed12a3ca764a9bb6f7f2b9f1c4dae33168 100644 (file)
@@ -55,23 +55,26 @@ void ConstructionPlugin_Point::initAttributes()
 
   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
 
-  /*data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
-  data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
-  data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
-  data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
-
+/*
   data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
 
   data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId());
 */
+
   data()->addAttribute(INTERSECTION_LINE(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(INTERSECTION_PLANE(), ModelAPI_AttributeSelection::typeId());
 
   data()->addAttribute(USE_OFFSET(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(OFFSET(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(REVERSE_OFFSET(), ModelAPI_AttributeBoolean::typeId());
+
+  data()->addAttribute(EDGE(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(OFFSET_TYPE(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(RATIO(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
 }
 
 //==================================================================================================
@@ -79,20 +82,33 @@ void ConstructionPlugin_Point::execute()
 {
   GeomShapePtr aShape;
 
-   // to support compatibility with old documents where aCreationMethod did not exist
+  // to support compatibility with old documents where aCreationMethod did not exist
   std::string aCreationMethod =
     string(CREATION_METHOD()).get() && !string(CREATION_METHOD())->value().empty() ?
     string(CREATION_METHOD())->value() : CREATION_METHOD_BY_XYZ();
   if(aCreationMethod == CREATION_METHOD_BY_XYZ()) {
     aShape = createByXYZ();
-  }/* else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
+  } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
     aShape = createByDistanceOnEdge();
-  } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
+  }/* else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
     aShape = createByProjection();
   } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
     aShape = createByLinesIntersection();
   }*/ else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) {
-    aShape = createByLineAndPlaneIntersection();
+    // this may produce several points
+    std::list<std::shared_ptr<GeomAPI_Vertex> > aPoints = createByLineAndPlaneIntersection();
+    if (!aPoints.empty()) { // if no points found produce the standard error later
+      int anIndex = 0;
+      std::list<std::shared_ptr<GeomAPI_Vertex> >::iterator aPIter = aPoints.begin();
+      for(; aPIter != aPoints.end(); aPIter++, anIndex++) {
+        std::shared_ptr<ModelAPI_ResultConstruction> aConstr =
+          document()->createConstruction(data(), anIndex);
+        aConstr->setShape(*aPIter);
+        setResult(aConstr, anIndex);
+      }
+      removeResults(anIndex);
+      return;
+    }
   }
 
   if(!aShape.get()) {
@@ -100,6 +116,7 @@ void ConstructionPlugin_Point::execute()
     return;
   }
 
+  removeResults(1); // for case the point type was switched from multi-results type
   std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
   aConstr->setShape(aShape);
   setResult(aConstr);
@@ -124,7 +141,7 @@ std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
                                           real(Z())->value());
 }
 
-/*//==================================================================================================
+//==================================================================================================
 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
 {
   // Get edge.
@@ -136,15 +153,22 @@ std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge
   std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
 
   // Get distance value and percent flag.
-  double aValue = real(DISTANCE_VALUE())->value();
-  bool anIsPercent = boolean(DISTANCE_PERCENT())->value();
+  double aValue;
+  bool anIsPercent = false;
+  if (string(OFFSET_TYPE())->value() == OFFSET_TYPE_BY_DISTANCE()) {
+    aValue = real(DISTANCE())->value();
+    anIsPercent = false;
+  } else {
+    aValue = real(RATIO())->value() * 100.0;
+    anIsPercent = true;
+  }
 
   // Get reverse flag.
   bool anIsReverse = boolean(REVERSE())->value();
 
   return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
 }
-
+/*
 //==================================================================================================
 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
 {
@@ -191,7 +215,8 @@ std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLinesIntersect
 */
 
 //==================================================================================================
-std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIntersection()
+std::list<std::shared_ptr<GeomAPI_Vertex> >
+  ConstructionPlugin_Point::createByLineAndPlaneIntersection()
 {
   // Get line.
   AttributeSelectionPtr aLineSelection = selection(INTERSECTION_LINE());
@@ -218,5 +243,6 @@ std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByLineAndPlaneIn
     }
   }
 
-  return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace);
+  return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace,
+    aPlaneSelection->context()->groupName() == ModelAPI_ResultConstruction::group());
 }