2008-03-24 20:54:45 +00:00
|
|
|
/***************************************************************/
|
|
|
|
/* base_screen.cpp - fonctions des classes du type BASE_SCREEN */
|
|
|
|
/***************************************************************/
|
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"
|
2009-01-18 15:51:06 +00:00
|
|
|
#include "sch_item_struct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#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
|
|
|
/* Implement wxSize array for grid list implementation. */
|
|
|
|
#include <wx/arrimpl.cpp>
|
|
|
|
WX_DEFINE_OBJARRAY( GridArray );
|
|
|
|
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* defines locaux */
|
2007-08-20 01:20:48 +00:00
|
|
|
#define CURSOR_SIZE 12 /* taille de la croix du curseur PCB */
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
/*******************************************************/
|
|
|
|
/* Class BASE_SCREEN: classe de gestion d'un affichage */
|
|
|
|
/*******************************************************/
|
2008-12-05 16:03:05 +00:00
|
|
|
BASE_SCREEN::BASE_SCREEN( KICAD_T aType ) : EDA_BaseStruct( aType )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
EEDrawList = NULL; /* Schematic items list */
|
|
|
|
m_UndoList = NULL;
|
|
|
|
m_RedoList = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
m_UndoRedoCountMax = 1;
|
2008-12-05 16:03:05 +00:00
|
|
|
m_FirstRedraw = TRUE;
|
|
|
|
m_ScreenNumber = 1;
|
|
|
|
m_NumberOfScreen = 1; /* Hierarchy: Root: ScreenNumber = 1 */
|
2009-01-29 14:26:20 +00:00
|
|
|
m_ZoomScalar = 10;
|
|
|
|
m_Zoom = 32 * m_ZoomScalar;
|
2009-02-07 08:33:25 +00:00
|
|
|
m_Grid = wxRealPoint( 50, 50 ); /* Default grid size */
|
2008-12-05 16:03:05 +00:00
|
|
|
m_UserGridIsON = FALSE;
|
|
|
|
m_Center = true;
|
|
|
|
m_CurrentSheetDesc = &g_Sheet_A4;
|
|
|
|
|
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
|
|
|
ClearUndoRedoList();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*******************************/
|
2009-03-02 13:43:52 +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 )
|
|
|
|
{
|
|
|
|
m_Curseur.x = m_Curseur.y = 0;
|
|
|
|
m_DrawOrg.x = -ReturnPageSize().x / 2;
|
|
|
|
m_DrawOrg.y = -ReturnPageSize().y / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_DrawOrg.x = m_DrawOrg.y = 0;
|
|
|
|
m_Curseur.x = ReturnPageSize().x / 2;
|
|
|
|
m_Curseur.y = ReturnPageSize().y / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_O_Curseur = m_Curseur;
|
|
|
|
|
|
|
|
SetCurItem( NULL );
|
|
|
|
|
|
|
|
/* indicateurs divers */
|
2008-12-05 16:03:05 +00:00
|
|
|
m_FlagRefreshReq = 0; /* Redraw screen requste flag */
|
|
|
|
m_FlagModified = 0; // Set when any change is made on borad
|
|
|
|
m_FlagSave = 1; // Used in auto save: set when an auto save is made
|
|
|
|
}
|
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
/**
|
2008-12-05 16:03:05 +00:00
|
|
|
* Get screen units scalar.
|
|
|
|
*
|
|
|
|
* Default implimentation returns scalar used for schematic screen. The
|
|
|
|
* 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-03-02 13:43:52 +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-03-02 13:43:52 +00:00
|
|
|
/************************************/
|
|
|
|
wxSize
|
|
|
|
BASE_SCREEN::ReturnPageSize( void )
|
|
|
|
/************************************/
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
|
|
|
int internal_units = GetInternalUnits();
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
return wxSize( ( m_CurrentSheetDesc->m_Size.x * internal_units ) / 1000,
|
|
|
|
( m_CurrentSheetDesc->m_Size.y * internal_units ) / 1000 );
|
2008-12-05 16:03:05 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-03-02 13:43:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function CursorRealPosition
|
2009-01-31 10:05:16 +00:00
|
|
|
* @return the position in user units of location ScreenPos
|
|
|
|
* @param ScreenPos = the screen (in pixel) position co convert
|
|
|
|
*/
|
2009-03-02 13:43:52 +00:00
|
|
|
/******************************************************************/
|
|
|
|
wxPoint
|
|
|
|
BASE_SCREEN::CursorRealPosition( const wxPoint& ScreenPos )
|
|
|
|
/******************************************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
wxPoint curpos = ScreenPos;
|
|
|
|
Unscale( curpos );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
curpos += m_DrawOrg;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
return curpos;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2009-02-02 12:12:18 +00:00
|
|
|
/** Function SetScalingFactor
|
|
|
|
* calculates the .m_Zoom member to have a given scaling facort
|
|
|
|
* @param the the current scale used to draw items on screen
|
|
|
|
* draw coordinates are user coordinates * GetScalingFactor( )
|
|
|
|
*/
|
|
|
|
void BASE_SCREEN::SetScalingFactor(double aScale )
|
|
|
|
{
|
|
|
|
int zoom = static_cast<int>( ceil(aScale * m_ZoomScalar) );
|
|
|
|
|
|
|
|
// Limit zoom to max and min allowed values:
|
|
|
|
if (zoom < m_ZoomList[0])
|
|
|
|
zoom = m_ZoomList[0];
|
|
|
|
int idxmax = m_ZoomList.GetCount() - 1;
|
|
|
|
if (zoom > m_ZoomList[idxmax])
|
|
|
|
zoom = m_ZoomList[idxmax];
|
|
|
|
|
|
|
|
SetZoom( zoom );
|
|
|
|
}
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
/**
|
|
|
|
* Calculate coordinate value for zooming.
|
|
|
|
*
|
|
|
|
* Call this method when drawing on the device context. It scales the
|
|
|
|
* coordinate using the current zoom settings. Zooming in Kicad occurs
|
|
|
|
* by actually scaling the entire drawing using the zoom setting.
|
|
|
|
*
|
|
|
|
* FIXME: We should probably use wxCoord instead of int here but that would
|
|
|
|
* require using wxCoord in all of the other code that makes device
|
|
|
|
* context calls as well.
|
|
|
|
*/
|
|
|
|
int BASE_SCREEN::Scale( int coord )
|
|
|
|
{
|
|
|
|
#ifdef WX_ZOOM
|
|
|
|
return coord;
|
|
|
|
#else
|
|
|
|
if( !m_ZoomScalar || !m_Zoom )
|
2009-02-10 12:37:12 +00:00
|
|
|
return coord;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
return wxRound( (double) ( coord * m_ZoomScalar ) / (double) m_Zoom );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BASE_SCREEN::Scale( wxPoint& pt )
|
|
|
|
{
|
|
|
|
pt.x = Scale( pt.x );
|
|
|
|
pt.y = Scale( pt.y );
|
|
|
|
}
|
|
|
|
|
2009-02-07 08:33:25 +00:00
|
|
|
void BASE_SCREEN::Scale( wxRealPoint& pt )
|
|
|
|
{
|
2009-02-10 12:37:12 +00:00
|
|
|
#ifdef WX_ZOOM
|
|
|
|
// No change
|
|
|
|
#else
|
|
|
|
if( !m_ZoomScalar || !m_Zoom )
|
|
|
|
return;
|
|
|
|
|
|
|
|
pt.x = pt.x * m_ZoomScalar / (double) m_Zoom;
|
|
|
|
pt.y = pt.y * m_ZoomScalar / (double) m_Zoom;
|
|
|
|
#endif
|
2009-02-07 08:33:25 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
void BASE_SCREEN::Scale( wxSize& sz )
|
|
|
|
{
|
|
|
|
sz.SetHeight( Scale( sz.GetHeight() ) );
|
|
|
|
sz.SetWidth( Scale( sz.GetWidth() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the physical (unzoomed) location of a coordinate.
|
|
|
|
*
|
|
|
|
* Call this method when you want to find the unzoomed (physical) location
|
|
|
|
* of a coordinate on the drawing.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-01-29 14:26:20 +00:00
|
|
|
int BASE_SCREEN::Unscale( int coord )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-01-29 14:26:20 +00:00
|
|
|
#ifdef WX_ZOOM
|
|
|
|
return coord;
|
|
|
|
#else
|
|
|
|
if( !m_Zoom || !m_ZoomScalar )
|
|
|
|
return 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
return wxRound( (double) ( coord * m_Zoom ) / (double) m_ZoomScalar );
|
|
|
|
#endif
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
void BASE_SCREEN::Unscale( wxPoint& pt )
|
|
|
|
{
|
|
|
|
pt.x = Unscale( pt.x );
|
|
|
|
pt.y = Unscale( pt.y );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-03-21 19:26:12 +00:00
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
void BASE_SCREEN::Unscale( wxSize& sz )
|
|
|
|
{
|
|
|
|
sz.SetHeight( Unscale( sz.GetHeight() ) );
|
|
|
|
sz.SetWidth( Unscale( sz.GetWidth() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BASE_SCREEN::SetZoomList( const wxArrayInt& zoomlist )
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
if( m_Zoom != m_ZoomScalar )
|
|
|
|
{
|
|
|
|
m_Zoom = m_ZoomScalar;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-21 19:26:12 +00:00
|
|
|
int 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
|
|
|
|
2009-02-11 19:39:55 +00:00
|
|
|
bool BASE_SCREEN::SetZoom( int 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
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( m_Zoom < 1 )
|
|
|
|
m_Zoom = 1;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************/
|
2008-12-05 16:03:05 +00:00
|
|
|
void BASE_SCREEN::SetGridList( GridArray& gridlist )
|
2007-05-06 16:03:28 +00:00
|
|
|
/********************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* init liste des zoom (NULL terminated)
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
if( !m_GridList.IsEmpty() )
|
|
|
|
m_GridList.Clear();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
m_GridList = gridlist;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +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
|
|
|
/**********************************************/
|
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
wxASSERT( !m_GridList.IsEmpty() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
size_t i;
|
|
|
|
|
2009-02-07 08:33:25 +00:00
|
|
|
wxRealPoint nearest_grid = m_GridList[0].m_Size;
|
2008-12-05 16:03:05 +00:00
|
|
|
for( i = 0; i < m_GridList.GetCount(); i++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
if( m_GridList[i].m_Size == size )
|
|
|
|
{
|
|
|
|
m_Grid = m_GridList[i].m_Size;
|
|
|
|
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
|
|
|
|
if ( size.x < m_GridList[i].m_Size.x )
|
|
|
|
nearest_grid = m_GridList[i].m_Size;
|
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-02-07 08:33:25 +00:00
|
|
|
wxLogWarning( _( "Grid size( %f, %f ) not in grid list, falling back to " \
|
|
|
|
"grid size( %f, %f )." ),
|
2008-12-05 16:03:05 +00:00
|
|
|
size.x, size.y, m_Grid.x, m_Grid.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set grid size from command ID. */
|
|
|
|
void BASE_SCREEN::SetGrid( int id )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
wxASSERT( !m_GridList.IsEmpty() );
|
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
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
for( i = 0; i < m_GridList.GetCount(); i++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
if( m_GridList[i].m_Id == id )
|
|
|
|
{
|
|
|
|
m_Grid = m_GridList[i].m_Size;
|
|
|
|
return;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
m_Grid = m_GridList[0].m_Size;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
wxLogWarning( _( "Grid ID %d not in grid list, falling back to " \
|
2009-02-07 14:13:16 +00:00
|
|
|
"grid size( %g, %g )." ), id, m_Grid.x, m_Grid.y );
|
2008-12-05 16:03:05 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +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
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
for( i = 0; i < m_GridList.GetCount(); i++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-02-07 14:13:16 +00:00
|
|
|
if( m_GridList[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;
|
|
|
|
}
|
|
|
|
if( m_GridList[i].m_Id == grid.m_Id )
|
|
|
|
{
|
2009-02-07 14:13:16 +00:00
|
|
|
wxLogDebug( wxT( "Changing grid ID %d from size( %g, %g ) to " \
|
|
|
|
"size( %g, %g )." ),
|
2008-12-05 16:03:05 +00:00
|
|
|
grid.m_Id, m_GridList[i].m_Size.x,
|
|
|
|
m_GridList[i].m_Size.y, grid.m_Size.x, grid.m_Size.y );
|
|
|
|
m_GridList[i].m_Size = grid.m_Size;
|
|
|
|
return;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2008-12-29 20:05:47 +00:00
|
|
|
// wxLogDebug( wxT( "Adding grid ID %d size( %d, %d ) to grid list." ), grid.m_Id, grid.m_Size.x, grid.m_Size.y );
|
2008-12-05 16:03:05 +00:00
|
|
|
|
|
|
|
m_GridList.Add( grid );
|
2007-05-06 16:03:28 +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
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
void BASE_SCREEN::AddGrid( const wxRealPoint& size, int units, 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
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
if( units == MILLIMETRE )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
x = size.x / 25.4;
|
|
|
|
y = size.y / 25.4;
|
|
|
|
}
|
|
|
|
else if( units == CENTIMETRE )
|
|
|
|
{
|
|
|
|
x = size.x / 2.54;
|
|
|
|
y = size.y / 2.54;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x = size.x;
|
|
|
|
y = size.y;
|
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
|
|
|
|
2008-12-05 16:03:05 +00:00
|
|
|
/*********************************/
|
2009-02-07 08:33:25 +00:00
|
|
|
wxRealPoint BASE_SCREEN::GetGrid()
|
2008-12-05 16:03:05 +00:00
|
|
|
/*********************************/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
void BASE_SCREEN::ClearUndoRedoList()
|
2007-05-06 16:03:28 +00:00
|
|
|
/*****************************************/
|
2007-08-20 01:20:48 +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
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
EDA_BaseStruct* nextitem;
|
|
|
|
|
|
|
|
while( m_UndoList )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
nextitem = m_UndoList->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
delete m_UndoList;
|
|
|
|
m_UndoList = nextitem;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( m_RedoList )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
nextitem = m_RedoList->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
delete m_RedoList;
|
|
|
|
m_RedoList = nextitem;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/***********************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
void BASE_SCREEN::AddItemToUndoList( EDA_BaseStruct* newitem )
|
2007-05-06 16:03:28 +00:00
|
|
|
/************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* Put newitem in head of undo list
|
2007-08-20 01:20:48 +00:00
|
|
|
* Deletes olds items if > count max.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int ii;
|
2008-11-24 06:53:43 +00:00
|
|
|
EDA_BaseStruct* item;
|
|
|
|
EDA_BaseStruct* nextitem;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( newitem == NULL )
|
|
|
|
return;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
newitem->SetNext( m_UndoList );
|
2007-08-20 01:20:48 +00:00
|
|
|
m_UndoList = newitem;
|
|
|
|
|
|
|
|
/* Free first items, if count max reached */
|
|
|
|
for( ii = 0, item = m_UndoList; ii < m_UndoRedoCountMax; ii++ )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
if( item->Next() == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2008-11-24 06:53:43 +00:00
|
|
|
item = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
return;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
nextitem = item->Next();
|
|
|
|
item->SetNext( NULL ); // Set end of chain
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
// Delete the extra items
|
|
|
|
for( item = nextitem; item != NULL; item = nextitem )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
nextitem = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
delete item;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/***********************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
void BASE_SCREEN::AddItemToRedoList( EDA_BaseStruct* newitem )
|
2007-05-06 16:03:28 +00:00
|
|
|
/***********************************************************/
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int ii;
|
|
|
|
EDA_BaseStruct* item, * nextitem;
|
|
|
|
|
|
|
|
if( newitem == NULL )
|
|
|
|
return;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
newitem->SetNext( m_RedoList );
|
2007-08-20 01:20:48 +00:00
|
|
|
m_RedoList = newitem;
|
|
|
|
/* Free first items, if count max reached */
|
|
|
|
for( ii = 0, item = m_RedoList; ii < m_UndoRedoCountMax; ii++ )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
if( item->Next() == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
item = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
return;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
nextitem = item->Next();
|
|
|
|
item->SetNext( NULL ); // Set end of chain
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
// Delete the extra items
|
|
|
|
for( item = nextitem; item != NULL; item = nextitem )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
nextitem = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
delete item;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*****************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
EDA_BaseStruct* BASE_SCREEN::GetItemFromUndoList()
|
2007-05-06 16:03:28 +00:00
|
|
|
/*****************************************************/
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
EDA_BaseStruct* item = m_UndoList;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( item )
|
2008-11-24 06:53:43 +00:00
|
|
|
m_UndoList = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
return item;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/******************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
EDA_BaseStruct* BASE_SCREEN::GetItemFromRedoList()
|
2007-05-06 16:03:28 +00:00
|
|
|
/******************************************************/
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
EDA_BaseStruct* item = m_RedoList;
|
|
|
|
|
|
|
|
if( item )
|
2008-11-24 06:53:43 +00:00
|
|
|
m_RedoList = item->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
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 )
|
|
|
|
{
|
2009-01-18 15:51:06 +00:00
|
|
|
SCH_ITEM* item = EEDrawList;
|
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.
|
|
|
|
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
|
2007-09-24 07:14:01 +00:00
|
|
|
|