def layoutSuite(self, vacantRow, suite, scopeKind=None, cf=None, column=1): " Does a single suite layout " if scopeKind: self.__currentCF = cf self.__currentScopeClass = _scopeToClass[scopeKind] for item in suite: if item.kind == CML_COMMENT_FRAGMENT: # CML comments are not shown on the diagram continue if item.kind in [FUNCTION_FRAGMENT, CLASS_FRAGMENT]: scopeCanvas = VirtualCanvas(self.settings, None, None, self) scopeItem = item if item.kind == FUNCTION_FRAGMENT: scopeCanvas.layout(item, CellElement.FUNC_SCOPE) else: scopeCanvas.layout(item, CellElement.CLASS_SCOPE) if item.decorators: for dec in reversed(item.decorators): # Create a decorator scope virtual canvas decScope = VirtualCanvas(self.settings, None, None, self) decScopeRows = len(decScope.cells) if scopeItem.leadingComment: # Need two rows; one for the comment + one for the scope decScope.layout(dec, CellElement.DECOR_SCOPE, 2) decScope.__allocateCell(decScopeRows - 3, 2) decScope.cells[decScopeRows - 3][1] = ConnectorCell( CONN_N_S, decScope, 1, decScopeRows - 3) decScope.cells[decScopeRows - 3][2] = LeadingCommentCell( scopeItem, decScope, 2, decScopeRows - 3) else: # Need one row for the scope decScope.layout(dec, CellElement.DECOR_SCOPE, 1) decScope.__allocateCell(decScopeRows - 2, 1) # Fix the parent scopeCanvas.parent = decScope scopeCanvas.canvas = decScope # Set the decorator content decScope.cells[decScopeRows - 2][1] = scopeCanvas scopeCanvas.addr = [1, decScopeRows - 2] # Set the current content scope scopeCanvas = decScope scopeItem = dec if scopeItem.leadingComment: self.__allocateCell(vacantRow, column + 1) self.cells[vacantRow][column] = ConnectorCell( CONN_N_S, self, column, vacantRow) self.cells[vacantRow][column + 1] = LeadingCommentCell( scopeItem, self, column + 1, vacantRow) vacantRow += 1 # Update the scope canvas parent and address scopeCanvas.parent = self scopeCanvas.addr = [column, vacantRow] self.__allocateAndSet(vacantRow, column, scopeCanvas) vacantRow += 1 continue if item.kind == WITH_FRAGMENT: if item.leadingComment: self.__allocateCell(vacantRow, column + 1) self.cells[vacantRow][column] = ConnectorCell( CONN_N_S, self, column, vacantRow) self.cells[vacantRow][column + 1] = LeadingCommentCell( item, self, column + 1, vacantRow) vacantRow += 1 self.__allocateScope(item, CellElement.WITH_SCOPE, vacantRow, column) vacantRow += 1 continue if item.kind in [WHILE_FRAGMENT, FOR_FRAGMENT]: targetScope = CellElement.WHILE_SCOPE if item.kind == FOR_FRAGMENT: targetScope = CellElement.FOR_SCOPE loopRegionBegin = vacantRow if self.__needLoopCommentRow(item): if item.leadingComment: comment = AboveCommentCell(item, self, column, vacantRow) comment.needConnector = True self.__allocateAndSet(vacantRow, column, comment) else: self.__allocateCell(vacantRow, column) self.cells[vacantRow][column] = ConnectorCell( CONN_N_S, self, column, vacantRow) if item.elsePart: if item.elsePart.leadingComment: self.__allocateAndSet( vacantRow, column + 1, AboveCommentCell(item.elsePart, self, column + 1, vacantRow)) self.dependentRegions.append( (loopRegionBegin, vacantRow + 1)) vacantRow += 1 self.__allocateScope(item, targetScope, vacantRow, column) if item.elsePart: self.__allocateScope(item.elsePart, CellElement.ELSE_SCOPE, vacantRow, column + 1) vacantRow += 1 continue if item.kind == COMMENT_FRAGMENT: self.__allocateCell(vacantRow, column + 1) self.cells[vacantRow][column] = ConnectorCell( CONN_N_S, self, column, vacantRow) self.cells[vacantRow][column + 1] = IndependentCommentCell( item, self, column + 1, vacantRow) vacantRow += 1 continue if item.kind == TRY_FRAGMENT: tryRegionBegin = vacantRow if self.__needTryCommentRow(item): commentRow = vacantRow vacantRow += 1 if item.leadingComment: comment = AboveCommentCell(item, self, column, commentRow) comment.needConnector = True self.__allocateAndSet(commentRow, column, comment) else: self.__allocateAndSet( commentRow, column, ConnectorCell(CONN_N_S, self, column, commentRow)) if item.exceptParts: self.dependentRegions.append( (tryRegionBegin, vacantRow)) self.__allocateScope(item, CellElement.TRY_SCOPE, vacantRow, column) nextColumn = column + 1 for exceptPart in item.exceptParts: if exceptPart.leadingComment: self.__allocateAndSet( commentRow, nextColumn, AboveCommentCell(exceptPart, self, nextColumn, commentRow)) self.__allocateScope(exceptPart, CellElement.EXCEPT_SCOPE, vacantRow, nextColumn) nextColumn += 1 # The else part goes below if item.elsePart: vacantRow += 1 vacantRow = self.__allocateLeadingComment( item.elsePart, vacantRow, column) self.__allocateScope(item.elsePart, CellElement.ELSE_SCOPE, vacantRow, column) # The finally part is located below if item.finallyPart: vacantRow += 1 vacantRow = self.__allocateLeadingComment( item.finallyPart, vacantRow, column) self.__allocateScope(item.finallyPart, CellElement.FINALLY_SCOPE, vacantRow, column) vacantRow += 1 continue if item.kind == IF_FRAGMENT: lastNonElseIndex = len(item.parts) - 1 for index in xrange(len(item.parts)): if item.parts[index].condition is None: lastNonElseIndex = index - 1 break canvas = VirtualCanvas(self.settings, 0, 0, self) canvas.isNoScope = True if lastNonElseIndex == len(item.parts) - 1: # There is no else canvas.layoutIfBranch(item.parts[lastNonElseIndex], None) else: canvas.layoutIfBranch(item.parts[lastNonElseIndex], item.parts[lastNonElseIndex + 1]) index = lastNonElseIndex - 1 while index >= 0: tempCanvas = VirtualCanvas(self.settings, 0, 0, self) tempCanvas.isNoScope = True tempCanvas.layoutIfBranch(item.parts[index], canvas) canvas = tempCanvas index -= 1 self.__allocateAndSet(vacantRow, 1, canvas) vacantRow += 1 continue # Below are the single cell fragments possibly with comments cellClass = _fragmentKindToCellClass[item.kind] vacantRow = self.__allocateLeadingComment(item, vacantRow, column) self.__allocateAndSet(vacantRow, column, cellClass(item, self, column, vacantRow)) if item.sideComment: self.__allocateAndSet( vacantRow, column + 1, SideCommentCell(item, self, column + 1, vacantRow)) vacantRow += 1 # end of for loop return vacantRow