def squareWithHole() -> Outline: outline = Outline(None) outline.addLinesFromCoordinateList([[0, 0], [50, 0], [50, 50], [0, 50], [0, 0]]) circle = a.Arc(Point(35, 25), Point(35, 25), c.CW, Point(25, 25)) outline.addLineGroup(circle) return outline
def regularDogBoneFillet(scale: float) -> Outline: dogBoneF = Outline(None) dogBoneF.addLinesFromCoordinateList([[82.5, 0], [82.5, 4.5]]) arc = a.Arc(Point(82.5, 4.5), Point(77.5, 9.5), c.CCW, Point(77.5, 4.5), 6) #5mm fillet dogBoneF.addLineGroup(arc) dogBoneF.addLinesFromCoordinateList([[77.5, 9.5], [49.642, 9.5]]) arc = a.Arc(Point(49.642, 9.5), Point(28.5, 6.5), c.CW, Point(28.5, 82.5), 20) dogBoneF.addLineGroup(arc) dogBoneF.addLinesFromCoordinateList([[28.5, 6.5], [0, 6.5]]) dogBoneF.addLineGroup(dogBoneF.mirror(c.Y)) dogBoneF.addLineGroup(dogBoneF.mirror(c.X)) dogBoneF = dogBoneF.translate(82.5, 9.5) dogBoneF.finishOutline() dogBoneF = dogBoneF.scale(scale) dogBoneF._name = 'regularDogBoneFillet' return dogBoneF
def rightGrip() -> Outline: outline = Outline(None) outline.addLinesFromCoordinateList([[82.5, 0], [82.5, 9.5], [49.642, 9.5]]) arc = a.Arc(Point(49.642, 9.5), Point(28.5, 6.5), c.CW, Point(28.5, 82.5), 20) outline.addLineGroup(arc) outline.addLinesFromCoordinateList([[28.5, 6.5], [28.5, 0]]) outline.addLineGroup(outline.mirror(c.X)) return outline.translate(82.5, 9.5)
def typeVDogBone(scale: float) -> Outline: typeV = Outline(None) typeV.addLinesFromCoordinateList([[31.75, 0], [31.75, 3.77]]) arc = a.Arc(Point(31.75, 3.77), Point(30.75, 4.77), c.CCW, Point(30.75, 3.77), 5) #1mm fillet typeV.addLineGroup(arc) typeV.addLinesFromCoordinateList([[30.75, 4.77], [13.17, 4.77]]) arc = a.Arc(Point(13.17, 4.77), Point(4.77, 1.59), c.CW, Point(4.77, 14.29)) typeV.addLineGroup(arc) typeV.addLinesFromCoordinateList([[4.77, 1.59], [0, 1.59]]) typeV.addLineGroup(typeV.mirror(c.Y)) typeV.addLineGroup(typeV.mirror(c.X)) typeV = typeV.translate(31.75, 4.77) typeV.finishOutline() typeV = typeV.scale(scale) typeV._name = 'typeVDogBone' return typeV
def regularDogBone() -> Outline: dogBone = Outline(None) dogBone.addLinesFromCoordinateList([[82.5, 0], [82.5, 9.5], [49.642, 9.5]]) arc = a.Arc(Point(49.642, 9.5), Point(28.5, 6.5), c.CW, Point(28.5, 82.5), 20) dogBone.addLineGroup(arc) dogBone.addLinesFromCoordinateList([[28.5, 6.5], [0, 6.5]]) dogBone.addLineGroup(dogBone.mirror(c.Y)) dogBone.addLineGroup(dogBone.mirror(c.X)) dogBone = dogBone.translate(82.5, 9.5) dogBone.finishOutline() dogBone._name = 'regularDogBone' return dogBone
def wideDogBone(gageWidth: float) -> Outline: halfWidth = gageWidth / 2.0 wideDogBone = Outline(None) wideDogBone.addLinesFromCoordinateList([[82.5, 0], [82.5, 9.5 + halfWidth], [49.642, 9.5 + halfWidth]]) wideArc = a.Arc(Point(49.642, 9.5 + halfWidth), Point(28.5, 6.5 + halfWidth), c.CW, Point(28.5, 82.5 + halfWidth), 20) wideDogBone.addLineGroup(wideArc) wideDogBone.addLinesFromCoordinateList([[28.5, 6.5 + halfWidth], [0, 6.5 + halfWidth]]) wideDogBone.addLineGroup(wideDogBone.mirror(c.Y)) wideDogBone.addLineGroup(wideDogBone.mirror(c.X)) return wideDogBone.translate(82.5, 9.5 + halfWidth)
def _update_arc(self): """ Update the current arc and update the functional core. """ # new component self.__new_component = arc.Arc() self.__new_component.line_type = arc.Arc.LINE_TYPE_STRAIGHT # check if the line type needs to be determined automatically if not self._auto_line_type: if self._arc_line_type == self.LT_STRAIGHT: self.__new_component.line_type = arc.Arc.LINE_TYPE_STRAIGHT if self._arc_line_type == self.LT_CURVED_LOWER: self.__new_component.line_type = arc.Arc.LINE_TYPE_ARC_LOWER if self._arc_line_type == self.LT_CURVED_UPPER: self.__new_component.line_type = arc.Arc.LINE_TYPE_ARC_UPPER else: # determine the line type and assign the correct one to the buffer component if self._model != None: # check if a similar arc already exists for key, item in self._model.data.arcs.items(): if type(item) == arc.Arc: if key == self._component.key and key != "new_component" and key != "new_comp" and key != "new component": if item.line_type == arc.Arc.LINE_TYPE_ARC_LOWER: self.__new_component.line_type = arc.Arc.LINE_TYPE_ARC_LOWER if item.line_type == arc.Arc.LINE_TYPE_ARC_UPPER: self.__new_component.line_type = arc.Arc.LINE_TYPE_ARC_UPPER if item.line_type == arc.Arc.LINE_TYPE_STRAIGHT: self.__new_component.line_type = arc.Arc.LINE_TYPE_STRAIGHT break else: if item.target.is_equal( self._component.origin ) and item.origin.is_equal(self._component.target): if item.line_type == arc.Arc.LINE_TYPE_ARC_LOWER: self.__new_component.line_type = arc.Arc.LINE_TYPE_ARC_UPPER if item.line_type == arc.Arc.LINE_TYPE_ARC_UPPER: self.__new_component.line_type = arc.Arc.LINE_TYPE_ARC_LOWER if item.line_type == arc.Arc.LINE_TYPE_STRAIGHT: if type(self._component.origin ) == place.Place: self.__new_component.line_type = arc.Arc.LINE_TYPE_ARC_LOWER else: self.__new_component.line_type = arc.Arc.LINE_TYPE_ARC_UPPER break # remove buffer component self._model.data.remove_key("new component") # update self.__update_component()
def add_standard_arc(self): """ Create a new standard arc component with default settings and forwards it to the ControllerDrawingArea which is responsible for displaying it. """ self.add_arc(arc.Arc())
def circle(centerX: float, centerY: float, radius: float) -> Outline: startPoint = Point(centerX + radius, centerY) center = Point(centerX, centerY) return Outline(a.Arc(startPoint, startPoint, c.CW, center, numPoints=40))
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()