Omniflo Boegen und Weichen auch durch .py erzeugen und ändern.
This commit is contained in:
@@ -10,11 +10,13 @@ import PyRx as Rx
|
||||
import PyGe as Ge
|
||||
import PyDb as Db
|
||||
import PyEd as Ed
|
||||
import wx
|
||||
|
||||
from elemente.utils import (
|
||||
get_block_path,
|
||||
component_next_number,
|
||||
merge_attribs,
|
||||
read_block_attribs,
|
||||
ensure_block_from_dwg,
|
||||
create_attrib_defs,
|
||||
insert_block_with_attribs,
|
||||
@@ -178,3 +180,126 @@ def ils_eckrad():
|
||||
# 5. Einfuegen
|
||||
insert_pt = Ge.Point3d(center_x, center_y, hoehe)
|
||||
insert_eckrad(db, insert_pt, rotation)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Eckrad bearbeiten (wx-Dialog)
|
||||
# ============================================================
|
||||
|
||||
class EckradEditDialog(wx.Dialog):
|
||||
"""Dialog zum Bearbeiten eines bestehenden Eckrads."""
|
||||
|
||||
def __init__(self, parent, attribs):
|
||||
super().__init__(parent, title="Eckrad bearbeiten",
|
||||
size=(320, 220),
|
||||
style=wx.DEFAULT_DIALOG_STYLE)
|
||||
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
# Name (readonly)
|
||||
row_name = wx.BoxSizer(wx.HORIZONTAL)
|
||||
row_name.Add(wx.StaticText(panel, label="Name:"), 0,
|
||||
wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
|
||||
self.txt_name = wx.TextCtrl(panel, value=attribs.get("NAME", ""),
|
||||
size=(180, -1), style=wx.TE_READONLY)
|
||||
row_name.Add(self.txt_name, 1)
|
||||
sizer.Add(row_name, 0, wx.EXPAND | wx.ALL, 5)
|
||||
|
||||
# Drehrichtung
|
||||
row_dreh = wx.BoxSizer(wx.HORIZONTAL)
|
||||
row_dreh.Add(wx.StaticText(panel, label="Drehrichtung:"), 0,
|
||||
wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
|
||||
self.cb_drehrichtung = wx.Choice(panel, choices=["UZS", "GUZ"])
|
||||
self.cb_drehrichtung.SetSelection(
|
||||
1 if attribs.get("DREHRICHTUNG") == "GUZ" else 0)
|
||||
row_dreh.Add(self.cb_drehrichtung, 0)
|
||||
sizer.Add(row_dreh, 0, wx.EXPAND | wx.ALL, 5)
|
||||
|
||||
# Hoehe
|
||||
row_hoehe = wx.BoxSizer(wx.HORIZONTAL)
|
||||
row_hoehe.Add(wx.StaticText(panel, label="Hoehe (mm):"), 0,
|
||||
wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
|
||||
self.txt_hoehe = wx.TextCtrl(panel, value=attribs.get("HOEHE", "0"),
|
||||
size=(80, -1))
|
||||
row_hoehe.Add(self.txt_hoehe, 0)
|
||||
sizer.Add(row_hoehe, 0, wx.EXPAND | wx.ALL, 5)
|
||||
|
||||
# OK / Cancel
|
||||
btn_sizer = self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL)
|
||||
sizer.Add(btn_sizer, 0, wx.EXPAND | wx.ALL, 10)
|
||||
|
||||
panel.SetSizer(sizer)
|
||||
self.Fit()
|
||||
self.CenterOnScreen()
|
||||
|
||||
def get_values(self):
|
||||
"""Dialog-Werte als dict zurueckgeben."""
|
||||
return {
|
||||
"drehrichtung": "GUZ" if self.cb_drehrichtung.GetSelection() == 1 else "UZS",
|
||||
"hoehe": self.txt_hoehe.GetValue(),
|
||||
}
|
||||
|
||||
|
||||
def eckrad_edit_entity(db, ent_id):
|
||||
"""Eckrad per wxPython-Dialog bearbeiten (fuer eine bestimmte Entity-ID).
|
||||
|
||||
Wird von EckradEdit und SSG_BLOCKEDIT aufgerufen.
|
||||
"""
|
||||
bref = Db.BlockReference(ent_id, Db.OpenMode.kForRead)
|
||||
attribs = read_block_attribs(bref)
|
||||
base_point = bref.position()
|
||||
rotation_deg = math.degrees(bref.rotation())
|
||||
|
||||
# HOEHE aus Z-Koordinate
|
||||
if base_point.z > 0:
|
||||
attribs["HOEHE"] = f"{base_point.z:.0f}"
|
||||
|
||||
print(f"\n-> Bestehend: Name={attribs.get('NAME', '?')}"
|
||||
f" Drehrichtung={attribs.get('DREHRICHTUNG', '?')}"
|
||||
f" Hoehe={attribs.get('HOEHE', '?')}")
|
||||
|
||||
dlg = EckradEditDialog(None, attribs)
|
||||
result = dlg.ShowModal()
|
||||
|
||||
if result == wx.ID_OK:
|
||||
new_values = dlg.get_values()
|
||||
dlg.Destroy()
|
||||
|
||||
attribs["DREHRICHTUNG"] = new_values["drehrichtung"]
|
||||
attribs["HOEHE"] = new_values["hoehe"]
|
||||
|
||||
new_hoehe = float(new_values["hoehe"])
|
||||
|
||||
# Alten Block loeschen
|
||||
bref.upgradeOpen()
|
||||
bref.erase()
|
||||
|
||||
# Neu einfuegen
|
||||
insert_pt = Ge.Point3d(base_point.x, base_point.y, new_hoehe)
|
||||
insert_eckrad(db, insert_pt, rotation_deg, attribs)
|
||||
|
||||
print(f"\nEckrad aktualisiert: Drehrichtung={new_values['drehrichtung']}"
|
||||
f" Hoehe={new_values['hoehe']}")
|
||||
else:
|
||||
dlg.Destroy()
|
||||
print("\nAbgebrochen.")
|
||||
|
||||
|
||||
@Rx.command("EckradEdit")
|
||||
def cmd_eckrad_edit():
|
||||
"""EckradEdit: Bestehenden Eckrad per wxPython-Dialog bearbeiten."""
|
||||
ed = Ed.Editor()
|
||||
db = Db.HostApplicationServices().workingDatabase()
|
||||
|
||||
res = ed.entSel("\nEckrad-Block auswaehlen: ")
|
||||
if res[0] != Ed.PromptStatus.eOk:
|
||||
return
|
||||
ent_id = res[1]
|
||||
|
||||
ent = Db.Entity(ent_id, Db.OpenMode.kForRead)
|
||||
if not ent.isKindOf(Db.BlockReference.desc()):
|
||||
print("\nKein Block ausgewaehlt!")
|
||||
return
|
||||
|
||||
eckrad_edit_entity(db, ent_id)
|
||||
|
||||
Reference in New Issue
Block a user