SVG file importer and exporter. More...
Classes | |
class | svgHandler |
Functions | |
def | arccenter2end (center, rx, ry, angle1, angledelta, xrotation=0.0) |
def | arcend2center (lastvec, currentvec, rx, ry, xrotation=0.0, correction=False) |
def | decodeName (name) |
def | export (exportList, filename) |
def | getcolor (color) |
def | getContents (filename, tag, stringmode=False) |
def | getrgb (color) |
def | getsize (length, mode='discard', base=1) |
def | insert (filename, docname) |
def | makewire (path, checkclosed=False, donttry=False) |
def | open (filename) |
def | transformCopyShape (shape, m) |
Variables | |
draftui = FreeCADGui.draftToolBar | |
bool | gui = True |
pythonopen = open | |
dictionary | svgcolors |
svgcolorslower = \ | |
SVG file importer and exporter.
def importSVG.arccenter2end | ( | center, | |
rx, | |||
ry, | |||
angle1, | |||
angledelta, | |||
xrotation = 0.0 |
|||
) |
Calculate start and end points, and flags of an arc. Calculate start and end points, and flags of an arc given in ``center parametrization``. See http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes Parameters ---------- center : Base::Vector3 Coordinates of the center of the ellipse. rx : float Radius of the ellipse, semi-major axis in the X direction ry : float Radius of the ellipse, semi-minor axis in the Y direction angle1 : float Initial angle in radians angledelta : float Additional angle in radians xrotation : float, optional Default 0. Rotation around the Z axis Returns ------- v1, v2, largerc, sweep Tuple indicating the end points of the arc, and two boolean values indicating whether the arc is less than 180 degrees or not, and whether the angledelta is negative.
def importSVG.arcend2center | ( | lastvec, | |
currentvec, | |||
rx, | |||
ry, | |||
xrotation = 0.0 , |
|||
correction = False |
|||
) |
Calculate the possible centers for an arc in endpoint parameterization. Calculate (positive and negative) possible centers for an arc given in ``endpoint parametrization``. See http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes the sweepflag is interpreted as: sweepflag <==> arc is travelled clockwise Parameters ---------- lastvec : Base::Vector3 First point of the arc. currentvec : Base::Vector3 End point (current) of the arc. rx : float Radius of the ellipse, semi-major axis in the X direction. ry : float Radius of the ellipse, semi-minor axis in the Y direction. xrotation : float, optional Default is 0. Rotation around the Z axis, in radians (CCW). correction : bool, optional Default is `False`. If it is `True`, the radii will be scaled by a factor. Returns ------- list, (float, float) A tuple that consists of one list, and a tuple of radii. [(positive), (negative)], (rx, ry) The first element of the list is the positive tuple, the second is the negative tuple. [(Base::Vector3, float, float), (Base::Vector3, float, float)], (float, float) Types [(vcenter+, angle1+, angledelta+), (vcenter-, angle1-, angledelta-)], (rx, ry) The first element of the list is the positive tuple, consisting of center, angle, and angle increment; the second element is the negative tuple.
References DraftVecUtils.angle().
def importSVG.decodeName | ( | name | ) |
Decode encoded name. Parameters ---------- name : str The string to decode. Returns ------- tuple (string) A tuple containing the decoded `name` in 'utf8', otherwise in 'latin1'. If it fails it returns the original `name`.
def importSVG.export | ( | exportList, | |
filename | |||
) |
Export the SVG file with a given list of objects. The objects must be derived from Part::Feature, in order to be processed and exported. Parameters ---------- exportList : list List of document objects to export. filename : str Path to the new file. Returns ------- None If `exportList` doesn't have shapes to export.
References pythonopen.
def importSVG.getcolor | ( | color | ) |
Check if the given string is an RGB value, or if it is a named color. Parameters ---------- color : str Color in hexadecimal format, long '#12ab9f' or short '#1af' Returns ------- tuple (r, g, b, a) RGBA float tuple, where each value is between 0.0 and 1.0.
def importSVG.getContents | ( | filename, | |
tag, | |||
stringmode = False |
|||
) |
Get the contents of all occurrences of the given tag in the file. Parameters ---------- filename : str A filename to scan for tags. tag : str An SVG tag to find inside a file, for example, `some` in <some id="12">information</some> stringmode : bool, optional The default is False. If False, `filename` is a path to a file. If True, `filename` is already a pointer to an open file. Returns ------- dict A dictionary with tagids and the information associated with that id results[tagid] = information
References pythonopen.
Referenced by draftutils.utils.load_svg_patterns().
def importSVG.getrgb | ( | color | ) |
Return an RGB hexadecimal string '#00aaff' from a FreeCAD color. Parameters ---------- color : App::Color::Color FreeCAD color. Returns ------- str The hexadecimal string representation of the color '#00aaff'.
def importSVG.getsize | ( | length, | |
mode = 'discard' , |
|||
base = 1 |
|||
) |
Parse the length string containing number and unit. Parameters ---------- length : str The length is a string, including sign, exponential notation, and unit: '+56215.14565E+6mm', '-23.156e-2px'. mode : str, optional One of 'discard', 'tuple', 'css90.0', 'css96.0', 'mm90.0', 'mm96.0'. 'discard' (default), it discards the unit suffix, and extracts a number from the given string. 'tuple', return number and unit as a tuple 'css90.0', convert the unit to pixels assuming 90 dpi 'css96.0', convert the unit to pixels assuming 96 dpi 'mm90.0', convert the unit to millimeters assuming 90 dpi 'mm96.0', convert the unit to millimeters assuming 96 dpi base : float, optional A base to scale the length. Returns ------- float The numeric value of the length, as is, or transformed to millimeters or pixels. float, string A tuple with the numeric value, and the unit if `mode='tuple'`.
Referenced by importSVG.svgHandler.startElement().
def importSVG.insert | ( | filename, | |
docname | |||
) |
Get an active document and parse using the svgHandler(). If no document exist, it is created. Parameters ---------- filename : str The path to the filename to be opened. docname : str The name of the active App::Document if one exists, or of the new one created. Returns ------- App::Document The active FreeCAD document, or the document created if none exists, with the parsed information.
References pythonopen.
def importSVG.makewire | ( | path, | |
checkclosed = False , |
|||
donttry = False |
|||
) |
Try to make a wire out of the list of edges. If the wire functions fail or the wire is not closed, if required the TopoShapeCompoundPy::connectEdgesToWires() function is used. Parameters ---------- path : Part.Edge A collection of edges checkclosed : bool, optional Default is `False`. donttry : bool, optional Default is `False`. If it's `True` it won't try to check for a closed path. Returns ------- Part::Wire A wire created from the ordered edges. Part::Compound A compound made of the edges, but unable to form a wire.
def importSVG.open | ( | filename | ) |
Open filename and parse using the svgHandler(). Parameters ---------- filename : str The path to the filename to be opened. Returns ------- App::Document The new FreeCAD document object created, with the parsed information.
References pythonopen.
Referenced by importDXF.exportPageLegacy().
def importSVG.transformCopyShape | ( | shape, | |
m | |||
) |
Apply transformation matrix m on given shape. Since OCCT 6.8.0 transformShape can be used to apply certain non-orthogonal transformations on shapes. This way a conversion to BSplines in transformGeometry can be avoided. @sa: Part::TopoShape::transformGeometry(), TopoShapePy::transformGeometry() @sa: Part::TopoShape::transformShape(), TopoShapePy::transformShape() Parameters ---------- shape : Part::TopoShape A given shape m : Base::Matrix4D A transformation matrix Returns ------- shape : Part::TopoShape The shape transformed by the matrix
importSVG.draftui = FreeCADGui.draftToolBar |
bool importSVG.gui = True |
importSVG.pythonopen = open |
Referenced by export(), getContents(), insert(), and open().
dictionary importSVG.svgcolors |
importSVG.svgcolorslower = \ |