]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1369: Feature "Edge" for Build plug-in
authordbv <dbv@opencascade.com>
Tue, 19 Apr 2016 13:41:52 +0000 (16:41 +0300)
committerdbv <dbv@opencascade.com>
Tue, 19 Apr 2016 13:42:10 +0000 (16:42 +0300)
src/BuildPlugin/BuildPlugin_Edge.cpp [new file with mode: 0644]
src/BuildPlugin/BuildPlugin_Edge.h [new file with mode: 0644]
src/BuildPlugin/BuildPlugin_Plugin.cpp
src/BuildPlugin/BuildPlugin_Validators.cpp
src/BuildPlugin/CMakeLists.txt
src/BuildPlugin/edge_widget.xml [new file with mode: 0644]
src/BuildPlugin/icons/feature_edge.png [new file with mode: 0644]
src/BuildPlugin/plugin-Build.xml

diff --git a/src/BuildPlugin/BuildPlugin_Edge.cpp b/src/BuildPlugin/BuildPlugin_Edge.cpp
new file mode 100644 (file)
index 0000000..0ae8acc
--- /dev/null
@@ -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 <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);
+}
diff --git a/src/BuildPlugin/BuildPlugin_Edge.h b/src/BuildPlugin/BuildPlugin_Edge.h
new file mode 100644 (file)
index 0000000..bbe3467
--- /dev/null
@@ -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 <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
index 3433f3b9e0bc5d09fe53b3d93b02a64ea3f1ac3d..f26c60ace00e00d3d24de00aba2f28927b3d2984 100644 (file)
@@ -10,6 +10,7 @@
 #include <ModelAPI_Validator.h>
 
 #include <BuildPlugin_Vertex.h>
+#include <BuildPlugin_Edge.h>
 #include <BuildPlugin_Wire.h>
 #include <BuildPlugin_Validators.h>
 
@@ -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());
   }
index 7706fe77a589f60f1748500304e6fdb5f3ec69f7..9aa7c8acd4e975622447c9a5b819ed41727472df 100644 (file)
@@ -76,17 +76,17 @@ bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute
       }
 
       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;
index 39e728f775623ea7ea72c2e1d37f52bace3b3c85..3c159e8d600399c8e6932fe6732e63f22e378ee3 100644 (file)
@@ -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 (file)
index 0000000..e02f272
--- /dev/null
@@ -0,0 +1,10 @@
+<!-- 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>
diff --git a/src/BuildPlugin/icons/feature_edge.png b/src/BuildPlugin/icons/feature_edge.png
new file mode 100644 (file)
index 0000000..4970612
Binary files /dev/null and b/src/BuildPlugin/icons/feature_edge.png differ
index 0fc10c8899092b161f4ef871bc327b81726b06d4..0c2161f68ae8041b6bcb0fb401efbf05d309e677 100644 (file)
@@ -6,6 +6,9 @@
       <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>