]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update pour separator
authorNATHALIE GORE <ng13417n@dsp0897499.atlas.edf.fr>
Wed, 21 Aug 2019 08:41:33 +0000 (10:41 +0200)
committerNATHALIE GORE <ng13417n@dsp0897499.atlas.edf.fr>
Wed, 21 Aug 2019 08:41:33 +0000 (10:41 +0200)
src/PythonAddons/macros/compoundVertices/feature.py
src/PythonAddons/macros/compoundVertices/widget.xml
src/PythonAddons/macros/importParameters/feature.py

index c8e5fed4863bce9a166c313425aa9d3277327d26..0f2189c1ec2a7c6e18e10d804438f9c59e8fd807 100644 (file)
@@ -26,6 +26,11 @@ class compoundVertices(model.Feature):
         """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()
@@ -37,6 +42,11 @@ class compoundVertices(model.Feature):
         """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
 
@@ -44,33 +54,39 @@ class compoundVertices(model.Feature):
         """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()
-        print("filepath : ", filepath)
         if filepath != "" :
-            
+            part = model.activeDocument()            
+            if self.lfeatures :
+                for feature in self.lfeatures:
+                   part.removeFeature(feature.feature())
+                self.lfeatures = []
+                #part.removeFeature(self.folder.feature())
+
             from os.path import basename
             filename = basename(filepath)
-            print("filename : ", filename)
+            nameRes = "Points_" + filename
 
             # Creating the construction points in the current document
-            part = model.activeDocument()
             lVertices = []
 
-            startPoint = None
-
             with open(filepath) as file:
                 for line in file:
-                    coord = line.split(' ')
+                    coord = line.split(self.separator)
                     x = float(coord[0]); y = float(coord[1]); z = float(coord[2]);
-                    point = model.addPoint(part, x,y,z); point.execute(True)
-                    if startPoint == None : startPoint = point
-                    vertex = model.addVertex(part, [point.result()]); vertex.execute(True)
+                    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)
-                folder = model.addFolder(part, startPoint, compound)
-                folder.setName(filename)
+                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")
@@ -82,4 +98,4 @@ class compoundVertices(model.Feature):
         compoundVertices feature is macro: removes itself on the creation transaction
         finish.
         """
-        return True                    
+        return True
index e8e2f2e8855070a79cb7184cdb2606ea3b777fb1..2fa559776a9c4f4f2126f1d35e07e485aa122e84 100644 (file)
@@ -5,6 +5,8 @@
       <feature id="compoundVertices" title="Points set" tooltip="Import a set of construction points" icon="icons/import.png">\r
         <file_selector id="file_path" title="Import file" path="">\r
         </file_selector>\r
+        <stringvalue id="separator"  label="Separator (optional): ">\r
+        </stringvalue>\r
       </feature>\r
 \r
     </group>\r
index 7f2f15055e32b9d5e214d9d66d26feab02ef8e33..6abd0ddf355219abcabb9669489d0ee4558c3e6b 100644 (file)
@@ -58,6 +58,8 @@ class importParameters(model.Feature):
                         model.addParameter(part, defParameters[0], defParameters[1])
                 file.close()
                 return
+        
+            setError("The file does not exist")
 
     def isMacro(self):
         """Override Feature.initAttributes().
@@ -67,6 +69,5 @@ class importParameters(model.Feature):
         finish.
         """
         return True
-        
-            setError("The file does not exist")
+