Salome HOME
les contraintes
[modules/shaper.git] / src / PythonAddons / macros / midSurface / feature.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2016-2022  CEA/DEN, EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 """Obtention des surfaces médianes à partir d'une CAO contenue dans un fichier
22
23 On sait traiter les faces :
24   . planes
25   . cylindriques
26   . sphériques
27   . toriques
28   . coniques
29
30 Author: Gérald NICOLAS
31 """
32 __revision__ = "V02.04"
33
34 import os
35
36 from salome.shaper import model
37
38 import ModelAPI
39
40 from macros.midSurface.surfaceMediane import SurfaceMediane
41
42 class midSurface(model.Feature):
43     """Création des fibres neutres"""
44
45 # Feature initializations
46
47     def __init__(self):
48         """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
49         model.Feature.__init__(self)
50
51     @staticmethod
52     def ID():
53         """Return Id of the Feature."""
54         return "midSurface"
55
56     @staticmethod
57     def FILE_ID():
58         """Returns ID of the CAD file."""
59         return "file_path"
60
61     def getKind(self):
62         """Override Feature.getKind()"""
63         return midSurface.ID()
64
65
66 #====================================================================================
67 # Initialization of the dialog panel
68
69     def initAttributes(self):
70         """Override Feature.initAttributes()"""
71         # Creating the input argument of the feature
72         self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
73
74 #====================================================================================
75 # Execution
76
77     def execute(self):
78         """F.execute() -- execute the Feature"""
79         # Retrieving the user input
80         apath    = self.string(self.FILE_ID())
81
82         filepath = apath.value()
83         #print("filepath : '{}'".format(filepath))
84         if filepath != "" :
85             if os.path.isfile(filepath):
86                 # print("filepath : {}".format(filepath))
87                 # Lancement du script de création des fibres neutres
88                 l_options = list()
89                 l_options.append("-v")
90                 #l_options.append("-vmax")
91                 #l_options.append("-export_step")
92                 print("l_options : {}".format(l_options))
93                 s_med = SurfaceMediane(l_options)
94                 with open("/tmp/grr_1", "w") as fic :
95                     fic.write("{}\n".format(dir(s_med)))
96                     fic.write("\nFichier : {}".format(filepath))
97                 erreur, message = s_med.surf_fic_cao (filepath)
98                 with open("/tmp/grr_2", "w") as fic :
99                     fic.write("erreur = {}, message = '{}'".format(erreur, message))
100                 del s_med
101                 if erreur:
102                     self.setError(message)
103             else:
104                 self.setError("The file '{}' does not exist".format(filepath))
105
106         return
107
108     def isMacro(self):
109         """Override Feature.initAttributes().
110         F.isMacro() -> True
111
112         midSurface feature is macro: removes itself on the creation transaction
113         finish.
114         """
115         return False