From f9af593ee3875692b80b5165a5d8d3f021355b39 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 12 Jan 2011 16:47:54 -0500 Subject: [PATCH] Minor EESchema improvements. * Rename sch_item files to sch_junction. * Make global variable g_ItemToRepeat a private member of SCH_EDIT_FRAME object. * Encapsulate SCH_SCREEN reference count member. --- common/sch_item_struct.cpp | 2 +- eeschema/CMakeLists.txt | 2 +- eeschema/block.cpp | 2 +- eeschema/bus-wire-junction.cpp | 62 +++++++++++--------- eeschema/busentry.cpp | 4 +- eeschema/cleanup.cpp | 2 +- eeschema/delete.cpp | 4 +- eeschema/edit_label.cpp | 9 +-- eeschema/eeredraw.cpp | 2 +- eeschema/eeschema.cpp | 5 +- eeschema/general.h | 3 - eeschema/getpart.cpp | 2 +- eeschema/hierarch.cpp | 4 +- eeschema/hotkeys.cpp | 4 +- eeschema/load_one_schematic_file.cpp | 2 +- eeschema/locate.cpp | 2 +- eeschema/netlist.cpp | 2 +- eeschema/onleftclick.cpp | 12 ++-- eeschema/onrightclick.cpp | 2 +- eeschema/operations_on_items_lists.cpp | 2 +- eeschema/plot.cpp | 2 +- eeschema/{sch_items.cpp => sch_junction.cpp} | 2 +- eeschema/{sch_items.h => sch_junction.h} | 0 eeschema/sch_screen.cpp | 12 +++- eeschema/sch_sheet.cpp | 28 ++++----- eeschema/schedit.cpp | 12 ++-- eeschema/schematic_undo_redo.cpp | 2 +- eeschema/schframe.cpp | 4 +- eeschema/sheet.cpp | 2 +- include/class_sch_screen.h | 12 +++- include/wxEeschemaStruct.h | 6 ++ 31 files changed, 116 insertions(+), 95 deletions(-) rename eeschema/{sch_items.cpp => sch_junction.cpp} (99%) rename eeschema/{sch_items.h => sch_junction.h} (100%) diff --git a/common/sch_item_struct.cpp b/common/sch_item_struct.cpp index f90271319f..f1fcb7bcd0 100644 --- a/common/sch_item_struct.cpp +++ b/common/sch_item_struct.cpp @@ -61,7 +61,7 @@ void SCH_ITEM::Place( SCH_EDIT_FRAME* frame, wxDC* DC ) if( !screen->CheckIfOnDrawList( this ) ) //don't want a loop! screen->AddToDrawList( this ); - g_ItemToRepeat = this; + frame->SetRepeatItem( this ); frame->SaveCopyInUndoList( this, UR_NEW ); } diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index ce65ff2660..efd952df58 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -119,7 +119,7 @@ set(EESCHEMA_SRCS sch_bus_entry.cpp sch_component.cpp sch_field.cpp - sch_items.cpp + sch_junction.cpp sch_line.cpp sch_marker.cpp sch_no_connect.cpp diff --git a/eeschema/block.cpp b/eeschema/block.cpp index 9d52dde72c..58dcee927b 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -17,7 +17,7 @@ #include "protos.h" #include "sch_bus_entry.h" #include "sch_marker.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_no_connect.h" #include "sch_text.h" diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 160841cf98..fa02fbdff9 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -15,7 +15,7 @@ #include "general.h" #include "protos.h" #include "sch_bus_entry.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_no_connect.h" #include "sch_polyline.h" @@ -183,7 +183,7 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type ) GetScreen()->SetCurItem( newsegment ); DrawPanel->ManageCurseur = DrawSegment; DrawPanel->ForceCloseManageCurseur = AbortCreateNewLine; - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; } else // A segment is in progress: terminates the current segment and add a new segment. { @@ -331,8 +331,8 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) { if( segment->m_Flags ) { - if( !g_ItemToRepeat ) - g_ItemToRepeat = segment; + if( !m_itemToRepeat ) + m_itemToRepeat = segment; } segment->m_Flags = 0; @@ -468,7 +468,7 @@ static void Show_Polyline_in_Ghost( WinEDA_DrawPanel* panel, wxDC* DC, bool eras */ void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC ) { - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; if( ( GetScreen()->GetCurItem() == NULL ) || ( ( GetScreen()->GetCurItem()->m_Flags & IS_NEW ) == 0 ) ) @@ -502,7 +502,7 @@ SCH_JUNCTION* SCH_EDIT_FRAME::CreateNewJunctionStruct( wxDC* DC, NewJunction = new SCH_JUNCTION( pos ); - g_ItemToRepeat = NewJunction; + m_itemToRepeat = NewJunction; DrawPanel->CursorOff( DC ); // Erase schematic cursor NewJunction->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); @@ -525,7 +525,7 @@ SCH_NO_CONNECT* SCH_EDIT_FRAME::CreateNewNoConnectStruct( wxDC* DC ) SCH_NO_CONNECT* NewNoConnect; NewNoConnect = new SCH_NO_CONNECT( GetScreen()->m_Curseur ); - g_ItemToRepeat = NewNoConnect; + m_itemToRepeat = NewNoConnect; DrawPanel->CursorOff( DC ); // Erase schematic cursor NewNoConnect->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); @@ -555,7 +555,11 @@ static void AbortCreateNewLine( WinEDA_DrawPanel* Panel, wxDC* DC ) Panel->Refresh(); } else - g_ItemToRepeat = NULL; + { + SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) Panel->GetParent(); + + parent->SetRepeatItem( NULL ); + } /* Clear m_Flags which is used in edit functions: */ SCH_ITEM* item = Screen->GetDrawItems(); @@ -574,40 +578,40 @@ static void AbortCreateNewLine( WinEDA_DrawPanel* Panel, wxDC* DC ) */ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC ) { - if( g_ItemToRepeat == NULL ) + if( m_itemToRepeat == NULL ) return; - g_ItemToRepeat = g_ItemToRepeat->Clone(); + m_itemToRepeat = m_itemToRepeat->Clone(); - if( g_ItemToRepeat->Type() == SCH_COMPONENT_T ) // If repeat component then put in move mode + if( m_itemToRepeat->Type() == SCH_COMPONENT_T ) // If repeat component then put in move mode { - wxPoint pos = GetScreen()->m_Curseur - ( (SCH_COMPONENT*) g_ItemToRepeat )->m_Pos; - g_ItemToRepeat->m_Flags = IS_NEW; - ( (SCH_COMPONENT*) g_ItemToRepeat )->m_TimeStamp = GetTimeStamp(); - g_ItemToRepeat->Move( pos ); - g_ItemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode ); - StartMovePart( (SCH_COMPONENT*) g_ItemToRepeat, DC ); + wxPoint pos = GetScreen()->m_Curseur - ( (SCH_COMPONENT*) m_itemToRepeat )->m_Pos; + m_itemToRepeat->m_Flags = IS_NEW; + ( (SCH_COMPONENT*) m_itemToRepeat )->m_TimeStamp = GetTimeStamp(); + m_itemToRepeat->Move( pos ); + m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode ); + StartMovePart( (SCH_COMPONENT*) m_itemToRepeat, DC ); return; } - g_ItemToRepeat->Move( wxPoint( g_RepeatStep.GetWidth(), g_RepeatStep.GetHeight() ) ); + m_itemToRepeat->Move( wxPoint( g_RepeatStep.GetWidth(), g_RepeatStep.GetHeight() ) ); - if( g_ItemToRepeat->Type() == SCH_TEXT_T - || g_ItemToRepeat->Type() == SCH_LABEL_T - || g_ItemToRepeat->Type() == SCH_HIERARCHICAL_LABEL_T - || g_ItemToRepeat->Type() == SCH_GLOBAL_LABEL_T ) + if( m_itemToRepeat->Type() == SCH_TEXT_T + || m_itemToRepeat->Type() == SCH_LABEL_T + || m_itemToRepeat->Type() == SCH_HIERARCHICAL_LABEL_T + || m_itemToRepeat->Type() == SCH_GLOBAL_LABEL_T ) { - ( (SCH_TEXT*) g_ItemToRepeat )->IncrementLabel(); + ( (SCH_TEXT*) m_itemToRepeat )->IncrementLabel(); } - if( g_ItemToRepeat ) + if( m_itemToRepeat ) { - g_ItemToRepeat->SetNext( GetScreen()->GetDrawItems() ); - GetScreen()->SetDrawItems( g_ItemToRepeat ); + m_itemToRepeat->SetNext( GetScreen()->GetDrawItems() ); + GetScreen()->SetDrawItems( m_itemToRepeat ); TestDanglingEnds( GetScreen()->GetDrawItems(), NULL ); - g_ItemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); - SaveCopyInUndoList( g_ItemToRepeat, UR_NEW ); - g_ItemToRepeat->m_Flags = 0; + m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); + SaveCopyInUndoList( m_itemToRepeat, UR_NEW ); + m_itemToRepeat->m_Flags = 0; } } diff --git a/eeschema/busentry.cpp b/eeschema/busentry.cpp index ffb1a62424..baf0e9f3ad 100644 --- a/eeschema/busentry.cpp +++ b/eeschema/busentry.cpp @@ -42,7 +42,9 @@ static void ExitBusEntry( WinEDA_DrawPanel* Panel, wxDC* DC ) } } - g_ItemToRepeat = NULL; + SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) Panel->GetParent(); + + parent->SetRepeatItem( NULL ); Panel->ManageCurseur = NULL; Panel->ForceCloseManageCurseur = NULL; } diff --git a/eeschema/cleanup.cpp b/eeschema/cleanup.cpp index d5dae8c0c1..86a2469027 100644 --- a/eeschema/cleanup.cpp +++ b/eeschema/cleanup.cpp @@ -13,7 +13,7 @@ #include "protos.h" #include "netlist.h" #include "sch_bus_entry.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" diff --git a/eeschema/delete.cpp b/eeschema/delete.cpp index afba05b661..f43dabac9d 100644 --- a/eeschema/delete.cpp +++ b/eeschema/delete.cpp @@ -11,7 +11,7 @@ #include "general.h" #include "protos.h" #include "sch_marker.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_sheet.h" #include "sch_text.h" @@ -312,7 +312,7 @@ bool LocateAndDeleteItem( SCH_EDIT_FRAME* frame, wxDC* DC ) if( DelStruct ) { - g_ItemToRepeat = NULL; + frame->SetRepeatItem( NULL ); DeleteStruct( frame->DrawPanel, DC, DelStruct ); frame->TestDanglingEnds( frame->GetScreen()->GetDrawItems(), DC ); frame->OnModify( ); diff --git a/eeschema/edit_label.cpp b/eeschema/edit_label.cpp index 4cbfd78412..89f60e6d9f 100644 --- a/eeschema/edit_label.cpp +++ b/eeschema/edit_label.cpp @@ -36,7 +36,7 @@ void SCH_EDIT_FRAME::StartMoveTexte( SCH_TEXT* TextStruct, wxDC* DC ) if( TextStruct == NULL ) return; - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; if( (TextStruct->m_Flags & IS_NEW) == 0 ) { @@ -120,7 +120,7 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( wxDC* DC, int type ) { SCH_TEXT* NewText = NULL; - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; switch( type ) { @@ -215,8 +215,9 @@ static void ExitMoveTexte( WinEDA_DrawPanel* Panel, wxDC* DC ) { BASE_SCREEN* screen = Panel->GetScreen(); SCH_ITEM* Struct = (SCH_ITEM*) screen->GetCurItem(); + SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) Panel->GetParent(); - g_ItemToRepeat = NULL; + parent->SetRepeatItem( NULL ); Panel->ManageCurseur = NULL; Panel->ForceCloseManageCurseur = NULL; @@ -335,7 +336,7 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* Text, wxDC* DC, int newtype ) DeleteStruct( DrawPanel, DC, Text ); // old text is really saved in // undo list GetScreen()->SetCurItem( NULL ); - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; } GetScreen()->SetCurItem( NULL ); diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index d14a60b91d..285851f17a 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -16,7 +16,7 @@ #include "class_library.h" #include "sch_bus_entry.h" #include "sch_component.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_no_connect.h" #include "sch_polyline.h" diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 4616a832dc..9cfae3f937 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -25,11 +25,8 @@ // Global variables -bool g_OptNetListUseNames; /* TRUE to use names rather than net +bool g_OptNetListUseNames; /* TRUE to use names rather than net * The numbers (PSPICE netlist only) */ -SCH_ITEM* g_ItemToRepeat; /* Pointer to the last structure - * for duplicatation by the repeat command. - * (NULL if no struct exists) */ wxSize g_RepeatStep; int g_RepeatDeltaLabel; diff --git a/eeschema/general.h b/eeschema/general.h index 9caf5d1cb4..ffd8dded1c 100644 --- a/eeschema/general.h +++ b/eeschema/general.h @@ -132,9 +132,6 @@ public: int Flags; }; -extern SCH_ITEM* g_ItemToRepeat; /* Pointer to the last structure used - * by the repeat command. NULL if no - * item to repeat */ extern wxSize g_RepeatStep; extern int g_RepeatDeltaLabel; diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 47c573ef2f..88b3edf8ac 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -76,7 +76,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, bool AllowWildSeach = TRUE; static wxString lastCommponentName; - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; DrawPanel->m_IgnoreMouseEvents = TRUE; if( !libname.IsEmpty() ) diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index 5697b9ccd4..8346d54e01 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -256,7 +256,7 @@ void SCH_EDIT_FRAME::InstallPreviousSheet() if( m_CurrentSheet->Last() == g_RootSheet ) return; - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; ClearMsgPanel(); //make a copy for testing purposes. @@ -287,7 +287,7 @@ void SCH_EDIT_FRAME::InstallNextScreen( SCH_SHEET* Sheet ) DisplayError( this, wxT( "InstallNextScreen() error" ) ); return; } m_CurrentSheet->Push( Sheet ); - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; ClearMsgPanel(); UpdateScreenFromSheet( this ); } diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index afa2433f08..63080af9af 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -12,7 +12,7 @@ #include "protos.h" #include "libeditframe.h" #include "class_libentry.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_component.h" #include "sch_sheet.h" @@ -351,7 +351,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct ) break; case HK_REPEAT_LAST: - if( notBusy && g_ItemToRepeat && ( g_ItemToRepeat->m_Flags == 0 ) ) + if( notBusy && m_itemToRepeat && ( m_itemToRepeat->m_Flags == 0 ) ) RepeatDrawItem( DC ); break; diff --git a/eeschema/load_one_schematic_file.cpp b/eeschema/load_one_schematic_file.cpp index 4885d21592..ca54cc2295 100644 --- a/eeschema/load_one_schematic_file.cpp +++ b/eeschema/load_one_schematic_file.cpp @@ -13,7 +13,7 @@ #include "protos.h" #include "sch_bus_entry.h" #include "sch_marker.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_no_connect.h" #include "sch_component.h" diff --git a/eeschema/locate.cpp b/eeschema/locate.cpp index b7cca07d15..4a0c61c409 100644 --- a/eeschema/locate.cpp +++ b/eeschema/locate.cpp @@ -13,7 +13,7 @@ #include "class_library.h" #include "sch_bus_entry.h" #include "sch_marker.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_component.h" #include "sch_line.h" #include "sch_no_connect.h" diff --git a/eeschema/netlist.cpp b/eeschema/netlist.cpp index cd1f98fbff..b91486fea1 100644 --- a/eeschema/netlist.cpp +++ b/eeschema/netlist.cpp @@ -12,7 +12,7 @@ #include "protos.h" #include "class_library.h" #include "lib_pin.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_component.h" #include "sch_line.h" #include "sch_no_connect.h" diff --git a/eeschema/onleftclick.cpp b/eeschema/onleftclick.cpp index a2c73ad69f..623632c1b7 100644 --- a/eeschema/onleftclick.cpp +++ b/eeschema/onleftclick.cpp @@ -15,7 +15,7 @@ #include "sch_bus_entry.h" #include "sch_text.h" #include "sch_marker.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_no_connect.h" #include "sch_component.h" @@ -36,7 +36,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) if( ( m_ID_current_state == 0 ) || ( DrawStruct && DrawStruct->m_Flags ) ) { DrawPanel->m_AutoPAN_Request = FALSE; - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; if( DrawStruct && DrawStruct->m_Flags ) { @@ -106,8 +106,8 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) case ID_NOCONN_BUTT: if( ( DrawStruct == NULL ) || ( DrawStruct->m_Flags == 0 ) ) { - g_ItemToRepeat = CreateNewNoConnectStruct( DC ); - GetScreen()->SetCurItem( g_ItemToRepeat ); + m_itemToRepeat = CreateNewNoConnectStruct( DC ); + GetScreen()->SetCurItem( m_itemToRepeat ); DrawPanel->m_AutoPAN_Request = TRUE; } else @@ -122,8 +122,8 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) case ID_JUNCTION_BUTT: if( ( DrawStruct == NULL ) || ( DrawStruct->m_Flags == 0 ) ) { - g_ItemToRepeat = CreateNewJunctionStruct( DC, GetScreen()->m_Curseur, TRUE ); - GetScreen()->SetCurItem( g_ItemToRepeat ); + m_itemToRepeat = CreateNewJunctionStruct( DC, GetScreen()->m_Curseur, TRUE ); + GetScreen()->SetCurItem( m_itemToRepeat ); DrawPanel->m_AutoPAN_Request = TRUE; } else diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index baf5274212..654f9ef184 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -18,7 +18,7 @@ #include "sch_bus_entry.h" #include "sch_marker.h" #include "sch_text.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_component.h" #include "sch_line.h" #include "sch_no_connect.h" diff --git a/eeschema/operations_on_items_lists.cpp b/eeschema/operations_on_items_lists.cpp index 5a1687e88c..c6ec90e9f6 100644 --- a/eeschema/operations_on_items_lists.cpp +++ b/eeschema/operations_on_items_lists.cpp @@ -20,7 +20,7 @@ #include "sch_polyline.h" #include "sch_sheet.h" #include "sch_component.h" -#include "sch_items.h" +#include "sch_junction.h" void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& rotationPoint ) diff --git a/eeschema/plot.cpp b/eeschema/plot.cpp index 8f6a4528f5..d3e228c5ef 100644 --- a/eeschema/plot.cpp +++ b/eeschema/plot.cpp @@ -15,7 +15,7 @@ #include "class_library.h" #include "lib_pin.h" #include "sch_bus_entry.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_no_connect.h" #include "sch_component.h" diff --git a/eeschema/sch_items.cpp b/eeschema/sch_junction.cpp similarity index 99% rename from eeschema/sch_items.cpp rename to eeschema/sch_junction.cpp index 98758718aa..7b77f573bc 100644 --- a/eeschema/sch_items.cpp +++ b/eeschema/sch_junction.cpp @@ -12,7 +12,7 @@ #include "general.h" #include "protos.h" -#include "sch_items.h" +#include "sch_junction.h" /**********************/ diff --git a/eeschema/sch_items.h b/eeschema/sch_junction.h similarity index 100% rename from eeschema/sch_items.h rename to eeschema/sch_junction.h diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index d6f73ef378..fec429a1b5 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -14,7 +14,7 @@ #include "protos.h" #include "netlist.h" #include "class_library.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_bus_entry.h" #include "sch_line.h" #include "sch_marker.h" @@ -101,7 +101,7 @@ SCH_SCREEN::SCH_SCREEN( KICAD_T type ) : BASE_SCREEN( type ) AddGrid( SchematicGridList[i] ); SetGrid( wxRealPoint( 50, 50 ) ); /* Default grid size. */ - m_RefCount = 0; + m_refCount = 0; m_Center = false; /* Suitable for schematic only. For * libedit and viewlib, must be set * to true */ @@ -116,6 +116,14 @@ SCH_SCREEN::~SCH_SCREEN() } +void SCH_SCREEN::DecRefCount() +{ + wxCHECK_RET( m_refCount != 0, + wxT( "Screen reference count already zero. Bad programmer!" ) ); + m_refCount--; +} + + void SCH_SCREEN::FreeDrawList() { SCH_ITEM* DrawStruct; diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index e93183369c..62a84729b5 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -59,7 +59,7 @@ SCH_SHEET::SCH_SHEET( const SCH_SHEET& aSheet ) : m_labels[i].SetParent( this ); if( m_AssociatedScreen ) - m_AssociatedScreen->m_RefCount++; + m_AssociatedScreen->IncRefCount(); } @@ -69,9 +69,9 @@ SCH_SHEET::~SCH_SHEET() // perhaps it should be deleted also. if( m_AssociatedScreen ) { - m_AssociatedScreen->m_RefCount--; + m_AssociatedScreen->GetRefCount(); - if( m_AssociatedScreen->m_RefCount == 0 ) + if( m_AssociatedScreen->GetRefCount() == 0 ) delete m_AssociatedScreen; } } @@ -692,14 +692,14 @@ bool SCH_SHEET::Load( SCH_EDIT_FRAME* aFrame ) if( screen ) { m_AssociatedScreen = screen; - m_AssociatedScreen->m_RefCount++; + m_AssociatedScreen->IncRefCount(); //do not need to load the sub-sheets - this has already been done. } else { m_AssociatedScreen = new SCH_SCREEN(); - m_AssociatedScreen->m_RefCount++; + m_AssociatedScreen->IncRefCount(); success = aFrame->LoadOneEEFile( m_AssociatedScreen, m_FileName ); if( success ) @@ -790,9 +790,9 @@ current sheet data if possible)?" ), // Can be NULL if loading a file when creating a new sheet. if( m_AssociatedScreen ) { - m_AssociatedScreen->m_RefCount--; // be careful with these + m_AssociatedScreen->DecRefCount(); // be careful with these - if( m_AssociatedScreen->m_RefCount == 0 ) + if( m_AssociatedScreen->GetRefCount() == 0 ) SAFE_DELETE( m_AssociatedScreen ); m_AssociatedScreen = NULL; // will be created later @@ -802,7 +802,7 @@ current sheet data if possible)?" ), // if an associated screen exists, shared between this sheet and others // sheets, what we do ? - if( m_AssociatedScreen && ( m_AssociatedScreen->m_RefCount > 1 ) ) + if( m_AssociatedScreen && ( m_AssociatedScreen->GetRefCount() > 1 ) ) { msg = _( "This sheet uses shared data in a complex hierarchy" ); msg << wxT( "\n" ); @@ -817,8 +817,8 @@ otherwise delete current sheet data)" ); aFrame->SaveEEFile( m_AssociatedScreen, FILE_SAVE_AS ); m_AssociatedScreen->m_FileName = oldfilename; } - m_AssociatedScreen->m_RefCount--; //be careful with these - m_AssociatedScreen = NULL; //will be created later + m_AssociatedScreen->DecRefCount(); //be careful with these + m_AssociatedScreen = NULL; //will be created later } SetFileName( aFileName ); @@ -827,9 +827,9 @@ otherwise delete current sheet data)" ); // current sheet data if( m_AssociatedScreen && (LoadFromFile || Screen_to_use) ) { - m_AssociatedScreen->m_RefCount--; + m_AssociatedScreen->DecRefCount(); - if( m_AssociatedScreen->m_RefCount == 0 ) + if( m_AssociatedScreen->GetRefCount() == 0 ) SAFE_DELETE( m_AssociatedScreen ); m_AssociatedScreen = NULL; // so that we reload.. @@ -840,14 +840,14 @@ otherwise delete current sheet data)" ); else if( Screen_to_use ) { m_AssociatedScreen = Screen_to_use; - m_AssociatedScreen->m_RefCount++; + m_AssociatedScreen->IncRefCount(); } //just make a new screen if needed. if( !m_AssociatedScreen ) { m_AssociatedScreen = new SCH_SCREEN(); - m_AssociatedScreen->m_RefCount++; // be careful with these + m_AssociatedScreen->IncRefCount(); // be careful with these } m_AssociatedScreen->m_FileName = aFileName; diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 507e20eee3..c9a3a4ad2c 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -20,7 +20,7 @@ #include "sch_bus_entry.h" #include "sch_marker.h" #include "sch_component.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_sheet.h" @@ -161,14 +161,14 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) { case ID_HIERARCHY: InstallHierarchyFrame( &dc, pos ); - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; break; case wxID_CUT: if( screen->m_BlockLocate.m_Command != BLOCK_MOVE ) break; HandleBlockEndByPopUp( BLOCK_DELETE, &dc ); - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; SetSheetNumberAndCount(); break; @@ -316,7 +316,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) DrawPanel->MouseToCursorSchema(); DeleteConnection( id == ID_POPUP_SCH_DELETE_CONNECTION ? TRUE : FALSE ); screen->SetCurItem( NULL ); - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; TestDanglingEnds( screen->GetDrawItems(), &dc ); DrawPanel->Refresh(); break; @@ -352,7 +352,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) DeleteStruct( DrawPanel, &dc, item ); screen->SetCurItem( NULL ); - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; TestDanglingEnds( screen->GetDrawItems(), &dc ); SetSheetNumberAndCount(); OnModify(); @@ -757,7 +757,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) // End switch ( id ) (Command execution) if( m_ID_current_state == 0 ) - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; SetToolbars(); } diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index 07cd4547e3..ab06469472 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -12,7 +12,7 @@ #include "protos.h" #include "sch_bus_entry.h" #include "sch_marker.h" -#include "sch_items.h" +#include "sch_junction.h" #include "sch_line.h" #include "sch_no_connect.h" #include "sch_component.h" diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index f787d8b35e..12e97967ae 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -181,7 +181,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father, SetIcon( wxICON( icon_eeschema ) ); #endif - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; /* Get config */ LoadSettings(); @@ -329,7 +329,7 @@ void SCH_EDIT_FRAME::CreateScreens() if( g_RootSheet->m_AssociatedScreen == NULL ) { g_RootSheet->m_AssociatedScreen = new SCH_SCREEN(); - g_RootSheet->m_AssociatedScreen->m_RefCount++; + g_RootSheet->m_AssociatedScreen->IncRefCount(); } g_RootSheet->m_AssociatedScreen->m_FileName = m_DefaultSchematicFileName; diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index f928a9ad37..13e17c86d8 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -213,7 +213,7 @@ static void ExitSheet( WinEDA_DrawPanel* aPanel, wxDC* aDC ) /* Create hierarchy sheet. */ SCH_SHEET* SCH_EDIT_FRAME::CreateSheet( wxDC* aDC ) { - g_ItemToRepeat = NULL; + m_itemToRepeat = NULL; SAFE_DELETE( g_ItemToUndoCopy ); SCH_SHEET* sheet = new SCH_SHEET( GetScreen()->m_Curseur ); diff --git a/include/class_sch_screen.h b/include/class_sch_screen.h index 31fdbaea36..14a659e283 100644 --- a/include/class_sch_screen.h +++ b/include/class_sch_screen.h @@ -22,6 +22,9 @@ class SCH_SHEET_PIN; class SCH_SCREEN : public BASE_SCREEN { + int m_refCount; ///< Number of sheets referencing this screen. + ///< Delete when it goes to zero. + /** * Function addConnectedItemsToBlock * add items connected at \a aPosition to the block pick list. @@ -35,9 +38,6 @@ class SCH_SCREEN : public BASE_SCREEN void addConnectedItemsToBlock( const wxPoint& aPosition ); public: - int m_RefCount; ///< Number of sheets referencing this screen. - ///< Delete when it goes to zero. - SCH_SCREEN( KICAD_T aType = SCH_SCREEN_T ); ~SCH_SCREEN(); @@ -46,6 +46,12 @@ public: return wxT( "SCH_SCREEN" ); } + void DecRefCount(); + + void IncRefCount() { m_refCount++; } + + int GetRefCount() const { return m_refCount; } + /** * Function GetDrawItems(). * diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 06507fae61..3634d16400 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -93,6 +93,8 @@ private: wxArrayString m_findStringHistoryList; wxArrayString m_replaceStringHistoryList; BLOCK_SELECTOR m_blockItems; ///< List of selected items. + SCH_ITEM* m_itemToRepeat; ///< Last item to insert by the repeat command. + int m_repeatLabelDelta; ///< Repeat label number increment step. public: SCH_EDIT_FRAME( wxWindow* father, @@ -500,6 +502,8 @@ public: void DeleteSheetLabel( bool aRedraw, SCH_SHEET_PIN* aSheetLabelToDel ); + int GetLabelIncrement() const { return m_repeatLabelDelta; } + private: // Component @@ -653,6 +657,8 @@ public: void RepeatDrawItem( wxDC* DC ); + void SetRepeatItem( SCH_ITEM* aItem ) { m_itemToRepeat = aItem; } + void TestDanglingEnds( SCH_ITEM* DrawList, wxDC* DC ); // ERC: