Class: Rectangle

Inherits:
Object
  • Object
show all
Defined in:
lib/ListHolder/GanttHolder/Gantt/Rectangle.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gantt, iter) ⇒ Rectangle

Returns a new instance of Rectangle.



6
7
8
9
10
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
38
39
40
41
42
43
44
45
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 6

def initialize(gantt,iter)
	@iter=iter
	@gantt=gantt
	@has_child=iter.has_child?
	@level=0
	@iter_id=iter[gantt.list.list_model.column_of_id].to_i
	@parent_r=@gantt.rectangles[iter.parent[gantt.list.list_model.column_of_id].to_i] unless iter.parent.nil?
	@successors=Hash.new
	if gantt.successors_column
			iter[gantt.successors_column].split(',').each{|pid|
				@successors[pid.to_i]=nil
			}
	end
	@group=iter[gantt.group_column] if gantt.group_column
	@partial=if gantt.partial_column then iter[gantt.partial_column].to_i else 100 end
	@percentage=if gantt.percentage_column then iter[gantt.percentage_column].to_i else 0 end
	if gantt.group_color_column
		begin
			@color=Gdk::Color.parse("##{iter[@gantt.group_color_column]}")
		rescue
			@color=nil
		end
		else
		@color=nil
	end
	@color=Gdk::Color.parse("#1782E0") if @color.nil?
	#we assume it's mysql unix_timestamp
	@start=iter[gantt.start_column].to_i
	@dur=iter[gantt.dur_column].to_i
	
	@y1=0
	@height=10
	@gantt_min_x=0
	iter_coordinates
	@visible=iter[gantt.list.list_model.column_of_visible]
	@px1=nil
	@pwidth=nil
	@py=nil
	@pheight=nil
end

Instance Attribute Details

#durObject (readonly)

Returns the value of attribute dur.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def dur
  @dur
end

#groupObject (readonly)

Returns the value of attribute group.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def group
  @group
end

#heightObject (readonly)

Returns the value of attribute height.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def height
  @height
end

#iterObject (readonly)

Returns the value of attribute iter.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def iter
  @iter
end

#iter_idObject (readonly)

Returns the value of attribute iter_id.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def iter_id
  @iter_id
end

#levelObject

Returns the value of attribute level.



47
48
49
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 47

def level
  @level
end

#percentageObject (readonly)

Returns the value of attribute percentage.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def percentage
  @percentage
end

#pheightObject

Returns the value of attribute pheight.



47
48
49
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 47

def pheight
  @pheight
end

#pwidthObject

Returns the value of attribute pwidth.



47
48
49
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 47

def pwidth
  @pwidth
end

#px1Object

Returns the value of attribute px1.



47
48
49
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 47

def px1
  @px1
end

#py1Object

Returns the value of attribute py1.



47
48
49
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 47

def py1
  @py1
end

#startObject (readonly)

Returns the value of attribute start.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def start
  @start
end

#successorsObject (readonly)

Returns the value of attribute successors.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def successors
  @successors
end

#y1Object (readonly)

Returns the value of attribute y1.



46
47
48
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 46

def y1
  @y1
end

Instance Method Details

#draw(cr, hilight = false) ⇒ Object



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
159
160
161
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 130

def draw(cr,hilight=false)
	return self unless visible?
	#fill bar
	cr.set_source_rgba(@color.red.to_f/0x10000,@color.green.to_f/0x10000,@color.blue.to_f/0x10000,@has_child ? 0.05 : 0.7)
	cr.set_line_width(1).set_dash(100000)
	cr.rounded_rectangle(x1,y1,width,height,4)
	cr.fill
	cr.stroke
	#bar border
	if hilight
		cr.set_source_rgba(0.7,0.1,0.1,0.9)
	else
		cr.set_source_rgba(0,0,0,0.7)
	end
	cr.rounded_rectangle(x1,y1,width,height,4)
	cr.stroke
	#draw collisions
	cr.set_source_rgba(1,0,0,0.1)
	@gantt.collisions(self).each{|coo|
		cr.rectangle(to_gui(coo[0]),0,to_gui(coo[1])-to_gui(coo[0]),@gantt.widget.allocation.height)
		cr.fill
		cr.stroke
	}
	#draw percentage
	if @gantt.percentage_column
		cr.set_source_rgba((1-@color.red.to_f)/0x10000,(1-@color.green.to_f)/0x10000,(1-@color.blue.to_f)/0x10000,if @has_child then 0.05 else 0.3 end)
		cr.rounded_rectangle(x1,y1+1,@percentage*width/100,height-2,3)
		cr.fill
		cr.stroke
	end
	self
end

#draw_arrow(cr) ⇒ Object



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
193
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 163

def draw_arrow(cr)
	#successors arrow
	@successors.each_value{|pred|
		if pred && visible? && pred.visible?
			cr.set_line_width(2).set_source_rgba(0.1,0.1,0.1,0.7).set_dash(100000)
			xx1=[x+10,x2].min
			yy4=if y<pred.y then pred.y1-1 else pred.y2+1 end
			yya=if y<pred.y then -3 else 3 end
			cr.move_to(xx1,y)
			cr.curve_to(pred.x,y,pred.x,y,pred.x,yy4)
#					cr.stroke
=begin					
			cr.set_source_rgba(1,0,0,0.5)
			cr.move_to(pred.x,y)
			cr.line_to(pred.x,yy4)

			cr.stroke

			cr.set_source_rgba(1,1,0,0.5)
			cr.move_to(xx1,y)
			cr.line_to(pred.x,y)
			cr.stroke
=end
			#arrow
			cr.move_to(pred.x,yy4).rel_line_to(-3,yya)
			cr.move_to(pred.x,yy4).rel_line_to(3,yya)
			cr.stroke
		end
	}
	self
end

#draw_hilight(cr) ⇒ Object



221
222
223
224
225
226
227
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 221

def draw_hilight(cr)
	return self unless visible?
	cr.set_source_rgba(0.5,0.5,0.5,0.3).set_dash(100000).set_line_cap(Cairo::LineCap::BUTT)
	cr.set_line_width(height).move_to(0,y).line_to(x2,y).stroke
	cr.set_line_width(width).move_to(x,0).line_to(x,y2).stroke
	cr.set_line_cap(Cairo::LineCap::ROUND)
end

#draw_verticals(cr) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 210

def draw_verticals(cr)
	return self unless visible?
	#verticals
	cr.set_source_rgba(48.0/255,88.0/255,116.0/255,0.4).set_line_width(0.7).set_dash(5)
	cr.move_to(x1,0)
	cr.rel_line_to(0,y1)
	cr.move_to(x2,0)
	cr.rel_line_to(0,y1)
	cr.stroke
	self
end

#ffinishObject

finish formatted



125
126
127
128
129
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 125

def ffinish #finish formatted
	if @gantt.list.column_by_id(@gantt.list.list_model.column_of_gantt_start['id'])
		Time.at(finish || 0).strftime(@gantt.list.column_by_id(@gantt.list.list_model.column_of_gantt_start['id']).timestamp_format)
	end
end

#finishObject



49
50
51
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 49

def finish
	@start+@dur
end

#fstartObject

start formatted



120
121
122
123
124
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 120

def fstart #start formatted
	if @gantt.list.column_by_id(@gantt.list.list_model.column_of_gantt_start['id'])
		Time.at(start || 0).strftime(@gantt.list.column_by_id(@gantt.list.list_model.column_of_gantt_start['id']).timestamp_format)
	end
end

#has_child?Boolean

Returns:

  • (Boolean)


309
310
311
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 309

def has_child?
	@has_child
end

#in_area?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 96

def in_area?(x,y)
	x1<=x && x<=x2 && y1<y && y<y2
end

#init_successorsObject



265
266
267
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 265

def init_successors
	@successors.each_key{|k| @successors[k]=@gantt.rectangles[k]}
end

#iter_coordinatesObject



67
68
69
70
71
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 67

def iter_coordinates
	r=@gantt.list.get_background_area(@gantt.list.model.convert_child_path_to_path(@gantt.list.model.model.convert_child_path_to_path(iter.path)),nil)
	@y1=r.y+@gantt.vadjustment.value+r.height/3
	@height=r.height*2/3
end

#move_finishedObject



245
246
247
248
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 245

def move_finished
	set_start(@start,true)
	push_successors(true)
end

#move_to(new_x, store = false) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 233

def move_to(new_x,store=false)
	return unless @gantt.start_editable
	new_start=@gantt.res*(@gantt_min_x+new_x)
	@store_start=true if @start!=new_start
	@start=new_start
	min=@gantt.min_for_rectangle(self)
	new_start=min if new_start<min
	@start=new_start
	@gantt.clear
	push_successors(store)
	set_start(@start,store)
end

#partial_durationObject



87
88
89
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 87

def partial_duration
	@dur*@partial.to_f/100.0
end

#partial_finishObject



90
91
92
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 90

def partial_finish
	@start+@dur*@partial.to_f/100.0
end

#partial_widthObject



81
82
83
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 81

def partial_width
	width*@partial.to_f/100.0
end

#partial_x2Object



84
85
86
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 84

def partial_x2
	x1+partial_width
end


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 194

def print_percentage(cr)
	if visible? && @gantt.percentage_column && width >22 && width*Pango::SCALE < 1073741824
		pl=cr.create_pango_layout
		font="Sans 7"
		pl.set_font_description(Pango::FontDescription.new(font))
		pl.set_width(width*Pango::SCALE) 
		pl.set_wrap(Pango::Layout::WRAP_WORD_CHAR).set_ellipsize(Pango::Layout::ELLIPSIZE_NONE).set_alignment(Pango::Layout::ALIGN_CENTER)
		cr.set_source_rgba(0,0,1,1)
			
		pl.set_text("#{@percentage}%")
		cr.move_to(x1,y1+2)
		cr.show_pango_layout(pl)
			
		cr.stroke
	end
end

#push_successors(store = false) ⇒ Object



295
296
297
298
299
300
301
302
303
304
305
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 295

def push_successors(store=false)
	successors.each_value{|pred|
		next if pred.nil?
		if store then 
			pred.move_to(pred.x1,store)
		else 
			pred.move_to(partial_x2,store)  if pred.start < @start+partial_duration
		end
		pred.push_successors(store)
	}
end

#pxObject



108
109
110
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 108

def px
	px1+pwidth/2 if px1 && pwidth
end

#px2Object



114
115
116
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 114

def px2
	px1+pwidth if px1 && pwidth
end

#pyObject



111
112
113
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 111

def py
	py1+pheight/2 if py1 && pheight
end

#py2Object



117
118
119
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 117

def py2
	py1+pheight if py1 && pheight
end

#recursion?(starter = nil) ⇒ Boolean

Returns:

  • (Boolean)


250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 250

def recursion?(starter=nil)
	ret=false
	successors.each_value{|pred|
		next if pred.nil?
		#avoid recursion
		if starter == pred
			ret=true
			ewarn("recursion")
			return ret
		end
		ret=pred.recursion?(if starter.nil? then self else starter end)
	}
	ret
end

#set_duration(ndur, store = false) ⇒ Object



53
54
55
56
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 53

def set_duration(ndur,store=false)
	@dur=ndur
	@gantt.list.list_model.change_value_of_id(iter_id,@gantt.list.gtk_attribute('gantt_duration'),@dur) if store
end

#set_gantt_min_x(gmin_x) ⇒ Object



229
230
231
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 229

def set_gantt_min_x(gmin_x)
	@gantt_min_x=gmin_x
end

#set_height(new_height) ⇒ Object



63
64
65
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 63

def set_height(new_height)
	@height=new_height
end

#set_percentage(npercentage, store = false) ⇒ Object



58
59
60
61
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 58

def set_percentage(npercentage,store=false)
	@percentage=npercentage
	@gantt.list.list_model.change_value_of_id(iter_id,@gantt.list.gtk_attribute('gantt_percentage'),@percentage) if store && @gantt.percentage_column
end

#set_start(new_start, store = false) ⇒ Object



288
289
290
291
292
293
294
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 288

def set_start(new_start,store=false)
	#save start
	@start=new_start
	if store
		@gantt.list.list_model.change_value_of_id(iter_id,@gantt.list.gtk_attribute('gantt_start'),@start)
	end
end

#to_gui(x) ⇒ Object



75
76
77
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 75

def to_gui(x)
	x.to_f/@gantt.res-@gantt_min_x
end

#to_sObject



312
313
314
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 312

def to_s
	"Rectangle(id:#{iter_id})"
end

#toggle_successor(pr) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 269

def toggle_successor(pr)
	return false if pr.nil?
	if ret=((@successors.has_key?(pr.iter_id)) || (pr==self))
		#this successor exists, removing
		@successors.delete(pr.iter_id)
	else
		#adding new successor
		@successors[pr.iter_id]=pr
		@successors.delete(pr.iter_id) if recursion?
	end

	#pr is successors rectangle, saving here
	pids=""
	@successors.each_key{|k| pids="#{pids}#{k},"}
	@gantt.list.list_model.change_value_of_id(iter_id,@gantt.list.gtk_attribute('gantt_successors'),pids.chomp(","))
	push_successors(true)
	ret
end

#visible?Boolean

Returns:

  • (Boolean)


306
307
308
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 306

def visible?
	@visible && (@parent_r.nil? || y1!=@parent_r.y1)
end

#widthObject



99
100
101
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 99

def width
	@dur/@gantt.res
end

#xObject



102
103
104
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 102

def x
	x1+width/2
end

#x1Object



72
73
74
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 72

def x1
	@start/@gantt.res-@gantt_min_x
end

#x2Object



78
79
80
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 78

def x2
	x1+width
end

#yObject



105
106
107
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 105

def y
	y1+height/2
end

#y2Object



93
94
95
# File 'lib/ListHolder/GanttHolder/Gantt/Rectangle.rb', line 93

def y2
	@y1+@height
end