os.mkdir(os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir) except: pass shutil.copy(theCoCaseFileName, os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir + '/.') # get all used .covise filenames from the cocase coviseFileNames = [] for item in cocase.items_: coviseFileNames.append(item.geometryFileName_) for var in item.variables_: coviseFileNames.append(os.path.basename(var[1])) # do the reducing i = 1 for coviseFileName in coviseFileNames: theRCovise.set_grid_path( os.path.dirname(theCoCaseFileName) + '/' + coviseFileName) theWCovise.set_grid_path( os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir + '/' + coviseFileName) print(i, "/", len(coviseFileNames), ": ", coviseFileName) theRCovise.execute() theNet.finishedBarrier() i += 1 sys.exit()
cocase = pickle.load(inputFile) inputFile.close() try: os.mkdir(os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir) except: pass shutil.copy(theCoCaseFileName, os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir + '/.') i = 1 for item in cocase.items_: print(i, "/", len(cocase.items_), ":", item.geometryFileName_) if (item.dimensionality_ == GEOMETRY_2D): print("CONVERTING") theGridRCovise.set_grid_path( os.path.dirname(theCoCaseFileName) + '/' + item.geometryFileName_) theGridWCovise.set_grid_path( os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir + '/' + item.geometryFileName_) theNet.connect(theGridRCovise, 'mesh', theSimplify, 'meshIn') theNet.connect(theSimplify, 'meshOut', theGridWCovise, 'mesh_in') if (len(item.variables_) == 0): theGridRCovise.execute() theNet.finishedBarrier() else: theNet.connect(theDataRCovise, 'mesh', theSimplify, 'dataIn_0') theNet.connect(theSimplify, 'dataOut_0', theDataWCovise, 'mesh_in') firstRun = True for var in item.variables_: theDataRCovise.set_grid_path( os.path.dirname(theCoCaseFileName) + '/' +
inputFile = open(theCoCaseFileName, "rb") cocase = pickle.load(inputFile) inputFile.close() try: os.mkdir(os.path.dirname(theCoCaseFileName) + "/" + theOutputSubDir) except: pass shutil.copy(theCoCaseFileName, os.path.dirname(theCoCaseFileName) + "/" + theOutputSubDir + "/.") i = 1 for item in cocase.items_: print(i, "/", len(cocase.items_), ":", item.geometryFileName_) if item.dimensionality_ == GEOMETRY_2D: print("CONVERTING") theGridRCovise.set_grid_path(os.path.dirname(theCoCaseFileName) + "/" + item.geometryFileName_) theGridWCovise.set_grid_path( os.path.dirname(theCoCaseFileName) + "/" + theOutputSubDir + "/" + item.geometryFileName_ ) theNet.connect(theGridRCovise, "mesh", theSimplify, "meshIn") theNet.connect(theSimplify, "meshOut", theGridWCovise, "mesh_in") if len(item.variables_) == 0: theGridRCovise.execute() theNet.finishedBarrier() else: theNet.connect(theDataRCovise, "mesh", theSimplify, "dataIn_0") theNet.connect(theSimplify, "dataOut_0", theDataWCovise, "mesh_in") firstRun = True for var in item.variables_: theDataRCovise.set_grid_path(os.path.dirname(theCoCaseFileName) + "/" + os.path.basename(var[1])) theDataWCovise.set_grid_path(
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()
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()
try: os.mkdir(os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir) except: pass shutil.copy(theCoCaseFileName, os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir + '/.') # get all used .covise filenames from the cocase coviseFileNames = [] for item in cocase.items_: coviseFileNames.append(item.geometryFileName_) for var in item.variables_: coviseFileNames.append(os.path.basename(var[1])) # do the reducing i = 1 for coviseFileName in coviseFileNames: theRCovise.set_grid_path(os.path.dirname(theCoCaseFileName) + '/' + coviseFileName) theWCovise.set_grid_path(os.path.dirname(theCoCaseFileName) + '/' + theOutputSubDir + '/' + coviseFileName) print(i, "/", len(coviseFileNames), ": ", coviseFileName) theRCovise.execute() theNet.finishedBarrier() i += 1 sys.exit()
class CoviseVis(VisItem): """ VisItem to show an covise object """ def __init__(self): VisItem.__init__(self, VIS_COVISE, self.__class__.__name__) self.params = CoviseVisParams() self.params.isVisible = True self.__initBase() def __initBase(self): _infoer.function = str(self.__initBase) _infoer.write(" ") self.rwCovise = None self.__connected = False self.__registered = False self.__loaded = None def __init(self, negMsgHandler): """called from __update start rwCovise and connects to COVER send params to GUI""" _infoer.function = str(self.__init) _infoer.write(" ") if self.rwCovise == None: self.rwCovise = RWCovise() theNet().add(self.rwCovise) VisItem.connectToCover(self, self) self.__connected = True def __update(self, negMsgHandler): """ __update is called from the run method to update the module parameter before execution + update module parameters """ _infoer.function = str(self.__update) _infoer.write(" ") self.__init(negMsgHandler) #update params # check if filename exists if getExistingFilename(self.params.filename) == None: raise IOError(self.params.filename) """ fn = os.path.basename(filename) # if a path allready was selected if not _newPath == None: fname = VRPCoviseNetAccess._newPath + fn # test new path if not os.access(fname, os.R_OK): filename = VRPCoviseNetAccess.changePath(filename, fn) else: filename = fname else: filename = VRPCoviseNetAccess.changePath(filename , fn) """ self.rwCovise.set_grid_path(self.params.filename) self.rwCovise.set_stepNo(self.params.stepNo) if (self.params.rotate_output == True): self.rwCovise.set_rotate_output('TRUE') else: self.rwCovise.set_rotate_output('FALSE') self.rwCovise.set_rotation_axis(self.params.rotation_axis) self.rwCovise.set_rot_speed(self.params.rot_speed) def createdKey(self, key): """ called during registration if key received from COVER """ _infoer.function = str(self.createdKey) _infoer.write("%s, %s" % (key, self.rwCovise.getCoObjName('mesh'))) importKey = self.rwCovise.getCoObjName('mesh') posCover = key.find("(") posImport = importKey.find("OUT") return (importKey[0:posImport - 1] == key[0:posCover]) def connectionPoint(self): """ return the object to be displayed called by the class VisItem """ if self.rwCovise: return ConnectionPoint(self.rwCovise, 'mesh') def recreate(self, negMsgHandler, parentKey, offset): self.__initBase() VisItem.recreate(self, negMsgHandler, parentKey, offset) def run(self, runmode, negMsgHandler=None): if runmode == RUN_ALL: _infoer.function = str(self.run) _infoer.write("go") self.__update(negMsgHandler) if not self.__connected: VisItem.connectToCover(self, self) self.__connected = True if self.__loaded == None or self.__loaded != self.params.filename: saveExecute(self.rwCovise) self.__loaded = self.params.filename def __register(self, negMsgHandler): """ register to receive events from covise """ if negMsgHandler and self.rwCovise: if not self.__registered: mL = [] mL.append(self.rwCovise) negMsgHandler.registerCopyModules(mL, self) paramList = [ 'grid_path', 'stepNo', 'rotate_output', 'rot_speed' ] negMsgHandler.registerParamsNotfier(self.rwCovise, self.key, paramList) self.__registered = True def setParams(self, params, negMsgHandler=None, sendToCover=True): """ set parameters from outside """ _infoer.function = str(self.setParams) _infoer.write("setParams") VisItem.setParams(self, params) def delete(self, isInitialized, negMsgHandler=None): ''' delete this CoviseVis: remove the module ''' _infoer.function = str(self.delete) _infoer.write(" ") if isInitialized: theNet().remove(self.rwCovise) VisItem.delete(self, isInitialized, negMsgHandler)
class Ensight2CoviseGui(Ensight2CoviseGuiBase): def __init__(self): #print "Ensight2CoviseGui.__init__" # init base class Ensight2CoviseGuiBase.__init__(self, None) # connect buttons self.outputDirLineEdit.returnPressed.connect(self.setOutputDir) self.byteswapped.stateChanged.connect(self.setByteswap) self.startConversionPushButton.clicked.connect(self.startConversion) # initialize output directory InitialDatasetSearchPath = covise.getCoConfigEntry("vr-prepare.InitialDatasetSearchPath") if not InitialDatasetSearchPath: InitialDatasetSearchPath = os.getcwd() self.currentFilePath = InitialDatasetSearchPath self.scale = 1.0 # disable all buttons at beginning self.settingsFrame.setEnabled(False) self.startConversionFrame.setEnabled(False) self.outputDirFrame.setEnabled(False) self.isByteSwapped = True def closeEvent(self, event): covise.clean() covise.quit() def fileOpen(self): #print "Ensight2CoviseGui.fileOpen" fd = QtWidgets.QFileDialog(self) fd.setMinimumWidth(1050) fd.setMinimumHeight(700) fd.setNameFilter('Ensight case File (*.case *.encas *.CASE *.ENCAS)') fd.setWindowTitle('Open Ensight Case File') fd.setDirectory(self.currentFilePath) acceptedOrRejected = fd.exec_() if acceptedOrRejected != QtWidgets.QDialog.Accepted : return filenamesQt = fd.selectedFiles() if filenamesQt.isEmpty(): return self.currentFilePath = os.path.dirname(str(filenamesQt[0])) self.fullEnsightCaseName = str(filenamesQt[0]) # try to open file if not os.access(self.fullEnsightCaseName, os.R_OK): self.statusText.append("ERROR: Could not open file "+self.fullEnsightCaseName+ " - not readable") else: # start modules self.startModules() # disable file open self.fileOpenAction.setEnabled(False) # set output File path self.outputFilePath = self.currentFilePath + "/CoviseDaten/" if os.path.isdir(self.outputFilePath): pass else: try: os.mkdir(self.outputFilePath) except(OSError): self.statusText.append("ERROR: Could not create directory "+str(self.outputFilePath)+" check permissions and enter again or select another directory") self.outputFilePath = None if (self.outputFilePath): self.outputDirLineEdit.setText(self.outputFilePath) # enable all buttons self.outputDirFrame.setEnabled(True) self.startConversionFrame.setEnabled(True) self.settingsFrame.setEnabled(True) def fileExit(self): #print "Ensight2CoviseGui.fileExit" self.close() sys.exit() def setByteswap(self, i): self.isByteSwapped = self.byteswapped.isChecked() def setOutputDir(self): #print "Ensight2CoviseGui.setOutputDir" self.outputFilePath=str(self.outputDirLineEdit.text()) if not os.path.isdir(self.outputFilePath): try: os.mkdir(self.outputFilePath) self.statusText.append("\nINFO: created directory "+self.outputFilePath) except(OSError): self.statusText.append("\nERROR: Could not create directory "+self.outputFilePath+" check permissions and enter again or select another directory") self.outputFilePath = None else: self.statusText.append("\nINFO: directory "+self.outputFilePath+" exists already") def customEvent(self,e): pass def startModules(self): #print "Ensight2CoviseGui.startModules" self.aErrorLogAction = ErrorLogAction() CoviseMsgLoop().register(self.aErrorLogAction) global theNet theNet = net() self.scalarVariables3DGetterAction = ChoiceGetterAction() self.vectorVariables3DGetterAction = ChoiceGetterAction() self.scalarVariables2DGetterAction = ChoiceGetterAction() self.vectorVariables2DGetterAction = ChoiceGetterAction() # MODULE: ReadEnsight self.ReadEnsight_1 = ReadEnsight() theNet.add( self.ReadEnsight_1 ) self.aPartsCollectorAction = PartsCollectorAction() CoviseMsgLoop().register(self.aPartsCollectorAction) # hang in variable-getters self.ReadEnsight_1.addNotifier('data_for_sdata1_3D', self.scalarVariables3DGetterAction) self.ReadEnsight_1.addNotifier('data_for_vdata1_3D', self.vectorVariables3DGetterAction) self.ReadEnsight_1.addNotifier('data_for_sdata1_2D', self.scalarVariables2DGetterAction) self.ReadEnsight_1.addNotifier('data_for_vdata1_2D', self.vectorVariables2DGetterAction) # set parameter values if self.isByteSwapped == True: self.ReadEnsight_1.set_data_byte_swap( "TRUE" ) else: self.ReadEnsight_1.set_data_byte_swap( "FALSE" ) self.ReadEnsight_1.set_case_file( self.fullEnsightCaseName ) self.ReadEnsight_1.set_include_polyhedra( "TRUE") self.ReadEnsight_1.set_enable_autocoloring( "FALSE" ) # wait for choices to be updated self.scalarVariables3DGetterAction.waitForChoices() self.vectorVariables3DGetterAction.waitForChoices() self.scalarVariables2DGetterAction.waitForChoices() self.vectorVariables2DGetterAction.waitForChoices() # wait for the part info message self.aPartsCollectorAction.waitForPartsinfoFinished() # get variables self.scalarVariables3D=self.scalarVariables3DGetterAction.getChoices() self.vectorVariables3D=self.vectorVariables3DGetterAction.getChoices() self.scalarVariables2D=self.scalarVariables2DGetterAction.getChoices() self.vectorVariables2D=self.vectorVariables2DGetterAction.getChoices() text = "Ensight Case File: %s"%(self.fullEnsightCaseName) self.statusText.append(text) self.statusText.append("\n3D parts:") for partid in self.aPartsCollectorAction.getRefNameDict3dParts().keys(): partname = self.aPartsCollectorAction.getRefNameDict3dParts()[partid] text = "\tPart %d = %s"%(partid, partname) self.statusText.append(text) self.statusText.append("3D Part Variables:") for svar in self.scalarVariables3D: text= "\t%s(scalar)"%(svar) self.statusText.append(text) for vvar in self.vectorVariables3D: text= "\t%s(vector)"%(vvar) self.statusText.append(text) self.statusText.append("\n2D parts:") for partid in self.aPartsCollectorAction.getRefNameDict2dParts().keys(): partname = self.aPartsCollectorAction.getRefNameDict2dParts()[partid] text = "\tPart %d = %s"%(partid, partname) self.statusText.append(text) self.statusText.append("2D Part Variables:") for svar in self.scalarVariables2D: text= "\t%s(scalar)"%(svar) self.statusText.append(text) for vvar in self.vectorVariables2D: text= "\t%s(vector)"%(vvar) self.statusText.append(text) QtWidgets.QApplication.processEvents() # MODULE: RWCovise self.RWCovise_1 = RWCovise() theNet.add( self.RWCovise_1 ) self.RWCovise_1.set_stepNo( 0 ) self.RWCovise_1.set_rotate_output( "FALSE" ) self.RWCovise_1.set_rotation_axis( 3 ) self.RWCovise_1.set_rot_speed( 2.000000 ) self.cocase = CoviseCaseFile() cn = os.path.basename(str(self.fullEnsightCaseName)) self.cocasename = cn[0: cn.rfind('.')] def startConversion(self): #print "Ensight2CoviseGui.startConversion" # Module Transform self.scale = float(str(self.leScale.text())) if self.scale != 1: if not hasattr(self, "Transform_1"): self.Transform_1 = Transform() theNet.add( self.Transform_1 ) self.Transform_1.set_Transform( 5 ) self.Transform_1.set_createSet( "FALSE" ) self.Transform_1.set_scaling_factor( self.scale ) self.outputDirFrame.setEnabled(False) self.startConversionFrame.setEnabled(False) self.settingsFrame.setEnabled(False) #self.statusText.clear() text="\nStarting Conversion in %s..."%(self.outputFilePath) self.statusText.append(text) QtWidgets.QApplication.processEvents() self.startConversionOf3DParts() self.startConversionOf2DParts() QtWidgets.QApplication.processEvents() CoviseMsgLoop().unregister(self.aPartsCollectorAction) CoviseMsgLoop().unregister(self.aErrorLogAction) theNet.remove( self.ReadEnsight_1 ) text="\nWriting cocase to file..." self.statusText.append(text) pickleFile = self.outputFilePath + self.cocasename + '.cocase' counter=0 while os.path.isfile(pickleFile): text= "! A file named %s is already available ... trying a new name"%(pickleFile) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter=counter+1 pickleFile = self.outputFilePath + self.cocasename + "_"+str(counter) output = open(pickleFile, 'wb') pickle.dump(self.cocase,output) output.close() text="cocasefile written to %s\n"%(pickleFile,) self.statusText.append(text) QtWidgets.QApplication.processEvents() text="\nConversion finished!" self.statusText.append(text) def startConversionOf3DParts(self): for partid in self.aPartsCollectorAction.getRefNameDict3dParts().keys(): #if int(partid) >= int(self.comboStartId.getCurrentIndex()): # get partname partname = self.aPartsCollectorAction.getRefNameDict3dParts()[partid] text = "\nConverting grid of part %s please be patient..."%(partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() # connect modules if self.scale != 1: theNet.connect( self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in" ) theNet.connect( self.Transform_1, "geo_out", self.RWCovise_1, "mesh_in" ) else: theNet.connect( self.ReadEnsight_1, "geoOut_3D", self.RWCovise_1, "mesh_in" ) # select part self.ReadEnsight_1.set_choose_parts( str(partid) ) # clean partname if "/" in partname: text="! Removing the / in partname = %s\n"%(partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname=partname.replace("/","") # create RW Covise name covisename = self.outputFilePath +partname + "-3D.covise" # check if file is already available #print "rwcovisename=", covisename counter=0 while os.path.isfile(covisename): text= "! A file named %s is already available ... trying a new name"%(covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter=counter+1 covisename = self.outputFilePath + partname + str(counter) + "-3D.covise" QtWidgets.QApplication.processEvents() self.RWCovise_1.set_grid_path( covisename ) QtWidgets.QApplication.processEvents() # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() #theNet.save( "grid.net" ) # write logfile text="Converted grid of part %s to covise file %s"%(partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # create cocase item item3D = CoviseCaseFileItem(partname, GEOMETRY_3D, os.path.basename(covisename)) # disconnect modules if self.scale !=1: theNet.disconnect( self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in" ) theNet.disconnect( self.Transform_1, "geo_out", self.RWCovise_1, "mesh_in" ) else: theNet.disconnect(self. ReadEnsight_1, "geoOut_3D", self.RWCovise_1, "mesh_in" ) QtWidgets.QApplication.processEvents() # scalar variables # connect modules if self.scale!=1: theNet.connect( self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in" ) theNet.connect( self.ReadEnsight_1, "sdata1_3D", self.Transform_1, "data_in0" ) theNet.connect( self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in" ) else: theNet.connect( self.ReadEnsight_1, "sdata1_3D", self.RWCovise_1, "mesh_in" ) # loop over scalar variables choice=1 for svar in self.scalarVariables3D: text= "\nConverting scalar variable %s of part %s, please be patient..."%(svar, partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() # select variable choice+=1 self.ReadEnsight_1.set_data_for_sdata1_3D( choice ) # clean variablename if "/" in svar: text="! Removing the / in svar = %s\n"%(svar,) statusText.append(text) QtWidgets.QApplication.processEvents() svar=svar.replace("/","") # create RWCovise name covisename = self.outputFilePath + partname + "-" + svar + "-3D.covise" # check if file is already available counter=0 while os.path.isfile(covisename): text="! A file named %s is already available ... trying a new name"%(covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter=counter+1 covisename = self.outputFilePath + partname + str(counter) + "-" + svar + "-3D.covise" self.RWCovise_1.set_grid_path( covisename ) QtWidgets.QApplication.processEvents() # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text="Converted scalar variable %s of part %s to file %s"%(svar, partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # add variable to cacase item item3D.addVariableAndFilename(svar, covisename, SCALARVARIABLE) #theNet.save( "scalar.net" ) # disconnect modules if self.scale!=1: theNet.disconnect( self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in" ) theNet.disconnect( self.ReadEnsight_1, "sdata1_3D", self.Transform_1, "data_in0" ) theNet.disconnect( self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in" ) else: theNet.disconnect( self.ReadEnsight_1, "sdata1_3D", self.RWCovise_1, "mesh_in" ) QtWidgets.QApplication.processEvents() # vector variables # connect modules if self.scale!=1: theNet.connect( self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in" ) theNet.connect( self.ReadEnsight_1, "vdata1_3D", self.Transform_1, "data_in0" ) theNet.connect( self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in" ) else: theNet.connect( self.ReadEnsight_1, "vdata1_3D", self.RWCovise_1, "mesh_in" ) # loop over variables choice=1 for vvar in self.vectorVariables3D: text= "\nConverting vector variable %s of part %s, please be patient..."%(vvar, partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() # select variable choice+=1 self.ReadEnsight_1.set_data_for_vdata1_3D( choice ) # clean variablename if "/" in vvar: text="! Removing the / in vvar = %s\n"%(vvar,) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname=partname.replace("/","") # create covisename covisename = self.outputFilePath + partname + "-" + vvar + "-3D.covise" # check if file is already available counter=0 while os.path.isfile(covisename): text="! A file named %s is already available trying a new name"%(covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter=counter+1 covisename = self.outputFilePath + partname + str(counter) + "-" + vvar + "-3D.covise" self.RWCovise_1.set_grid_path( covisename ) # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text="Converted vector variable%s of part %s to file %s"%(vvar,partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # add variable to cocase item item3D.addVariableAndFilename(vvar, covisename, VECTOR3DVARIABLE) # disconnect modules if self.scale!=1: theNet.disconnect( self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in" ) theNet.disconnect( self.ReadEnsight_1, "vdata1_3D", self.Transform_1, "data_in0" ) theNet.disconnect( self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in" ) else: theNet.disconnect( self.ReadEnsight_1, "vdata1_3D",self. RWCovise_1, "mesh_in" ) # add the cocase item to the case file self.cocase.add(item3D) QtWidgets.QApplication.processEvents() def startConversionOf2DParts(self): #print "__________START 2D---------" for partid in self.aPartsCollectorAction.getRefNameDict2dParts().keys(): partname = self.aPartsCollectorAction.getRefNameDict2dParts()[partid] # write logfile text="\nConverting surface of part %s, please be patient..."%(partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() # connect modules if self.scale!=1: theNet.connect( self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in" ) theNet.connect( self.Transform_1, "geo_out", self.RWCovise_1, "mesh_in" ) else: theNet.connect( self.ReadEnsight_1, "geoOut_2D", self.RWCovise_1, "mesh_in" ) # select part self.ReadEnsight_1.set_choose_parts( str(partid) ) # clean partname if "/" in partname: text="! Removing the / in partname = %s\n"%(partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname=partname.replace("/","") # create RWCovise name covisename = self.outputFilePath + partname + "-2D.covise" counter=0 while os.path.isfile(covisename): text="! A file named %s is already available trying a new name"%(covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter=counter+1 covisename = self.outputFilePath + partname + str(counter) + "-2D.covise" self.RWCovise_1.set_grid_path( covisename ) # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text="Converted surface of part %s to file %s"%(partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # create cocase item item2D = CoviseCaseFileItem(partname, GEOMETRY_2D, os.path.basename(covisename)) # disconnect the modules if self.scale !=1: theNet.disconnect( self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in" ) theNet.disconnect( self.Transform_1, "geo_out", self.RWCovise_1, "mesh_in" ) else: theNet.disconnect( self.ReadEnsight_1, "geoOut_2D", self.RWCovise_1, "mesh_in" ) # # scalar variables # # connect modules if self.scale!=1: theNet.connect( self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in" ) theNet.connect( self.ReadEnsight_1, "sdata1_2D", self.Transform_1, "data_in0" ) theNet.connect( self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in" ) else: theNet.connect( self.ReadEnsight_1, "sdata1_2D", self.RWCovise_1, "mesh_in" ) choice=1 for svar in self.scalarVariables2D: # select variable choice+=1 text="\nConverting scalar variable %s of part %s, please be patient..."%(svar, partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() self.ReadEnsight_1.set_data_for_sdata1_2D( choice ) # clean variablename if "/" in partname: text="! Removing the / in partname = %s\n"%(partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname=partname.replace("/","") # create RWCovise name covisename = self.outputFilePath + partname + "-" + svar + "-2D.covise" counter=0 while os.path.isfile(covisename): text="! A file named %s is already available ... trying a new name"%(covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter=counter+1 covisename = self.outputFilePath + partname + str(counter) + "-" + svar + "-2D.covise" self.RWCovise_1.set_grid_path( covisename ) # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text="Converted scalar variable %s of part %s to file %s"%(svar, partname, covisename,) self.statusText.append(text) QtWidgets.QApplication.processEvents() # add variable to cicase item item2D.addVariableAndFilename(svar, covisename, SCALARVARIABLE) # print memory usage of module #os.system('ps aux | grep ReadEnsight_1') # disconnect modules if self.scale!=1: theNet.disconnect( self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in" ) theNet.disconnect( self.ReadEnsight_1, "sdata1_2D", self.Transform_1, "data_in0" ) theNet.disconnect( self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in" ) else: theNet.disconnect( self.ReadEnsight_1, "sdata1_2D", self.RWCovise_1, "mesh_in" ) # vector variables # connect modules if self.scale!=1: theNet.connect( self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in" ) theNet.connect( self.ReadEnsight_1, "vdata1_2D", self.Transform_1, "data_in0" ) theNet.connect( self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in" ) else: theNet.connect( self.ReadEnsight_1, "vdata1_2D", self.RWCovise_1, "mesh_in" ) choice=1 for vvar in self.vectorVariables2D: # select variable choice+=1 text="\nConverting vector variable %s of part %s, please be patient..."%(vvar, partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() self.ReadEnsight_1.set_data_for_vdata1_2D( choice ) # clean partname if "/" in partname: text="! Removing the / in partname = %s\n"%(partname,) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname=partname.replace("/","") # create RWCovise name covisename = self.outputFilePath + partname + "-" + vvar + "-2D.covise" counter=0 while os.path.isfile(covisename): text="! A file named %s is already available ... trying a new name"%(covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter=counter+1 covisename = self.outputFilePath + partname + str(counter) + "-" + vvar + "-2D.covise" self.RWCovise_1.set_grid_path( covisename ) # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text="Converted vector variable%s of part %s to file %s"%(vvar, partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # add varibale to coscase item item2D.addVariableAndFilename(vvar, covisename, VECTOR3DVARIABLE) # disconnect modules if self.scale!=1: theNet.disconnect( self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in" ) theNet.disconnect( self.ReadEnsight_1, "vdata1_2D", self.Transform_1, "data_in0" ) theNet.disconnect( self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in" ) else: theNet.disconnect( self.ReadEnsight_1, "vdata1_2D", self.RWCovise_1, "mesh_in" ) # add the cocase item to the case file self.cocase.add(item2D)
class Ensight2CoviseGui(Ensight2CoviseGuiBase): def __init__(self): #print "Ensight2CoviseGui.__init__" # init base class Ensight2CoviseGuiBase.__init__(self, None) # connect buttons self.outputDirLineEdit.returnPressed.connect(self.setOutputDir) self.byteswapped.stateChanged.connect(self.setByteswap) self.startConversionPushButton.clicked.connect(self.startConversion) # initialize output directory InitialDatasetSearchPath = covise.getCoConfigEntry( "vr-prepare.InitialDatasetSearchPath") if not InitialDatasetSearchPath: InitialDatasetSearchPath = os.getcwd() self.currentFilePath = InitialDatasetSearchPath self.scale = 1.0 # disable all buttons at beginning self.settingsFrame.setEnabled(False) self.startConversionFrame.setEnabled(False) self.outputDirFrame.setEnabled(False) self.isByteSwapped = True def closeEvent(self, event): covise.clean() covise.quit() def fileOpen(self): #print "Ensight2CoviseGui.fileOpen" fd = QtWidgets.QFileDialog(self) fd.setMinimumWidth(1050) fd.setMinimumHeight(700) fd.setNameFilter('Ensight case File (*.case *.encas *.CASE *.ENCAS)') fd.setWindowTitle('Open Ensight Case File') fd.setDirectory(self.currentFilePath) acceptedOrRejected = fd.exec_() if acceptedOrRejected != QtWidgets.QDialog.Accepted: return filenamesQt = fd.selectedFiles() if filenamesQt.isEmpty(): return self.currentFilePath = os.path.dirname(str(filenamesQt[0])) self.fullEnsightCaseName = str(filenamesQt[0]) # try to open file if not os.access(self.fullEnsightCaseName, os.R_OK): self.statusText.append("ERROR: Could not open file " + self.fullEnsightCaseName + " - not readable") else: # start modules self.startModules() # disable file open self.fileOpenAction.setEnabled(False) # set output File path self.outputFilePath = self.currentFilePath + "/CoviseDaten/" if os.path.isdir(self.outputFilePath): pass else: try: os.mkdir(self.outputFilePath) except (OSError): self.statusText.append( "ERROR: Could not create directory " + str(self.outputFilePath) + " check permissions and enter again or select another directory" ) self.outputFilePath = None if (self.outputFilePath): self.outputDirLineEdit.setText(self.outputFilePath) # enable all buttons self.outputDirFrame.setEnabled(True) self.startConversionFrame.setEnabled(True) self.settingsFrame.setEnabled(True) def fileExit(self): #print "Ensight2CoviseGui.fileExit" self.close() sys.exit() def setByteswap(self, i): self.isByteSwapped = self.byteswapped.isChecked() def setOutputDir(self): #print "Ensight2CoviseGui.setOutputDir" self.outputFilePath = str(self.outputDirLineEdit.text()) if not os.path.isdir(self.outputFilePath): try: os.mkdir(self.outputFilePath) self.statusText.append("\nINFO: created directory " + self.outputFilePath) except (OSError): self.statusText.append( "\nERROR: Could not create directory " + self.outputFilePath + " check permissions and enter again or select another directory" ) self.outputFilePath = None else: self.statusText.append("\nINFO: directory " + self.outputFilePath + " exists already") def customEvent(self, e): pass def startModules(self): #print "Ensight2CoviseGui.startModules" self.aErrorLogAction = ErrorLogAction() CoviseMsgLoop().register(self.aErrorLogAction) global theNet theNet = net() self.scalarVariables3DGetterAction = ChoiceGetterAction() self.vectorVariables3DGetterAction = ChoiceGetterAction() self.scalarVariables2DGetterAction = ChoiceGetterAction() self.vectorVariables2DGetterAction = ChoiceGetterAction() # MODULE: ReadEnsight self.ReadEnsight_1 = ReadEnsight() theNet.add(self.ReadEnsight_1) self.aPartsCollectorAction = PartsCollectorAction() CoviseMsgLoop().register(self.aPartsCollectorAction) # hang in variable-getters self.ReadEnsight_1.addNotifier('data_for_sdata1_3D', self.scalarVariables3DGetterAction) self.ReadEnsight_1.addNotifier('data_for_vdata1_3D', self.vectorVariables3DGetterAction) self.ReadEnsight_1.addNotifier('data_for_sdata1_2D', self.scalarVariables2DGetterAction) self.ReadEnsight_1.addNotifier('data_for_vdata1_2D', self.vectorVariables2DGetterAction) # set parameter values if self.isByteSwapped == True: self.ReadEnsight_1.set_data_byte_swap("TRUE") else: self.ReadEnsight_1.set_data_byte_swap("FALSE") self.ReadEnsight_1.set_case_file(self.fullEnsightCaseName) self.ReadEnsight_1.set_include_polyhedra("TRUE") self.ReadEnsight_1.set_enable_autocoloring("FALSE") # wait for choices to be updated self.scalarVariables3DGetterAction.waitForChoices() self.vectorVariables3DGetterAction.waitForChoices() self.scalarVariables2DGetterAction.waitForChoices() self.vectorVariables2DGetterAction.waitForChoices() # wait for the part info message self.aPartsCollectorAction.waitForPartsinfoFinished() # get variables self.scalarVariables3D = self.scalarVariables3DGetterAction.getChoices( ) self.vectorVariables3D = self.vectorVariables3DGetterAction.getChoices( ) self.scalarVariables2D = self.scalarVariables2DGetterAction.getChoices( ) self.vectorVariables2D = self.vectorVariables2DGetterAction.getChoices( ) text = "Ensight Case File: %s" % (self.fullEnsightCaseName) self.statusText.append(text) self.statusText.append("\n3D parts:") for partid in self.aPartsCollectorAction.getRefNameDict3dParts().keys( ): partname = self.aPartsCollectorAction.getRefNameDict3dParts( )[partid] text = "\tPart %d = %s" % (partid, partname) self.statusText.append(text) self.statusText.append("3D Part Variables:") for svar in self.scalarVariables3D: text = "\t%s(scalar)" % (svar) self.statusText.append(text) for vvar in self.vectorVariables3D: text = "\t%s(vector)" % (vvar) self.statusText.append(text) self.statusText.append("\n2D parts:") for partid in self.aPartsCollectorAction.getRefNameDict2dParts().keys( ): partname = self.aPartsCollectorAction.getRefNameDict2dParts( )[partid] text = "\tPart %d = %s" % (partid, partname) self.statusText.append(text) self.statusText.append("2D Part Variables:") for svar in self.scalarVariables2D: text = "\t%s(scalar)" % (svar) self.statusText.append(text) for vvar in self.vectorVariables2D: text = "\t%s(vector)" % (vvar) self.statusText.append(text) QtWidgets.QApplication.processEvents() # MODULE: RWCovise self.RWCovise_1 = RWCovise() theNet.add(self.RWCovise_1) self.RWCovise_1.set_stepNo(0) self.RWCovise_1.set_rotate_output("FALSE") self.RWCovise_1.set_rotation_axis(3) self.RWCovise_1.set_rot_speed(2.000000) self.cocase = CoviseCaseFile() cn = os.path.basename(str(self.fullEnsightCaseName)) self.cocasename = cn[0:cn.rfind('.')] def startConversion(self): #print "Ensight2CoviseGui.startConversion" # Module Transform self.scale = float(str(self.leScale.text())) if self.scale != 1: if not hasattr(self, "Transform_1"): self.Transform_1 = Transform() theNet.add(self.Transform_1) self.Transform_1.set_Transform(5) self.Transform_1.set_createSet("FALSE") self.Transform_1.set_scaling_factor(self.scale) self.outputDirFrame.setEnabled(False) self.startConversionFrame.setEnabled(False) self.settingsFrame.setEnabled(False) #self.statusText.clear() text = "\nStarting Conversion in %s..." % (self.outputFilePath) self.statusText.append(text) QtWidgets.QApplication.processEvents() self.startConversionOf3DParts() self.startConversionOf2DParts() QtWidgets.QApplication.processEvents() CoviseMsgLoop().unregister(self.aPartsCollectorAction) CoviseMsgLoop().unregister(self.aErrorLogAction) theNet.remove(self.ReadEnsight_1) text = "\nWriting cocase to file..." self.statusText.append(text) pickleFile = self.outputFilePath + self.cocasename + '.cocase' counter = 0 while os.path.isfile(pickleFile): text = "! A file named %s is already available ... trying a new name" % ( pickleFile) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter = counter + 1 pickleFile = self.outputFilePath + self.cocasename + "_" + str( counter) output = open(pickleFile, 'wb') pickle.dump(self.cocase, output) output.close() text = "cocasefile written to %s\n" % (pickleFile, ) self.statusText.append(text) QtWidgets.QApplication.processEvents() text = "\nConversion finished!" self.statusText.append(text) def startConversionOf3DParts(self): for partid in self.aPartsCollectorAction.getRefNameDict3dParts().keys( ): #if int(partid) >= int(self.comboStartId.getCurrentIndex()): # get partname partname = self.aPartsCollectorAction.getRefNameDict3dParts( )[partid] text = "\nConverting grid of part %s please be patient..." % ( partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() # connect modules if self.scale != 1: theNet.connect(self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in") theNet.connect(self.Transform_1, "geo_out", self.RWCovise_1, "mesh_in") else: theNet.connect(self.ReadEnsight_1, "geoOut_3D", self.RWCovise_1, "mesh_in") # select part self.ReadEnsight_1.set_choose_parts(str(partid)) # clean partname if "/" in partname: text = "! Removing the / in partname = %s\n" % (partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname = partname.replace("/", "") # create RW Covise name covisename = self.outputFilePath + partname + "-3D.covise" # check if file is already available #print "rwcovisename=", covisename counter = 0 while os.path.isfile(covisename): text = "! A file named %s is already available ... trying a new name" % ( covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter = counter + 1 covisename = self.outputFilePath + partname + str( counter) + "-3D.covise" QtWidgets.QApplication.processEvents() self.RWCovise_1.set_grid_path(covisename) QtWidgets.QApplication.processEvents() # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() #theNet.save( "grid.net" ) # write logfile text = "Converted grid of part %s to covise file %s" % (partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # create cocase item item3D = CoviseCaseFileItem(partname, GEOMETRY_3D, os.path.basename(covisename)) # disconnect modules if self.scale != 1: theNet.disconnect(self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in") theNet.disconnect(self.Transform_1, "geo_out", self.RWCovise_1, "mesh_in") else: theNet.disconnect(self.ReadEnsight_1, "geoOut_3D", self.RWCovise_1, "mesh_in") QtWidgets.QApplication.processEvents() # scalar variables # connect modules if self.scale != 1: theNet.connect(self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in") theNet.connect(self.ReadEnsight_1, "sdata1_3D", self.Transform_1, "data_in0") theNet.connect(self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in") else: theNet.connect(self.ReadEnsight_1, "sdata1_3D", self.RWCovise_1, "mesh_in") # loop over scalar variables choice = 1 for svar in self.scalarVariables3D: text = "\nConverting scalar variable %s of part %s, please be patient..." % ( svar, partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() # select variable choice += 1 self.ReadEnsight_1.set_data_for_sdata1_3D(choice) # clean variablename if "/" in svar: text = "! Removing the / in svar = %s\n" % (svar, ) statusText.append(text) QtWidgets.QApplication.processEvents() svar = svar.replace("/", "") # create RWCovise name covisename = self.outputFilePath + partname + "-" + svar + "-3D.covise" # check if file is already available counter = 0 while os.path.isfile(covisename): text = "! A file named %s is already available ... trying a new name" % ( covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter = counter + 1 covisename = self.outputFilePath + partname + str( counter) + "-" + svar + "-3D.covise" self.RWCovise_1.set_grid_path(covisename) QtWidgets.QApplication.processEvents() # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text = "Converted scalar variable %s of part %s to file %s" % ( svar, partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # add variable to cacase item item3D.addVariableAndFilename(svar, covisename, SCALARVARIABLE) #theNet.save( "scalar.net" ) # disconnect modules if self.scale != 1: theNet.disconnect(self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in") theNet.disconnect(self.ReadEnsight_1, "sdata1_3D", self.Transform_1, "data_in0") theNet.disconnect(self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in") else: theNet.disconnect(self.ReadEnsight_1, "sdata1_3D", self.RWCovise_1, "mesh_in") QtWidgets.QApplication.processEvents() # vector variables # connect modules if self.scale != 1: theNet.connect(self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in") theNet.connect(self.ReadEnsight_1, "vdata1_3D", self.Transform_1, "data_in0") theNet.connect(self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in") else: theNet.connect(self.ReadEnsight_1, "vdata1_3D", self.RWCovise_1, "mesh_in") # loop over variables choice = 1 for vvar in self.vectorVariables3D: text = "\nConverting vector variable %s of part %s, please be patient..." % ( vvar, partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() # select variable choice += 1 self.ReadEnsight_1.set_data_for_vdata1_3D(choice) # clean variablename if "/" in vvar: text = "! Removing the / in vvar = %s\n" % (vvar, ) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname = partname.replace("/", "") # create covisename covisename = self.outputFilePath + partname + "-" + vvar + "-3D.covise" # check if file is already available counter = 0 while os.path.isfile(covisename): text = "! A file named %s is already available trying a new name" % ( covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter = counter + 1 covisename = self.outputFilePath + partname + str( counter) + "-" + vvar + "-3D.covise" self.RWCovise_1.set_grid_path(covisename) # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text = "Converted vector variable%s of part %s to file %s" % ( vvar, partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # add variable to cocase item item3D.addVariableAndFilename(vvar, covisename, VECTOR3DVARIABLE) # disconnect modules if self.scale != 1: theNet.disconnect(self.ReadEnsight_1, "geoOut_3D", self.Transform_1, "geo_in") theNet.disconnect(self.ReadEnsight_1, "vdata1_3D", self.Transform_1, "data_in0") theNet.disconnect(self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in") else: theNet.disconnect(self.ReadEnsight_1, "vdata1_3D", self.RWCovise_1, "mesh_in") # add the cocase item to the case file self.cocase.add(item3D) QtWidgets.QApplication.processEvents() def startConversionOf2DParts(self): #print "__________START 2D---------" for partid in self.aPartsCollectorAction.getRefNameDict2dParts().keys( ): partname = self.aPartsCollectorAction.getRefNameDict2dParts( )[partid] # write logfile text = "\nConverting surface of part %s, please be patient..." % ( partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() # connect modules if self.scale != 1: theNet.connect(self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in") theNet.connect(self.Transform_1, "geo_out", self.RWCovise_1, "mesh_in") else: theNet.connect(self.ReadEnsight_1, "geoOut_2D", self.RWCovise_1, "mesh_in") # select part self.ReadEnsight_1.set_choose_parts(str(partid)) # clean partname if "/" in partname: text = "! Removing the / in partname = %s\n" % (partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname = partname.replace("/", "") # create RWCovise name covisename = self.outputFilePath + partname + "-2D.covise" counter = 0 while os.path.isfile(covisename): text = "! A file named %s is already available trying a new name" % ( covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter = counter + 1 covisename = self.outputFilePath + partname + str( counter) + "-2D.covise" self.RWCovise_1.set_grid_path(covisename) # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text = "Converted surface of part %s to file %s" % (partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # create cocase item item2D = CoviseCaseFileItem(partname, GEOMETRY_2D, os.path.basename(covisename)) # disconnect the modules if self.scale != 1: theNet.disconnect(self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in") theNet.disconnect(self.Transform_1, "geo_out", self.RWCovise_1, "mesh_in") else: theNet.disconnect(self.ReadEnsight_1, "geoOut_2D", self.RWCovise_1, "mesh_in") # # scalar variables # # connect modules if self.scale != 1: theNet.connect(self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in") theNet.connect(self.ReadEnsight_1, "sdata1_2D", self.Transform_1, "data_in0") theNet.connect(self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in") else: theNet.connect(self.ReadEnsight_1, "sdata1_2D", self.RWCovise_1, "mesh_in") choice = 1 for svar in self.scalarVariables2D: # select variable choice += 1 text = "\nConverting scalar variable %s of part %s, please be patient..." % ( svar, partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() self.ReadEnsight_1.set_data_for_sdata1_2D(choice) # clean variablename if "/" in partname: text = "! Removing the / in partname = %s\n" % (partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname = partname.replace("/", "") # create RWCovise name covisename = self.outputFilePath + partname + "-" + svar + "-2D.covise" counter = 0 while os.path.isfile(covisename): text = "! A file named %s is already available ... trying a new name" % ( covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter = counter + 1 covisename = self.outputFilePath + partname + str( counter) + "-" + svar + "-2D.covise" self.RWCovise_1.set_grid_path(covisename) # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text = "Converted scalar variable %s of part %s to file %s" % ( svar, partname, covisename, ) self.statusText.append(text) QtWidgets.QApplication.processEvents() # add variable to cicase item item2D.addVariableAndFilename(svar, covisename, SCALARVARIABLE) # print memory usage of module #os.system('ps aux | grep ReadEnsight_1') # disconnect modules if self.scale != 1: theNet.disconnect(self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in") theNet.disconnect(self.ReadEnsight_1, "sdata1_2D", self.Transform_1, "data_in0") theNet.disconnect(self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in") else: theNet.disconnect(self.ReadEnsight_1, "sdata1_2D", self.RWCovise_1, "mesh_in") # vector variables # connect modules if self.scale != 1: theNet.connect(self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in") theNet.connect(self.ReadEnsight_1, "vdata1_2D", self.Transform_1, "data_in0") theNet.connect(self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in") else: theNet.connect(self.ReadEnsight_1, "vdata1_2D", self.RWCovise_1, "mesh_in") choice = 1 for vvar in self.vectorVariables2D: # select variable choice += 1 text = "\nConverting vector variable %s of part %s, please be patient..." % ( vvar, partname) self.statusText.append(text) QtWidgets.QApplication.processEvents() self.ReadEnsight_1.set_data_for_vdata1_2D(choice) # clean partname if "/" in partname: text = "! Removing the / in partname = %s\n" % (partname, ) self.statusText.append(text) QtWidgets.QApplication.processEvents() partname = partname.replace("/", "") # create RWCovise name covisename = self.outputFilePath + partname + "-" + vvar + "-2D.covise" counter = 0 while os.path.isfile(covisename): text = "! A file named %s is already available ... trying a new name" % ( covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() counter = counter + 1 covisename = self.outputFilePath + partname + str( counter) + "-" + vvar + "-2D.covise" self.RWCovise_1.set_grid_path(covisename) # execute self.ReadEnsight_1.execute() theNet.finishedBarrier() # write logfile text = "Converted vector variable%s of part %s to file %s" % ( vvar, partname, covisename) self.statusText.append(text) QtWidgets.QApplication.processEvents() # add varibale to coscase item item2D.addVariableAndFilename(vvar, covisename, VECTOR3DVARIABLE) # disconnect modules if self.scale != 1: theNet.disconnect(self.ReadEnsight_1, "geoOut_2D", self.Transform_1, "geo_in") theNet.disconnect(self.ReadEnsight_1, "vdata1_2D", self.Transform_1, "data_in0") theNet.disconnect(self.Transform_1, "data_out0", self.RWCovise_1, "mesh_in") else: theNet.disconnect(self.ReadEnsight_1, "vdata1_2D", self.RWCovise_1, "mesh_in") # add the cocase item to the case file self.cocase.add(item2D)