From: dbv Date: Mon, 18 Apr 2016 15:46:11 +0000 (+0300) Subject: Issue #1369: Added feature "Create Vertex" X-Git-Tag: V_2.3.0~198 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e22aa9625f7f95e564f698fac361976928dd87a0;p=modules%2Fshaper.git Issue #1369: Added feature "Create Vertex" --- diff --git a/src/BuildPlugin/BuildPlugin_Plugin.cpp b/src/BuildPlugin/BuildPlugin_Plugin.cpp index 5cd553df6..5df9e579a 100644 --- a/src/BuildPlugin/BuildPlugin_Plugin.cpp +++ b/src/BuildPlugin/BuildPlugin_Plugin.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -21,6 +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_ValidatorBaseForWire", new BuildPlugin_ValidatorBaseForWire()); @@ -31,7 +34,9 @@ BuildPlugin_Plugin::BuildPlugin_Plugin() //================================================================================================= FeaturePtr BuildPlugin_Plugin::createFeature(std::string theFeatureID) { - if (theFeatureID == BuildPlugin_Wire::ID()) { + if(theFeatureID == BuildPlugin_Vertex::ID()) { + return FeaturePtr(new BuildPlugin_Vertex()); + } else if(theFeatureID == BuildPlugin_Wire::ID()) { return FeaturePtr(new BuildPlugin_Wire()); } diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 0bd58859c..285a03121 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -15,6 +15,80 @@ #include +//================================================================================================= +bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + 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."; + return false; + } + + // Collect base shapes. + 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::VERTEX) { + theError = "Selected shape has wrong type. Only vertices acceptable."; + return false; + } + + // Check that it is vertex 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; + } + } + } + } + + return true; +} + //================================================================================================= bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute, const std::list& theArguments, @@ -97,4 +171,4 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute, } return true; -} \ No newline at end of file +} diff --git a/src/BuildPlugin/BuildPlugin_Validators.h b/src/BuildPlugin/BuildPlugin_Validators.h index 5156ae6c6..eb698b21a 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.h +++ b/src/BuildPlugin/BuildPlugin_Validators.h @@ -10,6 +10,22 @@ #include #include +/// \class BuildPlugin_ValidatorBaseForVertex +/// \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 +{ +public: + //! Returns true if attribute is ok. + //! \param[in] theAttribute the checked attribute. + //! \param[in] theArguments arguments of the attribute. + //! \param[out] theError error message. + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + /// \class BuildPlugin_ValidatorBaseForWire /// \ingroup Validators /// \brief A validator for selection base shapes for wire. Allows to select edges on sketch and diff --git a/src/BuildPlugin/BuildPlugin_Vertex.cpp b/src/BuildPlugin/BuildPlugin_Vertex.cpp new file mode 100644 index 000000000..a1bd7cc3a --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Vertex.cpp @@ -0,0 +1,82 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: BuildPlugin_Vertex.cpp +// Created: 18 April 2016 +// Author: Dmitry Bobylev + +#include "BuildPlugin_Vertex.h" + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +//================================================================================================= +BuildPlugin_Vertex::BuildPlugin_Vertex() +{ +} + +//================================================================================================= +void BuildPlugin_Vertex::initAttributes() +{ + data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId()); +} + +//================================================================================================= +void BuildPlugin_Vertex::execute() +{ + // Get base objects list. + AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); + if(!aSelectionList.get()) { + setError("Error: Could not get selection list."); + return; + } + if(aSelectionList->size() == 0) { + setError("Error: Empty selection list."); + return; + } + + // Collect base shapes. + ListOfShape aListOfShapes; + int aResultIndex = 0; + for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if(!aShape.get()) { + ResultPtr aContext = aSelection->context(); + if(!aContext.get()) { + setError("Error: Attribute has empty context."); + return; + } + + aShape = aContext->shape(); + } + if(!aShape.get()) { + setError("Error: Empty shape selected."); + return; + } + + if(aShape->shapeType() != GeomAPI_Shape::VERTEX) { + setError("Error: Selected shape has wrong type. Only vertices acceptable."); + return; + } + + // Store result. + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->store(aShape); + setResult(aResultBody, aResultIndex); + ++aResultIndex; + } + + removeResults(aResultIndex); +} diff --git a/src/BuildPlugin/BuildPlugin_Vertex.h b/src/BuildPlugin/BuildPlugin_Vertex.h new file mode 100644 index 000000000..082b90ebd --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Vertex.h @@ -0,0 +1,51 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: BuildPlugin_Vertex.h +// Created: 18 April 2016 +// Author: Dmitry Bobylev + +#ifndef BuildPlugin_Vertex_H_ +#define BuildPlugin_Vertex_H_ + +#include "BuildPlugin.h" + +#include + +/// \class BuildPlugin_Vertex +/// \ingroup Plugins +/// \brief Feature for creation of vertex from sketch vertex or existing vertices. +class BuildPlugin_Vertex: public ModelAPI_Feature +{ +public: + /// Use plugin manager for features creation + BuildPlugin_Vertex(); + + /// Feature kind. + inline static const std::string& ID() + { + static const std::string MY_ID("Vertex"); + return MY_ID; + } + + /// Attribute name of base objects. + inline static const std::string& BASE_OBJECTS_ID() + { + static const std::string MY_BASE_OBJECTS_ID("base_objects"); + return MY_BASE_OBJECTS_ID; + } + + /// \return the kind of a feature. + BUILDPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = BuildPlugin_Vertex::ID(); + return MY_KIND; + } + + /// Request for initialization of data model of the feature: adding all attributes. + BUILDPLUGIN_EXPORT virtual void initAttributes(); + + /// Creates a new part document if needed. + BUILDPLUGIN_EXPORT virtual void execute(); +}; + +#endif diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt index 17e11055d..7a49953a1 100644 --- a/src/BuildPlugin/CMakeLists.txt +++ b/src/BuildPlugin/CMakeLists.txt @@ -13,18 +13,21 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events SET(PROJECT_HEADERS BuildPlugin.h BuildPlugin_Plugin.h + BuildPlugin_Vertex.h BuildPlugin_Wire.h BuildPlugin_Validators.h ) SET(PROJECT_SOURCES BuildPlugin_Plugin.cpp + BuildPlugin_Vertex.cpp BuildPlugin_Wire.cpp BuildPlugin_Validators.cpp ) SET(XML_RESOURCES plugin-Build.xml + vertex_widget.xml wire_widget.xml ) diff --git a/src/BuildPlugin/icons/feature_vertex.png b/src/BuildPlugin/icons/feature_vertex.png new file mode 100644 index 000000000..6795c4c4e Binary files /dev/null and b/src/BuildPlugin/icons/feature_vertex.png differ diff --git a/src/BuildPlugin/plugin-Build.xml b/src/BuildPlugin/plugin-Build.xml index f710019f0..0fc10c889 100644 --- a/src/BuildPlugin/plugin-Build.xml +++ b/src/BuildPlugin/plugin-Build.xml @@ -3,6 +3,9 @@ + + + diff --git a/src/BuildPlugin/vertex_widget.xml b/src/BuildPlugin/vertex_widget.xml new file mode 100644 index 000000000..04d0603f8 --- /dev/null +++ b/src/BuildPlugin/vertex_widget.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 9afdafd18..3458bb7e8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -148,6 +148,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute return true; } } + + return false; } if(!aShape->isEqual(aContextShape)) {