Salome HOME
updated copyright message
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Point.cpp
index 8f4f8fc62ed55fec8c2226081ff66f03ddedc6e4..830920ad3005e7ae546a135ddbe947a4379b2f94 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ConstructionPlugin_Point.h"
 
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultConstruction.h>
@@ -36,6 +36,9 @@
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Vertex.h>
 #include <GeomAPI_Pln.h>
+#include <GeomAPI_ShapeIterator.h>
+
+#include <Config_PropManager.h>
 
 //==================================================================================================
 ConstructionPlugin_Point::ConstructionPlugin_Point()
@@ -118,6 +121,7 @@ void ConstructionPlugin_Point::execute()
         for (; aPIter != aPoints.end(); aPIter++, anIndex++) {
           std::shared_ptr<ModelAPI_ResultConstruction> aConstr =
             document()->createConstruction(data(), anIndex);
+          aConstr->setInfinite(true);
           aConstr->setShape(*aPIter);
           setResult(aConstr, anIndex);
         }
@@ -150,13 +154,27 @@ void ConstructionPlugin_Point::execute()
 
 //==================================================================================================
 bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
-                                                     AISObjectPtr thePrs,
-                                                std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+                                                     AISObjectPtr thePrs)
 {
-  bool isCustomized = theDefaultPrs.get() != NULL &&
-                      theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+  std::vector<int> aColor;
+  // get color from the attribute of the result
+  if (theResult.get() != NULL &&
+    theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+    AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+    if (aColorAttr.get() && aColorAttr->size()) {
+      aColor.push_back(aColorAttr->value(0));
+      aColor.push_back(aColorAttr->value(1));
+      aColor.push_back(aColorAttr->value(2));
+    }
+  }
+  if (aColor.empty())
+    aColor = Config_PropManager::color("Visualization", COLOR_NAME());
+
+  bool isCustomized = false;
+  if (aColor.size() == 3)
+    isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
   //thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
-  return true;
+  return isCustomized;
 }
 
 //==================================================================================================
@@ -271,7 +289,14 @@ std::list<std::shared_ptr<GeomAPI_Vertex> >
   if(!aLineShape.get()) {
     aLineShape = aLineSelection->context()->shape();
   }
-  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aLineShape));
+  GeomEdgePtr anEdge;
+  if (aLineShape->isEdge()) {
+    anEdge = aLineShape->edge();
+  }
+  else if (aLineShape->isCompound()) {
+    GeomAPI_ShapeIterator anIt(aLineShape);
+    anEdge = anIt.current()->edge();
+  }
 
   // Get plane.
   AttributeSelectionPtr aPlaneSelection= selection(INTERSECTION_PLANE());
@@ -279,7 +304,14 @@ std::list<std::shared_ptr<GeomAPI_Vertex> >
   if(!aPlaneShape.get()) {
     aPlaneShape = aPlaneSelection->context()->shape();
   }
-  std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
+  GeomFacePtr aFace;
+  if (aPlaneShape->isFace()) {
+    aFace = aPlaneShape->face();
+  }
+  else if (aPlaneShape->isCompound()) {
+    GeomAPI_ShapeIterator anIt(aPlaneShape);
+    aFace = anIt.current()->face();
+  }
 
   if (!string(USE_OFFSET())->value().empty()) {
     double anOffset = real(OFFSET())->value();
@@ -290,8 +322,7 @@ std::list<std::shared_ptr<GeomAPI_Vertex> >
     }
   }
 
-  return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace,
-    aPlaneSelection->context()->groupName() == ModelAPI_ResultConstruction::group());
+  return GeomAlgoAPI_ShapeTools::intersect(anEdge, aFace);
 }
 
 //==================================================================================================