From 33616f30511c7bf3af4257ed97935055c393795f Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 23 Apr 2012 16:56:26 -0500 Subject: [PATCH 01/11] * 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. --- common/base_screen.cpp | 31 ++- common/drawframe.cpp | 391 ++++++++++++++++----------------- common/drawpanel.cpp | 55 ++--- common/zoom.cpp | 32 ++- include/class_base_screen.h | 16 +- include/vector2d.h | 399 ++++++++++++++++++++++++++++++++++ include/wxstruct.h | 5 + pcbnew/basepcbframe.cpp | 9 +- pcbnew/classpcb.cpp | 15 +- polygon/math_for_graphics.cpp | 36 +-- polygon/math_for_graphics.h | 4 +- 11 files changed, 695 insertions(+), 298 deletions(-) create mode 100644 include/vector2d.h diff --git a/common/base_screen.cpp b/common/base_screen.cpp index 7c92d64dbe..7f65548a7e 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -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 ) { diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 7bd1f1441b..fa2f27173d 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include @@ -495,211 +496,6 @@ bool EDA_DRAW_FRAME::HandleBlockEnd( wxDC* DC ) } -void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPosition ) -{ - int unitsX, unitsY, posX, posY; - wxSize clientSize, logicalClientSize, virtualSize; - BASE_SCREEN* screen = GetScreen(); - bool noRefresh = true; - - if( screen == NULL || m_canvas == NULL ) - return; - - double scalar = screen->GetScalingFactor(); - - wxLogTrace( traceScrollSettings, wxT( "Center Position = ( %d, %d ), scalar = %0.5f." ), - aCenterPosition.x, aCenterPosition.y, scalar ); - - // Calculate the portion of the drawing that can be displayed in the - // client area at the current zoom level. - clientSize = m_canvas->GetClientSize(); - - // The logical size of the client window. - logicalClientSize.x = KiROUND( (double) clientSize.x / scalar ); - logicalClientSize.y = KiROUND( (double) clientSize.y / scalar ); - - // A corner of the drawing in internal units. - wxSize corner = GetPageSizeIU(); - - // The drawing rectangle logical units - wxRect drawingRect( wxPoint( 0, 0 ), corner ); - - wxLogTrace( traceScrollSettings, wxT( "Logical drawing rect = ( %d, %d, %d, %d )." ), - drawingRect.x, drawingRect.y, drawingRect.width, drawingRect.height ); - wxLogTrace( traceScrollSettings, wxT( " left %d, right %d, top %d, bottome %d" ), - drawingRect.GetLeft(), drawingRect.GetRight(), - drawingRect.GetTop(), drawingRect.GetBottom() ); - - // The size of the client rectangle in logical units. - int x = KiROUND( (double) aCenterPosition.x - ( (double) logicalClientSize.x / 2.0 ) ); - int y = KiROUND( (double) aCenterPosition.y - ( (double) logicalClientSize.y / 2.0 ) ); - - // If drawn around the center, adjust the client rectangle accordingly. - if( screen->m_Center ) - { - x += KiROUND( (double) drawingRect.width / 2.0 ); - y += KiROUND( (double) drawingRect.height / 2.0 ); - } - - wxRect logicalClientRect( wxPoint( x, y ), logicalClientSize ); - - wxLogTrace( traceScrollSettings, wxT( "Logical client rect = ( %d, %d, %d, %d )." ), - logicalClientRect.x, logicalClientRect.y, - logicalClientRect.width, logicalClientRect.height ); - wxLogTrace( traceScrollSettings, wxT( " left %d, right %d, top %d, bottome %d" ), - logicalClientRect.GetLeft(), logicalClientRect.GetRight(), - logicalClientRect.GetTop(), logicalClientRect.GetBottom() ); - - if( drawingRect == logicalClientRect ) - { - virtualSize = drawingRect.GetSize(); - } - else - { - if( drawingRect.GetLeft() < logicalClientRect.GetLeft() && drawingRect.GetRight() > logicalClientRect.GetRight() ) - { - virtualSize.x = drawingRect.GetSize().x; - } - else - { - int drawingCenterX = drawingRect.x + ( drawingRect.width / 2 ); - int clientCenterX = logicalClientRect.x + ( logicalClientRect.width / 2 ); - - if( logicalClientRect.width > drawingRect.width ) - { - if( drawingCenterX > clientCenterX ) - virtualSize.x = ( drawingCenterX - logicalClientRect.GetLeft() ) * 2; - else if( drawingCenterX < clientCenterX ) - virtualSize.x = ( logicalClientRect.GetRight() - drawingCenterX ) * 2; - else - virtualSize.x = logicalClientRect.width; - } - else - { - if( drawingCenterX > clientCenterX ) - virtualSize.x = drawingRect.width + - ( (drawingRect.GetLeft() - logicalClientRect.GetLeft() ) * 2 ); - else if( drawingCenterX < clientCenterX ) - virtualSize.x = drawingRect.width + - ( (logicalClientRect.GetRight() - drawingRect.GetRight() ) * 2 ); - else - virtualSize.x = drawingRect.width; - } - } - - if( drawingRect.GetTop() < logicalClientRect.GetTop() && drawingRect.GetBottom() > logicalClientRect.GetBottom() ) - { - virtualSize.y = drawingRect.GetSize().y; - } - else - { - int drawingCenterY = drawingRect.y + ( drawingRect.height / 2 ); - int clientCenterY = logicalClientRect.y + ( logicalClientRect.height / 2 ); - - if( logicalClientRect.height > drawingRect.height ) - { - if( drawingCenterY > clientCenterY ) - virtualSize.y = ( drawingCenterY - logicalClientRect.GetTop() ) * 2; - else if( drawingCenterY < clientCenterY ) - virtualSize.y = ( logicalClientRect.GetBottom() - drawingCenterY ) * 2; - else - virtualSize.y = logicalClientRect.height; - } - else - { - if( drawingCenterY > clientCenterY ) - virtualSize.y = drawingRect.height + - ( ( drawingRect.GetTop() - logicalClientRect.GetTop() ) * 2 ); - else if( drawingCenterY < clientCenterY ) - virtualSize.y = drawingRect.height + - ( ( logicalClientRect.GetBottom() - drawingRect.GetBottom() ) * 2 ); - else - virtualSize.y = drawingRect.height; - } - } - } - - - if( screen->m_Center ) - { - screen->m_DrawOrg.x = -( KiROUND( (double) virtualSize.x / 2.0 ) ); - screen->m_DrawOrg.y = -( KiROUND( (double) virtualSize.y / 2.0 ) ); - } - else - { - screen->m_DrawOrg.x = -( KiROUND( (double) (virtualSize.x - drawingRect.width) / 2.0 ) ); - screen->m_DrawOrg.y = -( KiROUND( (double) (virtualSize.y - drawingRect.height) / 2.0 ) ); - } - - /* Always set scrollbar pixels per unit to 1 unless you want the zoom - * around cursor to jump around. This reported problem occurs when the - * zoom point is not on a pixel per unit increment. If you set the - * pixels per unit to 10, you have potential for the zoom point to - * jump around +/-5 pixels from the nearest grid point. - */ - screen->m_ScrollPixelsPerUnitX = screen->m_ScrollPixelsPerUnitY = 1; - - // Calculate the number of scroll bar units for the given zoom level in device units. - unitsX = KiROUND( (double) virtualSize.x * scalar ); - unitsY = KiROUND( (double) virtualSize.y * scalar ); - - // Calculate the scroll bar position in logical units to place the center position at - // the center of client rectangle. - screen->SetScrollCenterPosition( aCenterPosition ); - posX = aCenterPosition.x - KiROUND( (double) logicalClientRect.width / 2.0 ) - - screen->m_DrawOrg.x; - posY = aCenterPosition.y - KiROUND( (double) logicalClientRect.height / 2.0 ) - - screen->m_DrawOrg.y; - - // Convert scroll bar position to device units. - posX = KiROUND( (double) posX * scalar ); - posY = KiROUND( (double) posY * scalar ); - - if( posX < 0 ) - { - wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %d" ), posX ); - posX = 0; - } - - if( posX > unitsX ) - { - wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %d" ), posX ); - posX = unitsX; - } - - if( posY < 0 ) - { - wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %d" ), posY ); - posY = 0; - } - - if( posY > unitsY ) - { - wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %d" ), posY ); - posY = unitsY; - } - - screen->m_ScrollbarPos = wxPoint( posX, posY ); - screen->m_ScrollbarNumber = wxSize( unitsX, unitsY ); - - wxLogTrace( traceScrollSettings, - wxT( "Drawing = (%d, %d), Client = (%d, %d), Offset = (%d, %d), \ -SetScrollbars(%d, %d, %d, %d, %d, %d)" ), - virtualSize.x, virtualSize.y, logicalClientSize.x, logicalClientSize.y, - screen->m_DrawOrg.x, screen->m_DrawOrg.y, - screen->m_ScrollPixelsPerUnitX, screen->m_ScrollPixelsPerUnitY, - screen->m_ScrollbarNumber.x, screen->m_ScrollbarNumber.y, - screen->m_ScrollbarPos.x, screen->m_ScrollbarPos.y ); - - m_canvas->SetScrollbars( screen->m_ScrollPixelsPerUnitX, - screen->m_ScrollPixelsPerUnitY, - screen->m_ScrollbarNumber.x, - screen->m_ScrollbarNumber.y, - screen->m_ScrollbarPos.x, - screen->m_ScrollbarPos.y, noRefresh ); -} - - void EDA_DRAW_FRAME::SetLanguage( wxCommandEvent& event ) { EDA_BASE_FRAME::SetLanguage( event ); @@ -858,3 +654,188 @@ bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosi Block->SetMessageBlock( this ); return true; } + + +void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU ) +{ + BASE_SCREEN* screen = GetScreen(); + + if( screen == NULL || m_canvas == NULL ) + return; + + // There are no safety limits on these calculations, so in NANOMETRES build it + // still blows up. This is incomplete work. + + double scale = screen->GetScalingFactor(); + + wxLogTrace( traceScrollSettings, wxT( "Center Position = ( %d, %d ), scale = %.16g" ), + aCenterPositionIU.x, aCenterPositionIU.y, scale ); + + // Calculate the portion of the drawing that can be displayed in the + // client area at the current zoom level. + + // visible viewport in device units ~ pixels + wxSize clientSizeDU = m_canvas->GetClientSize(); + + // Size of the client window in IU + DSIZE clientSizeIU( clientSizeDU.x / scale, clientSizeDU.y / scale ); + + // Full drawing or "page" rectangle in internal units + DRECT pageRectIU( 0, 0, GetPageSizeIU().x, GetPageSizeIU().y ); + + // The upper left corner of the client rectangle in internal units. + double xIU = aCenterPositionIU.x - clientSizeIU.x / 2.0; + double yIU = aCenterPositionIU.y - clientSizeIU.y / 2.0; + + // If drawn around the center, adjust the client rectangle accordingly. + if( screen->m_Center ) + { + // half page offset. + xIU += pageRectIU.width / 2.0; + yIU += pageRectIU.height / 2.0; + } + + DRECT clientRectIU( xIU, yIU, clientSizeIU.x, clientSizeIU.y ); + DSIZE virtualSizeIU; + + if( pageRectIU.GetLeft() < clientRectIU.GetLeft() && pageRectIU.GetRight() > clientRectIU.GetRight() ) + { + virtualSizeIU.x = pageRectIU.GetSize().x; + } + else + { + double drawingCenterX = pageRectIU.x + ( pageRectIU.width / 2 ); + double clientCenterX = clientRectIU.x + ( clientRectIU.width / 2 ); + + if( clientRectIU.width > pageRectIU.width ) + { + if( drawingCenterX > clientCenterX ) + virtualSizeIU.x = ( drawingCenterX - clientRectIU.GetLeft() ) * 2; + else if( drawingCenterX < clientCenterX ) + virtualSizeIU.x = ( clientRectIU.GetRight() - drawingCenterX ) * 2; + else + virtualSizeIU.x = clientRectIU.width; + } + else + { + if( drawingCenterX > clientCenterX ) + virtualSizeIU.x = pageRectIU.width + + ( (pageRectIU.GetLeft() - clientRectIU.GetLeft() ) * 2 ); + else if( drawingCenterX < clientCenterX ) + virtualSizeIU.x = pageRectIU.width + + ( (clientRectIU.GetRight() - pageRectIU.GetRight() ) * 2 ); + else + virtualSizeIU.x = pageRectIU.width; + } + } + + if( pageRectIU.GetTop() < clientRectIU.GetTop() && pageRectIU.GetBottom() > clientRectIU.GetBottom() ) + { + virtualSizeIU.y = pageRectIU.GetSize().y; + } + else + { + int drawingCenterY = pageRectIU.y + ( pageRectIU.height / 2 ); + int clientCenterY = clientRectIU.y + ( clientRectIU.height / 2 ); + + if( clientRectIU.height > pageRectIU.height ) + { + if( drawingCenterY > clientCenterY ) + virtualSizeIU.y = ( drawingCenterY - clientRectIU.GetTop() ) * 2; + else if( drawingCenterY < clientCenterY ) + virtualSizeIU.y = ( clientRectIU.GetBottom() - drawingCenterY ) * 2; + else + virtualSizeIU.y = clientRectIU.height; + } + else + { + if( drawingCenterY > clientCenterY ) + virtualSizeIU.y = pageRectIU.height + + ( ( pageRectIU.GetTop() - clientRectIU.GetTop() ) * 2 ); + else if( drawingCenterY < clientCenterY ) + virtualSizeIU.y = pageRectIU.height + + ( ( clientRectIU.GetBottom() - pageRectIU.GetBottom() ) * 2 ); + else + virtualSizeIU.y = pageRectIU.height; + } + } + + if( screen->m_Center ) + { + screen->m_DrawOrg.x = -KiROUND( virtualSizeIU.x / 2.0 ); + screen->m_DrawOrg.y = -KiROUND( virtualSizeIU.y / 2.0 ); + } + else + { + screen->m_DrawOrg.x = -KiROUND( ( virtualSizeIU.x - pageRectIU.width ) / 2.0 ); + screen->m_DrawOrg.y = -KiROUND( ( virtualSizeIU.y - pageRectIU.height ) / 2.0 ); + } + + /* Always set scrollbar pixels per unit to 1 unless you want the zoom + * around cursor to jump around. This reported problem occurs when the + * zoom point is not on a pixel per unit increment. If you set the + * pixels per unit to 10, you have potential for the zoom point to + * jump around +/-5 pixels from the nearest grid point. + */ + screen->m_ScrollPixelsPerUnitX = screen->m_ScrollPixelsPerUnitY = 1; + + // Number of scroll bar units for the given zoom level in device units. + double unitsX = virtualSizeIU.x * scale; + double unitsY = virtualSizeIU.y * scale; + + // Calculate the scroll bar position in internal units to place the + // center position at the center of client rectangle. + screen->SetScrollCenterPosition( aCenterPositionIU ); + + double posX = aCenterPositionIU.x - clientRectIU.width /2.0 - screen->m_DrawOrg.x; + double posY = aCenterPositionIU.y - clientRectIU.height/2.0 - screen->m_DrawOrg.y; + + // Convert scroll bar position to device units. + posX = KiROUND( posX * scale ); + posY = KiROUND( posY * scale ); + + if( posX < 0 ) + { + wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %d" ), posX ); + posX = 0; + } + + if( posX > unitsX ) + { + wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %d" ), posX ); + posX = unitsX; + } + + if( posY < 0 ) + { + wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %d" ), posY ); + posY = 0; + } + + if( posY > unitsY ) + { + wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %d" ), posY ); + posY = unitsY; + } + + screen->m_ScrollbarPos = wxPoint( KiROUND( posX ), KiROUND( posY ) ); + screen->m_ScrollbarNumber = wxSize( KiROUND( unitsX ), KiROUND( unitsY ) ); + + wxLogTrace( traceScrollSettings, + wxT( "Drawing = (%.16g, %.16g), Client = (%.16g, %.16g), Offset = (%d, %d), SetScrollbars(%d, %d, %d, %d, %d, %d)" ), + virtualSizeIU.x, virtualSizeIU.y, clientSizeIU.x, clientSizeIU.y, + screen->m_DrawOrg.x, screen->m_DrawOrg.y, + screen->m_ScrollPixelsPerUnitX, screen->m_ScrollPixelsPerUnitY, + screen->m_ScrollbarNumber.x, screen->m_ScrollbarNumber.y, + screen->m_ScrollbarPos.x, screen->m_ScrollbarPos.y ); + + bool noRefresh = true; + + m_canvas->SetScrollbars( screen->m_ScrollPixelsPerUnitX, + screen->m_ScrollPixelsPerUnitY, + screen->m_ScrollbarNumber.x, + screen->m_ScrollbarNumber.y, + screen->m_ScrollbarPos.x, + screen->m_ScrollbarPos.y, noRefresh ); +} + diff --git a/common/drawpanel.cpp b/common/drawpanel.cpp index fe95da1366..ee3e828bdb 100644 --- a/common/drawpanel.cpp +++ b/common/drawpanel.cpp @@ -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 + wxSize clientSize = GetClientSize(); + + // 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" ) ); } @@ -1264,8 +1269,8 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event ) switch( localkey ) { - default: - break; + default: + break; case WXK_ESCAPE: m_abortRequest = true; diff --git a/common/zoom.cpp b/common/zoom.cpp index 0f0b6524f1..dab51a79e3 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -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; diff --git a/include/class_base_screen.h b/include/class_base_screen.h index 47a390f0e4..26c9b2b99a 100644 --- a/include/class_base_screen.h +++ b/include/class_base_screen.h @@ -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; diff --git a/include/vector2d.h b/include/vector2d.h new file mode 100644 index 0000000000..6248b43a0d --- /dev/null +++ b/include/vector2d.h @@ -0,0 +1,399 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2010 Virtenio GmbH, Torsten Hueter, torsten.hueter virtenio.de + * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2012 Kicad Developers, see change_log.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef VECTOR2D_H_ +#define VECTOR2D_H_ + +#include +#include + + +/// Forward declaration for template friends +template class VECTOR2; + +/* +#include +template ostream& operator<<( ostream &stream, const VECTOR2& vector ); +*/ + +/** + * Class VECTOR2 + * defines a general 2D-vector. + * + * This class uses templates to be universal. Several operators are provided to help easy implementing + * of linear algebra equations. + * + */ +template class VECTOR2 +{ +public: + T x, y; + + // Constructors + + /// Construct a 2D-vector with x, y = 0 + VECTOR2(); + + /// Copy constructor + VECTOR2( const VECTOR2& aVector ); + + /// Constructor with a wxPoint as argument + VECTOR2( const wxPoint& aPoint ); + + /// Constructor with a wxSize as argument + VECTOR2( const wxSize& aSize ); + + /// Construct a vector with given components x, y + VECTOR2( T x, T y ); + + /// Destructor + // virtual ~VECTOR2(); + + /** + * Function Euclidean Norm + * computes the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2). + * It is used to calculate the length of the vector. + * @return Scalar, the euclidean norm + */ + T EuclideanNorm(); + + /** + * Function Perpendicular + * computes the perpendicular vector + * @return Perpendicular vector + */ + VECTOR2 Perpendicular(); + + /** + * Function Angle + * computes the angle of the vector + * @return vector angle + */ + T Angle(); + + // Operators + + /// Assignment operator + VECTOR2& operator=( const VECTOR2& aVector ); + + /// Vector addition operator + VECTOR2 operator+( const VECTOR2& aVector ); + + /// Compound assignment operator + VECTOR2& operator+=( const VECTOR2& aVector ); + + /// Vector subtraction operator + VECTOR2 operator-( const VECTOR2& aVector ); + + /// Compound assignment operator + VECTOR2& operator-=( const VECTOR2& aVector ); + + /// Negate Vector operator + VECTOR2 operator-(); + + /// Scalar product operator + T operator*( const VECTOR2& aVector ); + + /// Multiplication with a factor + VECTOR2 operator*( const T& aFactor ); + + /// Cross product operator + T operator^( const VECTOR2& aVector ); + + /// Equality operator + const bool operator==( const VECTOR2& aVector ); + + /// Not equality operator + const bool operator!=( const VECTOR2& aVector ); + + /// Smaller than operator + bool operator<( const VECTOR2& aVector ); + bool operator<=( const VECTOR2& aVector ); + + /// Greater than operator + bool operator>( const VECTOR2& aVector ); + bool operator>=( const VECTOR2& aVector ); + + /// Casting to int vector + // operator VECTOR2(); + + /// Type casting operator for the class wxPoint + //operator wxPoint(); + + // friend ostream& operator<< ( ostream &stream, const VECTOR2& vector ); +}; + + +// ---------------------- +// --- Implementation --- +// ---------------------- + +template VECTOR2::VECTOR2( VECTOR2 const& aVector ) : + x( aVector.x ), y( aVector.y ) +{ +} + +template VECTOR2::VECTOR2() +{ + x = y = 0.0; +} + +template VECTOR2::VECTOR2( wxPoint const& aPoint ) +{ + x = T( aPoint.x ); + y = T( aPoint.y ); +} + +template VECTOR2::VECTOR2( wxSize const& aSize ) +{ + x = T( aSize.x ); + y = T( aSize.y ); +} + +template VECTOR2::VECTOR2( T aX, T aY ) +{ + x = aX; + y = aY; +} + +// Not required at the moment for this class +//template VECTOR2::~VECTOR2() +//{ +// // TODO Auto-generated destructor stub +//} + +template T VECTOR2::EuclideanNorm() +{ + return sqrt( ( *this ) * ( *this ) ); +} + +template T VECTOR2::Angle() +{ + return atan2(y, x); +} + +template VECTOR2 VECTOR2::Perpendicular(){ + VECTOR2 perpendicular(-y, x); + return perpendicular; +} + +/* +template ostream &operator<<( ostream &aStream, const VECTOR2& aVector ) +{ + aStream << "[ " << aVector.x << " | " << aVector.y << " ]"; + return aStream; +} +*/ + +template VECTOR2 &VECTOR2::operator=( const VECTOR2& aVector ) +{ + x = aVector.x; + y = aVector.y; + return *this; +} + +template VECTOR2 &VECTOR2::operator+=( const VECTOR2& aVector ) +{ + x += aVector.x; + y += aVector.y; + return *this; +} + +template VECTOR2& VECTOR2::operator-=( const VECTOR2& aVector ) +{ + x -= aVector.x; + y -= aVector.y; + return *this; +} + +//template VECTOR2::operator wxPoint() +//{ +// wxPoint point; +// point.x = (int) x; +// point.y = (int) y; +// return point; +//} +// + +//// Use correct rounding for casting to wxPoint +//template<> VECTOR2::operator wxPoint() +//{ +// wxPoint point; +// point.x = point.x >= 0 ? (int) ( x + 0.5 ) : (int) ( x - 0.5 ); +// point.y = point.y >= 0 ? (int) ( y + 0.5 ) : (int) ( y - 0.5 ); +// return point; +//} + +// Use correct rounding for casting double->int +//template<> VECTOR2::operator VECTOR2() +//{ +// VECTOR2 vector; +// vector.x = vector.x >= 0 ? (int) ( x + 0.5 ) : (int) ( x - 0.5 ); +// vector.y = vector.y >= 0 ? (int) ( y + 0.5 ) : (int) ( y - 0.5 ); +// return vector; +//} + +template VECTOR2 VECTOR2::operator+( const VECTOR2& aVector ) +{ + return VECTOR2 ( x + aVector.x, y + aVector.y ); +} + +template VECTOR2 VECTOR2::operator-( const VECTOR2& aVector ) +{ + return VECTOR2 ( x - aVector.x, y - aVector.y ); +} + +template VECTOR2 VECTOR2::operator-() +{ + return VECTOR2 ( -x, -y ); +} + +template T VECTOR2::operator*( const VECTOR2& aVector ) +{ + return aVector.x * x + aVector.y * y; +} + +template VECTOR2 VECTOR2::operator*( const T& aFactor ) +{ + VECTOR2 vector( x * aFactor, y * aFactor ); + return vector; +} + +template VECTOR2 operator*( const T& aFactor, const VECTOR2& aVector){ + VECTOR2 vector( aVector.x * aFactor, aVector.y * aFactor ); + return vector; +} + +template T VECTOR2::operator^( const VECTOR2& aVector ) +{ + return x * aVector.y - y * aVector.x; +} + +template bool VECTOR2::operator<( const VECTOR2& o ) +{ + // VECTOR2 vector( aVector ); + return (double( x ) * x + double( y ) * y) < (double( o.x ) * o.x + double( o.y ) * y); +} + +template bool VECTOR2::operator<=( const VECTOR2& aVector ) +{ + VECTOR2 vector( aVector ); + return ( *this * *this ) <= ( vector * vector ); +} + +template bool VECTOR2::operator>( const VECTOR2& aVector ) +{ + VECTOR2 vector( aVector ); + return ( *this * *this ) > ( vector * vector ); +} + +template bool VECTOR2::operator>=( const VECTOR2& aVector ) +{ + VECTOR2 vector( aVector ); + return ( *this * *this ) >= ( vector * vector ); +} + +template bool const VECTOR2::operator==( VECTOR2 const& aVector ) +{ + return ( aVector.x == x ) && ( aVector.y == y ); +} + +template bool const VECTOR2::operator!=( VECTOR2 const& aVector ) +{ + return ( aVector.x != x ) || ( aVector.y != y ); +} + + +/** + * Class RECT + * is a description of a rectangle in cartesion coordinate system. + */ +template class RECT +{ +public: + RECT() : x(0), y(0), width(0), height(0) {} + + RECT( T aX, T aY, T aWidth, T aHeight ): + x( aX ), y( aY ), width( aWidth ), height( aHeight ) + {} + + + /// Copy constructor + RECT( const RECT& aRect ) : + x( aRect.x ), y( aRect.y ), width( aRect.width ), height( aRect.height ) + {} + + /// Constructor with a wxPoint as argument? + + VECTOR2 GetSize() const { return VECTOR2 ( width, height ); } + VECTOR2 GetPosition() const { return VECTOR2 ( x, y ); } + + T GetLeft() const { return x; } + void SetLeft( T n ) { width += x - n; x = n; } + void MoveLeftTo( T n ) { x = n; } + + T GetTop() const { return y; } + void SetTop( T n ) { height += y - n; y = n; } + void MoveTopTo( T n ) { y = n; } + + T GetBottom() const { return y + height; } + void SetBottom( T n ) { height += n - ( y + height ); } + void MoveBottomTo( T n ) { y = n - height; } + + T GetRight() const { return x + width; } + void SetRight( T n ) { width += n - ( x + width ); } + void MoveRightTo( T n ) { x = n - width; } + + VECTOR2 GetLeftTop() const { return VECTOR2( x , y ); } + void SetLeftTop( const VECTOR2& pt ) { width += x - pt.x; height += y - pt.y; x = pt.x; y = pt.y; } + void MoveLeftTopTo( const VECTOR2 &pt ) { x = pt.x; y = pt.y; } + + VECTOR2 GetLeftBottom() const { return VECTOR2( x, y + height ); } + void SetLeftBottom( const VECTOR2& pt ) { width += x - pt.x; height += pt.y - (y + height); x = pt.x; } + void MoveLeftBottomTo( const VECTOR2& pt ) { x = pt.x; y = pt.y - height; } + + VECTOR2 GetRightTop() const { return VECTOR2( x + width, y ); } + void SetRightTop( const VECTOR2& pt ) { width += pt.x - ( x + width ); height += y - pt.y; y = pt.y; } + void MoveRightTopTo( const VECTOR2& pt ) { x = pt.x - width; y = pt.y; } + + VECTOR2 GetRightBottom() const { return VECTOR2( x + width, y + height ); } + void SetRightBottom( const VECTOR2& pt ) { width += pt.x - ( x + width ); height += pt.y - ( y + height); } + void MoveRightBottomTo( const VECTOR2& pt ) { x = pt.x - width; y = pt.y - height; } + + VECTOR2 GetCentre() const { return VECTOR2( x + width/2, y + height/2 ); } + void SetCentre( const VECTOR2& pt ) { MoveCentreTo( pt ); } + void MoveCentreTo( const VECTOR2& pt ) { x += pt.x - (x + width/2), y += pt.y - (y + height/2); } + + T x, y, width, height; +}; + + +typedef VECTOR2 DPOINT; +typedef DPOINT DSIZE; + +typedef RECT DRECT; + + +#endif // VECTOR2D_H_ diff --git a/include/wxstruct.h b/include/wxstruct.h index 0638ae84e2..9577af8dfa 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -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 */ diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 8e25126426..58870b2490 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -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 diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index e04da70eac..c12497f27e 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -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] ); diff --git a/polygon/math_for_graphics.cpp b/polygon/math_for_graphics.cpp index 10498b2fbc..8b3e44968c 100644 --- a/polygon/math_for_graphics.cpp +++ b/polygon/math_for_graphics.cpp @@ -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 ) { diff --git a/polygon/math_for_graphics.h b/polygon/math_for_graphics.h index 99271bbe6d..5119cd7973 100644 --- a/polygon/math_for_graphics.h +++ b/polygon/math_for_graphics.h @@ -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 ); From 2140efdce3f0b92b7829f0a3a7a50b2045f6b64a Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 23 Apr 2012 21:39:56 -0500 Subject: [PATCH 02/11] Somebody else spelled rectangle as badly as me, fix the mingw build --- common/drawframe.cpp | 10 +++++----- include/vector2d.h | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index fa2f27173d..656589cbf1 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -675,13 +675,13 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU ) // client area at the current zoom level. // visible viewport in device units ~ pixels - wxSize clientSizeDU = m_canvas->GetClientSize(); + wxSize clientSizeDU = m_canvas->GetClientSize(); // Size of the client window in IU - DSIZE clientSizeIU( clientSizeDU.x / scale, clientSizeDU.y / scale ); + DSIZE clientSizeIU( clientSizeDU.x / scale, clientSizeDU.y / scale ); // Full drawing or "page" rectangle in internal units - DRECT pageRectIU( 0, 0, GetPageSizeIU().x, GetPageSizeIU().y ); + DBOX pageRectIU( 0, 0, GetPageSizeIU().x, GetPageSizeIU().y ); // The upper left corner of the client rectangle in internal units. double xIU = aCenterPositionIU.x - clientSizeIU.x / 2.0; @@ -695,8 +695,8 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU ) yIU += pageRectIU.height / 2.0; } - DRECT clientRectIU( xIU, yIU, clientSizeIU.x, clientSizeIU.y ); - DSIZE virtualSizeIU; + DBOX clientRectIU( xIU, yIU, clientSizeIU.x, clientSizeIU.y ); + DSIZE virtualSizeIU; if( pageRectIU.GetLeft() < clientRectIU.GetLeft() && pageRectIU.GetRight() > clientRectIU.GetRight() ) { diff --git a/include/vector2d.h b/include/vector2d.h index 6248b43a0d..71e37699c5 100644 --- a/include/vector2d.h +++ b/include/vector2d.h @@ -327,21 +327,21 @@ template bool const VECTOR2::operator!=( VECTOR2 const& aVector ) /** - * Class RECT - * is a description of a rectangle in cartesion coordinate system. + * Class BOX2 + * is a description of a rectangle in a cartesion coordinate system. */ -template class RECT +template class BOX2 { public: - RECT() : x(0), y(0), width(0), height(0) {} + BOX2() : x(0), y(0), width(0), height(0) {} - RECT( T aX, T aY, T aWidth, T aHeight ): + BOX2( T aX, T aY, T aWidth, T aHeight ): x( aX ), y( aY ), width( aWidth ), height( aHeight ) {} /// Copy constructor - RECT( const RECT& aRect ) : + BOX2( const BOX2& aRect ) : x( aRect.x ), y( aRect.y ), width( aRect.width ), height( aRect.height ) {} @@ -393,7 +393,7 @@ public: typedef VECTOR2 DPOINT; typedef DPOINT DSIZE; -typedef RECT DRECT; +typedef BOX2 DBOX; #endif // VECTOR2D_H_ From a2f148219272f7819791ca3e48b8b9cbe3a011c5 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Tue, 24 Apr 2012 09:23:41 -0500 Subject: [PATCH 03/11] TODO --- TODO.txt | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/TODO.txt b/TODO.txt index 5c02e6f6a0..14e4022afc 100644 --- a/TODO.txt +++ b/TODO.txt @@ -52,21 +52,33 @@ PCBNew See the @todos in class_zone.cpp -Dick's Peronal TODO Items (Last Update: 5-April-2012) +Dick's Peronal TODO Items (Last Update: 24-April-2012) ----------------------------------------------------- -0) Check that the new load visibility BOARD settings is properly setting the toolbar + +1) Work through some scroll, pan, zoom overflows in PCBNEW's nanometer build mode. + It is thought that if we can constrain the virtual IU space to within + INT_MIN to INT_MAX then a whole host of other problems will go away. Most + of the evil is in EDA_DRAW_FRAME::AdjustScrollBars() which assumes the + virtual IU space is infinite. This function triggers a movement of the + viewport within the virtual IU space and also a change in size of the virtual + IU space. Once this happens, you can end up thinking there are problems in + functions like EDA_DRAW_PANE::DrawCrossHair(), but this may be an artifact + of having travelled outside a limited virtual IU space. + + +2) Check that the new load visibility BOARD settings is properly setting the toolbar buttons like show grid or ratsnest. Add PCB_EDIT_FRAME::SetVisibleElements() so toolbar crap is not known to a BOARD. -1) Finish removing global access requirements from KICAD_PLUGIN, so that: - *) a BOARD is a fully self contained document description. - *) plugin developers do not have to access globals, since a plugin could +3) Finish removing global access requirements from KICAD_PLUGIN, so that: + *) a BOARD is a fully self contained document description. + *) plugin developers do not have to access globals, since a plugin could very well be a dynamically loaded DLL/DSO. - One final problem remains with BASE_SCREEN's grid origin, easy solution is to - move just that one field into the BOARD. + One final problem remains with BASE_SCREEN's grid origin, easy solution is to + move just that one field into the BOARD. -2) Do an EAGLE XML import PCBNEW PLUGIN, and possibly add export support to it. +4) Do an EAGLE XML import PCBNEW PLUGIN, and possibly add export support to it. This is PLUGIN::Load() and maybe PLUGIN::Save(). -3) Get back to the SWEET work. +5) Get back to the SWEET work. From e3b6385cd3e0b371d01c521f3cc06e642068a131 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Wed, 25 Apr 2012 09:12:25 -0500 Subject: [PATCH 04/11] I was disappointed when I disassembled the code using the KiROUND() inline function solution to see that it was not pre-computing constants when used in static initializers. So we have two use cases, and need two solutions to be optimal, since the compiler is too stupid to do the right thing. I think we need something else for compile time computable constants, to be optimal in both use cases. There is quite a bit of code savings by using a macro for that situation from my testing. To fully capitalize on this, we need to go back and make Mm2mils() and what not macros also, or have MACRO versions of them too. --- TODO.txt | 2 +- include/common.h | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/TODO.txt b/TODO.txt index 14e4022afc..3e842a8f00 100644 --- a/TODO.txt +++ b/TODO.txt @@ -63,7 +63,7 @@ Dick's Peronal TODO Items (Last Update: 24-April-2012) viewport within the virtual IU space and also a change in size of the virtual IU space. Once this happens, you can end up thinking there are problems in functions like EDA_DRAW_PANE::DrawCrossHair(), but this may be an artifact - of having travelled outside a limited virtual IU space. + of having traveled outside a limited virtual IU space. 2) Check that the new load visibility BOARD settings is properly setting the toolbar diff --git a/include/common.h b/include/common.h index e9d7274255..ff33adfafa 100644 --- a/include/common.h +++ b/include/common.h @@ -127,11 +127,24 @@ enum pseudokeys { * In Debug build an assert fires if will not fit into an int. */ -#if defined( DEBUG ) +#if !defined( DEBUG ) -// DEBUG: a macro to capture line and file, then calls this inline +/// KiROUND: a function so v is not evaluated twice. Unfortunately, compiler +/// is unable to pre-compute constants using this. +static inline int KiROUND( double v ) +{ + return int( v < 0 ? v - 0.5 : v + 0.5 ); +} -static inline int KiRound( double v, int line, const char* filename ) +/// KIROUND: a macro so compiler can pre-compute constants. Use this with compile +/// time constants rather than the inline function above. +#define KIROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) + +#else + +// DEBUG: KiROUND() is a macro to capture line and file, then calls this inline + +static inline int kiRound_( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) @@ -145,13 +158,10 @@ static inline int KiRound( double v, int line, const char* filename ) return int( v ); } -#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) +#define KiROUND( v ) kiRound_( v, __LINE__, __FILE__ ) -#else - -// RELEASE: a macro so compile can pre-compute constants. - -#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) +// in Debug build, use the overflow catcher since code size is immaterial +#define KIROUND( v ) KiROUND( v ) #endif From fa3ebc40432c95a991e64db1304405ce96f39098 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 25 Apr 2012 21:33:24 +0200 Subject: [PATCH 05/11] Define MM_TO_IU_SCALING_FACTOR (scaling factor from mm to internal units) only in convert_to_biu.h Other scaling factors (MILS_TO_IU_SCALING_FACTOR and DECIMILS_TO_IU_SCALING_FACTOR) also defined only in convert_to_biu.h. Allows different scaling value for Gerbview. Needs more tests. --- common/CMakeLists.txt | 2 -- common/base_units.cpp | 24 ++++--------- common/dialogs/dialog_page_settings.cpp | 3 +- common/eda_text.cpp | 6 +--- cvpcb/CMakeLists.txt | 1 + eeschema/dialogs/dialog_SVG_print.cpp | 2 +- .../dialogs/dialog_print_using_printer.cpp | 2 +- eeschema/eeredraw.cpp | 2 +- eeschema/schframe.cpp | 2 +- gerbview/CMakeLists.txt | 4 ++- gerbview/dcode.cpp | 5 +-- gerbview/draw_gerber_screen.cpp | 2 +- gerbview/excellon_read_drill_file.cpp | 2 +- gerbview/gerbview_frame.cpp | 13 ++++--- gerbview/gerbview_frame.h | 12 +++---- gerbview/onleftclick.cpp | 4 +-- gerbview/onrightclick.cpp | 4 +-- gerbview/options.cpp | 16 +++------ gerbview/rs274_read_XY_and_IJ_coordinates.cpp | 32 ++++++++--------- gerbview/rs274x.cpp | 19 +++++------ include/base_units.h | 14 +------- include/common.h | 16 +++------ include/convert_to_biu.h | 34 +++++++++++++++---- pcbnew/CMakeLists.txt | 5 ++- pcbnew/classpcb.cpp | 23 ++++--------- pcbnew/dialogs/dialog_SVG_print.cpp | 2 +- pcbnew/legacy_plugin.cpp | 9 ++--- pcbnew/printout_controler.cpp | 11 +++--- pcbnew/specctra_export.cpp | 10 ++---- pcbnew/tracepcb.cpp | 4 +-- polygon/PolyLine.cpp | 7 ++-- polygon/PolyLine.h | 3 +- 32 files changed, 126 insertions(+), 169 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7f8b5ded35..4841471478 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -83,7 +83,6 @@ add_library(common STATIC ${COMMON_SRCS}) set(PCB_COMMON_SRCS base_screen.cpp - base_units.cpp eda_text.cpp class_page_info.cpp pcbcommon.cpp @@ -120,7 +119,6 @@ set(PCB_COMMON_SRCS ../pcbnew/legacy_plugin.cpp ../pcbnew/kicad_plugin.cpp pcb_plot_params_keywords.cpp - dialogs/dialog_page_settings.cpp ) diff --git a/common/base_units.cpp b/common/base_units.cpp index d020791fd7..e8f19ba119 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -40,25 +40,13 @@ #include -#if defined( PCBNEW ) -#if defined( USE_PCBNEW_NANOMETRES ) -#define IU_TO_MM( x ) ( x * 1e-6 ) -#define IU_TO_IN( x ) ( ( x * 1e-6 ) / 25.4 ) -#define MM_TO_IU( x ) ( x * 1e6 ) -#define IN_TO_IU( x ) ( ( x * 25.4 ) * 1e6 ) +#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) +#define IU_TO_MM( x ) ( x / MM_TO_IU_SCALING_FACTOR ) +#define IU_TO_IN( x ) ( x / MILS_TO_IU_SCALING_FACTOR / 1000 ) +#define MM_TO_IU( x ) ( x * MM_TO_IU_SCALING_FACTOR ) +#define IN_TO_IU( x ) ( x * MILS_TO_IU_SCALING_FACTOR * 1000 ) #else -#define IU_TO_MM( x ) ( ( x * 0.0001 ) * 25.4 ) -#define IU_TO_IN( x ) ( x * 0.0001 ) -#define MM_TO_IU( x ) ( ( x / 25.4 ) * 10000.0 ) -#define IN_TO_IU( x ) ( x * 10000.0 ) -#endif -#elif defined( EESCHEMA ) -#define IU_TO_MM( x ) ( ( x * 0.001 ) * 25.4 ) -#define IU_TO_IN( x ) ( x * 0.001 ) -#define MM_TO_IU( x ) ( ( x / 25.4 ) * 1000.0 ) -#define IN_TO_IU( x ) ( x * 1000.0 ) -#else -#error "Cannot resolve internal units due to no definition of EESCHEMA or PCBNEW." +#error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW." #endif diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp index a5cee66249..c8c32d5523 100644 --- a/common/dialogs/dialog_page_settings.cpp +++ b/common/dialogs/dialog_page_settings.cpp @@ -34,7 +34,6 @@ #include #include #include -#include // MILS_TO_IU_SCALAR #include #include @@ -617,7 +616,7 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample() m_Parent->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ), wxSize( INT_MAX / 2, INT_MAX / 2 ) ) ); // Calculate layout preview scale. - int appScale = MILS_TO_IU_SCALAR; + int appScale = m_Screen->MilsToIuScalar(); double scaleW = (double) lyWidth / clamped_layout_size.x / appScale; double scaleH = (double) lyHeight / clamped_layout_size.y / appScale; diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 546a5deecf..1ade6a903c 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -37,11 +37,7 @@ // Conversion to application internal units defined at build time. #if defined( PCBNEW ) #include -#if defined( USE_PCBNEW_NANOMETRES ) -#define MILS_TO_IU( x ) ( x * 25400 ); -#else -#define MILS_TO_IU( x ) ( x * 10 ) -#endif +#define MILS_TO_IU( x ) ( x * MILS_TO_IU_SCALING_FACTOR ); #elif defined( EESCHEMA ) #include #define MILS_TO_IU( x ) ( x ) diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index 3256bb8935..64c10f9aa0 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -26,6 +26,7 @@ set(CVPCB_DIALOGS ) set(CVPCB_SRCS + ../common/base_units.cpp ../pcbnew/netlist_reader_common.cpp ../pcbnew/netlist_reader_kicad.cpp ../pcbnew/netlist_reader_firstformat.cpp diff --git a/eeschema/dialogs/dialog_SVG_print.cpp b/eeschema/dialogs/dialog_SVG_print.cpp index 4dfb675f2e..81dd581af5 100644 --- a/eeschema/dialogs/dialog_SVG_print.cpp +++ b/eeschema/dialogs/dialog_SVG_print.cpp @@ -237,7 +237,7 @@ bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame, sheetSize.y/2) ); if( aPrint_Sheet_Ref ) - frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); screen->m_IsPrinting = false; panel->SetClipBox( tmp ); diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index d9c787714f..91f9c80eaa 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -378,7 +378,7 @@ void SCH_PRINTOUT::DrawPage( SCH_SCREEN* aScreen ) aScreen->Draw( panel, dc, GR_DEFAULT_DRAWMODE ); if( printReference ) - parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); g_DrawBgColor = bg_color; aScreen->m_IsPrinting = false; diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index b571711594..62dfba469c 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -71,7 +71,7 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) GetScreen()->Draw( m_canvas, DC, GR_DEFAULT_DRAWMODE ); - TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); #ifdef USE_WX_OVERLAY if( IsShown() ) diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 20d4adc4f4..dddbf29ff7 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -863,7 +863,7 @@ void SCH_EDIT_FRAME::SVG_Print( wxCommandEvent& event ) void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData ) { GetScreen()->Draw( m_canvas, aDC, GR_DEFAULT_DRAWMODE ); - TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); } diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index f44c34125d..51bfd7988e 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -33,6 +33,7 @@ set(GERBVIEW_SRCS class_am_param.cpp class_aperture_macro.cpp class_DCodeSelectionbox.cpp + class_gbr_screen.cpp class_GERBER.cpp class_gerber_draw_item.cpp class_gerbview_layer_widget.cpp @@ -63,9 +64,10 @@ set(GERBVIEW_SRCS ) ### -# We need some extra sources from pcbnew +# We need some extra sources from common and pcbnew ### set(GERBVIEW_EXTRA_SRCS + ../common/base_units.cpp ../pcbnew/layer_widget.cpp ../pcbnew/printout_controler.cpp ../pcbnew/class_drc_item.cpp diff --git a/gerbview/dcode.cpp b/gerbview/dcode.cpp index beb64ef5e5..dd00855ff6 100644 --- a/gerbview/dcode.cpp +++ b/gerbview/dcode.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr * Copyright (C) 2011 Wayne Stambaugh * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * @@ -175,7 +175,8 @@ int GERBVIEW_FRAME::ReadDCodeDefinitionFile( const wxString& D_Code_FullFileName /* Updating gerber scale: */ - double dcode_scale = MILS_TO_IU_SCALAR; // By uniting dCode = mil, internal unit = MILS_TO_IU_SCALAR + double dcode_scale = MILS_TO_IU_SCALING_FACTOR; // By uniting dCode = mil, + // internal unit = MILS_TO_IU_SCALING_FACTOR current_Dcode = 0; if( D_Code_FullFileName.IsEmpty() ) diff --git a/gerbview/draw_gerber_screen.cpp b/gerbview/draw_gerber_screen.cpp index 7a6821a4ab..4f54dc047d 100644 --- a/gerbview/draw_gerber_screen.cpp +++ b/gerbview/draw_gerber_screen.cpp @@ -107,7 +107,7 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) if( IsElementVisible( DCODES_VISIBLE ) ) DrawItemsDCodeID( DC, GR_COPY ); - TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALAR ); + TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALING_FACTOR ); if( m_canvas->IsMouseCaptured() ) m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp index 64e40a4305..ccfada1cf2 100644 --- a/gerbview/excellon_read_drill_file.cpp +++ b/gerbview/excellon_read_drill_file.cpp @@ -432,7 +432,7 @@ bool EXCELLON_IMAGE::Execute_HEADER_Command( char*& text ) if( dcode == NULL ) break; // conv_scale = scaling factor from inch to Internal Unit - double conv_scale = MILS_TO_IU_SCALAR*1000; + double conv_scale = MILS_TO_IU_SCALING_FACTOR * 1000; if( m_GerbMetric ) conv_scale /= 25.4; diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index e922cf548c..d6eeb122da 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -44,6 +44,7 @@ #include #include #include +#include @@ -93,7 +94,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( wxWindow* father, PAGE_INFO pageInfo( wxT( "GERBER" ) ); GetBoard()->SetPageSettings( pageInfo ); - SetScreen( new PCB_SCREEN( pageInfo.GetSizeIU() ) ); + SetScreen( new GBR_SCREEN( pageInfo.GetSizeIU() ) ); // Create the PCB_LAYER_WIDGET *after* SetBoard(): wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); @@ -179,7 +180,7 @@ double GERBVIEW_FRAME::BestZoom() { // gives a minimal value to zoom, if no item in list if( GetBoard()->m_Drawings == NULL ) - return 160.0; + return ZOOM_FACTOR( 160.0 ); EDA_RECT bbox; BOARD_ITEM* item = GetBoard()->m_Drawings; @@ -210,7 +211,8 @@ void GERBVIEW_FRAME::LoadSettings() if( config == NULL ) return; - PCB_BASE_FRAME::LoadSettings(); +// PCB_BASE_FRAME::LoadSettings(); + EDA_DRAW_FRAME::LoadSettings(); wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() ); @@ -255,7 +257,8 @@ void GERBVIEW_FRAME::SaveSettings() if( config == NULL ) return; - PCB_BASE_FRAME::SaveSettings(); +// PCB_BASE_FRAME::SaveSettings(); + EDA_DRAW_FRAME::SaveSettings(); wxGetApp().SaveCurrentSetupValues( GetConfigurationSettings() ); @@ -408,7 +411,7 @@ void GERBVIEW_FRAME::Liste_D_Codes() D_CODE* pt_D_code; wxString Line; wxArrayString list; - double scale = MILS_TO_IU_SCALAR * 1000; + double scale = MILS_TO_IU_SCALING_FACTOR * 1000; int curr_layer = getActiveLayer(); for( int layer = 0; layer < 32; layer++ ) diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 58925dd8aa..d3e9559331 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -35,6 +35,7 @@ #include #include <../pcbnew/class_board.h> +#include class DCODE_SELECTION_BOX; @@ -53,7 +54,6 @@ class GERBER_DRAW_ITEM; class GERBVIEW_FRAME : public PCB_BASE_FRAME { - friend class PCB_LAYER_WIDGET; protected: GERBER_LAYER_WIDGET* m_LayersManager; @@ -62,7 +62,7 @@ protected: wxFileHistory m_drillFileHistory; public: - LAYER_BOX_SELECTOR* m_SelLayerBox; + LAYER_BOX_SELECTOR* m_SelLayerBox; DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight. wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about // gerber data (format..) @@ -84,7 +84,7 @@ private: bool m_show_layer_manager_tools; - // An array sting to store warning messages when reaging a gerber file. + // An array string to store warning messages when reading a gerber file. wxArrayString m_Messages; public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, @@ -226,7 +226,7 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, */ void setActiveLayer( int aLayer, bool doLayerWidgetUpdate = true ) { - ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; + ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; if( doLayerWidgetUpdate ) syncLayerWidget(); @@ -239,7 +239,7 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, */ int getActiveLayer() { - return ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer; + return ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer; } @@ -440,8 +440,6 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, */ void Block_Duplicate( wxDC* DC ); - void ToPostProcess( wxCommandEvent& event ); - /** * Function ToPlotter * Open a dialog frame to create plot and drill files diff --git a/gerbview/onleftclick.cpp b/gerbview/onleftclick.cpp index 8dee3d8b7d..41cb6126c5 100644 --- a/gerbview/onleftclick.cpp +++ b/gerbview/onleftclick.cpp @@ -21,7 +21,7 @@ */ void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) { - BOARD_ITEM* DrawStruct = GetScreen()->GetCurItem(); + EDA_ITEM* DrawStruct = GetScreen()->GetCurItem(); wxString msg; if( GetToolId() == ID_NO_TOOL_SELECTED ) @@ -36,7 +36,7 @@ void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) else { DrawStruct = Locate( aPosition, CURSEUR_OFF_GRILLE ); - GetScreen()->SetCurItem( DrawStruct ); + GetScreen()->SetCurItem( (BOARD_ITEM*)DrawStruct ); if( DrawStruct == NULL ) { GERBER_IMAGE* gerber = g_GERBER_List[getActiveLayer() ]; diff --git a/gerbview/onrightclick.cpp b/gerbview/onrightclick.cpp index bf9e24ca66..4fae60fe21 100644 --- a/gerbview/onrightclick.cpp +++ b/gerbview/onrightclick.cpp @@ -16,7 +16,7 @@ */ bool GERBVIEW_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) { - BOARD_ITEM* DrawStruct = GetScreen()->GetCurItem(); + EDA_ITEM* DrawStruct = GetScreen()->GetCurItem(); wxString msg; bool BlockActive = !GetScreen()->m_BlockLocate.IsIdle(); bool busy = DrawStruct && DrawStruct->GetFlags(); @@ -71,7 +71,7 @@ bool GERBVIEW_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) return true; if( DrawStruct ) - GetScreen()->SetCurItem( DrawStruct ); + GetScreen()->SetCurItem( (BOARD_ITEM*)DrawStruct ); return true; } diff --git a/gerbview/options.cpp b/gerbview/options.cpp index 0aa3dcbff9..b47edde65e 100644 --- a/gerbview/options.cpp +++ b/gerbview/options.cpp @@ -36,28 +36,20 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) { case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH: if( state ) - { - DisplayOpt.DisplayPadFill = m_DisplayPadFill = false; - } + DisplayOpt.DisplayPadFill = false; else - { - DisplayOpt.DisplayPadFill = m_DisplayPadFill = true; - } + DisplayOpt.DisplayPadFill = true; + m_DisplayPadFill = DisplayOpt.DisplayPadFill; m_canvas->Refresh( true ); break; case ID_TB_OPTIONS_SHOW_LINES_SKETCH: if(state ) - { - m_DisplayPcbTrackFill = false; DisplayOpt.DisplayPcbTrackFill = false; - } else - { - m_DisplayPcbTrackFill = true; DisplayOpt.DisplayPcbTrackFill = true; - } + m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill; m_canvas->Refresh( true ); break; diff --git a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp index eea3b618ca..bf3b04c33b 100644 --- a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp +++ b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp @@ -21,16 +21,16 @@ // for metric gerber units, the imperial to metric conversion is made in read functions static double scale_list[10] = { - 1000.0 * MILS_TO_IU_SCALAR, - 100.0 * MILS_TO_IU_SCALAR, - 10.0 * MILS_TO_IU_SCALAR, - 1.0 * MILS_TO_IU_SCALAR, - 0.1 * MILS_TO_IU_SCALAR, - 0.01 * MILS_TO_IU_SCALAR, - 0.001 * MILS_TO_IU_SCALAR, - 0.0001 * MILS_TO_IU_SCALAR, - 0.00001 * MILS_TO_IU_SCALAR, - 0.000001 * MILS_TO_IU_SCALAR + 1000.0 * MILS_TO_IU_SCALING_FACTOR, + 100.0 * MILS_TO_IU_SCALING_FACTOR, + 10.0 * MILS_TO_IU_SCALING_FACTOR, + 1.0 * MILS_TO_IU_SCALING_FACTOR, + 0.1 * MILS_TO_IU_SCALING_FACTOR, + 0.01 * MILS_TO_IU_SCALING_FACTOR, + 0.001 * MILS_TO_IU_SCALING_FACTOR, + 0.0001 * MILS_TO_IU_SCALING_FACTOR, + 0.00001 * MILS_TO_IU_SCALING_FACTOR, + 0.000001 * MILS_TO_IU_SCALING_FACTOR }; @@ -44,9 +44,9 @@ int scaletoIU( double aCoord, bool isMetric ) int ret; if( isMetric ) - ret = KiROUND( aCoord * MILS_TO_IU_SCALAR / 0.00254 ); + ret = KiROUND( aCoord * MILS_TO_IU_SCALING_FACTOR / 0.00254 ); else - ret = KiROUND( aCoord * MILS_TO_IU_SCALAR ); + ret = KiROUND( aCoord * MILS_TO_IU_SCALING_FACTOR ); return ret; } @@ -94,9 +94,9 @@ wxPoint GERBER_IMAGE::ReadXYCoord( char*& Text ) { // When X or Y values are float numbers, they are given in mm or inches if( m_GerbMetric ) // units are mm - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR / 0.0254 ); + current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR / 0.0254 ); else // units are inches - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR * 1000 ); + current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR * 1000 ); } else { @@ -185,9 +185,9 @@ wxPoint GERBER_IMAGE::ReadIJCoord( char*& Text ) { // When X or Y values are float numbers, they are given in mm or inches if( m_GerbMetric ) // units are mm - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR / 0.0254 ); + current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR / 0.0254 ); else // units are inches - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR * 1000 ); + current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR * 1000 ); } else { diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index 311566f0dc..3c9140795e 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -160,7 +160,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, double fcoord; // conv_scale = scaling factor from inch to Internal Unit - double conv_scale = MILS_TO_IU_SCALAR*1000; + double conv_scale = MILS_TO_IU_SCALING_FACTOR * 1000; if( m_GerbMetric ) conv_scale /= 25.4; @@ -294,7 +294,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, m_GerbMetric = false; else if( code == MILLIMETER ) m_GerbMetric = true; - conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT; + conv_scale = m_GerbMetric ? MILS_TO_IU_SCALING_FACTOR / 25.4 : MILS_TO_IU_SCALING_FACTOR; break; case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset @@ -579,8 +579,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, text += 2; // skip "C," for example - dcode->m_Size.x = dcode->m_Size.y = - KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Size.x = KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Size.y = dcode->m_Size.x; switch( stdAperture ) // Aperture desceiption has optional parameters. Read them { @@ -631,8 +631,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( *text == 'X' ) { text++; - dcode->m_Drill.x = dcode->m_Drill.y = - KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.y = dcode->m_Drill.x; dcode->m_DrillShape = APT_DEF_ROUND_HOLE; } @@ -679,8 +679,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( *text == 'X' ) { text++; - dcode->m_Drill.x = dcode->m_Drill.y = - KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.y = dcode->m_Drill.x = dcode->m_DrillShape = APT_DEF_ROUND_HOLE; } @@ -690,8 +690,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( *text == 'X' ) { text++; - dcode->m_Drill.y = - KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.y = KiROUND( ReadDouble( text ) * conv_scale ); dcode->m_DrillShape = APT_DEF_RECT_HOLE; } dcode->m_Defined = true; diff --git a/include/base_units.h b/include/base_units.h index 0d505d81ec..16276e64fb 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -35,19 +35,7 @@ #include - - - -/// Scalar to convert mils to internal units. -#if defined( PCBNEW ) -#if defined( USE_PCBNEW_NANOMETRES ) -#define MILS_TO_IU_SCALAR 25.4e3 // Pcbnew in nanometers. -#else -#define MILS_TO_IU_SCALAR 10.0 // Pcbnew in deci-mils. -#endif -#else -#define MILS_TO_IU_SCALAR 1.0 // Eeschema and anything else. -#endif +#include /** diff --git a/include/common.h b/include/common.h index ff33adfafa..e60cf9a6fc 100644 --- a/include/common.h +++ b/include/common.h @@ -39,6 +39,7 @@ #include #include +#include #if !wxUSE_PRINTING_ARCHITECTURE # error "You must use '--enable-printarch' in your wx library configuration." @@ -296,18 +297,9 @@ public: // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA, // and either deci-mils or nanometers in PCBNew. -#if defined(PCBNEW) -# if defined(KICAD_NANOMETRE) - int GetWidthIU() const { return 25400 * GetWidthMils(); } - int GetHeightIU() const { return 25400 * GetHeightMils(); } -# else - int GetWidthIU() const { return 10 * GetWidthMils(); } - int GetHeightIU() const { return 10 * GetHeightMils(); } -# endif - const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); } -#elif defined(EESCHEMA) - int GetWidthIU() const { return GetWidthMils(); } - int GetHeightIU() const { return GetHeightMils(); } +#if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) + int GetWidthIU() const { return MILS_TO_IU_SCALING_FACTOR * GetWidthMils(); } + int GetHeightIU() const { return MILS_TO_IU_SCALING_FACTOR * GetHeightMils(); } const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); } #endif diff --git a/include/convert_to_biu.h b/include/convert_to_biu.h index c6c537c6e7..333e5423e6 100644 --- a/include/convert_to_biu.h +++ b/include/convert_to_biu.h @@ -9,20 +9,37 @@ /** - * @brief inline convert functions to convert a value in decimils (or mils) - * to the internal unit used in pcbnew or cvpcb(nanometer or decimil) + * @brief some define and functions to convert a value in mils, decimils or mm + * to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or decimil) * depending on compil option */ -#if defined(PCBNEW) || defined(CVPCB) + + +/// Scaling factor to convert mils to internal units. +#if defined(PCBNEW) || defined(CVPCB) || defined(GERBVIEW) + #if defined( USE_PCBNEW_NANOMETRES ) + #if defined(GERBVIEW) + #define MM_TO_IU_SCALING_FACTOR 1e5 // Gerbview uses 10 micrometer. + #else + #define MM_TO_IU_SCALING_FACTOR 1e6 // Pcbnew uses nanometers. + #endif + #define MILS_TO_IU_SCALING_FACTOR ( MM_TO_IU_SCALING_FACTOR * 0.0254 ) + #define DECIMILS_TO_IU_SCALING_FACTOR (MM_TO_IU_SCALING_FACTOR * 0.00254 ) + #else // Pcbnew in deci-mils. + #define DECIMILS_TO_IU_SCALING_FACTOR 1 + #define MILS_TO_IU_SCALING_FACTOR 10.0 + #define MM_TO_IU_SCALING_FACTOR (1e4 / 25.4) + #endif + /// Convert mils to PCBNEW internal units (iu). inline int Mils2iu( int mils ) { #if defined( USE_PCBNEW_NANOMETRES ) - double x = mils * 25.4e3; + double x = mils * MILS_TO_IU_SCALING_FACTOR; return int( x < 0 ? x - 0.5 : x + 0.5 ); #else - return mils * 10; + return mils * MILS_TO_IU_SCALING_FACTOR; #endif } @@ -30,14 +47,17 @@ inline int Mils2iu( int mils ) inline int DMils2iu( int dmils ) { #if defined( USE_PCBNEW_NANOMETRES ) - double x = dmils * 25.4e2; + double x = dmils * DECIMILS_TO_IU_SCALING_FACTOR; return int( x < 0 ? x - 0.5 : x + 0.5 ); #else return dmils; #endif } -#elif defined(EESCHEMA) +#else // Eeschema and anything else. +#define MILS_TO_IU_SCALING_FACTOR 1.0 +#define MM_TO_IU_SCALING_FACTOR (MILS_TO_IU_SCALING_FACTOR / 0.0254) + inline int Mils2iu( int mils ) { return mils; diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 365cfa7971..104a46e3e2 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -203,7 +203,10 @@ set(PCBNEW_SRCS ### # We need some extra sources from common ### -#set(PCBNEW_COMMON_SRCS ../common/dialogs/dialog_page_settings.cpp ) +set(PCBNEW_COMMON_SRCS + ../common/dialogs/dialog_page_settings.cpp + ../common/base_units.cpp + ) ### diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index c12497f27e..13a621bfde 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -19,15 +19,11 @@ #include -#if defined( USE_PCBNEW_NANOMETRES ) -#define ZOOM_FACTOR( x ) ( x * 25.4e2 ) -#define DMIL_GRID( x ) wxRealPoint( x * 25.4e2, x * 25.4e2 ) -#define MM_GRID( x ) wxRealPoint( x * 1e6, x * 1e6 ) -#else -#define ZOOM_FACTOR( x ) x -#define DMIL_GRID( x ) wxRealPoint( x , x ) -#define MM_GRID( x ) wxRealPoint( x * 1e4 / 25.4, x * 1e4 / 25.4 ) -#endif +#define ZOOM_FACTOR( x ) ( x * DECIMILS_TO_IU_SCALING_FACTOR ) +#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_TO_IU_SCALING_FACTOR,\ + x * DECIMILS_TO_IU_SCALING_FACTOR ) +#define MM_GRID( x ) wxRealPoint( x * MM_TO_IU_SCALING_FACTOR,\ + x * MM_TO_IU_SCALING_FACTOR ) /** @@ -110,7 +106,6 @@ PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) : { wxSize displayz = wxGetDisplaySize(); - for( unsigned i = 0; i < DIM( pcbZoomList ); ++i ) m_ZoomList.Add( pcbZoomList[i] ); @@ -124,7 +119,7 @@ PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) : m_Route_Layer_TOP = LAYER_N_FRONT; // default layers pair for vias (bottom to top) m_Route_Layer_BOTTOM = LAYER_N_BACK; - SetZoom( ZOOM_FACTOR( 150 ) ); // a default value for zoom + SetZoom( ZOOM_FACTOR( 120 ) ); // a default value for zoom InitDataPoints( aPageSizeIU ); } @@ -138,11 +133,7 @@ PCB_SCREEN::~PCB_SCREEN() int PCB_SCREEN::MilsToIuScalar() { -#if defined( USE_PCBNEW_NANOMETRES ) - return 25400; -#else - return 10; -#endif + return (int)MILS_TO_IU_SCALING_FACTOR; } diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp index 19eea912fa..9f3b3e946b 100644 --- a/pcbnew/dialogs/dialog_SVG_print.cpp +++ b/pcbnew/dialogs/dialog_SVG_print.cpp @@ -271,7 +271,7 @@ bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName, g_DrawBgColor = WHITE; if( aPrint_Frame_Ref ) - m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_TO_IU_SCALAR ); + m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_TO_IU_SCALING_FACTOR ); m_Parent->PrintPage( &dc, m_PrintMaskLayer, false, &s_Parameters); g_DrawBgColor = bg_color; diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 263a9b4127..2894ece448 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -2682,7 +2682,7 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) // conversion factor for saving RAM BIUs to KICAD legacy file format. #if defined( USE_PCBNEW_NANOMETRES ) - biuToDisk = 1/1000000.0; // BIUs are nanometers & file is mm + biuToDisk = 1/MM_TO_IU_SCALING_FACTOR; // BIUs are nanometers & file is mm #else biuToDisk = 1.0; // BIUs are deci-mils #endif @@ -2694,11 +2694,8 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) // then, during the file loading process, to start a conversion from // mm to nanometers. -#if defined( USE_PCBNEW_NANOMETRES ) - diskToBiu = 2540.0; // BIUs are nanometers -#else - diskToBiu = 1.0; // BIUs are deci-mils -#endif + diskToBiu = DECIMILS_TO_IU_SCALING_FACTOR; // BIUs are nanometers if USE_PCBNEW_NANOMETRES + // or BIUs are deci-mils } diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp index 9df8d4b409..a098593ddd 100644 --- a/pcbnew/printout_controler.cpp +++ b/pcbnew/printout_controler.cpp @@ -180,12 +180,8 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() if( userscale == 0 ) // fit in page { - // Margin = 0.4 inch -#if defined(KICAD_NANOMETRE) - int extra_margin = int( 0.4 * 25400 ); // nanometers -#else - int extra_margin = int( 0.4 * 1000 ); // deci-mils -#endif + // Margin = 10mm + int extra_margin = int( 10 * MM_TO_IU_SCALING_FACTOR ); // deci-mils pageSizeIU.x = bbbox.GetWidth() + extra_margin * 2; pageSizeIU.y = bbbox.GetHeight() + extra_margin * 2; @@ -278,7 +274,8 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() int bg_color = g_DrawBgColor; if( m_PrintParams.m_Print_Sheet_Ref ) - m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize, MILS_TO_IU_SCALAR ); + m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize, + MILS_TO_IU_SCALING_FACTOR ); if( printMirror ) { diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index d30579ad35..02169a65b1 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -171,10 +171,10 @@ static inline double scale( int kicadDist ) #if defined(USE_PCBNEW_NANOMETRES) // nanometers to um - return kicadDist / 1000.0; + return kicadDist / ( MM_TO_IU_SCALING_FACTOR / 1000.0 ); // nanometers to mils - // return kicadDist/25400.0; + // return kicadDist/MILS_TO_IU_SCALING_FACTOR; #else // deci-mils to mils. @@ -185,11 +185,7 @@ static inline double scale( int kicadDist ) /// Convert integer internal units to float um static inline double IU2um( int kicadDist ) { -#if defined(USE_PCBNEW_NANOMETRES) - return kicadDist / 1000.0; -#else - return kicadDist * 25.4e-1; -#endif + return kicadDist * (1000.0 / MM_TO_IU_SCALING_FACTOR); } diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp index e24b92a36e..7858d08356 100644 --- a/pcbnew/tracepcb.cpp +++ b/pcbnew/tracepcb.cpp @@ -67,7 +67,7 @@ void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) GRSetDrawMode( DC, GR_COPY ); m_canvas->DrawBackGround( DC ); - TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALAR ); + TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALING_FACTOR ); // Redraw the footprints for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) @@ -105,7 +105,7 @@ void PCB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) m_canvas->DrawBackGround( DC ); - TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); GetBoard()->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST); diff --git a/polygon/PolyLine.cpp b/polygon/PolyLine.cpp index ff4753c749..113bd0eba4 100644 --- a/polygon/PolyLine.cpp +++ b/polygon/PolyLine.cpp @@ -357,9 +357,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector< else { // style is ARC_CW or ARC_CCW - int n; // number of steps for arcs - n = ( abs( x2 - x1 ) + abs( y2 - y1 ) ) / (CArc::MAX_STEP); - n = MAX( n, CArc::MIN_STEPS ); // or at most 5 degrees of arc + int n = CArc::ARC_STEPS; n_vertices += n; n_arcs++; } @@ -392,8 +390,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector< { // style is arc_cw or arc_ccw int n; // number of steps for arcs - n = ( abs( x2 - x1 ) + abs( y2 - y1 ) ) / (CArc::MAX_STEP); - n = MAX( n, CArc::MIN_STEPS ); // or at most 5 degrees of arc + n = CArc::ARC_STEPS; double xo, yo, theta1, theta2, a, b; a = fabs( (double) (x1 - x2) ); b = fabs( (double) (y1 - y2) ); diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index fc44f87755..3aa6ba60f3 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -77,8 +77,7 @@ public: class CArc { public: - enum { MAX_STEP = 50 * 25400 }; // max step is 20 mils - enum { MIN_STEPS = 18 }; // min step is 5 degrees + enum { ARC_STEPS = 16 }; // arc approximation step is 16 segm / 90 degres int style; int xi, yi, xf, yf; int n_steps; // number of straight-line segments in gpc_poly From a00df5b3305fc89befdf0a93508705ca15c111c2 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 25 Apr 2012 21:46:30 +0200 Subject: [PATCH 06/11] commit missing files --- gerbview/class_gbr_screen.cpp | 122 ++++++++++++++++++++++++++++++++++ gerbview/class_gbr_screen.h | 33 +++++++++ 2 files changed, 155 insertions(+) create mode 100644 gerbview/class_gbr_screen.cpp create mode 100644 gerbview/class_gbr_screen.h diff --git a/gerbview/class_gbr_screen.cpp b/gerbview/class_gbr_screen.cpp new file mode 100644 index 0000000000..82dd28314a --- /dev/null +++ b/gerbview/class_gbr_screen.cpp @@ -0,0 +1,122 @@ +/** + * @file classpcb.cpp + * @brief Member functions of classes used in Pcbnew (see pcbstruct.h) + * except for tracks (see class_track.cpp). + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + + +#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_TO_IU_SCALING_FACTOR,\ + x * DECIMILS_TO_IU_SCALING_FACTOR ) +#define MM_GRID( x ) wxRealPoint( x * MM_TO_IU_SCALING_FACTOR,\ + x * MM_TO_IU_SCALING_FACTOR ) + + +/** + Default Pcbnew zoom values. + Limited to 19 values to keep a decent size to menus. + Roughly a 1.5 progression. + The last 2 values are handy when somebody uses a library import of a module + (or foreign data) which has a bad coordinate. + Also useful in GerbView for this reason. + Zoom 5 and 10 can create artefacts when drawing (integer overflow in low level graphic + functions ) +*/ +static const double gbrZoomList[] = +{ + ZOOM_FACTOR( 0.5 ), + ZOOM_FACTOR( 1.0 ), + ZOOM_FACTOR( 1.5 ), + ZOOM_FACTOR( 2.0 ), + ZOOM_FACTOR( 3.0 ), + ZOOM_FACTOR( 4.5 ), + ZOOM_FACTOR( 7.0 ), + ZOOM_FACTOR( 10.0 ), + ZOOM_FACTOR( 15.0 ), + ZOOM_FACTOR( 22.0 ), + ZOOM_FACTOR( 35.0 ), + ZOOM_FACTOR( 50.0 ), + ZOOM_FACTOR( 80.0 ), + ZOOM_FACTOR( 120.0 ), + ZOOM_FACTOR( 200.0 ), + ZOOM_FACTOR( 350.0 ), + ZOOM_FACTOR( 500.0 ), + ZOOM_FACTOR( 1000.0 ), + ZOOM_FACTOR( 2000.0 ) +}; + + +// Default grid sizes for PCB editor screens. +static GRID_TYPE gbrGridList[] = +{ + // predefined grid list in 0.0001 inches + { ID_POPUP_GRID_LEVEL_1000, DMIL_GRID( 1000 ) }, + { ID_POPUP_GRID_LEVEL_500, DMIL_GRID( 500 ) }, + { ID_POPUP_GRID_LEVEL_250, DMIL_GRID( 250 ) }, + { ID_POPUP_GRID_LEVEL_200, DMIL_GRID( 200 ) }, + { ID_POPUP_GRID_LEVEL_100, DMIL_GRID( 100 ) }, + { ID_POPUP_GRID_LEVEL_50, DMIL_GRID( 50 ) }, + { ID_POPUP_GRID_LEVEL_25, DMIL_GRID( 25 ) }, + { ID_POPUP_GRID_LEVEL_20, DMIL_GRID( 20 ) }, + { ID_POPUP_GRID_LEVEL_10, DMIL_GRID( 10 ) }, + { ID_POPUP_GRID_LEVEL_5, DMIL_GRID( 5 ) }, + { ID_POPUP_GRID_LEVEL_2, DMIL_GRID( 2 ) }, + { ID_POPUP_GRID_LEVEL_1, DMIL_GRID( 1 ) }, + + // predefined grid list in mm + { ID_POPUP_GRID_LEVEL_5MM, MM_GRID( 5.0 ) }, + { ID_POPUP_GRID_LEVEL_2_5MM, MM_GRID( 2.5 ) }, + { ID_POPUP_GRID_LEVEL_1MM, MM_GRID( 1.0 ) }, + { ID_POPUP_GRID_LEVEL_0_5MM, MM_GRID( 0.5 ) }, + { ID_POPUP_GRID_LEVEL_0_25MM, MM_GRID( 0.25 ) }, + { ID_POPUP_GRID_LEVEL_0_2MM, MM_GRID( 0.2 ) }, + { ID_POPUP_GRID_LEVEL_0_1MM, MM_GRID( 0.1 ) }, + { ID_POPUP_GRID_LEVEL_0_0_5MM, MM_GRID( 0.05 ) }, + { ID_POPUP_GRID_LEVEL_0_0_25MM, MM_GRID( 0.025 ) }, + { ID_POPUP_GRID_LEVEL_0_0_1MM, MM_GRID( 0.01 ) } +}; + + +GBR_SCREEN::GBR_SCREEN( const wxSize& aPageSizeIU ) : + PCB_SCREEN( aPageSizeIU ) +{ + // Replace zoom and grid lists already set by PCB_SCREEN ctor + m_ZoomList.Clear(); + for( unsigned i = 0; i < DIM( gbrZoomList ); ++i ) + m_ZoomList.Add( gbrZoomList[i] ); + + GRIDS gridlist; + for( unsigned i = 0; i < DIM( gbrGridList ); ++i ) + gridlist.push_back( gbrGridList[i] ); + SetGridList( gridlist ); + + // Set the working grid size to a reasonnable value (in 1/10000 inch) + SetGrid( DMIL_GRID( 500 ) ); + + m_Active_Layer = LAYER_N_BACK; // default active layer = bottom layer + + SetZoom( ZOOM_FACTOR( 350 ) ); // a default value for zoom +} + + +GBR_SCREEN::~GBR_SCREEN() +{ +} + + +// virtual function +int GBR_SCREEN::MilsToIuScalar() +{ + return (int)MILS_TO_IU_SCALING_FACTOR; +} diff --git a/gerbview/class_gbr_screen.h b/gerbview/class_gbr_screen.h new file mode 100644 index 0000000000..d903de80bf --- /dev/null +++ b/gerbview/class_gbr_screen.h @@ -0,0 +1,33 @@ +/** + * @file class_gbr_screen.h + */ + +#ifndef CLASS_GBR_SCREEN_H_ +#define CLASS_GBR_SCREEN_H_ + + +#include +#include + +#define ZOOM_FACTOR( x ) ( x * DECIMILS_TO_IU_SCALING_FACTOR ) + + +/* Handle info to display a board */ +class GBR_SCREEN : public PCB_SCREEN +{ +public: + + /** + * Constructor + * @param aPageSizeIU is the size of the initial paper page in internal units. + */ + GBR_SCREEN( const wxSize& aPageSizeIU ); + + ~GBR_SCREEN(); + + GBR_SCREEN* Next() { return (GBR_SCREEN*) Pnext; } + + virtual int MilsToIuScalar(); +}; + +#endif // CLASS_GBR_SCREEN_H_ From 3b671e09d1a429e3084fec8dc8d556ab30e025cd Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 26 Apr 2012 22:21:31 +0200 Subject: [PATCH 07/11] All: change MILS_TO_IU_SCALING_FACTOR constant to MILS_PER_IU ( and MM_TO_IU_SCALING_FACTOR to MM_PER_IU) Also fix bug 985654. --- common/base_units.cpp | 8 +- common/eda_text.cpp | 2 +- eeschema/dialogs/dialog_SVG_print.cpp | 578 +++++++++--------- .../dialogs/dialog_print_using_printer.cpp | 2 +- eeschema/eeredraw.cpp | 2 +- eeschema/schframe.cpp | 2 +- gerbview/class_gbr_screen.cpp | 10 +- gerbview/class_gbr_screen.h | 2 +- gerbview/dcode.cpp | 4 +- gerbview/draw_gerber_screen.cpp | 2 +- gerbview/excellon_read_drill_file.cpp | 2 +- gerbview/gerbview_frame.cpp | 2 +- gerbview/rs274_read_XY_and_IJ_coordinates.cpp | 32 +- gerbview/rs274x.cpp | 4 +- include/common.h | 4 +- include/convert_to_biu.h | 24 +- pcbnew/classpcb.cpp | 12 +- pcbnew/dialogs/dialog_SVG_print.cpp | 2 +- pcbnew/legacy_plugin.cpp | 4 +- pcbnew/printout_controler.cpp | 6 +- pcbnew/specctra_export.cpp | 8 +- pcbnew/tracepcb.cpp | 4 +- 22 files changed, 358 insertions(+), 358 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index e8f19ba119..39b5890b63 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -41,10 +41,10 @@ #if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) -#define IU_TO_MM( x ) ( x / MM_TO_IU_SCALING_FACTOR ) -#define IU_TO_IN( x ) ( x / MILS_TO_IU_SCALING_FACTOR / 1000 ) -#define MM_TO_IU( x ) ( x * MM_TO_IU_SCALING_FACTOR ) -#define IN_TO_IU( x ) ( x * MILS_TO_IU_SCALING_FACTOR * 1000 ) +#define IU_TO_MM( x ) ( x / MM_PER_IU ) +#define IU_TO_IN( x ) ( x / MILS_PER_IU / 1000 ) +#define MM_TO_IU( x ) ( x * MM_PER_IU ) +#define IN_TO_IU( x ) ( x * MILS_PER_IU * 1000 ) #else #error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW." #endif diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 1ade6a903c..56c70a1d79 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -37,7 +37,7 @@ // Conversion to application internal units defined at build time. #if defined( PCBNEW ) #include -#define MILS_TO_IU( x ) ( x * MILS_TO_IU_SCALING_FACTOR ); +#define MILS_TO_IU( x ) ( x * MILS_PER_IU ); #elif defined( EESCHEMA ) #include #define MILS_TO_IU( x ) ( x ) diff --git a/eeschema/dialogs/dialog_SVG_print.cpp b/eeschema/dialogs/dialog_SVG_print.cpp index 81dd581af5..27ef2de71e 100644 --- a/eeschema/dialogs/dialog_SVG_print.cpp +++ b/eeschema/dialogs/dialog_SVG_print.cpp @@ -1,289 +1,289 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/** - * @file eeschema/dialogs/dialog_SVG_print.cpp - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - - -// Keys for configuration -#define PLOTSVGMODECOLOR_KEY wxT( "PlotSVGModeColor" ) - -#define WIDTH_MAX_VALUE 100 -#define WIDTH_MIN_VALUE 1 - -// Variables locales -static bool s_Print_Frame_Ref = true; -static int s_PlotBlackAndWhite = 0; - - -/*! - * DIALOG_SVG_PRINT functions - */ -DIALOG_SVG_PRINT::DIALOG_SVG_PRINT( EDA_DRAW_FRAME* parent ) : - DIALOG_SVG_PRINT_base( parent ) -{ - m_Parent = parent; - m_Config = wxGetApp().GetSettings(); -} - - -void DIALOG_SVG_PRINT::OnInitDialog( wxInitDialogEvent& event ) -{ - SetFocus(); // Make ESC key working - - if( m_Config ) - { - m_Config->Read( PLOTSVGMODECOLOR_KEY, &s_PlotBlackAndWhite ); - } - - m_ModeColorOption->SetSelection( s_PlotBlackAndWhite ); - - AddUnitSymbol( *m_TextPenWidth, g_UserUnit ); - m_DialogPenWidth->SetValue( - ReturnStringFromValue( g_UserUnit, g_DrawDefaultLineThickness ) ); - m_Print_Sheet_Ref->SetValue( s_Print_Frame_Ref ); - - if( GetSizer() ) - { - GetSizer()->SetSizeHints( this ); - } -} - - -void DIALOG_SVG_PRINT::SetPenWidth() -{ - g_DrawDefaultLineThickness = ReturnValueFromTextCtrl( *m_DialogPenWidth ); - - if( g_DrawDefaultLineThickness > WIDTH_MAX_VALUE ) - { - g_DrawDefaultLineThickness = WIDTH_MAX_VALUE; - } - - if( g_DrawDefaultLineThickness < WIDTH_MIN_VALUE ) - { - g_DrawDefaultLineThickness = WIDTH_MIN_VALUE; - } - - m_DialogPenWidth->SetValue( - ReturnStringFromValue( g_UserUnit, g_DrawDefaultLineThickness ) ); -} - - -void DIALOG_SVG_PRINT::PrintSVGDoc( bool aPrintAll, bool aPrint_Sheet_Ref ) -{ - wxString msg; - wxFileName fn; - - SetPenWidth(); - - g_DrawDefaultLineThickness = - ReturnValueFromTextCtrl( *m_DialogPenWidth ); - - SCH_SCREEN* screen = (SCH_SCREEN*) m_Parent->GetScreen(); - - if( aPrintAll && m_Parent->IsType( SCHEMATIC_FRAME ) ) - { - SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_Parent; - SCH_SHEET_PATH* sheetpath; - SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet(); - SCH_SCREEN* schscreen = schframe->GetScreen(); - SCH_SHEET_LIST SheetList( NULL ); - sheetpath = SheetList.GetFirst(); - SCH_SHEET_PATH list; - - for( ; ; ) - { - if( sheetpath == NULL ) - break; - - list.Clear(); - - if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) - { - schframe->SetCurrentSheet( list ); - schframe->GetCurrentSheet().UpdateAllScreenReferences(); - schframe->SetSheetNumberAndCount(); - schscreen = schframe->GetCurrentSheet().LastScreen(); - } - else // Should not happen - return; - - sheetpath = SheetList.GetNext(); - - fn = schframe->GetUniqueFilenameForCurrentSheet() + wxT( ".svg" ); - - bool success = DrawSVGPage( m_Parent, fn.GetFullPath(), ( SCH_SCREEN* ) schscreen, - m_ModeColorOption->GetSelection() == 0 ? false : true, - aPrint_Sheet_Ref ); - msg = _( "Create file " ) + fn.GetFullPath(); - if( !success ) - msg += _( " error" ); - msg += wxT( "\n" ); - m_MessagesBox->AppendText( msg ); - } - - schframe->SetCurrentSheet( oldsheetpath ); - schframe->GetCurrentSheet().UpdateAllScreenReferences(); - schframe->SetSheetNumberAndCount(); - } - else - { - fn = m_FileNameCtrl->GetValue(); - - if( !fn.IsOk() ) - fn = screen->GetFileName(); - - fn.SetExt( wxT( "svg" ) ); - fn.MakeAbsolute(); - - bool success = DrawSVGPage( m_Parent, fn.GetFullPath(), ( SCH_SCREEN* ) screen, - m_ModeColorOption->GetSelection() == 0 ? false : true, - aPrint_Sheet_Ref ); - msg = _( "Create file " ) + fn.GetFullPath(); - - if( !success ) - msg += _( " error" ); - - msg += wxT( "\n" ); - m_MessagesBox->AppendText( msg ); - } -} - - -bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame, - const wxString& FullFileName, - SCH_SCREEN* screen, - bool aPrintBlackAndWhite, - bool aPrint_Sheet_Ref ) -{ - int tmpzoom; - wxPoint tmp_startvisu; - wxSize sheetSize; // Sheet size in internal units - wxPoint old_org; - bool success = true; - - tmp_startvisu = screen->m_StartVisu; - tmpzoom = screen->GetZoom(); - old_org = screen->m_DrawOrg; - screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0; - screen->m_StartVisu.x = screen->m_StartVisu.y = 0; - - sheetSize = screen->GetPageSettings().GetSizeIU(); // page size in 1/1000 inch, ie in internal units - - screen->SetScalingFactor( 1.0 ); - EDA_DRAW_PANEL* panel = frame->GetCanvas(); - - LOCALE_IO toggle; - - float dpi = 1000.0; - KicadSVGFileDC dc( FullFileName, sheetSize.x, sheetSize.y, dpi ); - - EDA_RECT tmp = *panel->GetClipBox(); - GRResetPenAndBrush( &dc ); - GRForceBlackPen( aPrintBlackAndWhite ); - - - panel->SetClipBox( EDA_RECT( wxPoint( -0x3FFFFF0, -0x3FFFFF0 ), - wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) ); - - screen->m_IsPrinting = true; - - if( frame->IsType( SCHEMATIC_FRAME ) ) - screen->Draw( panel, &dc, GR_COPY ); - - if( frame->IsType( LIBEDITOR_FRAME ) ) - ((LIB_EDIT_FRAME*)frame)->RedrawComponent( &dc, - wxPoint(sheetSize.x/2, - sheetSize.y/2) ); - - if( aPrint_Sheet_Ref ) - frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); - - screen->m_IsPrinting = false; - panel->SetClipBox( tmp ); - - GRForceBlackPen( false ); - - screen->m_StartVisu = tmp_startvisu; - screen->m_DrawOrg = old_org; - screen->SetZoom( tmpzoom ); - - return success; -} - - -void DIALOG_SVG_PRINT::OnButtonPlotAllClick( wxCommandEvent& event ) -{ - PrintSVGDoc( true, m_Print_Sheet_Ref->GetValue() ); -} - - -void DIALOG_SVG_PRINT::OnButtonPlotCurrentClick( wxCommandEvent& event ) -{ - PrintSVGDoc( false, m_Print_Sheet_Ref->GetValue() ); -} - - -void DIALOG_SVG_PRINT::OnButtonCancelClick( wxCommandEvent& event ) -{ - Close(); -} - - -void DIALOG_SVG_PRINT::OnCloseWindow( wxCloseEvent& event ) -{ - if( m_Config ) - { - s_PlotBlackAndWhite = m_ModeColorOption->GetSelection(); - m_Config->Write( PLOTSVGMODECOLOR_KEY, s_PlotBlackAndWhite ); - } - EndModal( 0 ); -} - - -/* called on radiobox color/black and white selection - */ -void DIALOG_SVG_PRINT::OnSetColorModeSelected( wxCommandEvent& event ) -{ - s_PlotBlackAndWhite = m_ModeColorOption->GetSelection(); -} +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * @file eeschema/dialogs/dialog_SVG_print.cpp + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + + +// Keys for configuration +#define PLOTSVGMODECOLOR_KEY wxT( "PlotSVGModeColor" ) + +#define WIDTH_MAX_VALUE 100 +#define WIDTH_MIN_VALUE 1 + +// Variables locales +static bool s_Print_Frame_Ref = true; +static int s_PlotBlackAndWhite = 0; + + +/*! + * DIALOG_SVG_PRINT functions + */ +DIALOG_SVG_PRINT::DIALOG_SVG_PRINT( EDA_DRAW_FRAME* parent ) : + DIALOG_SVG_PRINT_base( parent ) +{ + m_Parent = parent; + m_Config = wxGetApp().GetSettings(); +} + + +void DIALOG_SVG_PRINT::OnInitDialog( wxInitDialogEvent& event ) +{ + SetFocus(); // Make ESC key working + + if( m_Config ) + { + m_Config->Read( PLOTSVGMODECOLOR_KEY, &s_PlotBlackAndWhite ); + } + + m_ModeColorOption->SetSelection( s_PlotBlackAndWhite ); + + AddUnitSymbol( *m_TextPenWidth, g_UserUnit ); + m_DialogPenWidth->SetValue( + ReturnStringFromValue( g_UserUnit, g_DrawDefaultLineThickness ) ); + m_Print_Sheet_Ref->SetValue( s_Print_Frame_Ref ); + + if( GetSizer() ) + { + GetSizer()->SetSizeHints( this ); + } +} + + +void DIALOG_SVG_PRINT::SetPenWidth() +{ + g_DrawDefaultLineThickness = ReturnValueFromTextCtrl( *m_DialogPenWidth ); + + if( g_DrawDefaultLineThickness > WIDTH_MAX_VALUE ) + { + g_DrawDefaultLineThickness = WIDTH_MAX_VALUE; + } + + if( g_DrawDefaultLineThickness < WIDTH_MIN_VALUE ) + { + g_DrawDefaultLineThickness = WIDTH_MIN_VALUE; + } + + m_DialogPenWidth->SetValue( + ReturnStringFromValue( g_UserUnit, g_DrawDefaultLineThickness ) ); +} + + +void DIALOG_SVG_PRINT::PrintSVGDoc( bool aPrintAll, bool aPrint_Sheet_Ref ) +{ + wxString msg; + wxFileName fn; + + SetPenWidth(); + + g_DrawDefaultLineThickness = + ReturnValueFromTextCtrl( *m_DialogPenWidth ); + + SCH_SCREEN* screen = (SCH_SCREEN*) m_Parent->GetScreen(); + + if( aPrintAll && m_Parent->IsType( SCHEMATIC_FRAME ) ) + { + SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_Parent; + SCH_SHEET_PATH* sheetpath; + SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet(); + SCH_SCREEN* schscreen = schframe->GetScreen(); + SCH_SHEET_LIST SheetList( NULL ); + sheetpath = SheetList.GetFirst(); + SCH_SHEET_PATH list; + + for( ; ; ) + { + if( sheetpath == NULL ) + break; + + list.Clear(); + + if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) + { + schframe->SetCurrentSheet( list ); + schframe->GetCurrentSheet().UpdateAllScreenReferences(); + schframe->SetSheetNumberAndCount(); + schscreen = schframe->GetCurrentSheet().LastScreen(); + } + else // Should not happen + return; + + sheetpath = SheetList.GetNext(); + + fn = schframe->GetUniqueFilenameForCurrentSheet() + wxT( ".svg" ); + + bool success = DrawSVGPage( m_Parent, fn.GetFullPath(), ( SCH_SCREEN* ) schscreen, + m_ModeColorOption->GetSelection() == 0 ? false : true, + aPrint_Sheet_Ref ); + msg = _( "Create file " ) + fn.GetFullPath(); + if( !success ) + msg += _( " error" ); + msg += wxT( "\n" ); + m_MessagesBox->AppendText( msg ); + } + + schframe->SetCurrentSheet( oldsheetpath ); + schframe->GetCurrentSheet().UpdateAllScreenReferences(); + schframe->SetSheetNumberAndCount(); + } + else + { + fn = m_FileNameCtrl->GetValue(); + + if( !fn.IsOk() ) + fn = screen->GetFileName(); + + fn.SetExt( wxT( "svg" ) ); + fn.MakeAbsolute(); + + bool success = DrawSVGPage( m_Parent, fn.GetFullPath(), ( SCH_SCREEN* ) screen, + m_ModeColorOption->GetSelection() == 0 ? false : true, + aPrint_Sheet_Ref ); + msg = _( "Create file " ) + fn.GetFullPath(); + + if( !success ) + msg += _( " error" ); + + msg += wxT( "\n" ); + m_MessagesBox->AppendText( msg ); + } +} + + +bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame, + const wxString& FullFileName, + SCH_SCREEN* screen, + bool aPrintBlackAndWhite, + bool aPrint_Sheet_Ref ) +{ + int tmpzoom; + wxPoint tmp_startvisu; + wxSize sheetSize; // Sheet size in internal units + wxPoint old_org; + bool success = true; + + tmp_startvisu = screen->m_StartVisu; + tmpzoom = screen->GetZoom(); + old_org = screen->m_DrawOrg; + screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0; + screen->m_StartVisu.x = screen->m_StartVisu.y = 0; + + sheetSize = screen->GetPageSettings().GetSizeIU(); // page size in 1/1000 inch, ie in internal units + + screen->SetScalingFactor( 1.0 ); + EDA_DRAW_PANEL* panel = frame->GetCanvas(); + + LOCALE_IO toggle; + + float dpi = 1000.0; + KicadSVGFileDC dc( FullFileName, sheetSize.x, sheetSize.y, dpi ); + + EDA_RECT tmp = *panel->GetClipBox(); + GRResetPenAndBrush( &dc ); + GRForceBlackPen( aPrintBlackAndWhite ); + + + panel->SetClipBox( EDA_RECT( wxPoint( -0x3FFFFF0, -0x3FFFFF0 ), + wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) ); + + screen->m_IsPrinting = true; + + if( frame->IsType( SCHEMATIC_FRAME ) ) + screen->Draw( panel, &dc, GR_COPY ); + + if( frame->IsType( LIBEDITOR_FRAME ) ) + ((LIB_EDIT_FRAME*)frame)->RedrawComponent( &dc, + wxPoint(sheetSize.x/2, + sheetSize.y/2) ); + + if( aPrint_Sheet_Ref ) + frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_PER_IU ); + + screen->m_IsPrinting = false; + panel->SetClipBox( tmp ); + + GRForceBlackPen( false ); + + screen->m_StartVisu = tmp_startvisu; + screen->m_DrawOrg = old_org; + screen->SetZoom( tmpzoom ); + + return success; +} + + +void DIALOG_SVG_PRINT::OnButtonPlotAllClick( wxCommandEvent& event ) +{ + PrintSVGDoc( true, m_Print_Sheet_Ref->GetValue() ); +} + + +void DIALOG_SVG_PRINT::OnButtonPlotCurrentClick( wxCommandEvent& event ) +{ + PrintSVGDoc( false, m_Print_Sheet_Ref->GetValue() ); +} + + +void DIALOG_SVG_PRINT::OnButtonCancelClick( wxCommandEvent& event ) +{ + Close(); +} + + +void DIALOG_SVG_PRINT::OnCloseWindow( wxCloseEvent& event ) +{ + if( m_Config ) + { + s_PlotBlackAndWhite = m_ModeColorOption->GetSelection(); + m_Config->Write( PLOTSVGMODECOLOR_KEY, s_PlotBlackAndWhite ); + } + EndModal( 0 ); +} + + +/* called on radiobox color/black and white selection + */ +void DIALOG_SVG_PRINT::OnSetColorModeSelected( wxCommandEvent& event ) +{ + s_PlotBlackAndWhite = m_ModeColorOption->GetSelection(); +} diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index 91f9c80eaa..deef5807ee 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -378,7 +378,7 @@ void SCH_PRINTOUT::DrawPage( SCH_SCREEN* aScreen ) aScreen->Draw( panel, dc, GR_DEFAULT_DRAWMODE ); if( printReference ) - parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); + parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_PER_IU ); g_DrawBgColor = bg_color; aScreen->m_IsPrinting = false; diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index 62dfba469c..93893cc81c 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -71,7 +71,7 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) GetScreen()->Draw( m_canvas, DC, GR_DEFAULT_DRAWMODE ); - TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); + TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_PER_IU ); #ifdef USE_WX_OVERLAY if( IsShown() ) diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index dddbf29ff7..5f16c9d2c9 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -863,7 +863,7 @@ void SCH_EDIT_FRAME::SVG_Print( wxCommandEvent& event ) void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData ) { GetScreen()->Draw( m_canvas, aDC, GR_DEFAULT_DRAWMODE ); - TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); + TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_PER_IU ); } diff --git a/gerbview/class_gbr_screen.cpp b/gerbview/class_gbr_screen.cpp index 82dd28314a..f4ae6293a5 100644 --- a/gerbview/class_gbr_screen.cpp +++ b/gerbview/class_gbr_screen.cpp @@ -17,10 +17,10 @@ #include -#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_TO_IU_SCALING_FACTOR,\ - x * DECIMILS_TO_IU_SCALING_FACTOR ) -#define MM_GRID( x ) wxRealPoint( x * MM_TO_IU_SCALING_FACTOR,\ - x * MM_TO_IU_SCALING_FACTOR ) +#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_PER_IU,\ + x * DECIMILS_PER_IU ) +#define MM_GRID( x ) wxRealPoint( x * MM_PER_IU,\ + x * MM_PER_IU ) /** @@ -118,5 +118,5 @@ GBR_SCREEN::~GBR_SCREEN() // virtual function int GBR_SCREEN::MilsToIuScalar() { - return (int)MILS_TO_IU_SCALING_FACTOR; + return (int)MILS_PER_IU; } diff --git a/gerbview/class_gbr_screen.h b/gerbview/class_gbr_screen.h index d903de80bf..ede5be2de7 100644 --- a/gerbview/class_gbr_screen.h +++ b/gerbview/class_gbr_screen.h @@ -9,7 +9,7 @@ #include #include -#define ZOOM_FACTOR( x ) ( x * DECIMILS_TO_IU_SCALING_FACTOR ) +#define ZOOM_FACTOR( x ) ( x * DECIMILS_PER_IU ) /* Handle info to display a board */ diff --git a/gerbview/dcode.cpp b/gerbview/dcode.cpp index dd00855ff6..fb96c3ba78 100644 --- a/gerbview/dcode.cpp +++ b/gerbview/dcode.cpp @@ -175,8 +175,8 @@ int GERBVIEW_FRAME::ReadDCodeDefinitionFile( const wxString& D_Code_FullFileName /* Updating gerber scale: */ - double dcode_scale = MILS_TO_IU_SCALING_FACTOR; // By uniting dCode = mil, - // internal unit = MILS_TO_IU_SCALING_FACTOR + double dcode_scale = MILS_PER_IU; // By uniting dCode = mil, + // internal unit = MILS_PER_IU current_Dcode = 0; if( D_Code_FullFileName.IsEmpty() ) diff --git a/gerbview/draw_gerber_screen.cpp b/gerbview/draw_gerber_screen.cpp index 4f54dc047d..6c09f37e47 100644 --- a/gerbview/draw_gerber_screen.cpp +++ b/gerbview/draw_gerber_screen.cpp @@ -107,7 +107,7 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) if( IsElementVisible( DCODES_VISIBLE ) ) DrawItemsDCodeID( DC, GR_COPY ); - TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALING_FACTOR ); + TraceWorkSheet( DC, screen, 0, MILS_PER_IU ); if( m_canvas->IsMouseCaptured() ) m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp index ccfada1cf2..8335b790c1 100644 --- a/gerbview/excellon_read_drill_file.cpp +++ b/gerbview/excellon_read_drill_file.cpp @@ -432,7 +432,7 @@ bool EXCELLON_IMAGE::Execute_HEADER_Command( char*& text ) if( dcode == NULL ) break; // conv_scale = scaling factor from inch to Internal Unit - double conv_scale = MILS_TO_IU_SCALING_FACTOR * 1000; + double conv_scale = MILS_PER_IU * 1000; if( m_GerbMetric ) conv_scale /= 25.4; diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index d6eeb122da..e254438066 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -411,7 +411,7 @@ void GERBVIEW_FRAME::Liste_D_Codes() D_CODE* pt_D_code; wxString Line; wxArrayString list; - double scale = MILS_TO_IU_SCALING_FACTOR * 1000; + double scale = MILS_PER_IU * 1000; int curr_layer = getActiveLayer(); for( int layer = 0; layer < 32; layer++ ) diff --git a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp index bf3b04c33b..9fa669acb9 100644 --- a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp +++ b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp @@ -21,16 +21,16 @@ // for metric gerber units, the imperial to metric conversion is made in read functions static double scale_list[10] = { - 1000.0 * MILS_TO_IU_SCALING_FACTOR, - 100.0 * MILS_TO_IU_SCALING_FACTOR, - 10.0 * MILS_TO_IU_SCALING_FACTOR, - 1.0 * MILS_TO_IU_SCALING_FACTOR, - 0.1 * MILS_TO_IU_SCALING_FACTOR, - 0.01 * MILS_TO_IU_SCALING_FACTOR, - 0.001 * MILS_TO_IU_SCALING_FACTOR, - 0.0001 * MILS_TO_IU_SCALING_FACTOR, - 0.00001 * MILS_TO_IU_SCALING_FACTOR, - 0.000001 * MILS_TO_IU_SCALING_FACTOR + 1000.0 * MILS_PER_IU, + 100.0 * MILS_PER_IU, + 10.0 * MILS_PER_IU, + 1.0 * MILS_PER_IU, + 0.1 * MILS_PER_IU, + 0.01 * MILS_PER_IU, + 0.001 * MILS_PER_IU, + 0.0001 * MILS_PER_IU, + 0.00001 * MILS_PER_IU, + 0.000001 * MILS_PER_IU }; @@ -44,9 +44,9 @@ int scaletoIU( double aCoord, bool isMetric ) int ret; if( isMetric ) - ret = KiROUND( aCoord * MILS_TO_IU_SCALING_FACTOR / 0.00254 ); + ret = KiROUND( aCoord * MILS_PER_IU / 0.00254 ); else - ret = KiROUND( aCoord * MILS_TO_IU_SCALING_FACTOR ); + ret = KiROUND( aCoord * MILS_PER_IU ); return ret; } @@ -94,9 +94,9 @@ wxPoint GERBER_IMAGE::ReadXYCoord( char*& Text ) { // When X or Y values are float numbers, they are given in mm or inches if( m_GerbMetric ) // units are mm - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR / 0.0254 ); + current_coord = KiROUND( atof( line ) * MILS_PER_IU / 0.0254 ); else // units are inches - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR * 1000 ); + current_coord = KiROUND( atof( line ) * MILS_PER_IU * 1000 ); } else { @@ -185,9 +185,9 @@ wxPoint GERBER_IMAGE::ReadIJCoord( char*& Text ) { // When X or Y values are float numbers, they are given in mm or inches if( m_GerbMetric ) // units are mm - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR / 0.0254 ); + current_coord = KiROUND( atof( line ) * MILS_PER_IU / 0.0254 ); else // units are inches - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR * 1000 ); + current_coord = KiROUND( atof( line ) * MILS_PER_IU * 1000 ); } else { diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index 3c9140795e..f879f4f9fe 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -160,7 +160,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, double fcoord; // conv_scale = scaling factor from inch to Internal Unit - double conv_scale = MILS_TO_IU_SCALING_FACTOR * 1000; + double conv_scale = MILS_PER_IU * 1000; if( m_GerbMetric ) conv_scale /= 25.4; @@ -294,7 +294,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, m_GerbMetric = false; else if( code == MILLIMETER ) m_GerbMetric = true; - conv_scale = m_GerbMetric ? MILS_TO_IU_SCALING_FACTOR / 25.4 : MILS_TO_IU_SCALING_FACTOR; + conv_scale = m_GerbMetric ? MILS_PER_IU / 25.4 : MILS_PER_IU; break; case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset diff --git a/include/common.h b/include/common.h index e60cf9a6fc..86ee71860f 100644 --- a/include/common.h +++ b/include/common.h @@ -298,8 +298,8 @@ public: // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA, // and either deci-mils or nanometers in PCBNew. #if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) - int GetWidthIU() const { return MILS_TO_IU_SCALING_FACTOR * GetWidthMils(); } - int GetHeightIU() const { return MILS_TO_IU_SCALING_FACTOR * GetHeightMils(); } + int GetWidthIU() const { return MILS_PER_IU * GetWidthMils(); } + int GetHeightIU() const { return MILS_PER_IU * GetHeightMils(); } const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); } #endif diff --git a/include/convert_to_biu.h b/include/convert_to_biu.h index 333e5423e6..8581550a0b 100644 --- a/include/convert_to_biu.h +++ b/include/convert_to_biu.h @@ -20,26 +20,26 @@ #if defined(PCBNEW) || defined(CVPCB) || defined(GERBVIEW) #if defined( USE_PCBNEW_NANOMETRES ) #if defined(GERBVIEW) - #define MM_TO_IU_SCALING_FACTOR 1e5 // Gerbview uses 10 micrometer. + #define MM_PER_IU 1e5 // Gerbview uses 10 micrometer. #else - #define MM_TO_IU_SCALING_FACTOR 1e6 // Pcbnew uses nanometers. + #define MM_PER_IU 1e6 // Pcbnew uses nanometers. #endif - #define MILS_TO_IU_SCALING_FACTOR ( MM_TO_IU_SCALING_FACTOR * 0.0254 ) - #define DECIMILS_TO_IU_SCALING_FACTOR (MM_TO_IU_SCALING_FACTOR * 0.00254 ) + #define MILS_PER_IU ( MM_PER_IU * 0.0254 ) + #define DECIMILS_PER_IU (MM_PER_IU * 0.00254 ) #else // Pcbnew in deci-mils. - #define DECIMILS_TO_IU_SCALING_FACTOR 1 - #define MILS_TO_IU_SCALING_FACTOR 10.0 - #define MM_TO_IU_SCALING_FACTOR (1e4 / 25.4) + #define DECIMILS_PER_IU 1 + #define MILS_PER_IU 10.0 + #define MM_PER_IU (1e4 / 25.4) #endif /// Convert mils to PCBNEW internal units (iu). inline int Mils2iu( int mils ) { #if defined( USE_PCBNEW_NANOMETRES ) - double x = mils * MILS_TO_IU_SCALING_FACTOR; + double x = mils * MILS_PER_IU; return int( x < 0 ? x - 0.5 : x + 0.5 ); #else - return mils * MILS_TO_IU_SCALING_FACTOR; + return mils * MILS_PER_IU; #endif } @@ -47,7 +47,7 @@ inline int Mils2iu( int mils ) inline int DMils2iu( int dmils ) { #if defined( USE_PCBNEW_NANOMETRES ) - double x = dmils * DECIMILS_TO_IU_SCALING_FACTOR; + double x = dmils * DECIMILS_PER_IU; return int( x < 0 ? x - 0.5 : x + 0.5 ); #else return dmils; @@ -55,8 +55,8 @@ inline int DMils2iu( int dmils ) } #else // Eeschema and anything else. -#define MILS_TO_IU_SCALING_FACTOR 1.0 -#define MM_TO_IU_SCALING_FACTOR (MILS_TO_IU_SCALING_FACTOR / 0.0254) +#define MILS_PER_IU 1.0 +#define MM_PER_IU (MILS_PER_IU / 0.0254) inline int Mils2iu( int mils ) { diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index 13a621bfde..9ee83d55b8 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -19,11 +19,11 @@ #include -#define ZOOM_FACTOR( x ) ( x * DECIMILS_TO_IU_SCALING_FACTOR ) -#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_TO_IU_SCALING_FACTOR,\ - x * DECIMILS_TO_IU_SCALING_FACTOR ) -#define MM_GRID( x ) wxRealPoint( x * MM_TO_IU_SCALING_FACTOR,\ - x * MM_TO_IU_SCALING_FACTOR ) +#define ZOOM_FACTOR( x ) ( x * DECIMILS_PER_IU ) +#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_PER_IU,\ + x * DECIMILS_PER_IU ) +#define MM_GRID( x ) wxRealPoint( x * MM_PER_IU,\ + x * MM_PER_IU ) /** @@ -133,7 +133,7 @@ PCB_SCREEN::~PCB_SCREEN() int PCB_SCREEN::MilsToIuScalar() { - return (int)MILS_TO_IU_SCALING_FACTOR; + return (int)MILS_PER_IU; } diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp index 9f3b3e946b..02e6c3d968 100644 --- a/pcbnew/dialogs/dialog_SVG_print.cpp +++ b/pcbnew/dialogs/dialog_SVG_print.cpp @@ -271,7 +271,7 @@ bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName, g_DrawBgColor = WHITE; if( aPrint_Frame_Ref ) - m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_TO_IU_SCALING_FACTOR ); + m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_PER_IU ); m_Parent->PrintPage( &dc, m_PrintMaskLayer, false, &s_Parameters); g_DrawBgColor = bg_color; diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 2894ece448..9400bea717 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -2682,7 +2682,7 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) // conversion factor for saving RAM BIUs to KICAD legacy file format. #if defined( USE_PCBNEW_NANOMETRES ) - biuToDisk = 1/MM_TO_IU_SCALING_FACTOR; // BIUs are nanometers & file is mm + biuToDisk = 1/MM_PER_IU; // BIUs are nanometers & file is mm #else biuToDisk = 1.0; // BIUs are deci-mils #endif @@ -2694,7 +2694,7 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) // then, during the file loading process, to start a conversion from // mm to nanometers. - diskToBiu = DECIMILS_TO_IU_SCALING_FACTOR; // BIUs are nanometers if USE_PCBNEW_NANOMETRES + diskToBiu = DECIMILS_PER_IU; // BIUs are nanometers if USE_PCBNEW_NANOMETRES // or BIUs are deci-mils } diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp index a098593ddd..fd29a10045 100644 --- a/pcbnew/printout_controler.cpp +++ b/pcbnew/printout_controler.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -181,7 +181,7 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() if( userscale == 0 ) // fit in page { // Margin = 10mm - int extra_margin = int( 10 * MM_TO_IU_SCALING_FACTOR ); // deci-mils + int extra_margin = int( 10 * MM_PER_IU ); // deci-mils pageSizeIU.x = bbbox.GetWidth() + extra_margin * 2; pageSizeIU.y = bbbox.GetHeight() + extra_margin * 2; @@ -275,7 +275,7 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() if( m_PrintParams.m_Print_Sheet_Ref ) m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize, - MILS_TO_IU_SCALING_FACTOR ); + MILS_PER_IU ); if( printMirror ) { diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 02169a65b1..9419ed56f5 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -99,7 +99,7 @@ void PCB_EDIT_FRAME::ExportToSpecctra( wxCommandEvent& event ) wxString errorText; BASE_SCREEN* screen = GetScreen(); - bool wasModified = screen->IsModify() && !screen->IsSave(); + bool wasModified = screen->IsModify(); db.SetPCB( SPECCTRA_DB::MakePCB() ); @@ -171,10 +171,10 @@ static inline double scale( int kicadDist ) #if defined(USE_PCBNEW_NANOMETRES) // nanometers to um - return kicadDist / ( MM_TO_IU_SCALING_FACTOR / 1000.0 ); + return kicadDist / ( MM_PER_IU / 1000.0 ); // nanometers to mils - // return kicadDist/MILS_TO_IU_SCALING_FACTOR; + // return kicadDist/MILS_PER_IU; #else // deci-mils to mils. @@ -185,7 +185,7 @@ static inline double scale( int kicadDist ) /// Convert integer internal units to float um static inline double IU2um( int kicadDist ) { - return kicadDist * (1000.0 / MM_TO_IU_SCALING_FACTOR); + return kicadDist * (1000.0 / MM_PER_IU); } diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp index 7858d08356..98ed2a7dda 100644 --- a/pcbnew/tracepcb.cpp +++ b/pcbnew/tracepcb.cpp @@ -67,7 +67,7 @@ void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) GRSetDrawMode( DC, GR_COPY ); m_canvas->DrawBackGround( DC ); - TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALING_FACTOR ); + TraceWorkSheet( DC, screen, 0, MILS_PER_IU ); // Redraw the footprints for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) @@ -105,7 +105,7 @@ void PCB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) m_canvas->DrawBackGround( DC ); - TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); + TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_PER_IU ); GetBoard()->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST); From 758f22161ac15b8c1d38eb6fc31d541a76ea87d9 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 26 Apr 2012 23:34:20 +0200 Subject: [PATCH 08/11] All: change MILS_TO_IU_SCALING_FACTOR constant to IU_PER_MILS ( and MM_TO_IU_SCALING_FACTOR to IU_PER_MM) Also fix bug 985654. --- common/base_units.cpp | 8 ++--- common/eda_text.cpp | 2 +- eeschema/dialogs/dialog_SVG_print.cpp | 2 +- .../dialogs/dialog_print_using_printer.cpp | 2 +- eeschema/eeredraw.cpp | 2 +- eeschema/schframe.cpp | 2 +- gerbview/class_gbr_screen.cpp | 10 +++--- gerbview/class_gbr_screen.h | 2 +- gerbview/dcode.cpp | 4 +-- gerbview/draw_gerber_screen.cpp | 2 +- gerbview/excellon_read_drill_file.cpp | 2 +- gerbview/gerbview_frame.cpp | 2 +- gerbview/rs274_read_XY_and_IJ_coordinates.cpp | 32 +++++++++---------- gerbview/rs274x.cpp | 4 +-- include/common.h | 4 +-- include/convert_to_biu.h | 24 +++++++------- pcbnew/classpcb.cpp | 12 +++---- pcbnew/dialogs/dialog_SVG_print.cpp | 2 +- pcbnew/legacy_plugin.cpp | 2 +- pcbnew/printout_controler.cpp | 10 +++--- pcbnew/specctra_export.cpp | 6 ++-- pcbnew/tracepcb.cpp | 4 +-- 22 files changed, 70 insertions(+), 70 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index 39b5890b63..a871a0d7ba 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -41,10 +41,10 @@ #if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) -#define IU_TO_MM( x ) ( x / MM_PER_IU ) -#define IU_TO_IN( x ) ( x / MILS_PER_IU / 1000 ) -#define MM_TO_IU( x ) ( x * MM_PER_IU ) -#define IN_TO_IU( x ) ( x * MILS_PER_IU * 1000 ) +#define IU_TO_MM( x ) ( x / IU_PER_MM ) +#define IU_TO_IN( x ) ( x / IU_PER_MILS / 1000 ) +#define MM_TO_IU( x ) ( x * IU_PER_MM ) +#define IN_TO_IU( x ) ( x * IU_PER_MILS * 1000 ) #else #error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW." #endif diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 56c70a1d79..6cbae0800f 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -37,7 +37,7 @@ // Conversion to application internal units defined at build time. #if defined( PCBNEW ) #include -#define MILS_TO_IU( x ) ( x * MILS_PER_IU ); +#define MILS_TO_IU( x ) ( x * IU_PER_MILS ); #elif defined( EESCHEMA ) #include #define MILS_TO_IU( x ) ( x ) diff --git a/eeschema/dialogs/dialog_SVG_print.cpp b/eeschema/dialogs/dialog_SVG_print.cpp index 27ef2de71e..5816f77655 100644 --- a/eeschema/dialogs/dialog_SVG_print.cpp +++ b/eeschema/dialogs/dialog_SVG_print.cpp @@ -237,7 +237,7 @@ bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame, sheetSize.y/2) ); if( aPrint_Sheet_Ref ) - frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_PER_IU ); + frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, IU_PER_MILS ); screen->m_IsPrinting = false; panel->SetClipBox( tmp ); diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index deef5807ee..c9a74cc03d 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -378,7 +378,7 @@ void SCH_PRINTOUT::DrawPage( SCH_SCREEN* aScreen ) aScreen->Draw( panel, dc, GR_DEFAULT_DRAWMODE ); if( printReference ) - parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_PER_IU ); + parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, IU_PER_MILS ); g_DrawBgColor = bg_color; aScreen->m_IsPrinting = false; diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index 93893cc81c..f14b07820a 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -71,7 +71,7 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) GetScreen()->Draw( m_canvas, DC, GR_DEFAULT_DRAWMODE ); - TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_PER_IU ); + TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, IU_PER_MILS ); #ifdef USE_WX_OVERLAY if( IsShown() ) diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 5f16c9d2c9..d2a9a35a49 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -863,7 +863,7 @@ void SCH_EDIT_FRAME::SVG_Print( wxCommandEvent& event ) void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData ) { GetScreen()->Draw( m_canvas, aDC, GR_DEFAULT_DRAWMODE ); - TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_PER_IU ); + TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, IU_PER_MILS ); } diff --git a/gerbview/class_gbr_screen.cpp b/gerbview/class_gbr_screen.cpp index f4ae6293a5..f11eac0157 100644 --- a/gerbview/class_gbr_screen.cpp +++ b/gerbview/class_gbr_screen.cpp @@ -17,10 +17,10 @@ #include -#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_PER_IU,\ - x * DECIMILS_PER_IU ) -#define MM_GRID( x ) wxRealPoint( x * MM_PER_IU,\ - x * MM_PER_IU ) +#define DMIL_GRID( x ) wxRealPoint( x * IU_PER_DECIMILS,\ + x * IU_PER_DECIMILS ) +#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM,\ + x * IU_PER_MM ) /** @@ -118,5 +118,5 @@ GBR_SCREEN::~GBR_SCREEN() // virtual function int GBR_SCREEN::MilsToIuScalar() { - return (int)MILS_PER_IU; + return (int)IU_PER_MILS; } diff --git a/gerbview/class_gbr_screen.h b/gerbview/class_gbr_screen.h index ede5be2de7..d809bc135d 100644 --- a/gerbview/class_gbr_screen.h +++ b/gerbview/class_gbr_screen.h @@ -9,7 +9,7 @@ #include #include -#define ZOOM_FACTOR( x ) ( x * DECIMILS_PER_IU ) +#define ZOOM_FACTOR( x ) ( x * IU_PER_DECIMILS ) /* Handle info to display a board */ diff --git a/gerbview/dcode.cpp b/gerbview/dcode.cpp index fb96c3ba78..4f3193af41 100644 --- a/gerbview/dcode.cpp +++ b/gerbview/dcode.cpp @@ -175,8 +175,8 @@ int GERBVIEW_FRAME::ReadDCodeDefinitionFile( const wxString& D_Code_FullFileName /* Updating gerber scale: */ - double dcode_scale = MILS_PER_IU; // By uniting dCode = mil, - // internal unit = MILS_PER_IU + double dcode_scale = IU_PER_MILS; // By uniting dCode = mil, + // internal unit = IU_PER_MILS current_Dcode = 0; if( D_Code_FullFileName.IsEmpty() ) diff --git a/gerbview/draw_gerber_screen.cpp b/gerbview/draw_gerber_screen.cpp index 6c09f37e47..a8b97ba378 100644 --- a/gerbview/draw_gerber_screen.cpp +++ b/gerbview/draw_gerber_screen.cpp @@ -107,7 +107,7 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) if( IsElementVisible( DCODES_VISIBLE ) ) DrawItemsDCodeID( DC, GR_COPY ); - TraceWorkSheet( DC, screen, 0, MILS_PER_IU ); + TraceWorkSheet( DC, screen, 0, IU_PER_MILS ); if( m_canvas->IsMouseCaptured() ) m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp index 8335b790c1..19f6064e44 100644 --- a/gerbview/excellon_read_drill_file.cpp +++ b/gerbview/excellon_read_drill_file.cpp @@ -432,7 +432,7 @@ bool EXCELLON_IMAGE::Execute_HEADER_Command( char*& text ) if( dcode == NULL ) break; // conv_scale = scaling factor from inch to Internal Unit - double conv_scale = MILS_PER_IU * 1000; + double conv_scale = IU_PER_MILS * 1000; if( m_GerbMetric ) conv_scale /= 25.4; diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index e254438066..a81ed9a5a0 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -411,7 +411,7 @@ void GERBVIEW_FRAME::Liste_D_Codes() D_CODE* pt_D_code; wxString Line; wxArrayString list; - double scale = MILS_PER_IU * 1000; + double scale = IU_PER_MILS * 1000; int curr_layer = getActiveLayer(); for( int layer = 0; layer < 32; layer++ ) diff --git a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp index 9fa669acb9..85417cbfc7 100644 --- a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp +++ b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp @@ -21,16 +21,16 @@ // for metric gerber units, the imperial to metric conversion is made in read functions static double scale_list[10] = { - 1000.0 * MILS_PER_IU, - 100.0 * MILS_PER_IU, - 10.0 * MILS_PER_IU, - 1.0 * MILS_PER_IU, - 0.1 * MILS_PER_IU, - 0.01 * MILS_PER_IU, - 0.001 * MILS_PER_IU, - 0.0001 * MILS_PER_IU, - 0.00001 * MILS_PER_IU, - 0.000001 * MILS_PER_IU + 1000.0 * IU_PER_MILS, + 100.0 * IU_PER_MILS, + 10.0 * IU_PER_MILS, + 1.0 * IU_PER_MILS, + 0.1 * IU_PER_MILS, + 0.01 * IU_PER_MILS, + 0.001 * IU_PER_MILS, + 0.0001 * IU_PER_MILS, + 0.00001 * IU_PER_MILS, + 0.000001 * IU_PER_MILS }; @@ -44,9 +44,9 @@ int scaletoIU( double aCoord, bool isMetric ) int ret; if( isMetric ) - ret = KiROUND( aCoord * MILS_PER_IU / 0.00254 ); + ret = KiROUND( aCoord * IU_PER_MILS / 0.00254 ); else - ret = KiROUND( aCoord * MILS_PER_IU ); + ret = KiROUND( aCoord * IU_PER_MILS ); return ret; } @@ -94,9 +94,9 @@ wxPoint GERBER_IMAGE::ReadXYCoord( char*& Text ) { // When X or Y values are float numbers, they are given in mm or inches if( m_GerbMetric ) // units are mm - current_coord = KiROUND( atof( line ) * MILS_PER_IU / 0.0254 ); + current_coord = KiROUND( atof( line ) * IU_PER_MILS / 0.0254 ); else // units are inches - current_coord = KiROUND( atof( line ) * MILS_PER_IU * 1000 ); + current_coord = KiROUND( atof( line ) * IU_PER_MILS * 1000 ); } else { @@ -185,9 +185,9 @@ wxPoint GERBER_IMAGE::ReadIJCoord( char*& Text ) { // When X or Y values are float numbers, they are given in mm or inches if( m_GerbMetric ) // units are mm - current_coord = KiROUND( atof( line ) * MILS_PER_IU / 0.0254 ); + current_coord = KiROUND( atof( line ) * IU_PER_MILS / 0.0254 ); else // units are inches - current_coord = KiROUND( atof( line ) * MILS_PER_IU * 1000 ); + current_coord = KiROUND( atof( line ) * IU_PER_MILS * 1000 ); } else { diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index f879f4f9fe..8af947aed7 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -160,7 +160,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, double fcoord; // conv_scale = scaling factor from inch to Internal Unit - double conv_scale = MILS_PER_IU * 1000; + double conv_scale = IU_PER_MILS * 1000; if( m_GerbMetric ) conv_scale /= 25.4; @@ -294,7 +294,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, m_GerbMetric = false; else if( code == MILLIMETER ) m_GerbMetric = true; - conv_scale = m_GerbMetric ? MILS_PER_IU / 25.4 : MILS_PER_IU; + conv_scale = m_GerbMetric ? IU_PER_MILS / 25.4 : IU_PER_MILS; break; case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset diff --git a/include/common.h b/include/common.h index 86ee71860f..3323ca7b9b 100644 --- a/include/common.h +++ b/include/common.h @@ -298,8 +298,8 @@ public: // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA, // and either deci-mils or nanometers in PCBNew. #if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) - int GetWidthIU() const { return MILS_PER_IU * GetWidthMils(); } - int GetHeightIU() const { return MILS_PER_IU * GetHeightMils(); } + int GetWidthIU() const { return IU_PER_MILS * GetWidthMils(); } + int GetHeightIU() const { return IU_PER_MILS * GetHeightMils(); } const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); } #endif diff --git a/include/convert_to_biu.h b/include/convert_to_biu.h index 8581550a0b..a4e9d62f19 100644 --- a/include/convert_to_biu.h +++ b/include/convert_to_biu.h @@ -20,26 +20,26 @@ #if defined(PCBNEW) || defined(CVPCB) || defined(GERBVIEW) #if defined( USE_PCBNEW_NANOMETRES ) #if defined(GERBVIEW) - #define MM_PER_IU 1e5 // Gerbview uses 10 micrometer. + #define IU_PER_MM 1e5 // Gerbview uses 10 micrometer. #else - #define MM_PER_IU 1e6 // Pcbnew uses nanometers. + #define IU_PER_MM 1e6 // Pcbnew uses nanometers. #endif - #define MILS_PER_IU ( MM_PER_IU * 0.0254 ) - #define DECIMILS_PER_IU (MM_PER_IU * 0.00254 ) + #define IU_PER_MILS ( IU_PER_MM * 0.0254 ) + #define IU_PER_DECIMILS (IU_PER_MM * 0.00254 ) #else // Pcbnew in deci-mils. - #define DECIMILS_PER_IU 1 - #define MILS_PER_IU 10.0 - #define MM_PER_IU (1e4 / 25.4) + #define IU_PER_DECIMILS 1 + #define IU_PER_MILS 10.0 + #define IU_PER_MM (1e4 / 25.4) #endif /// Convert mils to PCBNEW internal units (iu). inline int Mils2iu( int mils ) { #if defined( USE_PCBNEW_NANOMETRES ) - double x = mils * MILS_PER_IU; + double x = mils * IU_PER_MILS; return int( x < 0 ? x - 0.5 : x + 0.5 ); #else - return mils * MILS_PER_IU; + return mils * IU_PER_MILS; #endif } @@ -47,7 +47,7 @@ inline int Mils2iu( int mils ) inline int DMils2iu( int dmils ) { #if defined( USE_PCBNEW_NANOMETRES ) - double x = dmils * DECIMILS_PER_IU; + double x = dmils * IU_PER_DECIMILS; return int( x < 0 ? x - 0.5 : x + 0.5 ); #else return dmils; @@ -55,8 +55,8 @@ inline int DMils2iu( int dmils ) } #else // Eeschema and anything else. -#define MILS_PER_IU 1.0 -#define MM_PER_IU (MILS_PER_IU / 0.0254) +#define IU_PER_MILS 1.0 +#define IU_PER_MM (IU_PER_MILS / 0.0254) inline int Mils2iu( int mils ) { diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index 9ee83d55b8..b873e36be2 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -19,11 +19,11 @@ #include -#define ZOOM_FACTOR( x ) ( x * DECIMILS_PER_IU ) -#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_PER_IU,\ - x * DECIMILS_PER_IU ) -#define MM_GRID( x ) wxRealPoint( x * MM_PER_IU,\ - x * MM_PER_IU ) +#define ZOOM_FACTOR( x ) ( x * IU_PER_DECIMILS ) +#define DMIL_GRID( x ) wxRealPoint( x * IU_PER_DECIMILS,\ + x * IU_PER_DECIMILS ) +#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM,\ + x * IU_PER_MM ) /** @@ -133,7 +133,7 @@ PCB_SCREEN::~PCB_SCREEN() int PCB_SCREEN::MilsToIuScalar() { - return (int)MILS_PER_IU; + return (int)IU_PER_MILS; } diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp index 02e6c3d968..08ddb1219a 100644 --- a/pcbnew/dialogs/dialog_SVG_print.cpp +++ b/pcbnew/dialogs/dialog_SVG_print.cpp @@ -271,7 +271,7 @@ bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName, g_DrawBgColor = WHITE; if( aPrint_Frame_Ref ) - m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_PER_IU ); + m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, IU_PER_MILS ); m_Parent->PrintPage( &dc, m_PrintMaskLayer, false, &s_Parameters); g_DrawBgColor = bg_color; diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 9400bea717..d6598acae1 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -2694,7 +2694,7 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) // then, during the file loading process, to start a conversion from // mm to nanometers. - diskToBiu = DECIMILS_PER_IU; // BIUs are nanometers if USE_PCBNEW_NANOMETRES + diskToBiu = IU_PER_DECIMILS; // BIUs are nanometers if USE_PCBNEW_NANOMETRES // or BIUs are deci-mils } diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp index fd29a10045..2a75bcd012 100644 --- a/pcbnew/printout_controler.cpp +++ b/pcbnew/printout_controler.cpp @@ -181,7 +181,7 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() if( userscale == 0 ) // fit in page { // Margin = 10mm - int extra_margin = int( 10 * MM_PER_IU ); // deci-mils + int extra_margin = int( 10 * IU_PER_MM ); // deci-mils pageSizeIU.x = bbbox.GetWidth() + extra_margin * 2; pageSizeIU.y = bbbox.GetHeight() + extra_margin * 2; @@ -212,8 +212,8 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() MapScreenSizeToPaper(); int w, h; GetPPIPrinter( &w, &h ); - double accurate_Xscale = ( (double) ( DrawZoom * w ) ) / (double) PCB_INTERNAL_UNIT; - double accurate_Yscale = ( (double) ( DrawZoom * h ) ) / (double) PCB_INTERNAL_UNIT; + double accurate_Xscale = ( (double) ( DrawZoom * w ) ) / (IU_PER_MILS*1000); + double accurate_Yscale = ( (double) ( DrawZoom * h ) ) / (IU_PER_MILS*1000); if( IsPreview() ) // Scale must take in account the DC size in Preview { @@ -275,7 +275,7 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() if( m_PrintParams.m_Print_Sheet_Ref ) m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize, - MILS_PER_IU ); + IU_PER_MILS ); if( printMirror ) { @@ -317,7 +317,7 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() /* when printing in color mode, we use the graphic OR mode that gives the same look as the screen * But because the background is white when printing, we must use a trick: * In order to plot on a white background in OR mode we must: - * 1 - Plot all items in black, this creates a local black backgroud + * 1 - Plot all items in black, this creates a local black background * 2 - Plot in OR mode on black "local" background */ if( !m_PrintParams.m_Print_Black_and_White ) diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 9419ed56f5..656fea3c7c 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -171,10 +171,10 @@ static inline double scale( int kicadDist ) #if defined(USE_PCBNEW_NANOMETRES) // nanometers to um - return kicadDist / ( MM_PER_IU / 1000.0 ); + return kicadDist / ( IU_PER_MM / 1000.0 ); // nanometers to mils - // return kicadDist/MILS_PER_IU; + // return kicadDist/IU_PER_MILS; #else // deci-mils to mils. @@ -185,7 +185,7 @@ static inline double scale( int kicadDist ) /// Convert integer internal units to float um static inline double IU2um( int kicadDist ) { - return kicadDist * (1000.0 / MM_PER_IU); + return kicadDist * (1000.0 / IU_PER_MM); } diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp index 98ed2a7dda..f1c26eb47f 100644 --- a/pcbnew/tracepcb.cpp +++ b/pcbnew/tracepcb.cpp @@ -67,7 +67,7 @@ void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) GRSetDrawMode( DC, GR_COPY ); m_canvas->DrawBackGround( DC ); - TraceWorkSheet( DC, screen, 0, MILS_PER_IU ); + TraceWorkSheet( DC, screen, 0, IU_PER_MILS ); // Redraw the footprints for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) @@ -105,7 +105,7 @@ void PCB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) m_canvas->DrawBackGround( DC ); - TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_PER_IU ); + TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, IU_PER_MILS ); GetBoard()->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST); From cdaa5ceac7581012d8390633b9078f364fedc84a Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 27 Apr 2012 00:04:09 +0200 Subject: [PATCH 09/11] missing change. --- pcbnew/legacy_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index d6598acae1..3b83b00c33 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -2682,7 +2682,7 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) // conversion factor for saving RAM BIUs to KICAD legacy file format. #if defined( USE_PCBNEW_NANOMETRES ) - biuToDisk = 1/MM_PER_IU; // BIUs are nanometers & file is mm + biuToDisk = 1/IU_PER_MM; // BIUs are nanometers & file is mm #else biuToDisk = 1.0; // BIUs are deci-mils #endif From 9d6c1d12ed66799970e8c08f9084f9c771cdffda Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 27 Apr 2012 08:11:41 +0200 Subject: [PATCH 10/11] Fix some (not all) bad values displayed in NANOMETER mode. --- pcbnew/class_pad.cpp | 16 ++++++++-------- pcbnew/class_pcb_text.cpp | 6 +++--- pcbnew/class_text_mod.cpp | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 0ee5d847b3..86aa6c60cf 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -612,13 +612,13 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) frame->AppendMsgPanel( ShowPadShape(), ShowPadAttr(), DARKGREEN ); - valeur_param( m_Size.x, Line ); + Line = frame->CoordinateToString( m_Size.x ); frame->AppendMsgPanel( _( "H Size" ), Line, RED ); - valeur_param( m_Size.y, Line ); + Line = frame->CoordinateToString( m_Size.y ); frame->AppendMsgPanel( _( "V Size" ), Line, RED ); - valeur_param( (unsigned) m_Drill.x, Line ); + Line = frame->CoordinateToString( (unsigned) m_Drill.x ); if( m_DrillShape == PAD_CIRCLE ) { @@ -626,9 +626,9 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) } else { - valeur_param( (unsigned) m_Drill.x, Line ); + Line = frame->CoordinateToString( (unsigned) m_Drill.x ); wxString msg; - valeur_param( (unsigned) m_Drill.y, msg ); + Line = frame->CoordinateToString( (unsigned) m_Drill.y ); Line += wxT( " / " ) + msg; frame->AppendMsgPanel( _( "Drill X / Y" ), Line, RED ); } @@ -644,15 +644,15 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) frame->AppendMsgPanel( _( "Orient" ), Line, LIGHTBLUE ); - valeur_param( m_Pos.x, Line ); + Line = frame->CoordinateToString( m_Pos.x ); frame->AppendMsgPanel( _( "X Pos" ), Line, LIGHTBLUE ); - valeur_param( m_Pos.y, Line ); + Line = frame->CoordinateToString( m_Pos.y ); frame->AppendMsgPanel( _( "Y pos" ), Line, LIGHTBLUE ); if( GetDieLength() ) { - valeur_param( GetDieLength(), Line ); + Line = frame->CoordinateToString( GetDieLength() ); frame->AppendMsgPanel( _( "Length on die" ), Line, CYAN ); } } diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp index ec265d1ef3..e5099e9543 100644 --- a/pcbnew/class_pcb_text.cpp +++ b/pcbnew/class_pcb_text.cpp @@ -138,13 +138,13 @@ void TEXTE_PCB::DisplayInfo( EDA_DRAW_FRAME* frame ) msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 ); frame->AppendMsgPanel( _( "Orientation" ), msg, DARKGREEN ); - valeur_param( m_Thickness, msg ); + msg = frame->CoordinateToString( m_Thickness ); frame->AppendMsgPanel( _( "Thickness" ), msg, MAGENTA ); - valeur_param( m_Size.x, msg ); + msg = frame->CoordinateToString( m_Size.x ); frame->AppendMsgPanel( _( "Size X" ), msg, RED ); - valeur_param( m_Size.y, msg ); + msg = frame->CoordinateToString( m_Size.y ); frame->AppendMsgPanel( _( "Size Y" ), msg, RED ); } diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index 279489a06f..a588b12484 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -405,13 +405,13 @@ void TEXTE_MODULE::DisplayInfo( EDA_DRAW_FRAME* frame ) msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 ); frame->AppendMsgPanel( _( "Orient" ), msg, DARKGREEN ); - valeur_param( m_Thickness, msg ); + msg = frame->CoordinateToString( m_Thickness ); frame->AppendMsgPanel( _( "Thickness" ), msg, DARKGREEN ); - valeur_param( m_Size.x, msg ); + msg = frame->CoordinateToString( m_Size.x ); frame->AppendMsgPanel( _( "H Size" ), msg, RED ); - valeur_param( m_Size.y, msg ); + msg = frame->CoordinateToString( m_Size.y ); frame->AppendMsgPanel( _( "V Size" ), msg, RED ); } From e96f1aeb3d34fc07569a4de9830af92ce0cb98b4 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 27 Apr 2012 16:15:11 +0200 Subject: [PATCH 11/11] Remove valeur_param(), that does not work in Kicad Nanometer --- 3d-viewer/3d_aux.cpp | 2 +- common/base_units.cpp | 16 ++++++++++++++++ common/common.cpp | 33 --------------------------------- common/drawframe.cpp | 5 +++++ eeschema/class_drc_erc_item.cpp | 8 ++------ include/base_units.h | 25 +++++++++++++++++++++++-- include/common.h | 19 ------------------- include/fctsys.h | 3 --- include/wxstruct.h | 13 ++++++++++++- pcbnew/class_dimension.cpp | 3 ++- pcbnew/class_drawsegment.cpp | 8 ++++---- pcbnew/class_drc_item.cpp | 1 + pcbnew/class_edge_mod.cpp | 2 +- pcbnew/class_mire.cpp | 3 ++- pcbnew/class_track.cpp | 10 ++++------ pcbnew/editrack.cpp | 4 ++-- pcbnew/specctra_export.cpp | 1 + 17 files changed, 76 insertions(+), 80 deletions(-) diff --git a/3d-viewer/3d_aux.cpp b/3d-viewer/3d_aux.cpp index ceb7ba9711..865e199b17 100644 --- a/3d-viewer/3d_aux.cpp +++ b/3d-viewer/3d_aux.cpp @@ -70,7 +70,7 @@ void S3D_MASTER::Set_Object_Coords( std::vector< S3D_Vertex >& aVertices ) RotatePoint( &aVertices[ii].x, &aVertices[ii].y, (int) (m_MatRotation.z * 10) ); /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ -#define SCALE_3D_CONV (PCB_INTERNAL_UNIT / UNITS3D_TO_UNITSPCB) +#define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB) aVertices[ii].x += m_MatPosition.x * SCALE_3D_CONV; aVertices[ii].y += m_MatPosition.y * SCALE_3D_CONV; aVertices[ii].z += m_MatPosition.z * SCALE_3D_CONV; diff --git a/common/base_units.cpp b/common/base_units.cpp index a871a0d7ba..478bdca6e3 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -67,6 +67,11 @@ double To_User_Unit( EDA_UNITS_T aUnit, double aValue ) wxString CoordinateToString( int aValue, bool aConvertToMils ) +{ + return LengthDoubleToString( (double) aValue, aConvertToMils ); +} + +wxString LengthDoubleToString( double aValue, bool aConvertToMils ) { wxString text; const wxChar* format; @@ -249,3 +254,14 @@ int ReturnValueFromTextCtrl( const wxTextCtrl& aTextCtr ) return value; } + + +wxString& operator <<( wxString& aString, const wxPoint& aPos ) +{ + aString << wxT( "@ (" ) << CoordinateToString( aPos.x ); + aString << wxT( "," ) << CoordinateToString( aPos.y ); + aString << wxT( ")" ); + + return aString; +} + diff --git a/common/common.cpp b/common/common.cpp index 2697a6dae8..c3f298c3e3 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -334,39 +334,6 @@ unsigned long GetNewTimeStamp() } -const wxString& valeur_param( int valeur, wxString& buf_texte ) -{ - switch( g_UserUnit ) - { - case MILLIMETRES: - buf_texte.Printf( _( "%3.3f mm" ), valeur * 0.00254 ); - break; - - case INCHES: - buf_texte.Printf( wxT( "%2.4f \"" ), valeur * 0.0001 ); - break; - - case UNSCALED_UNITS: - buf_texte.Printf( wxT( "%d" ), valeur ); - break; - } - - return buf_texte; -} - - -wxString& operator <<( wxString& aString, const wxPoint& aPos ) -{ - wxString temp; - - aString << wxT( "@ (" ) << valeur_param( aPos.x, temp ); - aString << wxT( "," ) << valeur_param( aPos.y, temp ); - aString << wxT( ")" ); - - return aString; -} - - double RoundTo0( double x, double precision ) { assert( precision != 0 ); diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 656589cbf1..2078fdc4d3 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -584,6 +584,11 @@ wxString EDA_DRAW_FRAME::CoordinateToString( int aValue, bool aConvertToMils ) return ::CoordinateToString( aValue, aConvertToMils ); } +wxString EDA_DRAW_FRAME::LengthDoubleToString( double aValue, bool aConvertToMils ) +{ + return ::LengthDoubleToString( aValue, aConvertToMils ); +} + bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosition ) { diff --git a/eeschema/class_drc_erc_item.cpp b/eeschema/class_drc_erc_item.cpp index d9e1a0c2d9..928d72e9bf 100644 --- a/eeschema/class_drc_erc_item.cpp +++ b/eeschema/class_drc_erc_item.cpp @@ -30,6 +30,7 @@ #include #include +#include wxString DRC_ITEM::GetErrorText() const { @@ -57,14 +58,9 @@ wxString DRC_ITEM::GetErrorText() const } } - wxString DRC_ITEM::ShowCoord( const wxPoint& aPos ) { wxString ret; - wxPoint pos_in_pcb_units = aPos; - pos_in_pcb_units.x *= 10; - pos_in_pcb_units.y *= 10; - ret << pos_in_pcb_units; + ret << aPos; return ret; } - diff --git a/include/base_units.h b/include/base_units.h index 16276e64fb..790025fff8 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -50,16 +50,27 @@ double To_User_Unit( EDA_UNITS_T aUnit, double aValue ); /** * Function CoordinateToString - * is a helper to convert the integer coordinate \a aValue to a string in inches, + * is a helper to convert the \a integer coordinate \a aValue to a string in inches, * millimeters, or unscaled units according to the current user units setting. * - * @param aValue The coordinate to convert. + * @param aValue The integer coordinate to convert. * @param aConvertToMils Convert inch values to mils if true. This setting has no effect if * the current user unit is millimeters. * @return The converted string for display in user interface elements. */ wxString CoordinateToString( int aValue, bool aConvertToMils = false ); +/** + * Function LenghtDoubleToString + * is a helper to convert the \a double length \a aValue to a string in inches, + * millimeters, or unscaled units according to the current user units setting. + * + * @param aValue The double value to convert. + * @param aConvertToMils Convert inch values to mils if true. This setting has no effect if + * the current user unit is millimeters. + * @return The converted string for display in user interface elements. + */ +wxString LengthDoubleToString( double aValue, bool aConvertToMils = false ); /** * Function ReturnStringFromValue @@ -72,6 +83,16 @@ wxString CoordinateToString( int aValue, bool aConvertToMils = false ); */ wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol = false ); +/** + * Operator << overload + * outputs a point to the argument string in a format resembling + * "@ (x,y) + * @param aString Where to put the text describing the point value + * @param aPoint The point to output. + * @return wxString& - the input string + */ +wxString& operator <<( wxString& aString, const wxPoint& aPoint ); + /** * Function PutValueInLocalUnits * converts \a aValue from internal units to user units and append the units notation diff --git a/include/common.h b/include/common.h index 3323ca7b9b..3a1fed59f6 100644 --- a/include/common.h +++ b/include/common.h @@ -541,17 +541,6 @@ private: bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL ); -/** - * Operator << overload - * outputs a point to the argument string in a format resembling - * "@ (x,y) - * @param aString Where to put the text describing the point value - * @param aPoint The point to output. - * @return wxString& - the input string - */ -wxString& operator <<( wxString& aString, const wxPoint& aPoint ); - - /** * Function ProcessExecute * runs a child process. @@ -583,14 +572,6 @@ int GetCommandOptions( const int argc, const char** argv, const char* stringtst, const char** optarg, int* optind ); - -/* Returns to display the value of a parameter, by type of units selected - * Input: value in mils, buffer text - * Returns to buffer: text: value expressed in inches or millimeters - * Followed by " or mm - */ -const wxString& valeur_param( int valeur, wxString& buf_texte ); - /** * Returns the units symbol. * diff --git a/include/fctsys.h b/include/fctsys.h index 648baa5926..8225dfd0f3 100644 --- a/include/fctsys.h +++ b/include/fctsys.h @@ -29,9 +29,6 @@ #define M_PI 3.141592653 #endif -#define PCB_INTERNAL_UNIT 10000 // PCBNEW internal unit = 1/10000 inch -#define EESCHEMA_INTERNAL_UNIT 1000 // EESCHEMA internal unit = 1/1000 inch - #ifdef __WINDOWS__ #define DIR_SEP '\\' #define STRING_DIR_SEP wxT( "\\" ) diff --git a/include/wxstruct.h b/include/wxstruct.h index 9577af8dfa..39df566219 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -841,7 +841,7 @@ public: /** * Function CoordinateToString - * is a helper to convert the integer coordinate \a aValue to a string in inches or mm + * is a helper to convert the \a integer coordinate \a aValue to a string in inches or mm * according to the current user units setting. * @param aValue The coordinate to convert. * @param aConvertToMils Convert inch values to mils if true. This setting has no effect if @@ -850,6 +850,17 @@ public: */ wxString CoordinateToString( int aValue, bool aConvertToMils = false ); + /** + * Function LengthDoubleToString + * is a helper to convert the \a double value \a aValue to a string in inches or mm + * according to the current user units setting. + * @param aValue The coordinate to convert. + * @param aConvertToMils Convert inch values to mils if true. This setting has no effect if + * the current user unit is millimeters. + * @return The converted string for display in user interface elements. + */ + wxString LengthDoubleToString( double aValue, bool aConvertToMils = false ); + DECLARE_EVENT_TABLE() }; diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index 51af0595ed..49083ed105 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -41,6 +41,7 @@ #include #include #include +#include DIMENSION::DIMENSION( BOARD_ITEM* aParent ) : @@ -344,7 +345,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) if( !aDoNotChangeText ) { m_Value = mesure; - valeur_param( m_Value, msg ); + msg = ::CoordinateToString( m_Value ); SetText( msg ); } } diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index 0679b53ab4..a65ac9f05e 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -47,6 +47,7 @@ #include #include #include +#include DRAWSEGMENT::DRAWSEGMENT( BOARD_ITEM* aParent, KICAD_T idtype ) : @@ -373,7 +374,7 @@ void DRAWSEGMENT::DisplayInfo( EDA_DRAW_FRAME* frame ) frame->AppendMsgPanel( _( "Layer" ), board->GetLayerName( m_Layer ), DARKBROWN ); - valeur_param( (unsigned) m_Width, msg ); + msg = frame->CoordinateToString( m_Width ); frame->AppendMsgPanel( _( "Width" ), msg, DARKCYAN ); } @@ -527,12 +528,11 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect ) const wxString DRAWSEGMENT::GetSelectMenuText() const { wxString text; - wxString temp; + wxString temp = ::LengthDoubleToString( GetLength() ); text.Printf( _( "Pcb Graphic: %s length: %s on %s" ), GetChars( ShowShape( (STROKE_T) m_Shape ) ), - GetChars( valeur_param( GetLength(), temp ) ), - GetChars( GetLayerName() ) ); + GetChars( temp ), GetChars( GetLayerName() ) ); return text; } diff --git a/pcbnew/class_drc_item.cpp b/pcbnew/class_drc_item.cpp index 92924300a7..402e3643af 100644 --- a/pcbnew/class_drc_item.cpp +++ b/pcbnew/class_drc_item.cpp @@ -32,6 +32,7 @@ #include #include #include +#include wxString DRC_ITEM::GetErrorText() const diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp index b1ef13eef4..241f6182e0 100644 --- a/pcbnew/class_edge_mod.cpp +++ b/pcbnew/class_edge_mod.cpp @@ -255,7 +255,7 @@ void EDGE_MODULE::DisplayInfo( EDA_DRAW_FRAME* frame ) frame->AppendMsgPanel( _( "Mod Layer" ), board->GetLayerName( module->GetLayer() ), RED ); frame->AppendMsgPanel( _( "Seg Layer" ), board->GetLayerName( GetLayer() ), RED ); - valeur_param( m_Width, msg ); + msg = frame->CoordinateToString( m_Width ); frame->AppendMsgPanel( _( "Width" ), msg, BLUE ); } diff --git a/pcbnew/class_mire.cpp b/pcbnew/class_mire.cpp index 18bfc99849..21f0840cd1 100644 --- a/pcbnew/class_mire.cpp +++ b/pcbnew/class_mire.cpp @@ -42,6 +42,7 @@ #include #include +#include PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) : @@ -210,7 +211,7 @@ wxString PCB_TARGET::GetSelectMenuText() const wxString text; wxString msg; - valeur_param( m_Size, msg ); + msg = ::CoordinateToString( m_Size ); text.Printf( _( "Target on %s size %s" ), GetChars( GetLayerName() ), GetChars( msg ) ); diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 2ae5d9add1..e69eceb527 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -46,6 +46,7 @@ #include #include +#include /** * Function ShowClearance @@ -138,10 +139,7 @@ EDA_ITEM* TRACK::Clone() const wxString TRACK::ShowWidth() const { - wxString msg; - - valeur_param( m_Width, msg ); - + wxString msg = ::CoordinateToString( m_Width ); return msg; } @@ -1173,7 +1171,7 @@ void TRACK::DisplayInfoBase( EDA_DRAW_FRAME* frame ) // Display segment length if( Type() != PCB_VIA_T ) // Display Diam and Drill values { - msg = frame->CoordinateToString( KiROUND( GetLength() ) ); + msg = frame->LengthDoubleToString( GetLength() ); frame->AppendMsgPanel( _( "Segment Length" ), msg, DARKCYAN ); } } @@ -1553,7 +1551,7 @@ wxString TRACK::GetSelectMenuText() const } text << _( " on " ) << GetLayerName() << wxT(" ") << _("Net:") << GetNet() - << wxT(" ") << _("Length:") << valeur_param( GetLength(), temp ); + << wxT(" ") << _("Length:") << ::LengthDoubleToString( GetLength() ); return text; } diff --git a/pcbnew/editrack.cpp b/pcbnew/editrack.cpp index 269fe02e9b..ca3e87cd43 100644 --- a/pcbnew/editrack.cpp +++ b/pcbnew/editrack.cpp @@ -789,13 +789,13 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() ) trackLen += track->GetLength(); - valeur_param( KiROUND( trackLen ), msg ); + msg = frame->LengthDoubleToString( trackLen ); frame->AppendMsgPanel( _( "Track Len" ), msg, DARKCYAN ); if( lenDie != 0 ) // display the track len on board and the actual track len { frame->AppendMsgPanel( _( "Full Len" ), msg, DARKCYAN ); - valeur_param( KiROUND( trackLen+lenDie ), msg ); + msg = frame->LengthDoubleToString( trackLen+lenDie ); frame->AppendMsgPanel( _( "On Die" ), msg, DARKCYAN ); } diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 656fea3c7c..3ced90fe48 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include