1 # Copyright (C) 2016-2021 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """compound of vertices Feature
24 from salome.shaper import model
25 from salome.shaper import geom
28 class compoundVertices(model.Feature):
29 """Import of Construction points
32 # Feature initializations
35 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
36 model.Feature.__init__(self)
40 """Return Id of the Feature."""
41 return "compoundVertices"
45 """Returns ID of the file select parameter."""
50 """Returns ID of the separator parameter."""
54 """Override Feature.getKind()"""
55 return compoundVertices.ID()
58 # Initialization of the dialog panel
60 def initAttributes(self):
61 """Override Feature.initAttributes()"""
62 # Creating the input argument of the feature
63 self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
64 self.data().addAttribute(self.SEPARATOR_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
70 # Execution of the Import
73 """F.execute() -- execute the Feature"""
74 # Retrieving the user input
75 apath = self.string(self.FILE_ID())
76 aseparator = self.string(self.SEPARATOR_ID()).value()
78 self.separator = aseparator
80 filepath = apath.value()
82 part = model.activeDocument()
84 for feature in self.lfeatures:
85 part.removeFeature(feature.feature())
87 model.removeFolder(self.folder)
89 from os.path import basename
90 filename = basename(filepath)
91 nameRes = "Points_" + filename
93 # Creating the construction points in the current document
96 with open(filepath) as file:
98 coord = line.split(self.separator)
101 x = float(coord[0]); y = float(coord[1]); z = float(coord[2]);
102 point = model.addPoint(part, x,y,z); point.execute(True); self.lfeatures.append(point)
103 #vertex = model.addVertex(part, [point.result()]); vertex.execute(True); self.lfeatures.append(vertex)
104 lVertices.append(point.result())
106 compound = model.addCompound(part, lVertices)
107 compound.execute(True); self.lfeatures.append(compound)
108 compound.result().setName(nameRes)
109 self.folder = model.addFolder(part, self.lfeatures[0], compound)
110 self.folder.setName(nameRes)
113 setError("The file does not exist")
116 """Override Feature.initAttributes().
119 compoundVertices feature is macro: removes itself on the creation transaction