def OnGlCommands(self, select, marked, no_color): if marked and not select: tool = Tool.FindTool(self.tool_number) if tool == None: return radius = tool.CuttingRadius(True) global circle_sketch global arc1 global arc2 # get 3d position from the point objects, sorted by distance from camera forwards = wx.GetApp( ).frame.graphics_canvas.viewport.view_point.Forwards() lens_point = wx.GetApp( ).frame.graphics_canvas.viewport.view_point.lens_point posns = [] for point in self.points: object = cad.GetObjectFromId(cad.OBJECT_TYPE_POINT, point) if object == None: continue pos = object.GetStartPoint() dotp = (lens_point - pos) * forwards posns.append(DotpAndPos(dotp, pos)) posns = sorted(posns) for dotp_and_pos in posns: pos = dotp_and_pos.pos p0 = pos + geom.Point3D(-radius, 0, 0) p1 = pos + geom.Point3D(radius, 0, 0) if circle_sketch == None: circle_sketch = cad.NewSketch() arc1 = cad.NewArc(p0, p1, geom.Point3D(0, 0, 1), pos) arc2 = cad.NewArc(p1, p0, geom.Point3D(0, 0, 1), pos) circle_sketch.Add(arc1) circle_sketch.Add(arc2) else: arc1.SetStartPoint(p0) arc1.SetEndPoint(p1) arc1.SetCentrePoint(pos) arc2.SetStartPoint(p1) arc2.SetEndPoint(p0) arc2.SetCentrePoint(pos) cad.Material(cad.Color(255, 255, 0)).glMaterial(1.0) cad.DrawEnableLighting() cad.DrawDisableDepthTesting() cad.DrawEnableCullFace() cad.Sketch.RenderAsExtrusion(circle_sketch, self.start_depth, self.final_depth) cad.DrawDisableCullFace() cad.DrawEnableDepthTesting() cad.DrawDisableLighting()
def AddPoint(self, d): if (self.drawing_mode == LineDrawingMode) or (self.drawing_mode == ArcDrawingMode): # edit the end of the previous item to be the start of the arc # this only happens if we are drawing tangents to other objects # really need to fill the gap with whatever we are tangent around # ellipse,arc,spline or whatever if (self.TempObject() != None) and (self.prev_object != None): if (self.prev_object != None): spos = self.TempObject().GetStartPoint() epos = self.prev_object.GetEndPoint() tanobject = self.start_pos.GetObject1() if self.start_pos.type == cad.DigitizeType.DIGITIZE_TANGENT_TYPE and ( tanobject != None): if tanobject.GetType() == cad.OBJECT_TYPE_SKETCH_LINE: #((HLine*)prev_object)->B = p; pass elif tanobject.GetType() == cad.OBJECT_TYPE_SKETCH_ARC: tanobject.A = geom.Point3D(spos) tanobject.B = geom.Point3D(epos) self.AddToTempObjects(tanobject) elif tanobject.GetType() == cad.OBJECT_TYPE_CIRCLE: arc = cad.NewArc(spos, epos, tanobject.axis, tanobject.C) arc.A = geom.Point3D(spos) arc.B = geom.Point3D(epos) self.AddToTempObjects(arc) Drawing.AddPoint(self, d)
def CalculateObround(self, p0, p1, xdir, zdir): lines_disappear = False if self.obround_radius > 0.0000000001: if p0 == p1: lines_disappear = True else: return good_num = 4 if lines_disappear: good_num = 2 if self.TempObject().GetNumChildren() != good_num: self.ClearSketch() if lines_disappear: # make two arcs, for a circle arcs = [None, None] if self.TempObject().GetNumChildren() > 0: object = self.TempObject().GetFirstChild() for i in range(0, 2): arcs[i] = object object = self.TempObject().GetNextChild() else: for i in range(0, 2): arcs[i] = cad.NewArc(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0), geom.Point3D(0,0,1), geom.Point3D(0,0,0)) self.TempObject().Add(arcs[i]) arcs[0].A = p0 + xdir * self.obround_radius arcs[0].B = p0 - xdir * self.obround_radius arcs[0].C = p0 arcs[0].axis = zdir arcs[1].A = arcs[0].B arcs[1].B = arcs[0].A arcs[1].C = arcs[0].C arcs[1].axis = arcs[0].axis else: # arc-line-arc-line arcs = [None, None] lines = [None, None] if self.TempObject().GetNumChildren() > 0: object = self.TempObject().GetFirstChild() for i in range(0, 2): arcs[i] = object object = self.TempObject().GetNextChild() lines[i] = object object = self.TempObject().GetNextChild() else: for i in range(0, 2): arcs[i] = cad.NewArc(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0), geom.Point3D(0,0,1), geom.Point3D(0,0,0)) self.TempObject().Add(arcs[i]) lines[i] = cad.NewLine(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0)) self.TempObject().Add(lines[i]) along_dir = p1 - p0 along_dir.Normalize() right_dir = along_dir ^ zdir arcs[0].A = p1 + right_dir * self.obround_radius arcs[0].B = p1 - right_dir * self.obround_radius arcs[0].C = p1 arcs[0].axis = zdir lines[0].A = arcs[0].B lines[0].B = p0 - right_dir * self.obround_radius arcs[1].A = lines[0].B arcs[1].B = p0 + right_dir * self.obround_radius arcs[1].C = p0 arcs[1].axis = zdir lines[1].A = arcs[1].B lines[1].B = arcs[0].A
def calculate_item(self, end): if self.number_of_steps( ) > 1 and self.start_pos.type == cad.DigitizeType.DIGITIZE_NO_ITEM_TYPE: return False if end.type == cad.DigitizeType.DIGITIZE_NO_ITEM_TYPE: return False if self.drawing_mode == LineDrawingMode: if self.TempObject() != None and self.TempObject().GetType( ) != cad.OBJECT_TYPE_SKETCH_LINE: self.ClearObjectsMade() #DigitizeMode::GetLinePoints(GetStartPos(), end, p1, p2); p1 = self.start_pos.point p2 = end.point if p1 == p2: return False end.point = p2 if self.TempObject() == None: self.AddToTempObjects(cad.NewLine(p1, p2)) else: self.TempObject().A = p1 self.TempObject().B = p2 return True elif self.drawing_mode == ArcDrawingMode: # tangential arcs if (self.TempObject() != None) and (self.TempObject().GetType() != cad.OBJECT_TYPE_SKETCH_ARC): self.ClearObjectsMade() #Point3d centre; #Point3d axis; #Point3d p1, p2; #bool arc_found = DigitizeMode::GetArcPoints(GetStartPos(), m_previous_direction_set ? (&m_previous_direction) : NULL, end, p1, p2, centre, axis); arc_found = True p1 = self.start_pos.point p2 = end.point if p1 == p2: return False if self.previous_direction == None: return False if arc_found: tangent_arc_found, centre, axis = cad.TangentialArc( p1, self.previous_direction, p2) if tangent_arc_found: # arc if self.TempObject() == None: self.AddToTempObjects(cad.NewArc(p1, p2, axis, centre)) else: self.TempObject().axis = axis self.TempObject().C = centre self.TempObject().A = p1 self.TempObject().B = p2 else: # line if (self.TempObject() != None) and self.TempObject( ).GetType() != cad.OBJECT_TYPE_SKETCH_LINE: self.ClearObjectsMade() if self.TempObject() == None: self.AddToTempObjects(cad.NewLine(p1, p2)) else: self.TempObject().A = p1 self.TempObject().B = p2 return True elif self.drawing_mode == ILineDrawingMode: if self.TempObject( ) and self.TempObject().GetType() != cad.OBJECT_TYPE_ILINE: self.ClearObjectsMade() #DigitizeMode::GetLinePoints(GetStartPos(), end, p1, p2); p1 = self.start_pos.point p2 = end.point if p1 == p2: return False if self.TempObject() == None: new_object = cad.ILine(p1, p2) cad.PyIncref(new_object) self.AddToTempObjects(new_object) else: self.TempObject().A = p1 self.TempObject().B = p2 return True elif self.drawing_mode == CircleDrawingMode: if self.TempObject( ) and self.TempObject().GetType() != cad.OBJECT_TYPE_CIRCLE: self.ClearObjectsMade() if self.circle_mode == CentreAndPointCircleMode: # Point3d p1, p2, centre; # Point3d axis; # DigitizeMode::GetArcPoints(GetStartPos(), NULL, end, p1, p2, centre, axis); p1 = self.start_pos.point p2 = end.point self.radius_for_circle = p1.Dist(p2) if self.TempObject() == None: self.AddToTempObjects( cad.NewCircle(p1, geom.Point3D(0, 0, 1), self.radius_for_circle)) else: self.TempObject().C = p1 self.TempObject().radius = self.radius_for_circle return True elif self.circle_mode == ThreePointsCircleMode: if self.draw_step == 1: # add a line for graphics if self.TempObject() == None: self.AddToTempObjects( cad.NewLine(self.start_pos.point, end.point)) else: self.TempObject().A = self.start_pos.point self.TempObject().B = end.point else: # draw_step = 2 # add the circle found, c = cad.GetTangentCircle(self.before_start_pos, self.start_pos, end) if self.TempObject() == None: self.AddToTempObjects( cad.NewCircle(geom.Point3D(c.c.x, c.c.y, 0.0), geom.Point3D(0, 0, 1), c.radius)) else: self.TempObject().SetCircle(c) return True elif self.circle_mode == TwoPointsCircleMode: found, c = cad.GetCircleBetween(self.start_pos, end) if found: if self.TempObject() == None: self.AddToTempObjects( cad.NewCircle(geom.Point3D(c.c.x, c.c.y, 0.0), geom.Point3D(0, 0, 1), c.radius)) else: self.TempObject().SetCircle(c) return True elif self.circle_mode == CentreAndRadiusCircleMode: if self.TempObject() == None: self.AddToTempObjects( cad.NewCircle(end.point, geom.Point3D(0, 0, 1), self.radius_for_circle)) else: self.TempObject().C = end.point self.TempObject().radius = self.radius_for_circle return True
def CalculateRectangle(self, x, y, p0, p1, p2, p3, xdir, ydir, zdir): radii_wanted = False x_lines_disappear = False y_lines_disappear = False if self.rect_radius > 0.0000000001: if math.fabs(x) - self.rect_radius*2 > -0.0000000001 and math.fabs(y) - self.rect_radius*2 > -0.0000000001: radii_wanted = True if math.fabs(math.fabs(x) - self.rect_radius*2) < 0.0000000001: x_lines_disappear = True if math.fabs(math.fabs(y) - self.rect_radius*2) < 0.0000000001: y_lines_disappear = True good_num = 4 if radii_wanted: if x_lines_disappear and y_lines_disappear: good_num = 2 elif x_lines_disappear or y_lines_disappear: good_num = 4 else: good_num = 8 if self.TempObject().GetNumChildren() != good_num: self.ClearSketch() # check first item elif self.TempObject().GetFirstChild().GetType() != (cad.OBJECT_TYPE_SKETCH_ARC if radii_wanted else cad.OBJECT_TYPE_SKETCH_LINE): self.ClearSketch() if radii_wanted: if x_lines_disappear and y_lines_disappear: # make two arcs, for a circle arcs = [None, None] if self.TempObject().GetNumChildren() > 0: object = self.TempObject().GetFirstChild() for i in range(0, 2): arcs[i] = object; object = self.TempObject().GetNextChild() else: for i in range(0, 2): arcs[i] = cad.NewArc(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0), geom.Point3D(0,0,1), geom.Point3D(0,0,0)) self.TempObject().Add(arcs[i], None) arcs[0].A = p0 + xdir * self.rect_radius arcs[0].B = p3 + xdir * self.rect_radius arcs[0].C = p0 + xdir * self.rect_radius + ydir * self.rect_radius arcs[0].axis = zdir arcs[1].A = arcs[0].B arcs[1].B = arcs[0].A arcs[1].C = arcs[0].C arcs[1].axis = arcs[0].axis elif x_lines_disappear or y_lines_disappear: # arc-line-arc-line arcs = [None, None] lines = [None, None] if self.TempObject().GetNumChildren() > 0: object = self.TempObject().GetFirstChild() for i in range( 0, 2): arcs[i] = object object = self.TempObject().GetNextChild() lines[i] = object object = self.TempObject().GetNextChild() else: for i in range( 0, 2): arcs[i] = cad.NewArc(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0), geom.Point3D(0,0,1), geom.Point3D(0,0,0)) self.TempObject().Add(arcs[i], None) lines[i] = cad.NewLine(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0)) self.TempObject().Add(lines[i], None) if x_lines_disappear: arcs[0].A = p2 - ydir * self.rect_radius arcs[0].B = p3 - ydir * self.rect_radius arcs[0].C = p3 + xdir * self.rect_radius - ydir * self.rect_radius arcs[0].axis = zdir lines[0].A = arcs[0].B lines[0].B = p0 + ydir * self.rect_radius arcs[1].A = lines[0].B arcs[1].B = p1 + ydir * self.rect_radius arcs[1].C = p0 + xdir * self.rect_radius + ydir * self.rect_radius arcs[1].axis = arcs[0].axis lines[1].A = arcs[1].B lines[1].B = arcs[0].A else: arcs[0].A = p1 - xdir * self.rect_radius arcs[0].B = p2 - xdir * self.rect_radius arcs[0].C = p1 - xdir * self.rect_radius + ydir * self.rect_radius arcs[0].axis = zdir lines[0].A = arcs[0].B lines[0].B = p3 + xdir * self.rect_radius arcs[1].A = lines[0].B arcs[1].B = p0 + xdir * self.rect_radius arcs[1].C = p0 + xdir * self.rect_radius + ydir * self.rect_radius arcs[1].axis = zdir lines[1].A = arcs[1].B lines[1].B = arcs[0].A else: # arc-line-arc-line-arc-line-arc-line lines = [None, None, None, None] arcs = [None, None, None, None] if self.TempObject().GetNumChildren() > 0: object = self.TempObject().GetFirstChild() for i in range(0, 4): arcs[i] = object object = self.TempObject().GetNextChild() lines[i] = object object = self.TempObject().GetNextChild() else: for i in range(0, 4): arcs[i] = cad.NewArc(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0), geom.Point3D(0,0,1), geom.Point3D(0,0,0)) self.TempObject().Add(arcs[i], None) lines[i] = cad.NewLine(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0)) self.TempObject().Add(lines[i], None) arcs[0].A = p1 - xdir * self.rect_radius arcs[0].B = p1 + ydir * self.rect_radius arcs[0].C = p1 - xdir * self.rect_radius + ydir * self.rect_radius arcs[0].axis = zdir lines[0].A = arcs[0].B lines[0].B = p2 - ydir * self.rect_radius arcs[1].A = lines[0].B arcs[1].B = p2 - xdir * self.rect_radius arcs[1].C = p2 - xdir * self.rect_radius - ydir * self.rect_radius arcs[1].axis = zdir lines[1].A = arcs[1].B lines[1].B = p3 + xdir * self.rect_radius arcs[2].A = lines[1].B arcs[2].B = p3 - ydir * self.rect_radius arcs[2].C = p3 + xdir * self.rect_radius - ydir * self.rect_radius arcs[2].axis = zdir lines[2].A = arcs[2].B lines[2].B = p0 + ydir * self.rect_radius arcs[3].A = lines[2].B arcs[3].B = p0 + xdir * self.rect_radius arcs[3].C = p0 + xdir * self.rect_radius + ydir * self.rect_radius arcs[3].axis = zdir lines[3].A = arcs[3].B lines[3].B = arcs[0].A else: # line-line-line-line lines = [None, None, None, None] if self.TempObject().GetNumChildren() > 0: object = self.TempObject().GetFirstChild() for i in range(0, 4): lines[i] = object object = self.TempObject().GetNextChild() else: for i in range(0, 4): lines[i] = cad.NewLine(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0)) self.TempObject().Add(lines[i]) lines[0].A = p0 lines[0].B = p1 lines[1].A = p1 lines[1].B = p2 lines[2].A = p2 lines[2].B = p3 lines[3].A = p3 lines[3].B = p0