def setupScene(self, pipeline):
        old_pipeline = self.current_pipeline
        self.current_pipeline = pipeline
        if self.noUpdate: return
        if (pipeline is None or 
            (old_pipeline and not old_pipeline.is_valid) or 
            (pipeline and not pipeline.is_valid)):
            # clear things
            self.clear()
        if not pipeline: return 

        needReset = len(self.items())==0
        try:
            self.skip_update = True
            new_modules = set(pipeline.modules)
            modules_to_be_added = new_modules - self._old_module_ids
            modules_to_be_deleted = self._old_module_ids - new_modules
            common_modules = new_modules.intersection(self._old_module_ids)

            new_connections = set(pipeline.connections)
            connections_to_be_added = new_connections - self._old_connection_ids
            connections_to_be_deleted = self._old_connection_ids - new_connections
            common_connections = new_connections.intersection(self._old_connection_ids)


            # Check if connections to be added require
            # optional ports in modules to be visible
            # check all connections because the visible flag
            # may have been cleared
            for c_id in new_connections:
                connection = pipeline.connections[c_id]
                smid = connection.source.moduleId
                s = connection.source.spec
                if s and s.optional:
                    smm = pipeline.modules[smid]
                    smm.visible_output_ports.add(s.name)
                dmid = connection.destination.moduleId   
                d = connection.destination.spec
                if d and d.optional:
                    dmm = pipeline.modules[dmid]
                    dmm.visible_input_ports.add(d.name)

            # remove old connection shapes
            for c_id in connections_to_be_deleted:
                self.remove_connection(c_id)
            # remove old module shapes
            for m_id in modules_to_be_deleted:
                self.remove_module(m_id)

            selected_modules = []
            # create new module shapes
            for m_id in modules_to_be_added:
                self.addModule(pipeline.modules[m_id])
                if self.modules[m_id].isSelected():
                    selected_modules.append(m_id)

            moved = set()
            # Update common modules
            for m_id in common_modules:
                tm_item = self.modules[m_id]
                nm = pipeline.modules[m_id]
                if tm_item.moduleHasChanged(nm):
                    self.recreate_module(pipeline, m_id)
                    tm_item = self.modules[m_id]
                elif tm_item.moduleFunctionsHaveChanged(nm):
                    tm_item.update_function_ports(pipeline.modules[m_id])
                tm_item.update_function_values(pipeline.modules[m_id])
                if tm_item.isSelected():
                    selected_modules.append(m_id)
                if self.controller and self.controller.search:
                    moduleQuery = (self.controller.current_version, nm)
                    matched = \
                        self.controller.search.matchModule(*moduleQuery)
                    tm_item.setGhosted(not matched)
                else:
                    tm_item.setGhosted(False)
                tm_item.setBreakpoint(nm.is_breakpoint)

            # create new connection shapes
            for c_id in connections_to_be_added:
                self.addConnection(pipeline.connections[c_id])

            # Update common connections
            for c_id in common_connections:
                connection = pipeline.connections[c_id]
                pip_c = self.connections[c_id]
                pip_c.connectingModules = (self.modules[connection.source.moduleId],
                                           self.modules[connection.destination.moduleId])
                (srcModule, dstModule) = pip_c.connectingModules

            self._old_module_ids = new_modules
            self._old_connection_ids = new_connections
            self.unselect_all()
            self.reset_module_colors()
            for m_id in selected_modules:
                self.modules[m_id].setSelected(True)

        except ModuleRegistryException, e:
            debug.print_exc()
            views = self.views()
            assert len(views) > 0
            debug.critical("Missing package/module",
                ("Package '%s' is missing (or module '%s' is not present " +
                "in that package)") % (e._identifier, e._name))
            self.clear()
            self.controller.change_selected_version(0)
        finally:
            self.skip_update = False
            self.update_connections()

        if needReset and len(self.items())>0:
            self.fitToAllViews()
setupScene(pipeline: Pipeline) -> None
dataset/ETHPy150Open VisTrails/VisTrails/vistrails/gui/pipeline_view.py/QPipelineScene.setupScene