Salome HOME
Adding test for bos #41748 [CEA] Issue in interpolation edition
[modules/shaper.git] / src / PythonAPI / model / services / __init__.py
index d585c1891f9f763f7c72b283abf3af3268d7c1f0..ba95ba605dc0d4028a0b8e77561842396963ff81 100644 (file)
@@ -1,4 +1,4 @@
-# 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
@@ -28,4 +28,54 @@ from ModelHighAPI import undo, redo
 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