eric6/Graphics/UMLClassDiagramBuilder.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8270
6ba3564b7161
child 8400
b3eefd7e58d1
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
30 @param project reference to the project object (Project) 30 @param project reference to the project object (Project)
31 @param file file name of a python module to be shown (string) 31 @param file file name of a python module to be shown (string)
32 @param noAttrs flag indicating, that no attributes should be shown 32 @param noAttrs flag indicating, that no attributes should be shown
33 (boolean) 33 (boolean)
34 """ 34 """
35 super(UMLClassDiagramBuilder, self).__init__(dialog, view, project) 35 super().__init__(dialog, view, project)
36 self.setObjectName("UMLClassDiagramBuilder") 36 self.setObjectName("UMLClassDiagramBuilder")
37 37
38 self.file = file 38 self.file = file
39 self.noAttrs = noAttrs 39 self.noAttrs = noAttrs
40 40
41 def initialize(self): 41 def initialize(self):
42 """ 42 """
43 Public method to initialize the object. 43 Public method to initialize the object.
44 """ 44 """
45 pname = self.project.getProjectName() 45 pname = self.project.getProjectName()
46 if pname and self.project.isProjectSource(self.file): 46 name = (
47 name = self.tr("Class Diagram {0}: {1}").format( 47 self.tr("Class Diagram {0}: {1}").format(
48 pname, self.project.getRelativePath(self.file)) 48 pname, self.project.getRelativePath(self.file))
49 else: 49 if pname and self.project.isProjectSource(self.file) else
50 name = self.tr("Class Diagram: {0}").format(self.file) 50 self.tr("Class Diagram: {0}").format(self.file)
51 )
51 self.umlView.setDiagramName(name) 52 self.umlView.setDiagramName(name)
52 53
53 def __getCurrentShape(self, name): 54 def __getCurrentShape(self, name):
54 """ 55 """
55 Private method to get the named shape. 56 Private method to get the named shape.
178 currentHeight = 0 179 currentHeight = 0
179 180
180 for rect in generation: 181 for rect in generation:
181 if rect.bottom() > currentHeight: 182 if rect.bottom() > currentHeight:
182 currentHeight = rect.bottom() 183 currentHeight = rect.bottom()
183 currentWidth = currentWidth + rect.right() 184 currentWidth += rect.right()
184 185
185 # update totals 186 # update totals
186 if currentWidth > width: 187 if currentWidth > width:
187 width = currentWidth 188 width = currentWidth
188 height = height + currentHeight 189 height += currentHeight
189 190
190 # store generation info 191 # store generation info
191 widths.append(currentWidth) 192 widths.append(currentWidth)
192 heights.append(currentHeight) 193 heights.append(currentHeight)
193 194
194 # add in some whitespace 195 # add in some whitespace
195 width = width * whiteSpaceFactor 196 width *= whiteSpaceFactor
196 height = height * whiteSpaceFactor - 20 197 height = height * whiteSpaceFactor - 20
197 verticalWhiteSpace = 40.0 198 verticalWhiteSpace = 40.0
198 199
199 sceneRect = self.umlView.sceneRect() 200 sceneRect = self.umlView.sceneRect()
200 width += 50.0 201 width += 50.0
201 height += 50.0 202 height += 50.0
202 swidth = width < sceneRect.width() and sceneRect.width() or width 203 swidth = sceneRect.width() if width < sceneRect.width() else width
203 sheight = height < sceneRect.height() and sceneRect.height() or height 204 sheight = sceneRect.height() if height < sceneRect.height() else height
204 self.umlView.setSceneSize(swidth, sheight) 205 self.umlView.setSceneSize(swidth, sheight)
205 206
206 # distribute each generation across the width and the 207 # distribute each generation across the width and the
207 # generations across height 208 # generations across height
208 y = 10.0 209 y = 10.0
270 """ 271 """
271 Private method to generate the associations between the class shapes. 272 Private method to generate the associations between the class shapes.
272 273
273 @param routes list of relationsships 274 @param routes list of relationsships
274 """ 275 """
275 from .AssociationItem import AssociationItem, Generalisation 276 from .AssociationItem import AssociationItem, AssociationType
276 for route in routes: 277 for route in routes:
277 if len(route) > 1: 278 if len(route) > 1:
278 assoc = AssociationItem( 279 assoc = AssociationItem(
279 self.__getCurrentShape(route[1]), 280 self.__getCurrentShape(route[1]),
280 self.__getCurrentShape(route[0]), 281 self.__getCurrentShape(route[0]),
281 Generalisation, 282 AssociationType.GENERALISATION,
282 topToBottom=True, 283 topToBottom=True,
283 colors=self.umlView.getDrawingColors()) 284 colors=self.umlView.getDrawingColors())
284 self.scene.addItem(assoc) 285 self.scene.addItem(assoc)
285 286
286 def getPersistenceData(self): 287 def getPersistenceData(self):

eric ide

mercurial