]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1369: Added feature "Create Vertex"
authordbv <dbv@opencascade.com>
Mon, 18 Apr 2016 15:46:11 +0000 (18:46 +0300)
committerdbv <dbv@opencascade.com>
Mon, 18 Apr 2016 15:46:11 +0000 (18:46 +0300)
src/BuildPlugin/BuildPlugin_Plugin.cpp
src/BuildPlugin/BuildPlugin_Validators.cpp
src/BuildPlugin/BuildPlugin_Validators.h
src/BuildPlugin/BuildPlugin_Vertex.cpp [new file with mode: 0644]
src/BuildPlugin/BuildPlugin_Vertex.h [new file with mode: 0644]
src/BuildPlugin/CMakeLists.txt
src/BuildPlugin/icons/feature_vertex.png [new file with mode: 0644]
src/BuildPlugin/plugin-Build.xml
src/BuildPlugin/vertex_widget.xml [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp

index 5cd553df67f4a12b7bd4c91fca1e9e9b8aeac14b..5df9e579a446021a1e087669c669029bc1eb6df1 100644 (file)
@@ -9,6 +9,7 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <BuildPlugin_Vertex.h>
 #include <BuildPlugin_Wire.h>
 #include <BuildPlugin_Validators.h>
 
@@ -21,6 +22,8 @@ BuildPlugin_Plugin::BuildPlugin_Plugin()
   // Register validators.
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  aFactory->registerValidator("BuildPlugin_ValidatorBaseForVertex",
+                              new BuildPlugin_ValidatorBaseForVertex());
   aFactory->registerValidator("BuildPlugin_ValidatorBaseForWire",
                               new BuildPlugin_ValidatorBaseForWire());
 
@@ -31,7 +34,9 @@ BuildPlugin_Plugin::BuildPlugin_Plugin()
 //=================================================================================================
 FeaturePtr BuildPlugin_Plugin::createFeature(std::string theFeatureID)
 {
-  if (theFeatureID == BuildPlugin_Wire::ID()) {
+  if(theFeatureID == BuildPlugin_Vertex::ID()) {
+    return FeaturePtr(new BuildPlugin_Vertex());
+  } else if(theFeatureID == BuildPlugin_Wire::ID()) {
     return FeaturePtr(new BuildPlugin_Wire());
   }
 
index 0bd58859c2be7baf3a4870511581c585ad2b6555..285a03121fd95bf21083bd9eb36832b8b51f7a82 100644 (file)
 
 #include <Events_Error.h>
 
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForVertex::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.
+  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::VERTEX) {
+      theError = "Selected shape has wrong type. Only vertices acceptable.";
+      return false;
+    }
+
+    // Check that it is vertex 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;
+        }
+      }
+    }
+  }
+
+  return true;
+}
+
 //=================================================================================================
 bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
                                                const std::list<std::string>& theArguments,
@@ -97,4 +171,4 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
   }
 
   return true;
-}
\ No newline at end of file
+}
index 5156ae6c6ef7f8f6fe145dd71d48966dc05c6b5d..eb698b21ad9e50b8fcfed386c7387ea260426c67 100644 (file)
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_FeatureValidator.h>
 
+/// \class BuildPlugin_ValidatorBaseForVertex
+/// \ingroup Validators
+/// \brief A validator for selection base shapes for vertex. Allows to select vertices on sketch and
+/// vertex objects.
+class BuildPlugin_ValidatorBaseForVertex: 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;
+};
+
 /// \class BuildPlugin_ValidatorBaseForWire
 /// \ingroup Validators
 /// \brief A validator for selection base shapes for wire. Allows to select edges on sketch and
diff --git a/src/BuildPlugin/BuildPlugin_Vertex.cpp b/src/BuildPlugin/BuildPlugin_Vertex.cpp
new file mode 100644 (file)
index 0000000..a1bd7cc
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        BuildPlugin_Vertex.cpp
+// Created:     18 April 2016
+// Author:      Dmitry Bobylev
+
+#include "BuildPlugin_Vertex.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_Vertex::BuildPlugin_Vertex()
+{
+}
+
+//=================================================================================================
+void BuildPlugin_Vertex::initAttributes()
+{
+  data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
+}
+
+//=================================================================================================
+void BuildPlugin_Vertex::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::VERTEX) {
+      setError("Error: Selected shape has wrong type. Only vertices 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_Vertex.h b/src/BuildPlugin/BuildPlugin_Vertex.h
new file mode 100644 (file)
index 0000000..082b90e
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        BuildPlugin_Vertex.h
+// Created:     18 April 2016
+// Author:      Dmitry Bobylev
+
+#ifndef BuildPlugin_Vertex_H_
+#define BuildPlugin_Vertex_H_
+
+#include "BuildPlugin.h"
+
+#include <ModelAPI_Feature.h>
+
+/// \class BuildPlugin_Vertex
+/// \ingroup Plugins
+/// \brief Feature for creation of vertex from sketch vertex or existing vertices.
+class BuildPlugin_Vertex: public ModelAPI_Feature
+{
+public:
+  /// Use plugin manager for features creation
+  BuildPlugin_Vertex();
+
+  /// Feature kind.
+  inline static const std::string& ID()
+  {
+    static const std::string MY_ID("Vertex");
+    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_Vertex::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 17e11055dc4a8a4d7e28897f87739da041a243b3..7a49953a1bfc59cd7528cd35abc41bea3e192732 100644 (file)
@@ -13,18 +13,21 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
 SET(PROJECT_HEADERS
     BuildPlugin.h
     BuildPlugin_Plugin.h
+    BuildPlugin_Vertex.h
     BuildPlugin_Wire.h
     BuildPlugin_Validators.h
 )
 
 SET(PROJECT_SOURCES
     BuildPlugin_Plugin.cpp
+    BuildPlugin_Vertex.cpp
     BuildPlugin_Wire.cpp
     BuildPlugin_Validators.cpp
 )
 
 SET(XML_RESOURCES
     plugin-Build.xml
+    vertex_widget.xml
     wire_widget.xml
 )
 
diff --git a/src/BuildPlugin/icons/feature_vertex.png b/src/BuildPlugin/icons/feature_vertex.png
new file mode 100644 (file)
index 0000000..6795c4c
Binary files /dev/null and b/src/BuildPlugin/icons/feature_vertex.png differ
index f710019f01c0ea11d8720d6c91fdc21f2dae834e..0fc10c8899092b161f4ef871bc327b81726b06d4 100644 (file)
@@ -3,6 +3,9 @@
 <plugin>
   <workbench id="Build" document="Part">
     <group id="Shape">
+      <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="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>
diff --git a/src/BuildPlugin/vertex_widget.xml b/src/BuildPlugin/vertex_widget.xml
new file mode 100644 (file)
index 0000000..04d0603
--- /dev/null
@@ -0,0 +1,10 @@
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+  <multi_selector id="base_objects"
+                  label="Vertices:"
+                  tooltip="Select a vertices on sketch or vertex objects."
+                  type_choice="vertex objects">
+    <validator id="BuildPlugin_ValidatorBaseForVertex"/>
+  </multi_selector>
+</source>
index 9afdafd181a9ea9b4a9c4efd88716722d0d5009a..3458bb7e88fd581bcc526ee013be27fccaa8bacb 100644 (file)
@@ -148,6 +148,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute
           return true;
         }
       }
+
+      return false;
     }
 
     if(!aShape->isEqual(aContextShape)) {