2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file classpcb.cpp
|
|
|
|
* @brief Member functions of classes used in Pcbnew (see pcbstruct.h)
|
|
|
|
* except for tracks (see class_track.cpp).
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <class_pcb_screen.h>
|
2012-04-12 21:31:31 +00:00
|
|
|
#include <eda_text.h> // FILLED
|
2012-04-16 01:25:26 +00:00
|
|
|
#include <base_units.h>
|
2012-04-12 21:31:31 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <class_board_design_settings.h>
|
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew_id.h>
|
2008-12-05 16:03:05 +00:00
|
|
|
|
|
|
|
|
2016-06-05 11:49:25 +00:00
|
|
|
#define ZOOM_FACTOR( x ) ( x * IU_PER_MILS / 10 )
|
|
|
|
#define DMIL_GRID( x ) wxRealPoint( x * IU_PER_MILS / 10,\
|
|
|
|
x * IU_PER_MILS / 10 )
|
2012-04-26 21:34:20 +00:00
|
|
|
#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM,\
|
|
|
|
x * IU_PER_MM )
|
2012-04-16 01:25:26 +00:00
|
|
|
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
/**
|
|
|
|
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 )
|
|
|
|
*/
|
2015-01-06 07:38:58 +00:00
|
|
|
#define DEFAULT_ZOOM ZOOM_FACTOR( 120 )
|
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
static const double pcbZoomList[] =
|
2009-06-18 13:30:52 +00:00
|
|
|
{
|
2012-04-23 21:56:26 +00:00
|
|
|
ZOOM_FACTOR( 0.1 ),
|
|
|
|
ZOOM_FACTOR( 0.2 ),
|
|
|
|
ZOOM_FACTOR( 0.3 ),
|
2012-04-16 01:25:26 +00:00
|
|
|
ZOOM_FACTOR( 0.5 ),
|
|
|
|
ZOOM_FACTOR( 1.0 ),
|
|
|
|
ZOOM_FACTOR( 1.5 ),
|
|
|
|
ZOOM_FACTOR( 2.0 ),
|
|
|
|
ZOOM_FACTOR( 3.0 ),
|
|
|
|
ZOOM_FACTOR( 4.5 ),
|
2015-01-06 07:38:58 +00:00
|
|
|
ZOOM_FACTOR( 6.0 ),
|
|
|
|
ZOOM_FACTOR( 8.0 ),
|
|
|
|
ZOOM_FACTOR( 11.0 ),
|
2012-04-16 01:25:26 +00:00
|
|
|
ZOOM_FACTOR( 15.0 ),
|
|
|
|
ZOOM_FACTOR( 22.0 ),
|
|
|
|
ZOOM_FACTOR( 35.0 ),
|
|
|
|
ZOOM_FACTOR( 50.0 ),
|
|
|
|
ZOOM_FACTOR( 80.0 ),
|
2015-01-06 07:38:58 +00:00
|
|
|
ZOOM_FACTOR( 110.0 ),
|
|
|
|
ZOOM_FACTOR( 150.0 ),
|
2012-04-16 01:25:26 +00:00
|
|
|
ZOOM_FACTOR( 200.0 ),
|
2012-04-23 21:56:26 +00:00
|
|
|
ZOOM_FACTOR( 300.0 ),
|
2012-05-06 20:10:43 +00:00
|
|
|
/*
|
|
|
|
The largest distance that wx can support is INT_MAX, since it represents
|
|
|
|
distance often in a wxCoord or wxSize. As a scalar, a distance is always
|
|
|
|
positive. On most machines which run KiCad, int is 32 bits and INT_MAX is
|
|
|
|
2147483647. The most difficult distance for a virtual (world) cartesian
|
|
|
|
space is the hypotenuse, or diagonal measurement at a 45 degree angle. This
|
|
|
|
puts the most stress on the distance magnitude within the bounded virtual
|
|
|
|
space. So if we allow this distance to be our constraint of <= INT_MAX, this
|
|
|
|
constraint then propagates to the maximum distance in X and in Y that can be
|
|
|
|
supported on each axis. Remember that the hypotenuse of a 1x1 square is
|
|
|
|
sqrt( 1x1 + 1x1 ) = sqrt(2) = 1.41421356.
|
|
|
|
|
|
|
|
hypotenuse of any square = sqrt(2) * deltaX;
|
|
|
|
|
|
|
|
Let maximum supported hypotenuse be INT_MAX, then:
|
|
|
|
|
|
|
|
MAX_AXIS = INT_MAX / sqrt(2) = 2147483647 / 1.41421356 = 1518500251
|
|
|
|
|
|
|
|
This maximum distance is imposed by wxWidgets, not by KiCad. The imposition
|
|
|
|
comes in the form of the data structures used in the graphics API at the
|
|
|
|
wxDC level. Obviously when we are not interacting with wx we can use double
|
|
|
|
to compute distances larger than this. For example the computation of the
|
|
|
|
total length of a net, can and should be done in double, since it might
|
|
|
|
actually be longer than a single diagonal line.
|
|
|
|
|
|
|
|
The next choice is what to use for internal units (IU), sometimes called
|
|
|
|
world units. If nanometers, then the virtual space must be limited to
|
|
|
|
about 1.5 x 1.5 meters square. This is 1518500251 divided by 1e9 nm/meter.
|
|
|
|
|
|
|
|
The maximum zoom factor then depends on the client window size. If we ask
|
|
|
|
wx to handle something outside INT_MIN to INT_MAX, there are unreported
|
|
|
|
problems in the non-Debug build because wxRound() goes silent.
|
|
|
|
|
|
|
|
Let:
|
|
|
|
const double MAX_AXIS = 1518500251;
|
|
|
|
|
|
|
|
Then a maximum zoom factor for a screen of 1920 pixels wide is
|
|
|
|
1518500251 / 1920 = 790885.
|
|
|
|
|
|
|
|
The largest ZOOM_FACTOR in above table is ZOOM_FACTOR( 300 ), which computes
|
|
|
|
out to 762000 just below 790885.
|
|
|
|
*/
|
2009-03-12 15:24:52 +00:00
|
|
|
};
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
// Default grid sizes for PCB editor screens.
|
|
|
|
static GRID_TYPE pcbGridList[] =
|
2009-06-18 13:30:52 +00:00
|
|
|
{
|
2009-03-12 15:24:52 +00:00
|
|
|
// predefined grid list in 0.0001 inches
|
2012-04-16 01:25:26 +00:00
|
|
|
{ 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 ) },
|
2009-03-12 15:24:52 +00:00
|
|
|
|
|
|
|
// predefined grid list in mm
|
2012-04-16 01:25:26 +00:00
|
|
|
{ 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 ) }
|
2008-12-05 16:03:05 +00:00
|
|
|
};
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) :
|
|
|
|
BASE_SCREEN( SCREEN_T )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-05-06 23:32:01 +00:00
|
|
|
// D(wxSize displayz = wxGetDisplaySize();)
|
|
|
|
// D(printf( "displayz x:%d y:%d lastZoomFactor: %.16g\n", displayz.x, displayz.y, pcbZoomList[DIM(pcbZoomList)-1] );)
|
2012-05-06 20:10:43 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
for( unsigned i = 0; i < DIM( pcbZoomList ); ++i )
|
2012-05-06 20:10:43 +00:00
|
|
|
m_ZoomList.push_back( pcbZoomList[i] );
|
2008-12-05 16:03:05 +00:00
|
|
|
|
2011-12-31 05:44:00 +00:00
|
|
|
for( unsigned i = 0; i < DIM( pcbGridList ); ++i )
|
|
|
|
AddGrid( pcbGridList[i] );
|
2007-08-06 21:02:23 +00:00
|
|
|
|
2012-05-06 20:10:43 +00:00
|
|
|
// Set the working grid size to a reasonable value (in 1/10000 inch)
|
2012-04-16 01:25:26 +00:00
|
|
|
SetGrid( DMIL_GRID( 500 ) );
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2015-09-06 20:49:47 +00:00
|
|
|
m_Active_Layer = F_Cu; // default active layer = front layer
|
2014-06-24 16:17:18 +00:00
|
|
|
m_Route_Layer_TOP = F_Cu; // default layers pair for vias (bottom to top)
|
|
|
|
m_Route_Layer_BOTTOM = B_Cu;
|
2011-12-31 05:44:00 +00:00
|
|
|
|
2015-01-06 07:38:58 +00:00
|
|
|
SetZoom( DEFAULT_ZOOM ); // a default value for zoom
|
2011-12-31 05:44:00 +00:00
|
|
|
|
|
|
|
InitDataPoints( aPageSizeIU );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 21:02:23 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
PCB_SCREEN::~PCB_SCREEN()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-29 13:10:36 +00:00
|
|
|
ClearUndoRedoList();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 11:45:35 +00:00
|
|
|
|
2012-04-16 23:31:29 +00:00
|
|
|
int PCB_SCREEN::MilsToIuScalar()
|
2008-12-05 16:03:05 +00:00
|
|
|
{
|
2012-04-26 21:34:20 +00:00
|
|
|
return (int)IU_PER_MILS;
|
2008-12-05 16:03:05 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-06 11:45:35 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
DISPLAY_OPTIONS::DISPLAY_OPTIONS()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-02-02 08:06:39 +00:00
|
|
|
m_DisplayPadFill = FILLED;
|
|
|
|
m_DisplayViaFill = FILLED;
|
2015-01-10 10:27:49 +00:00
|
|
|
m_DisplayPadNum = true;
|
|
|
|
m_DisplayPadIsol = true;
|
|
|
|
|
2015-02-02 08:06:39 +00:00
|
|
|
m_DisplayModEdgeFill = FILLED;
|
|
|
|
m_DisplayModTextFill = FILLED;
|
|
|
|
m_DisplayPcbTrackFill = FILLED; // false = sketch , true = filled
|
2015-01-10 10:27:49 +00:00
|
|
|
m_ShowTrackClearanceMode = SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS;
|
2009-10-10 01:25:53 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
m_DisplayPolarCood = false; /* false = display absolute coordinates,
|
|
|
|
* true = display polar cordinates */
|
|
|
|
m_DisplayZonesMode = 0; /* 0 = Show filled areas outlines in zones,
|
|
|
|
* 1 = do not show filled areas outlines
|
|
|
|
* 2 = show outlines of filled areas */
|
|
|
|
m_DisplayNetNamesMode = 3; /* 0 do not show netnames,
|
|
|
|
* 1 show netnames on pads
|
|
|
|
* 2 show netnames on tracks
|
|
|
|
* 3 show netnames on tracks and pads */
|
2015-02-02 08:06:39 +00:00
|
|
|
m_DisplayDrawItemsFill = FILLED;
|
2015-01-10 10:27:49 +00:00
|
|
|
m_ContrastModeDisplay = false;
|
|
|
|
m_MaxLinksShowed = 3; // in track creation: number of hairwires shown
|
|
|
|
m_Show_Module_Ratsnest = true; // When moving a footprint: allows displaying a ratsnest
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|