def __init__(self, Ps, Pe, height, xyfeed, zfeed): LineGeo.__init__(self, Ps, Pe) self.type = "BreakGeo" self.height = height self.xyfeed = xyfeed self.zfeed = zfeed
def breakLineGeo(self, lineGeo, breakLayers): """ Try to break passed lineGeo with any of the shapes on a break layers. Will break lineGeos recursively. @return: The list of geometries after breaking (lineGeo itself if no breaking happened) """ newGeos = [] for breakLayer in breakLayers: for breakShape in breakLayer.shapes: intersections = self.intersectLineGeometry(lineGeo, breakShape) if len(intersections) == 2: (near, far) = self.classifyIntersections(lineGeo, intersections) logger.debug("Line %s broken from (%f, %f) to (%f, %f)" % (lineGeo.to_short_string(), near.x, near.y, far.x, far.y)) newGeos.extend( self.breakLineGeo(LineGeo(lineGeo.Ps, near), breakLayers)) newGeos.append( BreakGeo(near, far, breakLayer.axis3_mill_depth, breakLayer.f_g1_plane, breakLayer.f_g1_depth)) newGeos.extend( self.breakLineGeo(LineGeo(far, lineGeo.Pe), breakLayers)) return newGeos return [lineGeo]
def Write_GCode(self, parent=None, PostPro=None): """ Writes the GCODE for a Break. @param parent: This is the parent LayerContentClass @param PostPro: The PostProcessor instance to be used @return: Returns the string to be written to file. """ oldZ = PostPro.ze oldFeed = PostPro.feed if self.height <= oldZ: return (LineGeo.Write_GCode(self, parent, PostPro)) else: return (PostPro.chg_feed_rate(self.zfeed) + PostPro.lin_pol_z(self.height) + PostPro.chg_feed_rate(self.xyfeed) + LineGeo.Write_GCode(self, parent, PostPro) + PostPro.chg_feed_rate(self.zfeed) + PostPro.lin_pol_z(oldZ) + PostPro.chg_feed_rate(oldFeed))
def Read(self, caller): """ This function does read the geometry. @param caller: The instance which is calling the function """ #Assign short name lp = caller.line_pairs e = lp.index_code(0, caller.start + 1) #Assign layer s = lp.index_code(8, caller.start + 1) self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value) #X Value sl = lp.index_code(10, s + 1) x0 = float(lp.line_pair[sl].value) #Y Value s = lp.index_code(20, sl + 1) y0 = float(lp.line_pair[s].value) #X Value 2 s = lp.index_code(11, sl + 1) x1 = float(lp.line_pair[s].value) #Y Value 2 s = lp.index_code(21, s + 1) y1 = float(lp.line_pair[s].value) #Searching for an extrusion direction s_nxt_xt = lp.index_code(230, s + 1, e) #If there is a extrusion direction given flip around x-Axis if s_nxt_xt != None: extrusion_dir = float(lp.line_pair[s_nxt_xt].value) logger.debug( self.tr('Found extrusion direction: %s') % extrusion_dir) if extrusion_dir == -1: x0 = -x0 x1 = -x1 Ps = Point(x0, y0) Pe = Point(x1, y1) #Anhängen der LineGeo Klasse für die Geometrie #Annexes to LineGeo class for geometry ??? self.geo.append(LineGeo(Ps=Ps, Pe=Pe)) #Länge entspricht der Länge des Kreises #Length corresponding to the length (circumference?) of the circle self.length = self.geo[-1].length #Neuen Startwert für die nächste Geometrie zurückgeben #New starting value for the next geometry caller.start = s
def compress_lines(self, Curve): """ compress_lines() """ joint = [] NewCurve = [] Pts = [] for geo in Curve: NewCurve.append(geo) anz = len(NewCurve) if anz >= 2: #Wenn Geo eine Linie ist anh�ngen und �berpr�fen if (NewCurve[-2].type == "LineGeo") and (NewCurve[-1].type == "LineGeo"): Pts.append(geo.Pe) JointLine = LineGeo(NewCurve[-2].Ps, NewCurve[-1].Pe) #�berpr�fung der Abweichung res = [] for Point in Pts: res.append(JointLine.distance2point(Point)) #print res #Wenn die Abweichung OK ist Vorheriges anh�ngen if (max(res) < self.epsilon): anz = len(NewCurve) del NewCurve[anz - 2:anz] NewCurve.append(JointLine) points = [geo.Pe] #Wenn nicht nicht anh�ngen und Pts zur�cksetzen else: Pts = [geo.Pe] #Wenn es eines eine andere Geometrie als eine Linie ist else: Pts = [] return NewCurve
def Read(self, caller): """ Read() """ Old_Point = Point(0, 0) #Assign short name lp = caller.line_pairs e = lp.index_code(0, caller.start + 1) #Assign layer s = lp.index_code(8, caller.start + 1) self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value) #Pa=None for the first point Pa = None #Number of vertices s = lp.index_code(90, s + 1, e) NoOfVert = int(lp.line_pair[s].value) #Polyline flag (bit-coded); default is 0; 1 = Closed; 128 = Plinegen s = lp.index_code(70, s + 1, e) LWPLClosed = int(lp.line_pair[s].value) #print LWPLClosed s = lp.index_code(10, s + 1, e) while 1: #X Value if s == None: break x = float(lp.line_pair[s].value) #Y Value s = lp.index_code(20, s + 1, e) y = float(lp.line_pair[s].value) Pe = Point(x=x, y=y) #Bulge bulge = 0 s_nxt_x = lp.index_code(10, s + 1, e) e_nxt_b = s_nxt_x #Wenn am Ende dann Suche bis zum Ende #If in the end the search until the end ??? if e_nxt_b == None: e_nxt_b = e s_bulge = lp.index_code(42, s + 1, e_nxt_b) #print('stemp: %s, e: %s, next 10: %s' %(s_temp,e,lp.index_code(10,s+1,e))) if s_bulge != None: bulge = float(lp.line_pair[s_bulge].value) s_nxt_x = s_nxt_x #Take the next X value as the starting value s = s_nxt_x #Assign the geometries for the Polyline if not (type(Pa) == type(None)): if next_bulge == 0: self.geo.append(LineGeo(Pa=Pa, Pe=Pe)) else: #self.geo.append(LineGeo(Pa=Pa,Pe=Pe)) #print bulge self.geo.append(self.bulge2arc(Pa, Pe, next_bulge)) #Länge drauf rechnen wenns eine Geometrie ist #Wenns Ldnge count on it is a geometry ??? self.length += self.geo[-1].length #The bulge is always given for the next point next_bulge = bulge Pa = Pe if (LWPLClosed == 1) or (LWPLClosed == 129): #print("sollten Übereinstimmen: %s, %s" %(Pa,Pe)) if next_bulge: self.geo.append(self.bulge2arc(Pa, self.geo[0].Pa, next_bulge)) else: self.geo.append(LineGeo(Pa=Pa, Pe=self.geo[0].Pa)) self.length += self.geo[-1].length #New starting value for the next geometry caller.start = e
def make_start_moves(self): """ This function called to create the start move. It will be generated based on the given values for start and angle. """ del (self.geos[:]) if g.config.machine_type == 'drag_knife': self.make_swivelknife_move() return #BaseEntitie created to add the StartMoves etc. This Entitie must not #be offset or rotated etc. BaseEntitie = EntitieContentClass(Nr=-1, Name='BaseEntitie', parent=None, children=[], p0=Point(x=0.0, y=0.0), pb=Point(x=0.0, y=0.0), sca=[1, 1, 1], rot=0.0) self.parent = BaseEntitie #Get the start rad. and the length of the line segment at begin. start_rad = self.shape.LayerContent.start_radius start_ver = start_rad #Get tool radius based on tool diameter. tool_rad = self.shape.LayerContent.tool_diameter / 2 #Calculate the starting point with and without compensation. start = self.startp angle = self.angle if self.shape.cut_cor == 40: self.geos.append(start) #Cutting Compensation Left elif self.shape.cut_cor == 41: #Center of the Starting Radius. Oein = start.get_arc_point(angle + pi / 2, start_rad + tool_rad) #Start Point of the Radius Pa_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad) #Start Point of the straight line segment at begin. Pg_ein = Pa_ein.get_arc_point(angle + pi / 2, start_ver) #Get the dive point for the starting contour and append it. start_ein = Pg_ein.get_arc_point(angle, tool_rad) self.geos.append(start_ein) #generate the Start Line and append it including the compensation. start_line = LineGeo(Pg_ein, Pa_ein) self.geos.append(start_line) #generate the start rad. and append it. start_rad = ArcGeo(Pa=Pa_ein, Pe=start, O=Oein, r=start_rad + tool_rad, direction=1) self.geos.append(start_rad) #Cutting Compensation Right elif self.shape.cut_cor == 42: #Center of the Starting Radius. Oein = start.get_arc_point(angle - pi / 2, start_rad + tool_rad) #Start Point of the Radius Pa_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad) #Start Point of the straight line segment at begin. Pg_ein = Pa_ein.get_arc_point(angle - pi / 2, start_ver) #Get the dive point for the starting contour and append it. start_ein = Pg_ein.get_arc_point(angle, tool_rad) self.geos.append(start_ein) #generate the Start Line and append it including the compensation. start_line = LineGeo(Pg_ein, Pa_ein) self.geos.append(start_line) #generate the start rad. and append it. start_rad = ArcGeo(Pa=Pa_ein, Pe=start, O=Oein, r=start_rad + tool_rad, direction=0) self.geos.append(start_rad)
def __init__(self, Ps=Point(), tan_a=0.0, Pb=Point, tan_b=0.0, min_r=1e-6): """ Std. method to initialise the class. @param Ps: Start Point for the Biarc @param tan_a: Tangent of the Start Point @param Pb: End Point of the Biarc @param tan_b: Tangent of the End Point @param min_r: The minimum radius of a arc section. """ min_len = 1e-12 #Min Abstand f�r doppelten Punkt / Minimum clearance for double point min_alpha = 1e-4 #Winkel ab welchem Gerade angenommen wird inr rad / Angle for which it is assumed straight inr rad max_r = 5e3 #Max Radius ab welchem Gerade angenommen wird (5m) / Max radius is assumed from which line (5m) min_r = min_r #Min Radius ab welchem nichts gemacht wird / Min radius beyond which nothing is done self.Ps = Ps self.tan_a = tan_a self.Pb = Pb self.tan_b = tan_b self.l = 0.0 self.shape = None self.geos = [] self.k = 0.0 #Errechnen der Winkel, L�nge und Shape #Calculate the angle, length and shape norm_angle, self.l = self.calc_normal(self.Ps, self.Pb) alpha, beta, self.teta, self.shape = self.calc_diff_angles(norm_angle, \ self.tan_a, \ self.tan_b, \ min_alpha) if(self.l < min_len): self.shape = "Zero" elif(self.shape == "LineGeo"): #Erstellen der Geometrie #Create the geometry self.shape = "LineGeo" self.geos.append(LineGeo(self.Ps, self.Pb)) else: #Berechnen der Radien, Mittelpunkte, Zwichenpunkt #Calculate the radii, midpoints Zwichenpunkt r1, r2 = self.calc_r1_r2(self.l, alpha, beta, self.teta) if (abs(r1) > max_r)or(abs(r2) > max_r): #Erstellen der Geometrie #Create the geometry self.shape = "LineGeo" self.geos.append(LineGeo(self.Ps, self.Pb)) return elif (abs(r1) < min_r)or(abs(r2) < min_r): self.shape = "Zero" return O1, O2, k = self.calc_O1_O2_k(r1, r2, self.tan_a, self.teta) #Berechnen der Start und End- Angles f�r das drucken #Calculate the start and end angles for the print s_ang1, e_ang1 = self.calc_s_e_ang(self.Ps, O1, k) s_ang2, e_ang2 = self.calc_s_e_ang(k, O2, self.Pb) #Berechnen der Richtung und der Extend #Calculate the direction and extent dir_ang1 = (tan_a - s_ang1) % (-2 * pi) dir_ang1 -= ceil(dir_ang1 / (pi)) * (2 * pi) dir_ang2 = (tan_b - e_ang2) % (-2 * pi) dir_ang2 -= ceil(dir_ang2 / (pi)) * (2 * pi) #Erstellen der Geometrien #Create the geometries self.geos.append(ArcGeo(Ps=self.Ps, Pe=k, O=O1, r=r1, \ s_ang=s_ang1, e_ang=e_ang1, direction=dir_ang1)) self.geos.append(ArcGeo(Ps=k, Pe=self.Pb, O=O2, r=r2, \ s_ang=s_ang2, e_ang=e_ang2, direction=dir_ang2))
def Read(self, caller): """ Read() """ #Assign short name lp = caller.line_pairs e = lp.index_both(0, "SEQEND", caller.start + 1) + 1 #Assign layer s = lp.index_code(8, caller.start + 1) self.Layer_Nr = caller.Get_Layer_Nr(lp.line_pair[s].value) #Ps=None for the first point Ps = None #Polyline flag s_temp = lp.index_code(70, s + 1, e) if s_temp == None: PolyLineFlag = 0 else: PolyLineFlag = int(lp.line_pair[s_temp].value) s = s_temp #print("PolylineFlag: %i" %PolyLineFlag) while 1: #and not(s==None): s = lp.index_both(0, "VERTEX", s + 1, e) if s == None: break #X Value s = lp.index_code(10, s + 1, e) x = float(lp.line_pair[s].value) #Y Value s = lp.index_code(20, s + 1, e) y = float(lp.line_pair[s].value) Pe = Point(x=x, y=y) #Bulge bulge = 0 e_vertex = lp.index_both(0, "VERTEX", s + 1, e) if e_vertex == None: e_vertex = e s_temp = lp.index_code(42, s + 1, e_vertex) #print('stemp: %s, e: %s, next 10: %s' %(s_temp,e,lp.index_both(0,"VERTEX",s+1,e))) if s_temp != None: bulge = float(lp.line_pair[s_temp].value) s = s_temp #Vertex flag (bit-coded); default is 0; 1 = Closed; 128 = Plinegen s_temp = lp.index_code(70, s + 1, e_vertex) if s_temp == None: VertexFlag = 0 else: VertexFlag = int(lp.line_pair[s_temp].value) s = s_temp #print("Vertex Flag: %i" %PolyLineFlag) #Assign the geometries for the Polyline if (VertexFlag != 16): if type(Ps) != type(None): if next_bulge == 0: self.geo.append(LineGeo(Ps=Ps, Pe=Pe)) else: #self.geo.append(LineGeo(Ps=Ps,Pe=Pe)) #print bulge self.geo.append(self.bulge2arc(Ps, Pe, next_bulge)) #L�nge drauf rechnen wenns eine Geometrie ist #Wenns Ldnge count on it is a geometry ??? self.length += self.geo[-1].length #Der Bulge wird immer f�r den und den n�chsten Punkt angegeben #The bulge is always given for the next point next_bulge = bulge Ps = Pe #It is a closed polyline if PolyLineFlag == 1: #print("sollten �bereinstimmen: %s, %s" %(Ps,Pe)) if next_bulge == 0: self.geo.append(LineGeo(Ps=Ps, Pe=self.geo[0].Ps)) else: self.geo.append(self.bulge2arc(Ps, self.geo[0].Ps, next_bulge)) #L�nge drauf rechnen wenns eine Geometrie ist #Wenns Ldnge count on it is a geometry ??? self.length += self.geo[-1].length #Neuen Startwert f�r die n�chste Geometrie zur�ckgeben #New starting value for the next geometry caller.start = e