def _update_inhibitory_arc(self): """ Update inhibitory arc and set correct parameters. """ # instantiate InhibitoryArc object self.__new_component = inhibitory_arc.InhibitoryArc() # set line type self.__new_component.line_type = inhibitory_arc.InhibitoryArc.LINE_TYPE_ARC_UPPER if not self._auto_line_type: if self._arc_line_type == self.LT_STRAIGHT: self.__new_component.line_type = inhibitory_arc.InhibitoryArc.LINE_TYPE_STRAIGHT if self._arc_line_type == self.LT_CURVED_LOWER: self.__new_component.line_type = inhibitory_arc.InhibitoryArc.LINE_TYPE_ARC_LOWER if self._arc_line_type == self.LT_CURVED_UPPER: self.__new_component.line_type = inhibitory_arc.InhibitoryArc.LINE_TYPE_ARC_UPPER # remove buffer component self._model.data.remove_key("new component") # update component self.__update_component()
def add_inhibitory_arc(self): """ Create a new inhibitory arc component with default settings and forwards it to the ControllerDrawingArea which is responsible for displaying it. """ self.add_arc(inhibitory_arc.InhibitoryArc())
def convert_components(self, position=None): """ Based on the defined PetriNetData object, which contains the petri net specifications in matrix form, the single components will be created and automatically assigned to the dictionaries. """ # reset the dictionaries self._places = dict() self._transitions = dict() self._arcs = dict() # set data for the converter self._converter_components.data = self._pn_data # convert self._converter_components.convert() # assign new components self._places = self._converter_components.places self._transitions = self._converter_components.transitions # arcs cannot be assigned directly self._arcs = dict() arcs = self._converter_components.arcs # need to be recreated otherwise a problem with references occurres for key, item in arcs.items(): # arc component a = None # check object type an instantiate an object of the correct class if type(item) == arc.Arc: a = arc.Arc() if type(item) == test_arc.TestArc: a = test_arc.TestArc() if type(item) == inhibitory_arc.InhibitoryArc: a = inhibitory_arc.InhibitoryArc() # check if an object could be created if a != None: # set properties a.key = item.key a.label = item.label a.weight = item.weight a.line_type = item.line_type a.font_weight = item.font_weight a.font_label = item.font_label if item.target != None: a.target = self.get_component(item.target.key) if item.origin != None: a.origin = self.get_component(item.origin.key) # add arc self.add_arc(a) # check if positions are defined if position != None: # iteration through all positions self.set_positions(position) else: # instantiate layout object v = force_a.ForceDirected() # set data v.petri_net = self.petri_net_data.clone() v.get_petri_net() # set default parameter v.width = 900 v.height = 600 v.border = 100 v.grid_size = 50 v.iterations = 1 # calculate positions v.calculate() # read positions self.set_positions(v.node_positions)
def paste(self): """ Paste the copied components onto the drawing area. """ # create a snapshot self._model.create_snapshot() # set flags and object values self._selected_components = None self._component = None self._multi_select = False self._move_items = False self._paste = True # iteration through all copied components and add them to the core data except arcs for i in range(len(self._copied_components)): if type(self._copied_components[i]) == place.Place or type( self._copied_components[i]) == transition.Transition: # add component to the core data self._model.data.add(self._copied_components[i]) # dictionary of arcs arcs = self._model.data.arcs # iteration through all available arcs for key, item in arcs.items(): # check if both parties of the current arc are part of the copied components origin = False target = False key_origin = "" key_target = "" # iteration through all copied components for clone_key, orig_key in self._paste_dict.items(): if item.origin.key == orig_key: origin = True key_origin = clone_key if item.target.key == orig_key: target = True key_target = clone_key # check if both parties of an arc could be identified if origin and target: # add arc # reference issue - recreation of the arc component is necessary new_item_properties = self.copy_component(item) new_arc = None if type(item) == arc.Arc: new_arc = arc.Arc() if type(item) == inhibitory_arc.InhibitoryArc: new_arc = inhibitory_arc.InhibitoryArc() if type(item) == test_arc.TestArc: new_arc = inhibitory_arc.InhibitoryArc() if new_arc != None: new_arc.line_type = new_item_properties.line_type new_arc.label = new_item_properties.label new_arc.key = new_item_properties.key new_arc.origin = self._model.data.get_component(key_origin) new_arc.target = self._model.data.get_component(key_target) new_arc.weight = new_item_properties.weight # add arc to the core data self._model.data.add(new_arc) # remove labelling from the components for key, item in self._model.data.places.items(): try: self._model.data.places[key].rgb_edge = [0, 0, 0] except AttributeError: pass for key, item in self._model.data.transitions.items(): try: self._model.data.transitions[key].rgb_edge = [0, 0, 0] self._model.data.transitions[key].rgb_fill = [0, 0, 0] except AttributeError: pass for key, item in self._model.data.arcs.items(): try: self._model.data.arcs[key].rgb_edge = [0, 0, 0] self._model.data.arcs[key].origin.rgb_edge = [0, 0, 0] self._model.data.arcs[key].target.rgb_edge = [0, 0, 0] except AttributeError: pass # refresh the drawing area self.refresh()
def convert(self): """ Start converting process from matrices to components. """ # Information: A lot of exceptions will be thrown because of the NoneType issue we had and it is necessary to prevent the appliation from crashing. # create a PetriNet object self._pn = petri_net.PetriNet() # set PetriNetData object self._pn.data = self._data try: # create the individual places for i in range(len(self._data.places)): # set default values for the design p = place.Place([0.0, 0.0], 15., [0., 0., 0.], [255., 255., 255.]) # set properties p.label = self._data.places[i] p.key = self._data.places[i] if self._data.initial_marking != None: p.marking = self._data.initial_marking[i] try: if self._data.capacities != None: p.capacity = self._data.capacities[i] except IndexError: pass # add place to the PetriNet object self._pn.add_place(p, ) except TypeError: pass try: # create the individual transitions for i in range(len(self._data.transitions)): # set default values for the design t = transition.Transition([0.0, 0.0], [15, 30], [0., 0., 0.], [0., 0., 0.]) # set properties t.label = self._data.transitions[i] t.key = self._data.transitions[i] if self._data.rates != None: t.rate = self._data.rates[i] # add transition to the PetirNet object self._pn.add_transition(t) except TypeError: pass try: # create the individual arcs connecting two nodes for i in range(len(self._data.transitions)): for j in range(len(self._data.places)): a_pre = None a_post = None a_test = None a_inhib = None # iteration through the matrices to figure out which arc needs to be created try: if self._data.stoichiometry.pre_arcs != None: try: if self._data.stoichiometry.pre_arcs[ i, j] != None: if self._data.stoichiometry.pre_arcs[ i, j] != 0: # create a standard pre arc a_pre = arc.Arc() a_pre.line_type = arc.Arc.LINE_TYPE_STRAIGHT a_pre.label = str( "Arc" + self._data.places[j] + "to" + self._data.transitions[i]) a_pre.key = str( "Arc" + self._data.places[j] + "to" + self._data.transitions[i]) a_pre.origin = self._pn.get_component( self._data.places[j]) a_pre.target = self._pn.get_component( self._data.transitions[i]) if self._data.stoichiometry.pre_arcs != None: a_pre.weight = self._data.stoichiometry.pre_arcs[ i, j] # add arc to the PetriNet object self._pn.add_arc(a_pre) except IndexError: pass except TypeError: pass try: if self._data.stoichiometry.post_arcs != None: try: if self._data.stoichiometry.post_arcs[ i, j] != None: if self._data.stoichiometry.post_arcs[ i, j] != 0: # create a standard post arc a_post = arc.Arc() a_post.line_type = arc.Arc.LINE_TYPE_STRAIGHT a_post.label = str( self._data.transitions[i] + "to" + self._data.places[j]) a_post.key = str( self._data.transitions[i] + "to" + self._data.places[j]) a_post.origin = self._pn.get_component( self._data.transitions[i]) a_post.target = self._pn.get_component( self._data.places[j]) if self._data.stoichiometry.post_arcs != None: a_post.weight = self._data.stoichiometry.post_arcs[ i, j] # add arc to the PetriNet object self._pn.add_arc(a_post) except IndexError: pass except TypeError: pass try: if self._data.test_arcs != None: try: if self._data.test_arcs[i, j] != None: if self._data.test_arcs[i, j] != 0: # create a test arc a_test = test_arc.TestArc() a_test.line_type = test_arc.TestArc.LINE_TYPE_ARC_LOWER a_test.label = str( "TestArc" + self._data.transitions[i] + "to" + self._data.places[j]) a_test.key = str( "TestArc" + self._data.transitions[i] + "to" + self._data.places[j]) a_test.target = self._pn.get_component( self._data.transitions[i]) a_test.origin = self._pn.get_component( self._data.places[j]) if self._data.test_arcs != None: a_test.weight = self._data.test_arcs[ i, j] # add arc to the PetriNet object self._pn.add_arc(a_test) except IndexError: pass except TypeError: pass try: if self._data.inhibitory_arcs != None: try: if self._data.inhibitory_arcs[i, j] != None: if self._data.inhibitory_arcs[i, j] != 0: # create an inhibitory arc a_inhib = inhibitory_arc.InhibitoryArc( ) a_inhib.line_type = inhibitory_arc.InhibitoryArc.LINE_TYPE_ARC_UPPER a_inhib.label = str( "InhibitoryArc" + self._data.transitions[i] + "to" + self._data.places[j]) a_inhib.key = str( "InhibitoryArc" + self._data.transitions[i] + "to" + self._data.places[j]) a_inhib.target = self._pn.get_component( self._data.transitions[i]) a_inhib.origin = self._pn.get_component( self._data.places[j]) if self._data.inhibitory_arcs != None: a_inhib.weight = self._data.inhibitory_arcs[ i, j] # add arc to the PetriNet object self._pn.add_arc(a_inhib) except IndexError: pass except TypeError: pass # determine the style of the line automatically # if two standard arcs are available the curved arcs will be chosen if a_pre != None and a_post != None: a_pre.line_type = arc.Arc.LINE_TYPE_ARC_LOWER self._pn.update(a_pre, a_pre.key) a_post.line_type = arc.Arc.LINE_TYPE_ARC_UPPER self._pn.update(a_post, a_post.key) except TypeError: pass # print len(self._pn.arcs) # if an algorithm is defined the positions of the components will be determined if self._layout != None: self.__layout_components()