-# Copyright (C) 2016-2019 CEA/DEN, EDF R&D
+# Copyright (C) 2016-2024 CEA, EDF
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
from ModelHighAPI import reset
from ModelHighAPI import addFolder, removeFolder
from ModelHighAPI import ModelHighAPI_Selection as selection
-from ModelHighAPI import checkPythonDump as checkPythonDump
+from ModelAPI import findPartFeature
+
+# a method used for the python dump of the SHAPER STUDY
+def publishToShaperStudy():
+ begin()
+ activeDocument().addFeature("PublishToStudy")
+ end()
+
+# returns unique identifier of the feature : id of part it belongs to + ":" + id of feature
+# the second argument may be the number of result if feature has more than one result (1 corresponds to the second result, etc)
+def featureStringId(theFeature, *theArgs):
+ aRoot = moduleDocument()
+ aCurrent = theFeature.feature().document()
+ if aRoot and aCurrent:
+ aRes = str(findPartFeature(aRoot, aCurrent).data().featureId()) + ":" + str(theFeature.feature().data().featureId())
+ if len(theArgs) == 1:
+ aRes += ":" + str(theArgs[0])
+ return aRes
+ return ""
+
+
+import os
+
+def getTmpFileName(thePrefix, theSuffix):
+ import tempfile
+ tempdir = tempfile.gettempdir()
+ tmp_file = tempfile.NamedTemporaryFile(suffix=theSuffix, prefix=thePrefix, dir=tempdir, delete=False)
+ tmp_filename = tmp_file.name
+ if os.name == "nt":
+ tmp_filename.replace("\\", "/")
+ tmp_file.close()
+ return tmp_filename
+
+def removeTmpFile(theFilename):
+ try: os.remove(theFilename)
+ except OSError: pass
+
+# Verify the Python dump with generating the auxiliary filenames
+from ModelHighAPI import CHECK_NAMING_AND_GEOMETRICAL
+from ModelHighAPI import checkPyDump
+def checkPythonDump(theDumpMode = CHECK_NAMING_AND_GEOMETRICAL):
+ aPrefix = getTmpFileName("check_dump_", '')
+ aNaming = aPrefix + ".py"
+ aGeo = aPrefix + "_geo.py"
+ aWeak = aPrefix + "_weak.py"
+ isOk = checkPyDump(aNaming, aGeo, aWeak, theDumpMode)
+ removeTmpFile(aPrefix)
+ removeTmpFile(aNaming)
+ removeTmpFile(aGeo)
+ removeTmpFile(aWeak)
+ return isOk