diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index 58790a9e29..dae005df4d 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -307,6 +307,7 @@ def update_svg_cache(source, renderMode, showHidden, showFill, fillSpaces, joinA source.Proxy.shapecache = None return svgcache + def getSVG(source, renderMode="Wireframe", allOn=False, @@ -314,33 +315,49 @@ def getSVG(source, scale=1, rotation=0, linewidth=1, - lineColor=(0.0,0.0,0.0), + lineColor=(0.0, 0.0, 0.0), fontsize=1, showFill=False, - fillColor=(0.8,0.8,0.8), + fillColor=(0.8, 0.8, 0.8), techdraw=False, fillSpaces=False, cutlinewidth=0, joinArch=False): - - """ - returns an SVG fragment from an Arch SectionPlane or BuildingPart. If - allOn is True, all cut objects are shown, regardless if they are visible or not. - renderMode can be Wireframe (default) or Solid to use the Arch solid renderer. If - showHidden is True, the hidden geometry above the section plane is shown in dashed line. - If showFill is True, the cut areas get filled with a pattern. - lineColor -- Color of lines for the renderMode "Wireframe". - fillColor -- If showFill is True and renderMode is "Wireframe", - the cut areas are filled with fillColor. - fillSpaces - If True, shows space objects as filled surfaces """ + Return an SVG fragment from an Arch SectionPlane or BuildingPart. + + allOn + If it is `True`, all cut objects are shown, regardless of if they are + visible or not. + + renderMode + Can be `'Wireframe'` (default) or `'Solid'` to use the Arch solid + renderer. + + showHidden + If it is `True`, the hidden geometry above the section plane + is shown in dashed line. + + showFill + If it is `True`, the cut areas get filled with a pattern. + + lineColor + Color of lines for the `renderMode` is `'Wireframe'`. + + fillColor + If `showFill` is `True` and `renderMode` is `'Wireframe'`, + the cut areas are filled with `fillColor`. + + fillSpaces + If `True`, shows space objects as filled surfaces. + """ + import Part - import Part,DraftGeomUtils objs, cutplane, onlySolids, clip, direction = getSectionData(source) if not objs: return "" if not allOn: - objs = Draft.removeHidden(objs) + objs = Draft.removeHidden(objs) # separate spaces and Draft objects spaces = [] @@ -482,12 +499,17 @@ def getSVG(source, for s in shapes: if s.Edges: objectFill = getFillForObject(o, fillColor, source) - #svg += Draft.getSVG(s,direction=direction.negative(),linewidth=0,fillstyle="sectionfill",color=(0,0,0)) + # svg += Draft.get_svg(s, + # direction=direction.negative(), + # linewidth=0, + # fillstyle="sectionfill", + # color=(0,0,0)) # temporarily disabling fill patterns - svgcache += Draft.getSVG(s, direction=direction.negative(), - linewidth=0, - fillstyle=Draft.getrgb(objectFill), - color=lineColor) + svgcache += Draft.get_svg(s, + linewidth=0, + fillstyle=Draft.getrgb(objectFill), + direction=direction.negative(), + color=lineColor) svgcache += "\n" sshapes = Part.makeCompound(sshapes) style = {'stroke': "SVGLINECOLOR", @@ -510,9 +532,14 @@ def getSVG(source, if not techdraw: svg += '' for d in drafts: - svg += Draft.getSVG(d, scale=scale, linewidth=svgSymbolLineWidth, - fontsize=fontsize, direction=direction, color=lineColor, - techdraw=techdraw, rotation=rotation) + svg += Draft.get_svg(d, + scale=scale, + linewidth=svgSymbolLineWidth, + fontsize=fontsize, + direction=direction, + color=lineColor, + techdraw=techdraw, + rotation=rotation) if not techdraw: svg += '' @@ -527,9 +554,15 @@ def getSVG(source, if not techdraw: svg += '' for s in spaces: - svg += Draft.getSVG(s, scale=scale, linewidth=svgSymbolLineWidth, - fontsize=fontsize, direction=direction, color=lineColor, - techdraw=techdraw, rotation=rotation, fillSpaces=fillSpaces) + svg += Draft.get_svg(s, + scale=scale, + linewidth=svgSymbolLineWidth, + fontsize=fontsize, + direction=direction, + color=lineColor, + techdraw=techdraw, + rotation=rotation, + fillSpaces=fillSpaces) if not techdraw: svg += '' @@ -557,11 +590,15 @@ def getSVG(source, if not techdraw: svg += '' for s in sh: - svg += Draft.getSVG(s, scale=scale, - linewidth=svgSymbolLineWidth, - fontsize=fontsize, fillstyle="none", - direction=direction, color=lineColor, - techdraw=techdraw, rotation=rotation) + svg += Draft.get_svg(s, + scale=scale, + linewidth=svgSymbolLineWidth, + fontsize=fontsize, + fillstyle="none", + direction=direction, + color=lineColor, + techdraw=techdraw, + rotation=rotation) if not techdraw: svg += '' @@ -569,9 +606,7 @@ def getSVG(source, def getDXF(obj): - - """returns a DXF representation from a TechDraw/Drawing view""" - + """Return a DXF representation from a TechDraw/Drawing view.""" allOn = True if hasattr(obj,"AllOn"): allOn = obj.AllOn diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index 39d7a09aaa..c051f0f2cc 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -15,7 +15,6 @@ SET(Draft_SRCS_base DraftLayer.py DraftFillet.py WorkingPlane.py - getSVG.py TestDraft.py TestDraftGui.py ) @@ -97,6 +96,7 @@ SET(Draft_functions draftfunctions/rotate.py draftfunctions/scale.py draftfunctions/split.py + draftfunctions/svg.py draftfunctions/upgrade.py draftfunctions/README.md ) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 0d20c307b3..32d49010f1 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -95,8 +95,8 @@ from draftutils.utils import (string_encode_coin, get_DXF, getDXF) -from getSVG import (get_svg, - getSVG) +from draftfunctions.svg import (get_svg, + getSVG) from draftutils.gui_utils import (get3DView, get_3d_view, diff --git a/src/Mod/Draft/getSVG.py b/src/Mod/Draft/draftfunctions/svg.py similarity index 99% rename from src/Mod/Draft/getSVG.py rename to src/Mod/Draft/draftfunctions/svg.py index d9aa24d1d7..ecdf613f8d 100644 --- a/src/Mod/Draft/getSVG.py +++ b/src/Mod/Draft/draftfunctions/svg.py @@ -2,7 +2,7 @@ # *************************************************************************** # * Copyright (c) 2009 Yorik van Havre * # * Copyright (c) 2018 George Shuklin (amarao) * -# * Copyright (c) 2019 Eliud Cabrera Castillo * +# * Copyright (c) 2020 Eliud Cabrera Castillo * # * * # * This program is free software; you can redistribute it and/or modify * # * it under the terms of the GNU Lesser General Public License (LGPL) * @@ -22,9 +22,9 @@ # * * # *************************************************************************** """Provides functions to return the SVG representation of various shapes.""" -## @defgroup getSVG getSVG -# \ingroup DRAFT -# \brief Provides functions to return the SVG representation of shapes. +## @package svg +# \ingroup draftfuctions +# \brief Provides functions to return the SVG representation of shapes. import math import six @@ -45,7 +45,7 @@ Drawing = lz.LazyLoader("Drawing", globals(), "Drawing") param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") -## \addtogroup getSVG +## \addtogroup draftfuctions # @{ diff --git a/src/Mod/Draft/draftobjects/drawingview.py b/src/Mod/Draft/draftobjects/drawingview.py index a46c553897..53a7d2e3a6 100644 --- a/src/Mod/Draft/draftobjects/drawingview.py +++ b/src/Mod/Draft/draftobjects/drawingview.py @@ -1,7 +1,7 @@ # *************************************************************************** # * Copyright (c) 2009, 2010 Yorik van Havre * # * Copyright (c) 2009, 2010 Ken Cline * -# * Copyright (c) 2020 FreeCAD Developers * +# * Copyright (c) 2020 Eliud Cabrera Castillo * # * * # * This program is free software; you can redistribute it and/or modify * # * it under the terms of the GNU Lesser General Public License (LGPL) * @@ -39,7 +39,7 @@ this object should no longer be available. # @{ from PySide.QtCore import QT_TRANSLATE_NOOP -import getSVG +import draftfunctions.svg as get_svg import draftutils.utils as utils import draftutils.groups as groups @@ -47,90 +47,141 @@ from draftobjects.base import DraftObject class DrawingView(DraftObject): - """The Draft DrawingView object - - OBSOLETE: this class is obsolete, since Drawing was substituted by TechDraw. + """The DrawingView object. This class is OBSOLETE. + + This object was used with the Drawing Workbench, but since this workbench + because obsolete in v0.17, the object should no longer be used. + It is retained for compatibility purposes, that is, to open older + files that may contain this object. + + To produce 2D drawings, use TechDraw Workbench. """ def __init__(self, obj): super(DrawingView, self).__init__(obj, "DrawingView") - - _tip = QT_TRANSLATE_NOOP("App::Property", "The linked object") - obj.addProperty("App::PropertyLink", "Source", "Base", _tip) - - _tip = QT_TRANSLATE_NOOP("App::Property", "Projection direction") - obj.addProperty("App::PropertyVector", "Direction", "Shape View", _tip) - - _tip = QT_TRANSLATE_NOOP("App::Property", "The width of the lines inside this object") - obj.addProperty("App::PropertyFloat", "LineWidth", "View Style", _tip) - - _tip = QT_TRANSLATE_NOOP("App::Property", "The size of the texts inside this object") - obj.addProperty("App::PropertyLength", "FontSize", "View Style", _tip) - - _tip = QT_TRANSLATE_NOOP("App::Property", "The spacing between lines of text") - obj.addProperty("App::PropertyLength", "LineSpacing", "View Style", _tip) - - _tip = QT_TRANSLATE_NOOP("App::Property", "The color of the projected objects") - obj.addProperty("App::PropertyColor", "LineColor", "View Style", _tip) - - _tip = QT_TRANSLATE_NOOP("App::Property", "Shape Fill Style") - obj.addProperty("App::PropertyEnumeration", "FillStyle", "View Style", _tip) - - _tip = QT_TRANSLATE_NOOP("App::Property", "Line Style") - obj.addProperty("App::PropertyEnumeration", "LineStyle", "View Style", _tip) - - _tip = QT_TRANSLATE_NOOP("App::Property", - "If checked, source objects are displayed regardless of being \ - visible in the 3D model") - obj.addProperty("App::PropertyBool", "AlwaysOn", "View Style", _tip) - obj.FillStyle = ['shape color'] + list(utils.svgpatterns().keys()) - obj.LineStyle = ['Solid','Dashed','Dotted','Dashdot'] + _tip = QT_TRANSLATE_NOOP("App::Property", + "The linked object") + obj.addProperty("App::PropertyLink", + "Source", + "Base", + _tip) + + _tip = QT_TRANSLATE_NOOP("App::Property", + "Projection direction") + obj.addProperty("App::PropertyVector", + "Direction", + "Shape View", + _tip) + + _tip = QT_TRANSLATE_NOOP("App::Property", + "The width of the lines inside this object") + obj.addProperty("App::PropertyFloat", + "LineWidth", + "View Style", + _tip) obj.LineWidth = 0.35 + + _tip = QT_TRANSLATE_NOOP("App::Property", + "The size of the texts inside this object") + obj.addProperty("App::PropertyLength", + "FontSize", + "View Style", + _tip) obj.FontSize = 12 + _tip = QT_TRANSLATE_NOOP("App::Property", + "The spacing between lines of text") + obj.addProperty("App::PropertyLength", + "LineSpacing", + "View Style", + _tip) + + _tip = QT_TRANSLATE_NOOP("App::Property", + "The color of the projected objects") + obj.addProperty("App::PropertyColor", + "LineColor", + "View Style", + _tip) + + _tip = QT_TRANSLATE_NOOP("App::Property", + "Shape Fill Style") + obj.addProperty("App::PropertyEnumeration", + "FillStyle", + "View Style", + _tip) + obj.FillStyle = ['shape color'] + list(utils.svgpatterns().keys()) + + _tip = QT_TRANSLATE_NOOP("App::Property", + "Line Style") + obj.addProperty("App::PropertyEnumeration", + "LineStyle", + "View Style", + _tip) + obj.LineStyle = ['Solid', 'Dashed', 'Dotted', 'Dashdot'] + + _tip = QT_TRANSLATE_NOOP("App::Property", + "If checked, source objects are displayed " + "regardless of being visible in the 3D model") + obj.addProperty("App::PropertyBool", + "AlwaysOn", + "View Style", + _tip) + def execute(self, obj): + """Execute when the object is created or recomputed.""" 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 = groups.get_group_contents([obj.Source]) - for o in objs: - v = o.ViewObject.isVisible() - if hasattr(obj,"AlwaysOn"): - if obj.AlwaysOn: - v = True - if v: - svg += getSVG.getSVG(o,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc,lp) - else: - svg = getSVG.getSVG(obj.Source,obj.Scale,obj.LineWidth,obj.FontSize.Value,obj.FillStyle,obj.Direction,ls,lc,lp) - result += '