| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | """Provides functions to return the DXF representation of various shapes.""" |
| | |
| | |
| | |
| |
|
| | import lazy_loader.lazy_loader as lz |
| |
|
| | import FreeCAD as App |
| | import DraftVecUtils |
| | import WorkingPlane |
| | import draftutils.utils as utils |
| |
|
| | from draftutils.messages import _wrn |
| |
|
| | |
| | Part = lz.LazyLoader("Part", globals(), "Part") |
| | DraftGeomUtils = lz.LazyLoader("DraftGeomUtils", globals(), "DraftGeomUtils") |
| | TechDraw = lz.LazyLoader("TechDraw", globals(), "TechDraw") |
| |
|
| |
|
| | |
| | |
| |
|
| |
|
| | def _get_proj(vec, plane=None): |
| | """Get a projection of the vector in the plane's u and v directions. |
| | |
| | TODO: check if the same function for SVG and DXF projection can be used |
| | so that this function is not just duplicated code. |
| | This function may also be present elsewhere, like `WorkingPlane` |
| | or `DraftGeomUtils`, so we should avoid code duplication. |
| | """ |
| | if not plane: |
| | return vec |
| |
|
| | nx = DraftVecUtils.project(vec, plane.u) |
| | ny = DraftVecUtils.project(vec, plane.v) |
| | return App.Vector(nx.Length, ny.Length, 0) |
| |
|
| |
|
| | def get_dxf(obj, direction=None): |
| | """Return a DXF entity from the given object. |
| | |
| | If direction is given, the object is projected in 2D. |
| | """ |
| | plane = None |
| | result = "" |
| | if obj.isDerivedFrom("TechDraw::DrawView"): |
| | if obj.Source.isDerivedFrom("App::DocumentObjectGroup"): |
| | for o in obj.Source.Group: |
| | result += get_dxf(o, obj.Direction) |
| | else: |
| | result += get_dxf(obj.Source, obj.Direction) |
| | return result |
| |
|
| | if direction and isinstance(direction, App.Vector): |
| | if direction != App.Vector(0, 0, 0): |
| | plane = WorkingPlane.PlaneBase() |
| | plane.align_to_point_and_axis(App.Vector(0, 0, 0), direction) |
| |
|
| | if utils.get_type(obj) in ("Dimension", "LinearDimension"): |
| | p1 = _get_proj(obj.Start, plane=plane) |
| | p2 = _get_proj(obj.End, plane=plane) |
| | p3 = _get_proj(obj.Dimline, plane=plane) |
| | result += "0\nDIMENSION\n8\n0\n62\n0\n3\nStandard\n70\n1\n" |
| | result += "10\n" + str(p3.x) + "\n20\n" + str(p3.y) + "\n30\n" + str(p3.z) + "\n" |
| | result += "13\n" + str(p1.x) + "\n23\n" + str(p1.y) + "\n33\n" + str(p1.z) + "\n" |
| | result += "14\n" + str(p2.x) + "\n24\n" + str(p2.y) + "\n34\n" + str(p2.z) + "\n" |
| |
|
| | elif utils.get_type(obj) == "Annotation": |
| | |
| | p = _get_proj(obj.Position, plane=plane) |
| | count = 0 |
| | for t in obj.LabeLtext: |
| | result += "0\nTEXT\n8\n0\n62\n0\n" |
| | result += "10\n" |
| | result += str(p.x) + "\n20\n" |
| | result += str(p.y + count) + "\n30\n" |
| | result += str(p.z) + "\n" |
| | result += "40\n1\n" |
| | result += "1\n" + str(t) + "\n" |
| | result += "7\nSTANDARD\n" |
| | count += 1 |
| |
|
| | elif hasattr(obj, "Shape"): |
| | |
| | if not direction: |
| | direction = App.Vector(0, 0, -1) |
| |
|
| | if DraftVecUtils.isNull(direction): |
| | direction = App.Vector(0, 0, -1) |
| |
|
| | try: |
| | d = TechDraw.projectToDXF(obj.Shape, direction) |
| | except Exception: |
| | |
| | |
| | _wrn("get_dxf: " "unable to project '{}' to {}".format(obj.Label, direction)) |
| | else: |
| | result += d |
| | else: |
| | _wrn("get_dxf: unsupported object, '{}'".format(obj.Label)) |
| |
|
| | return result |
| |
|
| |
|
| | def getDXF(obj, direction=None): |
| | """Return DXF string of the object. DEPRECATED. Use 'get_dxf'.""" |
| | utils.use_instead("get_dxf") |
| | return get_dxf(obj, direction=direction) |
| |
|
| |
|
| | |
| |
|