Skip to content

Commit

Permalink
Merge pull request #35 from gramaziokohler/compas2.4
Browse files Browse the repository at this point in the history
Compas2.4
  • Loading branch information
chenkasirer authored Sep 16, 2024
2 parents 521a7e5 + 7263120 commit 664a4e0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 51 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Made changes to instruction scene objects to support recent COMPAS2.x versions.

### Removed

* Removed the unused `Model3dSceneObject`.

## [0.4.4] 2024-09-03

Expand Down
4 changes: 0 additions & 4 deletions src/compas_cadwork/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@

from compas_monosashi.sequencer import Text3d
from compas_monosashi.sequencer import LinearDimension
from compas_monosashi.sequencer import Model3d

from .camera import Camera
from .scene import CadworkSceneObject
from .instructionobject import Text3dSceneObject
from .instructionobject import LinearDimensionSceneObject
from .instructionobject import Model3dSceneObject

__all__ = [
"Camera",
"CadworkSceneObject",
"Text3dSceneObject",
"LinearDimensionSceneObject",
"Model3dSceneObject",
]


Expand All @@ -37,4 +34,3 @@ def after_draw(*args, **kwargs):
def register_scene_objects():
register(Text3d, Text3dSceneObject, context=CONTEXT)
register(LinearDimension, LinearDimensionSceneObject, context=CONTEXT)
register(Model3d, Model3dSceneObject, context=CONTEXT)
64 changes: 17 additions & 47 deletions src/compas_cadwork/scene/instructionobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

from compas.geometry import Frame
from compas_monosashi.sequencer import LinearDimension
from compas_monosashi.sequencer import Model3d
from compas_monosashi.sequencer import Text3d
from dimension_controller import create_dimension
from element_controller import apply_transformation_coordinate
from element_controller import create_text_object_with_options
from element_controller import get_bounding_box_vertices_local
from file_controller import import_element_light

from compas_cadwork.conversions import point_to_cadwork
from compas_cadwork.conversions import vector_to_cadwork
Expand All @@ -27,9 +24,9 @@ class Text3dSceneObject(CadworkSceneObject):
"""

def __init__(self, text_instruction: Text3d, **kwargs) -> None:
super().__init__(text_instruction)
self.text_instruction = text_instruction
def __init__(self, item: Text3d, **kwargs) -> None:
super().__init__(item)
self._text_instruction = item

@staticmethod
def _generate_translation_vectors(element_id: int, inst_frame: Frame):
Expand Down Expand Up @@ -83,21 +80,21 @@ def draw(self, *args, **kwargs):
text_options = cadwork.text_object_options()
text_options.set_color(color)
text_options.set_element_type(cadwork.raster)
text_options.set_text(self.text_instruction.text)
text_options.set_height(self.text_instruction.size)
text_options.set_text(self._text_instruction.text)
text_options.set_height(self._text_instruction.size)

loc = self.text_instruction.location
loc = self._text_instruction.location
element_id = create_text_object_with_options(
point_to_cadwork(loc.point), vector_to_cadwork(loc.xaxis), vector_to_cadwork(loc.yaxis), text_options
)

element = self.add_element(element_id)

if self.text_instruction.centered:
translation = self._generate_translation_vectors(element_id, self.text_instruction.location)
if self._text_instruction.centered:
translation = self._generate_translation_vectors(element_id, self._text_instruction.location)
element.translate(translation)

element.set_is_instruction(True, self.text_instruction.id)
element.set_is_instruction(True, self._text_instruction.id)
return [element_id]


Expand All @@ -111,9 +108,9 @@ class LinearDimensionSceneObject(CadworkSceneObject):
"""

def __init__(self, linear_dimension: LinearDimension, **kwargs) -> None:
super().__init__(linear_dimension)
self.linear_dimension = linear_dimension
def __init__(self, item: LinearDimension, **kwargs) -> None:
super().__init__(item)
self._linear_dimension = item

def draw(self, *args, **kwargs):
"""Adds a new dimension to the cadwork document.
Expand All @@ -124,42 +121,15 @@ def draw(self, *args, **kwargs):
cadwork element ID of the added dimension.
"""
text_plane_normal = self.linear_dimension.location.normal * -1.0
inst_frame = self.linear_dimension.location
distance_vector = inst_frame.point + self.linear_dimension.line_offset
text_plane_normal = self._linear_dimension.location.normal * -1.0
inst_frame = self._linear_dimension.location
distance_vector = inst_frame.point + self._linear_dimension.line_offset
element_id = create_dimension(
vector_to_cadwork(inst_frame.xaxis),
vector_to_cadwork(text_plane_normal),
vector_to_cadwork(distance_vector),
[point_to_cadwork(point) for point in self.linear_dimension.points],
[point_to_cadwork(point) for point in self._linear_dimension.points],
)
element = self.add_element(element_id)
element.set_is_instruction(True, self.linear_dimension.id)
return [element_id]


class Model3dSceneObject(CadworkSceneObject):
"""TODO: This is incomplete, complete."""

def __init__(self, model3d: Model3d, **kwargs) -> None:
super().__init__(model3d)
self.model3d = model3d

def draw(self):
element_id = import_element_light(self.model3d.obj_filepath, point_to_cadwork(self.model3d.location.point))
old_loc = self.model3d.location
new_loc = self.model3d.t_location

# TODO: missing scaling..
apply_transformation_coordinate(
[element_id],
point_to_cadwork(old_loc.point),
vector_to_cadwork(old_loc.xaxis),
vector_to_cadwork(old_loc.yaxis),
point_to_cadwork(new_loc.point),
point_to_cadwork(new_loc.xaxis),
point_to_cadwork(new_loc.yaxis),
)
element = self.add_element(element_id)
element.set_is_instruction(True, self.model3d.id)
element.set_is_instruction(True, self._linear_dimension.id)
return [element_id]

0 comments on commit 664a4e0

Please sign in to comment.