--- /dev/null
+// 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 <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_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);
+}
--- /dev/null
+// 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 <ModelAPI_Feature.h>
+
+/// \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
#include <ModelAPI_Validator.h>
#include <BuildPlugin_Vertex.h>
+#include <BuildPlugin_Edge.h>
#include <BuildPlugin_Wire.h>
#include <BuildPlugin_Validators.h>
{
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());
}
}
std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(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;
BuildPlugin.h
BuildPlugin_Plugin.h
BuildPlugin_Vertex.h
+ BuildPlugin_Edge.h
BuildPlugin_Wire.h
BuildPlugin_Validators.h
)
SET(PROJECT_SOURCES
BuildPlugin_Plugin.cpp
BuildPlugin_Vertex.cpp
+ BuildPlugin_Edge.cpp
BuildPlugin_Wire.cpp
BuildPlugin_Validators.cpp
)
SET(XML_RESOURCES
plugin-Build.xml
vertex_widget.xml
+ edge_widget.xml
wire_widget.xml
)
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <multi_selector id="base_objects"
+ label="Edges:"
+ tooltip="Select an edges on sketch or edge objects."
+ type_choice="edges objects">
+ <validator id="BuildPlugin_ValidatorBaseForBuild" parameters="edge"/>
+ </multi_selector>
+</source>
<feature id="Vertex" title="Vertex" tooltip ="Create a vertex from sketch vertex and vertex objects" icon="icons/Build/feature_vertex.png">
<source path="vertex_widget.xml"/>
</feature>
+ <feature id="Edge" title="Edge" tooltip ="Create an edge from sketch edges and edge objects" icon="icons/Build/feature_edge.png">
+ <source path="edge_widget.xml"/>
+ </feature>
<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>