7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-07 21:05:15 +00:00

Collapse a level out of the zoom settings.

The APP_SETTINGS_BASE now holds the list of zoom factors, and
the old legacy (screen-based) code has been removed.
This commit is contained in:
Jeff Young 2020-06-13 22:09:02 +01:00
parent fc44506fe1
commit c48f4272f3
42 changed files with 286 additions and 651 deletions

View File

@ -27,7 +27,6 @@
#include <base_screen.h>
#include <base_struct.h>
#include <fctsys.h>
#include <id.h>
#include <trace_helpers.h>
@ -41,7 +40,6 @@ BASE_SCREEN::BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType ) :
m_Initialized = false;
m_ScreenNumber = 1;
m_NumberOfScreens = 1; // Hierarchy: Root: ScreenNumber = 1
m_Zoom = 32.0;
m_Center = true;
m_FlagModified = false; // Set when any change is made on board.
@ -72,25 +70,6 @@ void BASE_SCREEN::InitDataPoints( const wxSize& aPageSizeIU )
}
bool BASE_SCREEN::SetZoom( double iu_per_du )
{
if( iu_per_du == m_Zoom )
return false;
wxLogTrace( traceScreen, "Zoom:%.16g 1/Zoom:%.16g", iu_per_du, 1/iu_per_du );
if( iu_per_du < GetMinAllowedZoom() )
return false;
if( iu_per_du > GetMaxAllowedZoom() )
return false;
m_Zoom = iu_per_du;
return true;
}
void BASE_SCREEN::ClearUndoRedoList()
{
ClearUndoORRedoList( m_UndoList );

View File

@ -158,13 +158,10 @@ void EDA_DRAW_PANEL_GAL::SetFocus()
void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
{
// Update current zoom settings if the canvas is managed by a EDA frame
// Update scroll position if the canvas is managed by a EDA frame
// (i.e. not by a preview panel in a dialog)
if( GetParentEDAFrame() && GetParentEDAFrame()->GetScreen() )
{
GetParentEDAFrame()->GetScreen()->SetZoom( GetLegacyZoom() );
GetParentEDAFrame()->GetScreen()->m_ScrollCenter = GetView()->GetCenter();
}
m_viewControls->UpdateScrollbars();
@ -355,12 +352,6 @@ void EDA_DRAW_PANEL_GAL::SetTopLayer( int aLayer )
}
double EDA_DRAW_PANEL_GAL::GetLegacyZoom() const
{
return m_edaFrame->GetZoomLevelCoeff() / m_gal->GetZoomFactor();
}
bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
{
// Do not do anything if the currently used GAL is correct

View File

@ -87,7 +87,6 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
// BLACK for Pcbnew, BLACK or WHITE for eeschema
m_colorSettings = nullptr;
m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();
m_zoomLevelCoeff = 1.0;
m_userUnits = EDA_UNITS::MILLIMETRES;
m_PolarCoords = false;
m_findReplaceData = new wxFindReplaceData( wxFR_DOWN );
@ -342,12 +341,6 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
}
double EDA_DRAW_FRAME::GetZoom()
{
return GetScreen()->GetZoom();
}
void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent )
{
// If the window is moved to a different display, the scaling factor may change
@ -458,7 +451,8 @@ const wxString EDA_DRAW_FRAME::GetZoomLevelIndicator() const
{
// returns a human readable value which can be displayed as zoom
// level indicator in dialogs.
return wxString::Format( wxT( "Z %.2f" ), m_canvas->GetGAL()->GetZoomFactor() );
double zoom = m_canvas->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
return wxString::Format( wxT( "Z %.2f" ), zoom );
}

View File

@ -255,6 +255,9 @@ void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std:
m_params.emplace_back( new PARAM<int>( aJsonPath + ".pos_y", &aWindow->pos_y, 0 ) );
m_params.emplace_back( new PARAM_LIST<double>( aJsonPath + ".zoom_factors",
&aWindow->zoom_factors, {} ) );
m_params.emplace_back( new PARAM<bool>( aJsonPath + ".grid.axes_enabled",
&aWindow->grid.axes_enabled, false ) );

View File

@ -195,30 +195,19 @@ int COMMON_TOOLS::ZoomInOutCenter( const TOOL_EVENT& aEvent )
int COMMON_TOOLS::doZoomInOut( bool aDirection, bool aCenterOnCursor )
{
double zoom = m_frame->GetCanvas()->GetLegacyZoom();
double zoom = getView()->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
// Step must be AT LEAST 1.3
if( aDirection )
zoom /= 1.3;
else
zoom *= 1.3;
else
zoom /= 1.3;
// Now look for the next closest menu step
std::vector<double>& zoomList = m_frame->GetScreen()->m_ZoomList;
std::vector<double>& zoomList = m_toolMgr->GetSettings()->m_Window.zoom_factors;
int idx;
if( aDirection )
{
for( idx = zoomList.size() - 1; idx >= 0; --idx )
{
if( zoomList[idx] <= zoom )
break;
}
if( idx < 0 )
idx = 0; // if we ran off the end then peg to the end
}
else
{
for( idx = 0; idx < (int)zoomList.size(); ++idx )
{
@ -226,8 +215,19 @@ int COMMON_TOOLS::doZoomInOut( bool aDirection, bool aCenterOnCursor )
break;
}
if( idx >= (int)zoomList.size() )
idx = zoomList.size() - 1; // if we ran off the end then peg to the end
if( idx >= zoomList.size() )
idx = (int) zoomList.size() - 1; // if we ran off the end then peg to the end
}
else
{
for( idx = (int) zoomList.size() - 1; idx >= 0; --idx )
{
if( zoomList[idx] <= zoom )
break;
}
if( idx < 0 )
idx = 0; // if we ran off the end then peg to the end
}
return doZoomToPreset( idx + 1, aCenterOnCursor );
@ -313,15 +313,14 @@ int COMMON_TOOLS::CenterContents( const TOOL_EVENT& aEvent )
int COMMON_TOOLS::ZoomPreset( const TOOL_EVENT& aEvent )
{
unsigned int idx = aEvent.Parameter<intptr_t>();
return doZoomToPreset( idx, false );
return doZoomToPreset( (int) idx, false );
}
// Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor )
{
std::vector<double>& zoomList = m_frame->GetScreen()->m_ZoomList;
KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
std::vector<double>& zoomList = m_toolMgr->GetSettings()->m_Window.zoom_factors;
if( idx == 0 ) // Zoom Auto
{
@ -333,18 +332,18 @@ int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor )
idx--;
}
double scale = m_frame->GetZoomLevelCoeff() / zoomList[idx];
double scale = zoomList[idx] * ZOOM_COEFF;
if( aCenterOnCursor )
{
view->SetScale( scale, getViewControls()->GetCursorPosition() );
getView()->SetScale( scale, getViewControls()->GetCursorPosition() );
if( getViewControls()->IsCursorWarpingEnabled() )
getViewControls()->CenterOnCursor();
}
else
{
view->SetScale( scale );
getView()->SetScale( scale );
}
return 0;

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
* Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -26,7 +26,6 @@
#include <tool/grid_menu.h>
#include <id.h>
#include <eda_draw_frame.h>
#include <base_screen.h>
#include <settings/app_settings.h>
#include <tool/actions.h>
#include <bitmaps.h>

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 CERN
* Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -23,61 +24,49 @@
*/
#include <tool/zoom_menu.h>
#include <id.h>
#include <eda_draw_frame.h>
#include <base_screen.h>
#include <settings/app_settings.h>
#include <tool/actions.h>
#include <gal/graphics_abstraction_layer.h>
#include <bitmaps.h>
#include <convert_to_biu.h>
#include <functional>
using namespace std::placeholders;
ZOOM_MENU::ZOOM_MENU( EDA_DRAW_FRAME* aParent ) :
ACTION_MENU( true ),
m_parent( aParent )
{
BASE_SCREEN* screen = aParent->GetScreen();
SetTitle( _( "Zoom" ) );
SetIcon( zoom_selection_xpm );
//int zoom = screen->GetZoom();
int maxZoomIds = std::min( ID_POPUP_ZOOM_LEVEL_END - ID_POPUP_ZOOM_LEVEL_START,
(int) screen->m_ZoomList.size() );
int i = 1; // 0 reserved for menus which support auto-zoom
for( int i = 0; i < maxZoomIds; ++i )
{
Append( ID_POPUP_ZOOM_LEVEL_START+1 + i, // ID_POPUP_ZOOM_LEVEL_START == Auto
wxString::Format( _( "Zoom: %.2f" ), aParent->GetZoomLevelCoeff() / screen->m_ZoomList[i] ),
wxEmptyString, wxITEM_CHECK );
}
for( double factor : m_parent->config()->m_Window.zoom_factors )
Append( i++, wxString::Format( _( "Zoom: %.2f" ), factor ), wxEmptyString, wxITEM_CHECK );
}
OPT_TOOL_EVENT ZOOM_MENU::eventHandler( const wxMenuEvent& aEvent )
{
OPT_TOOL_EVENT event( ACTIONS::zoomPreset.MakeEvent() );
intptr_t idx = aEvent.GetId() - ID_POPUP_ZOOM_LEVEL_START;
event->SetParameter( idx );
event->SetParameter( (intptr_t) aEvent.GetId() );
return event;
}
void ZOOM_MENU::update()
{
BASE_SCREEN* screen = m_parent->GetScreen();
double zoom = screen->GetZoom();
const std::vector<double>& zoomList = m_parent->GetScreen()->m_ZoomList;
double zoom = m_parent->GetCanvas()->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
// Check the current zoom
int maxZoomIds = std::min( ID_POPUP_ZOOM_LEVEL_END - ID_POPUP_ZOOM_LEVEL_START,
(int) screen->m_ZoomList.size() );
const std::vector<double>& zoomList = m_parent->config()->m_Window.zoom_factors;
for( int i = 0; i < maxZoomIds; ++i )
for( int i = 0; i < zoomList.size(); ++i )
{
// Search for a value near the current zoom setting:
double rel_error = std::fabs( zoomList[i] - zoom )/zoom;
Check( ID_POPUP_ZOOM_LEVEL_START+1 + i, rel_error < 0.1 );
double rel_error = std::fabs( zoomList[i] - zoom ) / zoom;
// IDs start with 1 (leaving 0 for auto-zoom)
Check( i+1, rel_error < 0.1 );
}
}

View File

@ -146,8 +146,6 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa
auto& galOpts = GetGalDisplayOptions();
galOpts.m_axesEnabled = true;
GetCanvas()->GetView()->SetScale( GetZoomLevelCoeff() / GetScreen()->GetZoom() );
ActivateGalCanvas();
// Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.)

View File

@ -103,7 +103,6 @@ SCH_ITEM* SCH_EDITOR_CONTROL::FindComponentAndItem( const wxString& aReference,
{
if( *sheetWithComponentFound != m_frame->GetCurrentSheet() )
{
sheetWithComponentFound->LastScreen()->SetZoom( m_frame->GetScreen()->GetZoom() );
m_frame->Schematic().SetCurrentSheet( *sheetWithComponentFound );
m_frame->DisplayCurrentSheet();
}

View File

@ -361,7 +361,6 @@ void DIALOG_ERC::OnERCItemSelected( wxDataViewEvent& aEvent )
m_parent->SetCurrentSheet( sheet );
m_parent->DisplayCurrentSheet();
sheet.LastScreen()->SetZoom( m_parent->GetScreen()->GetZoom() );
m_parent->RedrawScreen( (wxPoint) m_parent->GetScreen()->m_ScrollCenter, false );
}

View File

@ -178,7 +178,6 @@ void DIALOG_MIGRATE_BUSES::onItemSelected( wxListEvent& aEvent )
if( sheet != current )
{
sheet.LastScreen()->SetZoom( m_frame->GetScreen()->GetZoom() );
sheet.UpdateAllScreenReferences();
m_frame->Schematic().SetCurrentSheet( sheet );
sheet.LastScreen()->TestDanglingEnds();

View File

@ -422,7 +422,6 @@ bool SCH_PRINTOUT::OnBeginDocument( int startPage, int endPage )
*/
void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
{
int oldZoom;
wxPoint tmp_startvisu;
wxSize pageSizeIU; // Page size in internal units
wxPoint old_org;
@ -431,9 +430,8 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
wxBusyCursor dummy;
// Save current scale factor, offsets, and clip box.
// Save current offsets and clip box.
tmp_startvisu = aScreen->m_StartVisu;
oldZoom = aScreen->GetZoom();
old_org = aScreen->m_DrawOrg;
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
@ -532,7 +530,6 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen )
aScreen->m_StartVisu = tmp_startvisu;
aScreen->m_DrawOrg = old_org;
aScreen->SetZoom( oldZoom );
}

View File

@ -440,6 +440,29 @@ void SCH_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
"1 mil" };
}
if( aCfg->m_Window.zoom_factors.empty() )
{
aCfg->m_Window.zoom_factors = { 0.5,
0.7,
1.0,
1.5,
2.0,
3.0,
4.5,
6.5,
10.0,
15.0,
20.0,
30.0,
45.0,
65.0,
100.0,
150.0 };
}
for( double& factor : aCfg->m_Window.zoom_factors )
factor = std::min( factor, MAX_ZOOM_FACTOR );
wxString templateFieldNames = cfg->m_Drawing.field_names;
if( !templateFieldNames.IsEmpty() )

View File

@ -87,10 +87,6 @@ SCH_BASE_FRAME::SCH_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aWindo
m_defaults( &m_base_frame_defaults )
{
createCanvas();
// Adjusted to display zoom level ~ 1 when the screen shows a 1:1 image
// Obviously depends on the monitor, but this is an acceptable value
m_zoomLevelCoeff = 11.0 * IU_PER_MILS;
}
@ -117,12 +113,6 @@ LIBEDIT_SETTINGS* SCH_BASE_FRAME::libeditconfig() const
}
const wxString SCH_BASE_FRAME::GetZoomLevelIndicator() const
{
return EDA_DRAW_FRAME::GetZoomLevelIndicator();
}
void SCH_BASE_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
{
GetScreen()->SetPageSettings( aPageSettings );
@ -283,15 +273,6 @@ void SCH_BASE_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointe
{
KIGFX::GAL* gal = GetCanvas()->GetGAL();
double selectedZoom = GetScreen()->GetZoom();
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
double scale = 1.0 / ( zoomFactor * selectedZoom );
if( aCenterPoint != wxPoint( 0, 0 ) )
GetCanvas()->GetView()->SetScale( scale, aCenterPoint );
else
GetCanvas()->GetView()->SetScale( scale );
GetCanvas()->GetView()->SetCenter( aCenterPoint );
if( aWarpPointer )

View File

@ -130,14 +130,6 @@ public:
*/
virtual bool GetShowAllPins() const { return true; }
/**
* Function GetZoomLevelIndicator
* returns a human readable value which can be displayed as zoom
* level indicator in dialogs.
* Virtual from the base class
*/
const wxString GetZoomLevelIndicator() const override;
void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
const PAGE_INFO& GetPageSettings () const override;
const wxSize GetPageSizeIU() const override;

View File

@ -430,8 +430,6 @@ void SCH_EDIT_FRAME::CreateScreens()
screen->SetMaxUndoItems( m_UndoRedoCountMax );
SetScreen( screen );
}
GetScreen()->SetZoom( 32.0 );
}

View File

@ -66,35 +66,6 @@
// TODO(JE) Debugging only
#include <profile.h>
#define ZOOM_FACTOR( x ) ( x * IU_PER_MILS )
/* Default zoom values. Limited to these values to keep a decent size
* to menus
*/
static double SchematicZoomList[] =
{
ZOOM_FACTOR( 0.5 ),
ZOOM_FACTOR( 0.7 ),
ZOOM_FACTOR( 1.0 ),
ZOOM_FACTOR( 1.5 ),
ZOOM_FACTOR( 2.0 ),
ZOOM_FACTOR( 3.0 ),
ZOOM_FACTOR( 4.0 ),
ZOOM_FACTOR( 6.0 ),
ZOOM_FACTOR( 8.0 ),
ZOOM_FACTOR( 11.0 ),
ZOOM_FACTOR( 13.0 ),
ZOOM_FACTOR( 16.0 ),
ZOOM_FACTOR( 20.0 ),
ZOOM_FACTOR( 26.0 ),
ZOOM_FACTOR( 32.0 ),
ZOOM_FACTOR( 48.0 ),
ZOOM_FACTOR( 64.0 ),
ZOOM_FACTOR( 80.0 ),
ZOOM_FACTOR( 128.0 )
};
SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) :
BASE_SCREEN( aParent, SCH_SCREEN_T ),
@ -102,11 +73,6 @@ SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) :
{
m_modification_sync = 0;
SetZoom( 32 );
for( unsigned zoom : SchematicZoomList )
m_ZoomList.push_back( zoom );
m_refCount = 0;
// Suitable for schematic only. For libedit and viewlib, must be set to true

View File

@ -585,13 +585,10 @@ void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard()
// Set draw offset, zoom... to values needed to draw in the memory DC
// after saving initial values:
wxPoint tmp_startvisu = screen->m_StartVisu;
double tmpzoom = screen->GetZoom();
wxPoint old_org = screen->m_DrawOrg;
wxPoint old_org = screen->m_DrawOrg;
screen->m_DrawOrg.x = screen->m_DrawOrg.y = 0;
screen->m_StartVisu.x = screen->m_StartVisu.y = 0;
screen->SetZoom( 1 ); // we use zoom = 1 in draw functions.
wxMemoryDC dc;
wxBitmap image( dcsize );
dc.SelectObject( image );
@ -620,7 +617,6 @@ void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard()
screen->m_StartVisu = tmp_startvisu;
screen->m_DrawOrg = old_org;
screen->SetZoom( tmpzoom );
}

View File

@ -433,7 +433,6 @@ int SCH_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent )
m_frame->Schematic().SetCurrentSheet( *sheet );
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
screen->SetZoom( m_frame->GetScreen()->GetZoom() );
screen->TestDanglingEnds();
m_frame->SetScreen( screen );

View File

@ -30,7 +30,6 @@ set( GERBVIEW_SRCS
am_param.cpp
am_primitive.cpp
DCodeSelectionbox.cpp
gbr_screen.cpp
gbr_layout.cpp
gerber_file_image.cpp
gerber_file_image_list.cpp

View File

@ -34,6 +34,8 @@
#include <gerber_file_image_list.h>
#include <gerbview_layer_widget.h>
#include <view/view.h>
#include <base_screen.h>
#include <tool/tool_manager.h>
bool GERBVIEW_FRAME::Clear_DrawLayers( bool query )

View File

@ -1,71 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2020 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
*/
#include <fctsys.h>
#include <macros.h>
#include <gbr_screen.h>
/**
Default GerbView zoom values.
Roughly a 1.5 progression.
*/
static const double gbrZoomList[] =
{
ZOOM_FACTOR( 0.022 ),
ZOOM_FACTOR( 0.035 ),
ZOOM_FACTOR( 0.05 ),
ZOOM_FACTOR( 0.08 ),
ZOOM_FACTOR( 0.13 ),
ZOOM_FACTOR( 0.22 ),
ZOOM_FACTOR( 0.35 ),
ZOOM_FACTOR( 0.6 ),
ZOOM_FACTOR( 1.0 ),
ZOOM_FACTOR( 1.5 ),
ZOOM_FACTOR( 2.2 ),
ZOOM_FACTOR( 3.5 ),
ZOOM_FACTOR( 5.0 ),
ZOOM_FACTOR( 8.0 ),
ZOOM_FACTOR( 13.0 ),
ZOOM_FACTOR( 20.0 ),
ZOOM_FACTOR( 35.0 ),
ZOOM_FACTOR( 50.0 ),
ZOOM_FACTOR( 80.0 ),
ZOOM_FACTOR( 130.0 ),
ZOOM_FACTOR( 220.0 )
};
GBR_SCREEN::GBR_SCREEN( const wxSize& aPageSizeIU ) :
BASE_SCREEN( SCREEN_T )
{
for( unsigned i = 0; i < arrayDim( gbrZoomList ); ++i )
m_ZoomList.push_back( gbrZoomList[i] );
SetZoom( ZOOM_FACTOR( 350 ) ); // a default value for zoom
m_Active_Layer = 0; // default active layer = first graphic layer
InitDataPoints( aPageSizeIU );
}

View File

@ -1,53 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2014 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
*/
#ifndef GBR_SCREEN_H
#define GBR_SCREEN_H
#include <base_units.h>
#include <base_screen.h>
#define ZOOM_FACTOR( x ) ( x * IU_PER_MILS )
/* Handle info to display a board */
class GBR_SCREEN : public BASE_SCREEN
{
public:
int m_Active_Layer;
/**
* Constructor
* @param aPageSizeIU is the size of the initial paper page in internal units.
*/
GBR_SCREEN( const wxSize& aPageSizeIU );
/**
* Function ClearUndoORRedoList
* virtual pure in BASE_SCREEN, so it must be defined here
*/
void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override
{ }
};
#endif // GBR_SCREEN_H

View File

@ -50,6 +50,7 @@
#include <tools/gerbview_selection_tool.h>
#include <tools/gerbview_control.h>
#include <view/view.h>
#include <base_screen.h>
#include <gerbview_painter.h>
#include <geometry/shape_poly_set.h>
#include <widgets/paged_dialog.h>
@ -62,28 +63,24 @@
GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent )
: EDA_DRAW_FRAME( aKiway, aParent, FRAME_GERBER, wxT( "GerbView" ), wxDefaultPosition,
wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GERBVIEW_FRAME_NAME ),
m_activeLayer( 0 ),
m_zipFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_ZIP_FILE1,
ID_GERBVIEW_ZIP_FILE_LIST_CLEAR, _( "Clear Recent Zip Files" ) ),
m_drillFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_DRILL_FILE1,
ID_GERBVIEW_DRILL_FILE_LIST_CLEAR, _( "Clear Recent Drill Files" ) ),
m_jobFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_JOB_FILE1,
ID_GERBVIEW_JOB_FILE_LIST_CLEAR, _( "Clear Recent Job Files" ) )
ID_GERBVIEW_JOB_FILE_LIST_CLEAR, _( "Clear Recent Job Files" ) ),
m_TextInfo( nullptr )
{
m_gerberLayout = NULL;
m_zoomLevelCoeff = ZOOM_FACTOR( 110 ); // Adjusted to roughly displays zoom level = 1
// when the screen shows a 1:1 image
// obviously depends on the monitor,
// but this is an acceptable value
m_show_layer_manager_tools = true;
m_showBorderAndTitleBlock = false; // true for reference drawings.
m_SelLayerBox = NULL;
m_SelLayerBox = NULL;
m_DCodeSelector = NULL;
m_SelComponentBox = nullptr;
m_SelNetnameBox = nullptr;
m_SelAperAttributesBox = nullptr;
m_displayMode = 0;
m_displayMode = 0;
m_AboutTitle = "GerbView";
SHAPE_POLY_SET dummy; // A ugly trick to force the linker to include
@ -115,7 +112,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent )
SetVisibleLayers( LSET::AllLayersMask() ); // All draw layers visible.
SetScreen( new GBR_SCREEN( GetPageSettings().GetSizeIU() ) );
SetScreen( new BASE_SCREEN( GetPageSettings().GetSizeIU() ) );
// Create the PCB_LAYER_WIDGET *after* SetLayout():
m_LayersManager = new GERBER_LAYER_WIDGET( this, GetCanvas() );
@ -300,35 +297,62 @@ void GERBVIEW_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{
EDA_DRAW_FRAME::LoadSettings( aCfg );
if( aCfg->m_Window.grid.sizes.empty() )
{
aCfg->m_Window.grid.sizes = { "100 mil",
"50 mil",
"25 mil",
"20 mil",
"10 mil",
"5 mil",
"2.5 mil",
"2 mil",
"1 mil",
"0.5 mil",
"0.2 mil",
"0.1 mil",
"5.0 mm",
"2.5 mm",
"1.0 mm",
"0.5 mm",
"0.25 mm",
"0.2 mm",
"0.1 mm",
"0.05 mm",
"0.025 mm",
"0.01 mm" };
}
if( aCfg->m_Window.zoom_factors.empty() )
{
aCfg->m_Window.zoom_factors = { 0.022,
0.035,
0.05,
0.08,
0.13,
0.22,
0.35,
0.6,
1.0,
2.2,
3.5,
5.0,
8.0,
13.0,
22.0,
35.0,
50.0,
80.0,
130.0,
220.0 };
}
for( double& factor : aCfg->m_Window.zoom_factors )
factor = std::min( factor, MAX_ZOOM_FACTOR );
GERBVIEW_SETTINGS* cfg = dynamic_cast<GERBVIEW_SETTINGS*>( aCfg );
wxCHECK( cfg, /*void*/ );
if( cfg->m_Window.grid.sizes.empty() )
{
cfg->m_Window.grid.sizes = { "100 mil",
"50 mil",
"25 mil",
"20 mil",
"10 mil",
"5 mil",
"2.5 mil",
"2 mil",
"1 mil",
"0.5 mil",
"0.2 mil",
"0.1 mil",
"5.0 mm",
"2.5 mm",
"1.0 mm",
"0.5 mm",
"0.25 mm",
"0.2 mm",
"0.1 mm",
"0.05 mm",
"0.025 mm",
"0.01 mm" };
}
SetElementVisibility( LAYER_WORKSHEET, cfg->m_Appearance.show_border_and_titleblock );
PAGE_INFO pageInfo( wxT( "GERBER" ) );
@ -860,15 +884,9 @@ void GERBVIEW_FRAME::SetLayerColor( int aLayer, COLOR4D aColor )
}
int GERBVIEW_FRAME::GetActiveLayer()
{
return ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer;
}
void GERBVIEW_FRAME::SetActiveLayer( int aLayer, bool doLayerWidgetUpdate )
{
( (GBR_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
m_activeLayer = aLayer;
if( doLayerWidgetUpdate )
m_LayersManager->SelectLayer( aLayer );
@ -886,10 +904,9 @@ void GERBVIEW_FRAME::SetActiveLayer( int aLayer, bool doLayerWidgetUpdate )
void GERBVIEW_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
{
m_paper = aPageSettings;
GBR_SCREEN* screen = static_cast<GBR_SCREEN*>( GetScreen() );
if( screen )
screen->InitDataPoints( aPageSettings.GetSizeIU() );
if( GetScreen() )
GetScreen()->InitDataPoints( aPageSettings.GetSizeIU() );
auto drawPanel = static_cast<GERBVIEW_DRAW_PANEL_GAL*>( GetCanvas() );
@ -897,7 +914,7 @@ void GERBVIEW_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
auto worksheet = new KIGFX::WS_PROXY_VIEW_ITEM( IU_PER_MILS, &GetPageSettings(),
&Prj(), &GetTitleBlock() );
if( screen != NULL )
if( GetScreen() )
{
worksheet->SetSheetNumber( 1 );
worksheet->SetSheetCount( 1 );
@ -987,9 +1004,7 @@ void GERBVIEW_FRAME::UpdateStatusBar()
{
EDA_DRAW_FRAME::UpdateStatusBar();
GBR_SCREEN* screen = (GBR_SCREEN*) GetScreen();
if( !screen )
if( !GetScreen() )
return;
wxString line;
@ -997,8 +1012,8 @@ void GERBVIEW_FRAME::UpdateStatusBar()
if( GetShowPolarCoords() ) // display relative polar coordinates
{
double dx = cursorPos.x - screen->m_LocalOrigin.x;
double dy = cursorPos.y - screen->m_LocalOrigin.y;
double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
double theta = RAD2DEG( atan2( -dy, dx ) );
double ro = hypot( dx, dy );
wxString formatter;
@ -1051,8 +1066,8 @@ void GERBVIEW_FRAME::UpdateStatusBar()
if( !GetShowPolarCoords() ) // display relative cartesian coordinates
{
// Display relative coordinates:
dXpos = To_User_Unit( GetUserUnits(), cursorPos.x - screen->m_LocalOrigin.x );
dYpos = To_User_Unit( GetUserUnits(), cursorPos.y - screen->m_LocalOrigin.y );
dXpos = To_User_Unit( GetUserUnits(), cursorPos.x - GetScreen()->m_LocalOrigin.x );
dYpos = To_User_Unit( GetUserUnits(), cursorPos.y - GetScreen()->m_LocalOrigin.y );
// We already decided the formatter above
line.Printf( relformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
@ -1063,12 +1078,6 @@ void GERBVIEW_FRAME::UpdateStatusBar()
}
const wxString GERBVIEW_FRAME::GetZoomLevelIndicator() const
{
return EDA_DRAW_FRAME::GetZoomLevelIndicator();
}
GERBER_FILE_IMAGE* GERBVIEW_FRAME::GetGbrImage( int aIdx ) const
{
return m_gerberLayout->GetImagesList()->GetGbrImage( aIdx );
@ -1184,23 +1193,19 @@ void GERBVIEW_FRAME::updateZoomSelectBox()
if( m_zoomSelectBox == NULL )
return;
wxString msg;
double zoom = GetCanvas()->GetGAL()->GetZoomFactor() / ZOOM_COEFF;
m_zoomSelectBox->Clear();
m_zoomSelectBox->Append( _( "Zoom Auto" ) );
m_zoomSelectBox->SetSelection( 0 );
for( unsigned i = 0; i < GetScreen()->m_ZoomList.size(); ++i )
for( unsigned i = 0; i < config()->m_Window.zoom_factors.size(); ++i )
{
msg = _( "Zoom " );
double current = config()->m_Window.zoom_factors[i];
double level = m_zoomLevelCoeff / (double)GetScreen()->m_ZoomList[i];
wxString value = wxString::Format( wxT( "%.2f" ), level );
msg += value;
m_zoomSelectBox->Append( wxString::Format( _( "Zoom %.2f" ), current ) );
m_zoomSelectBox->Append( msg );
if( GetScreen()->GetZoom() == GetScreen()->m_ZoomList[i] )
if( zoom == current )
m_zoomSelectBox->SetSelection( i + 1 );
}
}

View File

@ -30,9 +30,9 @@
#include <gerbview.h>
#include <convert_to_biu.h>
#include <gbr_layout.h>
#include <gbr_screen.h>
#include <page_info.h>
#include <gbr_display_options.h>
#include <undo_redo_container.h>
#define NO_AVAILABLE_LAYERS UNDEFINED_LAYER
@ -55,6 +55,7 @@ class REPORTER;
class GERBVIEW_FRAME : public EDA_DRAW_FRAME // PCB_BASE_FRAME
{
GBR_LAYOUT* m_gerberLayout;
int m_activeLayer;
wxPoint m_grid_origin;
PAGE_INFO m_paper; // used only to show paper limits to screen
GBR_DISPLAY_OPTIONS m_DisplayOptions;
@ -221,14 +222,6 @@ public:
void ReCreateMenuBar() override;
void UpdateStatusBar() override;
/**
* Function GetZoomLevelIndicator
* returns a human readable value which can be displayed as zoom
* level indicator in dialogs.
* Virtual from the base class
*/
const wxString GetZoomLevelIndicator() const override;
/**
* Function GetDisplayMode
* @return 0 for fast mode (not fully compatible with negative objects)
@ -327,7 +320,7 @@ public:
* Function SetActiveLayer
* returns the active layer
*/
int GetActiveLayer();
int GetActiveLayer() const { return m_activeLayer; }
/**
* Function getNextAvailableLayer

Some files were not shown because too many files have changed in this diff Show More