Commit 33616f30 authored by Dick Hollenbeck's avatar Dick Hollenbeck

* Add DRECT, DPOINT, and DSIZE (double rect, point, and size) using Torsten's vector2d.h

  as a starting point
* Make double Distance() take double arguments and remove internal range checking.
* Start on EDA_DRAW_FRAME::AdjustScrollBars() and use "double" for most all calculations
  in anticipation of setting INT_MAX INT_MIN limits eventually.
parent d8b60a14
......@@ -70,17 +70,19 @@ void BASE_SCREEN::InitDataPoints( const wxSize& aPageSizeIU )
{
if( m_Center )
{
m_crossHairPosition.x = m_crossHairPosition.y = 0;
m_crossHairPosition.x = 0;
m_crossHairPosition.y = 0;
m_DrawOrg.x = -aPageSizeIU.x / 2;
m_DrawOrg.y = -aPageSizeIU.y / 2;
}
else
{
m_DrawOrg.x = m_DrawOrg.y = 0;
m_crossHairPosition.x = aPageSizeIU.x / 2;
m_crossHairPosition.y = aPageSizeIU.y / 2;
m_DrawOrg.x = 0;
m_DrawOrg.y = 0;
}
m_O_Curseur.x = m_O_Curseur.y = 0;
......@@ -142,6 +144,8 @@ bool BASE_SCREEN::SetZoom( double coeff )
if( coeff == m_Zoom )
return false;
wxLogDebug( "Zoom:%16g 1/Zoom:%16g", coeff, 1/coeff );
m_Zoom = coeff;
return true;
......@@ -168,12 +172,10 @@ bool BASE_SCREEN::SetNextZoom()
bool BASE_SCREEN::SetPreviousZoom()
{
size_t i;
if( m_ZoomList.IsEmpty() || m_Zoom <= m_ZoomList[0] )
return false;
for( i = m_ZoomList.GetCount(); i != 0; i-- )
for( unsigned i = m_ZoomList.GetCount(); i != 0; i-- )
{
if( m_Zoom > m_ZoomList[i - 1] )
{
......@@ -191,8 +193,7 @@ bool BASE_SCREEN::SetLastZoom()
if( m_ZoomList.IsEmpty() || m_Zoom == m_ZoomList.Last() )
return false;
SetZoom( m_ZoomList.Last() );
return true;
return SetZoom( m_ZoomList.Last() );
}
......@@ -216,11 +217,9 @@ void BASE_SCREEN::SetGrid( const wxRealPoint& size )
{
wxASSERT( !m_grids.empty() );
size_t i;
GRID_TYPE nearest_grid = m_grids[0];
for( i = 0; i < m_grids.size(); i++ )
for( unsigned i = 0; i < m_grids.size(); i++ )
{
if( m_grids[i].m_Size == size )
{
......@@ -228,7 +227,7 @@ void BASE_SCREEN::SetGrid( const wxRealPoint& size )
return;
}
// keep trace of the nearest grill size, if the exact size is not found
// keep track of the nearest larger grid size, if the exact size is not found
if ( size.x < m_grids[i].m_Size.x )
nearest_grid = m_grids[i];
}
......@@ -245,9 +244,7 @@ void BASE_SCREEN::SetGrid( int id )
{
wxASSERT( !m_grids.empty() );
size_t i;
for( i = 0; i < m_grids.size(); i++ )
for( unsigned i = 0; i < m_grids.size(); i++ )
{
if( m_grids[i].m_Id == id )
{
......@@ -266,9 +263,7 @@ void BASE_SCREEN::SetGrid( int id )
void BASE_SCREEN::AddGrid( const GRID_TYPE& grid )
{
size_t i;
for( i = 0; i < m_grids.size(); i++ )
for( unsigned i = 0; i < m_grids.size(); i++ )
{
if( m_grids[i].m_Size == grid.m_Size && grid.m_Id != ID_POPUP_GRID_USER )
{
......
This diff is collapsed.
......@@ -158,28 +158,34 @@ void EDA_DRAW_PANEL::DrawCrossHair( wxDC* aDC, int aColor )
if( m_cursorLevel != 0 || aDC == NULL || !m_showCrossHair )
return;
wxPoint Cursor = GetScreen()->GetCrossHairPosition();
wxPoint cursor = GetScreen()->GetCrossHairPosition();
GRSetDrawMode( aDC, GR_XOR );
if( GetParent()->m_cursorShape != 0 ) /* Draws full screen crosshair. */
if( GetParent()->m_cursorShape != 0 ) // Draws full screen crosshair.
{
wxSize clientSize = GetClientSize();
wxPoint lineStart = wxPoint( Cursor.x, aDC->DeviceToLogicalY( 0 ) );
wxPoint lineEnd = wxPoint( Cursor.x, aDC->DeviceToLogicalY( clientSize.y ) );
GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor ); // Y axis
lineStart = wxPoint( aDC->DeviceToLogicalX( 0 ), Cursor.y );
lineEnd = wxPoint( aDC->DeviceToLogicalX( clientSize.x ), Cursor.y );
GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor ); // X axis
// Y axis
wxPoint lineStart( cursor.x, aDC->DeviceToLogicalY( 0 ) );
wxPoint lineEnd( cursor.x, aDC->DeviceToLogicalY( clientSize.y ) );
GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor );
// X axis
lineStart = wxPoint( aDC->DeviceToLogicalX( 0 ), cursor.y );
lineEnd = wxPoint( aDC->DeviceToLogicalX( clientSize.x ), cursor.y );
GRLine( &m_ClipBox, aDC, lineStart, lineEnd, 0, aColor );
}
else
{
int len = aDC->DeviceToLogicalXRel( CURSOR_SIZE );
GRLine( &m_ClipBox, aDC, Cursor.x - len, Cursor.y,
Cursor.x + len, Cursor.y, 0, aColor );
GRLine( &m_ClipBox, aDC, Cursor.x, Cursor.y - len,
Cursor.x, Cursor.y + len, 0, aColor );
GRLine( &m_ClipBox, aDC, cursor.x - len, cursor.y,
cursor.x + len, cursor.y, 0, aColor );
GRLine( &m_ClipBox, aDC, cursor.x, cursor.y - len,
cursor.x, cursor.y + len, 0, aColor );
}
}
......@@ -469,7 +475,7 @@ void EDA_DRAW_PANEL::EraseScreen( wxDC* DC )
m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
0, g_DrawBgColor, g_DrawBgColor );
/* Set to one (1) to draw bounding box validate bounding box calculation. */
// Set to one (1) to draw bounding box validate bounding box calculation.
#if DEBUG_SHOW_CLIP_RECT
EDA_RECT bBox = m_ClipBox;
GRRect( NULL, DC, bBox.GetOrigin().x, bBox.GetOrigin().y,
......@@ -823,7 +829,7 @@ void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event )
wxRect rect = wxRect( wxPoint( 0, 0 ), GetClientSize() );
/* Ignore scroll events if the cursor is outside the drawing area. */
// Ignore scroll events if the cursor is outside the drawing area.
if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled()
|| !rect.Contains( event.GetPosition() ) )
{
......@@ -937,12 +943,12 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
if( event.MiddleDown() )
localbutt = GR_M_MIDDLE_DOWN;
localrealbutt |= localbutt; /* compensation default wxGTK */
localrealbutt |= localbutt; // compensation default wxGTK
INSTALL_UNBUFFERED_DC( DC, this );
DC.SetBackground( *wxBLACK_BRUSH );
/* Compute the cursor position in drawing (logical) units. */
// Compute the cursor position in drawing (logical) units.
screen->SetMousePosition( event.GetLogicalPosition( DC ) );
int kbstat = 0;
......@@ -1101,7 +1107,7 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
GetEventHandler()->ProcessEvent( cmd );
}
/* Calling the general function on mouse changes (and pseudo key commands) */
// Calling the general function on mouse changes (and pseudo key commands)
GetParent()->GeneralControl( &DC, event.GetLogicalPosition( DC ), 0 );
/*******************************/
......@@ -1165,17 +1171,16 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event )
if( !m_enableMiddleButtonPan && 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
*/
// 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++;
else
{
if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos ) )
{
// should not occurs: error
// should not occur: error
GetParent()->DisplayToolMsg(
wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) );
}
......
......@@ -52,15 +52,13 @@ void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointe
m_canvas->Refresh();
m_canvas->Update();
}
}
/** Redraw the screen with best zoom level and the best centering
* that shows all the page or the board
*/
void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
{
BASE_SCREEN * screen = GetScreen();
BASE_SCREEN* screen = GetScreen();
screen->SetZoom( BestZoom() ); // Set the best zoom and get center point.
if( screen->m_FirstRedraw )
......@@ -76,16 +74,15 @@ void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
*/
void EDA_DRAW_FRAME::Window_Zoom( EDA_RECT& Rect )
{
double scalex, bestscale;
wxSize size;
/* Compute the best zoom */
// Compute the best zoom
Rect.Normalize();
size = m_canvas->GetClientSize();
wxSize size = m_canvas->GetClientSize();
// Use ceil to at least show the full rect
scalex = (double) Rect.GetSize().x / size.x;
bestscale = (double) Rect.GetSize().y / size.y;
double scalex = (double) Rect.GetSize().x / size.x;
double bestscale = (double) Rect.GetSize().y / size.y;
bestscale = MAX( bestscale, scalex );
GetScreen()->SetScalingFactor( bestscale );
......@@ -102,7 +99,6 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
if( m_canvas == NULL )
return;
int i;
int id = event.GetId();
bool zoom_at_cursor = false;
BASE_SCREEN* screen = GetScreen();
......@@ -151,9 +147,11 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
break;
default:
unsigned i;
i = id - ID_POPUP_ZOOM_LEVEL_START;
if( ( i < 0 ) || ( (size_t) i >= screen->m_ZoomList.GetCount() ) )
if( i >= screen->m_ZoomList.GetCount() )
{
wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
__TFILE__, __LINE__, i );
......@@ -175,7 +173,7 @@ void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
int maxZoomIds;
int zoom;
wxString msg;
BASE_SCREEN * screen = m_canvas->GetScreen();
BASE_SCREEN* screen = m_canvas->GetScreen();
msg = AddHotkeyName( _( "Center" ), m_HotkeysZoomAndGridList, HK_ZOOM_CENTER );
AddMenuItem( MasterMenu, ID_POPUP_ZOOM_CENTER, msg, KiBitmap( zoom_center_on_screen_xpm ) );
......@@ -199,7 +197,7 @@ void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
maxZoomIds = ( (size_t) maxZoomIds < screen->m_ZoomList.GetCount() ) ?
maxZoomIds : screen->m_ZoomList.GetCount();
/* Populate zoom submenu. */
// Populate zoom submenu.
for( int i = 0; i < maxZoomIds; i++ )
{
msg.Printf( wxT( "%g" ), screen->m_ZoomList[i] );
......@@ -210,7 +208,7 @@ void EDA_DRAW_FRAME::AddMenuZoomAndGrid( wxMenu* MasterMenu )
zoom_choice->Check( ID_POPUP_ZOOM_LEVEL_START + i, true );
}
/* Create grid submenu as required. */
// Create grid submenu as required.
if( screen->GetGridCount() )
{
wxMenu* gridMenu = new wxMenu;
......
......@@ -276,16 +276,22 @@ public:
/**
* Function SetScalingFactor
* @param aScale = the the current scale used to draw items on screen
* draw coordinates are user coordinates * GetScalingFactor()
* sets the scaling factor of "device units per logical unit".
* If the output device is a screen, then "device units" are pixels. The
* "logical unit" is wx terminology, and corresponds to KiCad's "Internal Unit (IU)".
*
* Another way of thinking of scaling factor, when applied to a screen,
* is "pixelsPerIU".
* @param aScale = the the current scale used to draw items onto the device context wxDC.
* device coordinates (pixels) = IU coordinates * GetScalingFactor()
*/
void SetScalingFactor( double aScale );
/**
* Function GetZoom
* returns the
* @return the current zoom factor
* Note: the zoom factor is NOT the scaling factor
* the scaling factor is m_ZoomScalar * GetZoom()
*/
double GetZoom() const;
......@@ -420,7 +426,7 @@ public:
void ClearBlockCommand() { m_BlockLocate.Clear(); }
wxPoint GetScrollCenterPosition() const { return m_scrollCenter; }
const wxPoint& GetScrollCenterPosition() const { return m_scrollCenter; }
void SetScrollCenterPosition( const wxPoint& aCenterPosition )
{
m_scrollCenter = aCenterPosition;
......
This diff is collapsed.
......@@ -647,6 +647,11 @@ public:
*/
void RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer );
/**
* Function Zoom_Automatique
* redraws the screen with best zoom level and the best centering
* that shows all the page or the board
*/
void Zoom_Automatique( bool aWarpPointer );
/* Set the zoom level to show the area Rect */
......
......@@ -810,8 +810,12 @@ void PCB_BASE_FRAME::updateZoomSelectBox()
{
msg = _( "Zoom " );
wxString value;
value.Printf( wxT( "%g" ), GetScreen()->m_ZoomList[i]);
wxString value = wxString::Format( wxT( "%g" ),
// @todo could do scaling here and show a "percentage"
GetScreen()->m_ZoomList[i]
);
msg += value;
m_zoomSelectBox->Append( msg );
......@@ -821,6 +825,7 @@ void PCB_BASE_FRAME::updateZoomSelectBox()
}
}
/* Function GetActiveViewerFrame
* return a reference to the current Module Viewer Frame if exists
* if called from the PCB editor, this is the m_ModuleViewerFrame
......
......@@ -42,6 +42,12 @@
*/
static const double pcbZoomList[] =
{
#if defined( USE_PCBNEW_NANOMETRES )
ZOOM_FACTOR( 0.1 ),
ZOOM_FACTOR( 0.2 ),
ZOOM_FACTOR( 0.3 ),
#endif
ZOOM_FACTOR( 0.5 ),
ZOOM_FACTOR( 1.0 ),
ZOOM_FACTOR( 1.5 ),
......@@ -57,10 +63,14 @@ static const double pcbZoomList[] =
ZOOM_FACTOR( 80.0 ),
ZOOM_FACTOR( 120.0 ),
ZOOM_FACTOR( 200.0 ),
ZOOM_FACTOR( 350.0 ),
ZOOM_FACTOR( 300.0 ),
#if !defined( USE_PCBNEW_NANOMETRES )
ZOOM_FACTOR( 500.0 ),
ZOOM_FACTOR( 1000.0 ),
ZOOM_FACTOR( 2000.0 )
#endif
};
......@@ -98,6 +108,9 @@ static GRID_TYPE pcbGridList[] =
PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
BASE_SCREEN( SCREEN_T )
{
wxSize displayz = wxGetDisplaySize();
for( unsigned i = 0; i < DIM( pcbZoomList ); ++i )
m_ZoomList.Add( pcbZoomList[i] );
......
......@@ -12,6 +12,14 @@
#define NM_PER_MIL 25400
double Distance( double x1, double y1, double x2, double y2 )
{
double dx = x1 - x2;
double dy = y1 - y2;
double d = sqrt( dx * dx + dy * dy );
return d;
}
/**
* Function TestLineHit
......@@ -1031,7 +1039,7 @@ int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int style1,
y2 = el2.Center.Y + el2.yrad* sin( s2 );
}
double d = Distance( (int) x, (int) y, (int) x2, (int) y2 );
double d = Distance( x, y, x2, y2 );
if( d < dmin )
{
......@@ -1101,7 +1109,7 @@ double GetPointToLineDistance( double a, double b, int x, int y, double* xpp, do
}
// find distance
return Distance( x, y, (int) xp, (int) yp );
return Distance( x, y, xp, yp );
}
......@@ -1151,7 +1159,7 @@ double GetPointToLineSegmentDistance( int x, int y, int xi, int yi, int xf, int
// find distance
if( InRange( xp, xi, xf ) && InRange( yp, yi, yf ) )
return Distance( x, y, (int) xp, (int) yp );
return Distance( x, y, xp, yp );
else
return min( Distance( x, y, xi, yi ), Distance( x, y, xf, yf ) );
}
......@@ -1177,26 +1185,6 @@ bool InRange( double x, double xi, double xf )
}
// Get distance between 2 points
//
double Distance( int x1, int y1, int x2, int y2 )
{
double dx = x1 - x2;
double dy = y1 - y2;
double d = sqrt( dx * dx + dy * dy );
if( d > INT_MAX || d < INT_MIN )
{
wxASSERT( 0 );
}
// wxASSERT( d <= INT_MAX && d >= INT_MIN );
return int( d );
}
// this finds approximate solutions
// note: this works best if el2 is smaller than el1
//
......@@ -1368,7 +1356,7 @@ double GetArcClearance( EllipseKH* el1, EllipseKH* el2,
double x2 = el2->Center.X + el2->xrad * cos( theta2 );
double y2 = el2->Center.Y + el2->yrad * sin( theta2 );
double d = Distance( (int) x, (int) y, (int) x2, (int) y2 );
double d = Distance( x, y, x2, y2 );
if( d < dmin )
{
......
......@@ -71,7 +71,9 @@ double GetPointToLineSegmentDistance( int x, int y, int xi, int yi, int xf, int
double GetPointToLineDistance( double a, double b, int x, int y, double * xp=NULL, double * yp=NULL );
bool InRange( double x, double xi, double xf );
double Distance( int x1, int y1, int x2, int y2 );
double Distance( double x1, double y1, double x2, double y2 );
int GetArcIntersections( EllipseKH * el1, EllipseKH * el2,
double * x1=NULL, double * y1=NULL,
double * x2=NULL, double * y2=NULL );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment