2013-07-19 18:27:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-07-11 19:48:46 +00:00
|
|
|
* Copyright (C) 2013-2016 CERN
|
2022-02-28 18:02:00 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-11 19:48:46 +00:00
|
|
|
*
|
2013-08-13 17:51:22 +00:00
|
|
|
* @author Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2013-07-19 18:27:22 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <macros.h>
|
2021-06-10 22:39:03 +00:00
|
|
|
#include <math/vector2d.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_painter.h>
|
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_model.h>
|
2021-08-27 11:52:13 +00:00
|
|
|
#include <drawing_sheet/drawing_sheet_lexer.h>
|
2021-06-10 22:39:03 +00:00
|
|
|
#include <drawing_sheet/ds_file_versions.h>
|
2022-02-28 18:02:00 +00:00
|
|
|
#include <font/font.h>
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2020-10-18 18:24:20 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
using namespace DRAWINGSHEET_T;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
#define double2Str Double2Str
|
|
|
|
|
|
|
|
// A helper function to write tokens:
|
|
|
|
static const char* getTokenName( T aTok )
|
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
return DRAWING_SHEET_LEXER::TokenName( aTok );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// A basic helper class to write a drawing sheet file
|
2021-02-22 23:47:17 +00:00
|
|
|
// Not used alone, a file writer or a string writer should be derived to use it.
|
|
|
|
// Therefore the constructor is protected.
|
|
|
|
class DS_DATA_MODEL_IO
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-08-27 11:52:13 +00:00
|
|
|
void Format( DS_DATA_MODEL* aSheet ) const;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-11-09 23:17:44 +00:00
|
|
|
void Format( DS_DATA_MODEL* aModel, std::vector<DS_DATA_ITEM*>& aItemsList ) const;
|
2021-02-22 23:47:17 +00:00
|
|
|
void Format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
protected:
|
|
|
|
DS_DATA_MODEL_IO() { m_out = NULL; }
|
|
|
|
virtual ~DS_DATA_MODEL_IO() {}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
private:
|
2021-02-22 23:47:17 +00:00
|
|
|
void format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const;
|
|
|
|
void format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const;
|
2021-06-08 17:47:06 +00:00
|
|
|
void format( DS_DATA_ITEM_POLYGONS* aItem, int aNestLevel ) const;
|
2021-02-22 23:47:17 +00:00
|
|
|
void format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) const;
|
2021-06-08 17:47:06 +00:00
|
|
|
void formatCoordinate( const char* aToken, POINT_COORD& aCoord ) const;
|
2021-02-22 23:47:17 +00:00
|
|
|
void formatRepeatParameters( DS_DATA_ITEM* aItem ) const;
|
|
|
|
void formatOptions( DS_DATA_ITEM* aItem ) const;
|
2021-06-08 17:47:06 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
OUTPUTFORMATTER* m_out;
|
2013-07-19 18:27:22 +00:00
|
|
|
};
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// A helper class to write a drawing sheet to a file
|
2021-02-22 23:47:17 +00:00
|
|
|
class DS_DATA_MODEL_FILEIO : public DS_DATA_MODEL_IO
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL_FILEIO( const wxString& aFilename ) :
|
|
|
|
DS_DATA_MODEL_IO()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_fileout = new FILE_OUTPUTFORMATTER( aFilename );
|
|
|
|
m_out = m_fileout;
|
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-05-30 22:56:24 +00:00
|
|
|
wxMessageBox( ioe.What(), _( "Error writing drawing sheet file" ) );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
~DS_DATA_MODEL_FILEIO()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
delete m_fileout;
|
|
|
|
}
|
2021-06-08 17:47:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FILE_OUTPUTFORMATTER* m_fileout;
|
2013-07-19 18:27:22 +00:00
|
|
|
};
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// A helper class to write a drawing sheet to a string
|
2021-02-22 23:47:17 +00:00
|
|
|
class DS_DATA_MODEL_STRINGIO : public DS_DATA_MODEL_IO
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-06-09 09:47:14 +00:00
|
|
|
DS_DATA_MODEL_STRINGIO( wxString* aOutputString ) :
|
2021-06-08 17:47:06 +00:00
|
|
|
DS_DATA_MODEL_IO(),
|
|
|
|
m_output( aOutputString )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_writer = new STRING_FORMATTER();
|
|
|
|
m_out = m_writer;
|
|
|
|
}
|
2014-04-09 13:33:04 +00:00
|
|
|
catch( const IO_ERROR& ioe )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-05-30 22:56:24 +00:00
|
|
|
wxMessageBox( ioe.What(), _( "Error writing drawing sheet file" ) );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
~DS_DATA_MODEL_STRINGIO()
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-06-09 09:47:14 +00:00
|
|
|
*m_output = FROM_UTF8( m_writer->GetString().c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
delete m_writer;
|
|
|
|
}
|
2021-06-08 17:47:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
STRING_FORMATTER* m_writer;
|
2021-06-09 09:47:14 +00:00
|
|
|
wxString* m_output;
|
2013-07-19 18:27:22 +00:00
|
|
|
};
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL::Save( const wxString& aFullFileName )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL_FILEIO writer( aFullFileName );
|
2013-07-19 18:27:22 +00:00
|
|
|
writer.Format( this );
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-06-09 09:47:14 +00:00
|
|
|
void DS_DATA_MODEL::SaveInString( wxString* aOutputString )
|
2013-07-26 12:50:29 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL_STRINGIO writer( aOutputString );
|
2013-07-26 12:50:29 +00:00
|
|
|
writer.Format( this );
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-06-09 09:47:14 +00:00
|
|
|
void DS_DATA_MODEL::SaveInString( std::vector<DS_DATA_ITEM*>& aItemsList, wxString* aOutputString )
|
2019-05-26 18:35:20 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_MODEL_STRINGIO writer( aOutputString );
|
2021-11-09 23:17:44 +00:00
|
|
|
writer.Format( this, aItemsList );
|
|
|
|
}
|
|
|
|
|
2019-05-26 18:35:20 +00:00
|
|
|
|
2021-11-09 23:17:44 +00:00
|
|
|
void DS_DATA_MODEL_IO::Format( DS_DATA_MODEL* aModel, std::vector<DS_DATA_ITEM*>& aItemsList ) const
|
|
|
|
{
|
2019-06-10 09:55:52 +00:00
|
|
|
LOCALE_IO toggle; // switch on/off the locale "C" notation
|
|
|
|
|
2021-11-09 23:17:44 +00:00
|
|
|
m_out->Print( 0, "(kicad_wks (version %d) (generator pl_editor)\n",
|
|
|
|
SEXPR_WORKSHEET_FILE_VERSION );
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DATA_ITEM* item : aItemsList )
|
2021-11-09 23:17:44 +00:00
|
|
|
Format( aModel, item, 1 );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
2019-05-26 18:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL_IO::Format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
switch( aItem->GetType() )
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_TEXT:
|
|
|
|
format( (DS_DATA_ITEM_TEXT*) aItem, aNestLevel );
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_SEGMENT:
|
|
|
|
case DS_DATA_ITEM::DS_RECT:
|
2019-05-25 13:56:52 +00:00
|
|
|
format( aModel, aItem, aNestLevel );
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_POLYPOLYGON:
|
|
|
|
format( (DS_DATA_ITEM_POLYGONS*) aItem, aNestLevel );
|
2013-07-19 18:27:22 +00:00
|
|
|
break;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
case DS_DATA_ITEM::DS_BITMAP:
|
|
|
|
format( (DS_DATA_ITEM_BITMAP*) aItem, aNestLevel );
|
2013-10-18 17:38:03 +00:00
|
|
|
break;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxT( "Cannot format item" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
void DS_DATA_MODEL_IO::Format( DS_DATA_MODEL* aSheet ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO toggle; // switch on/off the locale "C" notation
|
|
|
|
|
2021-06-10 22:39:03 +00:00
|
|
|
m_out->Print( 0, "(kicad_wks (version %d) (generator pl_editor)\n",
|
|
|
|
SEXPR_WORKSHEET_FILE_VERSION );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
// Setup
|
|
|
|
int nestLevel = 1;
|
2013-07-20 19:36:19 +00:00
|
|
|
// Write default values:
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( nestLevel, "(setup " );
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, "(textsize %s %s)",
|
2021-08-27 11:52:13 +00:00
|
|
|
double2Str( aSheet->m_DefaultTextSize.x ).c_str(),
|
|
|
|
double2Str( aSheet->m_DefaultTextSize.y ).c_str() );
|
|
|
|
m_out->Print( 0, "(linewidth %s)", double2Str( aSheet->m_DefaultLineWidth ).c_str() );
|
|
|
|
m_out->Print( 0, "(textlinewidth %s)", double2Str( aSheet->m_DefaultTextThickness ).c_str() );
|
2013-07-20 19:36:19 +00:00
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
|
|
|
|
// Write margin values
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( nestLevel, "(left_margin %s)", double2Str( aSheet->GetLeftMargin() ).c_str() );
|
|
|
|
m_out->Print( 0, "(right_margin %s)", double2Str( aSheet->GetRightMargin() ).c_str() );
|
|
|
|
m_out->Print( 0, "(top_margin %s)", double2Str( aSheet->GetTopMargin() ).c_str() );
|
|
|
|
m_out->Print( 0, "(bottom_margin %s)", double2Str( aSheet->GetBottomMargin() ).c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// Save the graphical items on the drawing sheet
|
2021-08-27 11:52:13 +00:00
|
|
|
for( unsigned ii = 0; ii < aSheet->GetCount(); ii++ )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
DS_DATA_ITEM* item = aSheet->GetItem( ii );
|
|
|
|
Format( aSheet, item, nestLevel );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(tbtext" );
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, " %s", m_out->Quotew( aItem->m_TextBase ).c_str() );
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (name %s)", m_out->Quotew( aItem->m_Name ).c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
formatCoordinate( getTokenName( T_pos ), aItem->m_Pos );
|
|
|
|
formatOptions( aItem );
|
|
|
|
|
|
|
|
if( aItem->m_Orient )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (rotate %s)", double2Str(aItem->m_Orient ).c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2016-01-28 07:51:09 +00:00
|
|
|
// Write font info, only if it is not the default setup
|
|
|
|
bool write_size = aItem->m_TextSize.x != 0.0 || aItem->m_TextSize.y != 0.0;
|
2016-09-10 15:16:48 +00:00
|
|
|
bool write_thickness = aItem->m_LineWidth != 0.0;
|
2016-01-28 07:51:09 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
if( write_thickness || write_size || aItem->m_Bold || aItem->m_Italic )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (font" );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2022-02-28 18:02:00 +00:00
|
|
|
if( aItem->m_Font && !aItem->m_Font->Name().IsEmpty() )
|
|
|
|
m_out->Print( 0, " (face \"%s\")", aItem->m_Font->NameAsToken() );
|
|
|
|
|
2016-09-10 15:16:48 +00:00
|
|
|
if( write_thickness )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (linewidth %s)", double2Str( aItem->m_LineWidth ).c_str() );
|
2016-09-10 15:16:48 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
if( write_size )
|
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (size %s %s)",
|
|
|
|
double2Str( aItem->m_TextSize.x ).c_str(),
|
|
|
|
double2Str( aItem->m_TextSize.y ).c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
2021-08-27 11:52:13 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
if( aItem->m_Bold )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " bold" );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
if( aItem->m_Italic )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " italic" );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2022-03-31 18:43:08 +00:00
|
|
|
if( aItem->m_TextColor != COLOR4D::UNSPECIFIED )
|
|
|
|
{
|
|
|
|
m_out->Print( 0, " (color %d %d %d %s)",
|
|
|
|
KiROUND( aItem->m_TextColor.r * 255.0 ),
|
|
|
|
KiROUND( aItem->m_TextColor.g * 255.0 ),
|
|
|
|
KiROUND( aItem->m_TextColor.b * 255.0 ),
|
|
|
|
Double2Str( aItem->m_TextColor.a ).c_str() );
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write text justification
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aItem->m_Hjustify != GR_TEXT_H_ALIGN_LEFT || aItem->m_Vjustify != GR_TEXT_V_ALIGN_CENTER )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (justify" );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
// Write T_center opt first, because it is
|
|
|
|
// also a center for both m_Hjustify and m_Vjustify
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aItem->m_Hjustify == GR_TEXT_H_ALIGN_CENTER )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " center" );
|
2021-12-28 22:13:54 +00:00
|
|
|
else if( aItem->m_Hjustify == GR_TEXT_H_ALIGN_RIGHT )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " right" );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
if( aItem->m_Vjustify == GR_TEXT_V_ALIGN_TOP )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " top" );
|
2021-12-28 22:13:54 +00:00
|
|
|
else if( aItem->m_Vjustify == GR_TEXT_V_ALIGN_BOTTOM )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " bottom" );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// write constraints
|
|
|
|
if( aItem->m_BoundingBoxSize.x )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (maxlen %s)", double2Str(aItem->m_BoundingBoxSize.x ).c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
if( aItem->m_BoundingBoxSize.y )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (maxheight %s)", double2Str(aItem->m_BoundingBoxSize.y ).c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
formatRepeatParameters( aItem );
|
|
|
|
|
2021-05-02 06:54:16 +00:00
|
|
|
if( !aItem->m_Info.IsEmpty() )
|
|
|
|
m_out->Print( 0, " (comment %s)\n", m_out->Quotew( aItem->m_Info ).c_str() );
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL_IO::format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
if( aItem->GetType() == DS_DATA_ITEM::DS_RECT )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(rect" );
|
2013-07-19 18:27:22 +00:00
|
|
|
else
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(line" );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (name %s)", m_out->Quotew( aItem->m_Name ).c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
formatCoordinate( getTokenName( T_start ), aItem->m_Pos );
|
|
|
|
formatCoordinate( getTokenName( T_end ), aItem->m_End );
|
|
|
|
formatOptions( aItem );
|
|
|
|
|
2019-05-25 13:56:52 +00:00
|
|
|
if( aItem->m_LineWidth && aItem->m_LineWidth != aModel->m_DefaultLineWidth )
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, " (linewidth %s)", double2Str( aItem->m_LineWidth ).c_str() );
|
|
|
|
|
|
|
|
formatRepeatParameters( aItem );
|
|
|
|
|
2021-05-02 06:54:16 +00:00
|
|
|
if( !aItem->m_Info.IsEmpty() )
|
|
|
|
m_out->Print( 0, " (comment %s)\n", m_out->Quotew( aItem->m_Info ).c_str() );
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_POLYGONS* aItem, int aNestLevel ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(polygon" );
|
|
|
|
m_out->Print( 0, " (name %s)", m_out->Quotew( aItem->m_Name ).c_str() );
|
|
|
|
formatCoordinate( "pos", aItem->m_Pos );
|
2013-07-19 18:27:22 +00:00
|
|
|
formatOptions( aItem );
|
|
|
|
|
|
|
|
formatRepeatParameters( aItem );
|
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
if( !aItem->m_Orient.IsZero() )
|
|
|
|
m_out->Print( 0, " (rotate %s)", double2Str( aItem->m_Orient.AsDegrees() ).c_str() );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
if( aItem->m_LineWidth )
|
|
|
|
m_out->Print( 0, " (linewidth %s)\n", double2Str( aItem->m_LineWidth ).c_str() );
|
|
|
|
|
2021-05-02 06:54:16 +00:00
|
|
|
if( !aItem->m_Info.IsEmpty() )
|
|
|
|
m_out->Print( 0, " (comment %s)\n", m_out->Quotew( aItem->m_Info ).c_str() );
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
// Write polygon corners list
|
|
|
|
for( int kk = 0; kk < aItem->GetPolyCount(); kk++ )
|
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( aNestLevel+1, "(pts" );
|
2013-07-19 18:27:22 +00:00
|
|
|
// Create current polygon corners list
|
|
|
|
unsigned ist = aItem->GetPolyIndexStart( kk );
|
|
|
|
unsigned iend = aItem->GetPolyIndexEnd( kk );
|
|
|
|
int ii = 0;
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
while( ist <= iend )
|
|
|
|
{
|
2022-01-19 23:31:07 +00:00
|
|
|
VECTOR2D pos = aItem->m_Corners[ist++];
|
|
|
|
int nestLevel = 0;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
if( ii++ > 4)
|
|
|
|
{
|
|
|
|
m_out->Print( 0, "\n" );
|
|
|
|
nestLevel = aNestLevel+2;
|
|
|
|
ii = 0;
|
|
|
|
}
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( nestLevel, " (xy %s %s)",
|
2013-07-19 18:27:22 +00:00
|
|
|
double2Str( pos.x ).c_str(),
|
|
|
|
double2Str( pos.y ).c_str() );
|
|
|
|
}
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) const
|
2013-10-18 17:38:03 +00:00
|
|
|
{
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(bitmap" );
|
|
|
|
m_out->Print( 0, " (name %s)", m_out->Quotew( aItem->m_Name ).c_str() );
|
|
|
|
formatCoordinate( "pos", aItem->m_Pos );
|
2013-10-18 17:38:03 +00:00
|
|
|
formatOptions( aItem );
|
|
|
|
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (scale %s)", double2Str( aItem->m_ImageBitmap->GetScale() ).c_str() );
|
2013-10-18 17:38:03 +00:00
|
|
|
|
|
|
|
formatRepeatParameters( aItem );
|
|
|
|
m_out->Print( 0,"\n");
|
|
|
|
|
2021-05-02 06:54:16 +00:00
|
|
|
if( !aItem->m_Info.IsEmpty() )
|
|
|
|
m_out->Print( 0, " (comment %s)\n", m_out->Quotew( aItem->m_Info ).c_str() );
|
|
|
|
|
2013-10-18 17:38:03 +00:00
|
|
|
// Write image in png readable format
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( aNestLevel, "(pngdata\n" );
|
2013-10-18 17:38:03 +00:00
|
|
|
wxArrayString pngStrings;
|
|
|
|
aItem->m_ImageBitmap->SaveData( pngStrings );
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < pngStrings.GetCount(); ii++ )
|
|
|
|
m_out->Print( aNestLevel+1, "(data \"%s\")\n", TO_UTF8(pngStrings[ii]) );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel+1, ")\n" );
|
|
|
|
|
|
|
|
m_out->Print( aNestLevel, ")\n" );
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-06-08 17:47:06 +00:00
|
|
|
void DS_DATA_MODEL_IO::formatCoordinate( const char * aToken, POINT_COORD & aCoord ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
m_out->Print( 0, " (%s %s %s", aToken,
|
|
|
|
double2Str( aCoord.m_Pos.x ).c_str(),
|
|
|
|
double2Str( aCoord.m_Pos.y ).c_str() );
|
|
|
|
|
|
|
|
switch( aCoord.m_Anchor )
|
|
|
|
{
|
2019-05-25 11:05:39 +00:00
|
|
|
case RB_CORNER: break;
|
2021-08-27 11:52:13 +00:00
|
|
|
case LT_CORNER: m_out->Print( 0, " ltcorner" ); break;
|
|
|
|
case LB_CORNER: m_out->Print( 0, " lbcorner" ); break;
|
|
|
|
case RT_CORNER: m_out->Print( 0, " rtcorner" ); break;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_out->Print( 0, ")" );
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL_IO::formatRepeatParameters( DS_DATA_ITEM* aItem ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
if( aItem->m_RepeatCount <= 1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_out->Print( 0, " (repeat %d)", aItem->m_RepeatCount );
|
|
|
|
|
|
|
|
if( aItem->m_IncrementVector.x )
|
|
|
|
m_out->Print( 0, " (incrx %s)", double2Str(aItem-> m_IncrementVector.x ).c_str() );
|
|
|
|
|
|
|
|
if( aItem->m_IncrementVector.y )
|
|
|
|
m_out->Print( 0, " (incry %s)", double2Str( aItem->m_IncrementVector.y ).c_str() );
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
if( aItem->m_IncrementLabel != 1 && aItem->GetType() == DS_DATA_ITEM::DS_TEXT )
|
2013-07-19 18:27:22 +00:00
|
|
|
m_out->Print( 0, " (incrlabel %d)", aItem->m_IncrementLabel );
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
void DS_DATA_MODEL_IO::formatOptions( DS_DATA_ITEM* aItem ) const
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
2019-05-20 10:23:32 +00:00
|
|
|
if( aItem->GetPage1Option() == FIRST_PAGE_ONLY )
|
2021-08-27 18:10:38 +00:00
|
|
|
m_out->Print( 0, " (option page1only)" );
|
2019-05-20 10:23:32 +00:00
|
|
|
else if( aItem->GetPage1Option() == SUBSEQUENT_PAGES )
|
2021-08-27 11:52:13 +00:00
|
|
|
m_out->Print( 0, " (option notonpage1)" );
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|