kicad/cvpcb/displayframe.cpp

350 lines
9.3 KiB
C++
Raw Normal View History

/**********************/
/** displayframe.cpp **/
/**********************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "appl_wxstruct.h"
2007-05-06 16:03:28 +00:00
#include "common.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "macros.h"
2007-05-06 16:03:28 +00:00
#include "cvpcb.h"
#include "bitmaps.h"
#include "protos.h"
#include "cvstruct.h"
2007-05-06 16:03:28 +00:00
/*
* NOTE: There is something in 3d_viewer.h that causes a compiler error in
* <boost/foreach.hpp> in Linux so move it after cvpcb.h where it is
* included to prevent the error from occurring.
*/
#include "3d_viewer.h"
2007-05-06 16:03:28 +00:00
BEGIN_EVENT_TABLE( WinEDA_DisplayFrame, WinEDA_BasePcbFrame )
EVT_CLOSE( WinEDA_DisplayFrame::OnCloseWindow )
EVT_SIZE( WinEDA_DisplayFrame::OnSize )
2009-01-07 15:59:49 +00:00
EVT_TOOL_RANGE( ID_ZOOM_IN, ID_ZOOM_PAGE, WinEDA_DisplayFrame::OnZoom )
EVT_TOOL( ID_OPTIONS_SETUP, WinEDA_DisplayFrame::InstallOptionsDisplay )
EVT_TOOL( ID_CVPCB_SHOW3D_FRAME, WinEDA_DisplayFrame::Show3D_Frame )
END_EVENT_TABLE()
2007-05-06 16:03:28 +00:00
/***************************************************************************/
/* WinEDA_DisplayFrame: the frame to display the current focused footprint */
/***************************************************************************/
2007-05-06 16:03:28 +00:00
WinEDA_DisplayFrame::WinEDA_DisplayFrame( WinEDA_CvpcbFrame* father,
const wxString& title,
const wxPoint& pos,
const wxSize& size, long style ) :
WinEDA_BasePcbFrame( father, CVPCB_DISPLAY_FRAME, title, pos,
size, style )
{
m_FrameName = wxT( "CmpFrame" );
// Give an icon
#ifdef __WINDOWS__
SetIcon( wxICON( a_icon_cvpcb ) );
#else
SetIcon( wxICON( icon_cvpcb ) );
#endif
SetTitle( title );
2007-05-06 16:03:28 +00:00
SetBoard( new BOARD( NULL, this ) );
SetBaseScreen( new PCB_SCREEN() );
2007-05-06 16:03:28 +00:00
LoadSettings();
// Internalize grid id to a default value if not found in config or bad:
2009-10-15 11:35:53 +00:00
if( (m_LastGridSizeId <= 0) ||
(m_LastGridSizeId > (ID_POPUP_GRID_USER - ID_POPUP_GRID_LEVEL_1000)) )
2009-10-15 11:35:53 +00:00
m_LastGridSizeId = ID_POPUP_GRID_LEVEL_500 - ID_POPUP_GRID_LEVEL_1000;
GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
// Initialize some display options
DisplayOpt.DisplayPadIsol = false; // Pad clearance has no meaning here
DisplayOpt.ShowTrackClearanceMode = 0; /* tracks and vias clearance has
* no meaning here. */
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
ReCreateHToolbar();
ReCreateVToolbar();
#if defined(KICAD_AUIMANAGER)
m_auimgr.SetManagedWindow( this );
wxAuiPaneInfo horiz;
horiz.Gripper( false );
horiz.DockFixed( true );
horiz.Movable( false );
horiz.Floatable( false );
horiz.CloseButton( false );
horiz.CaptionVisible( false );
wxAuiPaneInfo vert( horiz );
vert.TopDockable( false ).BottomDockable( false );
horiz.LeftDockable( false ).RightDockable( false );
m_auimgr.AddPane( m_HToolBar,
wxAuiPaneInfo( horiz ).Name( wxT( "m_HToolBar" ) ).Top().
Row( 0 ) );
if( m_VToolBar ) // Currently, no vertical right toolbar.
m_auimgr.AddPane( m_VToolBar,
wxAuiPaneInfo( vert ).Name( wxT( "m_VToolBar" ) ).Right() );
m_auimgr.AddPane( DrawPanel,
wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() );
m_auimgr.AddPane( MsgPanel,
wxAuiPaneInfo( horiz ).Name( wxT( "MsgPanel" ) ).Bottom() );
m_auimgr.Update();
#endif
Show( TRUE );
2007-05-06 16:03:28 +00:00
}
WinEDA_DisplayFrame::~WinEDA_DisplayFrame()
2007-05-06 16:03:28 +00:00
{
delete GetBoard();
delete GetBaseScreen();
SetBaseScreen( 0 );
( (WinEDA_CvpcbFrame*) wxGetApp().GetTopWindow() )->DrawFrame = NULL;
2007-05-06 16:03:28 +00:00
}
/* Called when the frame is closed
* Save current settings (frame position and size
*/
void WinEDA_DisplayFrame::OnCloseWindow( wxCloseEvent& event )
2007-05-06 16:03:28 +00:00
{
wxPoint pos;
wxSize size;
2007-05-06 16:03:28 +00:00
size = GetSize();
pos = GetPosition();
2007-05-06 16:03:28 +00:00
SaveSettings();
Destroy();
2007-05-06 16:03:28 +00:00
}
void WinEDA_DisplayFrame::ReCreateVToolbar()
2007-05-06 16:03:28 +00:00
{
// Currently, no vertical right toolbar.
// So do nothing
2007-05-06 16:03:28 +00:00
}
void WinEDA_DisplayFrame::ReCreateHToolbar()
2007-05-06 16:03:28 +00:00
{
if( m_HToolBar != NULL )
return;
m_HToolBar = new WinEDA_Toolbar( TOOLBAR_MAIN, this, ID_H_TOOLBAR, TRUE );
2007-05-06 16:03:28 +00:00
2009-11-02 22:24:55 +00:00
SetToolBar( (wxToolBar*) m_HToolBar );
2007-05-06 16:03:28 +00:00
m_HToolBar->AddTool( ID_OPTIONS_SETUP, wxEmptyString,
wxBitmap( display_options_xpm ),
_( "Display Options" ) );
2007-05-06 16:03:28 +00:00
m_HToolBar->AddSeparator();
2007-05-06 16:03:28 +00:00
2009-01-07 15:59:49 +00:00
m_HToolBar->AddTool( ID_ZOOM_IN, wxEmptyString,
wxBitmap( zoom_in_xpm ),
2009-09-27 14:09:26 +00:00
_( "Zoom in (F1)" ) );
2007-05-06 16:03:28 +00:00
2009-01-07 15:59:49 +00:00
m_HToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString,
wxBitmap( zoom_out_xpm ),
2009-09-27 14:09:26 +00:00
_( "Zoom out (F2)" ) );
2007-05-06 16:03:28 +00:00
2009-01-07 15:59:49 +00:00
m_HToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString,
wxBitmap( zoom_redraw_xpm ),
2009-09-27 14:09:26 +00:00
_( "Redraw view (F3)" ) );
2007-05-06 16:03:28 +00:00
2009-01-07 15:59:49 +00:00
m_HToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString,
wxBitmap( zoom_auto_xpm ),
2009-09-27 14:09:26 +00:00
_( "Zoom auto (Home)" ) );
2007-05-06 16:03:28 +00:00
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( ID_CVPCB_SHOW3D_FRAME, wxEmptyString,
wxBitmap( show_3d_xpm ),
2009-09-27 14:09:26 +00:00
_( "3D Display" ) );
2007-05-06 16:03:28 +00:00
// after adding the buttons to the toolbar, must call Realize() to reflect
// the changes
m_HToolBar->Realize();
2007-05-06 16:03:28 +00:00
}
void WinEDA_DisplayFrame::SetToolbars()
2007-05-06 16:03:28 +00:00
{
}
void WinEDA_DisplayFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
2007-05-06 16:03:28 +00:00
{
}
void WinEDA_DisplayFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
2007-05-06 16:03:28 +00:00
{
}
bool WinEDA_DisplayFrame::OnRightClick( const wxPoint& MousePos,
wxMenu* PopMenu )
2007-05-06 16:03:28 +00:00
{
return true;
2007-05-06 16:03:28 +00:00
}
void WinEDA_DisplayFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
2007-05-06 16:03:28 +00:00
{
wxRealPoint delta;
int flagcurseur = 0;
wxPoint curpos, oldpos;
2009-01-07 15:59:49 +00:00
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetEventObject( this );
curpos = DrawPanel->CursorRealPosition( Mouse );
oldpos = GetScreen()->m_Curseur;
delta = GetScreen()->GetGridSize();
GetScreen()->Scale( delta );
if( delta.x <= 0 )
delta.x = 1;
if( delta.y <= 0 )
delta.y = 1;
switch( g_KeyPressed )
{
case WXK_F1:
cmd.SetId( ID_POPUP_ZOOM_IN );
GetEventHandler()->ProcessEvent( cmd );
flagcurseur = 2;
curpos = GetScreen()->m_Curseur;
break;
case WXK_F2:
cmd.SetId( ID_POPUP_ZOOM_OUT );
GetEventHandler()->ProcessEvent( cmd );
flagcurseur = 2;
curpos = GetScreen()->m_Curseur;
break;
case WXK_F3:
cmd.SetId( ID_ZOOM_REDRAW );
GetEventHandler()->ProcessEvent( cmd );
flagcurseur = 2;
break;
case WXK_F4:
cmd.SetId( ID_POPUP_ZOOM_CENTER );
GetEventHandler()->ProcessEvent( cmd );
flagcurseur = 2;
curpos = GetScreen()->m_Curseur;
break;
2009-09-27 14:09:26 +00:00
case WXK_HOME:
cmd.SetId( ID_ZOOM_PAGE );
GetEventHandler()->ProcessEvent( cmd );
flagcurseur = 2;
curpos = GetScreen()->m_Curseur;
break;
case ' ':
GetScreen()->m_O_Curseur = GetScreen()->m_Curseur;
break;
case WXK_NUMPAD8: /* cursor moved up */
case WXK_UP:
Mouse.y -= wxRound(delta.y);
DrawPanel->MouseTo( Mouse );
break;
case WXK_NUMPAD2: /* cursor moved down */
case WXK_DOWN:
Mouse.y += wxRound(delta.y);
DrawPanel->MouseTo( Mouse );
break;
case WXK_NUMPAD4: /* cursor moved left */
case WXK_LEFT:
Mouse.x -= wxRound(delta.x);
DrawPanel->MouseTo( Mouse );
break;
case WXK_NUMPAD6: /* cursor moved right */
case WXK_RIGHT:
Mouse.x += wxRound(delta.x);
DrawPanel->MouseTo( Mouse );
break;
}
GetScreen()->m_Curseur = curpos;
/* Put cursor on grid */
PutOnGrid( &GetScreen()->m_Curseur );
if( GetScreen()->IsRefreshReq() )
{
flagcurseur = 2;
RedrawActiveWindow( DC, TRUE );
}
if( oldpos != GetScreen()->m_Curseur )
{
if( flagcurseur != 2 )
{
curpos = GetScreen()->m_Curseur;
GetScreen()->m_Curseur = oldpos;
DrawPanel->CursorOff( DC );
GetScreen()->m_Curseur = curpos;
DrawPanel->CursorOn( DC );
}
if( DrawPanel->ManageCurseur )
{
DrawPanel->ManageCurseur( DrawPanel, DC, 0 );
}
}
UpdateStatusBar(); /* Display new cursor coordinates */
2007-05-06 16:03:28 +00:00
}
/**
* Display 3D frame of current footprint selection.
*/
void WinEDA_DisplayFrame::Show3D_Frame( wxCommandEvent& event )
{
if( m_Draw3DFrame )
{
DisplayInfoMessage( this, _( "3D Frame already opened" ) );
return;
}
m_Draw3DFrame = new WinEDA3D_DrawFrame( this, _( "3D Viewer" ),
KICAD_DEFAULT_3D_DRAWFRAME_STYLE |
wxFRAME_FLOAT_ON_PARENT );
m_Draw3DFrame->Show( TRUE );
}
/* Virtual function needed by the PCB_SCREEN class derived from BASE_SCREEN
* this is a virtual pure function in BASE_SCREEN
* do nothing in cvpcb
* could be removed later
*/
void PCB_SCREEN::ClearUndoORRedoList(UNDO_REDO_CONTAINER&, int )
{
}