2014-12-23 13:01:59 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2020-12-19 23:29:10 +00:00
|
|
|
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-10-31 12:04:46 +00:00
|
|
|
* Copyright (C) 2007-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-12-23 13:01:59 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-01-29 10:37:29 +00:00
|
|
|
* @file page_info.h
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-29 10:37:29 +00:00
|
|
|
#ifndef PAGE_INFO_H
|
|
|
|
#define PAGE_INFO_H
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2024-01-09 12:26:04 +00:00
|
|
|
#include <kicommon.h>
|
2020-10-18 18:24:20 +00:00
|
|
|
#include <wx/string.h>
|
2022-08-27 17:23:43 +00:00
|
|
|
#include <math/vector2d.h>
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2018-08-04 11:18:15 +00:00
|
|
|
/// Min and max page sizes for clamping, in mils.
|
2022-06-13 15:51:29 +00:00
|
|
|
#define MIN_PAGE_SIZE_MILS 1000
|
2022-03-22 08:40:16 +00:00
|
|
|
#define MAX_PAGE_SIZE_PCBNEW_MILS 48000
|
|
|
|
#define MAX_PAGE_SIZE_EESCHEMA_MILS 120000
|
2018-08-04 11:18:15 +00:00
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
/// Min and max page sizes for clamping, in mm.
|
|
|
|
#define MIN_PAGE_SIZE_MM 25.4
|
|
|
|
#define MAX_PAGE_SIZE_PCBNEW_MM 48000*.0254
|
|
|
|
#define MAX_PAGE_SIZE_EESCHEMA_MM 120000*.0254
|
|
|
|
|
2023-09-08 02:29:40 +00:00
|
|
|
class OUTPUTFORMATTER;
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* Describe the page size and margins of a paper page on which to eventually print or plot.
|
|
|
|
*
|
|
|
|
* Paper sizes are often described in inches. Here paper is described in 1/1000th of an
|
|
|
|
* inch (mils). For convenience there are some read only accessors for internal units
|
|
|
|
* which is a compile time calculation, not runtime.
|
2014-12-23 13:01:59 +00:00
|
|
|
*
|
|
|
|
* @author Dick Hollenbeck
|
|
|
|
*/
|
2024-01-09 12:26:04 +00:00
|
|
|
class KICOMMON_API PAGE_INFO
|
2014-12-23 13:01:59 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
PAGE_INFO( const wxString& aType = PAGE_INFO::A3, bool IsPortrait = false );
|
|
|
|
|
|
|
|
// paper size names which are part of the public API, pass to SetType() or
|
|
|
|
// above constructor.
|
|
|
|
|
|
|
|
// these were once wxStrings, but it caused static construction sequence problems:
|
2020-07-21 00:00:36 +00:00
|
|
|
static const wxChar A5[];
|
2014-12-23 13:01:59 +00:00
|
|
|
static const wxChar A4[];
|
|
|
|
static const wxChar A3[];
|
|
|
|
static const wxChar A2[];
|
|
|
|
static const wxChar A1[];
|
|
|
|
static const wxChar A0[];
|
|
|
|
static const wxChar A[];
|
|
|
|
static const wxChar B[];
|
|
|
|
static const wxChar C[];
|
|
|
|
static const wxChar D[];
|
|
|
|
static const wxChar E[];
|
|
|
|
static const wxChar GERBER[];
|
|
|
|
static const wxChar USLetter[];
|
|
|
|
static const wxChar USLegal[];
|
|
|
|
static const wxChar USLedger[];
|
|
|
|
static const wxChar Custom[]; ///< "User" defined page type
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* Set the name of the page type and also the sizes and margins commonly associated with
|
|
|
|
* that type name.
|
2014-12-23 13:01:59 +00:00
|
|
|
*
|
|
|
|
* @param aStandardPageDescriptionName is a wxString constant giving one of:
|
2020-07-21 00:00:36 +00:00
|
|
|
* "A5" "A4" "A3" "A2" "A1" "A0" "A" "B" "C" "D" "E" "GERBER", "USLetter", "USLegal",
|
2014-12-23 13:01:59 +00:00
|
|
|
* "USLedger", or "User". If "User" then the width and height are custom,
|
|
|
|
* and will be set according to <b>previous</b> calls to
|
|
|
|
* static PAGE_INFO::SetUserWidthMils() and
|
|
|
|
* static PAGE_INFO::SetUserHeightMils();
|
2017-12-18 13:07:17 +00:00
|
|
|
* @param aIsPortrait Set to true to set page orientation to portrait mode.
|
2020-12-19 23:29:10 +00:00
|
|
|
* @return true if @a aStandarePageDescription was a recognized type.
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
2017-12-18 13:07:17 +00:00
|
|
|
bool SetType( const wxString& aStandardPageDescriptionName, bool aIsPortrait = false );
|
2014-12-23 13:01:59 +00:00
|
|
|
const wxString& GetType() const { return m_type; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if the object has the default page settings which are A3, landscape.
|
|
|
|
*/
|
|
|
|
bool IsDefault() const { return m_type == PAGE_INFO::A3 && !m_portrait; }
|
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* @return true if the type is Custom.
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
|
|
|
bool IsCustom() const;
|
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* Rotate the paper page 90 degrees.
|
|
|
|
*
|
|
|
|
* This PAGE_INFO may either be in portrait or landscape mode. Use this function to
|
|
|
|
* change from one mode to the other mode.
|
|
|
|
*
|
|
|
|
* @param aIsPortrait if true and not already in portrait mode, will change this
|
|
|
|
* PAGE_INFO to portrait mode. Or if false and not already in
|
|
|
|
* landscape mode, will change this PAGE_INFO to landscape mode.
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
2017-12-18 13:07:17 +00:00
|
|
|
void SetPortrait( bool aIsPortrait );
|
2014-12-23 13:01:59 +00:00
|
|
|
bool IsPortrait() const { return m_portrait; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ws' style printing orientation (wxPORTRAIT or wxLANDSCAPE).
|
|
|
|
*/
|
|
|
|
wxPrintOrientation GetWxOrientation() const { return IsPortrait() ? wxPORTRAIT : wxLANDSCAPE; }
|
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* @return wxPrintData's style paper id associated with page type name.
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
|
|
|
wxPaperSize GetPaperId() const { return m_paper_id; }
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
void SetWidthMM( double aWidthInMM ) { SetWidthMils( aWidthInMM * 1000 / 25.4 ); }
|
|
|
|
void SetWidthMils( double aWidthInMils );
|
|
|
|
double GetWidthMils() const { return m_size.x; }
|
|
|
|
double GetWidthMM() const { return m_size.x * 25.4 / 1000; }
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
void SetHeightMM( double aHeightInMM ) { SetHeightMils( aHeightInMM * 1000 / 25.4 ); }
|
|
|
|
void SetHeightMils( double aHeightInMils );
|
|
|
|
double GetHeightMils() const { return m_size.y; }
|
|
|
|
double GetHeightMM() const { return m_size.y * 25.4 / 1000; }
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
const VECTOR2D& GetSizeMils() const { return m_size; }
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2022-08-27 17:23:43 +00:00
|
|
|
/**
|
|
|
|
* Gets the page width in IU
|
|
|
|
*
|
|
|
|
* @param aIUScale The IU scale, this is most likely always going to be IU_PER_MILS
|
|
|
|
* variable being passed. Note, this constexpr variable changes depending
|
|
|
|
* on application, hence why it is passed.
|
|
|
|
*/
|
|
|
|
int GetWidthIU( double aIUScale ) const { return aIUScale * GetWidthMils(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the page height in IU
|
|
|
|
*
|
|
|
|
* @param aIUScale The IU scale, this is most likely always going to be IU_PER_MILS
|
|
|
|
* variable being passed. Note, this constexpr variable changes depending
|
|
|
|
* on application, hence why it is passed.
|
|
|
|
*/
|
|
|
|
int GetHeightIU( double aIUScale ) const { return aIUScale * GetHeightMils(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the page size in internal units
|
|
|
|
*
|
|
|
|
* @param aIUScale The IU scale, this is most likely always going to be IU_PER_MILS
|
|
|
|
* variable being passed. Note, this constexpr variable changes depending
|
|
|
|
* on application, hence why it is passed.
|
|
|
|
*/
|
2023-10-31 12:04:46 +00:00
|
|
|
const VECTOR2D GetSizeIU( double aIUScale ) const
|
2022-08-27 17:23:43 +00:00
|
|
|
{
|
2023-10-31 12:04:46 +00:00
|
|
|
return VECTOR2D( GetWidthIU( aIUScale ), GetHeightIU( aIUScale ) );
|
2022-08-27 17:23:43 +00:00
|
|
|
}
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* Set the width of Custom page in mils for any custom page constructed or made via
|
|
|
|
* SetType() after making this call.
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
2023-10-31 12:04:46 +00:00
|
|
|
static void SetCustomWidthMils( double aWidthInMils );
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* Set the height of Custom page in mils for any custom page constructed or made via
|
|
|
|
* SetType() after making this call.
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
2023-10-31 12:04:46 +00:00
|
|
|
static void SetCustomHeightMils( double aHeightInMils );
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* @return custom paper width in mils.
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
2023-10-31 12:04:46 +00:00
|
|
|
static double GetCustomWidthMils() { return s_user_width; }
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* @return custom paper height in mils.
|
2014-12-23 13:01:59 +00:00
|
|
|
*/
|
2023-10-31 12:04:46 +00:00
|
|
|
static double GetCustomHeightMils() { return s_user_height; }
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-19 23:29:10 +00:00
|
|
|
* Output the page class to \a aFormatter in s-expression form.
|
2014-12-23 13:01:59 +00:00
|
|
|
*
|
|
|
|
* @param aFormatter The #OUTPUTFORMATTER object to write to.
|
|
|
|
* @param aNestLevel The indentation next level.
|
|
|
|
* @param aControlBits The control bit definition for object specific formatting.
|
|
|
|
* @throw IO_ERROR on write error.
|
|
|
|
*/
|
2017-06-08 21:47:21 +00:00
|
|
|
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// only the class implementation(s) may use this constructor
|
2023-10-31 12:04:46 +00:00
|
|
|
PAGE_INFO( const VECTOR2D& aSizeMils, const wxString& aName, wxPaperSize aPaperId );
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// standard pre-defined sizes
|
2020-07-21 00:00:36 +00:00
|
|
|
static const PAGE_INFO pageA5;
|
2014-12-23 13:01:59 +00:00
|
|
|
static const PAGE_INFO pageA4;
|
|
|
|
static const PAGE_INFO pageA3;
|
|
|
|
static const PAGE_INFO pageA2;
|
|
|
|
static const PAGE_INFO pageA1;
|
|
|
|
static const PAGE_INFO pageA0;
|
|
|
|
static const PAGE_INFO pageA;
|
|
|
|
static const PAGE_INFO pageB;
|
|
|
|
static const PAGE_INFO pageC;
|
|
|
|
static const PAGE_INFO pageD;
|
|
|
|
static const PAGE_INFO pageE;
|
|
|
|
static const PAGE_INFO pageGERBER;
|
|
|
|
|
|
|
|
static const PAGE_INFO pageUSLetter;
|
|
|
|
static const PAGE_INFO pageUSLegal;
|
|
|
|
static const PAGE_INFO pageUSLedger;
|
|
|
|
|
|
|
|
static const PAGE_INFO pageUser;
|
|
|
|
|
|
|
|
// all dimensions here are in mils
|
|
|
|
|
|
|
|
wxString m_type; ///< paper type: A4, A3, etc.
|
2023-10-31 12:04:46 +00:00
|
|
|
VECTOR2D m_size; ///< mils
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
bool m_portrait; ///< true if portrait, false if landscape
|
|
|
|
|
|
|
|
wxPaperSize m_paper_id; ///< wx' style paper id.
|
|
|
|
|
2023-10-31 12:04:46 +00:00
|
|
|
static double s_user_height;
|
|
|
|
static double s_user_width;
|
2014-12-23 13:01:59 +00:00
|
|
|
|
|
|
|
void updatePortrait();
|
|
|
|
|
|
|
|
void setMargins();
|
|
|
|
};
|
|
|
|
|
2018-01-29 10:37:29 +00:00
|
|
|
#endif // PAGE_INFO_H
|