From fc5fd86df3813fdb122301b3599e7e7a79e967e8 Mon Sep 17 00:00:00 2001 From: dbv Date: Mon, 18 Apr 2016 15:57:20 +0300 Subject: [PATCH] Issue #1369: moved Wire feature to new Build plug-in. --- CMakeLists.txt | 1 + src/BuildPlugin/BuildPlugin.h | 24 +++++ src/BuildPlugin/BuildPlugin_Plugin.cpp | 40 +++++++ src/BuildPlugin/BuildPlugin_Plugin.h | 28 +++++ src/BuildPlugin/BuildPlugin_Validators.cpp | 100 ++++++++++++++++++ src/BuildPlugin/BuildPlugin_Validators.h | 29 +++++ .../BuildPlugin_Wire.cpp} | 14 +-- .../BuildPlugin_Wire.h} | 24 ++--- src/BuildPlugin/CMakeLists.txt | 48 +++++++++ .../icons/feature_wire.png | Bin src/BuildPlugin/plugin-Build.xml | 11 ++ .../wire_widget.xml | 2 +- src/Config/plugins.xml.in | 1 + src/FeaturesPlugin/CMakeLists.txt | 3 - src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 6 +- src/FeaturesPlugin/plugin-Features.xml | 5 - 16 files changed, 303 insertions(+), 33 deletions(-) create mode 100644 src/BuildPlugin/BuildPlugin.h create mode 100644 src/BuildPlugin/BuildPlugin_Plugin.cpp create mode 100644 src/BuildPlugin/BuildPlugin_Plugin.h create mode 100644 src/BuildPlugin/BuildPlugin_Validators.cpp create mode 100644 src/BuildPlugin/BuildPlugin_Validators.h rename src/{FeaturesPlugin/FeaturesPlugin_Wire.cpp => BuildPlugin/BuildPlugin_Wire.cpp} (95%) rename src/{FeaturesPlugin/FeaturesPlugin_Wire.h => BuildPlugin/BuildPlugin_Wire.h} (69%) create mode 100644 src/BuildPlugin/CMakeLists.txt rename src/{FeaturesPlugin => BuildPlugin}/icons/feature_wire.png (100%) create mode 100644 src/BuildPlugin/plugin-Build.xml rename src/{FeaturesPlugin => BuildPlugin}/wire_widget.xml (89%) 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/FeaturesPlugin/FeaturesPlugin_Wire.cpp b/src/BuildPlugin/BuildPlugin_Wire.cpp similarity index 95% rename from src/FeaturesPlugin/FeaturesPlugin_Wire.cpp rename to src/BuildPlugin/BuildPlugin_Wire.cpp index c84f25c3b..a66975f98 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Wire.cpp +++ b/src/BuildPlugin/BuildPlugin_Wire.cpp @@ -1,10 +1,10 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// File: FeaturesPlugin_Wire.cpp +// File: BuildPlugin_Wire.cpp // Created: 14 April 2016 // Author: Dmitry Bobylev -#include "FeaturesPlugin_Wire.h" +#include "BuildPlugin_Wire.h" #include #include @@ -22,18 +22,18 @@ #include //================================================================================================= -FeaturesPlugin_Wire::FeaturesPlugin_Wire() +BuildPlugin_Wire::BuildPlugin_Wire() { } //================================================================================================= -void FeaturesPlugin_Wire::initAttributes() +void BuildPlugin_Wire::initAttributes() { data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId()); } //================================================================================================= -void FeaturesPlugin_Wire::execute() +void BuildPlugin_Wire::execute() { // Get base objects list. AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); @@ -78,7 +78,7 @@ void FeaturesPlugin_Wire::execute() } //================================================================================================= -bool FeaturesPlugin_Wire::customAction(const std::string& theActionId) +bool BuildPlugin_Wire::customAction(const std::string& theActionId) { if(theActionId == "add_contour") { return addContour(); @@ -90,7 +90,7 @@ bool FeaturesPlugin_Wire::customAction(const std::string& theActionId) } //================================================================================================= -bool FeaturesPlugin_Wire::addContour() +bool BuildPlugin_Wire::addContour() { // Get base objects list. AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Wire.h b/src/BuildPlugin/BuildPlugin_Wire.h similarity index 69% rename from src/FeaturesPlugin/FeaturesPlugin_Wire.h rename to src/BuildPlugin/BuildPlugin_Wire.h index c456d1d00..39128be6b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Wire.h +++ b/src/BuildPlugin/BuildPlugin_Wire.h @@ -1,24 +1,24 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// File: FeaturesPlugin_Wire.h +// File: BuildPlugin_Wire.h // Created: 14 April 2016 // Author: Dmitry Bobylev -#ifndef FeaturesPlugin_Wire_H_ -#define FeaturesPlugin_Wire_H_ +#ifndef BuildPlugin_Wire_H_ +#define BuildPlugin_Wire_H_ -#include "FeaturesPlugin.h" +#include "BuildPlugin.h" #include -/// \class FeaturesPlugin_Wire +/// \class BuildPlugin_Wire /// \ingroup Plugins /// \brief Feature for creation of wire from sketch edges or existing wires. -class FeaturesPlugin_Wire: public ModelAPI_Feature +class BuildPlugin_Wire: public ModelAPI_Feature { public: /// Use plugin manager for features creation - FeaturesPlugin_Wire(); + BuildPlugin_Wire(); /// Feature kind. inline static const std::string& ID() @@ -35,22 +35,22 @@ public: } /// \return the kind of a feature. - FEATURESPLUGIN_EXPORT virtual const std::string& getKind() + BUILDPLUGIN_EXPORT virtual const std::string& getKind() { - static std::string MY_KIND = FeaturesPlugin_Wire::ID(); + static std::string MY_KIND = BuildPlugin_Wire::ID(); return MY_KIND; } /// Request for initialization of data model of the feature: adding all attributes. - FEATURESPLUGIN_EXPORT virtual void initAttributes(); + BUILDPLUGIN_EXPORT virtual void initAttributes(); /// Creates a new part document if needed. - FEATURESPLUGIN_EXPORT virtual void execute(); + 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. - FEATURESPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId); + BUILDPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId); private: /// Action: Adds to the list of segments other segments of the sketcher connected to 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/FeaturesPlugin/icons/feature_wire.png b/src/BuildPlugin/icons/feature_wire.png similarity index 100% rename from src/FeaturesPlugin/icons/feature_wire.png rename to src/BuildPlugin/icons/feature_wire.png 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/FeaturesPlugin/wire_widget.xml b/src/BuildPlugin/wire_widget.xml similarity index 89% rename from src/FeaturesPlugin/wire_widget.xml rename to src/BuildPlugin/wire_widget.xml index 2b49cb9d8..967ba23fb 100644 --- a/src/FeaturesPlugin/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"> - + + 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/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 @@ - - - - - -- 2.39.2