diff --git a/setup.cfg b/setup.cfg index a443ffd..e7f4c12 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,11 @@ universal = 1 [flake8] max-line-length = 120 -exclude = */migrations/* +extend-ignore = + # See https://github.com/PyCQA/pycodestyle/issues/373 + E203, + # Only keep black line length check because flake8 forces it on comments as well + E501, [doc8] max-line-length = 120 diff --git a/src/compas_cadwork/artists/__init__.py b/src/compas_cadwork/artists/__init__.py index eeff8a6..6fc0984 100644 --- a/src/compas_cadwork/artists/__init__.py +++ b/src/compas_cadwork/artists/__init__.py @@ -11,12 +11,7 @@ from .instructionartist import LinearDimensionArtist from .instructionartist import Model3dArtist -__all__ = [ - "CadworkArtist", - "Text3dInstructionArtist", - "LinearDimensionArtist", - "Model3dArtist" -] +__all__ = ["CadworkArtist", "Text3dInstructionArtist", "LinearDimensionArtist", "Model3dArtist"] CONTEXT = "cadwork" diff --git a/src/compas_cadwork/artists/beamartists.py b/src/compas_cadwork/artists/beamartists.py deleted file mode 100644 index 6ff73ce..0000000 --- a/src/compas_cadwork/artists/beamartists.py +++ /dev/null @@ -1,104 +0,0 @@ -import os, sys - -import cadwork -import element_controller as ec -import utility_controller as uc - - -PLUGIN_PATH = uc.get_plugin_path() -SITE_PACKAGES = os.path.join(PLUGIN_PATH, "Lib", "site-packages") -sys.path.append(SITE_PACKAGES) -sys.path.append(r"C:\Users\mhelmrei\Documents\projects\monosashi\src") - -from compas.geometry import Box - - -class BeamArtist(): - """Base class for a Compas BeamArtist in Cadwork""" - def __init__(self, name : str = "", length : float = None, width : float = None): - self.name = name - self.length = length - self.width = width - - - def draw(self): - """Draws a beam to cadwork 3d through a button action and length width input data from the - user inteface. - - Parameters - ---------- - beam_name - string, beam name - beam_length - float, beam length - beam_width - float, beam width - - Returns - ------- - None - - """ - - - - cbeam = Box.from_corner_corner_height([0, 0, 0], - [0 + self.width, 0 + self.length, 0], - self.width) - - element_id = self.convert_compas_box_to_cadwork_beam(cbeam) - return element_id - - def convert_compas_box_to_cadwork_beam(self, box : object = None): - """Converts a compas box to a cadwork beam - - Parameters - ---------- - box - compas box - - Returns - ------- - draws a beam and returns element_id - - """ - point = box.vertices[0] - vector_x = box._frame.xaxis - vector_z = box._frame.zaxis - width = box.xsize - length = box.ysize - - element_id = self.draw_cadwork_square_beam_vectors(point, vector_x, vector_z, width, length) - return element_id - - def draw_cadwork_square_beam_vectors(self, point : list = [100., 200., 300.], vector_x : list = [1., 0., 0.], vector_z : list = [0., 0., 1.], width : float = 200., length : float = 2600.): - """Creates a square beam in cadwork - - Parameters - ---------- - point - list of floats, start point of the beam in mm - vector_x - list of floats, x vector length direction - vector_z - list of floats, z vector height orientation - width - float, width/ height in mm - length - float, length in mm - - Returns - ------- - draws a beam to cadwork and returns element_id - - """ - point = cadwork.point_3d(*point) - vector_x = cadwork.point_3d(*vector_x) - vector_z = cadwork.point_3d(*vector_z) - - element_id = ec.create_square_beam_vectors(width, length, point, vector_x, - vector_z) - return element_id - -if __name__ == "__main__": - pass \ No newline at end of file diff --git a/src/compas_cadwork/artists/instructionartist.py b/src/compas_cadwork/artists/instructionartist.py index 27a06d2..56a95f3 100644 --- a/src/compas_cadwork/artists/instructionartist.py +++ b/src/compas_cadwork/artists/instructionartist.py @@ -26,16 +26,13 @@ class Text3dInstructionArtist(CadworkArtist): The text instruction to draw. """ - TEXT_TYPE_MAP = { - "line": cadwork.line, - "surface": cadwork.surface, - "volume": cadwork.volume - } + + TEXT_TYPE_MAP = {"line": cadwork.line, "surface": cadwork.surface, "volume": cadwork.volume} def __init__(self, text_instruction: Text3d, **kwargs) -> None: super().__init__(text_instruction) self.text_instruction = text_instruction - + @staticmethod def _generate_translation_vectors(element_id: int): """Generates translation vectors from a bounding box that shift a text @@ -60,12 +57,12 @@ def _generate_translation_vectors(element_id: int): end_vec_x = bb[6] start_vec_z = bb[6] end_vec_z = bb[3] - + vx = start_vec_x - end_vec_x dx = start_vec_x.distance(end_vec_x) / 2.0 - + vx = vx.normalized() - vx = vx*dx*-1 + vx = vx * dx * -1 vz = end_vec_z - start_vec_z dz = start_vec_z.distance(end_vec_z) / 2.0 @@ -73,10 +70,10 @@ def _generate_translation_vectors(element_id: int): vz = vz.normalized() vz = vz * dz * -1 # write here why it has to be flipped return vx, vz - + def draw(self, *args, **kwargs): """Adds a text element with the text included in the provided text instruction. - + Returns ------- int @@ -86,31 +83,28 @@ def draw(self, *args, **kwargs): if self.text_instruction.geometry_type not in self.TEXT_TYPE_MAP: raise ValueError(f"Unsupported geometry type in Text3dArtist: {self.text_instruction.geometry_type}") - + color = 5 # TODO: find a way to map compas colors to cadwork materials - + text_options = cadwork.text_object_options() text_options.set_color(color) text_options.set_element_type(self.TEXT_TYPE_MAP[self.text_instruction.geometry_type]) text_options.set_text(self.text_instruction.text) text_options.set_height(self.text_instruction.size) text_options.set_thickness(self.text_instruction.thickness) - + 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 + point_to_cadwork(loc.point), vector_to_cadwork(loc.xaxis), vector_to_cadwork(loc.yaxis), text_options ) - + vx, vz = self._generate_translation_vectors(element_id) move_element([element_id], vx + vz) self.add_element(element_id) set_user_attribute([element_id], self.USER_ATTR_NUMBER, self.USER_ATTR_VALUE) return element_id - - + + class LinearDimensionArtist(CadworkArtist): """Draw a linear dimension instruction. @@ -120,6 +114,7 @@ class LinearDimensionArtist(CadworkArtist): The linear dimension to draw. """ + def __init__(self, linear_dimension: LinearDimension, **kwargs) -> None: super().__init__(linear_dimension) self.linear_dimension = linear_dimension @@ -133,7 +128,9 @@ def draw(self, *args, **kwargs): cadwork element ID of the added dimension. """ - direction = Vector.from_start_end(self.linear_dimension.start, self.linear_dimension.end).unitized() # why is this even needed? + direction = Vector.from_start_end( + self.linear_dimension.start, self.linear_dimension.end + ).unitized() # why is this even needed? text_plane_normal = self.linear_dimension.location.normal * -1.0 text_plane_origin = self.linear_dimension.location.point element_id = create_dimension( @@ -168,4 +165,3 @@ def draw(self): point_to_cadwork(new_loc.xaxis), point_to_cadwork(new_loc.yaxis), ) - diff --git a/src/compas_cadwork/datamodel/element.py b/src/compas_cadwork/datamodel/element.py index 080e158..a1f45e5 100644 --- a/src/compas_cadwork/datamodel/element.py +++ b/src/compas_cadwork/datamodel/element.py @@ -31,11 +31,13 @@ class StrEnum(str, Enum): """Why do *I* have to do this?""" + pass class ElementType(StrEnum): """CADWork Element type""" + BEAM = auto() # Stab PLATE = auto() # Platte SURFACE = auto() @@ -47,16 +49,16 @@ class ElementType(StrEnum): ELEMENT_TYPE_MAP = { - "de":{ + "de": { "Stab": ElementType.BEAM, "Platte": ElementType.PLATE, "Achse": ElementType.SHAFT, "Linie": ElementType.LINE, "Installation rechteckig": ElementType.INSTALLATION_STRAIGHT, "Fläche": ElementType.SURFACE, - "Installation rund": ElementType.INSTALLATION_ROUND + "Installation rund": ElementType.INSTALLATION_ROUND, }, - "en":{ + "en": { "Beam": ElementType.BEAM, "Plate": ElementType.PLATE, }, @@ -85,6 +87,7 @@ class ElementGroup: A list of Elements belonging to the Element Group """ + name: str elements: list = None wall_frame_element: Element = None @@ -147,6 +150,7 @@ class Element: Whether the Element is a framed wall i.e. container for all other elements in the building group. """ + id: int type: ElementType @@ -162,7 +166,8 @@ def frame(self) -> Frame: y_axis = Vector(*get_yl(self.id)) return Frame(p1, x_axis, y_axis) except ZeroDivisionError: - # TODO: get to the bottom of this, sometimes one of the axes comes back as [0,0,0] in the meantime just don't crash + # TODO: get to the bottom of this: + # sometimes one of the axes comes back as [0,0,0] in the meantime just don't crash return Frame.worldXY() @property @@ -233,4 +238,3 @@ def from_selection(cls) -> Generator[Element]: """ return (Element.from_id(e_id) for e_id in get_active_identifiable_element_ids()) - diff --git a/src/compas_cadwork/utilities/__init__.py b/src/compas_cadwork/utilities/__init__.py index c82911f..e5e2acf 100644 --- a/src/compas_cadwork/utilities/__init__.py +++ b/src/compas_cadwork/utilities/__init__.py @@ -13,7 +13,6 @@ from compas_cadwork.datamodel import ElementGroup - def get_language() -> str: """Returns the current language of the cadwork application. @@ -25,6 +24,7 @@ def get_language() -> str: """ return uc.get_language() + def get_group(element: int) -> str: """ [:information_source: Available for script filled attributes](#){.mark-text} @@ -37,6 +37,7 @@ def get_group(element: int) -> str: """ return ac.get_group(element) + def get_subgroup(element: int) -> str: """get subgroup @@ -50,6 +51,7 @@ def get_subgroup(element: int) -> str: """ return ac.get_subgroup(element) + def get_element_grouping_type() -> int: """Get element grouping type @@ -58,10 +60,12 @@ def get_element_grouping_type() -> int: """ return ac.get_element_grouping_type() + def get_active_element_ids() -> list: """Returns the elemend ids of the active selection""" return ec.get_active_identifiable_element_ids() + def get_plugin_home() -> str: """Returns the home root directory of the currently running plugin""" return uc.get_plugin_path() @@ -121,17 +125,20 @@ def get_element_groups(is_wall_frame=True) -> dict[str, ElementGroup]: return groups_elements + def _get_grouping_func() -> callable: if ac.get_element_grouping_type() == cadwork.element_grouping_type.subgroup: return ac.get_subgroup else: return ac.get_group + def _remove_wallless_groups(groups: Dict[str, ElementGroup]) -> None: to_remove = (group for group in groups.values() if group.wall_frame_element is None) for group in to_remove: del groups[group.name] + def activate_elements(elements: List[Union[Element, int]]) -> None: """Activates the given elements in the cadwork viewport.