def loadModelDialogSlot(self): """Start a file dialog to choose a model file. Once the dialog succeeds, we should hand-over the duty of actual model loading to something else. Then refresh the views. Things to check from the user: 1) The file type 2) Target element 3) Whether we should update the current window or start a new window. 4) Plugin to use for displaying this model (can be automated by looking into the model file for a regular expression) """ activeWindow = None # This to be used later to refresh the current widget with newly loaded model dialog = LoaderDialog(self, self.tr('Load model from file')) if dialog.exec_(): fileNames = dialog.selectedFiles() for fileName in fileNames: # print 'Current plugin', self.plugin modelName = dialog.getTargetPath() if '/' in modelName: raise mexception.ElementNameError('Model name cannot contain `/`') ret = loadFile(str(fileName), '/model/%s' % (modelName), merge=False) #print '11111' # Harsha: if subtype is None, in case of cspace then pluginLookup = /cspace/None # which will not call kkit plugin so cleaning to /cspace pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype']) try: pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])] except KeyError: pluginName = 'default' print 'Loaded model', ret['model'].path self.setPlugin(pluginName, ret['model'].path) #Harsha: This will clear out object editor's objectpath and make it invisible self.objectEditSlot('/',False)
def loadModelDialogSlot(self): """Start a file dialog to choose a model file. Once the dialog succeeds, we should hand-over the duty of actual model loading to something else. Then refresh the views. Things to check from the user: 1) The file type 2) Target element 3) Whether we should update the current window or start a new window. 4) Plugin to use for displaying this model (can be automated by looking into the model file for a regular expression) """ self.popup.close() activeWindow = None # This to be used later to refresh the current widget with newly loaded model dialog = LoaderDialog(self, self.tr('Load model from file')) if dialog.exec_(): fileNames = dialog.selectedFiles() for fileName in fileNames: modelName = dialog.getTargetPath() if '/' in modelName: raise mexception.ElementNameError('Model name cannot contain `/`') ret = loadFile(str(fileName),'%s' %(modelName),merge=False) #ret = loadFile(str(fileName), '/model/%s' % (modelName), merge=False) #Harsha: This will clear out object editor's objectpath and make it invisible self.objectEditSlot('/',False) # Harsha: if subtype is None, in case of cspace then pluginLookup = /cspace/None # which will not call kkit plugin so cleaning to /cspace pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype']) try: pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])] except KeyError: pluginName = 'default' print 'Loaded model', ret['model'].path if not moose.exists(ret['model'].path+'/info'): moose.Annotator(ret['model'].path+'/info') modelAnno = moose.Annotator(ret['model'].path+'/info') if ret['subtype']: modelAnno.modeltype = ret['subtype'] else: modelAnno.modeltype = ret['modeltype'] modelAnno.dirpath = str(dialog.directory().absolutePath()) self.loadedModelsAction(ret['model'].path,pluginName) self.setPlugin(pluginName, ret['model'].path) if pluginName == 'kkit': QtCore.QCoreApplication.sendEvent(self.plugin.getEditorView().getCentralWidget().view, QtGui.QKeyEvent(QtCore.QEvent.KeyPress, Qt.Qt.Key_A, Qt.Qt.NoModifier))