116 lines
4.3 KiB
Python
116 lines
4.3 KiB
Python
|
|
from ezdxf.entities import Line
|
|
import math
|
|
from pydantic import BaseModel, Field, field_validator
|
|
from typing import Optional
|
|
import plant2dxf
|
|
import block_methoden
|
|
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")
|
|
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)
|
|
@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
|
|
try:
|
|
anzahl_scanner = float(merkmale.get("Anzahl der Scanner", "0"))
|
|
except Exception:
|
|
anzahl_scanner = 0
|
|
try:
|
|
anzahl_separatoren = float(merkmale.get("Anzahl der Separatoren", "0"))
|
|
except Exception:
|
|
anzahl_separatoren = 0
|
|
return cls(
|
|
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
|
|
)
|
|
def Omniflo_geraden_erstellung(msp, doc, tefsivas, omniflo_objekt):
|
|
"""Erstellung der Tef gerade und Omniflo gerade"""
|
|
winkel_rad = math.radians(omniflo_objekt.drehung)
|
|
halbe_laenge = omniflo_objekt.laenge / 2
|
|
x = omniflo_objekt.x
|
|
y = omniflo_objekt.y
|
|
# 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, 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)
|
|
x = omniflo_objekt.x
|
|
y = omniflo_objekt.y
|
|
rotation = omniflo_objekt.drehung
|
|
laenge = omniflo_objekt.laenge
|
|
h0 = omniflo_objekt.h0
|
|
h1 = omniflo_objekt.h1
|
|
h_zwischen = omniflo_objekt.hight_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
|
|
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})
|
|
|