Merge branch 'master' into SuperChayan

This commit is contained in:
stefan schippers 2025-03-23 15:30:18 +01:00
commit 936b7157f5
3 changed files with 294 additions and 289 deletions

View File

@ -4130,7 +4130,8 @@ static void handle_key_press(int event, KeySym key, int state, int rstate, int m
} }
static void handle_button_press(int event, int state, int rstate, KeySym key, int button, int mx, int my, static void handle_button_press(int event, int state, int rstate, KeySym key, int button, int mx, int my,
double c_snap, int draw_xhair, int crosshair_size, int enable_stretch, int aux) double c_snap, int draw_xhair, int crosshair_size,
int enable_stretch, int cadence_compat, int aux)
{ {
int use_cursor_for_sel = tclgetintvar("use_cursor_for_selection"); int use_cursor_for_sel = tclgetintvar("use_cursor_for_selection");
int excl = xctx->ui_state & (STARTWIRE | STARTRECT | STARTLINE | STARTPOLYGON | STARTARC); int excl = xctx->ui_state & (STARTWIRE | STARTRECT | STARTLINE | STARTPOLYGON | STARTARC);
@ -4270,10 +4271,10 @@ static void handle_button_press(int event, int state, int rstate, KeySym key, in
} }
#endif #endif
/* In *NON* intuitive interface a button1 press with no modifiers will /* In *NON* intuitive interface (or cadence compatibility)
* first unselect everything... * a button1 press with no modifiers will first unselect everything...
* For intuitive interface unselection see below... */ * For intuitive interface unselection see below... */
if(!xctx->intuitive_interface && no_shift_no_ctrl ) unselect_all(1); if((cadence_compat || !xctx->intuitive_interface) && no_shift_no_ctrl) unselect_all(1);
/* find closest object. Use snap coordinates if full crosshair is enabled /* find closest object. Use snap coordinates if full crosshair is enabled
* since the mouse pointer is obscured and crosshair is snapped to grid points */ * since the mouse pointer is obscured and crosshair is snapped to grid points */
@ -4524,78 +4525,22 @@ static void handle_double_click(int event, int state, KeySym key, int button,
} }
/* main window callback */ static void update_statusbar(int persistent_command, int wire_draw_active)
/* mx and my are set to the mouse coord. relative to window */
/* win_path: set to .drw or sub windows .x1.drw, .x2.drw, ... */
int callback(const char *win_path, int event, int mx, int my, KeySym key,
int button, int aux, int state)
{ {
char str[PATH_MAX + 100];
int redraw_only;
double c_snap;
#ifndef __unix__
short cstate = GetKeyState(VK_CAPITAL);
short nstate = GetKeyState(VK_NUMLOCK);
#else
XKeyboardState kbdstate;
#endif
int enable_stretch = tclgetboolvar("enable_stretch");
int draw_xhair = tclgetboolvar("draw_crosshair");
int crosshair_size = tclgetintvar("crosshair_size");
int infix_interface = tclgetboolvar("infix_interface");
int rstate; /* (reduced state, without ShiftMask) */
int snap_cursor = tclgetboolvar("snap_cursor");
int cadence_compat = tclgetboolvar("cadence_compat");
int persistent_command = tclgetboolvar("persistent_command");
int wire_draw_active = (xctx->ui_state & STARTWIRE) || int line_draw_active = (xctx->ui_state & STARTLINE) ||
((xctx->ui_state2 & MENUSTARTWIRE) && (xctx->ui_state & MENUSTART)) ||
(persistent_command && (xctx->last_command & STARTWIRE));
int line_draw_active = (xctx->ui_state & STARTLINE) ||
((xctx->ui_state2 & MENUSTARTLINE) && (xctx->ui_state & MENUSTART)) || ((xctx->ui_state2 & MENUSTARTLINE) && (xctx->ui_state & MENUSTART)) ||
(persistent_command && (xctx->last_command & STARTLINE)); (persistent_command && (xctx->last_command & STARTLINE));
int poly_draw_active = (xctx->ui_state & STARTPOLYGON) || int poly_draw_active = (xctx->ui_state & STARTPOLYGON) ||
((xctx->ui_state2 & MENUSTARTPOLYGON) && (xctx->ui_state & MENUSTART)) || ((xctx->ui_state2 & MENUSTARTPOLYGON) && (xctx->ui_state & MENUSTART)) ||
(persistent_command && (xctx->last_command & STARTPOLYGON)); (persistent_command && (xctx->last_command & STARTPOLYGON));
int arc_draw_active = (xctx->ui_state & STARTARC) || int arc_draw_active = (xctx->ui_state & STARTARC) ||
((xctx->ui_state2 & MENUSTARTARC) && (xctx->ui_state & MENUSTART)) || ((xctx->ui_state2 & MENUSTARTARC) && (xctx->ui_state & MENUSTART)) ||
(persistent_command && (xctx->last_command & STARTARC)); (persistent_command && (xctx->last_command & STARTARC));
int rect_draw_active = (xctx->ui_state & STARTRECT) || int rect_draw_active = (xctx->ui_state & STARTRECT) ||
((xctx->ui_state2 & MENUSTARTRECT) && (xctx->ui_state & MENUSTART)) || ((xctx->ui_state2 & MENUSTARTRECT) && (xctx->ui_state & MENUSTART)) ||
(persistent_command && (xctx->last_command & STARTRECT)); (persistent_command && (xctx->last_command & STARTRECT));
/* this fix uses an alternative method for getting mouse coordinates on KeyPress/KeyRelease
* events. Some remote connection softwares do not generate the correct coordinates
* on such events */
if(fix_mouse_coord) {
if(event == KeyPress || event == KeyRelease) {
tclvareval("getmousex ", win_path, NULL);
mx = atoi(tclresult());
tclvareval("getmousey ", win_path, NULL);
my = atoi(tclresult());
dbg(1, "mx = %d my=%d\n", mx, my);
}
}
#ifndef __unix__
if(cstate & 0x0001) { /* caps lock */
tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL);
} else if (nstate & 0x0001) { /* num lock */
tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {NUM LOCK SET! }", NULL);
} else { /* normal state */
tclvareval(xctx->top_path, ".statusbar.8 configure -state normal -text {}", NULL);
}
#else
XGetKeyboardControl(display, &kbdstate);
if(kbdstate.led_mask & 1) { /* caps lock */
tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL);
} else if(kbdstate.led_mask & 2) { /* num lock */
tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {NUM LOCK SET! }", NULL);
} else { /* normal state */
tclvareval(xctx->top_path, ".statusbar.8 configure -state normal -text {}", NULL);
}
#endif
if(wire_draw_active) { if(wire_draw_active) {
tclvareval(xctx->top_path, ".statusbar.10 configure -state active -text {DRAW WIRE! }", NULL); tclvareval(xctx->top_path, ".statusbar.10 configure -state active -text {DRAW WIRE! }", NULL);
} else if(line_draw_active) { } else if(line_draw_active) {
@ -4612,11 +4557,70 @@ int rect_draw_active = (xctx->ui_state & STARTRECT) ||
tclvareval(xctx->top_path, ".statusbar.7 configure -text $netlist_type", NULL); tclvareval(xctx->top_path, ".statusbar.7 configure -text $netlist_type", NULL);
tclvareval(xctx->top_path, ".statusbar.3 delete 0 end;", tclvareval(xctx->top_path, ".statusbar.3 delete 0 end;",
xctx->top_path, ".statusbar.3 insert 0 $cadsnap", xctx->top_path, ".statusbar.3 insert 0 $cadsnap", NULL);
NULL);
tclvareval(xctx->top_path, ".statusbar.5 delete 0 end;", tclvareval(xctx->top_path, ".statusbar.5 delete 0 end;",
xctx->top_path, ".statusbar.5 insert 0 $cadgrid", xctx->top_path, ".statusbar.5 insert 0 $cadgrid", NULL);
NULL); }
/* main window callback */
/* mx and my are set to the mouse coord. relative to window */
/* win_path: set to .drw or sub windows .x1.drw, .x2.drw, ... */
int callback(const char *win_path, int event, int mx, int my, KeySym key, int button, int aux, int state)
{
char str[PATH_MAX + 100];
int redraw_only;
double c_snap;
#ifndef __unix__
short cstate = GetKeyState(VK_CAPITAL);
short nstate = GetKeyState(VK_NUMLOCK);
#else
XKeyboardState kbdstate;
#endif
int enable_stretch = tclgetboolvar("enable_stretch");
int draw_xhair = tclgetboolvar("draw_crosshair");
int crosshair_size = tclgetintvar("crosshair_size");
int infix_interface = tclgetboolvar("infix_interface");
int rstate; /* (reduced state, without ShiftMask) */
int snap_cursor = tclgetboolvar("snap_cursor");
int cadence_compat = tclgetboolvar("cadence_compat");
int persistent_command = tclgetboolvar("persistent_command");
int wire_draw_active = (xctx->ui_state & STARTWIRE) ||
((xctx->ui_state2 & MENUSTARTWIRE) && (xctx->ui_state & MENUSTART)) ||
(persistent_command && (xctx->last_command & STARTWIRE));
/* this fix uses an alternative method for getting mouse coordinates on KeyPress/KeyRelease
* events. Some remote connection softwares do not generate the correct coordinates
* on such events */
if(fix_mouse_coord) {
if(event == KeyPress || event == KeyRelease) {
tclvareval("getmousex ", win_path, NULL);
mx = atoi(tclresult());
tclvareval("getmousey ", win_path, NULL);
my = atoi(tclresult());
dbg(1, "mx = %d my=%d\n", mx, my);
}
}
#ifndef __unix__
if(cstate & 0x0001) { /* caps lock */
tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL);
} else if (nstate & 0x0001) { /* num lock */
tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {NUM LOCK SET! }", NULL);
} else { /* normal state */
tclvareval(xctx->top_path, ".statusbar.8 configure -state normal -text {}", NULL);
}
#else
XGetKeyboardControl(display, &kbdstate);
if(kbdstate.led_mask & 1) { /* caps lock */
tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {CAPS LOCK SET! }", NULL);
} else if(kbdstate.led_mask & 2) { /* num lock */
tclvareval(xctx->top_path, ".statusbar.8 configure -state active -text {NUM LOCK SET! }", NULL);
} else { /* normal state */
tclvareval(xctx->top_path, ".statusbar.8 configure -state normal -text {}", NULL);
}
#endif
update_statusbar(persistent_command, wire_draw_active);
#if 0 #if 0
/* exclude Motion and Expose events */ /* exclude Motion and Expose events */
@ -4638,7 +4642,8 @@ int rect_draw_active = (xctx->ui_state & STARTRECT) ||
old_win_path, win_path, xctx->semaphore); old_win_path, win_path, xctx->semaphore);
new_schematic("switch", win_path, "", 1); new_schematic("switch", win_path, "", 1);
} }
tclvareval("housekeeping_ctx", NULL); /* done in switch_window() */
/* tclvareval("housekeeping_ctx", NULL); */
} }
/* artificially set semaphore to allow only redraw operations in switched schematic, /* artificially set semaphore to allow only redraw operations in switched schematic,
* so we don't need to switch tcl context which is costly performance-wise * so we don't need to switch tcl context which is costly performance-wise
@ -4745,7 +4750,7 @@ int rect_draw_active = (xctx->ui_state & STARTRECT) ||
case ButtonPress: case ButtonPress:
handle_button_press(event, state, rstate, key, button, mx, my, handle_button_press(event, state, rstate, key, button, mx, my,
c_snap, draw_xhair, crosshair_size, enable_stretch, aux); c_snap, draw_xhair, crosshair_size, enable_stretch, cadence_compat, aux);
break; break;
case ButtonRelease: case ButtonRelease:

View File

@ -1524,11 +1524,13 @@ static int switch_window(int *window_count, const char *win_path, int tcl_ctx)
} }
} }
/* if window was closed then tkwin == 0 --> do nothing */ /* if window was closed then tkwin == 0 --> do nothing */
if((!has_x || tkwin) && n >= 0 && n < MAX_NEW_WINDOWS) { if(tkwin && n >= 0 && n < MAX_NEW_WINDOWS) {
if(tcl_ctx) tclvareval("save_ctx ", xctx->current_win_path, NULL); if(tcl_ctx) tclvareval("save_ctx ", xctx->current_win_path, NULL);
xctx = save_xctx[n]; xctx = save_xctx[n];
if(tcl_ctx) tclvareval("restore_ctx ", win_path, NULL); if(tcl_ctx) {
tclvareval("restore_ctx ", win_path, NULL);
tclvareval("housekeeping_ctx", NULL); tclvareval("housekeeping_ctx", NULL);
}
if(tcl_ctx && has_x) tclvareval("reconfigure_layers_button {}", NULL); if(tcl_ctx && has_x) tclvareval("reconfigure_layers_button {}", NULL);
set_modify(-1); /* sets window title */ set_modify(-1); /* sets window title */
return 0; return 0;

View File

@ -699,6 +699,19 @@ proc ev0 {args} {
} }
} }
# create the 'lassign' command if tcl does not have it (pre 8.5)
if {[info commands lassign] eq {}} {
proc lassign { list args } {
set n 0
foreach i $args {
upvar $i v
set v [lindex $list $n]
incr n
}
return [lrange $list $n end]
}
}
# return "$n * $indent" spaces # return "$n * $indent" spaces
proc spaces {n {indent 4}} { proc spaces {n {indent 4}} {
set n [expr {$n * $indent}] set n [expr {$n * $indent}]
@ -709,40 +722,32 @@ proc spaces {n {indent 4}} {
# complex number operators # complex number operators
# a + b # a + b
proc cadd {a b} { proc cadd {a b} {
# lassign $a ra ia lassign $a ra ia
# lassign $b rb ib lassign $b rb ib
foreach {ra ia} $a break
foreach {rb ib} $b break
set c [list [expr {$ra + $rb}] [expr {$ia + $ib}]] set c [list [expr {$ra + $rb}] [expr {$ia + $ib}]]
return $c return $c
} }
# a - b # a - b
proc csub {a b} { proc csub {a b} {
# lassign $a ra ia lassign $a ra ia
# lassign $b rb ib lassign $b rb ib
foreach {ra ia} $a break
foreach {rb ib} $b break
set c [list [expr {$ra - $rb}] [expr {$ia - $ib}]] set c [list [expr {$ra - $rb}] [expr {$ia - $ib}]]
return $c return $c
} }
# a * b # a * b
proc cmul {a b} { proc cmul {a b} {
# lassign $a ra ia lassign $a ra ia
# lassign $b rb ib lassign $b rb ib
foreach {ra ia} $a break
foreach {rb ib} $b break
set c [list [expr {$ra * $rb - $ia * $ib}] [expr {$ra * $ib + $rb * $ia}]] set c [list [expr {$ra * $rb - $ia * $ib}] [expr {$ra * $ib + $rb * $ia}]]
return $c return $c
} }
# a / b # a / b
proc cdiv {a b} { proc cdiv {a b} {
# lassign $a ra ia lassign $a ra ia
# lassign $b rb ib lassign $b rb ib
foreach {ra ia} $a break
foreach {rb ib} $b break
set ra [expr {double($ra)}] set ra [expr {double($ra)}]
set ia [expr {double($ia)}] set ia [expr {double($ia)}]
set rb [expr {double($rb)}] set rb [expr {double($rb)}]
@ -755,8 +760,7 @@ proc cdiv {a b} {
# 1/b # 1/b
proc cinv {b} { proc cinv {b} {
# lassign $b rb ib lassign $b rb ib
foreach {rb ib} $b break
set rb [expr {double($rb)}] set rb [expr {double($rb)}]
set ib [expr {double($ib)}] set ib [expr {double($ib)}]
set m [expr {$rb * $rb + $ib * $ib}] set m [expr {$rb * $rb + $ib * $ib}]
@ -766,15 +770,13 @@ proc cinv {b} {
# return real component # return real component
proc creal {a} { proc creal {a} {
# lassign $a ra ia lassign $a ra ia
foreach {ra ia} $a break
return $ra return $ra
} }
# return imaginary component # return imaginary component
proc cimag {a} { proc cimag {a} {
# lassign $a ra ia lassign $a ra ia
foreach {ra ia} $a break
return $ia return $ia
} }
@ -4825,8 +4827,8 @@ proc load_file_dialog {{msg {}} {ext {}} {global_initdir {INITIALINSTDIR}}
# if paths empty use XSCHEM_LIBRARY_PATH list. # if paths empty use XSCHEM_LIBRARY_PATH list.
# 'levels' is set to the number of levels to descend into. # 'levels' is set to the number of levels to descend into.
# 'level' is used internally by the function and should not be set. # 'level' is used internally by the function and should not be set.
proc get_list_of_dirs_with_symbols {{paths {}} {levels -1} {ext {\.(sch|sym)$}} {level -1}} { proc get_list_of_dirs_with_files {{paths {}} {levels -1} {ext {\.(sch|sym)$}} {level -1}} {
# puts "get_list_of_dirs_with_symbols paths=$paths" # puts "get_list_of_dirs_with_files paths=$paths"
global pathlist global pathlist
set dir_with_symbols {} set dir_with_symbols {}
if {$level == -1} { set level 0} if {$level == -1} { set level 0}
@ -4847,7 +4849,7 @@ proc get_list_of_dirs_with_symbols {{paths {}} {levels -1} {ext {\.(sch|sym)$}}
set dirlist [glob -nocomplain -directory $i -type d *] set dirlist [glob -nocomplain -directory $i -type d *]
if {$levels >=0 && $level + 1 > $levels} {return} if {$levels >=0 && $level + 1 > $levels} {return}
foreach d $dirlist { foreach d $dirlist {
set dirs [get_list_of_dirs_with_symbols $d $levels $ext [expr {$level + 1} ]] set dirs [get_list_of_dirs_with_files $d $levels $ext [expr {$level + 1} ]]
if { $dirs ne {}} {set dir_with_symbols [concat $dir_with_symbols $dirs]} if { $dirs ne {}} {set dir_with_symbols [concat $dir_with_symbols $dirs]}
} }
} }
@ -4923,7 +4925,7 @@ proc insert_symbol_update_dirs {} {
global insert_symbol global insert_symbol
# regenerate list of dirs # regenerate list of dirs
set insert_symbol(dirs) [ set insert_symbol(dirs) [
get_list_of_dirs_with_symbols $insert_symbol(paths) $insert_symbol(maxdepth) $insert_symbol(ext) get_list_of_dirs_with_files $insert_symbol(paths) $insert_symbol(maxdepth) $insert_symbol(ext)
] ]
set insert_symbol(dirtails) {} set insert_symbol(dirtails) {}
foreach i $insert_symbol(dirs) { foreach i $insert_symbol(dirs) {
@ -4939,8 +4941,7 @@ proc insert_symbol_update_dirs {} {
set insert_symbol(dirs) {} set insert_symbol(dirs) {}
foreach f $files { foreach f $files {
# lassign $f ff fff lassign $f ff fff
foreach {ff fff} $f break ;# pre-tcl8.5
lappend insert_symbol(dirtails) $ff lappend insert_symbol(dirtails) $ff
lappend insert_symbol(dirs) $fff lappend insert_symbol(dirs) $fff
} }
@ -4957,17 +4958,17 @@ proc insert_symbol_filelist {} {
.ins.center.leftdir.l selection set active .ins.center.leftdir.l selection set active
} }
set insert_symbol(dirindex) $sel set insert_symbol(dirindex) $sel
set paths [lindex $insert_symbol(dirs) $sel] set path [lindex $insert_symbol(dirs) $sel]
.ins.top2.dir_e configure -state normal .ins.top2.dir_e configure -state normal
.ins.top2.dir_e delete 0 end .ins.top2.dir_e delete 0 end
.ins.top2.dir_e insert 0 $paths .ins.top2.dir_e insert 0 $path
.ins.top2.dir_e configure -state readonly .ins.top2.dir_e configure -state readonly
# check if regex is valid # check if regex is valid
set err [catch {regexp $insert_symbol(regex) {12345}} res] set err [catch {regexp $insert_symbol(regex) {12345}} res]
if {$err} {return} if {$err} {return}
set f {} set f {}
if {$paths ne {} } { if {$path ne {} } {
set f [match_file $insert_symbol(regex) $paths 0] set f [match_file $insert_symbol(regex) $path 0]
} }
set filelist {} set filelist {}
set insert_symbol(fullpathlist) {} set insert_symbol(fullpathlist) {}
@ -4995,8 +4996,7 @@ proc insert_symbol_filelist {} {
set filelist {} set filelist {}
set insert_symbol(fullpathlist) {} set insert_symbol(fullpathlist) {}
foreach f $files { foreach f $files {
# lassign $f ff fff lassign $f ff fff
foreach {ff fff} $f break ;# pre-tcl8.5
lappend filelist $ff lappend filelist $ff
lappend insert_symbol(fullpathlist) $fff lappend insert_symbol(fullpathlist) $fff
} }
@ -5327,13 +5327,10 @@ proc schpins_to_sympins {} {
set textflip [expr {$flip}] set textflip [expr {$flip}]
} }
## lassign not available pre-tck8.5 ## lassign not available pre-tck8.5
# lassign [rotation $x0 $y0 $linex1 $liney1 $rot $flip] linex1 liney1 lassign [rotation $x0 $y0 $linex1 $liney1 $rot $flip] linex1 liney1
foreach {linex1 liney1} [rotation $x0 $y0 $linex1 $liney1 $rot $flip] break lassign [rotation $x0 $y0 $linex2 $liney2 $rot $flip] linex2 liney2
# lassign [rotation $x0 $y0 $linex2 $liney2 $rot $flip] linex2 liney2 lassign [order $linex1 $liney1 $linex2 $liney2] linex1 liney1 linex2 liney2
foreach {linex2 liney2} [rotation $x0 $y0 $linex2 $liney2 $rot $flip] break lassign [rotation $x0 $y0 $textx0 $texty0 $rot $flip] textx0 texty0
# lassign [order $linex1 $liney1 $linex2 $liney2] linex1 liney1 linex2 liney2
foreach {linex1 liney1 linex2 liney2} [order $linex1 $liney1 $linex2 $liney2] break
# lassign [rotation $x0 $y0 $textx0 $texty0 $rot $flip] textx0 texty0
foreach {textx0 texty0} [rotation $x0 $y0 $textx0 $texty0 $rot $flip] break foreach {textx0 texty0} [rotation $x0 $y0 $textx0 $texty0 $rot $flip] break
puts $fd "B 5 $pinx1 $piny1 $pinx2 $piny2 \{name=$lab dir=$dir\}" puts $fd "B 5 $pinx1 $piny1 $pinx2 $piny2 \{name=$lab dir=$dir\}"
puts $fd "L 4 $linex1 $liney1 $linex2 $liney2 \{\}" puts $fd "L 4 $linex1 $liney1 $linex2 $liney2 \{\}"
@ -8236,7 +8233,8 @@ proc quit_xschem { {force {}}} {
proc raise_dialog {parent window_path } { proc raise_dialog {parent window_path } {
global file_dialog_loadfile component_browser_on_top global file_dialog_loadfile component_browser_on_top
foreach i ".dialog .graphdialog .load" { foreach i ".dialog .graphdialog .load" {
if {!$component_browser_on_top && [info exists file_dialog_loadfile ] && $file_dialog_loadfile == 2 && $i eq {.load} } { if {!$component_browser_on_top && [info exists file_dialog_loadfile ] &&
$file_dialog_loadfile == 2 && $i eq {.load} } {
continue continue
} }
if {[winfo exists $i] && [winfo ismapped $i] && [winfo ismapped $parent] && if {[winfo exists $i] && [winfo ismapped $i] && [winfo ismapped $parent] &&