From 48b2661baa36efdb07087ab60485dfbbbfb9c458 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 15 Jun 2011 14:44:24 -0400 Subject: [PATCH] EESchema dead code removal and other minor changes. * Move code from function ClearProjectDrawList() into SCH_SCREEN object Clear() method. * Delete eeschema/delsheet.cpp as none of the code in it is ever called. * Move global spice and net list command line variables into SCH_EDIT_FRAME object as priviate members and provide access methods. * Remove unnecessary header includes from eeschema/sheet.cpp. * Minor coding policy fixes. --- eeschema/CMakeLists.txt | 1 - eeschema/delsheet.cpp | 94 -------------------------- eeschema/dialogs/dialog_color_config.h | 3 + eeschema/eeschema.cpp | 19 ++---- eeschema/eeschema_config.cpp | 4 +- eeschema/general.h | 3 - eeschema/netform.cpp | 9 ++- eeschema/netlist_control.cpp | 23 ++++--- eeschema/netlist_control.h | 4 +- eeschema/protos.h | 40 ++++------- eeschema/sch_screen.cpp | 17 +++++ eeschema/schframe.cpp | 2 +- eeschema/sheet.cpp | 5 -- include/class_sch_screen.h | 6 ++ include/wxEeschemaStruct.h | 15 +++- 15 files changed, 82 insertions(+), 163 deletions(-) delete mode 100644 eeschema/delsheet.cpp diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index b30a650873..79daba2a6a 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -25,7 +25,6 @@ set(EESCHEMA_SRCS cross-probing.cpp dangling_ends.cpp database.cpp - delsheet.cpp dialogs/dialog_color_config.cpp dialogs/dialog_plot_schematic_DXF.cpp dialogs/dialog_plot_schematic_DXF_base.cpp diff --git a/eeschema/delsheet.cpp b/eeschema/delsheet.cpp deleted file mode 100644 index 8f835b50f6..0000000000 --- a/eeschema/delsheet.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/****************/ -/* delsheet.cpp */ -/****************/ - -#include "fctsys.h" -#include "appl_wxstruct.h" -#include "common.h" -#include "confirm.h" -#include "class_sch_screen.h" -#include "wxEeschemaStruct.h" - -#include "general.h" -#include "protos.h" -#include "sch_sheet.h" - - -/* Free (delete) all schematic data (include the sub hierarchy sheets ) - * for the hierarchical sheet FirstSheet - * FirstSheet is not deleted. - */ -void DeleteSubHierarchy( SCH_SHEET* FirstSheet, bool confirm_deletion ) -{ - EDA_ITEM* DrawStruct; - EDA_ITEM* EEDrawList; - wxString msg; - SCH_EDIT_FRAME* frame; - - frame = (SCH_EDIT_FRAME*)wxGetApp().GetTopWindow(); - - if( FirstSheet == NULL ) - return; - - if( FirstSheet->Type() != SCH_SHEET_T ) - { - DisplayError( NULL, wxT( "DeleteSubHierarchy error(): NOT a Sheet" ) ); - return; - } - - if( FirstSheet->GetScreen()->IsModify() && confirm_deletion ) - { - msg.Printf( _( "Sheet %s (file %s) modified. Save it?" ), - FirstSheet->m_SheetName.GetData(), - FirstSheet->GetFileName().GetData() ); - - if( IsOK( NULL, msg ) ) - { - frame->SaveEEFile( FirstSheet->GetScreen(), FILE_SAVE_AS ); - } - } - - /* free the sub hierarchy */ - if( FirstSheet->GetScreen() ) - { - EEDrawList = FirstSheet->GetScreen()->GetDrawItems(); - - while( EEDrawList != NULL ) - { - DrawStruct = EEDrawList; - EEDrawList = EEDrawList->Next(); - - if( DrawStruct->Type() == SCH_SHEET_T ) - { - DeleteSubHierarchy( (SCH_SHEET*) DrawStruct, confirm_deletion ); - } - } - - FirstSheet->GetScreen()->FreeDrawList(); - } -} - - -/* free the draw list screen->EEDrawList and the subhierarchies - * clear the screen datas (filenames ..) - */ -bool ClearProjectDrawList( SCH_SCREEN* screen, bool confirm_deletion ) -{ - if( screen == NULL ) - return TRUE; - - screen->FreeDrawList(); - - /* Clear the screen datas */ - screen->m_ScreenNumber = screen->m_NumberOfScreen = 1; - screen->m_Title.Empty(); - screen->m_Revision.Empty(); - screen->m_Company.Empty(); - screen->m_Commentaire1.Empty(); - screen->m_Commentaire2.Empty(); - screen->m_Commentaire3.Empty(); - screen->m_Commentaire4.Empty(); - screen->m_Date = GenDate(); - - return TRUE; -} diff --git a/eeschema/dialogs/dialog_color_config.h b/eeschema/dialogs/dialog_color_config.h index a7c00ea50d..2dd235abed 100644 --- a/eeschema/dialogs/dialog_color_config.h +++ b/eeschema/dialogs/dialog_color_config.h @@ -10,6 +10,9 @@ class wxStaticLine; class wxStdDialogButtonSizer; +extern void SeedLayers(); + + // Specify the width and height of every (color-displaying / bitmap) button const int BUTT_SIZE_X = 16; const int BUTT_SIZE_Y = 16; diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index ef5f356afb..feb274793b 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -17,7 +17,7 @@ #include "general.h" #include "protos.h" #include "hotkeys.h" - +#include "dialogs/dialog_color_config.h" #include "transform.h" #include @@ -48,12 +48,6 @@ const wxString CompLibFileExtension( wxT( "lib" ) ); const wxString SymbolFileWildcard( wxT( "Kicad drawing symbol file (*.sym)|*.sym" ) ); const wxString CompLibFileWildcard( wxT( "Kicad component library file (*.lib)|*.lib" ) ); -// command line to call the simulator (gnucap, spice..) -wxString g_SimulatorCommandLine; - -// command line to call the simulator net lister (gnucap, spice..) -wxString g_NetListerCommandLine; - LayerStruct g_LayerDescr; /* layer colors. */ bool g_EditPinByPinIsOn = false; /* true to do not synchronize pins @@ -138,7 +132,7 @@ bool WinEDA_App::OnInit() frame = new SCH_EDIT_FRAME( NULL, wxT( "EESchema" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) ); SetTopWindow( frame ); - frame->Show( TRUE ); + frame->Show( true ); if( CreateServer( frame, KICAD_SCH_PORT_SERVICE_NUMBER ) ) { @@ -147,7 +141,7 @@ bool WinEDA_App::OnInit() SetupServerFunction( RemoteCommand ); } - frame->Zoom_Automatique( TRUE ); + frame->Zoom_Automatique( true ); /* Load file specified in the command line. */ if( filename.IsOk() ) @@ -156,6 +150,7 @@ bool WinEDA_App::OnInit() if( filename.GetExt() != SchematicFileExtension ) filename.SetExt( SchematicFileExtension ); + wxSetWorkingDirectory( filename.GetPath() ); if( frame->LoadOneEEProject( filename.GetFullPath(), false ) ) @@ -164,9 +159,9 @@ bool WinEDA_App::OnInit() else { // Read a default config file if no file to load. - frame->LoadProjectFile( wxEmptyString, TRUE ); - frame->DrawPanel->Refresh( TRUE ); + frame->LoadProjectFile( wxEmptyString, true ); + frame->DrawPanel->Refresh( true ); } - return TRUE; + return true; } diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index d50fd484dc..ef1bf5d20c 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -589,7 +589,7 @@ void SCH_EDIT_FRAME::LoadSettings() // Load netlists options: cfg->Read( SpiceNetNamesEntry, &g_OptNetListUseNames, false ); - cfg->Read( SimulatorCommandEntry, &g_SimulatorCommandLine ); + cfg->Read( SimulatorCommandEntry, &m_simulatorCommand ); /* Load find dialog session setting. */ cfg->Read( FindDialogPositionXEntry, &tmp, -1 ); @@ -675,7 +675,7 @@ void SCH_EDIT_FRAME::SaveSettings() // Save netlists options: cfg->Write( SpiceNetNamesEntry, g_OptNetListUseNames ); - cfg->Write( SimulatorCommandEntry, g_SimulatorCommandLine ); + cfg->Write( SimulatorCommandEntry, m_simulatorCommand ); /* Save find dialog session setting. */ cfg->Write( FindDialogPositionXEntry, m_findDialogPosition.x ); diff --git a/eeschema/general.h b/eeschema/general.h index 29f8370c1f..44a23452d4 100644 --- a/eeschema/general.h +++ b/eeschema/general.h @@ -146,9 +146,6 @@ extern const wxString SymbolFileWildcard; extern const wxString CompLibFileExtension; extern const wxString CompLibFileWildcard; -extern wxString g_SimulatorCommandLine; -extern wxString g_NetListerCommandLine; - extern LayerStruct g_LayerDescr; extern bool g_EditPinByPinIsOn; /* True to prevent displacing diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index f8f7201e35..14169bad8a 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -422,17 +422,16 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam break; // If user provided no plugin command line, return now. - if( g_NetListerCommandLine.IsEmpty() ) + if( m_netListerCommand.IsEmpty() ) break; // build full command line from user's format string, e.g.: // "xsltproc -o %O /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl %I" // becomes, after the user selects /tmp/s1.net as the output file from the file dialog: // "xsltproc -o /tmp/s1.net /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl /tmp/s1.tmp" - wxString commandLine = EXPORT_HELP::MakeCommandLine( - g_NetListerCommandLine, - tmpFile.GetFullPath(), - aFullFileName ); + wxString commandLine = EXPORT_HELP::MakeCommandLine( m_netListerCommand, + tmpFile.GetFullPath(), + aFullFileName ); D(printf("commandLine:'%s'\n", TO_UTF8( commandLine ) );) diff --git a/eeschema/netlist_control.cpp b/eeschema/netlist_control.cpp index 6112b267d1..bd220b1fbd 100644 --- a/eeschema/netlist_control.cpp +++ b/eeschema/netlist_control.cpp @@ -262,7 +262,7 @@ void NETLIST_DIALOG::InstallPageSpice() page->m_CommandStringCtrl = new WinEDA_EnterText( page, _( "Simulator command:" ), - g_SimulatorCommandLine, + m_Parent->GetSimulatorCommand(), page->m_LowBoxSizer, wxDefaultSize ); @@ -436,7 +436,7 @@ void NETLIST_DIALOG::NetlistUpdateOpt() { int ii; - g_SimulatorCommandLine = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue(); + m_Parent->SetSimulatorCommand( m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue() ); m_Parent->m_NetlistFormat = NET_TYPE_PCBNEW; for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ ) @@ -512,13 +512,14 @@ void NETLIST_DIALOG::GenNetlist( wxCommandEvent& event ) m_Parent->ClearMsgPanel(); if( CurrPage->m_CommandStringCtrl ) - g_NetListerCommandLine = CurrPage->m_CommandStringCtrl->GetValue(); + m_Parent->SetNetListerCommand( CurrPage->m_CommandStringCtrl->GetValue() ); else - g_NetListerCommandLine.Empty(); + m_Parent->SetNetListerCommand( wxEmptyString ); bool addSubPrefix = false; if( CurrPage->m_AddSubPrefix ) addSubPrefix = CurrPage->m_AddSubPrefix->GetValue(); + m_Parent->CreateNetlist( CurrPage->m_IdNetType, dlg.GetPath(), g_OptNetListUseNames, addSubPrefix ); @@ -592,12 +593,12 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event ) wxFileName fn; wxString ExecFile, CommandLine; - g_SimulatorCommandLine = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue(); - g_SimulatorCommandLine.Trim( false ); - g_SimulatorCommandLine.Trim( true ); - ExecFile = g_SimulatorCommandLine.BeforeFirst( ' ' ); - - CommandLine = g_SimulatorCommandLine.AfterFirst( ' ' ); + wxString tmp = m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue(); + tmp.Trim( false ); + tmp.Trim( true ); + m_Parent->SetSimulatorCommand( tmp ); + ExecFile = tmp.BeforeFirst( ' ' ); + CommandLine = tmp.AfterFirst( ' ' ); /* Calculate the netlist filename */ fn = g_RootSheet->GetScreen()->GetFileName(); @@ -609,8 +610,10 @@ void NETLIST_DIALOG::RunSimulator( wxCommandEvent& event ) CurrPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage(); bool addSubPrefix = false; + if( CurrPage->m_AddSubPrefix ) addSubPrefix = CurrPage->m_AddSubPrefix->GetValue(); + if( ! m_Parent->CreateNetlist( CurrPage->m_IdNetType, fn.GetFullPath(), g_OptNetListUseNames,addSubPrefix ) ) return; diff --git a/eeschema/netlist_control.h b/eeschema/netlist_control.h index c63507a900..e8b587b031 100644 --- a/eeschema/netlist_control.h +++ b/eeschema/netlist_control.h @@ -67,8 +67,8 @@ public: * Only one page can be created with selected = true. */ NETLIST_PAGE_DIALOG( wxNotebook* parent, const wxString& title, - int id_NetType, int idCheckBox, int idCreateFile, - bool selected ); + int id_NetType, int idCheckBox, int idCreateFile, + bool selected ); ~NETLIST_PAGE_DIALOG() { }; }; diff --git a/eeschema/protos.h b/eeschema/protos.h index 8da45fa26c..7267f77c2d 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -32,9 +32,9 @@ wxString DataBaseGetName( EDA_DRAW_FRAME* frame, wxString& Keys, wxString& BufNa bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint ); -/****************/ +/*************************/ /* BUS_WIRE_JUNCTION.CPP */ -/****************/ +/*************************/ void IncrementLabelMember( wxString& name ); @@ -58,22 +58,21 @@ void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList ); SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct, bool aClone = false ); -/***************/ +/****************/ /* EEREDRAW.CPP */ -/***************/ +/****************/ void DrawDanglingSymbol( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& pos, int Color ); -/**************/ -/* EELAYER.CPP */ -/**************/ -void SeedLayers(); +/***********************************/ +/* dialogs/dialog_color_config.cpp */ +/***********************************/ EDA_Colors ReturnLayerColor( int Layer ); -/**************/ +/***************/ /* NETLIST.CPP */ -/**************/ +/***************/ int IsBusLabel( const wxString& LabelDrawList ); @@ -84,25 +83,14 @@ void PlotDrawlist( PLOTTER* plotter, SCH_ITEM* drawlist ); /***************/ -/* DELSHEET.CPP */ -/***************/ -void DeleteSubHierarchy( SCH_SHEET* Sheet, bool confirm_deletion ); -bool ClearProjectDrawList( SCH_SCREEN* FirstWindow, bool confirm_deletion ); - -/* free the draw list screen->GetDrawItems() and the subhierarchies - * clear the screen datas (filenames ..) - */ - - -/**************/ /* PINEDIT.CPP */ -/**************/ +/***************/ void InstallPineditFrame( LIB_EDIT_FRAME* parent, wxDC* DC, const wxPoint& pos ); -/**************/ +/***************/ /* SELPART.CPP */ -/**************/ +/***************/ /** * Function DisplayComponentsNamesInLib @@ -139,9 +127,9 @@ CMP_LIBRARY* SelectLibraryFromList( EDA_DRAW_FRAME* frame ); */ int GetNameOfPartToLoad( EDA_DRAW_FRAME* frame, CMP_LIBRARY* Lib, wxString& BufName ); -/**************/ +/***************/ /* LIBARCH.CPP */ -/**************/ +/***************/ bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index d9db462bc3..0e7f898486 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -112,6 +112,23 @@ void SCH_SCREEN::DecRefCount() } +void SCH_SCREEN::Clear() +{ + FreeDrawList(); + + /* Clear the project settings. */ + m_ScreenNumber = m_NumberOfScreen = 1; + m_Title.Empty(); + m_Revision.Empty(); + m_Company.Empty(); + m_Commentaire1.Empty(); + m_Commentaire2.Empty(); + m_Commentaire3.Empty(); + m_Commentaire4.Empty(); + m_Date = GenDate(); +} + + void SCH_SCREEN::FreeDrawList() { SCH_ITEM* item; diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 01b0c49c31..ee8e5af145 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -418,7 +418,7 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) && (g_RootSheet->GetScreen()->GetDrawItems() != NULL) ) UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() ); - ClearProjectDrawList( g_RootSheet->GetScreen(), TRUE ); + g_RootSheet->GetScreen()->Clear(); /* all sub sheets are deleted, only the main sheet is usable */ m_CurrentSheet->Clear(); diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 00e93d8c0f..8047362b90 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -12,21 +12,16 @@ #include "fctsys.h" #include "gr_basic.h" #include "common.h" -#include "macros.h" #include "class_drawpanel.h" #include "confirm.h" -#include "gestfich.h" #include "wxEeschemaStruct.h" #include "class_sch_screen.h" #include "general.h" -#include "protos.h" #include "sch_sheet.h" #include "dialogs/dialog_sch_sheet_props.h" -#include - bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, wxDC* aDC ) { diff --git a/include/class_sch_screen.h b/include/class_sch_screen.h index 49f5fcfb92..a08ce62945 100644 --- a/include/class_sch_screen.h +++ b/include/class_sch_screen.h @@ -87,6 +87,12 @@ public: */ void SetCurItem( SCH_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); } + /** + * Function Clear + * deletes all draw items and clears the project settings. + */ + void Clear(); + /** * Free all the items from the schematic associated with the screen. * diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 3382ff5e44..2f1726a216 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -115,6 +115,10 @@ private: int m_repeatLabelDelta; ///< Repeat label number increment step. SCH_COLLECTOR m_collectedItems; ///< List of collected items. SCH_ITEM* m_undoItem; ///< Copy of the current item being edited. + wxString m_simulatorCommand; ///< Command line used to call the circuit + ///< simulator (gnucap, spice, ...) + wxString m_netListerCommand; ///< Command line to call a custom net list + ///< generator. static int m_lastSheetPinType; ///< Last sheet pin type. static wxSize m_lastSheetPinTextSize; ///< Last sheet pin text size. @@ -827,8 +831,7 @@ public: /** * Load component libraries defined in project file. */ - void LoadLibraries( void ); - + void LoadLibraries( void ); /** * Function PrintPage @@ -841,6 +844,14 @@ public: virtual void PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData = NULL ); + void SetSimulatorCommand( const wxString& aCommand ) { m_simulatorCommand = aCommand; } + + wxString GetSimulatorCommand() const { return m_simulatorCommand; } + + void SetNetListerCommand( const wxString& aCommand ) { m_netListerCommand = aCommand; } + + wxString GetNetListerCommand() const { return m_netListerCommand; } + DECLARE_EVENT_TABLE() };