Files
plant2dxf/lib/Elemente/Gefaehllestrecke.py
T

206 lines
12 KiB
Python

from pydantic import BaseModel, Field, field_validator
import re
import plant2dxf
import math
from ezdxf.math import Matrix44
import block_methoden
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 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):
block_Vario_Bogen_auf = (f"Vario_Bogen_auf_3°")
block_Vario_Bogen_ab = (f"Vario_Bogen_ab_3°")
block_Vario_Bogen_auf_links = (f"Vario_Bogen_auf_3°") + "_links"
block_Vario_Bogen_ab_links = (f"Vario_Bogen_ab_3°") + "_links"
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)
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"]))
for i, wert in enumerate(Vario_Bogen_auf_Delta_SP_0):
if wert < 0:
Vario_Bogen_auf_Delta_SP_0[i] = abs(wert)
for i, wert in enumerate(Vario_Bogen_auf_Delta_SP_1):
if wert< 0:
Vario_Bogen_auf_Delta_SP_1[i] = abs(wert)
for i, wert in enumerate(Vario_Bogen_ab_Delta_SP_0):
if wert< 0:
Vario_Bogen_ab_Delta_SP_0[i] = abs(wert)
for i, wert in enumerate(Vario_Bogen_ab_Delta_SP_1):
if wert< 0:
Vario_Bogen_ab_Delta_SP_1[i] = abs(wert)
block_methoden.turn_two_blocks_left(doc, block_Vario_Bogen_auf, block_Vario_Bogen_ab, block_Vario_Bogen_ab_links, block_Vario_Bogen_auf_links)
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})
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})
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})
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})
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})
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})
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})
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})
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})
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})
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})
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})
ende [1]= ende[1] + 500
return start,ende
def hat_motor_umlenk_station (gefaelle_objekt, gefaellestrecke_nachbarn):
hat_motor_0 = None
hat_motor_1 = None
hat_umlenk_0 = None
hat_umlenk_1 = None
tefkurve_0 = None
tefkurve_1 = None
umlenk_gerade = False
motor_gerade = False
upper_hoehe_gefaehlle = gefaelle_objekt.h1
lower_hoehe_gefaehlle = gefaelle_objekt.h0
rotation = gefaelle_objekt.drehung
x = gefaelle_objekt.x
y = gefaelle_objekt.y
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")
x_angetrieben = gefaellestrecke_nachbarn.get("X_angetrieben")
y_angetrieben = gefaellestrecke_nachbarn.get("Y_angetrieben")
x_angetrieben_1 = gefaellestrecke_nachbarn.get("X_angetrieben_1")
y_angetrieben_1 = gefaellestrecke_nachbarn.get("Y_angetrieben_1")
if (kurvenrichtung == "links" and tefkurve_0 == "außen") or kurvenrichtung == "rechts" and tefkurve_0 == "innen":
tefkurve_0 = "rechts"
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:
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:
hat_motor_0 = True
else:
hat_umlenk_0 = True
else:
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)):
hat_umlenk_0 = True
umlenk_gerade = True
else:
hat_motor_0 = True
motor_gerade = True
if "Kurvenrichtung_1" in gefaellestrecke_nachbarn:
vario_hoehe_0_1 = float(gefaellestrecke_nachbarn.get("vario_hoehe_0_1"))
vario_hoehe_1_1 = float(gefaellestrecke_nachbarn.get("vario_hoehe_1_1"))
kurvenrichtung_1 = gefaellestrecke_nachbarn.get("Kurvenrichtung_1")
tefkurve_1 = gefaellestrecke_nachbarn.get("Tefkurve_1")
if (kurvenrichtung_1 == "links" and tefkurve_1 == "außen") or kurvenrichtung_1 == "rechts" and tefkurve_1 == "innen":
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:
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:
hat_motor_1 = True
else:
hat_umlenk_1 = True
else:
rotation_zwischen = rotation
if rotation_zwischen == 0.0:
rotation_zwischen = -360.0
if (((-360.0<= rotation_zwischen< -270.0)and y > y_angetrieben_1) or ((-90.0< rotation< 0.0)and y > y_angetrieben_1) or
((-270.0< rotation_zwischen< -90.0)and y < y_angetrieben) or
(rotation == -90.0 and x < x_angetrieben_1) or ((rotation == -270.0)and x<x_angetrieben_1)):
hat_umlenk_1 = True
umlenk_gerade = True
else:
hat_motor_1 = True
motor_gerade = True
hat_zusatz ={}
hat_zusatz["hat_motor_0"] = hat_motor_0
hat_zusatz["hat_motor_1"] = hat_motor_1
hat_zusatz["hat_umlenk_0"] = hat_umlenk_0
hat_zusatz["hat_umlenk_1"] = hat_umlenk_1
hat_zusatz["tefkurve_0"] = tefkurve_0
hat_zusatz["tefkurve_1"] = tefkurve_1
hat_zusatz["umlenk_gerade"] = umlenk_gerade
hat_zusatz["motor_gerade"] = motor_gerade
return hat_zusatz