Class: LayoutAgent

Inherits:
MINT::Agent show all
Includes:
CUIControl
Defined in:
lib/MINT-core/agent/cui-gfx.rb

Instance Attribute Summary

Attributes inherited from MINT::Agent

#running_mappings

Instance Method Summary collapse

Methods included from CUIControl

add_to_cache, clearHighlighted, fill_active_cio_cache, find_cio_from_coordinates, refresh_all, remove_from_cache, retrieveHighlighted, update_cache

Methods included from MINT

#cache_coordinates, #cache_touched, #consume, #filter, #has_moved?, #restart_timeout, #start_one_time_tick, #start_timeout, #stop_timeout, #touch_changed?

Methods inherited from MINT::Agent

#addMapping, #run

Constructor Details

#initializeLayoutAgent

Returns a new instance of LayoutAgent.



6
7
8
9
# File 'lib/MINT-core/agent/cui-gfx.rb', line 6

def initialize
  @solver = Cassowary::ClSimplexSolver.new
  super
end

Instance Method Details

#calc_opt_square_traverse(quota, root_le, border) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/MINT-core/agent/cui-gfx.rb', line 107

def calc_opt_square_traverse(quota, root_le,border)
  max_space = root_le.minspace*quota
  kantenlaenge = Math.sqrt(max_space)
  border_space = 4 * border * kantenlaenge  -   (2 * border)**2
  optspace = root_le.minspace*quota-border_space
  #   p "Optspace for #{root_le.name} = #{optspace}"
  root_le.update(:optspace => optspace)

  if root_le.type=="layoutcontainer"
    root_le.layoutelements.each do |e|
      calc_opt_square_traverse(quota,e,border)
    end
  end
end

#calculate_layout_on_task_change(result) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/MINT-core/agent/cui-gfx.rb', line 40

def calculate_layout_on_task_change(result)
  p "Layout agent has recieved task removal request #{result.inspect}"

  deactivate_layout_on_task_deactivate(result.name)
  p "after task deaktivate"
  root = find_container_to_recalculate(result.name)
  c = Box.first(:name=>root)
  setup_constraints(c)
end

#calculateMinimumSquareSpace(le) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/MINT-core/agent/cui-gfx.rb', line 72

def calculateMinimumSquareSpace(le)
  if le.type=="layoutcontainer"
    #   p "Calculating space for container #{le.name}"
    space = 0

    le.layoutelements.each do |e|
      space = space + calculateMinimumSquareSpace(e)

    end
    #  p "Calculated from container #{space}"
    le.update(:minspace => space)


    return space
  else
    #     p "Calculating space for element #{le.inspect}"
    if (le.minwidth  and le.minheight)
      space =  le.minwidth*le.minheight
      le.update(:minspace => space)
      # p "calculated from element #{space}"
      return space
    else
      return 0
    end
  end
end

#calculateOptSquareSpace(root_container, available_space, border) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/MINT-core/agent/cui-gfx.rb', line 99

def calculateOptSquareSpace(root_container, available_space,border)
  root_le=Layoutelement.first(:name=>root_container)
  min_space_used = root_le.minspace
  quota =  Float(available_space )/Float( min_space_used)
  # p "quota: #{quota}"
  calc_opt_square_traverse(quota, root_le,border)
end

#find_container_to_recalculate(taskname) ⇒ String

Returns container name to recalculate.

Parameters:

  • taskname (String)

    name of container

Returns:

  • (String)

    container name to recalculate



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/MINT-core/agent/cui-gfx.rb', line 54

def find_container_to_recalculate(taskname)
  le = Layout.first(:name=>taskname)

  if le.state.eql?("inactive")
    # luis = Layout.all(:parent=>le.parent).map &:task
    #   luis.each do |name|
    #    cui = CUI.first(:task=>name)
    #    if (cui != nil)
    #      cui.destroy!
    #    end
    #  end
    find_container_to_recalculate(le.layout)
  else
    #p "Container to recalculate #{le.inspect}"
    return le.name
  end
end

#initial_calculation(result) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/MINT-core/agent/cui-gfx.rb', line 11

def initial_calculation(result)
  p  "Initial Layout recalculation requested for new PTS #{result.inspect} "

  #MINT::CIO.all.each { |c|
  #  c.calculateMinimumSize
  # }


  root_cio = CIO.first(:name=>result['root'])


  # p "#{root_le} root:#{root}"
  #p "minimumspace  = "+ calculateMinimumSquareSpace(root_le).to_s

  #calculateOptSquareSpace(result.root, 800*600, 10)

  root_cio.print
  # pts = result.interactionTasks.map &:name
  #root = find_common_container(pts,true)
#    c = Box.new(:name=>le.name, :x=>0,:y=>0, :width=>1200, :height=>800, :layer=>1)
  # c.save

  root_cio.calculate_container(@solver,20)

  CUIControl.fill_active_cio_cache
  true
end

#wait_border_crossing(result) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/MINT-core/agent/cui-gfx.rb', line 122

def wait_border_crossing(result)
  p "subscribing to pointer #{result.parent.inspect}"

  cio = CIO.first(:name=>result.parent.name)

  p "got #{cio.inspect}"
  Thread.new(cio.name,cio.x,cio.y,cio.width,cio.height) { |name,cx,cy,cw,ch|

    Redis.new.subscribe("juggernaut") do |on|
      on.message do |c,msg|
        r = MultiJson.decode msg
        if (r["channels"].include? "pointer")
          if /POS/.match(r["data"])
            z,x,y = /POS-(\d+),(\d+)/.match(r["data"]).to_a.map &:to_i
            p "data #{x},#{y} #{cx} #{cy} #{cw} #{ch}"

            if (x<cx or x>(cx+cw) or y<cy or y>(cy+ch))
              p "outside!!!"

              # Hacks start here

              aio = AIO.first(:name=>"0")
              aio.process_event(:suspend)

              arframe = AIO.first(:name=>"ar_frame")
              arframe.process_event(:present)
              p "after"

              Thread.stop
            end
          end
        end
      end
    end

  }
end