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.
This commit is contained in:
Wayne Stambaugh 2012-01-04 17:08:46 -05:00
parent 5a96588eec
commit 152b8d91e3
10 changed files with 126 additions and 157 deletions

View File

@ -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 )

View File

@ -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;
}

View File

@ -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:

View File

@ -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.
*/

View File

@ -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

View File

@ -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();

View File

@ -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;

View File

@ -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 );
}
}

View File

@ -179,15 +179,6 @@ public:
int aDrawMode,
int aColor = -1 ) = 0;
/**
* Function Place
* place the schematic item into the draw list.
* <p>
* If the schematic item is a new item or is modified, it is added to undo list.
* </p>
*/
virtual void Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC );
/**
* Function Move
* moves the item by \a aMoveVector to a new position.

View File

@ -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,