Drawing, pcbnew, and other minor fixes.

* Use wxDC to calculate screen center position.
* Minor grid drawing optimization.
* Remove an unnecessary use of global variable ActiveScreen.
* Doxygen warning fixes.
This commit is contained in:
Wayne Stambaugh 2011-01-31 13:26:12 -05:00
parent d657b43052
commit 44e474c25c
9 changed files with 64 additions and 51 deletions

View File

@ -146,6 +146,7 @@ void EDA_DRAW_FRAME::EraseMsgBox()
void EDA_DRAW_FRAME::OnActivate( wxActivateEvent& event )
{
m_FrameIsActive = event.GetActive();
if( DrawPanel )
DrawPanel->m_CanStartBlock = -1;
@ -157,6 +158,7 @@ void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event )
{
if( DrawPanel )
DrawPanel->m_CanStartBlock = -1;
event.Skip();
}
@ -197,6 +199,7 @@ void EDA_DRAW_FRAME::PrintPage( wxDC* aDC,int aPrintMask,
wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error"));
}
// Virtual function
void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
{
@ -253,7 +256,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
* index returned by GetSelection().
*/
m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000;
screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
screen->m_Curseur = DrawPanel->GetScreenCenterLogicalPosition();
screen->SetGrid( id );
Refresh();
}
@ -285,9 +288,11 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
{
id--;
int selectedZoom = GetBaseScreen()->m_ZoomList[id];
if( GetBaseScreen()->GetZoom() == selectedZoom )
return;
GetBaseScreen()->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
GetBaseScreen()->m_Curseur = DrawPanel->GetScreenCenterLogicalPosition();
GetBaseScreen()->SetZoom( selectedZoom );
RedrawScreen( false );
}
@ -382,12 +387,14 @@ void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
{
// Keep default cursor in toolbars
SetCursor( wxNullCursor );
// Change Cursor in DrawPanel only
if( DrawPanel )
{
DrawPanel->m_PanelDefaultCursor = aCursor;
DrawPanel->SetCursor( aCursor );
}
DisplayToolMsg( aToolMsg );
if( aId < 0 )
@ -428,6 +435,7 @@ void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
m_VToolBar->ToggleTool( ID_NO_SELECT_BUTT, TRUE );
m_ID_current_state = aId;
if( m_VToolBar )
m_VToolBar->Refresh( );
}
@ -527,6 +535,7 @@ void EDA_DRAW_FRAME::AdjustScrollBars()
if( posX < 0 )
posX = 0;
if( posY < 0 )
posY = 0;
@ -562,6 +571,7 @@ void EDA_DRAW_FRAME::SetLanguage( wxCommandEvent& event )
EDA_BASE_FRAME::SetLanguage( event );
}
/**
* Round to the nearest precision.
*
@ -575,6 +585,7 @@ double RoundTo0( double x, double precision )
assert( precision != 0 );
long long ix = wxRound( x * precision );
if ( x < 0.0 )
NEGATE( ix );
@ -613,15 +624,14 @@ void EDA_DRAW_FRAME::UpdateStatusBar()
if ( (screen->GetZoom() % screen->m_ZoomScalar) == 0 )
Line.Printf( wxT( "Z %d" ), screen->GetZoom() / screen->m_ZoomScalar );
else
Line.Printf( wxT( "Z %.1f" ),
(float)screen->GetZoom() / screen->m_ZoomScalar );
Line.Printf( wxT( "Z %.1f" ), (float)screen->GetZoom() / screen->m_ZoomScalar );
SetStatusText( Line, 1 );
/* Display absolute coordinates: */
double dXpos = To_User_Unit( g_UserUnit, screen->m_Curseur.x,
m_InternalUnits );
double dYpos = To_User_Unit( g_UserUnit, screen->m_Curseur.y,
m_InternalUnits );
double dXpos = To_User_Unit( g_UserUnit, screen->m_Curseur.x, m_InternalUnits );
double dYpos = To_User_Unit( g_UserUnit, screen->m_Curseur.y, m_InternalUnits );
/*
* Converting from inches to mm can give some coordinates due to
* float point precision rounding errors, like 1.999 or 2.001 so
@ -678,6 +688,7 @@ void EDA_DRAW_FRAME::UpdateStatusBar()
dy = screen->m_Curseur.y - screen->m_O_Curseur.y;
dXpos = To_User_Unit( g_UserUnit, dx, m_InternalUnits );
dYpos = To_User_Unit( g_UserUnit, dy, m_InternalUnits );
if( g_UserUnit == MILLIMETRES )
{
dXpos = RoundTo0( dXpos, (double) ( m_InternalUnits / 10 ) );
@ -704,11 +715,15 @@ void EDA_DRAW_FRAME::LoadSettings()
EDA_BASE_FRAME::LoadSettings();
cfg->Read( m_FrameName + CursorShapeEntryKeyword, &m_CursorShape, ( long )0 );
bool btmp;
if ( cfg->Read( m_FrameName + ShowGridEntryKeyword, &btmp ) )
SetGridVisibility( btmp);
int itmp;
if( cfg->Read( m_FrameName + GridColorEntryKeyword, &itmp ) )
SetGridColor(itmp);
cfg->Read( m_FrameName + LastGridSizeId, &m_LastGridSizeId, 0L );
}

View File

@ -272,26 +272,12 @@ wxPoint EDA_DRAW_PANEL::CursorScreenPosition()
}
/**
* Function GetScreenCenterRealPosition
* @return position (in internal units) of the current area center showed
* on screen
*/
wxPoint EDA_DRAW_PANEL::GetScreenCenterRealPosition( void )
wxPoint EDA_DRAW_PANEL::GetScreenCenterLogicalPosition()
{
int x, y, ppuX, ppuY;
wxPoint pos;
double scalar = GetScreen()->GetScalingFactor();
wxSize size = GetClientSize() / 2;
INSTALL_UNBUFFERED_DC( dc, this );
GetViewStart( &x, &y );
GetScrollPixelsPerUnit( &ppuX, &ppuY );
x *= ppuX;
y *= ppuY;
pos.x = wxRound( ( (double) GetClientSize().x / 2.0 + (double) x ) / scalar );
pos.y = wxRound( ( (double) GetClientSize().y / 2.0 + (double) y ) / scalar );
pos += GetScreen()->m_DrawOrg;
return pos;
return wxPoint( dc.DeviceToLogicalX( size.x ), dc.DeviceToLogicalY( size.y ) );
}
@ -650,6 +636,15 @@ void EDA_DRAW_PANEL::DrawGrid( wxDC* DC )
m_Parent->PutOnGrid( &org, &gridSize );
// Setting the nearest grid position can select grid points outside the clip box.
// Incrementing the start point by one grid step should prevent drawing grid points
// outside the clip box.
if( org.x < m_ClipBox.GetX() )
org.x += wxRound( gridSize.x );
if( org.y < m_ClipBox.GetY() )
org.y += wxRound( gridSize.y );
#if ( defined( __WXMAC__ ) || defined( __WXGTK__ ) || 1 )
// Use a pixel based draw to display grid. There are a lot of calls, so the cost is high
// and grid is slowly drawn on some platforms. Please note that this should always be

View File

@ -93,7 +93,7 @@ static wxDC* s_DC_lastDC = NULL;
*
* Please note that this is only accurate for lines that are one pixel wide.
*
* @param aRect - The rectangle to test.
* @param aClipBox - The rectangle to test.
* @param x1 - X coordinate of one end of a line.
* @param y1 - Y coordinate of one end of a line.
* @param x2 - X coordinate of the other end of a line.

View File

@ -125,7 +125,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
case ID_ZOOM_IN:
if( id == ID_ZOOM_IN )
screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
screen->m_Curseur = DrawPanel->GetScreenCenterLogicalPosition();
if( screen->SetPreviousZoom() )
RedrawScreen( zoom_at_cursor );
break;
@ -137,7 +137,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
case ID_ZOOM_OUT:
if( id == ID_ZOOM_OUT )
screen->m_Curseur = DrawPanel->GetScreenCenterRealPosition();
screen->m_Curseur = DrawPanel->GetScreenCenterLogicalPosition();
if( screen->SetNextZoom() )
RedrawScreen( zoom_at_cursor );
break;

View File

@ -154,7 +154,7 @@ public:
* converts \a aRect from device to drawing (logical) coordinates.
* <p>
* \a aRect must be in scrolled device units.
* <\p>
* </p>
* @param aRect The rectangle to convert.
* @param aDC The device context used for the conversion.
* @return A rectangle converted to drawing units.
@ -191,12 +191,12 @@ public:
* area. The clip box is used when drawing to determine which objects are not visible
* and do not need to be drawn.
* </p>
* @param aDc The device context use for drawing with the correct scale and
* @param aDC The device context use for drawing with the correct scale and
* offsets already configured. See DoPrepareDC().
* @param aRect The clip rectangle in device units or NULL for the entire visible area
* of the screen.
*/
void SetClipBox( wxDC& dc, const wxRect* aRect = NULL );
void SetClipBox( wxDC& aDC, const wxRect* aRect = NULL );
void ReDraw( wxDC* DC, bool erasebg = TRUE );
@ -222,7 +222,12 @@ public:
*/
void RefreshDrawingRect( const EDA_Rect& aRect, bool aEraseBackground = true );
wxPoint GetScreenCenterRealPosition( void );
/**
* Function GetScreenCenterLogicalPosition
* @return The current screen center position in logical (drawing) units.
*/
wxPoint GetScreenCenterLogicalPosition();
void MouseToCursorSchema();
void MouseTo( const wxPoint& Mouse );

View File

@ -295,8 +295,7 @@ void WinEDA_PcbFrame::End_Edge( DRAWSEGMENT* Segment, wxDC* DC )
*/
static void Montre_Position_NewSegment( EDA_DRAW_PANEL* panel, wxDC* DC, bool erase )
{
DRAWSEGMENT* Segment = (DRAWSEGMENT*)
panel->GetScreen()->GetCurItem();
DRAWSEGMENT* Segment = (DRAWSEGMENT*) panel->GetScreen()->GetCurItem();
int t_fill = DisplayOpt.DisplayDrawItems;
if( Segment == NULL )
@ -309,7 +308,8 @@ static void Montre_Position_NewSegment( EDA_DRAW_PANEL* panel, wxDC* DC, bool er
if( Segments_45_Only && ( Segment->m_Shape == S_SEGMENT ) )
{
Calcule_Coord_Extremite_45( Segment->m_Start.x, Segment->m_Start.y,
Calcule_Coord_Extremite_45( panel->GetScreen()->m_Curseur,
Segment->m_Start.x, Segment->m_Start.y,
&Segment->m_End.x, &Segment->m_End.y );
}
else /* here the angle is arbitrary */

View File

@ -751,7 +751,8 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* panel, wxDC* DC, bool erase )
/* Calculate of the end of the path for the permitted directions:
* horizontal, vertical or 45 degrees.
*/
Calcule_Coord_Extremite_45( g_CurrentTrackSegment->m_Start.x,
Calcule_Coord_Extremite_45( screen->m_Curseur,
g_CurrentTrackSegment->m_Start.x,
g_CurrentTrackSegment->m_Start.y,
&g_CurrentTrackSegment->m_End.x,
&g_CurrentTrackSegment->m_End.y );
@ -815,15 +816,14 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* panel, wxDC* DC, bool erase )
/* Determine the coordinate to advanced the the current segment
* in 0, 90, or 45 degrees, depending on position of origin and
* cursor position.
* in 0, 90, or 45 degrees, depending on position of origin and \a aPosition.
*/
void Calcule_Coord_Extremite_45( int ox, int oy, int* fx, int* fy )
void Calcule_Coord_Extremite_45( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy )
{
int deltax, deltay, angle;
deltax = ActiveScreen->m_Curseur.x - ox;
deltay = ActiveScreen->m_Curseur.y - oy;
deltax = aPosition.x - ox;
deltay = aPosition.y - oy;
deltax = abs( deltax );
deltay = abs( deltay );
@ -849,7 +849,7 @@ void Calcule_Coord_Extremite_45( int ox, int oy, int* fx, int* fy )
switch( angle )
{
case 0:
*fx = ActiveScreen->m_Curseur.x;
*fx = aPosition.x;
*fy = oy;
break;
@ -858,9 +858,9 @@ void Calcule_Coord_Extremite_45( int ox, int oy, int* fx, int* fy )
deltay = deltax;
/* Recalculate the signs fo deltax and deltaY. */
if( ( ActiveScreen->m_Curseur.x - ox ) < 0 )
if( ( aPosition.x - ox ) < 0 )
deltax = -deltax;
if( ( ActiveScreen->m_Curseur.y - oy ) < 0 )
if( ( aPosition.y - oy ) < 0 )
deltay = -deltay;
*fx = ox + deltax;
@ -869,7 +869,7 @@ void Calcule_Coord_Extremite_45( int ox, int oy, int* fx, int* fy )
case 90:
*fx = ox;
*fy = ActiveScreen->m_Curseur.y;
*fy = aPosition.y;
break;
}
}

View File

@ -216,10 +216,9 @@ TRACK* LocateIntrusion( TRACK* listStart, TRACK* aTrack, int aLayer, const wxPoi
void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* panel, wxDC* DC, bool erase );
/* Determine coordinate for a segment direction of 0, 90 or 45 degrees,
* depending on it's position from the origin (ox, oy) and the current
* cursor position.
* depending on it's position from the origin (ox, oy) and \a aPosiition..
*/
void Calcule_Coord_Extremite_45( int ox, int oy, int* fx, int* fy );
void Calcule_Coord_Extremite_45( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy );
/*****************/

View File

@ -750,8 +750,7 @@ static void Show_New_Edge_While_Move_Mouse( EDA_DRAW_PANEL* panel, wxDC* DC, boo
{
// calculate the new position as allowed
wxPoint StartPoint = zone->GetCornerPosition( icorner - 1 );
Calcule_Coord_Extremite_45( StartPoint.x, StartPoint.y,
&c_pos.x, &c_pos.y );
Calcule_Coord_Extremite_45( c_pos, StartPoint.x, StartPoint.y, &c_pos.x, &c_pos.y );
}
zone->SetCornerPosition( icorner, c_pos );