Salome HOME
Remove PythonAPI implementation
[modules/shaper.git] / src / PythonAPI / model / services.py
1 """General purpose Interface
2 Author: Daniel Brunier-Coulin
3 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 """
5
6 import ModelAPI
7 import GeomAPI
8
9 def moduleDocument ():
10     """Return the main document (the Partset) created or open from the Modeler.
11
12     This document is unique in the application session.
13     """
14     return ModelAPI.ModelAPI_Session.get().moduleDocument()
15
16
17 def activeDocument ():
18     """Return the active document.
19
20     This document can be either the main application document (i.e. the Partset) or one of documents
21     referred to by the main document (a Part).
22     """
23     return ModelAPI.ModelAPI_Session.get().activeDocument()
24
25
26 def defaultPlane (name):
27     """Return one of the three planes defined by the global coordinate system.
28
29     These planes are respectively referred to by name "XOY" (Z=0), "XOZ" (Y=0) or "YOZ" (X=0).
30     """
31     # Temporary implementation before the availability of default planes.
32     o = GeomAPI.GeomAPI_Pnt(0, 0, 0)
33     if   name == "XOY":
34         n = GeomAPI.GeomAPI_Dir(0, 0, 1)
35         x = GeomAPI.GeomAPI_Dir(1, 0, 0)
36     elif name == "XOZ":
37         n = GeomAPI.GeomAPI_Dir(0, -1, 0)
38         x = GeomAPI.GeomAPI_Dir(1, 0, 0)
39     elif name == "YOZ":
40         n = GeomAPI.GeomAPI_Dir(1, 0, 0)
41         x = GeomAPI.GeomAPI_Dir(0, 1, 0)
42
43     return GeomAPI.GeomAPI_Ax3(o, x, n)
44
45
46 def begin ():
47     """Start a data structure transaction.
48
49     Make a control point for being able to discard or undo
50     all operations done during this transaction.
51     """
52     ModelAPI.ModelAPI_Session.get().startOperation()
53
54
55 def end ():
56     """Commit the data structure transaction.
57
58     Make all operations done since the last control point undo-able.
59     """
60     ModelAPI.ModelAPI_Session.get().finishOperation()
61
62
63 def do ():
64     """Commit the data structure transaction and start the new one.
65
66     Make all operations done since the last control point undo-able
67     and continue with the new transaction.
68     """
69     session = ModelAPI.ModelAPI_Session.get()
70     session.finishOperation()
71     session.startOperation()
72
73
74 def undo ():
75     """Roll-back the data structure to the previous control point."""
76     ModelAPI.ModelAPI_Session.get().undo()
77
78
79 def redo ():
80     """Restore the data structure rolled-back by the last undo."""
81     ModelAPI.ModelAPI_Session.get().redo()
82
83
84 def reset ():
85     """Reset the data structure to initial state."""
86     ModelAPI.ModelAPI_Session.get().closeAll()