kicad/common/drawpanel.cpp

1380 lines
41 KiB
C++
Raw Normal View History

/******************************************/
/* drawpanel.cpp - WinEDA_DrawPanel class */
/******************************************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "appl_wxstruct.h"
#include "gr_basic.h"
2007-05-06 16:03:28 +00:00
#include "common.h"
#include "macros.h"
#include "id.h"
#include "class_drawpanel.h"
#include "class_base_screen.h"
#include "wxstruct.h"
2007-05-06 16:03:28 +00:00
// Local defines
#define CURSOR_SIZE 12 // Cursor size in pixels
2007-05-06 16:03:28 +00:00
// Local variables
/* Used to inhibit a response to a mouse left button release, after a double click
* (when releasing the left button at the end of the second click
* Used in eeschema to inhibit a mouse left release command when switching between
* hierarchical sheets on a double click
*/
static bool s_IgnoreNextLeftButtonRelease = false;
// Events used by WinEDA_DrawPanel
BEGIN_EVENT_TABLE( WinEDA_DrawPanel, wxScrolledWindow )
EVT_LEAVE_WINDOW( WinEDA_DrawPanel::OnMouseLeaving )
EVT_MOUSEWHEEL( WinEDA_DrawPanel::OnMouseWheel )
EVT_MOUSE_EVENTS( WinEDA_DrawPanel::OnMouseEvent )
EVT_CHAR( WinEDA_DrawPanel::OnKeyEvent )
EVT_CHAR_HOOK( WinEDA_DrawPanel::OnKeyEvent )
EVT_PAINT( WinEDA_DrawPanel::OnPaint )
EVT_SIZE( WinEDA_DrawPanel::OnSize )
EVT_ERASE_BACKGROUND( WinEDA_DrawPanel::OnEraseBackground )
EVT_SCROLLWIN( WinEDA_DrawPanel::OnScroll )
EVT_ACTIVATE( WinEDA_DrawPanel::OnActivate )
EVT_MENU_RANGE( ID_POPUP_GRID_LEVEL_1000, ID_POPUP_GRID_USER,
WinEDA_DrawPanel::OnPopupGridSelect )
EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, WinEDA_DrawPanel::OnPan )
2007-05-06 16:03:28 +00:00
END_EVENT_TABLE()
/************************************************************************/
/* WinEDA_DrawPanel basic functions (WinEDA_DrawPanel is the main panel)*/
/************************************************************************/
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
WinEDA_DrawPanel::WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id,
const wxPoint& pos, const wxSize& size ) :
wxScrolledWindow( parent, id, pos, size,
wxBORDER | wxNO_FULL_REPAINT_ON_RESIZE )
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
m_Parent = parent;
m_ScrollButt_unit = 40;
2007-08-22 05:11:01 +00:00
SetBackgroundColour( wxColour( ColorRefs[g_DrawBgColor].m_Red,
ColorRefs[g_DrawBgColor].m_Green,
ColorRefs[g_DrawBgColor].m_Blue ) );
2007-08-22 05:11:01 +00:00
EnableScrolling( TRUE, TRUE );
m_ClipBox.SetSize( size );
m_ClipBox.SetX( 0 );
m_ClipBox.SetY( 0 );
m_CanStartBlock = -1; // Command block can start if >= 0
m_AbortEnable = m_AbortRequest = FALSE;
m_AutoPAN_Enable = TRUE;
2007-09-15 04:25:54 +00:00
m_IgnoreMouseEvents = 0;
2007-08-22 05:11:01 +00:00
ManageCurseur = NULL;
ForceCloseManageCurseur = NULL;
if( wxGetApp().m_EDA_Config )
wxGetApp().m_EDA_Config->Read( wxT( "AutoPAN" ), &m_AutoPAN_Enable,
true );
2007-08-22 05:11:01 +00:00
m_AutoPAN_Request = FALSE;
m_Block_Enable = FALSE;
m_PanelDefaultCursor = m_PanelCursor = wxCURSOR_ARROW;
m_CursorLevel = 0;
m_PrintIsMirrored = false;
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
WinEDA_DrawPanel::~WinEDA_DrawPanel()
{
wxASSERT( wxGetApp().m_EDA_Config != NULL );
wxGetApp().m_EDA_Config->Write( wxT( "AutoPAN" ), m_AutoPAN_Enable );
}
BASE_SCREEN* WinEDA_DrawPanel::GetScreen()
{
WinEDA_DrawFrame* parentFrame = m_Parent;
wxASSERT( parentFrame );
return parentFrame->GetBaseScreen();
}
/*****************************************************************************
*
* Draw the schematic cursor which is usually on grid
*
*****************************************************************************/
void WinEDA_DrawPanel::Trace_Curseur( wxDC* DC, int color )
2007-05-06 16:03:28 +00:00
{
if( m_CursorLevel != 0 || DC == NULL )
2007-08-22 05:11:01 +00:00
return;
wxPoint Cursor = GetScreen()->m_Curseur;
2007-08-22 05:11:01 +00:00
GRSetDrawMode( DC, GR_XOR );
if( m_Parent->m_CursorShape == 1 ) /* Trace d'un reticule */
2007-08-22 05:11:01 +00:00
{
int dx = GetScreen()->Unscale( m_ClipBox.GetWidth() );
int dy = GetScreen()->Unscale( m_ClipBox.GetHeight() );
2007-08-22 05:11:01 +00:00
GRLine( &m_ClipBox, DC, Cursor.x - dx, Cursor.y,
Cursor.x + dx, Cursor.y, 0, color ); // axe Y
2007-08-22 05:11:01 +00:00
GRLine( &m_ClipBox, DC, Cursor.x, Cursor.y - dx,
Cursor.x, Cursor.y + dy, 0, color ); // axe X
2007-08-22 05:11:01 +00:00
}
else
{
int len = GetScreen()->Unscale( CURSOR_SIZE );
2007-08-22 05:11:01 +00:00
GRLine( &m_ClipBox, DC, Cursor.x - len, Cursor.y,
Cursor.x + len, Cursor.y, 0, color );
2007-08-22 05:11:01 +00:00
GRLine( &m_ClipBox, DC, Cursor.x, Cursor.y - len,
Cursor.x, Cursor.y + len, 0, color );
2007-08-22 05:11:01 +00:00
}
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/*******************************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::CursorOff( wxDC* DC )
2007-05-06 16:03:28 +00:00
/*******************************************************************/
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
/*
2007-08-22 05:11:01 +00:00
* Remove the grid cursor from the display in preparation for other drawing operations
*/
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
Trace_Curseur( DC );
--m_CursorLevel;
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/*******************************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::CursorOn( wxDC* DC )
2007-05-06 16:03:28 +00:00
/*******************************************************************/
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
/*
2007-08-22 05:11:01 +00:00
* Display the grid cursor
*/
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
++m_CursorLevel;
Trace_Curseur( DC );
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
if( m_CursorLevel > 0 ) // Shouldn't happen, but just in case ..
m_CursorLevel = 0;
2007-05-06 16:03:28 +00:00
}
/***********************************/
2007-09-01 12:00:30 +00:00
int WinEDA_DrawPanel::GetZoom()
2007-05-06 16:03:28 +00:00
/***********************************/
{
2007-08-22 05:11:01 +00:00
return GetScreen()->GetZoom();
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/***************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::SetZoom( int zoom )
2007-05-06 16:03:28 +00:00
/***************************************/
{
2007-08-22 05:11:01 +00:00
GetScreen()->SetZoom( zoom );
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/************************************/
wxRealPoint WinEDA_DrawPanel::GetGrid()
2007-05-06 16:03:28 +00:00
/************************************/
{
2007-08-22 05:11:01 +00:00
return GetScreen()->GetGrid();
2007-05-06 16:03:28 +00:00
}
/******************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::PrepareGraphicContext( wxDC* DC )
2007-05-06 16:03:28 +00:00
/******************************************************/
{
2007-08-22 05:11:01 +00:00
GRResetPenAndBrush( DC );
DC->SetBackgroundMode( wxTRANSPARENT );
2007-05-06 16:03:28 +00:00
#ifdef WX_ZOOM
double scale = GetScreen()->GetScalingFactor();
DC->SetUserScale( scale, scale );
wxPoint origin = GetScreen()->m_DrawOrg;
DC->SetLogicalOrigin( origin.x, origin.y );
2007-05-06 16:03:28 +00:00
#endif
2007-08-22 05:11:01 +00:00
SetBoundaryBox();
2007-05-06 16:03:28 +00:00
}
/**********************************************************************/
2007-08-22 05:11:01 +00:00
wxPoint WinEDA_DrawPanel::CursorRealPosition( const wxPoint& ScreenPos )
2007-05-06 16:03:28 +00:00
/**********************************************************************/
2007-08-22 05:11:01 +00:00
/** CursorRealPosition (used to calculate the cursor position in internal units)
* @return position (in internal units)
* @param ScreenPos = absolute position in pixels
2007-08-22 05:11:01 +00:00
*/
2007-05-06 16:03:28 +00:00
{
#ifdef WX_ZOOM
wxCoord x, y;
wxClientDC DC( this );
PrepareGraphicContext( &DC );
x = DC.DeviceToLogicalX( ScreenPos.x );
y = DC.DeviceToLogicalY( ScreenPos.y );
return wxPoint( x, y );
#else
return GetScreen()->CursorRealPosition( ScreenPos );
#endif
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/********************************************************/
2007-08-22 05:11:01 +00:00
bool WinEDA_DrawPanel::IsPointOnDisplay( wxPoint ref_pos )
2007-05-06 16:03:28 +00:00
/********************************************************/
2007-08-22 05:11:01 +00:00
/** Function IsPointOnDisplay
* @param ref_pos is the position to test in pixels, relative to the panel.
* @return TRUE if ref_pos is a point currently visible on screen
* FALSE if ref_pos is out of screen
2007-08-22 05:11:01 +00:00
*/
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
wxPoint pos;
EDA_Rect display_rect;
SetBoundaryBox();
display_rect = m_ClipBox;
// Reduction legere des dimension de l'ecran utile pour eviter cadrage
// en limite d'ecran
#define PIXEL_MARGIN 8
display_rect.Inflate( -PIXEL_MARGIN, -PIXEL_MARGIN );
// Conversion en coord physiques
pos = CalcUnscrolledPosition( display_rect.GetPosition() );
GetScreen()->Unscale( pos );
pos += GetScreen()->m_DrawOrg;
display_rect.m_Pos = pos;
GetScreen()->Unscale( display_rect.m_Size );
2007-08-22 05:11:01 +00:00
return display_rect.Inside( ref_pos );
2007-05-06 16:03:28 +00:00
}
2008-03-10 15:00:22 +00:00
void WinEDA_DrawPanel::PostDirtyRect( EDA_Rect aRect )
{
// D( printf( "1) PostDirtyRect( x=%d, y=%d, width=%d, height=%d)\n", aRect.m_Pos.x, aRect.m_Pos.y, aRect.m_Size.x, aRect.m_Size.y ); )
2008-05-17 19:08:23 +00:00
2008-03-10 15:00:22 +00:00
// Convert the rect coordinates and size to pixels (make a draw clip box):
ConvertPcbUnitsToPixelsUnits( &aRect );
2008-03-10 15:51:44 +00:00
// Ensure the rectangle is large enough after truncations.
// The pcb units have finer granularity than the pixels, so it can happen
// that the rectangle is not large enough for the erase portion.
2009-06-25 20:45:27 +00:00
aRect.m_Size.x += 4; // += 1 is not enough!
aRect.m_Size.y += 4;
2008-03-10 15:00:22 +00:00
// D( printf( "2) PostDirtyRect( x=%d, y=%d, width=%d, height=%d)\n", aRect.m_Pos.x, aRect.m_Pos.y, aRect.m_Size.x, aRect.m_Size.y ); )
2008-05-17 19:08:23 +00:00
2008-03-10 15:00:22 +00:00
// pass wxRect() via EDA_Rect::operator wxRect() overload
RefreshRect( aRect, TRUE );
}
/************************************************************************/
2008-03-10 13:33:12 +00:00
void WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( EDA_Rect* aRect )
/************************************************************************/
{
// Calculate the draw area origin in internal units:
2008-03-10 13:33:12 +00:00
wxPoint pos = aRect->GetPosition();
ConvertPcbUnitsToPixelsUnits( &pos );
aRect->SetOrigin( pos ); // rect origin in pixel units
GetScreen()->Scale( aRect->m_Size );
}
/***************************************************************************/
2008-03-10 13:33:12 +00:00
void WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( wxPoint* aPosition )
/***************************************************************************/
{
// Calculate the draw area origin in internal units:
wxPoint drwOrig;
int x_axis_scale, y_axis_scale;
2008-03-10 13:33:12 +00:00
// Origin in scroll units;
GetViewStart( &drwOrig.x, &drwOrig.y );
GetScrollPixelsPerUnit( &x_axis_scale, &y_axis_scale );
2008-03-10 13:33:12 +00:00
// Origin in pixels units
drwOrig.x *= x_axis_scale;
drwOrig.y *= y_axis_scale;
// Origin in internal units
GetScreen()->Unscale( drwOrig );
2008-03-10 13:33:12 +00:00
// Real origin, according to the "plot" origin
drwOrig += GetScreen()->m_DrawOrg;
2008-03-10 13:33:12 +00:00
// position in internal units, relative to the visible draw area origin
*aPosition -= drwOrig;
2008-03-10 13:33:12 +00:00
// position in pixels, relative to the visible draw area origin
GetScreen()->Scale( *aPosition );
}
/** Function CursorScreenPosition
* @return the cursor current position in pixels in the screen draw area
2007-08-22 05:11:01 +00:00
*/
wxPoint WinEDA_DrawPanel::CursorScreenPosition()
2007-05-06 16:03:28 +00:00
{
#ifdef WX_ZOOM
wxCoord x, y;
wxClientDC DC( this );
PrepareGraphicContext( &DC );
x = DC.LogicalToDeviceX( GetScreen()->m_Curseur.x );
y = DC.LogicalToDeviceY( GetScreen()->m_Curseur.y );
return wxPoint( x, y );
#else
wxPoint pos = GetScreen()->m_Curseur - GetScreen()->m_DrawOrg;
GetScreen()->Scale( pos );
return pos;
#endif
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/*********************************************************/
wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition( void )
2007-05-06 16:03:28 +00:00
/*********************************************************/
/** Function GetScreenCenterRealPosition()
* @return position (in internal units) of the current area centre showed on screen
*/
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
wxSize size;
wxPoint realpos;
2007-05-06 16:03:28 +00:00
size = GetClientSize() / 2;
realpos = CalcUnscrolledPosition( wxPoint( size.x, size.y ) );
GetScreen()->Unscale( realpos );
#ifdef WX_ZOOM
// wxCoord x, y;
// wxClientDC DC( this );
// PrepareGraphicContext( &DC );
// realpos.x = DC.DeviceToLogicalX( realpos.x );
// realpos.y = DC.DeviceToLogicalY( realpos.y );
#else
realpos += GetScreen()->m_DrawOrg;
#endif
2007-08-22 05:11:01 +00:00
return realpos;
2007-05-06 16:03:28 +00:00
}
/**********************************************/
2007-09-01 12:00:30 +00:00
void WinEDA_DrawPanel::MouseToCursorSchema()
2007-05-06 16:03:28 +00:00
/**********************************************/
2007-08-22 05:11:01 +00:00
/* Move the mouse cursor to the current schematic cursor
2007-08-22 05:11:01 +00:00
*/
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
wxPoint Mouse = CursorScreenPosition();
MouseTo( Mouse );
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/****************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::MouseTo( const wxPoint& Mouse )
2007-05-06 16:03:28 +00:00
/****************************************************/
2007-08-22 05:11:01 +00:00
/** Move the mouse cursor to the position "Mouse"
* @param Mouse = mouse cursor position, in pixels units
2007-08-22 05:11:01 +00:00
*/
2007-05-06 16:03:28 +00:00
{
int x, y, xPpu, yPpu;
wxPoint screenPos, drawingPos;
wxRect clientRect( wxPoint( 0, 0 ), GetClientSize() );
2007-05-06 16:03:28 +00:00
#ifdef WX_ZOOM
CalcScrolledPosition( Mouse.x, Mouse.y, &screenPos.x, &screenPos.y );
2007-05-06 16:03:28 +00:00
#else
screenPos = Mouse - GetScreen()->m_StartVisu;
2007-05-06 16:03:28 +00:00
#endif
/* Scroll if the requested mouse position cursor is outside the drawing
* area. */
if( !clientRect.Contains( screenPos ) )
{
GetViewStart( &x, &y );
GetScrollPixelsPerUnit( &xPpu, &yPpu );
CalcUnscrolledPosition( screenPos.x, screenPos.y,
&drawingPos.x, &drawingPos.y );
wxLogDebug( wxT( "MouseTo() initial screen position(%d, %d) " ) \
wxT( "rectangle(%d, %d, %d, %d) view(%d, %d)" ),
screenPos.x, screenPos.y, clientRect.x, clientRect.y,
clientRect.width, clientRect.height, x, y );
if( screenPos.y < clientRect.GetTop() )
y -= m_ScrollButt_unit * yPpu;
else if( screenPos.y > clientRect.GetBottom() )
y += m_ScrollButt_unit * yPpu;
else if( clientRect.GetRight() < screenPos.x )
x += m_ScrollButt_unit * xPpu;
else
x -= m_ScrollButt_unit * xPpu;
Scroll( x, y );
CalcScrolledPosition( drawingPos.x, drawingPos.y,
&screenPos.x, &screenPos.y );
wxLogDebug( wxT( "MouseTo() scrolled screen position(%d, %d) " ) \
wxT( "view(%d, %d)" ), screenPos.x, screenPos.y, x, y );
}
WarpPointer( screenPos.x, screenPos.y );
2007-05-06 16:03:28 +00:00
}
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
/********************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::OnActivate( wxActivateEvent& event )
2007-05-06 16:03:28 +00:00
/********************************************************/
/**
* Called on window activation.
* init the member m_CanStartBlock to avoid a block start command
* on activation (because a left mouse button can be pressed and no block command wanted
* This happens when enter on a hierarchycat sheet on double click
*/
2007-05-06 16:03:28 +00:00
{
m_CanStartBlock = -1; // Block Command can't start
2007-08-22 05:11:01 +00:00
event.Skip();
2007-05-06 16:03:28 +00:00
}
/***********************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::OnEraseBackground( wxEraseEvent& event )
2007-05-06 16:03:28 +00:00
/***********************************************************/
{
2007-08-22 05:11:01 +00:00
event.Skip();
2007-05-06 16:03:28 +00:00
}
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
/*********************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::OnScroll( wxScrollWinEvent& event )
2007-05-06 16:03:28 +00:00
/*********************************************************/
{
2007-08-22 05:11:01 +00:00
int id = event.GetEventType();
int dir, value = 0;
int x, y;
GetViewStart( &x, &y );
dir = event.GetOrientation(); // wxHORIZONTAL or wxVERTICAL
2007-08-22 05:11:01 +00:00
if( id == wxEVT_SCROLLWIN_LINEUP )
value = -m_ScrollButt_unit;
else if( id == wxEVT_SCROLLWIN_LINEDOWN )
value = m_ScrollButt_unit;
else if( id == wxEVT_SCROLLWIN_THUMBTRACK )
{
value = event.GetPosition();
if( dir == wxHORIZONTAL )
Scroll( value, -1 );
else
Scroll( -1, value );
return;
}
else
{
event.Skip();
return;
}
if( dir == wxHORIZONTAL )
{
Scroll( x + value, -1 );
}
else
{
Scroll( -1, y + value );
}
event.Skip();
2007-05-06 16:03:28 +00:00
}
/*************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::OnSize( wxSizeEvent& event )
2007-05-06 16:03:28 +00:00
/*************************************************/
{
2007-08-22 05:11:01 +00:00
SetBoundaryBox();
event.Skip();
2007-05-06 16:03:28 +00:00
}
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
/******************************************/
2007-09-01 12:00:30 +00:00
void WinEDA_DrawPanel::SetBoundaryBox()
2007-05-06 16:03:28 +00:00
/******************************************/
/** Function SetBoundaryBox()
* set the m_ClipBox member to the current displayed rectangle dimensions
*/
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
BASE_SCREEN* Screen = GetScreen();;
if( !Screen )
return;
wxPoint org;
int ii, jj;
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
GetViewStart( &org.x, &org.y );
GetScrollPixelsPerUnit( &ii, &jj );
2008-03-06 01:46:30 +00:00
org.x *= ii;
org.y *= jj;
2007-08-22 05:11:01 +00:00
Screen->m_StartVisu = org;
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
m_ClipBox.SetOrigin( org );
m_ClipBox.SetSize( GetClientSize() );
2007-05-06 16:03:28 +00:00
#ifdef WX_ZOOM
CalcUnscrolledPosition( m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y,
&m_ClipBox.m_Pos.x, &m_ClipBox.m_Pos.y );
2007-05-06 16:03:28 +00:00
#else
m_ClipBox.m_Pos -= GetScreen()->m_StartVisu;
2007-05-06 16:03:28 +00:00
#endif
2007-08-22 05:11:01 +00:00
m_ScrollButt_unit = MIN( Screen->m_SizeVisu.x, Screen->m_SizeVisu.y ) / 4;
if( m_ScrollButt_unit < 2 )
m_ScrollButt_unit = 2;
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
Screen->m_ScrollbarPos.x = GetScrollPos( wxHORIZONTAL );
Screen->m_ScrollbarPos.y = GetScrollPos( wxVERTICAL );
2007-05-06 16:03:28 +00:00
}
/*********************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::EraseScreen( wxDC* DC )
2007-05-06 16:03:28 +00:00
/*********************************************/
{
2007-08-22 05:11:01 +00:00
GRSetDrawMode( DC, GR_COPY );
2008-03-10 15:51:44 +00:00
#ifndef WX_ZOOM
GRSFilledRect( &m_ClipBox, DC, m_ClipBox.GetX(), m_ClipBox.GetY(),
m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
g_DrawBgColor, g_DrawBgColor );
#else
EDA_Rect tmp = m_ClipBox;
m_ClipBox.m_Pos.x = DC->DeviceToLogicalX( m_ClipBox.m_Pos.x );
m_ClipBox.m_Pos.y = DC->DeviceToLogicalY( m_ClipBox.m_Pos.y );
m_ClipBox.m_Size.SetWidth( DC->DeviceToLogicalXRel( m_ClipBox.m_Size.GetWidth() ) );
m_ClipBox.m_Size.SetHeight( DC->DeviceToLogicalYRel( m_ClipBox.m_Size.GetHeight() ) );
2007-08-22 05:11:01 +00:00
GRSFilledRect( &m_ClipBox, DC, m_ClipBox.GetX(), m_ClipBox.GetY(),
m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
g_DrawBgColor, g_DrawBgColor );
m_ClipBox = tmp;
#endif
2007-05-06 16:03:28 +00:00
}
2007-08-22 05:11:01 +00:00
#if wxUSE_GRAPHICS_CONTEXT
// note: wxUSE_GRAPHICS_CONTEXT must be set to 1 in wxWidgets
// see setup.h in wx Widgets.
// wxWidgets configure can need option --enable-graphics_ctx
// Currently, **only for tests**
//#define USE_GCDC_IN_KICAD // uncomment it to use wxGCDC
#endif
2007-05-06 16:03:28 +00:00
/***************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
2007-05-06 16:03:28 +00:00
/***************************************************/
2008-03-06 01:46:30 +00:00
{
if( GetScreen() == NULL )
{
event.Skip();
return;
}
#ifdef USE_GCDC_IN_KICAD
2009-01-29 17:25:10 +00:00
wxPaintDC pDC( this );
wxGCDC paintDC(pDC); // Following line should be disabled on MSW and OS X
paintDC.GetGraphicsContext()->Translate(0.5, 0.5); // Fix for pixel offset bug http://trac.wxwidgets.org/ticket/4187
#else
2008-03-06 01:46:30 +00:00
wxPaintDC paintDC( this );
#endif
2008-03-06 01:46:30 +00:00
EDA_Rect tmp;
wxRect PaintClipBox;
wxPoint org;
PrepareGraphicContext( &paintDC );
tmp = m_ClipBox;
org = m_ClipBox.GetOrigin();
wxRegion upd = GetUpdateRegion(); // get the update rect list
2008-03-06 01:46:30 +00:00
2008-03-10 13:33:12 +00:00
// get the union of all rectangles in the update region, 'upd'
2008-03-06 01:46:30 +00:00
PaintClipBox = upd.GetBox();
2008-03-10 13:33:12 +00:00
#if 0 && defined (DEBUG)
2008-05-17 19:08:23 +00:00
printf( "1) PaintClipBox=(%d, %d, %d, %d) org=(%d, %d) m_ClipBox=(%d, %d, %d, %d)\n",
PaintClipBox.x,
PaintClipBox.y,
PaintClipBox.width,
PaintClipBox.height,
org.x, org.y,
m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y,
m_ClipBox.m_Size.x, m_ClipBox.m_Size.y
);
2008-03-06 01:46:30 +00:00
#endif
#ifdef WX_ZOOM
wxLogDebug( wxT( "1) PaintClipBox=(%d, %d, %d, %d) org=(%d, %d) " \
"m_ClipBox=(%d, %d, %d, %d)\n" ), PaintClipBox.x,
PaintClipBox.y, PaintClipBox.width, PaintClipBox.height,
org.x, org.y, m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y,
m_ClipBox.m_Size.x, m_ClipBox.m_Size.y );
wxSize drawing_size = GetScreen()->ReturnPageSize() * 2;
m_ClipBox.m_Pos.x = 0;
m_ClipBox.m_Pos.y = 0;
m_ClipBox.SetWidth( drawing_size.x );
m_ClipBox.SetHeight( drawing_size.y );
wxLogDebug( wxT( "2) PaintClipBox=(%d, %d, %d, %d) org=(%d, %d) " \
"m_ClipBox=(%d, %d, %d, %d)\n" ), PaintClipBox.x,
PaintClipBox.y, PaintClipBox.width, PaintClipBox.height,
org.x, org.y, m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y,
m_ClipBox.m_Size.x, m_ClipBox.m_Size.y );
2008-03-06 01:46:30 +00:00
#else
PaintClipBox.Offset( org );
2008-03-06 01:46:30 +00:00
m_ClipBox.SetX( PaintClipBox.GetX() );
m_ClipBox.SetY( PaintClipBox.GetY() );
m_ClipBox.SetWidth( PaintClipBox.GetWidth() );
m_ClipBox.SetHeight( PaintClipBox.GetHeight() );
#endif
// Be sure the drawpanel clipbox is bigger than the region to repair:
m_ClipBox.Inflate(1,1); // Give it one pixel more in each direction
2008-03-06 01:46:30 +00:00
#if 0 && defined (DEBUG)
2008-05-17 19:08:23 +00:00
printf( "2) PaintClipBox=(%d, %d, %d, %d) org=(%d, %d) m_ClipBox=(%d, %d, %d, %d)\n",
PaintClipBox.x,
PaintClipBox.y,
PaintClipBox.width,
PaintClipBox.height,
org.x, org.y,
m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y,
m_ClipBox.m_Size.x, m_ClipBox.m_Size.y
);
2008-03-06 01:46:30 +00:00
#endif
PaintClipBox = m_ClipBox;
2008-03-10 13:33:12 +00:00
// call ~wxDCClipper() before ~wxPaintDC()
{
#ifndef WX_ZOOM
2008-03-10 13:33:12 +00:00
wxDCClipper dcclip( paintDC, PaintClipBox );
#endif
ReDraw( &paintDC, true );
#ifdef WX_ZOOM
paintDC.SetUserScale( 1.0, 1.0 );
#endif
2008-03-10 13:33:12 +00:00
}
2008-03-06 01:46:30 +00:00
m_ClipBox = tmp;
event.Skip();
}
2007-05-06 16:03:28 +00:00
/****************************************************/
2007-08-15 02:43:57 +00:00
void WinEDA_DrawPanel::ReDraw( wxDC* DC, bool erasebg )
2007-05-06 16:03:28 +00:00
/****************************************************/
{
2007-08-22 05:11:01 +00:00
BASE_SCREEN* Screen = GetScreen();
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
if( Screen == NULL )
2007-08-15 02:43:57 +00:00
return;
2007-05-06 16:03:28 +00:00
if( ( g_DrawBgColor != WHITE ) && ( g_DrawBgColor != BLACK ) )
2007-08-15 02:43:57 +00:00
g_DrawBgColor = BLACK;
2007-08-22 05:11:01 +00:00
if( g_DrawBgColor == WHITE )
{
g_XorMode = GR_NXOR;
g_GhostColor = BLACK;
}
else
{
g_XorMode = GR_XOR;
g_GhostColor = WHITE;
}
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
if( erasebg )
EraseScreen( DC );
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
SetBackgroundColour( wxColour( ColorRefs[g_DrawBgColor].m_Red,
ColorRefs[g_DrawBgColor].m_Green,
ColorRefs[g_DrawBgColor].m_Blue ) );
2007-05-06 16:03:28 +00:00
2007-08-22 05:11:01 +00:00
GRResetPenAndBrush( DC );
DC->SetBackground( *wxBLACK_BRUSH );
DC->SetBackgroundMode( wxTRANSPARENT );
m_Parent->RedrawActiveWindow( DC, erasebg );
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/***********************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::DrawBackGround( wxDC* DC )
2007-05-06 16:03:28 +00:00
/***********************************************/
2007-08-22 05:11:01 +00:00
/** Function DrawBackGround
* @param DC = current Device Context
* Draws X , Y axis
* draws the grid
* - the grid is drawn only if the zoom level allows a good visibility
* - the grid is always centered on the screen centre
2007-08-22 05:11:01 +00:00
*/
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
int Color = BLUE;
BASE_SCREEN* screen = GetScreen();
int ii, jj, xg, yg, color;
wxRealPoint screen_grid_size;
2007-08-22 05:11:01 +00:00
bool drawgrid = FALSE;
wxSize size;
wxPoint org;
color = g_GridColor;
2007-08-22 05:11:01 +00:00
GRSetDrawMode( DC, GR_COPY );
/* The grid must be visible. this is possible only is grid value
* and zoom value are sufficient
*/
2007-08-22 05:11:01 +00:00
drawgrid = m_Parent->m_Draw_Grid;
screen_grid_size = screen->GetGrid();
wxRealPoint dgrid = screen_grid_size;
screen->Scale( dgrid ); // dgrid = grid size in pixels
// if the grid size is small ( < 5 pixels) do not display all points
if( dgrid.x < 5 )
2007-08-22 05:11:01 +00:00
{
screen_grid_size.x *= 2;
dgrid.x *= 2;
2007-08-22 05:11:01 +00:00
}
if( dgrid.x < 5 )
drawgrid = FALSE; // The grid is too small: do not show it
if( dgrid.y < 5 )
2007-08-22 05:11:01 +00:00
{
screen_grid_size.y *= 2;
dgrid.y *= 2;
2007-08-22 05:11:01 +00:00
}
if( dgrid.y < 5 )
drawgrid = FALSE; // The grid is too small
2007-08-22 05:11:01 +00:00
GetViewStart( &org.x, &org.y );
GetScrollPixelsPerUnit( &ii, &jj );
org.x *= ii;
2007-10-09 12:29:02 +00:00
org.y *= jj;
2007-08-22 05:11:01 +00:00
screen->m_StartVisu = org;
screen->Unscale( org );
org += screen->m_DrawOrg;
size = GetClientSize();
screen->Unscale( size );
#ifdef WX_ZOOM
screen_grid_size = screen->GetGrid();
if( DC->LogicalToDeviceXRel( (int) screen_grid_size.x ) < 5
|| DC->LogicalToDeviceYRel( (int) screen_grid_size.y ) < 5 )
drawgrid = false;
org.x = DC->DeviceToLogicalX( org.x );
org.y = DC->DeviceToLogicalY( org.y );
size.SetWidth( DC->DeviceToLogicalXRel( size.GetWidth() ) );
size.SetHeight( DC->DeviceToLogicalYRel( size.GetHeight() ) );
#endif
2007-08-22 05:11:01 +00:00
if( drawgrid )
{
m_Parent->PutOnGrid( &org );
GRSetColorPen( DC, color );
for( ii = 0; ; ii++ )
{
xg = wxRound(ii * screen_grid_size.x);
if( xg > size.x )
break;
2007-08-22 05:11:01 +00:00
int xpos = org.x + xg;
xpos = GRMapX( xpos );
2007-08-22 05:11:01 +00:00
for( jj = 0; ; jj++ )
{
yg = wxRound(jj * screen_grid_size.y);
2007-08-22 05:11:01 +00:00
if( yg > size.y )
break;
int ypos = org.y + yg;
DC->DrawPoint( xpos, GRMapY( ypos ) );
2007-08-22 05:11:01 +00:00
}
}
2007-08-22 05:11:01 +00:00
}
/* Draw axis */
if( m_Parent->m_Draw_Axis )
2007-08-22 05:11:01 +00:00
{
/* Draw the Y axis */
2007-08-22 05:11:01 +00:00
GRDashedLine( &m_ClipBox, DC, 0, -screen->ReturnPageSize().y,
0, screen->ReturnPageSize().y, 0, Color );
2007-08-22 05:11:01 +00:00
/* Draw the X axis */
2007-08-22 05:11:01 +00:00
GRDashedLine( &m_ClipBox, DC, -screen->ReturnPageSize().x, 0,
screen->ReturnPageSize().x, 0, 0, Color );
2007-08-22 05:11:01 +00:00
}
DrawAuxiliaryAxis( DC, GR_COPY );
2007-05-06 16:03:28 +00:00
}
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
/********************************************************************/
void WinEDA_DrawPanel::DrawAuxiliaryAxis( wxDC* DC, int drawmode )
2007-05-06 16:03:28 +00:00
/********************************************************************/
/** m_Draw_Auxiliary_Axis
* Draw the Auxiliary Axis, used in pcbnew which as origin coordinates
* for gerber and excellon files
*/
2007-05-06 16:03:28 +00:00
{
if( !m_Parent->m_Draw_Auxiliary_Axis
|| ( m_Parent->m_Auxiliary_Axis_Position.x == 0
&& m_Parent->m_Auxiliary_Axis_Position.y == 0 ) )
2007-08-22 05:11:01 +00:00
return;
int Color = DARKRED;
BASE_SCREEN* screen = GetScreen();
GRSetDrawMode( DC, drawmode );
/* Draw the Y axis */
2007-08-22 05:11:01 +00:00
GRDashedLine( &m_ClipBox, DC,
m_Parent->m_Auxiliary_Axis_Position.x,
-screen->ReturnPageSize().y,
m_Parent->m_Auxiliary_Axis_Position.x,
screen->ReturnPageSize().y,
0, Color );
2007-08-22 05:11:01 +00:00
/* Draw the X axis */
2007-08-22 05:11:01 +00:00
GRDashedLine( &m_ClipBox, DC,
-screen->ReturnPageSize().x,
m_Parent->m_Auxiliary_Axis_Position.y,
screen->ReturnPageSize().x,
m_Parent->m_Auxiliary_Axis_Position.y,
0, Color );
2007-05-06 16:03:28 +00:00
}
2007-08-15 02:43:57 +00:00
2007-05-06 16:03:28 +00:00
/*******************************************************/
bool WinEDA_DrawPanel::OnRightClick( wxMouseEvent& event )
2007-05-06 16:03:28 +00:00
/*******************************************************/
2007-08-22 05:11:01 +00:00
/** Build and display a Popup menu on a right mouse button click
* @return true if a popup menu is shown, or false
2007-08-22 05:11:01 +00:00
*/
2007-05-06 16:03:28 +00:00
{
2007-08-22 05:11:01 +00:00
wxPoint pos;
wxMenu MasterMenu;
pos = event.GetPosition();
if( !m_Parent->OnRightClick( pos, &MasterMenu ) )
return false;
2007-08-22 05:11:01 +00:00
AddMenuZoom( &MasterMenu );
2007-08-22 05:11:01 +00:00
m_IgnoreMouseEvents = TRUE;
PopupMenu( &MasterMenu, pos );
MouseToCursorSchema();
m_IgnoreMouseEvents = FALSE;
return true;
2007-05-06 16:03:28 +00:00
}
/******************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::OnMouseLeaving( wxMouseEvent& event )
2007-05-06 16:03:28 +00:00
/*******************************************************/
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
// Called when the canvas receives a mouse event leaving frame. //
{
2007-08-22 05:11:01 +00:00
if( ManageCurseur == NULL ) // Pas de commande encours
m_AutoPAN_Request = FALSE;
if( !m_AutoPAN_Enable || !m_AutoPAN_Request || m_IgnoreMouseEvents )
return;
// Auto pan if mouse is leave working area:
2007-08-22 05:11:01 +00:00
wxSize size = GetClientSize();
2009-01-07 15:59:49 +00:00
if( ( size.x < event.GetX() ) || ( size.y < event.GetY() )
|| ( event.GetX() <= 0) || ( event.GetY() <= 0 ) )
{
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_POPUP_ZOOM_CENTER );
cmd.SetEventObject( this );
GetEventHandler()->ProcessEvent( cmd );
}
2007-05-06 16:03:28 +00:00
}
/*
* Handle mouse wheel events.
*
* The mouse wheel is used to provide support for zooming and panning. This
* is accomplished by converting mouse wheel events in pseudo menu command
* events.
*/
void WinEDA_DrawPanel::OnMouseWheel( wxMouseEvent& event )
{
wxRect rect = wxRect( wxPoint( 0, 0), GetClientSize() );
2009-01-07 15:59:49 +00:00
/* Ignore scroll events if the cursor is outside the drawing area. */
if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled()
|| !rect.Contains( event.GetPosition() ) )
{
wxLogDebug( wxT( "OnMouseWheel() position(%d, %d) " ) \
wxT( "rectangle(%d, %d, %d, %d)" ),
event.GetPosition().x, event.GetPosition().y,
rect.x, rect.y, rect.width, rect.height );
event.Skip();
return;
}
GetScreen()->m_Curseur =
CursorRealPosition( CalcUnscrolledPosition( event.GetPosition() ) );
2009-01-07 15:59:49 +00:00
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetEventObject( this );
2009-01-07 15:59:49 +00:00
// This is a zoom in or out command
if( event.GetWheelRotation() > 0 )
{
if( event.ShiftDown() && !event.ControlDown() )
cmd.SetId( ID_PAN_UP );
else if( event.ControlDown() && !event.ShiftDown() )
cmd.SetId( ID_PAN_LEFT );
else
cmd.SetId( ID_POPUP_ZOOM_IN );
}
else if ( event.GetWheelRotation() < 0 )
{
if( event.ShiftDown() && !event.ControlDown() )
cmd.SetId( ID_PAN_DOWN );
else if( event.ControlDown() && !event.ShiftDown() )
cmd.SetId( ID_PAN_RIGHT );
else
cmd.SetId( ID_POPUP_ZOOM_OUT );
}
GetEventHandler()->ProcessEvent( cmd );
}
2007-05-06 16:03:28 +00:00
/******************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
2007-05-06 16:03:28 +00:00
/*******************************************************/
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
// Called when the canvas receives a mouse event. //
{
2007-08-22 05:11:01 +00:00
int localrealbutt = 0, localbutt = 0, localkey = 0;
BASE_SCREEN* screen = GetScreen();
static WinEDA_DrawPanel* LastPanel;
if( !screen )
return;
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5 /* Adjust value to filter mouse displacement before
* consider the drag mouse is really a drag command, not just a movement while click
*/
static int MinDragEventCount; /* counts the drag events.
* used to filter mouse moves before starting a block command
* a block command can be started only if MinDragEventCount > MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND
* in order to avoid spurious block commands
*/
2007-08-22 05:11:01 +00:00
if( event.Leaving() || event.Entering() )
{
m_CanStartBlock = -1;
}
if( ManageCurseur == NULL ) // No command in progress
2007-08-22 05:11:01 +00:00
m_AutoPAN_Request = FALSE;
if( m_Parent->m_FrameIsActive )
SetFocus();
else
return;
if( !event.IsButton() && !event.Moving()
&& !event.Dragging() && !localkey )
{
return;
}
if( event.RightDown() )
{
OnRightClick( event );
2007-09-11 04:11:48 +00:00
return;
2007-08-22 05:11:01 +00:00
}
if( m_IgnoreMouseEvents )
return;
if( event.LeftIsDown() )
localrealbutt |= GR_M_LEFT_DOWN;
2007-08-22 05:11:01 +00:00
if( event.MiddleIsDown() )
localrealbutt |= GR_M_MIDDLE_DOWN;
if( event.LeftDown() )
localbutt = GR_M_LEFT_DOWN;
if( event.ButtonDClick( 1 ) )
localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK;
2007-08-22 05:11:01 +00:00
if( event.MiddleDown() )
localbutt = GR_M_MIDDLE_DOWN;
2007-08-22 05:11:01 +00:00
if( event.ButtonDClick( 2 ) )
{
}
; // Unused
localrealbutt |= localbutt; /* compensation default wxGTK */
2007-08-22 05:11:01 +00:00
/* Compute absolute m_MousePosition in pixel units: */
screen->m_MousePositionInPixels = CalcUnscrolledPosition( event.GetPosition() );
2007-08-22 05:11:01 +00:00
/* Compute absolute m_MousePosition in user units: */
screen->m_MousePosition = CursorRealPosition( screen->m_MousePositionInPixels );
wxClientDC DC( this );
int kbstat = 0;
DC.SetBackground( *wxBLACK_BRUSH );
PrepareGraphicContext( &DC );
g_KeyPressed = localkey;
if( event.ShiftDown() )
kbstat |= GR_KB_SHIFT;
if( event.ControlDown() )
kbstat |= GR_KB_CTRL;
if( event.AltDown() )
kbstat |= GR_KB_ALT;
g_MouseOldButtons = localrealbutt;
// Calling Double Click and Click functions :
2007-08-22 05:11:01 +00:00
if( localbutt == (int) (GR_M_LEFT_DOWN | GR_M_DCLICK) )
{
2007-08-22 05:11:01 +00:00
m_Parent->OnLeftDClick( &DC, screen->m_MousePositionInPixels );
// inhibit a response to the mouse left button release,
// because we have a double click, and we do not want a new OnLeftClick command at end of this Double Click
s_IgnoreNextLeftButtonRelease = true;
}
2007-10-09 12:29:02 +00:00
else if( event.LeftUp() )
{
if( screen->m_BlockLocate.m_State==STATE_NO_BLOCK // A block command is in progress: a left up is the end of block
&& !s_IgnoreNextLeftButtonRelease ) // This is the end of a double click, already seen
m_Parent->OnLeftClick( &DC, screen->m_MousePositionInPixels );
s_IgnoreNextLeftButtonRelease = false;
}
if( !event.LeftIsDown() )
{
/* be sure there is a response to a left button release command
* even when a LeftUp event is not seen
* happens when a double click opens a dialog box, and the release mouse button is made when the dialog box is open
*/
s_IgnoreNextLeftButtonRelease = false;
2007-10-09 12:29:02 +00:00
}
2007-08-22 05:11:01 +00:00
if( event.ButtonUp( 2 ) && (screen->m_BlockLocate.m_State == STATE_NO_BLOCK) )
{
// The middle button has been released, with no block command:
2009-01-07 15:59:49 +00:00
// We use it for a zoom center at cursor position command
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED,
ID_POPUP_ZOOM_CENTER );
cmd.SetEventObject( this );
GetEventHandler()->ProcessEvent( cmd );
2007-08-22 05:11:01 +00:00
}
/* Calling the general function on mouse changes (and pseudo key commands) */
2007-08-22 05:11:01 +00:00
m_Parent->GeneralControle( &DC, screen->m_MousePositionInPixels );
/*******************************/
/* Control of block commands : */
/*******************************/
// Command block can't start if mouse is dragging a new panel
if( LastPanel != this )
{
MinDragEventCount = 0;
m_CanStartBlock = -1;
}
2007-08-22 05:11:01 +00:00
/* A new command block can start after a release buttons
* and if the drag is enough
* This is to avoid a false start block when a dialog box is demiss,
* or when changing panels in hierarchy navigation
* or when clicking while and moving mouse
*/
2007-08-22 05:11:01 +00:00
if( !event.LeftIsDown() && !event.MiddleIsDown() )
{
MinDragEventCount = 0;
m_CanStartBlock = 0;
/* remember the last cursor position when a drag mouse starts
* this is the last position ** before ** clicking a button
* this is useful to start a block command from the point where the mouse was clicked first
2008-03-06 01:46:30 +00:00
* (a filter creates a delay for the real block command start, and we must remember this point)
*/
m_CursorStartPos = screen->m_Curseur;
2007-08-22 05:11:01 +00:00
}
if( m_Block_Enable && !(localbutt & GR_M_DCLICK) )
{
if( (screen->m_BlockLocate.m_Command == BLOCK_IDLE)
|| (screen->m_BlockLocate.m_State == STATE_NO_BLOCK) )
2007-08-22 05:11:01 +00:00
{
screen->m_BlockLocate.SetOrigin( m_CursorStartPos );
2007-08-22 05:11:01 +00:00
}
if( event.LeftDown() || event.MiddleDown() )
{
if( screen->m_BlockLocate.m_State == STATE_BLOCK_MOVE )
2007-08-22 05:11:01 +00:00
{
m_AutoPAN_Request = FALSE;
m_Parent->HandleBlockPlace( &DC );
s_IgnoreNextLeftButtonRelease = true;
2007-08-22 05:11:01 +00:00
}
}
else if( (m_CanStartBlock >= 0 )
&& ( event.LeftIsDown() || event.MiddleIsDown() )
&& ManageCurseur == NULL
&& ForceCloseManageCurseur == NULL )
{ // Mouse is dragging: if no block in progress: start a block command
if( screen->m_BlockLocate.m_State == STATE_NO_BLOCK )
{ // Start a block command
2007-08-22 05:11:01 +00:00
int cmd_type = kbstat;
2007-08-22 05:11:01 +00:00
if( event.MiddleIsDown() )
cmd_type |= MOUSE_MIDDLE;
/* A block command is started if the drag is enough.
* A small drag is ignored (it is certainly a little mouse move when clicking)
* not really a drag mouse
*/
if( MinDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND )
MinDragEventCount++;
2007-08-22 05:11:01 +00:00
else
{
if( !m_Parent->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos ) )
{
// should not occurs: error
m_Parent->DisplayToolMsg(
wxT( "WinEDA_DrawPanel::OnMouseEvent() Block Error" ) );
}
else
{
m_AutoPAN_Request = TRUE;
SetCursor( m_PanelCursor = wxCURSOR_SIZING );
}
2007-08-22 05:11:01 +00:00
}
}
}
if( event.ButtonUp( 1 ) || event.ButtonUp( 2 ) )
{
/* Release the mouse button: end of block.
* The command can finish (DELETE) or have a next command (MOVE, COPY).
* However the block command is canceled if the block size is small
* Because a block command filtering is already made, this case happens,
* but only when the on grid cursor has not moved.
2007-08-22 05:11:01 +00:00
*/
2008-03-06 01:46:30 +00:00
#define BLOCK_MINSIZE_LIMIT 1
2007-08-22 05:11:01 +00:00
bool BlockIsSmall =
( ABS( screen->Scale( screen->m_BlockLocate.GetWidth() ) ) < BLOCK_MINSIZE_LIMIT)
&& ( ABS( screen->Scale( screen->m_BlockLocate.GetHeight() ) ) < BLOCK_MINSIZE_LIMIT);
2007-08-22 05:11:01 +00:00
if( (screen->m_BlockLocate.m_State != STATE_NO_BLOCK) && BlockIsSmall )
2007-08-22 05:11:01 +00:00
{
if( ForceCloseManageCurseur )
{
ForceCloseManageCurseur( this, &DC );
m_AutoPAN_Request = FALSE;
}
SetCursor( m_PanelCursor = m_PanelDefaultCursor );
}
else if( screen->m_BlockLocate.m_State == STATE_BLOCK_END )
2007-08-22 05:11:01 +00:00
{
m_AutoPAN_Request = FALSE;
m_Parent->HandleBlockEnd( &DC );
SetCursor( m_PanelCursor = m_PanelDefaultCursor );
if( screen->m_BlockLocate.m_State == STATE_BLOCK_MOVE )
2007-08-22 05:11:01 +00:00
{
m_AutoPAN_Request = TRUE;
SetCursor( m_PanelCursor = wxCURSOR_HAND );
}
}
}
}
// End of block command on a double click
// To avoid an unwanted block move command if the mouse is moved while double clicking
2007-08-22 05:11:01 +00:00
if( localbutt == (int) (GR_M_LEFT_DOWN | GR_M_DCLICK) )
{
if( screen->m_BlockLocate.m_Command != BLOCK_IDLE )
2007-08-22 05:11:01 +00:00
{
if( ForceCloseManageCurseur )
{
ForceCloseManageCurseur( this, &DC );
m_AutoPAN_Request = FALSE;
}
}
}
2007-05-06 16:03:28 +00:00
#if 0
2007-08-22 05:11:01 +00:00
wxString msg_debug;
msg_debug.Printf( " block state %d, cmd %d",
screen->m_BlockLocate.m_State, screen->m_BlockLocate.m_Command );
2007-08-22 05:11:01 +00:00
m_Parent->PrintMsg( msg_debug );
2007-05-06 16:03:28 +00:00
#endif
2007-08-22 05:11:01 +00:00
LastPanel = this;
2007-05-06 16:03:28 +00:00
}
2007-08-22 05:11:01 +00:00
2007-05-06 16:03:28 +00:00
/****************************************************/
2007-08-22 05:11:01 +00:00
void WinEDA_DrawPanel::OnKeyEvent( wxKeyEvent& event )
2007-05-06 16:03:28 +00:00
/****************************************************/
{
long key, localkey;
bool escape = FALSE;
wxPoint pos;
2007-08-22 05:11:01 +00:00
key = localkey = event.GetKeyCode();
switch( localkey )
{
case WXK_CONTROL:
case WXK_CAPITAL:
case WXK_SHIFT:
case WXK_NUMLOCK:
case WXK_LBUTTON:
case WXK_RBUTTON:
case WXK_ALT:
2007-08-22 05:11:01 +00:00
return;
case WXK_ESCAPE:
escape = m_AbortRequest = TRUE;
break;
}
if( event.ControlDown() )
localkey |= GR_KB_CTRL;
if( event.AltDown() )
localkey |= GR_KB_ALT;
if( event.ShiftDown() && (key > 256) )
localkey |= GR_KB_SHIFT;
wxClientDC DC( this );
2007-08-22 05:11:01 +00:00
BASE_SCREEN* Screen = GetScreen();
PrepareGraphicContext( &DC );
g_KeyPressed = localkey;
if( escape )
{
if( ManageCurseur && ForceCloseManageCurseur )
{
SetCursor( m_PanelCursor = m_PanelDefaultCursor );
ForceCloseManageCurseur( this, &DC );
SetCursor( m_PanelCursor = m_PanelDefaultCursor );
}
else
2007-08-15 02:43:57 +00:00
{
m_PanelCursor = m_PanelDefaultCursor = wxCURSOR_ARROW;
2007-08-22 05:11:01 +00:00
m_Parent->SetToolID( 0, m_PanelCursor, wxEmptyString );
2007-08-15 02:43:57 +00:00
}
2007-08-22 05:11:01 +00:00
}
2007-05-06 16:03:28 +00:00
/* Some key commands use the current mouse position: refresh it */
#ifdef WX_ZOOM
pos = CalcUnscrolledPosition( wxGetMousePosition() );
#else
pos = CalcUnscrolledPosition( wxGetMousePosition() - GetScreenPosition() );
#endif
/* Compute absolute mouse position in pixel units (i.e. considering the
current scroll) : */
Screen->m_MousePositionInPixels = pos;
/* Compute absolute mouse position in user units: */
Screen->m_MousePosition = CursorRealPosition( pos );
2007-12-06 16:58:12 +00:00
m_Parent->GeneralControle( &DC, pos );
2007-08-22 05:11:01 +00:00
#if 0
event.Skip(); // Allow menu shortcut processing
#endif
2007-05-06 16:03:28 +00:00
}
void WinEDA_DrawPanel::OnPan( wxCommandEvent& event )
{
int x, y;
GetViewStart( &x, &y ); // x and y are in scroll units, not in pixels
switch( event.GetId() )
{
case ID_PAN_UP:
y -= m_ScrollButt_unit;
break;
case ID_PAN_DOWN:
y += m_ScrollButt_unit;
break;
case ID_PAN_LEFT:
x -= m_ScrollButt_unit;
break;
case ID_PAN_RIGHT:
x += m_ScrollButt_unit;
break;
default:
wxLogDebug( wxT( "Unknown ID %d in WinEDA_DrawPanel::OnPan()." ),
event.GetId() );
}
Scroll( x, y );
MouseToCursorSchema();
}