comparison orpg/mapper/whiteboard.py @ 18:97265586402b ornery-orc

Traipse 'OpenRPG' {090827-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc''s main goal is to offer more advanced features and enhance the productivity of the user. Update Summary: Update Manager is now in version 0.8. While not every button works, users can now browse the different revisions and their different changesets. The code has been refined some with feature from Core added to it. A Crash report is now created if the users software crashes. Update Manager has been moved to the Traipse Suite menu item, and a Debug Console as been added as well.
author sirebral
date Thu, 27 Aug 2009 01:04:43 -0500
parents 211ac836b6a0
children ff154cf3350c
comparison
equal deleted inserted replaced
17:265b987cce4f 18:97265586402b
41 else: value = 1 41 else: value = 1
42 return value 42 return value
43 43
44 class WhiteboardText: 44 class WhiteboardText:
45 def __init__(self, id, text_string, pos, style, pointsize, weight, color="#000000", log=None): 45 def __init__(self, id, text_string, pos, style, pointsize, weight, color="#000000", log=None):
46 self.log = log
47 self.log.log("Enter WhiteboardText", ORPG_DEBUG)
48 self.scale = 1 46 self.scale = 1
49 self.r_h = RGBHex() 47 self.r_h = RGBHex()
50 self.selected = False 48 self.selected = False
51 self.text_string = text_string 49 self.text_string = text_string
52 self.id = id 50 self.id = id
59 self.font = wx.Font(self.pointsize, wx.DEFAULT, self.style, self.weight) 57 self.font = wx.Font(self.pointsize, wx.DEFAULT, self.style, self.weight)
60 self.highlighted = False 58 self.highlighted = False
61 r,g,b = self.r_h.rgb_tuple(self.textcolor) 59 r,g,b = self.r_h.rgb_tuple(self.textcolor)
62 self.highlight_color = self.r_h.hexstring(r^255, g^255, b^255) 60 self.highlight_color = self.r_h.hexstring(r^255, g^255, b^255)
63 self.isUpdated = False 61 self.isUpdated = False
64 self.log.log("Exit WhiteboardText", ORPG_DEBUG)
65 62
66 def highlight(self, highlight=True): 63 def highlight(self, highlight=True):
67 self.log.log("Enter WhiteboardText->highlight(self, highlight)", ORPG_DEBUG)
68 self.highlighted = highlight 64 self.highlighted = highlight
69 self.log.log("Exit WhiteboardText->highlight(self, highlight)", ORPG_DEBUG)
70 65
71 def set_text_props(self, text_string, style, point, weight, color="#000000"): 66 def set_text_props(self, text_string, style, point, weight, color="#000000"):
72 self.log.log("Enter WhiteboardText->set_text_props(self, text_string, style, point, weight, color)", ORPG_DEBUG)
73 self.text_string = text_string 67 self.text_string = text_string
74 self.textcolor = color 68 self.textcolor = color
75 self.style = int(style) 69 self.style = int(style)
76 self.font.SetStyle(self.style) 70 self.font.SetStyle(self.style)
77 self.pointsize = int(point) 71 self.pointsize = int(point)
78 self.font.SetPointSize(self.pointsize) 72 self.font.SetPointSize(self.pointsize)
79 self.weight = int(weight) 73 self.weight = int(weight)
80 self.font.SetWeight(self.weight) 74 self.font.SetWeight(self.weight)
81 self.isUpdated = True 75 self.isUpdated = True
82 self.log.log("Exit WhiteboardText->set_text_props(self, text_string, style, point, weight, color)", ORPG_DEBUG)
83 76
84 def hit_test(self, pt, dc): 77 def hit_test(self, pt, dc):
85 self.log.log("Enter WhiteboardText->hit_test(self, pt, dc)", ORPG_DEBUG)
86 rect = self.get_rect(dc) 78 rect = self.get_rect(dc)
87 result = rect.InsideXY(pt.x, pt.y) 79 result = rect.InsideXY(pt.x, pt.y)
88 self.log.log("Exit WhiteboardText->hit_test(self, pt, dc)", ORPG_DEBUG)
89 return result 80 return result
90 81
91 def get_rect(self, dc): 82 def get_rect(self, dc):
92 self.log.log("Enter WhiteboardText->get_rect(self, dc)", ORPG_DEBUG)
93 dc.SetFont(self.font) 83 dc.SetFont(self.font)
94 (w,x,y,z) = dc.GetFullTextExtent(self.text_string) 84 (w,x,y,z) = dc.GetFullTextExtent(self.text_string)
95 self.log.log("Exit WhiteboardText->get_rect(self, dc)", ORPG_DEBUG)
96 return wx.Rect(self.posx,self.posy,w,(x+y+z)) 85 return wx.Rect(self.posx,self.posy,w,(x+y+z))
97 86
98 def draw(self, parent, dc, op=wx.COPY): 87 def draw(self, parent, dc, op=wx.COPY):
99 self.log.log("Enter WhiteboardText->draw(self, parent, dc, op)", ORPG_DEBUG)
100 self.scale = parent.canvas.layers['grid'].mapscale 88 self.scale = parent.canvas.layers['grid'].mapscale
101 if self.highlighted: textcolor = self.highlight_color 89 if self.highlighted: textcolor = self.highlight_color
102 else: textcolor = self.textcolor 90 else: textcolor = self.textcolor
103 try: dc.SetTextForeground(textcolor) 91 try: dc.SetTextForeground(textcolor)
104 except Exception,e: dc.SetTextForeground('#000000') 92 except Exception,e: dc.SetTextForeground('#000000')
107 # Draw text 95 # Draw text
108 (w,x,y,z) = self.get_rect(dc) 96 (w,x,y,z) = self.get_rect(dc)
109 dc.SetFont(self.font) 97 dc.SetFont(self.font)
110 dc.DrawText(self.text_string, self.posx, self.posy) 98 dc.DrawText(self.text_string, self.posx, self.posy)
111 dc.SetTextForeground(wx.Colour(0,0,0)) 99 dc.SetTextForeground(wx.Colour(0,0,0))
112 self.log.log("Exit WhiteboardText->draw(self, parent, dc, op)", ORPG_DEBUG)
113 100
114 def toxml(self, action="update"): 101 def toxml(self, action="update"):
115 self.log.log("Enter WhiteboardText->toxml(self, " + action + ")", ORPG_DEBUG)
116 if action == "del": 102 if action == "del":
117 xml_str = "<text action='del' id='" + str(self.id) + "'/>" 103 xml_str = "<text action='del' id='" + str(self.id) + "'/>"
118 self.log.log(xml_str, ORPG_DEBUG)
119 self.log.log("Exit WhiteboardText->toxml(self, " + action + ")", ORPG_DEBUG)
120 return xml_str 104 return xml_str
121 xml_str = "<text" 105 xml_str = "<text"
122 xml_str += " action='" + action + "'" 106 xml_str += " action='" + action + "'"
123 xml_str += " id='" + str(self.id) + "'" 107 xml_str += " id='" + str(self.id) + "'"
124 if self.pointsize != None: xml_str += " pointsize='" + str(self.pointsize) + "'" 108 if self.pointsize != None: xml_str += " pointsize='" + str(self.pointsize) + "'"
127 if self.posx != None: xml_str+= " posx='" + str(self.posx) + "'" 111 if self.posx != None: xml_str+= " posx='" + str(self.posx) + "'"
128 if not (self.posy is None): xml_str += " posy='" + str(self.posy) + "'" 112 if not (self.posy is None): xml_str += " posy='" + str(self.posy) + "'"
129 if self.text_string != None: xml_str+= " text_string='" + self.text_string + "'" 113 if self.text_string != None: xml_str+= " text_string='" + self.text_string + "'"
130 if self.textcolor != None: xml_str += " color='" + self.textcolor + "'" 114 if self.textcolor != None: xml_str += " color='" + self.textcolor + "'"
131 xml_str += "/>" 115 xml_str += "/>"
132 self.log.log(xml_str, ORPG_DEBUG)
133 self.log.log("Exit WhiteboardText->toxml(self, " + action + ")", ORPG_DEBUG)
134 if (action == "update" and self.isUpdated) or action == "new": 116 if (action == "update" and self.isUpdated) or action == "new":
135 self.isUpdated = False 117 self.isUpdated = False
136 return xml_str 118 return xml_str
137 else: return '' 119 else: return ''
138 120
139 def takedom(self, xml_dom): 121 def takedom(self, xml_dom):
140 self.log.log("Enter WhiteboardText->takedom(self, xml_dom)", ORPG_DEBUG)
141 self.text_string = xml_dom.getAttribute("text_string") 122 self.text_string = xml_dom.getAttribute("text_string")
142 self.log.log("self.text_string=" + self.text_string, ORPG_DEBUG)
143 self.id = xml_dom.getAttribute("id") 123 self.id = xml_dom.getAttribute("id")
144 self.log.log("self.id=" + str(self.id), ORPG_DEBUG)
145 if xml_dom.hasAttribute("posy"): 124 if xml_dom.hasAttribute("posy"):
146 self.posy = int(xml_dom.getAttribute("posy")) 125 self.posy = int(xml_dom.getAttribute("posy"))
147 self.log.log("self.posy=" + str(self.posy), ORPG_DEBUG)
148 if xml_dom.hasAttribute("posx"): 126 if xml_dom.hasAttribute("posx"):
149 self.posx = int(xml_dom.getAttribute("posx")) 127 self.posx = int(xml_dom.getAttribute("posx"))
150 self.log.log("self.posx=" + str(self.posx), ORPG_DEBUG)
151 if xml_dom.hasAttribute("weight"): 128 if xml_dom.hasAttribute("weight"):
152 self.weight = int(xml_dom.getAttribute("weight")) 129 self.weight = int(xml_dom.getAttribute("weight"))
153 self.font.SetWeight(self.weight) 130 self.font.SetWeight(self.weight)
154 self.log.log("self.weight=" + str(self.weight), ORPG_DEBUG)
155 if xml_dom.hasAttribute("style"): 131 if xml_dom.hasAttribute("style"):
156 self.style = int(xml_dom.getAttribute("style")) 132 self.style = int(xml_dom.getAttribute("style"))
157 self.font.SetStyle(self.style) 133 self.font.SetStyle(self.style)
158 self.log.log("self.style=" + str(self.style), ORPG_DEBUG)
159 if xml_dom.hasAttribute("pointsize"): 134 if xml_dom.hasAttribute("pointsize"):
160 self.pointsize = int(xml_dom.getAttribute("pointsize")) 135 self.pointsize = int(xml_dom.getAttribute("pointsize"))
161 self.font.SetPointSize(self.pointsize) 136 self.font.SetPointSize(self.pointsize)
162 self.log.log("self.pointsize=" + str(self.pointsize), ORPG_DEBUG)
163 if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '': 137 if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '':
164 self.textcolor = xml_dom.getAttribute("color") 138 self.textcolor = xml_dom.getAttribute("color")
165 if self.textcolor == '#0000000': self.textcolor = '#000000' 139 if self.textcolor == '#0000000': self.textcolor = '#000000'
166 self.log.log("self.textcolor=" + self.textcolor, ORPG_DEBUG)
167 self.log.log("Exit WhiteboardText->takedom(self, xml_dom)", ORPG_DEBUG)
168 140
169 class WhiteboardLine: 141 class WhiteboardLine:
170 def __init__(self, id, line_string, upperleft, lowerright, color="#000000", width=1, log=None): 142 def __init__(self, id, line_string, upperleft, lowerright, color="#000000", width=1, log=None):
171 self.log = log
172 self.log.log("Enter WhiteboardLine", ORPG_DEBUG)
173 self.scale = 1 143 self.scale = 1
174 self.r_h = RGBHex() 144 self.r_h = RGBHex()
175 if color == '': color = "#000000" 145 if color == '': color = "#000000"
176 self.linecolor = color 146 self.linecolor = color
177 self.linewidth = width 147 self.linewidth = width
181 self.line_string = line_string 151 self.line_string = line_string
182 self.id = id 152 self.id = id
183 self.highlighted = False 153 self.highlighted = False
184 r,g,b = self.r_h.rgb_tuple(self.linecolor) 154 r,g,b = self.r_h.rgb_tuple(self.linecolor)
185 self.highlight_color = self.r_h.hexstring(r^255, g^255, b^255) 155 self.highlight_color = self.r_h.hexstring(r^255, g^255, b^255)
186 self.log.log("Exit WhiteboardLine", ORPG_DEBUG)
187 156
188 def highlight(self, highlight=True): 157 def highlight(self, highlight=True):
189 self.log.log("Enter WhiteboardLine->highlight(self, highlight)", ORPG_DEBUG)
190 self.highlighted = highlight 158 self.highlighted = highlight
191 self.log.log("Enter WhiteboardLine->highlight(self, highlight)", ORPG_DEBUG) 159
192 160 def set_line_props(self, line_string="",
193 def set_line_props(self, line_string="", upperleftx=0, upperlefty=0, 161 upperleftx=0, upperlefty=0,
194 lowerrightx=0, lowerrighty=0, color="#000000", width=1): 162 lowerrightx=0, lowerrighty=0,
195 self.log.log("Enter WhiteboardLine->set_line_props(self, line_string, upperleftx, upperlefty, lowerrightx, lowerrighty, color, width)", ORPG_DEBUG) 163 color="#000000", width=1):
196 self.line_string = line_string 164 self.line_string = line_string
197 self.upperleft.x = upperleftx 165 self.upperleft.x = upperleftx
198 self.upperleft.y = upperlefty 166 self.upperleft.y = upperlefty
199 self.lowerright.x = lowerrightx 167 self.lowerright.x = lowerrightx
200 self.lowerright.y = lowerrighty 168 self.lowerright.y = lowerrighty
201 self.linecolor = color 169 self.linecolor = color
202 self.linewidth = width 170 self.linewidth = width
203 self.log.log("Exit WhiteboardLine->set_line_props(self, line_string, upperleftx, upperlefty, lowerrightx, lowerrighty, color, width)", ORPG_DEBUG)
204 171
205 def hit_test(self, pt): 172 def hit_test(self, pt):
206 self.log.log("Enter WhiteboardLine->hit_test(self, pt)", ORPG_DEBUG)
207 coords = self.line_string.split(";") 173 coords = self.line_string.split(";")
208 stcords = coords[0].split(",") 174 stcords = coords[0].split(",")
209 oldicords = (int(stcords[0]),int(stcords[1])) 175 oldicords = (int(stcords[0]),int(stcords[1]))
210 for coordinate_string_counter in range(1, len(coords)): 176 for coordinate_string_counter in range(1, len(coords)):
211 stcords = coords[coordinate_string_counter].split(",") 177 stcords = coords[coordinate_string_counter].split(",")
212 if stcords[0] == "": 178 if stcords[0] == "":
213 self.log.log("Exit WhiteboardLine->hit_test(self, pt) return False", ORPG_DEBUG)
214 return False 179 return False
215 icords = (int(stcords[0]),int(stcords[1])) 180 icords = (int(stcords[0]),int(stcords[1]))
216 if orpg.mapper.map_utils.proximity_test(oldicords,icords,pt,12): 181 if orpg.mapper.map_utils.proximity_test(oldicords,icords,pt,12):
217 self.log.log("Exit WhiteboardLine->hit_test(self, pt) return True", ORPG_DEBUG)
218 return True 182 return True
219 oldicords = icords 183 oldicords = icords
220 self.log.log("Exit WhiteboardLine->hit_test(self, pt) return False", ORPG_DEBUG)
221 return False 184 return False
222 185
223 def draw(self, parent, dc, op=wx.COPY): 186 def draw(self, parent, dc, op=wx.COPY):
224 self.log.log("Enter WhiteboardLine->draw(self, parent, dc, op=wx.COPY)", ORPG_DEBUG)
225 self.scale = parent.canvas.layers['grid'].mapscale 187 self.scale = parent.canvas.layers['grid'].mapscale
226 if self.highlighted: linecolor = self.highlight_color 188 if self.highlighted: linecolor = self.highlight_color
227 else: linecolor = self.linecolor 189 else: linecolor = self.linecolor
228 pen = wx.BLACK_PEN 190 pen = wx.BLACK_PEN
229 try: pen.SetColour(linecolor) 191 try: pen.SetColour(linecolor)
246 pen.SetColour(wx.Colour(0,0,0)) 208 pen.SetColour(wx.Colour(0,0,0))
247 dc.SetPen(pen) 209 dc.SetPen(pen)
248 dc.SetPen(wx.NullPen) 210 dc.SetPen(wx.NullPen)
249 dc.SetBrush(wx.NullBrush) 211 dc.SetBrush(wx.NullBrush)
250 #selected outline 212 #selected outline
251 self.log.log("Exit WhiteboardLine->draw(self, parent, dc, op=wx.COPY)", ORPG_DEBUG)
252 213
253 def toxml(self, action="update"): 214 def toxml(self, action="update"):
254 self.log.log("Enter WhiteboardLine->toxml(self, " + action + ")", ORPG_DEBUG)
255 if action == "del": 215 if action == "del":
256 xml_str = "<line action='del' id='" + str(self.id) + "'/>" 216 xml_str = "<line action='del' id='" + str(self.id) + "'/>"
257 self.log.log(xml_str, ORPG_DEBUG)
258 self.log.log("Exit WhiteboardLine->toxml(self, " + action + ")", ORPG_DEBUG)
259 return xml_str 217 return xml_str
260 # if there are any changes, make sure id is one of them 218 # if there are any changes, make sure id is one of them
261 xml_str = "<line" 219 xml_str = "<line"
262 xml_str += " action='" + action + "'" 220 xml_str += " action='" + action + "'"
263 xml_str += " id='" + str(self.id) + "'" 221 xml_str += " id='" + str(self.id) + "'"
271 if self.linecolor != None: 229 if self.linecolor != None:
272 xml_str += " color='" + str(self.linecolor) + "'" 230 xml_str += " color='" + str(self.linecolor) + "'"
273 if self.linewidth != None: 231 if self.linewidth != None:
274 xml_str += " width='" + str(self.linewidth) + "'" 232 xml_str += " width='" + str(self.linewidth) + "'"
275 xml_str += "/>" 233 xml_str += "/>"
276 self.log.log(xml_str, ORPG_DEBUG)
277 self.log.log("Exit WhiteboardLine->toxml(self, " + action + ")", ORPG_DEBUG)
278 if action == "new": return xml_str 234 if action == "new": return xml_str
279 return '' 235 return ''
280 236
281 def takedom(self, xml_dom): 237 def takedom(self, xml_dom):
282 self.log.log("Enter WhiteboardLine->takedom(self, xml_dom)", ORPG_DEBUG)
283 self.line_string = xml_dom.getAttribute("line_string") 238 self.line_string = xml_dom.getAttribute("line_string")
284 self.log.log("self.line_string=" + self.line_string, ORPG_DEBUG)
285 self.id = xml_dom.getAttribute("id") 239 self.id = xml_dom.getAttribute("id")
286 self.log.log("self.id=" + str(self.id), ORPG_DEBUG)
287 if xml_dom.hasAttribute("upperleftx"): 240 if xml_dom.hasAttribute("upperleftx"):
288 self.upperleft.x = int(xml_dom.getAttribute("upperleftx")) 241 self.upperleft.x = int(xml_dom.getAttribute("upperleftx"))
289 self.log.log("self.upperleft.x=" + str(self.upperleft.x), ORPG_DEBUG)
290 if xml_dom.hasAttribute("upperlefty"): 242 if xml_dom.hasAttribute("upperlefty"):
291 self.upperleft.y = int(xml_dom.getAttribute("upperlefty")) 243 self.upperleft.y = int(xml_dom.getAttribute("upperlefty"))
292 self.log.log("self.upperleft.y=" + str(self.upperleft.y), ORPG_DEBUG)
293 if xml_dom.hasAttribute("lowerrightx"): 244 if xml_dom.hasAttribute("lowerrightx"):
294 self.lowerright.x = int(xml_dom.getAttribute("lowerrightx")) 245 self.lowerright.x = int(xml_dom.getAttribute("lowerrightx"))
295 self.log.log("self.lowerright.x=" + str(self.lowerright.x), ORPG_DEBUG)
296 if xml_dom.hasAttribute("lowerrighty"): 246 if xml_dom.hasAttribute("lowerrighty"):
297 self.lowerright.y = int(xml_dom.getAttribute("lowerrighty")) 247 self.lowerright.y = int(xml_dom.getAttribute("lowerrighty"))
298 self.log.log("self.lowerright.y=" + str(self.lowerright.y), ORPG_DEBUG)
299 if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '': 248 if xml_dom.hasAttribute("color") and xml_dom.getAttribute("color") != '':
300 self.linecolor = xml_dom.getAttribute("color") 249 self.linecolor = xml_dom.getAttribute("color")
301 if self.linecolor == '#0000000': 250 if self.linecolor == '#0000000':
302 self.linecolor = '#000000' 251 self.linecolor = '#000000'
303 self.log.log("self.linecolor=" + self.linecolor, ORPG_DEBUG)
304 if xml_dom.hasAttribute("width"): 252 if xml_dom.hasAttribute("width"):
305 self.linewidth = int(xml_dom.getAttribute("width")) 253 self.linewidth = int(xml_dom.getAttribute("width"))
306 self.log.log("self.linewidth=" + str(self.linewidth), ORPG_DEBUG)
307 self.log.log("Exit WhiteboardLine->takedom(self, xml_dom)", ORPG_DEBUG)
308 254
309 ##----------------------------- 255 ##-----------------------------
310 ## whiteboard layer 256 ## whiteboard layer
311 ##----------------------------- 257 ##-----------------------------
312 class whiteboard_layer(layer_base): 258 class whiteboard_layer(layer_base):
313 259
314 def __init__(self, canvas): 260 def __init__(self, canvas):
315 self.canvas = canvas 261 self.canvas = canvas
316 self.log = self.canvas.log
317 self.log.log("Enter whiteboard_layer", ORPG_DEBUG)
318 layer_base.__init__(self) 262 layer_base.__init__(self)
319 self.r_h = RGBHex() 263 self.r_h = RGBHex()
320 self.id = -1 264 self.id = -1
321 self.lines = [] 265 self.lines = []
322 self.texts = [] 266 self.texts = []
323 self.serial_number = 0 267 self.serial_number = 0
324 self.color = "#000000" 268 self.color = "#000000"
325 self.width = 1 269 self.width = 1
326 self.removedLines = [] 270 self.removedLines = []
327 self.log.log("Exit whiteboard_layer", ORPG_DEBUG)
328 271
329 def next_serial(self): 272 def next_serial(self):
330 self.log.log("Enter whiteboard_layer->next_serial(self)", ORPG_DEBUG)
331 self.serial_number += 1 273 self.serial_number += 1
332 self.log.log("Exit whiteboard_layer->next_serial(self)", ORPG_DEBUG)
333 return self.serial_number 274 return self.serial_number
334 275
335 def get_next_highest_z(self): 276 def get_next_highest_z(self):
336 self.log.log("Enter whiteboard_layer->get_next_highest_z(self)", ORPG_DEBUG)
337 z = len(self.lines)+1 277 z = len(self.lines)+1
338 self.log.log("Exit whiteboard_layer->get_next_highest_z(self)", ORPG_DEBUG)
339 return z 278 return z
340 279
341 def cleanly_collapse_zorder(self): 280 def cleanly_collapse_zorder(self):
342 self.log.log("Enter/Exit whiteboard_layer->cleanly_collapse_zorder(self)", ORPG_DEBUG) 281 pass
343 282
344 def collapse_zorder(self): 283 def collapse_zorder(self):
345 self.log.log("Enter/Exit whiteboard_layer->collapse_zorder(self)", ORPG_DEBUG) 284 pass
346 285
347 def rollback_serial(self): 286 def rollback_serial(self):
348 self.log.log("Enter whiteboard_layer->rollback_serial(self)", ORPG_DEBUG)
349 self.serial_number -= 1 287 self.serial_number -= 1
350 self.log.log("Exit whiteboard_layer->rollback_serial(self)", ORPG_DEBUG)
351 288
352 def add_line(self, line_string="", upperleft=cmpPoint(0,0), lowerright=cmpPoint(0,0), color="#000000", width=1): 289 def add_line(self, line_string="", upperleft=cmpPoint(0,0), lowerright=cmpPoint(0,0), color="#000000", width=1):
353 self.log.log("Enter whiteboard_layer->add_line(self, line_string, upperleft, lowerright, color, width)", ORPG_DEBUG)
354 id = 'line-' + str(self.next_serial()) 290 id = 'line-' + str(self.next_serial())
355 line = WhiteboardLine(id, line_string, upperleft, lowerright, color=self.color, width=self.width, log=self.log) 291 line = WhiteboardLine(id, line_string, upperleft, lowerright, color=self.color, width=self.width)
356 self.lines.append(line) 292 self.lines.append(line)
357 xml_str = "<map><whiteboard>" 293 xml_str = "<map><whiteboard>"
358 xml_str += line.toxml("new") 294 xml_str += line.toxml("new")
359 xml_str += "</whiteboard></map>" 295 xml_str += "</whiteboard></map>"
360 self.canvas.frame.session.send(xml_str) 296 self.canvas.frame.session.send(xml_str)
361 self.canvas.Refresh(True) 297 self.canvas.Refresh(True)
362 self.log.log("Exit whiteboard_layer->add_line(self, line_string, upperleft, lowerright, color, width)", ORPG_DEBUG)
363 return line 298 return line
364 299
365 def get_line_by_id(self, id): 300 def get_line_by_id(self, id):
366 self.log.log("Enter whiteboard_layer->get_line_by_id(self, id)", ORPG_DEBUG)
367 for line in self.lines: 301 for line in self.lines:
368 if str(line.id) == str(id): 302 if str(line.id) == str(id):
369 self.log.log("Exit whiteboard_layer->get_line_by_id(self, id) return LineID: " + str(id), ORPG_DEBUG)
370 return line 303 return line
371 self.log.log("Exit whiteboard_layer->get_line_by_id(self, id) return None", ORPG_DEBUG)
372 return None 304 return None
373 305
374 def get_text_by_id(self, id): 306 def get_text_by_id(self, id):
375 self.log.log("Enter whiteboard_layer->get_text_by_id(self, id)", ORPG_DEBUG)
376 for text in self.texts: 307 for text in self.texts:
377 if str(text.id) == str(id): 308 if str(text.id) == str(id):
378 self.log.log("Exit whiteboard_layer->get_text_by_id(self, id) return textID: " + str(id), ORPG_DEBUG)
379 return text 309 return text
380 self.log.log("Enter whiteboard_layer->get_text_by_id(self, id) return None", ORPG_DEBUG)
381 return None 310 return None
382 311
383 def del_line(self, line): 312 def del_line(self, line):
384 self.log.log("Enter whiteboard_layer->del_line(self, line)", ORPG_DEBUG)
385 xml_str = "<map><whiteboard>" 313 xml_str = "<map><whiteboard>"
386 xml_str += line.toxml("del") 314 xml_str += line.toxml("del")
387 xml_str += "</whiteboard></map>" 315 xml_str += "</whiteboard></map>"
388 self.canvas.frame.session.send(xml_str) 316 self.canvas.frame.session.send(xml_str)
389 if line: 317 if line:
390 self.lines.remove(line) 318 self.lines.remove(line)
391 self.removedLines.append(line) 319 self.removedLines.append(line)
392 self.canvas.Refresh(True) 320 self.canvas.Refresh(True)
393 self.log.log("Exit whiteboard_layer->del_line(self, line)", ORPG_DEBUG)
394 321
395 def undo_line(self): 322 def undo_line(self):
396 if len(self.removedLines)>0: 323 if len(self.removedLines)>0:
397 line = self.removedLines[len(self.removedLines)-1] 324 line = self.removedLines[len(self.removedLines)-1]
398 self.removedLines.remove(line) 325 self.removedLines.remove(line)
399 self.add_line(line.line_string, line.upperleft, line.lowerright, line.linecolor, line.linewidth) 326 self.add_line(line.line_string, line.upperleft, line.lowerright, line.linecolor, line.linewidth)
400 self.canvas.Refresh(True) 327 self.canvas.Refresh(True)
401 328
402 def del_all_lines(self): 329 def del_all_lines(self):
403 self.log.log("Enter whiteboard_layer->del_all_lines(self)", ORPG_DEBUG)
404 for i in xrange(len(self.lines)): 330 for i in xrange(len(self.lines)):
405 self.del_line(self.lines[0]) 331 self.del_line(self.lines[0])
406 print self.lines 332 print self.lines
407 self.log.log("Exit whiteboard_layer->del_all_lines(self)", ORPG_DEBUG)
408 333
409 def del_text(self, text): 334 def del_text(self, text):
410 self.log.log("Enter whiteboard_layer->del_text(self, text)", ORPG_DEBUG)
411 xml_str = "<map><whiteboard>" 335 xml_str = "<map><whiteboard>"
412 xml_str += text.toxml("del") 336 xml_str += text.toxml("del")
413 xml_str += "</whiteboard></map>" 337 xml_str += "</whiteboard></map>"
414 self.canvas.frame.session.send(xml_str) 338 self.canvas.frame.session.send(xml_str)
415 if text: 339 if text:
416 self.texts.remove(text) 340 self.texts.remove(text)
417 self.canvas.Refresh(True) 341 self.canvas.Refresh(True)
418 self.log.log("Exit whiteboard_layer->del_text(self, text)", ORPG_DEBUG)
419 342
420 def layerDraw(self, dc): 343 def layerDraw(self, dc):
421 self.log.log("Enter whiteboard_layer->layerDraw(self, dc)", ORPG_DEBUG)
422 for m in self.lines: m.draw(self, dc) 344 for m in self.lines: m.draw(self, dc)
423 for m in self.texts: m.draw(self,dc) 345 for m in self.texts: m.draw(self,dc)
424 self.log.log("Exit whiteboard_layer->layerDraw(self, dc)", ORPG_DEBUG)
425 346
426 def hit_test_text(self, pos, dc): 347 def hit_test_text(self, pos, dc):
427 self.log.log("Enter whiteboard_layer->hit_test_text(self, pos, dc)", ORPG_DEBUG)
428 list_of_texts_matching = [] 348 list_of_texts_matching = []
429 if self.canvas.layers['fog'].use_fog == 1: 349 if self.canvas.layers['fog'].use_fog == 1:
430 if self.canvas.frame.session.role != "GM": 350 if self.canvas.frame.session.role != "GM":
431 self.log.log("Exit whiteboard_layer->hit_test_text(self, pos, dc)", ORPG_DEBUG)
432 return list_of_texts_matching 351 return list_of_texts_matching
433 for m in self.texts: 352 for m in self.texts:
434 if m.hit_test(pos,dc): list_of_texts_matching.append(m) 353 if m.hit_test(pos,dc): list_of_texts_matching.append(m)
435 self.log.log("Exit whiteboard_layer->hit_test_text(self, pos, dc)", ORPG_DEBUG)
436 return list_of_texts_matching 354 return list_of_texts_matching
437 355
438 def hit_test_lines(self, pos, dc): 356 def hit_test_lines(self, pos, dc):
439 self.log.log("Enter whiteboard_layer->hit_test_lines(self, pos, dc)", ORPG_DEBUG)
440 list_of_lines_matching = [] 357 list_of_lines_matching = []
441 if self.canvas.layers['fog'].use_fog == 1: 358 if self.canvas.layers['fog'].use_fog == 1:
442 if self.canvas.frame.session.role != "GM": 359 if self.canvas.frame.session.role != "GM":
443 self.log.log("Exit whiteboard_layer->hit_test_lines(self, pos, dc)", ORPG_DEBUG)
444 return list_of_lines_matching 360 return list_of_lines_matching
445 for m in self.lines: 361 for m in self.lines:
446 if m.hit_test(pos): list_of_lines_matching.append(m) 362 if m.hit_test(pos): list_of_lines_matching.append(m)
447 self.log.log("Exit whiteboard_layer->hit_test_lines(self, pos, dc)", ORPG_DEBUG)
448 return list_of_lines_matching 363 return list_of_lines_matching
449 364
450 def find_line(self, pt): 365 def find_line(self, pt):
451 self.log.log("Enter whiteboard_layer->find_line(self, pt)", ORPG_DEBUG)
452 scale = self.canvas.layers['grid'].mapscale 366 scale = self.canvas.layers['grid'].mapscale
453 dc = wx.ClientDC( self.canvas ) 367 dc = wx.ClientDC( self.canvas )
454 self.canvas.PrepareDC( dc ) 368 self.canvas.PrepareDC( dc )
455 dc.SetUserScale(scale,scale) 369 dc.SetUserScale(scale,scale)
456 line_list = self.hit_test_lines(pt,dc) 370 line_list = self.hit_test_lines(pt,dc)
457 if line_list: 371 if line_list:
458 self.log.log("Exit whiteboard_layer->find_line(self, pt)", ORPG_DEBUG)
459 return line_list[0] 372 return line_list[0]
460 else: 373 else:
461 self.log.log("Exit whiteboard_layer->find_line(self, pt) return None", ORPG_DEBUG)
462 return None 374 return None
463 375
464 def setcolor(self, color): 376 def setcolor(self, color):
465 self.log.log("Enter whiteboard_layer->setcolor(self, color)", ORPG_DEBUG)
466 r,g,b = color.Get() 377 r,g,b = color.Get()
467 self.color = self.r_h.hexstring(r,g,b) 378 self.color = self.r_h.hexstring(r,g,b)
468 self.log.log("Exit whiteboard_layer->setcolor(self, color)", ORPG_DEBUG)
469 379
470 def sethexcolor(self, hexcolor): 380 def sethexcolor(self, hexcolor):
471 self.log.log("Enter whiteboard_layer->sethexcolor(self, hexcolor)", ORPG_DEBUG)
472 self.color = hexcolor 381 self.color = hexcolor
473 self.log.log("Exit whiteboard_layer->sethexcolor(self, hexcolor)", ORPG_DEBUG)
474 382
475 def setwidth(self, width): 383 def setwidth(self, width):
476 self.log.log("Enter whiteboard_layer->setwidth(self, width)", ORPG_DEBUG)
477 self.width = int(width) 384 self.width = int(width)
478 self.log.log("Exit whiteboard_layer->setwidth(self, width)", ORPG_DEBUG)
479 385
480 def set_font(self, font): 386 def set_font(self, font):
481 self.log.log("Enter whiteboard_layer->set_font(self, font)", ORPG_DEBUG)
482 self.font = font 387 self.font = font
483 self.log.log("Exit whiteboard_layer->set_font(self, font)", ORPG_DEBUG)
484 388
485 def add_text(self, text_string, pos, style, pointsize, weight, color="#000000"): 389 def add_text(self, text_string, pos, style, pointsize, weight, color="#000000"):
486 self.log.log("Enter whiteboard_layer->add_text(self, text_string, pos, style, pointsize, weight, color)", ORPG_DEBUG)
487 id = 'text-' + str(self.next_serial()) 390 id = 'text-' + str(self.next_serial())
488 text = WhiteboardText(id,text_string, pos, style, pointsize, weight, color, self.log) 391 text = WhiteboardText(id,text_string, pos, style, pointsize, weight, color)
489 self.texts.append(text) 392 self.texts.append(text)
490 xml_str = "<map><whiteboard>" 393 xml_str = "<map><whiteboard>"
491 xml_str += text.toxml("new") 394 xml_str += text.toxml("new")
492 xml_str += "</whiteboard></map>" 395 xml_str += "</whiteboard></map>"
493 self.canvas.frame.session.send(xml_str) 396 self.canvas.frame.session.send(xml_str)
494 self.canvas.Refresh(True) 397 self.canvas.Refresh(True)
495 self.log.log("Exit whiteboard_layer->add_text(self, text_string, pos, style, pointsize, weight, color)", ORPG_DEBUG)
496 398
497 def draw_working_line(self, dc, line_string): 399 def draw_working_line(self, dc, line_string):
498 self.log.log("Enter whiteboard_layer->draw_working_line(self, dc, line_string)", ORPG_DEBUG)
499 scale = self.canvas.layers['grid'].mapscale 400 scale = self.canvas.layers['grid'].mapscale
500 dc.SetPen(wx.BLACK_PEN) 401 dc.SetPen(wx.BLACK_PEN)
501 dc.SetBrush(wx.BLACK_BRUSH) 402 dc.SetBrush(wx.BLACK_BRUSH)
502 pen = wx.BLACK_PEN 403 pen = wx.BLACK_PEN
503 pen.SetColour(self.color) 404 pen.SetColour(self.color)
515 dc.DrawLine(x2,y2,x1,y1) 416 dc.DrawLine(x2,y2,x1,y1)
516 x2 = x1 417 x2 = x1
517 y2 = y1 418 y2 = y1
518 dc.SetPen(wx.NullPen) 419 dc.SetPen(wx.NullPen)
519 dc.SetBrush(wx.NullBrush) 420 dc.SetBrush(wx.NullBrush)
520 self.log.log("Exit whiteboard_layer->draw_working_line(self, dc, line_string)", ORPG_DEBUG)
521 421
522 def layerToXML(self, action="update"): 422 def layerToXML(self, action="update"):
523 """ format """ 423 """ format """
524 self.log.log("Enter whiteboard_layer->layerToXML(self, " + action + ")", ORPG_DEBUG)
525 white_string = "" 424 white_string = ""
526 if self.lines: 425 if self.lines:
527 for l in self.lines: white_string += l.toxml(action) 426 for l in self.lines: white_string += l.toxml(action)
528 if self.texts: 427 if self.texts:
529 for l in self.texts: white_string += l.toxml(action) 428 for l in self.texts: white_string += l.toxml(action)
531 s = "<whiteboard" 430 s = "<whiteboard"
532 s += " serial='" + str(self.serial_number) + "'" 431 s += " serial='" + str(self.serial_number) + "'"
533 s += ">" 432 s += ">"
534 s += white_string 433 s += white_string
535 s += "</whiteboard>" 434 s += "</whiteboard>"
536 self.log.log(s, ORPG_DEBUG)
537 self.log.log("Exit whiteboard_layer->layerToXML(self, " + action + ")", ORPG_DEBUG)
538 return s 435 return s
539 else: 436 else:
540 self.log.log("Exit whiteboard_layer->layerToXML(self, " + action + ")", ORPG_DEBUG)
541 return "" 437 return ""
542 438
543 def layerTakeDOM(self, xml_dom): 439 def layerTakeDOM(self, xml_dom):
544 self.log.log("Enter whiteboard_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG)
545 serial_number = xml_dom.getAttribute('serial') 440 serial_number = xml_dom.getAttribute('serial')
546 if serial_number != "": self.serial_number = int(serial_number) 441 if serial_number != "": self.serial_number = int(serial_number)
547 children = xml_dom._get_childNodes() 442 children = xml_dom._get_childNodes()
548 for l in children: 443 for l in children:
549 nodename = l._get_nodeName() 444 nodename = l._get_nodeName()
551 id = l.getAttribute('id') 446 id = l.getAttribute('id')
552 if action == "del": 447 if action == "del":
553 if nodename == 'line': 448 if nodename == 'line':
554 line = self.get_line_by_id(id) 449 line = self.get_line_by_id(id)
555 if line != None: self.lines.remove(line) 450 if line != None: self.lines.remove(line)
556 else: self.log.log("Whiteboard error: Deletion of unknown line object attempted.", ORPG_GENERAL)
557 elif nodename == 'text': 451 elif nodename == 'text':
558 text = self.get_text_by_id(id) 452 text = self.get_text_by_id(id)
559 if text != None: self.texts.remove(text) 453 if text != None: self.texts.remove(text)
560 else: self.log.log("Whiteboard error: Deletion of unknown text object attempted.", ORPG_GENERAL)
561 else: self.log.log("Whiteboard error: Deletion of unknown whiteboard object attempted.", ORPG_GENERAL)
562 elif action == "new": 454 elif action == "new":
563 if nodename == "line": 455 if nodename == "line":
564 try: 456 try:
565 line_string = l.getAttribute('line_string') 457 line_string = l.getAttribute('line_string')
566 upperleftx = l.getAttribute('upperleftx') 458 upperleftx = l.getAttribute('upperleftx')
573 if color == '#0000000': color = '#000000' 465 if color == '#0000000': color = '#000000'
574 id = l.getAttribute('id') 466 id = l.getAttribute('id')
575 width = int(l.getAttribute('width')) 467 width = int(l.getAttribute('width'))
576 except: 468 except:
577 line_string = upperleftx = upperlefty = lowerrightx = lowerrighty = color = 0 469 line_string = upperleftx = upperlefty = lowerrightx = lowerrighty = color = 0
578 self.log.log(traceback.format_exc(), ORPG_GENERAL)
579 self.log.log("invalid line", ORPG_GENERAL)
580 continue 470 continue
581 line = WhiteboardLine(id, line_string, upperleft, lowerright, color, width, self.log) 471 line = WhiteboardLine(id, line_string, upperleft, lowerright, color, width)
582 self.lines.append(line) 472 self.lines.append(line)
583 elif nodename == "text": 473 elif nodename == "text":
584 try: 474 try:
585 text_string = l.getAttribute('text_string') 475 text_string = l.getAttribute('text_string')
586 style = l.getAttribute('style') 476 style = l.getAttribute('style')
593 posy = l.getAttribute('posy') 483 posy = l.getAttribute('posy')
594 pos = wx.Point(0,0) 484 pos = wx.Point(0,0)
595 pos.x = int(posx) 485 pos.x = int(posx)
596 pos.y = int(posy) 486 pos.y = int(posy)
597 except: 487 except:
598 self.log.log(traceback.format_exc(), ORPG_GENERAL)
599 self.log.log("invalid line", ORPG_GENERAL)
600 continue 488 continue
601 text = WhiteboardText(id, text_string, pos, style, pointsize, weight, color, self.log) 489 text = WhiteboardText(id, text_string, pos, style, pointsize, weight, color)
602 self.texts.append(text) 490 self.texts.append(text)
603 else: 491 else:
604 if nodename == "line": 492 if nodename == "line":
605 line = self.get_line_by_id(id) 493 line = self.get_line_by_id(id)
606 if line: line.takedom(l) 494 if line: line.takedom(l)
607 else: self.log.log("Whiteboard error: Update of unknown line attempted.", ORPG_GENERAL)
608 if nodename == "text": 495 if nodename == "text":
609 text = self.get_text_by_id(id) 496 text = self.get_text_by_id(id)
610 if text: text.takedom(l) 497 if text: text.takedom(l)
611 else: self.log.log("Whiteboard error: Update of unknown text attempted.", ORPG_GENERAL)
612 self.log.log("Enter whiteboard_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG)
613 #self.canvas.send_map_data() 498 #self.canvas.send_map_data()
614 499
615 def add_temp_line(self, line_string): 500 def add_temp_line(self, line_string):
616 line = WhiteboardLine(0, line_string, wx.Point(0,0), wx.Point(0,0), 501 line = WhiteboardLine(0, line_string, wx.Point(0,0), wx.Point(0,0),
617 color=self.color, width=self.width, log=self.log) 502 color=self.color, width=self.width)
618 self.lines.append(line) 503 self.lines.append(line)
619 return line 504 return line
620 505
621 def del_temp_line(self, line): 506 def del_temp_line(self, line):
622 if line: self.lines.remove(line) 507 if line: self.lines.remove(line)