1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/*
* COPYRIGHT
*
* pcb-rnd, interactive printed circuit board design
* (this file is based on PCB, interactive printed circuit board design)
* Copyright (C) 1994,1995,1996, 2005 Thomas Nau
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Contact:
* Project page: http://repo.hu/projects/pcb-rnd
* lead developer: http://repo.hu/projects/pcb-rnd/contact.html
* mailing list: pcb-rnd (at) list.repo.hu (send "subscribe")
*
*/
#include "config.h"
#include "conf_core.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "board.h"
#include "build_run.h"
#include "buffer.h"
#include "command.h"
#include "data.h"
#include <librnd/core/error.h>
#include <librnd/core/event.h>
#include "plug_io.h"
#include <librnd/core/plugins.h>
#include <librnd/core/actions.h>
#include <librnd/core/compat_misc.h>
#include <librnd/core/misc_util.h>
#include <librnd/hid/tool.h>
static const char pcb_acts_Help[] = "h";
static const char pcb_acth_Help[] = "Print a help message for commands.";
static fgw_error_t pcb_act_Help(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
rnd_message(RND_MSG_INFO,
"following shorthand commands are supported:\n"
" h display this help message\n"
" l [file] load layout\n"
" le [file] load element to buffer\n"
" m [file] load layout to buffer (merge)\n"
" q quits the application\n"
" q! quits without save warning\n"
" rn [file] read in a net-list file\n"
" s [file] save layout\n"
" w [file] save layout\n"
" wq [file] save layout and quit\n");
RND_ACT_IRES(0);
return 0;
}
static const char pcb_acts_LoadLayout[] = "l [name] [format]";
static const char pcb_acth_LoadLayout[] = "Loads layout data.";
/* DOC: l.html */
static fgw_error_t pcb_act_LoadLayout(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
const char *filename, *format = NULL;
RND_ACT_CONVARG(1, FGW_STR, LoadLayout, filename = argv[1].val.str);
RND_ACT_MAY_CONVARG(2, FGW_STR, LoadLayout, format = argv[2].val.str);
if (!PCB->Changed || (rnd_hid_message_box(RND_ACT_DESIGN, "warning", "Load data lose", "OK to override layout data?", "cancel", 0, "ok", 1, NULL) == 1))
pcb_load_pcb(filename, format, rnd_true, 0);
RND_ACT_IRES(0);
return 0;
}
static const char pcb_acts_LoadElementToBuffer[] = "le [name]";
static const char pcb_acth_LoadElementToBuffer[] = "Loads an element (subcircuit, footprint) into the current buffer.";
/* DOC: le.html */
static fgw_error_t pcb_act_LoadElementToBuffer(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
const char *filename;
RND_ACT_CONVARG(1, FGW_STR, LoadElementToBuffer, filename = argv[1].val.str);
if (pcb_buffer_load_footprint(PCB_PASTEBUFFER, filename, NULL))
rnd_tool_select_by_name(&PCB->hidlib, "buffer");
RND_ACT_IRES(0);
return 0;
}
static const char pcb_acts_LoadLayoutToBuffer[] = "m [name]";
static const char pcb_acth_LoadLayoutToBuffer[] = "Loads a layout into the current buffer.";
/* DOC: m.html */
static fgw_error_t pcb_act_LoadLayoutToBuffer(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
const char *filename, *format = NULL;
RND_ACT_CONVARG(1, FGW_STR, LoadLayoutToBuffer, filename = argv[1].val.str);
RND_ACT_MAY_CONVARG(2, FGW_STR, LoadLayoutToBuffer, format = argv[2].val.str);
if (pcb_buffer_load_layout(PCB, PCB_PASTEBUFFER, filename, format))
rnd_tool_select_by_name(&PCB->hidlib, "buffer");
RND_ACT_IRES(0);
return 0;
}
static const char pcb_acts_Quit[] = "q";
static const char pcb_acth_Quit[] = "Quits the application after confirming.";
/* DOC: q.html */
static fgw_error_t pcb_act_Quit(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
if (!PCB->Changed || (rnd_hid_message_box(RND_ACT_DESIGN, "warning", "Close: lose data", "OK to lose data?", "cancel", 0, "ok", 1, NULL) == 1))
pcb_quit_app();
RND_ACT_IRES(0);
return 0;
}
static const char pcb_acts_ReallyQuit[] = "q!";
static const char pcb_acth_ReallyQuit[] = "Quits the application without confirming.";
/* DOC: q.html */
static fgw_error_t pcb_act_ReallyQuit(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
pcb_quit_app();
RND_ACT_IRES(0);
return 0;
}
static const char pcb_acts_LoadNetlist[] = "rn [name]";
static const char pcb_acth_LoadNetlist[] = "Reads netlist.";
/* DOC: rn.html */
static fgw_error_t pcb_act_LoadNetlist(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
const char *filename;
RND_ACT_CONVARG(1, FGW_STR, LoadNetlist, filename = argv[1].val.str);
if (PCB->Netlistname)
free(PCB->Netlistname);
PCB->Netlistname = rnd_strdup_strip_wspace(filename);
RND_ACT_IRES(0);
return 0;
}
static const char pcb_acts_SaveLayout[] = "s [name]\nw [name]";
static const char pcb_acth_SaveLayout[] = "Saves layout data.";
/* DOC: s.html w.html */
static fgw_error_t pcb_act_SaveLayout(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
const char *filename = NULL;
RND_ACT_MAY_CONVARG(1, FGW_STR, SaveLayout, filename = argv[1].val.str);
if (filename == NULL) {
if (PCB->hidlib.loadname) {
if (pcb_save_pcb(PCB->hidlib.loadname, NULL) == 0)
pcb_board_set_changed_flag(PCB, rnd_false);
}
else
rnd_message(RND_MSG_ERROR, "No filename to save to yet\n");
}
else {
if (pcb_save_pcb(filename, NULL) == 0) {
pcb_board_set_changed_flag(PCB, rnd_false);
free(PCB->hidlib.loadname);
PCB->hidlib.loadname = rnd_strdup(filename);
rnd_event(&PCB->hidlib, RND_EVENT_DESIGN_FN_CHANGED, NULL);
}
}
RND_ACT_IRES(0);
return 0;
}
static const char pcb_acts_SaveLayoutAndQuit[] = "wq";
static const char pcb_acth_SaveLayoutAndQuit[] = "Saves the layout data and quits.";
/* DOC: wq.html */
static fgw_error_t pcb_act_SaveLayoutAndQuit(fgw_arg_t *res, int argc, fgw_arg_t *argv)
{
if (RND_ACT_CALL_C(RND_ACT_DESIGN, pcb_act_SaveLayout, res, argc, argv) == 0)
return pcb_act_Quit(res, argc, argv);
RND_ACT_IRES(1);
return 0;
}
rnd_action_t shand_cmd_action_list[] = {
{"h", pcb_act_Help, pcb_acth_Help, pcb_acts_Help},
{"l", pcb_act_LoadLayout, pcb_acth_LoadLayout, pcb_acts_LoadLayout},
{"le", pcb_act_LoadElementToBuffer, pcb_acth_LoadElementToBuffer, pcb_acts_LoadElementToBuffer},
{"m", pcb_act_LoadLayoutToBuffer, pcb_acth_LoadLayoutToBuffer, pcb_acts_LoadLayoutToBuffer},
{"q", pcb_act_Quit, pcb_acth_Quit, pcb_acts_Quit},
{"q!", pcb_act_ReallyQuit, pcb_acth_ReallyQuit, pcb_acts_ReallyQuit},
{"rn", pcb_act_LoadNetlist, pcb_acth_LoadNetlist, pcb_acts_LoadNetlist},
{"s", pcb_act_SaveLayout, pcb_acth_SaveLayout, pcb_acts_SaveLayout},
{"w", pcb_act_SaveLayout, pcb_acth_SaveLayout, pcb_acts_SaveLayout},
{"wq", pcb_act_SaveLayoutAndQuit, pcb_acth_SaveLayoutAndQuit, pcb_acts_SaveLayoutAndQuit}
};
static const char *shand_cmd_cookie = "shand_cmd plugin";
int pplg_check_ver_shand_cmd(int ver_needed) { return 0; }
void pplg_uninit_shand_cmd(void)
{
rnd_remove_actions_by_cookie(shand_cmd_cookie);
}
int pplg_init_shand_cmd(void)
{
RND_API_CHK_VER;
RND_REGISTER_ACTIONS(shand_cmd_action_list, shand_cmd_cookie)
return 0;
}
|