comparison orpg/mapper/whiteboard.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children 78407d627cba
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 # Copyright (C) 2000-2001 The OpenRPG Project
2 #
3 # openrpg-dev@lists.sourceforge.net
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 # --
19 #
20 # File: mapper/whiteboard.py
21 # Author: Chris Davis
22 # Maintainer:
23 # Version:
24 # $Id: whiteboard.py,v 1.47 2007/03/09 14:11:55 digitalxero Exp $
25 #
26 # Description: This file contains some of the basic definitions for the chat
27 # utilities in the orpg project.
28 #
29 __version__ = "$Id: whiteboard.py,v 1.47 2007/03/09 14:11:55 digitalxero Exp $"
30
31 from base import *
32 from orpg.mapper.map_utils import *
33
34 def cmp_zorder(first,second):
35 f = first.zorder
36 s = second.zorder
37 if f == None:
38 f = 0
39 if s == None:
40 s = 0
41 if f == s:
42 value = 0
43 elif f < s:
44 value = -1
45 else:
46 value = 1
47 return value
48
49 class WhiteboardText:
50 def __init__(self, id, text_string, pos, style, pointsize, weight, color="#000000", log=None):
51 self.log = log
52 self.log.log("Enter WhiteboardText", ORPG_DEBUG)
53 self.scale = 1
54 self.r_h = RGBHex()
55 self.selected = False
56 self.text_string = text_string
57 self.id = id
58 self.weight = int(weight)
59 self.pointsize = int(pointsize)
60 self.style = int(style)
61 self.textcolor = color
62 self.posx = pos.x
63 self.posy = pos.y
64 self.font = wx.Font(self.pointsize, wx.DEFAULT, self.style, self.weight)
65 self.highlighted = False
66 r,g,b = self.r_h.rgb_tuple(self.textcolor)
67 self.highlight_color = self.r_h.hexstring(r^255, g^255, b^255)
68 self.isUpdated = False
69 self.log.log("Exit WhiteboardText", ORPG_DEBUG)
70
71 def highlight(self, highlight=True):
72 self.log.log("Enter WhiteboardText->highlight(self, highlight)", ORPG_DEBUG)
73 self.highlighted = highlight
74 self.log.log("Exit WhiteboardText->highlight(self, highlight)", ORPG_DEBUG)
75
76 def set_text_props(self, text_string, style, point, weight, color="#000000"):
77 self.log.log("Enter WhiteboardText->set_text_props(self, text_string, style, point, weight, color)", ORPG_DEBUG)
78 self.text_string = text_string
79 self.textcolor = color
80 self.style = int(style)
81 self.font.SetStyle(self.style)
82 self.pointsize = int(point)
83 self.font.SetPointSize(self.pointsize)
84 self.weight = int(weight)
85 self.font.SetWeight(self.weight)
86 self.isUpdated = True
87 self.log.log("Exit WhiteboardText->set_text_props(self, text_string, style, point, weight, color)", ORPG_DEBUG)
88
89 def hit_test(self, pt, dc):
90 self.log.log("Enter WhiteboardText->hit_test(self, pt, dc)", ORPG_DEBUG)
91 rect = self.get_rect(dc)
92 result = rect.InsideXY(pt.x, pt.y)
93 self.log.log("Exit WhiteboardText->hit_test(self, pt, dc)", ORPG_DEBUG)
94 return result
95
96 def get_rect(self, dc):
97 self.log.log("Enter WhiteboardText->get_rect(self, dc)", ORPG_DEBUG)
98 dc.SetFont(self.font)
99 (w,x,y,z) = dc.GetFullTextExtent(self.text_string)
100 self.log.log("Exit WhiteboardText->get_rect(self, dc)", ORPG_DEBUG)
101 return wx.Rect(self.posx,self.posy,w,(x+y+z))
102
103 def draw(self, parent, dc, op=wx.COPY):
104 self.log.log("Enter WhiteboardText->draw(self, parent, dc, op)", ORPG_DEBUG)
105 self.scale = parent.canvas.layers['grid'].mapscale
106 if self.highlighted:
107 textcolor = self.highlight_color
108 else:
109 textcolor = self.textcolor
110 try:
111 dc.SetTextForeground(textcolor)
112 except Exception,e:
113 dc.SetTextForeground('#000000')
114 dc.SetUserScale(self.scale, self.scale)
115
116 # Draw text
117 (w,x,y,z) = self.get_rect(dc)
118 dc.SetFont(self.font)
119 dc.DrawText(self.text_string, self.posx, self.posy)
120 dc.SetTextForeground(wx.Colour(0,0,0))
121 self.log.log("Exit WhiteboardText->draw(self, parent, dc, op)", ORPG_DEBUG)
122
123 def toxml(self, action="update"):
124 self.log.log("Enter WhiteboardText->toxml(self, " + action + ")", ORPG_DEBUG)
125 if action == "del":
126 xml_str = "<text action='del' id='" + str(self.id) + "'/>"
127 self.log.log(xml_str, ORPG_DEBUG)
128 self.log.log("Exit WhiteboardText->toxml(self, " + action + ")", ORPG_DEBUG)
129 return xml_str
130 xml_str = "<text"
131 xml_str += " action='" + action + "'"
132 xml_str += " id='" + str(self.id) + "'"
133 if self.pointsize != None:
134 xml_str += " pointsize='" + str(self.pointsize) + "'"
135 if self.style != None:
136 xml_str += " style='" + str(self.style) + "'"
137 if self.weight != None:
138 xml_str += " weight='" + str(self.weight) + "'"
139 if self.posx != None:
140 xml_str+= " posx='" + str(self.posx) + "'"
141 if not (self.posy is None):
142 xml_str += " posy='" + str(self.posy) + "'"
143 if self.text_string != None:
144 xml_str+= " text_string='" + self.text_string + "'"
145 if self.textcolor != None:
146 xml_str += " color='" + self.textcolor + "'"
147 xml_str += "/>"
148 self.log.log(xml_str, ORPG_DEBUG)
149 self.log.log("Exit WhiteboardText->toxml(self, " + action + ")", ORPG_DEBUG)
150 if (action == "update" and self.isUpdated) or action == "new":
151 self.isUpdated = False
152 return xml_str
153 else:
154 return ''
155
156 def takedom(self, xml_dom):
157 self.log.log("Enter WhiteboardText->takedom(self, xml_dom)", ORPG_DEBUG)
158 self.text_string = xml_dom.getAttribute("text_string")
159 self.log.log("self.text_string=" + self.text_string, ORPG_DEBUG)
160 self.id = xml_dom.getAttribute("id")
161 self.log.log("self.id=" + str(self.id), ORPG_DEBUG)
162 if xml_dom.hasAttribute("posy"):
163 self.posy = int(xml_dom.getAttribute("posy"))
164 self.log.log("self.posy=" + str(self.posy), ORPG_DEBUG)
165 if xml_dom.hasAttribute("posx"):
166 self.posx = int(xml_dom.getAttribute("posx"))
167 self.log.log("self.posx=" + str(self.posx), ORPG_DEBUG)
168 if xml_dom.hasAttribute("weight"):
169 self.weight = int(xml_dom.getAttribute("weight"))
170 self.font.SetWeight(self.weight)
171 self.log.log("self.weight=" + str(self.weight), ORPG_DEBUG)
172 if xml_dom.hasAttribute("style"):
173 self.style = int(xml_dom.getAttribute("style"))
174 self.font.SetStyle(self.style)
175 self.log.log("self.style=" + str(self.style), ORPG_DEBUG)
176 if xml_dom.hasAttribute("pointsize"):
177 self.pointsize = int(xml_dom.getAttribute("pointsize"))
178 self.font.SetPointSize(self.pointsize)
179 self.log.log("self.pointsize=" + str(self.pointsize), ORPG_DEBUG)
180 if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '':
181 self.textcolor = xml_dom.getAttribute("color")
182 if self.textcolor == '#0000000':
183 self.textcolor = '#000000'
184 self.log.log("self.textcolor=" + self.textcolor, ORPG_DEBUG)
185 self.log.log("Exit WhiteboardText->takedom(self, xml_dom)", ORPG_DEBUG)
186
187 class WhiteboardLine:
188 def __init__(self, id, line_string, upperleft, lowerright, color="#000000", width=1, log=None):
189 self.log = log
190 self.log.log("Enter WhiteboardLine", ORPG_DEBUG)
191 self.scale = 1
192 self.r_h = RGBHex()
193 if color == '':
194 color = "#000000"
195 self.linecolor = color
196 self.linewidth = width
197 self.lowerright = lowerright
198 self.upperleft = upperleft
199 self.selected = False
200 self.line_string = line_string
201 self.id = id
202 self.highlighted = False
203 r,g,b = self.r_h.rgb_tuple(self.linecolor)
204 self.highlight_color = self.r_h.hexstring(r^255, g^255, b^255)
205 self.log.log("Exit WhiteboardLine", ORPG_DEBUG)
206
207 def highlight(self, highlight=True):
208 self.log.log("Enter WhiteboardLine->highlight(self, highlight)", ORPG_DEBUG)
209 self.highlighted = highlight
210 self.log.log("Enter WhiteboardLine->highlight(self, highlight)", ORPG_DEBUG)
211
212 def set_line_props(self, line_string="", upperleftx=0, upperlefty=0, lowerrightx=0, lowerrighty=0, color="#000000", width=1):
213 self.log.log("Enter WhiteboardLine->set_line_props(self, line_string, upperleftx, upperlefty, lowerrightx, lowerrighty, color, width)", ORPG_DEBUG)
214 self.line_string = line_string
215 self.upperleft.x = upperleftx
216 self.upperleft.y = upperlefty
217 self.lowerright.x = lowerrightx
218 self.lowerright.y = lowerrighty
219 self.linecolor = color
220 self.linewidth = width
221 self.log.log("Exit WhiteboardLine->set_line_props(self, line_string, upperleftx, upperlefty, lowerrightx, lowerrighty, color, width)", ORPG_DEBUG)
222
223 def hit_test(self, pt):
224 self.log.log("Enter WhiteboardLine->hit_test(self, pt)", ORPG_DEBUG)
225 coords = self.line_string.split(";")
226 stcords = coords[0].split(",")
227 oldicords = (int(stcords[0]),int(stcords[1]))
228 for coordinate_string_counter in range(1, len(coords)):
229 stcords = coords[coordinate_string_counter].split(",")
230 if stcords[0] == "":
231 self.log.log("Exit WhiteboardLine->hit_test(self, pt) return False", ORPG_DEBUG)
232 return False
233 icords = (int(stcords[0]),int(stcords[1]))
234 if orpg.mapper.map_utils.proximity_test(oldicords,icords,pt,12):
235 self.log.log("Exit WhiteboardLine->hit_test(self, pt) return True", ORPG_DEBUG)
236 return True
237 oldicords = icords
238 self.log.log("Exit WhiteboardLine->hit_test(self, pt) return False", ORPG_DEBUG)
239 return False
240
241 def draw(self, parent, dc, op=wx.COPY):
242 self.log.log("Enter WhiteboardLine->draw(self, parent, dc, op=wx.COPY)", ORPG_DEBUG)
243 self.scale = parent.canvas.layers['grid'].mapscale
244 if self.highlighted:
245 linecolor = self.highlight_color
246 else:
247 linecolor = self.linecolor
248 pen = wx.BLACK_PEN
249 try:
250 pen.SetColour(linecolor)
251 except Exception,e:
252 pen.SetColour('#000000')
253 pen.SetWidth( self.linewidth )
254 dc.SetPen( pen )
255 dc.SetBrush(wx.BLACK_BRUSH)
256 # draw lines
257 dc.SetUserScale(self.scale,self.scale)
258 pointArray = self.line_string.split(";")
259 x2 = y2 = -999
260 for m in range(len(pointArray)-1):
261 x = pointArray[m]
262 points = x.split(",")
263 x1 = int(points[0])
264 y1 = int(points[1])
265 if x2 != -999:
266 dc.DrawLine(x2,y2,x1,y1)
267 x2 = x1
268 y2 = y1
269 pen.SetColour(wx.Colour(0,0,0))
270 dc.SetPen(pen)
271 dc.SetPen(wx.NullPen)
272 dc.SetBrush(wx.NullBrush)
273 #selected outline
274 self.log.log("Exit WhiteboardLine->draw(self, parent, dc, op=wx.COPY)", ORPG_DEBUG)
275
276 def toxml(self, action="update"):
277 self.log.log("Enter WhiteboardLine->toxml(self, " + action + ")", ORPG_DEBUG)
278 if action == "del":
279 xml_str = "<line action='del' id='" + str(self.id) + "'/>"
280 self.log.log(xml_str, ORPG_DEBUG)
281 self.log.log("Exit WhiteboardLine->toxml(self, " + action + ")", ORPG_DEBUG)
282 return xml_str
283 # if there are any changes, make sure id is one of them
284 xml_str = "<line"
285 xml_str += " action='" + action + "'"
286 xml_str += " id='" + str(self.id) + "'"
287 xml_str+= " line_string='" + self.line_string + "'"
288 if self.upperleft != None:
289 xml_str += " upperleftx='" + str(self.upperleft.x) + "'"
290 xml_str += " upperlefty='" + str(self.upperleft.y) + "'"
291 if self.lowerright != None:
292 xml_str+= " lowerrightx='" + str(self.lowerright.x) + "'"
293 xml_str+= " lowerrighty='" + str(self.lowerright.y) + "'"
294 if self.linecolor != None:
295 xml_str += " color='" + str(self.linecolor) + "'"
296 if self.linewidth != None:
297 xml_str += " width='" + str(self.linewidth) + "'"
298 xml_str += "/>"
299 self.log.log(xml_str, ORPG_DEBUG)
300 self.log.log("Exit WhiteboardLine->toxml(self, " + action + ")", ORPG_DEBUG)
301 if action == "new":
302 return xml_str
303 return ''
304
305 def takedom(self, xml_dom):
306 self.log.log("Enter WhiteboardLine->takedom(self, xml_dom)", ORPG_DEBUG)
307 self.line_string = xml_dom.getAttribute("line_string")
308 self.log.log("self.line_string=" + self.line_string, ORPG_DEBUG)
309 self.id = xml_dom.getAttribute("id")
310 self.log.log("self.id=" + str(self.id), ORPG_DEBUG)
311 if xml_dom.hasAttribute("upperleftx"):
312 self.upperleft.x = int(xml_dom.getAttribute("upperleftx"))
313 self.log.log("self.upperleft.x=" + str(self.upperleft.x), ORPG_DEBUG)
314 if xml_dom.hasAttribute("upperlefty"):
315 self.upperleft.y = int(xml_dom.getAttribute("upperlefty"))
316 self.log.log("self.upperleft.y=" + str(self.upperleft.y), ORPG_DEBUG)
317 if xml_dom.hasAttribute("lowerrightx"):
318 self.lowerright.x = int(xml_dom.getAttribute("lowerrightx"))
319 self.log.log("self.lowerright.x=" + str(self.lowerright.x), ORPG_DEBUG)
320 if xml_dom.hasAttribute("lowerrighty"):
321 self.lowerright.y = int(xml_dom.getAttribute("lowerrighty"))
322 self.log.log("self.lowerright.y=" + str(self.lowerright.y), ORPG_DEBUG)
323 if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '':
324 self.linecolor = xml_dom.getAttribute("color")
325 if self.linecolor == '#0000000':
326 self.linecolor = '#000000'
327 self.log.log("self.linecolor=" + self.linecolor, ORPG_DEBUG)
328 if xml_dom.hasAttribute("width"):
329 self.linewidth = int(xml_dom.getAttribute("width"))
330 self.log.log("self.linewidth=" + str(self.linewidth), ORPG_DEBUG)
331 self.log.log("Exit WhiteboardLine->takedom(self, xml_dom)", ORPG_DEBUG)
332
333 ##-----------------------------
334 ## whiteboard layer
335 ##-----------------------------
336 class whiteboard_layer(layer_base):
337
338 def __init__(self, canvas):
339 self.canvas = canvas
340 self.log = self.canvas.log
341 self.log.log("Enter whiteboard_layer", ORPG_DEBUG)
342 layer_base.__init__(self)
343 self.r_h = RGBHex()
344 self.id = -1
345 self.lines = []
346 self.texts = []
347 self.serial_number = 0
348 self.color = "#000000"
349 self.width = 1
350 self.removedLines = []
351 self.log.log("Exit whiteboard_layer", ORPG_DEBUG)
352
353 def next_serial(self):
354 self.log.log("Enter whiteboard_layer->next_serial(self)", ORPG_DEBUG)
355 self.serial_number += 1
356 self.log.log("Exit whiteboard_layer->next_serial(self)", ORPG_DEBUG)
357 return self.serial_number
358
359 def get_next_highest_z(self):
360 self.log.log("Enter whiteboard_layer->get_next_highest_z(self)", ORPG_DEBUG)
361 z = len(self.lines)+1
362 self.log.log("Exit whiteboard_layer->get_next_highest_z(self)", ORPG_DEBUG)
363 return z
364
365 def cleanly_collapse_zorder(self):
366 self.log.log("Enter/Exit whiteboard_layer->cleanly_collapse_zorder(self)", ORPG_DEBUG)
367
368 def collapse_zorder(self):
369 self.log.log("Enter/Exit whiteboard_layer->collapse_zorder(self)", ORPG_DEBUG)
370
371 def rollback_serial(self):
372 self.log.log("Enter whiteboard_layer->rollback_serial(self)", ORPG_DEBUG)
373 self.serial_number -= 1
374 self.log.log("Exit whiteboard_layer->rollback_serial(self)", ORPG_DEBUG)
375
376 def add_line(self, line_string="", upperleft=cmpPoint(0,0), lowerright=cmpPoint(0,0), color="#000000", width=1):
377 self.log.log("Enter whiteboard_layer->add_line(self, line_string, upperleft, lowerright, color, width)", ORPG_DEBUG)
378 id = 'line-' + str(self.next_serial())
379 line = WhiteboardLine(id, line_string, upperleft, lowerright, color=self.color, width=self.width, log=self.log)
380 self.lines.append(line)
381 xml_str = "<map><whiteboard>"
382 xml_str += line.toxml("new")
383 xml_str += "</whiteboard></map>"
384 self.canvas.frame.session.send(xml_str)
385 self.canvas.Refresh(True)
386 self.log.log("Exit whiteboard_layer->add_line(self, line_string, upperleft, lowerright, color, width)", ORPG_DEBUG)
387 return line
388
389 def get_line_by_id(self, id):
390 self.log.log("Enter whiteboard_layer->get_line_by_id(self, id)", ORPG_DEBUG)
391 for line in self.lines:
392 if str(line.id) == str(id):
393 self.log.log("Exit whiteboard_layer->get_line_by_id(self, id) return LineID: " + str(id), ORPG_DEBUG)
394 return line
395 self.log.log("Exit whiteboard_layer->get_line_by_id(self, id) return None", ORPG_DEBUG)
396 return None
397
398 def get_text_by_id(self, id):
399 self.log.log("Enter whiteboard_layer->get_text_by_id(self, id)", ORPG_DEBUG)
400 for text in self.texts:
401 if str(text.id) == str(id):
402 self.log.log("Exit whiteboard_layer->get_text_by_id(self, id) return textID: " + str(id), ORPG_DEBUG)
403 return text
404 self.log.log("Enter whiteboard_layer->get_text_by_id(self, id) return None", ORPG_DEBUG)
405 return None
406
407 def del_line(self, line):
408 self.log.log("Enter whiteboard_layer->del_line(self, line)", ORPG_DEBUG)
409 xml_str = "<map><whiteboard>"
410 xml_str += line.toxml("del")
411 xml_str += "</whiteboard></map>"
412 self.canvas.frame.session.send(xml_str)
413 if line:
414 self.lines.remove(line)
415 self.removedLines.append(line)
416 self.canvas.Refresh(True)
417 self.log.log("Exit whiteboard_layer->del_line(self, line)", ORPG_DEBUG)
418
419 def undo_line(self):
420 if len(self.removedLines)>0:
421 line = self.removedLines[len(self.removedLines)-1]
422 self.removedLines.remove(line)
423 self.add_line(line.line_string, line.upperleft, line.lowerright, line.linecolor, line.linewidth)
424 self.canvas.Refresh(True)
425
426 def del_all_lines(self):
427 self.log.log("Enter whiteboard_layer->del_all_lines(self)", ORPG_DEBUG)
428 for i in xrange(len(self.lines)):
429 self.del_line(self.lines[0])
430 print self.lines
431 self.log.log("Exit whiteboard_layer->del_all_lines(self)", ORPG_DEBUG)
432
433 def del_text(self, text):
434 self.log.log("Enter whiteboard_layer->del_text(self, text)", ORPG_DEBUG)
435 xml_str = "<map><whiteboard>"
436 xml_str += text.toxml("del")
437 xml_str += "</whiteboard></map>"
438 self.canvas.frame.session.send(xml_str)
439 if text:
440 self.texts.remove(text)
441 self.canvas.Refresh(True)
442 self.log.log("Exit whiteboard_layer->del_text(self, text)", ORPG_DEBUG)
443
444 def layerDraw(self, dc):
445 self.log.log("Enter whiteboard_layer->layerDraw(self, dc)", ORPG_DEBUG)
446 for m in self.lines:
447 m.draw(self, dc)
448 for m in self.texts:
449 m.draw(self,dc)
450 self.log.log("Exit whiteboard_layer->layerDraw(self, dc)", ORPG_DEBUG)
451
452 def hit_test_text(self, pos, dc):
453 self.log.log("Enter whiteboard_layer->hit_test_text(self, pos, dc)", ORPG_DEBUG)
454 list_of_texts_matching = []
455 if self.canvas.layers['fog'].use_fog == 1:
456 if self.canvas.frame.session.role != "GM":
457 self.log.log("Exit whiteboard_layer->hit_test_text(self, pos, dc)", ORPG_DEBUG)
458 return list_of_texts_matching
459 for m in self.texts:
460 if m.hit_test(pos,dc):
461 list_of_texts_matching.append(m)
462 self.log.log("Exit whiteboard_layer->hit_test_text(self, pos, dc)", ORPG_DEBUG)
463 return list_of_texts_matching
464
465 def hit_test_lines(self, pos, dc):
466 self.log.log("Enter whiteboard_layer->hit_test_lines(self, pos, dc)", ORPG_DEBUG)
467 list_of_lines_matching = []
468 if self.canvas.layers['fog'].use_fog == 1:
469 if self.canvas.frame.session.role != "GM":
470 self.log.log("Exit whiteboard_layer->hit_test_lines(self, pos, dc)", ORPG_DEBUG)
471 return list_of_lines_matching
472 for m in self.lines:
473 if m.hit_test(pos):
474 list_of_lines_matching.append(m)
475 self.log.log("Exit whiteboard_layer->hit_test_lines(self, pos, dc)", ORPG_DEBUG)
476 return list_of_lines_matching
477
478 def find_line(self, pt):
479 self.log.log("Enter whiteboard_layer->find_line(self, pt)", ORPG_DEBUG)
480 scale = self.canvas.layers['grid'].mapscale
481 dc = wx.ClientDC( self.canvas )
482 self.canvas.PrepareDC( dc )
483 dc.SetUserScale(scale,scale)
484 line_list = self.hit_test_lines(pt,dc)
485 if line_list:
486 self.log.log("Exit whiteboard_layer->find_line(self, pt)", ORPG_DEBUG)
487 return line_list[0]
488 else:
489 self.log.log("Exit whiteboard_layer->find_line(self, pt) return None", ORPG_DEBUG)
490 return None
491
492 def setcolor(self, color):
493 self.log.log("Enter whiteboard_layer->setcolor(self, color)", ORPG_DEBUG)
494 r,g,b = color.Get()
495 self.color = self.r_h.hexstring(r,g,b)
496 self.log.log("Exit whiteboard_layer->setcolor(self, color)", ORPG_DEBUG)
497
498 def sethexcolor(self, hexcolor):
499 self.log.log("Enter whiteboard_layer->sethexcolor(self, hexcolor)", ORPG_DEBUG)
500 self.color = hexcolor
501 self.log.log("Exit whiteboard_layer->sethexcolor(self, hexcolor)", ORPG_DEBUG)
502
503 def setwidth(self, width):
504 self.log.log("Enter whiteboard_layer->setwidth(self, width)", ORPG_DEBUG)
505 self.width = int(width)
506 self.log.log("Exit whiteboard_layer->setwidth(self, width)", ORPG_DEBUG)
507
508 def set_font(self, font):
509 self.log.log("Enter whiteboard_layer->set_font(self, font)", ORPG_DEBUG)
510 self.font = font
511 self.log.log("Exit whiteboard_layer->set_font(self, font)", ORPG_DEBUG)
512
513 def add_text(self, text_string, pos, style, pointsize, weight, color="#000000"):
514 self.log.log("Enter whiteboard_layer->add_text(self, text_string, pos, style, pointsize, weight, color)", ORPG_DEBUG)
515 id = 'text-' + str(self.next_serial())
516 text = WhiteboardText(id,text_string, pos, style, pointsize, weight, color, self.log)
517 self.texts.append(text)
518 xml_str = "<map><whiteboard>"
519 xml_str += text.toxml("new")
520 xml_str += "</whiteboard></map>"
521 self.canvas.frame.session.send(xml_str)
522 self.canvas.Refresh(True)
523 self.log.log("Exit whiteboard_layer->add_text(self, text_string, pos, style, pointsize, weight, color)", ORPG_DEBUG)
524
525 def draw_working_line(self, dc, line_string):
526 self.log.log("Enter whiteboard_layer->draw_working_line(self, dc, line_string)", ORPG_DEBUG)
527 scale = self.canvas.layers['grid'].mapscale
528 dc.SetPen(wx.BLACK_PEN)
529 dc.SetBrush(wx.BLACK_BRUSH)
530 pen = wx.BLACK_PEN
531 pen.SetColour(self.color)
532 pen.SetWidth(self.width)
533 dc.SetPen(pen)
534 dc.SetUserScale(scale,scale)
535 pointArray = line_string.split(";")
536 x2 = y2 = -999
537 for m in range(len(pointArray)-1):
538 x = pointArray[m]
539 points = x.split(",")
540 x1 = int(points[0])
541 y1 = int(points[1])
542 if x2 != -999:
543 dc.DrawLine(x2,y2,x1,y1)
544 x2 = x1
545 y2 = y1
546 dc.SetPen(wx.NullPen)
547 dc.SetBrush(wx.NullBrush)
548 self.log.log("Exit whiteboard_layer->draw_working_line(self, dc, line_string)", ORPG_DEBUG)
549
550 def layerToXML(self, action="update"):
551 """ format """
552 self.log.log("Enter whiteboard_layer->layerToXML(self, " + action + ")", ORPG_DEBUG)
553 white_string = ""
554 if self.lines:
555 for l in self.lines:
556 white_string += l.toxml(action)
557 if self.texts:
558 for l in self.texts:
559 white_string += l.toxml(action)
560 if len(white_string):
561 s = "<whiteboard"
562 s += " serial='" + str(self.serial_number) + "'"
563 s += ">"
564 s += white_string
565 s += "</whiteboard>"
566 self.log.log(s, ORPG_DEBUG)
567 self.log.log("Exit whiteboard_layer->layerToXML(self, " + action + ")", ORPG_DEBUG)
568 return s
569 else:
570 self.log.log("Exit whiteboard_layer->layerToXML(self, " + action + ")", ORPG_DEBUG)
571 return ""
572
573 def layerTakeDOM(self, xml_dom):
574 self.log.log("Enter whiteboard_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG)
575 serial_number = xml_dom.getAttribute('serial')
576 if serial_number != "":
577 self.serial_number = int(serial_number)
578 children = xml_dom._get_childNodes()
579 for l in children:
580 nodename = l._get_nodeName()
581 action = l.getAttribute("action")
582 id = l.getAttribute('id')
583 if action == "del":
584 if nodename == 'line':
585 line = self.get_line_by_id(id)
586 if line != None:
587 self.lines.remove(line)
588 else:
589 self.log.log("Whiteboard error: Deletion of unknown line object attempted.", ORPG_GENERAL)
590 elif nodename == 'text':
591 text = self.get_text_by_id(id)
592 if text != None:
593 self.texts.remove(text)
594 else:
595 self.log.log("Whiteboard error: Deletion of unknown text object attempted.", ORPG_GENERAL)
596 else:
597 self.log.log("Whiteboard error: Deletion of unknown whiteboard object attempted.", ORPG_GENERAL)
598 elif action == "new":
599 if nodename == "line":
600 try:
601 line_string = l.getAttribute('line_string')
602 upperleftx = l.getAttribute('upperleftx')
603 upperlefty = l.getAttribute('upperlefty')
604 lowerrightx = l.getAttribute('lowerrightx')
605 lowerrighty = l.getAttribute('lowerrighty')
606 upperleft = wx.Point(int(upperleftx),int(upperlefty))
607 lowerright = wx.Point(int(lowerrightx),int(lowerrighty))
608 color = l.getAttribute('color')
609 if color == '#0000000':
610 color = '#000000'
611 id = l.getAttribute('id')
612 width = int(l.getAttribute('width'))
613 except:
614 line_string = upperleftx = upperlefty = lowerrightx = lowerrighty = color = 0
615 self.log.log(traceback.format_exc(), ORPG_GENERAL)
616 self.log.log("invalid line", ORPG_GENERAL)
617 continue
618 line = WhiteboardLine(id, line_string, upperleft, lowerright, color, width, self.log)
619 self.lines.append(line)
620 elif nodename == "text":
621 try:
622 text_string = l.getAttribute('text_string')
623 style = l.getAttribute('style')
624 pointsize = l.getAttribute('pointsize')
625 weight = l.getAttribute('weight')
626 color = l.getAttribute('color')
627 if color == '#0000000':
628 color = '#000000'
629 id = l.getAttribute('id')
630 posx = l.getAttribute('posx')
631 posy = l.getAttribute('posy')
632 pos = wx.Point(0,0)
633 pos.x = int(posx)
634 pos.y = int(posy)
635 except:
636 self.log.log(traceback.format_exc(), ORPG_GENERAL)
637 self.log.log("invalid line", ORPG_GENERAL)
638 continue
639 text = WhiteboardText(id, text_string, pos, style, pointsize, weight, color, self.log)
640 self.texts.append(text)
641 else:
642 if nodename == "line":
643 line = self.get_line_by_id(id)
644 if line:
645 line.takedom(l)
646 else:
647 self.log.log("Whiteboard error: Update of unknown line attempted.", ORPG_GENERAL)
648 if nodename == "text":
649 text = self.get_text_by_id(id)
650 if text:
651 text.takedom(l)
652 else:
653 self.log.log("Whiteboard error: Update of unknown text attempted.", ORPG_GENERAL)
654 self.log.log("Enter whiteboard_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG)
655 #self.canvas.send_map_data()
656
657 def add_temp_line(self, line_string):
658 line = WhiteboardLine(0, line_string, wx.Point(0,0), wx.Point(0,0), color=self.color, width=self.width, log=self.log)
659 self.lines.append(line)
660 return line
661
662 def del_temp_line(self, line):
663 if line:
664 self.lines.remove(line)