Salome HOME
updated copyright message
[modules/shaper.git] / src / PythonAPI / model / services / __init__.py
1 # Copyright (C) 2016-2023  CEA, EDF
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 """Package for services for the Parametric Geometry API of the Modeler.
20 """
21
22 from ModelHighAPI import moduleDocument, activeDocument
23 from ModelHighAPI import defaultPlane, standardPlane
24 from ModelHighAPI import begin, end
25 from ModelHighAPI import apply as do
26 from ModelHighAPI import updateFeatures
27 from ModelHighAPI import undo, redo
28 from ModelHighAPI import reset
29 from ModelHighAPI import addFolder, removeFolder
30 from ModelHighAPI import ModelHighAPI_Selection as selection
31 from ModelAPI import findPartFeature
32
33 # a method used for the python dump of the SHAPER STUDY
34 def publishToShaperStudy():
35   begin()
36   activeDocument().addFeature("PublishToStudy")
37   end()
38
39 # returns unique identifier of the feature : id of part it belongs to + ":" + id of feature
40 # the second argument may be the number of result if feature has more than one result (1 corresponds to the second result, etc)
41 def featureStringId(theFeature, *theArgs):
42   aRoot = moduleDocument()
43   aCurrent = theFeature.feature().document()
44   if aRoot and aCurrent:
45     aRes = str(findPartFeature(aRoot, aCurrent).data().featureId()) + ":" + str(theFeature.feature().data().featureId())
46     if len(theArgs) == 1:
47       aRes += ":" + str(theArgs[0])
48     return aRes
49   return ""
50
51
52 import os
53
54 def getTmpFileName(thePrefix, theSuffix):
55   import tempfile
56   tempdir = tempfile.gettempdir()
57   tmp_file = tempfile.NamedTemporaryFile(suffix=theSuffix, prefix=thePrefix, dir=tempdir, delete=False)
58   tmp_filename = tmp_file.name
59   if os.name == "nt":
60     tmp_filename.replace("\\", "/")
61   tmp_file.close()
62   return tmp_filename
63
64 def removeTmpFile(theFilename):
65   try: os.remove(theFilename)
66   except OSError: pass
67
68 # Verify the Python dump with generating the auxiliary filenames
69 from ModelHighAPI import CHECK_NAMING_AND_GEOMETRICAL
70 from ModelHighAPI import checkPyDump
71 def checkPythonDump(theDumpMode = CHECK_NAMING_AND_GEOMETRICAL):
72   aPrefix = getTmpFileName("check_dump_", '')
73   aNaming = aPrefix + ".py"
74   aGeo  = aPrefix + "_geo.py"
75   aWeak = aPrefix + "_weak.py"
76   isOk = checkPyDump(aNaming, aGeo, aWeak, theDumpMode)
77   removeTmpFile(aPrefix)
78   removeTmpFile(aNaming)
79   removeTmpFile(aGeo)
80   removeTmpFile(aWeak)
81   return isOk