Salome HOME
Updated copyright comment
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Validators.cpp
index 2390b83a4eec2b9e9327890a0c3d83f748dc02c5..09187e4c43818c6b5444479107dd618a4bc6fb1f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  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_Validators.h"
@@ -27,6 +26,7 @@
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_Vertex.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeIterator.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 
 #include <ModelAPI_AttributeSelection.h>
@@ -35,6 +35,7 @@
 #include <Events_InfoMessage.h>
 
 static std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape);
+static std::shared_ptr<GeomAPI_Face> getFace(const GeomShapePtr theShape);
 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
 static std::shared_ptr<GeomAPI_Pnt> getPnt(const GeomShapePtr theShape);
@@ -53,7 +54,7 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr
   GeomShapePtr aLineShape1 = aLineAttribute1->value();
   ResultPtr aContext1 = aLineAttribute1->context();
   if(!aContext1.get()) {
-    theError = "One of the attribute not initialized.";
+    theError = "One of the attribute is not initialized.";
     return false;
   }
   if(!aLineShape1.get()) {
@@ -114,12 +115,12 @@ bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid(
   AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
 
   std::shared_ptr<GeomAPI_Edge> anEdge;
-  std::shared_ptr<GeomAPI_Pln> aPln;
+  std::shared_ptr<GeomAPI_Face> aFace;
 
   GeomShapePtr aShape1 = anAttribute1->value();
   ResultPtr aContext1 = anAttribute1->context();
   if(!aContext1.get()) {
-    theError = "One of the attribute not initialized.";
+    theError = "One of the attribute is not initialized.";
     return false;
   }
   if(!aShape1.get()) {
@@ -135,22 +136,19 @@ bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid(
     aShape2 = aContext2->shape();
   }
 
-  bool isPlaneFirst = false;
   anEdge = getEdge(aShape1);
-  aPln = getPln(aShape2);
-  if(!anEdge.get() || !aPln.get()) {
+  aFace = getFace(aShape2);
+  if(!anEdge.get() || !aFace.get()) {
     anEdge = getEdge(aShape2);
-    aPln = getPln(aShape1);
-    isPlaneFirst = true;
+    aFace = getFace(aShape1);
   }
 
-  if(!anEdge.get() || !aPln.get()) {
+  if(!anEdge.get() || !aFace.get()) {
     theError = "Wrong shape types selected.";
     return false;
   }
 
-  std::shared_ptr<GeomAPI_Face> aPlaneFace(new GeomAPI_Face(isPlaneFirst ? aShape1 : aShape2));
-  if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aPlaneFace)) {
+  if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aFace)) {
     theError = "Plane and edge are parallel.";
     return false;
   }
@@ -173,7 +171,7 @@ bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& t
   GeomShapePtr aPointShape1 = aPointAttribute1->value();
   ResultPtr aContext1 = aPointAttribute1->context();
   if(!aContext1.get()) {
-    theError = "One of the attribute not initialized.";
+    theError = "One of the attribute is not initialized.";
     return false;
   }
   if(!aPointShape1.get()) {
@@ -251,7 +249,7 @@ bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
   GeomShapePtr aShape1 = anAttribute1->value();
   ResultPtr aContext1 = anAttribute1->context();
   if(!aContext1.get()) {
-    theError = "One of the attribute not initialized.";
+    theError = "One of the attribute is not initialized.";
     return false;
   }
   if(!aShape1.get()) {
@@ -309,7 +307,7 @@ bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
   GeomShapePtr aShape1 = anAttribute1->value();
   ResultPtr aContext1 = anAttribute1->context();
   if(!aContext1.get()) {
-    theError = "One of the attribute not initialized.";
+    theError = "One of the attribute is not initialized.";
     return false;
   }
   if(!aShape1.get()) {
@@ -362,7 +360,7 @@ bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
   GeomShapePtr aShape1 = anAttribute1->value();
   ResultPtr aContext1 = anAttribute1->context();
   if(!aContext1.get()) {
-    theError = "One of the attribute not initialized.";
+    theError = "One of the attribute is not initialized.";
     return false;
   }
   if(!aShape1.get()) {
@@ -413,7 +411,7 @@ bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid(
   GeomShapePtr aShape1 = anAttribute1->value();
   ResultPtr aContext1 = anAttribute1->context();
   if (!aContext1.get()) {
-    theError = "One of the attribute not initialized.";
+    theError = "One of the attribute is not initialized.";
     return false;
   }
   if (!aShape1.get()) {
@@ -472,27 +470,76 @@ bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid(
   return true;
 }
 
-std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
+//==================================================================================================
+bool ConstructionPlugin_ValidatorNotFeature::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& /*theArguments*/,
+    Events_InfoMessage& theError) const
 {
-  if(!theShape->isEdge()) {
-    return std::shared_ptr<GeomAPI_Edge>();
+  AttributeSelectionPtr aSelAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  if (!aSelAttr) {
+    theError = "Wrong attribute";
+    return false;
   }
 
-  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
+  FeaturePtr aContextFeature = aSelAttr->contextFeature();
+  if (aContextFeature) {
+    theError = "Feature should not be selected";
+    return false;
+  }
+  return true;
+}
+
+//==================================================================================================
+
+std::shared_ptr<GeomAPI_Edge> getEdge(const GeomShapePtr theShape)
+{
+  GeomEdgePtr anEdge;
+
+  if(theShape->isEdge()) {
+    anEdge = theShape->edge();
+  }
+  else if (theShape->isCompound()) {
+    GeomAPI_ShapeIterator anIt(theShape);
+    anEdge = anIt.current()->edge();
+  }
 
   return anEdge;
 }
 
+GeomFacePtr getFace(const GeomShapePtr theShape)
+{
+  GeomFacePtr aFace;
+
+  if (theShape->isFace()) {
+    aFace = theShape->face();
+  }
+  else if (theShape->isCompound()) {
+    GeomAPI_ShapeIterator anIt(theShape);
+    aFace = anIt.current()->face();
+  }
+
+  return aFace;
+}
+
 std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
 {
   std::shared_ptr<GeomAPI_Lin> aLin;
 
-  if(!theShape->isEdge()) {
+  GeomEdgePtr anEdge;
+
+  if (theShape->isEdge()) {
+    anEdge = theShape->edge();
+  }
+  else if (theShape->isCompound()) {
+    GeomAPI_ShapeIterator anIt(theShape);
+    anEdge = anIt.current()->edge();
+  }
+  else {
     return aLin;
   }
 
-  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
-
   if(!anEdge->isLine()) {
     return aLin;
   }
@@ -506,13 +553,20 @@ std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
 {
   std::shared_ptr<GeomAPI_Pln> aPln;
 
-  if(!theShape->isFace()) {
+  GeomFacePtr aFace;
+
+  if(theShape->isFace()) {
+    aFace = theShape->face();
+  }
+  else if (theShape->isCompound()) {
+    GeomAPI_ShapeIterator anIt(theShape);
+    aFace = anIt.current()->face();
+  }
+  else {
     return aPln;
   }
 
-  std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
-
-  if(!aFace->isPlanar()) {
+  if(!aFace || !aFace->isPlanar()) {
     return aPln;
   }