Skip to content

Commit

Permalink
[Upstream Compatibily Fixes]: Added a new TCL-variable 'cadence_compa…
Browse files Browse the repository at this point in the history
…t', which can be enabled from either the TCL-command execution prompt inside xschem, or by uncommenting the corresponding option in 'src/xschemrc' - used for enabling Cadence-friendly keybinds (simulate and snap-wire). Additionally, reset the default behavior of xschem to the upstream-version's behavior. All the disabled options can be re-enabled by uncommenting the correct options in 'src/xschemrc'. Added ANSI-C compatibility fixes suggested by @StefanSchippers in issue StefanSchippers#292 in upstream repo.
  • Loading branch information
TheSUPERCD committed Feb 1, 2025
1 parent de1ea56 commit d4b3881
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
36 changes: 31 additions & 5 deletions src/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include "xschem.h"
#include <X11/X.h>

/* allow to use the Windows keys as alternate for Alt */
#define SET_MODMASK ( (rstate & Mod1Mask) || (rstate & Mod4Mask) )
Expand Down Expand Up @@ -102,6 +103,7 @@ void redraw_w_a_l_r_p_z_rubbers(int force)
{
double mx = xctx->mousex_snap;
double my = xctx->mousey_snap;
double origin_shifted_x2, origin_shifted_y2;

if(!force && xctx->mousex_snap == xctx->prev_rubberx && xctx->mousey_snap == xctx->prev_rubbery) return;

Expand All @@ -112,7 +114,8 @@ void redraw_w_a_l_r_p_z_rubbers(int force)
if(tclgetboolvar("orthogonal_wiring")) {
new_wire(RUBBER|CLEAR, xctx->mousex_snap, xctx->mousey_snap);
/* Origin shift the cartesian coordinate p2(x2,y2) w.r.t. p1(x1,y1) */
int origin_shifted_x2 = xctx->nl_x2 - xctx->nl_x1, origin_shifted_y2 = xctx->nl_y2 - xctx->nl_y1;
origin_shifted_x2 = xctx->nl_x2 - xctx->nl_x1;
origin_shifted_y2 = xctx->nl_y2 - xctx->nl_y1;
/* Draw whichever component of the resulting orthogonal-wire is bigger (either horizontal or vertical), first */
if(origin_shifted_x2*origin_shifted_x2 > origin_shifted_y2*origin_shifted_y2){
xctx->manhattan_lines = 1;
Expand Down Expand Up @@ -1516,15 +1519,15 @@ void draw_snap_cursor(int what)
int sdw, sdp;
int snapcursor_size = tclgetintvar("snap_cursor_size");
int pos_changed = (xctx->mousex_snap - xctx->prev_gridx) || (xctx->mousey_snap - xctx->prev_gridy);
double prev_x = xctx->prev_snapx;
double prev_y = xctx->prev_snapy;
dbg(1, "draw_snap_cursor(): what=%d\n", what);
sdw = xctx->draw_window;
sdp = xctx->draw_pixmap;

if(!xctx->mouse_inside) return;
xctx->draw_pixmap = 0;
xctx->draw_window = 1;
double prev_x = xctx->prev_snapx;
double prev_y = xctx->prev_snapy;
if(what & 1) {
if(fix_broken_tiled_fill || !_unix) {
MyXCopyArea(display, xctx->save_pixmap, xctx->window, xctx->gc[0],
Expand Down Expand Up @@ -2418,6 +2421,7 @@ int draw_xhair = tclgetboolvar("draw_crosshair");
int crosshair_size = tclgetintvar("crosshair_size");
int infix_interface = tclgetboolvar("infix_interface");
int snap_cursor = tclgetboolvar("snap_cursor");
int cadence_compat = tclgetboolvar("cadence_compat");
int wire_draw_active = (xctx->ui_state & STARTWIRE) ||
((xctx->ui_state2 & MENUSTARTWIRE) && (xctx->ui_state & MENUSTART)) ||
(tclgetboolvar("persistent_command") && (xctx->last_command & STARTWIRE));
Expand Down Expand Up @@ -2958,7 +2962,12 @@ int rstate; /* (reduced state, without ShiftMask) */
hilight_net_pin_mismatches();
break;
}
if(key== 's' /* && !xctx->ui_state */ && rstate == 0) { /* create wire snapping to closest instance pin */
if(key== 'W' /* && !xctx->ui_state */ && rstate == 0 && !cadence_compat) { /* create wire snapping to closest instance pin (original keybind) */
if(xctx->semaphore >= 2) break;
snapped_wire(c_snap);
break;
}
if(key== 's' /* && !xctx->ui_state */ && rstate == 0 && cadence_compat) { /* create wire snapping to closest instance pin (cadence keybind) */
if(xctx->semaphore >= 2) break;
snapped_wire(c_snap);
break;
Expand Down Expand Up @@ -3016,6 +3025,9 @@ int rstate; /* (reduced state, without ShiftMask) */
if(tclgetboolvar("snap_cursor")) {
tclsetvar("snap_cursor", "0");
draw_snap_cursor(1);
xctx->closest_pin_found = 0;
xctx->prev_snapx = 0.0;
xctx->prev_snapy = 0.0;
} else {
tclsetvar("snap_cursor", "1");
if(wire_draw_active) draw_snap_cursor(3);
Expand Down Expand Up @@ -3213,7 +3225,21 @@ int rstate; /* (reduced state, without ShiftMask) */
draw(); /* needed to ungrey or grey out components due to *_ignore attribute */
break;
}
if(key=='r' && rstate == ControlMask ) /* simulate */
if((key=='s' && rstate == 0) && !cadence_compat) /* simulate (original keybind) */
{
if(xctx->semaphore >= 2) break;
if(waves_selected(event, key, state, button)) {
waves_callback(event, mx, my, key, button, aux, state);
break;
}
tcleval("tk_messageBox -type okcancel -parent [xschem get topwindow] "
"-message {Run circuit simulation?}");
if(strcmp(tclresult(),"ok")==0) {
tcleval("[xschem get top_path].menubar invoke Simulate");
}
break;
}
if((key=='r' && rstate == ControlMask) && cadence_compat) /* simulate (for cadence users) */
{
if(xctx->semaphore >= 2) break;
if(waves_selected(event, key, state, button)) {
Expand Down
9 changes: 5 additions & 4 deletions src/xschem.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -7702,7 +7702,7 @@ set tctx::global_list {
INITIALINSTDIR INITIALLOADDIR INITIALPROPDIR INITIALTEXTDIR XSCHEM_LIBRARY_PATH
add_all_windows_drives auto_hilight auto_hilight_graph_nodes autofocus_mainwindow
autotrim_wires orthogonal_wiring snap_cursor bespice_listen_port big_grid_points bus_replacement_char cadgrid cadlayers
cadsnap cairo_font_name cairo_font_scale change_lw color_ps tctx::colors compare_sch constr_mv
cadsnap cadence_compat cairo_font_name cairo_font_scale change_lw color_ps tctx::colors compare_sch constr_mv
copy_cell crosshair_layer crosshair_size cursor_2_hook snap_cursor_size custom_label_prefix custom_token
dark_colors dark_colorscheme dark_gui_colorscheme delay_flag
dim_bg dim_value disable_unique_names do_all_inst draw_crosshair
Expand Down Expand Up @@ -8120,7 +8120,7 @@ proc build_widgets { {topwin {} } } {
global dark_gui_colorscheme draw_crosshair
global recentfile color_ps transparent_svg menu_debug_var enable_stretch
global netlist_show flat_netlist split_files compare_sch intuitive_interface
global draw_grid big_grid_points sym_txt change_lw incr_hilight symbol_width
global draw_grid big_grid_points sym_txt change_lw incr_hilight symbol_width cadence_compat
global cadsnap cadgrid draw_window toolbar_visible hide_symbols undo_type snap_cursor
global disable_unique_names persistent_command autotrim_wires infix_interface orthogonal_wiring en_hilight_conn_inst
global local_netlist_dir editor netlist_type netlist_dir spiceprefix initial_geometry
Expand Down Expand Up @@ -9184,9 +9184,10 @@ set_ne draw_grid_axes 1
set_ne persistent_command 0
set_ne intuitive_interface 1
set_ne autotrim_wires 0
set_ne infix_interface 0
set_ne cadence_compat 0
set_ne infix_interface 1
set_ne snap_cursor 0
set_ne orthogonal_wiring 1
set_ne orthogonal_wiring 0
set_ne compare_sch 0
set_ne disable_unique_names 0
set_ne sym_txt 1
Expand Down
9 changes: 6 additions & 3 deletions src/xschemrc
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@
#### wires are drawn in free-form mode with this mode enabled (default).
#### if set to 0, wires drawn on the schematic will no longer strictly
#### follow orthogonal routes to connect two distinct points together.
#### default: 1
# set orthogonal_wiring 0
#### default: 0
# set orthogonal_wiring 1

#### if set to 1 automatically join/trim wires while editing
#### this may slow down on rally big designs. Can be disabled via menu
Expand Down Expand Up @@ -283,14 +283,17 @@
# set crosshair_layer 8

#### set crosshair size; Default: 0 (full screen spanning crosshair)
set crosshair_size 2
# set crosshair_size 2

#### enable drawing a diamond-shaped cursor at the closest circuit endpoint. Default: disabled (0)
# set snap_cursor 1

#### set snap_cursor_size; Default: 6 (Diamond-shaped cursor that snaps to nearest circuit endpoint)
# set snap_cursor_size 6

#### set cadence_compat; Default: 0 (Cadence-style keybinds are not used by default)
# set cadence_compat 1

#### enable to scale grid point size as done with lines at close zoom, default: 0
# set big_grid_points 0

Expand Down

0 comments on commit d4b3881

Please sign in to comment.