def copy_pipeline_to_other_location(pipeline, controller, sheetName, row, col,plot_type, cell):
        pip_str = core.db.io.serialize(pipeline)
        controller.change_selected_version(cell.current_parent_version)

        modules = controller.paste_modules_and_connections(pip_str, (0.0,0.0))
        cell.current_parent_version = controller.current_version
        pipeline = controller.current_pipeline

        reg = get_module_registry()
        cell_locations = CDMSPipelineHelper.find_modules_by_type(pipeline, [CellLocation])
        cell_modules = CDMSPipelineHelper.find_modules_by_type(pipeline, [SpreadsheetCell])

        #// We assume that there is only one CellLocation and one SpreadsheetCell
        #// delete location and create another one with the right locations
        action = controller.delete_module_list([cell_locations[0].id])
        cell.current_parent_version = action.id

        loc_module = controller.create_module_from_descriptor(
            reg.get_descriptor_by_name('edu.utah.sci.vistrails.spreadsheet',
                                       'CellLocation'))
        functions = controller.create_functions(loc_module,
            [('Row', [str(row+1)]), ('Column', [str(col+1)])])
        for f in functions:
            loc_module.add_function(f)
        loc_conn = controller.create_connection(loc_module, 'self',
                                                cell_modules[0], 'Location')
        ops = [('add', loc_module),
               ('add', loc_conn)]

        action = core.db.action.create_action(ops)
        controller.change_selected_version(cell.current_parent_version)
        controller.add_new_action(action)
        controller.perform_action(action)
        cell.current_parent_version = action.id

        #// Update project controller cell information
        pipeline = controller.vistrail.getPipeline(action.id)
        plot_modules = CDMSPipelineHelper.find_modules_by_type(pipeline, [CDMSPlot])
        for plot in cell.plots:
            plot.variables =[]
        #for plot in plot_modules:
        #    vars = CDMSPipelineHelper.find_variables_connected_to_plot_module(controller,
        #                                                               pipeline,
        #                                                               plot.id)
        #    for var in vars:
        #        cell.variables.append(CDMSPipelineHelper.get_variable_name_from_module(var))

        #FIXME: This does not consider if the workflow has more than one plot
        #gmName = CDMSPipelineHelper.get_graphics_method_name_from_module(plot_modules[0])
        #ptype = CDMSPipelineHelper.get_plot_type_from_module(plot_modules[0])
        #cell.plot = get_plot_manager().get_plot(plot_type, ptype, gmName)
        return action
    def load_pipeline_in_location(pipeline, controller, sheetName, row, col,plot_type, cell):
       cell_locations = CDMSPipelineHelper.find_modules_by_type(pipeline, [CellLocation])
       cell_modules = CDMSPipelineHelper.find_modules_by_type(pipeline, [SpreadsheetCell])
#       plot_modules = CDMSPipelineHelper.find_modules_by_type(pipeline, [CDMSPlot])

       #// we assume that there is only one CellLocation and one SpreadsheetCell
       #// update location values in place.
       loc_module = cell_locations[0]
       for i in xrange(loc_module.getNumFunctions()):
           if loc_module.functions[i].name == 'Row':
               loc_module.functions[i].params[0].strValue = str(row+1)
           elif loc_module.functions[i].name == "Column":
               loc_module.functions[i].params[0].strValue = str(col+1)
Esempio n. 3
0
 def show_configuration_widget(controller, version, plot_obj=None):
     pipeline = controller.vt_controller.vistrail.getPipeline(version)
     #print pipeline
     #plots = VisItPipelineHelper.find_plot_modules(pipeline)
     cell = CDMSPipelineHelper.find_modules_by_type(pipeline,[visitcell.VisItCell])
     vars = CDMSPipelineHelper.find_modules_by_type(pipeline,
                                                    [CDMSVariable,
                                                     CDMSVariableOperation])
     if len(cell) == 0:
         return visitcell.VisItCellConfigurationWidget(None,controller)
     else:
         vcell = cell[0].module_descriptor.module()
         #print "cellWidget should not be None", vcell, vcell.cellWidget
         return visitcell.VisItCellConfigurationWidget(cell[0],controller)
Esempio n. 4
0
 def show_configuration_widget(controller, version, plot_obj=None):
     pipeline = controller.vt_controller.vistrail.getPipeline(version)
     #print pipeline
     #plots = VisItPipelineHelper.find_plot_modules(pipeline)
     cell = CDMSPipelineHelper.find_modules_by_type(pipeline,
                                                    [visitcell.VisItCell])
     vars = CDMSPipelineHelper.find_modules_by_type(
         pipeline, [CDMSVariable, CDMSVariableOperation])
     if len(cell) == 0:
         return visitcell.VisItCellConfigurationWidget(None, controller)
     else:
         vcell = cell[0].module_descriptor.module()
         #print "cellWidget should not be None", vcell, vcell.cellWidget
         return visitcell.VisItCellConfigurationWidget(cell[0], controller)
    def show_configuration_widget(controller, version, plot_obj=None):
        #// Grab the pipeline
        pipeline = controller.vt_controller.vistrail.getPipeline(version)

        #// Find the cell
        cell = CDMSPipelineHelper.find_modules_by_type(pipeline,[PVGenericCell])

        PVClimatePipelineHelper.find_plot_representation(pipeline, PVClimatePipelineHelper.find_plot_modules(pipeline)[0])

        #// @todo: Remove this hack
        if len(cell) == 0:
          print >> sys.stderr, 'cell is empty'
          return None

        if len(cell) == 0:
            widget = PVGenericCellConfigurationWidget(None, controller.vt_controller)
            widget.init(pipeline, version)
            return widget
        else:
            pvcell = cell[0].module_descriptor.module()
            #// Create child widgets
            #// Attach it to the parent widget
            widget = PVGenericCellConfigurationWidget(cell[0], controller.vt_controller)
            widget.init(pipeline, version)
            return widget
Esempio n. 6
0
    def activateFromCell(self, canvas):
        self.activeCanvas = canvas
        self.setColorsFromCanvas()

        self.controller = api.get_current_controller()
        self.version = self.controller.current_version
        self.pipeline = self.controller.vistrail.getPipeline(self.version)
        self.plots = CDMSPipelineHelper.find_plot_modules(self.pipeline)

        #set up plot combo box
        #        self.plotCb.clear()
        #        for i in range(len(self.plots)):
        #            found = False
        #            for func in self.plots[i].functions:
        #                if func.name == 'graphicsMethodName':
        #                    self.plotCb.addItem(self.plots[i].module_descriptor.module.plot_type \
        #                        + '_' + func.params[0].strValue, userData=i)
        #                    found = True
        #            if not found:
        #                self.plotCb.addItem(self.plots[i].module_descriptor.module.plot_type, userData=i)
        #        self.plotCb.setCurrentIndex(0)

        self.mapNameChanged = False
        self.cellsDirty = False
        self.show()
Esempio n. 7
0
    def activateFromCell(self,canvas):
        self.activeCanvas = canvas
        self.setColorsFromCanvas()
        
        self.controller = api.get_current_controller()
        self.version = self.controller.current_version
        self.pipeline = self.controller.vistrail.getPipeline(self.version)
        self.plots = CDMSPipelineHelper.find_plot_modules(self.pipeline)
        
        #set up plot combo box
#        self.plotCb.clear()
#        for i in range(len(self.plots)):
#            found = False
#            for func in self.plots[i].functions:
#                if func.name == 'graphicsMethodName':
#                    self.plotCb.addItem(self.plots[i].module_descriptor.module.plot_type \
#                        + '_' + func.params[0].strValue, userData=i)
#                    found = True                
#            if not found:
#                self.plotCb.addItem(self.plots[i].module_descriptor.module.plot_type, userData=i)                
#        self.plotCb.setCurrentIndex(0)
        
        self.mapNameChanged = False
        self.cellsDirty = False
        self.show()        
    def build_python_script_from_pipeline(controller, version, plot=None):
        pipeline = controller.vistrail.getPipeline(version)
        plots = CDMSPipelineHelper.find_plot_modules(pipeline)
        text = "from PyQt4 import QtCore, QtGui\n"
        text += "import cdms2, cdutil, genutil\n"
        text += "import vcs\n\n"
        text += "if __name__ == '__main__':\n"
        text += "    import sys\n"
        text += "    app = QtGui.QApplication(sys.argv)\n"
        ident = '    '

        var_op_modules = CDMSPipelineHelper.find_topo_sort_modules_by_types(pipeline,
                                                                            [CDMSVariable,
                                                                             CDMSVariableOperation])
        for m in var_op_modules:
            desc = m.module_descriptor.module
            mobj = desc.from_module(m)
            text += mobj.to_python_script(ident=ident)

        text += ident + "canvas = vcs.init()\n"
        for mplot in plots:
            plot = mplot.module_descriptor.module.from_module(mplot)
            text += ident + "gm%s = canvas.get%s('%s')\n"%(plot.plot_type,
                                                 plot.plot_type.lower(),
                                                 plot.graphics_method_name)
            text += ident + "args = []\n"
            for varm in CDMSPipelineHelper.find_variables_connected_to_plot_module(controller, pipeline, mplot.id):
                text += ident + "args.append(%s)\n"%CDMSPipelineHelper.get_variable_name_from_module(varm)

            if plot.graphics_method_name != 'default':
                for k in plot.gm_attributes:
                    if hasattr(plot,k):
                        kval = getattr(plot,k)
                        if type(kval) == type("str") and k != 'legend':
                            text += ident + "gm%s.%s = '%s'\n"%(plot.plot_type,
                                                            k, kval)
                        else:
                            text += ident + "gm%s.%s = %s\n"%(plot.plot_type,
                                                      k,  kval)
            text += ident + "kwargs = %s\n"%plot.kwargs
            text += ident + "canvas.plot(gm%s,*args, **kwargs)\n"%(plot.plot_type)
        text += '    sys.exit(app.exec_())'
        return text
Esempio n. 9
0
    def activateFromCell(self, canvas):
        self.activeCanvas = canvas
        self.setColorsFromCanvas()

        self.controller = api.get_current_controller()
        self.version = self.controller.current_version
        self.pipeline = self.controller.vistrail.getPipeline(self.version)
        self.plots = CDMSPipelineHelper.find_plot_modules(self.pipeline)
        self.mapNameChanged = False
        self.cellsDirty = False
        self.show()
    def build_plot_pipeline_action(controller, version, var_modules, plots,row, col, template=None):
        #// @todo: want to make sure that nothing changes if var_module
        #// or plot_module do not change

        # Get controller
        if controller is None:
            controller = api.get_current_controller()
            version = 0L

        # Get module registry
        reg = get_module_registry()
        ops = []
        cell_module = None

        #// First get the pipeline
        pipeline = controller.vistrail.getPipeline(version)

        #// @todo: Add support for multiple variables per plot
        #// Use only the first var module for now
        var_module = var_modules[0]

        #// @Aashish: As of now, very first time var module is being added to the pipeline by the project controller
        #// but second time on the same cell, it gets removed and hence we needed to add var module again to pipeline.
        #// I need to put this code under try catch because as of now looking for an id that does not exists
        #// results in exception.
        try:
            temp_var_module = pipeline.get_module_by_id(var_module.id)
        except KeyError:
            temp_var_module = None

        if temp_var_module is not None:
            var_module = temp_var_module
        else:
            # This time we need to add var module to the pipeline
            ops.append(('add', var_module))

        for plot in plots:
            plot_gm = plot.name

            #// Create plot module from the descriptor
            #// Is there a better way? I looked around and found none
            import re
            plotUsableName = re.sub(r'\s', '', plot_gm)
            plot_module = PlotPipelineHelper.find_module_by_name(pipeline, plotUsableName)
            if plot_module is not None:
                continue

            plot_descriptor = reg.get_descriptor_by_name('com.kitware.pvclimate', plotUsableName)

            #// @Aashish: Looks like the pipeline is using the cached representation
            plot_module = controller.create_module_from_descriptor(plot_descriptor)
            ops.append(('add', plot_module))

            #// @Aashish: This is no longer required as of this commit
            #// e13bb034ceb302afe3aad3caf20153e1525586db
            #// I am not sure though why we still need to add plot module
            #ops.append(('add', var_modules[0]))

            #// Create cell - representation linkage
            #// Check to see if a cell already exits, if yes then set the input (representation on it) or else
            #// create a new one and then set the representation on it.
            if cell_module is None:
                cell_module = PlotPipelineHelper.find_module_by_name(pipeline, "PVGenericCell")

            #// If cell module is None, then create a new one
            if cell_module is None:
                cell_desc = reg.get_descriptor_by_name('com.kitware.pvclimate', "PVGenericCell")
                cell_module = controller.create_module_from_descriptor(cell_desc)
                ops.append(('add', cell_module))

                #// Create a connection between the cell and the variable
                #// @Aashish: I am expecting that every time we drop a variable, we will get a
                #// pipeline that does not have modules from the previous execution. I need to verify
                #// this but for now this assumption seems to hold.
                
                oport = CDMSPipelineHelper.get_output_port_name(
                        var_module.module_descriptor.module)
                conn = controller.create_connection(var_module, oport,
                                                    plot_module, 'cdms_variable')
                ops.append(('add', conn))

                loc_module = controller.create_module_from_descriptor(
                    reg.get_descriptor_by_name('edu.utah.sci.vistrails.spreadsheet',
                                               'CellLocation'))
                functions = controller.create_functions(loc_module,
                    [('Row', [str(row+1)]), ('Column', [str(col+1)])])
                for f in functions:
                    loc_module.add_function(f)
                loc_conn = controller.create_connection(loc_module, 'self',
                                                        cell_module, 'Location')
                ops.extend([('add', loc_module),
                            ('add', loc_conn)])

            #// Create connection between the cell and the representation
            conn = controller.create_connection(plot_module, 'self',
                                                cell_module, 'representation')

            #// Add the connection to the pipeline operations
            ops.append(('add', conn))

        action = core.db.action.create_action(ops)
        controller.change_selected_version(version)
        controller.add_new_action(action)
        controller.perform_action(action)
        return action
Esempio n. 11
0
    def add_project(self, view):
        """ add_project(view: QVistrailView) -> None
        vistrails calls this when a project is opened/created/saved
        Items and spreadsheets are updated
        """
        try:
            if id(view) not in self.viewToItem:
                if self.currentProject:
                    self.setBold(self.currentProject, False)
                p_name = "Project %i" % self.numProjects
                item = QProjectItem(view, p_name)
                self.currentProject = item
                self.current_controller = item.controller
                self.viewToItem[id(view)] = item
                self.treeProjects.addTopLevelItem(item)
                item.setExpanded(True)
                item.namedPipelines.setExpanded(True)
                self.numProjects += 1
                self.emit(QtCore.SIGNAL("project_added"), item.controller.name)
                self.state_changed(view)
                # add sheets from vistrail actionAnnotations
                tc = self.spreadsheetWindow.get_current_tab_controller()
                for annotation in view.controller.vistrail.action_annotations:
                    if annotation.db_key != 'uvcdatCell':
                        continue
                    cell = fromAnnotation(annotation.db_value)
                    plot_type = view.controller.vistrail.get_action_annotation(
                        annotation.db_action_id, "uvcdatType")
                    if cell[0] not in item.sheet_to_item:
                        rows, cols = self.currentProject.sheetSize(cell[0])
                        tc.setCurrentIndex(
                            tc.addTabWidget(StandardWidgetSheetTab(tc),
                                            cell[0]))
                        tab = tc.currentWidget()
                        tab.sheet.stretchCells()
                        tab.setDimension(rows, cols)
                        tab.sheet.setRowCount(rows)
                        tab.sheet.setColumnCount(cols)
                        tab.sheet.stretchCells()
                        tab.displayPrompt()
                        tab.setEditingMode(tab.tabWidget.editingMode)
                    else:
                        tab = item.sheet_to_tab[cell[0]]
                        self.spreadsheetWindow.get_current_tab_controller(
                        ).setCurrentWidget(tab)
                    # Add cell

                    if len(cell) < 5:
                        item.controller.vis_was_dropped(
                            (view.controller, annotation.db_action_id, cell[0],
                             int(cell[1]), int(cell[2]), plot_type.value))
                        item.update_cell(cell[0], int(cell[1]), int(cell[2]),
                                         None, None, plot_type.value,
                                         annotation.db_action_id, False)
                    else:
                        item.controller.vis_was_dropped(
                            (view.controller, annotation.db_action_id, cell[0],
                             int(cell[1]), int(cell[2]), plot_type.value))
                        item.update_cell(cell[0], int(cell[1]), int(cell[2]),
                                         int(cell[3]), int(cell[4]),
                                         plot_type.value,
                                         annotation.db_action_id, False)
                if not len(item.sheet_to_item):
                    tc.create_first_sheet()
                self.connect(item.controller, QtCore.SIGNAL("update_cell"),
                             item.update_cell)
                self.connect(item.controller,
                             QtCore.SIGNAL("sheet_size_changed"),
                             item.sheetSizeChanged)
                self.connect(item.controller, QtCore.SIGNAL("show_provenance"),
                             item.show_provenance)

                # add any variables that weren't automatically added above
                # by checking leaf nodes of the version tree
                from packages.uvcdat_cdms.init import CDMSVariable, CDMSVariableOperation
                from packages.uvcdat_cdms.pipeline_helper import CDMSPipelineHelper
                fullTree = view.controller.vistrail.tree.getVersionTree()
                pipelinesToSearch = []
                for version in fullTree.iter_vertices():
                    if fullTree.out_degree(version) == 0:
                        view.controller.change_selected_version(version)
                        pipeline = view.controller._get_current_pipeline()
                        found = False
                        for module in CDMSPipelineHelper.find_modules_by_type(
                                pipeline, [CDMSVariable]):
                            if module.name not in self.current_controller.defined_variables:
                                found = True
                                break

                        if not found:
                            for module in CDMSPipelineHelper.find_modules_by_type(
                                    pipeline, [CDMSVariableOperation]):
                                if module.varname not in self.current_controller.computed_variables:
                                    found = True
                                    break

                        if found:
                            pipelinesToSearch.append(pipeline)

                #perform this outside above loop because it changes the version tree that
                #is being iterated over
                for pipeline in pipelinesToSearch:
                    self.current_controller.search_and_emit_variables(
                        pipeline, CDMSPipelineHelper)

            if view.controller.locator:
                name = view.controller.locator.short_name
                self.viewToItem[id(view)].setText(0, name)
            self.treeProjects.setCurrentItem(self.viewToItem[id(view)])

        except Exception, err:
            print "Error adding project: ", str(err)
            traceback.print_exc(100, sys.stderr)
Esempio n. 12
0
 def add_project(self, view):
     """ add_project(view: QVistrailView) -> None
     vistrails calls this when a project is opened/created/saved
     Items and spreadsheets are updated
     """
     try:
         if id(view) not in self.viewToItem:
             if self.currentProject:
                 self.setBold(self.currentProject, False)
             p_name = "Project %i" % self.numProjects
             item = QProjectItem(view, p_name)
             self.currentProject = item
             self.current_controller = item.controller
             self.viewToItem[id(view)] = item
             self.treeProjects.addTopLevelItem(item)
             item.setExpanded(True)
             item.namedPipelines.setExpanded(True)
             self.numProjects += 1
             self.emit(QtCore.SIGNAL("project_added"), item.controller.name)
             self.state_changed(view)
             # add sheets from vistrail actionAnnotations
             tc = self.spreadsheetWindow.get_current_tab_controller()
             for annotation in view.controller.vistrail.action_annotations:
                 if annotation.db_key != 'uvcdatCell':
                     continue
                 cell = fromAnnotation(annotation.db_value)
                 plot_type = view.controller.vistrail.get_action_annotation(
                                 annotation.db_action_id, "uvcdatType")
                 if cell[0] not in item.sheet_to_item:
                     rows, cols = self.currentProject.sheetSize(cell[0])
                     tc.setCurrentIndex(tc.addTabWidget(
                                          StandardWidgetSheetTab(tc), cell[0]))
                     tab = tc.currentWidget()
                     tab.sheet.stretchCells()
                     tab.setDimension(rows, cols)
                     tab.sheet.setRowCount(rows)
                     tab.sheet.setColumnCount(cols)
                     tab.sheet.stretchCells()
                     tab.displayPrompt()
                     tab.setEditingMode(tab.tabWidget.editingMode)
                 else:
                     tab = item.sheet_to_tab[cell[0]]
                     self.spreadsheetWindow.get_current_tab_controller(
                                                        ).setCurrentWidget(tab)
                 # Add cell
                
                 if len(cell)<5:
                     item.controller.vis_was_dropped((view.controller, 
                                  annotation.db_action_id, cell[0],
                                  int(cell[1]), int(cell[2]), plot_type.value))
                     item.update_cell(cell[0], int(cell[1]), int(cell[2]),
                                      None, None, plot_type.value,
                                      annotation.db_action_id, False)
                 else:
                     item.controller.vis_was_dropped((view.controller,
                                  annotation.db_action_id, cell[0],
                                  int(cell[1]), int(cell[2]), plot_type.value))
                     item.update_cell(cell[0], int(cell[1]), int(cell[2]),
                                      int(cell[3]), int(cell[4]),
                                      plot_type.value,
                                      annotation.db_action_id, False)
             if not len(item.sheet_to_item):
                 tc.create_first_sheet()
             self.connect(item.controller, QtCore.SIGNAL("update_cell"),
                      item.update_cell)
             self.connect(item.controller, QtCore.SIGNAL("sheet_size_changed"),
                      item.sheetSizeChanged)
             self.connect(item.controller, QtCore.SIGNAL("show_provenance"),
                          item.show_provenance)
             
             # add any variables that weren't automatically added above
             # by checking leaf nodes of the version tree
             from packages.uvcdat_cdms.init import CDMSVariable, CDMSVariableOperation
             from packages.uvcdat_cdms.pipeline_helper import CDMSPipelineHelper
             fullTree = view.controller.vistrail.tree.getVersionTree()
             pipelinesToSearch = []
             for version in fullTree.iter_vertices():
                 if fullTree.out_degree(version) == 0:
                     view.controller.change_selected_version(version)
                     pipeline = view.controller._get_current_pipeline()
                     found = False
                     for module in CDMSPipelineHelper.find_modules_by_type(
                             pipeline, [CDMSVariable]):
                         if module.name not in self.current_controller.defined_variables:
                             found = True
                             break
                         
                     if not found:
                         for module in CDMSPipelineHelper.find_modules_by_type(
                                 pipeline, [CDMSVariableOperation]):
                             if module.varname not in self.current_controller.computed_variables:
                                 found = True
                                 break
                             
                     if found:
                         pipelinesToSearch.append(pipeline)
             
             #perform this outside above loop because it changes the version tree that 
             #is being iterated over
             for pipeline in pipelinesToSearch:
                 self.current_controller.search_and_emit_variables(pipeline, CDMSPipelineHelper)
  
         if view.controller.locator:
             name = view.controller.locator.short_name
             self.viewToItem[id(view)].setText(0, name)
         self.treeProjects.setCurrentItem(self.viewToItem[id(view)])
         
         
         
     except Exception, err:
         print "Error adding project: ", str(err)
         traceback.print_exc( 100, sys.stderr )