KiCad PCB EDA Suite
WORKSHEET_LAYOUT_IO Class Reference
Inheritance diagram for WORKSHEET_LAYOUT_IO:
WORKSHEET_LAYOUT_FILEIO WORKSHEET_LAYOUT_STRINGIO

Public Member Functions

void Format (WORKSHEET_LAYOUT *aPageLayout) const
 
void Format (WORKSHEET_DATAITEM *aItem, int aNestLevel) const
 

Protected Member Functions

 WORKSHEET_LAYOUT_IO ()
 
virtual ~WORKSHEET_LAYOUT_IO ()
 

Protected Attributes

OUTPUTFORMATTERm_out
 

Private Member Functions

void format (WORKSHEET_LAYOUT *aPageLayout) const
 
void format (WORKSHEET_DATAITEM_TEXT *aItem, int aNestLevel) const
 
void format (WORKSHEET_DATAITEM *aItem, int aNestLevel) const
 
void format (WORKSHEET_DATAITEM_POLYPOLYGON *aItem, int aNestLevel) const
 
void format (WORKSHEET_DATAITEM_BITMAP *aItem, int aNestLevel) const
 
void formatCoordinate (const char *aToken, POINT_COORD &aCoord) const
 
void formatRepeatParameters (WORKSHEET_DATAITEM *aItem) const
 
void formatOptions (WORKSHEET_DATAITEM *aItem) const
 

Detailed Description

Definition at line 57 of file page_layout_writer.cpp.

Constructor & Destructor Documentation

WORKSHEET_LAYOUT_IO::WORKSHEET_LAYOUT_IO ( )
inlineprotected

Definition at line 62 of file page_layout_writer.cpp.

62 { m_out = NULL; }
OUTPUTFORMATTER * m_out
virtual WORKSHEET_LAYOUT_IO::~WORKSHEET_LAYOUT_IO ( )
inlineprotectedvirtual

Definition at line 63 of file page_layout_writer.cpp.

63 {}

Member Function Documentation

void WORKSHEET_LAYOUT_IO::Format ( WORKSHEET_LAYOUT aPageLayout) const

Definition at line 186 of file page_layout_writer.cpp.

References double2Str, Format(), WORKSHEET_LAYOUT::GetBottomMargin(), WORKSHEET_LAYOUT::GetCount(), WORKSHEET_LAYOUT::GetItem(), WORKSHEET_LAYOUT::GetLeftMargin(), WORKSHEET_LAYOUT::GetRightMargin(), getTokenName(), WORKSHEET_LAYOUT::GetTopMargin(), WORKSHEET_DATAITEM::m_DefaultLineWidth, WORKSHEET_DATAITEM::m_DefaultTextSize, WORKSHEET_DATAITEM::m_DefaultTextThickness, TB_READER_T::T_bottom_margin, TB_READER_T::T_left_margin, TB_READER_T::T_right_margin, TB_READER_T::T_setup, and TB_READER_T::T_top_margin.

Referenced by WORKSHEET_LAYOUT::Save(), and WORKSHEET_LAYOUT::SaveInString().

187 {
188  LOCALE_IO toggle; // switch on/off the locale "C" notation
189 
190  m_out->Print( 0, "(page_layout\n" );
191 
192  // Setup
193  int nestLevel = 1;
194  // Write default values:
195  m_out->Print( nestLevel, "(%s ", getTokenName( T_setup ) );
196  m_out->Print( 0, "(textsize %s %s)",
199  m_out->Print( 0, "(linewidth %s)", double2Str( WORKSHEET_DATAITEM::m_DefaultLineWidth ).c_str() );
200  m_out->Print( 0, "(textlinewidth %s)", double2Str( WORKSHEET_DATAITEM::m_DefaultTextThickness ).c_str() );
201  m_out->Print( 0, "\n" );
202 
203  // Write margin values
204  m_out->Print( nestLevel, "(%s %s)", getTokenName( T_left_margin ),
205  double2Str( aPageLayout->GetLeftMargin() ).c_str() );
206  m_out->Print( 0, "(%s %s)", getTokenName( T_right_margin ),
207  double2Str( aPageLayout->GetRightMargin() ).c_str() );
208  m_out->Print( 0, "(%s %s)", getTokenName( T_top_margin ),
209  double2Str( aPageLayout->GetTopMargin() ).c_str() );
210  m_out->Print( 0, "(%s %s)", getTokenName( T_bottom_margin ),
211  double2Str( aPageLayout->GetBottomMargin() ).c_str() );
212  m_out->Print( 0, ")\n" );
213 
214  // Save the graphical items on the page layout
215  for( unsigned ii = 0; ii < aPageLayout->GetCount(); ii++ )
216  {
217  WORKSHEET_DATAITEM* item = aPageLayout->GetItem( ii );
218  Format( item, nestLevel );
219  }
220 
221  m_out->Print( 0, ")\n" );
222 }
#define double2Str
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
OUTPUTFORMATTER * m_out
void Format(WORKSHEET_LAYOUT *aPageLayout) const
WORKSHEET_DATAITEM * GetItem(unsigned aIdx) const
unsigned GetCount() const
static double m_DefaultTextThickness
static const char * getTokenName(T aTok)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void WORKSHEET_LAYOUT_IO::Format ( WORKSHEET_DATAITEM aItem,
int  aNestLevel 
) const

Definition at line 159 of file page_layout_writer.cpp.

References WORKSHEET_DATAITEM::GetType(), WORKSHEET_DATAITEM::WS_BITMAP, WORKSHEET_DATAITEM::WS_POLYPOLYGON, WORKSHEET_DATAITEM::WS_RECT, WORKSHEET_DATAITEM::WS_SEGMENT, and WORKSHEET_DATAITEM::WS_TEXT.

160 {
161  switch( aItem->GetType() )
162  {
164  format( (WORKSHEET_DATAITEM_TEXT*) aItem, aNestLevel );
165  break;
166 
169  format( aItem, aNestLevel );
170  break;
171 
173  format( (WORKSHEET_DATAITEM_POLYPOLYGON*) aItem, aNestLevel );
174  break;
175 
177  format( (WORKSHEET_DATAITEM_BITMAP*) aItem, aNestLevel );
178  break;
179 
180  default:
181  wxFAIL_MSG( wxT( "Cannot format item" ) );
182  }
183 }
void format(WORKSHEET_LAYOUT *aPageLayout) const
WS_ItemType GetType() const
void WORKSHEET_LAYOUT_IO::format ( WORKSHEET_LAYOUT aPageLayout) const
private
void WORKSHEET_LAYOUT_IO::format ( WORKSHEET_DATAITEM_TEXT aItem,
int  aNestLevel 
) const
private

Definition at line 225 of file page_layout_writer.cpp.

References double2Str, getTokenName(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, WORKSHEET_DATAITEM_TEXT::IsBold(), WORKSHEET_DATAITEM_TEXT::IsItalic(), WORKSHEET_DATAITEM_TEXT::m_BoundingBoxSize, WORKSHEET_DATAITEM_TEXT::m_Hjustify, WORKSHEET_DATAITEM::m_LineWidth, WORKSHEET_DATAITEM::m_Name, WORKSHEET_DATAITEM_TEXT::m_Orient, WORKSHEET_DATAITEM::m_Pos, WORKSHEET_DATAITEM_TEXT::m_TextBase, WORKSHEET_DATAITEM_TEXT::m_TextSize, WORKSHEET_DATAITEM_TEXT::m_Vjustify, TB_READER_T::T_bold, TB_READER_T::T_bottom, TB_READER_T::T_center, TB_READER_T::T_font, TB_READER_T::T_italic, TB_READER_T::T_justify, TB_READER_T::T_linewidth, TB_READER_T::T_maxheight, TB_READER_T::T_maxlen, TB_READER_T::T_name, TB_READER_T::T_pos, TB_READER_T::T_right, TB_READER_T::T_rotate, TB_READER_T::T_size, TB_READER_T::T_tbtext, TB_READER_T::T_top, VECTOR2< T >::x, and VECTOR2< T >::y.

226 {
227  m_out->Print( aNestLevel, "(%s", getTokenName( T_tbtext ) );
228  m_out->Print( 0, " %s", m_out->Quotew( aItem->m_TextBase ).c_str() );
229  m_out->Print( 0, " (%s %s)", getTokenName( T_name ),
230  m_out->Quotew( aItem->m_Name ).c_str() );
231 
233  formatOptions( aItem );
234 
235  if( aItem->m_Orient )
236  m_out->Print( 0, " (%s %s)", getTokenName( T_rotate ),
237  double2Str(aItem->m_Orient ).c_str() );
238 
239  // Write font info, only if it is not the default setup
240  bool write_size = aItem->m_TextSize.x != 0.0 || aItem->m_TextSize.y != 0.0;
241  bool write_thickness = aItem->m_LineWidth != 0.0;
242 
243  if( write_thickness || write_size || aItem->IsBold() || aItem->IsItalic() )
244  {
245  m_out->Print( 0, " (%s", getTokenName( T_font ) );
246 
247  if( write_thickness )
248  {
249  m_out->Print( 0, " (%s %s)", getTokenName( T_linewidth ),
250  double2Str(aItem->m_LineWidth ).c_str() );
251  }
252 
253  if( write_size )
254  {
255  m_out->Print( 0, " (%s %s %s)", getTokenName( T_size ),
256  double2Str(aItem->m_TextSize.x ).c_str(),
257  double2Str(aItem->m_TextSize.y ).c_str() );
258  }
259  if( aItem->IsBold() )
260  m_out->Print( 0, " %s", getTokenName( T_bold ) );
261 
262  if( aItem->IsItalic() )
263  m_out->Print( 0, " %s", getTokenName( T_italic ) );
264 
265  m_out->Print( 0, ")" );
266  }
267 
268  // Write text justification
269  if( aItem->m_Hjustify != GR_TEXT_HJUSTIFY_LEFT ||
271  {
272  m_out->Print( 0, " (%s", getTokenName( T_justify ) );
273 
274  // Write T_center opt first, because it is
275  // also a center for both m_Hjustify and m_Vjustify
276  if( aItem->m_Hjustify == GR_TEXT_HJUSTIFY_CENTER )
277  m_out->Print( 0, " %s", getTokenName( T_center ) );
278 
279  if( aItem->m_Hjustify == GR_TEXT_HJUSTIFY_RIGHT )
280  m_out->Print( 0, " %s", getTokenName( T_right ) );
281 
282  if( aItem->m_Vjustify == GR_TEXT_VJUSTIFY_TOP )
283  m_out->Print( 0, " %s", getTokenName( T_top ) );
284 
285  if( aItem->m_Vjustify == GR_TEXT_VJUSTIFY_BOTTOM )
286  m_out->Print( 0, " %s", getTokenName( T_bottom ) );
287 
288  m_out->Print( 0, ")" );
289  }
290 
291  // write constraints
292  if( aItem->m_BoundingBoxSize.x )
293  m_out->Print( 0, " (%s %s)", getTokenName( T_maxlen ),
294  double2Str(aItem->m_BoundingBoxSize.x ).c_str() );
295 
296  if( aItem->m_BoundingBoxSize.y )
297  m_out->Print( 0, " (%s %s)", getTokenName( T_maxheight ),
298  double2Str(aItem->m_BoundingBoxSize.y ).c_str() );
299 
300  formatRepeatParameters( aItem );
301 
302  m_out->Print( 0, ")\n" );
303 }
#define double2Str
OUTPUTFORMATTER * m_out
void formatOptions(WORKSHEET_DATAITEM *aItem) const
void formatRepeatParameters(WORKSHEET_DATAITEM *aItem) const
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
static const char * getTokenName(T aTok)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void formatCoordinate(const char *aToken, POINT_COORD &aCoord) const
void WORKSHEET_LAYOUT_IO::format ( WORKSHEET_DATAITEM aItem,
int  aNestLevel 
) const
private

Definition at line 305 of file page_layout_writer.cpp.

References double2Str, getTokenName(), WORKSHEET_DATAITEM::GetType(), WORKSHEET_DATAITEM::m_DefaultLineWidth, WORKSHEET_DATAITEM::m_End, WORKSHEET_DATAITEM::m_LineWidth, WORKSHEET_DATAITEM::m_Name, WORKSHEET_DATAITEM::m_Pos, TB_READER_T::T_end, TB_READER_T::T_line, TB_READER_T::T_name, TB_READER_T::T_rect, TB_READER_T::T_start, and WORKSHEET_DATAITEM::WS_RECT.

306 {
307  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_RECT )
308  m_out->Print( aNestLevel, "(%s", getTokenName( T_rect ) );
309  else
310  m_out->Print( aNestLevel, "(%s", getTokenName( T_line ) );
311 
312  m_out->Print( 0, " (%s %s)", getTokenName( T_name ),
313  m_out->Quotew( aItem->m_Name ).c_str() );
314 
317  formatOptions( aItem );
318 
319  if( aItem->m_LineWidth && aItem->m_LineWidth != aItem->m_DefaultLineWidth )
320  m_out->Print( 0, " (linewidth %s)", double2Str( aItem->m_LineWidth ).c_str() );
321 
322  formatRepeatParameters( aItem );
323 
324  m_out->Print( 0, ")\n" );
325 }
#define double2Str
OUTPUTFORMATTER * m_out
void formatOptions(WORKSHEET_DATAITEM *aItem) const
void formatRepeatParameters(WORKSHEET_DATAITEM *aItem) const
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
WS_ItemType GetType() const
static const char * getTokenName(T aTok)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void formatCoordinate(const char *aToken, POINT_COORD &aCoord) const
void WORKSHEET_LAYOUT_IO::format ( WORKSHEET_DATAITEM_POLYPOLYGON aItem,
int  aNestLevel 
) const
private

Definition at line 328 of file page_layout_writer.cpp.

References double2Str, WORKSHEET_DATAITEM_POLYPOLYGON::GetPolyCount(), WORKSHEET_DATAITEM_POLYPOLYGON::GetPolyIndexEnd(), WORKSHEET_DATAITEM_POLYPOLYGON::GetPolyIndexStart(), getTokenName(), WORKSHEET_DATAITEM_POLYPOLYGON::m_Corners, WORKSHEET_DATAITEM::m_LineWidth, WORKSHEET_DATAITEM::m_Name, WORKSHEET_DATAITEM_POLYPOLYGON::m_Orient, WORKSHEET_DATAITEM::m_Pos, TB_READER_T::T_name, TB_READER_T::T_polygon, TB_READER_T::T_pos, TB_READER_T::T_pts, TB_READER_T::T_rotate, TB_READER_T::T_xy, VECTOR2< T >::x, and VECTOR2< T >::y.

329 {
330  m_out->Print( aNestLevel, "(%s", getTokenName( T_polygon ) );
331  m_out->Print( 0, " (%s %s)", getTokenName( T_name ),
332  m_out->Quotew( aItem->m_Name ).c_str() );
334  formatOptions( aItem );
335 
336  formatRepeatParameters( aItem );
337 
338  if( aItem->m_Orient )
339  m_out->Print( 0, " (%s %s)", getTokenName( T_rotate ),
340  double2Str(aItem->m_Orient ).c_str() );
341 
342  if( aItem->m_LineWidth )
343  m_out->Print( 0, " (linewidth %s)\n", double2Str( aItem->m_LineWidth ).c_str() );
344 
345  // Write polygon corners list
346  for( int kk = 0; kk < aItem->GetPolyCount(); kk++ )
347  {
348  m_out->Print( aNestLevel+1, "(%s", getTokenName( T_pts ) );
349  // Create current polygon corners list
350  unsigned ist = aItem->GetPolyIndexStart( kk );
351  unsigned iend = aItem->GetPolyIndexEnd( kk );
352  int ii = 0;
353 
354  while( ist <= iend )
355  {
356  DPOINT pos = aItem->m_Corners[ist++];
357  int nestLevel = 0;
358 
359  if( ii++ > 4)
360  {
361  m_out->Print( 0, "\n" );
362  nestLevel = aNestLevel+2;
363  ii = 0;
364  }
365 
366  m_out->Print( nestLevel, " (%s %s %s)", getTokenName( T_xy ),
367  double2Str( pos.x ).c_str(),
368  double2Str( pos.y ).c_str() );
369  }
370 
371  m_out->Print( 0, ")\n" );
372  }
373 
374  m_out->Print( aNestLevel, ")\n" );
375 }
#define double2Str
OUTPUTFORMATTER * m_out
void formatOptions(WORKSHEET_DATAITEM *aItem) const
void formatRepeatParameters(WORKSHEET_DATAITEM *aItem) const
unsigned GetPolyIndexStart(unsigned aContour) const
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
static const char * getTokenName(T aTok)
unsigned GetPolyIndexEnd(unsigned aContour) const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void formatCoordinate(const char *aToken, POINT_COORD &aCoord) const
void WORKSHEET_LAYOUT_IO::format ( WORKSHEET_DATAITEM_BITMAP aItem,
int  aNestLevel 
) const
private

Definition at line 378 of file page_layout_writer.cpp.

References double2Str, BITMAP_BASE::GetScale(), getTokenName(), WORKSHEET_DATAITEM_BITMAP::m_ImageBitmap, WORKSHEET_DATAITEM::m_Name, WORKSHEET_DATAITEM::m_Pos, BITMAP_BASE::SaveData(), TB_READER_T::T_bitmap, TB_READER_T::T_name, TB_READER_T::T_pngdata, TB_READER_T::T_pos, TB_READER_T::T_scale, and TO_UTF8.

379 {
380  m_out->Print( aNestLevel, "(%s", getTokenName( T_bitmap ) );
381  m_out->Print( 0, " (%s %s)", getTokenName( T_name ),
382  m_out->Quotew( aItem->m_Name ).c_str() );
384  formatOptions( aItem );
385 
386  m_out->Print( 0, " (%s %s)", getTokenName( T_scale ),
387  double2Str( aItem->m_ImageBitmap->GetScale() ).c_str() );
388 
389  formatRepeatParameters( aItem );
390  m_out->Print( 0,"\n");
391 
392  // Write image in png readable format
393  m_out->Print( aNestLevel, "(%s\n", getTokenName( T_pngdata ) );
394  wxArrayString pngStrings;
395  aItem->m_ImageBitmap->SaveData( pngStrings );
396 
397  for( unsigned ii = 0; ii < pngStrings.GetCount(); ii++ )
398  m_out->Print( aNestLevel+1, "(data \"%s\")\n", TO_UTF8(pngStrings[ii]) );
399 
400  m_out->Print( aNestLevel+1, ")\n" );
401 
402  m_out->Print( aNestLevel, ")\n" );
403 }
#define double2Str
bool SaveData(FILE *aFile) const
writes the bitmap data to aFile The format is png, in Hexadecimal form: If the hexadecimal data is co...
OUTPUTFORMATTER * m_out
void formatOptions(WORKSHEET_DATAITEM *aItem) const
void formatRepeatParameters(WORKSHEET_DATAITEM *aItem) const
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:486
double GetScale() const
static const char * getTokenName(T aTok)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void formatCoordinate(const char *aToken, POINT_COORD &aCoord) const
void WORKSHEET_LAYOUT_IO::formatCoordinate ( const char *  aToken,
POINT_COORD aCoord 
) const
private

Definition at line 406 of file page_layout_writer.cpp.

References double2Str, getTokenName(), LB_CORNER, LT_CORNER, POINT_COORD::m_Anchor, POINT_COORD::m_Pos, RB_CORNER, RT_CORNER, TB_READER_T::T_lbcorner, TB_READER_T::T_ltcorner, TB_READER_T::T_rtcorner, VECTOR2< T >::x, and VECTOR2< T >::y.

408 {
409  m_out->Print( 0, " (%s %s %s", aToken,
410  double2Str( aCoord.m_Pos.x ).c_str(),
411  double2Str( aCoord.m_Pos.y ).c_str() );
412 
413  switch( aCoord.m_Anchor )
414  {
415  case RB_CORNER:
416  break;
417 
418  case LT_CORNER:
419  m_out->Print( 0, " %s", getTokenName( T_ltcorner ) );
420  break;
421 
422  case LB_CORNER:
423  m_out->Print( 0, " %s", getTokenName( T_lbcorner ) );
424  break;
425 
426  case RT_CORNER:
427  m_out->Print( 0, " %s", getTokenName( T_rtcorner ) );
428  break;
429  }
430 
431  m_out->Print( 0, ")" );
432 }
#define double2Str
OUTPUTFORMATTER * m_out
static const char * getTokenName(T aTok)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void WORKSHEET_LAYOUT_IO::formatOptions ( WORKSHEET_DATAITEM aItem) const
private

Definition at line 454 of file page_layout_writer.cpp.

References WORKSHEET_DATAITEM::GetPage1Option(), getTokenName(), TB_READER_T::T_notonpage1, TB_READER_T::T_option, and TB_READER_T::T_page1only.

455 {
456  switch( aItem->GetPage1Option() )
457  {
458  default:
459  case 0:
460  break;
461 
462  case 1:
463  m_out->Print( 0, " (%s %s)", getTokenName( T_option ),
465  break;
466 
467  case -1:
468  m_out->Print( 0, " (%s %s)", getTokenName( T_option ), getTokenName( T_notonpage1 ) );
469  break;
470  }
471 }
OUTPUTFORMATTER * m_out
static const char * getTokenName(T aTok)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void WORKSHEET_LAYOUT_IO::formatRepeatParameters ( WORKSHEET_DATAITEM aItem) const
private

Definition at line 435 of file page_layout_writer.cpp.

References double2Str, WORKSHEET_DATAITEM::GetType(), WORKSHEET_DATAITEM::m_IncrementLabel, WORKSHEET_DATAITEM::m_IncrementVector, WORKSHEET_DATAITEM::m_RepeatCount, WORKSHEET_DATAITEM::WS_TEXT, VECTOR2< T >::x, and VECTOR2< T >::y.

436 {
437  if( aItem->m_RepeatCount <= 1 )
438  return;
439 
440  m_out->Print( 0, " (repeat %d)", aItem->m_RepeatCount );
441 
442  if( aItem->m_IncrementVector.x )
443  m_out->Print( 0, " (incrx %s)", double2Str(aItem-> m_IncrementVector.x ).c_str() );
444 
445  if( aItem->m_IncrementVector.y )
446  m_out->Print( 0, " (incry %s)", double2Str( aItem->m_IncrementVector.y ).c_str() );
447 
448  if( aItem->m_IncrementLabel != 1 &&
450  m_out->Print( 0, " (incrlabel %d)", aItem->m_IncrementLabel );
451 }
#define double2Str
OUTPUTFORMATTER * m_out
WS_ItemType GetType() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

Member Data Documentation

OUTPUTFORMATTER* WORKSHEET_LAYOUT_IO::m_out
protected

Definition at line 60 of file page_layout_writer.cpp.


The documentation for this class was generated from the following file: