Commit 0025ac7d authored by Dick Hollenbeck's avatar Dick Hollenbeck

Add "portrait" support to the page size settings for all standard paper

    sizes.  Tested with postscript output only.  Required minor file format changes
    to reflect the "portrait" setting.  common/dialogs/dialog_page_settings.cpp
    uses a checkbox but its name is "Landscape", which is inverted from portrait,
    but since it is the more common choice, I used that rather than portrait.
    The tooltip for that checkbox makes it clear.  No portrait mode is supported
    for "User" paper size.
parent 9147e66d
......@@ -4,6 +4,17 @@ KiCad ChangeLog 2012
Please add newer entries at the top, list the date and your name with
email address.
2012-Jan-15 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++all
Add "portrait" support to the page size settings for all standard paper
sizes. Tested with postscript output only. Required minor file format changes
to reflect the "portrait" setting. common/dialogs/dialog_page_settings.cpp
uses a checkbox but its name is "Landscape", which is inverted from portrait,
but since it is the more common choice, I used that rather than portrait.
The tooltip for that checkbox makes it clear. No portrait mode is supported
for "User" paper size.
2012-Jan-9 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
......
......@@ -176,7 +176,7 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
//-----<PAGE_INFO>-------------------------------------------------------------
// Standard page sizes in mils
// Standard page sizes in mils, all constants
#if defined(KICAD_GOST)
const PAGE_INFO PAGE_INFO::pageA4( wxSize( 8283, 11700 ), wxT( "A4" ) );
#else
......@@ -224,6 +224,27 @@ wxArrayString PAGE_INFO::GetStandardSizes()
}
*/
PAGE_INFO::PAGE_INFO( const wxSize& aSizeMils, const wxString& aType ) :
m_type( aType ),
m_size( aSizeMils ),
m_portrait( false )
{
#if defined(KICAD_GOST)
m_left_margin = GOST_LEFTMARGIN;
m_right_margin = GOST_RIGHTMARGIN;
m_top_margin = GOST_TOPMARGIN;
m_bottom_margin = GOST_BOTTOMMARGIN;
#else
m_left_margin = m_right_margin = m_top_margin = m_bottom_margin = 400;
#endif
}
PAGE_INFO::PAGE_INFO( const wxString& aType )
{
SetType( aType );
}
bool PAGE_INFO::SetType( const wxString& aType )
{
bool rc = true;
......@@ -267,47 +288,79 @@ bool PAGE_INFO::SetType( const wxString& aType )
}
PAGE_INFO::PAGE_INFO( const wxSize& aSizeMils, const wxString& aType ) :
m_size( aSizeMils )
void PAGE_INFO::SetPortrait( bool isPortrait )
{
m_type = aType;
#if defined(KICAD_GOST)
m_left_margin = GOST_LEFTMARGIN;
m_right_margin = GOST_RIGHTMARGIN;
m_top_margin = GOST_TOPMARGIN;
m_bottom_margin = GOST_BOTTOMMARGIN;
#else
m_left_margin = m_right_margin = m_top_margin = m_bottom_margin = 400;
#endif
}
if( m_portrait != isPortrait )
{
// swap x and y in m_size
m_size = wxSize( m_size.y, m_size.x );
m_portrait = isPortrait;
PAGE_INFO::PAGE_INFO( const wxString& aType )
{
SetType( aType );
// margins are not touched.
}
}
void PAGE_INFO::SetUserWidthMils( int aWidthInMils )
static int clampWidth( int aWidthInMils )
{
if( aWidthInMils < 6000 )
aWidthInMils = 6000;
else if( aWidthInMils > 44000 )
if( aWidthInMils < 4000 ) // 4" is about a baseball card
aWidthInMils = 4000;
else if( aWidthInMils > 44000 ) //44" is plotter size
aWidthInMils = 44000;
s_user_width = aWidthInMils;
return aWidthInMils;
}
void PAGE_INFO::SetUserHeightMils( int aHeightInMils )
static int clampHeight( int aHeightInMils )
{
if( aHeightInMils < 4000 )
aHeightInMils = 4000;
else if( aHeightInMils > 44000 )
aHeightInMils = 44000;
return aHeightInMils;
}
s_user_height = aHeightInMils;
void PAGE_INFO::SetUserWidthMils( int aWidthInMils )
{
s_user_width = clampWidth( aWidthInMils );
}
void PAGE_INFO::SetUserHeightMils( int aHeightInMils )
{
s_user_height = clampHeight( aHeightInMils );
}
void PAGE_INFO::SetWidthMils( int aWidthInMils )
{
m_size.x = clampWidth( aWidthInMils );
}
int PAGE_INFO::GetWidthMils() const
{
return m_size.x;
}
void PAGE_INFO::SetHeightMils( int aHeightInMils )
{
m_size.y = clampHeight( aHeightInMils );
}
int PAGE_INFO::GetHeightMils() const
{
return m_size.y;
}
const wxSize& PAGE_INFO::GetSizeMils() const
{
return m_size;
}
//-----</PAGE_INFO>------------------------------------------------------------
......
......@@ -72,10 +72,16 @@ void DIALOG_PAGES_SETTINGS::initDialog()
msg.Printf( format, m_Screen->m_ScreenNumber );
m_TextSheetNumber->SetLabel( msg );
PAGE_INFO pageInfo = m_Parent->GetPageSettings();
const PAGE_INFO& pageInfo = m_Parent->GetPageSettings();
if( wxT( "User" ) != pageInfo.GetType() )
m_landscapeCheckbox->SetValue( !pageInfo.IsPortrait() );
setCurrentPageSizeSelection( pageInfo.GetType() );
// only a click fires the radiobutton selected event, so have to fabricate this check
onRadioButtonSelected();
switch( g_UserUnit )
{
case MILLIMETRES:
......@@ -149,20 +155,12 @@ void DIALOG_PAGES_SETTINGS::initDialog()
}
/*!
* wxEVT_CLOSE_WINDOW event handler for ID_DIALOG
*/
void DIALOG_PAGES_SETTINGS::OnCloseWindow( wxCloseEvent& event )
{
EndModal( m_modified );
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
*/
void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
{
SavePageSettings( event );
......@@ -171,16 +169,31 @@ void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
*/
void DIALOG_PAGES_SETTINGS::OnCancelClick( wxCommandEvent& event )
{
Close( true );
}
void DIALOG_PAGES_SETTINGS::onRadioButtonSelected()
{
if( wxT( "User" ) == m_PageSizeBox->GetStringSelection() )
{
m_landscapeCheckbox->Enable( false );
}
else
{
m_landscapeCheckbox->Enable( true );
}
}
void DIALOG_PAGES_SETTINGS::onRadioButtonSelected( wxCommandEvent& event )
{
onRadioButtonSelected(); // no event arg
}
void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event )
{
wxString msg;
......@@ -236,6 +249,9 @@ void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event )
// paperType is "User", otherwise User with and height will not go into effect right away.
PAGE_INFO pageInfo( paperType );
if( wxT( "User" ) != paperType )
pageInfo.SetPortrait( !m_landscapeCheckbox->IsChecked() );
m_Parent->SetPageSettings( pageInfo );
#ifdef EESCHEMA
......@@ -306,7 +322,5 @@ void DIALOG_PAGES_SETTINGS::setCurrentPageSizeSelection( const wxString& aPaperS
}
}
}
// m_PageSizeBox->SetSelection( 1 ); // wxFormBuilder does this, control there
}
......@@ -36,10 +36,14 @@ private:
/// wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
void OnCancelClick( wxCommandEvent& event );
/// wxEVT_COMMAND_RADIOBOX_SELECTED
void onRadioButtonSelected( wxCommandEvent& event );
void setCurrentPageSizeSelection( const wxString& aPaperSize );
void SavePageSettings(wxCommandEvent& event);
void ReturnSizeSelected(wxCommandEvent& event);
void onRadioButtonSelected();
};
#endif // _DIALOG_PAGES_SETTINGS_H_
......@@ -31,12 +31,23 @@ DIALOG_PAGES_SETTINGS_BASE::DIALOG_PAGES_SETTINGS_BASE( wxWindow* parent, wxWind
wxString m_PageSizeBoxChoices[] = { _("A4"), _("A3"), _("A2"), _("A1"), _("A0"), _("A"), _("B"), _("C"), _("D"), _("E"), _("User") };
int m_PageSizeBoxNChoices = sizeof( m_PageSizeBoxChoices ) / sizeof( wxString );
m_PageSizeBox = new wxRadioBox( this, wxID_ANY, _("Page Size:"), wxDefaultPosition, wxDefaultSize, m_PageSizeBoxNChoices, m_PageSizeBoxChoices, 1, wxRA_SPECIFY_COLS );
m_PageSizeBox->SetSelection( 1 );
m_PageSizeBox->SetSelection( 9 );
LeftColumnSizer->Add( m_PageSizeBox, 0, wxALL|wxEXPAND, 5 );
LeftColumnSizer->Add( 5, 0, 1, wxEXPAND, 5 );
wxStaticBoxSizer* sbSizer8;
sbSizer8 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Orientation:") ), wxVERTICAL );
m_landscapeCheckbox = new wxCheckBox( this, wxID_ANY, _("Landscape"), wxDefaultPosition, wxDefaultSize, 0 );
m_landscapeCheckbox->SetValue(true);
m_landscapeCheckbox->SetToolTip( _("Check for landscape, uncheck for portrait") );
sbSizer8->Add( m_landscapeCheckbox, 0, wxALL|wxEXPAND, 5 );
LeftColumnSizer->Add( sbSizer8, 1, wxALL|wxEXPAND, 5 );
wxBoxSizer* bSizerXsize;
bSizerXsize = new wxBoxSizer( wxVERTICAL );
......@@ -204,9 +215,11 @@ DIALOG_PAGES_SETTINGS_BASE::DIALOG_PAGES_SETTINGS_BASE( wxWindow* parent, wxWind
this->SetSizer( bMainSizer );
this->Layout();
bMainSizer->Fit( this );
// Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_PAGES_SETTINGS_BASE::OnCloseWindow ) );
m_PageSizeBox->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_PAGES_SETTINGS_BASE::onRadioButtonSelected ), NULL, this );
m_TextUserSizeX->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_PAGES_SETTINGS_BASE::OnTextctrlUserPageSizeXTextUpdated ), NULL, this );
m_TextUserSizeY->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_PAGES_SETTINGS_BASE::OnTextctrlUserPageSizeYTextUpdated ), NULL, this );
m_TitleExport->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_PAGES_SETTINGS_BASE::OnCheckboxTitleClick ), NULL, this );
......@@ -218,6 +231,7 @@ DIALOG_PAGES_SETTINGS_BASE::~DIALOG_PAGES_SETTINGS_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_PAGES_SETTINGS_BASE::OnCloseWindow ) );
m_PageSizeBox->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_PAGES_SETTINGS_BASE::onRadioButtonSelected ), NULL, this );
m_TextUserSizeX->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_PAGES_SETTINGS_BASE::OnTextctrlUserPageSizeXTextUpdated ), NULL, this );
m_TextUserSizeY->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_PAGES_SETTINGS_BASE::OnTextctrlUserPageSizeYTextUpdated ), NULL, this );
m_TitleExport->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_PAGES_SETTINGS_BASE::OnCheckboxTitleClick ), NULL, this );
......
......@@ -16,11 +16,11 @@
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/sizer.h>
#include <wx/checkbox.h>
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/dialog.h>
......@@ -52,6 +52,7 @@ class DIALOG_PAGES_SETTINGS_BASE : public wxDialog
protected:
wxRadioBox* m_PageSizeBox;
wxCheckBox* m_landscapeCheckbox;
wxStaticText* UserPageSizeX;
wxTextCtrl* m_TextUserSizeX;
wxStaticText* UserPageSizeY;
......@@ -81,6 +82,7 @@ class DIALOG_PAGES_SETTINGS_BASE : public wxDialog
// Virtual event handlers, overide them in your derived class
virtual void OnCloseWindow( wxCloseEvent& event ) { event.Skip(); }
virtual void onRadioButtonSelected( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTextctrlUserPageSizeXTextUpdated( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTextctrlUserPageSizeYTextUpdated( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCheckboxTitleClick( wxCommandEvent& event ) { event.Skip(); }
......@@ -90,7 +92,7 @@ class DIALOG_PAGES_SETTINGS_BASE : public wxDialog
public:
DIALOG_PAGES_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Page Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 439,497 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_PAGES_SETTINGS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Page Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_PAGES_SETTINGS_BASE();
};
......
......@@ -298,18 +298,22 @@ static void LoadLayers( LINE_READER* aLine )
}
}
/// Get the length of a string constant, at compile time
#define SZ( x ) (sizeof(x)-1)
static const char delims[] = " \t\r\n";
/* Read the schematic header. */
bool ReadSchemaDescr( LINE_READER* aLine, wxString& aMsgDiag, SCH_SCREEN* aScreen )
{
char text[256];
char buf[1024];
wxSize pageSize;
char* line = aLine->Line();
char* line = aLine->Line();
sscanf( line, "%s %s %d %d", text, text, &pageSize.x, &pageSize.y );
char* pageType = strtok( line + SZ( "$Descr" ), delims );
char* width = strtok( NULL, delims );
char* height = strtok( NULL, delims );
char* orient = strtok( NULL, delims );
wxString pagename = FROM_UTF8( text );
wxString pagename = FROM_UTF8( pageType );
PAGE_INFO pageInfo;
TITLE_BLOCK tb;
......@@ -324,14 +328,28 @@ line %d, \aAbort reading file.\n" ),
if( pagename == wxT( "User" ) )
{
pageInfo.SetWidthMils( pageSize.x );
pageInfo.SetHeightMils( pageSize.y );
if( width && height )
{
int w = atoi( width );
int h = atoi( height );
pageInfo.SetWidthMils( w );
pageInfo.SetHeightMils( h );
}
}
// portrait only supported in non "User" sizes
else if( orient && !strcmp( orient, "portrait" ) )
{
pageInfo.SetPortrait( true );
}
aScreen->SetPageSettings( pageInfo );
for( ; ; )
for(;;)
{
char buf[1024];
if( !aLine->ReadLine() )
return true;
......
......@@ -571,8 +571,12 @@ bool SCH_SCREEN::Save( FILE* aFile ) const
*/
const TITLE_BLOCK& tb = GetTitleBlock();
if( fprintf( aFile, "$Descr %s %d %d\n", TO_UTF8( m_paper.GetType() ),
m_paper.GetWidthMils(), m_paper.GetHeightMils() ) < 0
if( fprintf( aFile, "$Descr %s %d %d%s\n", TO_UTF8( m_paper.GetType() ),
m_paper.GetWidthMils(),
m_paper.GetHeightMils(),
m_paper.GetType() != wxT( "User" ) && m_paper.IsPortrait() ?
" portrait" : ""
) < 0
|| fprintf( aFile, "encoding utf-8\n") < 0
|| fprintf( aFile, "Sheet %d %d\n", m_ScreenNumber, m_NumberOfScreen ) < 0
|| fprintf( aFile, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() ) < 0
......
......@@ -139,8 +139,6 @@ public:
PAGE_INFO( const wxString& aType = wxT( "A3" ) );
PAGE_INFO( const wxSize& aSizeMils, const wxString& aName );
const wxString& GetType() const { return m_type; }
/**
* Function SetType
* sets the name of the page type and also the sizes and margins
......@@ -155,14 +153,27 @@ public:
* @return bool - true iff @a aStandarePageDescription was a recognized type.
*/
bool SetType( const wxString& aStandardPageDescriptionName );
const wxString& GetType() const { return m_type; }
void SetWidthMils( int aWidthInMils ) { m_size.x = aWidthInMils; }
int GetWidthMils() const { return m_size.x; }
/**
* Function SetPortrait
* will rotate the paper page 90 degrees. This PAGE_INFO may either be in
* portrait or landscape mode. Use this function to change from one to the
* other mode.
* @param isPortrait 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.
*/
void SetPortrait( bool isPortrait );
bool IsPortrait() const { return m_portrait; }
void SetWidthMils( int aWidthInMils );
int GetWidthMils() const;
void SetHeightMils( int aHeightInMils ) { m_size.y = aHeightInMils; }
int GetHeightMils() const { return m_size.y; }
void SetHeightMils( int aHeightInMils );
int GetHeightMils() const;
const wxSize& GetSizeMils() const { return m_size; }
const wxSize& GetSizeMils() const;
// Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA,
// and either deci-mils or nanometers in PCBNew.
......@@ -239,6 +250,8 @@ private:
int m_top_margin;
int m_bottom_margin;
bool m_portrait; ///< true if portrait, false if landscape
static int s_user_height;
static int s_user_width;
};
......
......@@ -841,10 +841,13 @@ bool PCB_EDIT_FRAME::WriteGeneralDescrPcb( FILE* File )
static bool WriteSheetDescr( const PAGE_INFO& aPageSettings, const TITLE_BLOCK& aTitleBlock, FILE* File )
{
fprintf( File, "$SHEETDESCR\n" );
fprintf( File, "Sheet %s %d %d\n",
fprintf( File, "Sheet %s %d %d%s\n",
TO_UTF8( aPageSettings.GetType() ),
aPageSettings.GetSizeMils().x,
aPageSettings.GetSizeMils().y );
aPageSettings.GetSizeMils().y,
aPageSettings.GetType() != wxT( "User" ) && aPageSettings.IsPortrait() ?
" portrait" : ""
);
fprintf( File, "Title %s\n", EscapedUTF8( aTitleBlock.GetTitle() ).c_str() );
fprintf( File, "Date %s\n", EscapedUTF8( aTitleBlock.GetDate() ).c_str() );
......@@ -897,12 +900,13 @@ static bool ReadSheetDescr( BOARD* aBoard, LINE_READER* aReader )
*/
}
// only parse the width and height if page size is "User"
char* width = strtok( NULL, delims );
char* height = strtok( NULL, delims );
char* orient = strtok( NULL, delims );
// only keep width and height if page size is "User"
if( wname == wxT( "User" ) )
{
char* width = strtok( NULL, delims );
char* height = strtok( NULL, delims );
if( width && height )
{
// legacy disk file describes paper in mils
......@@ -915,6 +919,11 @@ static bool ReadSheetDescr( BOARD* aBoard, LINE_READER* aReader )
}
}
if( orient && !strcmp( orient, "portrait" ) )
{
page.SetPortrait( true );
}
aBoard->SetPageSettings( page );
}
......
......@@ -461,12 +461,13 @@ void KICAD_PLUGIN::loadSHEET()
THROW_IO_ERROR( m_error );
}
char* width = strtok( NULL, delims );
char* height = strtok( NULL, delims );
char* orient = strtok( NULL, delims );
// only parse the width and height if page size is "User"
if( wname == wxT( "User" ) )
{
char* width = strtok( NULL, delims );
char* height = strtok( NULL, delims );
if( width && height )
{
// legacy disk file describes paper in mils
......@@ -479,6 +480,11 @@ void KICAD_PLUGIN::loadSHEET()
}
}
if( orient && !strcmp( orient, "portrait" ) )
{
page.SetPortrait( true );
}
m_board->SetPageSettings( page );
}
}
......@@ -2734,10 +2740,13 @@ void KICAD_PLUGIN::saveSHEET() const
fprintf( m_fp, "$SHEETDESCR\n" );
// paper is described in mils
fprintf( m_fp, "Sheet %s %d %d\n",
fprintf( m_fp, "Sheet %s %d %d%s\n",
TO_UTF8( pageInfo.GetType() ),
pageInfo.GetSizeMils().x,
pageInfo.GetSizeMils().y );
pageInfo.GetSizeMils().y
pageInfo.GetType() != wxT( "User" ) && pageInfo.IsPortrait() ?
" portrait" : ""
);
fprintf( m_fp, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
fprintf( m_fp, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment