1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2016-2021 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 """compound of vertices Feature
26 from salome.shaper import model
30 class compoundVertices(model.Feature):
31 """Import of Construction points
34 # Feature initializations
41 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
42 model.Feature.__init__(self)
46 """Return Id of the Feature."""
47 return "compoundVertices"
51 """Returns ID of the file."""
56 """Returns ID of the separator parameter."""
60 """Override Feature.getKind()"""
61 return compoundVertices.ID()
64 # Initialization of the dialog panel
66 def initAttributes(self):
67 """Override Feature.initAttributes()"""
68 # Creating the input argument of the feature
69 self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
70 self.data().addAttribute(self.SEPARATOR_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
72 # Execution of the Import
75 """F.execute() -- execute the Feature"""
76 # Retrieving the user input
77 apath = self.string(self.FILE_ID())
78 aseparator = self.string(self.SEPARATOR_ID()).value()
80 self.separator = aseparator
82 filepath = apath.value()
83 #print("filepath : '{}'".format(filepath))
85 if os.path.isfile(filepath):
86 part = model.activeDocument()
88 for feature in self.lfeatures:
89 part.removeFeature(feature.feature())
90 self.lfeatures = list()
91 model.removeFolder(self.folder)
93 filename = os.path.basename(filepath)
94 nameRes = "Points_" + filename
96 # Creating the construction points in the current document
99 with open(filepath) as fic:
101 coord = line.split(self.separator)
104 point = model.addPoint(part, float(coord[0]),float(coord[1]),float(coord[2]))
106 self.lfeatures.append(point)
107 #vertex = model.addVertex(part, [point.result()]); vertex.execute(True); self.lfeatures.append(vertex)
108 lVertices.append(point.result())
110 compound = model.addCompound(part, lVertices)
111 compound.execute(True)
112 self.lfeatures.append(compound)
113 compound.result().setName(nameRes)
114 self.folder = model.addFolder(part, self.lfeatures[0], compound)
115 self.folder.setName(nameRes)
117 self.setError("The file '{}' does not exist".format(filepath))
122 """Override Feature.initAttributes().
125 compoundVertices feature is macro: removes itself on the creation transaction