45#include <wx/tokenzr.h>
46#include <wx/filedlg.h>
47#include <wx/dcmemory.h>
51#define MAX_PAGE_EXAMPLE_SIZE 200
60#define _HKI( x ) wxT( x )
68 _HKI(
"A0 841x1189mm"),
74 _HKI(
"USLetter 8.5x11in"),
75 _HKI(
"USLegal 8.5x14in"),
76 _HKI(
"USLedger 11x17in"),
77 _HKI(
"User (Custom)"),
86 m_screen( m_parent->GetScreen() ),
87 m_initialized( false ),
88 m_pageBitmap( nullptr ),
89 m_iuPerMils( aIuPerMils ),
90 m_embeddedFiles( aEmbeddedFiles ),
91 m_customSizeX( aParent, m_userSizeXLabel, m_userSizeXCtrl, m_userSizeXUnits ),
92 m_customSizeY( aParent, m_userSizeYLabel, m_userSizeYCtrl, m_userSizeYUnits )
103 wxString serialization;
111 SetTitle(
_(
"Preview Settings" ) );
117 SetTitle(
_(
"Page Settings" ) );
145 for(
const wxString& pageFmt :
pageFmts )
159 wxCommandEvent
dummy;
210 GetSizer()->SetSizeHints(
this );
221 const wxString paperType =
m_pageFmt[idx];
254 const wxString paperType =
m_pageFmt[idx];
465 datetime.FormatISODate();
473 bool success =
false;
487 wxString::Format(
_(
"Error loading drawing sheet '%s'." ),
496 const wxString paperType =
m_pageFmt[idx];
556 wxFAIL_MSG(
"The translation for paper size must preserve original spellings" );
585 for(
unsigned i = 0; i <
m_pageFmt.GetCount(); ++i )
590 while( st.HasMoreTokens() )
592 if( st.GetNextToken() == aPaperSize )
604 int lyWidth, lyHeight;
611 double lyRatio = clamped_layout_size.
x < clamped_layout_size.
y ?
612 (double) clamped_layout_size.
y / clamped_layout_size.
x :
613 (
double) clamped_layout_size.
x / clamped_layout_size.
y;
615 if( clamped_layout_size.
x < clamped_layout_size.
y )
618 lyWidth =
KiROUND( (
double) lyHeight / lyRatio );
623 lyHeight =
KiROUND( (
double) lyWidth / lyRatio );
632 m_pageBitmap =
new wxBitmap( lyWidth + 1, lyHeight + 1 );
636 double scaleW = (double) lyWidth / clamped_layout_size.
x;
637 double scaleH = (
double) lyHeight / clamped_layout_size.
y;
638 double scale = std::min( scaleW, scaleH );
641 wxSize example_size( lyWidth + 1, lyHeight + 1 );
644 memDC.SetClippingRegion( wxPoint( 0, 0 ), example_size );
657 wxString pageFmtName =
m_pageFmt[idx].BeforeFirst(
' ' );
658 bool portrait = clamped_layout_size.
x < clamped_layout_size.
y;
659 pageDUMMY.
SetType( pageFmtName, portrait );
694 memDC.SelectObject( wxNullBitmap );
710 const wxString paperType =
m_pageFmt[idx];
729 static const wxChar* papers[] = {
749 for( i=0; i <
arrayDim( papers ); ++i )
751 if( paperType.Contains( papers[i] ) )
781 customSizeX = std::clamp( customSizeX,
double( INT_MIN ),
double( INT_MAX ) );
782 customSizeY = std::clamp( customSizeY,
double( INT_MIN ),
double( INT_MAX ) );
790 wxString
name = fn.GetFullName();
794 if( fn.IsAbsolute() )
802 if( expanded.IsAbsolute() )
803 path = expanded.GetPath();
810 wxFileDialog fileDialog(
this,
_(
"Drawing Sheet File" ),
path,
name,
812 wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
815 fileDialog.SetCustomizeHook( customize );
817 if( fileDialog.ShowModal() != wxID_OK )
820 wxString fileName = fileDialog.GetPath();
821 wxString shortFileName;
825 fn.Assign( fileName );
827 shortFileName = result->
GetLink();
833 fn = wxFileName( fileName );
835 shortFileName = fn.GetFullPath();
840 shortFileName =
NormalizePath( fileName, &
Pgm().GetLocalEnvVariables(),
nullptr );
843 std::unique_ptr<DS_DATA_MODEL> ws = std::make_unique<DS_DATA_MODEL>();
845 if( !ws->LoadDrawingSheet( fileName, &msg ) )
848 wxString::Format(
_(
"Error loading drawing sheet '%s'.\n%s" ),
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
BASE_SCREEN class implementation.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
int GetVirtualPageNumber() const
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
const wxString & GetPageNumber() const
void SetContentModified(bool aModified=true)
Color settings are a bit different than most of the settings objects in that there can be more than o...
Class DIALOG_PAGES_SETTINGS_BASE.
wxTextCtrl * m_TextCompany
wxCheckBox * m_Comment3Export
wxCheckBox * m_Comment6Export
wxCheckBox * m_Comment7Export
wxCheckBox * m_Comment4Export
wxChoice * m_orientationComboBox
wxTextCtrl * m_TextComment4
wxChoice * m_paperSizeComboBox
wxTextCtrl * m_TextComment9
wxTextCtrl * m_TextRevision
wxStaticText * m_staticTextPaper
wxTextCtrl * m_TextComment2
wxCheckBox * m_PaperExport
wxTextCtrl * m_TextComment8
wxCheckBox * m_RevisionExport
wxStaticText * m_staticTextTitleBlock
wxCheckBox * m_DateExport
wxStaticText * m_TextSheetCount
wxStaticText * m_TextSheetNumber
wxStaticBitmap * m_PageLayoutExampleBitmap
STD_BITMAP_BUTTON * m_browseButton
wxTextCtrl * m_TextComment3
wxCheckBox * m_Comment9Export
wxTextCtrl * m_TextComment6
wxTextCtrl * m_TextComment5
wxDatePickerCtrl * m_PickDate
wxStaticText * m_staticTextCustSize
wxCheckBox * m_CompanyExport
wxTextCtrl * m_TextComment7
wxCheckBox * m_Comment2Export
wxTextCtrl * m_TextComment1
wxStaticText * m_staticTextOrient
wxCheckBox * m_Comment1Export
wxCheckBox * m_Comment8Export
wxCheckBox * m_TitleExport
wxCheckBox * m_Comment5Export
EDA_DRAW_FRAME * m_parent
bool m_initialized
list of page sizes (not translated)
void SetCurrentPageSizeSelection(const wxString &aPaperSize)
bool m_localPrjConfigChanged
void OnComment4TextUpdated(wxCommandEvent &event) override
void UpdateDrawingSheetExample()
void OnPageOrientationChoice(wxCommandEvent &event) override
void OnUserPageSizeYTextUpdated(wxCommandEvent &event) override
PAGE_INFO m_pageInfo
The max page size allowed by the caller frame.
void GetCustomSizeMilsFromDialog()
FILENAME_RESOLVER * m_filenameResolver
DS_DATA_MODEL * m_drawingSheet
Temporary title block (basic inscriptions).
DIALOG_PAGES_SETTINGS(EDA_DRAW_FRAME *aParent, EMBEDDED_FILES *aEmbeddedFiles, double aIuPerMils, const VECTOR2D &aMaxUserSizeMils)
void OnRevisionTextUpdated(wxCommandEvent &event) override
UNIT_BINDER m_customSizeY
const wxString GetWksFileName()
bool LocalPrjConfigChanged()
void OnComment6TextUpdated(wxCommandEvent &event) override
void OnDateApplyClick(wxCommandEvent &event) override
TITLE_BLOCK m_tb
true if the page selection is custom
void OnDateTextUpdated(wxCommandEvent &event) override
VECTOR2D m_layout_size
Temporary bitmap for the drawing sheet example.
void OnComment3TextUpdated(wxCommandEvent &event) override
void OnCompanyTextUpdated(wxCommandEvent &event) override
void OnUserPageSizeXTextUpdated(wxCommandEvent &event) override
void OnComment7TextUpdated(wxCommandEvent &event) override
virtual ~DIALOG_PAGES_SETTINGS()
EMBEDDED_FILES * m_embeddedFiles
void OnPaperSizeChoice(wxCommandEvent &event) override
virtual bool onSavePageSettings()
void GetPageLayoutInfoFromDialog()
virtual void onTransferDataToWindow()
void OnComment5TextUpdated(wxCommandEvent &event) override
void OnComment9TextUpdated(wxCommandEvent &event) override
UNIT_BINDER m_customSizeX
void OnComment1TextUpdated(wxCommandEvent &event) override
void OnComment8TextUpdated(wxCommandEvent &event) override
void OnWksFileSelection(wxCommandEvent &event) override
VECTOR2D m_maxPageSizeMils
Logical drawing sheet size.
virtual bool TransferDataToWindow() override
virtual bool TransferDataFromWindow() override
void SetWksFileName(const wxString &aFilename)
bool m_customFmt
Temporary page info.
void OnComment2TextUpdated(wxCommandEvent &event) override
wxBitmap * m_pageBitmap
the page layuout filename was changed
void OnTitleTextUpdated(wxCommandEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
EDA_BASE_FRAME * m_parentFrame
Handle the graphic items list to draw/plot the frame and title block.
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
void SaveInString(wxString *aOutputString)
Save the description in a buffer.
void SetPageLayout(const char *aPageLayout, bool aAppend=false, const wxString &aSource=wxT("Sexpr_string"))
Populate the list from a S expr description stored in a string.
static void SetAltInstance(DS_DATA_MODEL *aLayout=nullptr)
Set an alternate instance of DS_DATA_MODEL.
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
bool IsType(FRAME_T aType) const
The base class for create windows for drawing purpose.
virtual void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)=0
virtual const TITLE_BLOCK & GetTitleBlock() const =0
virtual const PAGE_INFO & GetPageSettings() const =0
virtual void SetPageSettings(const PAGE_INFO &aPageSettings)=0
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const
Returns a pointer to the active color theme settings.
virtual void OnPageSettingsChange()
Called when modifying the page settings.
virtual COLOR4D GetDrawBgColor() const
wxFileName GetTemporaryFileName(const wxString &aName) const
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
Provide an extensible class to resolve 3D model paths.
bool SetProject(PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, const EMBEDDED_FILES *aFiles)
Determine the full path of the given file name.
A color representation with 4 components: red, green, blue, alpha.
Store page-layout-specific render settings.
void LoadColors(const COLOR_SETTINGS *aSettings) override
void SetDefaultPenWidth(int aWidth)
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
void SetPrintDC(wxDC *aDC)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Describe the page size and margins of a paper page on which to eventually print or plot.
static const wxChar USLedger[]
static const wxChar USLetter[]
static const wxChar USLegal[]
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
static void SetCustomWidthMils(double aWidthInMils)
Set the width of Custom page in mils for any custom page constructed or made via SetType() after maki...
static const wxChar Custom[]
"User" defined page type
void SetHeightMils(double aHeightInMils)
const VECTOR2D & GetSizeMils() const
static double GetCustomHeightMils()
double GetHeightMils() const
static const wxChar GERBER[]
const wxString & GetType() const
double GetWidthMils() const
void SetWidthMils(double aWidthInMils)
static double GetCustomWidthMils()
static void SetCustomHeightMils(double aHeightInMils)
Set the height of Custom page in mils for any custom page constructed or made via SetType() after mak...
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
virtual const wxString GetProjectPath() const
Return the full path of the project.
const wxString & GetCompany() const
void SetRevision(const wxString &aRevision)
void SetComment(int aIdx, const wxString &aComment)
const wxString & GetRevision() const
void SetTitle(const wxString &aTitle)
const wxString & GetDate() const
const wxString & GetComment(int aIdx) const
void SetCompany(const wxString &aCompany)
const wxString & GetTitle() const
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
virtual double GetDoubleValue()
Return the current value in Internal Units.
virtual void SetDoubleValue(double aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define MAX_PAGE_EXAMPLE_SIZE
static const wxString pageFmts[]
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aSheetName, const wxString &aSheetPath, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, const std::map< wxString, wxString > *aProperties, int aSheetCount, const wxString &aPageNumber, double aMils2Iu, const PROJECT *aProject, const wxString &aSheetLayer, bool aIsFirstPage)
Print the border and title block.
#define PL_EDITOR_FRAME_NAME
wxString NormalizePath(const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
Normalize a file path to an environmental variable, if possible.
Helper functions to substitute paths with environmental variables.
@ FRAME_SCH_SYMBOL_EDITOR
void GRResetPenAndBrush(wxDC *DC)
void GRFilledRect(wxDC *DC, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, const COLOR4D &aColor, const COLOR4D &aBgColor)
static wxString DrawingSheetFileWildcard()
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
@ LAYER_SCHEMATIC_DRAWINGSHEET
This file contains miscellaneous commonly used macros and functions.
#define MIN_PAGE_SIZE_MILS
Min and max page sizes for clamping, in mils.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
PGM_BASE & Pgm()
The global program "get" accessor.
static const char * emptyString
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
Definition of file extensions used in Kicad.