From a2cdc4e87b485cdb49a002ed847c00439152884a Mon Sep 17 00:00:00 2001 From: Michael Stangl Date: Fri, 8 May 2026 14:36:42 +0200 Subject: [PATCH] Omniflo Weichen Interface gebaut --- Lisp/OmniModulInsert.lsp | 327 +++++++++++++++++++++++++++++++++++---- lib/testpycall.py | 29 ++++ 2 files changed, 328 insertions(+), 28 deletions(-) create mode 100644 lib/testpycall.py diff --git a/Lisp/OmniModulInsert.lsp b/Lisp/OmniModulInsert.lsp index f4d09f8..f338803 100644 --- a/Lisp/OmniModulInsert.lsp +++ b/Lisp/OmniModulInsert.lsp @@ -569,78 +569,349 @@ (princ) ) +;; ============================================================ +;; OMNIFLO WEICHEN-DIALOG +;; Generischer Dialog fuer Weichen-Auswahl nach Winkel/Typ +;; mit Filter fuer Schaltungstyp und Richtung +;; ============================================================ + + +;; --- Aktuelle Filterwerte aus Radio-Buttons lesen --- +(defun omni:weichen-get-filter ( / sch ri) + (setq sch "alle") + (if (= (get_tile "sch_m") "1") (setq sch "M")) + (if (= (get_tile "sch_p") "1") (setq sch "P")) + (setq ri "alle") + (if (= (get_tile "ri_links") "1") (setq ri "1")) + (if (= (get_tile "ri_rechts") "1") (setq ri "2")) + (list sch ri) +) + + +;; --- Gefilterte Weichen-Liste aufbauen --- +;; basis-liste = alle Weichen fuer den gewaehlten Winkel/Typ +;; sch-filter = "M", "P" oder "alle" +;; ri-filter = "1", "2" oder "alle" +(defun omni:weichen-filter-liste (basis-liste sch-filter ri-filter / eintrag sch kr ergebnis) + (setq ergebnis nil) + (foreach eintrag basis-liste + (setq sch (cdr (assoc "Schaltungstyp" eintrag))) + (setq kr (cdr (assoc "KurvenRichtung" eintrag))) + (if (and + (or (= sch-filter "alle") (= sch sch-filter)) + (or (= ri-filter "alle") + (= (omni:sivasid-to-str kr) ri-filter)) + ) + (setq ergebnis (cons eintrag ergebnis)) + ) + ) + (reverse ergebnis) +) + + +;; --- Dropdown mit gefilterter Liste neu befuellen --- +(defun omni:weichen-dlg-refresh ( / filter sch-f ri-f gefiltert profil-liste) + (setq filter (omni:weichen-get-filter)) + (setq sch-f (car filter)) + (setq ri-f (cadr filter)) + (setq gefiltert (omni:weichen-filter-liste *OMNI-DLG-WEICHEN-BASIS* sch-f ri-f)) + (setq *OMNI-DLG-WEICHEN* gefiltert) + + ;; Dropdown neu befuellen + (setq profil-liste + (mapcar '(lambda (e) (cdr (assoc "ProfilTyp" e))) gefiltert)) + (start_list "profiltyp") + (mapcar 'add_list profil-liste) + (end_list) + + ;; Ersten Eintrag anzeigen (falls vorhanden) + (if gefiltert + (progn + (set_tile "profiltyp" "0") + (omni:weichen-dlg-update "0") + ) + (progn + (set_tile "val_sivasnr" "---") + (set_tile "val_winkel" "---") + (set_tile "val_breite" "---") + (set_tile "val_laenge" "---") + ) + ) +) + + +;; --- Detail-Felder im Weichen-Dialog aktualisieren --- +(defun omni:weichen-dlg-update (idx-str / idx eintrag wkl) + (setq idx (atoi idx-str)) + (setq eintrag (nth idx *OMNI-DLG-WEICHEN*)) + (if eintrag + (progn + (set_tile "val_sivasnr" + (omni:sivasid-to-str (omni:val eintrag "Sivasnr"))) + (setq wkl (omni:val eintrag "KurvenWinkel")) + (set_tile "val_winkel" + (if (= (type wkl) 'INT) (strcat (itoa wkl) " Grad") + (strcat (rtos wkl 2 1) " Grad") + ) + ) + (set_tile "val_breite" + (itoa (fix (omni:val eintrag "Breite")))) + (set_tile "val_laenge" + (itoa (fix (omni:val eintrag "Länge")))) + ) + ) +) + + +;; --- Weichen-Auswahl-Dialog oeffnen --- +;; winkel = KurvenWinkel (90, 45, 0, 22.5) +;; weichentyp = "Einzelweiche", "Doppelweiche", "Dreiwegeweiche" oder nil fuer alle +;; Rueckgabe: gewaehlter Weichen-Eintrag (alist) oder nil bei Abbruch +(defun omni:weichen-dialog (winkel weichentyp / dcl-pfad dat basis-liste + profil-liste ergebnis) + (if (null *OMNI-WEICHEN*) (omni:load-data)) + + ;; Weichen nach Winkel filtern (nil = alle Winkel) + (if winkel + (setq basis-liste (omni:filter *OMNI-WEICHEN* "KurvenWinkel" winkel)) + (setq basis-liste *OMNI-WEICHEN*) + ) + + ;; Optional nach WeichenTyp filtern + (if weichentyp + (setq basis-liste + (vl-remove-if-not + '(lambda (e) (= (cdr (assoc "WeichenTyp" e)) weichentyp)) + basis-liste)) + ) + + (if (null basis-liste) + (progn + (alert (strcat "Keine Weichen fuer " + (cond + ((null winkel) "alle Winkel") + ((= (type winkel) 'INT) (strcat (itoa winkel) " Grad")) + (T (strcat (rtos winkel 2 1) " Grad")) + ) + (if weichentyp (strcat " / " weichentyp) "") + " gefunden.")) + nil + ) + (progn + ;; Basis-Liste und gefilterte Liste in globalen Variablen speichern + (setq *OMNI-DLG-WEICHEN-BASIS* basis-liste) + (setq *OMNI-DLG-WEICHEN* basis-liste) + + ;; ProfilTyp-Liste fuer Dropdown aufbauen + (setq profil-liste + (mapcar '(lambda (e) (cdr (assoc "ProfilTyp" e))) basis-liste)) + + ;; DCL laden + (setq dcl-pfad (strcat (getenv "DXFM_DCL") "/omniflo_weichen.dcl")) + (setq dat (load_dialog dcl-pfad)) + (if (not (new_dialog "omniflo_weichen" dat)) + (progn (alert "Weichen-Dialog konnte nicht geladen werden.") nil) + (progn + ;; Dropdown befuellen + (start_list "profiltyp") + (mapcar 'add_list profil-liste) + (end_list) + (set_tile "profiltyp" "0") + + ;; Startwerte anzeigen + (omni:weichen-dlg-update "0") + + ;; Callback bei Dropdown-Aenderung + (action_tile "profiltyp" "(omni:weichen-dlg-update $value)") + + ;; Callbacks fuer Filter-Radio-Buttons (alle loesen Refresh aus) + (action_tile "sch_alle" "(omni:weichen-dlg-refresh)") + (action_tile "sch_m" "(omni:weichen-dlg-refresh)") + (action_tile "sch_p" "(omni:weichen-dlg-refresh)") + (action_tile "ri_alle" "(omni:weichen-dlg-refresh)") + (action_tile "ri_links" "(omni:weichen-dlg-refresh)") + (action_tile "ri_rechts" "(omni:weichen-dlg-refresh)") + + ;; OK/Abbrechen + (action_tile "accept" + "(setq ergebnis (atoi (get_tile \"profiltyp\"))) (done_dialog 1)") + (action_tile "cancel" "(done_dialog 0)") + + (start_dialog) + (unload_dialog dat) + + ;; Gewaehlten Eintrag zurueckgeben + (if ergebnis + (nth ergebnis *OMNI-DLG-WEICHEN*) + nil + ) + ) + ) + ) + ) +) + + +;; ============================================================ +;; OMNIFLO WEICHEN-BEFEHLE +;; ============================================================ + ;; --- Omniflo / Weiche 90 Grad --- -(defun c:OMNI_W90_Einfach () - (princ "\n[DUMMY] Einfach 90 700/700 links M (834372027)") +(defun c:OMNI_W90_Einfach ( / eintrag) + (setq eintrag (omni:weichen-dialog 90 "Einzelweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_W90_Doppel () - (princ "\n[DUMMY] Doppel 90 700/700 M (834372109)") +(defun c:OMNI_W90_Doppel ( / eintrag) + (setq eintrag (omni:weichen-dialog 90 "Doppelweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_W90_Dreiwege () - (princ "\n[DUMMY] Dreiwege 90 700/700 M (834372209)") +(defun c:OMNI_W90_Dreiwege ( / eintrag) + (setq eintrag (omni:weichen-dialog 90 "Dreiwegeweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) ;; --- Omniflo / Weiche 45 Grad --- -(defun c:OMNI_W45_Einfach () - (princ "\n[DUMMY] Einfach 45 350/700 links M (834372001)") +(defun c:OMNI_W45_Einfach ( / eintrag) + (setq eintrag (omni:weichen-dialog 45 "Einzelweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_W45_Doppel () - (princ "\n[DUMMY] Doppel 45 350/700 M (834372100)") +(defun c:OMNI_W45_Doppel ( / eintrag) + (setq eintrag (omni:weichen-dialog 45 "Doppelweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_W45_Dreiwege () - (princ "\n[DUMMY] Dreiwege 45 350/700 M (834372200)") +(defun c:OMNI_W45_Dreiwege ( / eintrag) + (setq eintrag (omni:weichen-dialog 45 "Dreiwegeweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) ;; --- Omniflo / Weichen Parallel --- -(defun c:OMNI_WP_Einfach () - (princ "\n[DUMMY] Einfach Parallel 200/750 links M (834372047)") +(defun c:OMNI_WP_Einfach ( / eintrag) + (setq eintrag (omni:weichen-dialog 0 "Einzelweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_WP_Doppel () - (princ "\n[DUMMY] Doppel Parallel 200/750 M (834372115)") +(defun c:OMNI_WP_Doppel ( / eintrag) + (setq eintrag (omni:weichen-dialog 0 "Doppelweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_WP_Dreiwege () - (princ "\n[DUMMY] Dreiwege Parallel 200/750 M (834372215)") +(defun c:OMNI_WP_Dreiwege ( / eintrag) + (setq eintrag (omni:weichen-dialog 0 "Dreiwegeweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) ;; --- Omniflo / Weichenkoerper --- -(defun c:OMNI_WK_Einfach () - (princ "\n[DUMMY] Weichenkoerper Einfach 22.5 links M (834342011)") +(defun c:OMNI_WK_Einfach ( / eintrag) + (setq eintrag (omni:weichen-dialog 22.5 "Einzelweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_WK_Doppel () - (princ "\n[DUMMY] Weichenkoerper Doppel 22.5 M (834342100)") +(defun c:OMNI_WK_Doppel ( / eintrag) + (setq eintrag (omni:weichen-dialog 22.5 "Doppelweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_WK_Dreiwege () - (princ "\n[DUMMY] Weichenkoerper Dreiwege 22.5 M (834342200)") +(defun c:OMNI_WK_Dreiwege ( / eintrag) + (setq eintrag (omni:weichen-dialog 22.5 "Dreiwegeweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) ;; --- Omniflo / Weichenkombinationen --- -(defun c:OMNI_WKomb_Delta () - (princ "\n[DUMMY] Delta 1400/700 M (834372400)") +(defun c:OMNI_WKomb_Delta ( / eintrag) + (setq eintrag (omni:weichen-dialog nil "Deltaweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) -(defun c:OMNI_WKomb_Star () - (princ "\n[DUMMY] Star 1400/1400 M (834372420)") +(defun c:OMNI_WKomb_Star ( / eintrag) + (setq eintrag (omni:weichen-dialog nil "Sternweiche")) + (if eintrag + (princ (strcat "\n[WEICHE] Gewaehlt: " + (omni:val eintrag "ProfilTyp") " (SivasNr: " + (omni:sivasid-to-str (omni:val eintrag "Sivasnr")) ")")) + (princ "\n[WEICHE] Abgebrochen.") + ) (princ) ) diff --git a/lib/testpycall.py b/lib/testpycall.py new file mode 100644 index 0000000..fe4b29a --- /dev/null +++ b/lib/testpycall.py @@ -0,0 +1,29 @@ +"""testpycall.py - Testskript fuer LISP-Python-Aufruf.""" + +import os +import sys +from datetime import datetime + + +def main(): + if len(sys.argv) > 1: + log_dir = sys.argv[1] + else: + log_dir = os.getenv("DXFM_LOG", ".") + + os.makedirs(log_dir, exist_ok=True) + log_file = os.path.join(log_dir, "testpycall.log") + return_file = os.path.join(log_dir, "testpycall_return.txt") + + timestamp = datetime.now().strftime("%y%m%d-%H:%M:%S") + + message = f"{timestamp} - been called from BricsCAD LISP via CALLPYTHON\n" + with open(log_file, "a", encoding="utf-8") as f: + f.write(message) + + with open(return_file, "w", encoding="utf-8") as f: + f.write(timestamp) + + +if __name__ == "__main__": + main()