kicad-patches/scripted-new.patch |
| 1 | diff -ruN kicad.orig/eeschema/eeschema_scripted.cpp kicad/eeschema/eeschema_scripted.cpp |
| 2 | --- kicad.orig/eeschema/eeschema_scripted.cpp 1970-01-01 00:00:00.000000000 +0000 |
| 3 | @@ -0,0 +1,251 @@ |
| 4 | +///////////////////////////////////////////////////////////////////////////// |
| 5 | +// Name: eeschema_scripted.cpp |
| 6 | +// Copyright: Werner Almesberger, Wolfgang Spraul |
| 7 | +// Licence: GPL v2 or higher |
| 8 | +///////////////////////////////////////////////////////////////////////////// |
| 9 | + |
| 10 | +#include "fctsys.h" |
| 11 | +#include "appl_wxstruct.h" |
| 12 | +#include "common.h" |
| 13 | +#include "program.h" |
| 14 | +#include "general.h" |
| 15 | +#include "netlist.h" |
| 16 | +#include "protos.h" |
| 17 | +#include "gr_basic.h" |
| 18 | +#include "plotps.h" |
| 19 | +#include "wx/cmdline.h" |
| 20 | +#include "dialog_build_BOM.h" |
| 21 | +#include "dialog_SVG_print_base.h" |
| 22 | +#include "dialog_erc.h" |
| 23 | +#include "plotdxf.h" |
| 24 | +#include "class_drawsheetpath.h" |
| 25 | +#include "eeschema_scripted.h" |
| 26 | + |
| 27 | +EESCHEMA_SCRIPTED g_EESchemaScripted; |
| 28 | + |
| 29 | +static const wxCmdLineEntryDesc g_cmdLineDesc [] = |
| 30 | +{ |
| 31 | + { wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("displays help on the command line parameters"), |
| 32 | + wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, |
| 33 | + |
| 34 | + { wxCMD_LINE_SWITCH, wxT("l"), wxT("list-sheets"), wxT("list schematics pages") }, |
| 35 | + |
| 36 | + { wxCMD_LINE_OPTION, wxT("px"), wxT("plotx"), wxT("plots the board [ps|svg|dxf]"), |
| 37 | + wxCMD_LINE_VAL_STRING }, |
| 38 | + { wxCMD_LINE_SWITCH, wxT("plotx-bw"), wxT("plotx-bw"), wxT("plot: black & white (default: color)") }, |
| 39 | + { wxCMD_LINE_SWITCH, wxT("plotx-sheetref"), wxT("plotx-sheetref"), wxT("plot: print sheet reference (default: off)") }, |
| 40 | + { wxCMD_LINE_SWITCH, wxT("p"), wxT("plot"), wxT("plots the schematics (deprecated, use --plotx=ps --plotx-bw)") }, |
| 41 | + |
| 42 | + { wxCMD_LINE_SWITCH, wxT("b"), wxT("bom"), wxT("generate bill of materials (.bom)") }, |
| 43 | + { wxCMD_LINE_SWITCH, wxT("e"), wxT("erc"), wxT("generate electric rules check (.erc) file") }, |
| 44 | + { wxCMD_LINE_SWITCH, wxT("n"), wxT("netlist"), wxT("generate netlist (.net)") }, |
| 45 | + { wxCMD_LINE_PARAM, 0, 0, wxT("<path to .sch file>"), |
| 46 | + wxCMD_LINE_VAL_STRING }, |
| 47 | + { wxCMD_LINE_NONE } |
| 48 | +}; |
| 49 | + |
| 50 | +bool ScriptedDrawSVGPage( WinEDA_DrawFrame * frame, |
| 51 | + const wxString& FullFileName, BASE_SCREEN* screen, |
| 52 | + bool aPrintBlackAndWhite = false, |
| 53 | + bool aPrint_Sheet_Ref = false); |
| 54 | + |
| 55 | +bool EESCHEMA_SCRIPTED::Run() |
| 56 | +{ |
| 57 | + wxFileName fn; |
| 58 | + WinEDA_SchematicFrame* frame; |
| 59 | + wxCommandEvent DummyCmd; |
| 60 | + wxString str; |
| 61 | + int i; |
| 62 | + |
| 63 | + WinEDA_App& app = wxGetApp(); |
| 64 | + if (app.argc < 2 || app.argv[1][0] != '-') |
| 65 | + return false; |
| 66 | + g_IsScripted = true; |
| 67 | + wxLog::EnableLogging(false); // this should suppress some wx dialogs |
| 68 | + app.InitEDA_Appl( wxT( "EESchema" ), APP_TYPE_EESCHEMA ); |
| 69 | + |
| 70 | + wxCmdLineParser parser; |
| 71 | + parser.SetDesc(g_cmdLineDesc); |
| 72 | + parser.SetCmdLine(app.argc, app.argv); |
| 73 | + if (parser.Parse()) |
| 74 | + return true; |
| 75 | + |
| 76 | + i = parser.Found( _("list-sheets") ) |
| 77 | + + parser.Found( _("plot") ) |
| 78 | + + parser.Found( _("plotx") ) |
| 79 | + + parser.Found( _("bom") ) |
| 80 | + + parser.Found( _("erc") ) |
| 81 | + + parser.Found( _("netlist") ); |
| 82 | + if ( !i ) |
| 83 | + { |
| 84 | + wxPrintf(wxT("One of --list-sheets --plot --plotx --bom --erc --netlist must be given.\n")); |
| 85 | + return true; |
| 86 | + } |
| 87 | + if ( i > 1 ) |
| 88 | + { |
| 89 | + wxPrintf(wxT("Only one of --list-sheets --plot --plotx --bom --erc --netlist may be given at a time.\n")); |
| 90 | + return true; |
| 91 | + } |
| 92 | + |
| 93 | + // parse plotting parameters |
| 94 | + enum PlotCommand { |
| 95 | + PLOT_NONE, |
| 96 | + PLOT_PS, |
| 97 | + PLOT_SVG, |
| 98 | + PLOT_DXF |
| 99 | + } PlotCmd; |
| 100 | + bool PlotBW; |
| 101 | + bool PlotSheetRef; |
| 102 | + |
| 103 | + PlotCmd = PLOT_NONE; |
| 104 | + if ( parser.Found( wxT("plot") ) ) // legacy parameter originally introduced by |
| 105 | + // Werner, still used in schhist and other places |
| 106 | + { |
| 107 | + PlotCmd = PLOT_PS; |
| 108 | + PlotBW = true; |
| 109 | + PlotSheetRef = false; |
| 110 | + } |
| 111 | + else if ( parser.Found( _("plotx"), &str ) ) |
| 112 | + { |
| 113 | + if (!str.CmpNoCase( wxT("ps") ) ) |
| 114 | + PlotCmd = PLOT_PS; |
| 115 | + else if ( !str.CmpNoCase( wxT("svg") ) ) |
| 116 | + PlotCmd = PLOT_SVG; |
| 117 | + else if ( !str.CmpNoCase( wxT("dxf") ) ) |
| 118 | + PlotCmd = PLOT_DXF; |
| 119 | + else |
| 120 | + { |
| 121 | + parser.Usage(); |
| 122 | + wxPrintf(wxT("Unexpected plot format '%ls'.\n"), str.c_str()); |
| 123 | + return true; |
| 124 | + } |
| 125 | + PlotBW = parser.Found( _("plotx-bw") ); |
| 126 | + PlotSheetRef = parser.Found( _("plotx-sheetref") ); |
| 127 | + } |
| 128 | + |
| 129 | + fn = parser.GetParam(); |
| 130 | + if( fn.GetExt() != SchematicFileExtension ) |
| 131 | + { |
| 132 | + wxLogDebug( wxT( "eeschema file <%s> has the wrong extension. Changing extension to .sch." ), GetChars( fn.GetFullPath() ) ); |
| 133 | + fn.SetExt( PcbFileExtension ); |
| 134 | + } |
| 135 | + if( !fn.FileExists()) |
| 136 | + { |
| 137 | + wxPrintf( wxT("%ls: file '%ls' does not exist.\n" ), app.argv[0], fn.GetFullPath().c_str() ); |
| 138 | + return true; |
| 139 | + } |
| 140 | + wxSetWorkingDirectory( fn.GetPath() ); |
| 141 | + |
| 142 | + g_DrawBgColor = BLACK; |
| 143 | + SeedLayers(); |
| 144 | + frame = new WinEDA_SchematicFrame( NULL, wxT( "EESchema" ), |
| 145 | + wxPoint( 0, 0 ), wxSize( 600, 400 ) ); |
| 146 | + ActiveScreen = frame->GetScreen(); |
| 147 | +#if 0 // enable this to see more of the GUI |
| 148 | + app.SetTopWindow( frame ); |
| 149 | + frame->Show( true ); |
| 150 | +#endif |
| 151 | + if( !frame->LoadOneEEProject( fn.GetFullPath(), false ) ) |
| 152 | + { |
| 153 | + fprintf( stderr, "%ls: can't load\n", fn.GetFullPath().c_str() ); |
| 154 | + return true; |
| 155 | + } |
| 156 | + |
| 157 | + if ( parser.Found( wxT("list-sheets") ) ) // class_drawsheetpath.h |
| 158 | + // dialog_SVG_print.cpp:DIALOG_SVG_PRINT:PrintSVGDoc() |
| 159 | + { |
| 160 | + SCH_SHEET_LIST SheetList( 0 /* aSheet */ ); |
| 161 | + SCH_SHEET_PATH* sheetpath, *oldsheetpath; |
| 162 | + SCH_SHEET_PATH list; |
| 163 | + SCH_SCREEN* schscreen; |
| 164 | + |
| 165 | + oldsheetpath = frame->GetSheet(); |
| 166 | + sheetpath = SheetList.GetFirst(); |
| 167 | + while ( sheetpath ) |
| 168 | + { |
| 169 | + list.Clear(); |
| 170 | + if ( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) |
| 171 | + { |
| 172 | + frame->m_CurrentSheet = &list; |
| 173 | + frame->m_CurrentSheet->UpdateAllScreenReferences(); |
| 174 | + frame->SetSheetNumberAndCount(); |
| 175 | + schscreen = frame->m_CurrentSheet->LastScreen(); |
| 176 | + ActiveScreen = schscreen; |
| 177 | + |
| 178 | + wxPrintf( sheetpath->Path() + _(" ") |
| 179 | + + sheetpath->PathHumanReadable() + _(" ") |
| 180 | + + sheetpath->Last()->GetFileName() + _(" ") |
| 181 | + + frame->GetUniqueFilenameForCurrentSheet( ) + wxT( ".sch\n") ); |
| 182 | + } |
| 183 | + sheetpath = SheetList.GetNext(); |
| 184 | + } |
| 185 | + frame->m_CurrentSheet = oldsheetpath; |
| 186 | + frame->m_CurrentSheet->UpdateAllScreenReferences(); |
| 187 | + frame->SetSheetNumberAndCount(); |
| 188 | + } |
| 189 | + else if ( PlotCmd == PLOT_PS ) // plotps.cpp |
| 190 | + { |
| 191 | + // values must be idential to plotps.cpp:PageFormatReq |
| 192 | + enum PageFormatReq { |
| 193 | + PAGE_SIZE_AUTO, |
| 194 | + PAGE_SIZE_A4, |
| 195 | + PAGE_SIZE_A |
| 196 | + }; |
| 197 | + |
| 198 | + WinEDA_PlotPSFrame* PlotPSFrame = new WinEDA_PlotPSFrame( frame ); |
| 199 | + PlotPSFrame->m_Plot_Sheet_Ref->SetValue( PlotSheetRef ); |
| 200 | + |
| 201 | + // Strangely it seems that the plots come out right when 'A4' is |
| 202 | + // selected, even if it's actually not A4 format. But when PAGE_SIZE_AUTO |
| 203 | + // is selected, pages are cut off. Until we understand this better we |
| 204 | + // always use A4. |
| 205 | + PlotPSFrame->m_SizeOption->SetSelection( PAGE_SIZE_A4 ); |
| 206 | + |
| 207 | + PlotPSFrame->m_PlotPSColorOption->SetSelection( !PlotBW ); |
| 208 | + PlotPSFrame->OnPlotPsAllExecuteClick( DummyCmd ); |
| 209 | + delete PlotPSFrame; |
| 210 | + } |
| 211 | + else if ( PlotCmd == PLOT_SVG ) // dialog_SVG_print.cpp:DIALOG_SVG_PRINT::DrawSVGPage() |
| 212 | + { |
| 213 | + void ScriptedPrintSVGDoc( WinEDA_DrawFrame* frame, bool aPrintAll, bool aPrint_Sheet_Ref, bool aPrintBlackAndWhite ); |
| 214 | + ScriptedPrintSVGDoc( frame, true /* aPrintAll */, PlotSheetRef, PlotBW ); |
| 215 | + } |
| 216 | + else if ( PlotCmd == PLOT_DXF ) // plotdxf.cpp:WinEDA_PlotDXFFrame::CreateDXFFile() |
| 217 | + { |
| 218 | + WinEDA_PlotDXFFrame* PlotDXFFrame = new WinEDA_PlotDXFFrame( frame ); |
| 219 | + PlotDXFFrame->m_Plot_Sheet_Ref->SetValue( PlotSheetRef ); |
| 220 | + PlotDXFFrame->m_PlotDXFColorOption->SetSelection( !PlotBW ); |
| 221 | + PlotDXFFrame->OnPlotDXFAllExecuteClick( DummyCmd ); |
| 222 | + delete PlotDXFFrame; |
| 223 | + } |
| 224 | + else if ( parser.Found( wxT("bom") ) ) // see build_BOM.cpp:DIALOG_BUILD_BOM::GenereListeOfItems() |
| 225 | + { |
| 226 | + DIALOG_BUILD_BOM* dlg = new DIALOG_BUILD_BOM( frame ); |
| 227 | + |
| 228 | + dlg->m_ListCmpbyRefItems->SetValue( true ); |
| 229 | + dlg->m_AddFootprintField->SetValue( true ); |
| 230 | + dlg->m_AddAllFields->SetValue( true ); |
| 231 | + |
| 232 | + fn = ActiveScreen->m_FileName; |
| 233 | + fn.SetExt( wxT( "lst" ) ); |
| 234 | + dlg->GenereListeOfItems( fn.GetFullPath(), false /* aIncludeSubComponents */ ); |
| 235 | + delete dlg; |
| 236 | + } |
| 237 | + else if ( parser.Found( wxT("erc") ) ) // erc.cpp:DIALOG_ERC::TestErc() |
| 238 | + { |
| 239 | + DIALOG_ERC* dlg = new DIALOG_ERC( frame ); |
| 240 | + dlg->m_WriteResultOpt->SetValue( true ); |
| 241 | + dlg->TestErc( 0 /* messageList */ ); |
| 242 | + delete dlg; |
| 243 | + } |
| 244 | + else if ( parser.Found( wxT("netlist") ) ) // netlist_control.cpp:WinEDA_SchematicFrame::CreateNetlist() |
| 245 | + { |
| 246 | + frame->BuildNetListBase(); |
| 247 | + fn = ActiveScreen->m_FileName; |
| 248 | + fn.SetExt( wxT( "net" ) ); |
| 249 | + frame->WriteNetListFile( NET_TYPE_PCBNEW /* aFormat */, fn.GetFullPath(), false /* aUse_netnames - only used for Spice */ ); |
| 250 | + } |
| 251 | + |
| 252 | + delete frame; |
| 253 | + return true; |
| 254 | +} |
| 255 | diff -ruN kicad.orig/eeschema/eeschema_scripted.h kicad/eeschema/eeschema_scripted.h |
| 256 | --- kicad.orig/eeschema/eeschema_scripted.h 1970-01-01 00:00:00.000000000 +0000 |
| 257 | @@ -0,0 +1,14 @@ |
| 258 | +///////////////////////////////////////////////////////////////////////////// |
| 259 | +// Name: eeschema_scripted.h |
| 260 | +// Copyright: Wolfgang Spraul |
| 261 | +// Licence: GPL v3 or higher |
| 262 | +///////////////////////////////////////////////////////////////////////////// |
| 263 | + |
| 264 | +class EESCHEMA_SCRIPTED |
| 265 | +{ |
| 266 | +public: |
| 267 | + EESCHEMA_SCRIPTED() { } |
| 268 | + bool Run(); |
| 269 | +}; |
| 270 | + |
| 271 | +extern EESCHEMA_SCRIPTED g_EESchemaScripted; |
| 272 | diff -ruN kicad.orig/pcbnew/pcbnew_scripted.cpp kicad/pcbnew/pcbnew_scripted.cpp |
| 273 | --- kicad.orig/pcbnew/pcbnew_scripted.cpp 1970-01-01 00:00:00.000000000 +0000 |
| 274 | @@ -0,0 +1,552 @@ |
| 275 | +///////////////////////////////////////////////////////////////////////////// |
| 276 | +// Name: pcbnew_scripted.cpp |
| 277 | +// Copyright: Wolfgang Spraul |
| 278 | +// Licence: GPL v3 or higher |
| 279 | +///////////////////////////////////////////////////////////////////////////// |
| 280 | + |
| 281 | +#include "fctsys.h" |
| 282 | +#include "appl_wxstruct.h" |
| 283 | +#include "confirm.h" |
| 284 | + |
| 285 | +#include <wx/file.h> |
| 286 | +#include <wx/snglinst.h> |
| 287 | +#include <wx/cmdline.h> |
| 288 | +#include <wx/tokenzr.h> |
| 289 | +#include <wx/svg/dcsvg.h> |
| 290 | + |
| 291 | +#include "common.h" |
| 292 | +#include "pcbnew.h" |
| 293 | +#include "wxPcbStruct.h" |
| 294 | +#include "plot_common.h" |
| 295 | +#include "gestfich.h" |
| 296 | +#include "pcbplot.h" |
| 297 | +#include "autorout.h" |
| 298 | +#include "cell.h" |
| 299 | +#include "worksheet.h" |
| 300 | +#include "zones.h" |
| 301 | +#include "drag.h" |
| 302 | +#include "eda_dde.h" |
| 303 | +#include "colors_selection.h" |
| 304 | +#include "class_drawpanel.h" |
| 305 | + |
| 306 | +#include "id.h" |
| 307 | + |
| 308 | +#include "build_version.h" |
| 309 | + |
| 310 | +#include "protos.h" |
| 311 | +#include "pcbnew_scripted.h" |
| 312 | +#include "gendrill.h" |
| 313 | +#include "dialog_gendrill.h" |
| 314 | +#include "dialog_drc.h" |
| 315 | +#include "printout_controler.h" |
| 316 | + |
| 317 | +extern int g_DrawDefaultLineThickness; |
| 318 | + |
| 319 | +static const wxCmdLineEntryDesc g_cmdLineDesc [] = |
| 320 | +{ |
| 321 | + { wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("displays help on the command line parameters"), |
| 322 | + wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, |
| 323 | + { wxCMD_LINE_SWITCH, wxT("d"), wxT("drill"), wxT("generates a .drl drill file") }, |
| 324 | + { wxCMD_LINE_SWITCH, wxT("list-layers"), wxT("list-layers"), wxT("lists the names of all enabled layers in the .brd file") }, |
| 325 | + { wxCMD_LINE_OPTION, wxT("p"), wxT("plot"), wxT("plots the board [hpgl|gerber|ps|ps_a4|dxf]"), |
| 326 | + wxCMD_LINE_VAL_STRING }, |
| 327 | + { wxCMD_LINE_OPTION, wxT("l"), wxT("layers"), wxT("comma separated list of layer names (default: all enabled layers)"), |
| 328 | + wxCMD_LINE_VAL_STRING }, |
| 329 | + { wxCMD_LINE_OPTION, wxT("ps-pads-drill-opt"), wxT("ps-pads-drill-opt"), wxT("Postscript pads drill option [none|small|real] (default:small)"), |
| 330 | + wxCMD_LINE_VAL_STRING }, |
| 331 | + { wxCMD_LINE_SWITCH, wxT("mirror"), wxT("mirror"), wxT("mirror plot (HPGL and Postscript only)") }, |
| 332 | + { wxCMD_LINE_SWITCH, wxT("fill-all-zones"), wxT("fill-all-zones"), wxT("fill zones before plotting") }, |
| 333 | + { wxCMD_LINE_SWITCH, wxT("drc"), wxT("drc"), wxT("generates a design rule check report (.rpt)") }, |
| 334 | + { wxCMD_LINE_SWITCH, wxT("svg"), wxT("svg"), wxT("plots the board in SVG format") }, |
| 335 | + { wxCMD_LINE_SWITCH, wxT("svg-merge"), wxT("svg-merge-layers"), wxT("merge layers into one SVG file") }, |
| 336 | + { wxCMD_LINE_SWITCH, wxT("svg-edge"), wxT("svg-board-edges"), wxT("add board edges to SVG plots") }, |
| 337 | + { wxCMD_LINE_SWITCH, wxT("pos"), wxT("pos"), wxT("create front and back .pos component position files") }, |
| 338 | + { wxCMD_LINE_SWITCH, wxT("bom"), wxT("bom"), wxT("create a .csv bom") }, |
| 339 | + { wxCMD_LINE_SWITCH, wxT("cmp"), wxT("cmp"), wxT("recreate .cmp components file for CvPcb") }, |
| 340 | + { wxCMD_LINE_SWITCH, wxT("vrml"), wxT("vrml"), wxT("generates a .wrl vrml board representation") }, |
| 341 | + { wxCMD_LINE_PARAM, 0, 0, wxT("<path to .brd file>"), |
| 342 | + wxCMD_LINE_VAL_STRING }, |
| 343 | + { wxCMD_LINE_NONE } |
| 344 | +}; |
| 345 | + |
| 346 | +bool Pcbnew_Scripted() |
| 347 | +{ |
| 348 | + wxFileName fn; |
| 349 | + wxString str; |
| 350 | + WinEDA_PcbFrame* frame = NULL; |
| 351 | + wxCommandEvent dummy; |
| 352 | + int i; |
| 353 | + |
| 354 | + WinEDA_App& app = wxGetApp(); |
| 355 | + if (app.argc < 2 || app.argv[1][0] != '-') |
| 356 | + return false; |
| 357 | + g_IsScripted = true; |
| 358 | + wxLog::EnableLogging(false); // this should suppress some wx dialogs |
| 359 | + app.InitEDA_Appl( wxT( "PCBnew" ), APP_TYPE_PCBNEW ); |
| 360 | + |
| 361 | + wxCmdLineParser parser; |
| 362 | + parser.SetDesc(g_cmdLineDesc); |
| 363 | + parser.SetCmdLine(app.argc, app.argv); |
| 364 | + if (parser.Parse()) |
| 365 | + return true; |
| 366 | + if ( parser.Found( wxT("ps-pads-drill-opt"), &str ) |
| 367 | + && str.CmpNoCase( wxT("none") ) |
| 368 | + && str.CmpNoCase( wxT("small") ) |
| 369 | + && str.CmpNoCase( wxT("real") )) |
| 370 | + { |
| 371 | + parser.Usage(); |
| 372 | + wxPrintf(wxT("Unexpected pads drill option '%ls'.\n"), str.c_str()); |
| 373 | + return true; |
| 374 | + } |
| 375 | + i = parser.Found( _("drill") ) |
| 376 | + + parser.Found( _("list-layers") ) |
| 377 | + + parser.Found( _("plot") ) |
| 378 | + + parser.Found( _("drc") ) |
| 379 | + + parser.Found( _("svg") ) |
| 380 | + + parser.Found( _("pos") ) |
| 381 | + + parser.Found( _("bom") ) |
| 382 | + + parser.Found( _("cmp") ) |
| 383 | + + parser.Found( _("vrml") ); |
| 384 | + if ( !i ) |
| 385 | + { |
| 386 | + wxPrintf(wxT("One of --drill --list-layers --plot --drc --svg --pos --bom --cmp --vrml must be given.\n")); |
| 387 | + return true; |
| 388 | + } |
| 389 | + if ( i > 1 ) |
| 390 | + { |
| 391 | + wxPrintf(wxT("Only one of --drill --list-layers --plot --drc --svg --pos --bom --cmp --vrml may be given at a time.\n")); |
| 392 | + return true; |
| 393 | + } |
| 394 | + |
| 395 | + fn = parser.GetParam(); |
| 396 | + if( fn.GetExt() != PcbFileExtension ) |
| 397 | + { |
| 398 | + wxLogDebug( wxT( "PcbNew file <%s> has the wrong extension. Changing extension to .brd." ), GetChars( fn.GetFullPath() ) ); |
| 399 | + fn.SetExt( PcbFileExtension ); |
| 400 | + } |
| 401 | + if( !fn.FileExists()) |
| 402 | + { |
| 403 | + wxPrintf( wxT("%ls: file '%ls' does not exist.\n" ), app.argv[0], fn.GetFullPath().c_str() ); |
| 404 | + exit(0); |
| 405 | + } |
| 406 | + wxSetWorkingDirectory( fn.GetPath() ); |
| 407 | + |
| 408 | + app.InitEDA_Appl( wxT( "PCBnew" ), APP_TYPE_PCBNEW ); |
| 409 | + ScreenPcb = new PCB_SCREEN(); |
| 410 | + ActiveScreen = ScreenPcb; |
| 411 | + app.GetSettings( false /* reopenLastUsedDirectory */ ); |
| 412 | + |
| 413 | + g_DrawBgColor = BLACK; |
| 414 | + frame = new WinEDA_PcbFrame( NULL, wxT( "PcbNew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) ); |
| 415 | + |
| 416 | +#if 0 // enable this to see more of the GUI |
| 417 | + app.SetTopWindow( frame ); |
| 418 | + frame->Show( true ); |
| 419 | + frame->Zoom_Automatique( true ); |
| 420 | +#endif |
| 421 | + |
| 422 | + frame->LoadOnePcbFile( fn.GetFullPath() ); |
| 423 | + frame->LoadProjectSettings( fn.GetFullPath() ); |
| 424 | + |
| 425 | + if ( parser.Found( wxT("drill") ) ) |
| 426 | + { |
| 427 | + DIALOG_GENDRILL* drill_frame = new DIALOG_GENDRILL( frame ); |
| 428 | + drill_frame->GenDrillFiles( dummy ); |
| 429 | + delete drill_frame; |
| 430 | + } |
| 431 | + if ( parser.Found( wxT("list-layers") ) ) |
| 432 | + { |
| 433 | + for ( i = 0; i < NB_LAYERS; i++ ) |
| 434 | + { |
| 435 | + if( frame->GetBoard()->IsLayerEnabled( i ) ) |
| 436 | + { |
| 437 | + str = frame->GetBoard()->GetLayerName( i ); |
| 438 | + str.Trim( true ); str.Trim( false ); // remove leading and trailing spaces if any |
| 439 | + wxPrintf(str + _("\n")); |
| 440 | + } |
| 441 | + } |
| 442 | + } |
| 443 | + if ( parser.Found( wxT("plot"), &str ) ) // see pcbplot.cpp |
| 444 | + { |
| 445 | + bool ps_use_a4; |
| 446 | + int plot_format; |
| 447 | + wxString ext, layers_str; |
| 448 | + |
| 449 | + g_pcb_plot_options.PlotLine_Width = g_DrawDefaultLineThickness; |
| 450 | + if (!str.CmpNoCase( wxT("ps") ) ) |
| 451 | + { |
| 452 | + plot_format = PLOT_FORMAT_POST; |
| 453 | + ext = wxT( "ps" ); |
| 454 | + ps_use_a4 = false; |
| 455 | + } |
| 456 | + else if ( !str.CmpNoCase( wxT("ps_a4") ) ) |
| 457 | + { |
| 458 | + plot_format = PLOT_FORMAT_POST; |
| 459 | + ext = wxT( "ps" ); |
| 460 | + ps_use_a4 = true; |
| 461 | + } |
| 462 | + else if ( !str.CmpNoCase( wxT("hpgl") ) ) |
| 463 | + { |
| 464 | + plot_format = PLOT_FORMAT_HPGL; |
| 465 | + ext = wxT( "plt" ); |
| 466 | + } |
| 467 | + else if ( !str.CmpNoCase( wxT("gerber") ) ) |
| 468 | + { |
| 469 | + plot_format = PLOT_FORMAT_GERBER; |
| 470 | + ext = wxT( "pho" ); |
| 471 | + } |
| 472 | + else if ( !str.CmpNoCase( wxT("dxf") ) ) |
| 473 | + { |
| 474 | + plot_format = PLOT_FORMAT_DXF; |
| 475 | + ext = wxT( "dxf" ); |
| 476 | + } |
| 477 | + else |
| 478 | + { |
| 479 | + parser.Usage(); |
| 480 | + wxPrintf(wxT("Unexpected plot type '%ls'.\n"), str.c_str()); |
| 481 | + exit(0); |
| 482 | + } |
| 483 | + |
| 484 | + // --ps-pads-drill-opt |
| 485 | + if ( plot_format == PLOT_FORMAT_POST && parser.Found( wxT("ps-pads-drill-opt"), &str ) ) |
| 486 | + { |
| 487 | + if (!str.CmpNoCase( wxT("none") ) ) |
| 488 | + g_pcb_plot_options.DrillShapeOpt = PCB_Plot_Options::NO_DRILL_SHAPE; |
| 489 | + else if ( !str.CmpNoCase( wxT("small") ) ) |
| 490 | + g_pcb_plot_options.DrillShapeOpt = PCB_Plot_Options::SMALL_DRILL_SHAPE; |
| 491 | + else if ( !str.CmpNoCase( wxT("real") ) ) |
| 492 | + g_pcb_plot_options.DrillShapeOpt = PCB_Plot_Options::FULL_DRILL_SHAPE; |
| 493 | + else |
| 494 | + { |
| 495 | + parser.Usage(); |
| 496 | + wxPrintf(wxT("Unexpected Postscript pads drill option '%ls'.\n"), str.c_str()); |
| 497 | + exit(0); |
| 498 | + } |
| 499 | + } |
| 500 | + |
| 501 | + // --mirror |
| 502 | + if ( parser.Found( wxT("mirror") ) ) |
| 503 | + g_pcb_plot_options.PlotOrient = PLOT_MIROIR; |
| 504 | + |
| 505 | + if ( parser.Found( wxT("fill-all-zones") ) ) |
| 506 | + frame->Fill_All_Zones( false /* verbose */ ); |
| 507 | + |
| 508 | + parser.Found( wxT("layers"), &layers_str ); |
| 509 | + wxStringTokenizer tokenizer( layers_str, _(",") ); |
| 510 | + int layer_i = 0; |
| 511 | + wxString layername; |
| 512 | + while ( ( layers_str.IsEmpty() && layer_i < NB_LAYERS ) || tokenizer.HasMoreTokens() ) |
| 513 | + { |
| 514 | + if ( layers_str.IsEmpty() ) |
| 515 | + { |
| 516 | + if( !frame->GetBoard()->IsLayerEnabled( layer_i ) ) |
| 517 | + { |
| 518 | + layer_i++; |
| 519 | + continue; |
| 520 | + } |
| 521 | + layername = frame->GetBoard()->GetLayerName( layer_i ); |
| 522 | + layername.Trim( true ); layername.Trim( false ); // remove leading and trailing spaces if any |
| 523 | + layer_i++; |
| 524 | + } |
| 525 | + else |
| 526 | + { |
| 527 | + layername = tokenizer.GetNextToken(); |
| 528 | + for( layer_i = 0; layer_i < NB_LAYERS; layer_i++ ) |
| 529 | + { |
| 530 | + str = frame->GetBoard()->GetLayerName( layer_i ); |
| 531 | + str.Trim( true ); str.Trim( false ); // remove leading and trailing spaces if any |
| 532 | + if ( !str.Cmp( layername ) ) |
| 533 | + break; |
| 534 | + } |
| 535 | + if (layer_i >= NB_LAYERS) |
| 536 | + { |
| 537 | + wxFprintf( stderr, _( "Unknown layer name '%ls'\n" ), layername.c_str() ); |
| 538 | + continue; |
| 539 | + } |
| 540 | + } |
| 541 | + fn = ScreenPcb->m_FileName; |
| 542 | + fn.SetName( fn.GetName() + wxT( "-" ) + layername ); |
| 543 | + |
| 544 | + // Use Gerber Extensions based on layer number |
| 545 | + // (See http://en.wikipedia.org/wiki/Gerber_File) |
| 546 | + if( (plot_format == PLOT_FORMAT_GERBER) && true /* always use gerber extensions */ ) |
| 547 | + { |
| 548 | + switch( layer_i ) |
| 549 | + { |
| 550 | + case LAYER_N_FRONT: |
| 551 | + fn.SetExt( wxT( "gtl" ) ); |
| 552 | + break; |
| 553 | + |
| 554 | + case LAYER_N_2: |
| 555 | + case LAYER_N_3: |
| 556 | + case LAYER_N_4: |
| 557 | + case LAYER_N_5: |
| 558 | + case LAYER_N_6: |
| 559 | + case LAYER_N_7: |
| 560 | + case LAYER_N_8: |
| 561 | + case LAYER_N_9: |
| 562 | + case LAYER_N_10: |
| 563 | + case LAYER_N_11: |
| 564 | + case LAYER_N_12: |
| 565 | + case LAYER_N_13: |
| 566 | + case LAYER_N_14: |
| 567 | + case LAYER_N_15: |
| 568 | + |
| 569 | + // TODO: see if we use .gbr or a layer identifier (gb1 .. gbnn ?) |
| 570 | + // according to the new internal layers designation |
| 571 | + // (1 is the first internal layer from the front layer) |
| 572 | + fn.SetExt( wxT( "gbr" ) ); |
| 573 | + break; |
| 574 | + |
| 575 | + case LAYER_N_BACK: |
| 576 | + fn.SetExt( wxT( "gbl" ) ); |
| 577 | + break; |
| 578 | + |
| 579 | + case ADHESIVE_N_BACK: |
| 580 | + fn.SetExt( wxT( "gba" ) ); |
| 581 | + break; |
| 582 | + |
| 583 | + case ADHESIVE_N_FRONT: |
| 584 | + fn.SetExt( wxT( "gta" ) ); |
| 585 | + break; |
| 586 | + |
| 587 | + case SOLDERPASTE_N_BACK: |
| 588 | + fn.SetExt( wxT( "gbp" ) ); |
| 589 | + break; |
| 590 | + |
| 591 | + case SOLDERPASTE_N_FRONT: |
| 592 | + fn.SetExt( wxT( "gtp" ) ); |
| 593 | + break; |
| 594 | + |
| 595 | + case SILKSCREEN_N_BACK: |
| 596 | + fn.SetExt( wxT( "gbo" ) ); |
| 597 | + break; |
| 598 | + |
| 599 | + case SILKSCREEN_N_FRONT: |
| 600 | + fn.SetExt( wxT( "gto" ) ); |
| 601 | + break; |
| 602 | + |
| 603 | + case SOLDERMASK_N_BACK: |
| 604 | + fn.SetExt( wxT( "gbs" ) ); |
| 605 | + break; |
| 606 | + |
| 607 | + case SOLDERMASK_N_FRONT: |
| 608 | + fn.SetExt( wxT( "gts" ) ); |
| 609 | + break; |
| 610 | + |
| 611 | + case DRAW_N: |
| 612 | + case COMMENT_N: |
| 613 | + case ECO1_N: |
| 614 | + case ECO2_N: |
| 615 | + case EDGE_N: |
| 616 | + default: |
| 617 | + fn.SetExt( wxT( "gbr" ) ); |
| 618 | + break; |
| 619 | + } |
| 620 | + } |
| 621 | + else |
| 622 | + { |
| 623 | + fn.SetExt( ext ); |
| 624 | + } |
| 625 | + |
| 626 | + bool success = false; |
| 627 | + |
| 628 | + switch( plot_format ) |
| 629 | + { |
| 630 | + case PLOT_FORMAT_POST: |
| 631 | + success = frame->Genere_PS( fn.GetFullPath(), layer_i, ps_use_a4, |
| 632 | + FILLED /* trace_mode */ ); |
| 633 | + break; |
| 634 | + |
| 635 | + case PLOT_FORMAT_GERBER: |
| 636 | + success = frame->Genere_GERBER( fn.GetFullPath(), layer_i, |
| 637 | + false /* PlotOriginIsAuxAxis */, |
| 638 | + FILLED /* trace_mode */ ); |
| 639 | + break; |
| 640 | + |
| 641 | + case PLOT_FORMAT_HPGL: |
| 642 | + success = frame->Genere_HPGL( fn.GetFullPath(), layer_i, |
| 643 | + FILLED /* trace_mode */ ); |
| 644 | + break; |
| 645 | + |
| 646 | + case PLOT_FORMAT_DXF: |
| 647 | + success = frame->Genere_DXF( fn.GetFullPath(), layer_i, |
| 648 | + FILLED /* trace_mode */ ); |
| 649 | + break; |
| 650 | + } |
| 651 | + |
| 652 | + // Print diags in messages box: |
| 653 | + wxString msg; |
| 654 | + if( !success ) |
| 655 | + wxFprintf( stderr, _( "Unable to create <%s>\n" ), GetChars( fn.GetFullPath() ) ); |
| 656 | + } |
| 657 | + } |
| 658 | + if ( parser.Found( wxT("drc") ) ) // drc_stuff.h drc.cpp dialog_drc.{h,cpp} |
| 659 | + { |
| 660 | + fn = ScreenPcb->m_FileName; |
| 661 | + fn.SetExt( _("rpt") ); |
| 662 | + |
| 663 | + // if you get a segfault, try adding frame->m_drc->ShowDialog() to run through the GUI codepath |
| 664 | + frame->m_drc->updatePointers(); |
| 665 | + frame->m_drc->SetSettings(true, // Pad to pad DRC test enabled |
| 666 | + true, // unconnected pdas DRC test enabled |
| 667 | + true, // DRC test for zones enabled |
| 668 | + fn.GetFullPath(), // report file name |
| 669 | + true /* aSaveReport */ ); |
| 670 | + frame->m_drc->m_pcb->m_Status_Pcb = 0; // Force full connectivity and ratsnest recalculations |
| 671 | + frame->m_drc->RunTests(); |
| 672 | + FILE* fp = wxFopen( fn.GetFullPath(), wxT( "w" ) ); |
| 673 | + { // strings should match dialog_drc.cpp:DIALOG_DRC_CONTROL::writeReport() |
| 674 | + int count; |
| 675 | + |
| 676 | + fprintf( fp, "** Drc report for %s **\n", |
| 677 | + CONV_TO_UTF8( ScreenPcb->m_FileName ) ); |
| 678 | + |
| 679 | + wxDateTime now = wxDateTime::Now(); |
| 680 | + fprintf( fp, "** Created on %s **\n", CONV_TO_UTF8( now.Format( wxT( "%F %T" ) ) ) ); |
| 681 | + |
| 682 | + class DRC_LIST_MARKERS* markers = new DRC_LIST_MARKERS( frame->m_drc->m_pcb ); |
| 683 | + count = markers->GetCount(); |
| 684 | + fprintf( fp, "\n** Found %d DRC errors **\n", count ); |
| 685 | + for ( i = 0; i < count; i++ ) |
| 686 | + fprintf( fp, "%s", CONV_TO_UTF8( markers->GetItem( i )->ShowReport()) ); |
| 687 | + delete markers; |
| 688 | + |
| 689 | + class DRC_LIST_UNCONNECTED* unconnected = new DRC_LIST_UNCONNECTED( &frame->m_drc->m_unconnected ); |
| 690 | + count = unconnected->GetCount(); |
| 691 | + fprintf( fp, "\n** Found %d unconnected pads **\n", count ); |
| 692 | + for ( i = 0; i < count; i++ ) |
| 693 | + fprintf( fp, "%s", CONV_TO_UTF8( unconnected->GetItem( i )->ShowReport()) ); |
| 694 | + delete unconnected; |
| 695 | + |
| 696 | + fprintf( fp, "\n** End of Report **\n" ); |
| 697 | + } |
| 698 | + fclose( fp ); |
| 699 | + } |
| 700 | + if ( parser.Found( wxT("svg") ) ) // see dialog_SVG_print.cpp:DIALOG_SVG_PRINT::DrawPage() |
| 701 | + { |
| 702 | + BASE_SCREEN* screen = frame->GetBaseScreen(); |
| 703 | + wxSize SheetSize; // Sheet size in internal units |
| 704 | + wxString layers_str; |
| 705 | + PRINT_PARAMETERS print_params; |
| 706 | + long PrintMaskLayer; |
| 707 | + int layer_i; |
| 708 | + wxSVGFileDC* dc; |
| 709 | + |
| 710 | + screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0; |
| 711 | + screen->m_StartVisu.x = screen->m_StartVisu.y = 0; |
| 712 | + SheetSize = screen->m_CurrentSheetDesc->m_Size; // size in 1/1000 inch |
| 713 | + SheetSize.x *= frame->m_InternalUnits / 1000; |
| 714 | + SheetSize.y *= frame->m_InternalUnits / 1000; // size in pixels |
| 715 | + screen->SetScalingFactor( 1.0 ); |
| 716 | + screen->m_IsPrinting = true; |
| 717 | + float dpi = (float)frame->m_InternalUnits; |
| 718 | + |
| 719 | + frame->DrawPanel->m_ClipBox.SetX( 0 ); |
| 720 | + frame->DrawPanel->m_ClipBox.SetY( 0 ); |
| 721 | + frame->DrawPanel->m_ClipBox.SetWidth( 0x7FFFFF0 ); |
| 722 | + frame->DrawPanel->m_ClipBox.SetHeight( 0x7FFFFF0 ); |
| 723 | + |
| 724 | + print_params.m_DrillShapeOpt = PRINT_PARAMETERS::FULL_DRILL_SHAPE; |
| 725 | + print_params.m_Print_Sheet_Ref = false; // reference in bottom-right corner |
| 726 | + |
| 727 | + SetLocaleTo_C_standard(); // Switch the locale to standard C (needed |
| 728 | + // to print floating point numbers like 1.3) |
| 729 | + int bg_color = g_DrawBgColor; |
| 730 | + g_DrawBgColor = WHITE; |
| 731 | + |
| 732 | + PrintMaskLayer = 0; |
| 733 | + if ( parser.Found( wxT("layers"), &layers_str ) ) |
| 734 | + { |
| 735 | + wxStringTokenizer tokenizer( layers_str, _(",") ); |
| 736 | + layer_i = 0; |
| 737 | + wxString layername; |
| 738 | + while ( tokenizer.HasMoreTokens() ) |
| 739 | + { |
| 740 | + layername = tokenizer.GetNextToken(); |
| 741 | + for( layer_i = 0; layer_i < NB_LAYERS; layer_i++ ) |
| 742 | + { |
| 743 | + str = frame->GetBoard()->GetLayerName( layer_i ); |
| 744 | + str.Trim( true ); str.Trim( false ); // remove leading and trailing spaces if any |
| 745 | + if ( !str.Cmp( layername ) ) |
| 746 | + break; |
| 747 | + } |
| 748 | + if (layer_i >= NB_LAYERS) |
| 749 | + { |
| 750 | + wxFprintf( stderr, _( "Unknown layer name '%ls'\n" ), layername.c_str() ); |
| 751 | + continue; |
| 752 | + } |
| 753 | + PrintMaskLayer |= 1 << layer_i; |
| 754 | + } |
| 755 | + } |
| 756 | + else |
| 757 | + { |
| 758 | + for ( layer_i = 0; layer_i < NB_LAYERS; layer_i++ ) |
| 759 | + { |
| 760 | + if ( frame->GetBoard()->IsLayerEnabled( layer_i ) ) |
| 761 | + PrintMaskLayer |= 1 << layer_i; |
| 762 | + } |
| 763 | + } |
| 764 | + |
| 765 | + bool SvgMergeLayers = parser.Found( wxT("svg-merge-layers") ); |
| 766 | + bool SvgEdgeLayer = parser.Found( wxT("svg-board-edges") ); |
| 767 | + |
| 768 | + for ( layer_i = 0; layer_i < NB_LAYERS; layer_i++ ) |
| 769 | + { |
| 770 | + long LayerMask; |
| 771 | + |
| 772 | + fn = ScreenPcb->m_FileName; |
| 773 | + fn.SetExt( _("svg") ); |
| 774 | + if ( SvgMergeLayers ) |
| 775 | + { |
| 776 | + fn.SetName( fn.GetName() + wxT( "-brd" ) ); |
| 777 | + LayerMask = PrintMaskLayer; |
| 778 | + } |
| 779 | + else |
| 780 | + { |
| 781 | + if ( !(PrintMaskLayer & (1 << layer_i) )) |
| 782 | + continue; |
| 783 | + str = frame->GetBoard()->GetLayerName( layer_i ); |
| 784 | + str.Trim( true ); str.Trim( false ); // remove leading and trailing spaces if any |
| 785 | + fn.SetName( fn.GetName() + wxT( "-" ) + str ); |
| 786 | + LayerMask = 1 << layer_i; |
| 787 | + } |
| 788 | + if ( SvgEdgeLayer ) |
| 789 | + LayerMask |= EDGE_LAYER; |
| 790 | + |
| 791 | + dc = new wxSVGFileDC( fn.GetFullPath(), SheetSize.x, SheetSize.y, dpi ); |
| 792 | + GRResetPenAndBrush( dc ); |
| 793 | + frame->PrintPage( dc, false /* aPrint_Frame_Ref */, LayerMask, false /* aPrintMirrorMode */, &print_params); |
| 794 | + delete dc; |
| 795 | + dc = 0; |
| 796 | + |
| 797 | + if ( SvgMergeLayers ) |
| 798 | + break; |
| 799 | + } |
| 800 | + g_DrawBgColor = bg_color; |
| 801 | + SetLocaleTo_Default(); // revert to the current locale |
| 802 | + screen->m_IsPrinting = false; |
| 803 | + } |
| 804 | + |
| 805 | + if ( parser.Found( wxT("pos") ) ) // see gen_modules_placefile.cpp:WinEDA_PcbFrame::GenModulesPosition() |
| 806 | + frame->GenModulesPosition( dummy ); |
| 807 | + |
| 808 | + if ( parser.Found( wxT("bom") ) ) // see build_BOM_from_board.cpp:WinEDA_PcbFrame::RecreateBOMFileFromBoard() |
| 809 | + frame->RecreateBOMFileFromBoard( dummy ); |
| 810 | + |
| 811 | + if ( parser.Found( wxT("cmp") ) ) // see xchgmod.cpp:WinEDA_PcbFrame::RecreateCmpFileFromBoard() |
| 812 | + frame->RecreateCmpFileFromBoard( dummy ); |
| 813 | + |
| 814 | + if ( parser.Found( wxT("vrml") ) ) // see export_vrml.cpp:WinEDA_PcbFrame::OnExportVRML() |
| 815 | + { |
| 816 | + wxString subDirFor3Dshapes( _( "shapes3D" ) ); |
| 817 | + |
| 818 | + fn = ScreenPcb->m_FileName; |
| 819 | + fn.SetExt( _("wrl") ); |
| 820 | + if( ! wxDirExists( subDirFor3Dshapes ) ) |
| 821 | + wxMkdir( subDirFor3Dshapes ); |
| 822 | + frame->ExportVRML_File( fn.GetFullPath(), 1.0 /* aScale */, true /* aExport3DFile */, subDirFor3Dshapes ); |
| 823 | + } |
| 824 | + delete frame; |
| 825 | + return true; |
| 826 | +} |
| 827 | diff -ruN kicad.orig/pcbnew/pcbnew_scripted.h kicad/pcbnew/pcbnew_scripted.h |
| 828 | --- kicad.orig/pcbnew/pcbnew_scripted.h 1970-01-01 00:00:00.000000000 +0000 |
| 829 | @@ -0,0 +1,7 @@ |
| 830 | +///////////////////////////////////////////////////////////////////////////// |
| 831 | +// Name: pcbnew_scripted.h |
| 832 | +// Copyright: Wolfgang Spraul |
| 833 | +// Licence: GPL v3 or higher |
| 834 | +///////////////////////////////////////////////////////////////////////////// |
| 835 | + |
| 836 | +bool Pcbnew_Scripted(); |
kicad-patches/scripted.patch |
130 | 130 | InitEDA_Appl( wxT( "EESchema" ), APP_TYPE_EESCHEMA ); |
131 | 131 | |
132 | 132 | if( m_Checker && m_Checker->IsAnotherRunning() ) |
133 | | diff -ruN kicad.orig/eeschema/eeschema_scripted.cpp kicad/eeschema/eeschema_scripted.cpp |
134 | | +++ kicad/eeschema/eeschema_scripted.cpp 2010-12-31 18:03:37.871822958 +0000 |
135 | | @@ -0,0 +1,251 @@ |
136 | | +///////////////////////////////////////////////////////////////////////////// |
137 | | +// Name: eeschema_scripted.cpp |
138 | | +// Copyright: Werner Almesberger, Wolfgang Spraul |
139 | | +// Licence: GPL v2 or higher |
140 | | +///////////////////////////////////////////////////////////////////////////// |
141 | | + |
142 | | +#include "fctsys.h" |
143 | | +#include "appl_wxstruct.h" |
144 | | +#include "common.h" |
145 | | +#include "program.h" |
146 | | +#include "general.h" |
147 | | +#include "netlist.h" |
148 | | +#include "protos.h" |
149 | | +#include "gr_basic.h" |
150 | | +#include "plotps.h" |
151 | | +#include "wx/cmdline.h" |
152 | | +#include "dialog_build_BOM.h" |
153 | | +#include "dialog_SVG_print_base.h" |
154 | | +#include "dialog_erc.h" |
155 | | +#include "plotdxf.h" |
156 | | +#include "class_drawsheetpath.h" |
157 | | +#include "eeschema_scripted.h" |
158 | | + |
159 | | +EESCHEMA_SCRIPTED g_EESchemaScripted; |
160 | | + |
161 | | +static const wxCmdLineEntryDesc g_cmdLineDesc [] = |
162 | | +{ |
163 | | + { wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("displays help on the command line parameters"), |
164 | | + wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, |
165 | | + |
166 | | + { wxCMD_LINE_SWITCH, wxT("l"), wxT("list-sheets"), wxT("list schematics pages") }, |
167 | | + |
168 | | + { wxCMD_LINE_OPTION, wxT("px"), wxT("plotx"), wxT("plots the board [ps|svg|dxf]"), |
169 | | + wxCMD_LINE_VAL_STRING }, |
170 | | + { wxCMD_LINE_SWITCH, wxT("plotx-bw"), wxT("plotx-bw"), wxT("plot: black & white (default: color)") }, |
171 | | + { wxCMD_LINE_SWITCH, wxT("plotx-sheetref"), wxT("plotx-sheetref"), wxT("plot: print sheet reference (default: off)") }, |
172 | | + { wxCMD_LINE_SWITCH, wxT("p"), wxT("plot"), wxT("plots the schematics (deprecated, use --plotx=ps --plotx-bw)") }, |
173 | | + |
174 | | + { wxCMD_LINE_SWITCH, wxT("b"), wxT("bom"), wxT("generate bill of materials (.bom)") }, |
175 | | + { wxCMD_LINE_SWITCH, wxT("e"), wxT("erc"), wxT("generate electric rules check (.erc) file") }, |
176 | | + { wxCMD_LINE_SWITCH, wxT("n"), wxT("netlist"), wxT("generate netlist (.net)") }, |
177 | | + { wxCMD_LINE_PARAM, 0, 0, wxT("<path to .sch file>"), |
178 | | + wxCMD_LINE_VAL_STRING }, |
179 | | + { wxCMD_LINE_NONE } |
180 | | +}; |
181 | | + |
182 | | +bool ScriptedDrawSVGPage( WinEDA_DrawFrame * frame, |
183 | | + const wxString& FullFileName, BASE_SCREEN* screen, |
184 | | + bool aPrintBlackAndWhite = false, |
185 | | + bool aPrint_Sheet_Ref = false); |
186 | | + |
187 | | +bool EESCHEMA_SCRIPTED::Run() |
188 | | +{ |
189 | | + wxFileName fn; |
190 | | + WinEDA_SchematicFrame* frame; |
191 | | + wxCommandEvent DummyCmd; |
192 | | + wxString str; |
193 | | + int i; |
194 | | + |
195 | | + WinEDA_App& app = wxGetApp(); |
196 | | + if (app.argc < 2 || app.argv[1][0] != '-') |
197 | | + return false; |
198 | | + g_IsScripted = true; |
199 | | + wxLog::EnableLogging(false); // this should suppress some wx dialogs |
200 | | + app.InitEDA_Appl( wxT( "EESchema" ), APP_TYPE_EESCHEMA ); |
201 | | + |
202 | | + wxCmdLineParser parser; |
203 | | + parser.SetDesc(g_cmdLineDesc); |
204 | | + parser.SetCmdLine(app.argc, app.argv); |
205 | | + if (parser.Parse()) |
206 | | + return true; |
207 | | + |
208 | | + i = parser.Found( _("list-sheets") ) |
209 | | + + parser.Found( _("plot") ) |
210 | | + + parser.Found( _("plotx") ) |
211 | | + + parser.Found( _("bom") ) |
212 | | + + parser.Found( _("erc") ) |
213 | | + + parser.Found( _("netlist") ); |
214 | | + if ( !i ) |
215 | | + { |
216 | | + wxPrintf(wxT("One of --list-sheets --plot --plotx --bom --erc --netlist must be given.\n")); |
217 | | + return true; |
218 | | + } |
219 | | + if ( i > 1 ) |
220 | | + { |
221 | | + wxPrintf(wxT("Only one of --list-sheets --plot --plotx --bom --erc --netlist may be given at a time.\n")); |
222 | | + return true; |
223 | | + } |
224 | | + |
225 | | + // parse plotting parameters |
226 | | + enum PlotCommand { |
227 | | + PLOT_NONE, |
228 | | + PLOT_PS, |
229 | | + PLOT_SVG, |
230 | | + PLOT_DXF |
231 | | + } PlotCmd; |
232 | | + bool PlotBW; |
233 | | + bool PlotSheetRef; |
234 | | + |
235 | | + PlotCmd = PLOT_NONE; |
236 | | + if ( parser.Found( wxT("plot") ) ) // legacy parameter originally introduced by |
237 | | + // Werner, still used in schhist and other places |
238 | | + { |
239 | | + PlotCmd = PLOT_PS; |
240 | | + PlotBW = true; |
241 | | + PlotSheetRef = false; |
242 | | + } |
243 | | + else if ( parser.Found( _("plotx"), &str ) ) |
244 | | + { |
245 | | + if (!str.CmpNoCase( wxT("ps") ) ) |
246 | | + PlotCmd = PLOT_PS; |
247 | | + else if ( !str.CmpNoCase( wxT("svg") ) ) |
248 | | + PlotCmd = PLOT_SVG; |
249 | | + else if ( !str.CmpNoCase( wxT("dxf") ) ) |
250 | | + PlotCmd = PLOT_DXF; |
251 | | + else |
252 | | + { |
253 | | + parser.Usage(); |
254 | | + wxPrintf(wxT("Unexpected plot format '%ls'.\n"), str.c_str()); |
255 | | + return true; |
256 | | + } |
257 | | + PlotBW = parser.Found( _("plotx-bw") ); |
258 | | + PlotSheetRef = parser.Found( _("plotx-sheetref") ); |
259 | | + } |
260 | | + |
261 | | + fn = parser.GetParam(); |
262 | | + if( fn.GetExt() != SchematicFileExtension ) |
263 | | + { |
264 | | + wxLogDebug( wxT( "eeschema file <%s> has the wrong extension. Changing extension to .sch." ), GetChars( fn.GetFullPath() ) ); |
265 | | + fn.SetExt( PcbFileExtension ); |
266 | | + } |
267 | | + if( !fn.FileExists()) |
268 | | + { |
269 | | + wxPrintf( wxT("%ls: file '%ls' does not exist.\n" ), app.argv[0], fn.GetFullPath().c_str() ); |
270 | | + return true; |
271 | | + } |
272 | | + wxSetWorkingDirectory( fn.GetPath() ); |
273 | | + |
274 | | + g_DrawBgColor = BLACK; |
275 | | + SeedLayers(); |
276 | | + frame = new WinEDA_SchematicFrame( NULL, wxT( "EESchema" ), |
277 | | + wxPoint( 0, 0 ), wxSize( 600, 400 ) ); |
278 | | + ActiveScreen = frame->GetScreen(); |
279 | | +#if 0 // enable this to see more of the GUI |
280 | | + app.SetTopWindow( frame ); |
281 | | + frame->Show( true ); |
282 | | +#endif |
283 | | + if( !frame->LoadOneEEProject( fn.GetFullPath(), false ) ) |
284 | | + { |
285 | | + fprintf( stderr, "%ls: can't load\n", fn.GetFullPath().c_str() ); |
286 | | + return true; |
287 | | + } |
288 | | + |
289 | | + if ( parser.Found( wxT("list-sheets") ) ) // class_drawsheetpath.h |
290 | | + // dialog_SVG_print.cpp:DIALOG_SVG_PRINT:PrintSVGDoc() |
291 | | + { |
292 | | + SCH_SHEET_LIST SheetList( 0 /* aSheet */ ); |
293 | | + SCH_SHEET_PATH* sheetpath, *oldsheetpath; |
294 | | + SCH_SHEET_PATH list; |
295 | | + SCH_SCREEN* schscreen; |
296 | | + |
297 | | + oldsheetpath = frame->GetSheet(); |
298 | | + sheetpath = SheetList.GetFirst(); |
299 | | + while ( sheetpath ) |
300 | | + { |
301 | | + list.Clear(); |
302 | | + if ( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) |
303 | | + { |
304 | | + frame->m_CurrentSheet = &list; |
305 | | + frame->m_CurrentSheet->UpdateAllScreenReferences(); |
306 | | + frame->SetSheetNumberAndCount(); |
307 | | + schscreen = frame->m_CurrentSheet->LastScreen(); |
308 | | + ActiveScreen = schscreen; |
309 | | + |
310 | | + wxPrintf( sheetpath->Path() + _(" ") |
311 | | + + sheetpath->PathHumanReadable() + _(" ") |
312 | | + + sheetpath->Last()->GetFileName() + _(" ") |
313 | | + + frame->GetUniqueFilenameForCurrentSheet( ) + wxT( ".sch\n") ); |
314 | | + } |
315 | | + sheetpath = SheetList.GetNext(); |
316 | | + } |
317 | | + frame->m_CurrentSheet = oldsheetpath; |
318 | | + frame->m_CurrentSheet->UpdateAllScreenReferences(); |
319 | | + frame->SetSheetNumberAndCount(); |
320 | | + } |
321 | | + else if ( PlotCmd == PLOT_PS ) // plotps.cpp |
322 | | + { |
323 | | + // values must be idential to plotps.cpp:PageFormatReq |
324 | | + enum PageFormatReq { |
325 | | + PAGE_SIZE_AUTO, |
326 | | + PAGE_SIZE_A4, |
327 | | + PAGE_SIZE_A |
328 | | + }; |
329 | | + |
330 | | + WinEDA_PlotPSFrame* PlotPSFrame = new WinEDA_PlotPSFrame( frame ); |
331 | | + PlotPSFrame->m_Plot_Sheet_Ref->SetValue( PlotSheetRef ); |
332 | | + |
333 | | + // Strangely it seems that the plots come out right when 'A4' is |
334 | | + // selected, even if it's actually not A4 format. But when PAGE_SIZE_AUTO |
335 | | + // is selected, pages are cut off. Until we understand this better we |
336 | | + // always use A4. |
337 | | + PlotPSFrame->m_SizeOption->SetSelection( PAGE_SIZE_A4 ); |
338 | | + |
339 | | + PlotPSFrame->m_PlotPSColorOption->SetSelection( !PlotBW ); |
340 | | + PlotPSFrame->OnPlotPsAllExecuteClick( DummyCmd ); |
341 | | + delete PlotPSFrame; |
342 | | + } |
343 | | + else if ( PlotCmd == PLOT_SVG ) // dialog_SVG_print.cpp:DIALOG_SVG_PRINT::DrawSVGPage() |
344 | | + { |
345 | | + void ScriptedPrintSVGDoc( WinEDA_DrawFrame* frame, bool aPrintAll, bool aPrint_Sheet_Ref, bool aPrintBlackAndWhite ); |
346 | | + ScriptedPrintSVGDoc( frame, true /* aPrintAll */, PlotSheetRef, PlotBW ); |
347 | | + } |
348 | | + else if ( PlotCmd == PLOT_DXF ) // plotdxf.cpp:WinEDA_PlotDXFFrame::CreateDXFFile() |
349 | | + { |
350 | | + WinEDA_PlotDXFFrame* PlotDXFFrame = new WinEDA_PlotDXFFrame( frame ); |
351 | | + PlotDXFFrame->m_Plot_Sheet_Ref->SetValue( PlotSheetRef ); |
352 | | + PlotDXFFrame->m_PlotDXFColorOption->SetSelection( !PlotBW ); |
353 | | + PlotDXFFrame->OnPlotDXFAllExecuteClick( DummyCmd ); |
354 | | + delete PlotDXFFrame; |
355 | | + } |
356 | | + else if ( parser.Found( wxT("bom") ) ) // see build_BOM.cpp:DIALOG_BUILD_BOM::GenereListeOfItems() |
357 | | + { |
358 | | + DIALOG_BUILD_BOM* dlg = new DIALOG_BUILD_BOM( frame ); |
359 | | + |
360 | | + dlg->m_ListCmpbyRefItems->SetValue( true ); |
361 | | + dlg->m_AddFootprintField->SetValue( true ); |
362 | | + dlg->m_AddAllFields->SetValue( true ); |
363 | | + |
364 | | + fn = ActiveScreen->m_FileName; |
365 | | + fn.SetExt( wxT( "lst" ) ); |
366 | | + dlg->GenereListeOfItems( fn.GetFullPath(), false /* aIncludeSubComponents */ ); |
367 | | + delete dlg; |
368 | | + } |
369 | | + else if ( parser.Found( wxT("erc") ) ) // erc.cpp:DIALOG_ERC::TestErc() |
370 | | + { |
371 | | + DIALOG_ERC* dlg = new DIALOG_ERC( frame ); |
372 | | + dlg->m_WriteResultOpt->SetValue( true ); |
373 | | + dlg->TestErc( 0 /* messageList */ ); |
374 | | + delete dlg; |
375 | | + } |
376 | | + else if ( parser.Found( wxT("netlist") ) ) // netlist_control.cpp:WinEDA_SchematicFrame::CreateNetlist() |
377 | | + { |
378 | | + frame->BuildNetListBase(); |
379 | | + fn = ActiveScreen->m_FileName; |
380 | | + fn.SetExt( wxT( "net" ) ); |
381 | | + frame->WriteNetListFile( NET_TYPE_PCBNEW /* aFormat */, fn.GetFullPath(), false /* aUse_netnames - only used for Spice */ ); |
382 | | + } |
383 | | + |
384 | | + delete frame; |
385 | | + return true; |
386 | | +} |
387 | | diff -ruN kicad.orig/eeschema/eeschema_scripted.h kicad/eeschema/eeschema_scripted.h |
388 | | +++ kicad/eeschema/eeschema_scripted.h 2010-12-29 15:09:05.802259004 +0000 |
389 | | @@ -0,0 +1,14 @@ |
390 | | +///////////////////////////////////////////////////////////////////////////// |
391 | | +// Name: eeschema_scripted.h |
392 | | +// Copyright: Wolfgang Spraul |
393 | | +// Licence: GPL v3 or higher |
394 | | +///////////////////////////////////////////////////////////////////////////// |
395 | | + |
396 | | +class EESCHEMA_SCRIPTED |
397 | | +{ |
398 | | +public: |
399 | | + EESCHEMA_SCRIPTED() { } |
400 | | + bool Run(); |
401 | | +}; |
402 | | + |
403 | | +extern EESCHEMA_SCRIPTED g_EESchemaScripted; |
404 | 133 | diff -ruN kicad.orig/eeschema/erc.cpp kicad/eeschema/erc.cpp |
405 | 134 | --- kicad.orig/eeschema/erc.cpp 2010-12-31 18:11:47.751823001 +0000 |
406 | 135 | +++ kicad/eeschema/erc.cpp 2010-12-29 15:43:01.970259008 +0000 |
... | ... | |
574 | 301 | InitEDA_Appl( wxT( "PCBnew" ), APP_TYPE_PCBNEW ); |
575 | 302 | |
576 | 303 | if( m_Checker && m_Checker->IsAnotherRunning() ) |
577 | | diff -ruN kicad.orig/pcbnew/pcbnew_scripted.cpp kicad/pcbnew/pcbnew_scripted.cpp |
578 | | +++ kicad/pcbnew/pcbnew_scripted.cpp 2010-12-28 13:58:44.257392001 +0000 |
579 | | @@ -0,0 +1,552 @@ |
580 | | +///////////////////////////////////////////////////////////////////////////// |
581 | | +// Name: pcbnew_scripted.cpp |
582 | | +// Copyright: Wolfgang Spraul |
583 | | +// Licence: GPL v3 or higher |
584 | | +///////////////////////////////////////////////////////////////////////////// |
585 | | + |
586 | | +#include "fctsys.h" |
587 | | +#include "appl_wxstruct.h" |
588 | | +#include "confirm.h" |
589 | | + |
590 | | +#include <wx/file.h> |
591 | | +#include <wx/snglinst.h> |
592 | | +#include <wx/cmdline.h> |
593 | | +#include <wx/tokenzr.h> |
594 | | +#include <wx/svg/dcsvg.h> |
595 | | + |
596 | | +#include "common.h" |
597 | | +#include "pcbnew.h" |
598 | | +#include "wxPcbStruct.h" |
599 | | +#include "plot_common.h" |
600 | | +#include "gestfich.h" |
601 | | +#include "pcbplot.h" |
602 | | +#include "autorout.h" |
603 | | +#include "cell.h" |
604 | | +#include "worksheet.h" |
605 | | +#include "zones.h" |
606 | | +#include "drag.h" |
607 | | +#include "eda_dde.h" |
608 | | +#include "colors_selection.h" |
609 | | +#include "class_drawpanel.h" |
610 | | + |
611 | | +#include "id.h" |
612 | | + |
613 | | +#include "build_version.h" |
614 | | + |
615 | | +#include "protos.h" |
616 | | +#include "pcbnew_scripted.h" |
617 | | +#include "gendrill.h" |
618 | | +#include "dialog_gendrill.h" |
619 | | +#include "dialog_drc.h" |
620 | | +#include "printout_controler.h" |
621 | | + |
622 | | +extern int g_DrawDefaultLineThickness; |
623 | | + |
624 | | +static const wxCmdLineEntryDesc g_cmdLineDesc [] = |
625 | | +{ |
626 | | + { wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("displays help on the command line parameters"), |
627 | | + wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, |
628 | | + { wxCMD_LINE_SWITCH, wxT("d"), wxT("drill"), wxT("generates a .drl drill file") }, |
629 | | + { wxCMD_LINE_SWITCH, wxT("list-layers"), wxT("list-layers"), wxT("lists the names of all enabled layers in the .brd file") }, |
630 | | + { wxCMD_LINE_OPTION, wxT("p"), wxT("plot"), wxT("plots the board [hpgl|gerber|ps|ps_a4|dxf]"), |
631 | | + wxCMD_LINE_VAL_STRING }, |
632 | | + { wxCMD_LINE_OPTION, wxT("l"), wxT("layers"), wxT("comma separated list of layer names (default: all enabled layers)"), |
633 | | + wxCMD_LINE_VAL_STRING }, |
634 | | + { wxCMD_LINE_OPTION, wxT("ps-pads-drill-opt"), wxT("ps-pads-drill-opt"), wxT("Postscript pads drill option [none|small|real] (default:small)"), |
635 | | + wxCMD_LINE_VAL_STRING }, |
636 | | + { wxCMD_LINE_SWITCH, wxT("mirror"), wxT("mirror"), wxT("mirror plot (HPGL and Postscript only)") }, |
637 | | + { wxCMD_LINE_SWITCH, wxT("fill-all-zones"), wxT("fill-all-zones"), wxT("fill zones before plotting") }, |
638 | | + { wxCMD_LINE_SWITCH, wxT("drc"), wxT("drc"), wxT("generates a design rule check report (.rpt)") }, |
639 | | + { wxCMD_LINE_SWITCH, wxT("svg"), wxT("svg"), wxT("plots the board in SVG format") }, |
640 | | + { wxCMD_LINE_SWITCH, wxT("svg-merge"), wxT("svg-merge-layers"), wxT("merge layers into one SVG file") }, |
641 | | + { wxCMD_LINE_SWITCH, wxT("svg-edge"), wxT("svg-board-edges"), wxT("add board edges to SVG plots") }, |
642 | | + { wxCMD_LINE_SWITCH, wxT("pos"), wxT("pos"), wxT("create front and back .pos component position files") }, |
643 | | + { wxCMD_LINE_SWITCH, wxT("bom"), wxT("bom"), wxT("create a .csv bom") }, |
644 | | + { wxCMD_LINE_SWITCH, wxT("cmp"), wxT("cmp"), wxT("recreate .cmp components file for CvPcb") }, |
645 | | + { wxCMD_LINE_SWITCH, wxT("vrml"), wxT("vrml"), wxT("generates a .wrl vrml board representation") }, |
646 | | + { wxCMD_LINE_PARAM, 0, 0, wxT("<path to .brd file>"), |
647 | | + wxCMD_LINE_VAL_STRING }, |
648 | | + { wxCMD_LINE_NONE } |
649 | | +}; |
650 | | + |
651 | | +bool Pcbnew_Scripted() |
652 | | +{ |
653 | | + wxFileName fn; |
654 | | + wxString str; |
655 | | + WinEDA_PcbFrame* frame = NULL; |
656 | | + wxCommandEvent dummy; |
657 | | + int i; |
658 | | + |
659 | | + WinEDA_App& app = wxGetApp(); |
660 | | + if (app.argc < 2 || app.argv[1][0] != '-') |
661 | | + return false; |
662 | | + g_IsScripted = true; |
663 | | + wxLog::EnableLogging(false); // this should suppress some wx dialogs |
664 | | + app.InitEDA_Appl( wxT( "PCBnew" ), APP_TYPE_PCBNEW ); |
665 | | + |
666 | | + wxCmdLineParser parser; |
667 | | + parser.SetDesc(g_cmdLineDesc); |
668 | | + parser.SetCmdLine(app.argc, app.argv); |
669 | | + if (parser.Parse()) |
670 | | + return true; |
671 | | + if ( parser.Found( wxT("ps-pads-drill-opt"), &str ) |
672 | | + && str.CmpNoCase( wxT("none") ) |
673 | | + && str.CmpNoCase( wxT("small") ) |
674 | | + && str.CmpNoCase( wxT("real") )) |
675 | | + { |
676 | | + parser.Usage(); |
677 | | + wxPrintf(wxT("Unexpected pads drill option '%ls'.\n"), str.c_str()); |
678 | | + return true; |
679 | | + } |
680 | | + i = parser.Found( _("drill") ) |
681 | | + + parser.Found( _("list-layers") ) |
682 | | + + parser.Found( _("plot") ) |
683 | | + + parser.Found( _("drc") ) |
684 | | + + parser.Found( _("svg") ) |
685 | | + + parser.Found( _("pos") ) |
686 | | + + parser.Found( _("bom") ) |
687 | | + + parser.Found( _("cmp") ) |
688 | | + + parser.Found( _("vrml") ); |
689 | | + if ( !i ) |
690 | | + { |
691 | | + wxPrintf(wxT("One of --drill --list-layers --plot --drc --svg --pos --bom --cmp --vrml must be given.\n")); |
692 | | + return true; |
693 | | + } |
694 | | + if ( i > 1 ) |
695 | | + { |
696 | | + wxPrintf(wxT("Only one of --drill --list-layers --plot --drc --svg --pos --bom --cmp --vrml may be given at a time.\n")); |
697 | | + return true; |
698 | | + } |
699 | | + |
700 | | + fn = parser.GetParam(); |
701 | | + if( fn.GetExt() != PcbFileExtension ) |
702 | | + { |
703 | | + wxLogDebug( wxT( "PcbNew file <%s> has the wrong extension. Changing extension to .brd." ), GetChars( fn.GetFullPath() ) ); |
704 | | + fn.SetExt( PcbFileExtension ); |
705 | | + } |
706 | | + if( !fn.FileExists()) |
707 | | + { |
708 | | + wxPrintf( wxT("%ls: file '%ls' does not exist.\n" ), app.argv[0], fn.GetFullPath().c_str() ); |
709 | | + exit(0); |
710 | | + } |
711 | | + wxSetWorkingDirectory( fn.GetPath() ); |
712 | | + |
713 | | + app.InitEDA_Appl( wxT( "PCBnew" ), APP_TYPE_PCBNEW ); |
714 | | + ScreenPcb = new PCB_SCREEN(); |
715 | | + ActiveScreen = ScreenPcb; |
716 | | + app.GetSettings( false /* reopenLastUsedDirectory */ ); |
717 | | + |
718 | | + g_DrawBgColor = BLACK; |
719 | | + frame = new WinEDA_PcbFrame( NULL, wxT( "PcbNew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) ); |
720 | | + |
721 | | +#if 0 // enable this to see more of the GUI |
722 | | + app.SetTopWindow( frame ); |
723 | | + frame->Show( true ); |
724 | | + frame->Zoom_Automatique( true ); |
725 | | +#endif |
726 | | + |
727 | | + frame->LoadOnePcbFile( fn.GetFullPath() ); |
728 | | + frame->LoadProjectSettings( fn.GetFullPath() ); |
729 | | + |
730 | | + if ( parser.Found( wxT("drill") ) ) |
731 | | + { |
732 | | + DIALOG_GENDRILL* drill_frame = new DIALOG_GENDRILL( frame ); |
733 | | + drill_frame->GenDrillFiles( dummy ); |
734 | | + delete drill_frame; |
735 | | + } |
736 | | + if ( parser.Found( wxT("list-layers") ) ) |
737 | | + { |
738 | | + for ( i = 0; i < NB_LAYERS; i++ ) |
739 | | + { |
740 | | + if( frame->GetBoard()->IsLayerEnabled( i ) ) |
741 | | + { |
742 | | + str = frame->GetBoard()->GetLayerName( i ); |
743 | | + str.Trim( true ); str.Trim( false ); // remove leading and trailing spaces if any |
744 | | + wxPrintf(str + _("\n")); |
745 | | + } |
746 | | + } |
747 | | + } |
748 | | + if ( parser.Found( wxT("plot"), &str ) ) // see pcbplot.cpp |
749 | | + { |
750 | | + bool ps_use_a4; |
751 | | + int plot_format; |
752 | | + wxString ext, layers_str; |
753 | | + |
754 | | + g_pcb_plot_options.PlotLine_Width = g_DrawDefaultLineThickness; |
755 | | + if (!str.CmpNoCase( wxT("ps") ) ) |
756 | | + { |
757 | | + plot_format = PLOT_FORMAT_POST; |
758 | | + ext = wxT( "ps" ); |
759 | | + ps_use_a4 = false; |
760 | | + } |
761 | | + else if ( !str.CmpNoCase( wxT("ps_a4") ) ) |
762 | | + { |
763 | | + plot_format = PLOT_FORMAT_POST; |
764 | | + ext = wxT( "ps" ); |
765 | | + ps_use_a4 = true; |
766 | | + } |
767 | | + else if ( !str.CmpNoCase( wxT("hpgl") ) ) |
768 | | + { |
769 | | + plot_format = PLOT_FORMAT_HPGL; |
770 | | + ext = wxT( "plt" ); |
771 | | + } |
772 | | + else if ( !str.CmpNoCase( wxT("gerber") ) ) |
773 | | + { |
774 | | + plot_format = PLOT_FORMAT_GERBER; |
775 | | + ext = wxT( "pho" ); |
776 | | + } |
777 | | + else if ( !str.CmpNoCase( wxT("dxf") ) ) |
778 | | + { |
779 | | + plot_format = PLOT_FORMAT_DXF; |
780 | | + ext = wxT( "dxf" ); |
781 | | + } |
782 | | + else |
783 | | + { |
784 | | + parser.Usage(); |
785 | | + wxPrintf(wxT("Unexpected plot type '%ls'.\n"), str.c_str()); |
786 | | + exit(0); |
787 | | + } |
788 | | + |
789 | | + // --ps-pads-drill-opt |
790 | | + if ( plot_format == PLOT_FORMAT_POST && parser.Found( wxT("ps-pads-drill-opt"), &str ) ) |
791 | | + { |
792 | | + if (!str.CmpNoCase( wxT("none") ) ) |
793 | | + g_pcb_plot_options.DrillShapeOpt = PCB_Plot_Options::NO_DRILL_SHAPE; |
794 | | + else if ( !str.CmpNoCase( wxT("small") ) ) |
795 | | + g_pcb_plot_options.DrillShapeOpt = PCB_Plot_Options::SMALL_DRILL_SHAPE; |
796 | | + else if ( !str.CmpNoCase( wxT("real") ) ) |
797 | | + g_pcb_plot_options.DrillShapeOpt = PCB_Plot_Options::FULL_DRILL_SHAPE; |
798 | | + else |
799 | | + { |
800 | | + parser.Usage(); |
801 | | + wxPrintf(wxT("Unexpected Postscript pads drill option '%ls'.\n"), str.c_str()); |
802 | | + exit(0); |
803 | | + } |
804 | | + } |
805 | | + |
806 | | + // --mirror |
807 | | + if ( parser.Found( wxT("mirror") ) ) |
808 | | + g_pcb_plot_options.PlotOrient = PLOT_MIROIR; |
809 | | + |
810 | | + if ( parser.Found( wxT("fill-all-zones") ) ) |
811 | | + frame->Fill_All_Zones( false /* verbose */ ); |
812 | | + |
813 | | + parser.Found( wxT("layers"), &layers_str ); |
814 | | + wxStringTokenizer tokenizer( layers_str, _(",") ); |
815 | | + int layer_i = 0; |
816 | | + wxString layername; |
817 | | + while ( ( layers_str.IsEmpty() && layer_i < NB_LAYERS ) || tokenizer.HasMoreTokens() ) |
818 | | + { |
819 | | + if ( layers_str.IsEmpty() ) |
820 | | + { |
821 | | + if( !frame->GetBoard()->IsLayerEnabled( layer_i ) ) |
822 | | + { |
823 | | + layer_i++; |
824 | | + continue; |
825 | | + } |
826 | | + layername = frame->GetBoard()->GetLayerName( layer_i ); |
827 | | + layername.Trim( true ); layername.Trim( false ); // remove leading and trailing spaces if any |
828 | | + layer_i++; |
829 | | + } |
830 | | + else |
831 | | + { |
832 | | + layername = tokenizer.GetNextToken(); |
833 | | + for( layer_i = 0; layer_i < NB_LAYERS; layer_i++ ) |
834 | | + { |
835 | | + str = frame->GetBoard()->GetLayerName( layer_i ); |
836 | | + str.Trim( true ); str.Trim( false ); // remove leading and trailing spaces if any |
837 | | + if ( !str.Cmp( layername ) ) |
838 | | + break; |
839 | | + } |
840 | | + if (layer_i >= NB_LAYERS) |
841 | | + { |
842 | | + wxFprintf( stderr, _( "Unknown layer name '%ls'\n" ), layername.c_str() ); |
843 | | + continue; |
844 | | + } |
845 | | + } |
846 | | + fn = ScreenPcb->m_FileName; |
847 | | + fn.SetName( fn.GetName() + wxT( "-" ) + layername ); |
848 | | + |
849 | | + // Use Gerber Extensions based on layer number |
850 | | + // (See http://en.wikipedia.org/wiki/Gerber_File) |
851 | | + if( (plot_format == PLOT_FORMAT_GERBER) && true /* always use gerber extensions */ ) |
852 | | + { |
853 | | + switch( layer_i ) |
854 | | + { |
855 | | + case LAYER_N_FRONT: |
856 | | + fn.SetExt( wxT( "gtl" ) ); |
857 | | + break; |
858 | | + |
859 | | + case LAYER_N_2: |
860 | | + case LAYER_N_3: |
861 | | + case LAYER_N_4: |
862 | | + case LAYER_N_5: |
863 | | + case LAYER_N_6: |
864 | | + case LAYER_N_7: |
865 | | + case LAYER_N_8: |
866 | | + case LAYER_N_9: |
867 | | + case LAYER_N_10: |
868 | | + case LAYER_N_11: |
869 | | + case LAYER_N_12: |
870 | | + case LAYER_N_13: |
871 | | + case LAYER_N_14: |
872 | | + case LAYER_N_15: |
873 | | + |
874 | | + // TODO: see if we use .gbr or a layer identifier (gb1 .. gbnn ?) |
875 | | + // according to the new internal layers designation |
876 | | + // (1 is the first internal layer from the front layer) |
877 | | + fn.SetExt( wxT( "gbr" ) ); |
878 | | + break; |
879 | | + |
880 | | + case LAYER_N_BACK: |
881 | | + fn.SetExt( wxT( "gbl" ) ); |
882 | | + break; |
883 | | + |
884 | | + case ADHESIVE_N_BACK: |
885 | | + fn.SetExt( wxT( "gba" ) ); |
886 | | + break; |
887 | | + |
888 | | + case ADHESIVE_N_FRONT: |
889 | | + fn.SetExt( wxT( "gta" ) ); |
890 | | + break; |
891 | | + |
892 | | + case SOLDERPASTE_N_BACK: |
893 | | + fn.SetExt( wxT( "gbp" ) ); |
894 | | + break; |
895 | | + |
896 | | + case SOLDERPASTE_N_FRONT: |
897 | | + fn.SetExt( wxT( "gtp" ) ); |
898 | | + break; |
899 | | + |
900 | | + case SILKSCREEN_N_BACK: |
901 | | + fn.SetExt( wxT( "gbo" ) ); |
902 | | + break; |
903 | | + |
904 | | + case SILKSCREEN_N_FRONT: |
905 | | + fn.SetExt( wxT( "gto" ) ); |
906 | | + break; |
907 | | + |
908 | | + case SOLDERMASK_N_BACK: |
909 | | + fn.SetExt( wxT( "gbs" ) ); |
910 | | + break; |
911 | | + |
912 | | + case SOLDERMASK_N_FRONT: |
913 | | + fn.SetExt( wxT( "gts" ) ); |
914 | | + break; |
915 | | + |
916 | | + case DRAW_N: |
917 | | + case COMMENT_N: |
918 | | + case ECO1_N: |
919 | | + case ECO2_N: |
920 | | + case EDGE_N: |
921 | | + default: |
922 | | + fn.SetExt( wxT( "gbr" ) ); |
923 | | + break; |
924 | | + } |
925 | | + } |
926 | | + else |
927 | | + { |
928 | | + fn.SetExt( ext ); |
929 | | + } |
930 | | + |
931 | | + bool success = false; |
932 | | + |
933 | | + switch( plot_format ) |
934 | | + { |
935 | | + case PLOT_FORMAT_POST: |
936 | | + success = frame->Genere_PS( fn.GetFullPath(), layer_i, ps_use_a4, |
937 | | + FILLED /* trace_mode */ ); |
938 | | + break; |
939 | | + |
940 | | + case PLOT_FORMAT_GERBER: |
941 | | + success = frame->Genere_GERBER( fn.GetFullPath(), layer_i, |
942 | | + false /* PlotOriginIsAuxAxis */, |
943 | | + FILLED /* trace_mode */ ); |
944 | | + break; |
945 | | + |
946 | | + case PLOT_FORMAT_HPGL: |
947 | | + success = frame->Genere_HPGL( fn.GetFullPath(), layer_i, |
948 | | + FILLED /* trace_mode */ ); |
949 | | + break; |
950 | | + |
951 | | + case PLOT_FORMAT_DXF: |
952 | | + success = frame->Genere_DXF( fn.GetFullPath(), layer_i, |
953 | | + FILLED /* trace_mode */ ); |
954 | | + break; |
955 | | + } |
956 | | + |
957 | | + // Print diags in messages box: |
958 | | + wxString msg; |
959 | | + if( !success ) |
960 | | + wxFprintf( stderr, _( "Unable to create <%s>\n" ), GetChars( fn.GetFullPath() ) ); |
961 | | + } |
962 | | + } |
963 | | + if ( parser.Found( wxT("drc") ) ) // drc_stuff.h drc.cpp dialog_drc.{h,cpp} |
964 | | + { |
965 | | + fn = ScreenPcb->m_FileName; |
966 | | + fn.SetExt( _("rpt") ); |
967 | | + |
968 | | + // if you get a segfault, try adding frame->m_drc->ShowDialog() to run through the GUI codepath |
969 | | + frame->m_drc->updatePointers(); |
970 | | + frame->m_drc->SetSettings(true, // Pad to pad DRC test enabled |
971 | | + true, // unconnected pdas DRC test enabled |
972 | | + true, // DRC test for zones enabled |
973 | | + fn.GetFullPath(), // report file name |
974 | | + true /* aSaveReport */ ); |
975 | | + frame->m_drc->m_pcb->m_Status_Pcb = 0; // Force full connectivity and ratsnest recalculations |
976 | | + frame->m_drc->RunTests(); |
977 | | + FILE* fp = wxFopen( fn.GetFullPath(), wxT( "w" ) ); |
978 | | + { // strings should match dialog_drc.cpp:DIALOG_DRC_CONTROL::writeReport() |
979 | | + int count; |
980 | | + |
981 | | + fprintf( fp, "** Drc report for %s **\n", |
982 | | + CONV_TO_UTF8( ScreenPcb->m_FileName ) ); |
983 | | + |
984 | | + wxDateTime now = wxDateTime::Now(); |
985 | | + fprintf( fp, "** Created on %s **\n", CONV_TO_UTF8( now.Format( wxT( "%F %T" ) ) ) ); |
986 | | + |
987 | | + class DRC_LIST_MARKERS* markers = new DRC_LIST_MARKERS( frame->m_drc->m_pcb ); |
988 | | + count = markers->GetCount(); |
989 | | + fprintf( fp, "\n** Found %d DRC errors **\n", count ); |
990 | | + for ( i = 0; i < count; i++ ) |
991 | | + fprintf( fp, "%s", CONV_TO_UTF8( markers->GetItem( i )->ShowReport()) ); |
992 | | + delete markers; |
993 | | + |
994 | | + class DRC_LIST_UNCONNECTED* unconnected = new DRC_LIST_UNCONNECTED( &frame->m_drc->m_unconnected ); |
995 | | + count = unconnected->GetCount(); |
996 | | + fprintf( fp, "\n** Found %d unconnected pads **\n", count ); |
997 | | + for ( i = 0; i < count; i++ ) |
998 | | + fprintf( fp, "%s", CONV_TO_UTF8( unconnected->GetItem( i )->ShowReport()) ); |
999 | | + delete unconnected; |
1000 | | + |
1001 | | + fprintf( fp, "\n** End of Report **\n" ); |
1002 | | + } |
1003 | | + fclose( fp ); |
1004 | | + } |
1005 | | + if ( parser.Found( wxT("svg") ) ) // see dialog_SVG_print.cpp:DIALOG_SVG_PRINT::DrawPage() |
1006 | | + { |
1007 | | + BASE_SCREEN* screen = frame->GetBaseScreen(); |
1008 | | + wxSize SheetSize; // Sheet size in internal units |
1009 | | + wxString layers_str; |
1010 | | + PRINT_PARAMETERS print_params; |
1011 | | + long PrintMaskLayer; |
1012 | | + int layer_i; |
1013 | | + wxSVGFileDC* dc; |
1014 | | + |
1015 | | + screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0; |
1016 | | + screen->m_StartVisu.x = screen->m_StartVisu.y = 0; |
1017 | | + SheetSize = screen->m_CurrentSheetDesc->m_Size; // size in 1/1000 inch |
1018 | | + SheetSize.x *= frame->m_InternalUnits / 1000; |
1019 | | + SheetSize.y *= frame->m_InternalUnits / 1000; // size in pixels |
1020 | | + screen->SetScalingFactor( 1.0 ); |
1021 | | + screen->m_IsPrinting = true; |
1022 | | + float dpi = (float)frame->m_InternalUnits; |
1023 | | + |
1024 | | + frame->DrawPanel->m_ClipBox.SetX( 0 ); |
1025 | | + frame->DrawPanel->m_ClipBox.SetY( 0 ); |
1026 | | + frame->DrawPanel->m_ClipBox.SetWidth( 0x7FFFFF0 ); |
1027 | | + frame->DrawPanel->m_ClipBox.SetHeight( 0x7FFFFF0 ); |
1028 | | + |
1029 | | + print_params.m_DrillShapeOpt = PRINT_PARAMETERS::FULL_DRILL_SHAPE; |
1030 | | + print_params.m_Print_Sheet_Ref = false; // reference in bottom-right corner |
1031 | | + |
1032 | | + SetLocaleTo_C_standard(); // Switch the locale to standard C (needed |
1033 | | + // to print floating point numbers like 1.3) |
1034 | | + int bg_color = g_DrawBgColor; |
1035 | | + g_DrawBgColor = WHITE; |
1036 | | + |
1037 | | + PrintMaskLayer = 0; |
1038 | | + if ( parser.Found( wxT("layers"), &layers_str ) ) |
1039 | | + { |
1040 | | + wxStringTokenizer tokenizer( layers_str, _(",") ); |
1041 | | + layer_i = 0; |
1042 | | + wxString layername; |
1043 | | + while ( tokenizer.HasMoreTokens() ) |
1044 | | + { |
1045 | | + layername = tokenizer.GetNextToken(); |
1046 | | + for( layer_i = 0; layer_i < NB_LAYERS; layer_i++ ) |
1047 | | + { |
1048 | | + str = frame->GetBoard()->GetLayerName( layer_i ); |
1049 | | + str.Trim( true ); str.Trim( false ); // remove leading and trailing spaces if any |
1050 | | + if ( !str.Cmp( layername ) ) |
1051 | | + break; |
1052 | | + } |
1053 | | + if (layer_i >= NB_LAYERS) |
1054 | | + { |
1055 | | + wxFprintf( stderr, _( "Unknown layer name '%ls'\n" ), layername.c_str() ); |
1056 | | + continue; |
1057 | | + } |
1058 | | + PrintMaskLayer |= 1 << layer_i; |
1059 | | + } |
1060 | | + } |
1061 | | + else |
1062 | | + { |
1063 | | + for ( layer_i = 0; layer_i < NB_LAYERS; layer_i++ ) |
1064 | | + { |
1065 | | + if ( frame->GetBoard()->IsLayerEnabled( layer_i ) ) |
1066 | | + PrintMaskLayer |= 1 << layer_i; |
1067 | | + } |
1068 | | + } |
1069 | | + |
1070 | | + bool SvgMergeLayers = parser.Found( wxT("svg-merge-layers") ); |
1071 | | + bool SvgEdgeLayer = parser.Found( wxT("svg-board-edges") ); |
1072 | | + |
1073 | | + for ( layer_i = 0; layer_i < NB_LAYERS; layer_i++ ) |
1074 | | + { |
1075 | | + long LayerMask; |
1076 | | + |
1077 | | + fn = ScreenPcb->m_FileName; |
1078 | | + fn.SetExt( _("svg") ); |
1079 | | + if ( SvgMergeLayers ) |
1080 | | + { |
1081 | | + fn.SetName( fn.GetName() + wxT( "-brd" ) ); |
1082 | | + LayerMask = PrintMaskLayer; |
1083 | | + } |
1084 | | + else |
1085 | | + { |
1086 | | + if ( !(PrintMaskLayer & (1 << layer_i) )) |
1087 | | + continue; |
1088 | | + str = frame->GetBoard()->GetLayerName( layer_i ); |
1089 | | + str.Trim( true ); str.Trim( false ); // remove leading and trailing spaces if any |
1090 | | + fn.SetName( fn.GetName() + wxT( "-" ) + str ); |
1091 | | + LayerMask = 1 << layer_i; |
1092 | | + } |
1093 | | + if ( SvgEdgeLayer ) |
1094 | | + LayerMask |= EDGE_LAYER; |
1095 | | + |
1096 | | + dc = new wxSVGFileDC( fn.GetFullPath(), SheetSize.x, SheetSize.y, dpi ); |
1097 | | + GRResetPenAndBrush( dc ); |
1098 | | + frame->PrintPage( dc, false /* aPrint_Frame_Ref */, LayerMask, false /* aPrintMirrorMode */, &print_params); |
1099 | | + delete dc; |
1100 | | + dc = 0; |
1101 | | + |
1102 | | + if ( SvgMergeLayers ) |
1103 | | + break; |
1104 | | + } |
1105 | | + g_DrawBgColor = bg_color; |
1106 | | + SetLocaleTo_Default(); // revert to the current locale |
1107 | | + screen->m_IsPrinting = false; |
1108 | | + } |
1109 | | + |
1110 | | + if ( parser.Found( wxT("pos") ) ) // see gen_modules_placefile.cpp:WinEDA_PcbFrame::GenModulesPosition() |
1111 | | + frame->GenModulesPosition( dummy ); |
1112 | | + |
1113 | | + if ( parser.Found( wxT("bom") ) ) // see build_BOM_from_board.cpp:WinEDA_PcbFrame::RecreateBOMFileFromBoard() |
1114 | | + frame->RecreateBOMFileFromBoard( dummy ); |
1115 | | + |
1116 | | + if ( parser.Found( wxT("cmp") ) ) // see xchgmod.cpp:WinEDA_PcbFrame::RecreateCmpFileFromBoard() |
1117 | | + frame->RecreateCmpFileFromBoard( dummy ); |
1118 | | + |
1119 | | + if ( parser.Found( wxT("vrml") ) ) // see export_vrml.cpp:WinEDA_PcbFrame::OnExportVRML() |
1120 | | + { |
1121 | | + wxString subDirFor3Dshapes( _( "shapes3D" ) ); |
1122 | | + |
1123 | | + fn = ScreenPcb->m_FileName; |
1124 | | + fn.SetExt( _("wrl") ); |
1125 | | + if( ! wxDirExists( subDirFor3Dshapes ) ) |
1126 | | + wxMkdir( subDirFor3Dshapes ); |
1127 | | + frame->ExportVRML_File( fn.GetFullPath(), 1.0 /* aScale */, true /* aExport3DFile */, subDirFor3Dshapes ); |
1128 | | + } |
1129 | | + delete frame; |
1130 | | + return true; |
1131 | | +} |
1132 | | diff -ruN kicad.orig/pcbnew/pcbnew_scripted.h kicad/pcbnew/pcbnew_scripted.h |
1133 | | +++ kicad/pcbnew/pcbnew_scripted.h 2010-12-22 18:47:58.774932729 +0000 |
1134 | | @@ -0,0 +1,7 @@ |
1135 | | +///////////////////////////////////////////////////////////////////////////// |
1136 | | +// Name: pcbnew_scripted.h |
1137 | | +// Copyright: Wolfgang Spraul |
1138 | | +// Licence: GPL v3 or higher |
1139 | | +///////////////////////////////////////////////////////////////////////////// |
1140 | | + |
1141 | | +bool Pcbnew_Scripted(); |
1142 | 304 | diff -ruN kicad.orig/pcbnew/xchgmod.cpp kicad/pcbnew/xchgmod.cpp |
1143 | 305 | --- kicad.orig/pcbnew/xchgmod.cpp 2010-10-19 08:48:07.000000000 +0000 |
1144 | 306 | +++ kicad/pcbnew/xchgmod.cpp 2010-12-28 13:59:06.985392003 +0000 |