#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_Document.h>
+#include <ModelAPI_Events.h>
//--------------------------------------------------------------------------------------
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());
+}
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
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;
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_ */
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
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)
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):
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)
<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>
- 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
--- /dev/null
+.. _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
--- /dev/null
+.. _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.
--- /dev/null
+"""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
--- /dev/null
+<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>
--- /dev/null
+"""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
--- /dev/null
+<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>