Class: PresentationLoader
- Inherits:
-
Object
- Object
- PresentationLoader
show all
- Includes:
- Soby
- Defined in:
- lib/soby/loader.rb
Defined Under Namespace
Classes: MyVideo
Constant Summary
Constants included
from Soby
Soby::SLEEP_TIME
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Soby
auto_update, #create_mat4x4, find_files, find_files_except, #get_angle, #get_global_transform, load_presentation, #read_transform, reload_presentation, start_presentation
Constructor Details
Returns a new instance of PresentationLoader.
18
19
20
21
22
23
24
25
26
|
# File 'lib/soby/loader.rb', line 18
def initialize (app, url)
@app = app
@url = url
@presentation = Presentation.new(app)
@presentation.url = @url
load_files
build_internal
end
|
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
14
15
16
|
# File 'lib/soby/loader.rb', line 14
def debug
@debug
end
|
#graphics ⇒ Object
Returns the value of attribute graphics.
16
17
18
|
# File 'lib/soby/loader.rb', line 16
def graphics
@graphics
end
|
#presentation ⇒ Object
Returns the value of attribute presentation.
14
15
16
|
# File 'lib/soby/loader.rb', line 14
def presentation
@presentation
end
|
#pshape ⇒ Object
Returns the value of attribute pshape.
13
14
15
|
# File 'lib/soby/loader.rb', line 13
def pshape
@pshape
end
|
#svg ⇒ Object
Returns the value of attribute svg.
13
14
15
|
# File 'lib/soby/loader.rb', line 13
def svg
@svg
end
|
#url ⇒ Object
Returns the value of attribute url.
14
15
16
|
# File 'lib/soby/loader.rb', line 14
def url
@url
end
|
Instance Method Details
#add_group(group, slide) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/soby/loader.rb', line 136
def add_group(group, slide)
id = slide.title
refid = slide.refid
surf_max = 0
biggest_rect = nil
group.css("rect").each do |rect|
if biggest_rect == nil
biggest_rect = rect
end
surf_rect = rect.attributes["width"].value.to_i \
* rect.attributes["height"].value.to_i
if(surf_rect > surf_max)
biggest_rect = rect
surf_max = surf_rect
end
end
rect_id = biggest_rect.attributes["id"].value
transform = get_global_transform biggest_rect
slide.set_geometry(biggest_rect, transform[0])
desc = group.css("desc").first
title = group.css("title").first
if desc != nil
if title == nil || (title.text.match(/animation/) == nil and title.text.match(/video/) == nil)
puts "Group Description read #{desc.text}"
slide.description = desc.text
end
end
e = @pshape.getChild(rect_id)
if e == nil
puts "Error: rect ID: #{rect_id} not found "
else
@pshape.getChild(rect_id).setVisible(!slide.hide)
end
puts "Slide #{id} created from a group, and the rectangle: #{rect_id}"
@presentation.add_slide(slide)
end
|
#add_rect_or_image_frame(element, slide) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/soby/loader.rb', line 113
def add_rect_or_image_frame(element, slide)
id = slide.title
refid = slide.refid
transform = get_global_transform element
slide.set_geometry(element, transform[0])
pshape_element = @pshape.getChild(refid)
if pshape_element == nil
puts "Error: rect or Image ID: #{refid} not found. CHECK THE PROCESSING VERSION."
else
pshape_element.setVisible(!slide.hide) if element.name == "rect"
end
puts "Slide #{id} created from a rect : #{refid}" if element.name == "rect"
puts "Slide #{id} created from an image: #{refid}" if element.name == "image"
@presentation.add_slide(slide)
end
|
#build_internal ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/soby/loader.rb', line 37
def build_internal
puts "Svg null, look for the error... !" if @svg == nil
return if @svg == nil
load_code
load_frames
load_videos
load_animations
end
|
#create_slide(child) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/soby/loader.rb', line 96
def create_slide child
slide = Slide.new(child)
@svg.search("[id=" + slide.refid + "]").each do |elem|
case elem.name
when "rect", "image"
add_rect_or_image_frame(elem, slide)
when "g"
add_group(elem, slide)
else
puts "Slide type not supported ! " + elem.name
end
end
end
|
#load_animations ⇒ Object
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/soby/loader.rb', line 238
def load_animations
puts "Loading the animations..."
@svg.css("*").each do |elem|
valid = false
elem.children.each do |child|
valid = true if child.name == "title" && child.text.match(/animation/)
end
next unless valid
id = elem.attributes["id"].value
t = elem.css("desc").text.split("\n")
slide_id = t[0]
anim_id = t[1].to_i
animation = OpenStruct.new
animation.pshape_elem = @pshape.getChild(id)
puts "Animation found on slide #{slide_id} with element #{animation.pshape_elem}"
if @presentation.slides[slide_id] == nil
puts "Error -> The animation #{id} is linked to the slide #{slide_id} which is not found !"
else
@presentation.slides[slide_id].add_animation(anim_id, animation)
animation.pshape_elem.setVisible(false) unless animation.pshape_elem == nil
puts "Animation #{id} loaded with #{slide_id}"
end
end
end
|
#load_code ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/soby/loader.rb', line 47
def load_code
puts "Loading the code..."
@svg.css("text").each do |text|
return if text.attributes["id"] == nil
id = text.attributes["id"].value
title = text.css("title")
next if title == nil
is_code = title.text.match(/code/) != nil
next unless is_code
files = text.css("desc").text.split("\n")
if files == nil
puts "Source not found, check your includes in svg"
next
end
files.each do |file|
dir = File.dirname(@url)
abs_file = dir + "/" + file
puts ("Loading the code: " + abs_file)
@presentation.add_source abs_file
load abs_file
end
@pshape.getChild(id).setVisible(false)
end
end
|
#load_files ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/soby/loader.rb', line 28
def load_files
xml = @app.loadXML(@url)
@pshape = Java::TechLityReaSvgextended::PShapeSVGExtended.new(xml)
@presentation.pshape = @pshape
@svg = Nokogiri::XML(open(@url)).children[1];
end
|
#load_frames ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/soby/loader.rb', line 83
def load_frames
puts "Loading the frames..."
@svg.children.each do |child|
next unless child.name =~ /frame/
attr = child.attributes
next if attr["refid"] == nil
create_slide child
end
end
|
#load_videos ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/soby/loader.rb', line 197
def load_videos
puts "Loading the videos..."
@svg.css("rect").each do |rect|
return if rect.attributes["id"] == nil
id = rect.attributes["id"].value
title = rect.css("title")
next if title == nil
is_video = title.text.match(/video/) != nil
next unless is_video
t = rect.css("desc").text.split("\n")
slide_id = t[0]
path = t[1]
puts ("Loading the video : " + path)
tr = get_global_transform rect
video = MyVideo.new(path, @presentation.slides[slide_id], tr[0], tr[1], tr[2])
if @presentation.slides[slide_id] == nil
puts "Error -> The video #{id} is linked to the slide #{slide_id} which is not found !"
else
@presentation.slides[slide_id].add_video(video)
puts "Video #{id} loaded with #{slide_id}"
end
end
end
|
#to_s ⇒ Object
321
322
323
|
# File 'lib/soby/loader.rb', line 321
def to_s
"Presentation loader. "
end
|