Class: Roby::GUI::RelationsCanvas
- Includes:
- TaskDisplayConfiguration
- Defined in:
- lib/roby/gui/relations_view/relations_canvas.rb
Constant Summary collapse
- COLORS =
%w{black #800000 #008000 #000080 #C05800 #6633FF #CDBE70 #CD8162 #A2B5CD}.freeze
- DISPLAY_POLICIES =
%i[explicit emitters emitters_and_parents].freeze
Instance Attribute Summary collapse
-
#arrows ⇒ Object
readonly
A [object, object, relation] => GraphicsItem mapping of arrows.
-
#current_color ⇒ Object
readonly
Returns the value of attribute current_color.
-
#current_time ⇒ Object
readonly
Returns the value of attribute current_time.
-
#display_policy ⇒ Object
Returns the value of attribute display_policy.
-
#enabled_relations ⇒ Object
readonly
The set of relations that should be displayed.
-
#flashing_objects ⇒ Object
readonly
A set of events that are shown during only two calls of #update.
-
#free_arrows ⇒ Object
readonly
Returns the value of attribute free_arrows.
-
#graphics ⇒ Object
readonly
A DRbObject => GraphicsItem mapping.
-
#hide_finalized ⇒ Object
True if the finalized tasks should not be displayed.
-
#keep_signals ⇒ Object
Returns the value of attribute keep_signals.
-
#last_arrows ⇒ Object
readonly
A [object, object, relation] => GraphicsItem mapping of arrows.
-
#plans ⇒ Object
readonly
The set of plans that should be displayed.
-
#relation_brushes ⇒ Object
readonly
Returns the value of attribute relation_brushes.
-
#relation_colors ⇒ Object
readonly
Returns the value of attribute relation_colors.
-
#relation_pens ⇒ Object
readonly
Returns the value of attribute relation_pens.
-
#scene ⇒ Object
readonly
The Qt::GraphicsScene we are manipulating.
-
#selected_objects ⇒ Object
readonly
The set of objects that are selected for display in the :explicit display mode.
-
#signal_arrows ⇒ Object
readonly
A pool of arrows items used to display the event signalling.
-
#visible_objects ⇒ Object
readonly
The set of objects that are to be shown at the last update.
Instance Method Summary collapse
- #[](item) ⇒ Object
-
#add_flashing_object(object, &block) ⇒ Object
Add
object
to the list of objects temporarily displayed. -
#allocate_color ⇒ Object
returns the next color in COLORS, cycles if at the end of the array.
- #apply_options(options) ⇒ Object
- #apply_simple_option(option_name, options) ⇒ Object
-
#arrow(from, to, rel, info, base_layer) ⇒ Object
Creates or reuses an arrow object to represent the given relation.
- #clear ⇒ Object
- #clear_arrows(object) ⇒ Object
-
#clear_flashing_objects ⇒ Object
Removes the objects added with #add_flashing_object when they should be removed.
- #create_or_get_item(object, initial_selection) ⇒ Object
- #disable_relation(relation) ⇒ Object
-
#display_plan_bounding_boxes? ⇒ Boolean
True if the plan’s bounding boxes should be displayed or not (true).
- #displayed?(object) ⇒ Boolean
-
#enable_relation(relation) ⇒ Object
Display this relation.
-
#event_relation(form, to, rel, info) ⇒ Object
Returns a canvas object that represents this relation.
-
#find(regex = nil) ⇒ Object
Centers the view on the set of object found which matches
regex
. -
#ignore_relation(relation) ⇒ Object
Don’t use this relation at all.
-
#initialize(plans) ⇒ RelationsCanvas
constructor
A new instance of RelationsCanvas.
- #layout_method ⇒ Object
- #layout_method=(new_method) ⇒ Object
- #layout_options ⇒ Object
-
#layout_relation(relation) ⇒ Object
Use this relation for layout but not for display.
-
#layout_relation?(relation) ⇒ Boolean
True if this relation should be used for layout.
- #make_graphics_visible(object) ⇒ Object
- #object_of(item) ⇒ Object
-
#propagation_style(arrow, flag) ⇒ Object
Sets the style on
arrow
according to the event propagation type provided inflag
. - #relation_color(relation) ⇒ Object
-
#relation_enabled?(relation) ⇒ Boolean
True if this relation should be displayed.
- #relation_of(item) ⇒ Object
- #remove_graphics(item, scene = nil) ⇒ Object
- #save_options ⇒ Object
-
#task_relation(from, to, rel, info) ⇒ Object
Returns a canvas object that represents this relation.
-
#update(time = nil) ⇒ Object
Update the display with new data that has come from the data stream.
- #update_relation_color(relation, color) ⇒ Object
- #update_visible_objects ⇒ Object
Methods included from TaskDisplayConfiguration
#filter_prefixes, #filtered_out_label?, #update_prefixes_removal
Constructor Details
#initialize(plans) ⇒ RelationsCanvas
Returns a new instance of RelationsCanvas.
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 495 def initialize(plans) @scene = Qt::GraphicsScene.new super() @plans = plans.dup @display_plan_bounding_boxes = false @display_policy = :explicit @graphics = {} @selected_objects = Set.new @visible_objects = Set.new @flashing_objects = {} @arrows = {} @free_arrows = [] @enabled_relations = Set.new @layout_relations = Set.new @relation_colors = {} @relation_pens = Hash.new(Qt::Pen.new(Qt::Color.new(ARROW_COLOR))) @relation_brushes = Hash.new(Qt::Brush.new(Qt::Color.new(ARROW_COLOR))) @current_color = 0 @signal_arrows = [] @hide_finalized = true @layout_options = {} default_colors = { Roby::TaskStructure::Dependency => "grey", Roby::TaskStructure::PlannedBy => "#32ba21", Roby::TaskStructure::ExecutionAgent => "#5d95cf", Roby::TaskStructure::ErrorHandling => "#ff2727" } default_colors.each do |rel, color| update_relation_color(rel, color) end relation_pens[Roby::EventStructure::Signal] = Qt::Pen.new(Qt::Color.new("black")) relation_brushes[Roby::EventStructure::Signal] = Qt::Brush.new(Qt::Color.new("black")) relation_pens[Roby::EventStructure::Forwarding] = Qt::Pen.new(Qt::Color.new("black")) relation_pens[Roby::EventStructure::Forwarding].style = Qt::DotLine relation_brushes[Roby::EventStructure::Forwarding] = Qt::Brush.new(Qt::Color.new("black")) relation_brushes[Roby::EventStructure::Forwarding].style = Qt::DotLine enable_relation(Roby::TaskStructure::Dependency) enable_relation(Roby::TaskStructure::ExecutionAgent) enable_relation(Roby::TaskStructure::PlannedBy) end |
Instance Attribute Details
#arrows ⇒ Object (readonly)
A [object, object, relation] => GraphicsItem mapping of arrows
465 466 467 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 465 def arrows @arrows end |
#current_color ⇒ Object (readonly)
Returns the value of attribute current_color.
470 471 472 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 470 def current_color @current_color end |
#current_time ⇒ Object (readonly)
Returns the value of attribute current_time.
470 471 472 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 470 def current_time @current_time end |
#display_policy ⇒ Object
Returns the value of attribute display_policy.
470 471 472 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 470 def display_policy @display_policy end |
#enabled_relations ⇒ Object (readonly)
The set of relations that should be displayed
707 708 709 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 707 def enabled_relations @enabled_relations end |
#flashing_objects ⇒ Object (readonly)
A set of events that are shown during only two calls of #update
483 484 485 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 483 def flashing_objects @flashing_objects end |
#free_arrows ⇒ Object (readonly)
Returns the value of attribute free_arrows.
470 471 472 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 470 def free_arrows @free_arrows end |
#graphics ⇒ Object (readonly)
A DRbObject => GraphicsItem mapping
473 474 475 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 473 def graphics @graphics end |
#hide_finalized ⇒ Object
True if the finalized tasks should not be displayed
489 490 491 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 489 def hide_finalized @hide_finalized end |
#keep_signals ⇒ Object
Returns the value of attribute keep_signals.
672 673 674 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 672 def keep_signals @keep_signals end |
#last_arrows ⇒ Object (readonly)
A [object, object, relation] => GraphicsItem mapping of arrows
468 469 470 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 468 def last_arrows @last_arrows end |
#plans ⇒ Object (readonly)
The set of plans that should be displayed
462 463 464 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 462 def plans @plans end |
#relation_brushes ⇒ Object (readonly)
Returns the value of attribute relation_brushes.
470 471 472 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 470 def relation_brushes @relation_brushes end |
#relation_colors ⇒ Object (readonly)
Returns the value of attribute relation_colors.
470 471 472 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 470 def relation_colors @relation_colors end |
#relation_pens ⇒ Object (readonly)
Returns the value of attribute relation_pens.
470 471 472 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 470 def relation_pens @relation_pens end |
#scene ⇒ Object (readonly)
The Qt::GraphicsScene we are manipulating
459 460 461 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 459 def scene @scene end |
#selected_objects ⇒ Object (readonly)
The set of objects that are selected for display in the :explicit display mode
480 481 482 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 480 def selected_objects @selected_objects end |
#signal_arrows ⇒ Object (readonly)
A pool of arrows items used to display the event signalling
486 487 488 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 486 def signal_arrows @signal_arrows end |
#visible_objects ⇒ Object (readonly)
The set of objects that are to be shown at the last update
476 477 478 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 476 def visible_objects @visible_objects end |
Instance Method Details
#[](item) ⇒ Object
596 597 598 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 596 def [](item) graphics[item] end |
#add_flashing_object(object, &block) ⇒ Object
Add object
to the list of objects temporarily displayed. If a block is given, the object is removed when the block returns false. Otherwise, it is removed at the next display update
If this method is called more than once for the same object, the object is removed when all blocks have returned false at least once
829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 829 def add_flashing_object(object, &block) if block flashing_objects[object] ||= [] flashing_objects[object] << block else flashing_objects[object] ||= nil end if object.display_parent add_flashing_object(object.display_parent, &block) end create_or_get_item(object, false) end |
#allocate_color ⇒ Object
returns the next color in COLORS, cycles if at the end of the array
677 678 679 680 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 677 def allocate_color @current_color = (current_color + 1) % COLORS.size COLORS[current_color] end |
#apply_options(options) ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 553 def () if enabled_relations = ["enabled_relations"] enabled_relations.each do |name| rel = constant(name) enable_relation(rel) end end apply_simple_option("show_ownership", ) apply_simple_option("removed_prefixes", ) apply_simple_option("hide_finalized", ) apply_simple_option("removed_prefixes", ) apply_simple_option("hidden_labels", ) apply_simple_option("display_policy", ) end |
#apply_simple_option(option_name, options) ⇒ Object
568 569 570 571 572 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 568 def apply_simple_option(option_name, ) if .has_key?(option_name) self.send("#{option_name}=", [option_name]) end end |
#arrow(from, to, rel, info, base_layer) ⇒ Object
Creates or reuses an arrow object to represent the given relation
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 611 def arrow(from, to, rel, info, base_layer) id = [from, to, rel] unless (item = arrows[id]) if item = last_arrows.delete(id) arrows[id] = item else item = arrows[id] = (free_arrows.pop || scene.add_arrow(ARROW_SIZE)) item.z_value = base_layer - 1 item.pen = item.line.pen = relation_pens[rel] item.brush = relation_brushes[rel] end end GUI.arrow_set item, self[from], self[to] end |
#clear ⇒ Object
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 1124 def clear arrows.dup.each_value(&method(:remove_graphics)) graphics.dup.each_value(&method(:remove_graphics)) arrows.clear free_arrows.clear last_arrows.clear graphics.clear signal_arrows.each do |arrow| arrow.visible = false end selected_objects.clear visible_objects.clear flashing_objects.clear scene.update(scene.scene_rect) end |
#clear_arrows(object) ⇒ Object
1115 1116 1117 1118 1119 1120 1121 1122 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 1115 def clear_arrows(object) arrows.delete_if do |(from, to, _), arrow| if from == object || to == object remove_graphics(arrow) true end end end |
#clear_flashing_objects ⇒ Object
Removes the objects added with #add_flashing_object when they should be removed
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 845 def clear_flashing_objects removed_objects = [] flashing_objects.delete_if do |object, blocks| blocks.delete_if { |block| !block.call } unless blocks.empty? next end removed_objects << object end removed_objects.each do |object| if item = graphics[object] item.visible = displayed?(object) end end end |
#create_or_get_item(object, initial_selection) ⇒ Object
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 804 def create_or_get_item(object, initial_selection) unless (item = graphics[object]) item = graphics[object] = object.display_create(self) if item if object.display_parent item.parent_item = self[object.display_parent] end yield(item) if block_given? if initial_selection selected_objects << object end end end item end |
#disable_relation(relation) ⇒ Object
723 724 725 726 727 728 729 730 731 732 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 723 def disable_relation(relation) return unless relation_enabled?(relation) @enabled_relations.delete(relation) arrows.each do |(_, _, rel), arrow| if rel == relation arrow.visible = false end end end |
#display_plan_bounding_boxes? ⇒ Boolean
Returns true if the plan’s bounding boxes should be displayed or not (true).
493 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 493 attr_predicate :display_plan_bounding_boxes?, true |
#displayed?(object) ⇒ Boolean
796 797 798 799 800 801 802 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 796 def displayed?(object) if (parent = object.display_parent) && !displayed?(parent) return false end visible_objects.include?(object) end |
#enable_relation(relation) ⇒ Object
Display this relation
695 696 697 698 699 700 701 702 703 704 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 695 def enable_relation(relation) return if relation_enabled?(relation) @enabled_relations << relation arrows.each do |(_, _, rel), arrow| if rel == relation arrow.visible = true end end end |
#event_relation(form, to, rel, info) ⇒ Object
Returns a canvas object that represents this relation
606 607 608 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 606 def event_relation(form, to, rel, info) arrow(from, to, rel, info, EVENT_LAYER) end |
#find(regex = nil) ⇒ Object
Centers the view on the set of object found which matches regex
. If regex
is nil, ask one to the user
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 629 def find(regex = nil) unless regex regex = Qt::InputDialog.get_text main, "Find objects in relation view", "Object name" return unless regex && !regex.empty? end regex = /#{regex.to_str}/i if regex.respond_to?(:to_str) # Get the tasks and events matching the string objects = [] for p in plans objects.concat( p.tasks.find_all do |object| displayed?(object) && regex === object.display_name(self) end ) objects.concat( p.free_events.find_all do |object| displayed?(object) && regex === object.display_name(self) end ) end return if objects.empty? # Find the graphics items bb = objects.inject(Qt::RectF.new) do |bb, object| if item = self[object] item.selected = true bb | item.scene_bounding_rect | item.map_to_scene(item.children_bounding_rect).bounding_rect else bb end end bb.adjust(-FIND_MARGIN, -FIND_MARGIN, FIND_MARGIN, FIND_MARGIN) ui.graphics.fit_in_view bb, Qt::KeepAspectRatio scale = ui.graphics.matrix.m11 if scale > 1 ui.graphics.resetMatrix ui.graphics.scale 1, 1 end end |
#ignore_relation(relation) ⇒ Object
Don’t use this relation at all
718 719 720 721 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 718 def ignore_relation(relation) disable_relation(relation) @layout_relations.delete(relation) end |
#layout_method ⇒ Object
778 779 780 781 782 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 778 def layout_method return @layout_method if @layout_method "dot" end |
#layout_method=(new_method) ⇒ Object
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 754 def layout_method=(new_method) return if new_method == @layout_method @layout_method = nil @layout_options = nil if new_method new_method =~ /^(\w+)(?: \[(.*)\])?$/ @layout_method = $1 if $2 @layout_options = $2.split(",").each_with_object({}) do |v, h| k, v = v.split("=") h[k] = v end end end display end |
#layout_options ⇒ Object
772 773 774 775 776 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 772 def return @layout_options if @layout_options { rankdir: "TB" } end |
#layout_relation(relation) ⇒ Object
Use this relation for layout but not for display
See also #ignore_relation
712 713 714 715 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 712 def layout_relation(relation) disable_relation(relation) @layout_relations << relation end |
#layout_relation?(relation) ⇒ Boolean
True if this relation should be used for layout
See also #relation_enabled?, #layout_relation, #ignore_relation
690 691 692 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 690 def layout_relation?(relation) relation_enabled?(relation) || @layout_relations.include?(relation) end |
#make_graphics_visible(object) ⇒ Object
945 946 947 948 949 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 945 def make_graphics_visible(object) object = create_or_get_item(object, false) object.visible = true object end |
#object_of(item) ⇒ Object
574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 574 def object_of(item) id = item.data(0).to_string return unless id id = Integer(id) obj, = graphics.find do |obj, obj_item| obj.object_id == id end obj end |
#propagation_style(arrow, flag) ⇒ Object
Sets the style on arrow
according to the event propagation type provided in flag
arrow
is the graphics item representing the relation and flag
is one of the PROPAG_ constant
868 869 870 871 872 873 874 875 876 877 878 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 868 def propagation_style(arrow, flag) unless defined? @@propagation_styles @@propagation_styles = {} @@propagation_styles[true] = [Qt::Brush.new(Qt::Color.new("black")), Qt::Pen.new, (forward_pen = Qt::Pen.new)] forward_pen.style = Qt::DotLine @@propagation_styles[false] = [Qt::Brush.new(Qt::Color.new("black")), Qt::Pen.new, Qt::Pen.new] end arrow.brush, arrow.pen, arrow.line.pen = @@propagation_styles[flag] end |
#relation_color(relation) ⇒ Object
734 735 736 737 738 739 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 734 def relation_color(relation) unless relation_colors.has_key?(relation) update_relation_color(relation, allocate_color) end relation_colors[relation] end |
#relation_enabled?(relation) ⇒ Boolean
True if this relation should be displayed
683 684 685 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 683 def relation_enabled?(relation) @enabled_relations.include?(relation) end |
#relation_of(item) ⇒ Object
586 587 588 589 590 591 592 593 594 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 586 def relation_of(item) id = item.data(0).to_string arrows.each do |(from, to, rel), arrow| if arrow.data(0).to_string == id return from, to, rel end end nil end |
#remove_graphics(item, scene = nil) ⇒ Object
1108 1109 1110 1111 1112 1113 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 1108 def remove_graphics(item, scene = nil) return unless item scene ||= item.scene scene&.remove_item(item) end |
#save_options ⇒ Object
542 543 544 545 546 547 548 549 550 551 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 542 def = {} ["enabled_relations"] = @enabled_relations.map(&:name) ["show_ownership"] = show_ownership ["hide_finalized"] = hide_finalized ["removed_prefixes"] = removed_prefixes.dup ["hidden_labels"] = hidden_labels.dup ["display_policy"] = display_policy end |
#task_relation(from, to, rel, info) ⇒ Object
Returns a canvas object that represents this relation
601 602 603 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 601 def task_relation(from, to, rel, info) arrow(from, to, rel, info, TASK_LAYER) end |
#update(time = nil) ⇒ Object
Update the display with new data that has come from the data stream.
It would be too complex at this stage to know if the plan has been updated, so the method always returns true
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 956 def update(time = nil) # Allow time to be a Qt::DateTime object, so that we can make it # a slot if time.kind_of?(Qt::DateTime) time = Time.at(Float(time.toMSecsSinceEpoch) / 1000) end enabled_relations << Roby::EventStructure::Signal << Roby::EventStructure::Forwarding if time @current_time = time end @last_arrows, @arrows = arrows, {} @free_arrows ||= [] update_prefixes_removal clear_flashing_objects # The sets of tasks and events know to the data stream all_tasks = plans.inject(Set.new) do |all_tasks, plan| all_tasks.merge plan.tasks all_tasks.merge plan.finalized_tasks end all_events = plans.inject(Set.new) do |all_events, plan| all_events.merge plan.free_events all_events.merge plan.finalized_events end all_task_events = all_tasks.inject(Set.new) do |all_task_events, task| all_task_events.merge(task.bound_events.values) end # Remove the items for objects that don't exist anymore (graphics.keys.to_set - all_tasks - all_events - all_task_events).each do |obj| selected_objects.delete(obj) remove_graphics(graphics.delete(obj)) clear_arrows(obj) end # Create graphics items for all objects that may get displayed # on the canvas all_tasks.each do |object| create_or_get_item(object, true) object.each_event do |ev| create_or_get_item(ev, false) end end all_events.each { |ev| create_or_get_item(ev, true) } plans.each { |p| create_or_get_item(p, display_plan_bounding_boxes?) } update_visible_objects graphics.each do |object, item| item.visible = displayed?(object) end RelationsCanvasEventGenerator.priorities.clear event_priority = 0 plans.each do |p| flags = Hash.new(0) p.called_generators.each do |generator| flags[generator] |= EVENT_CALLED end base_priority = p.called_generators.size p.emitted_events.each do |(_, event)| generator = event.generator flags[generator] |= EVENT_EMITTED end p.failed_emissions.each do |time, generator, reason| flags[generator] = FAILED_EMISSION end flags.each_with_index do |(generator, generator_flags), priority| RelationsCanvasEventGenerator.priorities[generator] = priority if displayed?(generator) item = graphics[generator] item.brush, item.pen = RelationsCanvasEventGenerator.style( generator, generator_flags ) end end end plans.each do |p| # rubocop:disable Style/CombinableLoops p.propagated_events.each do |_, _, sources, to, _| sources.each do |from| RelationsCanvasEventGenerator.priorities[from] ||= (event_priority += 1) RelationsCanvasEventGenerator.priorities[to] ||= (event_priority += 1) end end end [all_tasks, all_events, plans].each do |object_set| object_set.each do |object| graphics = self.graphics[object] if graphics.visible? object.display(self, graphics) end end end # Update arrow visibility arrows.each do |(from, to, rel), item| next unless @enabled_relations.include?(rel) item.visible = (displayed?(from) && displayed?(to)) end # Layout the graph layouts = plans.find_all(&:root_plan?) .map do |p| dot = PlanDotLayout.new begin dot.layout(self, p, ) dot rescue Exception => e puts "Failed to lay out the plan: #{e}" end end.compact layouts.each(&:apply) # Display the signals signal_arrow_idx = -1 plans.each do |p| p.propagated_events.each_with_index do |(_, flag, sources, to), signal_arrow_idx| relation = if flag Roby::EventStructure::Forwarding else Roby::EventStructure::Signal end sources.each do |source_event| arrow = arrow(source_event.generator, to, relation, nil, EVENT_PROPAGATION_LAYER) propagation_style(arrow, flag) end end end arrows.each do |(_, item)| item.visible = true end @free_arrows = last_arrows.values free_arrows.each do |item| item.visible = false end last_arrows.clear true end |
#update_relation_color(relation, color) ⇒ Object
741 742 743 744 745 746 747 748 749 750 751 752 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 741 def update_relation_color(relation, color) relation_colors[relation] = color color = Qt::Color.new(color) pen = relation_pens[relation] = Qt::Pen.new(color) brush = relation_brushes[relation] = Qt::Brush.new(color) arrows.each do |(_, _, rel), arrow| if rel == relation arrow.pen = arrow.line.pen = pen arrow.brush = brush end end end |
#update_visible_objects ⇒ Object
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
# File 'lib/roby/gui/relations_view/relations_canvas.rb', line 880 def update_visible_objects @visible_objects = Set.new # NOTE: we unconditionally add events that are propagated, as # #displayed?(obj) will filter out the ones whose task is hidden plans.each do |p| if display_plan_bounding_boxes? visible_objects << p end p.emitted_events.each do |(_, event)| visible_objects << event.generator end p.propagated_events.each do |_, _, sources, to, _| sources.each do |src| visible_objects << src.generator end visible_objects << to end end case display_policy when :explicit visible_objects.merge(selected_objects) when :emitters, :emitters_and_parents # Make sure that the event's tasks are added to # visible_objects as well visible_objects.dup.each do |obj| if parent = obj.display_parent visible_objects << parent end end end if display_policy == :emitters_and_parents loop do new_visible_objects = Set.new visible_objects.group_by(&:plan).each do |plan, plan_objects| graphs = plan.each_task_relation_graph.find_all(&:root_relation?).map(&:reverse) new_visible_objects.merge(plan.compute_useful_tasks(plan_objects.to_set, graphs: graphs)) new_visible_objects.subtract(plan_objects.to_set) end break if new_visible_objects.empty? visible_objects.merge(new_visible_objects) end visible_objects.dup.each do |obj| if obj.kind_of?(Roby::Task) obj.each_relation do |rel| visible_objects.merge(obj.child_objects(rel)) end end end end if hide_finalized plans.each do |plan| all_finalized = plan.finalized_tasks | plan.finalized_events @visible_objects = visible_objects - all_finalized end end visible_objects.delete_if do |obj| filtered_out_label?(obj.display_name(self)) end end |