Add versioning to page layout editor worksheets
This commit is contained in:
parent
ade38f48bc
commit
63c263090f
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <eda_item.h>
|
||||
#include <locale_io.h>
|
||||
#include <kicad_string.h>
|
||||
#include <drawing_sheet/ds_data_item.h>
|
||||
#include <drawing_sheet/ds_data_model.h>
|
||||
#include <drawing_sheet/ds_draw_item.h>
|
||||
|
@ -51,10 +52,22 @@ public:
|
|||
void Parse( DS_DATA_MODEL* aLayout );
|
||||
|
||||
private:
|
||||
int m_requiredVersion;
|
||||
|
||||
/**
|
||||
* Function parseInt
|
||||
* parses an integer and constrains it between two values.
|
||||
* Parse the data specified at the very beginning of the file, like version and the
|
||||
* application used to create this file.
|
||||
*/
|
||||
void parseHeader( T aHeaderType );
|
||||
|
||||
/**
|
||||
* Parse an integer.
|
||||
*/
|
||||
int parseInt();
|
||||
|
||||
/**
|
||||
* Parse an integer and constrain it between two values.
|
||||
*
|
||||
* @param aMin is the smallest return value.
|
||||
* @param aMax is the largest return value.
|
||||
* @return int - the parsed integer.
|
||||
|
@ -62,8 +75,8 @@ private:
|
|||
int parseInt( int aMin, int aMax );
|
||||
|
||||
/**
|
||||
* Function parseDouble
|
||||
* parses a double
|
||||
* Parse a double.
|
||||
*
|
||||
* @return double - the parsed double.
|
||||
*/
|
||||
double parseDouble();
|
||||
|
@ -71,29 +84,29 @@ private:
|
|||
void parseSetup( DS_DATA_MODEL* aLayout );
|
||||
|
||||
/**
|
||||
* parse a graphic item starting by "(line" or "(rect" and read parameters.
|
||||
* Parse a graphic item starting by "(line" or "(rect" and read parameters.
|
||||
*/
|
||||
void parseGraphic( DS_DATA_ITEM * aItem );
|
||||
|
||||
/**
|
||||
* parse a text item starting by "(tbtext" and read parameters.
|
||||
* Parse a text item starting by "(tbtext" and read parameters.
|
||||
*/
|
||||
void parseText( DS_DATA_ITEM_TEXT * aItem );
|
||||
|
||||
/**
|
||||
* parse a polygon item starting by "( polygon" and read parameters.
|
||||
* the list of corners included in this description is read by parsePolyOutline
|
||||
* Parse a polygon item starting by "( polygon" and read parameters.
|
||||
* the list of corners included in this description is read by parsePolyOutline.
|
||||
*/
|
||||
void parsePolygon( DS_DATA_ITEM_POLYGONS * aItem );
|
||||
|
||||
/**
|
||||
* parse a list of corners starting by "( pts" and read coordinates.
|
||||
* Parse a list of corners starting by "( pts" and read coordinates.
|
||||
*/
|
||||
void parsePolyOutline( DS_DATA_ITEM_POLYGONS * aItem );
|
||||
|
||||
|
||||
/**
|
||||
* parse a bitmap item starting by "( bitmap" and read parameters.
|
||||
* Parse a bitmap item starting by "( bitmap" and read parameters.
|
||||
*/
|
||||
void parseBitmap( DS_DATA_ITEM_BITMAP * aItem );
|
||||
|
||||
|
@ -106,7 +119,8 @@ private:
|
|||
|
||||
DRAWING_SHEET_READER_PARSER::DRAWING_SHEET_READER_PARSER( const char* aLine,
|
||||
const wxString& aSource ) :
|
||||
DRAWING_SHEET_READER_LEXER( aLine, aSource )
|
||||
DRAWING_SHEET_READER_LEXER( aLine, aSource ),
|
||||
m_requiredVersion( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -190,14 +204,17 @@ void DRAWING_SHEET_READER_PARSER::Parse( DS_DATA_MODEL* aLayout )
|
|||
DS_DATA_ITEM* item;
|
||||
LOCALE_IO toggle;
|
||||
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
NeedLEFT();
|
||||
T token = NextTok();
|
||||
|
||||
parseHeader( token );
|
||||
aLayout->SetFileFormatVersionAtLoad( m_requiredVersion );
|
||||
|
||||
for( token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_LEFT )
|
||||
token = NextTok();
|
||||
|
||||
if( token == T_page_layout || token == T_drawing_sheet )
|
||||
continue;
|
||||
|
||||
switch( token )
|
||||
{
|
||||
case T_setup: // Defines default values for graphic items
|
||||
|
@ -242,6 +259,42 @@ void DRAWING_SHEET_READER_PARSER::Parse( DS_DATA_MODEL* aLayout )
|
|||
}
|
||||
}
|
||||
|
||||
void DRAWING_SHEET_READER_PARSER::parseHeader( T aHeaderType )
|
||||
{
|
||||
// The older files had no versioning and their first token after the initial left parenthesis
|
||||
// was a `page_layout` or `drawing_sheet` token. The newer files have versions and have a
|
||||
// `kicad_wks` token instead.
|
||||
|
||||
if( aHeaderType == T_kicad_wks )
|
||||
{
|
||||
NeedLEFT();
|
||||
|
||||
T tok = NextTok();
|
||||
|
||||
if( tok == T_version )
|
||||
{
|
||||
m_requiredVersion = parseInt();
|
||||
NeedRIGHT();
|
||||
}
|
||||
else
|
||||
{
|
||||
Expecting( T_version );
|
||||
}
|
||||
|
||||
// Ignore generator info.
|
||||
NeedLEFT();
|
||||
NeedSYMBOL();
|
||||
NeedSYMBOL();
|
||||
NeedRIGHT();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We assign version 0 to files that were created before there was any versioning of
|
||||
// worksheets. The below line is not strictly necessary, as `m_requiredVersion` is already
|
||||
// initialized to 0 in the constructor.
|
||||
m_requiredVersion = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DRAWING_SHEET_READER_PARSER::parseSetup( DS_DATA_MODEL* aLayout )
|
||||
{
|
||||
|
@ -576,6 +629,9 @@ void DRAWING_SHEET_READER_PARSER::parseGraphic( DS_DATA_ITEM * aItem )
|
|||
|
||||
void DRAWING_SHEET_READER_PARSER::parseText( DS_DATA_ITEM_TEXT* aItem )
|
||||
{
|
||||
if( m_requiredVersion < 20210606 )
|
||||
aItem->m_TextBase = ConvertToNewOverbarNotation( aItem->m_TextBase );
|
||||
|
||||
for( T token = NextTok(); token != T_RIGHT && token != EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_LEFT )
|
||||
|
@ -731,14 +787,19 @@ void DRAWING_SHEET_READER_PARSER::parseCoordinate( POINT_COORD& aCoord)
|
|||
}
|
||||
}
|
||||
|
||||
int DRAWING_SHEET_READER_PARSER::parseInt( int aMin, int aMax )
|
||||
int DRAWING_SHEET_READER_PARSER::parseInt()
|
||||
{
|
||||
T token = NextTok();
|
||||
|
||||
if( token != T_NUMBER )
|
||||
Expecting( T_NUMBER );
|
||||
|
||||
int val = atoi( CurText() );
|
||||
return atoi( CurText() );
|
||||
}
|
||||
|
||||
int DRAWING_SHEET_READER_PARSER::parseInt( int aMin, int aMax )
|
||||
{
|
||||
int val = parseInt();
|
||||
|
||||
if( val < aMin )
|
||||
val = aMin;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
page_layout
|
||||
drawing_sheet
|
||||
version
|
||||
kicad_wks
|
||||
setup
|
||||
left_margin
|
||||
right_margin
|
||||
|
|
|
@ -66,6 +66,7 @@ DS_DATA_MODEL::DS_DATA_MODEL() :
|
|||
m_EditMode( false )
|
||||
{
|
||||
m_allowVoidList = false;
|
||||
m_fileFormatVersionAtLoad = 0;
|
||||
m_leftMargin = 10.0; // the left page margin in mm
|
||||
m_rightMargin = 10.0; // the right page margin in mm
|
||||
m_topMargin = 10.0; // the top page margin in mm
|
||||
|
|
|
@ -27,12 +27,13 @@
|
|||
#include <kicad_string.h>
|
||||
#include <locale_io.h>
|
||||
#include <macros.h>
|
||||
#include <math/vector2d.h>
|
||||
#include <drawing_sheet/ds_painter.h>
|
||||
#include <drawing_sheet/ds_draw_item.h>
|
||||
#include <drawing_sheet/ds_data_item.h>
|
||||
#include <drawing_sheet/ds_data_model.h>
|
||||
#include <math/vector2d.h>
|
||||
#include <drawing_sheet/drawing_sheet_reader_lexer.h>
|
||||
#include <drawing_sheet/ds_file_versions.h>
|
||||
|
||||
#include <wx/msgdlg.h>
|
||||
|
||||
|
@ -189,7 +190,8 @@ void DS_DATA_MODEL_IO::Format( DS_DATA_MODEL* aDrawingSheet ) const
|
|||
{
|
||||
LOCALE_IO toggle; // switch on/off the locale "C" notation
|
||||
|
||||
m_out->Print( 0, "(drawing_sheet\n" );
|
||||
m_out->Print( 0, "(kicad_wks (version %d) (generator pl_editor)\n",
|
||||
SEXPR_WORKSHEET_FILE_VERSION );
|
||||
|
||||
// Setup
|
||||
int nestLevel = 1;
|
||||
|
|
|
@ -540,7 +540,6 @@ VECTOR2D STROKE_FONT::ComputeStringBoundaryLimits( const UTF8& aText, const VECT
|
|||
double maxX = 0.0, curX = 0.0;
|
||||
|
||||
double curScale = 1.0;
|
||||
int overbarDepth = -1;
|
||||
int superSubDepth = -1;
|
||||
int braceNesting = 0;
|
||||
|
||||
|
|
|
@ -57,6 +57,9 @@ public:
|
|||
*/
|
||||
static void SetAltInstance( DS_DATA_MODEL* aLayout = NULL );
|
||||
|
||||
int GetFileFormatVersionAtLoad() { return m_fileFormatVersionAtLoad; }
|
||||
void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
|
||||
|
||||
double GetLeftMargin() { return m_leftMargin; }
|
||||
void SetLeftMargin( double aMargin ) { m_leftMargin = aMargin; }
|
||||
|
||||
|
@ -208,6 +211,7 @@ private:
|
|||
bool m_allowVoidList; // If false, the default drawing sheet will be loaded the
|
||||
// first time DS_DRAW_ITEM_LIST::BuildDrawItemsList is run
|
||||
// (useful mainly for drawing sheet editor)
|
||||
int m_fileFormatVersionAtLoad;
|
||||
double m_leftMargin; // the left page margin in mm
|
||||
double m_rightMargin; // the right page margin in mm
|
||||
double m_topMargin; // the top page margin in mm
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2021 Mikołaj Wielgus <wielgusmikolaj@gmail.com>
|
||||
* Copyright (C) 2021 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file contains the file format version information for the s-expression drawing sheet file
|
||||
* formats
|
||||
*
|
||||
* @note Comment out the last version and add the new version as a date time stamp in the YYYYMMDD
|
||||
* format. Comment the changes to the file format for historical purposes.
|
||||
*/
|
||||
|
||||
#define SEXPR_WORKSHEET_FILE_VERSION 20210606 // Initial version.
|
|
@ -27,6 +27,7 @@
|
|||
#include <confirm.h>
|
||||
#include <gestfich.h>
|
||||
#include <drawing_sheet/ds_data_model.h>
|
||||
#include <drawing_sheet/ds_file_versions.h>
|
||||
#include <paths.h>
|
||||
#include <widgets/infobar.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
|
@ -242,6 +243,15 @@ bool PL_EDITOR_FRAME::LoadDrawingSheetFile( const wxString& aFullFileName )
|
|||
wxFileName fn = aFullFileName;
|
||||
m_infoBar->Dismiss();
|
||||
|
||||
if( DS_DATA_MODEL::GetTheInstance().GetFileFormatVersionAtLoad() < SEXPR_WORKSHEET_FILE_VERSION )
|
||||
{
|
||||
m_infoBar->RemoveAllButtons();
|
||||
m_infoBar->AddCloseButton();
|
||||
m_infoBar->ShowMessage( _( "This file was created by an older version of KiCad. "
|
||||
"It will be converted to the new format when saved." ),
|
||||
wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
|
||||
}
|
||||
|
||||
if( fn.FileExists() && !fn.IsFileWritable() )
|
||||
{
|
||||
ShowInfoBarWarning( _( "Layout file is read only." ), true );
|
||||
|
|
Loading…
Reference in New Issue