Skip to content

Commit

Permalink
Merge pull request #47 from cadbuildr/CAD-265-svg
Browse files Browse the repository at this point in the history
 adding svg support
  • Loading branch information
clement91190 authored Sep 12, 2024
2 parents b498877 + 68d8b74 commit b798617
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "foundation"
version = "0.0.0.10"
version = "0.0.0.11"
description = "Python core package for builder"
authors = ["Clement Jambou"]

Expand Down
8 changes: 7 additions & 1 deletion src/foundation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
from foundation.sketch.primitives.line import Line
from foundation.sketch.axis import Axis
from foundation.sketch.point import Point
from foundation.sketch.closed_sketch_shape import Circle, Ellipse, Polygon, Hexagon
from foundation.sketch.closed_sketch_shape import (
Circle,
Ellipse,
SVGShape,
Polygon,
Hexagon,
)
from foundation.sketch.rectangle import Rectangle, Square
from foundation.geometry.plane import PlaneFromFrame, PlaneFactory
from foundation.geometry.frame import Frame
Expand Down
34 changes: 33 additions & 1 deletion src/foundation/sketch/closed_sketch_shape.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from foundation.types.node import Node
import math
from foundation.sketch.base import SketchElement
Expand All @@ -7,10 +9,17 @@
UnCastFloat,
cast_to_float_parameter,
FloatParameter,
StringParameter,
cast_to_string_parameter,
UnCastString,
)
from foundation.types.node_children import NodeChildren
from foundation.sketch.primitives import SketchPrimitiveTypes
from foundation.exceptions import ElementsNotOnSameSketchException
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from foundation.sketch.sketch import Sketch


class ClosedSketchShape(SketchElement):
Expand Down Expand Up @@ -291,4 +300,27 @@ def __init__(self, lines: list[Line], radius: float):
CustomClosedShape.__init__(self, closed_shape.primitives)


ClosedSketchShapeTypes = Polygon | Circle | Ellipse | CustomClosedShape
class SVGShapeChildren(NodeChildren):
svg: StringParameter


class SVGShape(ClosedSketchShape, Node):
"""Use a SVG file given as a string to the constructor to create a shape in the sketch."""

children_class = SVGShapeChildren

def __init__(self, sketch: Sketch, svg: UnCastString):
ClosedSketchShape.__init__(self, sketch)
Node.__init__(self, parents=[sketch])

self.children.set_svg(cast_to_string_parameter(svg))
self.sketch = sketch
self.params = {}

# add to sketch
sketch.add_element(self)


SVGShapeChildren.__annotations__["svg"] = StringParameter

ClosedSketchShapeTypes = Polygon | Circle | Ellipse | CustomClosedShape | SVGShape
1 change: 1 addition & 0 deletions src/foundation/types/serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
"Shell": 29,
"CustomClosedShape": 30,
"Arc": 31,
"SVGShape": 32,
}

0 comments on commit b798617

Please sign in to comment.