refectoring von omniflo

This commit is contained in:
2025-12-08 14:21:14 +01:00
parent 9bb174b621
commit b4d8632fdf
2 changed files with 118 additions and 85 deletions
+95
View File
@@ -0,0 +1,95 @@
from ezdxf.entities import Line
import math
from pydantic import BaseModel, Field, field_validator
from typing import Optional
import plant2dxf
class Omniflo(BaseModel):
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")
@classmethod
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
except Exception:
laenge = 0
try:
winkel = float(merkmale.get("Drehung"))
except Exception:
winkel = 0.0
try:
hoehe = float(merkmale.get("Höhe"))
except Exception:
hoehe = 0.0
try:
h0 = float(merkmale.get("Höhe unten"))
except Exception:
h0 = 0.0
try:
h1 = float(merkmale.get("Höhe oben"))
except Exception:
h1 = 0.0
return cls(
teileid= teileid,
x=x,
y=y,
sivasnummer = sivasnummer,
laenge = laenge,
drehung = winkel,
hoehe = hoehe,
h0 = h0,
h1 = h1
)
def Omniflo_geraden_erstellung(msp, x, y, doc, tefsivas, omniflo_objekt):
winkel_rad = math.radians(omniflo_objekt.drehung)
halbe_laenge = omniflo_objekt.laenge / 2
# 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)
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)
if omniflo_objekt.sivasnummer == tefsivas:
linie.dxf.layer = "F-1"
else:
linie.dxf.layer = "A-2"
def omniflo_foerdererstellung(msp, x, y, doc, lib_doc, omniflo_objekt, rotation):
plant2dxf.import_block("bogen1",lib_doc,doc)
plant2dxf.import_block("bogen2",lib_doc,doc)
laenge = omniflo_objekt.laenge
h0 = omniflo_objekt.h0
h1 = omniflo_objekt.h1
h_zwischen = (h0 + h1)/2
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
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)
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})
copy = line.copy()
copy.translate(-x,-y,-h_zwischen)
block.add_entity(copy)
msp.add_blockref(blockname,(x,y,h_zwischen),dxfattribs={"rotation": rotation})
+23 -85
View File
@@ -21,7 +21,7 @@ import math
from pydantic import BaseModel, Field, field_validator
from typing import Optional
from utils import check_environment_var, setup_logger
from Elemente import Kreisel, VarioFoerderer,Gefaehllestrecke,Angetriebene_Kurve,Bt_element
from Elemente import Kreisel, VarioFoerderer,Gefaehllestrecke,Angetriebene_Kurve,Bt_element,Omniflo
import as_es_methoden
@@ -1255,14 +1255,7 @@ def handle_bt___entladung(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, s
import_block(blockname,lib_doc,doc)
msp.add_blockref(blockname,(x,y,hight),dxfattribs={"rotation": rotation})
class Omniflo(BaseModel):
teileid:str
sivasnummer:str
laenge: Optional [float]
drehung: float
hoehe : Optional[float]
h0: Optional[float] = Field(description="Höhe unten im CSV")
h0: Optional[float] = Field(description="Höhe Oben im CSV")
def handle_omniflo(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols, strecken_nachbarn,config,config_allgemein):
"""
Für Omniflo Gerade: zeichnet eine Linie (Mitte = Koordinate, Länge und Winkel aus Merkmale).
@@ -1272,84 +1265,29 @@ def handle_omniflo(msp, teileid, merkmale, x, y, doc, lib_doc, verbose, symbols,
omnisivas = config.get("Omniflo","OFgeradesivas")
tefsivas = config.get("Omniflo","Tefgeradesivas")
foerderer = config.get("Omniflo","OFfoerderer")
if merkmale.get("SivasNummer") == omnisivas or merkmale.get("SivasNummer") == tefsivas:
try:
laenge = float(merkmale.get("Länge in Meter", "0").replace(",", ".")) * 1000 # Meter → mm
except Exception:
laenge = 0
try:
winkel = float(merkmale.get("Drehung"))
except Exception:
winkel = 0.0
winkel_rad = math.radians(winkel)
halbe_laenge = laenge / 2
# 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, float(merkmale.get("Höhe oben")) )
ende = (x - dx, y - dy, float(merkmale.get("Höhe unten")))
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)
if merkmale.get("SivasNummer") == tefsivas:
linie.dxf.layer = "F-1"
else:
linie.dxf.layer = "A-2"
if verbose:
print(f"[INFO] Omniflo Gerade → {teileid} Linie von ({start[0]:.1f}, {start[1]:.1f}) nach ({ende[0]:.1f}, {ende[1]:.1f})")
return
omniflo_objekt = Omniflo.Omniflo.from_merkmale(teileid,x,y,merkmale)
rotation = omniflo_objekt.drehung
if omniflo_objekt.sivasnummer == omnisivas or omniflo_objekt.sivasnummer == tefsivas:
Omniflo.Omniflo.Omniflo_geraden_erstellung(msp, x, y, doc, tefsivas, omniflo_objekt)
if merkmale.get("SivasNummer") == foerderer:
import_block("bogen1",lib_doc,doc)
import_block("bogen2",lib_doc,doc)
rotation = float(merkmale.get("Drehung"))
laenge = float(merkmale.get("laenge in meter")) * 1000
h0 = float(merkmale.get("Höhe unten"))
h1 = float(merkmale.get("Höhe oben"))
h_zwischen = (h0 + h1)/2
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
dx = halbe_laenge * math.sin(rotation * -1)
dy = halbe_laenge * math.cos(rotation)
start = (x + dx, y + dy, float(merkmale.get("Höhe oben")) )
ende = (x - dx, y - dy, float(merkmale.get("Höhe unten")))
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})
copy = line.copy()
copy.translate(-x,-y,-h_zwischen)
block.add_entity(copy)
msp.add_blockref(blockname,(x,y,h_zwischen),dxfattribs={"rotation": rotation})
return
elif omniflo_objekt.sivasnummer == foerderer:
Omniflo.Omniflo.omniflo_foerdererstellung(msp, x, y, doc, lib_doc, omniflo_objekt, rotation)
# Sonst wie gehabt: Block mit SivasNummer
if not lib_doc:
print("[WARN] lib_doc nicht verfügbar, Block wird nicht eingefügt.")
return
blockname = merkmale.get("SivasNummer")
if not blockname:
print(f"[WARN] Keine SivasNummer für {teileid}, überspringe.")
return
if blockname not in lib_doc.blocks:
print(f"[WARN] Omniflo-Block '{blockname}' nicht in Bibliothek {lib_doc.filename}. Überspringe {teileid}.")
return
blockname = blockname
drehung = merkmale.get("Drehung")
import_block(blockname, lib_doc, doc)
# blockref_layer = get_layer(doc, lib_doc, blockname)
drehung = merkmale.get("Drehung")
msp.add_blockref(blockname, (x, y,float(merkmale.get("Höhe"))), dxfattribs={"rotation": drehung})
else:
if not lib_doc:
print("[WARN] lib_doc nicht verfügbar, Block wird nicht eingefügt.")
return
blockname = merkmale.get("SivasNummer")
if not blockname:
print(f"[WARN] Keine SivasNummer für {teileid}, überspringe.")
return
if blockname not in lib_doc.blocks:
print(f"[WARN] Omniflo-Block '{blockname}' nicht in Bibliothek {lib_doc.filename}. Überspringe {teileid}.")
return
blockname = blockname
import_block(blockname, lib_doc, doc)
layer, color = 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})
def get_insert_color_layer(lib_doc, blockname):