Skip to content

Commit bfea63f

Browse files
committed
Support setting workplane/axis x-direction
1 parent 8656228 commit bfea63f

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

declaracad/occ/impl/occ_display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class OccDisplayArrow(OccDisplayItem, ProxyDisplayArrow):
154154

155155
def create_item(self):
156156
d = self.declaration
157-
axis = coerce_axis((d.position, d.direction, 0))
157+
axis = coerce_axis((d.position, d.direction, None, 0))
158158
ais_item = AIS_Arrow(axis.Axis(), *d.tube_size, *d.cone_size)
159159
self.update_color(ais_item)
160160
self.item = ais_item

declaracad/occ/impl/occ_shape.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
import os
14-
from typing import ClassVar, Generator, Union
14+
from typing import ClassVar, Generator, Optional, Union
1515

1616
from atom.api import Bool, Instance, List, Property, Str, Typed, observe
1717
from OCCT.AIS import AIS_MultipleConnectedInteractive, AIS_Shape, AIS_TexturedShape
@@ -53,9 +53,12 @@
5353
DEFAULT_AXIS = gp_Ax3(gp_Pnt(0, 0, 0), DZ, DX)
5454

5555

56-
def coerce_axis(value: tuple[Point, Direction, float]) -> gp_Ax2:
57-
pos, dir, rotation = value
58-
axis = gp_Ax2(pos.proxy, dir.proxy)
56+
def coerce_axis(value: tuple[Point, Direction, Optional[Direction], float]) -> gp_Ax2:
57+
pos, dn, dx, rotation = value
58+
if dx is None:
59+
axis = gp_Ax2(pos.proxy, dn.proxy) # dx is calculated
60+
else:
61+
axis = gp_Ax2(pos.proxy, dn.proxy, dx.proxy)
5962
axis.Rotate(axis.Axis(), rotation)
6063
return axis
6164

declaracad/occ/shape.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,25 +404,33 @@ def _default_position(self) -> Point:
404404
return Point(0, 0, 0)
405405

406406
#: A tuple or list of the (u, v, w) normal vector of this shape. This is
407-
#: coerced into a Vector setting the orentation of the shape.
407+
#: coerced into a Vector setting the orientation of the shape.
408408
#: This is effectively the working plane.
409409
direction = d_(Coerced(Direction, coercer=coerce_direction))
410410

411411
def _default_direction(self) -> Direction:
412412
return Direction(0, 0, 1)
413413

414+
#: Sets the x-direction of the shape's axis. If None (default) it is calculated using
415+
#: an axis perpendicular to the normal.
416+
x_direction = d_(
417+
Coerced(
418+
(type(None), Direction),
419+
coercer=lambda v: None if v is None else coerce_direction(v),
420+
)
421+
)
422+
414423
#: Rotation about the normal vector in radians
415424
rotation = d_(Coerced(float, coercer=coerce_rotation))
416425

417426
def _get_axis(self):
418-
return (self.position, self.direction, self.rotation)
427+
return (self.position, self.direction, self.x_direction, self.rotation)
419428

420429
def _set_axis(self, axis):
421-
self.position, self.direction, self.rotation = axis
430+
self.position, self.direction, self.x_direction, self.rotation = axis
422431

423-
#: A tuple or list of the (u, v, w) axis of this shape. This is
424-
#: coerced into a Vector that defines the x, y, and z orientation of
425-
#: this shape.
432+
#: A tuple of (position, normal direction, x-direction (optional), rotation) defining the
433+
#: axis or "workplane" where this shape located.
426434
axis = d_(Property(_get_axis, _set_axis))
427435

428436
def _get_topology(self):

0 commit comments

Comments
 (0)