/[eiffelstudio]/branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_metric_calculate_cmd.e
ViewVC logotype

Contents of /branches/Eiffel_57_docking/Src/Eiffel/interface/new_graphical/commands/eb_metric_calculate_cmd.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61994 - (show annotations)
Sun Jul 30 06:10:21 2006 UTC (13 years, 6 months ago) by manus
File size: 17768 byte(s)
EiffelStudio docking branch. It only contains modified classes needed to get the docking version of EiffelStudio.
1 indexing
2 description: "Command to calculate a metric over selected parameters."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 author: ""
6 date: "$Date$"
7 revision: "$Revision$"
8
9 class
10 EB_METRIC_CALCULATE_CMD
11
12 inherit
13 EB_METRIC_COMMAND
14
15 EB_CONSTANTS
16
17 EB_METRIC_SCOPE_INFO
18
19 SHARED_XML_ROUTINES
20
21 create
22 make
23
24 feature -- Initialization
25
26 execute is
27 -- Launch metric calculation regarding selected parameters.
28 do
29 on_calculate_click
30 end
31
32 pixmap: EV_PIXMAP is
33 -- Pixmap representing the command.
34 do
35 Result := Pixmaps.Icon_new_measure
36 end
37
38 tooltip: STRING is
39 -- Tooltip for the toolbar button.
40 do
41 Result := "Calculate metric with selected parameters"
42 end
43
44 description: STRING is
45 -- Description for this command.
46 do
47 Result := "Calculate metrics"
48 end
49
50 name: STRING is "calculate"
51 -- Name of the command. Used to store the command in the
52 -- preferences.
53
54
55 feature -- Displayed messages in text form.
56
57 has_metric (current_metric: EB_METRIC; f: PLAIN_TEXT_FILE): BOOLEAN is
58 -- Has `f' metric definition corresponding to `current_metric'?
59 require
60 f_not_void: f /= Void
61 metric_not_void: current_metric /= Void
62 local
63 defined_metric: EB_METRIC
64 archived_metrics: ARRAYED_LIST [EB_METRIC]
65 archived_xml: ARRAYED_LIST [XM_ELEMENT]
66 index_current_metric: INTEGER
67 current_formula: STRING
68 current_xml: XM_ELEMENT
69 defined_formula: STRING
70 do
71 create archived_metrics.make (0)
72 create archived_xml.make (0)
73 tool.file_handler.retrieve_metric (f, archived_metrics, archived_xml)
74
75 index_current_metric := tool.metrics.index_of (current_metric, 1)
76 current_xml := tool.user_metrics_xml_list.i_th (index_current_metric - tool.nb_basic_metrics)
77 current_formula := Xml_routines.xml_string (current_xml, "FORMULA")
78 from
79 archived_xml.start
80 until
81 archived_xml.after or defined_metric/= Void
82 loop
83 defined_formula := Xml_routines.xml_string (archived_xml.item, "FORMULA")
84 if equal (defined_formula, current_formula) then
85 Result := True
86 end
87 archived_xml.forth
88 end
89 end
90
91 retrieve_archived_measure (current_metric: EB_METRIC; f: PLAIN_TEXT_FILE): STRING is
92 -- Retrieve recorded measure of `current_metric' evaluated over `System_scope' if any
93 -- from file `f'.
94 require
95 f_not_void: f /= Void
96 metric_not_void: current_metric /= Void
97 local
98 final_result, archive_name: STRING
99 l_deserialized_document: XM_DOCUMENT
100 measure_element, node: XM_ELEMENT
101 a_cursor: DS_LINKED_LIST_CURSOR [XM_NODE]
102 retried, same_metric: BOOLEAN
103 basic_metric: EB_METRIC_BASIC
104 do
105 if not retried then
106 l_deserialized_document := Xml_routines.deserialize_document (f.name)
107 if l_deserialized_document /= Void then
108 if tool.archive.archive_syntax (l_deserialized_document.root_element) then
109 basic_metric ?= current_metric
110 if basic_metric = Void then
111 same_metric := has_metric (current_metric, f)
112 end
113 if (basic_metric /= Void or same_metric) then
114 if l_deserialized_document.root_element.has_attribute_by_name ("System") then
115 archive_name := l_deserialized_document.root_element.attribute_by_name ("System").value
116 end
117 measure_element := Xml_routines.element_by_name (l_deserialized_document.root_element, "RECORDED_MEASURES")
118 a_cursor := measure_element.new_cursor
119 Result := "Metric: " + current_metric.name + " " + "Scope: Archive"
120 from
121 a_cursor.start
122 until
123 a_cursor.after
124 loop
125 node ?= a_cursor.item
126 if node /= Void then
127 if node.attribute_by_name ("Metric").value.is_equal (current_metric.name) then
128 final_result := tool.fix_decimals_and_percentage (node.attribute_by_name ("Result").value.to_double, current_metric.percentage)
129 Result.append (" " + archive_name + ":")
130 Result.append (final_result)
131 end
132 end
133 a_cursor.forth
134 end
135 else
136 Result := "Sorry, no measure has been recorded for this metric."
137 end
138 else
139 Xml_routines.display_warning_message_relative (
140 "File: " + f.name + "%Nis not an archive file.",
141 tool.development_window.window)
142 end
143 else
144 Xml_routines.display_warning_message_relative (
145 "File: " + f.name + "%Nhas syntax errors or is not an archive file.",
146 tool.development_window.window)
147 end
148 -- if final_result = Void or else final_result.is_empty then
149 -- Result := "Sorry, no measure has been recorded for this metric."
150 -- end
151 end
152 rescue
153 retried := True
154 Xml_routines.display_warning_message_relative (
155 "Unable to read file:%N" + f.name,
156 tool.development_window.window)
157 retry
158 end
159
160 display_result (a_result: DOUBLE; num, den: STRING; percentage: BOOLEAN): STRING is
161 -- Display result of metric calculation.
162 local
163 final_result: STRING
164 composite_metric: EB_METRIC_COMPOSITE
165 do
166 final_result := tool.fix_decimals_and_percentage (a_result, percentage)
167 composite_metric ?= tool.metric (tool.selected_metric)
168 Result := "Metric: " + tool.selected_metric + " "
169 if composite_metric /= Void and then composite_metric.is_scope_ratio then
170 Result.append ("Scope: " + composite_metric.scope_num.name + ": " + num + " / "
171 + composite_metric.scope_den.name + ": " + den + " ")
172 else
173 Result.append ("Scope: " + tool.selected_scope + ": " + num + " ")
174 end
175 Result.append ("Value:" + final_result)
176 end
177
178 wrong_selection: BOOLEAN is
179 -- Is there a mismatch between stones and scope_index?
180 do
181 Result := (tool.feature_stone = Void and scope.index = Feature_scope) or
182 (tool.feature_stone = Void and tool.class_stone = Void and scope.index = Class_scope) or
183 (tool.feature_stone = Void and tool.class_stone = Void and tool.cluster_stone = Void and scope.index = Cluster_scope)
184 end
185
186 fill_text_area (current_metric: EB_METRIC): STRING is
187 -- Build a structured text to display metric results.
188 require
189 not wrong_selection
190 local
191 selected_feature: E_FEATURE
192 selected_class: CLASS_C
193 selected_cluster: CLUSTER_I
194 selected_system: SYSTEM_I
195 metric_result: DOUBLE
196 selected_name1, selected_name2: STRING
197 metric_composite: EB_METRIC_COMPOSITE
198 percentage: BOOLEAN
199 scope_num, scope_den: EB_METRIC_SCOPE
200 do
201 metric_composite ?= current_metric
202
203 if tool.feature_stone /= Void then
204 selected_feature := tool.feature_stone.e_feature
205 end
206 selected_class := tool.selected_class
207 selected_cluster := tool.selected_cluster
208 selected_system := tool.system
209
210 -- Case when selected class is not in system
211 if scope.index = Class_scope and selected_class = Void then
212 Result := "Class not compiled"
213 -- Result cannot be saved.
214 tool.add.set_added (True)
215 else
216 if metric_composite /= Void and then metric_composite.is_scope_ratio then
217 -- Adjust scopes of numerator and denominator.
218 scope_num := metric_composite.scope_num
219 scope_den := metric_composite.scope_den
220 -- `selected_name' is used just to adjust scopes.
221 -- It won't be used in `display_result'.
222 selected_name1 := select_name_and_adjust_scope (scope_num,
223 selected_feature, selected_class, selected_cluster, selected_system)
224 selected_name2 := select_name_and_adjust_scope (scope_den,
225 selected_feature, selected_class, selected_cluster, selected_system)
226 tool.add.set_scope_type (scope_num.name + " / " + scope_den.name)
227 tool.add.set_scope_name (selected_name1 + " / " + selected_name2)
228 else
229 selected_name1 := select_name_and_adjust_scope (scope,
230 selected_feature, selected_class, selected_cluster, selected_system)
231 selected_name2 := ""
232 tool.add.set_scope_type (scope.name)
233 tool.add.set_scope_name (selected_name1.twin)
234 end
235 metric_result := calculate_metric (current_metric, scope)
236 percentage := current_metric.percentage
237 Result := display_result (metric_result, selected_name1, selected_name2, percentage)
238 -- metric_result is useful to fill in multi_column_list on add click.
239 tool.set_metric_result (metric_result)
240 tool.add.set_added (False)
241 tool.add.enable_sensitive
242 tool.add_cmd_in_menu.enable_sensitive
243 end
244 end
245
246 select_name_and_adjust_scope (a_scope: EB_METRIC_SCOPE; feat: E_FEATURE; cla: CLASS_C; clu: CLUSTER_I; sys: SYSTEM_I): STRING is
247 -- Pick up name of the dropped stone.
248 require
249 valid_scope: a_scope /= void
250 do
251 inspect a_scope.index
252 when Feature_scope then
253 a_scope.set_e_feature (feat)
254 Result := feat.name + " (" + feat.written_class.name_in_upper + ")"
255
256 when Class_scope then
257 a_scope.set_class_c (cla)
258 Result := cla.name_in_upper
259
260 when Cluster_scope then
261 a_scope.set_cluster_i (clu)
262 Result := clu.cluster_name
263
264 when System_scope then
265 a_scope.set_system_i (sys)
266 Result := sys.name
267 end
268 ensure
269 something_selected: Result /= Void and then not Result.is_empty
270 end
271
272 calculate_metric (a_metric: EB_METRIC; a_scope: EB_METRIC_SCOPE): DOUBLE is
273 -- Evaluate `a_metric' over `a_scope'.
274 require
275 a_metric_not_void: a_metric /= Void
276 a_scope_not_void: a_scope /= Void
277 local
278 composite_metric: EB_METRIC_COMPOSITE
279 scope_num, scope_den: EB_METRIC_SCOPE
280 num_result, den_result: DOUBLE
281 do
282 composite_metric ?= a_metric
283 if composite_metric /= Void and then composite_metric.is_scope_ratio then
284 scope_num := composite_metric.scope_num.twin
285 scope_den := composite_metric.scope_den.twin
286 num_result := composite_metric.value (scope_num)
287 den_result := composite_metric.value (scope_den)
288 if den_result = 0 then
289 Result := -123456
290 else
291 Result := num_result / den_result
292 end
293 else
294 Result := a_metric.value (a_scope)
295 end
296 end
297
298 handle_details is
299 -- Enable details when available, disable otherwise.
300 local
301 metric: EB_METRIC
302 composite_metric: EB_METRIC_COMPOSITE
303 bool: BOOLEAN
304 do
305 metric := tool.metric (tool.selected_metric)
306 composite_metric ?= tool.metric (tool.selected_metric)
307
308 -- Disable details when:
309 -- scope is feature or class.
310 -- metric concerns systems and only systems (compilations...).
311 -- metric is composite and mixes classes and other Class_unit metric.
312 bool := (scope /= Void and then scope.index < Cluster_scope)
313 or (scope /= Void and then scope.index = Archive_scope)
314 or (metric /= Void and then metric.min_scope > Cluster_scope)
315 or (composite_metric /= Void and then
316 (metric.min_scope = Cluster_scope and equal (metric.unit, interface_names.metric_class_unit)))
317 or (composite_metric /= Void and then composite_metric.is_scope_ratio)
318 or not tool.is_calculation_done
319
320 if bool then
321 tool.details.disable_sensitive
322 tool.details_cmd_in_menu.disable_sensitive
323 else
324 tool.details.enable_sensitive
325 tool.details_cmd_in_menu.enable_sensitive
326 end
327 end
328
329 scope: EB_METRIC_SCOPE
330 -- Currently selected_scope.
331
332 on_calculate_click is
333 -- Calculte the metric asked and display result in text form.
334 local
335 str, archive: STRING
336 x_pos, y_pos: INTEGER
337 metric: EB_METRIC
338 retried: BOOLEAN
339 error_dialog: EB_INFORMATION_DIALOG
340 f: PLAIN_TEXT_FILE
341 do
342 if not retried then
343 x_pos := tool.development_window.window.x_position + 550
344 y_pos := tool.development_window.window.y_position + 100
345 if tool.workbench.successful then
346 disable_all_components
347 tool.development_window.window.set_pointer_style (tool.development_window.Wait_cursor)
348 tool.set_selected_metric (tool.metric_field.text)
349 tool.set_selected_scope (tool.scope_combobox.text)
350 scope := tool.scope (tool.selected_scope)
351 metric := tool.metric (tool.selected_metric)
352 check scope /= Void and metric /= Void end
353 tool.progress_dialog.start (100)
354 metric.progress_changed_actions.wipe_out
355 metric.progress_changed_actions.extend (agent display_metric_calculation_progress)
356 if scope.index /= Archive_scope then
357 str := fill_text_area (metric)
358 else
359 archive := tool.archive_for_measure
360 if archive /= Void and then not archive.is_empty then
361 create f.make (archive)
362 if f.exists then
363 str := retrieve_archived_measure (metric, f)
364 -- Archive result cannot be saved again.
365 tool.add.set_added (True)
366 else
367 create error_dialog.make_with_text ("Error in archive file.%N%
368 %No file has been selected or%N%
369 %selected file does not exist.")
370 error_dialog.set_position (x_pos, y_pos)
371 error_dialog.show_modal_to_window (tool.development_window.window)
372 end
373 end
374 end
375 if str = Void or str.is_empty then
376 tool.text_area.remove_text
377 else
378 tool.text_area.set_text (str)
379 end
380 tool.set_calculation_done (True)
381 tool.progress_dialog.hide
382 handle_details
383 tool.development_window.window.set_pointer_style (tool.development_window.Standard_cursor)
384 enable_all_components
385 if scope.index = Archive_scope or
386 equal (str, "Class not compiled") then
387 tool.add.disable_sensitive
388 tool.add_cmd_in_menu.disable_sensitive
389 end
390 else
391 create error_dialog.make_with_text ("Metric calculation is not available.%N%
392 %Compilation either is not finished yet%N%
393 %or has not been successful.")
394 error_dialog.set_position (x_pos, y_pos)
395 error_dialog.show_modal_to_window (tool.development_window.window)
396 end
397 end
398 rescue
399 retried := True
400 tool.progress_dialog.hide
401 tool.progress_dialog.enable_cancel
402 enable_all_components
403 tool.details.disable_sensitive
404 tool.details_cmd_in_menu.disable_sensitive
405 tool.development_window.window.set_pointer_style (tool.development_window.Standard_cursor)
406 retry
407 end
408
409 disable_all_components is
410 -- Disable buttons and menu items during calculation.
411 do
412 tool.details.disable_sensitive
413 tool.new_metric.disable_sensitive
414 tool.calculate.disable_sensitive
415 tool.add.disable_sensitive
416 tool.delete.disable_sensitive
417 tool.manage.disable_sensitive
418 tool.archive.disable_sensitive
419
420 tool.details_cmd_in_menu.disable_sensitive
421 tool.new_metric_cmd_in_menu.disable_sensitive
422 tool.calculate_cmd_in_menu.disable_sensitive
423 tool.add_cmd_in_menu.disable_sensitive
424 tool.delete_cmd_in_menu.disable_sensitive
425 tool.manage_cmd_in_menu.disable_sensitive
426 tool.archive_cmd_in_menu.disable_sensitive
427
428 tool.name.disable_sensitive
429 tool.scope_combobox.disable_sensitive
430 tool.metric_field.disable_sensitive
431 tool.metric_button.disable_sensitive
432 tool.unit_field.disable_sensitive
433 end
434
435 enable_all_components is
436 -- Enable buttons and menu items after calculation
437 do
438 -- Details are not necessarily enabled after a calculation.
439 -- This is handled by `handle_details'.
440 handle_details
441 if not tool.add.added then
442 tool.add.enable_sensitive
443 tool.add_cmd_in_menu.enable_sensitive
444 end
445 tool.new_metric.enable_sensitive
446 tool.calculate.enable_sensitive
447 tool.delete.enable_sensitive
448 tool.manage.enable_sensitive
449 tool.archive.enable_sensitive
450
451 tool.new_metric_cmd_in_menu.enable_sensitive
452 tool.calculate_cmd_in_menu.enable_sensitive
453 tool.delete_cmd_in_menu.enable_sensitive
454 tool.manage_cmd_in_menu.enable_sensitive
455 tool.archive_cmd_in_menu.enable_sensitive
456
457 tool.name.enable_sensitive
458 tool.scope_combobox.enable_sensitive
459 tool.metric_field.enable_sensitive
460 tool.metric_button.enable_sensitive
461 tool.unit_field.enable_sensitive
462 end
463
464 feature{NONE} -- Progress dialog display
465
466 display_metric_calculation_progress (progress_value, progress_count: INTEGER; message: STRING) is
467 -- Display progress infomation in `tool'.`progress_dialog'.
468 require
469 progress_value_not_negative: progress_value >= 0
470 pregress_count_not_negative: progress_count >= 0
471 proress_value_not_larger_than_progress_count:
472 progress_value <= progress_count
473 message_not_void: message /= Void
474 local
475 l_progress: DOUBLE
476 do
477 if progress_count > 0 then
478 l_progress := progress_value.to_double / progress_count.to_double
479 l_progress := l_progress * 100
480 tool.progress_dialog.set_value (l_progress.truncated_to_integer)
481 else
482 tool.progress_dialog.set_value (100)
483 end
484 tool.progress_dialog.set_current_entity (message)
485 end
486
487 indexing
488 copyright: "Copyright (c) 1984-2006, Eiffel Software"
489 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
490 licensing_options: "http://www.eiffel.com/licensing"
491 copying: "[
492 This file is part of Eiffel Software's Eiffel Development Environment.
493
494 Eiffel Software's Eiffel Development Environment is free
495 software; you can redistribute it and/or modify it under
496 the terms of the GNU General Public License as published
497 by the Free Software Foundation, version 2 of the License
498 (available at the URL listed under "license" above).
499
500 Eiffel Software's Eiffel Development Environment is
501 distributed in the hope that it will be useful, but
502 WITHOUT ANY WARRANTY; without even the implied warranty
503 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
504 See the GNU General Public License for more details.
505
506 You should have received a copy of the GNU General Public
507 License along with Eiffel Software's Eiffel Development
508 Environment; if not, write to the Free Software Foundation,
509 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
510 ]"
511 source: "[
512 Eiffel Software
513 356 Storke Road, Goleta, CA 93117 USA
514 Telephone 805-685-1006, Fax 805-685-6869
515 Website http://www.eiffel.com
516 Customer support http://support.eiffel.com
517 ]"
518
519 end -- class EB_METRIC_CALCULATE_CMD

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23