1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Anthony Geay
25 class WrappedType(object):
26 def __init__(self,varPtr,isTemporaryVar=False):
27 assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjServer))
29 if not isTemporaryVar:
30 self._var_ptr.Register()
31 self._is_temp=isTemporaryVar
35 return cPickle.loads(self._var_ptr.fetchSerializedContent())
38 return self.local_copy().__str__()
41 return self.local_copy().__repr__()
44 return (self._wrapped_type,(self.local_copy(),))
47 assert(isinstance(self._var_ptr,SALOME._objref_PickelizedPyObjRdWrServer))
48 st=cPickle.dumps(elt,cPickle.HIGHEST_PROTOCOL)
49 self._var_ptr.setSerializedContent(st)
53 self._var_ptr.UnRegister()
57 class List(WrappedType):
58 def __init__(self,varPtr,isTemporaryVar=False):
59 WrappedType.__init__(self,varPtr,isTemporaryVar)
60 self._wrapped_type=list
63 def __getitem__(self,*args):
64 ret=Caller(self._var_ptr,"__getitem__")
67 def __setitem__(self,*args):
68 ret=Caller(self._var_ptr,"__setitem__")
71 def __delitem__(self,*args):
72 ret=Caller(self._var_ptr,"__delitem__")
75 def append(self,*args):
76 ret=Caller(self._var_ptr,"append")
79 def extend(self,*args):
80 ret=Caller(self._var_ptr,"extend")
83 def insert(self,*args):
84 ret=Caller(self._var_ptr,"insert")
88 ret=Caller(self._var_ptr,"pop")
91 def remove(self,*args):
92 ret=Caller(self._var_ptr,"remove")
95 def reverse(self,*args):
96 ret=Caller(self._var_ptr,"reverse")
100 ret=Caller(self._var_ptr,"sort")
103 def count(self,*args):
104 return self.local_copy().count(*args)
106 def index(self,*args):
107 return self.local_copy().index(*args)
110 return len(self.local_copy())
113 class Dict(WrappedType):
114 def __init__(self,varPtr,isTemporaryVar=False):
115 WrappedType.__init__(self,varPtr,isTemporaryVar)
116 self._wrapped_type=dict
119 def __getitem__(self,*args):
120 ret=Caller(self._var_ptr,"__getitem__")
123 def __setitem__(self,*args):
124 ret=Caller(self._var_ptr,"__setitem__")
127 def __delitem__(self,*args):
128 ret=Caller(self._var_ptr,"__delitem__")
131 def clear(self,*args):
132 ret=Caller(self._var_ptr,"clear")
136 ret=Caller(self._var_ptr,"get")
139 def items(self,*args):
140 ret=Caller(self._var_ptr,"items")
144 ret=Caller(self._var_ptr,"pop")
147 def popitem(self,*args):
148 ret=Caller(self._var_ptr,"popitem")
151 def setdefault(self,*args):
152 ret=Caller(self._var_ptr,"setdefault")
155 def update(self,*args):
156 ret=Caller(self._var_ptr,"update")
159 def values(self,*args):
160 ret=Caller(self._var_ptr,"values")
165 def __contains__(self,*args):
166 return self.local_copy().__contains__(*args)
168 def has_key(self,*args):
169 return self.local_copy().has_key(*args)
171 def keys(self,*args):
172 return self.local_copy().keys(*args)
174 def copy(self,*args):
175 return self.local_copy().copy(*args)
178 return len(self.local_copy())
182 class Tuple(WrappedType):
183 def __init__(self,varPtr,isTemporaryVar=False):
184 WrappedType.__init__(self,varPtr,isTemporaryVar)
185 self._wrapped_type=tuple
188 def __getitem__(self,*args):
189 ret=Caller(self._var_ptr,"__getitem__")
194 def count(self,*args):
195 return self.local_copy().count(*args)
197 def index(self,*args):
198 return self.local_copy().index(*args)
201 return len(self.local_copy())
205 class Float(WrappedType):
206 def __init__(self,varPtr,isTemporaryVar=False):
207 WrappedType.__init__(self,varPtr,isTemporaryVar)
208 self._wrapped_type=float
211 def __iadd__(self,*args):
212 return self.local_copy().__add__(*args)
214 def __isub__(self,*args):
215 return self.local_copy().__sub__(*args)
217 def __imul__(self,*args):
218 return self.local_copy().__mul__(*args)
220 def __idiv__(self,*args):
221 return self.local_copy().__div__(*args)
223 def __add__(self,*args):
224 return self.local_copy().__add__(*args)
226 def __sub__(self,*args):
227 return self.local_copy().__sub__(*args)
229 def __mul__(self,*args):
230 return self.local_copy().__mul__(*args)
232 def __div__(self,*args):
233 return self.local_copy().__div__(*args)
235 def __pow__(self,*args):
236 return self.local_copy().__pow__(*args)
238 def as_integer_ratio(self,*args):
239 return self.local_copy().as_integer_ratio(*args)
241 def conjugate(self,*args):
242 return self.local_copy().conjugate(*args)
244 def fromhex(self,*args):
245 return self.local_copy().fromhex(*args)
248 return self.local_copy().hex(*args)
250 def imag(self,*args):
251 return self.local_copy().imag(*args)
253 def is_integer(self,*args):
254 return self.local_copy().is_integer(*args)
256 def real(self,*args):
257 return self.local_copy().real(*args)
260 class Int(WrappedType):
261 def __init__(self,varPtr,isTemporaryVar=False):
262 WrappedType.__init__(self,varPtr,isTemporaryVar)
263 self._wrapped_type=int
266 def __iadd__(self,*args):
267 return self.local_copy().__add__(*args)
269 def __isub__(self,*args):
270 return self.local_copy().__sub__(*args)
272 def __imul__(self,*args):
273 return self.local_copy().__mul__(*args)
275 def __imod__(self,*args):
276 return self.local_copy().__mod__(*args)
278 def __idiv__(self,*args):
279 return self.local_copy().__div__(*args)
281 def __add__(self,*args):
282 return self.local_copy().__add__(*args)
284 def __sub__(self,*args):
285 return self.local_copy().__sub__(*args)
287 def __mul__(self,*args):
288 return self.local_copy().__mul__(*args)
290 def __mod__(self,*args):
291 return self.local_copy().__mod__(*args)
293 def __div__(self,*args):
294 return self.local_copy().__div__(*args)
296 def __pow__(self,*args):
297 return self.local_copy().__pow__(*args)
299 def bit_length(self,*args):
300 return self.local_copy().bit_length(*args)
302 def conjugate(self,*args):
303 return self.local_copy().conjugate(*args)
305 def denominator(self,*args):
306 return self.local_copy().denominator(*args)
308 def imag(self,*args):
309 return self.local_copy().imag(*args)
311 def numerator(self,*args):
312 return self.local_copy().numerator(*args)
314 def real(self,*args):
315 return self.local_copy().real(*args)
318 class String(WrappedType):
319 def __init__(self,varPtr,isTemporaryVar=False):
320 WrappedType.__init__(self,varPtr,isTemporaryVar)
321 self._wrapped_type=int
324 def __add__(self,*args):
325 return self.local_copy().__add__(*args)
327 def __iadd__(self,*args):
328 return self.local_copy().__add__(*args)
330 def __getitem__(self,*args):
331 return self.local_copy().__getitem__(*args)
333 def capitalize(self,*args):
334 return self.local_copy().capitalize(*args)
336 def center(self,*args):
337 return self.local_copy().center(*args)
339 def count(self,*args):
340 return self.local_copy().count(*args)
342 def decode(self,*args):
343 return self.local_copy().decode(*args)
345 def encode(self,*args):
346 return self.local_copy().encode(*args)
348 def endswith(self,*args):
349 return self.local_copy().endswith(*args)
351 def expandtabs(self,*args):
352 return self.local_copy().expandtabs(*args)
354 def find(self,*args):
355 return self.local_copy().find(*args)
357 def format(self,*args):
358 return self.local_copy().format(*args)
360 def index(self,*args):
361 return self.local_copy().index(*args)
363 def isalnum(self,*args):
364 return self.local_copy().isalnum(*args)
366 def isalpha(self,*args):
367 return self.local_copy().isalpha(*args)
369 def isdigit(self,*args):
370 return self.local_copy().isdigit(*args)
372 def islower(self,*args):
373 return self.local_copy().islower(*args)
375 def isspace(self,*args):
376 return self.local_copy().isspace(*args)
378 def istitle(self,*args):
379 return self.local_copy().istitle(*args)
381 def isupper(self,*args):
382 return self.local_copy().isupper(*args)
384 def join(self,*args):
385 return self.local_copy().join(*args)
387 def ljust(self,*args):
388 return self.local_copy().ljust(*args)
390 def lower(self,*args):
391 return self.local_copy().lower(*args)
393 def lstrip(self,*args):
394 return self.local_copy().lstrip(*args)
396 def partition(self,*args):
397 return self.local_copy().partition(*args)
399 def replace(self,*args):
400 return self.local_copy().replace(*args)
402 def rfind(self,*args):
403 return self.local_copy().rfind(*args)
405 def rindex(self,*args):
406 return self.local_copy().rindex(*args)
408 def rjust(self,*args):
409 return self.local_copy().rjust(*args)
411 def rpartition(self,*args):
412 return self.local_copy().rpartition(*args)
414 def rsplit(self,*args):
415 return self.local_copy().rsplit(*args)
417 def rstrip(self,*args):
418 return self.local_copy().rstrip(*args)
420 def split(self,*args):
421 return self.local_copy().split(*args)
423 def splitlines(self,*args):
424 return self.local_copy().splitlines(*args)
426 def startswith(self,*args):
427 return self.local_copy().startswith(*args)
429 def strip(self,*args):
430 return self.local_copy().strip(*args)
432 def swapcase(self,*args):
433 return self.local_copy().swapcase(*args)
435 def title(self,*args):
436 return self.local_copy().title(*args)
438 def translate(self,*args):
439 return self.local_copy().translate(*args)
441 def upper(self,*args):
442 return self.local_copy().upper(*args)
444 def zfill(self,*args):
445 return self.local_copy().zfill(*args)
448 return len(self.local_copy())
452 def __init__(self,varPtr,meth):
453 assert(isinstance(varPtr,SALOME._objref_PickelizedPyObjServer))
458 def __call__(self,*args):
459 ret=self._var_ptr.invokePythonMethodOn(self._meth,cPickle.dumps(args,cPickle.HIGHEST_PROTOCOL))
460 return GetHandlerFromRef(ret,True)
463 PyHandlerTypeMap={int:Int,float:Float,str:String,list:List,tuple:Tuple,dict:Dict}
465 def GetHandlerFromRef(objCorba,isTempVar=False):
466 """ Returns a client that allows to handle a remote corba ref of a global var easily.
468 assert(isinstance(objCorba,SALOME._objref_PickelizedPyObjServer))
469 v=cPickle.loads(objCorba.fetchSerializedContent())
471 objCorba.UnRegister()
473 return PyHandlerTypeMap[v.__class__](objCorba,isTempVar)
476 def CreateRdOnlyGlobalVar(value,varName,scopeName):
478 dsm=salome.naming_service.Resolve("/DataServerManager")
479 d2s,isCreated=dsm.giveADataScopeCalled(scopeName)
480 return GetHandlerFromRef(d2s.createRdOnlyVar(varName,cPickle.dumps(value,cPickle.HIGHEST_PROTOCOL)),False)
482 def CreateRdExtGlobalVar(value,varName,scopeName):
484 dsm=salome.naming_service.Resolve("/DataServerManager")
485 d2s,isCreated=dsm.giveADataScopeCalled(scopeName)
486 return GetHandlerFromRef(d2s.createRdExtVar(varName,cPickle.dumps(value,cPickle.HIGHEST_PROTOCOL)),False)
488 def GetHandlerFromName(scopeName,varName):
490 dsm=salome.naming_service.Resolve("/DataServerManager")
491 d2s=dsm.retriveDataScope(scopeName)
492 return GetHandlerFromRef(d2s.retrieveVar(varName),False)