From 19282888ee0143f0af538459b2aba865d8ce8c63 Mon Sep 17 00:00:00 2001 From: mistangl Date: Tue, 27 Jan 2026 16:09:52 +0100 Subject: [PATCH] =?UTF-8?q?alles=20neu=20mit=20black=20formatiert.=20handl?= =?UTF-8?q?er=5Fcontext.py=20impl.=20um=20weniger=20=C3=9Cbergabeparameter?= =?UTF-8?q?=20zu=20haben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Elemente/Angetriebene_Kurve.py | 49 +- lib/Elemente/Bt_element.py | 20 +- lib/Elemente/Eckrad.py | 54 +- lib/Elemente/Gefaellestrecke.py | 52 +- lib/Elemente/Kreisel.py | 173 ++- lib/Elemente/Omniflo.py | 99 +- lib/Elemente/VarioFoerderer.py | 1737 +++++++++++++++++++++------- lib/arbeiten_mit_csv.py | 2 +- lib/as_es_methoden.py | 1022 +++++++++++----- lib/block_methoden.py | 138 ++- lib/dxf2lib.py | 448 ++++--- lib/handler_context.py | 214 ++++ lib/inspect_blocks.py | 4 +- lib/plant2dxf.py | 1598 ++++++++++++++++++------- lib/test_files.py | 289 +++-- lib/utils.py | 11 +- 16 files changed, 4228 insertions(+), 1682 deletions(-) create mode 100644 lib/handler_context.py diff --git a/lib/Elemente/Angetriebene_Kurve.py b/lib/Elemente/Angetriebene_Kurve.py index f311d0e..6e41cca 100644 --- a/lib/Elemente/Angetriebene_Kurve.py +++ b/lib/Elemente/Angetriebene_Kurve.py @@ -1,29 +1,35 @@ - from pydantic import BaseModel, Field, field_validator + class Angetriebene_Kurve(BaseModel): teileid: str x: float - y:float - drehung: float = Field(default=0.0,description="Rotation der Kurve") - hoehe0: float = Field(default=0.0,description="Hoehe Anfang der Kurve") - hoehe1: float = Field(default=0.0,description="Hoehe Ende der Kurve") + y: float + drehung: float = Field(default=0.0, description="Rotation der Kurve") + hoehe0: float = Field(default=0.0, description="Hoehe Anfang der Kurve") + hoehe1: float = Field(default=0.0, description="Hoehe Ende der Kurve") kurvenrichtung: str = Field(description="Kurvenrichtung der Kurve") - antriebNebenStrecke: str =Field(description="wo die Angetriebene Strecke ist abhängig von der kurvenrichtung") + antriebNebenStrecke: str = Field( + description="wo die Angetriebene Strecke ist abhängig von der kurvenrichtung" + ) winkel: int = Field(description="Der Winkel der Kurve") - + @property def antrieb(self): if self.antriebNebenStrecke == "Aussen": self.antriebNebenStrecke = "außen" - elif self.antriebNebenStrecke == "Innen": + elif self.antriebNebenStrecke == "Innen": self.antriebNebenStrecke = "innen" return self.antriebNebenStrecke + @property def hight_zwischen(self): - return ((self.hoehe0 + self.hoehe1) /2) + return (self.hoehe0 + self.hoehe1) / 2 + @classmethod - def from_merkmale(cls, teileid: str, x: float, y: float, merkmale: dict) -> 'Angetriebene_Kurve': + def from_merkmale( + cls, teileid: str, x: float, y: float, merkmale: dict + ) -> "Angetriebene_Kurve": hoehe0 = float(merkmale.get("Höhe Anfang")) * 1000 hoehe1 = float(merkmale.get("Höhe Ende")) * 1000 winkel = int(merkmale.get("Kurvenwinkel")) @@ -33,16 +39,15 @@ class Angetriebene_Kurve(BaseModel): drehung = float(merkmale.get("Drehung")) except Exception as e: drehung = 0.0 - - return cls( - teileid = teileid, - x = x, - y = y, - drehung = drehung, - hoehe0 = hoehe0, - hoehe1 = hoehe1, - kurvenrichtung = kurvenrichtung, - antriebNebenStrecke = antriebNebenstrecke, - winkel = winkel - ) \ No newline at end of file + return cls( + teileid=teileid, + x=x, + y=y, + drehung=drehung, + hoehe0=hoehe0, + hoehe1=hoehe1, + kurvenrichtung=kurvenrichtung, + antriebNebenStrecke=antriebNebenstrecke, + winkel=winkel, + ) diff --git a/lib/Elemente/Bt_element.py b/lib/Elemente/Bt_element.py index 49ae57d..57ae397 100644 --- a/lib/Elemente/Bt_element.py +++ b/lib/Elemente/Bt_element.py @@ -1,14 +1,18 @@ from pydantic import BaseModel, Field, field_validator from typing import Optional + class Bt_element(BaseModel): """Das sind beide BTMT Elemente""" + teileid: str - drehung: Optional [float] = Field(default=0.0,description="Rotation des Elements") - hoehe: Optional [float] = Field(default=0.0,description="Hoehe des Elements") + drehung: Optional[float] = Field(default=0.0, description="Rotation des Elements") + hoehe: Optional[float] = Field(default=0.0, description="Hoehe des Elements") @classmethod - def from_merkmale(cls, teileid: str, x: float, y: float, merkmale: dict) -> 'Bt_element': + def from_merkmale( + cls, teileid: str, x: float, y: float, merkmale: dict + ) -> "Bt_element": try: hoehe = float(merkmale.get("Höhe in Meter")) except Exception as e: @@ -17,11 +21,5 @@ class Bt_element(BaseModel): drehung = float(merkmale.get("Drehung")) except Exception as e: drehung = 0.0 - - return cls( - teileid = teileid, - x = x, - y = y, - hoehe = hoehe, - drehung = drehung - ) \ No newline at end of file + + return cls(teileid=teileid, x=x, y=y, hoehe=hoehe, drehung=drehung) diff --git a/lib/Elemente/Eckrad.py b/lib/Elemente/Eckrad.py index be6ec0b..78aa453 100644 --- a/lib/Elemente/Eckrad.py +++ b/lib/Elemente/Eckrad.py @@ -1,15 +1,22 @@ from pydantic import BaseModel, Field, field_validator from typing import Optional import block_methoden + RADIUS = 400 + + class Eckrad(BaseModel): teileid: str - drehung: Optional [float] = Field(default=0.0,description="Rotation des Elements") - hoehe: Optional [float] = Field(default=0.0,description="Hoehe des Elements") - drehrichtung: Optional [str] =Field(default=None,description="Richtung des Eckrads") + drehung: Optional[float] = Field(default=0.0, description="Rotation des Elements") + hoehe: Optional[float] = Field(default=0.0, description="Hoehe des Elements") + drehrichtung: Optional[str] = Field( + default=None, description="Richtung des Eckrads" + ) @classmethod - def from_merkmale(cls, teileid: str, x: float, y: float, merkmale: dict) -> 'Eckrad': + def from_merkmale( + cls, teileid: str, x: float, y: float, merkmale: dict + ) -> "Eckrad": try: hoehe = float(merkmale.get("Höhe in Meter")) * 1000 except Exception as e: @@ -22,27 +29,26 @@ class Eckrad(BaseModel): drehrichtung = merkmale.get("Drehrichtung") except Exception as e: drehrichtung = None - return cls( - teileid = teileid, - x = x, - y = y, - hoehe = hoehe, - drehrichtung = drehrichtung - ) + return cls(teileid=teileid, x=x, y=y, hoehe=hoehe, drehrichtung=drehrichtung) + def erstellung_eckrad_richtung(merkmale, doc, lib_doc): - block_methoden.import_block("AN8",lib_doc,doc) - block_methoden.import_block("Richtungspfeil",lib_doc,doc) + block_methoden.import_block("AN8", lib_doc, doc) + block_methoden.import_block("Richtungspfeil", lib_doc, doc) eckrad_rechts = "eckrad_UZS" eckrad_links = "eckrad_GUZS" hight = float(merkmale.get("Höhe in m")) * 1000 - # Erstellung der Richtungung Blöcke der Eckrads - if eckrad_rechts not in doc.blocks: - block_rechts = doc.blocks.new(name= eckrad_rechts,base_point=(0,0,0)) - block_links = doc.blocks.new(name= eckrad_links,base_point=(0,0,0)) - block_rechts.add_blockref("AN8",(0,0,0)) - block_links.add_blockref("AN8",(0,0,0)) - block_rechts.add_blockref("Richtungspfeil",(0+200,0+ RADIUS,0)) - block_rechts.add_blockref("Richtungspfeil",(0-200,0- RADIUS,0),dxfattribs={"rotation": 180}) - block_links.add_blockref("Richtungspfeil",(0+200,0- RADIUS,0)) - block_links.add_blockref("Richtungspfeil",(0-200,0+ RADIUS,0),dxfattribs={"rotation": 180}) - return eckrad_rechts,eckrad_links,hight \ No newline at end of file + # Erstellung der Richtungung Blöcke der Eckrads + if eckrad_rechts not in doc.blocks: + block_rechts = doc.blocks.new(name=eckrad_rechts, base_point=(0, 0, 0)) + block_links = doc.blocks.new(name=eckrad_links, base_point=(0, 0, 0)) + block_rechts.add_blockref("AN8", (0, 0, 0)) + block_links.add_blockref("AN8", (0, 0, 0)) + block_rechts.add_blockref("Richtungspfeil", (0 + 200, 0 + RADIUS, 0)) + block_rechts.add_blockref( + "Richtungspfeil", (0 - 200, 0 - RADIUS, 0), dxfattribs={"rotation": 180} + ) + block_links.add_blockref("Richtungspfeil", (0 + 200, 0 - RADIUS, 0)) + block_links.add_blockref( + "Richtungspfeil", (0 - 200, 0 + RADIUS, 0), dxfattribs={"rotation": 180} + ) + return eckrad_rechts, eckrad_links, hight diff --git a/lib/Elemente/Gefaellestrecke.py b/lib/Elemente/Gefaellestrecke.py index 9547fe4..9b38c00 100644 --- a/lib/Elemente/Gefaellestrecke.py +++ b/lib/Elemente/Gefaellestrecke.py @@ -38,11 +38,11 @@ class Gefaellestrecke(BaseModel): anzahl_scanner = int(merkmale.get("Anzahl der Scanner")), anzahl_separatoren = int(merkmale.get("Anzahl der Separatoren")) ) - def erstehlung_von_gefalle_ohne_aussnahmen(msp, x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, halbe_laenge, winkel): + def erstehlung_von_gefalle_ohne_aussnahmen(msp, x, y, upper_hoehe_gefaelle, lower_hoehe_gefaelle, halbe_laenge, winkel): dx = halbe_laenge *math.sin(winkel * -1) dy = halbe_laenge * math.cos(winkel) - start = x +dx, y + dy,upper_hoehe_gefaehlle - ende = x -dx, y - dy,lower_hoehe_gefaehlle + start = x +dx, y + dy,upper_hoehe_gefaelle + ende = x -dx, y - dy,lower_hoehe_gefaelle line =msp.add_line(start,ende) line.dxf.layer = "6-SP" def rotation_mit_zwei_verbunden(gefaellestrecke_nachbarn,richtung2, richtung0, am_kreisel, kreisel_verbunden, hight_position): @@ -137,7 +137,7 @@ class Gefaellestrecke(BaseModel): elif gefaelle == "rechts" : rotation = 270 return rotation,drehung0,drehung1,hight_position - def ein_motor_oder_eine_umlenk(x, y,start,ende, doc, lib_doc, hoehe_gefaehlle, block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links, hat_motor_0, hat_umlenk_0, tefkurve_0, block,umlenk_gerade,motor_gerade): + def ein_motor_oder_eine_umlenk(x, y,start,ende, doc, lib_doc, hoehe_gefaelle, block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links, hat_motor_0, hat_umlenk_0, tefkurve_0, block,umlenk_gerade,motor_gerade): block_Vario_Bogen_auf = (f"Vario_Bogen_auf_3°") block_Vario_Bogen_ab = (f"Vario_Bogen_ab_3°") @@ -165,48 +165,48 @@ class Gefaellestrecke(BaseModel): if hat_motor_0 == True: if tefkurve_0 == "links": if motor_gerade == False: - block.add_blockref(block_Vario_Bogen_ab_links,(start[0]-x,start[1]-Vario_Bogen_ab_Delta_SP_0[0]-y,start[2]- Vario_Bogen_ab_Delta_SP_0[2]-hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref(block_Vario_Bogen_ab_links,(start[0]-x,start[1]-Vario_Bogen_ab_Delta_SP_0[0]-y,start[2]- Vario_Bogen_ab_Delta_SP_0[2]-hoehe_gefaelle),dxfattribs={"rotation": 270}) start = [start[0],start[1]-Vario_Bogen_ab_Delta_SP_0[0]- Vario_Bogen_ab_Delta_SP_1[0],start[2]-Vario_Bogen_ab_Delta_SP_0[2]- Vario_Bogen_ab_Delta_SP_1[2]] - block.add_blockref(blockname_motor_links, (start[0]-x,start[1] - 250* math.cos(math.radians(3))-y,start[2] - 250* math.sin(math.radians(3))-hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref(blockname_motor_links, (start[0]-x,start[1] - 250* math.cos(math.radians(3))-y,start[2] - 250* math.sin(math.radians(3))-hoehe_gefaelle),dxfattribs={"rotation": 270}) start[1]= start[1] - 500* math.cos(math.radians(3)) start[2] = start[2] - 500* math.sin(math.radians(3)) else: - block.add_blockref("Vario_Motorstation_500mm_links", (start[0]-x,start[1] -250 -y,start[2] -hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref("Vario_Motorstation_500mm_links", (start[0]-x,start[1] -250 -y,start[2] -hoehe_gefaelle),dxfattribs={"rotation": 270}) start[1]= start[1] - 500 else: if motor_gerade == False: - block.add_blockref(block_Vario_Bogen_ab,(start[0]-x,start[1]-Vario_Bogen_ab_Delta_SP_0[0]-y,start[2]- Vario_Bogen_ab_Delta_SP_0[2]-hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref(block_Vario_Bogen_ab,(start[0]-x,start[1]-Vario_Bogen_ab_Delta_SP_0[0]-y,start[2]- Vario_Bogen_ab_Delta_SP_0[2]-hoehe_gefaelle),dxfattribs={"rotation": 270}) start = [start[0],start[1]-Vario_Bogen_ab_Delta_SP_0[0]- Vario_Bogen_ab_Delta_SP_1[0],start[2]-Vario_Bogen_ab_Delta_SP_0[2]- Vario_Bogen_ab_Delta_SP_1[2]] - block.add_blockref(block_Vario_Motorstation_500mm, (start[0]-x,start[1] - 250* math.cos(math.radians(3))-y,start[2] - 250* math.sin(math.radians(3))-hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref(block_Vario_Motorstation_500mm, (start[0]-x,start[1] - 250* math.cos(math.radians(3))-y,start[2] - 250* math.sin(math.radians(3))-hoehe_gefaelle),dxfattribs={"rotation": 270}) start[1]= start[1] - 500* math.cos(math.radians(3)) start[2] = start[2] - 500* math.sin(math.radians(3)) else: - block.add_blockref("Vario_Motorstation_500mm", (start[0]-x,start[1]- 250 -y,start[2] -hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref("Vario_Motorstation_500mm", (start[0]-x,start[1]- 250 -y,start[2] -hoehe_gefaelle),dxfattribs={"rotation": 270}) start[1]= start[1] - 500 if hat_umlenk_0 == True: if tefkurve_0 == "links": if umlenk_gerade == False: - block.add_blockref(block_Vario_Bogen_auf,(ende[0]-x,ende[1]+Vario_Bogen_auf_Delta_SP_0[0]-y,ende[2] + Vario_Bogen_auf_Delta_SP_0[2]-hoehe_gefaehlle),dxfattribs={"rotation": 90}) + block.add_blockref(block_Vario_Bogen_auf,(ende[0]-x,ende[1]+Vario_Bogen_auf_Delta_SP_0[0]-y,ende[2] + Vario_Bogen_auf_Delta_SP_0[2]-hoehe_gefaelle),dxfattribs={"rotation": 90}) ende = [ende[0],ende[1]+ Vario_Bogen_auf_Delta_SP_0[0]+ Vario_Bogen_auf_Delta_SP_1[0],ende[2]+Vario_Bogen_auf_Delta_SP_0[2]+ Vario_Bogen_auf_Delta_SP_1[2]] - block.add_blockref(blockname_umlenk_links, (ende[0]-x,ende[1] + 250* math.cos(math.radians(3))-y,ende[2] + 250* math.sin(math.radians(3))-hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref(blockname_umlenk_links, (ende[0]-x,ende[1] + 250* math.cos(math.radians(3))-y,ende[2] + 250* math.sin(math.radians(3))-hoehe_gefaelle),dxfattribs={"rotation": 270}) ende [1]= ende[1] + 500* math.cos(math.radians(3)) ende[2] = ende[2] + 500* math.sin(math.radians(3)) else: - block.add_blockref("Vario_Umlenkstation_500mm_links", (ende[0]-x,ende[1] + 250-y,ende[2] -hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref("Vario_Umlenkstation_500mm_links", (ende[0]-x,ende[1] + 250-y,ende[2] -hoehe_gefaelle),dxfattribs={"rotation": 270}) ende [1]= ende[1] + 500 else: if umlenk_gerade == False: - block.add_blockref(block_Vario_Bogen_auf_links,(ende[0]-x,ende[1]+Vario_Bogen_auf_Delta_SP_0[0]-y,ende[2] + Vario_Bogen_auf_Delta_SP_0[2]-hoehe_gefaehlle),dxfattribs={"rotation": 90}) + block.add_blockref(block_Vario_Bogen_auf_links,(ende[0]-x,ende[1]+Vario_Bogen_auf_Delta_SP_0[0]-y,ende[2] + Vario_Bogen_auf_Delta_SP_0[2]-hoehe_gefaelle),dxfattribs={"rotation": 90}) ende = [ende[0],ende[1]+ Vario_Bogen_auf_Delta_SP_0[0]+ Vario_Bogen_auf_Delta_SP_1[0],ende[2]+Vario_Bogen_auf_Delta_SP_0[2]+ Vario_Bogen_auf_Delta_SP_1[2]] - block.add_blockref(block_Vario_Umlenkstation_500mm, (ende[0]-x,ende[1] + 250* math.cos(math.radians(3))-y,ende[2] + 250* math.sin(math.radians(3))-hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref(block_Vario_Umlenkstation_500mm, (ende[0]-x,ende[1] + 250* math.cos(math.radians(3))-y,ende[2] + 250* math.sin(math.radians(3))-hoehe_gefaelle),dxfattribs={"rotation": 270}) ende [1]= ende[1] + 500* math.cos(math.radians(3)) ende[2] = ende[2] + 500* math.sin(math.radians(3)) else: - block.add_blockref("Vario_Umlenkstation_500mm", (ende[0]-x,ende[1] + 250-y,ende[2] -hoehe_gefaehlle),dxfattribs={"rotation": 270}) + block.add_blockref("Vario_Umlenkstation_500mm", (ende[0]-x,ende[1] + 250-y,ende[2] -hoehe_gefaelle),dxfattribs={"rotation": 270}) ende [1]= ende[1] + 500 return start,ende def hat_motor_umlenk_station (gefaelle_objekt, gefaellestrecke_nachbarn): @@ -218,8 +218,8 @@ class Gefaellestrecke(BaseModel): tefkurve_1 = None umlenk_gerade = False motor_gerade = False - upper_hoehe_gefaehlle = gefaelle_objekt.h1 - lower_hoehe_gefaehlle = gefaelle_objekt.h0 + upper_hoehe_gefaelle = gefaelle_objekt.h1 + lower_hoehe_gefaelle = gefaelle_objekt.h0 rotation = gefaelle_objekt.drehung x = gefaelle_objekt.x y = gefaelle_objekt.y @@ -238,13 +238,13 @@ class Gefaellestrecke(BaseModel): else: tefkurve_0 = "links" - if upper_hoehe_gefaehlle > lower_hoehe_gefaehlle: - if vario_hoehe_0 == upper_hoehe_gefaehlle or vario_hoehe_1 == upper_hoehe_gefaehlle: + if upper_hoehe_gefaelle > lower_hoehe_gefaelle: + if vario_hoehe_0 == upper_hoehe_gefaelle or vario_hoehe_1 == upper_hoehe_gefaelle: hat_motor_0 = True else: hat_umlenk_0 = True - elif upper_hoehe_gefaehlle < lower_hoehe_gefaehlle: - if vario_hoehe_0 == lower_hoehe_gefaehlle or vario_hoehe_1 == lower_hoehe_gefaehlle: + elif upper_hoehe_gefaelle < lower_hoehe_gefaelle: + if vario_hoehe_0 == lower_hoehe_gefaelle or vario_hoehe_1 == lower_hoehe_gefaelle: hat_motor_0 = True else: hat_umlenk_0 = True @@ -270,13 +270,13 @@ class Gefaellestrecke(BaseModel): tefkurve_1 = "rechts" else: tefkurve_1 = "links" - if upper_hoehe_gefaehlle > lower_hoehe_gefaehlle: - if vario_hoehe_0_1 == upper_hoehe_gefaehlle or vario_hoehe_1_1 == upper_hoehe_gefaehlle: + if upper_hoehe_gefaelle > lower_hoehe_gefaelle: + if vario_hoehe_0_1 == upper_hoehe_gefaelle or vario_hoehe_1_1 == upper_hoehe_gefaelle: hat_motor_1 = True else: hat_umlenk_1 = True - elif upper_hoehe_gefaehlle < lower_hoehe_gefaehlle: - if vario_hoehe_0_1 == lower_hoehe_gefaehlle or vario_hoehe_1_1 == lower_hoehe_gefaehlle: + elif upper_hoehe_gefaelle < lower_hoehe_gefaelle: + if vario_hoehe_0_1 == lower_hoehe_gefaelle or vario_hoehe_1_1 == lower_hoehe_gefaelle: hat_motor_1 = True else: hat_umlenk_1 = True diff --git a/lib/Elemente/Kreisel.py b/lib/Elemente/Kreisel.py index bd1ff0f..c228013 100644 --- a/lib/Elemente/Kreisel.py +++ b/lib/Elemente/Kreisel.py @@ -1,29 +1,36 @@ - from ezdxf.entities import Line import math from pydantic import BaseModel, Field, field_validator from typing import Optional -import plant2dxf +import plant2dxf import block_methoden -ATTR_TAG = "TeileId" # Attributtag im Block -RADIUS = 400 # Radius der Kreiselkreise (mm) +ATTR_TAG = "TeileId" # Attributtag im Block +RADIUS = 400 # Radius der Kreiselkreise (mm) + class Kreisel(BaseModel): """Pydantic-Modell für Kreisel-Komponenten.""" + teileid: str x: float = Field(description="X-Koordinate des Kreisel-Zentrums") y: float = Field(description="Y-Koordinate des Kreisel-Zentrums") hoehe: float = Field(description="Höhe in mm") drehung: float = Field(default=0.0, description="Drehung/Winkel in Grad") - drehrichtung: Optional[str] = Field(default=None, description="Drehrichtung: UZS oder GUZS") - abstand: float = Field(default=20000.0, description="Abstand zwischen Kreiselachsen in mm") - kreiselart: Optional[str] = Field(default=None, description="Kreiselart, z.B. 'Pin'") + drehrichtung: Optional[str] = Field( + default=None, description="Drehrichtung: UZS oder GUZS" + ) + abstand: float = Field( + default=20000.0, description="Abstand zwischen Kreiselachsen in mm" + ) + kreiselart: Optional[str] = Field( + default=None, description="Kreiselart, z.B. 'Pin'" + ) anzahl_scanner: float = Field(default=0.0, description="Anzahl der Scanner") anzahl_separatoren: float = Field(default=0.0, description="Anzahl der Separatoren") - - @field_validator('abstand') + + @field_validator("abstand") @classmethod def validate_abstand(cls, v): """Konvertiert Abstand von Meter zu mm, falls nötig.""" @@ -34,8 +41,8 @@ class Kreisel(BaseModel): except ValueError: v = 10000.0 # Fallback 10 m return v - - @field_validator('hoehe') + + @field_validator("hoehe") @classmethod def validate_hoehe(cls, v): """Konvertiert Höhe von Meter zu mm, falls nötig.""" @@ -46,12 +53,12 @@ class Kreisel(BaseModel): except ValueError: v = 0.0 return v - + @property def halbabstand(self) -> float: """Halbabstand zwischen den beiden Blöcken.""" return self.abstand / 2 - + @property def winkel_rad(self) -> float: """Winkel in Radianten für Berechnungen.""" @@ -59,62 +66,66 @@ class Kreisel(BaseModel): return math.radians(self.drehung) else: return math.radians(self.drehung - 180) - + @property def richtung_rad(self) -> float: """Richtung in Radianten (für am_kreisel_direct_verbunden).""" # Wird aus drehung abgeleitet oder separat gesetzt return math.radians(self.drehung) - + @property def pos1(self) -> tuple[float, float, float]: """Position des ersten Blocks (x, y, z).""" dx = self.halbabstand * math.cos(self.winkel_rad) dy = self.halbabstand * math.sin(self.winkel_rad) return (self.x - dx, self.y - dy, self.hoehe) - + @property def pos2(self) -> tuple[float, float, float]: """Position des zweiten Blocks (x, y, z).""" dx = self.halbabstand * math.cos(self.winkel_rad) dy = self.halbabstand * math.sin(self.winkel_rad) return (self.x + dx, self.y + dy, self.hoehe) - + @property def z(self) -> float: """Z-Koordinate (gleich der Höhe).""" return self.hoehe - + @classmethod - def from_merkmale(cls, teileid: str, x: float, y: float, merkmale: dict) -> 'Kreisel': + def from_merkmale( + cls, teileid: str, x: float, y: float, merkmale: dict + ) -> "Kreisel": """Erstellt ein Kreisel-Objekt aus einem merkmale-Dictionary.""" hoehe_m = merkmale.get("Höhe in m", "0").replace(",", ".") try: hoehe = float(hoehe_m) * 1000 except (ValueError, TypeError): hoehe = 0.0 - - abstand_m = merkmale.get("Abstand (Kreiselachse A - Kreiselachse) in Meter", "20").replace(",", ".") + + abstand_m = merkmale.get( + "Abstand (Kreiselachse A - Kreiselachse) in Meter", "20" + ).replace(",", ".") try: abstand = float(abstand_m) * 1000 except (ValueError, TypeError): abstand = 10000.0 - + try: drehung = float(merkmale.get("Drehung", "0")) except (ValueError, TypeError): drehung = 0.0 - + try: anzahl_scanner = float(merkmale.get("Anzahl der Scanner", "0")) except (ValueError, TypeError): anzahl_scanner = 0.0 - + try: anzahl_separatoren = float(merkmale.get("Anzahl der Separatoren", "0")) except (ValueError, TypeError): anzahl_separatoren = 0.0 - + return cls( teileid=teileid, x=x, @@ -125,9 +136,9 @@ class Kreisel(BaseModel): abstand=abstand, kreiselart=merkmale.get("Kreiselart"), anzahl_scanner=anzahl_scanner, - anzahl_separatoren=anzahl_separatoren + anzahl_separatoren=anzahl_separatoren, ) - + def draw_kreisel_lines(msp, pos1, pos2, kreisel): """Zeichnet tangentiale Linien zwischen zwei Kreiselblöcken, unabhängig vom Winkel.""" rotation = kreisel.drehung @@ -145,58 +156,76 @@ class Kreisel(BaseModel): nx = -dy / length * RADIUS ny = dx / length * RADIUS # Tangentialpunkte - p1a = (x1 + nx, y1 + ny,z1) - p1b = (x1 - nx, y1 - ny,z1) - p2a = (x2 + nx, y2 + ny,z1) - p2b = (x2 - nx, y2 - ny,z1) + p1a = (x1 + nx, y1 + ny, z1) + p1b = (x1 - nx, y1 - ny, z1) + p2a = (x2 + nx, y2 + ny, z1) + p2b = (x2 - nx, y2 - ny, z1) if kreisel.kreiselart == "Pin": if rotation == 0.0: p1a2 = p1a[0] - RADIUS - 50, p1a[1] + 50, z1 p1b2 = p1b[0] - RADIUS - 50, p1b[1] - 50, z1 p2a2 = p2a[0] + RADIUS + 50, p2a[1] + 50, z1 p2b2 = p2b[0] + RADIUS + 50, p2b[1] - 50, z1 - Line1 = Line.new(dxfattribs={"start": p1a2,"end": p2a2,"layer": "Pinbereich"}) - Line2 = Line.new(dxfattribs={"start": p1b2,"end": p2b2,"layer": "Pinbereich"}) + Line1 = Line.new( + dxfattribs={"start": p1a2, "end": p2a2, "layer": "Pinbereich"} + ) + Line2 = Line.new( + dxfattribs={"start": p1b2, "end": p2b2, "layer": "Pinbereich"} + ) msp.add_entity(Line1) msp.add_entity(Line2) - elif rotation == 180.0: + elif rotation == 180.0: p1a2 = p1a[0] + RADIUS + 50, p1a[1] - 50, z1 p1b2 = p1b[0] + RADIUS + 50, p1b[1] + 50, z1 p2a2 = p2a[0] - RADIUS - 50, p2a[1] - 50, z1 p2b2 = p2b[0] - RADIUS - 50, p2b[1] + 50, z1 - Line1 = Line.new(dxfattribs={"start": p1a2,"end": p2a2,"layer": "Pinbereich"}) - Line2 = Line.new(dxfattribs={"start": p1b2,"end": p2b2,"layer": "Pinbereich"}) + Line1 = Line.new( + dxfattribs={"start": p1a2, "end": p2a2, "layer": "Pinbereich"} + ) + Line2 = Line.new( + dxfattribs={"start": p1b2, "end": p2b2, "layer": "Pinbereich"} + ) msp.add_entity(Line1) msp.add_entity(Line2) - elif rotation == 90.0: - p1a2 = p1a[0] + 50, p1a[1] - 50 + RADIUS , z1 - p1b2 = p1b[0] - 50, p1b[1] - 50 + RADIUS, z1 - p2a2 = p2a[0] + 50, p2a[1] + 50 - RADIUS, z1 - p2b2 = p2b[0] - 50, p2b[1] + 50 - RADIUS, z1 - Line1 = Line.new(dxfattribs={"start": p1a2,"end": p2a2,"layer": "Pinbereich"}) - Line2 = Line.new(dxfattribs={"start": p1b2,"end": p2b2,"layer": "Pinbereich"}) + elif rotation == 90.0: + p1a2 = p1a[0] + 50, p1a[1] - 50 + RADIUS, z1 + p1b2 = p1b[0] - 50, p1b[1] - 50 + RADIUS, z1 + p2a2 = p2a[0] + 50, p2a[1] + 50 - RADIUS, z1 + p2b2 = p2b[0] - 50, p2b[1] + 50 - RADIUS, z1 + Line1 = Line.new( + dxfattribs={"start": p1a2, "end": p2a2, "layer": "Pinbereich"} + ) + Line2 = Line.new( + dxfattribs={"start": p1b2, "end": p2b2, "layer": "Pinbereich"} + ) msp.add_entity(Line1) msp.add_entity(Line2) - elif rotation == 270.0: - p1a2 = p1a[0] - 50, p1a[1] + 50 - RADIUS , z1 - p1b2 = p1b[0] + 50, p1b[1] + 50 - RADIUS, z1 - p2a2 = p2a[0] - 50, p2a[1] - 50 + RADIUS, z1 - p2b2 = p2b[0] + 50, p2b[1] - 50 + RADIUS, z1 - Line1 = Line.new(dxfattribs={"start": p1a2,"end": p2a2,"layer": "Pinbereich"}) - Line2 = Line.new(dxfattribs={"start": p1b2,"end": p2b2,"layer": "Pinbereich"}) + elif rotation == 270.0: + p1a2 = p1a[0] - 50, p1a[1] + 50 - RADIUS, z1 + p1b2 = p1b[0] + 50, p1b[1] + 50 - RADIUS, z1 + p2a2 = p2a[0] - 50, p2a[1] - 50 + RADIUS, z1 + p2b2 = p2b[0] + 50, p2b[1] - 50 + RADIUS, z1 + Line1 = Line.new( + dxfattribs={"start": p1a2, "end": p2a2, "layer": "Pinbereich"} + ) + Line2 = Line.new( + dxfattribs={"start": p1b2, "end": p2b2, "layer": "Pinbereich"} + ) msp.add_entity(Line1) msp.add_entity(Line2) # Linien zeichnen msp.add_line(p1a, p2a) msp.add_line(p1b, p2b) - - def draw_kreisel_drehrichtung_markierung(msp, pos1, pos2, kreisel, lib_doc, doc, verbose): + + def draw_kreisel_drehrichtung_markierung( + msp, pos1, pos2, kreisel, lib_doc, doc, verbose + ): drehrichtung = (kreisel.drehrichtung or "").upper() if drehrichtung not in ("UZS", "GUZS"): return - x1, y1,z1= pos1 - x2, y2,z2 = pos2 + x1, y1, z1 = pos1 + x2, y2, z2 = pos2 dx = x2 - x1 dy = y2 - y1 length = math.hypot(dx, dy) @@ -216,24 +245,44 @@ class Kreisel(BaseModel): t = i / 4 # 1/4, 2/4, 3/4 px = p1_oben[0] + t * (p2_oben[0] - p1_oben[0]) py = p1_oben[1] + t * (p2_oben[1] - p1_oben[1]) - rotation = math.degrees(math.atan2(p2_oben[1] - p1_oben[1], p2_oben[0] - p1_oben[0])) + rotation = math.degrees( + math.atan2(p2_oben[1] - p1_oben[1], p2_oben[0] - p1_oben[0]) + ) if drehrichtung == "GUZS": rotation += 180 block_methoden.import_block("Richtungspfeil", lib_doc, doc) - blockref_layer, color = block_methoden.get_insert_color_layer(lib_doc, "Richtungspfeil") - bref = msp.add_blockref("Richtungspfeil", (px, py,z1), dxfattribs={"rotation": rotation,"layer": blockref_layer}) + blockref_layer, color = block_methoden.get_insert_color_layer( + lib_doc, "Richtungspfeil" + ) + bref = msp.add_blockref( + "Richtungspfeil", + (px, py, z1), + dxfattribs={"rotation": rotation, "layer": blockref_layer}, + ) if verbose: - print(f"[INFO] Drehrichtung '{drehrichtung}': Richtungspfeil oben bei ({px:.1f}, {py:.1f}), rot={rotation:.1f}") + print( + f"[INFO] Drehrichtung '{drehrichtung}': Richtungspfeil oben bei ({px:.1f}, {py:.1f}), rot={rotation:.1f}" + ) # S-LP auf unterer Linie (Drehrichtung invertiert) for i in range(1, 4): t = i / 4 px = p1_unten[0] + t * (p2_unten[0] - p1_unten[0]) py = p1_unten[1] + t * (p2_unten[1] - p1_unten[1]) - rotation = math.degrees(math.atan2(p2_unten[1] - p1_unten[1], p2_unten[0] - p1_unten[0])) + rotation = math.degrees( + math.atan2(p2_unten[1] - p1_unten[1], p2_unten[0] - p1_unten[0]) + ) if drehrichtung == "UZS": rotation += 180 block_methoden.import_block("Richtungspfeil", lib_doc, doc) - blockref_layer, color = block_methoden.get_insert_color_layer( lib_doc, "Richtungspfeil") - bref = msp.add_blockref("Richtungspfeil", (px, py, z1), dxfattribs={"rotation": rotation , "layer": blockref_layer}) + blockref_layer, color = block_methoden.get_insert_color_layer( + lib_doc, "Richtungspfeil" + ) + bref = msp.add_blockref( + "Richtungspfeil", + (px, py, z1), + dxfattribs={"rotation": rotation, "layer": blockref_layer}, + ) if verbose: - print(f"[INFO] Drehrichtung '{drehrichtung}':Richtungspfeil unten bei ({px:.1f}, {py:.1f}), rot={rotation:.1f}") \ No newline at end of file + print( + f"[INFO] Drehrichtung '{drehrichtung}':Richtungspfeil unten bei ({px:.1f}, {py:.1f}), rot={rotation:.1f}" + ) diff --git a/lib/Elemente/Omniflo.py b/lib/Elemente/Omniflo.py index 022dc7a..262d184 100644 --- a/lib/Elemente/Omniflo.py +++ b/lib/Elemente/Omniflo.py @@ -1,31 +1,37 @@ - from ezdxf.entities import Line import math from pydantic import BaseModel, Field, field_validator from typing import Optional -import plant2dxf +import plant2dxf import block_methoden + + class Omniflo(BaseModel): - teileid:str - x:float - y:float - sivasnummer:str - laenge: Optional [float] + teileid: str + x: float + y: float + sivasnummer: str + laenge: Optional[float] drehung: float - hoehe : Optional[float] - h0: Optional[float] = Field(default = 0.0,description="Höhe unten im CSV") - h1: Optional[float] = Field(default = 0.0, description="Höhe Oben im CSV") - anzahl_scanner: Optional [int] = Field(default=0, description="Anzahl der Scanner") - anzahl_stopper: Optional [int] = Field(default=0, description="Anzahl der Separatoren") + hoehe: Optional[float] + h0: Optional[float] = Field(default=0.0, description="Höhe unten im CSV") + h1: Optional[float] = Field(default=0.0, description="Höhe Oben im CSV") + anzahl_scanner: Optional[int] = Field(default=0, description="Anzahl der Scanner") + anzahl_stopper: Optional[int] = Field( + default=0, description="Anzahl der Separatoren" + ) @property def hight_zwischen(self): - return ((self.h0 + self.h1) /2) + return (self.h0 + self.h1) / 2 + @classmethod - def from_merkmale(cls, teileid,x,y, merkmale): + def from_merkmale(cls, teileid, x, y, merkmale): sivasnummer = merkmale.get("SivasNummer") try: - laenge = float(merkmale.get("Länge in Meter", "0").replace(",", ".")) * 1000 # Meter → mm + laenge = ( + float(merkmale.get("Länge in Meter", "0").replace(",", ".")) * 1000 + ) # Meter → mm except Exception: laenge = 0 try: @@ -37,7 +43,7 @@ class Omniflo(BaseModel): except Exception: hoehe = 0.0 try: - h0 = float(merkmale.get("Höhe unten")) + h0 = float(merkmale.get("Höhe unten")) except Exception: h0 = 0.0 try: @@ -45,26 +51,27 @@ class Omniflo(BaseModel): except Exception: h1 = 0.0 try: - anzahl_scanner = float(merkmale.get("Anzahl der Scanner", "0")) + anzahl_scanner = float(merkmale.get("Anzahl der Scanner", "0")) except Exception: anzahl_scanner = 0 try: - anzahl_separatoren = float(merkmale.get("Anzahl der Separatoren", "0")) + anzahl_separatoren = float(merkmale.get("Anzahl der Separatoren", "0")) except Exception: anzahl_separatoren = 0 return cls( - teileid= teileid, + teileid=teileid, x=x, y=y, - sivasnummer = sivasnummer, - laenge = laenge, - drehung = winkel, - hoehe = hoehe, - h0 = h0, - h1 = h1, - anzahl_scanner = anzahl_scanner, - anzahl_stopper = anzahl_separatoren + sivasnummer=sivasnummer, + laenge=laenge, + drehung=winkel, + hoehe=hoehe, + h0=h0, + h1=h1, + anzahl_scanner=anzahl_scanner, + anzahl_stopper=anzahl_separatoren, ) + def Omniflo_geraden_erstellung(msp, doc, tefsivas, omniflo_objekt): """Erstellung der Tef gerade und Omniflo gerade""" winkel_rad = math.radians(omniflo_objekt.drehung) @@ -74,21 +81,22 @@ class Omniflo(BaseModel): # Man muss bei sin -1 machen wegen des links koordinaten system dx = halbe_laenge * math.sin(winkel_rad * -1) dy = halbe_laenge * math.cos(winkel_rad) - start = (x + dx, y + dy, omniflo_objekt.h1 ) - ende = (x - dx, y - dy, omniflo_objekt.h0) + start = (x + dx, y + dy, omniflo_objekt.h1) + ende = (x - dx, y - dy, omniflo_objekt.h0) if "A-2" not in doc.layers: doc.layers.add(name="A-2", color=2) if "F-1" not in doc.layers: - doc.layers.add(name="F-1", color =1) - linie=msp.add_line(start, ende) + doc.layers.add(name="F-1", color=1) + linie = msp.add_line(start, ende) if omniflo_objekt.sivasnummer == tefsivas: linie.dxf.layer = "F-1" else: linie.dxf.layer = "A-2" + def omniflo_foerdererstellung(msp, doc, lib_doc, omniflo_objekt): - """"Erstellung des Kettenförderers aktuell nur grundriss""" - block_methoden.import_block("bogen1",lib_doc,doc) - block_methoden.import_block("bogen2",lib_doc,doc) + """ "Erstellung des Kettenförderers aktuell nur grundriss""" + block_methoden.import_block("bogen1", lib_doc, doc) + block_methoden.import_block("bogen2", lib_doc, doc) x = omniflo_objekt.x y = omniflo_objekt.y rotation = omniflo_objekt.drehung @@ -96,21 +104,22 @@ class Omniflo(BaseModel): h0 = omniflo_objekt.h0 h1 = omniflo_objekt.h1 h_zwischen = omniflo_objekt.hight_zwischen - blockname = (f"OF_Förderer_{laenge}_{h_zwischen}") + blockname = f"OF_Förderer_{laenge}_{h_zwischen}" winkel_rad = math.radians(rotation) halbe_laenge = laenge / 2 - # Man muss bei sin -1 machen wegen des links koordinaten system + # Man muss bei sin -1 machen wegen des links koordinaten system dx = halbe_laenge * math.sin(rotation * -1) dy = halbe_laenge * math.cos(rotation) - start = (x + dx, y + dy, h1 ) - ende = (x - dx, y - dy, h0) + start = (x + dx, y + dy, h1) + ende = (x - dx, y - dy, h0) if blockname not in doc.blocks: - block = doc.blocks.new(blockname, base_point=(0,0,0)) - block.add_blockref("bogen1",start) - block.add_blockref("bogen2",ende) - line = Line.new(dxfattribs={"start": start,"end":ende}) + block = doc.blocks.new(blockname, base_point=(0, 0, 0)) + block.add_blockref("bogen1", start) + block.add_blockref("bogen2", ende) + line = Line.new(dxfattribs={"start": start, "end": ende}) copy = line.copy() - copy.translate(-x,-y,-h_zwischen) + copy.translate(-x, -y, -h_zwischen) block.add_entity(copy) - msp.add_blockref(blockname,(x,y,h_zwischen),dxfattribs={"rotation": rotation}) - \ No newline at end of file + msp.add_blockref( + blockname, (x, y, h_zwischen), dxfattribs={"rotation": rotation} + ) diff --git a/lib/Elemente/VarioFoerderer.py b/lib/Elemente/VarioFoerderer.py index 8da439c..041aaa6 100644 --- a/lib/Elemente/VarioFoerderer.py +++ b/lib/Elemente/VarioFoerderer.py @@ -2,7 +2,7 @@ from ezdxf.entities import Line import math from pydantic import BaseModel, Field, field_validator from typing import Optional -import plant2dxf +import plant2dxf from ezdxf.math import Matrix44 import re import block_methoden @@ -12,27 +12,35 @@ class VarioFoerderer(BaseModel): teileid: str x: float = Field(description="X-Koordinate des Foerder-Zentrums") y: float = Field(description="Y-Koordinate des Foerder-Zentrums") - laenge:float = Field(description = "Länge des Förderers") - winkel: float = Field(description = "Winkel des Färderers") + laenge: float = Field(description="Länge des Förderers") + winkel: float = Field(description="Winkel des Färderers") h0: float = Field(description="Höhe Anfang in Merkmale") h1: float = Field(description="Höhe Ende in Merkmale") hat_motor: bool = Field(description="Überprüft ob der Vörderer ein Motor hat") - hat_umlenk: bool = Field(description="Überprüft ob der Vörderer eine Umlenkstation hat") + hat_umlenk: bool = Field( + description="Überprüft ob der Vörderer eine Umlenkstation hat" + ) drehung: float = Field(default=0.0, description="Drehung/Winkel in Grad") - foerderer_richtung : str= Field(description="In welche richtung geförderd wird") - gefaelle_laenge: Optional [float] = Field(default=0.0,description="Länge der zusätzlichen Gefälle Strecke falls vorhanden") - gefaelle_winkel: Optional [float] = Field(default=0.0,description="Winkel der Gefällestrecke, falls diese Vorhanden ist") + foerderer_richtung: str = Field(description="In welche richtung geförderd wird") + gefaelle_laenge: Optional[float] = Field( + default=0.0, + description="Länge der zusätzlichen Gefälle Strecke falls vorhanden", + ) + gefaelle_winkel: Optional[float] = Field( + default=0.0, description="Winkel der Gefällestrecke, falls diese Vorhanden ist" + ) anzahl_scanner: int = Field(default=0, description="Anzahl der Scanner") anzahl_separatoren: int = Field(default=0, description="Anzahl der Separatoren") - + @property def hight_zwischen(self): - return ((self.h0 + self.h1) /2) - - + return (self.h0 + self.h1) / 2 + @classmethod - def from_merkmale(cls, teileid: str, x: float, y: float, merkmale: dict) -> 'VarioFoerderer': - + def from_merkmale( + cls, teileid: str, x: float, y: float, merkmale: dict + ) -> "VarioFoerderer": + h0 = float(merkmale.get("Höhe Anfang")) * 1000 h1 = float(merkmale.get("Höhe Ende")) * 1000 laenge = float(merkmale.get("Länge in Meter")) * 1000 @@ -45,23 +53,23 @@ class VarioFoerderer(BaseModel): gefaelle_laenge = float(gefaelle_laenge) gefaelle_winkel = float(gefaelle_winkel) return cls( - teileid = teileid, - x = x, - y = y, - laenge = laenge, - winkel = float(merkmale.get("Winkel")), - h0 = h0, - h1 =h1, - hat_motor = bool(merkmale.get("Motorstation_hinten")), - hat_umlenk = bool(merkmale.get("Spannstation_vorn")), - drehung = float(merkmale.get("Drehung")), - foerderer_richtung =merkmale.get("Förderrichtung"), - gefaelle_laenge = gefaelle_laenge, - gefaelle_winkel = gefaelle_winkel, - anzahl_scanner = int(merkmale.get("Anzahl der Scanner")), - anzahl_separatoren = int(merkmale.get("Anzahl der Separatoren")) - + teileid=teileid, + x=x, + y=y, + laenge=laenge, + winkel=float(merkmale.get("Winkel")), + h0=h0, + h1=h1, + hat_motor=bool(merkmale.get("Motorstation_hinten")), + hat_umlenk=bool(merkmale.get("Spannstation_vorn")), + drehung=float(merkmale.get("Drehung")), + foerderer_richtung=merkmale.get("Förderrichtung"), + gefaelle_laenge=gefaelle_laenge, + gefaelle_winkel=gefaelle_winkel, + anzahl_scanner=int(merkmale.get("Anzahl der Scanner")), + anzahl_separatoren=int(merkmale.get("Anzahl der Separatoren")), ) + def get_offset_of_Vario_line(doc, lib_doc, foerderer, gefaellestrecke_vario): """Schaut nach was für ein Zusatz oder nicht man braucht falls es kein motor/umlenk station hat und kein bogen""" winkel_VP_offset_vorne = None @@ -69,110 +77,268 @@ class VarioFoerderer(BaseModel): voerder_richtung = foerderer.foerderer_richtung winkel = int(foerderer.winkel) rotation = foerderer.drehung - upper_hoehe_vario= foerderer.h1 + upper_hoehe_vario = foerderer.h1 lower_hoehe_vario = foerderer.h0 - if (gefaellestrecke_vario.get("Winkel") != None or gefaellestrecke_vario.get("Kurvenrichtung") != None) and ((winkel == 3 and voerder_richtung == "Ab")or voerder_richtung == "Horizontal"): - # Überprüfung wo es verbunden ist und mit welchen fördere vorne ist ende der Fahrrichtung - if gefaellestrecke_vario.get("h0") != None : - if float(gefaellestrecke_vario.get("h0")) == lower_hoehe_vario and voerder_richtung != "Horizontal": - if (gefaellestrecke_vario.get("Foerderrichtung") == "Auf"): + if ( + gefaellestrecke_vario.get("Winkel") != None + or gefaellestrecke_vario.get("Kurvenrichtung") != None + ) and ( + (winkel == 3 and voerder_richtung == "Ab") + or voerder_richtung == "Horizontal" + ): + # Überprüfung wo es verbunden ist und mit welchen fördere vorne ist ende der Fahrrichtung + if gefaellestrecke_vario.get("h0") != None: + if ( + float(gefaellestrecke_vario.get("h0")) == lower_hoehe_vario + and voerder_richtung != "Horizontal" + ): + if gefaellestrecke_vario.get("Foerderrichtung") == "Auf": # Nehmen des winkels und diesen plus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte - winkel_vorne_plusbogen = int(gefaellestrecke_vario.get("Winkel")) +3 - winkel_vorne = int(gefaellestrecke_vario.get("Winkel")) - blockname = (f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°") - att_vorne =block_methoden.import_block(blockname,lib_doc,doc) - SP_1_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"])) - VP_1_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"])) + winkel_vorne_plusbogen = ( + int(gefaellestrecke_vario.get("Winkel")) + 3 + ) + winkel_vorne = int(gefaellestrecke_vario.get("Winkel")) + blockname = f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°" + att_vorne = block_methoden.import_block(blockname, lib_doc, doc) + SP_1_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"]) + ) + VP_1_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"]) + ) # Ausrechnen des Offsets - winkel_VP_offset_hinten = (SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) * math.cos(math.radians(3)) + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2])*math.sin(math.radians(3)), VP_1_nachbar_vorne[1],- (SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) * math.sin(math.radians(3)) + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2])*math.cos(math.radians(3)) - - elif gefaellestrecke_vario.get("Foerderrichtung") == "Ab" : - # Nehmen des winkels und diesen minus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte - winkel_vorne_minusbogen = int(gefaellestrecke_vario.get("Winkel")) -3 - winkel_vorne = int(gefaellestrecke_vario.get("Winkel")) - - blockname = (f"Vario_Bogen_ab_{winkel_vorne_minusbogen}°") - att_vorne =block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"])) - VP_0_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"])) - # Ausrechnung des Offsets - winkel_VP_offset_hinten = (SP_0_nachbar_vorne[0] - VP_0_nachbar_vorne[0]) * math.cos(math.radians(3)) + (SP_0_nachbar_vorne[2] - VP_0_nachbar_vorne[2])*math.sin(math.radians(3)), VP_0_nachbar_vorne[1],- (SP_0_nachbar_vorne[0] - VP_0_nachbar_vorne[0]) * math.sin(math.radians(3)) + (SP_0_nachbar_vorne[2] - VP_0_nachbar_vorne[2])*math.cos(math.radians(3)) - - elif float(gefaellestrecke_vario.get("h1")) == upper_hoehe_vario and voerder_richtung != "Horizontal": - if (gefaellestrecke_vario.get("Foerderrichtung") == "Auf" ): - # Nehmen des winkels und diesen plus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte - winkel_hinten_plusbogen = int(gefaellestrecke_vario.get("Winkel")) +3 - winkel_hinten = int(gefaellestrecke_vario.get("Winkel")) - - blockname = (f"Vario_Bogen_ab_{winkel_hinten_plusbogen}°") - att_hinten =block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"])) - VP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"])) - # Ausrechnung des Offsets - winkel_VP_offset_vorne = (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) * math.cos(math.radians(-winkel_hinten)) + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2])*math.sin(math.radians(-winkel_hinten)), VP_0_nachbar_hinten[1],- (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) * math.sin(math.radians(-winkel_hinten)) + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2])*math.cos(math.radians(-winkel_hinten)) + winkel_VP_offset_hinten = ( + (SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) + * math.cos(math.radians(3)) + + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2]) + * math.sin(math.radians(3)), + VP_1_nachbar_vorne[1], + -(SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) + * math.sin(math.radians(3)) + + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2]) + * math.cos(math.radians(3)), + ) elif gefaellestrecke_vario.get("Foerderrichtung") == "Ab": # Nehmen des winkels und diesen minus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte - winkel_hinten_minusbogen = int(gefaellestrecke_vario.get("Winkel")) -3 - winkel_hinten = int(gefaellestrecke_vario.get("Winkel")) + winkel_vorne_minusbogen = ( + int(gefaellestrecke_vario.get("Winkel")) - 3 + ) + winkel_vorne = int(gefaellestrecke_vario.get("Winkel")) - blockname = (f"Vario_Bogen_auf_{winkel_hinten_minusbogen}°") - att_hinten =block_methoden.import_block(blockname,lib_doc,doc) - SP_1_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"])) - VP_1_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"])) + blockname = f"Vario_Bogen_ab_{winkel_vorne_minusbogen}°" + att_vorne = block_methoden.import_block(blockname, lib_doc, doc) + SP_0_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"]) + ) + VP_0_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"]) + ) # Ausrechnung des Offsets - winkel_VP_offset_vorne = (SP_1_nachbar_hinten[0] - VP_1_nachbar_hinten[0]) * math.cos(math.radians(winkel_hinten)) + (SP_1_nachbar_hinten[2] - VP_1_nachbar_hinten[2])*math.sin(math.radians(winkel_hinten)), VP_1_nachbar_hinten[1],- (SP_1_nachbar_hinten[0] - VP_1_nachbar_hinten[0]) * math.sin(math.radians(winkel_hinten)) + (SP_1_nachbar_hinten[2] - VP_1_nachbar_hinten[2])*math.cos(math.radians(winkel_hinten)) + winkel_VP_offset_hinten = ( + (SP_0_nachbar_vorne[0] - VP_0_nachbar_vorne[0]) + * math.cos(math.radians(3)) + + (SP_0_nachbar_vorne[2] - VP_0_nachbar_vorne[2]) + * math.sin(math.radians(3)), + VP_0_nachbar_vorne[1], + -(SP_0_nachbar_vorne[0] - VP_0_nachbar_vorne[0]) + * math.sin(math.radians(3)) + + (SP_0_nachbar_vorne[2] - VP_0_nachbar_vorne[2]) + * math.cos(math.radians(3)), + ) + + elif ( + float(gefaellestrecke_vario.get("h1")) == upper_hoehe_vario + and voerder_richtung != "Horizontal" + ): + if gefaellestrecke_vario.get("Foerderrichtung") == "Auf": + # Nehmen des winkels und diesen plus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte + winkel_hinten_plusbogen = ( + int(gefaellestrecke_vario.get("Winkel")) + 3 + ) + winkel_hinten = int(gefaellestrecke_vario.get("Winkel")) + + blockname = f"Vario_Bogen_ab_{winkel_hinten_plusbogen}°" + att_hinten = block_methoden.import_block( + blockname, lib_doc, doc + ) + SP_0_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"]) + ) + VP_0_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"]) + ) + # Ausrechnung des Offsets + winkel_VP_offset_vorne = ( + (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) + * math.cos(math.radians(-winkel_hinten)) + + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2]) + * math.sin(math.radians(-winkel_hinten)), + VP_0_nachbar_hinten[1], + -(SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) + * math.sin(math.radians(-winkel_hinten)) + + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2]) + * math.cos(math.radians(-winkel_hinten)), + ) + + elif gefaellestrecke_vario.get("Foerderrichtung") == "Ab": + # Nehmen des winkels und diesen minus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte + winkel_hinten_minusbogen = ( + int(gefaellestrecke_vario.get("Winkel")) - 3 + ) + winkel_hinten = int(gefaellestrecke_vario.get("Winkel")) + + blockname = f"Vario_Bogen_auf_{winkel_hinten_minusbogen}°" + att_hinten = block_methoden.import_block( + blockname, lib_doc, doc + ) + SP_1_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"]) + ) + VP_1_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"]) + ) + # Ausrechnung des Offsets + winkel_VP_offset_vorne = ( + (SP_1_nachbar_hinten[0] - VP_1_nachbar_hinten[0]) + * math.cos(math.radians(winkel_hinten)) + + (SP_1_nachbar_hinten[2] - VP_1_nachbar_hinten[2]) + * math.sin(math.radians(winkel_hinten)), + VP_1_nachbar_hinten[1], + -(SP_1_nachbar_hinten[0] - VP_1_nachbar_hinten[0]) + * math.sin(math.radians(winkel_hinten)) + + (SP_1_nachbar_hinten[2] - VP_1_nachbar_hinten[2]) + * math.cos(math.radians(winkel_hinten)), + ) elif voerder_richtung == "Horizontal": - winkel_vorne_plusbogen = int(gefaellestrecke_vario.get("Winkel")) +3 - winkel_hinten = int(gefaellestrecke_vario.get("Winkel")) - blockname = (f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°") - att_vorne =block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_SP_1"])) - VP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_VP_1"])) - SP_1_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"])) - VP_1_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"])) - x_foerderer =gefaellestrecke_vario.get("X_foerderer") - y_foerderer =gefaellestrecke_vario.get("Y_foerderer") + winkel_vorne_plusbogen = ( + int(gefaellestrecke_vario.get("Winkel")) + 3 + ) + winkel_hinten = int(gefaellestrecke_vario.get("Winkel")) + blockname = f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°" + att_vorne = block_methoden.import_block(blockname, lib_doc, doc) + SP_0_nachbar_hinten = list( + float(att) for att in re.split(r"[;,]", att_vorne["DELTA_SP_1"]) + ) + VP_0_nachbar_hinten = list( + float(att) for att in re.split(r"[;,]", att_vorne["DELTA_VP_1"]) + ) + SP_1_nachbar_vorne = list( + float(att) for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"]) + ) + VP_1_nachbar_vorne = list( + float(att) for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"]) + ) + x_foerderer = gefaellestrecke_vario.get("X_foerderer") + y_foerderer = gefaellestrecke_vario.get("Y_foerderer") x = foerderer.x y = foerderer.y rotation_zwischen = rotation if rotation_zwischen == 0.0: rotation_zwischen = -360.0 - if (((-360.0<= rotation_zwischen< -270.0)and y > y_foerderer) or ((-90.0< rotation< 0.0)and y > y_foerderer) or - ((-270.0< rotation_zwischen< -90.0)and y < y_foerderer) or - (rotation == -90.0 and x < x_foerderer) or ((rotation == -270.0)and x y_foerderer) + or ((-90.0 < rotation < 0.0) and y > y_foerderer) + or ((-270.0 < rotation_zwischen < -90.0) and y < y_foerderer) + or (rotation == -90.0 and x < x_foerderer) + or ((rotation == -270.0) and x < x_foerderer) + ): + blockname = f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°" + att_vorne = block_methoden.import_block(blockname, lib_doc, doc) + SP_1_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"]) + ) + VP_1_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"]) + ) + winkel_VP_offset_vorne = ( + (SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) + * math.cos(math.radians(3)) + + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2]) + * math.sin(math.radians(3)), + VP_1_nachbar_vorne[1], + -(SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) + * math.sin(math.radians(3)) + + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2]) + * math.cos(math.radians(3)), + ) else: - blockname = (f"Vario_Bogen_ab_{winkel_vorne_plusbogen}°") - att_hinten =block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"])) - VP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"])) - winkel_VP_offset_hinten = (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) * math.cos(math.radians(-winkel_hinten)) + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2])*math.sin(math.radians(-winkel_hinten)), VP_0_nachbar_hinten[1],- (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) * math.sin(math.radians(-winkel_hinten)) + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2])*math.cos(math.radians(-winkel_hinten)) + blockname = f"Vario_Bogen_ab_{winkel_vorne_plusbogen}°" + att_hinten = block_methoden.import_block( + blockname, lib_doc, doc + ) + SP_0_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"]) + ) + VP_0_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"]) + ) + winkel_VP_offset_hinten = ( + (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) + * math.cos(math.radians(-winkel_hinten)) + + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2]) + * math.sin(math.radians(-winkel_hinten)), + VP_0_nachbar_hinten[1], + -(SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) + * math.sin(math.radians(-winkel_hinten)) + + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2]) + * math.cos(math.radians(-winkel_hinten)), + ) - else: - blockname = (f"Vario_Kurve_{gefaellestrecke_vario.get("Kurvenrichtung")}_{gefaellestrecke_vario.get("Kurvenwinkel")}°_TEF_{gefaellestrecke_vario.get("Tefkurve")}") - att_kurve = block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar = list(float(att)for att in re.split(r"[;,]", att_kurve["DELTA_SP_0"])) - VP_0_nachbar = list(float(att)for att in re.split(r"[;,]", att_kurve["DELTA_VP_0"])) - SP_1_nachbar = list(float(att)for att in re.split(r"[;,]", att_kurve["DELTA_SP_1"])) - VP_1_nachbar= list(float(att)for att in re.split(r"[;,]", att_kurve["DELTA_VP_1"])) - if (SP_1_nachbar[0] < 0 and VP_1_nachbar[0] < 0) or (SP_1_nachbar[0] >= 0 and VP_1_nachbar[0] < 0): + blockname = f"Vario_Kurve_{gefaellestrecke_vario.get("Kurvenrichtung")}_{gefaellestrecke_vario.get("Kurvenwinkel")}°_TEF_{gefaellestrecke_vario.get("Tefkurve")}" + att_kurve = block_methoden.import_block(blockname, lib_doc, doc) + SP_0_nachbar = list( + float(att) for att in re.split(r"[;,]", att_kurve["DELTA_SP_0"]) + ) + VP_0_nachbar = list( + float(att) for att in re.split(r"[;,]", att_kurve["DELTA_VP_0"]) + ) + SP_1_nachbar = list( + float(att) for att in re.split(r"[;,]", att_kurve["DELTA_SP_1"]) + ) + VP_1_nachbar = list( + float(att) for att in re.split(r"[;,]", att_kurve["DELTA_VP_1"]) + ) + if (SP_1_nachbar[0] < 0 and VP_1_nachbar[0] < 0) or ( + SP_1_nachbar[0] >= 0 and VP_1_nachbar[0] < 0 + ): SP_1_nachbar[0] = SP_1_nachbar[0] * -1 VP_1_nachbar[0] = VP_1_nachbar[0] * -1 - if (SP_0_nachbar[1] < 0 and VP_0_nachbar[1] < 0) or (SP_0_nachbar[1] >= 0 and VP_0_nachbar[1] < 0): + if (SP_0_nachbar[1] < 0 and VP_0_nachbar[1] < 0) or ( + SP_0_nachbar[1] >= 0 and VP_0_nachbar[1] < 0 + ): SP_0_nachbar[1] = SP_0_nachbar[1] * -1 VP_0_nachbar[1] = VP_0_nachbar[1] * -1 if voerder_richtung == "Ab": - - if float(gefaellestrecke_vario.get("vario_hoehe_1")) == lower_hoehe_vario: - winkel_VP_offset_hinten = (SP_1_nachbar[0] -VP_1_nachbar[0] ),0,( SP_1_nachbar[2]- VP_1_nachbar[2]) + + if ( + float(gefaellestrecke_vario.get("vario_hoehe_1")) + == lower_hoehe_vario + ): + winkel_VP_offset_hinten = ( + (SP_1_nachbar[0] - VP_1_nachbar[0]), + 0, + (SP_1_nachbar[2] - VP_1_nachbar[2]), + ) else: - winkel_VP_offset_vorne = (SP_0_nachbar[1] -VP_0_nachbar[1] ),0,( SP_1_nachbar[2]- VP_0_nachbar[2]) + winkel_VP_offset_vorne = ( + (SP_0_nachbar[1] - VP_0_nachbar[1]), + 0, + (SP_1_nachbar[2] - VP_0_nachbar[2]), + ) else: x_angetrieben = gefaellestrecke_vario.get("X_angetrieben") y_angetrieben = gefaellestrecke_vario.get("Y_angetrieben") @@ -181,115 +347,284 @@ class VarioFoerderer(BaseModel): rotation_zwischen = rotation if rotation_zwischen == 0.0: rotation_zwischen = -360.0 - if (((-360.0<= rotation_zwischen< -270.0)and y > y_angetrieben) or ((-90.0< rotation< 0.0)and y > y_angetrieben) or - ((-270.0< rotation_zwischen< -90.0)and y < y_angetrieben) or - (rotation == -90.0 and x < x_angetrieben) or ((rotation == -270.0)and x < x_angetrieben)): - winkel_VP_offset_hinten = (SP_0_nachbar[1] -VP_0_nachbar[1] ),0,( SP_1_nachbar[2]- VP_0_nachbar[2]) + if ( + ((-360.0 <= rotation_zwischen < -270.0) and y > y_angetrieben) + or ((-90.0 < rotation < 0.0) and y > y_angetrieben) + or ((-270.0 < rotation_zwischen < -90.0) and y < y_angetrieben) + or (rotation == -90.0 and x < x_angetrieben) + or ((rotation == -270.0) and x < x_angetrieben) + ): + winkel_VP_offset_hinten = ( + (SP_0_nachbar[1] - VP_0_nachbar[1]), + 0, + (SP_1_nachbar[2] - VP_0_nachbar[2]), + ) else: - winkel_VP_offset_vorne = (SP_1_nachbar[0] -VP_1_nachbar[0] ),0,( SP_1_nachbar[2]- VP_1_nachbar[2]) + winkel_VP_offset_vorne = ( + (SP_1_nachbar[0] - VP_1_nachbar[0]), + 0, + (SP_1_nachbar[2] - VP_1_nachbar[2]), + ) - - - # Das gleiche falls der 3 grad Förderer mit zwei Förderer Verbunden ist - if (gefaellestrecke_vario.get("Winkel_2") != None or gefaellestrecke_vario.get("Kurvenrichtung_1") != None) and ((winkel == 3 and voerder_richtung == "Ab")or voerder_richtung == "Horizontal"): - # Überprüfung wo es verbunden ist und mit welchen fördere vorne ist ende der Fahrrichtung + # Das gleiche falls der 3 grad Förderer mit zwei Förderer Verbunden ist + if ( + gefaellestrecke_vario.get("Winkel_2") != None + or gefaellestrecke_vario.get("Kurvenrichtung_1") != None + ) and ( + (winkel == 3 and voerder_richtung == "Ab") + or voerder_richtung == "Horizontal" + ): + # Überprüfung wo es verbunden ist und mit welchen fördere vorne ist ende der Fahrrichtung if gefaellestrecke_vario.get("h0_2") != None: - if float(gefaellestrecke_vario.get("h0_2")) == lower_hoehe_vario and voerder_richtung != "Horizontal": - if (gefaellestrecke_vario.get("Foerderrichtung_2") == "Auf"): + if ( + float(gefaellestrecke_vario.get("h0_2")) == lower_hoehe_vario + and voerder_richtung != "Horizontal" + ): + if gefaellestrecke_vario.get("Foerderrichtung_2") == "Auf": # Nehmen des winkels und diesen plus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte - winkel_vorne_plusbogen = int(gefaellestrecke_vario.get("Winkel_2")) +3 - winkel_vorne = int(gefaellestrecke_vario.get("Winkel_2")) - blockname = (f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°") - att_vorne =block_methoden.import_block(blockname,lib_doc,doc) - SP_1_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"])) - VP_1_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"])) + winkel_vorne_plusbogen = ( + int(gefaellestrecke_vario.get("Winkel_2")) + 3 + ) + winkel_vorne = int(gefaellestrecke_vario.get("Winkel_2")) + blockname = f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°" + att_vorne = block_methoden.import_block(blockname, lib_doc, doc) + SP_1_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"]) + ) + VP_1_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"]) + ) # Ausrechnen des Offsets - winkel_VP_offset_hinten = (SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) * math.cos(math.radians(3)) + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2])*math.sin(math.radians(3)), VP_1_nachbar_vorne[1],- (SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) * math.sin(math.radians(3)) + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2])*math.cos(math.radians(3)) + winkel_VP_offset_hinten = ( + (SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) + * math.cos(math.radians(3)) + + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2]) + * math.sin(math.radians(3)), + VP_1_nachbar_vorne[1], + -(SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) + * math.sin(math.radians(3)) + + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2]) + * math.cos(math.radians(3)), + ) elif gefaellestrecke_vario.get("Foerderrichtung_2") == "Ab": - # Nehmen des winkels und diesen minus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte - winkel_vorne_minusbogen = int(gefaellestrecke_vario.get("Winkel_2")) -3 - winkel_vorne = int(gefaellestrecke_vario.get("Winkel_2")) + # Nehmen des winkels und diesen minus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte + winkel_vorne_minusbogen = ( + int(gefaellestrecke_vario.get("Winkel_2")) - 3 + ) + winkel_vorne = int(gefaellestrecke_vario.get("Winkel_2")) - blockname = (f"Vario_Bogen_ab_{winkel_vorne_minusbogen}°") - att_vorne =block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"])) - VP_0_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"])) + blockname = f"Vario_Bogen_ab_{winkel_vorne_minusbogen}°" + att_vorne = block_methoden.import_block(blockname, lib_doc, doc) + SP_0_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"]) + ) + VP_0_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"]) + ) # Ausrechnung des Offsets - winkel_VP_offset_hinten = (SP_0_nachbar_vorne[0] - VP_0_nachbar_vorne[0]) * math.cos(math.radians(3)) + (SP_0_nachbar_vorne[2] - VP_0_nachbar_vorne[2])*math.sin(math.radians(3)), VP_0_nachbar_vorne[1],- (SP_0_nachbar_vorne[0] - VP_0_nachbar_vorne[0]) * math.sin(math.radians(3)) + (SP_0_nachbar_vorne[2] - VP_0_nachbar_vorne[2])*math.cos(math.radians(3)) - - elif float(gefaellestrecke_vario.get("h1_2")) == upper_hoehe_vario and voerder_richtung != "Horizontal": - if (gefaellestrecke_vario.get("Foerderrichtung_2") == "Auf"): + winkel_VP_offset_hinten = ( + (SP_0_nachbar_vorne[0] - VP_0_nachbar_vorne[0]) + * math.cos(math.radians(3)) + + (SP_0_nachbar_vorne[2] - VP_0_nachbar_vorne[2]) + * math.sin(math.radians(3)), + VP_0_nachbar_vorne[1], + -(SP_0_nachbar_vorne[0] - VP_0_nachbar_vorne[0]) + * math.sin(math.radians(3)) + + (SP_0_nachbar_vorne[2] - VP_0_nachbar_vorne[2]) + * math.cos(math.radians(3)), + ) + + elif ( + float(gefaellestrecke_vario.get("h1_2")) == upper_hoehe_vario + and voerder_richtung != "Horizontal" + ): + if gefaellestrecke_vario.get("Foerderrichtung_2") == "Auf": # Nehmen des winkels und diesen plus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte - winkel_hinten_plusbogen = int(gefaellestrecke_vario.get("Winkel_2")) +3 - winkel_hinten = int(gefaellestrecke_vario.get("Winkel_2")) + winkel_hinten_plusbogen = ( + int(gefaellestrecke_vario.get("Winkel_2")) + 3 + ) + winkel_hinten = int(gefaellestrecke_vario.get("Winkel_2")) - blockname = (f"Vario_Bogen_ab_{winkel_hinten_plusbogen}°") - att_hinten =block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"])) - VP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"])) + blockname = f"Vario_Bogen_ab_{winkel_hinten_plusbogen}°" + att_hinten = block_methoden.import_block( + blockname, lib_doc, doc + ) + SP_0_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"]) + ) + VP_0_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"]) + ) # Ausrechnung des Offsets - winkel_VP_offset_vorne = (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) * math.cos(math.radians(-winkel_hinten)) + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2])*math.sin(math.radians(-winkel_hinten)), VP_0_nachbar_hinten[1],- (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) * math.sin(math.radians(-winkel_hinten)) + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2])*math.cos(math.radians(-winkel_hinten)) + winkel_VP_offset_vorne = ( + (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) + * math.cos(math.radians(-winkel_hinten)) + + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2]) + * math.sin(math.radians(-winkel_hinten)), + VP_0_nachbar_hinten[1], + -(SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) + * math.sin(math.radians(-winkel_hinten)) + + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2]) + * math.cos(math.radians(-winkel_hinten)), + ) elif gefaellestrecke_vario.get("Foerderrichtung") == "Ab": - # Nehmen des winkels und diesen minus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte - winkel_hinten_minusbogen = int(gefaellestrecke_vario.get("Winkel_2")) -3 - winkel_hinten = int(gefaellestrecke_vario.get("Winkel_2")) + # Nehmen des winkels und diesen minus 3 nehmen, um den Bogen zu imporieren für heraufinden der Delta werte + winkel_hinten_minusbogen = ( + int(gefaellestrecke_vario.get("Winkel_2")) - 3 + ) + winkel_hinten = int(gefaellestrecke_vario.get("Winkel_2")) - blockname = (f"Vario_Bogen_auf_{winkel_hinten_minusbogen}°") - att_hinten =block_methoden.import_block(blockname,lib_doc,doc) - SP_1_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"])) - VP_1_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"])) - # Ausrechnung des Offsets - winkel_VP_offset_vorne = (SP_1_nachbar_hinten[0] - VP_1_nachbar_hinten[0]) * math.cos(math.radians(winkel_hinten)) + (SP_1_nachbar_hinten[2] - VP_1_nachbar_hinten[2])*math.sin(math.radians(winkel_hinten)), VP_1_nachbar_hinten[1],- (SP_1_nachbar_hinten[0] - VP_1_nachbar_hinten[0]) * math.sin(math.radians(winkel_hinten)) + (SP_1_nachbar_hinten[2] - VP_1_nachbar_hinten[2])*math.cos(math.radians(winkel_hinten)) + blockname = f"Vario_Bogen_auf_{winkel_hinten_minusbogen}°" + att_hinten = block_methoden.import_block( + blockname, lib_doc, doc + ) + SP_1_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"]) + ) + VP_1_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"]) + ) + # Ausrechnung des Offsets + winkel_VP_offset_vorne = ( + (SP_1_nachbar_hinten[0] - VP_1_nachbar_hinten[0]) + * math.cos(math.radians(winkel_hinten)) + + (SP_1_nachbar_hinten[2] - VP_1_nachbar_hinten[2]) + * math.sin(math.radians(winkel_hinten)), + VP_1_nachbar_hinten[1], + -(SP_1_nachbar_hinten[0] - VP_1_nachbar_hinten[0]) + * math.sin(math.radians(winkel_hinten)) + + (SP_1_nachbar_hinten[2] - VP_1_nachbar_hinten[2]) + * math.cos(math.radians(winkel_hinten)), + ) elif voerder_richtung == "Horizontal": - winkel_vorne_plusbogen = int(gefaellestrecke_vario.get("Winkel_2")) +3 - winkel_hinten = int(gefaellestrecke_vario.get("Winkel_2")) - blockname = (f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°") - att_vorne =block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_SP_1"])) - VP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_VP_1"])) - SP_1_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"])) - VP_1_nachbar_vorne = list(float(att)for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"])) - x_foerderer =gefaellestrecke_vario.get("X_foerderer_2") - y_foerderer =gefaellestrecke_vario.get("Y_foerderer_2") + winkel_vorne_plusbogen = ( + int(gefaellestrecke_vario.get("Winkel_2")) + 3 + ) + winkel_hinten = int(gefaellestrecke_vario.get("Winkel_2")) + blockname = f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°" + att_vorne = block_methoden.import_block(blockname, lib_doc, doc) + SP_0_nachbar_hinten = list( + float(att) for att in re.split(r"[;,]", att_vorne["DELTA_SP_1"]) + ) + VP_0_nachbar_hinten = list( + float(att) for att in re.split(r"[;,]", att_vorne["DELTA_VP_1"]) + ) + SP_1_nachbar_vorne = list( + float(att) for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"]) + ) + VP_1_nachbar_vorne = list( + float(att) for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"]) + ) + x_foerderer = gefaellestrecke_vario.get("X_foerderer_2") + y_foerderer = gefaellestrecke_vario.get("Y_foerderer_2") x = foerderer.x y = foerderer.y rotation_zwischen = rotation if rotation_zwischen == 0.0: rotation_zwischen = -360.0 - if (((-360.0<= rotation_zwischen< -270.0)and y > y_foerderer) or ((-90.0< rotation< 0.0)and y > y_foerderer) or - ((-270.0< rotation_zwischen< -90.0)and y < y_foerderer) or - (rotation == -90.0 and x < x_foerderer) or ((rotation == -270.0)and x y_foerderer) + or ((-90.0 < rotation < 0.0) and y > y_foerderer) + or ((-270.0 < rotation_zwischen < -90.0) and y < y_foerderer) + or (rotation == -90.0 and x < x_foerderer) + or ((rotation == -270.0) and x < x_foerderer) + ): + blockname = f"Vario_Bogen_auf_{winkel_vorne_plusbogen}°" + att_vorne = block_methoden.import_block(blockname, lib_doc, doc) + SP_1_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_SP_0"]) + ) + VP_1_nachbar_vorne = list( + float(att) + for att in re.split(r"[;,]", att_vorne["DELTA_VP_0"]) + ) + winkel_VP_offset_vorne = ( + (SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) + * math.cos(math.radians(3)) + + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2]) + * math.sin(math.radians(3)), + VP_1_nachbar_vorne[1], + -(SP_1_nachbar_vorne[0] - VP_1_nachbar_vorne[0]) + * math.sin(math.radians(3)) + + (SP_1_nachbar_vorne[2] - VP_1_nachbar_vorne[2]) + * math.cos(math.radians(3)), + ) else: - blockname = (f"Vario_Bogen_ab_{winkel_vorne_plusbogen}°") - att_hinten =block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"])) - VP_0_nachbar_hinten = list(float(att)for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"])) - winkel_VP_offset_hinten = (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) * math.cos(math.radians(-winkel_hinten)) + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2])*math.sin(math.radians(-winkel_hinten)), VP_0_nachbar_hinten[1],- (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) * math.sin(math.radians(-winkel_hinten)) + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2])*math.cos(math.radians(-winkel_hinten)) + blockname = f"Vario_Bogen_ab_{winkel_vorne_plusbogen}°" + att_hinten = block_methoden.import_block( + blockname, lib_doc, doc + ) + SP_0_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_SP_1"]) + ) + VP_0_nachbar_hinten = list( + float(att) + for att in re.split(r"[;,]", att_hinten["DELTA_VP_1"]) + ) + winkel_VP_offset_hinten = ( + (SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) + * math.cos(math.radians(-winkel_hinten)) + + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2]) + * math.sin(math.radians(-winkel_hinten)), + VP_0_nachbar_hinten[1], + -(SP_0_nachbar_hinten[0] - VP_0_nachbar_hinten[0]) + * math.sin(math.radians(-winkel_hinten)) + + (SP_0_nachbar_hinten[2] - VP_0_nachbar_hinten[2]) + * math.cos(math.radians(-winkel_hinten)), + ) else: - blockname = (f"Vario_Kurve_{gefaellestrecke_vario.get("Kurvenrichtung_1")}_{gefaellestrecke_vario.get("Kurvenwinkel_1")}°_TEF_{gefaellestrecke_vario.get("Tefkurve_1")}") - att_kurve = block_methoden.import_block(blockname,lib_doc,doc) - SP_0_nachbar = list(float(att)for att in re.split(r"[;,]", att_kurve["DELTA_SP_0"])) - VP_0_nachbar = list(float(att)for att in re.split(r"[;,]", att_kurve["DELTA_VP_0"])) - SP_1_nachbar = list(float(att)for att in re.split(r"[;,]", att_kurve["DELTA_SP_1"])) - VP_1_nachbar= list(float(att)for att in re.split(r"[;,]", att_kurve["DELTA_VP_1"])) - if (SP_1_nachbar[0] < 0 and VP_1_nachbar[0] < 0) or (SP_1_nachbar[0] >= 0 and VP_1_nachbar[0] < 0): + blockname = f"Vario_Kurve_{gefaellestrecke_vario.get("Kurvenrichtung_1")}_{gefaellestrecke_vario.get("Kurvenwinkel_1")}°_TEF_{gefaellestrecke_vario.get("Tefkurve_1")}" + att_kurve = block_methoden.import_block(blockname, lib_doc, doc) + SP_0_nachbar = list( + float(att) for att in re.split(r"[;,]", att_kurve["DELTA_SP_0"]) + ) + VP_0_nachbar = list( + float(att) for att in re.split(r"[;,]", att_kurve["DELTA_VP_0"]) + ) + SP_1_nachbar = list( + float(att) for att in re.split(r"[;,]", att_kurve["DELTA_SP_1"]) + ) + VP_1_nachbar = list( + float(att) for att in re.split(r"[;,]", att_kurve["DELTA_VP_1"]) + ) + if (SP_1_nachbar[0] < 0 and VP_1_nachbar[0] < 0) or ( + SP_1_nachbar[0] >= 0 and VP_1_nachbar[0] < 0 + ): SP_1_nachbar[0] = SP_1_nachbar[0] * -1 VP_1_nachbar[0] = VP_1_nachbar[0] * -1 - if (SP_0_nachbar[1] < 0 and VP_0_nachbar[1] < 0) or (SP_0_nachbar[1] >= 0 and VP_0_nachbar[1] < 0): + if (SP_0_nachbar[1] < 0 and VP_0_nachbar[1] < 0) or ( + SP_0_nachbar[1] >= 0 and VP_0_nachbar[1] < 0 + ): SP_0_nachbar[1] = SP_0_nachbar[1] * -1 VP_0_nachbar[1] = VP_0_nachbar[1] * -1 if voerder_richtung == "Ab": - if float(gefaellestrecke_vario.get("vario_hoehe_1_1")) == lower_hoehe_vario: - winkel_VP_offset_hinten = (SP_1_nachbar[0] -VP_1_nachbar[0] ),0,( SP_1_nachbar[2]- VP_1_nachbar[2]) - else: - winkel_VP_offset_vorne = (SP_0_nachbar[1] -VP_0_nachbar[1] ),0,( SP_0_nachbar[2]- VP_0_nachbar[2]) + if ( + float(gefaellestrecke_vario.get("vario_hoehe_1_1")) + == lower_hoehe_vario + ): + winkel_VP_offset_hinten = ( + (SP_1_nachbar[0] - VP_1_nachbar[0]), + 0, + (SP_1_nachbar[2] - VP_1_nachbar[2]), + ) + else: + winkel_VP_offset_vorne = ( + (SP_0_nachbar[1] - VP_0_nachbar[1]), + 0, + (SP_0_nachbar[2] - VP_0_nachbar[2]), + ) else: x_angetrieben = gefaellestrecke_vario.get("X_angetrieben_1") y_angetrieben = gefaellestrecke_vario.get("Y_angetrieben_1") @@ -298,15 +633,27 @@ class VarioFoerderer(BaseModel): rotation_zwischen = rotation if rotation_zwischen == 0.0: rotation_zwischen = -360.0 - if (((-360.0<= rotation_zwischen< -270.0)and y > y_angetrieben) or ((-90.0< rotation< 0.0)and y > y_angetrieben) or - ((-270.0< rotation_zwischen< -90.0)and y < y_angetrieben) or - (rotation == -90.0 and x < x_angetrieben) or ((rotation == -270.0)and x y_angetrieben) + or ((-90.0 < rotation < 0.0) and y > y_angetrieben) + or ((-270.0 < rotation_zwischen < -90.0) and y < y_angetrieben) + or (rotation == -90.0 and x < x_angetrieben) + or ((rotation == -270.0) and x < x_angetrieben) + ): + winkel_VP_offset_hinten = ( + (SP_0_nachbar[1] - VP_0_nachbar[1]), + 0, + (SP_0_nachbar[2] - VP_0_nachbar[2]), + ) else: - winkel_VP_offset_vorne = (SP_1_nachbar[0] -VP_1_nachbar[0] ),0,( SP_1_nachbar[2]- VP_1_nachbar[2]) - - return winkel_VP_offset_vorne,winkel_VP_offset_hinten - + winkel_VP_offset_vorne = ( + (SP_1_nachbar[0] - VP_1_nachbar[0]), + 0, + (SP_1_nachbar[2] - VP_1_nachbar[2]), + ) + + return winkel_VP_offset_vorne, winkel_VP_offset_hinten + def horizontale_ausrichtung(foerderer, x0_kreisel, y0_kreisel): """Schaut was für eine Ausrichtung der Horizontale Förder hat""" voerder_richtung = foerderer.foerderer_richtung @@ -317,28 +664,38 @@ class VarioFoerderer(BaseModel): mit_horizontal_verbunden = "None" if voerder_richtung == "Horizontal": if rotation == 0.0: - if y> y0_kreisel: + if y > y0_kreisel: mit_horizontal_verbunden = "unten_drehung_0_or_-90" else: mit_horizontal_verbunden = "oben_drehung_0_or_-90" if rotation == -180.0: - if y> y0_kreisel: + if y > y0_kreisel: mit_horizontal_verbunden = "unten_drehung_-180_or_-270" else: mit_horizontal_verbunden = "oben_drehung_-180_or_-270" if rotation == -90.0: - if x> x0_kreisel: + if x > x0_kreisel: mit_horizontal_verbunden = "unten_drehung_0_or_-90" else: mit_horizontal_verbunden = "oben_drehung_0_or_-90" if rotation == -270.0: - if x> x0_kreisel: + if x > x0_kreisel: mit_horizontal_verbunden = "unten_drehung_-180_or_-270" else: mit_horizontal_verbunden = "oben_drehung_-180_or_-270" return mit_horizontal_verbunden - def vario_verbuden_am_kreisel(foerderer, block_vario, start, ende, mit_horizontal_verbunden = None,kreisel_verbunden = None,am_kreisel = None,erster_kreisel_höher = None): - """""Methode für Erstellung der Gefällestrecke für Vario Förderrer die direkt am dem Kreisel hängt""" + + def vario_verbuden_am_kreisel( + foerderer, + block_vario, + start, + ende, + mit_horizontal_verbunden=None, + kreisel_verbunden=None, + am_kreisel=None, + erster_kreisel_höher=None, + ): + """ ""Methode für Erstellung der Gefällestrecke für Vario Förderrer die direkt am dem Kreisel hängt""" lower_hoehe_vario = foerderer.h0 upper_hoehe_vario = foerderer.h1 voerder_richtung = foerderer.foerderer_richtung @@ -346,84 +703,146 @@ class VarioFoerderer(BaseModel): x = foerderer.x y = foerderer.y gefaelle_länge = 500 - if (kreisel_verbunden == 2 or (am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel == 2 and erster_kreisel_höher == False))and voerder_richtung != "Horizontal": - l = (start[0],start[1],upper_hoehe_vario) - # Eine 500 mm gefällestrecke an anfang und am ende reintuen - if voerder_richtung =="Auf": - m = (start[0],start[1] - gefaelle_länge*math.cos(math.radians(3)),upper_hoehe_vario +gefaelle_länge* math.sin(math.radians(3))) + if ( + kreisel_verbunden == 2 + or (am_kreisel == 1 and erster_kreisel_höher == True) + or (am_kreisel == 2 and erster_kreisel_höher == False) + ) and voerder_richtung != "Horizontal": + l = (start[0], start[1], upper_hoehe_vario) + # Eine 500 mm gefällestrecke an anfang und am ende reintuen + if voerder_richtung == "Auf": + m = ( + start[0], + start[1] - gefaelle_länge * math.cos(math.radians(3)), + upper_hoehe_vario + gefaelle_länge * math.sin(math.radians(3)), + ) start = m elif voerder_richtung == "Ab": - m = (start[0],start[1] - gefaelle_länge*math.cos(math.radians(3)),upper_hoehe_vario -gefaelle_länge* math.sin(math.radians(3))) + m = ( + start[0], + start[1] - gefaelle_länge * math.cos(math.radians(3)), + upper_hoehe_vario - gefaelle_länge * math.sin(math.radians(3)), + ) start = m else: - m = (start[0],start[1] - gefaelle_länge*math.cos(math.radians(3)),upper_hoehe_vario ) + m = ( + start[0], + start[1] - gefaelle_länge * math.cos(math.radians(3)), + upper_hoehe_vario, + ) start = m if kreisel_verbunden == 1: z1 = m[2] - y1 = start[1] + y1 = start[1] - line = Line.new(dxfattribs={"start": l,"end":m }) + line = Line.new(dxfattribs={"start": l, "end": m}) line.dxf.layer = "6-SP" - copy= line.copy() - copy.translate(-x,-y,-hoehe_vario) + copy = line.copy() + copy.translate(-x, -y, -hoehe_vario) block_vario.add_entity(copy) - if (kreisel_verbunden == 2 or (am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel == 2 and erster_kreisel_höher == True)) and voerder_richtung != "Horizontal": - l = (ende[0],ende[1],lower_hoehe_vario) - if voerder_richtung =="Auf": - m = (ende[0],ende[1] + gefaelle_länge*math.cos(math.radians(3)) ,lower_hoehe_vario - gefaelle_länge* math.sin(math.radians(3))) + if ( + kreisel_verbunden == 2 + or (am_kreisel == 1 and erster_kreisel_höher == False) + or (am_kreisel == 2 and erster_kreisel_höher == True) + ) and voerder_richtung != "Horizontal": + l = (ende[0], ende[1], lower_hoehe_vario) + if voerder_richtung == "Auf": + m = ( + ende[0], + ende[1] + gefaelle_länge * math.cos(math.radians(3)), + lower_hoehe_vario - gefaelle_länge * math.sin(math.radians(3)), + ) ende = m elif voerder_richtung == "Ab": - m = (ende[0],ende[1] + gefaelle_länge*math.cos(math.radians(3)) ,lower_hoehe_vario + gefaelle_länge* math.sin(math.radians(3))) + m = ( + ende[0], + ende[1] + gefaelle_länge * math.cos(math.radians(3)), + lower_hoehe_vario + gefaelle_länge * math.sin(math.radians(3)), + ) ende = m else: - m = (ende[0],ende[1] + gefaelle_länge*math.cos(math.radians(3)) ,lower_hoehe_vario ) + m = ( + ende[0], + ende[1] + gefaelle_länge * math.cos(math.radians(3)), + lower_hoehe_vario, + ) ende = m - line = Line.new(dxfattribs={"start": l,"end":m }) + line = Line.new(dxfattribs={"start": l, "end": m}) line.dxf.layer = "6-SP" - copy= line.copy() - copy.translate(-x,-y,-hoehe_vario) + copy = line.copy() + copy.translate(-x, -y, -hoehe_vario) block_vario.add_entity(copy) if kreisel_verbunden == 1: z1 = m[2] - y1 = ende[1] + y1 = ende[1] elif voerder_richtung == "Horizontal": - if mit_horizontal_verbunden == "oben_drehung_0_or_-90" or mit_horizontal_verbunden == "unten_drehung_-180_or_-270": - l = (start[0],start[1],upper_hoehe_vario) - m = (start[0],start[1] - gefaelle_länge*math.cos(math.radians(3)),upper_hoehe_vario) + if ( + mit_horizontal_verbunden == "oben_drehung_0_or_-90" + or mit_horizontal_verbunden == "unten_drehung_-180_or_-270" + ): + l = (start[0], start[1], upper_hoehe_vario) + m = ( + start[0], + start[1] - gefaelle_länge * math.cos(math.radians(3)), + upper_hoehe_vario, + ) start = m - line = Line.new(dxfattribs={"start": l,"end":m }) + line = Line.new(dxfattribs={"start": l, "end": m}) line.dxf.layer = "6-SP" - copy= line.copy() - copy.translate(-x,-y,-hoehe_vario) + copy = line.copy() + copy.translate(-x, -y, -hoehe_vario) block_vario.add_entity(copy) else: - end = (ende[0],ende[1],lower_hoehe_vario) - en = (ende[0],ende[1] + gefaelle_länge*math.cos(math.radians(3)) ,lower_hoehe_vario ) + end = (ende[0], ende[1], lower_hoehe_vario) + en = ( + ende[0], + ende[1] + gefaelle_länge * math.cos(math.radians(3)), + lower_hoehe_vario, + ) ende = en - line = Line.new(dxfattribs={"start": end,"end":en }) + line = Line.new(dxfattribs={"start": end, "end": en}) line.dxf.layer = "6-SP" - copy= line.copy() - copy.translate(-x,-y,-hoehe_vario) - block_vario.add_entity(copy) + copy = line.copy() + copy.translate(-x, -y, -hoehe_vario) + block_vario.add_entity(copy) if kreisel_verbunden == 1 and mit_horizontal_verbunden == None: - return y1,z1 + return y1, z1 else: return start, ende - def vario_erstellung(foerderer, doc, lib_doc, config, block, block_name_links, start, ende, voerder_richtung, winkel_VP_offset_vorne, winkel_VP_offset_hinten ): + + def vario_erstellung( + foerderer, + doc, + lib_doc, + config, + block, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ): """Erstellung der Vario Blöcke""" # Entnehmen der Motor und Umlenk station um die Gefähle auzurechnen und ob man diese tatsächlich einfügen muss - winkel_motor = float(config.get("Ils 2.0 core winkel","winkel_motor")) - winkel_umlenk = float(config.get("Ils 2.0 core winkel","winkel_umlenk")) - umlenk_laenge = tuple(float(x) for x in(config.get("ILS 2.0 Variofoerderer","Umlenkstation")).split(",")) - motor_laenge = tuple(float(x) for x in(config.get("ILS 2.0 Variofoerderer","Motorstation")).split(",")) - - vario_abstand = float(config.get("ILS 2.0 Variofoerderer","vario_abstand")) + winkel_motor = float(config.get("Ils 2.0 core winkel", "winkel_motor")) + winkel_umlenk = float(config.get("Ils 2.0 core winkel", "winkel_umlenk")) + umlenk_laenge = tuple( + float(x) + for x in (config.get("ILS 2.0 Variofoerderer", "Umlenkstation")).split(",") + ) + motor_laenge = tuple( + float(x) + for x in (config.get("ILS 2.0 Variofoerderer", "Motorstation")).split(",") + ) + + vario_abstand = float(config.get("ILS 2.0 Variofoerderer", "vario_abstand")) motor_vorhanden = foerderer.hat_motor umlenk_vorhanden = foerderer.hat_umlenk - gefahellewinkel =foerderer.gefaelle_winkel + gefahellewinkel = foerderer.gefaelle_winkel gefaelle = foerderer.gefaelle_laenge x = foerderer.x y = foerderer.y @@ -431,340 +850,783 @@ class VarioFoerderer(BaseModel): winkel = int(foerderer.winkel) # Aktueller offset des motors und Umlenkungstation, wird wahrscheinlich später einfach berechnet (sobald man entschieden hat ob wir nur 3 grad neigung erlauben oder nicht) - motor_offset_x = umlenk_laenge[0]* math.cos(math.radians(winkel_motor)) - motor_offset_z = umlenk_laenge[0]* math.sin(math.radians(winkel_motor)) - umlenk_offset_x = motor_laenge[0]* math.cos(math.radians(winkel_umlenk)) - umlenk_offset_z = motor_laenge[0]* math.sin(math.radians(winkel_umlenk)) + motor_offset_x = umlenk_laenge[0] * math.cos(math.radians(winkel_motor)) + motor_offset_z = umlenk_laenge[0] * math.sin(math.radians(winkel_motor)) + umlenk_offset_x = motor_laenge[0] * math.cos(math.radians(winkel_umlenk)) + umlenk_offset_z = motor_laenge[0] * math.sin(math.radians(winkel_umlenk)) # Berechnung des Gefälles - if motor_vorhanden == True: + if motor_vorhanden == True: gefaelle = gefaelle - motor_offset_x if umlenk_vorhanden == True: gefaelle = gefaelle - umlenk_offset_x - #Erstellung des Förderes falls er auf ist oder Horizontal da diese gleich aufgebaut werden - if voerder_richtung== "Auf" or voerder_richtung== "Horizontal": + # Erstellung des Förderes falls er auf ist oder Horizontal da diese gleich aufgebaut werden + if voerder_richtung == "Auf" or voerder_richtung == "Horizontal": # erstellung des gefälles falls es nicht null ist (also keins angegeben ist oder es durch andere Sachen wie Motor ersetzt wird) if gefaelle > 0: # Setzng die hälfte des Gefälles auf beide seiten falls dieser nicht mit einem anderen Förder verbunden ist was durch die abwesenheit eines motors/umlenkung gezeigt wird - halbesgefaelle = gefaelle/2 + halbesgefaelle = gefaelle / 2 if motor_vorhanden == True and umlenk_vorhanden == True: - halbesgefaelle = gefaelle/2 - gefaelle_ende = ende[0], ende[1] +halbesgefaelle, ende[2] -math.sin(math.radians(gefahellewinkel))* halbesgefaelle - line_ende_gefaelle = Line.new(dxfattribs={"start": ende,"end": gefaelle_ende}) + halbesgefaelle = gefaelle / 2 + gefaelle_ende = ( + ende[0], + ende[1] + halbesgefaelle, + ende[2] + - math.sin(math.radians(gefahellewinkel)) * halbesgefaelle, + ) + line_ende_gefaelle = Line.new( + dxfattribs={"start": ende, "end": gefaelle_ende} + ) line_ende_gefaelle.dxf.layer = "6-SP" copy_ende = line_ende_gefaelle.copy() - copy_ende.translate(-x,-y,-hoehe_vario) + copy_ende.translate(-x, -y, -hoehe_vario) block.add_entity(copy_ende) ende = gefaelle_ende - - gefaelle_start = start[0], start[1] -halbesgefaelle, start[2] +math.sin(math.radians(gefahellewinkel)) * halbesgefaelle - line_start_gefaelle = Line.new(dxfattribs={"start": start,"end": gefaelle_start}) + + gefaelle_start = ( + start[0], + start[1] - halbesgefaelle, + start[2] + + math.sin(math.radians(gefahellewinkel)) * halbesgefaelle, + ) + line_start_gefaelle = Line.new( + dxfattribs={"start": start, "end": gefaelle_start} + ) line_start_gefaelle.dxf.layer = "6-SP" copy_start = line_start_gefaelle.copy() - copy_start.translate(-x,-y,-hoehe_vario) + copy_start.translate(-x, -y, -hoehe_vario) block.add_entity(copy_start) start = gefaelle_start - elif motor_vorhanden== True: - gefaelle_start = start[0], start[1] -gefaelle, start[2] +math.sin(math.radians(gefahellewinkel)) * gefaelle - line_start_gefaelle = Line.new(dxfattribs={"start": start,"end": gefaelle_start}) + elif motor_vorhanden == True: + gefaelle_start = ( + start[0], + start[1] - gefaelle, + start[2] + math.sin(math.radians(gefahellewinkel)) * gefaelle, + ) + line_start_gefaelle = Line.new( + dxfattribs={"start": start, "end": gefaelle_start} + ) line_start_gefaelle.dxf.layer = "6-SP" copy_start = line_start_gefaelle.copy() - copy_start.translate(-x,-y,-hoehe_vario) + copy_start.translate(-x, -y, -hoehe_vario) block.add_entity(copy_start) start = gefaelle_start - elif umlenk_vorhanden== True: - gefaelle_ende = ende[0], ende[1] +gefaelle, ende[2] -math.sin(math.radians(gefahellewinkel))* gefaelle - line_ende_gefaelle = Line.new(dxfattribs={"start": ende,"end": gefaelle_ende}) + elif umlenk_vorhanden == True: + gefaelle_ende = ( + ende[0], + ende[1] + gefaelle, + ende[2] - math.sin(math.radians(gefahellewinkel)) * gefaelle, + ) + line_ende_gefaelle = Line.new( + dxfattribs={"start": ende, "end": gefaelle_ende} + ) line_ende_gefaelle.dxf.layer = "6-SP" copy_ende = line_ende_gefaelle.copy() - copy_ende.translate(-x,-y,-hoehe_vario) + copy_ende.translate(-x, -y, -hoehe_vario) block.add_entity(copy_ende) ende = gefaelle_ende - + # Den Motorstaton und Umlenkstation auf die richtige position in block einfügen falls nötig - block_Vario_Umlenkstation_500mm ="Vario_Umlenkstation_500mm" + block_Vario_Umlenkstation_500mm = "Vario_Umlenkstation_500mm" block_Vario_Motorstation_500mm = "Vario_Motorstation_500mm" block_methoden.import_block(block_Vario_Motorstation_500mm, lib_doc, doc) - block_methoden.import_block(block_Vario_Umlenkstation_500mm , lib_doc, doc) - layer_motor, color_motor = block_methoden.get_insert_color_layer(lib_doc,block_Vario_Motorstation_500mm) - layer_umlenk, color_umlenk = block_methoden.get_insert_color_layer(lib_doc,block_Vario_Umlenkstation_500mm) - block_Vario_Motorstation_500mm = block_methoden.dreh_block(block_Vario_Motorstation_500mm,doc,lib_doc,math.radians(winkel_motor)) - block_Vario_Umlenkstation_500mm = block_methoden.dreh_block( block_Vario_Umlenkstation_500mm, doc,lib_doc,math.radians(winkel_umlenk)) + block_methoden.import_block(block_Vario_Umlenkstation_500mm, lib_doc, doc) + layer_motor, color_motor = block_methoden.get_insert_color_layer( + lib_doc, block_Vario_Motorstation_500mm + ) + layer_umlenk, color_umlenk = block_methoden.get_insert_color_layer( + lib_doc, block_Vario_Umlenkstation_500mm + ) + block_Vario_Motorstation_500mm = block_methoden.dreh_block( + block_Vario_Motorstation_500mm, doc, lib_doc, math.radians(winkel_motor) + ) + block_Vario_Umlenkstation_500mm = block_methoden.dreh_block( + block_Vario_Umlenkstation_500mm, + doc, + lib_doc, + math.radians(winkel_umlenk), + ) if umlenk_vorhanden == True: - block.add_blockref(block_Vario_Umlenkstation_500mm,(ende[0] -x,ende[1] -y + umlenk_offset_x/2,ende[2] - hoehe_vario -umlenk_offset_z/2 ),dxfattribs={"rotation": 90, "layer":layer_umlenk,"color": color_umlenk}) - ende = (ende[0] ,ende[1] + umlenk_offset_x,ende[2] - umlenk_offset_z) + block.add_blockref( + block_Vario_Umlenkstation_500mm, + ( + ende[0] - x, + ende[1] - y + umlenk_offset_x / 2, + ende[2] - hoehe_vario - umlenk_offset_z / 2, + ), + dxfattribs={ + "rotation": 90, + "layer": layer_umlenk, + "color": color_umlenk, + }, + ) + ende = (ende[0], ende[1] + umlenk_offset_x, ende[2] - umlenk_offset_z) if motor_vorhanden == True: - block.add_blockref(block_Vario_Motorstation_500mm, (start[0]-x , start[1] - motor_offset_x/2 -y ,start[2] - hoehe_vario +motor_offset_z/2),dxfattribs={"rotation": 90, "layer":layer_motor,"color": color_motor}) - start = start[0] , start[1] - motor_offset_x,start[2] + motor_offset_z - + block.add_blockref( + block_Vario_Motorstation_500mm, + ( + start[0] - x, + start[1] - motor_offset_x / 2 - y, + start[2] - hoehe_vario + motor_offset_z / 2, + ), + dxfattribs={ + "rotation": 90, + "layer": layer_motor, + "color": color_motor, + }, + ) + start = start[0], start[1] - motor_offset_x, start[2] + motor_offset_z + # Einfügen der grad Bogen und deren notwendigen Werten von den attributen des bogens in den block - winkel_core = int(config.get("Ils 2.0 core winkel","winkel_boegen")) + winkel_core = int(config.get("Ils 2.0 core winkel", "winkel_boegen")) winkel_plus = winkel + winkel_core - block_Vario_Bogen_auf = (f"Vario_Bogen_auf_{winkel_plus}°") - block_Vario_Bogen_ab = (f"Vario_Bogen_ab_{winkel_plus}°") - - auf_attrib =block_methoden.import_block(block_Vario_Bogen_auf, lib_doc, doc) - ab_attrib =block_methoden.import_block(block_Vario_Bogen_ab, lib_doc, doc) - layer_auf,color_auf = block_methoden.get_insert_color_layer(lib_doc,block_Vario_Bogen_auf) - layer_ab,color_ab =block_methoden.get_insert_color_layer(lib_doc,block_Vario_Bogen_ab) - block_Vario_Bogen_auf = block_methoden.dreh_block(block_Vario_Bogen_auf, doc,lib_doc,math.radians(winkel_core)) - block_Vario_Bogen_ab = block_methoden.dreh_block(block_Vario_Bogen_ab, doc,lib_doc,math.radians(-winkel)) - - #Entnehmen der Werte von den Attributen - Vario_Bogen_auf_Delta_SP_0 = list(float(att)for att in re.split(r"[;,]", auf_attrib["DELTA_SP_0"])) - Vario_Bogen_auf_Delta_SP_1 = list(float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_SP_1"])) - Vario_Bogen_ab_Delta_SP_0 = list(float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_SP_0"])) - Vario_Bogen_ab_Delta_SP_1 = list(float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_SP_1"])) - Vario_Bogen_auf_Delta_VP_1 = list(float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_VP_1"])) - Vario_Bogen_ab_Delta_VP_0= list(float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_VP_0"])) + block_Vario_Bogen_auf = f"Vario_Bogen_auf_{winkel_plus}°" + block_Vario_Bogen_ab = f"Vario_Bogen_ab_{winkel_plus}°" + + auf_attrib = block_methoden.import_block( + block_Vario_Bogen_auf, lib_doc, doc + ) + ab_attrib = block_methoden.import_block(block_Vario_Bogen_ab, lib_doc, doc) + layer_auf, color_auf = block_methoden.get_insert_color_layer( + lib_doc, block_Vario_Bogen_auf + ) + layer_ab, color_ab = block_methoden.get_insert_color_layer( + lib_doc, block_Vario_Bogen_ab + ) + block_Vario_Bogen_auf = block_methoden.dreh_block( + block_Vario_Bogen_auf, doc, lib_doc, math.radians(winkel_core) + ) + block_Vario_Bogen_ab = block_methoden.dreh_block( + block_Vario_Bogen_ab, doc, lib_doc, math.radians(-winkel) + ) + + # Entnehmen der Werte von den Attributen + Vario_Bogen_auf_Delta_SP_0 = list( + float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_SP_0"]) + ) + Vario_Bogen_auf_Delta_SP_1 = list( + float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_SP_1"]) + ) + Vario_Bogen_ab_Delta_SP_0 = list( + float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_SP_0"]) + ) + Vario_Bogen_ab_Delta_SP_1 = list( + float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_SP_1"]) + ) + Vario_Bogen_auf_Delta_VP_1 = list( + float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_VP_1"]) + ) + Vario_Bogen_ab_Delta_VP_0 = list( + float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_VP_0"]) + ) # Werte von den Attributen durch den Winkel ändern wegen der Neugung in 3 Dimensionalen raum - Vario_Bogen_auf_Delta_SP_0 = [Vario_Bogen_auf_Delta_SP_0 [0] * math.cos(math.radians(winkel_core))+ Vario_Bogen_auf_Delta_SP_0[2]* math.sin(math.radians(winkel_core)) ,Vario_Bogen_auf_Delta_SP_0[1],-Vario_Bogen_auf_Delta_SP_0[0] * math.sin(math.radians(winkel_core))+ Vario_Bogen_auf_Delta_SP_0[2] * math.cos(math.radians(winkel_core)) ] - Vario_Bogen_auf_Delta_SP_1 = [Vario_Bogen_auf_Delta_SP_1 [0] * math.cos(math.radians(winkel_core))+ Vario_Bogen_auf_Delta_SP_1[2]* math.sin(math.radians(winkel_core)) ,Vario_Bogen_auf_Delta_SP_1[1],-Vario_Bogen_auf_Delta_SP_1[0] * math.sin(math.radians(winkel_core))+ Vario_Bogen_auf_Delta_SP_1[2] * math.cos(math.radians(winkel_core)) ] - Vario_Bogen_ab_Delta_SP_0 = [Vario_Bogen_ab_Delta_SP_0 [0] * math.cos(math.radians(-winkel))+ Vario_Bogen_ab_Delta_SP_0[2]* math.sin(math.radians(-winkel)) ,Vario_Bogen_ab_Delta_SP_0[1],-Vario_Bogen_ab_Delta_SP_0[0] * math.sin(math.radians(-winkel))+ Vario_Bogen_ab_Delta_SP_0[2] * math.cos(math.radians(-winkel)) ] - Vario_Bogen_ab_Delta_SP_1 =[ Vario_Bogen_ab_Delta_SP_1 [0] * math.cos(math.radians(-winkel))+ Vario_Bogen_ab_Delta_SP_1[2]* math.sin(math.radians(-winkel)) ,Vario_Bogen_ab_Delta_SP_1[1],-Vario_Bogen_ab_Delta_SP_1[0] * math.sin(math.radians(-winkel))+ Vario_Bogen_ab_Delta_SP_1[2] * math.cos(math.radians(-winkel)) ] - Vario_Bogen_auf_Delta_VP_1 = [Vario_Bogen_auf_Delta_VP_1 [0] * math.cos(math.radians(winkel_core))+ Vario_Bogen_auf_Delta_VP_1[2]* math.sin(math.radians(winkel_core)) ,Vario_Bogen_auf_Delta_VP_1[1],-Vario_Bogen_auf_Delta_VP_1[0] * math.sin(math.radians(winkel_core))+ Vario_Bogen_auf_Delta_VP_1[2] * math.cos(math.radians(winkel_core)) ] - Vario_Bogen_ab_Delta_VP_0 = [Vario_Bogen_ab_Delta_VP_0 [0] * math.cos(math.radians(-winkel))+ Vario_Bogen_ab_Delta_VP_0[2]* math.sin(math.radians(-winkel)) ,Vario_Bogen_ab_Delta_VP_0[1],-Vario_Bogen_ab_Delta_VP_0[0] * math.sin(math.radians(-winkel))+ Vario_Bogen_ab_Delta_VP_0[2] * math.cos(math.radians(-winkel)) ] - - # negative Zahlen für x und y positive setzen, damit man weniger nachdenken muss (theoretisch ist SP0 x immer negative und SP1 immer positive aber dies vereinfacht die konsistenz der Werte wann ich was addieren oder subtrahieren muss) - for i, wert in enumerate(Vario_Bogen_auf_Delta_SP_0): - if i< 2 and wert < 0: - Vario_Bogen_auf_Delta_SP_0[i] = abs(wert) + Vario_Bogen_auf_Delta_SP_0 = [ + Vario_Bogen_auf_Delta_SP_0[0] * math.cos(math.radians(winkel_core)) + + Vario_Bogen_auf_Delta_SP_0[2] * math.sin(math.radians(winkel_core)), + Vario_Bogen_auf_Delta_SP_0[1], + -Vario_Bogen_auf_Delta_SP_0[0] * math.sin(math.radians(winkel_core)) + + Vario_Bogen_auf_Delta_SP_0[2] * math.cos(math.radians(winkel_core)), + ] + Vario_Bogen_auf_Delta_SP_1 = [ + Vario_Bogen_auf_Delta_SP_1[0] * math.cos(math.radians(winkel_core)) + + Vario_Bogen_auf_Delta_SP_1[2] * math.sin(math.radians(winkel_core)), + Vario_Bogen_auf_Delta_SP_1[1], + -Vario_Bogen_auf_Delta_SP_1[0] * math.sin(math.radians(winkel_core)) + + Vario_Bogen_auf_Delta_SP_1[2] * math.cos(math.radians(winkel_core)), + ] + Vario_Bogen_ab_Delta_SP_0 = [ + Vario_Bogen_ab_Delta_SP_0[0] * math.cos(math.radians(-winkel)) + + Vario_Bogen_ab_Delta_SP_0[2] * math.sin(math.radians(-winkel)), + Vario_Bogen_ab_Delta_SP_0[1], + -Vario_Bogen_ab_Delta_SP_0[0] * math.sin(math.radians(-winkel)) + + Vario_Bogen_ab_Delta_SP_0[2] * math.cos(math.radians(-winkel)), + ] + Vario_Bogen_ab_Delta_SP_1 = [ + Vario_Bogen_ab_Delta_SP_1[0] * math.cos(math.radians(-winkel)) + + Vario_Bogen_ab_Delta_SP_1[2] * math.sin(math.radians(-winkel)), + Vario_Bogen_ab_Delta_SP_1[1], + -Vario_Bogen_ab_Delta_SP_1[0] * math.sin(math.radians(-winkel)) + + Vario_Bogen_ab_Delta_SP_1[2] * math.cos(math.radians(-winkel)), + ] + Vario_Bogen_auf_Delta_VP_1 = [ + Vario_Bogen_auf_Delta_VP_1[0] * math.cos(math.radians(winkel_core)) + + Vario_Bogen_auf_Delta_VP_1[2] * math.sin(math.radians(winkel_core)), + Vario_Bogen_auf_Delta_VP_1[1], + -Vario_Bogen_auf_Delta_VP_1[0] * math.sin(math.radians(winkel_core)) + + Vario_Bogen_auf_Delta_VP_1[2] * math.cos(math.radians(winkel_core)), + ] + Vario_Bogen_ab_Delta_VP_0 = [ + Vario_Bogen_ab_Delta_VP_0[0] * math.cos(math.radians(-winkel)) + + Vario_Bogen_ab_Delta_VP_0[2] * math.sin(math.radians(-winkel)), + Vario_Bogen_ab_Delta_VP_0[1], + -Vario_Bogen_ab_Delta_VP_0[0] * math.sin(math.radians(-winkel)) + + Vario_Bogen_ab_Delta_VP_0[2] * math.cos(math.radians(-winkel)), + ] + + # negative Zahlen für x und y positive setzen, damit man weniger nachdenken muss (theoretisch ist SP0 x immer negative und SP1 immer positive aber dies vereinfacht die konsistenz der Werte wann ich was addieren oder subtrahieren muss) + for i, wert in enumerate(Vario_Bogen_auf_Delta_SP_0): + if i < 2 and wert < 0: + Vario_Bogen_auf_Delta_SP_0[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_auf_Delta_SP_1): - if i< 2 and wert< 0: - Vario_Bogen_auf_Delta_SP_1[i] = abs(wert) + if i < 2 and wert < 0: + Vario_Bogen_auf_Delta_SP_1[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_ab_Delta_SP_0): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_ab_Delta_SP_0[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_ab_Delta_SP_1): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_ab_Delta_SP_1[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_auf_Delta_VP_1): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_auf_Delta_VP_1[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_ab_Delta_VP_0): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_ab_Delta_VP_0[i] = abs(wert) - #einfügen des auf blockes und veränderund der ende Punktes dementsprechend und erstellung von endeVP für die VARIO linie + # einfügen des auf blockes und veränderund der ende Punktes dementsprechend und erstellung von endeVP für die VARIO linie if voerder_richtung == "Auf": - block.add_blockref(block_Vario_Bogen_auf,(ende[0] -x ,ende[1] +Vario_Bogen_auf_Delta_SP_0[0] -y ,ende[2] - Vario_Bogen_auf_Delta_SP_0[2]- hoehe_vario ),dxfattribs={"rotation": 90,"layer": layer_auf,"color": color_auf}) - ende_VP = (ende[0] +Vario_Bogen_auf_Delta_VP_1[1], ende[1]+Vario_Bogen_auf_Delta_VP_1[0]+Vario_Bogen_auf_Delta_SP_0[0],ende[2] + Vario_Bogen_auf_Delta_VP_1[2]- Vario_Bogen_auf_Delta_SP_0[2]) - ende = (ende[0] ,ende[1] +Vario_Bogen_auf_Delta_SP_1[0] + Vario_Bogen_auf_Delta_SP_0[0] ,ende[2] + Vario_Bogen_auf_Delta_SP_1[2] - Vario_Bogen_auf_Delta_SP_0[2]) - #einfügen des auf blockes und veränderund der start Punktes dementsprechend und erstellung von startVP für die VARIO linie - block.add_blockref(block_Vario_Bogen_ab ,(start[0]-x,start[1] - Vario_Bogen_ab_Delta_SP_1[0] -y ,start[2] - hoehe_vario-Vario_Bogen_ab_Delta_SP_1[2]),dxfattribs={"rotation": 90,"layer": layer_ab,"color": color_ab}) + block.add_blockref( + block_Vario_Bogen_auf, + ( + ende[0] - x, + ende[1] + Vario_Bogen_auf_Delta_SP_0[0] - y, + ende[2] - Vario_Bogen_auf_Delta_SP_0[2] - hoehe_vario, + ), + dxfattribs={"rotation": 90, "layer": layer_auf, "color": color_auf}, + ) + ende_VP = ( + ende[0] + Vario_Bogen_auf_Delta_VP_1[1], + ende[1] + + Vario_Bogen_auf_Delta_VP_1[0] + + Vario_Bogen_auf_Delta_SP_0[0], + ende[2] + + Vario_Bogen_auf_Delta_VP_1[2] + - Vario_Bogen_auf_Delta_SP_0[2], + ) + ende = ( + ende[0], + ende[1] + + Vario_Bogen_auf_Delta_SP_1[0] + + Vario_Bogen_auf_Delta_SP_0[0], + ende[2] + + Vario_Bogen_auf_Delta_SP_1[2] + - Vario_Bogen_auf_Delta_SP_0[2], + ) + # einfügen des auf blockes und veränderund der start Punktes dementsprechend und erstellung von startVP für die VARIO linie + block.add_blockref( + block_Vario_Bogen_ab, + ( + start[0] - x, + start[1] - Vario_Bogen_ab_Delta_SP_1[0] - y, + start[2] - hoehe_vario - Vario_Bogen_ab_Delta_SP_1[2], + ), + dxfattribs={"rotation": 90, "layer": layer_ab, "color": color_ab}, + ) + + start_VP = ( + start[0] + Vario_Bogen_ab_Delta_VP_0[1], + start[1] + - Vario_Bogen_ab_Delta_VP_0[0] + - Vario_Bogen_ab_Delta_SP_1[0], + start[2] + + Vario_Bogen_ab_Delta_VP_0[2] + - Vario_Bogen_ab_Delta_SP_1[2], + ) + start = ( + start[0], + start[1] + - Vario_Bogen_ab_Delta_SP_0[0] + - Vario_Bogen_ab_Delta_SP_1[0], + start[2] + - Vario_Bogen_ab_Delta_SP_1[2] + + Vario_Bogen_ab_Delta_SP_0[2], + ) - start_VP = start[0] +Vario_Bogen_ab_Delta_VP_0[1],start[1]-Vario_Bogen_ab_Delta_VP_0[0] - Vario_Bogen_ab_Delta_SP_1[0] ,start[2]+Vario_Bogen_ab_Delta_VP_0[2] - Vario_Bogen_ab_Delta_SP_1[2] - start = start[0] ,start[1] - Vario_Bogen_ab_Delta_SP_0[0] - Vario_Bogen_ab_Delta_SP_1[0],start[2] - Vario_Bogen_ab_Delta_SP_1[2]+ Vario_Bogen_ab_Delta_SP_0[2] - # Erstellung der VARIO Line - line_VP = Line.new(dxfattribs={"start":start_VP,"end": ende_VP}) + line_VP = Line.new(dxfattribs={"start": start_VP, "end": ende_VP}) line_VP.dxf.layer = "VARIO" copy_VP = line_VP.copy() - copy_VP.translate(-x,-y,-hoehe_vario) + copy_VP.translate(-x, -y, -hoehe_vario) block.add_entity(copy_VP) # Erstellung der zwischen Line line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" - copy= line.copy() + copy = line.copy() - copy.translate(-x,-y,-hoehe_vario) + copy.translate(-x, -y, -hoehe_vario) block.add_entity(copy) - + else: if umlenk_vorhanden == True: - block.add_blockref(block_Vario_Bogen_ab ,(start[0]-x,start[1] - Vario_Bogen_ab_Delta_SP_1[0] -y ,start[2] - hoehe_vario-Vario_Bogen_ab_Delta_SP_1[2]),dxfattribs={"rotation": 90,"layer": layer_ab,"color": color_ab}) - start_VP = start[0] +Vario_Bogen_ab_Delta_VP_0[1],start[1]-Vario_Bogen_ab_Delta_VP_0[0] - Vario_Bogen_ab_Delta_SP_1[0] ,start[2]+Vario_Bogen_ab_Delta_VP_0[2] - Vario_Bogen_ab_Delta_SP_1[2] - start = start[0] ,start[1] - Vario_Bogen_ab_Delta_SP_0[0] - Vario_Bogen_ab_Delta_SP_1[0],start[2] - Vario_Bogen_ab_Delta_SP_1[2]+ Vario_Bogen_ab_Delta_SP_0[2] - - else: - start_VP = start[0] +vario_abstand,start[1] + winkel_VP_offset_hinten[0], start[2] - winkel_VP_offset_hinten[2] + block.add_blockref( + block_Vario_Bogen_ab, + ( + start[0] - x, + start[1] - Vario_Bogen_ab_Delta_SP_1[0] - y, + start[2] - hoehe_vario - Vario_Bogen_ab_Delta_SP_1[2], + ), + dxfattribs={ + "rotation": 90, + "layer": layer_ab, + "color": color_ab, + }, + ) + start_VP = ( + start[0] + Vario_Bogen_ab_Delta_VP_0[1], + start[1] + - Vario_Bogen_ab_Delta_VP_0[0] + - Vario_Bogen_ab_Delta_SP_1[0], + start[2] + + Vario_Bogen_ab_Delta_VP_0[2] + - Vario_Bogen_ab_Delta_SP_1[2], + ) + start = ( + start[0], + start[1] + - Vario_Bogen_ab_Delta_SP_0[0] + - Vario_Bogen_ab_Delta_SP_1[0], + start[2] + - Vario_Bogen_ab_Delta_SP_1[2] + + Vario_Bogen_ab_Delta_SP_0[2], + ) - #einfügen des auf blockes und veränderund der start Punktes dementsprechend und erstellung von startVP für die VARIO linie - if motor_vorhanden == True: - block.add_blockref(block_Vario_Bogen_auf,(ende[0] -x ,ende[1] +Vario_Bogen_auf_Delta_SP_0[0] -y ,ende[2] - Vario_Bogen_auf_Delta_SP_0[2]- hoehe_vario ),dxfattribs={"rotation": 90,"layer": layer_auf,"color": color_auf}) - ende_VP = (ende[0] +Vario_Bogen_auf_Delta_VP_1[1], ende[1]+Vario_Bogen_auf_Delta_VP_1[0]+Vario_Bogen_auf_Delta_SP_0[0],ende[2] + Vario_Bogen_auf_Delta_VP_1[2]- Vario_Bogen_auf_Delta_SP_0[2]) - ende = (ende[0] ,ende[1] +Vario_Bogen_auf_Delta_SP_1[0] + Vario_Bogen_auf_Delta_SP_0[0] ,ende[2] + Vario_Bogen_auf_Delta_SP_1[2] - Vario_Bogen_auf_Delta_SP_0[2]) else: - ende_VP = ende[0] +vario_abstand,ende[1] - winkel_VP_offset_vorne[0], ende[2] - winkel_VP_offset_vorne[2] + start_VP = ( + start[0] + vario_abstand, + start[1] + winkel_VP_offset_hinten[0], + start[2] - winkel_VP_offset_hinten[2], + ) + + # einfügen des auf blockes und veränderund der start Punktes dementsprechend und erstellung von startVP für die VARIO linie + if motor_vorhanden == True: + block.add_blockref( + block_Vario_Bogen_auf, + ( + ende[0] - x, + ende[1] + Vario_Bogen_auf_Delta_SP_0[0] - y, + ende[2] - Vario_Bogen_auf_Delta_SP_0[2] - hoehe_vario, + ), + dxfattribs={ + "rotation": 90, + "layer": layer_auf, + "color": color_auf, + }, + ) + ende_VP = ( + ende[0] + Vario_Bogen_auf_Delta_VP_1[1], + ende[1] + + Vario_Bogen_auf_Delta_VP_1[0] + + Vario_Bogen_auf_Delta_SP_0[0], + ende[2] + + Vario_Bogen_auf_Delta_VP_1[2] + - Vario_Bogen_auf_Delta_SP_0[2], + ) + ende = ( + ende[0], + ende[1] + + Vario_Bogen_auf_Delta_SP_1[0] + + Vario_Bogen_auf_Delta_SP_0[0], + ende[2] + + Vario_Bogen_auf_Delta_SP_1[2] + - Vario_Bogen_auf_Delta_SP_0[2], + ) + else: + ende_VP = ( + ende[0] + vario_abstand, + ende[1] - winkel_VP_offset_vorne[0], + ende[2] - winkel_VP_offset_vorne[2], + ) # Erstellung der VARIO Line - line_VP = Line.new(dxfattribs={"start":start_VP,"end": ende_VP}) + line_VP = Line.new(dxfattribs={"start": start_VP, "end": ende_VP}) line_VP.dxf.layer = "VARIO" copy_VP = line_VP.copy() - copy_VP.translate(-x,-y,-hoehe_vario) + copy_VP.translate(-x, -y, -hoehe_vario) block.add_entity(copy_VP) - + # Erstellung der zwischen Line line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" - copy= line.copy() + copy = line.copy() - copy.translate(-x,-y,-hoehe_vario) + copy.translate(-x, -y, -hoehe_vario) block.add_entity(copy) elif voerder_richtung == "Ab": # Setzng die hälfte des Gefälles auf beide seiten falls dieser nicht mit einem anderen Förder verbunden ist was durch die abwesenheit eines motors/umlenkung gezeigt wird if gefaelle > 0: if motor_vorhanden == True and umlenk_vorhanden == True: - halbesgefaelle = gefaelle/2 - gefaelle_ende = ende[0], ende[1] +halbesgefaelle, ende[2] + math.sin(math.radians(gefahellewinkel))* halbesgefaelle - line_ende_gefaelle = Line.new(dxfattribs={"start": ende,"end": gefaelle_ende}) + halbesgefaelle = gefaelle / 2 + gefaelle_ende = ( + ende[0], + ende[1] + halbesgefaelle, + ende[2] + + math.sin(math.radians(gefahellewinkel)) * halbesgefaelle, + ) + line_ende_gefaelle = Line.new( + dxfattribs={"start": ende, "end": gefaelle_ende} + ) line_ende_gefaelle.dxf.layer = "6-SP" copy_ende = line_ende_gefaelle.copy() - copy_ende.translate(-x,-y,-hoehe_vario) + copy_ende.translate(-x, -y, -hoehe_vario) block.add_entity(copy_ende) ende = gefaelle_ende - - gefaelle_start = start[0], start[1] -halbesgefaelle, start[2] - math.sin(math.radians(gefahellewinkel)) * halbesgefaelle - line_start_gefaelle = Line.new(dxfattribs={"start": start,"end": gefaelle_start}) + + gefaelle_start = ( + start[0], + start[1] - halbesgefaelle, + start[2] + - math.sin(math.radians(gefahellewinkel)) * halbesgefaelle, + ) + line_start_gefaelle = Line.new( + dxfattribs={"start": start, "end": gefaelle_start} + ) line_start_gefaelle.dxf.layer = "6-SP" copy_start = line_start_gefaelle.copy() - copy_start.translate(-x,-y,-hoehe_vario) + copy_start.translate(-x, -y, -hoehe_vario) block.add_entity(copy_start) start = gefaelle_start elif motor_vorhanden == True: - gefaelle_ende = ende[0], ende[1] +gefaelle, ende[2] + math.sin(math.radians(gefahellewinkel))* gefaelle - line_ende_gefaelle = Line.new(dxfattribs={"start": ende,"end": gefaelle_ende}) + gefaelle_ende = ( + ende[0], + ende[1] + gefaelle, + ende[2] + math.sin(math.radians(gefahellewinkel)) * gefaelle, + ) + line_ende_gefaelle = Line.new( + dxfattribs={"start": ende, "end": gefaelle_ende} + ) line_ende_gefaelle.dxf.layer = "6-SP" copy_ende = line_ende_gefaelle.copy() - copy_ende.translate(-x,-y,-hoehe_vario) + copy_ende.translate(-x, -y, -hoehe_vario) block.add_entity(copy_ende) ende = gefaelle_ende elif umlenk_vorhanden == True: - gefaelle_start = start[0], start[1] -gefaelle, start[2] - math.sin(math.radians(gefahellewinkel)) * gefaelle - line_start_gefaelle = Line.new(dxfattribs={"start": start,"end": gefaelle_start}) + gefaelle_start = ( + start[0], + start[1] - gefaelle, + start[2] - math.sin(math.radians(gefahellewinkel)) * gefaelle, + ) + line_start_gefaelle = Line.new( + dxfattribs={"start": start, "end": gefaelle_start} + ) line_start_gefaelle.dxf.layer = "6-SP" copy_start = line_start_gefaelle.copy() - copy_start.translate(-x,-y,-hoehe_vario) + copy_start.translate(-x, -y, -hoehe_vario) block.add_entity(copy_start) start = gefaelle_start # Importieren und setzen der UMlenkungstation oder Motorstation falls nötig - block_Vario_Umlenkstation_500mm ="Vario_Umlenkstation_500mm" + block_Vario_Umlenkstation_500mm = "Vario_Umlenkstation_500mm" block_Vario_Motorstation_500mm = "Vario_Motorstation_500mm" - block_methoden.import_block( block_Vario_Motorstation_500mm, lib_doc, doc) - block_methoden.import_block( block_Vario_Umlenkstation_500mm , lib_doc, doc) - layer_motor, color_motor = block_methoden.get_insert_color_layer(lib_doc,block_Vario_Motorstation_500mm) - layer_umlenk, color_umlenk = block_methoden.get_insert_color_layer(lib_doc,block_Vario_Umlenkstation_500mm) - block_Vario_Motorstation_500mm = block_methoden.dreh_block( block_Vario_Motorstation_500mm, doc,lib_doc,math.radians(winkel_motor)) - block_Vario_Umlenkstation_500mm = block_methoden.dreh_block( block_Vario_Umlenkstation_500mm , doc,lib_doc,math.radians(winkel_umlenk)) + block_methoden.import_block(block_Vario_Motorstation_500mm, lib_doc, doc) + block_methoden.import_block(block_Vario_Umlenkstation_500mm, lib_doc, doc) + layer_motor, color_motor = block_methoden.get_insert_color_layer( + lib_doc, block_Vario_Motorstation_500mm + ) + layer_umlenk, color_umlenk = block_methoden.get_insert_color_layer( + lib_doc, block_Vario_Umlenkstation_500mm + ) + block_Vario_Motorstation_500mm = block_methoden.dreh_block( + block_Vario_Motorstation_500mm, doc, lib_doc, math.radians(winkel_motor) + ) + block_Vario_Umlenkstation_500mm = block_methoden.dreh_block( + block_Vario_Umlenkstation_500mm, + doc, + lib_doc, + math.radians(winkel_umlenk), + ) if umlenk_vorhanden == True: - block.add_blockref(block_Vario_Umlenkstation_500mm,(start[0] -x,start[1] -y - umlenk_offset_x/2, start[2] - hoehe_vario -umlenk_offset_z/2 ),dxfattribs={"rotation": 270,"layer": layer_umlenk,"color": color_umlenk}) - start_Umlenkstation_VP = start[0] - vario_abstand, start[1] -500 *math.cos(math.radians(-winkel_umlenk))+ math.sin(math.radians(-winkel_umlenk))* -45,start[2] + math.sin(math.radians(-winkel_umlenk))*500+ math.cos(math.radians(-winkel_umlenk))*-45 - start = (start[0] ,start[1] - umlenk_offset_x,start[2] -umlenk_offset_z) + block.add_blockref( + block_Vario_Umlenkstation_500mm, + ( + start[0] - x, + start[1] - y - umlenk_offset_x / 2, + start[2] - hoehe_vario - umlenk_offset_z / 2, + ), + dxfattribs={ + "rotation": 270, + "layer": layer_umlenk, + "color": color_umlenk, + }, + ) + start_Umlenkstation_VP = ( + start[0] - vario_abstand, + start[1] + - 500 * math.cos(math.radians(-winkel_umlenk)) + + math.sin(math.radians(-winkel_umlenk)) * -45, + start[2] + + math.sin(math.radians(-winkel_umlenk)) * 500 + + math.cos(math.radians(-winkel_umlenk)) * -45, + ) + start = ( + start[0], + start[1] - umlenk_offset_x, + start[2] - umlenk_offset_z, + ) elif winkel == 3: - start_Umlenkstation_VP = start[0] - vario_abstand, start[1]+ winkel_VP_offset_vorne[0],start[2] -winkel_VP_offset_vorne[2] + start_Umlenkstation_VP = ( + start[0] - vario_abstand, + start[1] + winkel_VP_offset_vorne[0], + start[2] - winkel_VP_offset_vorne[2], + ) if motor_vorhanden == True: - block.add_blockref(block_Vario_Motorstation_500mm, (ende[0]-x , ende[1] + motor_offset_x/2 -y ,ende[2] - hoehe_vario + motor_offset_z/2),dxfattribs={"rotation": 270,"layer": layer_motor,"color": color_motor}) - ende_Motor_VP = ende[0] - vario_abstand, ende[1] +500 *math.cos(math.radians(-winkel_motor))+ math.sin(math.radians(-winkel_motor))* -45,ende[2] - math.sin(math.radians(-winkel_motor))*500+ math.cos(math.radians(-winkel_motor))*-45 + block.add_blockref( + block_Vario_Motorstation_500mm, + ( + ende[0] - x, + ende[1] + motor_offset_x / 2 - y, + ende[2] - hoehe_vario + motor_offset_z / 2, + ), + dxfattribs={ + "rotation": 270, + "layer": layer_motor, + "color": color_motor, + }, + ) + ende_Motor_VP = ( + ende[0] - vario_abstand, + ende[1] + + 500 * math.cos(math.radians(-winkel_motor)) + + math.sin(math.radians(-winkel_motor)) * -45, + ende[2] + - math.sin(math.radians(-winkel_motor)) * 500 + + math.cos(math.radians(-winkel_motor)) * -45, + ) - ende = ende[0] , ende[1] + motor_offset_x,ende[2] +motor_offset_z + ende = ende[0], ende[1] + motor_offset_x, ende[2] + motor_offset_z elif winkel == 3: - ende_Motor_VP = ende[0] - vario_abstand, ende[1]- winkel_VP_offset_vorne[0] ,ende[2] - winkel_VP_offset_hinten[2] - + ende_Motor_VP = ( + ende[0] - vario_abstand, + ende[1] - winkel_VP_offset_vorne[0], + ende[2] - winkel_VP_offset_hinten[2], + ) + if winkel != 3: - winkel_core = int(config.get("Ils 2.0 core winkel","winkel_boegen")) + winkel_core = int(config.get("Ils 2.0 core winkel", "winkel_boegen")) winkel_minus = winkel - winkel_core - block_Vario_Bogen_auf = (f"Vario_Bogen_auf_{winkel_minus}°") - block_Vario_Bogen_ab = (f"Vario_Bogen_ab_{winkel_minus}°") - ab_attrib =block_methoden.import_block( block_Vario_Bogen_ab , lib_doc, doc) - auf_attrib =block_methoden.import_block( block_Vario_Bogen_auf, lib_doc, doc) - layer_auf,color_auf = block_methoden.get_insert_color_layer(lib_doc,block_Vario_Bogen_auf) - layer_ab,color_ab =block_methoden.get_insert_color_layer(lib_doc,block_Vario_Bogen_ab) - block_Vario_Bogen_ab = block_methoden.dreh_block( block_Vario_Bogen_ab, doc,lib_doc, math.radians(winkel_core)) - block_Vario_Bogen_auf= block_methoden.dreh_block( block_Vario_Bogen_auf, doc,lib_doc, math.radians(winkel)) - Vario_Bogen_auf_Delta_SP_0 = list(float(att)for att in re.split(r"[;,]", auf_attrib["DELTA_SP_0"])) - Vario_Bogen_auf_Delta_SP_1 = list(float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_SP_1"])) - Vario_Bogen_ab_Delta_SP_0 = list(float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_SP_0"])) - Vario_Bogen_ab_Delta_SP_1 = list(float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_SP_1"])) - Vario_Bogen_auf_Delta_VP_0 = list(float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_VP_0"])) - Vario_Bogen_ab_Delta_VP_1= list(float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_VP_1"])) - - Vario_Bogen_auf_Delta_SP_0 = [Vario_Bogen_auf_Delta_SP_0 [0] * math.cos(math.radians(winkel))+ Vario_Bogen_auf_Delta_SP_0[2]* math.sin(math.radians(winkel)) ,Vario_Bogen_auf_Delta_SP_0[1],-Vario_Bogen_auf_Delta_SP_0[0] * math.sin(math.radians(winkel))+ Vario_Bogen_auf_Delta_SP_0[2] * math.cos(math.radians(winkel)) ] - Vario_Bogen_auf_Delta_SP_1 = [Vario_Bogen_auf_Delta_SP_1 [0] * math.cos(math.radians(winkel))+ Vario_Bogen_auf_Delta_SP_1[2]* math.sin(math.radians(winkel)) ,Vario_Bogen_auf_Delta_SP_1[1],-Vario_Bogen_auf_Delta_SP_1[0] * math.sin(math.radians(winkel))+ Vario_Bogen_auf_Delta_SP_1[2] * math.cos(math.radians(winkel)) ] - Vario_Bogen_ab_Delta_SP_0 = [Vario_Bogen_ab_Delta_SP_0 [0] * math.cos(math.radians(winkel_core))+ Vario_Bogen_ab_Delta_SP_0[2]* math.sin(math.radians(winkel_core)) ,Vario_Bogen_ab_Delta_SP_0[1],-Vario_Bogen_ab_Delta_SP_0[0] * math.sin(math.radians(3))+ Vario_Bogen_ab_Delta_SP_0[2] * math.cos(math.radians(winkel_core)) ] - Vario_Bogen_ab_Delta_SP_1 =[ Vario_Bogen_ab_Delta_SP_1 [0] * math.cos(math.radians(winkel_core))+ Vario_Bogen_ab_Delta_SP_1[2]* math.sin(math.radians(winkel_core)) ,Vario_Bogen_ab_Delta_SP_1[1],-Vario_Bogen_ab_Delta_SP_1[0] * math.sin(math.radians(3))+ Vario_Bogen_ab_Delta_SP_1[2] * math.cos(math.radians(winkel_core)) ] - Vario_Bogen_auf_Delta_VP_0 = [Vario_Bogen_auf_Delta_VP_0 [0] * math.cos(math.radians(winkel))+ Vario_Bogen_auf_Delta_VP_0[2]* math.sin(math.radians(winkel)) ,Vario_Bogen_auf_Delta_VP_0[1],-Vario_Bogen_auf_Delta_VP_0[0] * math.sin(math.radians(winkel))+ Vario_Bogen_auf_Delta_VP_0[2] * math.cos(math.radians(winkel)) ] - Vario_Bogen_ab_Delta_VP_1 = [Vario_Bogen_ab_Delta_VP_1 [0] * math.cos(math.radians(winkel_core))+ Vario_Bogen_ab_Delta_VP_1[2]* math.sin(math.radians(winkel_core)) ,Vario_Bogen_ab_Delta_VP_1[1],-Vario_Bogen_ab_Delta_VP_1[0] * math.sin(math.radians(3))+ Vario_Bogen_ab_Delta_VP_1[2] * math.cos(math.radians(winkel_core)) ] - + block_Vario_Bogen_auf = f"Vario_Bogen_auf_{winkel_minus}°" + block_Vario_Bogen_ab = f"Vario_Bogen_ab_{winkel_minus}°" + ab_attrib = block_methoden.import_block( + block_Vario_Bogen_ab, lib_doc, doc + ) + auf_attrib = block_methoden.import_block( + block_Vario_Bogen_auf, lib_doc, doc + ) + layer_auf, color_auf = block_methoden.get_insert_color_layer( + lib_doc, block_Vario_Bogen_auf + ) + layer_ab, color_ab = block_methoden.get_insert_color_layer( + lib_doc, block_Vario_Bogen_ab + ) + block_Vario_Bogen_ab = block_methoden.dreh_block( + block_Vario_Bogen_ab, doc, lib_doc, math.radians(winkel_core) + ) + block_Vario_Bogen_auf = block_methoden.dreh_block( + block_Vario_Bogen_auf, doc, lib_doc, math.radians(winkel) + ) + Vario_Bogen_auf_Delta_SP_0 = list( + float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_SP_0"]) + ) + Vario_Bogen_auf_Delta_SP_1 = list( + float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_SP_1"]) + ) + Vario_Bogen_ab_Delta_SP_0 = list( + float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_SP_0"]) + ) + Vario_Bogen_ab_Delta_SP_1 = list( + float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_SP_1"]) + ) + Vario_Bogen_auf_Delta_VP_0 = list( + float(att) for att in re.split(r"[;,]", auf_attrib["DELTA_VP_0"]) + ) + Vario_Bogen_ab_Delta_VP_1 = list( + float(att) for att in re.split(r"[;,]", ab_attrib["DELTA_VP_1"]) + ) + + Vario_Bogen_auf_Delta_SP_0 = [ + Vario_Bogen_auf_Delta_SP_0[0] * math.cos(math.radians(winkel)) + + Vario_Bogen_auf_Delta_SP_0[2] * math.sin(math.radians(winkel)), + Vario_Bogen_auf_Delta_SP_0[1], + -Vario_Bogen_auf_Delta_SP_0[0] * math.sin(math.radians(winkel)) + + Vario_Bogen_auf_Delta_SP_0[2] * math.cos(math.radians(winkel)), + ] + Vario_Bogen_auf_Delta_SP_1 = [ + Vario_Bogen_auf_Delta_SP_1[0] * math.cos(math.radians(winkel)) + + Vario_Bogen_auf_Delta_SP_1[2] * math.sin(math.radians(winkel)), + Vario_Bogen_auf_Delta_SP_1[1], + -Vario_Bogen_auf_Delta_SP_1[0] * math.sin(math.radians(winkel)) + + Vario_Bogen_auf_Delta_SP_1[2] * math.cos(math.radians(winkel)), + ] + Vario_Bogen_ab_Delta_SP_0 = [ + Vario_Bogen_ab_Delta_SP_0[0] * math.cos(math.radians(winkel_core)) + + Vario_Bogen_ab_Delta_SP_0[2] + * math.sin(math.radians(winkel_core)), + Vario_Bogen_ab_Delta_SP_0[1], + -Vario_Bogen_ab_Delta_SP_0[0] * math.sin(math.radians(3)) + + Vario_Bogen_ab_Delta_SP_0[2] + * math.cos(math.radians(winkel_core)), + ] + Vario_Bogen_ab_Delta_SP_1 = [ + Vario_Bogen_ab_Delta_SP_1[0] * math.cos(math.radians(winkel_core)) + + Vario_Bogen_ab_Delta_SP_1[2] + * math.sin(math.radians(winkel_core)), + Vario_Bogen_ab_Delta_SP_1[1], + -Vario_Bogen_ab_Delta_SP_1[0] * math.sin(math.radians(3)) + + Vario_Bogen_ab_Delta_SP_1[2] + * math.cos(math.radians(winkel_core)), + ] + Vario_Bogen_auf_Delta_VP_0 = [ + Vario_Bogen_auf_Delta_VP_0[0] * math.cos(math.radians(winkel)) + + Vario_Bogen_auf_Delta_VP_0[2] * math.sin(math.radians(winkel)), + Vario_Bogen_auf_Delta_VP_0[1], + -Vario_Bogen_auf_Delta_VP_0[0] * math.sin(math.radians(winkel)) + + Vario_Bogen_auf_Delta_VP_0[2] * math.cos(math.radians(winkel)), + ] + Vario_Bogen_ab_Delta_VP_1 = [ + Vario_Bogen_ab_Delta_VP_1[0] * math.cos(math.radians(winkel_core)) + + Vario_Bogen_ab_Delta_VP_1[2] + * math.sin(math.radians(winkel_core)), + Vario_Bogen_ab_Delta_VP_1[1], + -Vario_Bogen_ab_Delta_VP_1[0] * math.sin(math.radians(3)) + + Vario_Bogen_ab_Delta_VP_1[2] + * math.cos(math.radians(winkel_core)), + ] + # negative Zahlen für x und y positive setzen, damit man weniger nachdenken muss (theoretisch ist SP0 x immer negative und SP1 immer positive aber dies vereinfacht die konsistenz der Werte wann ich was addieren oder subtrahieren muss) - for i, wert in enumerate(Vario_Bogen_auf_Delta_SP_0): - if i< 2 and wert < 0: - Vario_Bogen_auf_Delta_SP_0[i] = abs(wert) + for i, wert in enumerate(Vario_Bogen_auf_Delta_SP_0): + if i < 2 and wert < 0: + Vario_Bogen_auf_Delta_SP_0[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_auf_Delta_SP_1): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_auf_Delta_SP_1[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_ab_Delta_SP_0): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_ab_Delta_SP_0[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_ab_Delta_SP_1): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_ab_Delta_SP_1[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_auf_Delta_VP_0): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_auf_Delta_VP_0[i] = abs(wert) for i, wert in enumerate(Vario_Bogen_ab_Delta_VP_1): - if i< 2 and wert< 0: + if i < 2 and wert < 0: Vario_Bogen_ab_Delta_VP_1[i] = abs(wert) - #einfügen des auf blockes und veränderund der start Punktes dementsprechend und erstellung von startVP für die VARIO linie - block.add_blockref(block_Vario_Bogen_ab, (start[0]-x,start[1]-y- Vario_Bogen_ab_Delta_SP_0[0], start[2]- hoehe_vario- Vario_Bogen_ab_Delta_SP_0[2]),dxfattribs={"rotation": 270,"layer": layer_ab,"color": color_ab}) - start_VP = start[0] -Vario_Bogen_ab_Delta_VP_1[1],start[1]- Vario_Bogen_ab_Delta_VP_1[0]- Vario_Bogen_ab_Delta_SP_0[0] ,start[2]+Vario_Bogen_ab_Delta_VP_1[2]-Vario_Bogen_ab_Delta_SP_0[2] + # einfügen des auf blockes und veränderund der start Punktes dementsprechend und erstellung von startVP für die VARIO linie + block.add_blockref( + block_Vario_Bogen_ab, + ( + start[0] - x, + start[1] - y - Vario_Bogen_ab_Delta_SP_0[0], + start[2] - hoehe_vario - Vario_Bogen_ab_Delta_SP_0[2], + ), + dxfattribs={"rotation": 270, "layer": layer_ab, "color": color_ab}, + ) + start_VP = ( + start[0] - Vario_Bogen_ab_Delta_VP_1[1], + start[1] + - Vario_Bogen_ab_Delta_VP_1[0] + - Vario_Bogen_ab_Delta_SP_0[0], + start[2] + + Vario_Bogen_ab_Delta_VP_1[2] + - Vario_Bogen_ab_Delta_SP_0[2], + ) + + start = ( + start[0], + start[1] + - Vario_Bogen_ab_Delta_SP_0[0] + - Vario_Bogen_ab_Delta_SP_1[0], + start[2] + - Vario_Bogen_ab_Delta_SP_0[2] + + Vario_Bogen_ab_Delta_SP_1[2], + ) + + # einfügen des auf blockes und veränderund der ende Punktes dementsprechend und erstellung von endeVP für die VARIO linie + block.add_blockref( + block_Vario_Bogen_auf, + ( + ende[0] - x, + ende[1] - y + Vario_Bogen_auf_Delta_SP_1[0], + ende[2] - hoehe_vario - Vario_Bogen_auf_Delta_SP_1[2], + ), + dxfattribs={ + "rotation": 270, + "layer": layer_auf, + "color": color_auf, + }, + ) + ende_VP = ( + ende[0] - Vario_Bogen_auf_Delta_VP_0[1], + ende[1] + + Vario_Bogen_auf_Delta_VP_0[0] + + Vario_Bogen_auf_Delta_SP_1[0], + ende[2] + + Vario_Bogen_auf_Delta_VP_0[2] + - Vario_Bogen_auf_Delta_SP_1[2], + ) + ende = ( + ende[0], + ende[1] + + Vario_Bogen_auf_Delta_SP_1[0] + + Vario_Bogen_auf_Delta_SP_0[0], + ende[2] + - Vario_Bogen_auf_Delta_SP_1[2] + + Vario_Bogen_auf_Delta_SP_0[2], + ) - start =(start[0], start[1]- Vario_Bogen_ab_Delta_SP_0[0]- Vario_Bogen_ab_Delta_SP_1[0],start[2]-Vario_Bogen_ab_Delta_SP_0[2]+Vario_Bogen_ab_Delta_SP_1[2]) - - #einfügen des auf blockes und veränderund der ende Punktes dementsprechend und erstellung von endeVP für die VARIO linie - block.add_blockref(block_Vario_Bogen_auf, (ende[0]-x,ende[1]-y+ Vario_Bogen_auf_Delta_SP_1[0],ende[2]-hoehe_vario -Vario_Bogen_auf_Delta_SP_1[2]),dxfattribs={"rotation": 270,"layer": layer_auf,"color": color_auf}) - ende_VP = (ende[0] -Vario_Bogen_auf_Delta_VP_0[1], ende[1] + Vario_Bogen_auf_Delta_VP_0[0]+ Vario_Bogen_auf_Delta_SP_1[0],ende[2]+ Vario_Bogen_auf_Delta_VP_0[2]- Vario_Bogen_auf_Delta_SP_1[2]) - ende = (ende[0],ende[1]+ Vario_Bogen_auf_Delta_SP_1[0]+ Vario_Bogen_auf_Delta_SP_0[0],ende[2]- Vario_Bogen_auf_Delta_SP_1[2]+ Vario_Bogen_auf_Delta_SP_0[2]) - # Erstellung der VARIO Line - line_VP = Line.new(dxfattribs={"start":start_VP,"end": ende_VP}) + line_VP = Line.new(dxfattribs={"start": start_VP, "end": ende_VP}) line_VP.dxf.layer = "VARIO" copy_VP = line_VP.copy() - copy_VP.translate(-x,-y,-hoehe_vario) + copy_VP.translate(-x, -y, -hoehe_vario) block.add_entity(copy_VP) # Erstellung der zwischen Line - line = Line.new(dxfattribs={"start":start,"end":ende }) + line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" copy = line.copy() - copy.translate(-x,-y,-hoehe_vario) + copy.translate(-x, -y, -hoehe_vario) block.add_entity(copy) - #Sonderlogik für grad 3, weil es kein bogen braucht + # Sonderlogik für grad 3, weil es kein bogen braucht elif winkel == 3: # Nur erstellung der zwischen und Vario linie weil der Bogen hier nicht nötig ist - line_VP = Line.new(dxfattribs={"start": start_Umlenkstation_VP,"end": ende_Motor_VP}) + line_VP = Line.new( + dxfattribs={"start": start_Umlenkstation_VP, "end": ende_Motor_VP} + ) line_VP.dxf.layer = "VARIO" copy_VP = line_VP.copy() - copy_VP.translate(-x,-y,-hoehe_vario) + copy_VP.translate(-x, -y, -hoehe_vario) block.add_entity(copy_VP) line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" - copy= line.copy() + copy = line.copy() - copy.translate(-x,-y,-hoehe_vario) + copy.translate(-x, -y, -hoehe_vario) block.add_entity(copy) - # Erstellung einer Spiegelung an der y achse (hier wird es ausgeführt durch -x) für die erstellung des Förderers mit den vario stationen links - matrix = Matrix44.scale(-1,1,1) - block_links = doc.blocks.new(block_name_links, base_point=(0,0,0)) - #spiegelung aller elemente außer es und as elemente falls diese vorhanden sind um die logik wie die platziert werden nicht zu zerstören + # Erstellung einer Spiegelung an der y achse (hier wird es ausgeführt durch -x) für die erstellung des Förderers mit den vario stationen links + matrix = Matrix44.scale(-1, 1, 1) + block_links = doc.blocks.new(block_name_links, base_point=(0, 0, 0)) + # spiegelung aller elemente außer es und as elemente falls diese vorhanden sind um die logik wie die platziert werden nicht zu zerstören for entity in block: - clone= entity.copy() + clone = entity.copy() if entity.dxftype() == "INSERT": - if (entity.dxf.name.startswith("400102632_ES-Element_90_links") or entity.dxf.name.startswith("200000146_ES-Element_90_rechts") or - entity.dxf.name.startswith("200000241_AS-Element_90_rechts") or entity.dxf.name.startswith("200000217_AS-Element_90_links") - ): + if ( + entity.dxf.name.startswith("400102632_ES-Element_90_links") + or entity.dxf.name.startswith("200000146_ES-Element_90_rechts") + or entity.dxf.name.startswith("200000241_AS-Element_90_rechts") + or entity.dxf.name.startswith("200000217_AS-Element_90_links") + ): block_links.add_entity(clone) else: clone.transform(matrix) @@ -772,4 +1634,3 @@ class VarioFoerderer(BaseModel): else: clone.transform(matrix) block_links.add_entity(clone) - \ No newline at end of file diff --git a/lib/arbeiten_mit_csv.py b/lib/arbeiten_mit_csv.py index 2e46956..3765bb0 100644 --- a/lib/arbeiten_mit_csv.py +++ b/lib/arbeiten_mit_csv.py @@ -6,7 +6,7 @@ import re import configparser from pathlib import Path from utils import check_environment_var, setup_logger -from Elemente import Kreisel, VarioFoerderer,Gefaehllestrecke,Angetriebene_Kurve,Bt_element,Omniflo, Eckrad +from Elemente import Kreisel, VarioFoerderer,Gefaellestrecke,Angetriebene_Kurve,Bt_element,Omniflo, Eckrad # --------------------------------------------------------- CFG-Leser für shapes.cfg def get_shape_cfg(teileart, cfg_path, logger=None): parser = configparser.ConfigParser() diff --git a/lib/as_es_methoden.py b/lib/as_es_methoden.py index 6b0e9a2..85433fb 100644 --- a/lib/as_es_methoden.py +++ b/lib/as_es_methoden.py @@ -4,6 +4,8 @@ import plant2dxf import block_methoden RADIUS = 400 + + def vertausch_der_höhe(objekt): upper_hoehe_objekt = objekt.h1 lower_hoehe_objekt = objekt.h0 @@ -15,13 +17,36 @@ def vertausch_der_höhe(objekt): objekt.h1 = upper_hoehe_objekt lower_hoehe_objekt = hoehe2 objekt.h0 = lower_hoehe_objekt - rotation = rotation -180 + rotation = rotation - 180 objekt.drehung = rotation objekt.h1 = upper_hoehe_objekt objekt.h0 = lower_hoehe_objekt - -def erstellung_gefaelle_block_verbunenden_am_einen(msp,x, y, doc, lib_doc, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, hoehe_gefaehlle, drehung0, laenge,blockname,config, hight = None, block_vario = None, vario_richtung = None, verbunden_höher = None,gefaelle_block=None,start = None,ende = None,mit_horizontal_verbunden = None,as_es_rotation= None): - """Tut ein as/es element in den Block für gefällestrecken wird auch überprüft ob nur ein as es element vorhanden ist""" + + +def erstellung_gefaelle_block_verbunden_an_einen( + msp, + x, + y, + doc, + lib_doc, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + hoehe_gefaelle, + drehung0, + laenge, + blockname, + config, + hight=None, + block_vario=None, + vario_richtung=None, + verbunden_höher=None, + gefaelle_block=None, + start=None, + ende=None, + mit_horizontal_verbunden=None, + as_es_rotation=None, +): + """Tut ein as/es element in den Block für Gefällestrecken wird auch überprüft ob nur ein as es Element vorhanden ist""" halbe_laenge = laenge / 2 dy = halbe_laenge * math.cos(0) asoffset = float(config.get("ILS 2.0 Gefällestrecke", "asoffset")) @@ -34,96 +59,216 @@ def erstellung_gefaelle_block_verbunenden_am_einen(msp,x, y, doc, lib_doc, upper esoffset_z = esoffset * math.sin(math.radians(winkel_es)) block_as = None block_es = None - if (( hight == "higher" and drehung0 == "GUZS" )or (vario_richtung == "Auf"and verbunden_höher == False and drehung0 == "GUZS")or - (vario_richtung == "Ab" and verbunden_höher == True and drehung0 == "GUZS")or (vario_richtung == "Horizontal" and drehung0 == "GUZS" and (mit_horizontal_verbunden == "unten_drehung_0_or_-90" or mit_horizontal_verbunden == "oben_drehung_-180_or_-270"))): + if ( + (hight == "higher" and drehung0 == "GUZS") + or (vario_richtung == "Auf" and verbunden_höher == False and drehung0 == "GUZS") + or (vario_richtung == "Ab" and verbunden_höher == True and drehung0 == "GUZS") + or ( + vario_richtung == "Horizontal" + and drehung0 == "GUZS" + and ( + mit_horizontal_verbunden == "unten_drehung_0_or_-90" + or mit_horizontal_verbunden == "oben_drehung_-180_or_-270" + ) + ) + ): block_as = "200000241_AS-Element_90_rechts" - block_methoden.import_block(block_as,lib_doc,doc) + block_methoden.import_block(block_as, lib_doc, doc) layer, color = block_methoden.get_insert_color_layer(lib_doc, block_as) - elif ((hight == "lower" and drehung0 == "GUZS") or (vario_richtung == "Auf"and verbunden_höher == True and drehung0 == "GUZS") or - (vario_richtung == "Ab" and verbunden_höher == False and drehung0 == "GUZS")or (vario_richtung == "Horizontal" and drehung0 == "GUZS" and (mit_horizontal_verbunden == "oben_drehung_0_or_-90" or mit_horizontal_verbunden == "unten_drehung_-180_or_-270"))): + elif ( + (hight == "lower" and drehung0 == "GUZS") + or (vario_richtung == "Auf" and verbunden_höher == True and drehung0 == "GUZS") + or (vario_richtung == "Ab" and verbunden_höher == False and drehung0 == "GUZS") + or ( + vario_richtung == "Horizontal" + and drehung0 == "GUZS" + and ( + mit_horizontal_verbunden == "oben_drehung_0_or_-90" + or mit_horizontal_verbunden == "unten_drehung_-180_or_-270" + ) + ) + ): block_es = "200000146_ES-Element_90_rechts" - block_methoden.import_block(block_es,lib_doc,doc) + block_methoden.import_block(block_es, lib_doc, doc) layer, color = block_methoden.get_insert_color_layer(lib_doc, block_es) - elif ((hight == "higher" and drehung0 == "UZS")or (vario_richtung == "Auf"and verbunden_höher == False and drehung0 == "UZS") or - (vario_richtung == "Ab" and verbunden_höher == True and drehung0 == "UZS")or (vario_richtung == "Horizontal" and drehung0 == "UZS" and (mit_horizontal_verbunden == "unten_drehung_0_or_-90" or mit_horizontal_verbunden == "oben_drehung_-180_or_-270"))): + elif ( + (hight == "higher" and drehung0 == "UZS") + or (vario_richtung == "Auf" and verbunden_höher == False and drehung0 == "UZS") + or (vario_richtung == "Ab" and verbunden_höher == True and drehung0 == "UZS") + or ( + vario_richtung == "Horizontal" + and drehung0 == "UZS" + and ( + mit_horizontal_verbunden == "unten_drehung_0_or_-90" + or mit_horizontal_verbunden == "oben_drehung_-180_or_-270" + ) + ) + ): block_as = "200000217_AS-Element_90_links" - block_methoden.import_block(block_as,lib_doc,doc) + block_methoden.import_block(block_as, lib_doc, doc) layer, color = block_methoden.get_insert_color_layer(lib_doc, block_as) - elif (( hight == "lower" and drehung0 == "UZS") or (vario_richtung == "Auf" and verbunden_höher == True and drehung0 == "UZS") or - (vario_richtung == "Ab" and verbunden_höher == False and drehung0 == "UZS")or (vario_richtung == "Horizontal" and drehung0 == "UZS" and (mit_horizontal_verbunden == "oben_drehung_0_or_-90" or mit_horizontal_verbunden == "unten_drehung_-180_or_-270"))): + elif ( + (hight == "lower" and drehung0 == "UZS") + or (vario_richtung == "Auf" and verbunden_höher == True and drehung0 == "UZS") + or (vario_richtung == "Ab" and verbunden_höher == False and drehung0 == "UZS") + or ( + vario_richtung == "Horizontal" + and drehung0 == "UZS" + and ( + mit_horizontal_verbunden == "oben_drehung_0_or_-90" + or mit_horizontal_verbunden == "unten_drehung_-180_or_-270" + ) + ) + ): block_es = "400102632_ES-Element_90_links" - block_methoden.import_block(block_es,lib_doc,doc) + block_methoden.import_block(block_es, lib_doc, doc) layer, color = block_methoden.get_insert_color_layer(lib_doc, block_es) if block_as != None: - block_as = block_methoden.dreh_block(block_as,doc,lib_doc,math.radians(winkel_as)) - if vario_richtung == "Auf" or vario_richtung =="Horizontal": - start = (x , y + dy ,upper_hoehe_gefaehlle) - ende = (x , y - dy + asoffset_y ,lower_hoehe_gefaehlle - asoffset_z) - block_vario.add_blockref(block_as,(ende[0]-x ,ende[1]-asoffset_y -y,ende[2] -hoehe_gefaehlle + asoffset_z),dxfattribs={"rotation": 180,"layer":layer,"color":color}) + block_as = block_methoden.dreh_block( + block_as, doc, lib_doc, math.radians(winkel_as) + ) + if vario_richtung == "Auf" or vario_richtung == "Horizontal": + start = (x, y + dy, upper_hoehe_gefaelle) + ende = (x, y - dy + asoffset_y, lower_hoehe_gefaelle - asoffset_z) + block_vario.add_blockref( + block_as, + ( + ende[0] - x, + ende[1] - asoffset_y - y, + ende[2] - hoehe_gefaelle + asoffset_z, + ), + dxfattribs={"rotation": 180, "layer": layer, "color": color}, + ) return start, ende elif vario_richtung == "Ab": - start = (x , y + dy - asoffset_y,upper_hoehe_gefaehlle - asoffset_z) - ende = (x , y - dy ,lower_hoehe_gefaehlle) - block_vario.add_blockref(block_as,(start[0]-x ,start[1]+asoffset_y -y,start[2] -hoehe_gefaehlle + asoffset_z),dxfattribs={"layer":layer,"color":color}) - return start,ende + start = (x, y + dy - asoffset_y, upper_hoehe_gefaelle - asoffset_z) + ende = (x, y - dy, lower_hoehe_gefaelle) + block_vario.add_blockref( + block_as, + ( + start[0] - x, + start[1] + asoffset_y - y, + start[2] - hoehe_gefaelle + asoffset_z, + ), + dxfattribs={"layer": layer, "color": color}, + ) + return start, ende if laenge >= asoffset: start[1] = start[1] - asoffset_y start[2] = start[2] - asoffset_z line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" - copy= line.copy() - copy.translate(-x,-y,-hoehe_gefaehlle) + copy = line.copy() + copy.translate(-x, -y, -hoehe_gefaelle) gefaelle_block.add_entity(copy) - gefaelle_block.add_blockref(block_as,(start[0]-x ,start[1]+asoffset_y -y,start[2] -hoehe_gefaehlle + asoffset_z),dxfattribs={"layer":layer,"color":color}) + gefaelle_block.add_blockref( + block_as, + ( + start[0] - x, + start[1] + asoffset_y - y, + start[2] - hoehe_gefaelle + asoffset_z, + ), + dxfattribs={"layer": layer, "color": color}, + ) return False else: - msp.add_blockref(block_as,(start[0],start[1]+asoffset_y,upper_hoehe_gefaehlle),dxfattribs={"layer":layer,"color":color}) + msp.add_blockref( + block_as, + (start[0], start[1] + asoffset_y, upper_hoehe_gefaelle), + dxfattribs={"layer": layer, "color": color}, + ) return True elif block_es != None: - block_es = block_methoden.dreh_block(block_es,doc,lib_doc,math.radians(winkel_es)) - if vario_richtung == "Auf" or vario_richtung =="Horizontal": - start = (x , y + dy-esoffset_y ,upper_hoehe_gefaehlle + esoffset_z) - ende = (x , y - dy,lower_hoehe_gefaehlle) - block_vario.add_blockref(block_es, (start[0]-x ,start[1]+esoffset_y -y,start[2] - hoehe_gefaehlle - esoffset_z),dxfattribs={"rotation": 180,"layer":layer,"color":color}) - return start, ende + block_es = block_methoden.dreh_block( + block_es, doc, lib_doc, math.radians(winkel_es) + ) + if vario_richtung == "Auf" or vario_richtung == "Horizontal": + start = (x, y + dy - esoffset_y, upper_hoehe_gefaelle + esoffset_z) + ende = (x, y - dy, lower_hoehe_gefaelle) + block_vario.add_blockref( + block_es, + ( + start[0] - x, + start[1] + esoffset_y - y, + start[2] - hoehe_gefaelle - esoffset_z, + ), + dxfattribs={"rotation": 180, "layer": layer, "color": color}, + ) + return start, ende elif vario_richtung == "Ab": - start = (x , y + dy ,upper_hoehe_gefaehlle) - ende = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z) - block_vario.add_blockref(block_es, (ende[0]-x ,ende[1]-esoffset_y -y,ende[2] - hoehe_gefaehlle -esoffset_z),dxfattribs={"rotation": as_es_rotation,"layer":layer,"color":color}) - return start,ende + start = (x, y + dy, upper_hoehe_gefaelle) + ende = (x, y - dy + esoffset_y, lower_hoehe_gefaelle + esoffset_z) + block_vario.add_blockref( + block_es, + ( + ende[0] - x, + ende[1] - esoffset_y - y, + ende[2] - hoehe_gefaelle - esoffset_z, + ), + dxfattribs={"rotation": as_es_rotation, "layer": layer, "color": color}, + ) + return start, ende if laenge >= esoffset: - ende[1] = ende[1] + esoffset_y - ende[2] = ende[2] + esoffset_z + ende[1] = ende[1] + esoffset_y + ende[2] = ende[2] + esoffset_z line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" - copy= line.copy() - copy.translate(-x ,-y,-hoehe_gefaehlle) + copy = line.copy() + copy.translate(-x, -y, -hoehe_gefaelle) gefaelle_block.add_entity(copy) - gefaelle_block.add_blockref(block_es, (ende[0]-x ,ende[1]-esoffset_y -y,ende[2] - hoehe_gefaehlle -esoffset_z),dxfattribs={"layer":layer,"color":color}) + gefaelle_block.add_blockref( + block_es, + ( + ende[0] - x, + ende[1] - esoffset_y - y, + ende[2] - hoehe_gefaelle - esoffset_z, + ), + dxfattribs={"layer": layer, "color": color}, + ) return False else: - msp.add_blockref(block_es,(ende[0],ende[1]+esoffset_y,lower_hoehe_gefaehlle),dxfattribs={"rotation": as_es_rotation,"layer":layer,"color":color}) + msp.add_blockref( + block_es, + (ende[0], ende[1] + esoffset_y, lower_hoehe_gefaelle), + dxfattribs={"rotation": as_es_rotation, "layer": layer, "color": color}, + ) return True -def gefaellegerade_erstellung(objekt,doc, lib_doc,richtung2, drehung0, drehung1,hight_position, blockname,config, block_vario = None, am_kreisel = None, erster_kreisel_höher = None,y1=None,z1 =None): + +def gefaellegerade_erstellung( + objekt, + doc, + lib_doc, + richtung2, + drehung0, + drehung1, + hight_position, + blockname, + config, + block_vario=None, + am_kreisel=None, + erster_kreisel_höher=None, + y1=None, + z1=None, +): """erstellung des blockes falls die gefaelle strecke mit einem kreisel verbunden ist, mehrere variation von selben weil diese nötig sind sobald man die richtigen inserts bekommen""" - if hasattr(objekt,"foerderer_richtung"): + if hasattr(objekt, "foerderer_richtung"): voerder_richtung = objekt.foerderer_richtung else: voerder_richtung = None - - laenge =objekt.laenge - upper_hoehe_gefaehlle = objekt.h1 - lower_hoehe_gefaehlle = objekt.h0 + + laenge = objekt.laenge + upper_hoehe_gefaelle = objekt.h1 + lower_hoehe_gefaelle = objekt.h0 x = objekt.x y = objekt.y - hoehe_gefaehlle = objekt.hight_zwischen + hoehe_gefaelle = objekt.hight_zwischen asoffset = float(config.get("ILS 2.0 Gefällestrecke", "asoffset")) esoffset = float(config.get("ILS 2.0 Gefällestrecke", "esoffset")) @@ -137,172 +282,435 @@ def gefaellegerade_erstellung(objekt,doc, lib_doc,richtung2, drehung0, drehung1, block_es = None halbe_laenge = laenge / 2 dy = halbe_laenge * math.cos(0) - if upper_hoehe_gefaehlle < lower_hoehe_gefaehlle: - middle_hoehe = upper_hoehe_gefaehlle - upper_hoehe_gefaehlle = lower_hoehe_gefaehlle - lower_hoehe_gefaehlle = middle_hoehe + if upper_hoehe_gefaelle < lower_hoehe_gefaelle: + middle_hoehe = upper_hoehe_gefaelle + upper_hoehe_gefaelle = lower_hoehe_gefaelle + lower_hoehe_gefaelle = middle_hoehe # Entnehmung welches as/es element man braucht wenn es mit zwei Kreisel verbunden ist aber ein Kreisel direkt am Kopf hängt - if richtung2!= "DEFAULT" or am_kreisel != None: + if richtung2 != "DEFAULT" or am_kreisel != None: # Schaut bei gleicher Orentierung - if ((drehung0 == "GUZS" and drehung1 == "GUZS" and hight_position == "higher") or - (voerder_richtung == "Auf" and((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel== 2 and erster_kreisel_höher == True)) and drehung0 == "GUZS" and drehung1== "GUZS") or - (voerder_richtung == "Ab"and ((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel== 2 and erster_kreisel_höher == False)) and drehung0 == "GUZS" and drehung1== "GUZS") or - # Schaut bei ungleicher Orentierung - ((drehung0 == "UZS" and drehung1 == "GUZS" and hight_position== "higher"))or - (voerder_richtung == "Auf"and ((am_kreisel == 1 and erster_kreisel_höher == False) or (am_kreisel ==2 and erster_kreisel_höher ==True))and (drehung0 == "GUZS" and drehung1 == "UZS")) or - (voerder_richtung == "Ab" and((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel == 2 and erster_kreisel_höher == False))and (drehung0 == "UZS" and drehung1 == "GUZS"))): + if ( + (drehung0 == "GUZS" and drehung1 == "GUZS" and hight_position == "higher") + or ( + voerder_richtung == "Auf" + and ( + (am_kreisel == 1 and erster_kreisel_höher == False) + or (am_kreisel == 2 and erster_kreisel_höher == True) + ) + and drehung0 == "GUZS" + and drehung1 == "GUZS" + ) + or ( + voerder_richtung == "Ab" + and ( + (am_kreisel == 1 and erster_kreisel_höher == True) + or (am_kreisel == 2 and erster_kreisel_höher == False) + ) + and drehung0 == "GUZS" + and drehung1 == "GUZS" + ) + or + # Schaut bei ungleicher Orentierung + ((drehung0 == "UZS" and drehung1 == "GUZS" and hight_position == "higher")) + or ( + voerder_richtung == "Auf" + and ( + (am_kreisel == 1 and erster_kreisel_höher == False) + or (am_kreisel == 2 and erster_kreisel_höher == True) + ) + and (drehung0 == "GUZS" and drehung1 == "UZS") + ) + or ( + voerder_richtung == "Ab" + and ( + (am_kreisel == 1 and erster_kreisel_höher == True) + or (am_kreisel == 2 and erster_kreisel_höher == False) + ) + and (drehung0 == "UZS" and drehung1 == "GUZS") + ) + ): block_es = "200000146_ES-Element_90_rechts" - block_methoden.import_block(block_es,lib_doc,doc) - layer, color = block_methoden.get_insert_color_layer(lib_doc,block_es) - - elif ((drehung0 == "GUZS" and drehung1 == "GUZS") or - (am_kreisel != None and drehung0 == "GUZS" and drehung1 == "GUZS") or - (drehung0 == "UZS" and drehung1 == "GUZS" and hight_position == "lower")or - (voerder_richtung == "Auf" and((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel == 2 and erster_kreisel_höher == False))and (drehung0 == "UZS" and drehung1 == "GUZS")) or - (voerder_richtung == "Ab"and ((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel == 2 and erster_kreisel_höher == True))and (drehung0 == "GUZS" and drehung1 == "UZS"))): + block_methoden.import_block(block_es, lib_doc, doc) + layer, color = block_methoden.get_insert_color_layer(lib_doc, block_es) + + elif ( + (drehung0 == "GUZS" and drehung1 == "GUZS") + or (am_kreisel != None and drehung0 == "GUZS" and drehung1 == "GUZS") + or (drehung0 == "UZS" and drehung1 == "GUZS" and hight_position == "lower") + or ( + voerder_richtung == "Auf" + and ( + (am_kreisel == 1 and erster_kreisel_höher == True) + or (am_kreisel == 2 and erster_kreisel_höher == False) + ) + and (drehung0 == "UZS" and drehung1 == "GUZS") + ) + or ( + voerder_richtung == "Ab" + and ( + (am_kreisel == 1 and erster_kreisel_höher == False) + or (am_kreisel == 2 and erster_kreisel_höher == True) + ) + and (drehung0 == "GUZS" and drehung1 == "UZS") + ) + ): block_as = "200000241_AS-Element_90_rechts" - block_methoden.import_block(block_as,lib_doc,doc) - layer, color = block_methoden.get_insert_color_layer(lib_doc,block_as) - - elif ((drehung0 == "UZS" and drehung1 == "UZS" and hight_position == "higher")or - (voerder_richtung == "Auf" and((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel== 2 and erster_kreisel_höher == True)) and drehung0 == "UZS" and drehung1== "UZS")or - (voerder_richtung == "Ab" and((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel== 2 and erster_kreisel_höher == False)) and drehung0 == "UZS" and drehung1== "UZS") or - - (drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "higher")or - (voerder_richtung == "Auf" and((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel == 2 and erster_kreisel_höher == True))and (drehung0 == "UZS" and drehung1 == "GUZS")) or - (voerder_richtung == "Ab" and((am_kreisel == 1 and erster_kreisel_höher == True) or (am_kreisel ==2 and erster_kreisel_höher ==False))and (drehung0 == "GUZS" and drehung1 == "UZS"))): + block_methoden.import_block(block_as, lib_doc, doc) + layer, color = block_methoden.get_insert_color_layer(lib_doc, block_as) + + elif ( + (drehung0 == "UZS" and drehung1 == "UZS" and hight_position == "higher") + or ( + voerder_richtung == "Auf" + and ( + (am_kreisel == 1 and erster_kreisel_höher == False) + or (am_kreisel == 2 and erster_kreisel_höher == True) + ) + and drehung0 == "UZS" + and drehung1 == "UZS" + ) + or ( + voerder_richtung == "Ab" + and ( + (am_kreisel == 1 and erster_kreisel_höher == True) + or (am_kreisel == 2 and erster_kreisel_höher == False) + ) + and drehung0 == "UZS" + and drehung1 == "UZS" + ) + or (drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "higher") + or ( + voerder_richtung == "Auf" + and ( + (am_kreisel == 1 and erster_kreisel_höher == False) + or (am_kreisel == 2 and erster_kreisel_höher == True) + ) + and (drehung0 == "UZS" and drehung1 == "GUZS") + ) + or ( + voerder_richtung == "Ab" + and ( + (am_kreisel == 1 and erster_kreisel_höher == True) + or (am_kreisel == 2 and erster_kreisel_höher == False) + ) + and (drehung0 == "GUZS" and drehung1 == "UZS") + ) + ): block_es = "400102632_ES-Element_90_links" - block_methoden.import_block(block_es,lib_doc,doc) - layer, color = block_methoden.get_insert_color_layer(lib_doc,block_es) + block_methoden.import_block(block_es, lib_doc, doc) + layer, color = block_methoden.get_insert_color_layer(lib_doc, block_es) - - elif (((drehung0 == "UZS" and drehung1 == "UZS")or - (am_kreisel!= None and drehung0 == "UZS" and drehung1 == "UZS")) or - (drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "lower")or - (voerder_richtung == "Auf"and((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel == 2 and erster_kreisel_höher == False))and (drehung0 == "GUZS" and drehung1 == "UZS")) or - (voerder_richtung == "Ab" and((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel == 2 and erster_kreisel_höher == True))and (drehung0 == "UZS" and drehung1 == "GUZS"))): + elif ( + ( + (drehung0 == "UZS" and drehung1 == "UZS") + or (am_kreisel != None and drehung0 == "UZS" and drehung1 == "UZS") + ) + or (drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "lower") + or ( + voerder_richtung == "Auf" + and ( + (am_kreisel == 1 and erster_kreisel_höher == True) + or (am_kreisel == 2 and erster_kreisel_höher == False) + ) + and (drehung0 == "GUZS" and drehung1 == "UZS") + ) + or ( + voerder_richtung == "Ab" + and ( + (am_kreisel == 1 and erster_kreisel_höher == False) + or (am_kreisel == 2 and erster_kreisel_höher == True) + ) + and (drehung0 == "UZS" and drehung1 == "GUZS") + ) + ): block_as = "200000217_AS-Element_90_links" - block_methoden.import_block(block_as,lib_doc,doc) - layer, color = block_methoden.get_insert_color_layer(lib_doc,block_as) + block_methoden.import_block(block_as, lib_doc, doc) + layer, color = block_methoden.get_insert_color_layer(lib_doc, block_as) # Erstellt den Block if block_es != None: - block_es = block_methoden.dreh_block(block_es,doc,lib_doc,math.radians(winkel_es)) + block_es = block_methoden.dreh_block( + block_es, doc, lib_doc, math.radians(winkel_es) + ) if voerder_richtung == "Auf": - start = (x , y+ dy - esoffset_y,upper_hoehe_gefaehlle + esoffset_z) - ende = (x , y1 ,z1) - block_vario.add_blockref(block_es, (start[0]-x ,start[1]+esoffset_y-y ,start[2] - esoffset_z-hoehe_gefaehlle),dxfattribs={"rotation": 180,"layer": layer,"color": color}) - return start,ende - elif(voerder_richtung == "Ab"): - start = (x , y1 ,z1) - ende = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z) - block_vario.add_blockref(block_es, (ende[0]-x ,ende[1]-esoffset_y-y ,ende[2] - esoffset_z -hoehe_gefaehlle),dxfattribs={"layer": layer,"color": color}) - return start, ende - elif am_kreisel == None and blockname not in doc.blocks: - block = doc.blocks.new(name=blockname, base_point=(0,0,0)) - start = (x , y + dy,upper_hoehe_gefaehlle) - ende = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z) - line = Line.new(dxfattribs={"start": start, "end": ende}) - line.dxf.layer = "6-SP" - copy= line.copy() - copy.translate(-x,-y,-hoehe_gefaehlle) - block.add_entity(copy) - block.add_blockref(block_es, (ende[0]-x ,ende[1]- esoffset_y -y ,ende[2] -hoehe_gefaehlle ),dxfattribs={"layer": layer,"color": color}) - if block_as != None: - block_as = block_methoden.dreh_block(block_as,doc,lib_doc,math.radians(winkel_as)) - if voerder_richtung == "Auf": - start = (x , y1,z1) - ende = (x , y - dy + asoffset_y ,lower_hoehe_gefaehlle) - block_vario.add_blockref(block_as,(ende[0]-x ,ende[1]-asoffset_y -y,ende[2] - esoffset_z - hoehe_gefaehlle ),dxfattribs={"rotation": 180,"layer": layer,"color": color}) + start = (x, y + dy - esoffset_y, upper_hoehe_gefaelle + esoffset_z) + ende = (x, y1, z1) + block_vario.add_blockref( + block_es, + ( + start[0] - x, + start[1] + esoffset_y - y, + start[2] - esoffset_z - hoehe_gefaelle, + ), + dxfattribs={"rotation": 180, "layer": layer, "color": color}, + ) return start, ende elif voerder_richtung == "Ab": - start = (x , y +dy - asoffset_y,upper_hoehe_gefaehlle - asoffset_z) - ende = (x , y1 ,z1) - block_vario.add_blockref(block_as,(start[0]-x ,start[1]+asoffset_y -y,start[2] + asoffset_z - hoehe_gefaehlle),dxfattribs={"layer": layer,"color": color}) - return start,ende + start = (x, y1, z1) + ende = (x, y - dy + esoffset_y, lower_hoehe_gefaelle + esoffset_z) + block_vario.add_blockref( + block_es, + ( + ende[0] - x, + ende[1] - esoffset_y - y, + ende[2] - esoffset_z - hoehe_gefaelle, + ), + dxfattribs={"layer": layer, "color": color}, + ) + return start, ende elif am_kreisel == None and blockname not in doc.blocks: - block = doc.blocks.new(name=blockname, base_point=(0,0,0)) - start = (x , y +dy - asoffset_y,upper_hoehe_gefaehlle- asoffset_z) - ende = (x , y - dy ,lower_hoehe_gefaehlle) + block = doc.blocks.new(name=blockname, base_point=(0, 0, 0)) + start = (x, y + dy, upper_hoehe_gefaelle) + ende = (x, y - dy + esoffset_y, lower_hoehe_gefaelle + esoffset_z) + line = Line.new(dxfattribs={"start": start, "end": ende}) + line.dxf.layer = "6-SP" + copy = line.copy() + copy.translate(-x, -y, -hoehe_gefaelle) + block.add_entity(copy) + block.add_blockref( + block_es, + (ende[0] - x, ende[1] - esoffset_y - y, ende[2] - hoehe_gefaelle), + dxfattribs={"layer": layer, "color": color}, + ) + if block_as != None: + block_as = block_methoden.dreh_block( + block_as, doc, lib_doc, math.radians(winkel_as) + ) + if voerder_richtung == "Auf": + start = (x, y1, z1) + ende = (x, y - dy + asoffset_y, lower_hoehe_gefaelle) + block_vario.add_blockref( + block_as, + ( + ende[0] - x, + ende[1] - asoffset_y - y, + ende[2] - esoffset_z - hoehe_gefaelle, + ), + dxfattribs={"rotation": 180, "layer": layer, "color": color}, + ) + return start, ende + elif voerder_richtung == "Ab": + start = (x, y + dy - asoffset_y, upper_hoehe_gefaelle - asoffset_z) + ende = (x, y1, z1) + block_vario.add_blockref( + block_as, + ( + start[0] - x, + start[1] + asoffset_y - y, + start[2] + asoffset_z - hoehe_gefaelle, + ), + dxfattribs={"layer": layer, "color": color}, + ) + return start, ende + elif am_kreisel == None and blockname not in doc.blocks: + block = doc.blocks.new(name=blockname, base_point=(0, 0, 0)) + start = (x, y + dy - asoffset_y, upper_hoehe_gefaelle - asoffset_z) + ende = (x, y - dy, lower_hoehe_gefaelle) line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" - copy= line.copy() - copy.translate(-x ,-y,-hoehe_gefaehlle) + copy = line.copy() + copy.translate(-x, -y, -hoehe_gefaelle) block.add_entity(copy) - block.add_blockref(block_as,(start[0]-x ,start[1]+asoffset_y -y,start[2] + asoffset_z - hoehe_gefaehlle)) + block.add_blockref( + block_as, + ( + start[0] - x, + start[1] + asoffset_y - y, + start[2] + asoffset_z - hoehe_gefaelle, + ), + ) else: - if (( drehung0 == "GUZS" and drehung1 == "GUZS") or (voerder_richtung != None and drehung0 == "GUZS" and drehung1 == "GUZS")): + if (drehung0 == "GUZS" and drehung1 == "GUZS") or ( + voerder_richtung != None and drehung0 == "GUZS" and drehung1 == "GUZS" + ): block_as = "200000241_AS-Element_90_rechts" - block_methoden.import_block(block_as,lib_doc,doc) + block_methoden.import_block(block_as, lib_doc, doc) block_es = "200000146_ES-Element_90_rechts" - block_methoden.import_block(block_es,lib_doc,doc) - as_layer, as_color = block_methoden.get_insert_color_layer(lib_doc,block_as) - es_layer, es_color = block_methoden.get_insert_color_layer(lib_doc,block_es) - elif (((drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "higher")or (drehung0 == "UZS" and drehung1 == "GUZS" and hight_position == "lower")) or - (voerder_richtung == "Auf" and drehung0 == "UZS"and drehung1 == "GUZS") or - (voerder_richtung == "Ab" and drehung0 == "GUZS" and drehung1 == "UZS")) : + block_methoden.import_block(block_es, lib_doc, doc) + as_layer, as_color = block_methoden.get_insert_color_layer( + lib_doc, block_as + ) + es_layer, es_color = block_methoden.get_insert_color_layer( + lib_doc, block_es + ) + elif ( + ( + ( + drehung0 == "GUZS" + and drehung1 == "UZS" + and hight_position == "higher" + ) + or ( + drehung0 == "UZS" + and drehung1 == "GUZS" + and hight_position == "lower" + ) + ) + or (voerder_richtung == "Auf" and drehung0 == "UZS" and drehung1 == "GUZS") + or (voerder_richtung == "Ab" and drehung0 == "GUZS" and drehung1 == "UZS") + ): block_as = "200000241_AS-Element_90_rechts" - block_methoden.import_block(block_as,lib_doc,doc) + block_methoden.import_block(block_as, lib_doc, doc) block_es = "400102632_ES-Element_90_links" - block_methoden.import_block(block_es,lib_doc,doc) - as_layer, as_color = block_methoden.get_insert_color_layer(lib_doc,block_as) - es_layer, es_color = block_methoden.get_insert_color_layer(lib_doc,block_es) - elif (( drehung0 == "UZS" and drehung1 == "UZS") or (voerder_richtung != None and drehung0 == "UZS" and drehung1 == "UZS")): + block_methoden.import_block(block_es, lib_doc, doc) + as_layer, as_color = block_methoden.get_insert_color_layer( + lib_doc, block_as + ) + es_layer, es_color = block_methoden.get_insert_color_layer( + lib_doc, block_es + ) + elif (drehung0 == "UZS" and drehung1 == "UZS") or ( + voerder_richtung != None and drehung0 == "UZS" and drehung1 == "UZS" + ): block_as = "200000217_AS-Element_90_links" - block_methoden.import_block(block_as,lib_doc,doc) + block_methoden.import_block(block_as, lib_doc, doc) block_es = "400102632_ES-Element_90_links" - block_methoden.import_block(block_es,lib_doc,doc) - as_layer, as_color = block_methoden.get_insert_color_layer(lib_doc,block_as) - es_layer, es_color = block_methoden.get_insert_color_layer(lib_doc,block_es) - elif ((((drehung0 == "UZS" and drehung1 == "GUZS" and hight_position== "higher")or (drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "lower")))or - (voerder_richtung == "Auf" and drehung0 == "GUZS" and drehung1 == "UZS") or - (voerder_richtung == "Ab" and drehung0 == "UZS"and drehung1 == "GUZS")) : + block_methoden.import_block(block_es, lib_doc, doc) + as_layer, as_color = block_methoden.get_insert_color_layer( + lib_doc, block_as + ) + es_layer, es_color = block_methoden.get_insert_color_layer( + lib_doc, block_es + ) + elif ( + ( + ( + ( + drehung0 == "UZS" + and drehung1 == "GUZS" + and hight_position == "higher" + ) + or ( + drehung0 == "GUZS" + and drehung1 == "UZS" + and hight_position == "lower" + ) + ) + ) + or (voerder_richtung == "Auf" and drehung0 == "GUZS" and drehung1 == "UZS") + or (voerder_richtung == "Ab" and drehung0 == "UZS" and drehung1 == "GUZS") + ): block_as = "200000217_AS-Element_90_links" - block_methoden.import_block(block_as,lib_doc,doc) + block_methoden.import_block(block_as, lib_doc, doc) block_es = "200000146_ES-Element_90_rechts" - block_methoden.import_block(block_es,lib_doc,doc) - as_layer, as_color = block_methoden.get_insert_color_layer(lib_doc,block_as) - es_layer, es_color = block_methoden.get_insert_color_layer(lib_doc,block_es) - block_as = block_methoden.dreh_block(block_as,doc,lib_doc,math.radians(winkel_as)) - block_es = block_methoden.dreh_block(block_es,doc,lib_doc,math.radians(winkel_es)) + block_methoden.import_block(block_es, lib_doc, doc) + as_layer, as_color = block_methoden.get_insert_color_layer( + lib_doc, block_as + ) + es_layer, es_color = block_methoden.get_insert_color_layer( + lib_doc, block_es + ) + block_as = block_methoden.dreh_block( + block_as, doc, lib_doc, math.radians(winkel_as) + ) + block_es = block_methoden.dreh_block( + block_es, doc, lib_doc, math.radians(winkel_es) + ) halbe_laenge = laenge / 2 dy = halbe_laenge * math.cos(0) if hight_position != None and blockname not in doc.blocks: - block = doc.blocks.new(name=blockname, base_point=(0,0,0)) - start = (x , y + dy - asoffset_y,upper_hoehe_gefaehlle- asoffset_z) - ende = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z) + block = doc.blocks.new(name=blockname, base_point=(0, 0, 0)) + start = (x, y + dy - asoffset_y, upper_hoehe_gefaelle - asoffset_z) + ende = (x, y - dy + esoffset_y, lower_hoehe_gefaelle + esoffset_z) line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" - copy= line.copy() + copy = line.copy() - copy.translate(-x ,-y,-hoehe_gefaehlle) + copy.translate(-x, -y, -hoehe_gefaelle) block.add_entity(copy) - block.add_blockref(block_as,(start[0]-x ,start[1]+asoffset_y -y,start[2] + asoffset_z - hoehe_gefaehlle),dxfattribs={"layer": as_layer,"color": as_color}) - block.add_blockref(block_es, (ende[0]-x ,ende[1]-esoffset_y -y,ende[2] - esoffset_z - hoehe_gefaehlle ),dxfattribs={"layer": es_layer,"color": es_color}) + block.add_blockref( + block_as, + ( + start[0] - x, + start[1] + asoffset_y - y, + start[2] + asoffset_z - hoehe_gefaelle, + ), + dxfattribs={"layer": as_layer, "color": as_color}, + ) + block.add_blockref( + block_es, + ( + ende[0] - x, + ende[1] - esoffset_y - y, + ende[2] - esoffset_z - hoehe_gefaelle, + ), + dxfattribs={"layer": es_layer, "color": es_color}, + ) return if voerder_richtung == "Auf": - start = (x , y + dy - esoffset_y,upper_hoehe_gefaehlle + esoffset_z) - ende = (x , y - dy + asoffset,lower_hoehe_gefaehlle -asoffset_z) + start = (x, y + dy - esoffset_y, upper_hoehe_gefaelle + esoffset_z) + ende = (x, y - dy + asoffset, lower_hoehe_gefaelle - asoffset_z) - block_vario.add_blockref(block_es,(start[0]-x ,start[1]+esoffset_y -y,start[2] - esoffset_z - hoehe_gefaehlle ),dxfattribs={"rotation": 180,"layer": as_layer,"color": as_color}) - block_vario.add_blockref(block_as, (ende[0]-x ,ende[1]-asoffset_y -y,ende[2] + asoffset_z - hoehe_gefaehlle ),dxfattribs={"rotation": 180,"layer": es_layer,"color": es_color}) - return start,ende + block_vario.add_blockref( + block_es, + ( + start[0] - x, + start[1] + esoffset_y - y, + start[2] - esoffset_z - hoehe_gefaelle, + ), + dxfattribs={"rotation": 180, "layer": as_layer, "color": as_color}, + ) + block_vario.add_blockref( + block_as, + ( + ende[0] - x, + ende[1] - asoffset_y - y, + ende[2] + asoffset_z - hoehe_gefaelle, + ), + dxfattribs={"rotation": 180, "layer": es_layer, "color": es_color}, + ) + return start, ende elif voerder_richtung == "Ab": - start = (x , y + dy - asoffset_y,upper_hoehe_gefaehlle - asoffset_z) - ende = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z) + start = (x, y + dy - asoffset_y, upper_hoehe_gefaelle - asoffset_z) + ende = (x, y - dy + esoffset_y, lower_hoehe_gefaelle + esoffset_z) - block_vario.add_blockref(block_as,(start[0]-x ,start[1]+asoffset_y -y,start[2] + asoffset_z - hoehe_gefaehlle),dxfattribs={"layer": as_layer,"color": as_color}) - block_vario.add_blockref(block_es, (ende[0]-x ,ende[1]-esoffset_y -y,ende[2] - esoffset_z - hoehe_gefaehlle),dxfattribs={"layer": es_layer,"color": es_color}) - return start,ende + block_vario.add_blockref( + block_as, + ( + start[0] - x, + start[1] + asoffset_y - y, + start[2] + asoffset_z - hoehe_gefaelle, + ), + dxfattribs={"layer": as_layer, "color": as_color}, + ) + block_vario.add_blockref( + block_es, + ( + ende[0] - x, + ende[1] - esoffset_y - y, + ende[2] - esoffset_z - hoehe_gefaelle, + ), + dxfattribs={"layer": es_layer, "color": es_color}, + ) + return start, ende - -def am_kreisel_direct_verbunden(x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, x0_kreisel, y0_kreisel, richtung_rad0, abstand0, dx, dy, x1_kreisel, y1_kreisel, richtung_rad1, abstand1,kreisel_verbunden= None, richtung0 = None, richtung1 = None, richtung2 = None): + +def am_kreisel_direct_verbunden( + x, + y, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + x0_kreisel, + y0_kreisel, + richtung_rad0, + abstand0, + dx, + dy, + x1_kreisel, + y1_kreisel, + richtung_rad1, + abstand1, + kreisel_verbunden=None, + richtung0=None, + richtung1=None, + richtung2=None, +): """Schaut ob das Element direkt am Kreisle Kopf hängt""" if kreisel_verbunden == None: kreisel_verbunden = 0 @@ -311,13 +719,13 @@ def am_kreisel_direct_verbunden(x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehl halbabstand0 = abstand0 / 2 dx0 = halbabstand0 * math.cos(richtung_rad0) dy0 = halbabstand0 * math.sin(richtung_rad0) - pos0_0_floor= (math.floor(x0_kreisel + dx0),math.floor( y0_kreisel + dy0)) - pos0_1_floor = (math.floor(x0_kreisel- dx0),math.floor( y0_kreisel- dy0)) - pos0_0_round= (round(x0_kreisel + dx0),round( y0_kreisel + dy0)) - pos0_1_round = (round(x0_kreisel- dx0),round( y0_kreisel- dy0)) - if (x1_kreisel != None): + pos0_0_floor = (math.floor(x0_kreisel + dx0), math.floor(y0_kreisel + dy0)) + pos0_1_floor = (math.floor(x0_kreisel - dx0), math.floor(y0_kreisel - dy0)) + pos0_0_round = (round(x0_kreisel + dx0), round(y0_kreisel + dy0)) + pos0_1_round = (round(x0_kreisel - dx0), round(y0_kreisel - dy0)) + if x1_kreisel != None: halbabstand1 = abstand1 / 2 - dx1 = halbabstand1 * math.cos(richtung_rad1 ) + dx1 = halbabstand1 * math.cos(richtung_rad1) dy1 = halbabstand1 * math.sin(richtung_rad1) pos1_0_floor = (math.floor(x1_kreisel + dx1), math.floor(y1_kreisel + dy1)) pos1_1_floor = (math.floor(x1_kreisel - dx1), math.floor(y1_kreisel - dy1)) @@ -325,67 +733,65 @@ def am_kreisel_direct_verbunden(x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehl pos1_1_round = (round(x1_kreisel - dx1), round(y1_kreisel - dy1)) # berechnung der geraden einmal abgerunden und einmal gerunden zur negirung des offsets - start_floor = (math.floor(x +dx ), math.floor(y + dy ),upper_hoehe_gefaehlle) - ende_floor = (math.floor(x -dx), math.floor(y - dy ) ,lower_hoehe_gefaehlle) - start_round = (round(x +dx ), round(y + dy ),upper_hoehe_gefaehlle) - ende_round= (round(x -dx), round(y - dy ) ,lower_hoehe_gefaehlle) - # verschiebund der endpunkte der gerade in richtung von dem potentiellen Kreisel für den vergleich wieder mit floor und rundung - abstand_fuer_kreis_start_x_floor = start_floor[0] +RADIUS, start_floor[1] - abstand_gegen_kreis_start_x_floor = start_floor[0] -RADIUS, start_floor[1] + start_floor = (math.floor(x + dx), math.floor(y + dy), upper_hoehe_gefaelle) + ende_floor = (math.floor(x - dx), math.floor(y - dy), lower_hoehe_gefaelle) + start_round = (round(x + dx), round(y + dy), upper_hoehe_gefaelle) + ende_round = (round(x - dx), round(y - dy), lower_hoehe_gefaelle) + # verschiebund der endpunkte der gerade in richtung von dem potentiellen Kreisel für den vergleich wieder mit floor und rundung + abstand_fuer_kreis_start_x_floor = start_floor[0] + RADIUS, start_floor[1] + abstand_gegen_kreis_start_x_floor = start_floor[0] - RADIUS, start_floor[1] abstand_fuer_kreis_start_y_floor = start_floor[0], start_floor[1] + RADIUS abstand_gegen_kreis_start_y_floor = start_floor[0], start_floor[1] - RADIUS - abstand_fuer_kreis_ende_x_floor= ende_floor[0] + RADIUS, ende_floor[1] - abstand_gegen_kreis_ende_x_floor= ende_floor[0] - RADIUS, ende_floor[1] - abstand_fuer_kreis_ende_y_floor = ende_floor[0] , ende_floor[1] + RADIUS - abstand_gegen_kreis_ende_y_floor = ende_floor[0] , ende_floor[1] - RADIUS + abstand_fuer_kreis_ende_x_floor = ende_floor[0] + RADIUS, ende_floor[1] + abstand_gegen_kreis_ende_x_floor = ende_floor[0] - RADIUS, ende_floor[1] + abstand_fuer_kreis_ende_y_floor = ende_floor[0], ende_floor[1] + RADIUS + abstand_gegen_kreis_ende_y_floor = ende_floor[0], ende_floor[1] - RADIUS - abstand_fuer_kreis_start_x_round= start_round[0] +RADIUS, start_round[1] - abstand_gegen_kreis_start_x_round = start_round[0] -RADIUS, start_round[1] + abstand_fuer_kreis_start_x_round = start_round[0] + RADIUS, start_round[1] + abstand_gegen_kreis_start_x_round = start_round[0] - RADIUS, start_round[1] abstand_fuer_kreis_start_y_round = start_round[0], start_round[1] + RADIUS abstand_gegen_kreis_start_y_round = start_round[0], start_round[1] - RADIUS - abstand_fuer_kreis_ende_x_round= ende_round[0] + RADIUS, ende_round[1] - abstand_gegen_kreis_ende_x_round= ende_round[0] - RADIUS, ende_round[1] - abstand_fuer_kreis_ende_y_round = ende_round[0] , ende_round[1] + RADIUS - abstand_gegen_kreis_ende_y_round = ende_round[0] , ende_round[1] - RADIUS - if(richtung0 != None and richtung0 != None): - if (richtung0 != richtung1 and kreisel_verbunden ==1): - if( - (abstand_fuer_kreis_start_y_floor == pos0_0_floor) or - (abstand_fuer_kreis_start_y_floor == pos0_1_floor) or - (abstand_gegen_kreis_start_y_floor == pos0_0_floor) or - (abstand_gegen_kreis_start_y_floor == pos0_1_floor) or - (abstand_fuer_kreis_ende_y_floor == pos0_0_floor) or - (abstand_fuer_kreis_ende_y_floor == pos0_1_floor) or - (abstand_gegen_kreis_ende_y_floor == pos0_0_floor) or - (abstand_gegen_kreis_ende_y_floor == pos0_1_floor) or - (abstand_fuer_kreis_start_y_round == pos0_0_round) or - (abstand_fuer_kreis_start_y_round == pos0_1_round) or - (abstand_gegen_kreis_start_y_round == pos0_0_round) or - (abstand_gegen_kreis_start_y_round == pos0_1_round) or - (abstand_fuer_kreis_ende_y_round == pos0_0_round) or - (abstand_fuer_kreis_ende_y_round == pos0_1_round) or - (abstand_gegen_kreis_ende_y_round == pos0_0_round) or - (abstand_gegen_kreis_ende_y_round == pos0_1_round) or - - (abstand_fuer_kreis_start_y_floor == pos1_0_floor) or - (abstand_fuer_kreis_start_y_floor == pos1_1_floor) or - (abstand_gegen_kreis_start_y_floor == pos1_0_floor) or - (abstand_gegen_kreis_start_y_floor == pos1_1_floor) or - (abstand_fuer_kreis_ende_y_floor == pos1_0_floor) or - (abstand_fuer_kreis_ende_y_floor == pos1_1_floor) or - (abstand_gegen_kreis_ende_y_floor == pos1_0_floor) or - (abstand_gegen_kreis_ende_y_floor == pos1_1_floor) or - - (abstand_fuer_kreis_start_y_round == pos1_0_round) or - (abstand_fuer_kreis_start_y_round == pos1_1_round) or - (abstand_gegen_kreis_start_y_round == pos1_0_round) or - (abstand_gegen_kreis_start_y_round == pos1_1_round) or - (abstand_fuer_kreis_ende_y_round == pos1_0_round) or - (abstand_fuer_kreis_ende_y_round == pos1_1_round) or - (abstand_gegen_kreis_ende_y_round == pos1_0_round) or - (abstand_gegen_kreis_ende_y_round == pos1_1_round) + abstand_fuer_kreis_ende_x_round = ende_round[0] + RADIUS, ende_round[1] + abstand_gegen_kreis_ende_x_round = ende_round[0] - RADIUS, ende_round[1] + abstand_fuer_kreis_ende_y_round = ende_round[0], ende_round[1] + RADIUS + abstand_gegen_kreis_ende_y_round = ende_round[0], ende_round[1] - RADIUS + if richtung0 != None and richtung0 != None: + if richtung0 != richtung1 and kreisel_verbunden == 1: + if ( + (abstand_fuer_kreis_start_y_floor == pos0_0_floor) + or (abstand_fuer_kreis_start_y_floor == pos0_1_floor) + or (abstand_gegen_kreis_start_y_floor == pos0_0_floor) + or (abstand_gegen_kreis_start_y_floor == pos0_1_floor) + or (abstand_fuer_kreis_ende_y_floor == pos0_0_floor) + or (abstand_fuer_kreis_ende_y_floor == pos0_1_floor) + or (abstand_gegen_kreis_ende_y_floor == pos0_0_floor) + or (abstand_gegen_kreis_ende_y_floor == pos0_1_floor) + or (abstand_fuer_kreis_start_y_round == pos0_0_round) + or (abstand_fuer_kreis_start_y_round == pos0_1_round) + or (abstand_gegen_kreis_start_y_round == pos0_0_round) + or (abstand_gegen_kreis_start_y_round == pos0_1_round) + or (abstand_fuer_kreis_ende_y_round == pos0_0_round) + or (abstand_fuer_kreis_ende_y_round == pos0_1_round) + or (abstand_gegen_kreis_ende_y_round == pos0_0_round) + or (abstand_gegen_kreis_ende_y_round == pos0_1_round) + or (abstand_fuer_kreis_start_y_floor == pos1_0_floor) + or (abstand_fuer_kreis_start_y_floor == pos1_1_floor) + or (abstand_gegen_kreis_start_y_floor == pos1_0_floor) + or (abstand_gegen_kreis_start_y_floor == pos1_1_floor) + or (abstand_fuer_kreis_ende_y_floor == pos1_0_floor) + or (abstand_fuer_kreis_ende_y_floor == pos1_1_floor) + or (abstand_gegen_kreis_ende_y_floor == pos1_0_floor) + or (abstand_gegen_kreis_ende_y_floor == pos1_1_floor) + or (abstand_fuer_kreis_start_y_round == pos1_0_round) + or (abstand_fuer_kreis_start_y_round == pos1_1_round) + or (abstand_gegen_kreis_start_y_round == pos1_0_round) + or (abstand_gegen_kreis_start_y_round == pos1_1_round) + or (abstand_fuer_kreis_ende_y_round == pos1_0_round) + or (abstand_fuer_kreis_ende_y_round == pos1_1_round) + or (abstand_gegen_kreis_ende_y_round == pos1_0_round) + or (abstand_gegen_kreis_ende_y_round == pos1_1_round) ): - richtung2= "Vertikal" + richtung2 = "Vertikal" unterschiedlich = True else: @@ -395,78 +801,80 @@ def am_kreisel_direct_verbunden(x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehl return richtung2, unterschiedlich # vergleich mit einem kreisel von zwei - if( (abstand_fuer_kreis_start_x_floor == pos0_0_floor) or - (abstand_fuer_kreis_start_x_floor == pos0_1_floor) or - (abstand_gegen_kreis_start_x_floor == pos0_0_floor) or - (abstand_gegen_kreis_start_x_floor == pos0_1_floor) or - (abstand_fuer_kreis_ende_x_floor == pos0_0_floor) or - (abstand_fuer_kreis_ende_x_floor == pos0_1_floor) or - (abstand_gegen_kreis_ende_x_floor == pos0_0_floor) or - (abstand_gegen_kreis_ende_x_floor == pos0_1_floor) or - (abstand_fuer_kreis_start_y_floor == pos0_0_floor) or - (abstand_fuer_kreis_start_y_floor == pos0_1_floor) or - (abstand_gegen_kreis_start_y_floor == pos0_0_floor) or - (abstand_gegen_kreis_start_y_floor == pos0_1_floor) or - (abstand_fuer_kreis_ende_y_floor == pos0_0_floor) or - (abstand_fuer_kreis_ende_y_floor == pos0_1_floor) or - (abstand_gegen_kreis_ende_y_floor == pos0_0_floor) or - (abstand_gegen_kreis_ende_y_floor == pos0_1_floor) or - (abstand_fuer_kreis_start_x_round == pos0_0_round ) or - (abstand_fuer_kreis_start_x_round == pos0_1_round) or - (abstand_gegen_kreis_start_x_round == pos0_0_round) or - (abstand_gegen_kreis_start_x_round == pos0_1_round) or - (abstand_fuer_kreis_ende_x_round == pos0_0_round) or - (abstand_fuer_kreis_ende_x_round == pos0_1_round) or - (abstand_gegen_kreis_ende_x_round == pos0_0_round) or - (abstand_gegen_kreis_ende_x_round == pos0_1_round) or - (abstand_fuer_kreis_start_y_round == pos0_0_round) or - (abstand_fuer_kreis_start_y_round == pos0_1_round) or - (abstand_gegen_kreis_start_y_round == pos0_0_round) or - (abstand_gegen_kreis_start_y_round == pos0_1_round) or - (abstand_fuer_kreis_ende_y_round == pos0_0_round) or - (abstand_fuer_kreis_ende_y_round == pos0_1_round) or - (abstand_gegen_kreis_ende_y_round == pos0_0_round) or - (abstand_gegen_kreis_ende_y_round == pos0_1_round) - ): - kreisel_verbunden = kreisel_verbunden +1 - # setzung auf kreisel 1 für spätere ausrechnung der geraden form + if ( + (abstand_fuer_kreis_start_x_floor == pos0_0_floor) + or (abstand_fuer_kreis_start_x_floor == pos0_1_floor) + or (abstand_gegen_kreis_start_x_floor == pos0_0_floor) + or (abstand_gegen_kreis_start_x_floor == pos0_1_floor) + or (abstand_fuer_kreis_ende_x_floor == pos0_0_floor) + or (abstand_fuer_kreis_ende_x_floor == pos0_1_floor) + or (abstand_gegen_kreis_ende_x_floor == pos0_0_floor) + or (abstand_gegen_kreis_ende_x_floor == pos0_1_floor) + or (abstand_fuer_kreis_start_y_floor == pos0_0_floor) + or (abstand_fuer_kreis_start_y_floor == pos0_1_floor) + or (abstand_gegen_kreis_start_y_floor == pos0_0_floor) + or (abstand_gegen_kreis_start_y_floor == pos0_1_floor) + or (abstand_fuer_kreis_ende_y_floor == pos0_0_floor) + or (abstand_fuer_kreis_ende_y_floor == pos0_1_floor) + or (abstand_gegen_kreis_ende_y_floor == pos0_0_floor) + or (abstand_gegen_kreis_ende_y_floor == pos0_1_floor) + or (abstand_fuer_kreis_start_x_round == pos0_0_round) + or (abstand_fuer_kreis_start_x_round == pos0_1_round) + or (abstand_gegen_kreis_start_x_round == pos0_0_round) + or (abstand_gegen_kreis_start_x_round == pos0_1_round) + or (abstand_fuer_kreis_ende_x_round == pos0_0_round) + or (abstand_fuer_kreis_ende_x_round == pos0_1_round) + or (abstand_gegen_kreis_ende_x_round == pos0_0_round) + or (abstand_gegen_kreis_ende_x_round == pos0_1_round) + or (abstand_fuer_kreis_start_y_round == pos0_0_round) + or (abstand_fuer_kreis_start_y_round == pos0_1_round) + or (abstand_gegen_kreis_start_y_round == pos0_0_round) + or (abstand_gegen_kreis_start_y_round == pos0_1_round) + or (abstand_fuer_kreis_ende_y_round == pos0_0_round) + or (abstand_fuer_kreis_ende_y_round == pos0_1_round) + or (abstand_gegen_kreis_ende_y_round == pos0_0_round) + or (abstand_gegen_kreis_ende_y_round == pos0_1_round) + ): + kreisel_verbunden = kreisel_verbunden + 1 + # setzung auf kreisel 1 für spätere ausrechnung der geraden form am_kreisel = 1 - if (x1_kreisel == None): - return am_kreisel,kreisel_verbunden + if x1_kreisel == None: + return am_kreisel, kreisel_verbunden - if( (abstand_fuer_kreis_start_x_floor == pos1_0_floor )or - (abstand_fuer_kreis_start_x_floor == pos1_1_floor) or - (abstand_gegen_kreis_start_x_floor == pos1_0_floor) or - (abstand_gegen_kreis_start_x_floor == pos1_1_floor) or - (abstand_fuer_kreis_ende_x_floor == pos1_0_floor) or - (abstand_fuer_kreis_ende_x_floor == pos1_1_floor) or - (abstand_gegen_kreis_ende_x_floor == pos1_0_floor) or - (abstand_gegen_kreis_ende_x_floor == pos1_1_floor) or - (abstand_fuer_kreis_start_y_floor == pos1_0_floor ) or - (abstand_fuer_kreis_start_y_floor == pos1_1_floor) or - (abstand_gegen_kreis_start_y_floor == pos1_0_floor) or - (abstand_gegen_kreis_start_y_floor == pos1_1_floor) or - (abstand_fuer_kreis_ende_y_floor == pos1_0_floor ) or - (abstand_fuer_kreis_ende_y_floor == pos1_1_floor) or - (abstand_gegen_kreis_ende_y_floor == pos1_0_floor) or - (abstand_gegen_kreis_ende_y_floor == pos1_1_floor) or - (abstand_fuer_kreis_start_x_round == pos1_0_round ) or - (abstand_fuer_kreis_start_x_round == pos1_1_round) or - (abstand_gegen_kreis_start_x_round == pos1_0_round) or - (abstand_gegen_kreis_start_x_round == pos1_1_round) or - (abstand_fuer_kreis_ende_x_round == pos1_0_round) or - (abstand_fuer_kreis_ende_x_round == pos1_1_round) or - (abstand_gegen_kreis_ende_x_round == pos1_0_round) or - (abstand_gegen_kreis_ende_x_round == pos1_1_round) or - (abstand_fuer_kreis_start_y_round == pos1_0_round) or - (abstand_fuer_kreis_start_y_round == pos1_1_round) or - (abstand_gegen_kreis_start_y_round == pos1_0_round) or - (abstand_gegen_kreis_start_y_round == pos1_1_round) or - (abstand_fuer_kreis_ende_y_round == pos1_0_round) or - (abstand_fuer_kreis_ende_y_round == pos1_1_round) or - (abstand_gegen_kreis_ende_y_round == pos1_0_round) or - (abstand_gegen_kreis_ende_y_round == pos1_1_round) - ): - kreisel_verbunden = kreisel_verbunden +1 - am_kreisel = 2 - return am_kreisel,kreisel_verbunden \ No newline at end of file + if ( + (abstand_fuer_kreis_start_x_floor == pos1_0_floor) + or (abstand_fuer_kreis_start_x_floor == pos1_1_floor) + or (abstand_gegen_kreis_start_x_floor == pos1_0_floor) + or (abstand_gegen_kreis_start_x_floor == pos1_1_floor) + or (abstand_fuer_kreis_ende_x_floor == pos1_0_floor) + or (abstand_fuer_kreis_ende_x_floor == pos1_1_floor) + or (abstand_gegen_kreis_ende_x_floor == pos1_0_floor) + or (abstand_gegen_kreis_ende_x_floor == pos1_1_floor) + or (abstand_fuer_kreis_start_y_floor == pos1_0_floor) + or (abstand_fuer_kreis_start_y_floor == pos1_1_floor) + or (abstand_gegen_kreis_start_y_floor == pos1_0_floor) + or (abstand_gegen_kreis_start_y_floor == pos1_1_floor) + or (abstand_fuer_kreis_ende_y_floor == pos1_0_floor) + or (abstand_fuer_kreis_ende_y_floor == pos1_1_floor) + or (abstand_gegen_kreis_ende_y_floor == pos1_0_floor) + or (abstand_gegen_kreis_ende_y_floor == pos1_1_floor) + or (abstand_fuer_kreis_start_x_round == pos1_0_round) + or (abstand_fuer_kreis_start_x_round == pos1_1_round) + or (abstand_gegen_kreis_start_x_round == pos1_0_round) + or (abstand_gegen_kreis_start_x_round == pos1_1_round) + or (abstand_fuer_kreis_ende_x_round == pos1_0_round) + or (abstand_fuer_kreis_ende_x_round == pos1_1_round) + or (abstand_gegen_kreis_ende_x_round == pos1_0_round) + or (abstand_gegen_kreis_ende_x_round == pos1_1_round) + or (abstand_fuer_kreis_start_y_round == pos1_0_round) + or (abstand_fuer_kreis_start_y_round == pos1_1_round) + or (abstand_gegen_kreis_start_y_round == pos1_0_round) + or (abstand_gegen_kreis_start_y_round == pos1_1_round) + or (abstand_fuer_kreis_ende_y_round == pos1_0_round) + or (abstand_fuer_kreis_ende_y_round == pos1_1_round) + or (abstand_gegen_kreis_ende_y_round == pos1_0_round) + or (abstand_gegen_kreis_ende_y_round == pos1_1_round) + ): + kreisel_verbunden = kreisel_verbunden + 1 + am_kreisel = 2 + return am_kreisel, kreisel_verbunden diff --git a/lib/block_methoden.py b/lib/block_methoden.py index 866c392..67f0799 100644 --- a/lib/block_methoden.py +++ b/lib/block_methoden.py @@ -3,22 +3,32 @@ import plant2dxf from ezdxf import units from ezdxf.entities import Line from ezdxf.addons import importer -from ezdxf.math import Matrix44, X_AXIS,Y_AXIS,Z_AXIS -def dreh_block(block_name: str, to_doc,lib_doc, winkel) : - """Nimmt ein schon importierten Block und erstellt einen neuen der an der y_axis oder x_axis gedreht wird - """ - dreh_block_name = block_name +f"_{math.degrees(winkel)}" - layer, color = get_insert_color_layer(lib_doc,block_name) - if (dreh_block_name in to_doc.blocks): - return dreh_block_name - block_zwischen = to_doc.blocks.new(name=block_name + f"zwischenschrit_{winkel}", base_point=(0,0,0)) - block = to_doc.blocks.new(name=dreh_block_name, base_point=(0,0,0)) - if block_name == "200000146_ES-Element_90_rechts" or block_name =="400102632_ES-Element_90_links" or block_name =="200000241_AS-Element_90_rechts" or block_name =="200000217_AS-Element_90_links": +from ezdxf.math import Matrix44, X_AXIS, Y_AXIS, Z_AXIS + + +def dreh_block(block_name: str, to_doc, lib_doc, winkel): + """Nimmt ein schon importierten Block und erstellt einen neuen der an der y_axis oder x_axis gedreht wird""" + dreh_block_name = block_name + f"_{math.degrees(winkel)}" + layer, color = get_insert_color_layer(lib_doc, block_name) + if dreh_block_name in to_doc.blocks: + return dreh_block_name + block_zwischen = to_doc.blocks.new( + name=block_name + f"zwischenschrit_{winkel}", base_point=(0, 0, 0) + ) + block = to_doc.blocks.new(name=dreh_block_name, base_point=(0, 0, 0)) + if ( + block_name == "200000146_ES-Element_90_rechts" + or block_name == "400102632_ES-Element_90_links" + or block_name == "200000241_AS-Element_90_rechts" + or block_name == "200000217_AS-Element_90_links" + ): rotation_matrix = Matrix44.axis_rotate(X_AXIS, winkel) - else: + else: rotation_matrix = Matrix44.axis_rotate(Y_AXIS, winkel) - block_zwischen.add_blockref(block_name,(0,0,0),dxfattribs={"layer":layer,"color": color}) + block_zwischen.add_blockref( + block_name, (0, 0, 0), dxfattribs={"layer": layer, "color": color} + ) for e in block_zwischen: copy = e.copy() copy.transform(rotation_matrix) @@ -26,7 +36,7 @@ def dreh_block(block_name: str, to_doc,lib_doc, winkel) : return dreh_block_name -def import_block(block_name: str, from_doc, to_doc, winkel = None) -> None: +def import_block(block_name: str, from_doc, to_doc, winkel=None) -> None: """Importiert Blockdefinition block_name von from_doc nach to_doc. - Kopiert alle Entities des Blocks @@ -41,16 +51,16 @@ def import_block(block_name: str, from_doc, to_doc, winkel = None) -> None: # Alle Linientypen importieren imp.import_table("linetypes") - if ((block_name in to_doc.blocks)): + if block_name in to_doc.blocks: # speichern der attdef elemente in eine Liste falks diese verhanden sind und gibt diese zurück for ent in src: copy = ent.copy() if ent.dxftype() == "ATTDEF": - att_def[ent.dxf.tag] =ent.dxf.text + att_def[ent.dxf.tag] = ent.dxf.text if ent.dxftype() == "INSERT": - import_block(ent.dxf.name,from_doc, to_doc,None) + import_block(ent.dxf.name, from_doc, to_doc, None) if att_def != {}: return att_def @@ -87,21 +97,22 @@ def import_block(block_name: str, from_doc, to_doc, winkel = None) -> None: except Exception: pass # kopiert die elemente von dem element aus dem block und speichert diese in den block für dass Modelspace auf und # speichern der attdef elemente in eine Liste falks diese verhanden sind und gibt diese zurück - + for ent in src: copy = ent.copy() if ent.dxftype() == "ATTDEF": - att_def[ent.dxf.tag] =ent.dxf.text + att_def[ent.dxf.tag] = ent.dxf.text if ent.dxftype() == "INSERT": - import_block(ent.dxf.name,from_doc, to_doc,None) + import_block(ent.dxf.name, from_doc, to_doc, None) tgt.add_entity(copy) - + if att_def != {}: return att_def - + + def get_insert_color_layer(lib_doc, blockname): - """Gibt den Layer und die Color für den Jeweiligen block in der Libary datei zurück""" + """Gibt den Layer und die Color für den Jeweiligen block in der Libary datei zurück""" msp_lib = lib_doc.modelspace() color = 0 layer = 0 @@ -111,34 +122,65 @@ def get_insert_color_layer(lib_doc, blockname): layer = insert.dxf.layer return layer, color -def rotatate_and_left_motor_umlenk(doc, lib_doc,config): - motor_rotation = float(config.get("Ils 2.0 core winkel","winkel_motor")) - umlenk_rotation = float(config.get("Ils 2.0 core winkel","winkel_umlenk")) - block_Vario_Umlenkstation_500mm ="Vario_Umlenkstation_500mm" + +def rotatate_and_left_motor_umlenk(doc, lib_doc, config): + motor_rotation = float(config.get("Ils 2.0 core winkel", "winkel_motor")) + umlenk_rotation = float(config.get("Ils 2.0 core winkel", "winkel_umlenk")) + block_Vario_Umlenkstation_500mm = "Vario_Umlenkstation_500mm" block_Vario_Motorstation_500mm = "Vario_Motorstation_500mm" - blockname_motor_links = block_Vario_Motorstation_500mm +"_links" + blockname_motor_links = block_Vario_Motorstation_500mm + "_links" blockname_umlenk_links = block_Vario_Umlenkstation_500mm + "_links" - import_block(block_Vario_Umlenkstation_500mm,lib_doc,doc) - import_block(block_Vario_Motorstation_500mm,lib_doc,doc) - turn_two_blocks_left(doc, block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links) + import_block(block_Vario_Umlenkstation_500mm, lib_doc, doc) + import_block(block_Vario_Motorstation_500mm, lib_doc, doc) + turn_two_blocks_left( + doc, + block_Vario_Umlenkstation_500mm, + block_Vario_Motorstation_500mm, + blockname_motor_links, + blockname_umlenk_links, + ) - block_Vario_Umlenkstation_500mm =dreh_block(block_Vario_Umlenkstation_500mm,doc,lib_doc,math.radians(umlenk_rotation)) - block_Vario_Motorstation_500mm =dreh_block(block_Vario_Motorstation_500mm,doc,lib_doc,math.radians(motor_rotation)) - blockname_motor_links =dreh_block(blockname_motor_links,doc,lib_doc,math.radians(umlenk_rotation)) - blockname_umlenk_links =dreh_block(blockname_umlenk_links,doc,lib_doc,math.radians(motor_rotation)) - return block_Vario_Umlenkstation_500mm,block_Vario_Motorstation_500mm,blockname_motor_links,blockname_umlenk_links + block_Vario_Umlenkstation_500mm = dreh_block( + block_Vario_Umlenkstation_500mm, doc, lib_doc, math.radians(umlenk_rotation) + ) + block_Vario_Motorstation_500mm = dreh_block( + block_Vario_Motorstation_500mm, doc, lib_doc, math.radians(motor_rotation) + ) + blockname_motor_links = dreh_block( + blockname_motor_links, doc, lib_doc, math.radians(umlenk_rotation) + ) + blockname_umlenk_links = dreh_block( + blockname_umlenk_links, doc, lib_doc, math.radians(motor_rotation) + ) + return ( + block_Vario_Umlenkstation_500mm, + block_Vario_Motorstation_500mm, + blockname_motor_links, + blockname_umlenk_links, + ) -def turn_two_blocks_left(doc, block_1_name_zwischen, block_2_name_zwischen, block_2_left_name, block_1_left_name): + +def turn_two_blocks_left( + doc, + block_1_name_zwischen, + block_2_name_zwischen, + block_2_left_name, + block_1_left_name, +): blockname1 = block_1_name_zwischen blockname2 = block_2_name_zwischen if block_2_left_name not in doc.blocks: - matrix = Matrix44.scale(1,-1,1) - block1_zwischen = doc.blocks.new(name=block_1_name_zwischen + "zwischenschrit", base_point=(0,0,0)) - block2_zwischen = doc.blocks.new(name=block_2_name_zwischen + "zwischenschrit", base_point=(0,0,0)) - block_2 = doc.blocks.new(name=block_2_left_name,base_point=(0,0,0)) - block_1_left_name = doc.blocks.new(name=block_1_left_name,base_point=(0,0,0)) - block1_zwischen.add_blockref(blockname1,(0,0,0)) - block2_zwischen.add_blockref(blockname2,(0,0,0)) + matrix = Matrix44.scale(1, -1, 1) + block1_zwischen = doc.blocks.new( + name=block_1_name_zwischen + "zwischenschrit", base_point=(0, 0, 0) + ) + block2_zwischen = doc.blocks.new( + name=block_2_name_zwischen + "zwischenschrit", base_point=(0, 0, 0) + ) + block_2 = doc.blocks.new(name=block_2_left_name, base_point=(0, 0, 0)) + block_1_left_name = doc.blocks.new(name=block_1_left_name, base_point=(0, 0, 0)) + block1_zwischen.add_blockref(blockname1, (0, 0, 0)) + block2_zwischen.add_blockref(blockname2, (0, 0, 0)) for e in block2_zwischen: copy = e.copy() copy.transform(matrix) @@ -149,11 +191,11 @@ def turn_two_blocks_left(doc, block_1_name_zwischen, block_2_name_zwischen, bloc copy.transform(matrix) block_1_left_name.add_entity(copy) + def add_attributes_to_block(block, attributes): - """ Fügt einem bestehenden ezdxf-Block Attribut-Definitionen hinzu. - + Parameter: block – ein ezdxf.blocks.BlockLayout Objekt attributes – Liste von Tupeln [(tag, value), ...] @@ -161,8 +203,8 @@ def add_attributes_to_block(block, attributes): for tag, value in attributes.items(): tag = tag value = value - a =block.add_attrib( + a = block.add_attrib( tag=tag, text=value, ) - a.is_invisible = True \ No newline at end of file + a.is_invisible = True diff --git a/lib/dxf2lib.py b/lib/dxf2lib.py index 0ab251a..8b107f6 100644 --- a/lib/dxf2lib.py +++ b/lib/dxf2lib.py @@ -4,27 +4,27 @@ from ezdxf.math import Matrix44, Vec3, BoundingBox, Vec2 import math import argparse import sys -import shutil import configparser from utils import check_environment_var, setup_logger from pathlib import Path import logging + def create_block_library(input_dir, output_file, config, logger=None): """ Erstellt eine DXF-Block-Bibliothek aus einzelnen DXF-Dateien. - + Diese Funktion liest alle DXF-Dateien aus einem Verzeichnis und erstellt daraus eine Bibliothek mit Blöcken. Die Blöcke werden in einem Raster angeordnet und mit Beschriftungen versehen. Fehlerhafte Dateien werden protokolliert. - + Args: input_dir (str): Verzeichnis mit den zu verarbeitenden DXF-Dateien output_file (str): Pfad zur zu erstellenden Bibliotheks-DXF-Datei config: ConfigParser-Objekt mit den Konfigurationswerten logger: Optionaler Logger für Logging-Ausgaben - + Note: - Unterstützte Entity-Typen: LINE, LWPOLYLINE, POLYLINE, SPLINE, CIRCLE, ARC, INSERT, TEXT, MTEXT, REGION, … - Blöcke werden zentriert und in einem 20x20 Raster angeordnet @@ -37,12 +37,12 @@ def create_block_library(input_dir, output_file, config, logger=None): x_offset = 0 y_offset = 0 blocks_in_row = 0 - + error_files = [] processed_files = [] max_blockspacing_x = 0 max_blockspacing_y = 0 - + for filename in os.listdir(input_dir): if not filename.lower().endswith(".dxf"): @@ -79,22 +79,21 @@ def create_block_library(input_dir, output_file, config, logger=None): "REGION", } filtered_entities = [] - att_def= {} + att_def = {} for insert in src_msp.query("INSERT"): for attrib in insert.attribs: att_def[attrib.dxf.tag] = attrib.dxf.text - for e in entities: - if e.dxftype() in allowed_types: + if e.dxftype() in allowed_types: filtered_entities.append(e) else: - logger.info(f"{e.dxftype()} is nicht in der erlaubten Liste. Diese befindet sich in {filename}") - - + logger.info( + f"{e.dxftype()} is nicht in der erlaubten Liste. Diese befindet sich in {filename}" + ) + entities = filtered_entities - - + except Exception as e: error_msg = f"Fehler beim Lesen von {filename}: {e}" if logger: @@ -106,7 +105,9 @@ def create_block_library(input_dir, output_file, config, logger=None): # Sicherstellen, dass die im Quell-DXF verwendeten Layer im Zieldokument existieren try: - used_layer_names = {e.dxf.layer for e in entities if hasattr(e.dxf, "layer")} + used_layer_names = { + e.dxf.layer for e in entities if hasattr(e.dxf, "layer") + } for layer_name in used_layer_names: if layer_name and layer_name not in doc.layers: try: @@ -122,8 +123,10 @@ def create_block_library(input_dir, output_file, config, logger=None): doc.layers.add(name=layer_name) except Exception: pass - - boundingbox, ausdehnung, center = calculate_block_bounding_box(filtered_entities, doc,src_doc, filename,config) + + boundingbox, ausdehnung, center = calculate_block_bounding_box( + filtered_entities, doc, src_doc, filename, config + ) if center is None: error_msg = f"Keine gültige Geometrie in {filename}" if logger: @@ -136,7 +139,7 @@ def create_block_library(input_dir, output_file, config, logger=None): if name in doc.blocks: doc.blocks.delete_block(name) - blk = doc.blocks.new(name=name, base_point=(0,0)) + blk = doc.blocks.new(name=name, base_point=(0, 0)) for e in entities: cp = copy_entity(logger, error_files, filename, e, center) @@ -146,11 +149,10 @@ def create_block_library(input_dir, output_file, config, logger=None): # Platzierung in Reihen und Spalten # Attribut-Definition (ATTDEF) hinzufügen - - # Blockreferenz-Layer bestimmen + # Blockreferenz-Layer bestimmen blockref_layer = None try: - #Konfiguration erlaubt expliziten Layernamen + # Konfiguration erlaubt expliziten Layernamen cfg_layer = None try: cfg_layer = config.get("dxf2lib", "blockref_layer") @@ -186,42 +188,59 @@ def create_block_library(input_dir, output_file, config, logger=None): blockref_layer = None section = "dxf2lib" text_height = get_cfg_value(section, "text_height", DEFAULTS["text_height"]) - extra_block_space_x = get_cfg_value(section, "extra_block_space_x", DEFAULTS["extra_block_space_x"]) - blocks_per_row = get_cfg_value(section, "blocks_per_row", DEFAULTS["blocks_per_row"]) - extra_text_space_y = get_cfg_value(section, "extra_text_space_y", DEFAULTS["extra_text_space_y"]) + extra_block_space_x = get_cfg_value( + section, "extra_block_space_x", DEFAULTS["extra_block_space_x"] + ) + blocks_per_row = get_cfg_value( + section, "blocks_per_row", DEFAULTS["blocks_per_row"] + ) + extra_text_space_y = get_cfg_value( + section, "extra_text_space_y", DEFAULTS["extra_text_space_y"] + ) ausdehnung_x, ausdehung_y = ausdehnung[0], ausdehnung[1] - + block_spacing_y = ausdehung_y + 400 block_spacing_x = ausdehnung_x + extra_block_space_x - max_blockspacing_x = max(max_blockspacing_x, block_spacing_x) - max_blockspacing_y = max(max_blockspacing_y, block_spacing_y) - x_offset += max_blockspacing_x + max_blockspacing_x = max(max_blockspacing_x, block_spacing_x) + max_blockspacing_y = max(max_blockspacing_y, block_spacing_y) + x_offset += max_blockspacing_x # Blockreferenz mit optionalem Layer einfügen (Entity-Layer bleiben erhalten) if blockref_layer: - test =msp.add_blockref(name, insert=(x_offset, y_offset), dxfattribs={"layer": blockref_layer}) + test = msp.add_blockref( + name, insert=(x_offset, y_offset), dxfattribs={"layer": blockref_layer} + ) else: - test =msp.add_blockref(name, insert=(x_offset, y_offset)) + test = msp.add_blockref(name, insert=(x_offset, y_offset)) # Text mit Blocknamen über dem Block if name == "a" or name == "b": for tag, value in att_def.items(): tag = tag value = value - a =test.add_attrib( + a = test.add_attrib( tag=tag, text=value, ) a.is_invisible = True # Werte aus Config holen (Block: [dxf2lib]) - - msp.add_text(name, dxfattribs={'height': text_height, 'insert': (x_offset -ausdehnung_x/2 , y_offset + ausdehung_y/2 + extra_text_space_y)}) + + msp.add_text( + name, + dxfattribs={ + "height": text_height, + "insert": ( + x_offset - ausdehnung_x / 2, + y_offset + ausdehung_y / 2 + extra_text_space_y, + ), + }, + ) processed_files.append(filename) blocks_in_row += 1 - # Abstand zwischen Blöcken in einer Reihe + # Abstand zwischen Blöcken in einer Reihe if blocks_in_row == blocks_per_row: - + blocks_in_row = 0 x_offset = 0 y_offset -= max_blockspacing_y # Neue Zeile, nach unten versetzt @@ -232,9 +251,11 @@ def create_block_library(input_dir, output_file, config, logger=None): logger.info(f"Bibliotheks-DXF gespeichert: {output_file}") logger.info(f"Verarbeitete Dateien: {len(processed_files)}") logger.info(f"Fehlerhafte Dateien: {len(error_files)}") - + if error_files: - logger.warning(f"{len(error_files)} Dateien konnten nicht verarbeitet werden:") + logger.warning( + f"{len(error_files)} Dateien konnten nicht verarbeitet werden:" + ) for filename, error_msg in error_files: logger.error(f"{filename}: {error_msg}") else: @@ -243,9 +264,11 @@ def create_block_library(input_dir, output_file, config, logger=None): print(f"Bibliotheks-DXF gespeichert: {output_file}") print(f"Verarbeitete Dateien: {len(processed_files)}") print(f"Fehlerhafte Dateien: {len(error_files)}") - + if error_files: - print(f"Warnung: {len(error_files)} Dateien konnten nicht verarbeitet werden.") + print( + f"Warnung: {len(error_files)} Dateien konnten nicht verarbeitet werden." + ) output_dir = output_file.parent if not output_dir.exists(): @@ -267,24 +290,26 @@ def copy_entity(logger, error_files, filename, e, center): return cp except Exception as err: - error_msg = f"Fehler beim Verarbeiten von Entity {e.dxftype()} in {filename}: {err}" + error_msg = ( + f"Fehler beim Verarbeiten von Entity {e.dxftype()} in {filename}: {err}" + ) if logger: logger.error(error_msg) else: print(error_msg) error_files.append((filename, error_msg)) return None - # Standardwerte (falls nicht in der Config) DEFAULTS = { - "text_height": 20, # Schriftgröße des Texts (in DXF-Einheiten) - "blocks_per_row": 20, # Anzahl Blöcke pro Zeile im Raster - "extra_block_space_x" : 50, # Extra Platz damit sich Blöcke nicht überlappen - "extra_text_space_y" : 50 # Abstand der Überschrift über dem Symbol - + "text_height": 20, # Schriftgröße des Texts (in DXF-Einheiten) + "blocks_per_row": 20, # Anzahl Blöcke pro Zeile im Raster + "extra_block_space_x": 50, # Extra Platz damit sich Blöcke nicht überlappen + "extra_text_space_y": 50, # Abstand der Überschrift über dem Symbol } + + def get_cfg_value(section, key, fallback): try: return int(config.get(section, key)) @@ -292,9 +317,9 @@ def get_cfg_value(section, key, fallback): return fallback - - -def convert_dxf_to_block_with_inserts(input_filename, output_filename, block_name="CONVERTED_BLOCK"): +def convert_dxf_to_block_with_inserts( + input_filename, output_filename, block_name="CONVERTED_BLOCK" +): """ Konvertiert alle Entities einer DXF-Datei in einen neuen Block INSERTs werden als Referenzen beibehalten (nicht explodiert) @@ -303,57 +328,57 @@ def convert_dxf_to_block_with_inserts(input_filename, output_filename, block_nam # Eingabe-DXF laden input_doc = ezdxf.readfile(input_filename) print(f"Lade DXF-Datei: {input_filename}") - + # Neue Ausgabe-DXF erstellen - output_doc = ezdxf.new('R2010') - output_doc.header['$INSUNITS'] = 4 # Millimeter - + output_doc = ezdxf.new("R2010") + output_doc.header["$INSUNITS"] = 4 # Millimeter + # Zuerst alle Block-Definitionen kopieren copied_blocks = copy_block_definitions(input_doc, output_doc) print(f"Block-Definitionen kopiert: {len(copied_blocks)}") - + # Neuen Hauptblock erstellen new_block = output_doc.blocks.new(name=block_name) print(f"Erstelle neuen Block: {block_name}") - + # Alle Entities aus dem Modelspace kopieren msp = input_doc.modelspace() entity_count = 0 insert_count = 0 - + for entity in msp: - if entity.dxftype() == 'INSERT': + if entity.dxftype() == "INSERT": # INSERT direkt kopieren (nicht explodieren) copy_entity_to_block(entity, new_block) insert_count += 1 else: # Normale Entity kopieren copy_entity_to_block(entity, new_block) - + entity_count += 1 - + # Bounding Box berechnen bbox = calculate_block_bounding_box(new_block, output_doc) - + # Block im Modelspace der neuen Datei platzieren output_msp = output_doc.modelspace() output_msp.add_blockref(block_name, insert=(0, 0)) - + # Bounding Box als Hilfslinien hinzufügen (optional) if bbox.has_data: add_bounding_box_to_modelspace(output_msp, bbox) - + # Speichern output_doc.saveas(output_filename) - + print(f"Konvertierung abgeschlossen:") print(f" - {entity_count} Entities übertragen") print(f" - {insert_count} INSERTs als Referenzen beibehalten") print(f" - Bounding Box: {format_bounding_box(bbox)}") print(f" - Ausgabe: {output_filename}") - + return bbox - + except FileNotFoundError: print(f"Fehler: Datei {input_filename} nicht gefunden") return None @@ -370,48 +395,53 @@ def copy_block_definitions(source_doc, target_doc): Kopiert alle Block-Definitionen vom Quell- zum Ziel-Dokument """ copied_blocks = [] - + for block_name in source_doc.blocks: # Standard-Blöcke (MODEL_SPACE, PAPER_SPACE) überspringen - if block_name.startswith('*'): + if block_name.startswith("*"): continue - + source_block = source_doc.blocks[block_name] - + # Prüfen ob Block bereits existiert if block_name in target_doc.blocks: print(f"Warnung: Block '{block_name}' existiert bereits, wird übersprungen") continue - + # Neuen Block in Ziel-Dokument erstellen target_block = target_doc.blocks.new(name=block_name) - + # Alle Entities des Quell-Blocks kopieren for entity in source_block: copy_entity_to_block(entity, target_block) - + copied_blocks.append(block_name) - + return copied_blocks -def calculate_block_bounding_box(block, doc, src_doc, filename,config): +def calculate_block_bounding_box(block, doc, src_doc, filename, config): """ Berechnet die Bounding Box eines Blocks inklusive aller INSERTs """ - + bbox = BoundingBox() - + for entity in block: - entity_bbox = get_entity_bounding_box(entity, doc,src_doc,filename,config) + entity_bbox = get_entity_bounding_box(entity, doc, src_doc, filename, config) if entity_bbox and entity_bbox.has_data: bbox.extend(entity_bbox) - - - return bbox, (bbox.extmax.x - bbox.extmin.x, bbox.extmax.y - bbox.extmin.y), bbox.center + + return ( + bbox, + (bbox.extmax.x - bbox.extmin.x, bbox.extmax.y - bbox.extmin.y), + bbox.center, + ) -def _bbox_from_virtual_entities(entity, doc, src_doc, filename, config, transform_matrix=None): +def _bbox_from_virtual_entities( + entity, doc, src_doc, filename, config, transform_matrix=None +): """ Nutzt virtual_entities(), um komplexe Objekte (z.B. SURFACE) in auswertbare Geometrie zu zerlegen und darauf eine Bounding Box zu @@ -432,15 +462,15 @@ def _bbox_from_virtual_entities(entity, doc, src_doc, filename, config, transfor return v_bbox -def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=None): +def get_entity_bounding_box(e, doc, src_doc, filename, config, transform_matrix=None): """ Berechnet die Bounding Box einer einzelnen Entity Berücksichtigt INSERTs mit ihren Block-Inhalten """ - bbox = BoundingBox() + bbox = BoundingBox() try: - if e.dxftype() == 'LINE': + if e.dxftype() == "LINE": start = Vec3(e.dxf.start) end = Vec3(e.dxf.end) if transform_matrix: @@ -448,8 +478,8 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non end = transform_matrix.transform(end) bbox.extend([start]) bbox.extend([end]) - - elif e.dxftype() == 'CIRCLE': + + elif e.dxftype() == "CIRCLE": # Kreis durch Punktabtastung (robust bei Transformationen) center = Vec3(e.dxf.center) radius = float(e.dxf.radius) @@ -464,8 +494,8 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non points.append(p) if points: bbox.extend(points) - - elif e.dxftype() == 'ARC': + + elif e.dxftype() == "ARC": # Bogen durch Punktabtastung zwischen Start- und Endwinkel center = Vec3(e.dxf.center) radius = float(e.dxf.radius) @@ -495,16 +525,16 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non points.append(p) if points: bbox.extend(points) - - elif e.dxftype() == 'LWPOLYLINE': + + elif e.dxftype() == "LWPOLYLINE": # Nutze virtuelle Entities (Linien/Bögen), inkl. Bulge-Unterstützung ve_bbox = _bbox_from_virtual_entities( e, doc, src_doc, filename, config, transform_matrix ) if ve_bbox.has_data: bbox.extend(ve_bbox) - - elif e.dxftype() == 'POLYLINE': + + elif e.dxftype() == "POLYLINE": # 2D/3D Polylines ebenfalls über virtuelle Entities ve_bbox = _bbox_from_virtual_entities( e, doc, src_doc, filename, config, transform_matrix @@ -512,7 +542,7 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non if ve_bbox.has_data: bbox.extend(ve_bbox) - elif e.dxftype() == '3DFACE': + elif e.dxftype() == "3DFACE": # 3DFace: direkte Eckpunkte verwenden pts = [] try: @@ -527,15 +557,15 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non if pts: bbox.extend(pts) - elif e.dxftype() in {'MESH', 'POLYFACE', 'POLYFACEMESH'}: + elif e.dxftype() in {"MESH", "POLYFACE", "POLYFACEMESH"}: # Mesh/Polyface über virtuelle Geometrie auswerten ve_bbox = _bbox_from_virtual_entities( e, doc, src_doc, filename, config, transform_matrix ) if ve_bbox.has_data: bbox.extend(ve_bbox) - - elif e.dxftype() == 'SPLINE': + + elif e.dxftype() == "SPLINE": # Approximation der Spline-Kurve try: pts = list(e.approximate(60)) @@ -556,19 +586,21 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non sampled.append(v) if sampled: bbox.extend(sampled) - - elif e.dxftype() == 'ATTDEF': - + + elif e.dxftype() == "ATTDEF": + insert_point = Vec3(e.dxf.insert) if transform_matrix: insert_point = transform_matrix.transform(insert_point) - elif e.dxftype() == 'TEXT': + elif e.dxftype() == "TEXT": insert_point = Vec3(e.dxf.insert) height = float(getattr(e.dxf, "height", 1.0)) width_factor = float(getattr(e.dxf, "width", 1.0)) rotation = math.radians(getattr(e.dxf, "rotation", 0.0)) text_content = getattr(e.dxf, "text", "") or "" - est_width = max(len(text_content) * height * 0.6 * width_factor, height * 0.5) + est_width = max( + len(text_content) * height * 0.6 * width_factor, height * 0.5 + ) corners = [ insert_point, insert_point + Vec3(est_width, 0, 0), @@ -590,7 +622,7 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non pt = transform_matrix.transform(pt) bbox.extend([pt]) - elif e.dxftype() == 'MTEXT': + elif e.dxftype() == "MTEXT": insert_point = Vec3(e.dxf.insert) char_height = float(getattr(e.dxf, "char_height", 1.0)) width = float(getattr(e.dxf, "width", 0.0)) @@ -610,86 +642,99 @@ def get_entity_bounding_box(e, doc,src_doc,filename,config, transform_matrix=Non pt = transform_matrix.transform(pt) bbox.extend([pt]) - elif e.dxftype() == 'REGION': + elif e.dxftype() == "REGION": # Region: Begrenzungsgeometrie über virtual_entities() ve_bbox = _bbox_from_virtual_entities( e, doc, src_doc, filename, config, transform_matrix ) if ve_bbox.has_data: bbox.extend(ve_bbox) - - elif e.dxftype().endswith('SURFACE'): + + elif e.dxftype().endswith("SURFACE"): # Viele Surface-Typen liefern ihre Proxy-Geometrie über virtual_entities() ve_bbox = _bbox_from_virtual_entities( e, doc, src_doc, filename, config, transform_matrix ) if ve_bbox.has_data: bbox.extend(ve_bbox) - - elif e.dxftype() == 'INSERT': + + elif e.dxftype() == "INSERT": # INSERT: Block-Inhalt mit Transformation berücksichtigen - insert_bbox = calculate_insert_bounding_box(e, doc,src_doc,filename,config, transform_matrix) - if insert_bbox and insert_bbox.has_data and e.dxf.layer not in config.get("dxf2lib","automation_layer"): + insert_bbox = calculate_insert_bounding_box( + e, doc, src_doc, filename, config, transform_matrix + ) + if ( + insert_bbox + and insert_bbox.has_data + and e.dxf.layer not in config.get("dxf2lib", "automation_layer") + ): bbox.extend(insert_bbox) - + except Exception as e: print(f"Fehler bei Bounding Box Berechnung für {e.dxftype()}: {e}") - - + return bbox -def extract_scaling(matrix): - sx = math.sqrt(matrix[0, 0]**2 + matrix[0, 1]**2 + matrix[0, 2]**2) - sy = math.sqrt(matrix[1, 0]**2 + matrix[1, 1]**2 + matrix[1, 2]**2) - return sx, sy, -def calculate_insert_bounding_box(insert_entity, doc,src_doc,filename,config,parent_transform=None): +def extract_scaling(matrix): + sx = math.sqrt(matrix[0, 0] ** 2 + matrix[0, 1] ** 2 + matrix[0, 2] ** 2) + sy = math.sqrt(matrix[1, 0] ** 2 + matrix[1, 1] ** 2 + matrix[1, 2] ** 2) + return ( + sx, + sy, + ) + + +def calculate_insert_bounding_box( + insert_entity, doc, src_doc, filename, config, parent_transform=None +): """ Berechnet die Bounding Box eines INSERTs inklusive Block-Inhalt """ - + try: - # Block-Definition finden + # Block-Definition finden block_name = insert_entity.dxf.name src_blk = src_doc.blocks[block_name] - + if block_name in doc.blocks: dst_blk = doc.blocks[block_name] new_insert = False - + else: dst_blk = doc.blocks.new(name=block_name) new_insert = True if block_name not in src_doc.blocks: print(f"Warnung: Block '{block_name}' ") return BoundingBox() - + block_def = src_blk - # Transformation der INSERT-Entity berechnen insert_transform = get_insert_transform_matrix(insert_entity) - + # Mit übergeordneter Transformation kombinieren if parent_transform: combined_transform = parent_transform * insert_transform else: combined_transform = insert_transform - + # Bounding Box aller Entities im Block berechnen block_bbox = BoundingBox() - + for block_entity in block_def: - - entity_bbox= get_entity_bounding_box(block_entity, doc,src_doc,filename, config,combined_transform) - if entity_bbox and entity_bbox.has_data: - if new_insert: - dst_blk.add_entity(block_entity.copy()) - block_bbox.extend(entity_bbox) + + entity_bbox = get_entity_bounding_box( + block_entity, doc, src_doc, filename, config, combined_transform + ) + if entity_bbox and entity_bbox.has_data: + if new_insert: + dst_blk.add_entity(block_entity.copy()) + block_bbox.extend(entity_bbox) return block_bbox - + except Exception as e: print(f"Fehler bei INSERT Bounding Box: {e},{filename}") return BoundingBox() @@ -701,22 +746,22 @@ def get_insert_transform_matrix(insert_entity): """ # Position insert_point = Vec3(insert_entity.dxf.insert) - + # Skalierung - xscale = getattr(insert_entity.dxf, 'xscale', 1.0) - yscale = getattr(insert_entity.dxf, 'yscale', 1.0) - zscale = getattr(insert_entity.dxf, 'zscale', 1.0) - + xscale = getattr(insert_entity.dxf, "xscale", 1.0) + yscale = getattr(insert_entity.dxf, "yscale", 1.0) + zscale = getattr(insert_entity.dxf, "zscale", 1.0) + # Rotation (in Radiant umwandeln) - rotation = math.radians(getattr(insert_entity.dxf, 'rotation', 0.0)) - + rotation = math.radians(getattr(insert_entity.dxf, "rotation", 0.0)) + # Transformationsmatrix erstellen matrix = Matrix44.chain( Matrix44.scale(xscale, yscale, zscale), Matrix44.z_rotate(rotation), - Matrix44.translate(insert_point.x, insert_point.y, insert_point.z) + Matrix44.translate(insert_point.x, insert_point.y, insert_point.z), ) - + return matrix @@ -728,7 +773,7 @@ def copy_entity_to_block(entity, target_block): # Entity kopieren und zum Block hinzufügen entity_copy = entity.copy() target_block.add_entity(entity_copy) - + except Exception as e: print(f"Fehler beim Kopieren von {entity.dxftype()}: {e}") @@ -741,13 +786,13 @@ def add_bounding_box_to_modelspace(msp, bbox, centered=False): """ if not bbox.has_data: return - + # Bounding Box Rechteck zeichnen min_pt = bbox.extmin max_pt = bbox.extmax width = max_pt.x - min_pt.x height = max_pt.y - min_pt.y - + if centered: # Rechteck um (0,0) zentriert left = -width / 2.0 @@ -759,11 +804,14 @@ def add_bounding_box_to_modelspace(msp, bbox, centered=False): (right, bottom), (right, top), (left, top), - (left, bottom) + (left, bottom), ] # Roter Punkt in der Mitte - msp.add_circle(center=(0.0, 0.0), radius=max(0.5, min(width, height) * 0.01), - dxfattribs={"layer": "BOUNDING_BOX", "color": 1}) + msp.add_circle( + center=(0.0, 0.0), + radius=max(0.5, min(width, height) * 0.01), + dxfattribs={"layer": "BOUNDING_BOX", "color": 1}, + ) else: # Ursprüngliche, nicht-zentrierte Bounding Box bbox_points = [ @@ -771,21 +819,31 @@ def add_bounding_box_to_modelspace(msp, bbox, centered=False): (max_pt.x, min_pt.y), (max_pt.x, max_pt.y), (min_pt.x, max_pt.y), - (min_pt.x, min_pt.y) + (min_pt.x, min_pt.y), ] - + bbox_poly = msp.add_lwpolyline(bbox_points) bbox_poly.dxf.layer = "BOUNDING_BOX" bbox_poly.dxf.color = 1 # Rot - + # Text mit Abmessungen - text_pos = Vec3(bbox_points[0][0], (bbox_points[2][1] if centered else max_pt.y) + 5, 0) - msp.add_text(f"Breite: {width:.2f} mm", height=3, - dxfattribs={'insert': text_pos, 'layer': "BOUNDING_BOX", 'color': 1}) - - text_pos2 = Vec3(bbox_points[0][0], (bbox_points[2][1] if centered else max_pt.y) + 10, 0) - msp.add_text(f"Höhe: {height:.2f} mm", height=3, - dxfattribs={'insert': text_pos2, 'layer': "BOUNDING_BOX", 'color': 1}) + text_pos = Vec3( + bbox_points[0][0], (bbox_points[2][1] if centered else max_pt.y) + 5, 0 + ) + msp.add_text( + f"Breite: {width:.2f} mm", + height=3, + dxfattribs={"insert": text_pos, "layer": "BOUNDING_BOX", "color": 1}, + ) + + text_pos2 = Vec3( + bbox_points[0][0], (bbox_points[2][1] if centered else max_pt.y) + 10, 0 + ) + msp.add_text( + f"Höhe: {height:.2f} mm", + height=3, + dxfattribs={"insert": text_pos2, "layer": "BOUNDING_BOX", "color": 1}, + ) def format_bounding_box(bbox): @@ -794,16 +852,18 @@ def format_bounding_box(bbox): """ if not bbox.has_data: return "Keine gültigen Geometriedaten gefunden" - + min_pt = bbox.extmin max_pt = bbox.extmax width = max_pt.x - min_pt.x height = max_pt.y - min_pt.y depth = max_pt.z - min_pt.z - - return (f"Min: ({min_pt.x:.2f}, {min_pt.y:.2f}, {min_pt.z:.2f}) " - f"Max: ({max_pt.x:.2f}, {max_pt.y:.2f}, {max_pt.z:.2f}) " - f"Größe: {width:.2f} × {height:.2f} × {depth:.2f} mm") + + return ( + f"Min: ({min_pt.x:.2f}, {min_pt.y:.2f}, {min_pt.z:.2f}) " + f"Max: ({max_pt.x:.2f}, {max_pt.y:.2f}, {max_pt.z:.2f}) " + f"Größe: {width:.2f} × {height:.2f} × {depth:.2f} mm" + ) def analyze_source_dxf_with_blocks(filename): @@ -813,76 +873,88 @@ def analyze_source_dxf_with_blocks(filename): try: doc = ezdxf.readfile(filename) msp = doc.modelspace() - + entity_types = {} layer_count = {} insert_blocks = {} block_definitions = {} - + # Modelspace analysieren for entity in msp: entity_type = entity.dxftype() entity_types[entity_type] = entity_types.get(entity_type, 0) + 1 - - layer = getattr(entity.dxf, 'layer', '0') + + layer = getattr(entity.dxf, "layer", "0") layer_count[layer] = layer_count.get(layer, 0) + 1 - - if entity_type == 'INSERT': + + if entity_type == "INSERT": block_name = entity.dxf.name insert_blocks[block_name] = insert_blocks.get(block_name, 0) + 1 - + # Block-Definitionen analysieren for block_name in doc.blocks: - if not block_name.startswith('*'): # Keine Standard-Blöcke + if not block_name.startswith("*"): # Keine Standard-Blöcke block_def = doc.blocks[block_name] entity_count = len(list(block_def)) block_definitions[block_name] = entity_count - + print(f"\nAnalyse von {filename}:") print("=" * 50) print("Entity-Typen im Modelspace:") for etype, count in sorted(entity_types.items()): print(f" {etype}: {count}") - + print(f"\nLayer ({len(layer_count)}):") for layer, count in sorted(layer_count.items()): print(f" {layer}: {count} entities") - + if insert_blocks: print(f"\nINSERT-Verwendungen ({sum(insert_blocks.values())} total):") for block, count in sorted(insert_blocks.items()): print(f" {block}: {count}× verwendet") - + if block_definitions: print(f"\nBlock-Definitionen ({len(block_definitions)}):") for block, count in sorted(block_definitions.items()): print(f" {block}: {count} entities") - + return entity_types, layer_count, insert_blocks, block_definitions - + except Exception as e: print(f"Fehler bei der Analyse: {e}") return {}, {}, {}, {} + if __name__ == "__main__": # Argumentparser für Kommandozeilenoptionen parser = argparse.ArgumentParser(description="SVG/XML zu DXF Konverter") - parser.add_argument('-i', '--input', type=str, help='Input-Verzeichnis mit SVG/XML-Dateien') - parser.add_argument('-n', '--name', required=False, type=str, help='Name der zu erzeugenden Bibliothek (optional, wird sonst abgefragt)', default="test") - + parser.add_argument( + "-i", "--input", type=str, help="Input-Verzeichnis mit SVG/XML-Dateien" + ) + parser.add_argument( + "-n", + "--name", + required=False, + type=str, + help="Name der zu erzeugenden Bibliothek (optional, wird sonst abgefragt)", + default="test", + ) + if len(sys.argv) == 2 and sys.argv[1] in ("-h", "--help"): parser.print_help() sys.exit(0) - + args = parser.parse_args() if not args.name: - args.name = input("Bitte Namen der zu erzeugenden Bibliothek eingeben: ").strip() + args.name = input( + "Bitte Namen der zu erzeugenden Bibliothek eingeben: " + ).strip() if not args.name: print("Fehler: Kein Name angegeben. Beende.") sys.exit(1) - # Verzeichnisse über Umgebungsvariablen oder Fallback + # Verzeichnisse über Umgebungsvariablen oder Fallback if args.input: INPUT_DIR = Path(args.input) print(f"Verwende Input-Verzeichnis: {INPUT_DIR} \n") @@ -890,7 +962,9 @@ if __name__ == "__main__": INPUT_DIR = check_environment_var("PROJECT_DATA") / "omniflo" print(f"Kein Input-Verzeichnis angegeben, verwende Standard: {INPUT_DIR} \n") - OUTPUT_FILE = check_environment_var("PROJECT_DATA") / "block_libraries" / f"{args.name}.dxf" + OUTPUT_FILE = ( + check_environment_var("PROJECT_DATA") / "block_libraries" / f"{args.name}.dxf" + ) # Prüfe und erstelle log-Verzeichnis falls nötig log_dir = check_environment_var("PROJECT_LOG") @@ -899,9 +973,9 @@ if __name__ == "__main__": print(f"Log-Verzeichnis erstellt: {log_dir}") # Logger Setup - log_file = Path(os.environ['PROJECT_LOG']) / 'dxf2lib.log' - file_handler = logging.FileHandler(str(log_file), 'a', 'utf-8') - logger = setup_logger(log_dir, name='dxf2lib') + log_file = Path(os.environ["PROJECT_LOG"]) / "dxf2lib.log" + file_handler = logging.FileHandler(str(log_file), "a", "utf-8") + logger = setup_logger(log_dir, name="dxf2lib") logger.info("=== DXF2LIB Verarbeitung gestartet ===") logger.info(f"Input-Verzeichnis: {INPUT_DIR}") logger.info(f"Output-Datei: {OUTPUT_FILE}") diff --git a/lib/handler_context.py b/lib/handler_context.py new file mode 100644 index 0000000..3f6aa92 --- /dev/null +++ b/lib/handler_context.py @@ -0,0 +1,214 @@ +""" +Handler Context für DXF-Elementgenerierung. +Vereinfacht die Aufrufe der handle-Funktionen und bietet Debug-Unterstützung. +""" + + +class HandlerContext: + """ + Kontextobjekt für Handler-Funktionsaufrufe. + + Speichert alle Parameter für handle-Funktionen und bietet: + - Vereinfachte Aufrufe + - Schöne String-Repräsentation für Debugging + - Einfachen Zugriff auf alle Parameter + """ + + def __init__( + self, + msp, + teileid, + merkmale, + x, + y, + doc, + lib_doc, + verbose=False, + symbols=None, + strecken_nachbarn=None, + config=None, + config_allgemein=None, + ): + self.msp = msp + self.teileid = teileid + self.merkmale = merkmale if merkmale is not None else {} + self.x = x + self.y = y + self.doc = doc + self.lib_doc = lib_doc + self.verbose = verbose + self.symbols = symbols if symbols is not None else [] + self.strecken_nachbarn = ( + strecken_nachbarn if strecken_nachbarn is not None else [] + ) + self.config = config + self.config_allgemein = config_allgemein + + def call(self, handler_func): + """ + Ruft eine Handler-Funktion mit allen gespeicherten Parametern auf. + + Args: + handler_func: Die Handler-Funktion (z.B. handle_ils_2_0_kreisel) + + Returns: + Rückgabewert der Handler-Funktion + """ + return handler_func( + self.msp, + self.teileid, + self.merkmale, + self.x, + self.y, + self.doc, + self.lib_doc, + self.verbose, + self.symbols, + self.strecken_nachbarn, + self.config, + self.config_allgemein, + ) + + def __str__(self): + """String-Repräsentation für Debugging.""" + lines = [ + "=" * 80, + "HandlerContext:", + "=" * 80, + f"TeileId: {self.teileid}", + f"Position: x={self.x:.2f}, y={self.y:.2f}", + f"Verbose: {self.verbose}", + "-" * 80, + "Merkmale:", + ] + + if self.merkmale: + for key, value in self.merkmale.items(): + lines.append(f" {key:20s}: {value}") + else: + lines.append(" (keine)") + + lines.append("-" * 80) + lines.append(f"Symbols: {len(self.symbols)} Einträge") + if self.symbols: + for i, sym in enumerate(self.symbols, 1): + lines.append(f" [{i}] {sym}") + + lines.append("-" * 80) + lines.append(f"Nachbarn: {len(self.strecken_nachbarn)} Einträge") + + lines.append("-" * 80) + lines.append(f"doc: {type(self.doc).__name__}") + lines.append( + f"lib_doc: {type(self.lib_doc).__name__ if self.lib_doc else 'None'}" + ) + lines.append(f"msp: {type(self.msp).__name__}") + lines.append(f"config: {'vorhanden' if self.config else 'None'}") + lines.append(f"config_allg: {'vorhanden' if self.config_allgemein else 'None'}") + lines.append("=" * 80) + + return "\n".join(lines) + + def __repr__(self): + """Kurze Repräsentation.""" + return ( + f"HandlerContext(teileid={self.teileid!r}, " + f"x={self.x:.2f}, y={self.y:.2f}, " + f"merkmale={len(self.merkmale)} items)" + ) + + def to_dict(self): + """ + Gibt alle Parameter als Dictionary zurück (ohne Objekt-Referenzen). + Nützlich für Logging oder Serialisierung. + """ + return { + "teileid": self.teileid, + "x": self.x, + "y": self.y, + "verbose": self.verbose, + "merkmale": self.merkmale.copy(), + "symbols_count": len(self.symbols), + "symbols": self.symbols, + "nachbarn_count": len(self.strecken_nachbarn), + "has_config": self.config is not None, + "has_config_allgemein": self.config_allgemein is not None, + "has_lib_doc": self.lib_doc is not None, + } + + @property + def position(self): + """Gibt Position als Tuple zurück.""" + return (self.x, self.y) + + @property + def has_library(self): + """Prüft, ob eine Bibliothek verfügbar ist.""" + return self.lib_doc is not None + + def get_merkmal(self, key, default=None): + """ + Holt ein Merkmal mit Fallback-Wert. + + Args: + key: Merkmal-Schlüssel + default: Standardwert, falls Merkmal nicht existiert + + Returns: + Merkmalwert oder default + """ + return self.merkmale.get(key, default) + + +def create_context_from_row( + row, + msp, + doc, + lib_doc, + strecken_nachbarn, + config, + config_allgemein, + symbols=None, + verbose=False, +): + """ + Factory-Funktion: Erstellt HandlerContext aus einer CSV-Zeile. + + Args: + row: Dictionary mit CSV-Daten + msp: Modelspace + doc: DXF-Dokument + lib_doc: Bibliotheks-Dokument + strecken_nachbarn: Liste der Nachbarn + config: Config-Parser + config_allgemein: Allgemeine Config + symbols: Symbol-Liste (optional) + verbose: Debug-Modus (optional) + + Returns: + HandlerContext-Instanz + """ + from arbeiten_mit_csv import parse_merkmale, extract_coords + + bezeichner = row["Bezeichnung"].strip() + teileid = row["TeileId"].strip() + planquadrat = row["Planquadrat"] + merkmale = parse_merkmale(row.get("Merkmale", "")) + merkmale["bezeichner"] = bezeichner + + x, y = extract_coords(planquadrat) + + return HandlerContext( + msp=msp, + teileid=teileid, + merkmale=merkmale, + x=x, + y=y, + doc=doc, + lib_doc=lib_doc, + verbose=verbose, + symbols=symbols if symbols is not None else [], + strecken_nachbarn=strecken_nachbarn, + config=config, + config_allgemein=config_allgemein, + ) diff --git a/lib/inspect_blocks.py b/lib/inspect_blocks.py index 409a494..a83f426 100644 --- a/lib/inspect_blocks.py +++ b/lib/inspect_blocks.py @@ -7,7 +7,7 @@ def inspect_blocks(dxf_path): print(f"Datei: {dxf_path}") print("Gefundene Blöcke und Attribute:\n") for block in doc.blocks: - if block.name.startswith('*'): # Überspringe anonyme/Standardblöcke + if block.name.startswith("*"): # Überspringe anonyme/Standardblöcke continue print(f"Block: {block.name}") attribs = [e for e in block if e.dxftype() == "ATTDEF"] @@ -22,4 +22,4 @@ def inspect_blocks(dxf_path): if __name__ == "__main__": dxf_file = "data/blocks.dxf" - inspect_blocks(dxf_file) \ No newline at end of file + inspect_blocks(dxf_file) diff --git a/lib/plant2dxf.py b/lib/plant2dxf.py index 6badec2..5014bfd 100644 --- a/lib/plant2dxf.py +++ b/lib/plant2dxf.py @@ -2,6 +2,7 @@ placeblocks.py Erzeugt DXF-Elemente aus einer RuleDesigner-CSV. """ + import os import sys import csv @@ -13,117 +14,162 @@ from ezdxf.entities import Line from pathlib import Path import math from utils import check_environment_var, setup_logger -from Elemente import Kreisel, VarioFoerderer,Gefaehllestrecke,Angetriebene_Kurve,Bt_element,Omniflo, Eckrad +from handler_context import HandlerContext +from Elemente import ( + Kreisel, + VarioFoerderer, + Gefaellestrecke, + Angetriebene_Kurve, + Bt_element, + Omniflo, + Eckrad, +) import as_es_methoden import block_methoden import arbeiten_mit_csv + # --------------------------------------------------------- Konstante Parameter -ATTR_TAG = "TeileId" # Attributtag im Block -RADIUS = 400 # Radius der Kreiselkreise (mm) +ATTR_TAG = "TeileId" # Attributtag im Block +RADIUS = 400 # Radius der Kreiselkreise (mm) + + # --------------------------------------------------------- Hilfsfunktionen -def handle_ils_2_0_kreisel(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols,strecken_nachbarn,config,config_allgemein): +def handle_ils_2_0_kreisel(ctx): """Erstellt ein Kreisel in der neuen Dxf""" - kreisel = Kreisel.Kreisel.from_merkmale(teileid, x, y, merkmale) + kreisel = Kreisel.Kreisel.from_merkmale(ctx.teileid, ctx.x, ctx.y, ctx.merkmale) block_scanner = "SCAN" block_separatoren = "S-LP" scanner_x = kreisel.x scanner_y = kreisel.y separatoren_x = kreisel.x separatoren_y = kreisel.y + 160 - block_methoden.import_block(block_scanner,lib_doc,doc) - block_methoden.import_block(block_separatoren,lib_doc,doc) + block_methoden.import_block(block_scanner, ctx.lib_doc, ctx.doc) + block_methoden.import_block(block_separatoren, ctx.lib_doc, ctx.doc) i = 0 while i < kreisel.anzahl_scanner: - msp.add_blockref(block_scanner, (scanner_x,scanner_y, kreisel.hoehe)) + ctx.msp.add_blockref(block_scanner, (scanner_x, scanner_y, kreisel.hoehe)) scanner_x = scanner_x + 300 - i = i+1 - + i = i + 1 + i = 0 while i < kreisel.anzahl_separatoren: - msp.add_blockref(block_separatoren, (separatoren_x,separatoren_y, kreisel.hoehe)) + ctx.msp.add_blockref( + block_separatoren, (separatoren_x, separatoren_y, kreisel.hoehe) + ) separatoren_x = separatoren_x + 300 - i = i +1 - + i = i + 1 + # Die Koordinaten (x, y) sind die Mitte zwischen den beiden Blöcken (bereits transformiert) pos1 = kreisel.pos1 pos2 = kreisel.pos2 positions = [pos1, pos2] - for i, sym in enumerate(symbols): + for i, sym in enumerate(ctx.symbols): blockname = sym["name"] offset = sym["offset"] rotation = sym["rotation"] if i < len(positions): - pos = (positions[i][0] + offset[0], positions[i][1] + offset[1], kreisel.hoehe) - block_methoden.import_block(blockname, lib_doc, doc) - blockref_layer, color = block_methoden.get_insert_color_layer(lib_doc, blockname) - bref = msp.add_blockref(blockname, pos, dxfattribs={"layer" : blockref_layer}) - bref.add_auto_attribs({ATTR_TAG: teileid}) - if verbose: - print(f"[INFO] Block '{blockname}' (Kreisel) → {teileid} " - f"({pos[0]:.1f}, {pos[1]:.1f}), rot={rotation}") + pos = ( + positions[i][0] + offset[0], + positions[i][1] + offset[1], + kreisel.hoehe, + ) + block_methoden.import_block(blockname, ctx.lib_doc, ctx.doc) + blockref_layer, color = block_methoden.get_insert_color_layer( + ctx.lib_doc, blockname + ) + bref = ctx.msp.add_blockref( + blockname, pos, dxfattribs={"layer": blockref_layer} + ) + bref.add_auto_attribs({ATTR_TAG: ctx.teileid}) + if ctx.verbose: + print( + f"[INFO] Block '{blockname}' (Kreisel) → {ctx.teileid} " + f"({pos[0]:.1f}, {pos[1]:.1f}), rot={rotation}" + ) # Linien zeichnen - block_methoden.import_block("Pinbereich",lib_doc,doc) - Kreisel.Kreisel.draw_kreisel_lines(msp, pos1, pos2, kreisel) - Kreisel.Kreisel.draw_kreisel_drehrichtung_markierung(msp, pos1, pos2, kreisel, lib_doc, doc, verbose) + block_methoden.import_block("Pinbereich", ctx.lib_doc, ctx.doc) + Kreisel.Kreisel.draw_kreisel_lines(ctx.msp, pos1, pos2, kreisel) + Kreisel.Kreisel.draw_kreisel_drehrichtung_markierung( + ctx.msp, pos1, pos2, kreisel, ctx.lib_doc, ctx.doc, ctx.verbose + ) -def handle_ils_2_0_eckrad(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein): + +def handle_ils_2_0_eckrad(ctx): """Erstellt ein Eckrad in der neuen Dxf""" - eckrad_rechts, eckrad_links, hight = Eckrad.Eckrad.erstellung_eckrad_richtung(merkmale, doc, lib_doc) - if merkmale.get("Drehrichtung") == "UZS": - msp.add_blockref(eckrad_rechts,(x,y,hight)) - elif merkmale.get("Drehrichtung") == "GUZS": - msp.add_blockref(eckrad_links,(x,y,hight)) + eckrad_rechts, eckrad_links, hight = Eckrad.Eckrad.erstellung_eckrad_richtung( + ctx.merkmale, ctx.doc, ctx.lib_doc + ) + if ctx.merkmale.get("Drehrichtung") == "UZS": + ctx.msp.add_blockref(eckrad_rechts, (ctx.x, ctx.y, hight)) + elif ctx.merkmale.get("Drehrichtung") == "GUZS": + ctx.msp.add_blockref(eckrad_links, (ctx.x, ctx.y, hight)) else: - msp.add_blockref("AN8",(x,y,hight)) + ctx.msp.add_blockref("AN8", (ctx.x, ctx.y, hight)) -def handle_ils_2_0_gefaellestrecke(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein): +def handle_ils_2_0_gefaellestrecke(ctx): """Erstellt eine Gefällestrecke in der neuen Dxf""" - #Vorbereitung der attributen - gefaelle_objekt = Gefaehllestrecke.Gefaellestrecke.from_merkmale(teileid,x,y,merkmale) - asoffset = float(config.get("ILS 2.0 Gefällestrecke", "asoffset")) - esoffset = float(config.get("ILS 2.0 Gefällestrecke", "esoffset")) - upper_hoehe_gefaehlle= gefaelle_objekt.h1 - lower_hoehe_gefaehlle = gefaelle_objekt.h0 - hoehe_gefaehlle = gefaelle_objekt.hight_zwischen + # Vorbereitung der attributen + gefaelle_objekt = Gefaellestrecke.Gefaellestrecke.from_merkmale( + ctx.teileid, ctx.x, ctx.y, ctx.merkmale + ) + asoffset = float(ctx.config.get("ILS 2.0 Gefällestrecke", "asoffset")) + esoffset = float(ctx.config.get("ILS 2.0 Gefällestrecke", "esoffset")) + upper_hoehe_gefaelle = gefaelle_objekt.h1 + lower_hoehe_gefaelle = gefaelle_objekt.h0 + hoehe_gefaelle = gefaelle_objekt.hight_zwischen laenge = gefaelle_objekt.laenge halbe_laenge = laenge / 2 - rotation= gefaelle_objekt.drehung + rotation = gefaelle_objekt.drehung winkel = math.radians(float(rotation)) - dx = halbe_laenge *math.sin(winkel * -1) + dx = halbe_laenge * math.sin(winkel * -1) dy = halbe_laenge * math.cos(winkel) - start = x +dx, y + dy,upper_hoehe_gefaehlle - if "6-SP" not in doc.layers: - doc.layers.add(name="6-SP", color=7) + start = ctx.x + dx, ctx.y + dy, upper_hoehe_gefaelle + if "6-SP" not in ctx.doc.layers: + ctx.doc.layers.add(name="6-SP", color=7) gefaelle_layer = "6-SP" verbunden_am_einen = False - richtung2 ="DEFAULT" + richtung2 = "DEFAULT" unterschiedlich = False - anzahl_seperatoren_oder_scan(msp, doc, lib_doc, gefaelle_objekt,config) - for nachbarn in strecken_nachbarn: - if teileid == nachbarn.get("Id"): + anzahl_seperatoren_oder_scan( + ctx.msp, ctx.doc, ctx.lib_doc, gefaelle_objekt, ctx.config + ) + for nachbarn in ctx.strecken_nachbarn: + if ctx.teileid == nachbarn.get("Id"): gefaellestrecke_nachbarn = nachbarn break # Fall verbunden mit exakt einem Kreisel - if "Drehung0" in gefaellestrecke_nachbarn and "Drehung1" not in gefaellestrecke_nachbarn: + if ( + "Drehung0" in gefaellestrecke_nachbarn + and "Drehung1" not in gefaellestrecke_nachbarn + ): # Entnehmen der Attribute der Nacharn - drehung0 =gefaellestrecke_nachbarn.get("Drehung0") + drehung0 = gefaellestrecke_nachbarn.get("Drehung0") x0_kreisel = float(gefaellestrecke_nachbarn.get("x0")) y0_kreisel = float(gefaellestrecke_nachbarn.get("y0")) hoehe0 = float(gefaellestrecke_nachbarn.get("Hoehe0")) richtung0 = float(gefaellestrecke_nachbarn.get("rotation0")) - richtung_rad0= math.radians(richtung0) + richtung_rad0 = math.radians(richtung0) abstand0 = float(gefaellestrecke_nachbarn.get("abstand0")) * 1000 - #Austauch der höhen und dementsprechende Koorekur falls nötig, dieser Schritt ist notwendig für die Konsistzenz der Blockerstellung + # Austauch der höhen und dementsprechende Koorekur falls nötig, dieser Schritt ist notwendig für die Konsistzenz der Blockerstellung as_es_methoden.vertausch_der_höhe(gefaelle_objekt) # Übrerprüfung ob die Gefällestrecke einen Motor oder Umlenkstation braucht, wenn es mit einer angetriebenen Kurve verbunden ist - upper_hoehe_gefaehlle = gefaelle_objekt.h1 - lower_hoehe_gefaehlle = gefaelle_objekt.h0 + upper_hoehe_gefaelle = gefaelle_objekt.h1 + lower_hoehe_gefaelle = gefaelle_objekt.h0 rotation = gefaelle_objekt.drehung - block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links = block_methoden.rotatate_and_left_motor_umlenk(doc, lib_doc,config) - hat_zusatz = Gefaehllestrecke.Gefaellestrecke.hat_motor_umlenk_station (gefaelle_objekt, gefaellestrecke_nachbarn) + ( + block_Vario_Umlenkstation_500mm, + block_Vario_Motorstation_500mm, + blockname_motor_links, + blockname_umlenk_links, + ) = block_methoden.rotatate_and_left_motor_umlenk( + ctx.doc, ctx.lib_doc, ctx.config + ) + hat_zusatz = Gefaellestrecke.Gefaellestrecke.hat_motor_umlenk_station( + gefaelle_objekt, gefaellestrecke_nachbarn + ) hat_motor_0 = hat_zusatz.get("hat_motor_0") hat_umlenk_0 = hat_zusatz.get("hat_umlenk_0") tefkurve_0 = hat_zusatz.get("tefkurve_0") @@ -133,90 +179,184 @@ def handle_ils_2_0_gefaellestrecke(msp, teileid, merkmale, x, y, doc, lib_doc, v umlenk_gerade = hat_zusatz.get("umlenk_gerade") motor_gerade = hat_zusatz.get("motor_gerade") verbunden_am_einen = True - # Überprüfung ist die Gefällestrecke direkt mit dem Kreisel verbunden, anstelle des Stahlbandes - am_kreisel, kreisel_verbunden =as_es_methoden.am_kreisel_direct_verbunden(x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, x0_kreisel, y0_kreisel, richtung_rad0, abstand0, dx, dy, None, None, None, None) + # Überprüfung ist die Gefällestrecke direkt mit dem Kreisel verbunden, anstelle des Stahlbandes + am_kreisel, kreisel_verbunden = as_es_methoden.am_kreisel_direct_verbunden( + ctx.x, + ctx.y, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + x0_kreisel, + y0_kreisel, + richtung_rad0, + abstand0, + dx, + dy, + None, + None, + None, + None, + ) # Bearbeitung der Gefälle Strecke falls dies der Fall ist if am_kreisel == 1: if hat_motor_0 == False and hat_umlenk_0 == False: - Gefaehllestrecke.Gefaehllestrecke.erstehlung_von_gefalle_ohne_aussnahmen(msp, x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, halbe_laenge, winkel) + Gefaellestrecke.Gefaellestrecke.erstehlung_von_gefalle_ohne_aussnahmen( + ctx.msp, + ctx.x, + ctx.y, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + halbe_laenge, + winkel, + ) return - #Bearbeitung der Gefällestrecke die direkt am Kreisel hängt und eine Motor- Umlenkstation besitzt - else: + # Bearbeitung der Gefällestrecke die direkt am Kreisel hängt und eine Motor- Umlenkstation besitzt + else: dy = halbe_laenge * math.cos(0) - start = [x , y + dy ,upper_hoehe_gefaehlle] - ende = [x , y - dy ,lower_hoehe_gefaehlle] - blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaehlle}_{hat_umlenk_0}_{hat_motor_0}_{tefkurve_0}_{umlenk_gerade}_{motor_gerade}" - if blockname not in doc.blocks: - block = doc.blocks.new(name=blockname,base_point= (0,0,0)) + start = [ctx.x, ctx.y + dy, upper_hoehe_gefaelle] + ende = [ctx.x, ctx.y - dy, lower_hoehe_gefaelle] + blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaelle}_{hat_umlenk_0}_{hat_motor_0}_{tefkurve_0}_{umlenk_gerade}_{motor_gerade}" + if blockname not in ctx.doc.blocks: + block = ctx.doc.blocks.new(name=blockname, base_point=(0, 0, 0)) dy = halbe_laenge * math.cos(0) - start = [x , y + dy ,upper_hoehe_gefaehlle] - ende = [x , y - dy ,lower_hoehe_gefaehlle] - start, ende = Gefaehllestrecke.Gefaellestrecke.ein_motor_oder_eine_umlenk(x, y,start,ende, doc, lib_doc, hoehe_gefaehlle, block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links, hat_motor_0, hat_umlenk_0, tefkurve_0, block,umlenk_gerade,motor_gerade) - line = Line.new(dxfattribs={"start":start,"end":ende}) - line.translate(-x,-y,-hoehe_gefaehlle) + start = [ctx.x, ctx.y + dy, upper_hoehe_gefaelle] + ende = [ctx.x, ctx.y - dy, lower_hoehe_gefaelle] + start, ende = ( + Gefaellestrecke.Gefaellestrecke.ein_motor_oder_eine_umlenk( + ctx.x, + ctx.y, + start, + ende, + ctx.doc, + ctx.lib_doc, + hoehe_gefaelle, + block_Vario_Umlenkstation_500mm, + block_Vario_Motorstation_500mm, + blockname_motor_links, + blockname_umlenk_links, + hat_motor_0, + hat_umlenk_0, + tefkurve_0, + block, + umlenk_gerade, + motor_gerade, + ) + ) + line = Line.new(dxfattribs={"start": start, "end": ende}) + line.translate(-ctx.x, -ctx.y, -hoehe_gefaelle) block.add_entity(line) - msp.add_blockref(blockname,(x,y,hoehe_gefaehlle),dxfattribs={"rotation": rotation,"layer": gefaelle_layer}) + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_gefaelle), + dxfattribs={"rotation": rotation, "layer": gefaelle_layer}, + ) return # Schauen ob die Gefällestrecke mit dem Höheren oder unterm Teil a, Kreisel Verbunden ist - if upper_hoehe_gefaehlle == hoehe0: - hight ="higher" + if upper_hoehe_gefaelle == hoehe0: + hight = "higher" else: hight = "lower" # Erstelle den Block if hat_motor_0 == False and hat_umlenk_0 == False: - blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{drehung0}_{hoehe_gefaehlle}_{verbunden_am_einen}_{hight}" - else: - blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{drehung0}_{hoehe_gefaehlle}_{verbunden_am_einen}_{hight}_{hat_umlenk_0}_{hat_motor_0}_{tefkurve_0}_{umlenk_gerade}_{motor_gerade}" - - if blockname in doc.blocks: - bref =msp.add_blockref(blockname,(x,y,hoehe_gefaehlle),dxfattribs={"rotation": rotation,"layer": gefaelle_layer}) - a =bref.add_attrib( - tag= "NAME", - text= merkmale.get("bezeichner"), - insert = (x,y) + blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{drehung0}_{hoehe_gefaelle}_{verbunden_am_einen}_{hight}" + else: + blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{drehung0}_{hoehe_gefaelle}_{verbunden_am_einen}_{hight}_{hat_umlenk_0}_{hat_motor_0}_{tefkurve_0}_{umlenk_gerade}_{motor_gerade}" + + if blockname in ctx.doc.blocks: + bref = ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_gefaelle), + dxfattribs={"rotation": rotation, "layer": gefaelle_layer}, + ) + a = bref.add_attrib( + tag="NAME", text=ctx.merkmale.get("bezeichner"), insert=(ctx.x, ctx.y) ) a.is_invisible = True return if laenge > asoffset or laenge > esoffset: - block = doc.blocks.new(name=blockname,base_point= (0,0,0)) + block = ctx.doc.blocks.new(name=blockname, base_point=(0, 0, 0)) else: block = None - + dy = halbe_laenge * math.cos(0) - start = [x , y + dy ,upper_hoehe_gefaehlle] - ende = [x , y - dy ,lower_hoehe_gefaehlle] - start, ende = Gefaehllestrecke.Gefaellestrecke.ein_motor_oder_eine_umlenk(x, y, start,ende,doc, lib_doc, hoehe_gefaehlle, block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links, hat_motor_0, hat_umlenk_0, tefkurve_0, block,umlenk_gerade,motor_gerade) - #Füge die AS- Eselemente ein, falls die Gefällestrecke größer ist als das jeweilige Element + start = [ctx.x, ctx.y + dy, upper_hoehe_gefaelle] + ende = [ctx.x, ctx.y - dy, lower_hoehe_gefaelle] + start, ende = Gefaellestrecke.Gefaellestrecke.ein_motor_oder_eine_umlenk( + ctx.x, + ctx.y, + start, + ende, + ctx.doc, + ctx.lib_doc, + hoehe_gefaelle, + block_Vario_Umlenkstation_500mm, + block_Vario_Motorstation_500mm, + blockname_motor_links, + blockname_umlenk_links, + hat_motor_0, + hat_umlenk_0, + tefkurve_0, + block, + umlenk_gerade, + motor_gerade, + ) + # Füge die AS- Eselemente ein, falls die Gefällestrecke größer ist als das jeweilige Element if richtung0 == 0.0 or richtung0 == -180: rotation_ersatz = "V" else: rotation_ersatz = "H" if rotation_ersatz == "H": - if x> x0_kreisel: - as_es_rotation= -90 + if ctx.x > x0_kreisel: + as_es_rotation = -90 else: - as_es_rotation= -270 + as_es_rotation = -270 else: - if y> y0_kreisel: - as_es_rotation= 0 + if ctx.y > y0_kreisel: + as_es_rotation = 0 else: - as_es_rotation= -180 + as_es_rotation = -180 # Fügt as oder es Element ein oder fügt nur as oder es element hinzu falls nötig - only_es_or_as = as_es_methoden.erstellung_gefaelle_block_verbunenden_am_einen(msp,x, y, doc, lib_doc, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, hoehe_gefaehlle, drehung0, laenge, blockname,config,hight,None,None,None,block,start,ende,None,as_es_rotation) + only_es_or_as = as_es_methoden.erstellung_gefaelle_block_verbunden_an_einen( + ctx.msp, + ctx.x, + ctx.y, + ctx.doc, + ctx.lib_doc, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + hoehe_gefaelle, + drehung0, + laenge, + blockname, + ctx.config, + hight, + None, + None, + None, + block, + start, + ende, + None, + as_es_rotation, + ) if only_es_or_as == False: - bref =msp.add_blockref(blockname,(x,y,hoehe_gefaehlle),dxfattribs={"rotation": rotation,"layer": gefaelle_layer}) - a =bref.add_attrib( - tag= "NAME", - text= merkmale.get("bezeichner"), - insert = (x,y) + bref = ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_gefaelle), + dxfattribs={"rotation": rotation, "layer": gefaelle_layer}, + ) + a = bref.add_attrib( + tag="NAME", text=ctx.merkmale.get("bezeichner"), insert=(ctx.x, ctx.y) ) a.is_invisible = True - #Abarbeitung der Gefallestrecke falls es mit 2 Kreiseln verbunden ist - elif "Drehung0" in gefaellestrecke_nachbarn and "Drehung1" in gefaellestrecke_nachbarn: - #Hollen der nötigen Atributte - dx = halbe_laenge *math.sin(winkel * -1) + # Abarbeitung der Gefallestrecke falls es mit 2 Kreiseln verbunden ist + elif ( + "Drehung0" in gefaellestrecke_nachbarn + and "Drehung1" in gefaellestrecke_nachbarn + ): + # Hollen der nötigen Atributte + dx = halbe_laenge * math.sin(winkel * -1) dy = halbe_laenge * math.cos(winkel) - drehung0 =gefaellestrecke_nachbarn.get("Drehung0") + drehung0 = gefaellestrecke_nachbarn.get("Drehung0") drehung1 = gefaellestrecke_nachbarn.get("Drehung1") hoehe0 = gefaellestrecke_nachbarn.get("Hoehe0") hoehe1 = gefaellestrecke_nachbarn.get("Hoehe1") @@ -226,56 +366,128 @@ def handle_ils_2_0_gefaellestrecke(msp, teileid, merkmale, x, y, doc, lib_doc, v y1_kreisel = float(gefaellestrecke_nachbarn.get("y1")) richtung0 = float(gefaellestrecke_nachbarn.get("rotation0")) richtung1 = float(gefaellestrecke_nachbarn.get("rotation1")) - richtung2 ="DEFAULT" - richtung_rad0= math.radians(richtung0) + richtung2 = "DEFAULT" + richtung_rad0 = math.radians(richtung0) richtung_rad1 = math.radians(richtung1) abstand0 = float(gefaellestrecke_nachbarn.get("abstand0")) * 1000 - abstand1 = float(gefaellestrecke_nachbarn.get("abstand1")) * 1000 - rotation = float(merkmale.get("Drehung")) + abstand1 = float(gefaellestrecke_nachbarn.get("abstand1")) * 1000 + rotation = float(ctx.merkmale.get("Drehung")) # Überprüfung ist die Gefällestrecke direkt mit eimen Kreisel verbunden, anstelle des Stahlbandes und wenn ja wie viele - am_kreisel, kreisel_verbunden= as_es_methoden.am_kreisel_direct_verbunden(x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, x0_kreisel, y0_kreisel, richtung_rad0, abstand0, dx, dy, x1_kreisel, y1_kreisel, richtung_rad1, abstand1) + am_kreisel, kreisel_verbunden = as_es_methoden.am_kreisel_direct_verbunden( + ctx.x, + ctx.y, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + x0_kreisel, + y0_kreisel, + richtung_rad0, + abstand0, + dx, + dy, + x1_kreisel, + y1_kreisel, + richtung_rad1, + abstand1, + ) # falls beide enden direkt mit dem Kreisel verbunden sind zeichnen einfacher Linie if kreisel_verbunden == 2: - Gefaehllestrecke.Gefaellestrecke.erstehlung_von_gefalle_ohne_aussnahmen(msp, x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, halbe_laenge, winkel) + Gefaellestrecke.Gefaellestrecke.erstehlung_von_gefalle_ohne_aussnahmen( + ctx.msp, + ctx.x, + ctx.y, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + halbe_laenge, + winkel, + ) return - #umbezeichnung von den geraden zu strings ob es Vertikal oder Horizontal ist - if richtung0 == 90.0 or richtung0 ==270: - richtung0= "Vertikal" + # umbezeichnung von den geraden zu strings ob es Vertikal oder Horizontal ist + if richtung0 == 90.0 or richtung0 == 270: + richtung0 = "Vertikal" else: richtung0 = "Horizontal" - if richtung1 == 90.0 or richtung1 ==270: - richtung1= "Vertikal" + if richtung1 == 90.0 or richtung1 == 270: + richtung1 = "Vertikal" else: richtung1 = "Horizontal" - richtung2,unterschiedlich = as_es_methoden.am_kreisel_direct_verbunden(x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, x0_kreisel, y0_kreisel, richtung_rad0, abstand0, dx, dy, x1_kreisel, y1_kreisel, richtung_rad1, abstand1,kreisel_verbunden, richtung0 , richtung1 , richtung2 ) - #Berechnung des Gefälles + richtung2, unterschiedlich = as_es_methoden.am_kreisel_direct_verbunden( + ctx.x, + ctx.y, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + x0_kreisel, + y0_kreisel, + richtung_rad0, + abstand0, + dx, + dy, + x1_kreisel, + y1_kreisel, + richtung_rad1, + abstand1, + kreisel_verbunden, + richtung0, + richtung1, + richtung2, + ) + # Berechnung des Gefälles if hoehe0 > hoehe1: hight_position = "higher" else: hight_position = "lower" - rotation, drehung0, drehung1, hight_position = Gefaehllestrecke.Gefaellestrecke.rotation_mit_zwei_verbunden(gefaellestrecke_nachbarn, richtung2, richtung0, am_kreisel, kreisel_verbunden, hight_position) - #geben der richtung2 eines wertes außer default wenn beide kreisel die gleiche richung haben - if (kreisel_verbunden == 1 and richtung2 =="DEFAULT"): + rotation, drehung0, drehung1, hight_position = ( + Gefaellestrecke.Gefaellestrecke.rotation_mit_zwei_verbunden( + gefaellestrecke_nachbarn, + richtung2, + richtung0, + am_kreisel, + kreisel_verbunden, + hight_position, + ) + ) + # geben der richtung2 eines wertes außer default wenn beide kreisel die gleiche richung haben + if kreisel_verbunden == 1 and richtung2 == "DEFAULT": richtung2 = richtung0 if richtung2 == "DEFAULT": - blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaehlle}_{drehung0}_{drehung1}_{hight_position}_{verbunden_am_einen}" + blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaelle}_{drehung0}_{drehung1}_{hight_position}_{verbunden_am_einen}" else: - blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaehlle}_{drehung0}_{drehung1}_{hight_position}_{unterschiedlich}_{richtung2}_{verbunden_am_einen}" - as_es_methoden.gefaellegerade_erstellung(gefaelle_objekt, doc, lib_doc,richtung2,drehung0, drehung1, hight_position,blockname,config) - bref =msp.add_blockref(blockname,(x,y,hoehe_gefaehlle),dxfattribs={"rotation": rotation, "layer": gefaelle_layer}) + blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaelle}_{drehung0}_{drehung1}_{hight_position}_{unterschiedlich}_{richtung2}_{verbunden_am_einen}" + as_es_methoden.gefaellegerade_erstellung( + gefaelle_objekt, + ctx.doc, + ctx.lib_doc, + richtung2, + drehung0, + drehung1, + hight_position, + blockname, + ctx.config, + ) + bref = ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_gefaelle), + dxfattribs={"rotation": rotation, "layer": gefaelle_layer}, + ) a = bref.add_attrib( - tag= "NAME", - text= merkmale.get("bezeichner"), - insert = (x,y) + tag="NAME", text=ctx.merkmale.get("bezeichner"), insert=(ctx.x, ctx.y) ) a.is_invisible = True - #falls eine gefällestrecke nicht mit einem kreisel verbunden ist + # falls eine gefällestrecke nicht mit einem kreisel verbunden ist else: # Schauen ob die Gefällestruktur mit einer Kurve verbunden ist und deswegen ein Motor und oder eine Umlenkstation braucht - block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links = block_methoden.rotatate_and_left_motor_umlenk(doc, lib_doc,config) - hat_zusatz = Gefaehllestrecke.Gefaellestrecke.hat_motor_umlenk_station(gefaelle_objekt, gefaellestrecke_nachbarn) + ( + block_Vario_Umlenkstation_500mm, + block_Vario_Motorstation_500mm, + blockname_motor_links, + blockname_umlenk_links, + ) = block_methoden.rotatate_and_left_motor_umlenk( + ctx.doc, ctx.lib_doc, ctx.config + ) + hat_zusatz = Gefaellestrecke.Gefaellestrecke.hat_motor_umlenk_station( + gefaelle_objekt, gefaellestrecke_nachbarn + ) hat_motor_0 = hat_zusatz.get("hat_motor_0") hat_umlenk_0 = hat_zusatz.get("hat_umlenk_0") tefkurve_0 = hat_zusatz.get("tefkurve_0") @@ -285,518 +497,975 @@ def handle_ils_2_0_gefaellestrecke(msp, teileid, merkmale, x, y, doc, lib_doc, v umlenk_gerade = hat_zusatz.get("umlenk_gerade") motor_gerade = hat_zusatz.get("motor_gerade") - blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaehlle}_{hat_motor_0}_{hat_umlenk_0}_{tefkurve_0}_{hat_motor_1}_{hat_umlenk_1}_{tefkurve_1}_{umlenk_gerade}_{motor_gerade}" + blockname = f"Ils_2.0_Gefaellestrecke_{laenge}_{hoehe_gefaelle}_{hat_motor_0}_{hat_umlenk_0}_{tefkurve_0}_{hat_motor_1}_{hat_umlenk_1}_{tefkurve_1}_{umlenk_gerade}_{motor_gerade}" # behandlung der Gefällestrecke falls es keine Vario Kurve hat - if hat_motor_0 == None and hat_umlenk_0 == None and hat_motor_1 == None and hat_umlenk_1 == None: - Gefaehllestrecke.Gefaellestrecke.erstehlung_von_gefalle_ohne_aussnahmen(msp, x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, halbe_laenge, winkel) + if ( + hat_motor_0 == None + and hat_umlenk_0 == None + and hat_motor_1 == None + and hat_umlenk_1 == None + ): + Gefaellestrecke.Gefaellestrecke.erstehlung_von_gefalle_ohne_aussnahmen( + ctx.msp, + ctx.x, + ctx.y, + upper_hoehe_gefaelle, + lower_hoehe_gefaelle, + halbe_laenge, + winkel, + ) return # Behandlung falls es mit einer odr zwei Vario kurve verbunden ist - if blockname not in doc.blocks: - rotation= float(merkmale.get("Drehung")) + if blockname not in ctx.doc.blocks: + rotation = float(ctx.merkmale.get("Drehung")) as_es_methoden.vertausch_der_höhe(gefaelle_objekt) - upper_hoehe_gefaehlle = gefaelle_objekt.h1 - lower_hoehe_gefaehlle = gefaelle_objekt.h0 + upper_hoehe_gefaelle = gefaelle_objekt.h1 + lower_hoehe_gefaelle = gefaelle_objekt.h0 rotation = gefaelle_objekt.drehung - block = doc.blocks.new(name=blockname,base_point = (0,0,0)) + block = ctx.doc.blocks.new(name=blockname, base_point=(0, 0, 0)) dy = halbe_laenge * math.cos(0) - start = [x , y + dy ,upper_hoehe_gefaehlle] - ende = [x , y - dy ,lower_hoehe_gefaehlle] - start, ende = Gefaehllestrecke.Gefaellestrecke.ein_motor_oder_eine_umlenk(x, y,start,ende, doc, lib_doc, hoehe_gefaehlle, block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links, hat_motor_0, hat_umlenk_0, tefkurve_0, block,umlenk_gerade,motor_gerade) - start, ende = Gefaehllestrecke.Gefaellestrecke.ein_motor_oder_eine_umlenk(x, y,start,ende, doc, lib_doc, hoehe_gefaehlle, block_Vario_Umlenkstation_500mm, block_Vario_Motorstation_500mm, blockname_motor_links, blockname_umlenk_links, hat_motor_1, hat_umlenk_1, tefkurve_1, block,umlenk_gerade,motor_gerade) - line = Line.new(dxfattribs={"start":start,"end":ende}) + start = [ctx.x, ctx.y + dy, upper_hoehe_gefaelle] + ende = [ctx.x, ctx.y - dy, lower_hoehe_gefaelle] + start, ende = Gefaellestrecke.Gefaellestrecke.ein_motor_oder_eine_umlenk( + ctx.x, + ctx.y, + start, + ende, + ctx.doc, + ctx.lib_doc, + hoehe_gefaelle, + block_Vario_Umlenkstation_500mm, + block_Vario_Motorstation_500mm, + blockname_motor_links, + blockname_umlenk_links, + hat_motor_0, + hat_umlenk_0, + tefkurve_0, + block, + umlenk_gerade, + motor_gerade, + ) + start, ende = Gefaellestrecke.Gefaellestrecke.ein_motor_oder_eine_umlenk( + ctx.x, + ctx.y, + start, + ende, + ctx.doc, + ctx.lib_doc, + hoehe_gefaelle, + block_Vario_Umlenkstation_500mm, + block_Vario_Motorstation_500mm, + blockname_motor_links, + blockname_umlenk_links, + hat_motor_1, + hat_umlenk_1, + tefkurve_1, + block, + umlenk_gerade, + motor_gerade, + ) + line = Line.new(dxfattribs={"start": start, "end": ende}) line.dxf.layer = "6-SP" - line.translate(-x,-y,-hoehe_gefaehlle) + line.translate(-ctx.x, -ctx.y, -hoehe_gefaelle) block.add_entity(line) - msp.add_blockref(blockname,(x,y,hoehe_gefaehlle),dxfattribs={"rotation": rotation,"layer": gefaelle_layer}) + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_gefaelle), + dxfattribs={"rotation": rotation, "layer": gefaelle_layer}, + ) -def handle_ils_2_0_variofoerderer(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein): + +def handle_ils_2_0_variofoerderer(ctx): """Erstellt ein Vario Förderer in der neuen Dxf""" - foerderer = VarioFoerderer.VarioFoerderer.from_merkmale(teileid,x,y,merkmale) + foerderer = VarioFoerderer.VarioFoerderer.from_merkmale( + ctx.teileid, ctx.x, ctx.y, ctx.merkmale + ) # für spätere Namens benenung der Vario forderer motor_vorhanden = foerderer.hat_motor umlenk_vorhanden = foerderer.hat_umlenk gefahellewinkel = foerderer.gefaelle_winkel gefaelle = foerderer.gefaelle_laenge - # Offsets für die Vario Linie für ab 3 bogen, da es in diesem Fall keine bögen hat die sich mit den nachbarn Bögen für andere Vario Förderer verbinden kann + # Offsets für die Vario Linie für ab 3 bogen, da es in diesem Fall keine bögen hat die sich mit den nachbarn Bögen für andere Vario Förderer verbinden kann winkel_VP_offset_vorne = None winkel_VP_offset_hinten = None # erstellung des Layers falls nicht vorhanden - if "VARIO" not in doc.layers: - doc.layers.add(name="VARIO", color=3) - - if "6-SP" not in doc.layers: - doc.layers.add(name="6-SP", color=7) - # Vorbereitung der Werte + if "VARIO" not in ctx.doc.layers: + ctx.doc.layers.add(name="VARIO", color=3) + + if "6-SP" not in ctx.doc.layers: + ctx.doc.layers.add(name="6-SP", color=7) + # Vorbereitung der Werte voerder_richtung = foerderer.foerderer_richtung winkel = int(foerderer.winkel) erster_kreisel_höher = False ein_kreisel_höher = False - richtung2 ="DEFAULT" + richtung2 = "DEFAULT" rotation = foerderer.drehung - upper_hoehe_vario= foerderer.h1 + upper_hoehe_vario = foerderer.h1 lower_hoehe_vario = foerderer.h0 - hoehe_vario= foerderer.hight_zwischen - anzahl_seperatoren_oder_scan(msp, doc, lib_doc, foerderer,config) + hoehe_vario = foerderer.hight_zwischen + anzahl_seperatoren_oder_scan(ctx.msp, ctx.doc, ctx.lib_doc, foerderer, ctx.config) as_es_methoden.vertausch_der_höhe(foerderer) upper_hoehe_vario = foerderer.h1 lower_hoehe_vario = foerderer.h0 rotation = foerderer.drehung # Hollen der Information der Nachbarn strukturen ob diese Kreisel sind - for nachbarn in strecken_nachbarn: - if teileid == nachbarn.get("Id"): + for nachbarn in ctx.strecken_nachbarn: + if ctx.teileid == nachbarn.get("Id"): gefaellestrecke_vario = nachbarn break laenge = foerderer.laenge halbe_laenge = laenge / 2 -# Ausrechnung der nötigen Offset falls der Vario Förderer ab mit drei grad mit einem anderen Verbunden ist - winkel_VP_offset_vorne, winkel_VP_offset_hinten = VarioFoerderer.VarioFoerderer.get_offset_of_Vario_line(doc, lib_doc,foerderer, gefaellestrecke_vario) - + # Ausrechnung der nötigen Offset falls der Vario Förderer ab mit drei grad mit einem anderen Verbunden ist + winkel_VP_offset_vorne, winkel_VP_offset_hinten = ( + VarioFoerderer.VarioFoerderer.get_offset_of_Vario_line( + ctx.doc, ctx.lib_doc, foerderer, gefaellestrecke_vario + ) + ) + # Für spätere berechnung schauen ob der erste Kreis in der Liste höher ist if upper_hoehe_vario == gefaellestrecke_vario.get("Hoehe0"): ein_kreisel_höher = True # Falls der Förderer mit einem Eckrad verbunden ist - if "Eckrad_x" in gefaellestrecke_vario and "Eckrad_x_1" not in gefaellestrecke_vario: + if ( + "Eckrad_x" in gefaellestrecke_vario + and "Eckrad_x_1" not in gefaellestrecke_vario + ): x0_eckrad = gefaellestrecke_vario.get("Eckrad_x") y0_eckrad = gefaellestrecke_vario.get("Eckrad_y") hoehe_eckrad = gefaellestrecke_vario.get("Eckrad_höhe") - if(upper_hoehe_vario == hoehe_eckrad): + if upper_hoehe_vario == hoehe_eckrad: ein_kreisel_höher = True else: ein_kreisel_höher = False - mit_horizontal_verbunden = VarioFoerderer.VarioFoerderer.horizontale_ausrichtung(foerderer, x0_eckrad, y0_eckrad) - blockname = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{ein_kreisel_höher}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}") - block_name_links = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{ein_kreisel_höher}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}") - if blockname not in doc.blocks: - block_vario = doc.blocks.new(blockname, base_point=(0,0,0)) + mit_horizontal_verbunden = ( + VarioFoerderer.VarioFoerderer.horizontale_ausrichtung( + foerderer, x0_eckrad, y0_eckrad + ) + ) + blockname = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{ein_kreisel_höher}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}" + block_name_links = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{ein_kreisel_höher}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}" + if blockname not in ctx.doc.blocks: + block_vario = ctx.doc.blocks.new(blockname, base_point=(0, 0, 0)) - dy_true = halbe_laenge * math.cos (0) - start = (x, y + dy_true,upper_hoehe_vario) - ende = (x,y -dy_true,lower_hoehe_vario) - start, ende = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel(foerderer, block_vario, start, ende, mit_horizontal_verbunden,1,1,ein_kreisel_höher) - VarioFoerderer.VarioFoerderer.vario_erstellung(foerderer, doc, lib_doc, config, block_vario,block_name_links, start, ende,voerder_richtung ,winkel_VP_offset_vorne,winkel_VP_offset_hinten) + dy_true = halbe_laenge * math.cos(0) + start = (ctx.x, ctx.y + dy_true, upper_hoehe_vario) + ende = (ctx.x, ctx.y - dy_true, lower_hoehe_vario) + start, ende = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel( + foerderer, + block_vario, + start, + ende, + mit_horizontal_verbunden, + 1, + 1, + ein_kreisel_höher, + ) + VarioFoerderer.VarioFoerderer.vario_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + ctx.config, + block_vario, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ) # reintuen des förderes in den Modelspace - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return # Falls der Förderer mit zwei Eckrads verbunden ist if "Eckrad_x" in gefaellestrecke_vario and "Eckrad_x_1" in gefaellestrecke_vario: - blockname = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_2_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") - block_name_links = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_2_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") - if blockname not in doc.blocks: - block_vario = doc.blocks.new(blockname, base_point=(0,0,0)) + blockname = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_2_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" + block_name_links = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_2_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" + if blockname not in ctx.doc.blocks: + block_vario = ctx.doc.blocks.new(blockname, base_point=(0, 0, 0)) - dy_true = halbe_laenge * math.cos (0) - start = (x, y + dy_true,upper_hoehe_vario) - ende = (x,y -dy_true,lower_hoehe_vario) - start, ende = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel(foerderer, block_vario, start, ende, None,2,) - VarioFoerderer.VarioFoerderer.vario_erstellung(foerderer, doc, lib_doc, config, block_vario,block_name_links, start, ende,voerder_richtung ,winkel_VP_offset_vorne,winkel_VP_offset_hinten) + dy_true = halbe_laenge * math.cos(0) + start = (ctx.x, ctx.y + dy_true, upper_hoehe_vario) + ende = (ctx.x, ctx.y - dy_true, lower_hoehe_vario) + start, ende = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel( + foerderer, + block_vario, + start, + ende, + None, + 2, + ) + VarioFoerderer.VarioFoerderer.vario_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + ctx.config, + block_vario, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ) # reintuen des förderes in den Modelspace - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return # Aufruf falls nur mit einem Kreisel verbunden if "Drehung0" in gefaellestrecke_vario and "Drehung1" not in gefaellestrecke_vario: # Vorbereitund der Daten des Kreisel halbe_laenge = laenge / 2 - zwischen_winkel = float(merkmale.get("Drehung")) + zwischen_winkel = float(ctx.merkmale.get("Drehung")) richtung_rad = math.radians(zwischen_winkel) - dx = halbe_laenge * math.sin(-1 *richtung_rad) + dx = halbe_laenge * math.sin(-1 * richtung_rad) dy = halbe_laenge * math.cos(richtung_rad) drehung0 = gefaellestrecke_vario.get("Drehung0") abstand0 = float(gefaellestrecke_vario.get("abstand0")) * 1000 x0_kreisel = float(gefaellestrecke_vario.get("x0")) y0_kreisel = float(gefaellestrecke_vario.get("y0")) richtung0 = float(gefaellestrecke_vario.get("rotation0")) - richtung_rad0= math.radians(richtung0) + richtung_rad0 = math.radians(richtung0) - mit_horizontal_verbunden = VarioFoerderer.VarioFoerderer.horizontale_ausrichtung(foerderer, x0_kreisel, y0_kreisel) - am_kreisel,kreseil_verbunden =as_es_methoden.am_kreisel_direct_verbunden(x, y, upper_hoehe_vario, lower_hoehe_vario, x0_kreisel, y0_kreisel, richtung_rad0, abstand0, dx, dy, None, None, None, None ) + mit_horizontal_verbunden = ( + VarioFoerderer.VarioFoerderer.horizontale_ausrichtung( + foerderer, x0_kreisel, y0_kreisel + ) + ) + am_kreisel, kreseil_verbunden = as_es_methoden.am_kreisel_direct_verbunden( + ctx.x, + ctx.y, + upper_hoehe_vario, + lower_hoehe_vario, + x0_kreisel, + y0_kreisel, + richtung_rad0, + abstand0, + dx, + dy, + None, + None, + None, + None, + ) if am_kreisel == 1: # Erstellung der blockname für wenn die Motorstation rechts und links - blockname = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{ein_kreisel_höher}_{drehung0}_True_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}") - block_name_links = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{ein_kreisel_höher}_{drehung0}_True_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}") - # Falls der Block bereits in dem doc ist platziere diesen einfach - if blockname in doc.blocks: - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + blockname = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{ein_kreisel_höher}_{drehung0}_True_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}" + block_name_links = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{ein_kreisel_höher}_{drehung0}_True_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}" + # Falls der Block bereits in dem ctx.doc ist platziere diesen einfach + if blockname in ctx.doc.blocks: + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return # Erstellung des Blocks und diesen in die Modelspace tuen. Die Linke version wird bei der vario erstellung selber am ende gemacht - block_vario = doc.blocks.new(blockname, base_point=(0,0,0)) - dy_true = halbe_laenge * math.cos (0) - start = (x, y + dy_true,upper_hoehe_vario) - ende = (x,y -dy_true,lower_hoehe_vario) + block_vario = ctx.doc.blocks.new(blockname, base_point=(0, 0, 0)) + dy_true = halbe_laenge * math.cos(0) + start = (ctx.x, ctx.y + dy_true, upper_hoehe_vario) + ende = (ctx.x, ctx.y - dy_true, lower_hoehe_vario) # Erstellung einer Gefällestrecke von 500 mm in der Vario rein, wo es verbunden ist - start, ende = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel(foerderer, block_vario, start, ende, mit_horizontal_verbunden,kreseil_verbunden,am_kreisel,ein_kreisel_höher) - + start, ende = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel( + foerderer, + block_vario, + start, + ende, + mit_horizontal_verbunden, + kreseil_verbunden, + am_kreisel, + ein_kreisel_höher, + ) + # Erstellung des Vario_förderes selber - VarioFoerderer.VarioFoerderer.vario_erstellung(foerderer, doc, lib_doc, config, block_vario,block_name_links, start, ende,voerder_richtung ,winkel_VP_offset_vorne,winkel_VP_offset_hinten) + VarioFoerderer.VarioFoerderer.vario_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + ctx.config, + block_vario, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ) # reintuen des förderes in den Modelspace - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return # Abschnitt falls der Vario nur mit einem Kreisel verbunden ist und nicht an dem Kreisel direkt verbunden ist - + # Erstellung der blockname für wenn die Motorstation rechts und links - blockname = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{ein_kreisel_höher}_{drehung0}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}") - block_name_links = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{ein_kreisel_höher}_{drehung0}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}") - # Falls der Block bereits in dem doc ist platziere diesen einfach - if blockname in doc.blocks: - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + blockname = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{ein_kreisel_höher}_{drehung0}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}" + block_name_links = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{ein_kreisel_höher}_{drehung0}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}_{mit_horizontal_verbunden}" + # Falls der Block bereits in dem ctx.doc ist platziere diesen einfach + if blockname in ctx.doc.blocks: + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return # Erstellung des Blocks und diesen in die Modelspace tuen. Die Linke version wird bei der vario erstellung selber am ende gemacht - block_vario = doc.blocks.new(blockname, base_point=(0,0,0)) - dy_true = halbe_laenge * math.cos (0) + block_vario = ctx.doc.blocks.new(blockname, base_point=(0, 0, 0)) + dy_true = halbe_laenge * math.cos(0) # Schauen welches as oder es element man wo verbinden muss und bereits in den block tuen, der None wert ist ein Wert der für die Gefällestrecke notwendig ist # Entnehmen von start und end Werte für spätere vario erstellung - - start, ende = as_es_methoden.erstellung_gefaelle_block_verbunenden_am_einen(msp,x, y, doc, lib_doc, upper_hoehe_vario, lower_hoehe_vario, hoehe_vario, drehung0, laenge, blockname,config,None ,block_vario, voerder_richtung, ein_kreisel_höher,None,None,None,mit_horizontal_verbunden) + + start, ende = as_es_methoden.erstellung_gefaelle_block_verbunden_an_einen( + ctx.msp, + ctx.x, + ctx.y, + ctx.doc, + ctx.lib_doc, + upper_hoehe_vario, + lower_hoehe_vario, + hoehe_vario, + drehung0, + laenge, + blockname, + ctx.config, + None, + block_vario, + voerder_richtung, + ein_kreisel_höher, + None, + None, + None, + mit_horizontal_verbunden, + ) # Erstellung des Varios selber - VarioFoerderer.VarioFoerderer.vario_erstellung(foerderer, doc, lib_doc, config, block_vario,block_name_links, start, ende,voerder_richtung ,winkel_VP_offset_vorne,winkel_VP_offset_hinten) + VarioFoerderer.VarioFoerderer.vario_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + ctx.config, + block_vario, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ) # reintuen des förderes in den Modelspace - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) - if merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) + if ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) # Erstellung einer Vario förderes wenn es mit zwei Kreisel verbunden ist elif "Drehung0" in gefaellestrecke_vario and "Drehung1" in gefaellestrecke_vario: - # Vorbereitung der Werte für beide Kreisel + # Vorbereitung der Werte für beide Kreisel halbe_laenge = laenge / 2 - zwischen_winkel = float(merkmale.get("Drehung")) + zwischen_winkel = float(ctx.merkmale.get("Drehung")) richtung_rad = math.radians(zwischen_winkel) - dx = halbe_laenge * math.sin(-1 *richtung_rad) + dx = halbe_laenge * math.sin(-1 * richtung_rad) dy = halbe_laenge * math.cos(richtung_rad) drehung0 = gefaellestrecke_vario.get("Drehung0") abstand0 = float(gefaellestrecke_vario.get("abstand0")) * 1000 x0_kreisel = float(gefaellestrecke_vario.get("x0")) y0_kreisel = float(gefaellestrecke_vario.get("y0")) richtung0 = float(gefaellestrecke_vario.get("rotation0")) - richtung_rad0= math.radians(richtung0) - kreisel_hoehe0 =float(gefaellestrecke_vario.get("Hoehe0")) + richtung_rad0 = math.radians(richtung0) + kreisel_hoehe0 = float(gefaellestrecke_vario.get("Hoehe0")) drehung1 = gefaellestrecke_vario.get("Drehung1") abstand1 = float(gefaellestrecke_vario.get("abstand1")) * 1000 x1_kreisel = float(gefaellestrecke_vario.get("x1")) y1_kreisel = float(gefaellestrecke_vario.get("y1")) richtung1 = float(gefaellestrecke_vario.get("rotation1")) - richtung_rad1= math.radians(richtung1) - kreisel_hoehe1= float(gefaellestrecke_vario.get("Hoehe1")) + richtung_rad1 = math.radians(richtung1) + kreisel_hoehe1 = float(gefaellestrecke_vario.get("Hoehe1")) # Anpassung der Kreisel, damit der Höhere Kreisel immer zuerst ist - if kreisel_hoehe0< kreisel_hoehe1: + if kreisel_hoehe0 < kreisel_hoehe1: drehung2 = drehung0 drehung0 = drehung1 drehung1 = drehung2 # Schauen ob der Förderer direkt am Kreisel verbunden ist - am_kreisel,kreisel_verbunden = as_es_methoden.am_kreisel_direct_verbunden(x, y, upper_hoehe_vario, lower_hoehe_vario, x0_kreisel, y0_kreisel, richtung_rad0, abstand0, dx, dy, x1_kreisel, y1_kreisel, richtung_rad1, abstand1) + am_kreisel, kreisel_verbunden = as_es_methoden.am_kreisel_direct_verbunden( + ctx.x, + ctx.y, + upper_hoehe_vario, + lower_hoehe_vario, + x0_kreisel, + y0_kreisel, + richtung_rad0, + abstand0, + dx, + dy, + x1_kreisel, + y1_kreisel, + richtung_rad1, + abstand1, + ) # Falls der Förder mit beiden Kreisel verbunden ist if kreisel_verbunden == 2: - # Erstellung der blockname für wenn die Motorstation rechts und links - blockname = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{kreisel_verbunden}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") - block_name_links = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{kreisel_verbunden}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") - # Falls der Block bereits in dem doc ist platziere diesen einfach - if blockname in doc.blocks: - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) - return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) - return - # Erstellung des Blocks und diesen in die Modelspace tuen. Die Linke version wird bei der vario erstellung selber am ende gemacht - block_vario = doc.blocks.new(blockname, base_point=(0,0,0)) - dy_true = halbe_laenge * math.cos (0) - start = (x, y + dy_true,upper_hoehe_vario) - ende = (x,y -dy_true,lower_hoehe_vario) - start, ende = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel(foerderer, block_vario, start, ende,None,kreisel_verbunden) - # Die Vario erstellung selber - VarioFoerderer.VarioFoerderer.vario_erstellung(foerderer,doc, lib_doc, config, block_vario,block_name_links, start, ende,voerder_richtung ,winkel_VP_offset_vorne,winkel_VP_offset_hinten) - # reintuen des förderes in den Modelspace - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + # Erstellung der blockname für wenn die Motorstation rechts und links + blockname = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{kreisel_verbunden}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" + block_name_links = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{kreisel_verbunden}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" + # Falls der Block bereits in dem ctx.doc ist platziere diesen einfach + if blockname in ctx.doc.blocks: + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return + # Erstellung des Blocks und diesen in die Modelspace tuen. Die Linke version wird bei der vario erstellung selber am ende gemacht + block_vario = ctx.doc.blocks.new(blockname, base_point=(0, 0, 0)) + dy_true = halbe_laenge * math.cos(0) + start = (ctx.x, ctx.y + dy_true, upper_hoehe_vario) + ende = (ctx.x, ctx.y - dy_true, lower_hoehe_vario) + start, ende = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel( + foerderer, block_vario, start, ende, None, kreisel_verbunden + ) + # Die Vario erstellung selber + VarioFoerderer.VarioFoerderer.vario_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + ctx.config, + block_vario, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ) + # reintuen des förderes in den Modelspace + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) + return + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) + return # Falls der Förderer nur mit einem Kreisel direkt verbunden ist if am_kreisel != 0: - #schauen ob der erste Kreisel höher ist + # schauen ob der erste Kreisel höher ist if upper_hoehe_vario == kreisel_hoehe0: erster_kreisel_höher = True else: erster_kreisel_höher = False # Erstellung der blockname für wenn die Motorstation rechts und links - blockname = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{am_kreisel}_{erster_kreisel_höher}_{drehung0}_{drehung1}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") - block_name_links = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{am_kreisel}_{erster_kreisel_höher}_{drehung0}_{drehung1}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") + blockname = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{am_kreisel}_{erster_kreisel_höher}_{drehung0}_{drehung1}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" + block_name_links = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{am_kreisel}_{erster_kreisel_höher}_{drehung0}_{drehung1}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" - # Falls der Block bereits in dem doc ist platziere diesen einfach - if blockname in doc.blocks: - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + # Falls der Block bereits in dem ctx.doc ist platziere diesen einfach + if blockname in ctx.doc.blocks: + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return # Erstellung des Blocks und diesen in die Modelspace tuen. Die Linke version wird bei der vario erstellung selber am ende gemacht - block_vario = doc.blocks.new(blockname, base_point=(0,0,0)) + block_vario = ctx.doc.blocks.new(blockname, base_point=(0, 0, 0)) dy_true = halbe_laenge * math.cos(0) - start = (x, y + dy_true,upper_hoehe_vario) - ende = (x,y -dy_true,lower_hoehe_vario) + start = (ctx.x, ctx.y + dy_true, upper_hoehe_vario) + ende = (ctx.x, ctx.y - dy_true, lower_hoehe_vario) # schauen ob der Förderer mit welchen Kreisel der Förderer verbunden ist, und dem entsprechend eine Gefällestrecke dort reintuern - y1,z1 = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel(foerderer, block_vario, start, ende,None,kreisel_verbunden,am_kreisel,erster_kreisel_höher ) + y1, z1 = VarioFoerderer.VarioFoerderer.vario_verbuden_am_kreisel( + foerderer, + block_vario, + start, + ende, + None, + kreisel_verbunden, + am_kreisel, + erster_kreisel_höher, + ) # Schauen welche es oder as element man braucht man braucht und diese in den block einfügen # Entnehmen von start und end Werte für spätere vario erstellung - start, ende = as_es_methoden.gefaellegerade_erstellung(foerderer, doc, lib_doc,richtung2, drehung0, drehung1, None, blockname,config,block_vario, am_kreisel,erster_kreisel_höher,y1,z1) + start, ende = as_es_methoden.gefaellegerade_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + richtung2, + drehung0, + drehung1, + None, + blockname, + ctx.config, + block_vario, + am_kreisel, + erster_kreisel_höher, + y1, + z1, + ) # Erstellung der Vario gefälle selber - VarioFoerderer.VarioFoerderer.vario_erstellung(foerderer, doc, lib_doc, config, block_vario,block_name_links, start, ende,voerder_richtung ,winkel_VP_offset_vorne,winkel_VP_offset_hinten) + VarioFoerderer.VarioFoerderer.vario_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + ctx.config, + block_vario, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ) # Reintuen des endblockes in den Modelspace - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) # Falls es nicht mit dem Kreisel direkt verbunden ist else: # Erstellung der blockname für wenn die Motorstation rechts und links - blockname = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{drehung0}_{drehung1}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") - block_name_links = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{drehung0}_{drehung1}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") + blockname = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{drehung0}_{drehung1}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" + block_name_links = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{drehung0}_{drehung1}_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" - # Falls der Block bereits in dem doc ist platziere diesen einfach - if blockname in doc.blocks: - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + # Falls der Block bereits in dem ctx.doc ist platziere diesen einfach + if blockname in ctx.doc.blocks: + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return # Erstellung des Blocks und diesen in die Modelspace tuen. Die Linke version wird bei der vario erstellung selber am ende gemacht - block_vario = doc.blocks.new(blockname, base_point=(0,0,0)) + block_vario = ctx.doc.blocks.new(blockname, base_point=(0, 0, 0)) # Schauen welche es oder as element man braucht man braucht und diese in den block einfügen # Entnehmen von start und end Werte für spätere vario erstellung - start, ende = as_es_methoden.gefaellegerade_erstellung(foerderer, doc, lib_doc,richtung2, drehung0, drehung1, None, blockname,config,block_vario) + start, ende = as_es_methoden.gefaellegerade_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + richtung2, + drehung0, + drehung1, + None, + blockname, + ctx.config, + block_vario, + ) # Erstellung des Vario selber - VarioFoerderer.VarioFoerderer.vario_erstellung(foerderer, doc, lib_doc, config, block_vario,block_name_links, start, ende,voerder_richtung,winkel_VP_offset_vorne,winkel_VP_offset_hinten ) + VarioFoerderer.VarioFoerderer.vario_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + ctx.config, + block_vario, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ) # Reintuen des endblockes in den Modelspace - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) - + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) + # Erstellung des Varios falls es nicht mit einem Kreisel verbunden ist else: - halbe_laenge = laenge/2 + halbe_laenge = laenge / 2 dy = halbe_laenge * math.cos(0) # Erstellung der blockname für wenn die Motorstation rechts und links - blockname = (f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") - block_name_links =(f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}") - # Falls der Block bereits in dem doc ist platziere diesen einfach - if blockname in doc.blocks: - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + blockname = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_rechts_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" + block_name_links = f"Vario_Foerderer_{winkel}_{voerder_richtung}_{laenge}_{hoehe_vario}_links_{motor_vorhanden}_{umlenk_vorhanden}_{gefaelle}_{gefahellewinkel}" + # Falls der Block bereits in dem ctx.doc ist platziere diesen einfach + if blockname in ctx.doc.blocks: + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - elif merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + elif ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) return - + # Erstellung des Blocks und diesen in die Modelspace tuen. Die Linke version wird bei der vario erstellung selber am ende gemacht - block = doc.blocks.new(blockname, base_point=(0,0,0)) + block = ctx.doc.blocks.new(blockname, base_point=(0, 0, 0)) # Erstellung von start und ende - start = (x,y +dy, upper_hoehe_vario) - ende = (x ,y -dy, lower_hoehe_vario) + start = (ctx.x, ctx.y + dy, upper_hoehe_vario) + ende = (ctx.x, ctx.y - dy, lower_hoehe_vario) # Erstellung des Förderes selber - VarioFoerderer.VarioFoerderer.vario_erstellung(foerderer, doc, lib_doc, config, block,block_name_links, start, ende,voerder_richtung ,winkel_VP_offset_vorne,winkel_VP_offset_hinten) + VarioFoerderer.VarioFoerderer.vario_erstellung( + foerderer, + ctx.doc, + ctx.lib_doc, + ctx.config, + block, + block_name_links, + start, + ende, + voerder_richtung, + winkel_VP_offset_vorne, + winkel_VP_offset_hinten, + ) # Reintuen des endblockes in den Modelspace - if merkmale.get("Motorseite")== "links": - msp.add_blockref(block_name_links,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) - - if merkmale.get("Motorseite")== "rechts": - msp.add_blockref(blockname,(x,y,hoehe_vario),dxfattribs={"rotation": rotation}) + if ctx.merkmale.get("Motorseite") == "links": + ctx.msp.add_blockref( + block_name_links, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) -def handle_ils_2_0_kurve_angetrieben(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein): + if ctx.merkmale.get("Motorseite") == "rechts": + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, hoehe_vario), + dxfattribs={"rotation": rotation}, + ) + + +def handle_ils_2_0_kurve_angetrieben(ctx): """Erstellt eine Angetriebene Kurve (Förderer Kurve) in der neuen Dxf""" - voerder_kurve = Angetriebene_Kurve.Angetriebene_Kurve.from_merkmale(teileid,x,y,merkmale) + voerder_kurve = Angetriebene_Kurve.Angetriebene_Kurve.from_merkmale( + ctx.teileid, ctx.x, ctx.y, ctx.merkmale + ) kurvenwinkel = voerder_kurve.winkel h_zwischen = voerder_kurve.hight_zwischen antriebNebenStrecke = voerder_kurve.antrieb kurvenrichtung = voerder_kurve.kurvenrichtung - rotation = voerder_kurve.drehung - blockname = (f"Vario_Kurve_{kurvenrichtung}_{kurvenwinkel}°_TEF_{antriebNebenStrecke}") - block_methoden.import_block(blockname,lib_doc,doc) - layer, color = block_methoden.get_insert_color_layer(lib_doc, blockname) - msp.add_blockref(blockname,(x,y,h_zwischen),dxfattribs={"rotation": rotation,"layer": layer, "color":color}) + rotation = voerder_kurve.drehung + blockname = ( + f"Vario_Kurve_{kurvenrichtung}_{kurvenwinkel}°_TEF_{antriebNebenStrecke}" + ) + block_methoden.import_block(blockname, ctx.lib_doc, ctx.doc) + layer, color = block_methoden.get_insert_color_layer(ctx.lib_doc, blockname) + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, h_zwischen), + dxfattribs={"rotation": rotation, "layer": layer, "color": color}, + ) -def handle_ils_2_0_kurve(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein): + +def handle_ils_2_0_kurve(ctx): """Erstellt eine Kurve (Gefälle Kurve) in der neuen Dxf""" - rotation= float(merkmale.get("Drehung")) - h0 = float(merkmale.get("Höhe Anfang")) * 1000 - h1 = float(merkmale.get("Höhe Ende")) * 1000 - hz = (h0 + h1)/2 - kurvenrichtung = merkmale.get("Kurvenrichtung") - kurvenwinkel =int(merkmale.get("Kurvenwinkel")) - blockname = (f"Kurve_{kurvenrichtung}_{kurvenwinkel}°_R500_Gefälle") - block_methoden.import_block(blockname,lib_doc,doc) - msp.add_blockref(blockname,(x,y,hz),dxfattribs={"rotation": rotation}) + rotation = float(ctx.merkmale.get("Drehung")) + h0 = float(ctx.merkmale.get("Höhe Anfang")) * 1000 + h1 = float(ctx.merkmale.get("Höhe Ende")) * 1000 + hz = (h0 + h1) / 2 + kurvenrichtung = ctx.merkmale.get("Kurvenrichtung") + kurvenwinkel = int(ctx.merkmale.get("Kurvenwinkel")) + blockname = f"Kurve_{kurvenrichtung}_{kurvenwinkel}°_R500_Gefälle" + block_methoden.import_block(blockname, ctx.lib_doc, ctx.doc) + ctx.msp.add_blockref( + blockname, (ctx.x, ctx.y, hz), dxfattribs={"rotation": rotation} + ) -def handle_bt___beladung(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein): + +def handle_bt___beladung(ctx): """Erstellt ein BT Element in der neuen Dxf""" - bt_element = Bt_element.Bt_element.from_merkmale(teileid,x,y,merkmale) + bt_element = Bt_element.Bt_element.from_merkmale( + ctx.teileid, ctx.x, ctx.y, ctx.merkmale + ) rotation = bt_element.drehung hight = bt_element.hoehe blockname = "AN8" - block_methoden.import_block(blockname,lib_doc,doc) - msp.add_blockref(blockname,(x,y,hight),dxfattribs={"rotation": rotation}) + block_methoden.import_block(blockname, ctx.lib_doc, ctx.doc) + ctx.msp.add_blockref( + blockname, (ctx.x, ctx.y, hight), dxfattribs={"rotation": rotation} + ) -def handle_bt___entladung(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein): + +def handle_bt___entladung(ctx): """Erstellt ein BT Element in der neuen Dxf""" - bt_element = Bt_element.Bt_element.from_merkmale(teileid,x,y,merkmale) + bt_element = Bt_element.Bt_element.from_merkmale( + ctx.teileid, ctx.x, ctx.y, ctx.merkmale + ) rotation = bt_element.drehung hight = bt_element.hoehe blockname = "AN8" - block_methoden.import_block(blockname,lib_doc,doc) - msp.add_blockref(blockname,(x,y,hight),dxfattribs={"rotation": rotation}) + block_methoden.import_block(blockname, ctx.lib_doc, ctx.doc) + ctx.msp.add_blockref( + blockname, (ctx.x, ctx.y, hight), dxfattribs={"rotation": rotation} + ) -def handle_omniflo(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein): + +def handle_omniflo(ctx): """ Für Omniflo Gerade: zeichnet eine Linie (Mitte = Koordinate, Länge und Winkel aus Merkmale). Für alle anderen Omniflo-Typen: Block mit SivasNummer an den Koordinaten. """ # Prüfen, ob es sich um eine Gerade handelt - omnisivas = config.get("Omniflo","OFgeradesivas") - tefsivas = config.get("Omniflo","Tefgeradesivas") - foerderer = config.get("Omniflo","OFfoerderer") - omniflo_objekt = Omniflo.Omniflo.from_merkmale(teileid,x,y,merkmale) + omnisivas = ctx.config.get("Omniflo", "OFgeradesivas") + tefsivas = ctx.config.get("Omniflo", "Tefgeradesivas") + foerderer = ctx.config.get("Omniflo", "OFfoerderer") + omniflo_objekt = Omniflo.Omniflo.from_merkmale( + ctx.teileid, ctx.x, ctx.y, ctx.merkmale + ) rotation = omniflo_objekt.drehung - if omniflo_objekt.sivasnummer == omnisivas or omniflo_objekt.sivasnummer == tefsivas: - Omniflo.Omniflo.Omniflo_geraden_erstellung(msp, doc, tefsivas, omniflo_objekt) + if ( + omniflo_objekt.sivasnummer == omnisivas + or omniflo_objekt.sivasnummer == tefsivas + ): + Omniflo.Omniflo.Omniflo_geraden_erstellung( + ctx.msp, ctx.doc, tefsivas, omniflo_objekt + ) if omniflo_objekt.sivasnummer == omnisivas: - anzahl_seperatoren_oder_scan(msp, doc, lib_doc, omniflo_objekt,config) + anzahl_seperatoren_oder_scan( + ctx.msp, ctx.doc, ctx.lib_doc, omniflo_objekt, ctx.config + ) elif omniflo_objekt.sivasnummer == foerderer: - Omniflo.Omniflo.omniflo_foerdererstellung(msp, doc, lib_doc, omniflo_objekt) + Omniflo.Omniflo.omniflo_foerdererstellung( + ctx.msp, ctx.doc, ctx.lib_doc, omniflo_objekt + ) return # Sonst wie gehabt: Block mit SivasNummer else: - if not lib_doc: + if not ctx.lib_doc: print("[WARN] lib_doc nicht verfügbar, Block wird nicht eingefügt.") return - blockname = merkmale.get("SivasNummer") + blockname = ctx.merkmale.get("SivasNummer") if not blockname: - print(f"[WARN] Keine SivasNummer für {teileid}, überspringe.") + print(f"[WARN] Keine SivasNummer für {ctx.teileid}, überspringe.") return - if blockname not in lib_doc.blocks: - print(f"[WARN] Omniflo-Block '{blockname}' nicht in Bibliothek {lib_doc.filename}. Überspringe {teileid}.") + if blockname not in ctx.lib_doc.blocks: + print( + f"[WARN] Omniflo-Block '{blockname}' nicht in Bibliothek {ctx.lib_doc.filename}. Überspringe {ctx.teileid}." + ) return blockname = blockname - block_methoden.import_block(blockname, lib_doc, doc) - layer, color = block_methoden.get_insert_color_layer(lib_doc, omniflo_objekt.sivasnummer) - msp.add_blockref(blockname, (x, y,omniflo_objekt.hoehe), dxfattribs={"rotation": rotation,"layer": layer, "color": color}) + block_methoden.import_block(blockname, ctx.lib_doc, ctx.doc) + layer, color = block_methoden.get_insert_color_layer( + ctx.lib_doc, omniflo_objekt.sivasnummer + ) + ctx.msp.add_blockref( + blockname, + (ctx.x, ctx.y, omniflo_objekt.hoehe), + dxfattribs={"rotation": rotation, "layer": layer, "color": color}, + ) -def anzahl_seperatoren_oder_scan(msp, doc, lib_doc, klassen_objekt,config): + +def anzahl_seperatoren_oder_scan(msp, doc, lib_doc, klassen_objekt, config): """Importiert alle seperatoren und/oder scanner für das nötige objekt""" - omniflo_scanner = config.get("Scanner_Stoper_namen","Omniflo_scanner") - ILS_scanner = config.get("Scanner_Stoper_namen","Ils_scanner") - omniflo_stopper = config.get("Scanner_Stoper_namen","Omniflo_stopper") - ILS_seperator = config.get("Scanner_Stoper_namen","ILS_seperator") + omniflo_scanner = config.get("Scanner_Stoper_namen", "Omniflo_scanner") + ILS_scanner = config.get("Scanner_Stoper_namen", "Ils_scanner") + omniflo_stopper = config.get("Scanner_Stoper_namen", "Omniflo_stopper") + ILS_seperator = config.get("Scanner_Stoper_namen", "ILS_seperator") scanner = klassen_objekt.anzahl_scanner separatoren = None stopper = None x = klassen_objekt.x y = klassen_objekt.y - hoehe =klassen_objekt.hight_zwischen + hoehe = klassen_objekt.hight_zwischen rotation = klassen_objekt.drehung - + # Schauen welche Ausrichtung das Objekt hat, damit man die Separtoren unbd Scanner nicht in das Objekt tut - if rotation == 0 or rotation == -180: + if rotation == 0 or rotation == -180: ausrichtung = "V" else: ausrichtung = "H" if ausrichtung == "V": - einsatz_fest = [x + 300, y,hoehe] + einsatz_fest = [x + 300, y, hoehe] modular = 2 else: - einsatz_fest = [x,y - 150,hoehe] + einsatz_fest = [x, y - 150, hoehe] modular = 3 if omniflo_scanner not in lib_doc.blocks: - block_methoden.import_block(ILS_scanner,lib_doc,doc) - block_methoden.import_block(ILS_seperator,lib_doc,doc) + block_methoden.import_block(ILS_scanner, lib_doc, doc) + block_methoden.import_block(ILS_seperator, lib_doc, doc) scanner_name = ILS_scanner separator_name = ILS_seperator - layer_scan, color_scan = block_methoden.get_insert_color_layer(lib_doc, ILS_scanner) - layer_separatioren, color_separatioren = block_methoden.get_insert_color_layer(lib_doc, ILS_seperator) + layer_scan, color_scan = block_methoden.get_insert_color_layer( + lib_doc, ILS_scanner + ) + layer_separatioren, color_separatioren = block_methoden.get_insert_color_layer( + lib_doc, ILS_seperator + ) separatoren = klassen_objekt.anzahl_separatoren else: - block_methoden.import_block(omniflo_scanner,lib_doc,doc) - block_methoden.import_block(omniflo_stopper,lib_doc,doc) + block_methoden.import_block(omniflo_scanner, lib_doc, doc) + block_methoden.import_block(omniflo_stopper, lib_doc, doc) scanner_name = omniflo_scanner stopper_name = omniflo_stopper - layer_scan, color_scan = block_methoden.get_insert_color_layer(lib_doc, omniflo_scanner) - layer_stopper, color_stopper = block_methoden.get_insert_color_layer(lib_doc, omniflo_stopper) + layer_scan, color_scan = block_methoden.get_insert_color_layer( + lib_doc, omniflo_scanner + ) + layer_stopper, color_stopper = block_methoden.get_insert_color_layer( + lib_doc, omniflo_stopper + ) stopper = klassen_objekt.anzahl_stopper - - einsatz_zwischen =[ einsatz_fest[0],einsatz_fest[1],einsatz_fest[2]] - anzahl =0 + + einsatz_zwischen = [einsatz_fest[0], einsatz_fest[1], einsatz_fest[2]] + anzahl = 0 if separatoren != None: while anzahl < separatoren: anzahl = anzahl + 1 - msp.add_blockref(separator_name,einsatz_zwischen, dxfattribs={"layer": layer_separatioren,"color": color_separatioren}) + msp.add_blockref( + separator_name, + einsatz_zwischen, + dxfattribs={"layer": layer_separatioren, "color": color_separatioren}, + ) if anzahl % modular == 0: einsatz_fest[1] = einsatz_fest[1] - 150 einsatz_zwischen = einsatz_fest.copy() else: - einsatz_zwischen[0] = einsatz_zwischen[0]+ 300 + einsatz_zwischen[0] = einsatz_zwischen[0] + 300 if anzahl % modular != 0: einsatz_fest[1] = einsatz_fest[1] - 150 einsatz_zwischen = einsatz_fest.copy() - anzahl =0 + anzahl = 0 else: while anzahl < stopper: anzahl = anzahl + 1 - msp.add_blockref(stopper_name,einsatz_zwischen, dxfattribs={"layer": layer_stopper,"color": color_stopper}) + msp.add_blockref( + stopper_name, + einsatz_zwischen, + dxfattribs={"layer": layer_stopper, "color": color_stopper}, + ) if anzahl % modular == 0: einsatz_fest[1] = einsatz_fest[1] - 250 einsatz_zwischen = einsatz_fest.copy() else: - einsatz_zwischen[0] = einsatz_zwischen[0]+ 200 + einsatz_zwischen[0] = einsatz_zwischen[0] + 200 if anzahl % modular != 0: einsatz_fest[1] = einsatz_fest[1] - 250 einsatz_zwischen = einsatz_fest.copy() - anzahl =0 + anzahl = 0 while anzahl < scanner: anzahl = anzahl + 1 - msp.add_blockref(scanner_name,einsatz_zwischen,dxfattribs={"layer": layer_scan,"color": color_scan}) + msp.add_blockref( + scanner_name, + einsatz_zwischen, + dxfattribs={"layer": layer_scan, "color": color_scan}, + ) if anzahl % modular == 0: einsatz_fest[1] = einsatz_fest[1] - 150 einsatz_zwischen = einsatz_fest.copy() else: - einsatz_zwischen[0] = einsatz_zwischen[0]+ 300 + einsatz_zwischen[0] = einsatz_zwischen[0] + 300 + + def get_libfile_cfg(teileart, cfg_path): """Liest den Bibliotheksdateinamen für eine TeileArt aus der allgemein.cfg.""" parser = configparser.ConfigParser() - with open(cfg_path, encoding='utf-8') as f: + with open(cfg_path, encoding="utf-8") as f: parser.read_file(f) # Teileart kann z.B. "ILS 2.0 Kreisel" sein, wir nehmen den ersten Teil vor erstem Leerzeichen oder Punkt # oder suchen iterativ nach Sektionen, die im Teileart-Namen vorkommen @@ -805,31 +1474,40 @@ def get_libfile_cfg(teileart, cfg_path): return parser.get(section, "libfile", fallback=None) return None + # --------------------------------------------------------- Hauptfunktion -def main(csv_path: Path, lib_path: Path, cfg_path: Path, allgemein_cfg_path: Path, - output_path: Path, output_path_jason: Path, verbose=False, logger=None ): - data_dir = check_environment_var("PROJECT_DATA") +def main( + csv_path: Path, + lib_path: Path, + cfg_path: Path, + allgemein_cfg_path: Path, + output_path: Path, + output_path_json: Path, + verbose=False, + logger=None, +): + data_dir = check_environment_var("PROJECT_DATA") # Bibliothek nur laden, wenn Datei existiert check_dxflibrary_path(lib_path, verbose, logger) parser_cfg_path = configparser.ConfigParser() try: - with open(cfg_path, encoding='utf-8') as f: + with open(cfg_path, encoding="utf-8") as f: parser_cfg_path.read_file(f) except Exception as e: msg = f"Fehler beim Lesen der Config-Datei {cfg_path}: {e}" # Neue Ziel­zeichnung (DXF R2018) - config =parser_cfg_path + config = parser_cfg_path parser_allgemein_path = configparser.ConfigParser() try: - with open(allgemein_cfg_path, encoding='utf-8') as f: + with open(allgemein_cfg_path, encoding="utf-8") as f: parser_allgemein_path.read_file(f) except Exception as e: msg = f"Fehler beim Lesen der Config-Datei {cfg_path}: {e}" # Neue Ziel­zeichnung (DXF R2018) - config_allgemein =parser_allgemein_path + config_allgemein = parser_allgemein_path doc = ezdxf.new(dxfversion="R2018", setup=True) doc.units = units.M - doc.header['$INSUNITS'] = 4 # Millimeter + doc.header["$INSUNITS"] = 4 # Millimeter msp = doc.modelspace() blocklib_dir = data_dir / "block_libraries" @@ -840,19 +1518,19 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path, allgemein_cfg_path: Pat strecken_nachbarn = arbeiten_mit_csv.get_nachbar_information(csv_path) # Verarbeitung der Blöcke - + with csv_path.open(newline="", encoding="utf-8") as fh: - reader = csv.DictReader(fh, delimiter=';') + reader = csv.DictReader(fh, delimiter=";") for row in reader: bezeichner = row["Bezeichnung"].strip() teileart = row["TeileArt"].strip() - teileid = row["TeileId"].strip() + teileid = row["TeileId"].strip() planquadrat = row["Planquadrat"] merkmale = arbeiten_mit_csv.parse_merkmale(row.get("Merkmale", "")) merkmale["bezeichner"] = bezeichner try: x, y = arbeiten_mit_csv.extract_coords(planquadrat) - + except Exception as e: msg = f"[WARN] {teileid}: {e}" if logger: @@ -881,19 +1559,38 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path, allgemein_cfg_path: Pat except Exception as e: print(f"[WARN] Fehler beim Lesen der Bibliothek '{lib_path}': {e}") else: - print(f"[INFO] Keine Bibliothek gefunden unter {lib_path}. Komplexe Formen werden übersprungen.") + print( + f"[INFO] Keine Bibliothek gefunden unter {lib_path}. Komplexe Formen werden übersprungen." + ) # Funktions-Dispatch: handle_ (mit _ statt Leerzeichen und Punkten, alles klein) - func_name = f'handle_{arbeiten_mit_csv.normalize_func_name(teileart)}' + func_name = f"handle_{arbeiten_mit_csv.normalize_func_name(teileart)}" handler = globals().get(func_name) symbols = arbeiten_mit_csv.get_shape_cfg(teileart, cfg_path, logger=logger) # Mapping für Omniflo-Typen - if func_name.startswith('handle_omniflo') or func_name.startswith('handle_tef'): - handler = globals().get('handle_omniflo') + if func_name.startswith("handle_omniflo") or func_name.startswith( + "handle_tef" + ): + handler = globals().get("handle_omniflo") if func_name.startswith("handle_ils_2_0_kreisel"): handler = globals().get("handle_ils_2_0_kreisel") if handler: - handler(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn, config,config_allgemein) + # Erstelle HandlerContext-Objekt + ctx = HandlerContext( + msp=msp, + teileid=teileid, + merkmale=merkmale, + x=x, + y=y, + doc=doc, + lib_doc=lib_doc, + verbose=verbose, + symbols=symbols, + strecken_nachbarn=strecken_nachbarn, + config=config, + config_allgemein=config_allgemein, + ) + handler(ctx) else: msg = f"[WARN] Keine Routine für TeileArt '{teileart}'. Überspringe '{teileid}'." if logger: @@ -907,13 +1604,18 @@ def main(csv_path: Path, lib_path: Path, cfg_path: Path, allgemein_cfg_path: Pat else: print(f"[DONE] DXF gespeichert unter: {output_path}") + def check_dxflibrary_path(lib_path, verbose, logger): lib_doc = None if lib_path.exists(): try: lib_doc = ezdxf.readfile(lib_path) if verbose: - logger.info(f"[INFO] Bibliothek geladen: {lib_path}") if logger else print(f"[INFO] Bibliothek geladen: {lib_path}") + ( + logger.info(f"[INFO] Bibliothek geladen: {lib_path}") + if logger + else print(f"[INFO] Bibliothek geladen: {lib_path}") + ) except Exception as e: msg = f"Fehler beim Lesen der Bibliothek '{lib_path}': {e}" if logger: @@ -929,24 +1631,43 @@ def check_dxflibrary_path(lib_path, verbose, logger): print(msg) sys.exit(1) + if __name__ == "__main__": parser = argparse.ArgumentParser( - description="Plaziert Anlagenkomponenten aus RuleDesigner CSV.") - parser.add_argument("-f", "--file", required=True, help="CSV-Datei (Name oder Pfad)", metavar="input.csv") - parser.add_argument("-c", "--config", help="CFG mit einfachen Formen", metavar="shapes.cfg") - parser.add_argument("-l", "--lib", help="DXF-Bibliothek mit Blöcken", metavar="bibliothek.dxf") - parser.add_argument("-o", "--output", help="Ziel-DXF (Standard: PROJECT_WORK/anlage.dxf)", metavar="anlage.dxf") - parser.add_argument("-v", "--verbose", action="store_true", help="mehr Ausgaben anzeigen") + description="Plaziert Anlagenkomponenten aus RuleDesigner CSV." + ) + parser.add_argument( + "-f", + "--file", + required=True, + help="CSV-Datei (Name oder Pfad)", + metavar="input.csv", + ) + parser.add_argument( + "-c", "--config", help="CFG mit einfachen Formen", metavar="shapes.cfg" + ) + parser.add_argument( + "-l", "--lib", help="DXF-Bibliothek mit Blöcken", metavar="bibliothek.dxf" + ) + parser.add_argument( + "-o", + "--output", + help="Ziel-DXF (Standard: PROJECT_WORK/anlage.dxf)", + metavar="anlage.dxf", + ) + parser.add_argument( + "-v", "--verbose", action="store_true", help="mehr Ausgaben anzeigen" + ) args = parser.parse_args() - + # Verzeichnisse aus Umgebungs­variablen - log_dir = check_environment_var("PROJECT_LOG") - data_dir = check_environment_var("PROJECT_DATA") - work_dir = check_environment_var("PROJECT_WORK") + log_dir = check_environment_var("PROJECT_LOG") + data_dir = check_environment_var("PROJECT_DATA") + work_dir = check_environment_var("PROJECT_WORK") config_dir = check_environment_var("PROJECT_CFG") - logger = setup_logger(log_dir, name='plant2dxf') + logger = setup_logger(log_dir, name="plant2dxf") logger.info("=== plant2dxf Verarbeitung gestartet ===") # CSV‑Pfad: nur Dateiname → im WORK‑Ordner suchen @@ -955,10 +1676,23 @@ if __name__ == "__main__": else: csv_path = Path(args.file) - cfg_path = Path(args.config) if args.config else config_dir / "shapes.cfg" + cfg_path = Path(args.config) if args.config else config_dir / "shapes.cfg" allgemein_cfg_path = config_dir / "allgemein.cfg" - default_lib_path = Path(args.lib) if args.lib else data_dir / "blocks.dxf" - output_path = Path(args.output) if args.output else (work_dir / f"{csv_path.stem}.dxf") - output_path_jason = Path(args.output) if args.output else (work_dir / f"{csv_path.stem}.jason") - main(csv_path, default_lib_path, cfg_path,allgemein_cfg_path, output_path,output_path_jason, verbose=args.verbose, logger=logger) - logger.info("=== plant2dxf Verarbeitung abgeschlossen ===") \ No newline at end of file + default_lib_path = Path(args.lib) if args.lib else data_dir / "blocks.dxf" + output_path = ( + Path(args.output) if args.output else (work_dir / f"{csv_path.stem}.dxf") + ) + output_path_json = ( + Path(args.output) if args.output else (work_dir / f"{csv_path.stem}.json") + ) + main( + csv_path, + default_lib_path, + cfg_path, + allgemein_cfg_path, + output_path, + output_path_json, + verbose=args.verbose, + logger=logger, + ) + logger.info("=== plant2dxf Verarbeitung abgeschlossen ===") diff --git a/lib/test_files.py b/lib/test_files.py index 4ce603a..15c1128 100644 --- a/lib/test_files.py +++ b/lib/test_files.py @@ -4,6 +4,7 @@ import difflib from utils import check_environment_var, setup_logger import plant2dxf + class TestDXFGeometry(unittest.TestCase): testordner_path = Path(check_environment_var("PROJECT_TEST")) lib_path = Path(check_environment_var("PROJECT_DATA")) @@ -12,8 +13,26 @@ class TestDXFGeometry(unittest.TestCase): default_lib_path = lib_path / "blocks.dxf" cfg_path = config_dir / "shapes.cfg" allgemein_cfg_path = config_dir / "allgemein.cfg" - - GEOM_CODES = {"0", "8", "10", "20", "30", "11", "21", "31", "41", "42", "43", "70", "71", "72", "73", "74", "75"} + + GEOM_CODES = { + "0", + "8", + "10", + "20", + "30", + "11", + "21", + "31", + "41", + "42", + "43", + "70", + "71", + "72", + "73", + "74", + "75", + } def extract_geometry_lines(self, file_path): """ @@ -39,125 +58,251 @@ class TestDXFGeometry(unittest.TestCase): geom1 = self.extract_geometry_lines(file1) geom2 = self.extract_geometry_lines(file2) if geom1 != geom2: - diff = "".join(difflib.unified_diff(geom1, geom2, fromfile=str(file1), tofile=str(file2))) + diff = "".join( + difflib.unified_diff( + geom1, geom2, fromfile=str(file1), tofile=str(file2) + ) + ) raise AssertionError(f"Geometrische Daten unterscheiden sich:\n{diff}") def test_omniflobogen_dxf_file(self): omniflo_bogen = "omniflo_bogen" - omniflo_bogen_csv = self.testordner_path / f"{omniflo_bogen}.csv" + omniflo_bogen_csv = self.testordner_path / f"{omniflo_bogen}.csv" omniflo_bogen_dxf = f"{omniflo_bogen}.dxf" - omniflo_bogen_jason = self.work_dir / f"{omniflo_bogen}.jason" - omniflo_bogen_output = self.work_dir / omniflo_bogen_dxf - omniflo_bogen_reference = self.testordner_path / omniflo_bogen_dxf - plant2dxf.main(omniflo_bogen_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, omniflo_bogen_output,omniflo_bogen_jason) + omniflo_bogen_json = self.work_dir / f"{omniflo_bogen}.json" + omniflo_bogen_output = self.work_dir / omniflo_bogen_dxf + omniflo_bogen_reference = self.testordner_path / omniflo_bogen_dxf + plant2dxf.main( + omniflo_bogen_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + omniflo_bogen_output, + omniflo_bogen_json, + ) self.assert_dxf_geometry_equal(omniflo_bogen_output, omniflo_bogen_reference) - + def test_weiche_90_dxf_file(self): - weiche_90= "weiche_90" - weiche_90_csv = self.testordner_path / f"{weiche_90}.csv" + weiche_90 = "weiche_90" + weiche_90_csv = self.testordner_path / f"{weiche_90}.csv" weiche_90_dxf = f"{weiche_90}.dxf" - weiche_90_jason = self.work_dir /f"{weiche_90}.jason" + weiche_90_json = self.work_dir / f"{weiche_90}.json" weiche_90_output = self.work_dir / weiche_90_dxf weiche_90_reference = self.testordner_path / weiche_90_dxf - plant2dxf.main(weiche_90_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, weiche_90_output,weiche_90_jason) + plant2dxf.main( + weiche_90_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + weiche_90_output, + weiche_90_json, + ) self.assert_dxf_geometry_equal(weiche_90_output, weiche_90_reference) def test_weiche_45_simple_dxf_file(self): - weiche_45_simple= "weiche_45_simple" - weiche_45_simple_csv = self.testordner_path / f"{weiche_45_simple}.csv" + weiche_45_simple = "weiche_45_simple" + weiche_45_simple_csv = self.testordner_path / f"{weiche_45_simple}.csv" weiche_45_simple_dxf = f"{weiche_45_simple}.dxf" - weiche_45_simple_jason = self.work_dir/ f"{weiche_45_simple}.jason" + weiche_45_simple_json = self.work_dir / f"{weiche_45_simple}.json" weiche_45_simple_output = self.work_dir / weiche_45_simple_dxf weiche_45_simple_reference = self.testordner_path / weiche_45_simple_dxf - plant2dxf.main(weiche_45_simple_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, weiche_45_simple_output,weiche_45_simple_jason) - self.assert_dxf_geometry_equal(weiche_45_simple_output, weiche_45_simple_reference) + plant2dxf.main( + weiche_45_simple_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + weiche_45_simple_output, + weiche_45_simple_json, + ) + self.assert_dxf_geometry_equal( + weiche_45_simple_output, weiche_45_simple_reference + ) def test_weiche_45_doppel_dxf_file(self): - weiche_45_doppel= "weiche_45_doppel" - weiche_45_doppel_csv = self.testordner_path / f"{weiche_45_doppel}.csv" + weiche_45_doppel = "weiche_45_doppel" + weiche_45_doppel_csv = self.testordner_path / f"{weiche_45_doppel}.csv" weiche_45_doppel_dxf = f"{weiche_45_doppel}.dxf" - weiche_45_doppel_jason = self.work_dir /f"{weiche_45_doppel}.jason" + weiche_45_doppel_json = self.work_dir / f"{weiche_45_doppel}.json" weiche_45_doppel_output = self.work_dir / weiche_45_doppel_dxf weiche_45_doppel_reference = self.testordner_path / weiche_45_doppel_dxf - plant2dxf.main(weiche_45_doppel_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, weiche_45_doppel_output,weiche_45_doppel_jason) - self.assert_dxf_geometry_equal(weiche_45_doppel_output, weiche_45_doppel_reference) + plant2dxf.main( + weiche_45_doppel_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + weiche_45_doppel_output, + weiche_45_doppel_json, + ) + self.assert_dxf_geometry_equal( + weiche_45_doppel_output, weiche_45_doppel_reference + ) def test_weiche_45_dreiwege_dxf_file(self): - weiche_45_dreiwege= "weiche_45_dreiwege" - weiche_45_dreiwege_csv = self.testordner_path / f"{weiche_45_dreiwege}.csv" + weiche_45_dreiwege = "weiche_45_dreiwege" + weiche_45_dreiwege_csv = self.testordner_path / f"{weiche_45_dreiwege}.csv" weiche_45_dreiwege_dxf = f"{weiche_45_dreiwege}.dxf" - weiche_45_dreiwege_jason = self.work_dir /f"{weiche_45_dreiwege}.jason" + weiche_45_dreiwege_json = self.work_dir / f"{weiche_45_dreiwege}.json" weiche_45_dreiwege_output = self.work_dir / weiche_45_dreiwege_dxf weiche_45_dreiwege_reference = self.testordner_path / weiche_45_dreiwege_dxf - plant2dxf.main(weiche_45_dreiwege_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, weiche_45_dreiwege_output,weiche_45_dreiwege_jason) - self.assert_dxf_geometry_equal(weiche_45_dreiwege_output, weiche_45_dreiwege_reference) + plant2dxf.main( + weiche_45_dreiwege_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + weiche_45_dreiwege_output, + weiche_45_dreiwege_json, + ) + self.assert_dxf_geometry_equal( + weiche_45_dreiwege_output, weiche_45_dreiwege_reference + ) def test_weichenkoerper_dxf_file(self): - weichenkoerper= "weichenkoerper" - weichenkoerper_csv = self.testordner_path / f"{weichenkoerper}.csv" + weichenkoerper = "weichenkoerper" + weichenkoerper_csv = self.testordner_path / f"{weichenkoerper}.csv" weichenkoerper_dxf = f"{weichenkoerper}.dxf" - weichenkoerper_jason = self.work_dir /f"{weichenkoerper}.jason" + weichenkoerper_json = self.work_dir / f"{weichenkoerper}.json" weichenkoerper_output = self.work_dir / weichenkoerper_dxf weichenkoerper_reference = self.testordner_path / weichenkoerper_dxf - plant2dxf.main(weichenkoerper_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, weichenkoerper_output,weichenkoerper_jason) + plant2dxf.main( + weichenkoerper_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + weichenkoerper_output, + weichenkoerper_json, + ) self.assert_dxf_geometry_equal(weichenkoerper_output, weichenkoerper_reference) def test_weichenkombination_dxf_file(self): - weichenkombination= "weichenkombination" - weichenkombination_csv = self.testordner_path / f"{weichenkombination}.csv" + weichenkombination = "weichenkombination" + weichenkombination_csv = self.testordner_path / f"{weichenkombination}.csv" weichenkombination_dxf = f"{weichenkombination}.dxf" - weichenkombination_jason = self.work_dir /f"{weichenkombination}.jason" + weichenkombination_json = self.work_dir / f"{weichenkombination}.json" weichenkombination_output = self.work_dir / weichenkombination_dxf weichenkombination_reference = self.testordner_path / weichenkombination_dxf - plant2dxf.main(weichenkombination_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, weichenkombination_output,weichenkombination_jason) - self.assert_dxf_geometry_equal(weichenkombination_output, weichenkombination_reference) - + plant2dxf.main( + weichenkombination_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + weichenkombination_output, + weichenkombination_json, + ) + self.assert_dxf_geometry_equal( + weichenkombination_output, weichenkombination_reference + ) + def test_gefaelle_dxf_file(self): - gefaelle= "gefaelle" - gefaelle_csv = self.testordner_path / f"{gefaelle}.csv" + gefaelle = "gefaelle" + gefaelle_csv = self.testordner_path / f"{gefaelle}.csv" gefaelle_dxf = f"{gefaelle}.dxf" - gefaelle_jason = self.work_dir /f"{gefaelle}.jason" + gefaelle_json = self.work_dir / f"{gefaelle}.json" weichenkombination_output = self.work_dir / gefaelle_dxf weichenkombination_reference = self.testordner_path / gefaelle_dxf - plant2dxf.main(gefaelle_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, weichenkombination_output,gefaelle_jason) - self.assert_dxf_geometry_equal(weichenkombination_output, weichenkombination_reference) + plant2dxf.main( + gefaelle_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + weichenkombination_output, + gefaelle_json, + ) + self.assert_dxf_geometry_equal( + weichenkombination_output, weichenkombination_reference + ) def test_gefaelle_ausnahme_gleiche_orientierung_dxf_file(self): - gefaelle_ausnahme_gleiche_orientierung= "gefaelle_ausnahme_gleiche_orientierung" - gefaelle_ausnahme_gleiche_orientierung_csv = self.testordner_path / f"{gefaelle_ausnahme_gleiche_orientierung}.csv" - gefaelle_ausnahme_gleiche_orientierung_dxf = f"{gefaelle_ausnahme_gleiche_orientierung}.dxf" - gefaelle_ausnahme_gleiche_orientierung_jason = self.work_dir /f"{gefaelle_ausnahme_gleiche_orientierung}.jason" - gefaelle_ausnahme_gleiche_orientierung_output = self.work_dir / gefaelle_ausnahme_gleiche_orientierung_dxf - gefaelle_ausnahme_gleiche_orientierung_reference = self.testordner_path / gefaelle_ausnahme_gleiche_orientierung_dxf - plant2dxf.main(gefaelle_ausnahme_gleiche_orientierung_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, gefaelle_ausnahme_gleiche_orientierung_output,gefaelle_ausnahme_gleiche_orientierung_jason) - self.assert_dxf_geometry_equal(gefaelle_ausnahme_gleiche_orientierung_output, gefaelle_ausnahme_gleiche_orientierung_reference) + gefaelle_ausnahme_gleiche_orientierung = ( + "gefaelle_ausnahme_gleiche_orientierung" + ) + gefaelle_ausnahme_gleiche_orientierung_csv = ( + self.testordner_path / f"{gefaelle_ausnahme_gleiche_orientierung}.csv" + ) + gefaelle_ausnahme_gleiche_orientierung_dxf = ( + f"{gefaelle_ausnahme_gleiche_orientierung}.dxf" + ) + gefaelle_ausnahme_gleiche_orientierung_json = ( + self.work_dir / f"{gefaelle_ausnahme_gleiche_orientierung}.json" + ) + gefaelle_ausnahme_gleiche_orientierung_output = ( + self.work_dir / gefaelle_ausnahme_gleiche_orientierung_dxf + ) + gefaelle_ausnahme_gleiche_orientierung_reference = ( + self.testordner_path / gefaelle_ausnahme_gleiche_orientierung_dxf + ) + plant2dxf.main( + gefaelle_ausnahme_gleiche_orientierung_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + gefaelle_ausnahme_gleiche_orientierung_output, + gefaelle_ausnahme_gleiche_orientierung_json, + ) + self.assert_dxf_geometry_equal( + gefaelle_ausnahme_gleiche_orientierung_output, + gefaelle_ausnahme_gleiche_orientierung_reference, + ) def test_gefaelle_ausnahme_unterschiedlich_orientierung_dxf_file(self): - gefaelle_ausnahme_unterschiedlich_orientierung= "gefaelle_ausnahme_unterschiedlich_orientierung" - gefaelle_ausnahme_unterschiedlich_orientierung_csv = self.testordner_path / f"{gefaelle_ausnahme_unterschiedlich_orientierung}.csv" - gefaelle_ausnahme_unterschiedlich_orientierung_dxf = f"{gefaelle_ausnahme_unterschiedlich_orientierung}.dxf" - gefaelle_ausnahme_unterschiedlich_orientierung_jason = self.work_dir /f"{gefaelle_ausnahme_unterschiedlich_orientierung}.jason" - gefaelle_ausnahme_unterschiedlich_orientierung_output = self.work_dir / gefaelle_ausnahme_unterschiedlich_orientierung_dxf - gefaelle_ausnahme_unterschiedlich_orientierung_reference = self.testordner_path / gefaelle_ausnahme_unterschiedlich_orientierung_dxf - plant2dxf.main(gefaelle_ausnahme_unterschiedlich_orientierung_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, gefaelle_ausnahme_unterschiedlich_orientierung_output,gefaelle_ausnahme_unterschiedlich_orientierung_jason) - self.assert_dxf_geometry_equal(gefaelle_ausnahme_unterschiedlich_orientierung_output, gefaelle_ausnahme_unterschiedlich_orientierung_reference) + gefaelle_ausnahme_unterschiedlich_orientierung = ( + "gefaelle_ausnahme_unterschiedlich_orientierung" + ) + gefaelle_ausnahme_unterschiedlich_orientierung_csv = ( + self.testordner_path + / f"{gefaelle_ausnahme_unterschiedlich_orientierung}.csv" + ) + gefaelle_ausnahme_unterschiedlich_orientierung_dxf = ( + f"{gefaelle_ausnahme_unterschiedlich_orientierung}.dxf" + ) + gefaelle_ausnahme_unterschiedlich_orientierung_json = ( + self.work_dir / f"{gefaelle_ausnahme_unterschiedlich_orientierung}.json" + ) + gefaelle_ausnahme_unterschiedlich_orientierung_output = ( + self.work_dir / gefaelle_ausnahme_unterschiedlich_orientierung_dxf + ) + gefaelle_ausnahme_unterschiedlich_orientierung_reference = ( + self.testordner_path / gefaelle_ausnahme_unterschiedlich_orientierung_dxf + ) + plant2dxf.main( + gefaelle_ausnahme_unterschiedlich_orientierung_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + gefaelle_ausnahme_unterschiedlich_orientierung_output, + gefaelle_ausnahme_unterschiedlich_orientierung_json, + ) + self.assert_dxf_geometry_equal( + gefaelle_ausnahme_unterschiedlich_orientierung_output, + gefaelle_ausnahme_unterschiedlich_orientierung_reference, + ) def test_gefaelle_einzeln_verbunden_dxf_file(self): - gefaelle_einzeln_verbunden= "gefaelle_einzeln_verbunden" - gefaelle_einzeln_verbunden_csv = self.testordner_path / f"{gefaelle_einzeln_verbunden}.csv" + gefaelle_einzeln_verbunden = "gefaelle_einzeln_verbunden" + gefaelle_einzeln_verbunden_csv = ( + self.testordner_path / f"{gefaelle_einzeln_verbunden}.csv" + ) gefaelle_einzeln_verbunden_dxf = f"{gefaelle_einzeln_verbunden}.dxf" - gefaelle_einzeln_verbunden_jason = self.work_dir /f"{gefaelle_einzeln_verbunden}.jason" - gefaelle_einzeln_verbunden_output = self.work_dir / gefaelle_einzeln_verbunden_dxf - gefaelle_einzeln_verbunden_reference = self.testordner_path / gefaelle_einzeln_verbunden_dxf - plant2dxf.main(gefaelle_einzeln_verbunden_csv , self.default_lib_path, self.cfg_path, self.allgemein_cfg_path, gefaelle_einzeln_verbunden_output,gefaelle_einzeln_verbunden_jason) - self.assert_dxf_geometry_equal(gefaelle_einzeln_verbunden_output, gefaelle_einzeln_verbunden_reference) - - - + gefaelle_einzeln_verbunden_json = ( + self.work_dir / f"{gefaelle_einzeln_verbunden}.json" + ) + gefaelle_einzeln_verbunden_output = ( + self.work_dir / gefaelle_einzeln_verbunden_dxf + ) + gefaelle_einzeln_verbunden_reference = ( + self.testordner_path / gefaelle_einzeln_verbunden_dxf + ) + plant2dxf.main( + gefaelle_einzeln_verbunden_csv, + self.default_lib_path, + self.cfg_path, + self.allgemein_cfg_path, + gefaelle_einzeln_verbunden_output, + gefaelle_einzeln_verbunden_json, + ) + self.assert_dxf_geometry_equal( + gefaelle_einzeln_verbunden_output, gefaelle_einzeln_verbunden_reference + ) if __name__ == "__main__": unittest.main() - - - \ No newline at end of file diff --git a/lib/utils.py b/lib/utils.py index daf0326..2f94004 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -14,11 +14,11 @@ def check_environment_var(env_str: str) -> Path: sys.exit(1) -def setup_logger(log_dir: Path, name: str = 'app') -> logging.Logger: +def setup_logger(log_dir: Path, name: str = "app") -> logging.Logger: """ Erstellt und konfiguriert einen Logger, der sowohl in eine Datei als auch auf die Konsole schreibt. Die Logdatei erhält einen Zeitstempel im Namen und ist UTF-8 kodiert. - + Args: log_dir (Path): Verzeichnis für die Log-Dateien name (str): Name des Loggers (z.B. 'plant2dxf', 'dxf2lib') @@ -26,6 +26,7 @@ def setup_logger(log_dir: Path, name: str = 'app') -> logging.Logger: logging.Logger: Konfigurierter Logger """ from datetime import datetime + logger = logging.getLogger(name) logger.setLevel(logging.INFO) @@ -38,7 +39,7 @@ def setup_logger(log_dir: Path, name: str = 'app') -> logging.Logger: # Logdatei mit Zeitstempel im Namen erzeugen log_file = log_dir / f"{name}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log" - file_handler = logging.FileHandler(log_file, encoding='utf-8') + file_handler = logging.FileHandler(log_file, encoding="utf-8") file_handler.setLevel(logging.INFO) # Handler für die Konsole @@ -46,11 +47,11 @@ def setup_logger(log_dir: Path, name: str = 'app') -> logging.Logger: console_handler.setLevel(logging.INFO) # Einheitliches Log-Format definieren - formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') + formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") file_handler.setFormatter(formatter) console_handler.setFormatter(formatter) # Handler dem Logger hinzufügen logger.addHandler(file_handler) logger.addHandler(console_handler) - return logger \ No newline at end of file + return logger