Graphics/PackageDiagramBuilder.py

Wed, 12 Sep 2012 19:41:50 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 12 Sep 2012 19:41:50 +0200
changeset 2039
fa41ccd7f7bc
parent 2037
7a3470ae170e
child 2302
f29e9405c851
permissions
-rw-r--r--

Added the capability to rebuild a diagram without losing the current item positions.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
1509
c0b5e693b0eb Updated copyright for 2012.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1112
diff changeset
3 # Copyright (c) 2007 - 2012 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog showing a UML like class diagram of a package.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import glob
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os.path
35
42f5cfc851da Ported the UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 28
diff changeset
12 import itertools
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
1112
8a7d1b9d18db Improved code quality by getting rid of star imports. That way pyflakes can do its job. A few bugs fixed found by flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
14 from PyQt4.QtGui import QProgressDialog, QApplication, QGraphicsTextItem
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
16 from .UMLDiagramBuilder import UMLDiagramBuilder
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
17 from .ClassItem import ClassItem, ClassModel
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
18 from .PackageItem import PackageItem, PackageModel
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
19 from .AssociationItem import AssociationItem, Generalisation
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
20 from . import GraphicsUtilities
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 import Utilities.ModuleParser
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 import Utilities
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
24 import Preferences
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
26
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
27 class PackageDiagramBuilder(UMLDiagramBuilder):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
29 Class implementing a builder for UML like class diagrams of a package.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
31 def __init__(self, dialog, view, project, package, noAttrs=False):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
35 @param dialog reference to the UML dialog (UMLDialog)
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
36 @param view reference to the view object (UMLGraphicsView)
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
37 @param project reference to the project object (Project)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param package name of a python package to be shown (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @keyparam noAttrs flag indicating, that no attributes should be shown (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
41 super().__init__(dialog, view, project)
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
42 self.setObjectName("PackageDiagram")
2026
18f2b30ed046 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
43
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.package = Utilities.normabspath(package)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.noAttrs = noAttrs
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
46
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
47 def initialize(self):
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
48 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
49 Public method to initialize the object.
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
50 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
51 pname = self.project.getProjectName()
2025
8bb085c59cd2 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2024
diff changeset
52 if pname:
2026
18f2b30ed046 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
53 name = self.trUtf8("Package Diagram {0}: {1}").format(
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
54 pname, self.project.getRelativePath(self.package))
2025
8bb085c59cd2 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2024
diff changeset
55 else:
2026
18f2b30ed046 Changed the diagrams to show a better diagram title when printed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2025
diff changeset
56 name = self.trUtf8("Package Diagram: {0}").format(self.package)
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
57 self.umlView.setDiagramName(name)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
58
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def __getCurrentShape(self, name):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Private method to get the named shape.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @param name name of the shape (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @return shape (QCanvasItem)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 return self.allClasses.get(name)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
67
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 def __buildModulesDict(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Private method to build a dictionary of modules contained in the package.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @return dictionary of modules contained in the package.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
74 supportedExt = \
413
3d82e6eb3516 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
75 ['*{0}'.format(ext) for ext in Preferences.getPython("PythonExtensions")] + \
3d82e6eb3516 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
76 ['*{0}'.format(ext) for ext in Preferences.getPython("Python3Extensions")] + \
40
c2e5472b112c Changed some code to adjust eric5 to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
77 ['*.rb']
1845
d481279d882b Fixed an issue parsing sources in the various UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
78 extensions = Preferences.getPython("PythonExtensions") + \
d481279d882b Fixed an issue parsing sources in the various UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
79 Preferences.getPython("Python3Extensions") + ['.rb']
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 moduleDict = {}
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 modules = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 for ext in supportedExt:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 modules.extend(glob.glob(Utilities.normjoinpath(self.package, ext)))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 tot = len(modules)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 try:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 prog = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 progress = QProgressDialog(self.trUtf8("Parsing modules..."),
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
89 None, 0, tot, self.parent())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 progress.show()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 QApplication.processEvents()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 for module in modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 progress.setValue(prog)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 QApplication.processEvents()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 prog += 1
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
96 try:
2039
fa41ccd7f7bc Added the capability to rebuild a diagram without losing the current item positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2037
diff changeset
97 mod = Utilities.ModuleParser.readModule(module, extensions=extensions,
fa41ccd7f7bc Added the capability to rebuild a diagram without losing the current item positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2037
diff changeset
98 caching=False)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 except ImportError:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 name = mod.name
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 if name.startswith(self.package):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 name = name[len(self.package) + 1:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 moduleDict[name] = mod
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 finally:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 progress.setValue(tot)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 return moduleDict
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
109
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
110 def __buildSubpackagesDict(self):
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
111 """
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
112 Private method to build a dictionary of sub-packages contained in this package.
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
113
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
114 @return dictionary of sub-packages contained in this package
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
115 """
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
116 supportedExt = \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
117 ['*{0}'.format(ext) for ext in Preferences.getPython("PythonExtensions")] + \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
118 ['*{0}'.format(ext) for ext in Preferences.getPython("Python3Extensions")] + \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
119 ['*.rb']
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
120 extensions = Preferences.getPython("PythonExtensions") + \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
121 Preferences.getPython("Python3Extensions") + ['.rb']
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
122
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
123 subpackagesDict = {}
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
124 subpackagesList = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
125
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
126 for subpackage in os.listdir(self.package):
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
127 subpackagePath = os.path.join(self.package, subpackage)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
128 if os.path.isdir(subpackagePath) and \
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
129 len(glob.glob(os.path.join(subpackagePath, "__init__.*"))) != 0:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
130 subpackagesList.append(subpackagePath)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
131
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
132 tot = 0
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
133 for ext in supportedExt:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
134 for subpackage in subpackagesList:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
135 tot += len(glob.glob(Utilities.normjoinpath(subpackage, ext)))
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
136 try:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
137 prog = 0
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
138 progress = QProgressDialog(self.trUtf8("Parsing modules..."),
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
139 None, 0, tot, self.parent())
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
140 progress.show()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
141 QApplication.processEvents()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
142 for subpackage in subpackagesList:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
143 packageName = os.path.basename(subpackage)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
144 subpackagesDict[packageName] = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
145 modules = []
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
146 for ext in supportedExt:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
147 modules.extend(glob.glob(Utilities.normjoinpath(subpackage, ext)))
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
148 for module in modules:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
149 progress.setValue(prog)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
150 QApplication.processEvents()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
151 prog += 1
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
152 try:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
153 mod = Utilities.ModuleParser.readModule(
2039
fa41ccd7f7bc Added the capability to rebuild a diagram without losing the current item positions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2037
diff changeset
154 module, extensions=extensions, caching=False)
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
155 except ImportError:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
156 continue
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
157 else:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
158 name = mod.name
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
159 if "." in name:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
160 name = name.rsplit(".", 1)[1]
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
161 subpackagesDict[packageName].append(name)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
162 subpackagesDict[packageName].sort()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
163 # move __init__ to the front
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
164 if "__init__" in subpackagesDict[packageName]:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
165 subpackagesDict[packageName].remove("__init__")
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
166 subpackagesDict[packageName].insert(0, "__init__")
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
167 finally:
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
168 progress.setValue(tot)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
169 return subpackagesDict
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
170
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
171 def buildDiagram(self):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
173 Public method to build the class shapes of the package diagram.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 The algorithm is borrowed from Boa Constructor.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
2031
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
177 self.allClasses = {}
c36c2eb62a75 Refactored the UML graphics code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2030
diff changeset
178
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 initlist = glob.glob(os.path.join(self.package, '__init__.*'))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 if len(initlist) == 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 ct = QGraphicsTextItem(None, self.scene)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
182 ct.setHtml(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.trUtf8("The directory <b>'{0}'</b> is not a package.")\
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 .format(self.package))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 modules = self.__buildModulesDict()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 if not modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 ct = QGraphicsTextItem(None, self.scene)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
190 ct.setHtml(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 self.trUtf8("The package <b>'{0}'</b> does not contain any modules.")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 .format(self.package))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 # step 1: build all classes found in the modules
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 classesFound = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
198 for modName in list(modules.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 module = modules[modName]
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
200 for cls in list(module.classes.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 classesFound = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 self.__addLocalClass(cls, module.classes[cls], 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 if not classesFound:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 ct = QGraphicsTextItem(None, self.scene)
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
205 ct.setHtml(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 self.trUtf8("The package <b>'{0}'</b> does not contain any classes.")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 .format(self.package))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 # step 2: build the class hierarchies
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 routes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 nodes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
214 for modName in list(modules.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 module = modules[modName]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 todo = [module.createHierarchy()]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 while todo:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 hierarchy = todo[0]
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
219 for className in list(hierarchy.keys()):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 cw = self.__getCurrentShape(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 if not cw and className.find('.') >= 0:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 cw = self.__getCurrentShape(className.split('.')[-1])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 if cw:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 self.allClasses[className] = cw
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 if cw and cw.noAttrs != self.noAttrs:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 cw = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 if cw and not (cw.external and \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 (className in module.classes or
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 className in module.modules)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 ):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 if className not in nodes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 nodes.append(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 if className in module.classes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 # this is a local class (defined in this module)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
236 self.__addLocalClass(className, module.classes[className],
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 elif className in module.modules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 # this is a local module (defined in this module)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
240 self.__addLocalClass(className, module.modules[className],
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 0, 0, True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 self.__addExternalClass(className, 0, 0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 nodes.append(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 if hierarchy.get(className):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 todo.append(hierarchy.get(className))
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
248 children = list(hierarchy.get(className).keys())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 for child in children:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 if (className, child) not in routes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 routes.append((className, child))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 del todo[0]
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
254
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
255 # step 3: build the subpackages
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
256 subpackages = self.__buildSubpackagesDict()
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
257 for subpackage in sorted(subpackages.keys()):
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
258 self.__addPackage(subpackage, subpackages[subpackage], 0, 0)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
259 nodes.append(subpackage)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
260
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 self.__arrangeClasses(nodes, routes[:])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 self.__createAssociations(routes)
2027
144463496a54 A few fixes for issues with the graphics dialogs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2026
diff changeset
263 self.umlView.autoAdjustSceneSize(limit=True)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
264
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
265 def __arrangeClasses(self, nodes, routes, whiteSpaceFactor=1.2):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 Private method to arrange the shapes on the canvas.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 The algorithm is borrowed from Boa Constructor.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 generations = GraphicsUtilities.sort(nodes, routes)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 # calculate width and height of all elements
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 sizes = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 for generation in generations:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 sizes.append([])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 for child in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 sizes[-1].append(self.__getCurrentShape(child).sceneBoundingRect())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 # calculate total width and total height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281 width = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 height = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 widths = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 heights = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 for generation in sizes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 currentWidth = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 currentHeight = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 for rect in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 if rect.bottom() > currentHeight:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 currentHeight = rect.bottom()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 currentWidth = currentWidth + rect.right()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 # update totals
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 if currentWidth > width:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 width = currentWidth
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 height = height + currentHeight
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 # store generation info
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 widths.append(currentWidth)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 heights.append(currentHeight)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 # add in some whitespace
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 width = width * whiteSpaceFactor
2028
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
305 ## rawHeight = height
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 height = height * whiteSpaceFactor - 20
2028
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
307 ## verticalWhiteSpace = max(
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
308 ## (height - rawHeight) / (len(generations) - 1.0 or 2.0),
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
309 ## 40.0
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
310 ## )
30247d523fdb A few more Graphics fixes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2027
diff changeset
311 verticalWhiteSpace = 40.0
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 sceneRect = self.umlView.sceneRect()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 width += 50.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 height += 50.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 swidth = width < sceneRect.width() and sceneRect.width() or width
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 sheight = height < sceneRect.height() and sceneRect.height() or height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 self.umlView.setSceneSize(swidth, sheight)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 # distribute each generation across the width and the
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 # generations across height
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 y = 10.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 for currentWidth, currentHeight, generation in \
35
42f5cfc851da Ported the UML like diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 28
diff changeset
324 itertools.zip_longest(widths, heights, generations):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 x = 10.0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 # whiteSpace is the space between any two elements
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 whiteSpace = (width - currentWidth - 20) / (len(generation) - 1.0 or 2.0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 for className in generation:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 cw = self.__getCurrentShape(className)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 cw.setPos(x, y)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 rect = cw.sceneBoundingRect()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 x = x + rect.width() + whiteSpace
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 y = y + currentHeight + verticalWhiteSpace
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
334
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
335 def __addLocalClass(self, className, _class, x, y, isRbModule=False):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 Private method to add a class defined in the module.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 @param className name of the class to be as a dictionary key (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 @param _class class to be shown (ModuleParser.Class)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 @param x x-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 @param y y-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 @param isRbModule flag indicating a Ruby module (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 meths = sorted(_class.methods.keys())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 attrs = sorted(_class.attributes.keys())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 name = _class.name
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 if isRbModule:
413
3d82e6eb3516 Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 40
diff changeset
349 name = "{0} (Module)".format(name)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 cl = ClassModel(name, meths[:], attrs[:])
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
351 cw = ClassItem(cl, False, x, y, noAttrs=self.noAttrs, scene=self.scene)
2030
db11a2fe9bbc Implemented functions to save the UML graphics to disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2028
diff changeset
352 cw.setId(self.umlView.getItemId())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 self.allClasses[className] = cw
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
354
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 def __addExternalClass(self, _class, x, y):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 Private method to add a class defined outside the module.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 If the canvas is too small to take the shape, it
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 is enlarged.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 @param _class class to be shown (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 @param x x-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 @param y y-coordinate (float)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 cl = ClassModel(_class)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
367 cw = ClassItem(cl, True, x, y, noAttrs=self.noAttrs, scene=self.scene)
2030
db11a2fe9bbc Implemented functions to save the UML graphics to disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2028
diff changeset
368 cw.setId(self.umlView.getItemId())
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 self.allClasses[_class] = cw
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
370
2037
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
371 def __addPackage(self, name, modules, x, y):
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
372 """
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
373 Private method to add a package to the diagram.
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
374
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
375 @param name package name to be shown (string)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
376 @param modules list of module names contained in the package
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
377 (list of strings)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
378 @param x x-coordinate (float)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
379 @param y y-coordinate (float)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
380 """
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
381 pm = PackageModel(name, modules)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
382 pw = PackageItem(pm, x, y, scene=self.scene)
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
383 pw.setId(self.umlView.getItemId())
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
384 self.allClasses[name] = pw
7a3470ae170e Improved the package diagram to include subpackages and their module names.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2034
diff changeset
385
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 def __createAssociations(self, routes):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 Private method to generate the associations between the class shapes.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 @param routes list of relationsships
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 for route in routes:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 if len(route) > 1:
564
b3d966393ba9 Did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 483
diff changeset
394 assoc = AssociationItem(
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 self.__getCurrentShape(route[1]),
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 self.__getCurrentShape(route[0]),
2024
717b72b32420 Changed the association layout for the package and class diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1845
diff changeset
397 Generalisation,
717b72b32420 Changed the association layout for the package and class diagrams.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1845
diff changeset
398 topToBottom=True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 self.scene.addItem(assoc)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
400
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
401 def getPersistenceData(self):
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
402 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
403 Public method to get a string for data to be persisted.
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
404
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
405 @return persisted data string (string)
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
406 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
407 return "package={0}, no_attributes={1}".format(self.package, self.noAttrs)
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
408
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
409 def parsePersistenceData(self, version, data):
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
410 """
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
411 Public method to parse persisted data.
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
412
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
413 @param version version of the data (string)
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
414 @param data persisted data to be parsed (string)
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
415 @return flag indicating success (boolean)
2033
4b99609f6a87 Some more refactorings to prepare loading graphics diagrams from file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2031
diff changeset
416 """
2034
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
417 parts = data.split(", ")
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
418 if len(parts) != 2 or \
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
419 not parts[0].startswith("package=") or \
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
420 not parts[1].startswith("no_attributes="):
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
421 return False
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
422
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
423 self.package = parts[0].split("=", 1)[1].strip()
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
424 self.noAttrs = Utilities.toBool(parts[1].split("=", 1)[1].strip())
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
425
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
426 self.initialize()
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
427
8de0fc1f7fef Implemented functions to load UML graphics from disc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2033
diff changeset
428 return True

eric ide

mercurial