From 152b8d91e39321ae99af788992cb6a65f0b8bc69 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 4 Jan 2012 17:08:46 -0500 Subject: [PATCH] Eeschema schematic object improvements. * Move SCH_ITEM::Place() code into SCH_EDIT_FRAME so schematic item objects no longer have any knowledge of the schematic frame window or undo/redo containers. --- common/sch_item_struct.cpp | 31 --------------- eeschema/busentry.cpp | 16 ++++---- eeschema/onleftclick.cpp | 78 ++++++++++++++------------------------ eeschema/sch_sheet.cpp | 24 ------------ eeschema/sch_sheet.h | 4 -- eeschema/sch_sheet_pin.cpp | 26 ------------- eeschema/schedit.cpp | 10 ++--- eeschema/schframe.cpp | 77 +++++++++++++++++++++++++++++++++++++ include/sch_item_struct.h | 9 ----- include/wxEeschemaStruct.h | 8 ++++ 10 files changed, 126 insertions(+), 157 deletions(-) diff --git a/common/sch_item_struct.cpp b/common/sch_item_struct.cpp index e6cff77782..90f88bf652 100644 --- a/common/sch_item_struct.cpp +++ b/common/sch_item_struct.cpp @@ -80,37 +80,6 @@ SCH_ITEM::~SCH_ITEM() } -void SCH_ITEM::Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC ) -{ - SCH_SCREEN* screen = aFrame->GetScreen(); - - if( IsNew() ) - { - if( !screen->CheckIfOnDrawList( this ) ) // don't want a loop! - screen->AddToDrawList( this ); - - aFrame->SetRepeatItem( this ); - aFrame->SaveCopyInUndoList( this, UR_NEW ); - } - else - { - aFrame->SaveUndoItemInUndoList( this ); - } - - m_Flags = 0; - screen->SetModify(); - screen->SetCurItem( NULL ); - aFrame->GetCanvas()->SetMouseCapture( NULL, NULL ); - aFrame->GetCanvas()->EndMouseCapture(); - - if( aDC ) - { - EDA_CROSS_HAIR_MANAGER( aFrame->GetCanvas(), aDC ); // Erase schematic cursor - Draw( aFrame->GetCanvas(), aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); - } -} - - bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const { if( m_Flags & STRUCT_DELETED || m_Flags & SKIP_STRUCT ) diff --git a/eeschema/busentry.cpp b/eeschema/busentry.cpp index 9cf60b3304..cf9ea84ed7 100644 --- a/eeschema/busentry.cpp +++ b/eeschema/busentry.cpp @@ -43,15 +43,17 @@ static int s_LastShape = '\\'; -SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* DC, int entry_type ) +SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* aDC, int aType ) { + SCH_SCREEN* screen = GetScreen(); + // Create and place a new bus entry at cursor position - SCH_BUS_ENTRY* BusEntry = new SCH_BUS_ENTRY( GetScreen()->GetCrossHairPosition(), s_LastShape, - entry_type ); - BusEntry->SetFlags( IS_NEW ); - BusEntry->Place( this, DC ); - OnModify(); - return BusEntry; + SCH_BUS_ENTRY* busEntry = new SCH_BUS_ENTRY( screen->GetCrossHairPosition(), s_LastShape, + aType ); + busEntry->SetFlags( IS_NEW ); + GetScreen()->SetCurItem( busEntry ); + addCurrentItemToList( aDC ); + return busEntry; } diff --git a/eeschema/onleftclick.cpp b/eeschema/onleftclick.cpp index d6618e046c..3e28088fb5 100644 --- a/eeschema/onleftclick.cpp +++ b/eeschema/onleftclick.cpp @@ -76,10 +76,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) case SCH_FIELD_T: case SCH_BITMAP_T: case SCH_NO_CONNECT_T: - item->Place( this, aDC ); - GetScreen()->SetCurItem( NULL ); - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); + addCurrentItemToList( aDC ); return; case SCH_LINE_T: // May already be drawing segment. @@ -133,12 +130,9 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); + addCurrentItemToList( aDC ); } - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); break; case ID_JUNCTION_BUTT: @@ -150,30 +144,22 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); + addCurrentItemToList( aDC ); } - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); break; case ID_WIRETOBUS_ENTRY_BUTT: case ID_BUSTOBUS_ENTRY_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { - item = CreateBusEntry( aDC, ( GetToolId() == ID_WIRETOBUS_ENTRY_BUTT ) ? - WIRE_TO_BUS : BUS_TO_BUS ); - GetScreen()->SetCurItem( item ); + CreateBusEntry( aDC, ( GetToolId() == ID_WIRETOBUS_ENTRY_BUTT ) ? + WIRE_TO_BUS : BUS_TO_BUS ); m_canvas->SetAutoPanRequest( true ); } else { - item->Place( this, aDC ); - GetScreen()->SetCurItem( NULL ); - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); - m_canvas->SetAutoPanRequest( false ); + addCurrentItemToList( aDC ); } break; @@ -204,9 +190,9 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); + addCurrentItemToList( aDC ); } + break; case ID_ADD_IMAGE_BUTT: @@ -217,9 +203,9 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); + addCurrentItemToList( aDC ); } + break; case ID_LABEL_BUTT: @@ -230,11 +216,9 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); + addCurrentItemToList( aDC ); } + break; case ID_GLABEL_BUTT: @@ -251,26 +235,27 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); + addCurrentItemToList( aDC ); } + break; case ID_SHEET_SYMBOL_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { - GetScreen()->SetCurItem( CreateSheet( aDC ) ); - m_canvas->SetAutoPanRequest( true ); + item = CreateSheet( aDC ); + + if( item != NULL ) + { + GetScreen()->SetCurItem( item ); + m_canvas->SetAutoPanRequest( true ); + } } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); + addCurrentItemToList( aDC ); } + break; case ID_IMPORT_HLABEL_BUTT: @@ -290,10 +275,9 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else if( (item->Type() == SCH_SHEET_PIN_T) && (item->GetFlags() != 0) ) { - item->Place( this, aDC ); - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); + addCurrentItemToList( aDC ); } + break; case ID_SCH_PLACE_COMPONENT: @@ -304,11 +288,9 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); + addCurrentItemToList( aDC ); } + break; case ID_PLACE_POWER_BUTT: @@ -320,11 +302,9 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) } else { - item->Place( this, aDC ); - m_canvas->SetAutoPanRequest( false ); - GetScreen()->TestDanglingEnds(); - m_canvas->Refresh( true ); + addCurrentItemToList( aDC ); } + break; default: diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 4ead3f3bf7..572668221c 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -477,30 +477,6 @@ int SCH_SHEET::GetMinHeight() const } -void SCH_SHEET::Place( SCH_EDIT_FRAME* frame, wxDC* DC ) -{ - /* Place list structures for new sheet. */ - if( IsNew() ) - { - // fix size and position of the new sheet - // using the last values set by the m_mouseCaptureCallback function - frame->GetCanvas()->SetMouseCapture( NULL, NULL ); - - if( !frame->EditSheet( this, DC ) ) - { - frame->GetScreen()->SetCurItem( NULL ); - Draw( frame->GetCanvas(), DC, wxPoint( 0, 0 ), g_XorMode ); - delete this; - return; - } - - frame->SetSheetNumberAndCount(); - } - - SCH_ITEM::Place( frame, DC ); //puts it on the GetDrawItems(). -} - - /** * Delete sheet labels which do not have corresponding hierarchical label. */ diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index b427da8eb8..1b378347dd 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -148,8 +148,6 @@ public: */ SCH_SHEET* GetParent() const { return (SCH_SHEET*) m_Parent; } - void Place( SCH_EDIT_FRAME* frame, wxDC* DC ); - /** * Function Save * writes the data structures for this object out to a FILE in "*.sch" @@ -342,8 +340,6 @@ public: */ virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ); - void Place( SCH_EDIT_FRAME* frame, wxDC* DC ); - void DisplayInfo( EDA_DRAW_FRAME* frame ); /* there is no member for orientation in sch_sheet, to preserve file diff --git a/eeschema/sch_sheet_pin.cpp b/eeschema/sch_sheet_pin.cpp index 58f208cb9b..442dfd44a6 100644 --- a/eeschema/sch_sheet_pin.cpp +++ b/eeschema/sch_sheet_pin.cpp @@ -126,32 +126,6 @@ void SCH_SHEET_PIN::SetNumber( int aNumber ) } -void SCH_SHEET_PIN::Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC ) -{ - SCH_SHEET* sheet = (SCH_SHEET*) GetParent(); - - wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T), - wxT( "Cannot place sheet pin in invalid schematic sheet object." ) ); - - if( IsNew() ) - { - aFrame->SaveCopyInUndoList( sheet, UR_CHANGED ); - sheet->AddPin( this ); - } - else // Sheet pin already existed and was only moved. - { - aFrame->SaveUndoItemInUndoList( sheet ); - } - - ClearFlags(); - sheet->Draw( aFrame->GetCanvas(), aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); - - // Make sure we don't call the abort move function. - aFrame->GetCanvas()->SetMouseCapture( NULL, NULL ); - aFrame->GetCanvas()->EndMouseCapture(); -} - - void SCH_SHEET_PIN::SetEdge( int aEdge ) { SCH_SHEET* Sheet = (SCH_SHEET*) GetParent(); diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 647c420241..232c942e46 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -1,4 +1,4 @@ -/* + /* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com @@ -204,7 +204,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_SCH_END_SHEET: m_canvas->MoveCursorToCrossHair(); - item->Place( this, &dc ); + addCurrentItemToList( &dc ); break; case ID_POPUP_SCH_RESIZE_SHEET: @@ -330,11 +330,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) item = screen->GetCurItem(); if( item ) - { - item->Place( this, &dc ); - screen->TestDanglingEnds( m_canvas, &dc ); - screen->SetCurItem( NULL ); - } + addCurrentItemToList( &dc ); break; diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index c9a1447711..c4fa729df3 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -902,3 +902,80 @@ bool SCH_EDIT_FRAME::isAutoSaveRequired() const return SheetList.IsAutoSaveRequired(); } + + +void SCH_EDIT_FRAME::addCurrentItemToList( wxDC* aDC ) +{ + SCH_SCREEN* screen = GetScreen(); + SCH_ITEM* item = screen->GetCurItem(); + + wxCHECK_RET( item != NULL, wxT( "Cannot add current item to list." ) ); + + m_canvas->SetAutoPanRequest( false ); + + SCH_ITEM* undoItem = item; + + if( item->Type() == SCH_SHEET_PIN_T ) + { + SCH_SHEET* sheet = (SCH_SHEET*) item->GetParent(); + + wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T), + wxT( "Cannot place sheet pin in invalid schematic sheet object." ) ); + + undoItem = sheet; + } + + if( item->IsNew() ) + { + if( item->Type() == SCH_SHEET_T ) + { + // Fix the size and position of the new sheet using the last values set by + // the m_mouseCaptureCallback function. + m_canvas->SetMouseCapture( NULL, NULL ); + + if( !EditSheet( (SCH_SHEET*)item, aDC ) ) + { + screen->SetCurItem( NULL ); + item->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); + delete item; + return; + } + + SetSheetNumberAndCount(); + } + + if( undoItem == item ) + { + if( !screen->CheckIfOnDrawList( item ) ) // don't want a loop! + screen->AddToDrawList( item ); + + SetRepeatItem( item ); + + SaveCopyInUndoList( undoItem, UR_NEW ); + } + else + { + SaveCopyInUndoList( undoItem, UR_CHANGED ); + ( (SCH_SHEET*)undoItem )->AddPin( (SCH_SHEET_PIN*) item ); + } + } + else + { + SaveUndoItemInUndoList( undoItem ); + } + + item->ClearFlags(); + screen->SetModify(); + screen->SetCurItem( NULL ); + m_canvas->SetMouseCapture( NULL, NULL ); + m_canvas->EndMouseCapture(); + + if( item->IsConnectable() ) + screen->TestDanglingEnds(); + + if( aDC ) + { + EDA_CROSS_HAIR_MANAGER( m_canvas, aDC ); // Erase schematic cursor + undoItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); + } +} diff --git a/include/sch_item_struct.h b/include/sch_item_struct.h index e459759588..42c1e3717e 100644 --- a/include/sch_item_struct.h +++ b/include/sch_item_struct.h @@ -179,15 +179,6 @@ public: int aDrawMode, int aColor = -1 ) = 0; - /** - * Function Place - * place the schematic item into the draw list. - *

- * If the schematic item is a new item or is modified, it is added to undo list. - *

- */ - virtual void Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC ); - /** * Function Move * moves the item by \a aMoveVector to a new position. diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 65f09de0bb..b165d75c6e 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -181,6 +181,14 @@ protected: */ virtual bool isAutoSaveRequired() const; + /** + * Function addCurrentItemToList + * adds the item currently being edited to the schematic and adds the changes to + * the undo/redo container. + * + * @param aDC A pointer the device context to draw on when not NULL. + */ + void addCurrentItemToList( wxDC* aDC ); public: SCH_EDIT_FRAME( wxWindow* father,