def __init__(self, net, id, position, size): NetItem.__init__(self, net, id) self.point1 = citems.Point(self, "point1", citems.AbsPlacement(position)) self.point1.action = "resize_ltop" self.point2 = citems.Point( self, "point2", citems.AbsPlacement(utils.vector_add(position, size))) self.point2.owner = self self.point2.action = "resize_rbottom"
def draw(self, cr): NetEditCanvasConfig.draw(self, cr) if self.mouse_position: position = utils.snap_to_grid( self.get_position(self.mouse_position), self.grid_size) placement = citems.AbsPlacement(position) box = citems.ElementBox(None, "", placement, self.element.default_size, self.element.default_radius) box.draw(cr)
def add_point(self, position): inscription_position = self.inscription.get_position() for i, (a, b) in enumerate(utils.pairs_generator(self.get_all_points())): if utils.is_near_line_segment(a, b, position, 5): point = citems.Point(self, "point", citems.AbsPlacement(position)) point.owner = self self.points.insert(i, point) break self.inscription.set_position(inscription_position) self.net.changed( ) # Canvas items changed, so self.changed() is not sufficient
def get_packet_items(self): def get_size(self, cr): if not self.texts: return tx = max(utils.text_size(cr, t)[0] for t in self.texts) tx += 20 ty = 13 * len(self.texts) + 4 return (tx, ty) result = [] color = (0.8, 0.3, 0.1, 0.85) color_active = (1, 1, 1) color_inactive = (0.8, 0.8, 0.8) for edge in self.perspective.runinstance.net.edges_out(): packets = self.perspective.get_packets_info(edge.id) packet_box = self.packet_boxes.get(edge.id) if packet_box is None: position = utils.vector_add(edge.inscription.get_position(), (0, 15)) placement = citems.AbsPlacement(position) packet_box = citems.Box(None, "packetbox", placement) packet_box.size_fn = get_size packet_box.background = color packet_box.radius = 5 self.packet_boxes[edge.id] = packet_box result.append(packet_box) packet_box.texts = [ p[3] for p in packets ] for i, (process_id, origin_id, top, text) in enumerate(packets): position = utils.vector_add(packet_box.get_position(), (10, 13 * i)) t = citems.Text( None, "packet", packet_box.get_relative_placement(position), text) if top: t.color = color_active t.packet_data = (process_id, origin_id) else: t.color = color_inactive t.packet_data = None t.padding_y = 4 t.z_level = 15 t.action = None result.append(t) return result
def get_activation_items(self): result = [] for transition in self.perspective.runinstance.net.transitions(): activations = self.activations.get(transition.id) if activations is None: position = utils.vector_add( transition.box.get_position(), (0, transition.box.size[1] + 10)) activations = citems.TransitionActivations( None, "activations", citems.AbsPlacement(position)) self.activations[transition.id] = activations values = self.perspective.get_activations_values(transition) if values: result.append(activations) result += activations.create_activations(values) return result
def __init__(self, net, id, from_item, to_item, points): NetItem.__init__(self, net, id) self.from_item = from_item self.to_item = to_item self.points = [ citems.Point(self, "point", citems.AbsPlacement(p)) for p in points ] self.line = citems.ArrowLine(self, "line", self.get_all_points) self.inscription = citems.Text(self, "inscription", self.line.get_relative_placement(None), "") self.label_simrun = citems.SimRunLabel( self, "simrunbox", self.inscription.get_relative_placement((0, 18), absolute=False)) self.label_simrun.text_fn = self.get_simrun_label_text
def get_token_items(self): places = self.perspective.runinstance.net.places() result = [] for place in places: token_box = self.token_boxes.get(place.id) if token_box is None: sx, sy = place.box.size position = utils.vector_add(place.box.get_position(), (sx + 20, sy / 2)) token_box = citems.TokenBox(None, "tokenbox", citems.AbsPlacement(position)) self.token_boxes[place.id] = token_box token_box.set_tokens(self.perspective.get_tokens(place), self.perspective.get_new_tokens(place), self.perspective.get_removed_tokens(place)) result.append(token_box) return result
def __init__(self, net, id, position): NetItem.__init__(self, net, id) self.box = citems.ElementBox(self, "box", citems.AbsPlacement(position), self.default_size, self.default_radius) self.label_placement = self.box.get_relative_placement( utils.vector_add_t(position, self.default_size, 0.5)) self.label_trace = citems.TraceLabel(self, "tracebox", self.label_placement) self.label_trace.text_fn = self.get_trace_label_text self.label_simrun = citems.SimRunLabel(self, "simrunbox", self.label_placement) self.label_simrun.text_fn = self.get_simrun_label_text self.label_verif = citems.VerifLabel(self, "verifbox", self.label_placement) self.label_verif.text_fn = self.get_verif_label_text