from pydantic import BaseModel, Field, field_validator import math import plant2dxf from ezdxf.math import Matrix44 class Gefaellestrecke(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") h0: float = Field(description="Höhe Unten in Merkmale") h1: float = Field(description="Höhe Oben in Merkmale") drehung: float = Field(default=0.0, description="Drehung an z achse") 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) @classmethod def from_merkmale(cls, teileid: str, x: float, y: float, merkmale: dict) -> 'Gefaellestrecke': h0 = float(merkmale.get("Höhe unten")) * 1000 h1 = float(merkmale.get("Höhe oben")) * 1000 laenge = float(merkmale.get("Länge in Meter")) * 1000 return cls( teileid = teileid, laenge = laenge, x = x, y = y, h0 = h0, h1 =h1, drehung = float(merkmale.get("Drehung")), anzahl_scanner = int(merkmale.get("Anzahl der Scanner")), anzahl_separatoren = int(merkmale.get("Anzahl der Separatoren")) ) def hat_motor_umlenk_station (doc, lib_doc, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, gefaellestrecke_nachbarn): hat_motor_0 = None hat_motor_1 = None hat_umlenk_0 = None hat_umlenk_1 = None tefkurve_0 = None tefkurve_1 = None if "Kurvenrichtung" in gefaellestrecke_nachbarn: vario_hoehe_0 = float(gefaellestrecke_nachbarn.get("vario_hoehe_0")) vario_hoehe_1 = float(gefaellestrecke_nachbarn.get("vario_hoehe_1")) kurvenrichtung = gefaellestrecke_nachbarn.get("Kurvenrichtung") tefkurve_0 = gefaellestrecke_nachbarn.get("Tefkurve") if (kurvenrichtung == "links" and tefkurve_0 == "Aussen") or kurvenrichtung == "rechts" and tefkurve_0 == "Innen": tefkurve_0 = "links" else: tefkurve_0 = "rechts" block_Vario_Umlenkstation_500mm ="Vario_Umlenkstation_500mm" block_Vario_Motorstation_500mm = "Vario_Motorstation_500mm" blockname_motor_links = block_Vario_Motorstation_500mm +"links" blockname_umlenk_links = block_Vario_Umlenkstation_500mm + "links" plant2dxf.import_block(block_Vario_Umlenkstation_500mm,lib_doc,doc) plant2dxf.import_block(block_Vario_Motorstation_500mm,lib_doc,doc) block_Vario_Umlenkstation_500mm =plant2dxf.dreh_block(block_Vario_Umlenkstation_500mm,doc,lib_doc,math.radians(3)) block_Vario_Motorstation_500mm =plant2dxf.dreh_block(block_Vario_Motorstation_500mm,doc,lib_doc,math.radians(3)) if blockname_motor_links not in doc.blocks: matrix = Matrix44.scale(1,-1,1) block_motor_links = doc.blocks.new(name=blockname_motor_links,base_point=(0,0,0)) block_umlenk_links = doc.blocks.new(name=blockname_umlenk_links,base_point=(0,0,0)) block_motor_rechts = doc.blocks[block_Vario_Motorstation_500mm] block_umlenk_rechts = doc.blocks[block_Vario_Umlenkstation_500mm] for e in block_motor_rechts: copy = e.copy() copy.transform(matrix) block_motor_links.add_entity(copy) for e in block_umlenk_rechts: copy = e.copy() copy.transform(matrix) block_umlenk_links.add_entity(copy) if upper_hoehe_gefaehlle > lower_hoehe_gefaehlle: if vario_hoehe_0 == upper_hoehe_gefaehlle or vario_hoehe_1 == upper_hoehe_gefaehlle: hat_motor_0 = True else: hat_umlenk_0 = True if upper_hoehe_gefaehlle < lower_hoehe_gefaehlle: if vario_hoehe_0 == lower_hoehe_gefaehlle or vario_hoehe_1 == lower_hoehe_gefaehlle: hat_motor_0 = True else: hat_umlenk_0 = True if "Kurvenrichtung_1" in gefaellestrecke_nachbarn: vario_hoehe_0_1 = float(gefaellestrecke_nachbarn.get("vario_hoehe_0_1")) * 1000 vario_hoehe_1_1 = float(gefaellestrecke_nachbarn.get("vario_hoehe_1_1")) * 1000 kurvenrichtung_1 = gefaellestrecke_nachbarn.get("Kurvenrichtung_1") tefkurve_1 = gefaellestrecke_nachbarn.get("Tefkurve_1") if (kurvenrichtung_1 == "links" and tefkurve_1 == "Aussen") or kurvenrichtung_1 == "rechts" and tefkurve_1 == "Innen": tefkurve_0 = "links" else: tefkurve_0 = "rechts" if upper_hoehe_gefaehlle > lower_hoehe_gefaehlle: if vario_hoehe_0_1 == upper_hoehe_gefaehlle or vario_hoehe_1_1 == upper_hoehe_gefaehlle: hat_motor_1 = True else: hat_umlenk_1 = True if upper_hoehe_gefaehlle < lower_hoehe_gefaehlle: if vario_hoehe_0_1 == lower_hoehe_gefaehlle or vario_hoehe_1_1 == lower_hoehe_gefaehlle: hat_motor_1 = True else: hat_umlenk_1 = True return hat_motor_0,hat_umlenk_0,hat_motor_1,hat_umlenk_1, tefkurve_0, tefkurve_1