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 noModules flag indicating, that no module names should be |
35 @param noModules flag indicating, that no module names should be |
36 shown (boolean) |
36 shown (boolean) |
37 """ |
37 """ |
38 super(ApplicationDiagramBuilder, self).__init__(dialog, view, project) |
38 super().__init__(dialog, view, project) |
39 self.setObjectName("ApplicationDiagram") |
39 self.setObjectName("ApplicationDiagram") |
40 |
40 |
41 self.noModules = noModules |
41 self.noModules = noModules |
42 |
42 |
43 self.umlView.setDiagramName( |
43 self.umlView.setDiagramName( |
66 progress = E5ProgressDialog( |
66 progress = E5ProgressDialog( |
67 self.tr("Parsing modules..."), |
67 self.tr("Parsing modules..."), |
68 None, 0, tot, self.tr("%v/%m Modules"), self.parent()) |
68 None, 0, tot, self.tr("%v/%m Modules"), self.parent()) |
69 progress.setWindowTitle(self.tr("Application Diagram")) |
69 progress.setWindowTitle(self.tr("Application Diagram")) |
70 try: |
70 try: |
71 prog = 0 |
|
72 progress.show() |
71 progress.show() |
73 QApplication.processEvents() |
72 QApplication.processEvents() |
74 |
73 |
75 for module in modules: |
74 for prog, module in enumerate(modules): |
76 progress.setValue(prog) |
75 progress.setValue(prog) |
77 QApplication.processEvents() |
76 QApplication.processEvents() |
78 prog += 1 |
|
79 if module.endswith("__init__.py"): |
77 if module.endswith("__init__.py"): |
80 continue |
78 continue |
81 try: |
79 try: |
82 mod = Utilities.ModuleParser.readModule( |
80 mod = Utilities.ModuleParser.readModule( |
83 module, extensions=extensions, caching=False) |
81 module, extensions=extensions, caching=False) |
105 y = 10 |
103 y = 10 |
106 maxHeight = 0 |
104 maxHeight = 0 |
107 sceneRect = self.umlView.sceneRect() |
105 sceneRect = self.umlView.sceneRect() |
108 |
106 |
109 modules = self.__buildModulesDict() |
107 modules = self.__buildModulesDict() |
110 sortedkeys = sorted(modules.keys()) |
|
111 |
108 |
112 # step 1: build a dictionary of packages |
109 # step 1: build a dictionary of packages |
113 for module in sortedkeys: |
110 for module in sorted(modules.keys()): |
114 li = module.split('.') |
111 packageName, moduleName = module.rsplit(".", 1) |
115 package = '.'.join(li[:-1]) |
112 if packageName in packages: |
116 if package in packages: |
113 packages[packageName][0].append(moduleName) |
117 packages[package][0].append(li[-1]) |
|
118 else: |
114 else: |
119 packages[package] = ([li[-1]], []) |
115 packages[packageName] = ([moduleName], []) |
120 |
116 |
121 # step 2: assign modules to dictionaries and update import relationship |
117 # step 2: assign modules to dictionaries and update import relationship |
122 for module in sortedkeys: |
118 for module in sorted(modules.keys()): |
123 li = module.split('.') |
119 package = module.rsplit(".", 1)[0] |
124 package = '.'.join(li[:-1]) |
|
125 impLst = [] |
120 impLst = [] |
126 for i in modules[module].imports: |
121 for moduleImport in modules[module].imports: |
127 if i in modules: |
122 if moduleImport in modules: |
128 impLst.append(i) |
123 impLst.append(moduleImport) |
129 else: |
124 else: |
130 if i.find('.') == -1: |
125 if moduleImport.find('.') == -1: |
131 n = "{0}.{1}".format(modules[module].package, i) |
126 n = "{0}.{1}".format(modules[module].package, |
|
127 moduleImport) |
132 if n in modules: |
128 if n in modules: |
133 impLst.append(n) |
129 impLst.append(n) |
134 else: |
130 else: |
135 n = "{0}.{1}".format(project, i) |
131 n = "{0}.{1}".format(project, moduleImport) |
136 if n in modules: |
132 if n in modules: |
137 impLst.append(n) |
133 impLst.append(n) |
138 elif n in packages: |
134 elif n in packages: |
139 n = "{0}.<<Dummy>>".format(n) |
135 n = "{0}.<<Dummy>>".format(n) |
140 impLst.append(n) |
136 impLst.append(n) |
141 else: |
137 else: |
142 n = "{0}.{1}".format(project, i) |
138 n = "{0}.{1}".format(project, moduleImport) |
143 if n in modules: |
139 if n in modules: |
144 impLst.append(n) |
140 impLst.append(n) |
145 for i in list(modules[module].from_imports.keys()): |
141 for moduleImport in list(modules[module].from_imports.keys()): |
146 if i.startswith('.'): |
142 if moduleImport.startswith('.'): |
147 dots = len(i) - len(i.lstrip('.')) |
143 dots = len(moduleImport) - len(moduleImport.lstrip('.')) |
148 if dots == 1: |
144 if dots == 1: |
149 i = i[1:] |
145 moduleImport = moduleImport[1:] |
150 elif dots > 1: |
146 elif dots > 1: |
151 packagePath = os.path.dirname(modules[module].file) |
147 packagePath = os.path.dirname(modules[module].file) |
152 hasInit = True |
148 hasInit = True |
153 ppath = packagePath |
149 ppath = packagePath |
154 while hasInit: |
150 while hasInit: |
159 packagePath.replace(ppath, '') |
155 packagePath.replace(ppath, '') |
160 .replace(os.sep, '.')[1:] |
156 .replace(os.sep, '.')[1:] |
161 ) |
157 ) |
162 packageList = shortPackage.split('.')[1:] |
158 packageList = shortPackage.split('.')[1:] |
163 packageListLen = len(packageList) |
159 packageListLen = len(packageList) |
164 i = '.'.join( |
160 moduleImport = '.'.join( |
165 packageList[:packageListLen - dots + 1] + |
161 packageList[:packageListLen - dots + 1] + |
166 [i[dots:]]) |
162 [moduleImport[dots:]]) |
167 |
163 |
168 if i in modules: |
164 if moduleImport in modules: |
169 impLst.append(i) |
165 impLst.append(moduleImport) |
170 else: |
166 else: |
171 if i.find('.') == -1: |
167 if moduleImport.find('.') == -1: |
172 n = "{0}.{1}".format(modules[module].package, i) |
168 n = "{0}.{1}".format(modules[module].package, |
|
169 moduleImport) |
173 if n in modules: |
170 if n in modules: |
174 impLst.append(n) |
171 impLst.append(n) |
175 else: |
172 else: |
176 n = "{0}.{1}".format(project, i) |
173 n = "{0}.{1}".format(project, moduleImport) |
177 if n in modules: |
174 if n in modules: |
178 impLst.append(n) |
175 impLst.append(n) |
179 elif n in packages: |
176 elif n in packages: |
180 n = "{0}.<<Dummy>>".format(n) |
177 n = "{0}.<<Dummy>>".format(n) |
181 impLst.append(n) |
178 impLst.append(n) |
182 else: |
179 else: |
183 n = "{0}.{1}".format(project, i) |
180 n = "{0}.{1}".format(project, moduleImport) |
184 if n in modules: |
181 if n in modules: |
185 impLst.append(n) |
182 impLst.append(n) |
186 for imp in impLst: |
183 for moduleImport in impLst: |
187 impPackage = '.'.join(imp.split('.')[:-1]) |
184 impPackage = moduleImport.rsplit(".", 1)[0] |
188 if ( |
185 if ( |
189 impPackage not in packages[package][1] and |
186 impPackage not in packages[package][1] and |
190 not impPackage == package |
187 impPackage != package |
191 ): |
188 ): |
192 packages[package][1].append(impPackage) |
189 packages[package][1].append(impPackage) |
193 |
190 |
194 sortedkeys = sorted(packages.keys()) |
191 for package in sorted(packages.keys()): |
195 for package in sortedkeys: |
|
196 if package: |
192 if package: |
197 relPackage = package.replace(project, '') |
193 relPackage = package.replace(project, '') |
198 if relPackage and relPackage[0] == '.': |
194 if relPackage and relPackage[0] == '.': |
199 relPackage = relPackage[1:] |
195 relPackage = relPackage[1:] |
200 else: |
196 else: |
251 """ |
247 """ |
252 Private method to generate the associations between the package shapes. |
248 Private method to generate the associations between the package shapes. |
253 |
249 |
254 @param shapes list of shapes |
250 @param shapes list of shapes |
255 """ |
251 """ |
256 from .AssociationItem import AssociationItem, Imports |
252 from .AssociationItem import AssociationItem, AssociationType |
257 for package in shapes: |
253 for package in shapes: |
258 for rel in shapes[package][1]: |
254 for rel in shapes[package][1]: |
259 assoc = AssociationItem( |
255 assoc = AssociationItem( |
260 shapes[package][0], shapes[rel][0], |
256 shapes[package][0], shapes[rel][0], |
261 Imports, |
257 AssociationType.IMPORTS, |
262 colors=self.umlView.getDrawingColors()) |
258 colors=self.umlView.getDrawingColors()) |
263 self.scene.addItem(assoc) |
259 self.scene.addItem(assoc) |
264 |
260 |
265 def getPersistenceData(self): |
261 def getPersistenceData(self): |
266 """ |
262 """ |