Salome HOME
#1707 Fatal error when Recover box
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
index db8348cd2a1b8fd0af2099e061313b34b8cd0369..c77f516b64c14c8b09fe732d2efa850e360139ec 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "FeaturesPlugin_Union.h"
 
+#include <Events_InfoMessage.h>
+
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
@@ -38,7 +40,7 @@
 //==================================================================================================
 bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
                                                const std::list<std::string>& theArguments,
-                                               std::string& theError) const
+                                               Events_InfoMessage& theError) const
 {
   AttributeSelectionPtr aPathAttrSelection = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
   if(!aPathAttrSelection.get()) {
@@ -64,20 +66,22 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
 //==================================================================================================
 bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                     const std::list<std::string>& theArguments,
-                                                    std::string& theError) const
+                                                    Events_InfoMessage& theError) const
 {
   static const std::string aCreationMethodID = "creation_method";
   static const std::string aBaseObjectsID = "base_objects";
   static const std::string aLocationsID = "locations_objects";
 
   if(theFeature->getKind() != "Pipe") {
-    theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
+    theError = "Error: Feature \"%1\" does not supported by this validator.";
+    theError.arg(theFeature->getKind());
     return false;
   }
 
   AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
   if(!aCreationMethodAttr.get()) {
-    theError = "Error: Could not get \"" + aCreationMethodID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aCreationMethodID);
     return false;
   }
 
@@ -87,13 +91,15 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelA
 
   AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
   if(!aBaseObjectsSelectionList.get()) {
-    theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseObjectsID);
     return false;
   }
 
   AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
   if(!aLocationsSelectionList.get()) {
-    theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseObjectsID);
     return false;
   }
 
@@ -114,7 +120,7 @@ bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeatu
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
-                                                        std::string& theError) const
+                                                        Events_InfoMessage& theError) const
 {
   if(theArguments.empty()) {
     theError = "Error: Validator parameters is empty.";
@@ -207,7 +213,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
                                                                  const std::list<std::string>& theArguments,
-                                                                 std::string& theError) const
+                                                                 Events_InfoMessage& theError) const
 {
   if(!theAttribute.get()) {
     theError = "Error: Empty attribute.";
@@ -274,18 +280,20 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
     // Check that object is a shape with allowed type.
     GeomValidators_ShapeType aShapeTypeValidator;
     if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
-      theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, "
-                 "whole sketch(if it has at least one face), and whole objects with shape types: ";
-      std::list<std::string>::const_iterator anIt = theArguments.cbegin();
-      theError += *anIt;
-      for(++anIt; anIt != theArguments.cend(); ++anIt) {
-        theError += ", " + *anIt;
+      theError = "Error: Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, whole sketch(if it has at least one face), and whole objects with shape types: %1";
+      std::string anArgumentString;
+      for(auto anIt = theArguments.cbegin(); anIt != theArguments.cend(); ++anIt) {
+        if (!anArgumentString.empty())
+          anArgumentString += ", ";
+        anArgumentString += *anIt;
       }
+      theError.arg(anArgumentString);
       return false;
     }
 
   } else {
-    theError = "Error: Attribute \"" + anAttributeType + "\" does not supported by this validator.";
+    theError = "Error: Attribute \"%1\" does not supported by this validator.";
+    theError.arg(anAttributeType);
     return false;
   }
 
@@ -295,14 +303,16 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
 //==================================================================================================
 bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
-                                                        std::string& theError) const
+                                                        Events_InfoMessage& theError) const
 {
   if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
-    theError = "Error: The attribute with the " + theAttribute->attributeType() + " type is not processed";
+    theError = "Error: The attribute with the %1 type is not processed";
+    theError.arg(theAttribute->attributeType());
     return false;
   }
   if (theArguments.size() != 2) {
-    theError = "Error: Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+    theError = "Error: Wrong parameters in XML definition for %1 type";
+    theError.arg(theAttribute->attributeType());
     return false;
   }
   // first argument is for the base attribute, second - for skipping feature kind
@@ -311,7 +321,8 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA
   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
   AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
   if (!aBaseAttribute.get()) {
-    theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+    theError = "Wrong parameters in XML definition for %1 type";
+    theError.arg(theAttribute->attributeType());
     return false;
   }
   if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
@@ -340,7 +351,7 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA
 //==================================================================================================
 bool FeaturesPlugin_ValidatorExtrusionDir::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                  const std::list<std::string>& theArguments,
-                                                 std::string& theError) const
+                                                 Events_InfoMessage& theError) const
 {
   if(theArguments.size() != 2) {
     theError = "Error: Validator should be used with 2 parameters for extrusion.";
@@ -367,8 +378,8 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(const std::shared_ptr<ModelAP
   if(!aDirShape.get()) {
     // Check that dir can be empty.
     if(!isShapesCanBeEmpty(aCheckAttribute, theError)) {
-      theError = "Error: Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
-               + "\" can not be used with default value. Select direction for extrusion.";
+      theError = "Error: Base objects list contains vertex or edge, so attribute \"%1\" can not be used with default value. Select direction for extrusion.";
+      theError.arg(*anArgsIt);
       return false;
     } else {
       return true;
@@ -427,7 +438,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeatur
 
 //==================================================================================================
 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
-                                                            std::string& theError) const
+                                                              Events_InfoMessage& theError) const
 {
   if(!theAttribute.get()) {
     return true;
@@ -474,7 +485,7 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAttribute,
                                                        const std::list<std::string>& theArguments,
-                                                       std::string& theError) const
+                                                       Events_InfoMessage& theError) const
 {
   AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!anAttrSelectionList.get()) {
@@ -502,13 +513,19 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
       return false;
     }
     std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    GeomShapePtr aContextShape = aContext->shape();
     if(!aShape.get()) {
-      aShape = aContext->shape();
+      aShape = aContextShape;
     }
     if(!aShape.get()) {
       theError = "Error: Empty shape.";
       return false;
     }
+    if(!aShape->isEqual(aContextShape)) {
+      theError = "Error: Local selection not allowed.";
+      return false;
+    }
+
     int aShapeType = aShape->shapeType();
     if(anOperationType == 1) {
       // Fuse operation. Allow to select edges, faces and solids.
@@ -536,7 +553,7 @@ bool FeaturesPlugin_ValidatorBooleanSelection::isValid(const AttributePtr& theAt
 //==================================================================================================
 bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& theAttribute,
                                                          const std::list<std::string>& theArguments,
-                                                         std::string& theError) const
+                                                         Events_InfoMessage& theError) const
 {
   AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!anAttrSelectionList.get()) {
@@ -580,7 +597,7 @@ bool FeaturesPlugin_ValidatorPartitionSelection::isValid(const AttributePtr& the
 //==================================================================================================
 bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
                                                                const std::list<std::string>& theArguments,
-                                                               std::string& theError) const
+                                                               Events_InfoMessage& theError) const
 {
   AttributeSelectionListPtr aSubShapesAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!aSubShapesAttrList.get()) {
@@ -593,7 +610,8 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
   AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
 
   if(!aShapeAttrSelection.get()) {
-    theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseShapeID);
     return false;
   }
 
@@ -633,25 +651,28 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePt
 //==================================================================================================
 bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                             const std::list<std::string>& theArguments,
-                                                            std::string& theError) const
+                                                            Events_InfoMessage& theError) const
 {
   static const std::string aBaseShapeID = "base_shape";
   static const std::string aSubShapesID = "subshapes";
 
   if(theFeature->getKind() != "Remove_SubShapes") {
-    theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
+    theError = "Error: Feature \"%1\" does not supported by this validator.";
+    theError.arg(theFeature->getKind());
     return false;
   }
 
   AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
   if(!aShapeAttrSelection.get()) {
-    theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseShapeID);
     return false;
   }
 
   AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
   if(!aSubShapesAttrList.get()) {
-    theError = "Error: Could not get \"" + aSubShapesID + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aSubShapesID);
     return false;
   }
 
@@ -689,11 +710,12 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string
 //==================================================================================================
 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
                                                      const std::list<std::string>& theArguments,
-                                                     std::string& theError) const
+                                                     Events_InfoMessage& theError) const
 {
   AttributeSelectionListPtr aBaseObjectsAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
   if(!aBaseObjectsAttrList.get()) {
-    theError = "Error: This validator can only work with selection list in \"" + FeaturesPlugin_Union::ID() + "\" feature.";
+    theError = "Error: This validator can only work with selection list in \"%1\" feature.";
+    theError.arg(FeaturesPlugin_Union::ID());
     return false;
   }
 
@@ -716,18 +738,20 @@ bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttr
 //==================================================================================================
 bool FeaturesPlugin_ValidatorUnionArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                      const std::list<std::string>& theArguments,
-                                                     std::string& theError) const
+                                                     Events_InfoMessage& theError) const
 {
   // Check feature kind.
   if(theFeature->getKind() != FeaturesPlugin_Union::ID()) {
-    theError = "Error: This validator supports only \"" + FeaturesPlugin_Union::ID() + "\" feature.";
+    theError = "Error: This validator supports only \"%1\" feature.";
+    theError.arg(FeaturesPlugin_Union::ID());
     return false;
   }
 
   // Get base objects attribute list.
   AttributeSelectionListPtr aBaseObejctsAttrList = theFeature->selectionList(FeaturesPlugin_Union::BASE_OBJECTS_ID());
   if(!aBaseObejctsAttrList.get()) {
-    theError = "Error: Could not get \"" + FeaturesPlugin_Union::BASE_OBJECTS_ID() + "\" attribute.";
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(FeaturesPlugin_Union::BASE_OBJECTS_ID());
     return false;
   }