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