Merge pull request #17 from TheSUPERCD/upstream-clone

Resolve merge conflicts
This commit is contained in:
Chayan Deb 2025-03-18 08:25:35 +00:00 committed by GitHub
commit 8d4654f643
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 266 additions and 112 deletions

View File

@ -1599,7 +1599,8 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
} else {
const char msg[]="scope_ammeter is being inserted but no selected ammeter device/vsource to link to\n";
dbg(0, "%s", msg);
if(has_x) tclvareval("alert_ {", msg, "} {}", NULL);
if(has_x) tclvareval("alert_ {", msg, "} {} 1", NULL);
#if 1
if(xctx->inst[n].instname) my_free(_ALLOC_ID_, &xctx->inst[n].instname);
if(xctx->inst[n].name) my_free(_ALLOC_ID_, &xctx->inst[n].name);
if(xctx->inst[n].prop_ptr) my_free(_ALLOC_ID_, &xctx->inst[n].prop_ptr);
@ -1607,6 +1608,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
if(prop) my_free(_ALLOC_ID_, &prop);
xctx->instances--;
return 0;
#endif
}
} else if(xctx->sym[i].rects[PINLAYER] == 1) {
my_mstrcat(_ALLOC_ID_, &prop,

View File

@ -3433,19 +3433,6 @@ static void handle_key_press(int event, KeySym key, int state, int rstate, int m
tcleval("[xschem get top_path].menubar invoke Simulate");
}
}
else if(SET_MODMASK) { /* reload */
if(xctx->semaphore >= 2) break;
tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] "
"-message {Are you sure you want to reload from disk?}");
if(strcmp(tclresult(),"ok")==0) {
char filename[PATH_MAX];
unselect_all(1);
remove_symbols();
my_strncpy(filename, abs_sym_path(xctx->sch[xctx->currsch], ""), S(filename));
load_schematic(1, filename, 1, 1);
draw();
}
}
else if(EQUAL_MODMASK) { /* rotate objects around their anchor points 20171208 */
if(xctx->ui_state & STARTMOVE) move_objects(ROTATE|ROTATELOCAL,0,0,0);
else if(xctx->ui_state & STARTCOPY) copy_objects(ROTATE|ROTATELOCAL);
@ -3489,7 +3476,8 @@ static void handle_key_press(int event, KeySym key, int state, int rstate, int m
tcleval("[xschem get top_path].menubar invoke Simulate");
}
}
else if(/* !xctx->ui_state && */ (rstate == 0) && cadence_compat) { /* create wire snapping to closest instance pin (cadence keybind) */
/* create wire snapping to closest instance pin (cadence keybind) */
else if(/* !xctx->ui_state && */ (rstate == 0) && cadence_compat) {
if(xctx->semaphore >= 2) break;
snapped_wire(c_snap);
}
@ -3506,6 +3494,21 @@ static void handle_key_press(int event, KeySym key, int state, int rstate, int m
save(1, 0);
}
}
else if(SET_MODMASK) { /* reload */
if(xctx->semaphore >= 2) break;
tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] "
"-message {Are you sure you want to reload from disk?}");
if(strcmp(tclresult(),"ok")==0) {
char filename[PATH_MAX];
unselect_all(1);
remove_symbols();
my_strncpy(filename, abs_sym_path(xctx->sch[xctx->currsch], ""), S(filename));
load_schematic(1, filename, 1, 1);
draw();
}
}
else if(SET_MODMASK && (state & ControlMask) ) { /* save as symbol */
if(xctx->semaphore >= 2) break;
saveas(NULL, SYMBOL);

View File

@ -377,26 +377,42 @@ void draw_selection(GC g, int interruptable)
ORDER(xctx->rx1,xctx->ry1,xctx->rx2,xctx->ry2);
if(xctx->wire[n].sel==SELECTED)
{
if(xctx->wire[n].bus)
drawtemp_manhattanline(g, THICK, xctx->rx1+xctx->deltax, xctx->ry1+xctx->deltay,
xctx->rx2+xctx->deltax, xctx->ry2+xctx->deltay, 1);
else
drawtemp_manhattanline(g, ADD, xctx->rx1+xctx->deltax, xctx->ry1+xctx->deltay,
xctx->rx2+xctx->deltax, xctx->ry2+xctx->deltay, 1);
double x1 = xctx->rx1 + xctx->deltax;
double y1 = xctx->ry1 + xctx->deltay;
double x2 = xctx->rx2 + xctx->deltax;
double y2 = xctx->ry2 + xctx->deltay;
dbg(1, "draw_selection() wire: %g %g - %g %g manhattan=%d\n", x1, y1, x2, y2, xctx->manhattan_lines);
if(xctx->wire[n].bus) {
drawtemp_manhattanline(g, THICK, x1, y1, x2, y2, 1);
} else {
drawtemp_manhattanline(g, ADD, x1, y1, x2, y2, 1);
}
}
else if(xctx->wire[n].sel==SELECTED1)
{
if(xctx->wire[n].bus)
drawtemp_manhattanline(g, THICK, xctx->rx1+xctx->deltax, xctx->ry1+xctx->deltay, xctx->rx2, xctx->ry2, 1);
else
drawtemp_manhattanline(g, ADD, xctx->rx1+xctx->deltax, xctx->ry1+xctx->deltay, xctx->rx2, xctx->ry2, 1);
double x1 = xctx->rx1 + xctx->deltax;
double y1 = xctx->ry1 + xctx->deltay;
double x2 = xctx->rx2;
double y2 = xctx->ry2;
dbg(1, "draw_selection() wire: %g %g - %g %g manhattan=%d\n", x1, y1, x2, y2, xctx->manhattan_lines);
if(xctx->wire[n].bus) {
drawtemp_manhattanline(g, THICK, x2, y2, x1, y1, 1);
} else {
drawtemp_manhattanline(g, ADD, x2, y2, x1, y1, 1);
}
}
else if(xctx->wire[n].sel==SELECTED2)
{
if(xctx->wire[n].bus)
drawtemp_manhattanline(g, THICK, xctx->rx1, xctx->ry1, xctx->rx2+xctx->deltax, xctx->ry2+xctx->deltay, 1);
else
drawtemp_manhattanline(g, ADD, xctx->rx1, xctx->ry1, xctx->rx2+xctx->deltax, xctx->ry2+xctx->deltay, 1);
double x1 = xctx->rx1;
double y1 = xctx->ry1;
double x2 = xctx->rx2 + xctx->deltax;
double y2 = xctx->ry2 + xctx->deltay;
dbg(1, "draw_selection() wire: %g %g - %g %g manhattan=%d\n", x1, y1, x2, y2, xctx->manhattan_lines);
if(xctx->wire[n].bus) {
drawtemp_manhattanline(g, THICK, x1, y1, x2, y2, 1);
} else {
drawtemp_manhattanline(g, ADD, x1, y1, x2, y2, 1);
}
}
break;
case LINE:
@ -991,6 +1007,145 @@ void copy_objects(int what)
}
/* order wire points and swap SELECTED1 / SELECTED2 if needed */
static void order_wire_points(int n)
{
xWire * const wire = xctx->wire;
double x1, y1;
x1=wire[n].x1;
y1=wire[n].y1;
ORDER(wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2);
if( x1 == wire[n].x2 && y1 == wire[n].y2) /* wire points reversed, so swap SELECTEDn */
{
if(wire[n].sel == SELECTED1) wire[n].sel = SELECTED2;
else if(wire[n].sel == SELECTED2) wire[n].sel = SELECTED1;
}
}
/* xctx->{rx1, ry1} and xctx->{rx2, ry2} are the two line points after the move.
* they are not guaranteed to be ordered (since only one of the two points may have changed)
* so this must be taken care for */
static void place_moved_wire(int n, int orthogonal_wiring)
{
xWire * const wire = xctx->wire;
/* FIXME: Chayan Deb: this needs to be updated
* If things get too complicated a place_moved_wire_orthogonal() can be created
*/
if((wire[n].sel & (SELECTED|SELECTED1)) && orthogonal_wiring)
{
if(xctx->manhattan_lines & 1) xctx->manhattan_lines=2;
else if(xctx->manhattan_lines & 2) xctx->manhattan_lines=1;
}
/* wire x1,y1 point was moved
*
* x1,y1(old) rx2,ry2
* -----------------o-----------------o
* | (H)
* selected |(V)
* |
* o
* rx1,ry1(new)
*/
if(wire[n].sel == SELECTED1 && (xctx->manhattan_lines & 1)) /* H - V */
{
int last;
wire[n].x1 = xctx->rx1;
wire[n].y1 = xctx->ry1;
wire[n].x2 = xctx->rx1;
wire[n].y2 = xctx->ry2;
order_wire_points(n);
storeobject(-1, xctx->rx1,xctx->ry2,xctx->rx2,xctx->ry2,WIRE,0,0,NULL);
last = xctx->wires-1;
order_wire_points(last);
/* drawline(WIRELAYER,NOW, wire[last].x1, wire[last].y1, wire[last].x2, wire[last].y2, 0, NULL); */
}
/* wire x2,y2 point was moved
*
* rx1,ry1 x2,y2(old)
* o-----------------o-----------------
* (H) |
* (V)| selected
* |
* o
* rx2,ry2(new)
*/
else if(wire[n].sel == SELECTED2 && (xctx->manhattan_lines & 1)) /* H - V */
{
int last;
wire[n].x1 = xctx->rx2;
wire[n].y1 = xctx->ry1;
wire[n].x2 = xctx->rx2;
wire[n].y2 = xctx->ry2;
order_wire_points(n);
storeobject(-1, xctx->rx1,xctx->ry1,xctx->rx2,xctx->ry1,WIRE,0,0,NULL);
last = xctx->wires-1;
order_wire_points(last);
/* drawline(WIRELAYER,NOW, wire[last].x1, wire[last].y1, wire[last].x2, wire[last].y2, 0, NULL); */
}
/* wire x1,y1 point was moved
*
* x1,y1(old) rx2,ry2
* o-----------------o
* |
* (V)|
* (H) selected |
* o-----------------------------------
* rx1,ry1(new)
*/
else if(wire[n].sel == SELECTED1 && (xctx->manhattan_lines & 2)) /* V - H */
{
int last;
wire[n].x1 = xctx->rx1;
wire[n].y1 = xctx->ry1;
wire[n].x2 = xctx->rx2;
wire[n].y2 = xctx->ry1;
order_wire_points(n);
storeobject(-1, xctx->rx2,xctx->ry1,xctx->rx2,xctx->ry2,WIRE,0,0,NULL);
last = xctx->wires-1;
order_wire_points(last);
/* drawline(WIRELAYER,NOW, wire[last].x1, wire[last].y1, wire[last].x2, wire[last].y2, 0, NULL); */
}
/* wire x2,y2 point was moved
*
* rx1,ry1 x2,y2(old)
* o-----------------o
* |
* |(V)
* | (H) selected
* -----------------------------------o
* rx2,ry2(new)
*/
else if(wire[n].sel == SELECTED2 && (xctx->manhattan_lines & 2)) /* V - H */
{
int last;
wire[n].x1 = xctx->rx1;
wire[n].y1 = xctx->ry2;
wire[n].x2 = xctx->rx2;
wire[n].y2 = xctx->ry2;
order_wire_points(n);
storeobject(-1, xctx->rx1,xctx->ry1,xctx->rx1,xctx->ry2,WIRE,0,0,NULL);
last = xctx->wires-1;
order_wire_points(last);
/* drawline(WIRELAYER,NOW, wire[last].x1, wire[last].y1, wire[last].x2, wire[last].y2, 0, NULL); */
}
else /* no manhattan or traslation since both line points moved */
{
wire[n].x1 = xctx->rx1;
wire[n].y1 = xctx->ry1;
wire[n].x2 = xctx->rx2;
wire[n].y2 = xctx->ry2;
order_wire_points(n);
}
}
/* merge param unused, RFU */
void move_objects(int what, int merge, double dx, double dy)
{
@ -998,6 +1153,7 @@ void move_objects(int what, int merge, double dx, double dy)
double angle, dtmp;
double tx1,ty1; /* temporaries for swapping coordinates 20070302 */
char *estr = NULL;
int orthogonal_wiring = tclgetboolvar("orthogonal_wiring");
#if HAS_CAIRO==1
int customfont;
#endif
@ -1127,46 +1283,8 @@ void move_objects(int what, int merge, double dx, double dy)
xctx->rx2+=xctx->deltax;
xctx->ry2+=xctx->deltay;
}
wire[n].x1=xctx->rx1;
wire[n].y1=xctx->ry1;
ORDER(xctx->rx1,xctx->ry1,xctx->rx2,xctx->ry2);
if( wire[n].x1 == xctx->rx2 && wire[n].y1 == xctx->ry2)
{
if(wire[n].sel == SELECTED1) wire[n].sel = SELECTED2;
else if(wire[n].sel == SELECTED2) wire[n].sel = SELECTED1;
}
if((wire[n].sel & (SELECTED|SELECTED1)) && tclgetboolvar("orthogonal_wiring"))
{
if(xctx->manhattan_lines & 1) xctx->manhattan_lines=2;
else if(xctx->manhattan_lines & 2) xctx->manhattan_lines=1;
}
wire[n].x1 = xctx->rx1;
wire[n].y1 = xctx->ry1;
if(xctx->manhattan_lines&1)
{
wire[n].x2 = xctx->rx2;
wire[n].y2 = xctx->ry1;
ORDER(xctx->rx2,xctx->ry1,xctx->rx2,xctx->ry2);
storeobject(-1, xctx->rx2,xctx->ry1,xctx->rx2,xctx->ry2,WIRE,0,0,NULL);
hash_wire(XINSERT, xctx->wires-1, 1);
drawline(WIRELAYER,ADD, xctx->rx2,xctx->ry1,xctx->rx2,xctx->ry2, 0, NULL);
}
else if(xctx->manhattan_lines&2)
{
wire[n].x2 = xctx->rx1;
wire[n].y2 = xctx->ry2;
ORDER(xctx->rx1,xctx->ry2,xctx->rx2,xctx->ry2);
storeobject(-1, xctx->rx1,xctx->ry2,xctx->rx2,xctx->ry2,WIRE,0,0,NULL);
hash_wire(XINSERT, xctx->wires-1, 1);
drawline(WIRELAYER,ADD, xctx->rx1,xctx->ry2,xctx->rx2,xctx->ry2, 0, NULL);
}
else
{
/* no need for ordering coordinates - already done before */
wire[n].x2 = xctx->rx2;
wire[n].y2 = xctx->ry2;
}
place_moved_wire(n, orthogonal_wiring);
}
break;
@ -1236,9 +1354,7 @@ void move_objects(int what, int merge, double dx, double dy)
p->x[j] = xctx->rx1+xctx->deltax;
p->y[j] = xctx->ry1+xctx->deltay;
}
}
for(j=0; j<p->points; ++j) {
if(j==0 || p->x[j] < bx1) bx1 = p->x[j];
if(j==0 || p->y[j] < by1) by1 = p->y[j];

View File

@ -4133,7 +4133,7 @@ namespace eval c_toolbar {
set c_t($i,file) $f
set c_t($i,command) "
set file_dialog_retval {}
xschem abort_operation
if { \[xschem get ui_state\] & 8192 } { xschem abort_operation }
file_dialog_display_preview {$f}
xschem place_symbol {$f} "
set c_t($i,text) [file tail [file rootname $f]]
@ -4357,7 +4357,9 @@ proc file_dialog_place_symbol {} {
set file_dialog_retval $entry
set sym [file_dialog_getresult 2 0]
# puts "sym=$sym"
xschem abort_operation
if { [xschem get ui_state] & 8192 } {
xschem abort_operation
}
if {$sym ne {}} {
xschem place_symbol "$sym"
}
@ -4836,11 +4838,28 @@ proc get_list_of_dirs_with_symbols {{paths {}} {levels -1} {ext {\.(sch|sym)$}}
#######################################################################
#### Display preview of selected symbol and start sym placement
proc insert_symbol_preview {} {
# puts "insert_symbol_preview"
proc insert_symbol_draw_preview {f} {
# puts "insert_symbol_draw_preview"
if {[winfo exists .ins]} {
.ins.center.right configure -bg {}
xschem preview_window create .ins.center.right {}
xschem preview_window draw .ins.center.right [list $f]
bind .ins.center.right <Expose> "xschem preview_window draw .ins.center.right [list $f]"
bind .ins.center.right <Configure> "xschem preview_window draw .ins.center.right [list $f]"
insert_symbol_place
}
}
proc insert_symbol_select_preview {} {
# puts "insert_symbol_select_preview"
global insert_symbol
if {[info exists insert_symbol(f)]} {
after cancel ".ins.center.right configure -bg white"
after cancel "insert_symbol_draw_preview $insert_symbol(f)"
unset insert_symbol(f)
}
xschem preview_window close .ins.center.right {}
.ins.center.right configure -bg white
bind .ins.center.right <Expose> {}
bind .ins.center.right <Configure> {}
set sel [.ins.center.left.l curselection]
@ -4854,6 +4873,7 @@ proc insert_symbol_preview {} {
.ins.center.left.l see $sel
set f [lindex $insert_symbol(fullpathlist) $sel]
if {$f ne {}} {
set insert_symbol(f) $f
set type [is_xschem_file $f]
if {$type ne {0}} {
set dir [rel_sym_path $f]
@ -4866,21 +4886,43 @@ proc insert_symbol_preview {} {
.ins.top2.dir_e delete 0 end
.ins.top2.dir_e insert 0 $f
.ins.top2.dir_e configure -state readonly
.ins.center.right configure -bg {}
xschem preview_window create .ins.center.right {}
xschem preview_window draw .ins.center.right [list $f]
bind .ins.center.right <Expose> "xschem preview_window draw .ins.center.right [list $f]"
bind .ins.center.right <Configure> "xschem preview_window draw .ins.center.right [list $f]"
# global used to cancel delayed script
after 200 "insert_symbol_draw_preview $f"
} else {
after 200 {.ins.center.right configure -bg white}
}
insert_symbol_place
}
}
}
proc insert_symbol_update_dirs {paths {maxdepth -1}} {
global insert_symbol new_symbol_browser_ext
# regenerate list of dirs
set insert_symbol(dirs) [get_list_of_dirs_with_symbols $paths $maxdepth $new_symbol_browser_ext]
set insert_symbol(dirtails) {}
foreach i $insert_symbol(dirs) {
lappend insert_symbol(dirtails) [file tail $i]
}
# sort dirs using dirtails as key
set files {}
foreach f $insert_symbol(dirtails) ff $insert_symbol(dirs) {
lappend files [list $f $ff]
}
set files [lsort -dictionary -index 0 $files]
set insert_symbol(dirtails) {}
set insert_symbol(dirs) {}
foreach f $files {
lassign $f ff fff
lappend insert_symbol(dirtails) $ff
lappend insert_symbol(dirs) $fff
}
}
#### fill list of files matching pattern
proc insert_symbol_filelist {paths {maxdepth -1}} {
global insert_symbol new_symbol_browser_ext
set sel [.ins.center.leftdir.l curselection]
if {![info exists insert_symbol(dirs)]} {return}
if {$sel eq {}} {
@ -4947,7 +4989,9 @@ proc insert_symbol_place {} {
if {$f ne {}} {
set type [is_xschem_file $f]
if {$type ne {0}} {
xschem abort_operation
if { [xschem get ui_state] & 8192 } {
xschem abort_operation
}
xschem place_symbol $f
}
}
@ -5012,23 +5056,30 @@ proc insert_symbol {{paths {}} {maxdepth -1} {ext {.*}}} {
-readonlybackground [option get . background {}] -takefocus 0
label .ins.top.ext_l -text Ext:
entry .ins.top.ext_e -width 15 -takefocus 0 -state normal -textvariable new_symbol_browser_ext
button .ins.top.upd -takefocus 0 -text Update -command "
insert_symbol_update_dirs [list $paths] [list $maxdepth]
insert_symbol_filelist [list $paths] [list $maxdepth]
"
bind .ins <KeyPress-Escape> {.ins.bottom.dismiss invoke}
bind .ins <KeyRelease> "
if {{%K} eq {Tab} && {%W} eq {.ins.center.left.l}} {
insert_symbol_filelist [list $paths] [list $maxdepth]
insert_symbol_preview
insert_symbol_select_preview
} elseif {{%K} eq {Tab} && {%W} eq {.ins.center.leftdir.l}} {
insert_symbol_filelist [list $paths] [list $maxdepth]
}
"
bind .ins.center.leftdir.l <<ListboxSelect>> "insert_symbol_filelist [list $paths] [list $maxdepth]"
bind .ins.center.left.l <<ListboxSelect>> "insert_symbol_preview"
bind .ins.center.left.l <<ListboxSelect>> "insert_symbol_select_preview"
bind .ins.center.left.l <KeyPress-Return> "
xschem preview_window close .ins.center.right {}
destroy .ins
"
bind .ins.center.left.l <Enter> "xschem abort_operation"
bind .ins.center.left.l <Enter> "
if { \[xschem get ui_state\] & 8192 } {
xschem abort_operation
}
"
label .ins.bottom.n -text { N. of items:}
label .ins.bottom.nitems -textvariable insert_symbol(nitems)
button .ins.bottom.dismiss -takefocus 0 -text Dismiss -command {
@ -5048,35 +5099,17 @@ proc insert_symbol {{paths {}} {maxdepth -1} {ext {.*}}} {
pack .ins.top.pat_e -side left
pack .ins.top.dir_l -side left
pack .ins.top.dir_e -side left
pack .ins.top.upd -side left
pack .ins.top.ext_l -side left
pack .ins.top.ext_e -side left
set insert_symbol(dirs) [get_list_of_dirs_with_symbols $paths $maxdepth $new_symbol_browser_ext]
set insert_symbol(dirtails) {}
foreach i $insert_symbol(dirs) {
lappend insert_symbol(dirtails) [file tail $i]
}
insert_symbol_update_dirs $paths $maxdepth
# sort dirs using dirtails as key
set files {}
foreach f $insert_symbol(dirtails) ff $insert_symbol(dirs) {
lappend files [list $f $ff]
}
set files [lsort -dictionary -index 0 $files]
set insert_symbol(dirtails) {}
set insert_symbol(dirs) {}
foreach f $files {
lassign $f ff fff
lappend insert_symbol(dirtails) $ff
lappend insert_symbol(dirs) $fff
}
# insert_symbol_filelist $paths $maxdepth
# tkwait window .ins
# xschem set semaphore [expr {[xschem get semaphore] -1}]
if {[info exists insert_symbol(dirindex)]} {.ins.center.leftdir.l selection set $insert_symbol(dirindex)}
if {[info exists insert_symbol(fileindex)]} {.ins.center.left.l selection set $insert_symbol(fileindex)}
if {[info exists insert_symbol(fileindex)]} {
.ins.center.left.l selection set $insert_symbol(fileindex)
.ins.center.left.l see $insert_symbol(fileindex)
}
return {}
}
#######################################################################