From: dbv Date: Fri, 7 Apr 2017 08:37:22 +0000 (+0300) Subject: Issue #2111: Strange compsolid X-Git-Tag: V_2.7.0~31 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1060ef85c112c911bdfe6b77635a8c1fac2118af;p=modules%2Fshaper.git Issue #2111: Strange compsolid Moved validation of selected objects for generation from attribute validator to feature validator. --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 1509e6c77..a7a0ccf01 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -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", diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index c4d7cb671..01f5e6233 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -142,8 +142,6 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA return false; } - std::set aSelectedSketches; - std::set 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& theFeature, + const std::list& 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 aSelectedSketches; + std::set 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(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::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& theArguments, diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.h b/src/FeaturesPlugin/FeaturesPlugin_Validators.h index d01605463..0efd753d6 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.h @@ -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& theFeature, + const std::list& 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 diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 25a388dff..221ce6079 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -85,4 +85,5 @@ + diff --git a/src/FeaturesPlugin/extrusioncut_widget.xml b/src/FeaturesPlugin/extrusioncut_widget.xml index fb9607c85..c4cedff0c 100755 --- a/src/FeaturesPlugin/extrusioncut_widget.xml +++ b/src/FeaturesPlugin/extrusioncut_widget.xml @@ -95,4 +95,5 @@ + diff --git a/src/FeaturesPlugin/extrusionfuse_widget.xml b/src/FeaturesPlugin/extrusionfuse_widget.xml index d4105c496..a9b114ef8 100644 --- a/src/FeaturesPlugin/extrusionfuse_widget.xml +++ b/src/FeaturesPlugin/extrusionfuse_widget.xml @@ -95,4 +95,5 @@ + diff --git a/src/FeaturesPlugin/pipe_widget.xml b/src/FeaturesPlugin/pipe_widget.xml index f2807b069..ba9e808a9 100644 --- a/src/FeaturesPlugin/pipe_widget.xml +++ b/src/FeaturesPlugin/pipe_widget.xml @@ -34,4 +34,5 @@ + diff --git a/src/FeaturesPlugin/revolution_widget.xml b/src/FeaturesPlugin/revolution_widget.xml index db35c6ee2..852c1328d 100644 --- a/src/FeaturesPlugin/revolution_widget.xml +++ b/src/FeaturesPlugin/revolution_widget.xml @@ -84,4 +84,5 @@ + diff --git a/src/FeaturesPlugin/revolutioncut_widget.xml b/src/FeaturesPlugin/revolutioncut_widget.xml index b9b30d7f2..a95956bcc 100644 --- a/src/FeaturesPlugin/revolutioncut_widget.xml +++ b/src/FeaturesPlugin/revolutioncut_widget.xml @@ -94,4 +94,5 @@ + diff --git a/src/FeaturesPlugin/revolutionfuse_widget.xml b/src/FeaturesPlugin/revolutionfuse_widget.xml index 5afe59cfa..5c10528a1 100644 --- a/src/FeaturesPlugin/revolutionfuse_widget.xml +++ b/src/FeaturesPlugin/revolutionfuse_widget.xml @@ -94,4 +94,5 @@ +