From: dbv Date: Tue, 19 Apr 2016 13:41:52 +0000 (+0300) Subject: Issue #1369: Feature "Edge" for Build plug-in X-Git-Tag: V_2.3.0~185 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1be6afdf88358a1f6823078e65e7d42574c10b8b;p=modules%2Fshaper.git Issue #1369: Feature "Edge" for Build plug-in --- diff --git a/src/BuildPlugin/BuildPlugin_Edge.cpp b/src/BuildPlugin/BuildPlugin_Edge.cpp new file mode 100644 index 000000000..0ae8accdd --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Edge.cpp @@ -0,0 +1,82 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: BuildPlugin_Edge.cpp +// Created: 18 April 2016 +// Author: Dmitry Bobylev + +#include "BuildPlugin_Edge.h" + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +//================================================================================================= +BuildPlugin_Edge::BuildPlugin_Edge() +{ +} + +//================================================================================================= +void BuildPlugin_Edge::initAttributes() +{ + data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId()); +} + +//================================================================================================= +void BuildPlugin_Edge::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::EDGE) { + setError("Error: Selected shape has wrong type. Only edges 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_Edge.h b/src/BuildPlugin/BuildPlugin_Edge.h new file mode 100644 index 000000000..bbe34674a --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Edge.h @@ -0,0 +1,51 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: BuildPlugin_Edge.h +// Created: 18 April 2016 +// Author: Dmitry Bobylev + +#ifndef BuildPlugin_Edge_H_ +#define BuildPlugin_Edge_H_ + +#include "BuildPlugin.h" + +#include + +/// \class BuildPlugin_Edge +/// \ingroup Plugins +/// \brief Feature for creation of edge from sketch edge or existing edges. +class BuildPlugin_Edge: public ModelAPI_Feature +{ +public: + /// Use plugin manager for features creation + BuildPlugin_Edge(); + + /// Feature kind. + inline static const std::string& ID() + { + static const std::string MY_ID("Edge"); + 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_Edge::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/BuildPlugin_Plugin.cpp b/src/BuildPlugin/BuildPlugin_Plugin.cpp index 3433f3b9e..f26c60ace 100644 --- a/src/BuildPlugin/BuildPlugin_Plugin.cpp +++ b/src/BuildPlugin/BuildPlugin_Plugin.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -36,6 +37,8 @@ FeaturePtr BuildPlugin_Plugin::createFeature(std::string theFeatureID) { if(theFeatureID == BuildPlugin_Vertex::ID()) { return FeaturePtr(new BuildPlugin_Vertex()); + } else if(theFeatureID == BuildPlugin_Edge::ID()) { + return FeaturePtr(new BuildPlugin_Edge()); } 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 7706fe77a..9aa7c8acd 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -76,17 +76,17 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute } std::shared_ptr anEdges = std::dynamic_pointer_cast(aContextShape); - if(anEdges.get() && !aShape->isEqual(aContextShape)) { - // It is local selection on sketch. Ok. - return true; + if(anEdges.get()) { + if(aShape->isEqual(aContextShape)) { + // It is whole sketch. + return false; + } + } else 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(!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; diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt index 39e728f77..3c159e8d6 100644 --- a/src/BuildPlugin/CMakeLists.txt +++ b/src/BuildPlugin/CMakeLists.txt @@ -15,6 +15,7 @@ SET(PROJECT_HEADERS BuildPlugin.h BuildPlugin_Plugin.h BuildPlugin_Vertex.h + BuildPlugin_Edge.h BuildPlugin_Wire.h BuildPlugin_Validators.h ) @@ -22,6 +23,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES BuildPlugin_Plugin.cpp BuildPlugin_Vertex.cpp + BuildPlugin_Edge.cpp BuildPlugin_Wire.cpp BuildPlugin_Validators.cpp ) @@ -29,6 +31,7 @@ SET(PROJECT_SOURCES SET(XML_RESOURCES plugin-Build.xml vertex_widget.xml + edge_widget.xml wire_widget.xml ) diff --git a/src/BuildPlugin/edge_widget.xml b/src/BuildPlugin/edge_widget.xml new file mode 100644 index 000000000..e02f2721e --- /dev/null +++ b/src/BuildPlugin/edge_widget.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/src/BuildPlugin/icons/feature_edge.png b/src/BuildPlugin/icons/feature_edge.png new file mode 100644 index 000000000..497061286 Binary files /dev/null and b/src/BuildPlugin/icons/feature_edge.png differ diff --git a/src/BuildPlugin/plugin-Build.xml b/src/BuildPlugin/plugin-Build.xml index 0fc10c889..0c2161f68 100644 --- a/src/BuildPlugin/plugin-Build.xml +++ b/src/BuildPlugin/plugin-Build.xml @@ -6,6 +6,9 @@ + + +