From: dbv Date: Tue, 19 Apr 2016 12:17:53 +0000 (+0300) Subject: Issue #1369: Optimized validators for Build plug-in X-Git-Tag: V_2.3.0~186 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c4d2f68414d305c0d8abc70b6cfa80887427303b;p=modules%2Fshaper.git Issue #1369: Optimized validators for Build plug-in --- diff --git a/src/BuildPlugin/BuildPlugin_Plugin.cpp b/src/BuildPlugin/BuildPlugin_Plugin.cpp index 5df9e579a..3433f3b9e 100644 --- a/src/BuildPlugin/BuildPlugin_Plugin.cpp +++ b/src/BuildPlugin/BuildPlugin_Plugin.cpp @@ -22,8 +22,8 @@ BuildPlugin_Plugin::BuildPlugin_Plugin() // Register validators. SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - aFactory->registerValidator("BuildPlugin_ValidatorBaseForVertex", - new BuildPlugin_ValidatorBaseForVertex()); + aFactory->registerValidator("BuildPlugin_ValidatorBaseForBuild", + new BuildPlugin_ValidatorBaseForBuild()); aFactory->registerValidator("BuildPlugin_ValidatorBaseForWire", new BuildPlugin_ValidatorBaseForWire()); diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 285a03121..7706fe77a 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -13,12 +13,14 @@ #include +#include + #include //================================================================================================= -bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const +bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const { // Get base objects list. if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) { @@ -59,13 +61,13 @@ bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribut return false; } - // Check that shape has acceptable type. - if(aShape->shapeType() != GeomAPI_Shape::VERTEX) { - theError = "Selected shape has wrong type. Only vertices acceptable."; + // Check that shapes has acceptable type. + GeomValidators_ShapeType aValidatorShapeType; + if(!aValidatorShapeType.isValid(aSelection, theArguments, theError)) { return false; } - // Check that it is vertex on sketch. + // Check that it is shape on sketch. ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); if(aConstruction.get()) { if(aConstruction->isInfinite()) { @@ -74,16 +76,17 @@ bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribut } std::shared_ptr anEdges = std::dynamic_pointer_cast(aContextShape); - if(!anEdges.get()) { - // It is not an edge on the sketch. - // Check that it is not local selection. - if(!aShape->isEqual(aContextShape)) { - // Local selection on body does not allowed. - theError = "Selected shape is in the local selection. Only global selection is allowed."; - return false; - } + if(anEdges.get() && !aShape->isEqual(aContextShape)) { + // It is local selection on sketch. Ok. + return true; } } + + if(!aShape->isEqual(aContextShape)) { + // Local selection on body does not allowed. + theError = "Selected shape is in the local selection. Only global selection is allowed."; + return false; + } } return true; @@ -95,71 +98,23 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute, std::string& theError) const { // Get base objects list. - if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) { - Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType() - + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported."); - return false; - } - AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast(theAttribute); - if(!aSelectionList.get()) { - theError = "Could not get selection list."; - return false; - } - if(aSelectionList->size() == 0) { - theError = "Empty selection list."; + BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild; + if(!aValidatorBaseForBuild.isValid(theAttribute, theArguments, 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); - if(!aSelection.get()) { - theError = "Could not get selection."; - return false; - } ResultPtr aContext = aSelection->context(); - if(!aContext.get()) { - theError = "Attribute have empty context."; - return false; - } - GeomShapePtr aShape = aSelection->value(); GeomShapePtr aContextShape = aContext->shape(); if(!aShape.get()) { - aShape = aContextShape; - } - if(!aShape.get()) { - theError = "Empty shape selected."; - return false; - } - - // Check that shape has acceptable type. - if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) { - theError = "Selected shape has wrong type. Only edges and wires acceptable."; - return false; - } - - // Check that it is edge on sketch. - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); - if(aConstruction.get()) { - if(aConstruction->isInfinite()) { - theError = "Inifinte objects not acceptable."; - return false; - } - - std::shared_ptr anEdges = std::dynamic_pointer_cast(aContextShape); - if(!anEdges.get()) { - // It is not an edge on the sketch. - // Check that it is not local selection. - if(!aShape->isEqual(aContextShape)) { - // Local selection on body does not allowed. - theError = "Selected shape is in the local selection. Only global selection is allowed."; - return false; - } - } + aShape = aSelection->context()->shape(); } - aListOfShapes.push_back(aShape); } diff --git a/src/BuildPlugin/BuildPlugin_Validators.h b/src/BuildPlugin/BuildPlugin_Validators.h index eb698b21a..b7c2420d9 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.h +++ b/src/BuildPlugin/BuildPlugin_Validators.h @@ -10,11 +10,11 @@ #include #include -/// \class BuildPlugin_ValidatorBaseForVertex +/// \class BuildPlugin_ValidatorBaseForBuild /// \ingroup Validators -/// \brief A validator for selection base shapes for vertex. Allows to select vertices on sketch and -/// vertex objects. -class BuildPlugin_ValidatorBaseForVertex: public ModelAPI_AttributeValidator +/// \brief A validator for selection base shapes for build features. Allows to select shapes on sketch and +/// whole objects with allowed type. +class BuildPlugin_ValidatorBaseForBuild: public ModelAPI_AttributeValidator { public: //! Returns true if attribute is ok. diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt index 7a49953a1..39e728f77 100644 --- a/src/BuildPlugin/CMakeLists.txt +++ b/src/BuildPlugin/CMakeLists.txt @@ -8,6 +8,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/ModelAPI ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI + ${PROJECT_SOURCE_DIR}/src/GeomValidators ) SET(PROJECT_HEADERS @@ -37,6 +38,7 @@ SET(PROJECT_LIBRARIES ModelAPI GeomAPI GeomAlgoAPI + GeomValidators ) ADD_DEFINITIONS(-DBUILDPLUGIN_EXPORTS) diff --git a/src/BuildPlugin/vertex_widget.xml b/src/BuildPlugin/vertex_widget.xml index 04d0603f8..bc9b7f318 100644 --- a/src/BuildPlugin/vertex_widget.xml +++ b/src/BuildPlugin/vertex_widget.xml @@ -4,7 +4,7 @@ - + type_choice="vertices objects"> + diff --git a/src/BuildPlugin/wire_widget.xml b/src/BuildPlugin/wire_widget.xml index 967ba23fb..e2843b437 100644 --- a/src/BuildPlugin/wire_widget.xml +++ b/src/BuildPlugin/wire_widget.xml @@ -5,7 +5,7 @@ label="Segments and wires:" tooltip="Select an edges on sketch or wires objects." type_choice="edges objects"> - +