-from omniORB import CORBA
-from SALOME_NamingServicePy import *
-from LifeCycleCORBA import *
-import SALOMEDS
-import SALOMEDS_Attributes_idl
-
-
-VARIABLE_ID = 1030
-
-################################################
-
-# init ORB
-orb = CORBA.ORB_init( [''], CORBA.ORB_ID )
-
-# create naming service instance
-naming_service = SALOME_NamingServicePy_i( orb )
-
-# create life cycle CORBA instance
-lcc = LifeCycleCORBA( orb )
-
-# get study manager
-obj = naming_service.Resolve( '/myStudyManager' )
-studyManager = obj._narrow( SALOMEDS.StudyManager )
-
-################################################
-###
-# get active study
-###
-def getStudy( studyId ):
- #studyId = getStudyId()
- study = studyManager.GetStudyByID( studyId )
- return study
-
-###
-# Retrieve data from selected case
-###
-def GetDataFromCase( studyId, caseEntry ):
- theCase = {}
- study = getStudy( studyId )
- case = study.FindObjectID( caseEntry )
- builder = study.NewBuilder()
- # Get the values of the variables and make them a list
- for name in ("E", "F", "L", "I"):
- var = getSubSObjectByName( studyId, case, name )
- if var == None:
- print "GENERICSOLVER.GetDataFromCase : ERROR! no variable '%s'" % name
- break
- theCase[ name ] = getValueOfVariable( builder, var )
- return theCase
-
-###
-# Add some variable to the case
-###
-def AddDataToCase( studyId, caseEntry, varName, varValue ):
- study = getStudy( studyId )
- case = study.FindObjectID( caseEntry )
- builder = study.NewBuilder()
- var = addObjectInStudy( builder, case, varName, VARIABLE_ID )
- setValueToVariable( builder, var, varValue )
- sg.updateObjBrowser( True )
- pass
-
-###
-# Plays with study
-###
-def addObjectInStudy( builder, father, objname, objid ):
- obj = getSubSObjectByName( father, objname )
- if obj is None:
- obj = builder.NewObject( father )
- attr = builder.FindOrCreateAttribute( obj, "AttributeName" )
- attr.SetValue( objname )
- attr = builder.FindOrCreateAttribute( obj, "AttributeLocalID" )
- attr.SetValue( objid )
- return obj
-
-def setValueToVariable( builder, varobj, value ):
- attr = builder.FindOrCreateAttribute( varobj, "AttributeLocalID" )
- objid = attr.Value()
- if (objid == VARIABLE_ID):
- attr = builder.FindOrCreateAttribute( varobj, "AttributeReal" )
- attr.SetValue( value )
- else:
- attr = builder.FindOrCreateAttribute( varobj, "AttributeName" )
- QMessageBox.information( sgPyQt.getDesktop(), 'Info', "Object '%s' isn't a variable. Can't set value." % attr.Value() )
- pass
-
-def getValueOfVariable( builder, varobj ):
- attr = builder.FindOrCreateAttribute( varobj, "AttributeLocalID" )
- objid = attr.Value()
- if (objid == VARIABLE_ID):
- attr = builder.FindOrCreateAttribute( varobj, "AttributeReal" )
- return attr.Value()
- else:
- attr = builder.FindOrCreateAttribute( varobj, "AttributeName" )
- QMessageBox.information( sgPyQt.getDesktop(), 'Info', "Object '%s' isn't a variable. Can't set value." % attr.Value() )
- return 0.
-
-def getSubSObjectByName( studyId, sobjFather, childName ):
- print "GENERICSOLVER.getSubSObjectByName Looking for sobjet named", childName
- study = getStudy( studyId )
- iter = study.NewChildIterator( sobjFather )
- #builder = study.NewBuilder()
- while iter.More():
- sobj = iter.Value()
- print "GENERICSOLVER.getSubSObjectByName Got sobjet named", sobj.GetName()
- if sobj.GetName() == childName:
- return sobj
- iter.Next()
- pass
- return None
-
-################################################