def __init__(self, Ps, Pe): """ Standard Method to initialize the LineGeo. @param Ps: The Start Point of the line @param Pe: the End Point of the line """ LineGeo.__init__(self, Ps=Ps, Pe=Pe)
def Write_GCode(self, PostPro): """ Writes the GCODE for a Break. @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, 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, PostPro) + PostPro.chg_feed_rate(self.zfeed) + PostPro.lin_pol_z(oldZ) + PostPro.chg_feed_rate(oldFeed))
def breakLineGeo(self, lineGeo): """ 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 = Geos([]) for breakLayer in self.breakLayers: for breakShape in breakLayer.shapes.not_disabled_iter(): 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))) newGeos.append(BreakGeo(near, far, breakShape.axis3_mill_depth, breakShape.f_g1_plane, breakShape.f_g1_depth)) newGeos.extend(self.breakLineGeo(LineGeo(far, lineGeo.Pe))) return newGeos return [lineGeo]
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 is not 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() """ 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 isinstance(NewCurve[-2], LineGeo) and isinstance( NewCurve[-1], 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 compress_lines(self, Curve): """ compress_lines() """ 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 isinstance(NewCurve[-2], LineGeo) and isinstance(NewCurve[-1], 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.distance(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 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. """ self.geos = Geos([]) if g.config.machine_type == 'drag_knife': self.make_swivelknife_move() return # Get the start rad. and the length of the line segment at begin. start_rad = self.shape.parentLayer.start_radius # Get tool radius based on tool diameter. tool_rad = self.shape.parentLayer.getToolRadius() # Calculate the starting point with and without compensation. start = self.start angle = self.angle if self.shape.cut_cor == 40: self.append(RapidPos(start)) elif self.shape.cut_cor != 40 and not g.config.vars.Cutter_Compensation[ "done_by_machine"]: toolwidth = self.shape.parentLayer.getToolRadius() offtype = "in" if self.shape.cut_cor == 42 else "out" offshape = offShapeClass(parent=self.shape, offset=toolwidth, offtype=offtype) if len(offshape.rawoff) > 0: start, angle = offshape.rawoff[0].get_start_end_points( True, True) self.append(RapidPos(start)) self.geos += offshape.rawoff # 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 Ps_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad) # Start Point of the straight line segment at begin. Pg_ein = Ps_ein.get_arc_point(angle + pi / 2, start_rad) # Get the dive point for the starting contour and append it. start_ein = Pg_ein.get_arc_point(angle, tool_rad) self.append(RapidPos(start_ein)) # generate the Start Line and append it including the compensation. start_line = LineGeo(start_ein, Ps_ein) self.append(start_line) # generate the start rad. and append it. start_rad = ArcGeo(Ps=Ps_ein, Pe=start, O=Oein, r=start_rad + tool_rad, direction=1) self.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 Ps_ein = Oein.get_arc_point(angle + pi, start_rad + tool_rad) # Start Point of the straight line segment at begin. Pg_ein = Ps_ein.get_arc_point(angle - pi / 2, start_rad) # Get the dive point for the starting contour and append it. start_ein = Pg_ein.get_arc_point(angle, tool_rad) self.append(RapidPos(start_ein)) # generate the Start Line and append it including the compensation. start_line = LineGeo(start_ein, Ps_ein) self.append(start_line) # generate the start rad. and append it. start_rad = ArcGeo(Ps=Ps_ein, Pe=start, O=Oein, r=start_rad + tool_rad, direction=0) self.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.theta, 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.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.theta) 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.theta) # 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 __init__(self, Ps, Pe, height, xyfeed, zfeed): LineGeo.__init__(self, Ps, Pe) self.height = height self.xyfeed = xyfeed self.zfeed = zfeed
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 is None: PolyLineFlag = 0 else: PolyLineFlag = int(lp.line_pair[s_temp].value) s = s_temp # print("PolylineFlag: %i" %PolyLineFlag) while 1: # and s is not 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, y) # Bulge bulge = 0 e_vertex = lp.index_both(0, "VERTEX", s + 1, e) if e_vertex is 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 is not 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 is 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 Ps is not 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
def make_own_cutter_compensation(self): toolwidth = self.shape.parentLayer.getToolRadius() geos = Geos([]) direction = -1 if self.shape.cut_cor == 41 else 1 if self.shape.closed: end, end_dir = self.shape.get_start_end_points(False, False) end_proj = Point(direction * end_dir.y, -direction * end_dir.x) prv_Pe = end + toolwidth * end_proj else: prv_Pe = None for geo_nr, geo in enumerate(self.shape.geos.abs_iter()): start, start_dir = geo.get_start_end_points(True, False) end, end_dir = geo.get_start_end_points(False, False) start_proj = Point(direction * start_dir.y, -direction * start_dir.x) end_proj = Point(direction * end_dir.y, -direction * end_dir.x) Ps = start + toolwidth * start_proj Pe = end + toolwidth * end_proj if Ps == Pe: continue if prv_Pe: r = geo.Ps.distance(Ps) d = (prv_Pe - geo.Ps).to3D().cross_product( (Ps - geo.Ps).to3D()).z if direction * d > 0 and prv_Pe != Ps: geos.append( ArcGeo(Ps=prv_Pe, Pe=Ps, O=geo.Ps, r=r, direction=d)) geos[-1].geo_nr = geo_nr # else: # geos.append(LineGeo(Ps=prv_Pe, Pe=Ps)) if isinstance(geo, LineGeo): geos.append(LineGeo(Ps, Pe)) geos[-1].geo_nr = geo_nr elif isinstance(geo, ArcGeo): O = geo.O r = O.distance(Ps) geos.append(ArcGeo(Ps=Ps, Pe=Pe, O=O, r=r, direction=geo.ext)) geos[-1].geo_nr = geo_nr # TODO other geos are not supported; disable them in gui for this option # else: # geos.append(geo) prv_Pe = Pe tot_length = 0 for geo in geos.abs_iter(): tot_length += geo.length reorder_shape = False for start_geo_nr in range(len(geos)): # if shape is not closed we may only remove shapes from the start last_geo_nr = start_geo_nr if self.shape.closed else 0 geos_adj = deepcopy(geos[start_geo_nr:]) + deepcopy( geos[:last_geo_nr]) new_geos = Geos([]) i = 0 while i in range(len(geos_adj)): geo = geos_adj[i] intersections = [] for j in range(i + 1, len(geos_adj)): intersection = Intersect.get_intersection_point( geos_adj[j], geos_adj[i]) if intersection and intersection != geos_adj[i].Ps: intersections.append([j, intersection]) if len(intersections) > 0: intersection = intersections[-1] change_end_of_geo = True if i == 0 and intersection[0] >= len(geos_adj) // 2: geo.update_start_end_points(True, intersection[1]) geos_adj[intersection[0]].update_start_end_points( False, intersection[1]) if len(intersections) > 1: intersection = intersections[-2] else: change_end_of_geo = False i += 1 if change_end_of_geo: geo.update_start_end_points(False, intersection[1]) i = intersection[0] geos_adj[i].update_start_end_points( True, intersection[1]) else: i += 1 # TODO # if len(new_geos) > 0 and not new_geos[-1].Pe.eq(geo.Ps, g.config.fitting_tolerance): # break # geo is disconnected new_geos.append(geo) if new_geos[0].Ps == new_geos[-1].Pe: break new_length = 0 for geo in new_geos: new_length += geo.length if tot_length * g.config.vars.Cutter_Compensation['min_length_considered']\ <= new_length <= tot_length * g.config.vars.Cutter_Compensation['max_length_considered'] and\ (not g.config.vars.Cutter_Compensation['direction_maintained'] or not self.shape.closed or self.shape.isDirectionOfGeosCCW(new_geos) != self.shape.cw): self.append(RapidPos(new_geos[0].Ps)) for geo in new_geos: if geo.Ps != geo.Pe: self.append(geo) reorder_shape = True break if reorder_shape and self.shape.closed: # we do not reorder the original shape if it's not closed self.shape.geos = Geos( self.shape.geos[geos[start_geo_nr].geo_nr:] + self.shape.geos[:geos[start_geo_nr].geo_nr]) if len(self.geos) == 0: self.append(RapidPos(self.start))
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) # Ps=None for the first point Ps = 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 is 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 is 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 is not 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 Ps is not 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 # The bulge is always given for the next point next_bulge = bulge Ps = Pe if LWPLClosed == 1 or LWPLClosed == 129: # print("sollten �bereinstimmen: %s, %s" %(Ps,Pe)) if next_bulge: self.geo.append(self.bulge2arc(Ps, self.geo[0].Ps, next_bulge)) else: self.geo.append(LineGeo(Ps=Ps, Pe=self.geo[0].Ps)) self.length += self.geo[-1].length # New starting value for the next geometry caller.start = e