diff --git a/src/compas_cadwork/artists/__init__.py b/src/compas_cadwork/artists/__init__.py index 247aefe..773fb24 100644 --- a/src/compas_cadwork/artists/__init__.py +++ b/src/compas_cadwork/artists/__init__.py @@ -3,6 +3,7 @@ from compas.artists import Artist from compas_monosashi.sequencer import Text3d +from compas_monosashi.sequencer import Text3d_Volume from compas_monosashi.sequencer import LinearDimension from compas_monosashi.sequencer import Model3d @@ -16,6 +17,8 @@ "CadworkArtist", "Text3dInstructionArtist", "Text3dVolumeInstructionArtist", + "LinearDimensionArtist", + "Model3dArtist" ] @@ -44,6 +47,8 @@ def redraw_cadwork(): @plugin(category="factories", requires=[CONTEXT]) def register_artists(): - Artist.register(Text3d, Text3dInstrcutionArtist, context=CONTEXT) + Artist.register(Text3d, Text3dInstructionArtist, context=CONTEXT) + Artist.register(Text3d_Volume, Text3dVolumeInstructionArtist, context=CONTEXT) Artist.register(LinearDimension, LinearDimensionArtist, context=CONTEXT) Artist.register(Model3d, Model3dArtist, context=CONTEXT) + diff --git a/src/compas_cadwork/artists/instructionartist.py b/src/compas_cadwork/artists/instructionartist.py index c628511..e91b24f 100644 --- a/src/compas_cadwork/artists/instructionartist.py +++ b/src/compas_cadwork/artists/instructionartist.py @@ -9,6 +9,8 @@ from element_controller import create_text_object from element_controller import create_text_object_with_font from element_controller import create_text_object_with_options +from element_controller import move_element +from element_controller import get_bounding_box_vertices_local from file_controller import import_element_light import cadwork @@ -73,6 +75,68 @@ def __init__(self, text_volume_instruction: Text3d_Volume, **kwargs) -> None: super().__init__(text_volume_instruction) self.text_volume_instruction = text_volume_instruction + def generate_translation_vectors_from_bounding_box_local(self, element_ids: list = [], + input_geometry: str = "3d text"): + + """Generates translation vectors from a bounding box that shift a text + or a box from the bottom left point of the object to the center point + of the object. + + + Parameters + ---------- + element_ids : list + The respective texts or boxes + input_geometry : string + Type of object + + Return + ---------- + Cadwork Vector X and Z + vx, vz + """ + + bb_vl = get_bounding_box_vertices_local(element_ids[0], element_ids) + + # as explained and diagrammed for some reason the bounding box vertices + # are sorted differently for a 3d text or a 3d box + keys_start_end = { + "Bounding Box": { + "start_vec_x": 0, + "end_vec_x": 3, + "start_vec_z": 3, + "end_vec_z": 2 + }, + "3d text": { + "start_vec_x": 5, + "end_vec_x": 6, + "start_vec_z": 6, + "end_vec_z": 3 + } + } + + vx = cadwork.point_3d(*bb_vl[keys_start_end[input_geometry]["start_vec_x"]]) - cadwork.point_3d( + *bb_vl[keys_start_end[input_geometry]["end_vec_x"]]) + dx = cadwork.point_3d(*bb_vl[keys_start_end[input_geometry]["start_vec_x"]]).distance( + cadwork.point_3d(*bb_vl[keys_start_end[input_geometry]["end_vec_x"]]))/2 + + vx = vx.normalized() + vx = vx*dx*-1 + + vz = cadwork.point_3d(*bb_vl[keys_start_end[input_geometry]["end_vec_z"]]) - cadwork.point_3d( + *bb_vl[keys_start_end[input_geometry]["start_vec_z"]]) + dz = cadwork.point_3d(*bb_vl[keys_start_end[input_geometry]["start_vec_z"]]).distance( + cadwork.point_3d(*bb_vl[keys_start_end[input_geometry]["end_vec_z"]]))/2 + + vz = vz.normalized() + vz = vz*dz*-1 + + return vx, vz + + def shift_text_from_bottom_left_to_center(self, element_ids: list = []): + vx, vz = self.generate_translation_vectors_from_bounding_box_local(element_ids) + move_element(element_ids, vx + vz) + def draw(self, *args, **kwargs): """Adds a text element with the text included in the provided text instruction. @@ -86,18 +150,19 @@ def draw(self, *args, **kwargs): text_options.set_color(5) text_options.set_element_type(cadwork.volume) text_options.set_text(self.text_volume_instruction.text) - text_options.set_height(100.0) - text_options.set_thickness(5.0) + text_options.set_height(50.0) + text_options.set_thickness(0.5) # font = "Times New Roman" loc = self.text_volume_instruction.location element_id = create_text_object_with_options( - self.text_volume_instruction.text, point_to_cadwork(loc.point), vector_to_cadwork(loc.xaxis), vector_to_cadwork(loc.yaxis), text_options ) + + self.shift_text_from_bottom_left_to_center([element_id]) self.add_element(element_id) set_user_attribute([element_id], self.USER_ATTR_NUMBER, self.USER_ATTR_VALUE) return element_id