Graphics/UMLClassDiagramBuilder.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2602
affc66a603c7
parent 2992
dbdf27746da5
child 3060
5883ce99ee12
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
31 31
32 @param dialog reference to the UML dialog (UMLDialog) 32 @param dialog reference to the UML dialog (UMLDialog)
33 @param view reference to the view object (UMLGraphicsView) 33 @param view reference to the view object (UMLGraphicsView)
34 @param project reference to the project object (Project) 34 @param project reference to the project object (Project)
35 @param file file name of a python module to be shown (string) 35 @param file file name of a python module to be shown (string)
36 @keyparam noAttrs flag indicating, that no attributes should be shown (boolean) 36 @keyparam noAttrs flag indicating, that no attributes should be shown
37 (boolean)
37 """ 38 """
38 super(UMLClassDiagramBuilder, self).__init__(dialog, view, project) 39 super(UMLClassDiagramBuilder, self).__init__(dialog, view, project)
39 self.setObjectName("UMLClassDiagramBuilder") 40 self.setObjectName("UMLClassDiagramBuilder")
40 41
41 self.file = file 42 self.file = file
74 self.allModules = {} 75 self.allModules = {}
75 76
76 try: 77 try:
77 extensions = Preferences.getPython("PythonExtensions") + \ 78 extensions = Preferences.getPython("PythonExtensions") + \
78 Preferences.getPython("Python3Extensions") + ['.rb'] 79 Preferences.getPython("Python3Extensions") + ['.rb']
79 module = Utilities.ModuleParser.readModule(self.file, extensions=extensions, 80 module = Utilities.ModuleParser.readModule(
80 caching=False) 81 self.file, extensions=extensions, caching=False)
81 except ImportError: 82 except ImportError:
82 ct = QGraphicsTextItem(None) 83 ct = QGraphicsTextItem(None)
83 ct.setHtml( 84 ct.setHtml(
84 self.trUtf8("The module <b>'{0}'</b> could not be found.") 85 self.trUtf8("The module <b>'{0}'</b> could not be found.")
85 .format(self.file)) 86 .format(self.file))
141 self.__arrangeClasses(nodes, routes[:]) 142 self.__arrangeClasses(nodes, routes[:])
142 self.__createAssociations(routes) 143 self.__createAssociations(routes)
143 self.umlView.autoAdjustSceneSize(limit=True) 144 self.umlView.autoAdjustSceneSize(limit=True)
144 else: 145 else:
145 ct = QGraphicsTextItem(None) 146 ct = QGraphicsTextItem(None)
146 ct.setHtml( 147 ct.setHtml(self.trUtf8(
147 self.trUtf8("The module <b>'{0}'</b> does not contain any classes.")\ 148 "The module <b>'{0}'</b> does not contain any classes.")
148 .format(self.file)) 149 .format(self.file))
149 self.scene.addItem(ct) 150 self.scene.addItem(ct)
150 151
151 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2): 152 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2):
152 """ 153 """
153 Private method to arrange the shapes on the canvas. 154 Private method to arrange the shapes on the canvas.
154 155
155 The algorithm is borrowed from Boa Constructor. 156 The algorithm is borrowed from Boa Constructor.
157
158 @param nodes list of nodes to arrange
159 @param routes list of routes
160 @param whiteSpaceFactor factor to increase whitespace between
161 items (float)
156 """ 162 """
157 from . import GraphicsUtilities 163 from . import GraphicsUtilities
158 generations = GraphicsUtilities.sort(nodes, routes) 164 generations = GraphicsUtilities.sort(nodes, routes)
159 165
160 # calculate width and height of all elements 166 # calculate width and height of all elements
161 sizes = [] 167 sizes = []
162 for generation in generations: 168 for generation in generations:
163 sizes.append([]) 169 sizes.append([])
164 for child in generation: 170 for child in generation:
165 sizes[-1].append(self.__getCurrentShape(child).sceneBoundingRect()) 171 sizes[-1].append(
172 self.__getCurrentShape(child).sceneBoundingRect())
166 173
167 # calculate total width and total height 174 # calculate total width and total height
168 width = 0 175 width = 0
169 height = 0 176 height = 0
170 widths = [] 177 widths = []
209 y = 10.0 216 y = 10.0
210 for currentWidth, currentHeight, generation in \ 217 for currentWidth, currentHeight, generation in \
211 zip_longest(widths, heights, generations): 218 zip_longest(widths, heights, generations):
212 x = 10.0 219 x = 10.0
213 # whiteSpace is the space between any two elements 220 # whiteSpace is the space between any two elements
214 whiteSpace = (width - currentWidth - 20) / (len(generation) - 1.0 or 2.0) 221 whiteSpace = (width - currentWidth - 20) / \
222 (len(generation) - 1.0 or 2.0)
215 for className in generation: 223 for className in generation:
216 cw = self.__getCurrentShape(className) 224 cw = self.__getCurrentShape(className)
217 cw.setPos(x, y) 225 cw.setPos(x, y)
218 rect = cw.sceneBoundingRect() 226 rect = cw.sceneBoundingRect()
219 x = x + rect.width() + whiteSpace 227 x = x + rect.width() + whiteSpace

eric ide

mercurial