From c8c05cb4ee18c84f92b4999e54c43715daa1cbdd Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 7 Jun 2013 11:49:36 +0200 Subject: [PATCH] page layout: if the environment variable KICAD_WKSFILE points a S expr page layout descr, this descr is used instead of internal descr. Mainly for testing purposes. Eeschema, dialog edit component: minor enhancement (the last selected notebook page is remembered during a session) --- common/page_layout_default_description.cpp | 4 +- common/page_layout_reader.cpp | 62 +++++++++++++++++++ common/title_block_shapes.cpp | 35 ++++++++--- .../dialogs/dialog_edit_component_in_lib.cpp | 37 ++++++++--- .../dialogs/dialog_edit_component_in_lib.h | 33 ++++++++-- .../dialog_edit_component_in_lib_base.cpp | 9 ++- .../dialog_edit_component_in_lib_base.fbp | 4 +- .../dialog_edit_component_in_lib_base.h | 4 +- include/worksheet.h | 4 -- include/worksheet_shape_builder.h | 7 +++ template/pagelayout.kicad_wks | 34 ++++++++++ 11 files changed, 201 insertions(+), 32 deletions(-) create mode 100644 template/pagelayout.kicad_wks diff --git a/common/page_layout_default_description.cpp b/common/page_layout_default_description.cpp index 8b9b93633e..ba112fa865 100644 --- a/common/page_layout_default_description.cpp +++ b/common/page_layout_default_description.cpp @@ -27,8 +27,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include - /* keyword used in page layout description are (see page_layout_reader.keywords) * page_layout * setup @@ -136,6 +134,8 @@ // default line width 0.15 mm // frame ref pitch 50 mm +// export defaultPageLayout: +extern const char defaultPageLayout[]; // Default page layout (sizes are in mm) const char defaultPageLayout[] = "( page_layout\n" diff --git a/common/page_layout_reader.cpp b/common/page_layout_reader.cpp index 19f56dcdb4..9ed36e724c 100644 --- a/common/page_layout_reader.cpp +++ b/common/page_layout_reader.cpp @@ -441,9 +441,14 @@ double PAGE_LAYOUT_READER_PARSER::parseDouble() return val; } +// defaultPageLayout is the default page layout description +// using the S expr. +// see page_layout_default_shape.cpp +extern const char defaultPageLayout[]; void WORKSHEET_LAYOUT::SetDefaultLayout() { + ClearList(); PAGE_LAYOUT_READER_PARSER lp_parser( defaultPageLayout, wxT( "default page" ) ); try @@ -455,3 +460,60 @@ void WORKSHEET_LAYOUT::SetDefaultLayout() wxLogMessage( ioe.errorText ); } } + +#include + +// SetLayout() try to load a custom layout file, +// currently defined by the environment variable KICAD_WKSFILE +// (a *.kicad_wks file). +// if does not exists, loads the default page layout. +void WORKSHEET_LAYOUT::SetLayout() +{ + wxString fullFileName; + wxGetEnv( wxT( "KICAD_WKSFILE" ), &fullFileName ); + + if( fullFileName.IsEmpty() || !wxFileExists( fullFileName ) ) + { + #ifdef DEBUG + if( !wxFileExists( fullFileName ) ) + { + wxLogMessage( wxT("Page layout file <%s> not found"), + fullFileName.GetData() ); + } + #endif + SetDefaultLayout(); + return; + } + + wxFile wksFile( fullFileName ); + + if( ! wksFile.IsOpened() ) + { + SetDefaultLayout(); + return; + } + + int filelen = wksFile.Length(); + char * buffer = new char[filelen+10]; + + if( wksFile.Read( buffer, filelen ) != filelen ) + wxLogMessage( _("The file <%s> was not fully read"), + fullFileName.GetData() ); + else + { + buffer[filelen]=0; + ClearList(); + PAGE_LAYOUT_READER_PARSER lp_parser( buffer, fullFileName ); + + try + { + lp_parser.Parse( this ); + } + catch( IO_ERROR ioe ) + { + wxLogMessage( ioe.errorText ); + } + } + + delete[] buffer; +} diff --git a/common/title_block_shapes.cpp b/common/title_block_shapes.cpp index 6a3ac779f7..33ea5ee12f 100644 --- a/common/title_block_shapes.cpp +++ b/common/title_block_shapes.cpp @@ -3,11 +3,6 @@ * @brief description of graphic items and texts to build a title block */ -/* - * This file creates a lot of structures which define the shape of a title block - * and frame references - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * @@ -33,14 +28,38 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ + +/* + * the class WORKSHEET_DATAITEM (and WORKSHEET_DATAITEM_TEXT) defines + * a basic shape of a page layout ( frame references and title block ) + * Basic shapes are line, rect and texts + * the WORKSHEET_DATAITEM coordinates units is the mm, and are relative to + * one of 4 page corners. + * + * These items cannot be drawn or plot "as this". they should be converted + * to a "draw list" (WS_DRAW_ITEM_BASE and derived items) + + * The list of these items is stored in a WORKSHEET_LAYOUT instance. + * + * When building the draw list: + * the WORKSHEET_LAYOUT is used to create a WS_DRAW_ITEM_LIST + * coordinates are converted to draw/plot coordinates. + * texts are expanded if they contain format symbols. + * Items with m_RepeatCount > 1 are created m_RepeatCount times + * + * the WORKSHEET_LAYOUT is created only once. + * the WS_DRAW_ITEM_LIST is created each time the page layout is plot/drawn + * + * the WORKSHEET_LAYOUT instance is created from a S expression which + * describes the page layout (can be the default page layout or a custom file). + */ + #include #include #include #include #include -extern void SetDataList( WORKSHEET_LAYOUT& aDataList ); - WORKSHEET_DATAITEM_TEXT::WORKSHEET_DATAITEM_TEXT( const wxChar* aTextBase ) : WORKSHEET_DATAITEM( WS_TEXT ) @@ -207,7 +226,7 @@ void WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList( // Build the basic layout shape, if the layout list is empty if( dataList.GetCount() == 0 ) - dataList.SetDefaultLayout(); + dataList.SetLayout(); WORKSHEET_DATAITEM::m_WSunits2Iu = m_milsToIu / milsTomm; diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp index 42a2d55034..72b4c4c69a 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp @@ -1,8 +1,29 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: dialog_edit_component_in_lib.cpp -// Author: jean-pierre Charras -// Licence: GPL -///////////////////////////////////////////////////////////////////////////// +/** + * @file dialog_edit_component_in_lib.cpp + */ + +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2013 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 + */ #include #include @@ -11,12 +32,12 @@ #include #include -#include #include #include #include +int DIALOG_EDIT_COMPONENT_IN_LIBRARY::m_lastOpenedPage = 0; DIALOG_EDIT_COMPONENT_IN_LIBRARY::DIALOG_EDIT_COMPONENT_IN_LIBRARY( LIB_EDIT_FRAME* aParent ): DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( aParent ) @@ -33,6 +54,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY::DIALOG_EDIT_COMPONENT_IN_LIBRARY( LIB_EDIT_FRA DIALOG_EDIT_COMPONENT_IN_LIBRARY::~DIALOG_EDIT_COMPONENT_IN_LIBRARY() { + m_lastOpenedPage = m_NoteBook->GetSelection( ); } /* Initialize state of check boxes and texts @@ -86,6 +108,8 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::initDlg() m_ButtonDeleteOneFootprintFilter->Enable( false ); } + m_NoteBook->SetSelection( m_lastOpenedPage ); + m_stdSizerButtonOK->SetDefault(); } @@ -156,7 +180,6 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitBasicPanel() void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) { - /* Update the doc, keyword and doc filename strings */ int index; LIB_ALIAS* alias; diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.h b/eeschema/dialogs/dialog_edit_component_in_lib.h index 547050f618..c343cf1cc2 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.h +++ b/eeschema/dialogs/dialog_edit_component_in_lib.h @@ -1,8 +1,29 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: dialog_edit_component_in_lib.h -// Author: jean-pierre Charras -// Licence: GPL -///////////////////////////////////////////////////////////////////////////// +/** + * @file dialog_edit_component_in_lib.h + */ + +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2013 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 _DIALOG_EDIT_COMPONENT_IN_LIB_H_ @@ -13,6 +34,8 @@ class DIALOG_EDIT_COMPONENT_IN_LIBRARY: public DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE { + static int m_lastOpenedPage; // To remember the last notebook selection + public: LIB_EDIT_FRAME* m_Parent; bool m_RecreateToolbar; diff --git a/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp b/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp index 231ac05511..6f9b889844 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 10 2012) +// C++ code generated with wxFormBuilder (version Oct 8 2012) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -109,7 +109,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx m_PanelBasic->SetSizer( bSizerBasicPanel ); m_PanelBasic->Layout(); bSizerBasicPanel->Fit( m_PanelBasic ); - m_NoteBook->AddPage( m_PanelBasic, _("Options"), false ); + m_NoteBook->AddPage( m_PanelBasic, _("Options"), true ); m_PanelDoc = new wxPanel( m_NoteBook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); wxBoxSizer* m_PanelDocBoxSizer; m_PanelDocBoxSizer = new wxBoxSizer( wxVERTICAL ); @@ -121,6 +121,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx m_PanelDocBoxSizer->Add( m_staticTextDescription, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_DocCtrl = new wxTextCtrl( m_PanelDoc, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_DocCtrl->SetMaxLength( 0 ); m_PanelDocBoxSizer->Add( m_DocCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_staticTextKeywords = new wxStaticText( m_PanelDoc, wxID_ANY, _("Keywords:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -130,6 +131,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx m_PanelDocBoxSizer->Add( m_staticTextKeywords, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_KeywordsCtrl = new wxTextCtrl( m_PanelDoc, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_KeywordsCtrl->SetMaxLength( 0 ); m_PanelDocBoxSizer->Add( m_KeywordsCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_staticTextDocFileName = new wxStaticText( m_PanelDoc, wxID_ANY, _("DocFileName:"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -139,6 +141,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx m_PanelDocBoxSizer->Add( m_staticTextDocFileName, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_DocfileCtrl = new wxTextCtrl( m_PanelDoc, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 400,-1 ), 0 ); + m_DocfileCtrl->SetMaxLength( 0 ); m_PanelDocBoxSizer->Add( m_DocfileCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); wxBoxSizer* bSizerPaneldocbutts; @@ -157,7 +160,7 @@ DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE::DIALOG_EDIT_COMPONENT_IN_LIBRARY_BASE( wx m_PanelDoc->SetSizer( m_PanelDocBoxSizer ); m_PanelDoc->Layout(); m_PanelDocBoxSizer->Fit( m_PanelDoc ); - m_NoteBook->AddPage( m_PanelDoc, _("Description"), true ); + m_NoteBook->AddPage( m_PanelDoc, _("Description"), false ); m_PanelAlias = new wxPanel( m_NoteBook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); wxBoxSizer* bSizerMainPanelAlias; bSizerMainPanelAlias = new wxBoxSizer( wxHORIZONTAL ); diff --git a/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp b/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp index 2fda7f816d..4db20d476f 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp +++ b/eeschema/dialogs/dialog_edit_component_in_lib_base.fbp @@ -185,7 +185,7 @@ Options - 0 + 1 1 1 @@ -1348,7 +1348,7 @@ Description - 1 + 0 1 1 diff --git a/eeschema/dialogs/dialog_edit_component_in_lib_base.h b/eeschema/dialogs/dialog_edit_component_in_lib_base.h index 79b7c88a80..d07b912be2 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib_base.h +++ b/eeschema/dialogs/dialog_edit_component_in_lib_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 10 2012) +// C++ code generated with wxFormBuilder (version Oct 8 2012) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -11,6 +11,8 @@ #include #include #include +class DIALOG_SHIM; + #include "dialog_shim.h" #include #include diff --git a/include/worksheet.h b/include/worksheet.h index d58203d77b..7757d9282d 100644 --- a/include/worksheet.h +++ b/include/worksheet.h @@ -47,9 +47,5 @@ void DrawPageLayout( wxDC* aDC, EDA_DRAW_PANEL * aCanvas, int aPenWidth, double aScalar, EDA_COLOR_T aLineColor, EDA_COLOR_T aTextColor ); -// defaultPageLayout is the default page layout description -// using the S expr. -// see page_layout_default_shape.cpp -extern const char defaultPageLayout[]; #endif // WORKSHEET_H_ diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h index 661c6cdd83..94d8d5fe10 100644 --- a/include/worksheet_shape_builder.h +++ b/include/worksheet_shape_builder.h @@ -507,6 +507,13 @@ public: * Fills the list with the default layout shape */ void SetDefaultLayout(); + + /** + * Fills the list with a custom layout, or + * the default layout, if no custom layout available + */ + void SetLayout(); + }; #endif // WORKSHEET_SHAPE_BUILDER_H diff --git a/template/pagelayout.kicad_wks b/template/pagelayout.kicad_wks new file mode 100644 index 0000000000..4a8d16b1ae --- /dev/null +++ b/template/pagelayout.kicad_wks @@ -0,0 +1,34 @@ +( page_layout + ( setup (textsize 1.5 1.5) (linewidth 0.15) (textlinewidth 0.15) ) + ( rect (comment rect around the title block) (linewidth 0.15) (start 110 34) (end 2 2) ) + ( rect (start 0 0 ltcorner) (end 0 0 rbcorner) (repeat 2) (incrx 2) (incry 2) ) + ( line (start 50 2 ltcorner) (end 50 0 ltcorner) (repeat 30) (incrx 50) ) + ( tbtext "1" (pos 25 1 ltcorner) (font (size 1.3 1.3))(repeat 100) (incrx 50) ) + ( line (start 50 2 lbcorner) (end 50 0 lbcorner) (repeat 30) (incrx 50) ) + ( tbtext "1" (pos 25 1 lbcorner) (font (size 1.3 1.3)) (repeat 100) (incrx 50) ) + ( line (start 0 50 ltcorner) (end 2 50 ltcorner) (repeat 30) (incry 50) ) + ( tbtext "A" (pos 1 25 ltcorner) (font (size 1.3 1.3)) + (justify center)(repeat 100) (incry 50) ) + ( line (start 0 50 rtcorner) (end 2 50 rtcorner) (repeat 30) (incry 50) ) + ( tbtext "A" (pos 1 25 rtcorner) (font (size 1.3 1.3)) + (justify center) (repeat 100) (incry 50) ) + ( tbtext "Date: %D" (pos 87 6.9) ) + ( line (start 110 5.5) end 2 5.5) ) + ( tbtext "%K" (pos 109 4.1) (comment Kicad version ) ) + ( line (start 110 8.5) end 2 8.5) ) + ( tbtext "Rev: %R" (pos 24 6.9)(font bold)(justify left) ) + ( tbtext "Size: %Z" (comment Paper format name)(pos 109 6.9) ) + ( tbtext "Id: %S/%N" (comment Sheet id)(pos 24 4.1) ) + ( line (start 110 12.5) end 2 12.5) ) + ( tbtext "Title: %T" (pos 109 10.7)(font bold (size 2 2)) ) + ( tbtext "File: %F" (pos 109 14.3) ) + ( line (start 110 18.5) end 2 18.5) ) + ( tbtext "Sheet: %P" (pos 109 17) ) + ( tbtext "%Y" (comment Company name) (pos 109 20)(font bold) ) + ( tbtext "%C0" (comment Comment 0) (pos 109 23) ) + ( tbtext "%C1" (comment Comment 0) (pos 109 26) ) + ( tbtext "%C2" (comment Comment 0) (pos 109 29) ) + ( tbtext "%C3" (comment Comment 0) (pos 109 32) ) + ( line (start 90 8.5) end 90 5.5) ) + ( line (start 26 8.5) end 26 2) ) +)