def on_mouse_motion(self, event): if (self.drag_id < 0 or not event.Dragging() or not event.LeftIsDown()): return ok_to_drag = win_data.program().check_drag(self.drag_id, self.drag_name) if (not ok_to_drag): return raw_pt = event.GetPosition() check_pt = self.CalcUnscrolledPosition(raw_pt) if (not self.drag_image): # BED zooming support check_pt = wx.Point(check_pt.x/self.zoom, check_pt.y/self.zoom) #print "Move, raw:", raw_pt, "check:", check_pt tolerance = 4 dx = abs(check_pt.x - self.drag_start_pos.x) dy = abs(check_pt.y - self.drag_start_pos.y) if (dx <= tolerance and dy <= tolerance): return #print "Start drag with movement:", dx, dy # remove the old one but remember it if we have to put it back self.drag_start = (self.drag_id, self.drag_name) win_data.program().start_move(self.drag_id, self.drag_which) # force the work area to redraw self.Refresh() self.Update() # get the selected variant since we had to click to get here bmp = bric_data.get_bric_bmap(self.drag_name, bric_data.BRIC_SELECTED) if (self.zoom != 1.0): image = bmp.ConvertToImage() w = image.GetWidth() * self.zoom h = image.GetHeight() * self.zoom image.Rescale(w, h) bmp = image.ConvertToBitmap() self.drag_image = wx.DragImage(bmp, wx.StockCursor(wx.CURSOR_HAND)) dev_x,dev_y = bmp.GetSize() hotspot = (dev_x/2, dev_y/2) self.drag_image.BeginDrag(hotspot, self, False, self.GetClientRect()) loc, update,which_id = self.local_move_centre_pt(raw_pt, self.drag_name, self.drag_image) self.drag_image.Move(raw_pt) self.drag_image.Show() else: loc, update,which_id = self.local_move_centre_pt(raw_pt, self.drag_name, self.drag_image) self.drag_image.Move(raw_pt) if (update): self.drag_image.Show()
def on_left_up(self, event): # do parent processing prev_id, bric_name, which_id = self.parent_on_left_up(event) if prev_id >= 0: # it is a valid drop! new_id = win_data.program().add_new_bric(prev_id, which_id, bric_name) # set the selection win_data.selection_take("pwork", bric_name, new_id) # force the work area to redraw win_data.force_redraw("pwork")
def on_left_up(self, event): # do parent processing prev_id, bric_name, which_id = self.parent_on_left_up(event) if (prev_id >= 0): # it is a valid drop! new_id = win_data.program().add_new_bric(prev_id, which_id, bric_name) # set the selection win_data.selection_take('pwork', bric_name, new_id) # force the work area to redraw win_data.force_redraw('pwork')
def on_left_up(self, event): loc = -1 self.scroll_x, self.scroll_y = 0, 0 if (self.drag_image): pt = event.GetPosition() loc, update, which_id = self.local_move_centre_pt( pt, self.drag_name, self.drag_image) self.drag_bmp = None self.drag_image.Hide() self.drag_image.EndDrag() self.drag_image = None if (loc == -1): win_data.selection_drop_all() if (not win_data.get_ok_to_delete("Program")): win_data.program().abort_move() else: win_data.program().end_move(loc, which_id) self.big_x = -1 self.Refresh(True) self.Update() else: win_data.program().end_move(loc, which_id) win_data.click_sound() # force the work area to redraw self.SetCursor(wx.NullCursor) self.Refresh()
def on_left_up(self, event): loc = -1 self.scroll_x, self.scroll_y = 0,0 if (self.drag_image): pt = event.GetPosition() loc,update,which_id = self.local_move_centre_pt(pt, self.drag_name, self.drag_image) self.drag_bmp = None self.drag_image.Hide() self.drag_image.EndDrag() self.drag_image = None if (loc == -1): win_data.selection_drop_all() if (not win_data.get_ok_to_delete("Program")): win_data.program().abort_move() else: win_data.program().end_move(loc, which_id) self.big_x = -1 self.Refresh(True) self.Update() else: win_data.program().end_move(loc, which_id) win_data.click_sound() # force the work area to redraw self.SetCursor(wx.NullCursor) self.Refresh()
def compute_bmap(self, name, x, bric_id): if (name == "new_event"): bmap = bric_data.get_new_bmap(False) elif (name == 'If'): if_var = win_data.program().get_bric_if_variant(bric_id) if (win_data.selection_check('pwork', None, bric_id)): bmap = bric_data.get_if_bmap(if_var, True) else: bmap = bric_data.get_if_bmap(if_var, False) else: if (win_data.selection_check('pwork', None, bric_id)): bmap = bric_data.get_bric_bmap(name, bric_data.BRIC_SELECTED) else: bmap = bric_data.get_bric_bmap(name, bric_data.BRIC_NORMAL) x += bmap.GetWidth() return x
def draw_bmap(self, dc, name, x, cl, bric_id): # **BED** scale bitmap if needed #print "Drawing:", name, "x:",x, "cl:", cl, "bric_id:", bric_id if (name == "new_event"): bmap = bric_data.get_new_bmap(False) elif (name == 'If'): if_var = win_data.program().get_bric_if_variant(bric_id) if (win_data.selection_check('pwork', None, bric_id)): bmap = bric_data.get_if_bmap(if_var, True) else: bmap = bric_data.get_if_bmap(if_var, False) else: if (win_data.selection_check('pwork', None, bric_id)): bmap = bric_data.get_bric_bmap(name, bric_data.BRIC_SELECTED) else: bmap = bric_data.get_bric_bmap(name, bric_data.BRIC_NORMAL) y = cl - bmap.GetHeight() / 2 dc.DrawBitmap(bmap, x, y, True) x += bmap.GetWidth() return (x, bmap.GetSize())
def draw_bmap(self, dc, name, x, cl, bric_id): # **BED** scale bitmap if needed #print "Drawing:", name, "x:",x, "cl:", cl, "bric_id:", bric_id if (name == "new_event"): bmap = bric_data.get_new_bmap(False) elif (name == 'If'): if_var = win_data.program().get_bric_if_variant(bric_id) if (win_data.selection_check('pwork', None, bric_id)): bmap = bric_data.get_if_bmap(if_var, True) else: bmap = bric_data.get_if_bmap(if_var, False) else: if (win_data.selection_check('pwork', None, bric_id)): bmap = bric_data.get_bric_bmap(name, bric_data.BRIC_SELECTED) else: bmap = bric_data.get_bric_bmap(name, bric_data.BRIC_NORMAL) y = cl - bmap.GetHeight()/2 dc.DrawBitmap(bmap, x, y, True) x += bmap.GetWidth() return (x, bmap.GetSize())
def on_mouse_motion(self, event): if (self.drag_id < 0 or not event.Dragging() or not event.LeftIsDown()): return ok_to_drag = win_data.program().check_drag(self.drag_id, self.drag_name) if (not ok_to_drag): return raw_pt = event.GetPosition() check_pt = self.CalcUnscrolledPosition(raw_pt) if (not self.drag_image): # BED zooming support check_pt = wx.Point(check_pt.x / self.zoom, check_pt.y / self.zoom) #print "Move, raw:", raw_pt, "check:", check_pt tolerance = 4 dx = abs(check_pt.x - self.drag_start_pos.x) dy = abs(check_pt.y - self.drag_start_pos.y) if (dx <= tolerance and dy <= tolerance): return #print "Start drag with movement:", dx, dy # remove the old one but remember it if we have to put it back self.drag_start = (self.drag_id, self.drag_name) win_data.program().start_move(self.drag_id, self.drag_which) # force the work area to redraw self.Refresh() self.Update() # get the selected variant since we had to click to get here bmp = bric_data.get_bric_bmap(self.drag_name, bric_data.BRIC_SELECTED) if (self.zoom != 1.0): image = bmp.ConvertToImage() w = image.GetWidth() * self.zoom h = image.GetHeight() * self.zoom image.Rescale(w, h) bmp = image.ConvertToBitmap() self.drag_image = wx.DragImage(bmp, wx.StockCursor(wx.CURSOR_HAND)) dev_x, dev_y = bmp.GetSize() hotspot = (dev_x / 2, dev_y / 2) self.drag_image.BeginDrag(hotspot, self, False, self.GetClientRect()) loc, update, which_id = self.local_move_centre_pt( raw_pt, self.drag_name, self.drag_image) self.drag_image.Move(raw_pt) self.drag_image.Show() else: loc, update, which_id = self.local_move_centre_pt( raw_pt, self.drag_name, self.drag_image) self.drag_image.Move(raw_pt) if (update): self.drag_image.Show()
def paint_flow(self, dc, x, cl_base, flow, branch, stream): #print "paint_flow() x:", x, "cl_base:", cl_base, "flow:", flow # flow starts with cl adjustment then nodes cl_adjust = 90 cl_skip = 90 + 10 cl_max = cl_base x_max = x new_cl = [cl_base, cl_base] loop_returns = {} self.in_paint = True #cl = cl_base + flow[0] * cl_adjust cl = cl_base i = 1 end = len(flow) - 1 while (i < end): if (flow[i] == -2): (big_x_1, new_cl_1) = self.paint_flow(dc, x, new_cl[0], flow[i + 1], 0, stream) (big_x_2, new_cl_2) = self.paint_flow(dc, x, new_cl[1], flow[i + 2], 1, stream) i += 3 # Next one will be the End so can connect up unequal branches then x = max(big_x_1, big_x_2) if (new_cl_1 > cl_max): cl_max = new_cl_1 if (new_cl_2 > cl_max): cl_max = new_cl_2 else: bric_id = flow[i] name = win_data.program().get_bric_name(bric_id) prev_0 = win_data.program().get_prev_id(bric_id, 0) if (prev_0 > 0): prev_name_0 = win_data.program().get_bric_name(prev_0) if (name not in ("If", "Loop", "EndIf", "EndLoop")): # draw the bric, then the arrow self.connections[bric_id][0] = (x, cl) self.connections[bric_id][1] = (x, cl) x = self.draw_bmap_and_add_location( dc, name, x, cl, bric_id, branch) # draw an arrow self.draw_arrow_and_add_location(dc, 0, x, cl, bric_id, branch) x += self.arrow_w self.connections[bric_id][2] = (x, cl) ## #BED try connecting everything ## print "not-if-loop-end" ## if (prev_0 > 0): ## if (prev_name_0 in ("Loop", "If")): ## self.connect(dc, self.connections[prev_0][branch+2], self.connections[bric_id][0]) ## else: ## self.connect(dc, self.connections[prev_0][2], self.connections[bric_id][0]) elif (name in ("EndIf", "EndLoop")): # draw the bric, then the arrow self.connections[bric_id][0] = (x, cl - cl_adjust) self.connections[bric_id][1] = (x, cl + cl_adjust) x = self.draw_bmap_and_add_location( dc, name, x, cl, bric_id, branch) # draw an arrow self.draw_arrow_and_add_location(dc, 0, x, cl, bric_id, branch) x += self.arrow_w self.connections[bric_id][2] = (x, cl) # Check for connecting the lines for unequal lengths and loops start_bric_id = bric_id - 1 prev_name = win_data.program().get_bric_name(start_bric_id) if (prev_name == "Loop"): # draw a line if more then 1 apart #print "end-loop" if (prev_0 != bric_id - 1): self.connect(dc, self.connections[bric_id][0], self.connections[prev_0][2]) self.connect(dc, self.connections[bric_id][1], self.connections[bric_id - 1][2]) else: # If prev_0 = win_data.program().get_prev_id(bric_id, 0) prev_1 = win_data.program().get_prev_id(bric_id, 1) #print "Bric id:", bric_id, prev_0, prev_1 #print "end-if" if (prev_0 == bric_id - 1): self.connect(dc, self.connections[bric_id][0], self.connections[prev_0][1]) else: self.connect(dc, self.connections[bric_id][0], self.connections[prev_0][2]) if (prev_1 == bric_id - 1): self.connect(dc, self.connections[bric_id][1], self.connections[prev_1][2]) else: self.connect(dc, self.connections[bric_id][1], self.connections[prev_1][2]) elif (name == "Loop"): self.connections[bric_id][0] = (x, cl) # draw the bric, then the arrow x = self.draw_bmap_and_add_location( dc, name, x, cl, bric_id, branch) arrow_y = self.draw_arrow(dc, 1, x, cl + cl_adjust) self.draw_arrow_and_add_location(dc, 0, x, cl - cl_adjust, bric_id, branch) x += self.arrow_w self.connections[bric_id][1] = (x, cl - cl_adjust) self.connections[bric_id][2] = (x, cl + cl_adjust) ## #BED try connecting everything ## prev_0 = win_data.program().get_prev_id(bric_id, 0) ## print "loop" ## self.connect(dc, self.connections[prev_0][2], self.connections[bric_id][0]) # Create two streams and be intelligent about the hit points top, bot = self.adj[bric_id] new_cl = (cl - cl_adjust + top * cl_skip, cl + cl_adjust + bot * cl_skip) if ((top < 0) and win_data.program().get_next_id(bric_id, 0) != (bric_id + 1)): self.connect(dc, self.connections[bric_id][1], (x, new_cl[0])) ## if (bot > 0): ## self.connect(dc, self.connections[bric_id][2], (x,new_cl[1])) if (new_cl[1] > cl_max): cl_max = new_cl[1] else: self.connections[bric_id][0] = (x, cl) # draw the bric, then the arrow x = self.draw_bmap_and_add_location( dc, name, x, cl, bric_id, branch) # draw two arrows self.draw_arrow_and_add_location(dc, 0, x, cl - cl_adjust, bric_id, 0) self.draw_arrow_and_add_location(dc, 0, x, cl + cl_adjust, bric_id, 1) x += self.arrow_w self.connections[bric_id][1] = (x, cl - cl_adjust) self.connections[bric_id][2] = (x, cl + cl_adjust) ## #BED try connecting everything ## prev_0 = win_data.program().get_prev_id(bric_id, 0) ## print "if" ## self.connect(dc, self.connections[prev_0][2], self.connections[bric_id][0]) # Create two streams and be intelligent about the hit points top, bot = self.adj[bric_id] new_cl = (cl - cl_adjust + top * cl_skip, cl + cl_adjust + bot * cl_skip) if ((top < 0) and win_data.program().get_next_id(bric_id, 0) != (bric_id + 1)): self.connect(dc, self.connections[bric_id][1], (x, new_cl[0])) if ((bot > 0) and win_data.program().get_next_id(bric_id, 1) != (bric_id + 1)): self.connect(dc, self.connections[bric_id][2], (x, new_cl[1])) if (new_cl[1] > cl_max): cl_max = new_cl[1] i += 1 #print "paint_flow returns", (x,1) # now do the final bric - Last if (flow[0] == 0): #print "Flow:", flow[0], "i:", i, "Stream:", stream if (stream == 0): new_x, bmap_size = self.draw_bmap(dc, "Last", x, cl, 0) else: new_x, bmap_size = self.draw_bmap(dc, "EndEvent", x, cl, 0) self.in_paint = False return (x, cl_max)
def compute_placement(self, x, cl_base, flow, branch, connections): # flow starts with cl adjustment then nodes cl_adjust = 90 cl_skip = 90 + 10 cl_max = cl_base x_max = x new_cl = [cl_base, cl_base] cl = cl_base i = 1 end = len(flow) - 1 while (i < end): if (flow[i] == -2): (big_x_1, new_cl_1) = self.compute_placement(x, new_cl[0], flow[i + 1], 0, connections) (big_x_2, new_cl_2) = self.compute_placement(x, new_cl[1], flow[i + 2], 1, connections) i += 3 # Next one will be the End so can connect up unequal branches then x = max(big_x_1, big_x_2) else: bric_id = flow[i] if (bric_id not in connections): connections[bric_id] = [None, None, None] name = win_data.program().get_bric_name(bric_id) prev_0 = win_data.program().get_prev_id(bric_id, 0) if (prev_0 > 0): prev_name_0 = win_data.program().get_bric_name(prev_0) if (name not in ("If", "Loop", "EndIf", "EndLoop")): # draw the bric, then the arrow connections[bric_id][0] = (x, cl) connections[bric_id][1] = (x, cl) x = self.compute_bmap(name, x, bric_id) # allow for an arrow x += self.arrow_w connections[bric_id][2] = (x, cl) elif (name in ("EndIf", "EndLoop")): # draw the bric, then the arrow connections[bric_id][0] = (x, cl - cl_adjust) connections[bric_id][1] = (x, cl + cl_adjust) x = self.compute_bmap(name, x, bric_id) # allow for an arrow x += self.arrow_w connections[bric_id][2] = (x, cl) elif (name == "Loop"): connections[bric_id][0] = (x, cl) x = self.compute_bmap(name, x, bric_id) # allow for an arrow x += self.arrow_w connections[bric_id][1] = (x, cl - cl_adjust) connections[bric_id][2] = (x, cl + cl_adjust) # Create two streams and be intelligent about the hit points top, bot = self.adj[bric_id] new_cl = (cl - cl_adjust + top * cl_skip, cl + cl_adjust + bot * cl_skip) else: connections[bric_id][0] = (x, cl) # draw the bric, then the arrow x = self.compute_bmap(name, x, bric_id) # allow for the arrows x += self.arrow_w connections[bric_id][1] = (x, cl - cl_adjust) connections[bric_id][2] = (x, cl + cl_adjust) # Create two streams and be intelligent about the hit points top, bot = self.adj[bric_id] new_cl = (cl - cl_adjust + top * cl_skip, cl + cl_adjust + bot * cl_skip) i += 1 return (x, cl_max)
def on_paint(self, event): #print "Starting paint" self.y_offset = 0 dc = wx.PaintDC(self) self.DoPrepareDC(dc) # Things can move about now self.zone_hit = -1 dc.SetBackground(wx.Brush("white", wx.SOLID)) dc.SetUserScale(self.zoom, self.zoom) dc.Clear() ourGray = wx.Colour(red=108, green=109, blue=112) ourPen = wx.Pen(ourGray, 12) ourPen.SetCap(wx.CAP_BUTT) dc.SetPen(ourPen) dc.SetBrush(wx.Brush(ourGray, wx.SOLID)) centre_line = 0 centre_line_buffer = 200 left = 20 loop_returns = {} self.drop_locations = [] self.pickup_locations = [] streams = win_data.program().get_stream_count() stream = 0 x = 20 biggest_x = 0 limits = [] while (stream < streams): # is the stream being moved (ready for deletion) if (win_data.program().get_stream_id(stream) == -1): stream += 1 continue compute_connections = {} x = 20 tree_data, adj, min_min_up = win_data.program().get_tree_data( stream) #print "tree_data", tree_data #print "Adj", adj, "min_min_up", min_min_up self.adj = adj self.compute_placement(x, 0, tree_data, 0, compute_connections) #print "Compute_connections", compute_connections # find the smallest and biggest y and biggest x initialised = False x_max = 0 x_min = 0 y_max = 0 y_min = 0 for bric_id in compute_connections: for point in compute_connections[bric_id]: x, y = point if (not initialised): x_max = x_min = x y_max = y_min = y initialised = True else: if (x > x_max): x_max = x if (x < x_min): x_min = x if (y > y_max): y_max = y if (y < y_min): y_min = y #print "x_max", x_max, "y_max", y_max, "x_min", x_min, "y_min", y_min limits.append((x_min, x_max, y_min, y_max)) stream += 1 #print "Limits", limits centre_line = 0 visible_stream = 0 stream = 0 x = 20 while (stream < streams): # is the stream being moved (ready for deletion) if (win_data.program().get_stream_id(stream) == -1): stream += 1 continue win_data.program().zero_connections(self.connections) tree_data, adj, min_min_up = win_data.program().get_tree_data( stream) ## print "tree_data", tree_data ## print "Adj", adj, "min_min_up", min_min_up ## if (min_min_up < 0): ## centre_line += (min_min_up * -1 * 100) ## print "Centre_line dropped:", min_min_up * -100 self.adj = adj y_offset = limits[visible_stream][2] - 100 centre_line += -1 * y_offset y_range = limits[visible_stream][3] - limits[visible_stream][2] bottom_adjust = y_range - (-1 * y_offset) + 100 #print "Centre_line", centre_line (x_max, cl_max) = self.paint_flow(dc, x, centre_line, tree_data, 0, stream) #print "from paint_flow():", x_max, cl_max x_offset = limits[visible_stream][1] + 20 if (x_offset > biggest_x): biggest_x = x_offset self.big_x = biggest_x #print "Biggest x", biggest_x centre_line += bottom_adjust #print "bottom centre_line", bottom_adjust, centre_line stream += 1 visible_stream += 1 # now need the point for adding new streams x = left cl = centre_line + 100 x, bmap_size = self.draw_bmap(dc, "new_event", x, cl, 0) self.drop_locations.append((0, None, (left, cl - bmap_size[1] / 2), 0, wx.Rect(left, cl - bmap_size[1] / 2, bmap_size[0], bmap_size[1]))) #print "Post-Bounding box", dc.MinY(), dc.MaxY() self.SetVirtualSize(((biggest_x + 20) * self.zoom, (cl + centre_line_buffer) * self.zoom))
def paint_flow(self, dc, x, cl_base, flow, branch, stream): #print "paint_flow() x:", x, "cl_base:", cl_base, "flow:", flow # flow starts with cl adjustment then nodes cl_adjust = 90 cl_skip = 90+10 cl_max = cl_base x_max = x new_cl = [cl_base, cl_base] loop_returns = {} self.in_paint = True #cl = cl_base + flow[0] * cl_adjust cl = cl_base i = 1 end = len(flow)-1 while (i < end): if (flow[i] == -2): (big_x_1, new_cl_1) = self.paint_flow(dc, x, new_cl[0], flow[i+1], 0, stream) (big_x_2, new_cl_2) = self.paint_flow(dc, x, new_cl[1], flow[i+2], 1, stream) i += 3 # Next one will be the End so can connect up unequal branches then x = max(big_x_1, big_x_2) if (new_cl_1 > cl_max): cl_max = new_cl_1 if (new_cl_2 > cl_max): cl_max = new_cl_2 else: bric_id = flow[i] name = win_data.program().get_bric_name(bric_id) prev_0 = win_data.program().get_prev_id(bric_id, 0) if (prev_0 > 0): prev_name_0 = win_data.program().get_bric_name(prev_0) if (name not in ("If","Loop", "EndIf", "EndLoop")): # draw the bric, then the arrow self.connections[bric_id][0] = (x,cl) self.connections[bric_id][1] = (x,cl) x = self.draw_bmap_and_add_location(dc, name, x, cl, bric_id, branch) # draw an arrow self.draw_arrow_and_add_location(dc, 0, x, cl, bric_id, branch) x += self.arrow_w self.connections[bric_id][2] = (x,cl) ## #BED try connecting everything ## print "not-if-loop-end" ## if (prev_0 > 0): ## if (prev_name_0 in ("Loop", "If")): ## self.connect(dc, self.connections[prev_0][branch+2], self.connections[bric_id][0]) ## else: ## self.connect(dc, self.connections[prev_0][2], self.connections[bric_id][0]) elif (name in ("EndIf", "EndLoop")): # draw the bric, then the arrow self.connections[bric_id][0] = (x, cl-cl_adjust) self.connections[bric_id][1] = (x, cl+cl_adjust) x = self.draw_bmap_and_add_location(dc, name, x, cl, bric_id, branch) # draw an arrow self.draw_arrow_and_add_location(dc, 0, x, cl, bric_id, branch) x += self.arrow_w self.connections[bric_id][2] = (x, cl) # Check for connecting the lines for unequal lengths and loops start_bric_id = bric_id - 1 prev_name = win_data.program().get_bric_name(start_bric_id) if (prev_name == "Loop"): # draw a line if more then 1 apart #print "end-loop" if (prev_0 != bric_id - 1): self.connect(dc, self.connections[bric_id][0], self.connections[prev_0][2]) self.connect(dc, self.connections[bric_id][1], self.connections[bric_id-1][2]) else: # If prev_0 = win_data.program().get_prev_id(bric_id, 0) prev_1 = win_data.program().get_prev_id(bric_id, 1) #print "Bric id:", bric_id, prev_0, prev_1 #print "end-if" if (prev_0 == bric_id-1): self.connect(dc, self.connections[bric_id][0], self.connections[prev_0][1]) else: self.connect(dc, self.connections[bric_id][0], self.connections[prev_0][2]) if (prev_1 == bric_id-1): self.connect(dc, self.connections[bric_id][1], self.connections[prev_1][2]) else: self.connect(dc, self.connections[bric_id][1], self.connections[prev_1][2]) elif (name == "Loop"): self.connections[bric_id][0] = (x, cl) # draw the bric, then the arrow x = self.draw_bmap_and_add_location(dc, name, x, cl, bric_id, branch) arrow_y = self.draw_arrow(dc, 1, x, cl+cl_adjust) self.draw_arrow_and_add_location(dc, 0, x, cl-cl_adjust, bric_id, branch) x += self.arrow_w self.connections[bric_id][1] = (x, cl-cl_adjust) self.connections[bric_id][2] = (x, cl+cl_adjust) ## #BED try connecting everything ## prev_0 = win_data.program().get_prev_id(bric_id, 0) ## print "loop" ## self.connect(dc, self.connections[prev_0][2], self.connections[bric_id][0]) # Create two streams and be intelligent about the hit points top, bot = self.adj[bric_id] new_cl = (cl - cl_adjust + top*cl_skip, cl + cl_adjust + bot*cl_skip) if ((top < 0) and win_data.program().get_next_id(bric_id, 0) != (bric_id+1)): self.connect(dc, self.connections[bric_id][1], (x,new_cl[0])) ## if (bot > 0): ## self.connect(dc, self.connections[bric_id][2], (x,new_cl[1])) if (new_cl[1] > cl_max): cl_max = new_cl[1] else: self.connections[bric_id][0] = (x, cl) # draw the bric, then the arrow x = self.draw_bmap_and_add_location(dc, name, x, cl, bric_id, branch) # draw two arrows self.draw_arrow_and_add_location(dc, 0, x, cl-cl_adjust, bric_id, 0) self.draw_arrow_and_add_location(dc, 0, x, cl+cl_adjust, bric_id, 1) x += self.arrow_w self.connections[bric_id][1] = (x, cl-cl_adjust) self.connections[bric_id][2] = (x, cl+cl_adjust) ## #BED try connecting everything ## prev_0 = win_data.program().get_prev_id(bric_id, 0) ## print "if" ## self.connect(dc, self.connections[prev_0][2], self.connections[bric_id][0]) # Create two streams and be intelligent about the hit points top, bot = self.adj[bric_id] new_cl = (cl - cl_adjust + top*cl_skip, cl + cl_adjust + bot*cl_skip) if ((top < 0) and win_data.program().get_next_id(bric_id, 0) != (bric_id+1)): self.connect(dc, self.connections[bric_id][1], (x,new_cl[0])) if ((bot > 0) and win_data.program().get_next_id(bric_id, 1) != (bric_id+1)): self.connect(dc, self.connections[bric_id][2], (x,new_cl[1])) if (new_cl[1] > cl_max): cl_max = new_cl[1] i += 1 #print "paint_flow returns", (x,1) # now do the final bric - Last if (flow[0] == 0): #print "Flow:", flow[0], "i:", i, "Stream:", stream if (stream == 0): new_x, bmap_size = self.draw_bmap(dc, "Last", x, cl, 0) else: new_x, bmap_size = self.draw_bmap(dc, "EndEvent", x, cl, 0) self.in_paint = False return (x,cl_max)
def compute_placement(self, x, cl_base, flow, branch, connections): # flow starts with cl adjustment then nodes cl_adjust = 90 cl_skip = 90+10 cl_max = cl_base x_max = x new_cl = [cl_base, cl_base] cl = cl_base i = 1 end = len(flow)-1 while (i < end): if (flow[i] == -2): (big_x_1, new_cl_1) = self.compute_placement(x, new_cl[0], flow[i+1], 0, connections) (big_x_2, new_cl_2) = self.compute_placement(x, new_cl[1], flow[i+2], 1, connections) i += 3 # Next one will be the End so can connect up unequal branches then x = max(big_x_1, big_x_2) else: bric_id = flow[i] if (bric_id not in connections): connections[bric_id] = [None, None, None] name = win_data.program().get_bric_name(bric_id) prev_0 = win_data.program().get_prev_id(bric_id, 0) if (prev_0 > 0): prev_name_0 = win_data.program().get_bric_name(prev_0) if (name not in ("If","Loop", "EndIf", "EndLoop")): # draw the bric, then the arrow connections[bric_id][0] = (x,cl) connections[bric_id][1] = (x,cl) x = self.compute_bmap(name, x, bric_id) # allow for an arrow x += self.arrow_w connections[bric_id][2] = (x,cl) elif (name in ("EndIf", "EndLoop")): # draw the bric, then the arrow connections[bric_id][0] = (x, cl-cl_adjust) connections[bric_id][1] = (x, cl+cl_adjust) x = self.compute_bmap(name, x, bric_id) # allow for an arrow x += self.arrow_w connections[bric_id][2] = (x,cl) elif (name == "Loop"): connections[bric_id][0] = (x, cl) x = self.compute_bmap(name, x, bric_id) # allow for an arrow x += self.arrow_w connections[bric_id][1] = (x, cl-cl_adjust) connections[bric_id][2] = (x, cl+cl_adjust) # Create two streams and be intelligent about the hit points top, bot = self.adj[bric_id] new_cl = (cl - cl_adjust + top*cl_skip, cl + cl_adjust + bot*cl_skip) else: connections[bric_id][0] = (x, cl) # draw the bric, then the arrow x = self.compute_bmap(name, x, bric_id) # allow for the arrows x += self.arrow_w connections[bric_id][1] = (x, cl-cl_adjust) connections[bric_id][2] = (x, cl+cl_adjust) # Create two streams and be intelligent about the hit points top, bot = self.adj[bric_id] new_cl = (cl - cl_adjust + top*cl_skip, cl + cl_adjust + bot*cl_skip) i += 1 return (x,cl_max)
def on_paint(self, event): #print "Starting paint" self.y_offset = 0 dc = wx.PaintDC(self) self.DoPrepareDC(dc) # Things can move about now self.zone_hit = -1 dc.SetBackground(wx.Brush("white", wx.SOLID)) dc.SetUserScale(self.zoom, self.zoom) dc.Clear() ourGray = wx.Colour(red=108, green=109, blue=112) ourPen = wx.Pen(ourGray, 12) ourPen.SetCap(wx.CAP_BUTT) dc.SetPen(ourPen) dc.SetBrush(wx.Brush(ourGray, wx.SOLID)) centre_line = 0 centre_line_buffer = 200 left = 20 loop_returns = {} self.drop_locations = [] self.pickup_locations = [] streams = win_data.program().get_stream_count() stream = 0 x = 20 biggest_x = 0 limits = [] while (stream < streams): # is the stream being moved (ready for deletion) if (win_data.program().get_stream_id(stream) == -1): stream += 1 continue compute_connections = {} x = 20 tree_data, adj, min_min_up = win_data.program().get_tree_data(stream) #print "tree_data", tree_data #print "Adj", adj, "min_min_up", min_min_up self.adj = adj self.compute_placement(x, 0, tree_data, 0, compute_connections) #print "Compute_connections", compute_connections # find the smallest and biggest y and biggest x initialised = False x_max = 0 x_min = 0 y_max = 0 y_min = 0 for bric_id in compute_connections: for point in compute_connections[bric_id]: x, y = point if (not initialised): x_max = x_min = x y_max = y_min = y initialised = True else: if (x > x_max): x_max = x if (x < x_min): x_min = x if (y > y_max): y_max = y if (y < y_min): y_min = y #print "x_max", x_max, "y_max", y_max, "x_min", x_min, "y_min", y_min limits.append((x_min, x_max, y_min, y_max)) stream += 1 #print "Limits", limits centre_line = 0 visible_stream = 0 stream = 0 x = 20 while (stream < streams): # is the stream being moved (ready for deletion) if (win_data.program().get_stream_id(stream) == -1): stream += 1 continue win_data.program().zero_connections(self.connections) tree_data, adj, min_min_up = win_data.program().get_tree_data(stream) ## print "tree_data", tree_data ## print "Adj", adj, "min_min_up", min_min_up ## if (min_min_up < 0): ## centre_line += (min_min_up * -1 * 100) ## print "Centre_line dropped:", min_min_up * -100 self.adj = adj y_offset = limits[visible_stream][2] - 100 centre_line += -1 * y_offset; y_range = limits[visible_stream][3] - limits[visible_stream][2] bottom_adjust = y_range - (-1 * y_offset) + 100 #print "Centre_line", centre_line (x_max, cl_max) = self.paint_flow(dc, x, centre_line, tree_data, 0, stream) #print "from paint_flow():", x_max, cl_max x_offset = limits[visible_stream][1] + 20 if (x_offset > biggest_x): biggest_x = x_offset self.big_x = biggest_x #print "Biggest x", biggest_x centre_line += bottom_adjust #print "bottom centre_line", bottom_adjust, centre_line stream += 1 visible_stream += 1 # now need the point for adding new streams x = left cl = centre_line + 100 x, bmap_size = self.draw_bmap(dc, "new_event", x, cl, 0) self.drop_locations.append((0, None, (left, cl-bmap_size[1]/2), 0, wx.Rect(left, cl-bmap_size[1]/2, bmap_size[0], bmap_size[1]))) #print "Post-Bounding box", dc.MinY(), dc.MaxY() self.SetVirtualSize(((biggest_x+20) * self.zoom,(cl + centre_line_buffer)*self.zoom))