40 super().__init__(dialog, view, project) |
40 super().__init__(dialog, view, project) |
41 self.setObjectName("PackageDiagram") |
41 self.setObjectName("PackageDiagram") |
42 |
42 |
43 self.package = Utilities.normabspath(package) |
43 self.package = Utilities.normabspath(package) |
44 self.noAttrs = noAttrs |
44 self.noAttrs = noAttrs |
45 |
45 |
46 self.umlView.setPersistenceData("package={0}".format(self.package)) |
46 def initialize(self): |
47 |
47 """ |
48 pname = project.getProjectName() |
48 Public method to initialize the object. |
|
49 """ |
|
50 pname = self.project.getProjectName() |
49 if pname: |
51 if pname: |
50 name = self.trUtf8("Package Diagram {0}: {1}").format( |
52 name = self.trUtf8("Package Diagram {0}: {1}").format( |
51 pname, project.getRelativePath(self.package)) |
53 pname, self.project.getRelativePath(self.package)) |
52 else: |
54 else: |
53 name = self.trUtf8("Package Diagram: {0}").format(self.package) |
55 name = self.trUtf8("Package Diagram: {0}").format(self.package) |
54 self.umlView.setDiagramName(name) |
56 self.umlView.setDiagramName(name) |
55 |
57 |
56 def __getCurrentShape(self, name): |
58 def __getCurrentShape(self, name): |
57 """ |
59 """ |
58 Private method to get the named shape. |
60 Private method to get the named shape. |
59 |
61 |
60 @param name name of the shape (string) |
62 @param name name of the shape (string) |
61 @return shape (QCanvasItem) |
63 @return shape (QCanvasItem) |
62 """ |
64 """ |
63 return self.allClasses.get(name) |
65 return self.allClasses.get(name) |
64 |
66 |
65 def __buildModulesDict(self): |
67 def __buildModulesDict(self): |
66 """ |
68 """ |
67 Private method to build a dictionary of modules contained in the package. |
69 Private method to build a dictionary of modules contained in the package. |
68 |
70 |
69 @return dictionary of modules contained in the package. |
71 @return dictionary of modules contained in the package. |
100 name = name[len(self.package) + 1:] |
102 name = name[len(self.package) + 1:] |
101 moduleDict[name] = mod |
103 moduleDict[name] = mod |
102 finally: |
104 finally: |
103 progress.setValue(tot) |
105 progress.setValue(tot) |
104 return moduleDict |
106 return moduleDict |
105 |
107 |
106 def buildDiagram(self): |
108 def buildDiagram(self): |
107 """ |
109 """ |
108 Public method to build the class shapes of the package diagram. |
110 Public method to build the class shapes of the package diagram. |
109 |
111 |
110 The algorithm is borrowed from Boa Constructor. |
112 The algorithm is borrowed from Boa Constructor. |
188 del todo[0] |
190 del todo[0] |
189 |
191 |
190 self.__arrangeClasses(nodes, routes[:]) |
192 self.__arrangeClasses(nodes, routes[:]) |
191 self.__createAssociations(routes) |
193 self.__createAssociations(routes) |
192 self.umlView.autoAdjustSceneSize(limit=True) |
194 self.umlView.autoAdjustSceneSize(limit=True) |
193 |
195 |
194 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2): |
196 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2): |
195 """ |
197 """ |
196 Private method to arrange the shapes on the canvas. |
198 Private method to arrange the shapes on the canvas. |
197 |
199 |
198 The algorithm is borrowed from Boa Constructor. |
200 The algorithm is borrowed from Boa Constructor. |
258 cw = self.__getCurrentShape(className) |
260 cw = self.__getCurrentShape(className) |
259 cw.setPos(x, y) |
261 cw.setPos(x, y) |
260 rect = cw.sceneBoundingRect() |
262 rect = cw.sceneBoundingRect() |
261 x = x + rect.width() + whiteSpace |
263 x = x + rect.width() + whiteSpace |
262 y = y + currentHeight + verticalWhiteSpace |
264 y = y + currentHeight + verticalWhiteSpace |
263 |
265 |
264 def __addLocalClass(self, className, _class, x, y, isRbModule=False): |
266 def __addLocalClass(self, className, _class, x, y, isRbModule=False): |
265 """ |
267 """ |
266 Private method to add a class defined in the module. |
268 Private method to add a class defined in the module. |
267 |
269 |
268 @param className name of the class to be as a dictionary key (string) |
270 @param className name of the class to be as a dictionary key (string) |
278 name = "{0} (Module)".format(name) |
280 name = "{0} (Module)".format(name) |
279 cl = ClassModel(name, meths[:], attrs[:]) |
281 cl = ClassModel(name, meths[:], attrs[:]) |
280 cw = ClassItem(cl, False, x, y, noAttrs=self.noAttrs, scene=self.scene) |
282 cw = ClassItem(cl, False, x, y, noAttrs=self.noAttrs, scene=self.scene) |
281 cw.setId(self.umlView.getItemId()) |
283 cw.setId(self.umlView.getItemId()) |
282 self.allClasses[className] = cw |
284 self.allClasses[className] = cw |
283 |
285 |
284 def __addExternalClass(self, _class, x, y): |
286 def __addExternalClass(self, _class, x, y): |
285 """ |
287 """ |
286 Private method to add a class defined outside the module. |
288 Private method to add a class defined outside the module. |
287 |
289 |
288 If the canvas is too small to take the shape, it |
290 If the canvas is too small to take the shape, it |
294 """ |
296 """ |
295 cl = ClassModel(_class) |
297 cl = ClassModel(_class) |
296 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene) |
298 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene) |
297 cw.setId(self.umlView.getItemId()) |
299 cw.setId(self.umlView.getItemId()) |
298 self.allClasses[_class] = cw |
300 self.allClasses[_class] = cw |
299 |
301 |
300 def __createAssociations(self, routes): |
302 def __createAssociations(self, routes): |
301 """ |
303 """ |
302 Private method to generate the associations between the class shapes. |
304 Private method to generate the associations between the class shapes. |
303 |
305 |
304 @param routes list of relationsships |
306 @param routes list of relationsships |
309 self.__getCurrentShape(route[1]), |
311 self.__getCurrentShape(route[1]), |
310 self.__getCurrentShape(route[0]), |
312 self.__getCurrentShape(route[0]), |
311 Generalisation, |
313 Generalisation, |
312 topToBottom=True) |
314 topToBottom=True) |
313 self.scene.addItem(assoc) |
315 self.scene.addItem(assoc) |
|
316 |
|
317 def getPersistenceData(self): |
|
318 """ |
|
319 Public method to get a string for data to be persisted. |
|
320 |
|
321 @return persisted data string (string) |
|
322 """ |
|
323 return "package={0}, no_attributes={1}".format(self.package, self.noAttrs) |
|
324 |
|
325 def parsePersistenceData(self, data): |
|
326 """ |
|
327 Public method to parse persisted data. |
|
328 |
|
329 @param dat persisted data to be parsed (string) |
|
330 """ |
|
331 # TODO: implement this |
|
332 return |