Salome HOME
Deleted check after build for transformations.
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Validators.cpp
index 234e697b2d7712f36986c76fca5aad3265a5b33c..fc93bc7dfd204b0f6486da93f2012aaf0f9c2dcb 100644 (file)
 //=================================================================================================
 bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute,
                                                 const std::list<std::string>& theArguments,
-                                                std::string& theError) const
+                                                Events_InfoMessage& theError) const
 {
   // Get base objects list.
   if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
-    std::string aMsg = "Error: BuildPlugin_ValidatorBaseForBuild does not support attribute type '%1'\nOnly '%2' is supported.";
+    std::string aMsg = "Error: BuildPlugin_ValidatorBaseForBuild does "
+                       "not support attribute type '%1'\nOnly '%2' is supported.";
     Events_InfoMessage("BuildPlugin_Validators", aMsg).
       arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
     return false;
@@ -78,14 +79,16 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute
     }
 
     // Check that it is shape on sketch.
-    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    ResultConstructionPtr aConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(aConstruction.get()) {
       if(aConstruction->isInfinite()) {
         theError = "Inifinte objects not acceptable.";
         return false;
       }
 
-      std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
+      std::shared_ptr<GeomAPI_PlanarEdges> anEdges =
+        std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
       if(anEdges.get()) {
         if(aShape->isEqual(aContextShape)) {
           // It is whole sketch.
@@ -109,17 +112,19 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute
 //=================================================================================================
 bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                const std::list<std::string>& theArguments,
-                                               std::string& theError) const
+                                               Events_InfoMessage& theError) const
 {
   // Get attribute.
   if(theArguments.size() != 1) {
-    std::string aMsg = "Error: BuildPlugin_ValidatorBaseForWire should be used only with 1 parameter (ID of base objects list).";
+    std::string aMsg = "Error: BuildPlugin_ValidatorBaseForWire should be used only "
+                       "with 1 parameter (ID of base objects list).";
     Events_InfoMessage("BuildPlugin_Validators", aMsg).send();
     return false;
   }
   AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
   if(!aSelectionList.get()) {
-    theError = "Empty attribute \"" + theArguments.front() + "\".";
+    theError = "Empty attribute \"%1\".";
+    theError.arg(theArguments.front());
     return false;
   }
 
@@ -130,9 +135,11 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr<ModelAPI_Fe
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
     GeomShapePtr aShape = aSelection->value();
     if(!aShape.get()) {
-      aShape = aSelection->context()->shape();
+      if (aSelection->context().get())
+        aShape = aSelection->context()->shape();
     }
-    aListOfShapes.push_back(aShape);
+    if (aShape.get())
+      aListOfShapes.push_back(aShape);
   }
 
   // Create wire.
@@ -146,7 +153,8 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr<ModelAPI_Fe
 }
 
 //=================================================================================================
-bool BuildPlugin_ValidatorBaseForWire::isNotObligatory(std::string theFeature, std::string theAttribute)
+bool BuildPlugin_ValidatorBaseForWire::isNotObligatory(std::string theFeature,
+                                                       std::string theAttribute)
 {
   return false;
 }
@@ -154,7 +162,7 @@ bool BuildPlugin_ValidatorBaseForWire::isNotObligatory(std::string theFeature, s
 //=================================================================================================
 bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                const std::list<std::string>& theArguments,
-                                               std::string& theError) const
+                                               Events_InfoMessage& theError) const
 {
   // Get attribute.
   if(theArguments.size() != 1) {
@@ -165,7 +173,8 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
   }
   AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
   if(!aSelectionList.get()) {
-    theError = "Empty attribute \"" + theArguments.front() + "\".";
+    theError = "Empty attribute \"%1\".";
+    theError.arg(theArguments.front());
     return false;
   }
 
@@ -183,6 +192,11 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
     }
   }
 
+  if(anEdges.empty()) {
+    theError = "Objects not selected.";
+    return false;
+  }
+
   // Check that edges does not have intersections.
   if(anEdges.size() > 1) {
     GeomAlgoAPI_PaveFiller aPaveFiller(anEdges, false);
@@ -193,7 +207,8 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
     GeomShapePtr aSectedEdges = aPaveFiller.shape();
 
     int anEdgesNum = 0;
-    for(GeomAPI_ShapeExplorer anExp(aSectedEdges, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+    for(GeomAPI_ShapeExplorer
+        anExp(aSectedEdges, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
       anEdgesNum++;
     }
     if(anEdgesNum != anEdges.size()) {
@@ -205,15 +220,16 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
   // Check that they are planar.
   std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
   if(!aPln.get()) {
-    theError = "Selected objects are not planar.";
+    theError = "Selected object(s) should belong to only one plane.";
     return false;
   }
 
   // Check that selected objects have closed contours.
   ListOfShape aFaces;
-  GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(), aPln->direction(), anEdges, aFaces);
+  GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(),
+                                         aPln->direction(), anEdges, aFaces);
   if(aFaces.empty()) {
-    theError = "Selected objects does not have closed contours.";
+    theError = "Selected objects do not generate closed contour.";
     return false;
   }
 
@@ -221,7 +237,8 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
 }
 
 //=================================================================================================
-bool BuildPlugin_ValidatorBaseForFace::isNotObligatory(std::string theFeature, std::string theAttribute)
+bool BuildPlugin_ValidatorBaseForFace::isNotObligatory(std::string theFeature,
+                                                       std::string theAttribute)
 {
   return false;
 }
@@ -229,7 +246,7 @@ bool BuildPlugin_ValidatorBaseForFace::isNotObligatory(std::string theFeature, s
 //=================================================================================================
 bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAttribute,
                                                       const std::list<std::string>& theArguments,
-                                                      std::string& theError) const
+                                                      Events_InfoMessage& theError) const
 {
   if(theArguments.size() != 1) {
     std::string aMsg = "Error: BuildPlugin_ValidatorSubShapesSelection should be used only with "
@@ -240,7 +257,8 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt
 
   // Get base objects list.
   if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
-    std::string aMsg = "Error: BuildPlugin_ValidatorSubShapesSelection does not support attribute type \""
+    std::string aMsg =
+      "Error: BuildPlugin_ValidatorSubShapesSelection does not support attribute type \""
       "%1\"\n Only \"%2\" supported.";
     Events_InfoMessage("BuildPlugin_Validators", aMsg).
       arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();