def connectToCover(self, visConnectionModule): self.__creationModule = visConnectionModule VRPCoviseNetAccess.connect(visConnectionModule.connectionPoint(), globalRenderer().connectionPoint()) if os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR'): #filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' + self.params.name + "_%s.covise" % self.key #rw = RWCoviseModule(filename, True) #filename = rw.gridPath() #connect( visConnectionModule.connectionPoint(), rw.inConnectionPoint() ) filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' \ + self.params.name + "_" + str(self.key) + ".covise" self.__debugRwModule = RWCoviseModule(filename, True) connect(visConnectionModule.connectionPoint(), self.__debugRwModule.inConnectionPoint())
def _initData(self, name): if name in self._dataFileNames: if not name in self._data: self._data[name] = RWCoviseModule(self._dataFileNames[name]) self._dataFileNames[name] = self._data[name].gridPath() self.__dataConnectionPoints[name] = self._data[ name].connectionPoint()
def connectToCover( self, visConnectionModule ): self.__creationModule = visConnectionModule VRPCoviseNetAccess.connect( visConnectionModule.connectionPoint(), globalRenderer().connectionPoint() ) if os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR'): #filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' + self.params.name + "_%s.covise" % self.key #rw = RWCoviseModule(filename, True) #filename = rw.gridPath() #connect( visConnectionModule.connectionPoint(), rw.inConnectionPoint() ) filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' \ + self.params.name + "_" + str(self.key) + ".covise" self.__debugRwModule = RWCoviseModule(filename, True) connect( visConnectionModule.connectionPoint(), self.__debugRwModule.inConnectionPoint() )
class VisItem(coKeydObject): """ a visitem gets its input from an importModule and gives a geometry object out which is connected to the COVER """ def __init__(self, typeNr, name='VisItem' ): coKeydObject.__init__(self, typeNr, name) self.__init() self.importModule = None def __init(self): # key which is defined by COVER self.covise_key = 'No key' # the module that can check if a covise_key is created by this VisItem self.__creationModule = None # the module that writes the covise object into a file for testing self.__debugRwModule = None # register ui action Neg2Gui.theNegMsgHandler().registerVisItem(self) def recreate(self, negMsgHandler, parentKey, offset): VisItemParams.mergeDefaultParams(self.params) # explicitly call mergeDefaultParams of this class self.__init() coKeydObject.recreate(self, negMsgHandler, parentKey, offset) def registerCOVISEkey( self, covise_key): """ check if object name was created by this visItem and if yes store it """ if not self.__creationModule==None: if self.createdKey( covise_key ): firstTime = not self.keyRegistered() self.covise_key = covise_key self.sendVisibility() self.sendCaseName() self.sendCaseTransform() self.sendName() return (True, firstTime) return (False, False) def keyRegistered(self): if self.covise_key=='No key': return False return True def __getCaseName(self): caseName = None key = self.parentKey #for i in range(3): while key >= 0 and caseName==None: parent = globalKeyHandler().getObject(key) if isinstance(parent,coCaseMgr.coCaseMgr ): caseName = parent.params.name else : key = parent.parentKey return caseName def getCoObjName(self): return self.importModule.getCoObjName() def createdKey(self, key): importKey = self.getCoObjName() _infoer.function = str(self.createdKey) _infoer.write("check my key %s against COVER key %s" % (importKey, key) ) posCover = key.find("(") posImport = importKey.find("OUT") # if the beginning of my key and COVER key are equal, dann the key exists return ( importKey[0:posImport-1]==key[0:posCover] ) def sendVisibility(self): """ send visibility msg to cover """ if not self.covise_key=='No key': msg = coGRObjVisMsg( coGRMsg.GEO_VISIBLE, self.covise_key, self.params.isVisible ) covise.sendRendMsg(msg.c_str()) def sendName(self): """ send name of the VisItem to cover """ if not self.covise_key=='No key': msg = coGRObjSetNameMsg( coGRMsg.SET_NAME, self.covise_key, str(self.params.name) ) covise.sendRendMsg(msg.c_str()) def sendCaseName(self): """ send visibility msg to cover """ if not self.covise_key=='No key': caseName = self.__getCaseName() if caseName: msg = coGRObjSetCaseMsg( coGRMsg.SET_CASE, self.covise_key, caseName) covise.sendRendMsg(msg.c_str()) def sendCaseTransform(self): """ send case transformation to COVER """ key = self.parentKey sentMatrix = False while key >= 0 and not sentMatrix: parent = globalKeyHandler().getObject(key) if isinstance(parent,coCaseMgr.coCaseMgr ): # send transformation matrix for this visItem parent._sendMatrix() sentMatrix = True else : key = parent.parentKey def reconnect(self): coKeydObject.reconnect(self) if self.__creationModule : self.connectToCover(self.__creationModule) def connectToCover( self, visConnectionModule ): self.__creationModule = visConnectionModule VRPCoviseNetAccess.connect( visConnectionModule.connectionPoint(), globalRenderer().connectionPoint() ) if os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR'): #filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' + self.params.name + "_%s.covise" % self.key #rw = RWCoviseModule(filename, True) #filename = rw.gridPath() #connect( visConnectionModule.connectionPoint(), rw.inConnectionPoint() ) filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' \ + self.params.name + "_" + str(self.key) + ".covise" self.__debugRwModule = RWCoviseModule(filename, True) connect( visConnectionModule.connectionPoint(), self.__debugRwModule.inConnectionPoint() ) def disconnectFromCover(self, visConnectionModule): coverModule = globalRenderer().connectionPoint().module visItemModule = visConnectionModule.connectionPoint().module theNet().disconnectModuleModule(coverModule, visItemModule) def delete(self, isInitialized, negMsgHandler=None): if isInitialized: if os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') and hasattr(self, '_VisItem__debugRwModule') and self.__debugRwModule: self.__debugRwModule.remove() return coKeydObject.delete(self, isInitialized, negMsgHandler) def setImport(self, group): self.importModule = group def setParams(self, params, negMsgHandler=None, sendToCover=True): visibility_changed = (params.isVisible!=self.params.isVisible) self.params.isVisible = params.isVisible # check if params contains more than isVisible if issubclass( params.__class__, VisItemParams): name_changed = (params.name!=self.params.name) coKeydObject.setParams(self, params) if name_changed: self.sendName() if visibility_changed: self.sendVisibility() def sendParams(self): """ send Params to Gui """ Neg2Gui.theNegMsgHandler().sendParams(self.key, self.params ) def recvParams( self, isVisible): self.params.isVisible = isVisible self.sendParams() def updateDebugFilename(self, PresentationStepKey): if hasattr(self, '_VisItem__debugRwModule') and self.__debugRwModule: filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' \ + 'STEP' + str(PresentationStepKey) + "_" \ + self.params.name + "_" + str(self.key) + ".covise" self.__debugRwModule.setGridPath(filename, True)
class ImportModule(object): def __init__(self, dimension, partcase): global testPath self._dim = dimension self._name = partcase.name self._part = partcase # Module Classes holding geo, oct and data self._geo = None self._data = {} self._oct = None # list of loaded files self._files_loaded = [] self._oct_ready = False self._octTreeFileName = None self._octTreeFileExists = False self._octTreeWriter = None # RWCovise to write out octtree # mapping variable name to filename and filetype self._dataFileNames = {} self._dataVariableType = {} self.__dataConnectionPoints = {} # bounding box module and content self._bb = None self._boundingBox = None self._numTimeSteps = None # bounding box module and content from unfiltered geometry self.__bbFromGeoRWCovise = None # the module self.__boundingBoxFromGeoRWCovise = None # the AABB # colors module to calculate min/max self._minMax = None def readPartcase(self): varNotFound = [] for v in self._part.variables: if getExistingFilename(v.filename) == None: self._part.variables.remove(v) varNotFound.append(v.filename) else: self._dataFileNames[v.name] = v.filename self._dataVariableType[v.name] = v.variableDimension # check if file is transient self._isTransient = False filename = getExistingFilename(self._part.filename) if filename == None: raise CoviseFileNotFoundError(self._part.filename) in_file = open( filename, "rb" ) # open in binary mode (makes a difference on windows (read() may stop too early)) # first check if we have TIMESTEP at the end in_file.seek(-100, os.SEEK_END) tail = in_file.read(100) if b"TIMESTEP" in tail: self._isTransient = True else: # if not already recognized as transient, check if we have SETELE at the beginning head = in_file.read(100) if b"SETELE" in head: # if we have, check the entire file since we might have nested sets in_file.seek(0, os.SEEK_BEGIN) line = in_file.readline() while line: if b"TIMESTEP" in line: self._isTransient = True break line = in_file.readline() in_file.close() return varNotFound """ ------------------------ """ """ init by starting modules """ """ ------------------------ """ def _initGeo(self): if self._geo == None: self._geo = RWCoviseModule(self._part.filename) self._part.filename = self._geo.gridPath() def _initData(self, name): if name in self._dataFileNames: if not name in self._data: self._data[name] = RWCoviseModule(self._dataFileNames[name]) self._dataFileNames[name] = self._data[name].gridPath() self.__dataConnectionPoints[name] = self._data[ name].connectionPoint() def _initOct(self): self._initGeo() if self._oct == None: # create or use disk-cached octtrees if enableCachedOctTrees == True and self._dim == 3: basename, extension = os.path.splitext(self._part.filename) self._octTreeFileName = basename + ".octtree" + extension print("self._octTreeFileName = ", self._octTreeFileName) if os.path.isfile(self._octTreeFileName) == False: # create disk-cached octtree self._octTreeFileExists = False self._oct = MakeOctTree() theNet().add(self._oct) self._octIn = ConnectionPoint(self._oct, 'inGrid') self._octOut = ConnectionPoint(self._oct, 'outOctTree') connect(self.geoConnectionPoint(), self._octIn) # connect RWCovise to MakeOctTree self._octTreeWriter = RWCovise() # writable theNet().add(self._octTreeWriter) self._octTreeWriter.set_grid_path(self._octTreeFileName) connect(self._octOut, ConnectionPoint(self._octTreeWriter, 'mesh_in')) else: # use disk-cached octtree self._octTreeFileExists = True self._oct = RWCovise() theNet().add(self._oct) self._oct.set_grid_path(self._octTreeFileName) # cached octtrees must never get an input connection (RWCovise!) self._octIn = None # ConnectionPoint(self._oct, 'mesh_in') self._octOut = ConnectionPoint(self._oct, 'mesh') else: self._oct = MakeOctTree() theNet().add(self._oct) self._octIn = ConnectionPoint(self._oct, 'inGrid') self._octOut = ConnectionPoint(self._oct, 'outOctTree') connect(self.geoConnectionPoint(), self._octIn) else: if enableCachedOctTrees == True and self._octTreeFileExists == True: # no reconnect necessary, if using disk-cached octtree pass else: # reconnect OctTree theNet().disconnectAllFromModulePort(self._oct, 'inGrid') connect(self.geoConnectionPoint(), self._octIn) """ ------------------------ """ """ connection points """ """ ------------------------ """ def geoConnectionPoint(self): # print("ImportModule::geoConnectionPoint() called") self._initGeo() return self._geo.connectionPoint() def dataConnectionPoint(self, name): if name in self._dataFileNames: self._initData(name) #return self._data[name].connectionPoint() return self.__dataConnectionPoints[name] return None def octTreeConnectionPoint(self): self._initOct() return self._octOut def boundingBoxConnectionPoint(self): self.getBox() return ConnectionPoint(self._bb, 'GridOut0') """ ------------------------ """ """ execution methods """ """ ------------------------ """ def execute(self): self.executeGeo() self.executeOct() for name in self._data: self.executeData(name) def executeGeo(self): self._initGeo() if not self._part.filename in self._files_loaded: _infoer.function = str(self.executeGeo) _infoer.write("Loading file " + self._part.filename) self._geo.execute() self._files_loaded.append(self._part.filename) return True return False def executeData(self, name): # print("ImportModule::executeData() called") _infoer.function = str(self.executeGeo) _infoer.write("Load request for " + name) if name in self._dataFileNames: self._initData(name) if not self._dataFileNames[name] in self._files_loaded: _infoer.write("Loading " + self._dataFileNames[name]) self._data[name].execute() self._files_loaded.append(self._dataFileNames[name]) return True else: # print("Import Module: no variable called %s in part %s " % ( name, self._name )) assert False _infoer.write("Returning False") return False def executeOct(self): self._initOct() if not self._oct_ready: if enableCachedOctTrees == True and self._octTreeFileExists == True: # cached octtrees aren't connected to the geo-RWCovise saveExecute(self._oct) elif not self.executeGeo(): saveExecute(self._oct) self._oct_ready = True return True return False def reloadGeo(self): if not self.executeGeo(): self._geo.execute() """ ------------------------ """ """ delete """ """ ------------------------ """ def delete(self): if hasattr(self, "_geo") and self._geo: self._geo.remove() if hasattr(self, "_data"): for module in self._data.values(): module.remove() if hasattr(self, "_oct") and self._oct: theNet().remove(self._oct) if hasattr(self, "_octTreeWriter") and self._octTreeWriter: theNet().remove(self._octTreeWriter) if hasattr(self, "_bb") and self._bb: theNet().remove(self._bb) if hasattr(self, "_ImportModule__bbFromGeoRWCovise" ) and self.__bbFromGeoRWCovise: theNet().remove(self.__bbFromGeoRWCovise) if hasattr(self, "_minMax") and self._minMax: theNet().remove(self._minMax) """ ------------------------ """ """ read private variables """ """ ------------------------ """ def getDimension(self): return self._dim def getName(self): return self._name def getParts(self): return [self._part] def getPartCase(self): return self._part def getBoxFromGeoRWCovise(self): """ return the bounding box from the originally unfiltered geometry """ if self.__boundingBoxFromGeoRWCovise == None: self.__bbFromGeoRWCovise = BoundingBox() theNet().add(self.__bbFromGeoRWCovise) connect(self._geo.connectionPoint(), ConnectionPoint(self.__bbFromGeoRWCovise, 'GridIn0')) # Clear info queue so we dont read a previous BB output. # (If something goes wrong with the queue, this could be the reason.) coviseStartup.globalReceiverThread.infoQueue_.clear() saveExecute(self.__bbFromGeoRWCovise) boxParser = BoundingBoxParser() boxParser.parseQueue(coviseStartup.globalReceiverThread.infoQueue_) self.__boundingBoxFromGeoRWCovise = boxParser.getBox() return self.__boundingBoxFromGeoRWCovise def getBox(self, execute=False): """ return the bounding box """ if self._bb == None: self._bb = BoundingBox() theNet().add(self._bb) connect(self.geoConnectionPoint(), ConnectionPoint(self._bb, 'GridIn0')) # Clear info queue so we dont read a previous BB output. # (If something goes wrong with the queue, this could be the reason.) coviseStartup.globalReceiverThread.infoQueue_.clear() if not self.executeGeo(): saveExecute(self._bb) boxParser = BoundingBoxParser() boxParser.parseQueue(coviseStartup.globalReceiverThread.infoQueue_) self._boundingBox = boxParser.getBox() self._numTimeSteps = boxParser.getNumTimeSteps() elif execute: theNet().disconnectAllFromModule(self._bb) connect(self.geoConnectionPoint(), ConnectionPoint(self._bb, 'GridIn0')) # Clear info queue so we dont read a previous BB output. # (If something goes wrong with the queue, this could be the reason.) coviseStartup.globalReceiverThread.infoQueue_.clear() if not self.executeGeo(): saveExecute(self._bb) boxParser = BoundingBoxParser() boxParser.parseQueue(coviseStartup.globalReceiverThread.infoQueue_) try: oldbb = self._boundingBox self._boundingBox = boxParser.getBox() #self._numTimeSteps = boxParser.getNumTimeSteps() except (ValueError): self._boundingBox = oldbb if self._bb != None: theNet().disconnectAllFromModulePort(self._bb, 'GridIn0') connect(self.geoConnectionPoint(), ConnectionPoint(self._bb, 'GridIn0')) return self._boundingBox def getNumTimeSteps(self): if not self._numTimeSteps: self.getBox() return self._numTimeSteps def getDataMinMax(self, variable): """ return min and max value of variable """ if variable == None: return if self._minMax == None: self._minMax = Colors() theNet().add(self._minMax) theNet().disconnectAllFromModulePort(self._minMax, 'DataIn0') connect(self.dataConnectionPoint(variable), ConnectionPoint(self._minMax, 'DataIn0')) if not self.executeData(variable): saveExecute(self._minMax) return ( float(self._minMax.getParamValue('MinMax')[0]),\ float(self._minMax.getParamValue('MinMax')[1]) ) def getIsTransient(self): return self._isTransient """ ------------------------ """ """ return status string """ """ ------------------------ """ def __str__(self): string = 'Status of ' + self._name + '\n' for v in self._part.variables: string = string + v.name + '\n' return string def getCoObjName(self): if not self._geo == None: return self._geo.getCoObjName()
def _initGeo(self): if self._geo == None: self._geo = RWCoviseModule(self._part.filename) self._part.filename = self._geo.gridPath()
class ImportModule(object): def __init__(self, dimension, partcase ): global testPath self._dim = dimension self._name = partcase.name self._part = partcase # Module Classes holding geo, oct and data self._geo = None self._data = {} self._oct = None # list of loaded files self._files_loaded = [] self._oct_ready = False self._octTreeFileName = None self._octTreeFileExists = False self._octTreeWriter = None # RWCovise to write out octtree # mapping variable name to filename and filetype self._dataFileNames = {} self._dataVariableType = {} self.__dataConnectionPoints = {} # bounding box module and content self._bb = None self._boundingBox = None self._numTimeSteps = None # bounding box module and content from unfiltered geometry self.__bbFromGeoRWCovise = None # the module self.__boundingBoxFromGeoRWCovise = None # the AABB # colors module to calculate min/max self._minMax = None def readPartcase(self): varNotFound = [] for v in self._part.variables: if getExistingFilename(v.filename) == None: self._part.variables.remove(v) varNotFound.append( v.filename ) else: self._dataFileNames[ v.name ] = v.filename self._dataVariableType[ v.name ] = v.variableDimension # check if file is transient self._isTransient = False filename = getExistingFilename(self._part.filename) if filename == None: raise CoviseFileNotFoundError(self._part.filename) in_file = open(filename, "rb") # open in binary mode (makes a difference on windows (read() may stop too early)) # first check if we have TIMESTEP at the end in_file.seek(-100, os.SEEK_END) tail = in_file.read(100) if b"TIMESTEP" in tail: self._isTransient = True else: # if not already recognized as transient, check if we have SETELE at the beginning head = in_file.read(100) if b"SETELE" in head: # if we have, check the entire file since we might have nested sets in_file.seek(0, os.SEEK_BEGIN) line = in_file.readline() while line: if b"TIMESTEP" in line: self._isTransient = True break line = in_file.readline() in_file.close() return varNotFound """ ------------------------ """ """ init by starting modules """ """ ------------------------ """ def _initGeo(self): if self._geo==None: self._geo = RWCoviseModule(self._part.filename) self._part.filename = self._geo.gridPath() def _initData(self, name): if name in self._dataFileNames: if not name in self._data: self._data[name] = RWCoviseModule( self._dataFileNames[name] ) self._dataFileNames[name] = self._data[name].gridPath() self.__dataConnectionPoints[name] = self._data[name].connectionPoint() def _initOct(self): self._initGeo() if self._oct==None: # create or use disk-cached octtrees if enableCachedOctTrees == True and self._dim == 3: basename, extension = os.path.splitext(self._part.filename) self._octTreeFileName = basename + ".octtree" + extension print("self._octTreeFileName = ", self._octTreeFileName) if os.path.isfile(self._octTreeFileName) == False: # create disk-cached octtree self._octTreeFileExists = False self._oct = MakeOctTree() theNet().add(self._oct) self._octIn = ConnectionPoint( self._oct, 'inGrid' ) self._octOut = ConnectionPoint( self._oct, 'outOctTree' ) connect( self.geoConnectionPoint(), self._octIn ) # connect RWCovise to MakeOctTree self._octTreeWriter = RWCovise() # writable theNet().add(self._octTreeWriter) self._octTreeWriter.set_grid_path(self._octTreeFileName) connect(self._octOut, ConnectionPoint(self._octTreeWriter, 'mesh_in')) else: # use disk-cached octtree self._octTreeFileExists = True self._oct = RWCovise() theNet().add(self._oct) self._oct.set_grid_path(self._octTreeFileName) # cached octtrees must never get an input connection (RWCovise!) self._octIn = None # ConnectionPoint(self._oct, 'mesh_in') self._octOut = ConnectionPoint(self._oct, 'mesh') else: self._oct = MakeOctTree() theNet().add(self._oct) self._octIn = ConnectionPoint( self._oct, 'inGrid' ) self._octOut = ConnectionPoint( self._oct, 'outOctTree' ) connect( self.geoConnectionPoint(), self._octIn ) else: if enableCachedOctTrees == True and self._octTreeFileExists == True: # no reconnect necessary, if using disk-cached octtree pass else: # reconnect OctTree theNet().disconnectAllFromModulePort(self._oct, 'inGrid') connect(self.geoConnectionPoint(), self._octIn) """ ------------------------ """ """ connection points """ """ ------------------------ """ def geoConnectionPoint(self): # print("ImportModule::geoConnectionPoint() called") self._initGeo() return self._geo.connectionPoint() def dataConnectionPoint(self, name ): if name in self._dataFileNames: self._initData(name) #return self._data[name].connectionPoint() return self.__dataConnectionPoints[name] return None def octTreeConnectionPoint(self): self._initOct() return self._octOut def boundingBoxConnectionPoint(self): self.getBox() return ConnectionPoint(self._bb, 'GridOut0' ) """ ------------------------ """ """ execution methods """ """ ------------------------ """ def execute(self): self.executeGeo() self.executeOct() for name in self._data: self.executeData(name) def executeGeo(self): self._initGeo() if not self._part.filename in self._files_loaded: _infoer.function = str(self.executeGeo) _infoer.write("Loading file " + self._part.filename) self._geo.execute() self._files_loaded.append(self._part.filename) return True return False def executeData( self, name ): # print("ImportModule::executeData() called") _infoer.function = str(self.executeGeo) _infoer.write("Load request for " + name) if name in self._dataFileNames: self._initData(name) if not self._dataFileNames[name] in self._files_loaded: _infoer.write("Loading " + self._dataFileNames[name]) self._data[name].execute() self._files_loaded.append(self._dataFileNames[name]) return True else : # print("Import Module: no variable called %s in part %s " % ( name, self._name )) assert False _infoer.write("Returning False") return False def executeOct(self): self._initOct() if not self._oct_ready: if enableCachedOctTrees == True and self._octTreeFileExists == True: # cached octtrees aren't connected to the geo-RWCovise saveExecute(self._oct) elif not self.executeGeo(): saveExecute(self._oct) self._oct_ready = True return True return False def reloadGeo(self): if not self.executeGeo(): self._geo.execute() """ ------------------------ """ """ delete """ """ ------------------------ """ def delete(self): if hasattr(self, "_geo") and self._geo: self._geo.remove() if hasattr(self, "_data"): for module in self._data.values(): module.remove() if hasattr(self, "_oct") and self._oct: theNet().remove(self._oct) if hasattr(self, "_octTreeWriter") and self._octTreeWriter: theNet().remove(self._octTreeWriter) if hasattr(self, "_bb") and self._bb: theNet().remove(self._bb) if hasattr(self, "_ImportModule__bbFromGeoRWCovise") and self.__bbFromGeoRWCovise: theNet().remove(self.__bbFromGeoRWCovise) if hasattr(self, "_minMax") and self._minMax: theNet().remove(self._minMax) """ ------------------------ """ """ read private variables """ """ ------------------------ """ def getDimension(self): return self._dim def getName(self): return self._name def getParts(self): return [self._part] def getPartCase(self): return self._part def getBoxFromGeoRWCovise(self): """ return the bounding box from the originally unfiltered geometry """ if self.__boundingBoxFromGeoRWCovise == None: self.__bbFromGeoRWCovise = BoundingBox() theNet().add(self.__bbFromGeoRWCovise) connect( self._geo.connectionPoint(), ConnectionPoint(self.__bbFromGeoRWCovise, 'GridIn0')) # Clear info queue so we dont read a previous BB output. # (If something goes wrong with the queue, this could be the reason.) coviseStartup.globalReceiverThread.infoQueue_.clear() saveExecute(self.__bbFromGeoRWCovise) boxParser = BoundingBoxParser() boxParser.parseQueue(coviseStartup.globalReceiverThread.infoQueue_) self.__boundingBoxFromGeoRWCovise = boxParser.getBox() return self.__boundingBoxFromGeoRWCovise def getBox(self, execute = False): """ return the bounding box """ if self._bb==None: self._bb = BoundingBox() theNet().add( self._bb) connect( self.geoConnectionPoint(), ConnectionPoint( self._bb, 'GridIn0' ) ) # Clear info queue so we dont read a previous BB output. # (If something goes wrong with the queue, this could be the reason.) coviseStartup.globalReceiverThread.infoQueue_.clear() if not self.executeGeo(): saveExecute(self._bb) boxParser = BoundingBoxParser() boxParser.parseQueue(coviseStartup.globalReceiverThread.infoQueue_) self._boundingBox = boxParser.getBox() self._numTimeSteps = boxParser.getNumTimeSteps() elif execute: theNet().disconnectAllFromModule(self._bb) connect( self.geoConnectionPoint(), ConnectionPoint( self._bb, 'GridIn0' ) ) # Clear info queue so we dont read a previous BB output. # (If something goes wrong with the queue, this could be the reason.) coviseStartup.globalReceiverThread.infoQueue_.clear() if not self.executeGeo(): saveExecute(self._bb) boxParser = BoundingBoxParser() boxParser.parseQueue(coviseStartup.globalReceiverThread.infoQueue_) try: oldbb = self._boundingBox self._boundingBox = boxParser.getBox() #self._numTimeSteps = boxParser.getNumTimeSteps() except (ValueError): self._boundingBox = oldbb if self._bb != None: theNet().disconnectAllFromModulePort(self._bb, 'GridIn0') connect( self.geoConnectionPoint(), ConnectionPoint( self._bb, 'GridIn0' ) ) return self._boundingBox def getNumTimeSteps(self): if not self._numTimeSteps: self.getBox() return self._numTimeSteps def getDataMinMax( self, variable): """ return min and max value of variable """ if variable==None: return if self._minMax==None: self._minMax = Colors() theNet().add(self._minMax) theNet().disconnectAllFromModulePort( self._minMax, 'DataIn0' ) connect(self.dataConnectionPoint(variable), ConnectionPoint(self._minMax, 'DataIn0')) if not self.executeData( variable ): saveExecute(self._minMax) return ( float(self._minMax.getParamValue('MinMax')[0]),\ float(self._minMax.getParamValue('MinMax')[1]) ) def getIsTransient(self): return self._isTransient """ ------------------------ """ """ return status string """ """ ------------------------ """ def __str__(self): string = 'Status of ' + self._name + '\n' for v in self._part.variables: string = string + v.name + '\n' return string def getCoObjName(self): if not self._geo==None: return self._geo.getCoObjName()
def _initGeo(self): if self._geo==None: self._geo = RWCoviseModule(self._part.filename) self._part.filename = self._geo.gridPath()
class VisItem(coKeydObject): """ a visitem gets its input from an importModule and gives a geometry object out which is connected to the COVER """ def __init__(self, typeNr, name='VisItem'): coKeydObject.__init__(self, typeNr, name) self.__init() self.importModule = None def __init(self): # key which is defined by COVER self.covise_key = 'No key' # the module that can check if a covise_key is created by this VisItem self.__creationModule = None # the module that writes the covise object into a file for testing self.__debugRwModule = None # register ui action Neg2Gui.theNegMsgHandler().registerVisItem(self) def recreate(self, negMsgHandler, parentKey, offset): VisItemParams.mergeDefaultParams( self.params) # explicitly call mergeDefaultParams of this class self.__init() coKeydObject.recreate(self, negMsgHandler, parentKey, offset) def registerCOVISEkey(self, covise_key): """ check if object name was created by this visItem and if yes store it """ if not self.__creationModule == None: if self.createdKey(covise_key): firstTime = not self.keyRegistered() self.covise_key = covise_key self.sendVisibility() self.sendCaseName() self.sendCaseTransform() self.sendName() return (True, firstTime) return (False, False) def keyRegistered(self): if self.covise_key == 'No key': return False return True def __getCaseName(self): caseName = None key = self.parentKey #for i in range(3): while key >= 0 and caseName == None: parent = globalKeyHandler().getObject(key) if isinstance(parent, coCaseMgr.coCaseMgr): caseName = parent.params.name else: key = parent.parentKey return caseName def getCoObjName(self): return self.importModule.getCoObjName() def createdKey(self, key): importKey = self.getCoObjName() _infoer.function = str(self.createdKey) _infoer.write("check my key %s against COVER key %s" % (importKey, key)) posCover = key.find("(") posImport = importKey.find("OUT") # if the beginning of my key and COVER key are equal, dann the key exists return (importKey[0:posImport - 1] == key[0:posCover]) def sendVisibility(self): """ send visibility msg to cover """ if not self.covise_key == 'No key': msg = coGRObjVisMsg(coGRMsg.GEO_VISIBLE, self.covise_key, self.params.isVisible) covise.sendRendMsg(msg.c_str()) def sendName(self): """ send name of the VisItem to cover """ if not self.covise_key == 'No key': msg = coGRObjSetNameMsg(coGRMsg.SET_NAME, self.covise_key, str(self.params.name)) covise.sendRendMsg(msg.c_str()) def sendCaseName(self): """ send visibility msg to cover """ if not self.covise_key == 'No key': caseName = self.__getCaseName() if caseName: msg = coGRObjSetCaseMsg(coGRMsg.SET_CASE, self.covise_key, caseName) covise.sendRendMsg(msg.c_str()) def sendCaseTransform(self): """ send case transformation to COVER """ key = self.parentKey sentMatrix = False while key >= 0 and not sentMatrix: parent = globalKeyHandler().getObject(key) if isinstance(parent, coCaseMgr.coCaseMgr): # send transformation matrix for this visItem parent._sendMatrix() sentMatrix = True else: key = parent.parentKey def reconnect(self): coKeydObject.reconnect(self) if self.__creationModule: self.connectToCover(self.__creationModule) def connectToCover(self, visConnectionModule): self.__creationModule = visConnectionModule VRPCoviseNetAccess.connect(visConnectionModule.connectionPoint(), globalRenderer().connectionPoint()) if os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR'): #filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' + self.params.name + "_%s.covise" % self.key #rw = RWCoviseModule(filename, True) #filename = rw.gridPath() #connect( visConnectionModule.connectionPoint(), rw.inConnectionPoint() ) filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' \ + self.params.name + "_" + str(self.key) + ".covise" self.__debugRwModule = RWCoviseModule(filename, True) connect(visConnectionModule.connectionPoint(), self.__debugRwModule.inConnectionPoint()) def disconnectFromCover(self, visConnectionModule): coverModule = globalRenderer().connectionPoint().module visItemModule = visConnectionModule.connectionPoint().module theNet().disconnectModuleModule(coverModule, visItemModule) def delete(self, isInitialized, negMsgHandler=None): if isInitialized: if os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') and hasattr( self, '_VisItem__debugRwModule') and self.__debugRwModule: self.__debugRwModule.remove() return coKeydObject.delete(self, isInitialized, negMsgHandler) def setImport(self, group): self.importModule = group def setParams(self, params, negMsgHandler=None, sendToCover=True): visibility_changed = (params.isVisible != self.params.isVisible) self.params.isVisible = params.isVisible # check if params contains more than isVisible if issubclass(params.__class__, VisItemParams): name_changed = (params.name != self.params.name) coKeydObject.setParams(self, params) if name_changed: self.sendName() if visibility_changed: self.sendVisibility() def sendParams(self): """ send Params to Gui """ Neg2Gui.theNegMsgHandler().sendParams(self.key, self.params) def recvParams(self, isVisible): self.params.isVisible = isVisible self.sendParams() def updateDebugFilename(self, PresentationStepKey): if hasattr(self, '_VisItem__debugRwModule') and self.__debugRwModule: filename = os.getenv('VR_PREPARE_DEBUG_VISITEMS_DIR') + '/' \ + 'STEP' + str(PresentationStepKey) + "_" \ + self.params.name + "_" + str(self.key) + ".covise" self.__debugRwModule.setGridPath(filename, True)