From: dbv Date: Wed, 20 Apr 2016 15:55:22 +0000 (+0300) Subject: Issue #1369: Validator for selection base objects for "Face" feature. Modified BuildP... X-Git-Tag: V_2.3.0~135 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e8109d1f288ff9d45c2e9622116c903a562fda14;p=modules%2Fshaper.git Issue #1369: Validator for selection base objects for "Face" feature. Modified BuildPlugin_ValidatorBaseForWire into feature validator to allow select disconnected edges in wire creation process. --- diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 9aa7c8acd..7204aebce 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -11,6 +11,7 @@ #include +#include #include #include @@ -24,7 +25,7 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute { // Get base objects list. if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) { - Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType() + Events_Error::send("Error: BuildPlugin_ValidatorBaseForBuild does not support attribute type \"" + theAttribute->attributeType() + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported."); return false; } @@ -93,25 +94,33 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute } //================================================================================================= -bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute, +bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, std::string& theError) const { - // Get base objects list. + // Get attribute. + if(theArguments.size() != 1) { + Events_Error::send("Error: BuildPlugin_ValidatorBaseForWire should be used only with 1 parameter (ID of base objects list)"); + return false; + } + AttributePtr anAttribute = theFeature->attribute(theArguments.front()); + + // Check base objects list. BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild; - if(!aValidatorBaseForBuild.isValid(theAttribute, theArguments, theError)) { + std::list anArguments; + anArguments.push_back("edge"); + anArguments.push_back("wire"); + if(!aValidatorBaseForBuild.isValid(anAttribute, anArguments, theError)) { return false; } // Collect base shapes. AttributeSelectionListPtr aSelectionList = - std::dynamic_pointer_cast(theAttribute); + std::dynamic_pointer_cast(anAttribute); ListOfShape aListOfShapes; for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); - ResultPtr aContext = aSelection->context(); GeomShapePtr aShape = aSelection->value(); - GeomShapePtr aContextShape = aContext->shape(); if(!aShape.get()) { aShape = aSelection->context()->shape(); } @@ -127,3 +136,42 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute, return true; } + +//================================================================================================= +bool BuildPlugin_ValidatorBaseForWireisNotObligatory(std::string theFeature, std::string theAttribute) +{ + return false; +} + +//================================================================================================= +bool BuildPlugin_ValidatorBaseForFace::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + // Get base objects list. + BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild; + std::list anArguments; + anArguments.push_back("edge"); + anArguments.push_back("wire"); + if(!aValidatorBaseForBuild.isValid(theAttribute, anArguments, theError)) { + return false; + } + + // Collect base shapes. + AttributeSelectionListPtr aSelectionList = + std::dynamic_pointer_cast(theAttribute); + ListOfShape aListOfShapes; + for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if(!aShape.get()) { + aShape = aSelection->context()->shape(); + } + aListOfShapes.push_back(aShape); + } + + // Check that they are planar. + GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShapes); + + return aCompound->isPlanar(); +} diff --git a/src/BuildPlugin/BuildPlugin_Validators.h b/src/BuildPlugin/BuildPlugin_Validators.h index b7c2420d9..8792c42ce 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.h +++ b/src/BuildPlugin/BuildPlugin_Validators.h @@ -30,7 +30,26 @@ public: /// \ingroup Validators /// \brief A validator for selection base shapes for wire. Allows to select edges on sketch and /// wires objects that are connected to already selected shapes. -class BuildPlugin_ValidatorBaseForWire: public ModelAPI_AttributeValidator +class BuildPlugin_ValidatorBaseForWire: public ModelAPI_FeatureValidator +{ +public: + //! Returns true if attributes is ok. + //! \param theFeature the checked feature. + //! \param theArguments arguments of the feature. + //! \param theError error message. + virtual bool isValid(const std::shared_ptr& theFeature, + const std::list& theArguments, + std::string& theError) const; + + /// \return true if the attribute in feature is not obligatory for the feature execution + virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); +}; + +/// \class BuildPlugin_ValidatorBaseForFace +/// \ingroup Validators +/// \brief A validator for selection base shapes for face. Allows to select sketch edges, edges and +/// wires objects that lie in the same plane. +class BuildPlugin_ValidatorBaseForFace: public ModelAPI_AttributeValidator { public: //! Returns true if attribute is ok. diff --git a/src/BuildPlugin/wire_widget.xml b/src/BuildPlugin/wire_widget.xml index e2843b437..696c5fb9a 100644 --- a/src/BuildPlugin/wire_widget.xml +++ b/src/BuildPlugin/wire_widget.xml @@ -5,10 +5,11 @@ label="Segments and wires:" tooltip="Select an edges on sketch or wires objects." type_choice="edges objects"> - + +