Draft: move getDXF to draftfunctions submodule
Update the appropriate interface in `Draft.py`.
This commit is contained in:
@@ -86,6 +86,7 @@ SET(Draft_functions
|
|||||||
draftfunctions/cut.py
|
draftfunctions/cut.py
|
||||||
draftfunctions/downgrade.py
|
draftfunctions/downgrade.py
|
||||||
draftfunctions/draftify.py
|
draftfunctions/draftify.py
|
||||||
|
draftfunctions/dxf.py
|
||||||
draftfunctions/extrude.py
|
draftfunctions/extrude.py
|
||||||
draftfunctions/fuse.py
|
draftfunctions/fuse.py
|
||||||
draftfunctions/heal.py
|
draftfunctions/heal.py
|
||||||
|
|||||||
@@ -91,13 +91,14 @@ from draftutils.utils import (string_encode_coin,
|
|||||||
svg_patterns,
|
svg_patterns,
|
||||||
svgpatterns,
|
svgpatterns,
|
||||||
get_rgb,
|
get_rgb,
|
||||||
getrgb,
|
getrgb)
|
||||||
get_DXF,
|
|
||||||
getDXF)
|
|
||||||
|
|
||||||
from draftfunctions.svg import (get_svg,
|
from draftfunctions.svg import (get_svg,
|
||||||
getSVG)
|
getSVG)
|
||||||
|
|
||||||
|
from draftfunctions.dxf import (get_dxf,
|
||||||
|
getDXF)
|
||||||
|
|
||||||
from draftutils.gui_utils import (get3DView,
|
from draftutils.gui_utils import (get3DView,
|
||||||
get_3d_view,
|
get_3d_view,
|
||||||
autogroup,
|
autogroup,
|
||||||
|
|||||||
128
src/Mod/Draft/draftfunctions/dxf.py
Normal file
128
src/Mod/Draft/draftfunctions/dxf.py
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
# -*- coding: utf8 -*-
|
||||||
|
# ***************************************************************************
|
||||||
|
# * Copyright (c) 2009 Yorik van Havre <yorik@uncreated.net> *
|
||||||
|
# * Copyright (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
|
||||||
|
# * *
|
||||||
|
# * This program is free software; you can redistribute it and/or modify *
|
||||||
|
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||||
|
# * as published by the Free Software Foundation; either version 2 of *
|
||||||
|
# * the License, or (at your option) any later version. *
|
||||||
|
# * for detail see the LICENCE text file. *
|
||||||
|
# * *
|
||||||
|
# * This program is distributed in the hope that it will be useful, *
|
||||||
|
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
# * GNU Library General Public License for more details. *
|
||||||
|
# * *
|
||||||
|
# * You should have received a copy of the GNU Library General Public *
|
||||||
|
# * License along with this program; if not, write to the Free Software *
|
||||||
|
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||||
|
# * USA *
|
||||||
|
# * *
|
||||||
|
# ***************************************************************************
|
||||||
|
"""Provides functions to return the DXF representation of various shapes."""
|
||||||
|
## @package dxf
|
||||||
|
# \ingroup draftfuctions
|
||||||
|
# \brief Provides functions to return the SVG representation of 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
|
||||||
|
|
||||||
|
# Delay import of module until first use because it is heavy
|
||||||
|
Part = lz.LazyLoader("Part", globals(), "Part")
|
||||||
|
DraftGeomUtils = lz.LazyLoader("DraftGeomUtils", globals(), "DraftGeomUtils")
|
||||||
|
Drawing = lz.LazyLoader("Drawing", globals(), "Drawing")
|
||||||
|
|
||||||
|
|
||||||
|
## \addtogroup draftfuctions
|
||||||
|
# @{
|
||||||
|
|
||||||
|
def _get_proj(vec, plane=None):
|
||||||
|
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("Drawing::View")
|
||||||
|
or 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.Plane()
|
||||||
|
plane.alignToPointAndAxis(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":
|
||||||
|
# Only for App::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'):
|
||||||
|
# TODO do this the Draft way, for ex. using polylines and rectangles
|
||||||
|
if not direction:
|
||||||
|
direction = App.Vector(0, 0, -1)
|
||||||
|
|
||||||
|
if DraftVecUtils.isNull(direction):
|
||||||
|
direction = App.Vector(0, 0, -1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
d = Drawing.projectToDXF(obj.Shape, direction)
|
||||||
|
except:
|
||||||
|
_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,
|
||||||
|
projection=None):
|
||||||
|
"""Return DXF string of the object. DEPRECATED. Use 'get_dxf'."""
|
||||||
|
utils.use_instead("get_dxf")
|
||||||
|
return get_dxf(obj,
|
||||||
|
projection=projection)
|
||||||
|
|
||||||
|
## @}
|
||||||
@@ -40,6 +40,7 @@ this object should no longer be available.
|
|||||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||||
|
|
||||||
import draftfunctions.svg as get_svg
|
import draftfunctions.svg as get_svg
|
||||||
|
import draftfunctions.dxf as get_dxf
|
||||||
import draftutils.utils as utils
|
import draftutils.utils as utils
|
||||||
import draftutils.groups as groups
|
import draftutils.groups as groups
|
||||||
|
|
||||||
@@ -182,7 +183,7 @@ class DrawingView(DraftObject):
|
|||||||
|
|
||||||
def getDXF(self, obj):
|
def getDXF(self, obj):
|
||||||
"""Return a DXF fragment."""
|
"""Return a DXF fragment."""
|
||||||
return utils.getDXF(obj)
|
return get_dxf.get_dxf(obj)
|
||||||
|
|
||||||
|
|
||||||
# Alias for compatibility with v0.18 and earlier
|
# Alias for compatibility with v0.18 and earlier
|
||||||
|
|||||||
@@ -786,75 +786,6 @@ def get_rgb(color, testbw=True):
|
|||||||
getrgb = get_rgb
|
getrgb = get_rgb
|
||||||
|
|
||||||
|
|
||||||
def get_DXF(obj,direction=None):
|
|
||||||
"""getDXF(object,[direction]): returns a DXF entity from the given
|
|
||||||
object. If direction is given, the object is projected in 2D."""
|
|
||||||
plane = None
|
|
||||||
result = ""
|
|
||||||
if obj.isDerivedFrom("Drawing::View") or obj.isDerivedFrom("TechDraw::DrawView"):
|
|
||||||
if obj.Source.isDerivedFrom("App::DocumentObjectGroup"):
|
|
||||||
for o in obj.Source.Group:
|
|
||||||
result += getDXF(o,obj.Direction)
|
|
||||||
else:
|
|
||||||
result += getDXF(obj.Source,obj.Direction)
|
|
||||||
return result
|
|
||||||
if direction:
|
|
||||||
if isinstance(direction, App.Vector):
|
|
||||||
import WorkingPlane
|
|
||||||
if direction != App.Vector(0,0,0):
|
|
||||||
plane = WorkingPlane.Plane()
|
|
||||||
plane.alignToPointAndAxis(App.Vector(0,0,0), direction)
|
|
||||||
|
|
||||||
def getProj(vec):
|
|
||||||
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)
|
|
||||||
|
|
||||||
if getType(obj) in ["Dimension","LinearDimension"]:
|
|
||||||
p1 = getProj(obj.Start)
|
|
||||||
p2 = getProj(obj.End)
|
|
||||||
p3 = getProj(obj.Dimline)
|
|
||||||
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 getType(obj) == "Annotation":
|
|
||||||
p = getProj(obj.Position)
|
|
||||||
count = 0
|
|
||||||
for t in obj.LabeLtext:
|
|
||||||
result += "0\nTEXT\n8\n0\n62\n0\n"
|
|
||||||
result += "10\n"+str(p.x)+"\n20\n"+str(p.y+count)+"\n30\n"+str(p.z)+"\n"
|
|
||||||
result += "40\n1\n"
|
|
||||||
result += "1\n"+str(t)+"\n"
|
|
||||||
result += "7\nSTANDARD\n"
|
|
||||||
count += 1
|
|
||||||
|
|
||||||
elif hasattr(obj,'Shape'):
|
|
||||||
# TODO do this the Draft way, for ex. using polylines and rectangles
|
|
||||||
import Drawing
|
|
||||||
import DraftVecUtils
|
|
||||||
if not direction:
|
|
||||||
direction = App.Vector(0,0,-1)
|
|
||||||
if DraftVecUtils.isNull(direction):
|
|
||||||
direction = App.Vector(0,0,-1)
|
|
||||||
try:
|
|
||||||
d = Drawing.projectToDXF(obj.Shape,direction)
|
|
||||||
except:
|
|
||||||
print("Draft.getDXF: Unable to project ",obj.Label," to ",direction)
|
|
||||||
else:
|
|
||||||
result += d
|
|
||||||
|
|
||||||
else:
|
|
||||||
print("Draft.getDXF: Unsupported object: ",obj.Label)
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
getDXF = get_DXF
|
|
||||||
|
|
||||||
|
|
||||||
def filter_objects_for_modifiers(objects, isCopied=False):
|
def filter_objects_for_modifiers(objects, isCopied=False):
|
||||||
filteredObjects = []
|
filteredObjects = []
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
|
|||||||
Reference in New Issue
Block a user