2009-11-23 15:16:50 +00:00
|
|
|
/********************************************************/
|
|
|
|
/* base_screen.cpp - BASE_SCREEN object implementation. */
|
|
|
|
/********************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "base_struct.h"
|
|
|
|
#include "class_base_screen.h"
|
2009-02-07 14:13:16 +00:00
|
|
|
#include "id.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
#define CURSOR_SIZE 12 /* size of the cross cursor. */
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
BASE_SCREEN::BASE_SCREEN( KICAD_T aType ) : EDA_ITEM( aType )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
m_drawList = NULL; /* Draw items list */
|
2009-11-23 15:16:50 +00:00
|
|
|
m_UndoRedoCountMax = 10; /* undo/Redo command Max depth, 10 is a
|
|
|
|
* reasonable value */
|
2008-12-05 16:03:05 +00:00
|
|
|
m_FirstRedraw = TRUE;
|
|
|
|
m_ScreenNumber = 1;
|
|
|
|
m_NumberOfScreen = 1; /* Hierarchy: Root: ScreenNumber = 1 */
|
2011-07-05 12:46:14 +00:00
|
|
|
m_Zoom = 32.0;
|
2009-10-14 19:43:31 +00:00
|
|
|
m_Grid.m_Size = wxRealPoint( 50, 50 ); /* Default grid size */
|
|
|
|
m_Grid.m_Id = ID_POPUP_GRID_LEVEL_50;
|
2008-12-05 16:03:05 +00:00
|
|
|
m_Center = true;
|
|
|
|
m_CurrentSheetDesc = &g_Sheet_A4;
|
2009-04-05 20:49:15 +00:00
|
|
|
m_IsPrinting = false;
|
2010-02-14 18:14:33 +00:00
|
|
|
m_ScrollPixelsPerUnitX = 1;
|
|
|
|
m_ScrollPixelsPerUnitY = 1;
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
InitDatas();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
BASE_SCREEN::~BASE_SCREEN()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-08 18:06:22 +00:00
|
|
|
void BASE_SCREEN::InitDatas()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
if( m_Center )
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
m_crossHairPosition.x = m_crossHairPosition.y = 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
m_DrawOrg.x = -ReturnPageSize().x / 2;
|
|
|
|
m_DrawOrg.y = -ReturnPageSize().y / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_DrawOrg.x = m_DrawOrg.y = 0;
|
2011-02-11 20:48:13 +00:00
|
|
|
m_crossHairPosition.x = ReturnPageSize().x / 2;
|
|
|
|
m_crossHairPosition.y = ReturnPageSize().y / 2;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 19:57:59 +00:00
|
|
|
m_O_Curseur.x = m_O_Curseur.y = 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
SetCurItem( NULL );
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
m_FlagModified = 0; // Set when any change is made on broad
|
2008-12-05 16:03:05 +00:00
|
|
|
m_FlagSave = 1; // Used in auto save: set when an auto save is made
|
|
|
|
}
|
|
|
|
|
2011-02-21 21:07:00 +00:00
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
/**
|
2008-12-05 16:03:05 +00:00
|
|
|
* Get screen units scalar.
|
|
|
|
*
|
2009-11-23 15:16:50 +00:00
|
|
|
* Default implementation returns scalar used for schematic screen. The
|
2008-12-05 16:03:05 +00:00
|
|
|
* internal units used by the schematic screen is 1 mil (0.001"). Override
|
|
|
|
* this in derived classes that require internal units other than 1 mil.
|
|
|
|
*/
|
2009-04-08 18:06:22 +00:00
|
|
|
int BASE_SCREEN::GetInternalUnits( void )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
|
|
|
return EESCHEMA_INTERNAL_UNIT;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-04-08 18:06:22 +00:00
|
|
|
wxSize BASE_SCREEN::ReturnPageSize( void )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
|
|
|
int internal_units = GetInternalUnits();
|
2010-03-19 20:15:30 +00:00
|
|
|
wxSize size = m_CurrentSheetDesc->m_Size;
|
|
|
|
size.x = (int)( (double)size.x * internal_units / 1000 );
|
|
|
|
size.y = (int)( (double)size.y * internal_units / 1000 );
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2010-03-19 20:15:30 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BASE_SCREEN::SetPageSize( wxSize& aPageSize )
|
|
|
|
{
|
|
|
|
int internal_units = GetInternalUnits();
|
|
|
|
|
|
|
|
m_CurrentSheetDesc->m_Size.x = (int) ((double)aPageSize.x * 1000 / internal_units);
|
|
|
|
m_CurrentSheetDesc->m_Size.y = (int) ((double)aPageSize.y * 1000 / internal_units);
|
2008-12-05 16:03:05 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
|
2011-04-01 17:10:16 +00:00
|
|
|
/**
|
|
|
|
* Function GetScalingFactor
|
|
|
|
* @return the the current scale used to draw items on screen
|
|
|
|
* draw coordinates are user coordinates * GetScalingFactor( )
|
|
|
|
*/
|
|
|
|
double BASE_SCREEN::GetScalingFactor() const
|
|
|
|
{
|
2011-07-05 12:46:14 +00:00
|
|
|
double scale = 1.0 / GetZoom();
|
2011-04-01 17:10:16 +00:00
|
|
|
return scale;
|
|
|
|
}
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function SetScalingFactor
|
2009-11-23 15:16:50 +00:00
|
|
|
* calculates the .m_Zoom member to have a given scaling factor
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aScale - the the current scale used to draw items on screen
|
|
|
|
* draw coordinates are user coordinates * GetScalingFactor()
|
|
|
|
*/
|
2009-04-08 18:06:22 +00:00
|
|
|
void BASE_SCREEN::SetScalingFactor(double aScale )
|
2009-02-02 12:12:18 +00:00
|
|
|
{
|
2011-07-05 12:46:14 +00:00
|
|
|
double zoom = aScale;
|
2009-02-02 12:12:18 +00:00
|
|
|
|
|
|
|
// Limit zoom to max and min allowed values:
|
|
|
|
if (zoom < m_ZoomList[0])
|
|
|
|
zoom = m_ZoomList[0];
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2009-02-02 12:12:18 +00:00
|
|
|
int idxmax = m_ZoomList.GetCount() - 1;
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2009-02-02 12:12:18 +00:00
|
|
|
if (zoom > m_ZoomList[idxmax])
|
|
|
|
zoom = m_ZoomList[idxmax];
|
|
|
|
|
|
|
|
SetZoom( zoom );
|
|
|
|
}
|
|
|
|
|
2011-07-05 12:46:14 +00:00
|
|
|
void BASE_SCREEN::SetZoomList( const wxArrayDouble& zoomlist )
|
2009-01-29 14:26:20 +00:00
|
|
|
{
|
|
|
|
if( !m_ZoomList.IsEmpty() )
|
|
|
|
m_ZoomList.Empty();
|
|
|
|
|
|
|
|
m_ZoomList = zoomlist;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-02-11 19:39:55 +00:00
|
|
|
bool BASE_SCREEN::SetFirstZoom()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
if( m_ZoomList.IsEmpty() )
|
2009-02-11 19:39:55 +00:00
|
|
|
{
|
2011-07-05 12:46:14 +00:00
|
|
|
if( m_Zoom != 1.0 )
|
2009-02-11 19:39:55 +00:00
|
|
|
{
|
2011-07-05 12:46:14 +00:00
|
|
|
m_Zoom = 1.0;
|
2009-02-11 19:39:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( m_Zoom != m_ZoomList[0] )
|
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
m_Zoom = m_ZoomList[0];
|
2009-02-11 19:39:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-05 12:46:14 +00:00
|
|
|
double BASE_SCREEN::GetZoom() const
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
return m_Zoom;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-07-05 12:46:14 +00:00
|
|
|
bool BASE_SCREEN::SetZoom( double coeff )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-02-11 19:39:55 +00:00
|
|
|
if( coeff == m_Zoom )
|
|
|
|
return false;
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
m_Zoom = coeff;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2009-02-11 19:39:55 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-11 19:39:55 +00:00
|
|
|
bool BASE_SCREEN::SetNextZoom()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
size_t i;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
if( m_ZoomList.IsEmpty() || m_Zoom >= m_ZoomList.Last() )
|
2009-02-11 19:39:55 +00:00
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
for( i = 0; i < m_ZoomList.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
if( m_Zoom < m_ZoomList[i] )
|
|
|
|
{
|
|
|
|
m_Zoom = m_ZoomList[i];
|
2009-02-11 19:39:55 +00:00
|
|
|
return true;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-11 19:39:55 +00:00
|
|
|
|
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-11 19:39:55 +00:00
|
|
|
bool BASE_SCREEN::SetPreviousZoom()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if( m_ZoomList.IsEmpty() || m_Zoom <= m_ZoomList[0] )
|
2009-02-11 19:39:55 +00:00
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
for( i = m_ZoomList.GetCount(); i != 0; i-- )
|
|
|
|
{
|
|
|
|
if( m_Zoom > m_ZoomList[i - 1] )
|
|
|
|
{
|
|
|
|
m_Zoom = m_ZoomList[i - 1];
|
2009-02-11 19:39:55 +00:00
|
|
|
return true;
|
2009-01-29 14:26:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-11 19:39:55 +00:00
|
|
|
|
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-11 19:39:55 +00:00
|
|
|
bool BASE_SCREEN::SetLastZoom()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-02-11 19:39:55 +00:00
|
|
|
if( m_ZoomList.IsEmpty() || m_Zoom == m_ZoomList.Last() )
|
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
m_Zoom = m_ZoomList.Last();
|
2009-02-11 19:39:55 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void BASE_SCREEN::SetGridList( GRIDS& gridlist )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
if( !m_grids.empty() )
|
|
|
|
m_grids.clear();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
m_grids = gridlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BASE_SCREEN::GetGrids( GRIDS& aList )
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_grids.size(); i++ )
|
|
|
|
aList.push_back( m_grids[ i ] );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-02-07 08:33:25 +00:00
|
|
|
void BASE_SCREEN::SetGrid( const wxRealPoint& size )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
wxASSERT( !m_grids.empty() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
size_t i;
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
GRID_TYPE nearest_grid = m_grids[0];
|
2009-10-14 19:43:31 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( i = 0; i < m_grids.size(); i++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
if( m_grids[i].m_Size == size )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
m_Grid = m_grids[i];
|
2008-12-05 16:03:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-02-07 08:33:25 +00:00
|
|
|
|
2009-02-06 11:45:35 +00:00
|
|
|
// keep trace of the nearest grill size, if the exact size is not found
|
2010-12-08 20:12:46 +00:00
|
|
|
if ( size.x < m_grids[i].m_Size.x )
|
|
|
|
nearest_grid = m_grids[i];
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-06 11:45:35 +00:00
|
|
|
m_Grid = nearest_grid;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
wxLogWarning( wxT( "Grid size( %f, %f ) not in grid list, falling back " ) \
|
|
|
|
wxT( "to grid size( %f, %f )." ),
|
2009-10-14 19:43:31 +00:00
|
|
|
size.x, size.y, m_Grid.m_Size.x, m_Grid.m_Size.y );
|
2008-12-05 16:03:05 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
/* Set grid size from command ID. */
|
|
|
|
void BASE_SCREEN::SetGrid( int id )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
wxASSERT( !m_grids.empty() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
size_t i;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( i = 0; i < m_grids.size(); i++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
if( m_grids[i].m_Id == id )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
m_Grid = m_grids[i];
|
2008-12-05 16:03:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
m_Grid = m_grids[0];
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
wxLogWarning( wxT( "Grid ID %d not in grid list, falling back to " ) \
|
2009-10-14 19:43:31 +00:00
|
|
|
wxT( "grid size( %g, %g )." ), id, m_Grid.m_Size.x,
|
|
|
|
m_Grid.m_Size.y );
|
2008-12-05 16:03:05 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
void BASE_SCREEN::AddGrid( const GRID_TYPE& grid )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
size_t i;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( i = 0; i < m_grids.size(); i++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
if( m_grids[i].m_Size == grid.m_Size && grid.m_Id != ID_POPUP_GRID_USER )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
2009-02-07 14:13:16 +00:00
|
|
|
wxLogDebug( wxT( "Discarding duplicate grid size( %g, %g )." ),
|
2008-12-05 16:03:05 +00:00
|
|
|
grid.m_Size.x, grid.m_Size.y );
|
|
|
|
return;
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
|
|
|
if( m_grids[i].m_Id == grid.m_Id )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
wxLogDebug( wxT( "Changing grid ID %d from size( %g, %g ) to " ) \
|
|
|
|
wxT( "size( %g, %g )." ),
|
2010-12-08 20:12:46 +00:00
|
|
|
grid.m_Id, m_grids[i].m_Size.x,
|
|
|
|
m_grids[i].m_Size.y, grid.m_Size.x, grid.m_Size.y );
|
|
|
|
m_grids[i].m_Size = grid.m_Size;
|
2008-12-05 16:03:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
m_grids.push_back( grid );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-02-07 08:33:25 +00:00
|
|
|
void BASE_SCREEN::AddGrid( const wxRealPoint& size, int id )
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
|
|
|
GRID_TYPE grid;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
grid.m_Size = size;
|
|
|
|
grid.m_Id = id;
|
|
|
|
AddGrid( grid );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
void BASE_SCREEN::AddGrid( const wxRealPoint& size, EDA_UNITS_T aUnit, int id )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
double x, y;
|
2009-02-07 08:33:25 +00:00
|
|
|
wxRealPoint new_size;
|
2008-12-05 16:03:05 +00:00
|
|
|
GRID_TYPE new_grid;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
switch( aUnit )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-07-12 14:07:09 +00:00
|
|
|
case MILLIMETRES:
|
2010-03-20 19:57:59 +00:00
|
|
|
x = size.x / 25.4;
|
|
|
|
y = size.y / 25.4;
|
2010-07-12 14:07:09 +00:00
|
|
|
break;
|
|
|
|
|
2010-07-12 19:28:38 +00:00
|
|
|
default:
|
2010-07-12 14:07:09 +00:00
|
|
|
case INCHES:
|
|
|
|
case UNSCALED_UNITS:
|
2008-12-05 16:03:05 +00:00
|
|
|
x = size.x;
|
|
|
|
y = size.y;
|
2010-07-12 14:07:09 +00:00
|
|
|
break;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 14:13:16 +00:00
|
|
|
new_size.x = x * GetInternalUnits();
|
|
|
|
new_size.y = y * GetInternalUnits();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
new_grid.m_Id = id;
|
|
|
|
new_grid.m_Size = new_size;
|
|
|
|
AddGrid( new_grid );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
GRID_TYPE& BASE_SCREEN::GetGrid( size_t aIndex )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( !m_grids.empty() && aIndex < m_grids.size(), m_Grid,
|
|
|
|
wxT( "Cannot get grid object outside the bounds of the grid list." ) );
|
|
|
|
|
|
|
|
return m_grids[ aIndex ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
GRID_TYPE BASE_SCREEN::GetGrid()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
return m_Grid;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-07-13 10:42:32 +00:00
|
|
|
const wxPoint& BASE_SCREEN::GetGridOrigin()
|
|
|
|
{
|
|
|
|
return m_GridOrigin;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
wxRealPoint BASE_SCREEN::GetGridSize()
|
|
|
|
{
|
|
|
|
return m_Grid.m_Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int BASE_SCREEN::GetGridId()
|
|
|
|
{
|
|
|
|
return m_Grid.m_Id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-02 19:01:21 +00:00
|
|
|
wxPoint BASE_SCREEN::GetNearestGridPosition( const wxPoint& aPosition, wxRealPoint* aGridSize )
|
|
|
|
{
|
|
|
|
wxPoint pt;
|
|
|
|
wxRealPoint gridSize;
|
|
|
|
|
|
|
|
if( aGridSize )
|
|
|
|
gridSize = *aGridSize;
|
|
|
|
else
|
|
|
|
gridSize = GetGridSize();
|
|
|
|
|
|
|
|
wxPoint gridOrigin = m_GridOrigin;
|
|
|
|
|
|
|
|
double offset = fmod( gridOrigin.x, gridSize.x );
|
|
|
|
int x = wxRound( (aPosition.x - offset) / gridSize.x );
|
|
|
|
pt.x = wxRound( x * gridSize.x + offset );
|
|
|
|
|
|
|
|
offset = fmod( gridOrigin.y, gridSize.y );
|
|
|
|
int y = wxRound( (aPosition.y - offset) / gridSize.y );
|
|
|
|
pt.y = wxRound ( y * gridSize.y + offset );
|
|
|
|
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxPoint BASE_SCREEN::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize )
|
|
|
|
{
|
|
|
|
if( aOnGrid )
|
2011-02-11 20:48:13 +00:00
|
|
|
return GetNearestGridPosition( m_crossHairPosition, aGridSize );
|
2011-02-02 19:01:21 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
return m_crossHairPosition;
|
2011-02-02 19:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
wxPoint BASE_SCREEN::GetCrossHairScreenPosition() const
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
wxPoint pos = m_crossHairPosition - m_DrawOrg;
|
2011-02-09 19:47:33 +00:00
|
|
|
double scalar = GetScalingFactor();
|
|
|
|
|
|
|
|
pos.x = wxRound( (double) pos.x * scalar );
|
|
|
|
pos.y = wxRound( (double) pos.y * scalar );
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
void BASE_SCREEN::SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGrid )
|
|
|
|
{
|
|
|
|
if( aSnapToGrid )
|
|
|
|
m_crossHairPosition = GetNearestGridPosition( aPosition );
|
|
|
|
else
|
|
|
|
m_crossHairPosition = aPosition;
|
|
|
|
}
|
|
|
|
|
2011-02-09 19:47:33 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* free the undo and the redo lists
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void BASE_SCREEN::ClearUndoRedoList()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
ClearUndoORRedoList( m_UndoList );
|
|
|
|
ClearUndoORRedoList( m_RedoList );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
/* Put aNewitem in top of undo list
|
2009-11-23 15:16:50 +00:00
|
|
|
* Deletes old items if > count max.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aNewitem )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
m_UndoList.PushCommand( aNewitem );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
/* Delete the extra items, if count max reached */
|
|
|
|
int extraitems = GetUndoCommandCount() - m_UndoRedoCountMax;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
if( extraitems > 0 ) // Delete the extra items
|
|
|
|
ClearUndoORRedoList( m_UndoList, extraitems );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
void BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aNewitem )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
m_RedoList.PushCommand( aNewitem );
|
|
|
|
|
|
|
|
/* Delete the extra items, if count max reached */
|
|
|
|
int extraitems = GetRedoCommandCount() - m_UndoRedoCountMax;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-07-29 13:10:36 +00:00
|
|
|
if( extraitems > 0 ) // Delete the extra items
|
|
|
|
ClearUndoORRedoList( m_RedoList, extraitems );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
PICKED_ITEMS_LIST* BASE_SCREEN::PopCommandFromUndoList( )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-07-23 15:37:00 +00:00
|
|
|
return m_UndoList.PopCommand( );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
PICKED_ITEMS_LIST* BASE_SCREEN::PopCommandFromRedoList( )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-07-23 15:37:00 +00:00
|
|
|
return m_RedoList.PopCommand( );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void BASE_SCREEN::AddItem( EDA_ITEM* aItem )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aItem != NULL, wxT( "Attempt to add NULL item pointer to " ) + GetClass() +
|
|
|
|
wxT( "item list" ) );
|
|
|
|
m_items.push_back( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void BASE_SCREEN::InsertItem( EDA_ITEMS::iterator aIter, EDA_ITEM* aItem )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( aItem != NULL, wxT( "Attempt to insert NULL item pointer to " ) + GetClass() +
|
|
|
|
wxT( "item list" ) );
|
|
|
|
m_items.insert( aIter, aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* is used to output the object tree, currently for debugging only.
|
2008-03-21 19:26:12 +00:00
|
|
|
* @param nestLevel An aid to prettier tree indenting, and is the level
|
2007-09-20 21:06:49 +00:00
|
|
|
* of nesting of this object within the overall tree.
|
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
|
|
|
void BASE_SCREEN::Show( int nestLevel, std::ostream& os )
|
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* item = m_drawList;
|
2008-03-21 19:26:12 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
// for now, make it look like XML, expand on this later.
|
2010-12-08 20:12:46 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << ">\n";
|
2008-03-21 19:26:12 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
for( ; item; item = item->Next() )
|
|
|
|
{
|
|
|
|
item->Show( nestLevel+1, os );
|
|
|
|
}
|
2008-03-21 19:26:12 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
|
|
|
|
}
|
|
|
|
#endif
|