Commit aaab12d3 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Mainly for testing purposes: page layout: if the environment variable...

Mainly for testing purposes: page layout: if the environment variable KICAD_WKSFILE points a S expr page layout descr, this descr is used instead of internal descr.
Therefore one can use a custom page layout and title block.
Eeschema, dialog edit component: minor enhancement (the last selected notebook page is remembered during a session)
parents 7432d4de c8c05cb4
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#include <fctsys.h>

/* 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"
+62 −0
Original line number Diff line number Diff line
@@ -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 <wx/file.h>

// 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;
}
+27 −8
Original line number Diff line number Diff line
@@ -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 <fctsys.h>
#include <drawtxt.h>
#include <worksheet.h>
#include <class_title_block.h>
#include <worksheet_shape_builder.h>

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;

+30 −7
Original line number Diff line number Diff line
/////////////////////////////////////////////////////////////////////////////
// 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 <fctsys.h>
#include <common.h>
@@ -11,12 +32,12 @@
#include <appl_wxstruct.h>

#include <general.h>
#include <protos.h>
#include <libeditframe.h>
#include <class_library.h>

#include <dialog_edit_component_in_lib.h>

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;
+28 −5
Original line number Diff line number Diff line
/////////////////////////////////////////////////////////////////////////////
// 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;
Loading