def do_copy(self, new_ids=False, id_scope=None, id_remap=None): cp = DBConnection.do_copy(self, new_ids, id_scope, id_remap) cp.__class__ = Connection cp.makeConnection = moduleConnection(cp) for port in cp.ports: Port.convert(port) return cp
def getClearPipelines(self, dimensions, clientDimensions): result = [] for row in range(dimensions[3]): for column in range(dimensions[2]): localPipeline = Pipeline() vtkversion = self.getPackageVersion("edu.utah.sci.vistrails.vtk") vtkCell = Module(id=localPipeline.fresh_module_id(), name="VTKCell", package="edu.utah.sci.vistrails.vtk", version=vtkversion) action = create_action([('add',vtkCell)]) localPipeline.perform_action(action) vtkRenderer = Module(id=localPipeline.fresh_module_id(), name="vtkRenderer", package="edu.utah.sci.vistrails.vtk", version=vtkversion) action = create_action([('add',vtkRenderer)]) localPipeline.perform_action(action) src = registry.get_port_spec('edu.utah.sci.vistrails.vtk','vtkRenderer', None, 'self','output') dst = registry.get_port_spec('edu.utah.sci.vistrails.vtk','VTKCell', None, 'AddRenderer','input') inputPort = Port(id=localPipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkCell.id, moduleName=vtkCell.name) outputPort = Port(id=localPipeline.get_tmp_id(Port.vtType), spec=src, moduleId=vtkRenderer.id, moduleName=vtkRenderer.name) connection = Connection(id=localPipeline.fresh_connection_id(), ports=[inputPort,outputPort]) action = create_action([('add',connection)]) localPipeline.perform_action(action) cellLocation = self.getCellLocationModule(vtkCell, localPipeline) if not cellLocation is None: self.deleteModule(cellLocation, localPipeline) dim = clientDimensions[(column+dimensions[0], row+dimensions[1])] self.addCellLocation(vtkCell, localPipeline, (column, row), dimensions, dim) result.append(((dimensions[0]+column,dimensions[1]+row), serialize(localPipeline))) return result
def convert(_connection): # print "ports: %s" % _Connection._get_ports(_connection) if _connection.__class__ == Connection: return _connection.__class__ = Connection for port in _connection.ports: Port.convert(port) # _connection.sourceInfo = \ # (_connection.source.moduleName, _connection.source.sig) # _connection.destinationInfo = \ # (_connection.destination.moduleName, _connection.destination.sig) # # print _connection.sourceInfo # # print _connection.destinationInfo # portFromRepresentation = registry.portFromRepresentation # newSource = \ # portFromRepresentation(_connection.source.moduleName, # _connection.source.sig, # PortEndPoint.Source, None, True) # newDestination = \ # portFromRepresentation(_connection.destination.moduleName, # _connection.destination.sig, # PortEndPoint.Destination, None, True) # newSource.moduleId = _connection.source.moduleId # newDestination.moduleId = _connection.destination.moduleId # _connection.source = newSource # _connection.destination = newDestination _connection.makeConnection = moduleConnection(_connection)
def __init__(self, *args, **kwargs): """__init__() -> Connection Initializes source and destination ports. """ DBConnection.__init__(self, *args, **kwargs) if self.id is None: self.db_id = -1 if not len(self.ports) > 0: self.source = Port(type='source') self.destination = Port(type='destination') # self.source.endPoint = PortEndPoint.Source # self.destination.endPoint = PortEndPoint.Destination self.makeConnection = moduleConnection(self)
def make_port_from_module(module, port_type): for function in module.functions: if function.name == 'name': port_name = function.params[0].strValue if function.name == 'spec': port_spec = function.params[0].strValue port = Port(id=-1, name=port_name, type=port_type) portSpecs = port_spec[1:-1].split(',') signature = [] for s in portSpecs: spec = s.split(':', 2) signature.append(registry.get_descriptor_by_name(*spec).module) port.spec = core.modules.module_registry.PortSpec(signature) return port
def create_connection(self, id_scope=IdScope()): from core.vistrail.port import Port source = Port(id=id_scope.getNewId(Port.vtType), type='source', moduleId=21L, moduleName='String', name='value', signature='(edu.utah.sci.vistrails.basic:String)') destination = Port(id=id_scope.getNewId(Port.vtType), type='destination', moduleId=20L, moduleName='Float', name='value', signature='(edu.utah.sci.vistrails.basic:Float)') connection = Connection(id=id_scope.getNewId(Connection.vtType), ports=[source, destination]) return connection
def add_port_to_registry(self, port_spec): module = \ registry.get_descriptor_by_name(self.package, self.name, self.namespace).module if self.registry is None: self.registry = ModuleRegistry() self.registry.add_hierarchy(registry, self) if port_spec.type == 'input': endpoint = PortEndPoint.Destination else: endpoint = PortEndPoint.Source portSpecs = port_spec.spec[1:-1].split(',') signature = [registry.get_descriptor_from_name_only(spec).module for spec in portSpecs] port = Port() port.name = port_spec.name port.spec = core.modules.module_registry.PortSpec(signature) self.registry.add_port(module, endpoint, port)
def delete_port_from_registry(self, id): if not id in self.port_specs: raise VistrailsInternalError("id missing in port_specs") portSpec = self.port_specs[id] portSpecs = portSpec.spec[1:-1].split(',') signature = [registry.get_descriptor_from_name_only(spec).module for spec in portSpecs] port = Port(signature) port.name = portSpec.name port.spec = core.modules.module_registry.PortSpec(signature) module = \ registry.get_descriptor_by_name(self.package, self.name, self.namespace).module assert isinstance(self.registry, ModuleRegistry) if portSpec.type == 'input': self.registry.delete_input_port(module, port.name) else: self.registry.delete_output_port(module, port.name)
def addVTKCameraToRenderer(self, vtkRenderer, pipeline): """addVTKCameraToRenderer(renderer: Module, pipeline: Pipeline) -> Module Adds a vtkCamera module to the received vtkRenderer. If a camera already exists, it returns this camera""" vtkCamera = self.findUpstreamModuleByClass(vtkRenderer, self.getModuleClassByName('edu.utah.sci.vistrails.vtk','vtkCamera'), pipeline) if not vtkCamera is None: ### If a camera is already connected to the renderer, just return it return vtkCamera # Making sure we create the vtkCamera module using the current version of # the vtk package version = self.getPackageVersion("edu.utah.sci.vistrails.vtk") vtkCamera = Module(id=pipeline.fresh_module_id(), name="vtkCamera", package="edu.utah.sci.vistrails.vtk", version=version) action = create_action([('add',vtkCamera)]) pipeline.perform_action(action) src = registry.get_port_spec('edu.utah.sci.vistrails.vtk','vtkCamera', None, 'self','output') dst = registry.get_port_spec('edu.utah.sci.vistrails.vtk','vtkRenderer', None, 'SetActiveCamera','input') inputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkRenderer.id, moduleName=vtkRenderer.name) outputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=src, moduleId=vtkCamera.id, moduleName=vtkCamera.name) connection = Connection(id=pipeline.fresh_connection_id(), ports=[inputPort,outputPort]) action = create_action([('add',connection)]) pipeline.perform_action(action) return vtkCamera
def create_new_connection(controller, src_module, src_port, dst_module, dst_port): # spec -> name, type, signature output_port_id = controller.id_scope.getNewId(Port.vtType) if type(src_port) == type(""): output_port_spec = src_module.get_port_spec(src_port, 'output') output_port = Port(id=output_port_id, spec=output_port_spec, moduleId=src_module.id, moduleName=src_module.name) else: output_port = Port(id=output_port_id, name=src_port.name, type=src_port.type, signature=src_port.signature, moduleId=src_module.id, moduleName=src_module.name) input_port_id = controller.id_scope.getNewId(Port.vtType) if type(dst_port) == type(""): input_port_spec = dst_module.get_port_spec(dst_port, 'input') input_port = Port(id=input_port_id, spec=input_port_spec, moduleId=dst_module.id, moduleName=dst_module.name) else: input_port = Port(id=input_port_id, name=dst_port.name, type=dst_port.type, signature=dst_port.signature, moduleId=dst_module.id, moduleName=dst_module.name) conn_id = controller.id_scope.getNewId(Connection.vtType) connection = Connection(id=conn_id, ports=[input_port, output_port]) return connection
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
def addCellLocation(self, vtkCell, pipeline, position, dimensions, deviceDimensions): """addCellLocation(vtkCell: Module, pipeline: Pipeline, position: (Int, Int)) -> None This method adds a CellLocation module to the vtkCell to ensure that it is sent to the right spreadsheet cell in the display wall. This is done according to the tuple in position""" print "Device Dimensions", deviceDimensions ### Adds the CellLocation Module # We need to make sure we create the Cell Location Module using # the current spreadsheet version version = self.getPackageVersion("edu.utah.sci.vistrails.spreadsheet") cellLocation = Module(id=pipeline.fresh_module_id(), name="CellLocation", package="edu.utah.sci.vistrails.spreadsheet", version=version) action = create_action([('add',cellLocation)]) pipeline.perform_action(action) cellLocation = pipeline.get_module_by_id(cellLocation.id) vtkCell = pipeline.get_module_by_id(vtkCell.id) src = registry.get_port_spec('edu.utah.sci.vistrails.spreadsheet','CellLocation', None, 'self','output') dst = registry.get_port_spec('edu.utah.sci.vistrails.vtk','VTKCell', None, 'Location','input') ### Connects the CellLocation module to the vtkCell inputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=dst, moduleId=vtkCell.id, moduleName=vtkCell.name) outputPort = Port(id=pipeline.get_tmp_id(Port.vtType), spec=src, moduleId=cellLocation.id, moduleName=cellLocation.name) connection = Connection(id=pipeline.fresh_connection_id(), ports=[inputPort,outputPort]) action = create_action([('add',connection)]) pipeline.perform_action(action) action_list = [] ### Creates the Column function spec = registry.get_port_spec('edu.utah.sci.vistrails.spreadsheet','CellLocation',None, 'Column','input') columnFunction = spec.create_module_function() columnFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) columnFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) columnFunction.db_parameters_id_index[columnFunction.db_parameters[0].db_id] = columnFunction.db_parameters[0] action_list.append(('add',columnFunction, cellLocation.vtType, cellLocation.id)) ### Creates the Row function spec = registry.get_port_spec('edu.utah.sci.vistrails.spreadsheet','CellLocation',None, 'Row','input') rowFunction = spec.create_module_function() rowFunction.real_id = pipeline.get_tmp_id(ModuleFunction.vtType) rowFunction.db_parameters[0].db_id = pipeline.get_tmp_id(ModuleParam.vtType) rowFunction.db_parameters_id_index[rowFunction.db_parameters[0].db_id] = rowFunction.db_parameters[0] action_list.append(('add',rowFunction, cellLocation.vtType, cellLocation.id)) action = create_action(action_list) pipeline.perform_action(action) cellLocation = pipeline.get_module_by_id(cellLocation.id) columnFunction = [x for x in cellLocation._get_functions() if x.name == "Column"][0] rowFunction = [x for x in cellLocation._get_functions() if x.name == "Row"][0] ### Sets the value of columnFunction and rowFunction paramList = [] # columnValue = (dimensions[0] + position[0]) % 2 + 1 # rowValue = (dimensions[1] + position[1]) % 2 + 1 gPos = (dimensions[0] + position[0], dimensions[1] + position[1]) columnValue = (gPos[0]-deviceDimensions[0]) % deviceDimensions[2] + 1 rowValue = (gPos[1]-deviceDimensions[1]) % deviceDimensions[3] + 1 print (columnValue, rowValue) ### changes the Column function paramList.append((str(columnValue), columnFunction.params[0].type, columnFunction.params[0].namespace, columnFunction.params[0].identifier, None)) ### changes the Row function paramList.append((str(rowValue), rowFunction.params[0].type, rowFunction.params[0].namespace, rowFunction.params[0].identifier, None)) action_list = [] for i in xrange(len(paramList)): (p_val, p_type, p_namespace, p_identifier, p_alias) = paramList[i] function = columnFunction if i == 0 else rowFunction old_param = function.params[0] param_id = pipeline.get_tmp_id(ModuleParam.vtType) new_param = ModuleParam(id=param_id, pos=i, name='<no description>', alias=p_alias, val=p_val, type=p_type, identifier=p_identifier, namespace=p_namespace, ) action_list.append(('change', old_param, new_param, function.vtType, function.real_id)) action = create_action(action_list) pipeline.perform_action(action)
class Connection(DBConnection): """ A Connection is a connection between two modules. Right now there's only Module connections. """ ########################################################################## # Constructors and copy @staticmethod def from_port_specs(source, dest): """from_port_specs(source: PortSpec, dest: PortSpec) -> Connection Static method that creates a Connection given source and destination ports. """ conn = Connection() conn.source = copy.copy(source) conn.destination = copy.copy(dest) return conn @staticmethod def fromID(id): """fromTypeID(id: int) -> Connection Static method that creates a Connection given an id. """ conn = Connection() conn.id = id conn.source.endPoint = PortEndPoint.Source conn.destination.endPoint = PortEndPoint.Destination return conn def __init__(self, *args, **kwargs): """__init__() -> Connection Initializes source and destination ports. """ DBConnection.__init__(self, *args, **kwargs) if self.id is None: self.db_id = -1 if not len(self.ports) > 0: self.source = Port(type='source') self.destination = Port(type='destination') # self.source.endPoint = PortEndPoint.Source # self.destination.endPoint = PortEndPoint.Destination self.makeConnection = moduleConnection(self) def __copy__(self): """__copy__() -> Connection - Returns a clone of self. """ return Connection.do_copy(self) def do_copy(self, new_ids=False, id_scope=None, id_remap=None): cp = DBConnection.do_copy(self, new_ids, id_scope, id_remap) cp.__class__ = Connection cp.makeConnection = moduleConnection(cp) for port in cp.ports: Port.convert(port) return cp ########################################################################## @staticmethod def convert(_connection): # print "ports: %s" % _Connection._get_ports(_connection) if _connection.__class__ == Connection: return _connection.__class__ = Connection for port in _connection.ports: Port.convert(port) # _connection.sourceInfo = \ # (_connection.source.moduleName, _connection.source.sig) # _connection.destinationInfo = \ # (_connection.destination.moduleName, _connection.destination.sig) # # print _connection.sourceInfo # # print _connection.destinationInfo # portFromRepresentation = registry.portFromRepresentation # newSource = \ # portFromRepresentation(_connection.source.moduleName, # _connection.source.sig, # PortEndPoint.Source, None, True) # newDestination = \ # portFromRepresentation(_connection.destination.moduleName, # _connection.destination.sig, # PortEndPoint.Destination, None, True) # newSource.moduleId = _connection.source.moduleId # newDestination.moduleId = _connection.destination.moduleId # _connection.source = newSource # _connection.destination = newDestination _connection.makeConnection = moduleConnection(_connection) ########################################################################## # Debugging def show_comparison(self, other): if type(other) != type(self): print "Type mismatch" return if self.__source != other.__source: print "Source mismatch" self.__source.show_comparison(other.__source) return if self.__dest != other.__dest: print "Dest mismatch" self.__dest.show_comparison(other.__dest) return print "no difference found" assert self == other ########################################################################## # Properties id = DBConnection.db_id ports = DBConnection.db_ports def add_port(self, port): self.db_add_port(port) def _get_sourceId(self): """ _get_sourceId() -> int Returns the module id of source port. Do not use this function, use sourceId property: c.sourceId """ return self.source.moduleId def _set_sourceId(self, id): """ _set_sourceId(id : int) -> None Sets this connection source id. It updates both self.__source.moduleId and self.__source.id. Do not use this function, use sourceId property: c.sourceId = id """ self.source.moduleId = id self.source.id = id sourceId = property(_get_sourceId, _set_sourceId) def _get_destinationId(self): """ _get_destinationId() -> int Returns the module id of dest port. Do not use this function, use sourceId property: c.destinationId """ return self.destination.moduleId def _set_destinationId(self, id): """ _set_destinationId(id : int) -> None Sets this connection destination id. It updates self.__dest.moduleId. Do not use this function, use destinationId property: c.destinationId = id """ self.destination.moduleId = id destinationId = property(_get_destinationId, _set_destinationId) def _get_type(self): """_get_type() -> VistrailModuleType - Returns this connection type. Do not use this function, use type property: c.type = t """ return self.source.type def _set_type(self, t): """ _set_type(t: VistrailModuleType) -> None Sets this connection type and updates self.__source.type and self.__dest.type. It also updates the correct makeConnection function. Do not use this function, use type property: c.type = t """ self.source.type = t self.destination.type = t self.updateMakeConnection() type = property(_get_type, _set_type) def _get_source(self): """_get_source() -> Port Returns source port. Do not use this function, use source property: c.source """ try: return self.db_get_port_by_type('source') except KeyError: pass return None def _set_source(self, source): """_set_source(source: Port) -> None Sets this connection source port. It also updates this connection makeConnection function. Do not use this function, use source property instead: c.source = source """ try: port = self.db_get_port_by_type('source') self.db_delete_port(port) except KeyError: pass if source is not None: self.db_add_port(source) source = property(_get_source, _set_source) def _get_destination(self): """_get_destination() -> Port Returns destination port. Do not use this function, use destination property: c.destination """ # return self.db_ports['destination'] try: return self.db_get_port_by_type('destination') except KeyError: pass return None def _set_destination(self, dest): """_set_destination(dest: Port) -> None Sets this connection destination port. It also updates this connection makeConnection function. Do not use this function, use destination property instead: c.destination = dest """ try: port = self.db_get_port_by_type('destination') self.db_delete_port(port) except KeyError: pass if dest is not None: self.db_add_port(dest) destination = property(_get_destination, _set_destination) dest = property(_get_destination, _set_destination) ########################################################################## # Operators def __str__(self): """__str__() -> str - Returns a string representation of a Connection object. """ rep = "<connection id='%s'>%s%s</connection>" return rep % (str(self.id), str(self.source), str(self.destination)) def __ne__(self, other): return not self.__eq__(other) def __eq__(self, other): if type(other) != type(self): return False return (self.source == other.source and self.dest == other.dest) def equals_no_id(self, other): """Checks equality up to ids (connection and ports).""" if type(self) != type(other): return False return (self.source.equals_no_id(other.source) and self.dest.equals_no_id(other.dest))