]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge remote-tracking branch 'origin/ngo/Lot5'
authormpv <mpv@opencascade.com>
Wed, 2 Oct 2019 10:04:46 +0000 (13:04 +0300)
committermpv <mpv@opencascade.com>
Wed, 2 Oct 2019 10:04:46 +0000 (13:04 +0300)
22 files changed:
src/ModelHighAPI/ModelHighAPI_Folder.cpp
src/ModelHighAPI/ModelHighAPI_Folder.h
src/PythonAPI/model/services/__init__.py
src/PythonAddons/CMakeLists.txt
src/PythonAddons/addons_Features.py
src/PythonAddons/addons_Features.xml.in
src/PythonAddons/doc/addons_Features.rst
src/PythonAddons/doc/compoundVerticesFeature.rst [new file with mode: 0644]
src/PythonAddons/doc/images/compound.png [new file with mode: 0644]
src/PythonAddons/doc/images/compoundVertices.png [new file with mode: 0644]
src/PythonAddons/doc/images/compoundVerticesPanel.png [new file with mode: 0644]
src/PythonAddons/doc/images/importParameters.png [new file with mode: 0644]
src/PythonAddons/doc/images/importParametersPanel.png [new file with mode: 0644]
src/PythonAddons/doc/importParametersFeature.rst [new file with mode: 0644]
src/PythonAddons/macros/compoundVertices/__init__.py [new file with mode: 0644]
src/PythonAddons/macros/compoundVertices/feature.py [new file with mode: 0644]
src/PythonAddons/macros/compoundVertices/icons/import.png [new file with mode: 0644]
src/PythonAddons/macros/compoundVertices/widget.xml [new file with mode: 0644]
src/PythonAddons/macros/importParameters/__init__.py [new file with mode: 0644]
src/PythonAddons/macros/importParameters/feature.py [new file with mode: 0644]
src/PythonAddons/macros/importParameters/icons/parameters.png [new file with mode: 0644]
src/PythonAddons/macros/importParameters/widget.xml [new file with mode: 0644]

index 3640677a3a0b12de0009c615a7e44f95c51acd0a..b47d4b48de92e3235940c80389119d77aea5c0cc 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_Events.h>
 
 //--------------------------------------------------------------------------------------
 
@@ -109,5 +110,13 @@ std::shared_ptr<ModelHighAPI_Folder> addFolder(const std::shared_ptr<ModelAPI_Do
   AttributeReferencePtr aLastFeatAttr = aFolder->reference(ModelAPI_Folder::LAST_FEATURE_ID());
   fillAttribute(theLastFeature.feature(), aLastFeatAttr);
 
+  // to update the folder state in the Object Browser
+  theDoc->updateHistory(ModelAPI_Feature::group());
+
   return std::shared_ptr<ModelHighAPI_Folder>(new ModelHighAPI_Folder(aFolder));
 }
+
+void removeFolder(std::shared_ptr<ModelHighAPI_Folder>& theFolder)
+{
+  theFolder->folder()->document()->removeFolder(theFolder->folder());
+}
index 66fe99b3c9c95676f903819dcee2c91a4113aa10..2f99aabf82d865f95c571897f3a24e5c9a705aaa 100644 (file)
@@ -46,6 +46,7 @@ public:
 
   static std::string ID() { return ModelAPI_Folder::ID(); }
   virtual std::string getID() { return ID(); }
+  const std::shared_ptr<ModelAPI_Folder>& folder() const {return myFolder;}
 
   /// First feature reference
   std::shared_ptr<ModelAPI_AttributeReference> firstFeature() const
@@ -63,6 +64,11 @@ public:
   MODELHIGHAPI_EXPORT
   std::string name() const;
 
+  /// To update the folder state
+  /// \param isForce start execution of feature instead of sending events
+  //MODELHIGHAPI_EXPORT void execute();
+
+
   /// Dump wrapped feature
   MODELHIGHAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 
@@ -90,5 +96,10 @@ MODELHIGHAPI_EXPORT
 std::shared_ptr<ModelHighAPI_Folder> addFolder(const std::shared_ptr<ModelAPI_Document>& theDoc,
                                                const ModelHighAPI_Reference& theFirstFeature,
                                                const ModelHighAPI_Reference& theLastFeature);
+/**\ingroup CPPHighAPI
+* \brief Removes Folder feature
+*/
+MODELHIGHAPI_EXPORT
+void removeFolder(std::shared_ptr<ModelHighAPI_Folder>& theFolder);
 //--------------------------------------------------------------------------------------
 #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_FOLDER_H_ */
index 74336295962a41229c49f67cea7f8897398c6b6d..d585c1891f9f763f7c72b283abf3af3268d7c1f0 100644 (file)
@@ -26,6 +26,6 @@ from ModelHighAPI import apply as do
 from ModelHighAPI import updateFeatures
 from ModelHighAPI import undo, redo
 from ModelHighAPI import reset
-from ModelHighAPI import addFolder
+from ModelHighAPI import addFolder, removeFolder
 from ModelHighAPI import ModelHighAPI_Selection as selection
 from ModelHighAPI import checkPythonDump as checkPythonDump
index 4dad90f28d3c1816f5045b49ca784f04f81b969b..3597646b33b5cb3fb38ef45c28f7f999b5c27907 100644 (file)
@@ -39,6 +39,8 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/addons_Features.xml DESTINATION ${SHAP
 INSTALL(FILES __init__.py DESTINATION ${SHAPER_INSTALL_ADDONS})
 INSTALL(DIRECTORY macros DESTINATION ${SHAPER_INSTALL_ADDONS})
 INSTALL(DIRECTORY macros/rectangle/icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
+INSTALL(DIRECTORY macros/compoundVertices/icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
+INSTALL(DIRECTORY macros/importParameters/icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Addons)
 INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
 
 INCLUDE(UnitTest)
index d28db61ab6a461154707c619d61ac6819bf3d976..bdafa15175d1ee117315bd3e8a4c34e96da22fd6 100644 (file)
@@ -22,6 +22,8 @@
 
 import ModelAPI
 from macros.rectangle.feature import SketchPlugin_Rectangle
+from macros.compoundVertices.feature import compoundVertices
+from macros.importParameters.feature import importParameters
 
 
 class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin):
@@ -43,7 +45,10 @@ class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin):
 
         if theFeatureID == SketchPlugin_Rectangle.ID():
             aFeature = SketchPlugin_Rectangle().__disown__()
-
+        elif theFeatureID == compoundVertices.ID():
+            aFeature = compoundVertices().__disown__()
+        elif theFeatureID == importParameters.ID():
+            aFeature = importParameters().__disown__()
         else:
             raise Exception("No such feature %s" % theFeatureID)
 
index f0190ba6293862a1e5b75a7a4ecc628fcc3a7dcb..3f3b7666d7f1b41f33820f09202eaf5ddc8597c1 100644 (file)
@@ -1,3 +1,5 @@
 <plugin>
   <source path="@ADDONS_FOLDER_PATH@/macros/rectangle/widget.xml"/>
+  <source path="@ADDONS_FOLDER_PATH@/macros/compoundVertices/widget.xml"/>
+  <source path="@ADDONS_FOLDER_PATH@/macros/importParameters/widget.xml"/>
 </plugin>
index 85346ff09ca301c27ba3e87e2bc6de5e374f8cb3..1db6329d641b948d2c99f16223f01903ea839a8c 100644 (file)
@@ -13,10 +13,12 @@ A feature description includes 4 files:
 - feature.py with python commands, 
 - icon.png with image of button in the toolbar (the file is located at sub-folder /icons).
 
-An example of already created custom features is:
+Some examples of already created custom features are:
 
 .. toctree::
    :titlesonly:
    :maxdepth: 1
 
    rectangleFeature.rst
+   compoundVerticesFeature.rst
+   importParametersFeature.rst
diff --git a/src/PythonAddons/doc/compoundVerticesFeature.rst b/src/PythonAddons/doc/compoundVerticesFeature.rst
new file mode 100644 (file)
index 0000000..00cc89a
--- /dev/null
@@ -0,0 +1,39 @@
+.. _create_compound_Vertices:
+.. |compoundVertices.icon|    image:: images/compound.png
+
+compound Vertices
+=================
+
+Compound Vertices is a feature and can be edited after execution.
+It allows creation of several points basing on XYZ coords file.
+
+.. warning::
+  Please note that it is better to limit yourself to create a maximum of 100 points.
+
+These set of points will be grouped in a compound and can be used for others features. 
+
+To add a new set of points:
+
+#. select in the Main Menu *Macros - > Points set* item  or
+#. click |compoundVertices.icon| **Points set** button in Macros toolbar:
+
+The following property panel appears:
+
+.. image:: images/compoundVerticesPanel.png
+  :align: center
+
+.. centered::
+   set of Points
+
+Select your points file and define a separator if it's different that " " in your points file
+
+Result
+""""""
+
+A resulting compound will contain the points 
+
+.. image:: images/compoundVertices.png
+          :align: center
+
+.. centered::
+   Points
diff --git a/src/PythonAddons/doc/images/compound.png b/src/PythonAddons/doc/images/compound.png
new file mode 100644 (file)
index 0000000..5e119b3
Binary files /dev/null and b/src/PythonAddons/doc/images/compound.png differ
diff --git a/src/PythonAddons/doc/images/compoundVertices.png b/src/PythonAddons/doc/images/compoundVertices.png
new file mode 100644 (file)
index 0000000..9f624f8
Binary files /dev/null and b/src/PythonAddons/doc/images/compoundVertices.png differ
diff --git a/src/PythonAddons/doc/images/compoundVerticesPanel.png b/src/PythonAddons/doc/images/compoundVerticesPanel.png
new file mode 100644 (file)
index 0000000..e24bf2e
Binary files /dev/null and b/src/PythonAddons/doc/images/compoundVerticesPanel.png differ
diff --git a/src/PythonAddons/doc/images/importParameters.png b/src/PythonAddons/doc/images/importParameters.png
new file mode 100644 (file)
index 0000000..3b382b9
Binary files /dev/null and b/src/PythonAddons/doc/images/importParameters.png differ
diff --git a/src/PythonAddons/doc/images/importParametersPanel.png b/src/PythonAddons/doc/images/importParametersPanel.png
new file mode 100644 (file)
index 0000000..f395df5
Binary files /dev/null and b/src/PythonAddons/doc/images/importParametersPanel.png differ
diff --git a/src/PythonAddons/doc/importParametersFeature.rst b/src/PythonAddons/doc/importParametersFeature.rst
new file mode 100644 (file)
index 0000000..3fdfc6f
--- /dev/null
@@ -0,0 +1,27 @@
+.. _create_import_Parameters:
+.. |importParameters.icon|    image:: images/importParameters.png
+
+import Parameters
+=================
+
+Import Parameters is a macro-feature and can not be edited after execution.
+It allows creation of several parameters basing on variables-values file.
+
+To import parameters:
+
+#. select in the Main Menu *Macros - > import Parameters* item  or
+#. click |importParameters.icon| **import Parameters** button in Macros toolbar:
+
+The following property panel appears:
+
+.. image:: images/importParametersPanel.png
+  :align: center
+
+.. centered::
+   Import Parameters
+
+
+Result
+""""""
+
+Several parameters are automatically created.
diff --git a/src/PythonAddons/macros/compoundVertices/__init__.py b/src/PythonAddons/macros/compoundVertices/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/PythonAddons/macros/compoundVertices/feature.py b/src/PythonAddons/macros/compoundVertices/feature.py
new file mode 100644 (file)
index 0000000..492594c
--- /dev/null
@@ -0,0 +1,105 @@
+"""compound of vertices Feature
+Author: Nathalie Gore
+"""
+
+from qtsalome import QMessageBox
+from salome.shaper import model
+from salome.shaper import geom
+import ModelAPI
+
+class compoundVertices(model.Feature):
+    """Import of Construction points
+    """
+
+# Feature initializations
+
+    def __init__(self):
+        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
+        model.Feature.__init__(self)
+
+    @staticmethod
+    def ID():
+        """Return Id of the Feature."""
+        return "compoundVertices"
+
+    @staticmethod
+    def FILE_ID():
+        """Returns ID of the file select parameter."""
+        return "file_path"
+
+    @staticmethod
+    def SEPARATOR_ID():
+        """Returns ID of the separator parameter."""
+        return "separator"
+
+    def getKind(self):
+        """Override Feature.getKind()"""
+        return compoundVertices.ID()
+
+
+# Initialization of the dialog panel
+
+    def initAttributes(self):
+        """Override Feature.initAttributes()"""
+        # Creating the input argument of the feature
+        self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
+        self.data().addAttribute(self.SEPARATOR_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
+
+        self.lfeatures = []
+        self.folder = None
+        self.separator = " "
+
+# Execution of the Import
+
+    def execute(self):
+        """F.execute() -- execute the Feature"""
+        # Retrieving the user input
+        apath    = self.string(self.FILE_ID())
+        aseparator = self.string(self.SEPARATOR_ID()).value()
+        if aseparator:
+            self.separator = aseparator
+
+        filepath = apath.value()
+        if filepath != "" :
+            part = model.activeDocument()
+            if self.lfeatures :
+                for feature in self.lfeatures:
+                   part.removeFeature(feature.feature())
+                self.lfeatures = []
+                model.removeFolder(self.folder)
+
+            from os.path import basename
+            filename = basename(filepath)
+            nameRes = "Points_" + filename
+
+            # Creating the construction points in the current document
+            lVertices = []
+
+            with open(filepath) as file:
+                for line in file:
+                    coord = line.split(self.separator)
+                    if len(coord) != 3:
+                        #QMessageBox.warning( self, 'Error!', '3D coords waited!' )
+                        return
+                    x = float(coord[0]); y = float(coord[1]); z = float(coord[2]);
+                    point = model.addPoint(part, x,y,z); point.execute(True); self.lfeatures.append(point)
+                    vertex = model.addVertex(part, [point.result()]); vertex.execute(True); self.lfeatures.append(vertex)
+                    lVertices.append(vertex.result())
+                file.close()
+                compound = model.addCompound(part, lVertices)
+                compound.execute(True); self.lfeatures.append(compound)
+                compound.result().setName(nameRes)
+                self.folder = model.addFolder(part, self.lfeatures[0], compound)
+                self.folder.setName(nameRes)
+                return
+
+            setError("The file does not exist")
+
+    def isMacro(self):
+        """Override Feature.initAttributes().
+        F.isMacro() -> True
+
+        compoundVertices feature is macro: removes itself on the creation transaction
+        finish.
+        """
+        return False
diff --git a/src/PythonAddons/macros/compoundVertices/icons/import.png b/src/PythonAddons/macros/compoundVertices/icons/import.png
new file mode 100644 (file)
index 0000000..5e119b3
Binary files /dev/null and b/src/PythonAddons/macros/compoundVertices/icons/import.png differ
diff --git a/src/PythonAddons/macros/compoundVertices/widget.xml b/src/PythonAddons/macros/compoundVertices/widget.xml
new file mode 100644 (file)
index 0000000..c33e845
--- /dev/null
@@ -0,0 +1,17 @@
+<source>
+  <workbench id="Macros" document="Part">
+    <group id="Samples">
+      <feature
+        id="compoundVertices"
+        title="Points set"
+        tooltip="Import a set of construction points"
+        icon="icons/Addons/import.png"
+        helpfile="compoundVerticesFeature.html">
+        <file_selector id="file_path" title="Import txt file (X Y Z)" path="">
+        </file_selector>
+        <stringvalue id="separator"  label="Separator (optional): ">
+        </stringvalue>
+      </feature>
+    </group>
+  </workbench>
+</source>
diff --git a/src/PythonAddons/macros/importParameters/__init__.py b/src/PythonAddons/macros/importParameters/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/PythonAddons/macros/importParameters/feature.py b/src/PythonAddons/macros/importParameters/feature.py
new file mode 100644 (file)
index 0000000..72111d7
--- /dev/null
@@ -0,0 +1,71 @@
+"""importParameters
+Author: Nathalie Gore
+"""
+
+from salome.shaper import model
+from salome.shaper import geom
+import ModelAPI
+
+class importParameters(model.Feature):
+    """Import of Construction points
+    """
+
+# Feature initializations
+
+    def __init__(self):
+        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
+        model.Feature.__init__(self)
+
+    @staticmethod
+    def ID():
+        """Return Id of the Feature."""
+        return "importParameters"
+
+    @staticmethod
+    def FILE_ID():
+        """Returns ID of the file select parameter."""
+        return "file_path"
+
+    def getKind(self):
+        """Override Feature.getKind()"""
+        return importParameters.ID()
+
+
+# Initialization of the dialog panel
+
+    def initAttributes(self):
+        """Override Feature.initAttributes()"""
+        # Creating the input argument of the feature
+        self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
+
+# Execution of the Import
+
+    def execute(self):
+        """F.execute() -- execute the Feature"""
+        # Retrieving the user input
+        apath    = self.string(self.FILE_ID())
+        filepath = apath.value()
+        #print("filepath : ", filepath)
+        if filepath != "" :
+
+            # Creating the parameters in the current document
+            part = model.activeDocument()
+
+            with open(filepath) as file:
+                for line in file:
+                    defParameters = line.replace("\n","").split(' ')
+                    if len(defParameters) == 2 :
+                        model.addParameter(part, defParameters[0], defParameters[1])
+                file.close()
+                return
+
+            setError("The file does not exist")
+
+    def isMacro(self):
+        """Override Feature.initAttributes().
+        F.isMacro() -> True
+
+        importParameters feature is macro: removes itself on the creation transaction
+        finish.
+        """
+        return True
diff --git a/src/PythonAddons/macros/importParameters/icons/parameters.png b/src/PythonAddons/macros/importParameters/icons/parameters.png
new file mode 100644 (file)
index 0000000..3b382b9
Binary files /dev/null and b/src/PythonAddons/macros/importParameters/icons/parameters.png differ
diff --git a/src/PythonAddons/macros/importParameters/widget.xml b/src/PythonAddons/macros/importParameters/widget.xml
new file mode 100644 (file)
index 0000000..37e0208
--- /dev/null
@@ -0,0 +1,14 @@
+<source>
+  <workbench id="Macros" document="Part">
+    <group id="Samples">
+      <feature id="importParameters"
+        title="List of Parameters"
+        tooltip="Import a set of parameters"
+        icon="icons/Addons/parameters.png"
+        helpfile="importParametersFeature.html">
+        <file_selector id="file_path" title="Import file" path="">
+        </file_selector>
+      </feature>
+    </group>
+  </workbench>
+</source>