From: dbv Date: Mon, 18 Apr 2016 12:57:20 +0000 (+0300) Subject: Issue #1369: moved Wire feature to new Build plug-in. X-Git-Tag: V_2.3.0~200 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fc5fd86df3813fdb122301b3599e7e7a79e967e8;p=modules%2Fshaper.git Issue #1369: moved Wire feature to new Build plug-in. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 649cf98c0..4f430b1c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ ADD_SUBDIRECTORY (src/GeomData) ADD_SUBDIRECTORY (src/GeomDataAPI) ADD_SUBDIRECTORY (src/PartSetPlugin) ADD_SUBDIRECTORY (src/ConstructionPlugin) +ADD_SUBDIRECTORY (src/BuildPlugin) ADD_SUBDIRECTORY (src/FeaturesPlugin) ADD_SUBDIRECTORY (src/SamplePanelPlugin) ADD_SUBDIRECTORY (src/SketcherPrs) diff --git a/src/BuildPlugin/BuildPlugin.h b/src/BuildPlugin/BuildPlugin.h new file mode 100644 index 000000000..da8021748 --- /dev/null +++ b/src/BuildPlugin/BuildPlugin.h @@ -0,0 +1,24 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: BuildPlugin.h +// Created: 18 April 2016 +// Author: Dmitry Bobylev + +#ifndef BuildPlugin_H_ +#define BuildPlugin_H_ + +#if defined BUILDPLUGIN_EXPORTS +# if defined WIN32 +# define BUILDPLUGIN_EXPORT __declspec( dllexport ) +# else +# define BUILDPLUGIN_EXPORT +# endif +#else +# if defined WIN32 +# define BUILDPLUGIN_EXPORT __declspec( dllimport ) +# else +# define BUILDPLUGIN_EXPORT +# endif +#endif + +#endif diff --git a/src/BuildPlugin/BuildPlugin_Plugin.cpp b/src/BuildPlugin/BuildPlugin_Plugin.cpp new file mode 100644 index 000000000..5cd553df6 --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Plugin.cpp @@ -0,0 +1,40 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: BuildPlugin_Plugin.cpp +// Created: 18 April 2016 +// Author: Dmitry Bobylev + +#include "BuildPlugin_Plugin.h" + +#include +#include + +#include +#include + +// the only created instance of this plugin +static BuildPlugin_Plugin* MY_INSTANCE = new BuildPlugin_Plugin(); + +//================================================================================================= +BuildPlugin_Plugin::BuildPlugin_Plugin() +{ + // Register validators. + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + aFactory->registerValidator("BuildPlugin_ValidatorBaseForWire", + new BuildPlugin_ValidatorBaseForWire()); + + // Register this plugin. + ModelAPI_Session::get()->registerPlugin(this); +} + +//================================================================================================= +FeaturePtr BuildPlugin_Plugin::createFeature(std::string theFeatureID) +{ + if (theFeatureID == BuildPlugin_Wire::ID()) { + return FeaturePtr(new BuildPlugin_Wire()); + } + + // Feature of such kind is not found. + return FeaturePtr(); +} diff --git a/src/BuildPlugin/BuildPlugin_Plugin.h b/src/BuildPlugin/BuildPlugin_Plugin.h new file mode 100644 index 000000000..b36f44579 --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Plugin.h @@ -0,0 +1,28 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: BuildPlugin_Plugin.h +// Created: 18 April 2016 +// Author: Dmitry Bobylev + +#ifndef BuildPlugin_Plugin_H_ +#define BuildPlugin_Plugin_H_ + +#include "BuildPlugin.h" + +#include +#include + +/// \class BuildPlugin_Plugin +/// \ingroup Plugins +/// \brief The main class for management the build features as plugin. +class BUILDPLUGIN_EXPORT BuildPlugin_Plugin: public ModelAPI_Plugin +{ +public: + /// Default constructor + BuildPlugin_Plugin(); + + /// Creates the feature object of this plugin by the feature string ID + virtual FeaturePtr createFeature(std::string theFeatureID); +}; + +#endif diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp new file mode 100644 index 000000000..0bd58859c --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -0,0 +1,100 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: BuildPlugin_Validators.cpp +// Created: 22 March 2016 +// Author: Dmitry Bobylev + +#include "BuildPlugin_Validators.h" + +#include +#include + +#include + +#include + +#include + +//================================================================================================= +bool BuildPlugin_ValidatorBaseForWire::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. + 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; + } + } + } + + aListOfShapes.push_back(aShape); + } + + // Create wire. + GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes); + if(!aWire.get()) { + theError = "Result wire empty. Probably it has disconnected edges or non-manifold."; + return false; + } + + return true; +} \ No newline at end of file diff --git a/src/BuildPlugin/BuildPlugin_Validators.h b/src/BuildPlugin/BuildPlugin_Validators.h new file mode 100644 index 000000000..5156ae6c6 --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Validators.h @@ -0,0 +1,29 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: BuildPlugin_Validators.h +// Created: 22 March 2016 +// Author: Dmitry Bobylev + +#ifndef BuildPlugin_Validators_H_ +#define BuildPlugin_Validators_H_ + +#include +#include + +/// \class BuildPlugin_ValidatorBaseForWire +/// \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 +{ +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; +}; + +#endif diff --git a/src/BuildPlugin/BuildPlugin_Wire.cpp b/src/BuildPlugin/BuildPlugin_Wire.cpp new file mode 100644 index 000000000..a66975f98 --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Wire.cpp @@ -0,0 +1,202 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: BuildPlugin_Wire.cpp +// Created: 14 April 2016 +// Author: Dmitry Bobylev + +#include "BuildPlugin_Wire.h" + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +//================================================================================================= +BuildPlugin_Wire::BuildPlugin_Wire() +{ +} + +//================================================================================================= +void BuildPlugin_Wire::initAttributes() +{ + data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId()); +} + +//================================================================================================= +void BuildPlugin_Wire::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; + for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if(!aShape.get()) { + setError("Error: Empty shape selected."); + return; + } + + if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) { + setError("Error: Selected shape has wrong type. Only edges and wires acceptable."); + return; + } + + aListOfShapes.push_back(aShape); + } + + // Create wire. + GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes); + if(!aWire.get()) { + setError("Error: Result wire empty. Probably it has disconnected edges or non-manifold."); + return; + } + + // Store result. + ResultBodyPtr aResultBody = document()->createBody(data()); + aResultBody->store(aWire); + setResult(aResultBody); +} + +//================================================================================================= +bool BuildPlugin_Wire::customAction(const std::string& theActionId) +{ + if(theActionId == "add_contour") { + return addContour(); + } else { + Events_Error::send("Error: Feature \"" + getKind() + "\" does not support action \"" + theActionId + "\"."); + } + + return false; +} + +//================================================================================================= +bool BuildPlugin_Wire::addContour() +{ + // Get base objects list. + AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); + if(aSelectionList->size() == 0) { + Events_Error::send("Error: Empty selection list."); + return false; + } + + // Collect attributes to check. + std::list anAttributesToCheck; + for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr anEdgeInList = aSelection->value(); + if(!anEdgeInList.get()) { + continue; + } + + // Check that it is edge. + if(anEdgeInList->shapeType() != GeomAPI_Shape::EDGE) { + continue; + } + + // Check that it is edge on sketch. + ResultPtr aContext = aSelection->context(); + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); + if(!aConstruction.get()) { + continue; + } + GeomShapePtr aContextShape = aConstruction->shape(); + std::shared_ptr aPlanarEdges = std::dynamic_pointer_cast(aContextShape); + if(!aPlanarEdges.get()) { + continue; + } + + // Check that sketch have faces. + if(aConstruction->facesNum() == 0) { + continue; + } + + anAttributesToCheck.push_back(aSelection); + } + + // Check if edges have contours. + ListOfShape anAddedEdges; + bool isAnyContourFound = false; + for(std::list::const_iterator aListIt = anAttributesToCheck.cbegin(); + aListIt != anAttributesToCheck.cend(); + ++aListIt) { + AttributeSelectionPtr aSelection = *aListIt; + std::shared_ptr anEdgeInList(new GeomAPI_Edge(aSelection->value())); + + ListOfShape::const_iterator anEdgesIt = anAddedEdges.cbegin(); + for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) { + if(anEdgeInList->isEqual(*anEdgesIt)) { + break; + } + } + if(anEdgesIt != anAddedEdges.cend()) { + // This edge is already in list. + continue; + } + + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSelection->context()); + std::shared_ptr aPlanarEdges = std::dynamic_pointer_cast(aConstruction->shape()); + + // Iterate on faces and add face with this edge. + std::shared_ptr aFoundFace; + for(int anIndex = 0; anIndex < aConstruction->facesNum(); ++anIndex) { + std::shared_ptr aFace = aConstruction->face(anIndex); + for(GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { + std::shared_ptr anEdgeOnFace(new GeomAPI_Edge(anExp.current())); + if(anEdgeInList->isEqual(anEdgeOnFace)) { + aFoundFace = aFace; + break; + } + } + + if(aFoundFace.get()) { + break; + } + } + + // If face with the same edge found. Add all other edges to list. + if(aFoundFace.get()) { + isAnyContourFound = true; + anAddedEdges.push_back(anEdgeInList); + for(GeomAPI_ShapeExplorer anExp(aFoundFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { + std::shared_ptr anEdgeOnFace(new GeomAPI_Edge(anExp.current())); + anEdgesIt = anAddedEdges.cbegin(); + for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) { + if(anEdgeOnFace->isEqual(*anEdgesIt)) { + break; + } + } + if(anEdgesIt == anAddedEdges.cend()) { + anAddedEdges.push_back(anEdgeOnFace); + aSelectionList->append(aConstruction, anEdgeOnFace); + } + } + } + } + + if(!isAnyContourFound) { + Events_Error::send("Error: Contours already closed or no contours found for selected edges."); + return false; + } + + return true; +} diff --git a/src/BuildPlugin/BuildPlugin_Wire.h b/src/BuildPlugin/BuildPlugin_Wire.h new file mode 100644 index 000000000..39128be6b --- /dev/null +++ b/src/BuildPlugin/BuildPlugin_Wire.h @@ -0,0 +1,62 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: BuildPlugin_Wire.h +// Created: 14 April 2016 +// Author: Dmitry Bobylev + +#ifndef BuildPlugin_Wire_H_ +#define BuildPlugin_Wire_H_ + +#include "BuildPlugin.h" + +#include + +/// \class BuildPlugin_Wire +/// \ingroup Plugins +/// \brief Feature for creation of wire from sketch edges or existing wires. +class BuildPlugin_Wire: public ModelAPI_Feature +{ +public: + /// Use plugin manager for features creation + BuildPlugin_Wire(); + + /// Feature kind. + inline static const std::string& ID() + { + static const std::string MY_ID("Wire"); + 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_Wire::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(); + + /// Performs some functionality by action id. + /// \param[in] theAttributeId action key id. + /// \return false in case if action not perfomed. + BUILDPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId); + +private: + /// Action: Adds to the list of segments other segments of the sketcher connected to + /// the already selected ones to create a closed contour. + /// \return false in case if no countours have been added. + bool addContour(); +}; + +#endif diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt new file mode 100644 index 000000000..17e11055d --- /dev/null +++ b/src/BuildPlugin/CMakeLists.txt @@ -0,0 +1,48 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +INCLUDE(Common) +INCLUDE(UnitTest) + +INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/Config + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/GeomAPI + ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI +) + +SET(PROJECT_HEADERS + BuildPlugin.h + BuildPlugin_Plugin.h + BuildPlugin_Wire.h + BuildPlugin_Validators.h +) + +SET(PROJECT_SOURCES + BuildPlugin_Plugin.cpp + BuildPlugin_Wire.cpp + BuildPlugin_Validators.cpp +) + +SET(XML_RESOURCES + plugin-Build.xml + wire_widget.xml +) + +SET(PROJECT_LIBRARIES + Events + Config + ModelAPI + GeomAPI + GeomAlgoAPI +) + +ADD_DEFINITIONS(-DBUILDPLUGIN_EXPORTS) +ADD_LIBRARY(BuildPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES}) + +TARGET_LINK_LIBRARIES(BuildPlugin ${PROJECT_LIBRARIES}) + +INSTALL(TARGETS BuildPlugin DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES}) +INSTALL(FILES ${XML_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) +INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Build) + +# ADD_UNIT_TESTS() diff --git a/src/BuildPlugin/icons/feature_wire.png b/src/BuildPlugin/icons/feature_wire.png new file mode 100644 index 000000000..87b855649 Binary files /dev/null and b/src/BuildPlugin/icons/feature_wire.png differ diff --git a/src/BuildPlugin/plugin-Build.xml b/src/BuildPlugin/plugin-Build.xml new file mode 100644 index 000000000..f710019f0 --- /dev/null +++ b/src/BuildPlugin/plugin-Build.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/BuildPlugin/wire_widget.xml b/src/BuildPlugin/wire_widget.xml new file mode 100644 index 000000000..967ba23fb --- /dev/null +++ b/src/BuildPlugin/wire_widget.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/src/Config/plugins.xml.in b/src/Config/plugins.xml.in index 328bb5fff..a1d2354cb 100644 --- a/src/Config/plugins.xml.in +++ b/src/Config/plugins.xml.in @@ -6,6 +6,7 @@ + diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 0c8d1dfef..89429c4d1 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -26,7 +26,6 @@ SET(PROJECT_HEADERS FeaturesPlugin_RevolutionFuse.h FeaturesPlugin_ValidatorTransform.h FeaturesPlugin_Validators.h - FeaturesPlugin_Wire.h ) SET(PROJECT_SOURCES @@ -51,7 +50,6 @@ SET(PROJECT_SOURCES FeaturesPlugin_RevolutionFuse.cpp FeaturesPlugin_ValidatorTransform.cpp FeaturesPlugin_Validators.cpp - FeaturesPlugin_Wire.cpp ) SET(XML_RESOURCES @@ -70,7 +68,6 @@ SET(XML_RESOURCES placement_widget.xml intersection_widget.xml pipe_widget.xml - wire_widget.xml ) INCLUDE_DIRECTORIES( diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index b83fc3339..efb079e15 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include @@ -45,8 +44,6 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin() new FeaturesPlugin_ValidatorPipeLocations); aFactory->registerValidator("FeaturesPlugin_ValidatorCanBeEmpty", new FeaturesPlugin_ValidatorCanBeEmpty); - aFactory->registerValidator("FeaturesPlugin_ValidatorBaseForWire", - new FeaturesPlugin_ValidatorBaseForWire); // register this plugin ModelAPI_Session::get()->registerPlugin(this); @@ -82,9 +79,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID) return FeaturePtr(new FeaturesPlugin_RevolutionCut); } else if (theFeatureID == FeaturesPlugin_RevolutionFuse::ID()) { return FeaturePtr(new FeaturesPlugin_RevolutionFuse); - } else if (theFeatureID == FeaturesPlugin_Wire::ID()) { - return FeaturePtr(new FeaturesPlugin_Wire); } + // feature of such kind is not found return FeaturePtr(); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Wire.cpp b/src/FeaturesPlugin/FeaturesPlugin_Wire.cpp deleted file mode 100644 index c84f25c3b..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_Wire.cpp +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: FeaturesPlugin_Wire.cpp -// Created: 14 April 2016 -// Author: Dmitry Bobylev - -#include "FeaturesPlugin_Wire.h" - -#include -#include -#include - -#include - -#include -#include -#include - -#include -#include - -#include - -//================================================================================================= -FeaturesPlugin_Wire::FeaturesPlugin_Wire() -{ -} - -//================================================================================================= -void FeaturesPlugin_Wire::initAttributes() -{ - data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId()); -} - -//================================================================================================= -void FeaturesPlugin_Wire::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; - for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { - AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); - GeomShapePtr aShape = aSelection->value(); - if(!aShape.get()) { - setError("Error: Empty shape selected."); - return; - } - - if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) { - setError("Error: Selected shape has wrong type. Only edges and wires acceptable."); - return; - } - - aListOfShapes.push_back(aShape); - } - - // Create wire. - GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes); - if(!aWire.get()) { - setError("Error: Result wire empty. Probably it has disconnected edges or non-manifold."); - return; - } - - // Store result. - ResultBodyPtr aResultBody = document()->createBody(data()); - aResultBody->store(aWire); - setResult(aResultBody); -} - -//================================================================================================= -bool FeaturesPlugin_Wire::customAction(const std::string& theActionId) -{ - if(theActionId == "add_contour") { - return addContour(); - } else { - Events_Error::send("Error: Feature \"" + getKind() + "\" does not support action \"" + theActionId + "\"."); - } - - return false; -} - -//================================================================================================= -bool FeaturesPlugin_Wire::addContour() -{ - // Get base objects list. - AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); - if(aSelectionList->size() == 0) { - Events_Error::send("Error: Empty selection list."); - return false; - } - - // Collect attributes to check. - std::list anAttributesToCheck; - for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { - AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); - GeomShapePtr anEdgeInList = aSelection->value(); - if(!anEdgeInList.get()) { - continue; - } - - // Check that it is edge. - if(anEdgeInList->shapeType() != GeomAPI_Shape::EDGE) { - continue; - } - - // Check that it is edge on sketch. - ResultPtr aContext = aSelection->context(); - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); - if(!aConstruction.get()) { - continue; - } - GeomShapePtr aContextShape = aConstruction->shape(); - std::shared_ptr aPlanarEdges = std::dynamic_pointer_cast(aContextShape); - if(!aPlanarEdges.get()) { - continue; - } - - // Check that sketch have faces. - if(aConstruction->facesNum() == 0) { - continue; - } - - anAttributesToCheck.push_back(aSelection); - } - - // Check if edges have contours. - ListOfShape anAddedEdges; - bool isAnyContourFound = false; - for(std::list::const_iterator aListIt = anAttributesToCheck.cbegin(); - aListIt != anAttributesToCheck.cend(); - ++aListIt) { - AttributeSelectionPtr aSelection = *aListIt; - std::shared_ptr anEdgeInList(new GeomAPI_Edge(aSelection->value())); - - ListOfShape::const_iterator anEdgesIt = anAddedEdges.cbegin(); - for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) { - if(anEdgeInList->isEqual(*anEdgesIt)) { - break; - } - } - if(anEdgesIt != anAddedEdges.cend()) { - // This edge is already in list. - continue; - } - - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSelection->context()); - std::shared_ptr aPlanarEdges = std::dynamic_pointer_cast(aConstruction->shape()); - - // Iterate on faces and add face with this edge. - std::shared_ptr aFoundFace; - for(int anIndex = 0; anIndex < aConstruction->facesNum(); ++anIndex) { - std::shared_ptr aFace = aConstruction->face(anIndex); - for(GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { - std::shared_ptr anEdgeOnFace(new GeomAPI_Edge(anExp.current())); - if(anEdgeInList->isEqual(anEdgeOnFace)) { - aFoundFace = aFace; - break; - } - } - - if(aFoundFace.get()) { - break; - } - } - - // If face with the same edge found. Add all other edges to list. - if(aFoundFace.get()) { - isAnyContourFound = true; - anAddedEdges.push_back(anEdgeInList); - for(GeomAPI_ShapeExplorer anExp(aFoundFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) { - std::shared_ptr anEdgeOnFace(new GeomAPI_Edge(anExp.current())); - anEdgesIt = anAddedEdges.cbegin(); - for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) { - if(anEdgeOnFace->isEqual(*anEdgesIt)) { - break; - } - } - if(anEdgesIt == anAddedEdges.cend()) { - anAddedEdges.push_back(anEdgeOnFace); - aSelectionList->append(aConstruction, anEdgeOnFace); - } - } - } - } - - if(!isAnyContourFound) { - Events_Error::send("Error: Contours already closed or no contours found for selected edges."); - return false; - } - - return true; -} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Wire.h b/src/FeaturesPlugin/FeaturesPlugin_Wire.h deleted file mode 100644 index c456d1d00..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_Wire.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: FeaturesPlugin_Wire.h -// Created: 14 April 2016 -// Author: Dmitry Bobylev - -#ifndef FeaturesPlugin_Wire_H_ -#define FeaturesPlugin_Wire_H_ - -#include "FeaturesPlugin.h" - -#include - -/// \class FeaturesPlugin_Wire -/// \ingroup Plugins -/// \brief Feature for creation of wire from sketch edges or existing wires. -class FeaturesPlugin_Wire: public ModelAPI_Feature -{ -public: - /// Use plugin manager for features creation - FeaturesPlugin_Wire(); - - /// Feature kind. - inline static const std::string& ID() - { - static const std::string MY_ID("Wire"); - 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. - FEATURESPLUGIN_EXPORT virtual const std::string& getKind() - { - static std::string MY_KIND = FeaturesPlugin_Wire::ID(); - return MY_KIND; - } - - /// Request for initialization of data model of the feature: adding all attributes. - FEATURESPLUGIN_EXPORT virtual void initAttributes(); - - /// Creates a new part document if needed. - FEATURESPLUGIN_EXPORT virtual void execute(); - - /// Performs some functionality by action id. - /// \param[in] theAttributeId action key id. - /// \return false in case if action not perfomed. - FEATURESPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId); - -private: - /// Action: Adds to the list of segments other segments of the sketcher connected to - /// the already selected ones to create a closed contour. - /// \return false in case if no countours have been added. - bool addContour(); -}; - -#endif diff --git a/src/FeaturesPlugin/icons/feature_wire.png b/src/FeaturesPlugin/icons/feature_wire.png deleted file mode 100644 index 87b855649..000000000 Binary files a/src/FeaturesPlugin/icons/feature_wire.png and /dev/null differ diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index a6e7f8bd1..411397b8f 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -2,11 +2,6 @@ - - - - - diff --git a/src/FeaturesPlugin/wire_widget.xml b/src/FeaturesPlugin/wire_widget.xml deleted file mode 100644 index 2b49cb9d8..000000000 --- a/src/FeaturesPlugin/wire_widget.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - -