Salome HOME
Issue #2111: Strange compsolid
authordbv <dbv@opencascade.com>
Fri, 7 Apr 2017 08:37:22 +0000 (11:37 +0300)
committerdbv <dbv@opencascade.com>
Fri, 7 Apr 2017 08:37:50 +0000 (11:37 +0300)
Moved validation of selected objects for generation from attribute validator to feature validator.

src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.h
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/extrusioncut_widget.xml
src/FeaturesPlugin/extrusionfuse_widget.xml
src/FeaturesPlugin/pipe_widget.xml
src/FeaturesPlugin/revolution_widget.xml
src/FeaturesPlugin/revolutioncut_widget.xml
src/FeaturesPlugin/revolutionfuse_widget.xml

index 1509e6c776ec6d654f3293241fa90e03292050f8..a7a0ccf01efeb4ab231e7f77cccba21a3b0f6355 100644 (file)
@@ -43,6 +43,8 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin()
                               new FeaturesPlugin_ValidatorCompositeLauncher);
   aFactory->registerValidator("FeaturesPlugin_ValidatorBaseForGeneration",
                               new FeaturesPlugin_ValidatorBaseForGeneration);
+  aFactory->registerValidator("FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects",
+                              new FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects);
   aFactory->registerValidator("FeaturesPlugin_ValidatorPipeLocations",
                               new FeaturesPlugin_ValidatorPipeLocations);
   aFactory->registerValidator("FeaturesPlugin_ValidatorExtrusionDir",
index c4d7cb6717d052a930753e94a8b1c91c0aa58a99..01f5e623390e69387d636e67d1bd2afd66b5af59 100644 (file)
@@ -142,8 +142,6 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
     return false;
   }
 
-  std::set<ResultConstructionPtr> aSelectedSketches;
-  std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
   GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
   std::string anAttributeType = theAttribute->attributeType();
   if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
@@ -184,26 +182,10 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
       GeomShapePtr aShape = aSelectionAttr->value();
       GeomShapePtr aContextShape = aResultConstruction->shape();
       if(!aShape.get()) {
-        // For possibility to select whole sketch from ObjectBrowser when
-        // Extrusion already has sub-element of this sketch, the next check
-        // is commented
         // Whole sketch selected.
-        /*if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
-            aSelectedSketchesFromObjects.cend()) {
-          theError = "Error: Object from this sketch is already selected. "
-                     "Sketch is not allowed for selection.";
-          return false;
-        }*/
-
-        aSelectedSketches.insert(aResultConstruction);
+        continue;
       } else {
         // Object from sketch selected.
-        if(aSelectedSketches.find(aResultConstruction) != aSelectedSketches.cend()) {
-          theError = "Error: Whole sketch with this object is already selected. "
-                     "Don't allow to select this object.";
-          return false;
-        }
-
         for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
           GeomShapePtr aWire = anExp.current();
           if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
@@ -218,7 +200,6 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
           }
 
           aSelectedWiresFromObjects.bind(aWire, aWire);
-          aSelectedSketchesFromObjects.insert(aResultConstruction);
         }
       }
     }
@@ -227,6 +208,73 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA
   return true;
 }
 
+//==================================================================================================
+bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
+{
+  const std::string aBaseObjectsID = theArguments.front();
+
+  AttributeSelectionListPtr aListAttr = theFeature->selectionList(aBaseObjectsID);
+  if(!aListAttr.get()) {
+    theError = "Error: Could not get \"%1\" attribute.";
+    theError.arg(aBaseObjectsID);
+    return false;
+  }
+
+  std::set<ResultConstructionPtr> aSelectedSketches;
+  std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
+
+  for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
+    AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
+    ResultPtr aContext = aSelectionAttr->context();
+    if(!aContext.get()) {
+      theError = "Error: Empty context.";
+      return false;
+    }
+
+    ResultConstructionPtr aResultConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if(!aResultConstruction.get()) {
+      // It is not a result construction.
+      continue;
+    }
+
+    GeomShapePtr aShape = aSelectionAttr->value();
+    GeomShapePtr aContextShape = aResultConstruction->shape();
+    if(!aShape.get()) {
+      // Whole sketch selected.
+      aSelectedSketches.insert(aResultConstruction);
+    } else {
+      // Object from sketch selected.
+      aSelectedSketchesFromObjects.insert(aResultConstruction);
+    }
+  }
+
+
+  for(std::set<ResultConstructionPtr>::const_iterator anIt = aSelectedSketches.cbegin();
+      anIt != aSelectedSketches.cend();
+      ++anIt) {
+    ResultConstructionPtr aResultConstruction = *anIt;
+    if(aSelectedSketchesFromObjects.find(aResultConstruction) !=
+        aSelectedSketchesFromObjects.cend()) {
+      theError = "Sketch and objects from it can not be selected at the same time.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isNotObligatory(
+    std::string theFeature,
+    std::string theAttribute)
+{
+  return false;
+}
+
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
index d01605463efc0bd9577bc6c719b7660513927863..0efd753d68d2510b44adebae32a870e6da89d549 100644 (file)
@@ -64,6 +64,26 @@ private:
                         Events_InfoMessage& theError) const;
 };
 
+/// \class FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects
+/// \ingroup Validators
+/// \brief Validator for the base objects for generation. Checks that sketch and it objects
+///        are not selected at the same time.
+class FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects:
+  public ModelAPI_FeatureValidator
+{
+ public:
+  //! \return true if sketch and it objects not selected at the same time.
+  //! \param theFeature the checked feature
+  //! \param theArguments arguments of the feature (not used)
+  //! \param theError error message
+  virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                       const std::list<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
+
+  /// Returns true if the attribute in feature is not obligatory for the feature execution
+  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+};
+
 /// \class FeaturesPlugin_ValidatorCompositeLauncher
 /// \ingroup Validators
 /// \brief A validator for selection at composite feature start
index 25a388dffb92d64cedcd05360f487b82eb82a568..221ce6079d41582bf854c734dfcedac5d576f9b6 100644 (file)
@@ -85,4 +85,5 @@
   </toolbox>
   <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,BySizes,base,to_size,from_size,to_object,to_offset,from_object,from_offset"/>
   <validator id="FeaturesPlugin_ValidatorExtrusionDir" parameters="base,direction_object"/>
+  <validator id="FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects" parameters="base"/>
 </source>
index fb9607c85c8c7d2fb14a85725c765b85a2758fe7..c4cedff0c8509fab504a2bb1ba0cd9984a9df6a1 100755 (executable)
@@ -95,4 +95,5 @@
   </multi_selector>
   <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,BySizes,sketch_selection,to_size,from_size,to_object,to_offset,from_object,from_offset"/>
   <validator id="FeaturesPlugin_ValidatorExtrusionDir" parameters="base,direction_object"/>
+  <validator id="FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects" parameters="base"/>
 </source>
index d4105c496e9dfe4eceff943daf93893229886cc6..a9b114ef8b81cab3fb14e23bc9ab90ab9ea2f0cc 100644 (file)
@@ -95,4 +95,5 @@
   </multi_selector>
   <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,BySizes,sketch_selection,to_size,from_size,to_object,to_offset,from_object,from_offset"/>
   <validator id="FeaturesPlugin_ValidatorExtrusionDir" parameters="base,direction_object"/>
+  <validator id="FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects" parameters="base"/>
 </source>
index f2807b069e7f6e211782f7b2e2ecec25c6649a7e..ba9e808a9a3264e23c6a6d3fddb5634f6dc1fbc7 100644 (file)
@@ -34,4 +34,5 @@
     </box>
   </toolbox>
   <validator id="FeaturesPlugin_ValidatorPipeLocations"/>
+  <validator id="FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects" parameters="base_objects"/>
 </source>
index db35c6ee28ca882f57d96871b964c66fbcd7e376..852c1328d14904522e9203afeaaedafb7762e7ce 100644 (file)
@@ -84,4 +84,5 @@
     </box>
   </toolbox>
   <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,ByAngles,base,to_angle,from_angle,to_object,to_offset,from_object,from_offset"/>
+  <validator id="FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects" parameters="base"/>
 </source>
index b9b30d7f29b4eade6e252aca5c4c4ff037618088..a95956bcc2c9c31ec0a23c6749b97a5bf2fc699d 100644 (file)
@@ -94,4 +94,5 @@
     <validator id="GeomValidators_ShapeType" parameters="solid"/>
   </multi_selector>
   <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,ByAngles,sketch_selection,to_angle,from_angle,to_object,to_offset,from_object,from_offset"/>
+  <validator id="FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects" parameters="base"/>
 </source>
index 5afe59cfa33e2f8bbb99ce75215e7685a19dbec7..5c10528a19f22a9a88bd18a4295de85ce6dd7896 100644 (file)
@@ -94,4 +94,5 @@
     <validator id="GeomValidators_ShapeType" parameters="solid"/>
   </multi_selector>
   <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,ByAngles,sketch_selection,to_angle,from_angle,to_object,to_offset,from_object,from_offset"/>
+  <validator id="FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects" parameters="base"/>
 </source>