From a2db0d172988b8168e6dca53a19044f95abfae85 Mon Sep 17 00:00:00 2001 From: NATHALIE GORE Date: Thu, 8 Aug 2019 16:18:25 +0200 Subject: [PATCH] Adding some macros : compound of vertices --- src/PythonAddons/addons_Features.py | 7 +- src/PythonAddons/addons_Features.xml.in | 2 + src/PythonAddons/macros/box/__init__.py | 1 + src/PythonAddons/macros/box/feature.py | 128 ++++++++++++++++++ src/PythonAddons/macros/box/icons/box_ico.png | Bin 0 -> 405 bytes src/PythonAddons/macros/box/widget.xml | 22 +++ .../macros/compoundVertices/__init__.py | 0 .../macros/compoundVertices/feature.py | 69 ++++++++++ .../macros/compoundVertices/widget.xml | 13 ++ 9 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 src/PythonAddons/macros/box/__init__.py create mode 100644 src/PythonAddons/macros/box/feature.py create mode 100644 src/PythonAddons/macros/box/icons/box_ico.png create mode 100644 src/PythonAddons/macros/box/widget.xml create mode 100644 src/PythonAddons/macros/compoundVertices/__init__.py create mode 100644 src/PythonAddons/macros/compoundVertices/feature.py create mode 100644 src/PythonAddons/macros/compoundVertices/widget.xml diff --git a/src/PythonAddons/addons_Features.py b/src/PythonAddons/addons_Features.py index d28db61ab..1bb7354a9 100644 --- a/src/PythonAddons/addons_Features.py +++ b/src/PythonAddons/addons_Features.py @@ -22,6 +22,8 @@ import ModelAPI from macros.rectangle.feature import SketchPlugin_Rectangle +from macros.compoundVertices.feature import compoundVertices +from macros.box.feature import BoxFeature 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 == BoxFeature.ID(): + aFeature = BoxFeature().__disown__() else: raise Exception("No such feature %s" % theFeatureID) diff --git a/src/PythonAddons/addons_Features.xml.in b/src/PythonAddons/addons_Features.xml.in index f0190ba62..958ef4511 100644 --- a/src/PythonAddons/addons_Features.xml.in +++ b/src/PythonAddons/addons_Features.xml.in @@ -1,3 +1,5 @@ + + diff --git a/src/PythonAddons/macros/box/__init__.py b/src/PythonAddons/macros/box/__init__.py new file mode 100644 index 000000000..1b78cf4b8 --- /dev/null +++ b/src/PythonAddons/macros/box/__init__.py @@ -0,0 +1 @@ +## Copyright (C) 2014-20xx OPEN CASCADE diff --git a/src/PythonAddons/macros/box/feature.py b/src/PythonAddons/macros/box/feature.py new file mode 100644 index 000000000..5af78bdec --- /dev/null +++ b/src/PythonAddons/macros/box/feature.py @@ -0,0 +1,128 @@ +## Copyright (C) 2014-20xx OPEN CASCADE + +""" +Box macro-feature +""" + +from salome.shaper import model +from salome.shaper import geom + + +class BoxFeature(model.Feature): + """An example of feature implementation. + """ + +# 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 "Box_script" + + @staticmethod + def WIDTH_ID(): + """Returns ID of Width parameter.""" + return "width" + + @staticmethod + def LENGTH_ID(): + """Returns ID of Length parameter.""" + return "length" + + @staticmethod + def HEIGHT_ID(): + """Returns ID of Height parameter.""" + return "height" + + def getKind(self): + """Override Feature.getKind()""" + return BoxFeature.ID() + + +# Creation of the box at default size + + def initAttributes(self): + """Override Feature.initAttributes()""" + # Creating the input arguments of the feature + self.addRealInput(self.WIDTH_ID()) + self.addRealInput(self.LENGTH_ID()) + self.addRealInput(self.HEIGHT_ID()) + + # Creating the base of the box with unit values + mypart = model.activeDocument() + xoy = model.defaultPlane("XOY") + + # A base of the geometry + self.base = model.addSketch(mypart, xoy) + + p1 = geom.Pnt2d(0, 0) + p2 = geom.Pnt2d(0, 1) + p3 = geom.Pnt2d(1, 1) + p4 = geom.Pnt2d(1, 0) + + line = model.addPolygon(self.base, p1, p2, p3, p4) + + self.base.setFixed(line[0].startPoint()) + self.base.setVertical(line[0]) + + # Setting the size of the base with default values + # Width + self.width = self.base.setLength(line[3], 50) # Keeps the constraint for edition + # Length + self.length = self.base.setLength(line[0], 50) # Keeps the constraint for edition + + # Keeping the rectangle + self.base.setParallel(line[0], line[2]) + self.base.setParallel(line[1], line[3]) + self.base.setPerpendicular(line[0], line[3]) + + # execute sketch + mypart.setCurrentFeature(self.base.feature(), False) + model.updateFeatures() + + # Creating the extrusion (the box) at default size + # A box result + self.box = model.addExtrusion(mypart, self.base.selectFace(), 50) + self.box.setNestedSketch(self.base) +# self.box.setName(self.name()) + +# Edition of the box at user size + + def execute(self): + """F.execute() -- execute the feature""" + # Retrieving the user inputs + width = self.real(self.WIDTH_ID()) + length = self.real(self.LENGTH_ID()) + height = self.real(self.HEIGHT_ID()) + + # Editing the box + if width.text() == "": + self.base.setValue(self.width, width.value()) + else: + self.base.setValue(self.width, width.text()) + + if length.text() == "": + self.base.setValue(self.length, length.value()) + else: + self.base.setValue(self.length, length.text()) + + if (height.text() == ""): + self.box.setSize(height.value()) + else: + self.box.setSize(height.text()) + + # Publishing the result: not needed for Macro feature + # self.addResult( self.box.result() ) + + def isMacro(self): + """Override Feature.initAttributes(). + F.isMacro() -> True + + Box feature is macro: removes itself on the creation transaction + finish. + """ + return True diff --git a/src/PythonAddons/macros/box/icons/box_ico.png b/src/PythonAddons/macros/box/icons/box_ico.png new file mode 100644 index 0000000000000000000000000000000000000000..104a1edde755dae03a8348b40b4667b0e70d860c GIT binary patch literal 405 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4kh`q^SLUNVrt6;T)nD-m^ zgx#~wmA}0-iBrvlZ+0>_!?oD=JHuAKnG4I#Lt<9A;joy~jYU0bN z6tK-c@ZFsDSF^2|A~iUDR-b)#rsw*C-!oS`xcpLmA?AB6cgy!myT?zvXKqgTBR*rX zyD|sEYyHEW*LGBW5cXcVJf8cJ%CV<=*Z)53c%l1HF?YkqZ~?)XJ9l3lJpN&sc + + + + + + + + + + + + + + + + + + + diff --git a/src/PythonAddons/macros/compoundVertices/__init__.py b/src/PythonAddons/macros/compoundVertices/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/PythonAddons/macros/compoundVertices/feature.py b/src/PythonAddons/macros/compoundVertices/feature.py new file mode 100644 index 000000000..141b35bb0 --- /dev/null +++ b/src/PythonAddons/macros/compoundVertices/feature.py @@ -0,0 +1,69 @@ +"""compound of vertices Feature +Author: Nathalie Gore +""" + +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" + + 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()) + +# 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 construction points in the current document + part = model.activeDocument() + lVertices = [] + + with open(filepath) as file: + for line in file: + coord = line.split(' ') + x = float(coord[0]); y = float(coord[1]); z = float(coord[2]); + print(line) + point = model.addPoint(part, x,y,z) + print(line) + vertex = model.addVertex(part, [point.result()]) + print(line) + #lVertices.append(vertex) + file.close() + return + + setError("The file does not exist") + diff --git a/src/PythonAddons/macros/compoundVertices/widget.xml b/src/PythonAddons/macros/compoundVertices/widget.xml new file mode 100644 index 000000000..d7901cf22 --- /dev/null +++ b/src/PythonAddons/macros/compoundVertices/widget.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + -- 2.39.2