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)
--- /dev/null
+// 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
--- /dev/null
+// 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 <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <BuildPlugin_Wire.h>
+#include <BuildPlugin_Validators.h>
+
+// 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();
+}
--- /dev/null
+// 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 <ModelAPI_Plugin.h>
+#include <ModelAPI_Feature.h>
+
+/// \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
--- /dev/null
+// 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 <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <GeomAPI_PlanarEdges.h>
+
+#include <GeomAlgoAPI_WireBuilder.h>
+
+#include <Events_Error.h>
+
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& 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<ModelAPI_AttributeSelectionList>(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<ModelAPI_ResultConstruction>(aContext);
+ if(aConstruction.get()) {
+ if(aConstruction->isInfinite()) {
+ theError = "Inifinte objects not acceptable.";
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(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
--- /dev/null
+// 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 <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_FeatureValidator.h>
+
+/// \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<std::string>& theArguments,
+ std::string& theError) const;
+};
+
+#endif
--- /dev/null
+// 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 <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <Events_Error.h>
+
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_ShapeExplorer.h>
+
+#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_WireBuilder.h>
+
+#include <algorithm>
+
+//=================================================================================================
+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<AttributeSelectionPtr> 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<ModelAPI_ResultConstruction>(aContext);
+ if(!aConstruction.get()) {
+ continue;
+ }
+ GeomShapePtr aContextShape = aConstruction->shape();
+ std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(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<AttributeSelectionPtr>::const_iterator aListIt = anAttributesToCheck.cbegin();
+ aListIt != anAttributesToCheck.cend();
+ ++aListIt) {
+ AttributeSelectionPtr aSelection = *aListIt;
+ std::shared_ptr<GeomAPI_Edge> 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<ModelAPI_ResultConstruction>(aSelection->context());
+ std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aConstruction->shape());
+
+ // Iterate on faces and add face with this edge.
+ std::shared_ptr<GeomAPI_Face> aFoundFace;
+ for(int anIndex = 0; anIndex < aConstruction->facesNum(); ++anIndex) {
+ std::shared_ptr<GeomAPI_Face> aFace = aConstruction->face(anIndex);
+ for(GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+ std::shared_ptr<GeomAPI_Edge> 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<GeomAPI_Edge> 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;
+}
--- /dev/null
+// 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 <ModelAPI_Feature.h>
+
+/// \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
--- /dev/null
+## 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()
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<plugin>
+ <workbench id="Build" document="Part">
+ <group id="Shape">
+ <feature id="Wire" title="Wire" tooltip ="Create a wire from sketch edges and wires objects" icon="icons/Build/feature_wire.png">
+ <source path="wire_widget.xml"/>
+ </feature>
+ </group>
+ </workbench>
+</plugin>
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <multi_selector id="base_objects"
+ label="Segments and wires:"
+ tooltip="Select an edges on sketch or wires objects."
+ type_choice="edges objects">
+ <validator id="BuildPlugin_ValidatorBaseForWire"/>
+ </multi_selector>
+ <action id="add_contour"
+ label="Add contour"
+ tooltip="Adds to the list of segments other segments of the sketcher
+ connected to the already selected ones to create a closed contour."/>
+</source>
<plugin library="PartSetPlugin" configuration="plugin-PartSet.xml"/>
<plugin library="SketchPlugin" configuration="plugin-Sketch.xml"/>
<plugin library="ConstructionPlugin" configuration="plugin-Construction.xml"/>
+ <plugin library="BuildPlugin" configuration="plugin-Build.xml"/>
<plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
<plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
<plugin script="addons_Features" configuration="addons_Features.xml"/>
FeaturesPlugin_RevolutionFuse.h
FeaturesPlugin_ValidatorTransform.h
FeaturesPlugin_Validators.h
- FeaturesPlugin_Wire.h
)
SET(PROJECT_SOURCES
FeaturesPlugin_RevolutionFuse.cpp
FeaturesPlugin_ValidatorTransform.cpp
FeaturesPlugin_Validators.cpp
- FeaturesPlugin_Wire.cpp
)
SET(XML_RESOURCES
placement_widget.xml
intersection_widget.xml
pipe_widget.xml
- wire_widget.xml
)
INCLUDE_DIRECTORIES(
#include <FeaturesPlugin_Rotation.h>
#include <FeaturesPlugin_ValidatorTransform.h>
#include <FeaturesPlugin_Validators.h>
-#include <FeaturesPlugin_Wire.h>
#include <ModelAPI_Session.h>
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);
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();
}
+++ /dev/null
-// 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 <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultConstruction.h>
-
-#include <Events_Error.h>
-
-#include <GeomAPI_DataMapOfShapeShape.h>
-#include <GeomAPI_PlanarEdges.h>
-#include <GeomAPI_ShapeExplorer.h>
-
-#include <GeomAlgoAPI_ShapeTools.h>
-#include <GeomAlgoAPI_WireBuilder.h>
-
-#include <algorithm>
-
-//=================================================================================================
-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<AttributeSelectionPtr> 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<ModelAPI_ResultConstruction>(aContext);
- if(!aConstruction.get()) {
- continue;
- }
- GeomShapePtr aContextShape = aConstruction->shape();
- std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(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<AttributeSelectionPtr>::const_iterator aListIt = anAttributesToCheck.cbegin();
- aListIt != anAttributesToCheck.cend();
- ++aListIt) {
- AttributeSelectionPtr aSelection = *aListIt;
- std::shared_ptr<GeomAPI_Edge> 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<ModelAPI_ResultConstruction>(aSelection->context());
- std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aConstruction->shape());
-
- // Iterate on faces and add face with this edge.
- std::shared_ptr<GeomAPI_Face> aFoundFace;
- for(int anIndex = 0; anIndex < aConstruction->facesNum(); ++anIndex) {
- std::shared_ptr<GeomAPI_Face> aFace = aConstruction->face(anIndex);
- for(GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
- std::shared_ptr<GeomAPI_Edge> 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<GeomAPI_Edge> 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;
-}
+++ /dev/null
-// 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 <ModelAPI_Feature.h>
-
-/// \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
<plugin>
<workbench id="Features" document="Part">
- <group id="Shape">
- <feature id="Wire" title="Wire" tooltip ="Create a wire from sketch edges and wires objects" icon="icons/Features/feature_wire.png">
- <source path="wire_widget.xml"/>
- </feature>
- </group>
<group id="Extrusion">
<feature id="Extrusion" title="Extrusion" tooltip="Create a solid by extrusion of a face" icon="icons/Features/extrusion.png">
<source path="extrusion_widget.xml"/>
+++ /dev/null
-<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-<source>
- <multi_selector id="base_objects"
- label="Segments and wires:"
- tooltip="Select an edges on sketch or wires objects."
- type_choice="edges objects">
- <validator id="FeaturesPlugin_ValidatorBaseForWire"/>
- </multi_selector>
- <action id="add_contour"
- label="Add contour"
- tooltip="Adds to the list of segments other segments of the sketcher
- connected to the already selected ones to create a closed contour."/>
-</source>