2009-11-03 13:26:31 +00:00
|
|
|
/*****************************************************/
|
|
|
|
/* Code to handle manipulation on bus entry objects. */
|
|
|
|
/*****************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "eeschema_id.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_bus_entry.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
static int s_LastShape = '\\';
|
2007-05-06 16:03:28 +00:00
|
|
|
static wxPoint ItemInitialPosition;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
static void ExitBusEntry( EDA_DRAW_PANEL* Panel, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Exit bus entry mode. */
|
2010-11-10 15:30:12 +00:00
|
|
|
SCH_BUS_ENTRY* BusEntry = (SCH_BUS_ENTRY*) Panel->GetScreen()->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( BusEntry )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-01-10 16:50:40 +00:00
|
|
|
BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
if( BusEntry->IsNew() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
delete BusEntry;
|
|
|
|
Panel->GetScreen()->SetCurItem( NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BusEntry->m_Pos = ItemInitialPosition;
|
2011-01-10 16:50:40 +00:00
|
|
|
BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2007-08-20 01:20:48 +00:00
|
|
|
BusEntry->m_Flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) Panel->GetParent();
|
|
|
|
|
|
|
|
parent->SetRepeatItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-11-11 17:54:24 +00:00
|
|
|
// Draws the bus entry while moving the cursor
|
2011-02-03 19:27:28 +00:00
|
|
|
BASE_SCREEN* screen = aPanel->GetScreen();
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_BUS_ENTRY* BusEntry = (SCH_BUS_ENTRY*) screen->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( BusEntry == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Erase the last segment position. */
|
2011-02-03 19:27:28 +00:00
|
|
|
if( aErase )
|
|
|
|
BusEntry->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Redraw at the new position. */
|
2011-02-11 20:48:13 +00:00
|
|
|
BusEntry->m_Pos = screen->GetCrossHairPosition();
|
2011-02-03 19:27:28 +00:00
|
|
|
BusEntry->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* DC, int entry_type )
|
2009-11-03 13:26:31 +00:00
|
|
|
{
|
2010-11-11 17:54:24 +00:00
|
|
|
// Create and place a new bus entry at cursor position
|
2011-02-11 20:48:13 +00:00
|
|
|
SCH_BUS_ENTRY* BusEntry = new SCH_BUS_ENTRY( GetScreen()->GetCrossHairPosition(), s_LastShape,
|
|
|
|
entry_type );
|
2007-08-20 01:20:48 +00:00
|
|
|
BusEntry->m_Flags = IS_NEW;
|
2011-03-03 19:08:13 +00:00
|
|
|
BusEntry->Place( this, DC );
|
2010-12-08 20:12:46 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
return BusEntry;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::StartMoveBusEntry( SCH_BUS_ENTRY* BusEntry, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
if( BusEntry == NULL )
|
|
|
|
return;
|
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
if( !BusEntry->IsNew() ) // not already in edit, save shape
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
delete g_ItemToUndoCopy;
|
2010-12-21 15:13:09 +00:00
|
|
|
g_ItemToUndoCopy = BusEntry->Clone();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BusEntry->m_Flags |= IS_MOVED;
|
|
|
|
|
|
|
|
ItemInitialPosition = BusEntry->m_Pos;
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOff( DC );
|
|
|
|
GetScreen()->SetCrossHairPosition( BusEntry->m_Pos );
|
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
GetScreen()->SetCurItem( BusEntry );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback = ShowWhileMoving;
|
|
|
|
DrawPanel->m_endMouseCaptureCallback = ExitBusEntry;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOn( DC );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* set the shape of BusEntry (shape = / or \ )
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY* BusEntry, int entry_shape )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
if( BusEntry == NULL )
|
|
|
|
return;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( BusEntry->Type() != SCH_BUS_ENTRY_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "SetBusEntryType: Bad StructType" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put old item in undo list if it is not currently in edit */
|
|
|
|
if( BusEntry->m_Flags == 0 )
|
2009-07-26 17:16:42 +00:00
|
|
|
SaveCopyInUndoList( BusEntry, UR_CHANGED );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-10 16:50:40 +00:00
|
|
|
BusEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
switch( entry_shape )
|
|
|
|
{
|
|
|
|
case '\\':
|
|
|
|
s_LastShape = '\\';
|
|
|
|
BusEntry->m_Size.y = 100;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '/':
|
|
|
|
s_LastShape = '/';
|
|
|
|
BusEntry->m_Size.y = -100;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds();
|
2011-01-10 16:50:40 +00:00
|
|
|
BusEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
int SCH_EDIT_FRAME::GetBusEntryShape( SCH_BUS_ENTRY* BusEntry )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int entry_shape = '\\';
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( BusEntry->m_Size.y < 0 )
|
|
|
|
entry_shape = '/';
|
|
|
|
return entry_shape;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|