Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_SWIG / batchmode_visu.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 #  This library is free software; you can redistribute it and/or
8 #  modify it under the terms of the GNU Lesser General Public
9 #  License as published by the Free Software Foundation; either
10 #  version 2.1 of the License.
11 #
12 #  This library is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  Lesser General Public License for more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public
18 #  License along with this library; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 #  VISU VISU_SWIG : binding of C++ implementation and Python
25 #  File   : batchmode_visu.py
26 #  Module : VISU
27 #
28 from batchmode_salome import *
29 import salome
30 import visu
31
32 myVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,myStudy,10)
33 if myVisu is None:
34     raise RuntimeError, "myVisu is none, VISU component is not loaded  or found"
35     
36 myVisu.SetCurrentStudy(salome.myStudy)
37     
38 def try_mesh_parameters(theMeshPattern):
39     aResult = []
40     if theMeshPattern is None : return aResult ;
41     theMeshPattern =  theMeshPattern._narrow(VISU.Mesh)
42     if theMeshPattern is None : return aResult ;
43
44     aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
45     import copy; import os;
46     for ind in aTYPES:
47         aNewMesh = copy.deepcopy(theMeshPattern);
48         aNewMesh.SetPresentationType(ind)
49         aResult.append(aNewMesh)
50
51     return aResult
52     
53 def try_scalarmap_parameters(thePattern, theNum):
54     aList = []
55     if thePattern  is None : return aList 
56     thePattern =  thePattern._narrow(VISU.ScalarMap)
57     if thePattern  is None : return aList 
58     SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
59     import copy
60     import random
61     for ind in range(0,theNum):
62         anObj = copy.deepcopy(thePattern);
63         if ind%2 :
64             #try incorrect value deliberately (but allowed by idl description)
65             #try SetScalarMode(long)
66             mode = random.randint(-100000,100000); #incorrect value deliberately
67         else:
68             #correct value of ScalarMode
69             mode = random.randint(0, 3)
70
71         print "\tSetScalarMode(" + str(mode) +")"
72         anObj.SetScalarMode(mode)
73
74         # --- SCALING ---
75         scal = random.randint(0,1)
76         print "\tSetScaling(" + str(SCALING[scal]) +")"
77         anObj.SetScaling(SCALING[scal])
78         
79         # --- BOUNDARIES ---
80         if ind%2 :
81             alfa =  random.random()*random.randint(-100000,100000)
82             betta = random.random()*random.randint(-100000,100000)
83             aMin = alfa; aMax = betta
84         else:
85             #more correct set
86             aPMin = thePattern.GetMin()
87             aPMax = thePattern.GetMax()
88             aLen = aPMax - aPMin
89             alfa =  random.random()%0.5
90             betta = random.random()%0.5
91             aMin = alfa*aLen*random.randint(-1,1) + aPMin
92             aMax = betta*aLen*random.randint(-1,1) + aPMax
93         print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
94         anObj.SetRange(aMin, aMax)
95         aList.append(anObj) 
96        
97     return aList