Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint format #8

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions src/compas_cadwork/artists/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
from .instructionartist import LinearDimensionArtist
from .instructionartist import Model3dArtist

__all__ = [
"CadworkArtist",
"Text3dInstructionArtist",
"LinearDimensionArtist",
"Model3dArtist"
]
__all__ = ["CadworkArtist", "Text3dInstructionArtist", "LinearDimensionArtist", "Model3dArtist"]


CONTEXT = "cadwork"
Expand Down
104 changes: 0 additions & 104 deletions src/compas_cadwork/artists/beamartists.py

This file was deleted.

42 changes: 19 additions & 23 deletions src/compas_cadwork/artists/instructionartist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,23 +57,23 @@ 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

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
Expand All @@ -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.

Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -168,4 +165,3 @@ def draw(self):
point_to_cadwork(new_loc.xaxis),
point_to_cadwork(new_loc.yaxis),
)

14 changes: 9 additions & 5 deletions src/compas_cadwork/datamodel/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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())

9 changes: 8 additions & 1 deletion src/compas_cadwork/utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from compas_cadwork.datamodel import ElementGroup



def get_language() -> str:
"""Returns the current language of the cadwork application.

Expand All @@ -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}
Expand All @@ -37,6 +37,7 @@ def get_group(element: int) -> str:
"""
return ac.get_group(element)


def get_subgroup(element: int) -> str:
"""get subgroup

Expand All @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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.

Expand Down