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)
1  2 
src/PythonAddons/macros/compoundVertices/feature.py
src/PythonAddons/macros/compoundVertices/widget.xml
src/PythonAddons/macros/importParameters/feature.py
src/PythonAddons/macros/importParameters/widget.xml

index 0000000000000000000000000000000000000000,bf5ce564b89506f0d73898da78a7c5e25310779c..492594c4ae9eeec0d028f93159e55c388e70f570
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,105 +1,105 @@@
 -            part = model.activeDocument()            
+ """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
index 0000000000000000000000000000000000000000,75e5a6c21b76133b20e6a5686325e8e0d6374f97..c33e845dd1f9511d3560bbb6a32ca6207dceb280
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,19 +1,17 @@@
 -<source>\r
 -  <workbench id="Macros" document="Part">\r
 -    <group id="Samples">\r
 -\r
 -      <feature\r
 -        id="compoundVertices"\r
 -        title="Points set"\r
 -        tooltip="Import a set of construction points"\r
 -        icon="icons/Addons/import.png"\r
 -        helpfile="compoundVerticesFeature.html">\r
 -        <file_selector id="file_path" title="Import txt file (X Y Z)" path="">\r
 -        </file_selector>\r
 -        <stringvalue id="separator"  label="Separator (optional): ">\r
 -        </stringvalue>\r
 -      </feature>\r
 -\r
 -    </group>\r
 -  </workbench>  \r
 -</source>\r
++<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>
index 0000000000000000000000000000000000000000,6abd0ddf355219abcabb9669489d0ee4558c3e6b..72111d75bb2c41a0e235086ac235b0a520a936cb
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,73 +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
index 0000000000000000000000000000000000000000,0865719931043ea94664e7f280e97d9098c8588c..37e0208d7219019bc65ea5d064b2eb1c7c3ece20
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,16 +1,14 @@@
 -<source>\r
 -  <workbench id="Macros" document="Part">\r
 -    <group id="Samples">\r
 -\r
 -      <feature id="importParameters"\r
 -        title="List of Parameters"\r
 -        tooltip="Import a set of parameters"\r
 -        icon="icons/Addons/parameters.png"\r
 -        helpfile="importParametersFeature.html">\r
 -        <file_selector id="file_path" title="Import file" path="">\r
 -        </file_selector>\r
 -      </feature>\r
 -\r
 -    </group>\r
 -  </workbench>  \r
 -</source>\r
++<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>