Salome HOME
c1da528a41086963d91bab10b69523680ea5a985
[modules/med.git] / src / MEDCalc / tui / medpresentation.py
1 # Copyright (C) 2011-2016  CEA/DEN, EDF R&D
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
20 import medcalc
21 import MEDCALC, SALOME
22 from medcalc.medevents import notifyGui_addPresentation, notifyGui_removePresentation, notifyGui_error
23
24 __manager = medcalc.medcorba.factory.getPresentationManager()
25
26 def MakeMeshView(proxy,
27                  viewMode=MEDCALC.VIEW_MODE_DEFAULT,
28                  meshMode=MEDCALC.MESH_MODE_DEFAULT):
29   # Create the presentation instance in CORBA engine
30   # The engine in turn creates the ParaView pipeline elements
31   params = MEDCALC.MeshViewParameters(proxy.id, meshMode)
32   try:
33     presentation_id = __manager.makeMeshView(params, viewMode)
34     notifyGui_addPresentation(proxy.id, presentation_id)
35     return presentation_id
36   except SALOME.SALOME_Exception as e:
37     notifyGui_error("An error occured while creating the mesh view:\n" + e.details.text)
38     raise Exception(e.details.text)
39
40
41 def MakeScalarMap(proxy,
42                   viewMode=MEDCALC.VIEW_MODE_DEFAULT,
43                   displayedComponent=MEDCALC.DISPLAY_DEFAULT,
44                   scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
45                   colorMap=MEDCALC.COLOR_MAP_DEFAULT
46                   ):
47   # Create the presentation instance in CORBA engine
48   # The engine in turn creates the ParaView pipeline elements
49   params = MEDCALC.ScalarMapParameters(proxy.id, displayedComponent, scalarBarRange, colorMap)
50   try:
51     presentation_id = __manager.makeScalarMap(params, viewMode)
52     notifyGui_addPresentation(proxy.id, presentation_id)
53     return presentation_id
54   except SALOME.SALOME_Exception as e:
55     notifyGui_error("An error occured while creating the scalar map:\n" + e.details.text)
56     raise Exception(e.details.text)
57
58 def MakeContour(proxy,
59                 viewMode=MEDCALC.VIEW_MODE_DEFAULT,
60                 scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
61                 colorMap=MEDCALC.COLOR_MAP_DEFAULT,
62                 nbContours=MEDCALC.NB_CONTOURS_DEFAULT
63                 ):
64   params = MEDCALC.ContourParameters(proxy.id, scalarBarRange, colorMap, nbContours)
65   try:
66     presentation_id = __manager.makeContour(params, viewMode)
67     notifyGui_addPresentation(proxy.id, presentation_id)
68     return presentation_id
69   except SALOME.SALOME_Exception as e:
70     notifyGui_error("An error occured while creating the contour:\n" + e.details.text)
71     raise Exception(e.details.text)
72
73 ##
74 #
75 #def MakeVectorField(proxy,
76 #                    viewMode=MEDCALC.VIEW_MODE_DEFAULT
77 #                    ):
78 #  params = MEDCALC.VectorFieldParameters(proxy.id, viewMode)
79 #  presentation_id = __manager.makeVectorField(params)
80 #  notifyGui_addPresentation(proxy.id, presentation_id)
81 #  return presentation_id
82 ##
83 #
84 def MakeSlices(proxy,
85                 viewMode=MEDCALC.VIEW_MODE_DEFAULT,
86                 displayedComponent=MEDCALC.DISPLAY_DEFAULT,
87                 scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
88                 colorMap=MEDCALC.COLOR_MAP_DEFAULT,
89                 sliceOrientation=MEDCALC.SLICE_ORIENTATION_DEFAULT,
90                 nbSlices=MEDCALC.NB_SLICES_DEFAULT):
91   # Create the presentation instance in CORBA engine
92   # The engine in turn creates the ParaView pipeline elements
93   params = MEDCALC.SlicesParameters(proxy.id, displayedComponent,scalarBarRange, colorMap, 
94                                     sliceOrientation, nbSlices)
95   try:
96     presentation_id = __manager.makeSlices(params, viewMode)
97     notifyGui_addPresentation(proxy.id, presentation_id)
98     return presentation_id
99   except SALOME.SALOME_Exception as e:
100     notifyGui_error("An error occured while creating the slices:\n" + e.details.text)
101     raise Exception(e.details.text)
102 ##
103 #
104 #def MakeDeflectionShape(proxy,
105 #                        viewMode=MEDCALC.VIEW_MODE_DEFAULT
106 #                        ):
107 #  params = MEDCALC.DeflectionShapeParameters(proxy.id, viewMode)
108 #  presentation_id = __manager.makeDeflectionShape(params)
109 #  notifyGui_addPresentation(proxy.id, presentation_id)
110 #  return presentation_id
111 ##
112 #
113 #def MakePointSprite(proxy,
114 #                    viewMode=MEDCALC.VIEW_MODE_DEFAULT,
115 #                    displayedComponent=MEDCALC.DISPLAY_DEFAULT,
116 #                    scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT,
117 #                    colorMap=MEDCALC.COLOR_MAP_DEFAULT,
118 #                    ):
119 #  params = MEDCALC.PointSpriteParameters(proxy.id, viewMode, displayedComponent, scalarBarRange, colorMap)
120 #  presentation_id = __manager.makePointSprite(params)
121 #  notifyGui_addPresentation(proxy.id, presentation_id)
122 #  return presentation_id
123 #
124
125 def RemovePresentation(presentation_id):
126   ok = __manager.removePresentation(presentation_id)
127   if ok:
128     notifyGui_removePresentation(presentation_id)
129 #
130
131 def GetGENERICParameters(tag, presentation_id):
132   exec "params = __manager.get%sParameters(presentation_id)" % tag
133   return params
134
135 GetMeshViewParameters = lambda pres_id: GetGENERICParameters("MeshView", pres_id)
136 GetScalarMapParameters = lambda pres_id: GetGENERICParameters("ScalarMap", pres_id)
137 GetContourParameters = lambda pres_id: GetGENERICParameters("Contour", pres_id)
138 GetSlicesParameters = lambda pres_id: GetGENERICParameters("Slices", pres_id)
139
140
141 def UpdateGENERIC(tag, presentation_id, params):
142   exec "__manager.update%s(presentation_id, params)" % tag
143
144 UpdateMeshView = lambda pres_id, params: UpdateGENERIC("MeshView", pres_id, params)
145 UpdateScalarMap = lambda pres_id, params: UpdateGENERIC("ScalarMap", pres_id, params)
146 UpdateContour = lambda pres_id, params: UpdateGENERIC("Contour", pres_id, params)
147 UpdateSlices = lambda pres_id, params: UpdateGENERIC("Slices", pres_id, params)