Draft: split DrawingView from Draft.py
This commit is contained in:
committed by
Yorik van Havre
parent
b1e2574f1c
commit
95fe3076bd
@@ -88,6 +88,7 @@ SET(Draft_make_functions
|
||||
draftmake/make_circle.py
|
||||
draftmake/make_clone.py
|
||||
draftmake/make_copy.py
|
||||
draftmake/make_drawingview.py
|
||||
draftmake/make_ellipse.py
|
||||
draftmake/make_facebinder.py
|
||||
draftmake/make_fillet.py
|
||||
@@ -115,6 +116,7 @@ SET(Draft_objects
|
||||
draftobjects/circulararray.py
|
||||
draftobjects/circle.py
|
||||
draftobjects/clone.py
|
||||
draftobjects/drawingview.py
|
||||
draftobjects/ellipse.py
|
||||
draftobjects/facebinder.py
|
||||
draftobjects/orthoarray.py
|
||||
|
||||
@@ -255,6 +255,10 @@ from draftviewproviders.view_draftlink import _ViewProviderDraftLink
|
||||
from draftmake.make_circle import make_circle, makeCircle
|
||||
from draftobjects.circle import Circle, _Circle
|
||||
|
||||
# drawing: view NOTE: Obsolete since Drawing was substituted bu TechDraw
|
||||
from draftmake.make_drawingview import make_drawing_view, makeDrawingView
|
||||
from draftobjects.drawingview import DrawingView, _DrawingView
|
||||
|
||||
# arcs
|
||||
from draftmake.make_arc_3points import make_arc_3points
|
||||
|
||||
@@ -428,126 +432,5 @@ def convertDraftTexts(textslist=[]):
|
||||
for n in todelete:
|
||||
FreeCAD.ActiveDocument.removeObject(n)
|
||||
|
||||
def makeDrawingView(obj,page,lwmod=None,tmod=None,otherProjection=None):
|
||||
"""
|
||||
makeDrawingView(object,page,[lwmod,tmod]) - adds a View of the given object to the
|
||||
given page. lwmod modifies lineweights (in percent), tmod modifies text heights
|
||||
(in percent). The Hint scale, X and Y of the page are used.
|
||||
"""
|
||||
if not FreeCAD.ActiveDocument:
|
||||
FreeCAD.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
if getType(obj) == "SectionPlane":
|
||||
import ArchSectionPlane
|
||||
viewobj = FreeCAD.ActiveDocument.addObject("Drawing::FeatureViewPython","View")
|
||||
page.addObject(viewobj)
|
||||
ArchSectionPlane._ArchDrawingView(viewobj)
|
||||
viewobj.Source = obj
|
||||
viewobj.Label = "View of "+obj.Name
|
||||
elif getType(obj) == "Panel":
|
||||
import ArchPanel
|
||||
viewobj = ArchPanel.makePanelView(obj,page)
|
||||
else:
|
||||
viewobj = FreeCAD.ActiveDocument.addObject("Drawing::FeatureViewPython","View"+obj.Name)
|
||||
_DrawingView(viewobj)
|
||||
page.addObject(viewobj)
|
||||
if (otherProjection):
|
||||
if hasattr(otherProjection,"Scale"):
|
||||
viewobj.Scale = otherProjection.Scale
|
||||
if hasattr(otherProjection,"X"):
|
||||
viewobj.X = otherProjection.X
|
||||
if hasattr(otherProjection,"Y"):
|
||||
viewobj.Y = otherProjection.Y
|
||||
if hasattr(otherProjection,"Rotation"):
|
||||
viewobj.Rotation = otherProjection.Rotation
|
||||
if hasattr(otherProjection,"Direction"):
|
||||
viewobj.Direction = otherProjection.Direction
|
||||
else:
|
||||
if hasattr(page.ViewObject,"HintScale"):
|
||||
viewobj.Scale = page.ViewObject.HintScale
|
||||
if hasattr(page.ViewObject,"HintOffsetX"):
|
||||
viewobj.X = page.ViewObject.HintOffsetX
|
||||
if hasattr(page.ViewObject,"HintOffsetY"):
|
||||
viewobj.Y = page.ViewObject.HintOffsetY
|
||||
viewobj.Source = obj
|
||||
if lwmod: viewobj.LineweightModifier = lwmod
|
||||
if tmod: viewobj.TextModifier = tmod
|
||||
if hasattr(obj.ViewObject,"Pattern"):
|
||||
if str(obj.ViewObject.Pattern) in list(svgpatterns().keys()):
|
||||
viewobj.FillStyle = str(obj.ViewObject.Pattern)
|
||||
if hasattr(obj.ViewObject,"DrawStyle"):
|
||||
viewobj.LineStyle = obj.ViewObject.DrawStyle
|
||||
if hasattr(obj.ViewObject,"LineColor"):
|
||||
viewobj.LineColor = obj.ViewObject.LineColor
|
||||
elif hasattr(obj.ViewObject,"TextColor"):
|
||||
viewobj.LineColor = obj.ViewObject.TextColor
|
||||
return viewobj
|
||||
|
||||
class _DrawingView(_DraftObject):
|
||||
"""The Draft DrawingView object
|
||||
|
||||
TODO: this class is obsolete, since Drawing was substituted by TechDraw.
|
||||
"""
|
||||
|
||||
def __init__(self, obj):
|
||||
_DraftObject.__init__(self,obj,"DrawingView")
|
||||
obj.addProperty("App::PropertyVector","Direction","Shape View",QT_TRANSLATE_NOOP("App::Property","Projection direction"))
|
||||
obj.addProperty("App::PropertyFloat","LineWidth","View Style",QT_TRANSLATE_NOOP("App::Property","The width of the lines inside this object"))
|
||||
obj.addProperty("App::PropertyLength","FontSize","View Style",QT_TRANSLATE_NOOP("App::Property","The size of the texts inside this object"))
|
||||
obj.addProperty("App::PropertyLength","LineSpacing","View Style",QT_TRANSLATE_NOOP("App::Property","The spacing between lines of text"))
|
||||
obj.addProperty("App::PropertyColor","LineColor","View Style",QT_TRANSLATE_NOOP("App::Property","The color of the projected objects"))
|
||||
obj.addProperty("App::PropertyLink","Source","Base",QT_TRANSLATE_NOOP("App::Property","The linked object"))
|
||||
obj.addProperty("App::PropertyEnumeration","FillStyle","View Style",QT_TRANSLATE_NOOP("App::Property","Shape Fill Style"))
|
||||
obj.addProperty("App::PropertyEnumeration","LineStyle","View Style",QT_TRANSLATE_NOOP("App::Property","Line Style"))
|
||||
obj.addProperty("App::PropertyBool","AlwaysOn","View Style",QT_TRANSLATE_NOOP("App::Property","If checked, source objects are displayed regardless of being visible in the 3D model"))
|
||||
obj.FillStyle = ['shape color'] + list(svgpatterns().keys())
|
||||
obj.LineStyle = ['Solid','Dashed','Dotted','Dashdot']
|
||||
obj.LineWidth = 0.35
|
||||
obj.FontSize = 12
|
||||
|
||||
def execute(self, obj):
|
||||
result = ""
|
||||
if hasattr(obj,"Source"):
|
||||
if obj.Source:
|
||||
if hasattr(obj,"LineStyle"):
|
||||
ls = obj.LineStyle
|
||||
else:
|
||||
ls = None
|
||||
if hasattr(obj,"LineColor"):
|
||||
lc = obj.LineColor
|
||||
else:
|
||||
lc = None
|
||||
if hasattr(obj,"LineSpacing"):
|
||||
lp = obj.LineSpacing
|
||||
else:
|
||||
lp = None
|
||||
if obj.Source.isDerivedFrom("App::DocumentObjectGroup"):
|
||||
svg = ""
|
||||
shapes = []
|
||||
others = []
|
||||
objs = getGroupContents([obj.Source])
|
||||
for o in objs:
|
||||
v = o.ViewObject.isVisible()
|
||||
if hasattr(obj,"AlwaysOn"):
|
||||
if obj.AlwaysOn:
|
||||
v = True
|
||||
if v:
|
||||
svg += getSVG(o,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc,lp)
|
||||
else:
|
||||
svg = getSVG(obj.Source,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc,lp)
|
||||
result += '<g id="' + obj.Name + '"'
|
||||
result += ' transform="'
|
||||
result += 'rotate('+str(obj.Rotation)+','+str(obj.X)+','+str(obj.Y)+') '
|
||||
result += 'translate('+str(obj.X)+','+str(obj.Y)+') '
|
||||
result += 'scale('+str(obj.Scale)+','+str(-obj.Scale)+')'
|
||||
result += '">'
|
||||
result += svg
|
||||
result += '</g>'
|
||||
obj.ViewResult = result
|
||||
|
||||
def getDXF(self,obj):
|
||||
"returns a DXF fragment"
|
||||
return getDXF(obj)
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
104
src/Mod/Draft/draftmake/make_drawingview.py
Normal file
104
src/Mod/Draft/draftmake/make_drawingview.py
Normal file
@@ -0,0 +1,104 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
|
||||
# * Copyright (c) 2020 FreeCAD Developers *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
"""This module provides the code for Draft make_drawing_view function.
|
||||
"""
|
||||
## @package make_drawingview
|
||||
# \ingroup DRAFT
|
||||
# \brief This module provides the code for Draft make_drawing_view function.
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
import draftutils.utils as utils
|
||||
|
||||
from draftobjects.drawingview import DrawingView
|
||||
|
||||
|
||||
def make_drawing_view(obj, page, lwmod=None, tmod=None, otherProjection=None):
|
||||
"""
|
||||
make_drawing_view(object,page,[lwmod,tmod])
|
||||
|
||||
Add a View of the given object to the given page.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
lwmod :
|
||||
modifies lineweights (in percent),
|
||||
|
||||
tmod :
|
||||
modifies text heights (in percent).
|
||||
|
||||
The Hint scale, X and Y of the page are used.
|
||||
TODO: Document it properly
|
||||
"""
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
if utils.get_type(obj) == "SectionPlane":
|
||||
import ArchSectionPlane
|
||||
viewobj = App.ActiveDocument.addObject("Drawing::FeatureViewPython","View")
|
||||
page.addObject(viewobj)
|
||||
ArchSectionPlane._ArchDrawingView(viewobj)
|
||||
viewobj.Source = obj
|
||||
viewobj.Label = "View of "+obj.Name
|
||||
elif utils.get_type(obj) == "Panel":
|
||||
import ArchPanel
|
||||
viewobj = ArchPanel.makePanelView(obj, page)
|
||||
else:
|
||||
viewobj = App.ActiveDocument.addObject("Drawing::FeatureViewPython",
|
||||
"View"+ obj.Name)
|
||||
DrawingView(viewobj)
|
||||
page.addObject(viewobj)
|
||||
if (otherProjection):
|
||||
if hasattr(otherProjection,"Scale"):
|
||||
viewobj.Scale = otherProjection.Scale
|
||||
if hasattr(otherProjection,"X"):
|
||||
viewobj.X = otherProjection.X
|
||||
if hasattr(otherProjection,"Y"):
|
||||
viewobj.Y = otherProjection.Y
|
||||
if hasattr(otherProjection,"Rotation"):
|
||||
viewobj.Rotation = otherProjection.Rotation
|
||||
if hasattr(otherProjection,"Direction"):
|
||||
viewobj.Direction = otherProjection.Direction
|
||||
else:
|
||||
if hasattr(page.ViewObject,"HintScale"):
|
||||
viewobj.Scale = page.ViewObject.HintScale
|
||||
if hasattr(page.ViewObject,"HintOffsetX"):
|
||||
viewobj.X = page.ViewObject.HintOffsetX
|
||||
if hasattr(page.ViewObject,"HintOffsetY"):
|
||||
viewobj.Y = page.ViewObject.HintOffsetY
|
||||
viewobj.Source = obj
|
||||
if lwmod: viewobj.LineweightModifier = lwmod
|
||||
if tmod: viewobj.TextModifier = tmod
|
||||
if hasattr(obj.ViewObject,"Pattern"):
|
||||
if str(obj.ViewObject.Pattern) in list(utils.svgpatterns().keys()):
|
||||
viewobj.FillStyle = str(obj.ViewObject.Pattern)
|
||||
if hasattr(obj.ViewObject,"DrawStyle"):
|
||||
viewobj.LineStyle = obj.ViewObject.DrawStyle
|
||||
if hasattr(obj.ViewObject,"LineColor"):
|
||||
viewobj.LineColor = obj.ViewObject.LineColor
|
||||
elif hasattr(obj.ViewObject,"TextColor"):
|
||||
viewobj.LineColor = obj.ViewObject.TextColor
|
||||
return viewobj
|
||||
|
||||
|
||||
makeDrawingView = make_drawing_view
|
||||
141
src/Mod/Draft/draftobjects/drawingview.py
Normal file
141
src/Mod/Draft/draftobjects/drawingview.py
Normal file
@@ -0,0 +1,141 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
|
||||
# * Copyright (c) 2020 FreeCAD Developers *
|
||||
# * *
|
||||
# * 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 *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
"""This module provides the object code for the Draft DrawingView object.
|
||||
"""
|
||||
## @package drawingview
|
||||
# \ingroup DRAFT
|
||||
# \brief This module provides the object code for the Draft DrawingView object.
|
||||
|
||||
import math
|
||||
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
import DraftVecUtils
|
||||
|
||||
import getSVG as svg
|
||||
getSVG = svg.getSVG
|
||||
|
||||
import draftutils.utils as utils
|
||||
|
||||
from draftobjects.base import DraftObject
|
||||
|
||||
|
||||
class DrawingView(DraftObject):
|
||||
"""The Draft DrawingView object
|
||||
|
||||
TODO: this class is obsolete, since Drawing was substituted by TechDraw.
|
||||
"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super(DrawingView, self).__init__(obj, "DrawingView")
|
||||
|
||||
_tip = "The linked object"
|
||||
obj.addProperty("App::PropertyLink", "Source",
|
||||
"Base", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip ="Projection direction"
|
||||
obj.addProperty("App::PropertyVector", "Direction",
|
||||
"Shape View", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "The width of the lines inside this object"
|
||||
obj.addProperty("App::PropertyFloat", "LineWidth",
|
||||
"View Style", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "The size of the texts inside this object"
|
||||
obj.addProperty("App::PropertyLength", "FontSize",
|
||||
"View Style", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "The spacing between lines of text"
|
||||
obj.addProperty("App::PropertyLength", "LineSpacing",
|
||||
"View Style", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "The color of the projected objects"
|
||||
obj.addProperty("App::PropertyColor", "LineColor",
|
||||
"View Style", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "Shape Fill Style"
|
||||
obj.addProperty("App::PropertyEnumeration", "FillStyle",
|
||||
"View Style", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "Line Style"
|
||||
obj.addProperty("App::PropertyEnumeration", "LineStyle",
|
||||
"View Style", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "If checked, source objects are displayed regardless of being \
|
||||
visible in the 3D model"
|
||||
obj.addProperty("App::PropertyBool", "AlwaysOn",
|
||||
"View Style", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
obj.FillStyle = ['shape color'] + list(utils.svgpatterns().keys())
|
||||
obj.LineStyle = ['Solid','Dashed','Dotted','Dashdot']
|
||||
obj.LineWidth = 0.35
|
||||
obj.FontSize = 12
|
||||
|
||||
def execute(self, obj):
|
||||
result = ""
|
||||
if hasattr(obj,"Source"):
|
||||
if obj.Source:
|
||||
if hasattr(obj,"LineStyle"):
|
||||
ls = obj.LineStyle
|
||||
else:
|
||||
ls = None
|
||||
if hasattr(obj,"LineColor"):
|
||||
lc = obj.LineColor
|
||||
else:
|
||||
lc = None
|
||||
if hasattr(obj,"LineSpacing"):
|
||||
lp = obj.LineSpacing
|
||||
else:
|
||||
lp = None
|
||||
if obj.Source.isDerivedFrom("App::DocumentObjectGroup"):
|
||||
svg = ""
|
||||
shapes = []
|
||||
others = []
|
||||
objs = utils.getGroupContents([obj.Source])
|
||||
for o in objs:
|
||||
v = o.ViewObject.isVisible()
|
||||
if hasattr(obj,"AlwaysOn"):
|
||||
if obj.AlwaysOn:
|
||||
v = True
|
||||
if v:
|
||||
svg += getSVG(o,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc,lp)
|
||||
else:
|
||||
svg = getSVG(obj.Source,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc,lp)
|
||||
result += '<g id="' + obj.Name + '"'
|
||||
result += ' transform="'
|
||||
result += 'rotate('+str(obj.Rotation)+','+str(obj.X)+','+str(obj.Y)+') '
|
||||
result += 'translate('+str(obj.X)+','+str(obj.Y)+') '
|
||||
result += 'scale('+str(obj.Scale)+','+str(-obj.Scale)+')'
|
||||
result += '">'
|
||||
result += svg
|
||||
result += '</g>'
|
||||
obj.ViewResult = result
|
||||
|
||||
def getDXF(self,obj):
|
||||
"returns a DXF fragment"
|
||||
return utils.getDXF(obj)
|
||||
|
||||
|
||||
_DrawingView = DrawingView
|
||||
Reference in New Issue
Block a user