Salome HOME
Merge branch 'python_parametric_api' of https://git.salome-platform.org/git/modules...
[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 from ModelAPI import *
7 from GeomAPI  import *
8 import geom              # To be removed when gp_Ax3 will be Pythonized
9
10
11 def moduleDocument ():
12   """Returns the main document (the Partset) created or open from the Modeler.
13   This document is unique in the application session.
14   """
15   return ModelAPI_Session.get().moduleDocument()
16
17
18 def activeDocument ():
19   """Returns the active document.
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_Session.get().activeDocument()
24
25
26 def defaultPlane (name):
27   """Returns one of the three planes defined by the global coordinate system.
28   These planes are respectively referred to by name "XOY" (Z=0), "XOZ" (Y=0) or "YOZ" (X=0).
29   """
30 # Temporary implementation before the availability of default planes.
31
32   o = GeomAPI_Pnt( 0, 0, 0 )
33   if   name == "XOY":
34     n = GeomAPI_Dir( 0, 0, 1)
35     x = GeomAPI_Dir( 1, 0, 0)
36   elif name == "XOZ":
37     n = GeomAPI_Dir( 0, 1, 0)
38     x = GeomAPI_Dir( 1, 0, 0)
39   elif name == "YOZ":
40     n = GeomAPI_Dir( 1, 0, 0)
41     x = GeomAPI_Dir( 0, 1, 0)
42
43   return geom.Ax3( o, n, x )
44
45
46 def begin ():
47   """Starts a data structure transaction, as such making a control point for being able to discard or undo
48   all operations done during this transaction.
49   """
50   ModelAPI_Session.get().startOperation()
51
52
53 def end ():
54   """Commits the data structure transaction and makes all operations done since the last control point undo-able."""
55   ModelAPI_Session.get().finishOperation()
56
57
58 def do ():
59   """Commits the data structure transaction and makes all operations done since the last control point undo-able."""
60   session = ModelAPI_Session.get()
61   session.finishOperation()
62   session.startOperation()
63
64
65 def undo ():
66   """Rolls-back the data structure to the previous control point."""
67   ModelAPI_Session.get().undo()
68
69
70 def redo ():
71   """Restore the data structure rolled-back by the last undo."""
72   ModelAPI_Session.get().redo()