kicad/eeschema/busentry.cpp

156 lines
3.9 KiB
C++
Raw Normal View History

/*****************************************************/
/* 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"
#include "class_drawpanel.h"
#include "eeschema_id.h"
#include "confirm.h"
#include "class_sch_screen.h"
#include "wxEeschemaStruct.h"
2007-05-06 16:03:28 +00:00
#include "general.h"
#include "protos.h"
#include "sch_bus_entry.h"
2007-05-06 16:03:28 +00:00
static int s_LastShape = '\\';
2007-05-06 16:03:28 +00:00
static wxPoint ItemInitialPosition;
static void ExitBusEntry( EDA_DRAW_PANEL* Panel, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
/* Exit bus entry mode. */
SCH_BUS_ENTRY* BusEntry = (SCH_BUS_ENTRY*) Panel->GetScreen()->GetCurItem();
if( BusEntry )
{
BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), g_XorMode );
if( BusEntry->m_Flags & IS_NEW )
{
delete BusEntry;
Panel->GetScreen()->SetCurItem( NULL );
}
else
{
BusEntry->m_Pos = ItemInitialPosition;
BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
BusEntry->m_Flags = 0;
}
}
SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) Panel->GetParent();
parent->SetRepeatItem( NULL );
Panel->ManageCurseur = NULL;
Panel->ForceCloseManageCurseur = NULL;
2007-05-06 16:03:28 +00:00
}
static void ShowWhileMoving( EDA_DRAW_PANEL* panel, wxDC* DC, bool erase )
2007-05-06 16:03:28 +00:00
{
// Draws the bus entry while moving the cursor
BASE_SCREEN* screen = panel->GetScreen();
SCH_BUS_ENTRY* BusEntry = (SCH_BUS_ENTRY*) screen->GetCurItem();
if( BusEntry == NULL )
return;
/* Erase the last segment position. */
if( erase )
BusEntry->Draw( panel, DC, wxPoint( 0, 0 ), g_XorMode );
/* Redraw at the new position. */
BusEntry->m_Pos = screen->m_Curseur;
BusEntry->Draw( panel, DC, wxPoint( 0, 0 ), g_XorMode );
2007-05-06 16:03:28 +00:00
}
SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* DC, int entry_type )
{
// Create and place a new bus entry at cursor position
SCH_BUS_ENTRY* BusEntry = new SCH_BUS_ENTRY( GetScreen()->m_Curseur, s_LastShape, entry_type );
BusEntry->m_Flags = IS_NEW;
BusEntry->Place( this, DC );;
OnModify();
return BusEntry;
2007-05-06 16:03:28 +00:00
}
void SCH_EDIT_FRAME::StartMoveBusEntry( SCH_BUS_ENTRY* BusEntry, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( BusEntry == NULL )
return;
if( (BusEntry->m_Flags & IS_NEW) == 0 ) // not already in edit, save shape
{
delete g_ItemToUndoCopy;
g_ItemToUndoCopy = BusEntry->Clone();
}
BusEntry->m_Flags |= IS_MOVED;
ItemInitialPosition = BusEntry->m_Pos;
DrawPanel->CursorOff( DC );
GetScreen()->m_Curseur = BusEntry->m_Pos;
DrawPanel->MouseToCursorSchema();
GetScreen()->SetCurItem( BusEntry );
DrawPanel->ManageCurseur = ShowWhileMoving;
DrawPanel->ForceCloseManageCurseur = ExitBusEntry;
DrawPanel->CursorOn( DC );
2007-05-06 16:03:28 +00:00
}
/* set the shape of BusEntry (shape = / or \ )
*/
void SCH_EDIT_FRAME::SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY* BusEntry, int entry_shape )
{
if( BusEntry == NULL )
return;
if( BusEntry->Type() != SCH_BUS_ENTRY_T )
{
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 )
SaveCopyInUndoList( BusEntry, UR_CHANGED );
BusEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
switch( entry_shape )
{
case '\\':
s_LastShape = '\\';
BusEntry->m_Size.y = 100;
break;
case '/':
s_LastShape = '/';
BusEntry->m_Size.y = -100;
break;
}
GetScreen()->TestDanglingEnds();
BusEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
OnModify( );
2007-05-06 16:03:28 +00:00
}
int SCH_EDIT_FRAME::GetBusEntryShape( SCH_BUS_ENTRY* BusEntry )
2007-05-06 16:03:28 +00:00
{
int entry_shape = '\\';
2007-05-06 16:03:28 +00:00
if( BusEntry->m_Size.y < 0 )
entry_shape = '/';
return entry_shape;
2007-05-06 16:03:28 +00:00
}