Skip to content

Commit 8851146

Browse files
Adds support for the sketch capability to the CadDocument class (#805)
* Adds support for the `sketch` capability to the `CadDocument` class (in progress) * Adds support for the `sketch` capability to the `CadDocument` class (in progress) * Adds support for the `sketch` capability to the `CadDocument` class (working!) * Tidy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add # noqa * Add point * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove geomPoint (see comments in #807) see comments in #807) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent aefbfd7 commit 8851146

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

python/jupytercad_core/jupytercad_core/schema/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .interfaces.chamfer import IChamfer # noqa
1212
from .interfaces.fillet import IFillet # noqa
1313
from .interfaces.any import IAny # noqa
14-
14+
from .interfaces.sketch import ISketchObject # noqa
1515
from .interfaces.jcad import IJCadContent
1616

1717
SCHEMA_VERSION = IJCadContent.model_fields["schemaVersion"].default # noqa

python/jupytercad_lab/jupytercad_lab/notebook/cad_document.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
IChamfer,
2525
IFillet,
2626
ITorus,
27+
ISketchObject,
2728
Parts,
2829
ShapeMetadata,
2930
IAny,
3031
SCHEMA_VERSION,
3132
)
33+
from jupytercad_core.schema.interfaces import geomLineSegment, geomCircle
3234

3335
logger = logging.getLogger(__file__)
3436

@@ -542,6 +544,54 @@ def add_torus(
542544
}
543545
return self.add_object(OBJECT_FACTORY.create_object(data, self))
544546

547+
def add_sketch(
548+
self,
549+
name: str = "",
550+
geometry: List[
551+
Union[geomCircle.IGeomCircle, geomLineSegment.IGeomLineSegment]
552+
] = [],
553+
attachment_offset_position: List[float] = [0, 0, 0],
554+
attachment_offset_rotation_axis: List[float] = [0, 0, 1],
555+
attachment_offset_rotation_angle: float = 0,
556+
color: str = "#808080",
557+
position: List[float] = [0, 0, 0],
558+
rotation_axis: List[float] = [0, 0, 1],
559+
rotation_angle: float = 0,
560+
) -> CadDocument:
561+
"""
562+
Add a sketch to the document.
563+
564+
:param name: The name that will be used for the object in the document.
565+
:param geometry: The list of geometries for the sketch.
566+
:param attachment_offset_position: The attachment offset 3D position.
567+
:param attachment_offset_rotation_axis: The attachment offset 3D axis used for the rotation.
568+
:param attachment_offset_rotation_angle: The attachment offset rotation angle, in degrees.
569+
:param color: The color of the sketch in hex format (e.g., "#FF5733") or RGB float list.
570+
:param position: The shape 3D position.
571+
:param rotation_axis: The 3D axis used for the rotation.
572+
:param rotation_angle: The shape rotation angle, in degrees.
573+
:return: The document itself.
574+
"""
575+
data = {
576+
"shape": Parts.Sketcher__SketchObject.value,
577+
"name": name if name else self._new_name("Sketch"),
578+
"parameters": {
579+
"AttachmentOffset": {
580+
"Position": attachment_offset_position,
581+
"Axis": attachment_offset_rotation_axis,
582+
"Angle": attachment_offset_rotation_angle,
583+
},
584+
"Geometry": geometry,
585+
"Color": color,
586+
"Placement": {
587+
"Position": position,
588+
"Axis": rotation_axis,
589+
"Angle": rotation_angle,
590+
},
591+
},
592+
}
593+
return self.add_object(OBJECT_FACTORY.create_object(data, self))
594+
545595
def cut(
546596
self,
547597
name: str = "",
@@ -886,6 +936,7 @@ class Config:
886936
IFuse,
887937
ISphere,
888938
ITorus,
939+
ISketchObject,
889940
IFillet,
890941
IChamfer,
891942
]
@@ -954,5 +1005,6 @@ def create_object(
9541005
OBJECT_FACTORY.register_factory(Parts.Part__MultiFuse.value, IFuse)
9551006
OBJECT_FACTORY.register_factory(Parts.Part__Sphere.value, ISphere)
9561007
OBJECT_FACTORY.register_factory(Parts.Part__Torus.value, ITorus)
1008+
OBJECT_FACTORY.register_factory(Parts.Sketcher__SketchObject.value, ISketchObject)
9571009
OBJECT_FACTORY.register_factory(Parts.Part__Chamfer.value, IChamfer)
9581010
OBJECT_FACTORY.register_factory(Parts.Part__Fillet.value, IFillet)

0 commit comments

Comments
 (0)