Skip to content

Commit

Permalink
[Interposer] Added support for run_drc
Browse files Browse the repository at this point in the history
- Only KiCad 5
- Avoid Unicode errors (generated by KiCad 5)
- Added more debug to the refill test
  • Loading branch information
set-soft committed Aug 1, 2022
1 parent c8a0f03 commit 9d040da
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
22 changes: 22 additions & 0 deletions interposer/interposer.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,25 @@ GtkPrintOperationResult gtk_print_operation_run(GtkPrintOperation* op, GtkPrintO
return res;
}


void gtk_label_set_text_with_mnemonic(GtkLabel *label, const gchar *str)
{
static void (*next_func)(GtkLabel *label, const gchar *str)=NULL;

if (next_func==NULL)
{ /* Initialization */
char *msg;
printf("* wrapping label set text\n");
next_func=dlsym(RTLD_NEXT,"gtk_label_set_text_with_mnemonic");
if ((msg=dlerror())!=NULL)
printf("** dlopen failed : %s\n", msg);
}

if (g_strcmp0(str, "Report all errors for tracks (slower)")==0)
str="_Report all errors for tracks (slower)";
next_func(label, str);

printf("GTK:Label Set Text 2:%s\n", str);
fflush(stdout);
}

Binary file modified interposer/libinterposer.so
Binary file not shown.
50 changes: 46 additions & 4 deletions src/pcbnew_do
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ def print_layers(cfg, id_pcbnew):
# to just use the menu accelerators (removed on KiCad 6)
print_dialog_keys = ['alt+f', 'p']
if use_interposer:
# TODO: Not sure if worst the effort, is marginally faster and doesn't look to be more reliable
return print_layers_i(cfg, id_pcbnew, print_dialog_keys)
return print_layers_n(cfg, id_pcbnew, print_dialog_keys)

Expand Down Expand Up @@ -720,7 +719,7 @@ def run_drc_python(cfg):
cfg.board.Save(cfg.input_file)


def run_drc(cfg):
def run_drc_n(cfg):
if not cfg.ki5:
run_drc_6_0(cfg)
else:
Expand All @@ -738,6 +737,48 @@ def run_drc(cfg):
exit_pcbnew(cfg)


def run_drc_5_1_i(cfg):
open_dialog_i('DRC Control', ['key', 'alt+i', 'd'])
logger.info('Enable reporting all errors for tracks')
wait_point(cfg)
# Here we added a shortcut for "Report all errors for tracks (slower)"
xdotool(['key', 'alt+r', 'Tab', 'Tab', 'Tab', 'Tab'])
paste_output_file_i(cfg)
open_dialog_i('Disk File Report Completed', ['key', 'Return'])
wait_for_window('Report completed dialog', 'Disk File Report Completed')
wait_point(cfg)
xdotool(['key', 'Return'])
wait_for_window('DRC modal window', 'DRC Control')
logger.info('Closing the DRC dialog')
wait_point(cfg)
xdotool(['key', 'shift+Tab', 'Return'])
wait_pcbnew()


def run_drc_i(cfg):
if not cfg.ki5:
run_drc_6_0_i(cfg)
else:
run_drc_5_1_i(cfg)
# Save the PCB
if cfg.save:
logger.info('Saving PCB')
wait_point(cfg)
os.rename(cfg.input_file, cfg.input_file + '-bak')
xdotool(['key', 'ctrl+s'])
logger.info('Wait for PCB file creation')
wait_point(cfg)
wait_for_file_created_by_process(cfg.pcbnew_pid, os.path.realpath(cfg.input_file))
# Exit
exit_pcbnew_i(cfg)


def run_drc(cfg):
if use_interposer and cfg.ki5:
return run_drc_i(cfg)
return run_drc_n(cfg)


def export_gencad(cfg):
wait_point(cfg)
if cfg.ki5:
Expand Down Expand Up @@ -1625,6 +1666,8 @@ def start_queue(cfg):
It will collect all messages from the interposer. """
logger.debug('Starting queue thread')
cfg.kicad_q = Queue()
# Avoid crashes when KiCad 5 sends an invalid Unicode sequence
cfg.popen_obj.stdout.reconfigure(errors='ignore')
cfg.kicad_t = Thread(target=enqueue_output, args=(cfg.popen_obj.stdout, cfg.kicad_q))
cfg.kicad_t.daemon = True # thread dies with the program
cfg.kicad_t.start()
Expand Down Expand Up @@ -1906,8 +1949,7 @@ if __name__ == '__main__':
else:
os.environ['LD_PRELOAD'] = interposer_lib
logger.debug('** Using interposer: '+interposer_lib)
use_interposer = interposer_lib and (args.command == '3d_view' or args.command == 'export_gencad' or
args.command == 'ipc_netlist' or args.command == 'export')
use_interposer = interposer_lib
enable_interposer = (interposer_lib and args.interposer_sniff) or use_interposer
#
# Do all the work
Expand Down
2 changes: 1 addition & 1 deletion tests/pcbnew/test_print_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_print_pcb_good_wm(test_dir):
def test_print_pcb_refill(test_dir):
ctx = context.TestContext(test_dir, 'Print_Refill', 'zone-refill')
pdf = 'zone-refill.pdf'
cmd = [PROG, '-v', 'export', '-f', '--output_name', pdf]
cmd = [PROG, '-vvv', 'export', '-f', '--output_name', pdf]
layers = ['F.Cu', 'B.Cu', 'Edge.Cuts']
ctx.run(cmd, extra=layers)
ctx.expect_out_file(pdf)
Expand Down

0 comments on commit 9d040da

Please sign in to comment.