Exemplo n.º 1
0
def decodeConfiguration(pipeline, cells):
    """ decodeConfiguration(pipeline: Pipeline,
        cells: configuration) -> decoded cells
    Convert cells of type [{(type,id): (row, column)}) to
    (mId, row, col) in a particular pipeline

    """
    decodedCells = []
    inspector = PipelineInspector()
    inspector.inspect_spreadsheet_cells(pipeline)
    inspector.inspect_ambiguous_modules(pipeline)
    orig_pipeline = pipeline

    for id_list in inspector.spreadsheet_cells:
        pipeline = orig_pipeline
        id_iter = iter(id_list)
        m = pipeline.modules[id_iter.next()]
        m_id = m.id
        for m_id in id_iter:
            pipeline = m.pipeline
            m = pipeline.modules[m_id]
        name = m.name

        if len(id_list) == 1 and m_id in inspector.annotated_modules:
            idx = inspector.annotated_modules[m_id]
        elif tuple(id_list) in inspector.annotated_modules:
            idx = inspector.annotated_modules[tuple(id_list)]
        else:
            idx = -1
        (vRow, vCol) = cells[(name, idx)]
        if len(id_list) == 1:
            decodedCells.append((m_id, vRow, vCol))
        else:
            decodedCells.append((tuple(id_list), vRow, vCol))
    return decodedCells
    def dropEvent(self, event):
        """ Execute the pipeline at the particular location """
        mimeData = event.mimeData()        
        if (hasattr(mimeData, 'versionId') and
            hasattr(mimeData, 'controller')):
            event.accept()
            versionId = mimeData.versionId
            controller = mimeData.controller
            pipeline = controller.vistrail.getPipeline(versionId)

            inspector = PipelineInspector()
            inspector.inspect_spreadsheet_cells(pipeline)
            inspector.inspect_ambiguous_modules(pipeline)
            if len(inspector.spreadsheet_cells)==1:
                localPos = self.sheet.viewport().mapFromGlobal(QtGui.QCursor.pos())
                row = self.sheet.rowAt(localPos.y())
                col = self.sheet.columnAt(localPos.x())
                if (row!=-1 and col!=-1):
                    pipeline = self.setPipelineToLocateAt(row, col, pipeline)
            executePipelineWithProgress(pipeline, 'Execute Cell',
                                        locator=controller.locator,
                                        current_version=versionId,
                                        reason='Drop Version')
        else:
            event.ignore()
Exemplo n.º 3
0
 def __init__(self, parent=None):
     """ QPipelineView(parent: QWidget) -> QPipelineView
     Initialize the graphics view and its properties
     
     """
     QPipelineView.__init__(self, parent)
     self.setWindowTitle('Annotated Pipeline')
     self.inspector = PipelineInspector()
Exemplo n.º 4
0
 def __init__(self):
     """ SubModule() -> SubModule
     Create an inspector for pipeline
     
     """
     NotCacheable.__init__(self)
     Module.__init__(self)
     self.inspector = PipelineInspector()
Exemplo n.º 5
0
 def __init__(self, parent=None):
     """ QPipelineView(parent: QWidget) -> QPipelineView
     Initialize the graphics view and its properties
     
     """
     QPipelineView.__init__(self, parent)
     self.setWindowTitle('Annotated Pipeline')
     self.inspector = PipelineInspector()
Exemplo n.º 6
0
 def decodeConfiguration(self, pipeline, cells):
     """ decodeConfiguration(pipeline: Pipeline,
                             cells: configuration) -> decoded cells
     Convert cells of type [{(type,id): (row, column)}) to
     (mId, row, col) in a particular pipeline
     
     """
     decodedCells = []
     inspector = PipelineInspector()
     inspector.inspect_spreadsheet_cells(pipeline)
     inspector.inspect_ambiguous_modules(pipeline)
     for mId in inspector.spreadsheet_cells:
         name = pipeline.modules[mId].name
         if inspector.annotated_modules.has_key(mId):
             idx = inspector.annotated_modules[mId]
         else:
             idx = -1
         (vRow, vCol) = cells[(name, idx)]
         decodedCells.append((mId, vRow, vCol))
     return decodedCells
Exemplo n.º 7
0
def decodeConfiguration(pipeline, cells):
    """ decodeConfiguration(pipeline: Pipeline,
        cells: configuration) -> decoded cells
    Convert cells of type [{(type,id): (row, column)}) to
    (mId, row, col) in a particular pipeline

    """
    decodedCells = []
    inspector = PipelineInspector()
    inspector.inspect_spreadsheet_cells(pipeline)
    inspector.inspect_ambiguous_modules(pipeline)
    orig_pipeline = pipeline

    for id_list in inspector.spreadsheet_cells:
        pipeline = orig_pipeline
        id_iter = iter(id_list)
        m = pipeline.modules[id_iter.next()]
        m_id = m.id
        for m_id in id_iter:
            pipeline = m.pipeline
            m = pipeline.modules[m_id]
        name = m.name

        if len(id_list) == 1 and m_id in inspector.annotated_modules:
            idx = inspector.annotated_modules[m_id]
        elif tuple(id_list) in inspector.annotated_modules:
            idx = inspector.annotated_modules[tuple(id_list)]
        else:
            idx = -1
        (vRow, vCol) = cells[(name, idx)]
        if len(id_list) == 1:
            decodedCells.append((m_id, vRow, vCol))
        else:
            decodedCells.append((tuple(id_list), vRow, vCol))
    return decodedCells
Exemplo n.º 8
0
    def __init__(self, parent=None):
        """ QVirtualCellWindow(parent: QWidget) -> QVirtualCellWindow
        Initialize the widget

        """
        QtGui.QFrame.__init__(self, parent)
        self.setFrameShape(QtGui.QFrame.StyledPanel)
        self.setWindowTitle('Spreadsheet Virtual Cell')
        vLayout = QtGui.QVBoxLayout(self)
        vLayout.setMargin(2)
        vLayout.setSpacing(0)
        self.setLayout(vLayout)

        label = QtGui.QLabel('Arrange the cell(s) below to construct'
                             ' a virtual cell')
        font = QtGui.QFont(label.font())
        label.setFont(font)
        label.setWordWrap(True)
        vLayout.addWidget(label)

        hLayout = QtGui.QVBoxLayout()
        hLayout.setMargin(0)
        hLayout.setSpacing(0)
        vLayout.addLayout(hLayout)
        self.config = QVirtualCellConfiguration()
        self.config.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                  QtGui.QSizePolicy.Maximum)
        hLayout.addWidget(self.config)
        hPadWidget = QtGui.QWidget()
        hLayout.addWidget(hPadWidget)
        hPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                 QtGui.QSizePolicy.Ignored)

        vPadWidget = QtGui.QWidget()
        vLayout.addWidget(vPadWidget)
        vPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                 QtGui.QSizePolicy.Expanding)

        self.inspector = PipelineInspector()
        self.pipeline = None
Exemplo n.º 9
0
    def __init__(self, parent=None):
        """ QVirtualCellWindow(parent: QWidget) -> QVirtualCellWindow
        Initialize the widget

        """
        QtGui.QFrame.__init__(self, parent)
        self.setFrameShape(QtGui.QFrame.StyledPanel)
        self.setWindowTitle('Spreadsheet Virtual Cell')
        vLayout = QtGui.QVBoxLayout(self)
        vLayout.setMargin(2)
        vLayout.setSpacing(0)
        self.setLayout(vLayout)
        
        label = QtGui.QLabel('Arrange the cell(s) below to construct'
                             ' a virtual cell')
        font = QtGui.QFont(label.font())
        label.setFont(font)
        label.setWordWrap(True)        
        vLayout.addWidget(label)

        hLayout = QtGui.QVBoxLayout()
        hLayout.setMargin(0)
        hLayout.setSpacing(0)
        vLayout.addLayout(hLayout)
        self.config = QVirtualCellConfiguration()
        self.config.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                  QtGui.QSizePolicy.Maximum)
        hLayout.addWidget(self.config)
        hPadWidget = QtGui.QWidget()
        hLayout.addWidget(hPadWidget)
        hPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                 QtGui.QSizePolicy.Ignored)

        vPadWidget = QtGui.QWidget()
        vLayout.addWidget(vPadWidget)
        vPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                QtGui.QSizePolicy.Expanding)

        self.inspector = PipelineInspector()
        self.pipeline = None
    def updateFromPipeline(self, pipeline):
        """ updateFromPipeline(pipeline: Pipeline) -> None
        Read the list of aliases and parameters from the pipeline
        
        """
        self.clear()
        if not pipeline:
            return

        # Update the aliases
        if len(pipeline.aliases)>0:
            aliasRoot = QParameterTreeWidgetItem(None, self,
                                                 QtCore.QStringList('Aliases'))
            aliasRoot.setFlags(QtCore.Qt.ItemIsEnabled,
                               )
            for (alias, info) in pipeline.aliases.iteritems():
                ptype, pId, parentType, parentId, _ = info
                parameter = pipeline.db_get_object(ptype, pId)
                v = parameter.strValue
                aType = parameter.type
                aIdentifier = parameter.identifier
                aNamespace = parameter.namespace
                label = QtCore.QStringList('%s = %s' % (alias, v))
                pInfo = ParameterInfo(type=aType,
                                      identifier=aIdentifier,
                                      namespace=aNamespace,
                                      value=v,
                                      id=pId,
                                      dbtype=ptype,
                                      parent_dbtype=parentType,
                                      parent_id=parentId,
                                      is_alias=True)
                aliasItem = QParameterTreeWidgetItem((alias, [pInfo]),
                                                     aliasRoot, label)
            aliasRoot.setExpanded(True)
            
        # Now go through all modules and functions

        inspector = PipelineInspector()
        inspector.inspect_ambiguous_modules(pipeline)
        sortedModules = sorted(pipeline.modules.iteritems(),
                               key=lambda item: item[1].name)
        for mId, module in sortedModules:
            if len(module.functions)>0:
                mLabel = QtCore.QStringList(module.name)
                moduleItem = None
                for fId in xrange(len(module.functions)):
                    function = module.functions[fId]
                    if len(function.params)==0: continue
                    if moduleItem==None:
                        if inspector.annotated_modules.has_key(mId):
                            annotatedId = inspector.annotated_modules[mId]
                            moduleItem = QParameterTreeWidgetItem(annotatedId,
                                                                  self, mLabel)
                        else:
                            moduleItem = QParameterTreeWidgetItem(None,
                                                                  self, mLabel)
                    v = ', '.join([p.strValue for p in function.params])
                    label = QtCore.QStringList('%s(%s)' % (function.name, v))
                    
                    pList = [ParameterInfo(type=function.params[pId].type,
                                           identifier=function.params[pId].identifier,
                                           namespace=function.params[pId].namespace,
                                           value=function.params[pId].strValue,
                                           id=function.params[pId].real_id,
                                           dbtype=ModuleParam.vtType,
                                           parent_dbtype=function.vtType,
                                           parent_id=function.real_id,
                                           is_alias=False)
                             for pId in xrange(len(function.params))]
                    mName = module.name
                    if moduleItem.parameter!=None:
                        mName += '(%d)' % moduleItem.parameter
                    fName = '%s :: %s' % (mName, function.name)
                    mItem = QParameterTreeWidgetItem((fName, pList),
                                                     moduleItem,
                                                     label)
                if moduleItem:
                    moduleItem.setExpanded(True)
Exemplo n.º 11
0
class QVirtualCellWindow(QtGui.QFrame, QToolWindowInterface):
    """
    QVirtualCellWindow contains a caption, a virtual cell
    configuration
    
    """
    def __init__(self, parent=None):
        """ QVirtualCellWindow(parent: QWidget) -> QVirtualCellWindow
        Initialize the widget

        """
        QtGui.QFrame.__init__(self, parent)
        self.setFrameShape(QtGui.QFrame.StyledPanel)
        self.setWindowTitle('Spreadsheet Virtual Cell')
        vLayout = QtGui.QVBoxLayout(self)
        vLayout.setMargin(2)
        vLayout.setSpacing(0)
        self.setLayout(vLayout)
        
        label = QtGui.QLabel('Arrange the cell(s) below to construct'
                             ' a virtual cell')
        font = QtGui.QFont(label.font())
        label.setFont(font)
        label.setWordWrap(True)        
        vLayout.addWidget(label)

        hLayout = QtGui.QVBoxLayout()
        hLayout.setMargin(0)
        hLayout.setSpacing(0)
        vLayout.addLayout(hLayout)
        self.config = QVirtualCellConfiguration()
        self.config.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                  QtGui.QSizePolicy.Maximum)
        hLayout.addWidget(self.config)
        hPadWidget = QtGui.QWidget()
        hLayout.addWidget(hPadWidget)
        hPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                 QtGui.QSizePolicy.Ignored)

        vPadWidget = QtGui.QWidget()
        vLayout.addWidget(vPadWidget)
        vPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                QtGui.QSizePolicy.Expanding)

        self.inspector = PipelineInspector()
        self.pipeline = None

    def updateVirtualCell(self, pipeline):        
        """ updateVirtualCell(pipeline: QPipeline) -> None
        Setup the virtual cells given a pipeline
        
        """
        self.pipeline = pipeline
        if self.pipeline and self.pipeline.is_valid:
            self.inspector.inspect_spreadsheet_cells(self.pipeline)
            self.inspector.inspect_ambiguous_modules(self.pipeline)
            cells = []
            for id_list in self.inspector.spreadsheet_cells:
                pipeline = self.pipeline
                id_iter = iter(id_list)
                m = pipeline.modules[id_iter.next()]
                m_id = m.id
                for m_id in id_iter:
                    pipeline = m.pipeline
                    m = pipeline.modules[m_id]
                    
                name = m.name
                if len(id_list) == 1 and \
                        m_id in self.inspector.annotated_modules:
                    cells.append((name, self.inspector.annotated_modules[m_id]))
                elif tuple(id_list) in self.inspector.annotated_modules:
                    cells.append((name, self.inspector.annotated_modules[ \
                                tuple(id_list)]))
                else:
                    cells.append((name, -1))
            self.config.configVirtualCells(cells)
        else:

            self.config.clear()

    def getConfiguration(self):
        """ getConfiguration() -> info (see below)
        Return the current configuration of the virtual cell. The
        information is:
        info = (rowCount, columnCount,
                {(type,id): (row, column)})
        """
        return self.config.getConfiguration()
                
    def setConfiguration(self, info):
        """ setConfiguration(info) -> None (see below)
        Set the configuration of the virtual cell. The
        information is:
        info = {(type, id): (row, column)}
          or
        info = (rowCount, columnCount,
                {(type, id): (row, column)})
        The second form is allowed so that the output of
        getConfiguration could be passed directly to
        setConfiguration (the dimensions aren't used).
        """
        self.config.setConfiguration(info)

    def positionPipelines(self, sheetPrefix, sheetCount, rowCount, colCount,
                          pipelines, controller):
        """ positionPipelines(sheetPrefix: str, sheetCount: int, rowCount: int,
                              colCount: int, pipelines: list of Pipeline)
                              -> list of Pipelines
        Apply the virtual cell location to a list of pipelines in a
        parameter exploration given that pipelines has multiple chunk
        of sheetCount x rowCount x colCount cells
        
        """
        return _positionPipelines(sheetPrefix, sheetCount, rowCount, colCount, 
                                  pipelines, self.getConfiguration(), 
                                  self.pipeline, controller)
Exemplo n.º 12
0
class QVirtualCellWindow(QtGui.QFrame, QToolWindowInterface):
    """
    QVirtualCellWindow contains a caption, a virtual cell
    configuration
    
    """
    def __init__(self, parent=None):
        """ QVirtualCellWindow(parent: QWidget) -> QVirtualCellWindow
        Initialize the widget

        """
        QtGui.QFrame.__init__(self, parent)
        self.setFrameShape(QtGui.QFrame.StyledPanel)
        self.setWindowTitle('Spreadsheet Virtual Cell')
        vLayout = QtGui.QVBoxLayout(self)
        vLayout.setMargin(2)
        vLayout.setSpacing(0)
        self.setLayout(vLayout)

        label = QtGui.QLabel('Arrange the cell(s) below to construct'
                             ' a virtual cell')
        font = QtGui.QFont(label.font())
        label.setFont(font)
        label.setWordWrap(True)
        vLayout.addWidget(label)

        hLayout = QtGui.QVBoxLayout()
        hLayout.setMargin(0)
        hLayout.setSpacing(0)
        vLayout.addLayout(hLayout)
        self.config = QVirtualCellConfiguration()
        self.config.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                  QtGui.QSizePolicy.Maximum)
        hLayout.addWidget(self.config)
        hPadWidget = QtGui.QWidget()
        hLayout.addWidget(hPadWidget)
        hPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                 QtGui.QSizePolicy.Ignored)

        vPadWidget = QtGui.QWidget()
        vLayout.addWidget(vPadWidget)
        vPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                 QtGui.QSizePolicy.Expanding)

        self.inspector = PipelineInspector()
        self.pipeline = None

    def updateVirtualCell(self, pipeline):
        """ updateVirtualCell(pipeline: QPipeline) -> None
        Setup the virtual cells given a pipeline
        
        """
        self.pipeline = pipeline
        if self.pipeline and self.pipeline.is_valid:
            self.inspector.inspect_spreadsheet_cells(self.pipeline)
            self.inspector.inspect_ambiguous_modules(self.pipeline)
            cells = []
            for id_list in self.inspector.spreadsheet_cells:
                pipeline = self.pipeline
                id_iter = iter(id_list)
                m = pipeline.modules[id_iter.next()]
                m_id = m.id
                for m_id in id_iter:
                    pipeline = m.pipeline
                    m = pipeline.modules[m_id]

                name = m.name
                if len(id_list) == 1 and \
                        m_id in self.inspector.annotated_modules:
                    cells.append(
                        (name, self.inspector.annotated_modules[m_id]))
                elif tuple(id_list) in self.inspector.annotated_modules:
                    cells.append((name, self.inspector.annotated_modules[ \
                                tuple(id_list)]))
                else:
                    cells.append((name, -1))
            self.config.configVirtualCells(cells)
        else:

            self.config.clear()

    def getConfiguration(self):
        """ getConfiguration() -> info (see below)
        Return the current configuration of the virtual cell. The
        information is:
        info = (rowCount, columnCount,
                {(type,id): (row, column)})
        """
        return self.config.getConfiguration()

    def setConfiguration(self, info):
        """ setConfiguration(info) -> None (see below)
        Set the configuration of the virtual cell. The
        information is:
        info = {(type, id): (row, column)}
          or
        info = (rowCount, columnCount,
                {(type, id): (row, column)})
        The second form is allowed so that the output of
        getConfiguration could be passed directly to
        setConfiguration (the dimensions aren't used).
        """
        self.config.setConfiguration(info)

    def positionPipelines(self, sheetPrefix, sheetCount, rowCount, colCount,
                          pipelines, controller):
        """ positionPipelines(sheetPrefix: str, sheetCount: int, rowCount: int,
                              colCount: int, pipelines: list of Pipeline)
                              -> list of Pipelines
        Apply the virtual cell location to a list of pipelines in a
        parameter exploration given that pipelines has multiple chunk
        of sheetCount x rowCount x colCount cells
        
        """
        return _positionPipelines(sheetPrefix, sheetCount,
                                  rowCount, colCount, pipelines,
                                  self.getConfiguration(), self.pipeline,
                                  controller)
Exemplo n.º 13
0
    def updateFromPipeline(self, pipeline):
        """ updateFromPipeline(pipeline: Pipeline) -> None
        Read the list of aliases and parameters from the pipeline
        
        """
        self.clear()
        if not pipeline:
            return

        # Update the aliases
        if len(pipeline.aliases) > 0:
            aliasRoot = QParameterTreeWidgetItem(None, self,
                                                 QtCore.QStringList('Aliases'))
            aliasRoot.setFlags(QtCore.Qt.ItemIsEnabled, )
            for (alias, info) in pipeline.aliases.iteritems():
                ptype, pId, parentType, parentId, _ = info
                parameter = pipeline.db_get_object(ptype, pId)
                v = parameter.strValue
                aType = parameter.type
                aIdentifier = parameter.identifier
                aNamespace = parameter.namespace
                label = QtCore.QStringList('%s = %s' % (alias, v))
                pInfo = ParameterInfo(type=aType,
                                      identifier=aIdentifier,
                                      namespace=aNamespace,
                                      value=v,
                                      id=pId,
                                      dbtype=ptype,
                                      parent_dbtype=parentType,
                                      parent_id=parentId,
                                      is_alias=True)
                aliasItem = QParameterTreeWidgetItem((alias, [pInfo]),
                                                     aliasRoot, label)
            aliasRoot.setExpanded(True)

        # Now go through all modules and functions

        inspector = PipelineInspector()
        inspector.inspect_ambiguous_modules(pipeline)
        sortedModules = sorted(pipeline.modules.iteritems(),
                               key=lambda item: item[1].name)
        for mId, module in sortedModules:
            if len(module.functions) > 0:
                mLabel = QtCore.QStringList(module.name)
                moduleItem = None
                for fId in xrange(len(module.functions)):
                    function = module.functions[fId]
                    if len(function.params) == 0: continue
                    if moduleItem == None:
                        if inspector.annotated_modules.has_key(mId):
                            annotatedId = inspector.annotated_modules[mId]
                            moduleItem = QParameterTreeWidgetItem(
                                annotatedId, self, mLabel)
                        else:
                            moduleItem = QParameterTreeWidgetItem(
                                None, self, mLabel)
                    v = ', '.join([p.strValue for p in function.params])
                    label = QtCore.QStringList('%s(%s)' % (function.name, v))

                    pList = [
                        ParameterInfo(
                            type=function.params[pId].type,
                            identifier=function.params[pId].identifier,
                            namespace=function.params[pId].namespace,
                            value=function.params[pId].strValue,
                            id=function.params[pId].real_id,
                            dbtype=ModuleParam.vtType,
                            parent_dbtype=function.vtType,
                            parent_id=function.real_id,
                            is_alias=False)
                        for pId in xrange(len(function.params))
                    ]
                    mName = module.name
                    if moduleItem.parameter != None:
                        mName += '(%d)' % moduleItem.parameter
                    fName = '%s :: %s' % (mName, function.name)
                    mItem = QParameterTreeWidgetItem((fName, pList),
                                                     moduleItem, label)
                if moduleItem:
                    moduleItem.setExpanded(True)
Exemplo n.º 14
0
class QAnnotatedPipelineView(QPipelineView, QToolWindowInterface):
    """
    QAnnotatedPipelineView subclass QPipelineView to perform some overlay
    marking on a pipeline view
    
    """
    def __init__(self, parent=None):
        """ QPipelineView(parent: QWidget) -> QPipelineView
        Initialize the graphics view and its properties
        
        """
        QPipelineView.__init__(self, parent)
        self.setWindowTitle('Annotated Pipeline')
        self.inspector = PipelineInspector()

    def sizeHint(self):
        """ sizeHint() -> QSize
        Prefer the view not so large
        
        """
        return QtCore.QSize(256, 256)

    def paintEvent(self, event):
        """ paintEvent(event: QPaintEvent) -> None
        Paint an overlay annotation on spreadsheet cell modules
        
        """
        QPipelineView.paintEvent(self, event)
        # super(QAnnotatedPipelineView, self).paintEvent(event)
        if self.scene():
            painter = QtGui.QPainter(self.viewport())
            for mId, annotatedId in \
                    self.inspector.annotated_modules.iteritems():
                if mId not in self.scene().modules:
                    # faulty annotated_modules entry
                    continue
                item = self.scene().modules[mId]
                br = item.sceneBoundingRect()
                rect = QtCore.QRect(self.mapFromScene(br.topLeft()),
                                    self.mapFromScene(br.bottomRight()))
                QAnnotatedPipelineView.drawId(painter, rect, annotatedId)
            painter.end()

    def updateAnnotatedIds(self, pipeline):
        """ updateAnnotatedIds(pipeline: Pipeline) -> None
        Re-inspect the pipeline to get annotated ids
        
        """
        if pipeline and self.scene():
            self.inspector.inspect_ambiguous_modules(pipeline)
            self.scene().fitToView(self)

    @staticmethod
    def drawId(painter, rect, id, align=QtCore.Qt.AlignCenter):
        """ drawId(painter: QPainter, rect: QRect, id: int,
                   align: QtCore.Qt.Align) -> None
        Draw the rounded id number on a rectangular area
        
        """
        painter.save()
        painter.setRenderHints(QtGui.QPainter.Antialiasing)
        painter.setPen(CurrentTheme.ANNOTATED_ID_BRUSH.color())
        painter.setBrush(CurrentTheme.ANNOTATED_ID_BRUSH)
        font = QtGui.QFont()
        font.setStyleStrategy(QtGui.QFont.ForceOutline)
        font.setBold(True)
        painter.setFont(font)
        fm = QtGui.QFontMetrics(font)
        size = fm.size(QtCore.Qt.TextSingleLine, str(id))
        size = max(size.width(), size.height())
        
        x = rect.left()
        if align & QtCore.Qt.AlignHCenter:
            x = rect.left() + rect.width()/2-size/2
        if align & QtCore.Qt.AlignRight:
            x = rect.left() + rect.width()-size
        y = rect.top()
        if align & QtCore.Qt.AlignVCenter:
            y = rect.top() + rect.height()/2-size/2
        if align & QtCore.Qt.AlignBottom:
            y = rect.top() + rect.height()-size
            
        newRect = QtCore.QRect(x, y, size, size)
        painter.drawEllipse(newRect)
        painter.setPen(CurrentTheme.ANNOTATED_ID_PEN)
        painter.drawText(newRect, QtCore.Qt.AlignCenter, str(id))
        painter.restore()
Exemplo n.º 15
0
class QVirtualCellWindow(QtGui.QFrame, QToolWindowInterface):
    """
    QVirtualCellWindow contains a caption, a virtual cell
    configuration
    
    """
    def __init__(self, parent=None):
        """ QVirtualCellWindow(parent: QWidget) -> QVirtualCellWindow
        Initialize the widget

        """
        QtGui.QFrame.__init__(self, parent)
        self.setFrameShape(QtGui.QFrame.StyledPanel)
        self.setWindowTitle('Spreadsheet Virtual Cell')
        vLayout = QtGui.QVBoxLayout(self)
        vLayout.setMargin(2)
        vLayout.setSpacing(0)
        self.setLayout(vLayout)
        
        label = QtGui.QLabel('Arrange the cell(s) below to construct'
                             ' a virtual cell')
        font = QtGui.QFont(label.font())
        label.setFont(font)
        label.setWordWrap(True)        
        vLayout.addWidget(label)

        hLayout = QtGui.QVBoxLayout()
        hLayout.setMargin(0)
        hLayout.setSpacing(0)
        vLayout.addLayout(hLayout)
        self.config = QVirtualCellConfiguration()
        self.config.setSizePolicy(QtGui.QSizePolicy.Maximum,
                                  QtGui.QSizePolicy.Maximum)
        hLayout.addWidget(self.config)
        hPadWidget = QtGui.QWidget()
        hLayout.addWidget(hPadWidget)
        hPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                 QtGui.QSizePolicy.Ignored)

        vPadWidget = QtGui.QWidget()
        vLayout.addWidget(vPadWidget)
        vPadWidget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                QtGui.QSizePolicy.Expanding)

        self.inspector = PipelineInspector()
        self.pipeline = None

    def updateVirtualCell(self, pipeline):        
        """ updateVirtualCell(pipeline: QPipeline) -> None
        Setup the virtual cells given a pipeline
        
        """
        self.pipeline = pipeline
        if pipeline:
            self.inspector.inspect_spreadsheet_cells(pipeline)
            self.inspector.inspect_ambiguous_modules(pipeline)
            cells = []
            for mId in self.inspector.spreadsheet_cells:
                name = pipeline.modules[mId].name
                if self.inspector.annotated_modules.has_key(mId):
                    cells.append((name, self.inspector.annotated_modules[mId]))
                else:
                    cells.append((name, -1))
            self.config.configVirtualCells(cells)
        else:

            self.config.clear()

    def getConfiguration(self):
        """ getConfiguration() -> info (see below)
        Return the current configuration of the virtual cell. The
        information is:
        info = (rowCount, columnCount,
                [{(type,id): (row, column)})
        """
        return self.config.getConfiguration()
                
    def decodeConfiguration(self, pipeline, cells):
        """ decodeConfiguration(pipeline: Pipeline,
                                cells: configuration) -> decoded cells
        Convert cells of type [{(type,id): (row, column)}) to
        (mId, row, col) in a particular pipeline
        
        """
        decodedCells = []
        inspector = PipelineInspector()
        inspector.inspect_spreadsheet_cells(pipeline)
        inspector.inspect_ambiguous_modules(pipeline)
        for mId in inspector.spreadsheet_cells:
            name = pipeline.modules[mId].name
            if inspector.annotated_modules.has_key(mId):
                idx = inspector.annotated_modules[mId]
            else:
                idx = -1
            (vRow, vCol) = cells[(name, idx)]
            decodedCells.append((mId, vRow, vCol))
        return decodedCells

    def positionPipelines(self, sheetPrefix, sheetCount, rowCount, colCount,
                          pipelines):
        """ positionPipelines(sheetPrefix: str, sheetCount: int, rowCount: int,
                              colCount: int, pipelines: list of Pipeline)
                              -> list of Pipelines
        Apply the virtual cell location to a list of pipelines in a
        parameter exploration given that pipelines has multiple chunk
        of sheetCount x rowCount x colCount cells
        
        """
        (vRCount, vCCount, cells) = self.getConfiguration()
        modifiedPipelines = []
        for pId in xrange(len(pipelines)):
            pipeline = copy.copy(pipelines[pId])
            col = pId % colCount
            row = (pId / colCount) % rowCount
            sheet = (pId / (colCount*rowCount)) % sheetCount
            
            decodedCells = self.decodeConfiguration(pipeline, cells)

            for (mId, vRow, vCol) in decodedCells:
                # Walk through all connection and remove all
                # CellLocation connected to this spreadsheet cell
                #  delConn = DeleteConnectionAction()
                action_list = []
                for (cId,c) in self.pipeline.connections.iteritems():
                    if (c.destinationId==mId and 
                        pipeline.modules[c.sourceId].name=="CellLocation"):
                        action_list.append(('delete', c))
                        # delConn.addId(cId)
                # delConn.perform(pipeline)
                action = db.services.action.create_action(action_list)
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)
                
                # Add a sheet reference with a specific name
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                sheetNameParam = ModuleParam(id=param_id,
                                             pos=0,
                                             name="",
                                             val="%s %d" % (sheetPrefix, sheet),
                                             type="String",
                                             alias="",
                                             )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                sheetNameFunction = ModuleFunction(id=function_id,
                                                   pos=0,
                                                   name="SheetName",
                                                   parameters=[sheetNameParam],
                                                   )
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                minRowParam = ModuleParam(id=param_id,
                                          pos=0,
                                          name="",
                                          val=str(rowCount*vRCount),
                                          type="Integer",
                                          alias="",
                                          )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                minRowFunction = ModuleFunction(id=function_id,
                                                pos=1,
                                                name="MinRowCount",
                                                parameters=[minRowParam],
                                                )
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                minColParam = ModuleParam(id=param_id,
                                          pos=0,
                                          name="",
                                          val=str(colCount*vCCount),
                                          type="Integer",
                                          alias="",
                                          )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                minColFunction = ModuleFunction(id=function_id,
                                                pos=2,
                                                name="MinColumnCount",
                                                parameters=[minColParam],
                                                )
                module_id = -pipeline.tmp_id.getNewId(module.Module.vtType)
                sheetReference = module.Module(id=module_id,
                                               name="SheetReference",
                                               package="edu.utah.sci.vistrails.spreadsheet",
                                               functions=[sheetNameFunction,
                                                          minRowFunction,
                                                          minColFunction])
                action = db.services.action.create_action([('add', 
                                                           sheetReference)])
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)

#                 sheetReference.id = pipeline.fresh_module_id()
#                 sheetReference.name = "SheetReference"
#                 addModule = AddModuleAction()
#                 addModule.module = sheetReference
#                 addModule.perform(pipeline)
#
#                 addParam = ChangeParameterAction()
#                 addParam.addParameter(sheetReference.id, 0, 0,
#                                       "SheetName", "",
#                                       '%s %d' % (sheetPrefix, sheet),
#                                       "String", "" )
#                 addParam.addParameter(sheetReference.id, 1, 0,
#                                       "MinRowCount", "",
#                                       str(rowCount*vRCount), "Integer", "" )
#                 addParam.addParameter(sheetReference.id, 2, 0,
#                                       "MinColumnCount", "",
#                                       str(colCount*vCCount), "Integer", "" )
#                 addParam.perform(pipeline)

                # Add a cell location module with a specific row and column
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                rowParam = ModuleParam(id=param_id,
                                       pos=0,
                                       name="",
                                       val=str(row*vRCount+vRow+1),
                                       type="Integer",
                                       alias="",
                                       )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                rowFunction = ModuleFunction(id=function_id,
                                             pos=0,
                                             name="Row",
                                             parameters=[rowParam],
                                             )
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                colParam = ModuleParam(id=param_id,
                                       pos=0,
                                       name="",
                                       val=str(col*vCCount+vCol+1),
                                       type="Integer",
                                       alias="",
                                       )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                colFunction = ModuleFunction(id=function_id,
                                             pos=1,
                                             name="Column",
                                             parameters=[colParam],
                                             )
                module_id = -pipeline.tmp_id.getNewId(module.Module.vtType)
                cellLocation = module.Module(id=module_id,
                                             name="CellLocation",
                                             package="edu.utah.sci.vistrails.spreadsheet",
                                             functions=[rowFunction,
                                                        colFunction])
                action = db.services.action.create_action([('add', 
                                                           cellLocation)])
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)
                
#                 cellLocation.id = pipeline.fresh_module_id()
#                 cellLocation.name = "CellLocation"
#                 addModule = AddModuleAction()
#                 addModule.module = cellLocation
#                 addModule.perform(pipeline)
#                
#                 addParam = ChangeParameterAction()                
#                 addParam.addParameter(cellLocation.id, 0, 0,
#                                       "Row", "", str(row*vRCount+vRow+1),
#                                       "Integer", "" )
#                 addParam.addParameter(cellLocation.id, 1, 0,
#                                       "Column", "", str(col*vCCount+vCol+1),
#                                       "Integer", "" )
#                 addParam.perform(pipeline)
                
                # Then connect the SheetReference to the CellLocation
                port_id = -pipeline.tmp_id.getNewId(Port.vtType)
                source = Port(id=port_id,
                              type='source',
                              moduleId=sheetReference.id,
                              moduleName=sheetReference.name)
                source.name = "self"
                source.spec = copy.copy(registry.get_output_port_spec(sheetReference,
                                                                      "self"))
                port_id = -pipeline.tmp_id.getNewId(Port.vtType)
                destination = Port(id=port_id,
                                   type='destination',
                                   moduleId=cellLocation.id,
                                   moduleName=cellLocation.name)
                destination.name = "SheetReference"
                destination.spec = copy.copy(registry.get_input_port_spec(cellLocation,
                                                                          "SheetReference"))
                c_id = -pipeline.tmp_id.getNewId(connection.Connection.vtType)
                conn = connection.Connection(id=c_id,
                                             ports=[source, destination])
                action = db.services.action.create_action([('add', 
                                                           conn)])
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)
                              
#                 conn = connection.Connection()
#                 conn.id = pipeline.fresh_connection_id()
#                 conn.source.moduleId = sheetReference.id
#                 conn.source.moduleName = sheetReference.name
#                 conn.source.name = "self"
#                 conn.source.spec = registry.getOutputPortSpec(
#                     sheetReference, "self")
#                 conn.connectionId = conn.id
#                 conn.destination.moduleId = cellLocation.id
#                 conn.destination.moduleName = cellLocation.name
#                 conn.destination.name = "SheetReference"
#                 conn.destination.spec = registry.getInputPortSpec(
#                     cellLocation, "SheetReference")
#                 addConnection = AddConnectionAction()
#                 addConnection.connection = conn
#                 addConnection.perform(pipeline)
                
                # Then connect the CellLocation to the spreadsheet cell
                port_id = -pipeline.tmp_id.getNewId(Port.vtType)
                source = Port(id=port_id,
                              type='source',
                              moduleId=cellLocation.id,
                              moduleName=cellLocation.name)
                source.name = "self"
                source.spec = registry.get_output_port_spec(cellLocation, "self")
                port_id = -pipeline.tmp_id.getNewId(Port.vtType)
                cell_module = pipeline.get_module_by_id(mId)
                destination = Port(id=port_id,
                                   type='destination',
                                   moduleId=mId,
                                   moduleName=pipeline.modules[mId].name)
                destination.name = "Location"
                destination.spec = registry.get_input_port_spec(cell_module,
                                                                "Location")
                c_id = -pipeline.tmp_id.getNewId(connection.Connection.vtType)
                conn = connection.Connection(id=c_id,
                                             ports=[source, destination])
                action = db.services.action.create_action([('add', 
                                                           conn)])
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)

#                 conn = connection.Connection()
#                 conn.id = pipeline.fresh_connection_id()
#                 conn.source.moduleId = cellLocation.id
#                 conn.source.moduleName = cellLocation.name
#                 conn.source.name = "self"
#                 conn.source.spec = registry.getOutputPortSpec(
#                     cellLocation, "self")
#                 conn.connectionId = conn.id
#                 conn.destination.moduleId = mId
#                 conn.destination.moduleName = pipeline.modules[mId].name
#                 conn.destination.name = "Location"
#                 conn.destination.spec = registry.getInputPortSpec(
#                     cellLocation, "Location")
#                 addConnection = AddConnectionAction()
#                 addConnection.connection = conn
#                 addConnection.perform(pipeline)

            modifiedPipelines.append(pipeline)

        return modifiedPipelines
Exemplo n.º 16
0
class QAnnotatedPipelineView(QPipelineView, QToolWindowInterface):
    """
    QAnnotatedPipelineView subclass QPipelineView to perform some overlay
    marking on a pipeline view
    
    """
    def __init__(self, parent=None):
        """ QPipelineView(parent: QWidget) -> QPipelineView
        Initialize the graphics view and its properties
        
        """
        QPipelineView.__init__(self, parent)
        self.setWindowTitle('Annotated Pipeline')
        self.inspector = PipelineInspector()

    def sizeHint(self):
        """ sizeHint() -> QSize
        Prefer the view not so large
        
        """
        return QtCore.QSize(256, 256)

    def paintEvent(self, event):
        """ paintEvent(event: QPaintEvent) -> None
        Paint an overlay annotation on spreadsheet cell modules
        
        """
        QPipelineView.paintEvent(self, event)
        # super(QAnnotatedPipelineView, self).paintEvent(event)
        if self.scene():
            painter = QtGui.QPainter(self.viewport())
            for mId, annotatedId in \
                    self.inspector.annotated_modules.iteritems():
                item = self.scene().modules[mId]
                br = item.sceneBoundingRect()
                rect = QtCore.QRect(self.mapFromScene(br.topLeft()),
                                    self.mapFromScene(br.bottomRight()))
                QAnnotatedPipelineView.drawId(painter, rect, annotatedId)
            painter.end()

    def updateAnnotatedIds(self, pipeline):
        """ updateAnnotatedIds(pipeline: Pipeline) -> None
        Re-inspect the pipeline to get annotated ids
        
        """
        self.inspector.inspect_ambiguous_modules(pipeline)
        self.scene().fitToView(self)

    @staticmethod
    def drawId(painter, rect, id, align=QtCore.Qt.AlignCenter):
        """ drawId(painter: QPainter, rect: QRect, id: int,
                   align: QtCore.Qt.Align) -> None
        Draw the rounded id number on a rectangular area
        
        """
        painter.save()
        painter.setRenderHints(QtGui.QPainter.Antialiasing)
        painter.setPen(CurrentTheme.ANNOTATED_ID_BRUSH.color())
        painter.setBrush(CurrentTheme.ANNOTATED_ID_BRUSH)
        font = QtGui.QFont()
        font.setStyleStrategy(QtGui.QFont.ForceOutline)
        font.setBold(True)
        painter.setFont(font)
        fm = QtGui.QFontMetrics(font)
        size = fm.size(QtCore.Qt.TextSingleLine, str(id))
        size = max(size.width(), size.height())
        
        x = rect.left()
        if align & QtCore.Qt.AlignHCenter:
            x = rect.left() + rect.width()/2-size/2
        if align & QtCore.Qt.AlignRight:
            x = rect.left() + rect.width()-size
        y = rect.top()
        if align & QtCore.Qt.AlignVCenter:
            y = rect.top() + rect.height()/2-size/2
        if align & QtCore.Qt.AlignBottom:
            y = rect.top() + rect.height()-size
            
        newRect = QtCore.QRect(x, y, size, size)
        painter.drawEllipse(newRect)
        painter.setPen(CurrentTheme.ANNOTATED_ID_PEN)
        painter.drawText(newRect, QtCore.Qt.AlignCenter, str(id))
        painter.restore()
Exemplo n.º 17
0
class SubModule(NotCacheable, Module):
    """
    SubModule is the base class of all SubModule class. Inherited
    classes should change vistrail locator and version number refering
    to the sub pipeline it represents
    
    """
    # Vistrail object where this sub module is from
    Vistrail = None
    
    # XML File containing the Vistrail
    VistrailLocator = None

    # Version number, within the locator, that represents the pipeline
    VersionNumber = 0

    def __init__(self):
        """ SubModule() -> SubModule
        Create an inspector for pipeline
        
        """
        NotCacheable.__init__(self)
        Module.__init__(self)
        self.inspector = PipelineInspector()

    def compute(self):
        """ compute() -> None
        Connects the sub-pipeline to the rest of the module
        """
        pipeline = self.Vistrail.getPipeline(self.VersionNumber)
        interpreter = noncached_interpreter.get()
        interpreter.set_done_summon_hook(self.glueInputPorts)
        interpreter.set_done_update_hook(self.glueOutputPorts)        
        interpreter.execute(None,
                            pipeline,
                            '<<SUBMODULE>>',
                            None,
                            useLock=False)
        interpreter.set_done_summon_hook(None)
        interpreter.set_done_update_hook(None)

    def glueInputPorts(self, pipeline, objects):
        """ glueInputPorts(pipeline: Pipeline, objects: [object]) -> None
        Added additional input port to sub module
        
        """
        # Make sure we the sub modules interpreter point to the
        # sub_module interpreter for file pool
        for obj in objects.itervalues():
            obj.interpreter = self.interpreter
        
        self.inspector.inspect_input_output_ports(pipeline)
        for iport, conn in self.inputPorts.iteritems():
            inputPortId = self.inspector.input_port_by_name[iport]
            inputPortModule = objects[inputPortId]
            inputPortModule.set_input_port('ExternalPipe', conn[0])
        
    def glueOutputPorts(self, pipeline, objects):
        """ glueOutputPorts(pipeline: Pipeline, objects: [object]) -> None
        Added additional output port to sub module
        
        """
        self.inspector.inspect_input_output_ports(pipeline)
        for oport in self.outputPorts.keys():
            if self.inspector.output_port_by_name.has_key(oport):
                outputPortId = self.inspector.output_port_by_name[oport]
                outputPortModule = objects[outputPortId]
                self.setResult(oport,
                               outputPortModule.get_output('ExternalPipe'))
Exemplo n.º 18
0
def assignPipelineCellLocations(pipeline,
                                sheetName,
                                row,
                                col,
                                cellIds=None,
                                minRowCount=None,
                                minColCount=None):

    reg = get_module_registry()
    spreadsheet_cell_desc = \
        reg.get_descriptor_by_name('edu.utah.sci.vistrails.spreadsheet', \
                                       'SpreadsheetCell')

    create_module = VistrailController.create_module_static
    create_function = VistrailController.create_function_static
    create_connection = VistrailController.create_connection_static

    pipeline = copy.copy(pipeline)
    root_pipeline = pipeline
    if cellIds is None:
        inspector = PipelineInspector()
        inspector.inspect_spreadsheet_cells(pipeline)
        inspector.inspect_ambiguous_modules(pipeline)
        cellIds = inspector.spreadsheet_cells

    for id_list in cellIds:
        # find at which depth we need to be working
        try:
            id_iter = iter(id_list)
            m = pipeline.modules[id_iter.next()]
            for mId in id_iter:
                pipeline = m.pipeline
                m = pipeline.modules[mId]
        except TypeError:
            mId = id_list

        m = pipeline.modules[mId]
        if not reg.is_descriptor_subclass(m.module_descriptor,
                                          spreadsheet_cell_desc):
            continue

        # Walk through all connections and remove all CellLocation
        # modules connected to this spreadsheet cell
        conns_to_delete = []
        for (cId, c) in pipeline.connections.iteritems():
            if (c.destinationId == mId
                    and pipeline.modules[c.sourceId].name == "CellLocation"):
                conns_to_delete.append(c.id)
        for c_id in conns_to_delete:
            pipeline.delete_connection(c_id)

        # a hack to first get the id_scope to the local pipeline scope
        # then make them negative by hacking the getNewId method
        # all of this is reset at the end of this block
        id_scope = pipeline.tmp_id
        orig_getNewId = pipeline.tmp_id.__class__.getNewId

        def getNewId(self, objType):
            return -orig_getNewId(self, objType)

        pipeline.tmp_id.__class__.getNewId = getNewId

        # Add a sheet reference with a specific name
        sheetReference = create_module(id_scope,
                                       "edu.utah.sci.vistrails.spreadsheet",
                                       "SheetReference")
        sheetNameFunction = create_function(id_scope, sheetReference,
                                            "SheetName", [str(sheetName)])
        # ["%s %d" % (sheetPrefix, sheet)])

        sheetReference.add_function(sheetNameFunction)

        if minRowCount is not None:
            minRowFunction = create_function(id_scope, sheetReference,
                                             "MinRowCount", [str(minRowCount)])
            # [str(rowCount*vRCount)])
            sheetReference.add_function(minRowFunction)
        if minColCount is not None:
            minColFunction = create_function(id_scope, sheetReference,
                                             "MinColumnCount",
                                             [str(minColCount)])
            # [str(colCount*vCCount)])
            sheetReference.add_function(minColFunction)

        # Add a cell location module with a specific row and column
        cellLocation = create_module(id_scope,
                                     "edu.utah.sci.vistrails.spreadsheet",
                                     "CellLocation")
        rowFunction = create_function(id_scope, cellLocation, "Row",
                                      [str(row)])
        # [str(row*vRCount+vRow+1)])
        colFunction = create_function(id_scope, cellLocation, "Column",
                                      [str(col)])
        # [str(col*vCCount+vCol+1)])

        cellLocation.add_function(rowFunction)
        cellLocation.add_function(colFunction)

        # Then connect the SheetReference to the CellLocation
        sheet_conn = create_connection(id_scope, sheetReference, "self",
                                       cellLocation, "SheetReference")

        # Then connect the CellLocation to the spreadsheet cell
        cell_module = pipeline.get_module_by_id(mId)
        cell_conn = create_connection(id_scope, cellLocation, "self",
                                      cell_module, "Location")

        pipeline.add_module(sheetReference)
        pipeline.add_module(cellLocation)
        pipeline.add_connection(sheet_conn)
        pipeline.add_connection(cell_conn)
        # replace the getNewId method
        pipeline.tmp_id.__class__.getNewId = orig_getNewId

    return root_pipeline
def assignPipelineCellLocations(pipeline, sheetName, 
                                row, col, cellIds=None,
                                minRowCount=None, minColCount=None):

    reg = get_module_registry()
    spreadsheet_cell_desc = \
        reg.get_descriptor_by_name('edu.utah.sci.vistrails.spreadsheet', \
                                       'SpreadsheetCell')

    create_module = VistrailController.create_module_static
    create_function = VistrailController.create_function_static
    create_connection = VistrailController.create_connection_static

    pipeline = copy.copy(pipeline)
    root_pipeline = pipeline
    if cellIds is None:
        inspector = PipelineInspector()
        inspector.inspect_spreadsheet_cells(pipeline)
        inspector.inspect_ambiguous_modules(pipeline)
        cellIds = inspector.spreadsheet_cells

    for id_list in cellIds:
        # find at which depth we need to be working
        try:                
            id_iter = iter(id_list)
            m = pipeline.modules[id_iter.next()]
            for mId in id_iter:
                pipeline = m.pipeline
                m = pipeline.modules[mId]
        except TypeError:
            mId = id_list

        m = pipeline.modules[mId]
        if not reg.is_descriptor_subclass(m.module_descriptor, 
                                          spreadsheet_cell_desc):
            continue

        # Walk through all connections and remove all CellLocation
        # modules connected to this spreadsheet cell
        conns_to_delete = []
        for (cId,c) in pipeline.connections.iteritems():
            if (c.destinationId==mId and 
                pipeline.modules[c.sourceId].name=="CellLocation"):
                conns_to_delete.append(c.id)
        for c_id in conns_to_delete:
            pipeline.delete_connection(c_id)

        # a hack to first get the id_scope to the local pipeline scope
        # then make them negative by hacking the getNewId method
        # all of this is reset at the end of this block
        id_scope = pipeline.tmp_id
        orig_getNewId = pipeline.tmp_id.__class__.getNewId
        def getNewId(self, objType):
            return -orig_getNewId(self, objType)
        pipeline.tmp_id.__class__.getNewId = getNewId

        # Add a sheet reference with a specific name
        sheetReference = create_module(id_scope,
                                       "edu.utah.sci.vistrails.spreadsheet",
                                       "SheetReference")
        sheetNameFunction = create_function(id_scope, sheetReference, 
                                            "SheetName", [str(sheetName)])
            # ["%s %d" % (sheetPrefix, sheet)])

        sheetReference.add_function(sheetNameFunction)

        if minRowCount is not None:
            minRowFunction = create_function(id_scope, sheetReference, 
                                             "MinRowCount", [str(minRowCount)])
                                                   # [str(rowCount*vRCount)])
            sheetReference.add_function(minRowFunction)
        if minColCount is not None:
            minColFunction = create_function(id_scope, sheetReference, 
                                             "MinColumnCount", 
                                             [str(minColCount)])
                                                   # [str(colCount*vCCount)])
            sheetReference.add_function(minColFunction)

        # Add a cell location module with a specific row and column
        cellLocation = create_module(id_scope, 
                                     "edu.utah.sci.vistrails.spreadsheet",
                                     "CellLocation")
        rowFunction = create_function(id_scope, cellLocation, "Row", [str(row)])
                                                 # [str(row*vRCount+vRow+1)])
        colFunction = create_function(id_scope, cellLocation, "Column", 
                                      [str(col)])
                                                 # [str(col*vCCount+vCol+1)])

        cellLocation.add_function(rowFunction)
        cellLocation.add_function(colFunction)

        # Then connect the SheetReference to the CellLocation
        sheet_conn = create_connection(id_scope, sheetReference, "self",
                                       cellLocation, "SheetReference")

        # Then connect the CellLocation to the spreadsheet cell
        cell_module = pipeline.get_module_by_id(mId)
        cell_conn = create_connection(id_scope, cellLocation, "self",
                                      cell_module, "Location")

        pipeline.add_module(sheetReference)
        pipeline.add_module(cellLocation)
        pipeline.add_connection(sheet_conn)
        pipeline.add_connection(cell_conn)
        # replace the getNewId method
        pipeline.tmp_id.__class__.getNewId = orig_getNewId

    return root_pipeline