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 throw ( IO_ERROR )
 
void Format (WORKSHEET_DATAITEM *aItem, int aNestLevel) const throw ( IO_ERROR )
 

Protected Member Functions

 WORKSHEET_LAYOUT_IO ()
 
virtual ~WORKSHEET_LAYOUT_IO ()
 

Protected Attributes

OUTPUTFORMATTERm_out
 

Private Member Functions

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

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
throw (IO_ERROR
)

Definition at line 192 of file page_layout_writer.cpp.

References double2Str, Format(), getTokenName(), WORKSHEET_DATAITEM::m_DefaultLineWidth, WORKSHEET_DATAITEM::m_DefaultTextSize, WORKSHEET_DATAITEM::m_DefaultTextThickness, OUTPUTFORMATTER::Print(), 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().

194 {
195  LOCALE_IO toggle; // switch on/off the locale "C" notation
196 
197  m_out->Print( 0, "(page_layout\n" );
198 
199  // Setup
200  int nestLevel = 1;
201  // Write default values:
202  m_out->Print( nestLevel, "(%s ", getTokenName( T_setup ) );
203  m_out->Print( 0, "(textsize %s %s)",
206  m_out->Print( 0, "(linewidth %s)", double2Str( WORKSHEET_DATAITEM::m_DefaultLineWidth ).c_str() );
207  m_out->Print( 0, "(textlinewidth %s)", double2Str( WORKSHEET_DATAITEM::m_DefaultTextThickness ).c_str() );
208  m_out->Print( 0, "\n" );
209 
210  // Write margin values
211  m_out->Print( nestLevel, "(%s %s)", getTokenName( T_left_margin ),
212  double2Str( aPageLayout->GetLeftMargin() ).c_str() );
213  m_out->Print( 0, "(%s %s)", getTokenName( T_right_margin ),
214  double2Str( aPageLayout->GetRightMargin() ).c_str() );
215  m_out->Print( 0, "(%s %s)", getTokenName( T_top_margin ),
216  double2Str( aPageLayout->GetTopMargin() ).c_str() );
217  m_out->Print( 0, "(%s %s)", getTokenName( T_bottom_margin ),
218  double2Str( aPageLayout->GetBottomMargin() ).c_str() );
219  m_out->Print( 0, ")\n" );
220 
221  // Save the graphical items on the page layout
222  for( unsigned ii = 0; ii < aPageLayout->GetCount(); ii++ )
223  {
224  WORKSHEET_DATAITEM* item = aPageLayout->GetItem( ii );
225  Format( item, nestLevel );
226  }
227 
228  m_out->Print( 0, ")\n" );
229 }
#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
throw (IO_ERROR
)

Definition at line 164 of file page_layout_writer.cpp.

References WORKSHEET_DATAITEM::WS_BITMAP, WORKSHEET_DATAITEM::WS_POLYPOLYGON, WORKSHEET_DATAITEM::WS_RECT, WORKSHEET_DATAITEM::WS_SEGMENT, and WORKSHEET_DATAITEM::WS_TEXT.

166 {
167  switch( aItem->GetType() )
168  {
170  format( (WORKSHEET_DATAITEM_TEXT*) aItem, aNestLevel );
171  break;
172 
175  format( aItem, aNestLevel );
176  break;
177 
179  format( (WORKSHEET_DATAITEM_POLYPOLYGON*) aItem, aNestLevel );
180  break;
181 
183  format( (WORKSHEET_DATAITEM_BITMAP*) aItem, aNestLevel );
184  break;
185 
186  default:
187  wxFAIL_MSG( wxT( "Cannot format item" ) );
188  }
189 }
void format(WORKSHEET_LAYOUT *aPageLayout) const
WS_ItemType GetType() const
void WORKSHEET_LAYOUT_IO::format ( WORKSHEET_LAYOUT aPageLayout) const
throw (IO_ERROR
)
private
void WORKSHEET_LAYOUT_IO::format ( WORKSHEET_DATAITEM_TEXT aItem,
int  aNestLevel 
) const
throw (IO_ERROR
)
private

Definition at line 232 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, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), 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, and TB_READER_T::T_top.

234 {
235  m_out->Print( aNestLevel, "(%s", getTokenName( T_tbtext ) );
236  m_out->Print( 0, " %s", m_out->Quotew( aItem->m_TextBase ).c_str() );
237  m_out->Print( 0, " (%s %s)", getTokenName( T_name ),
238  m_out->Quotew( aItem->m_Name ).c_str() );
239 
241  formatOptions( aItem );
242 
243  if( aItem->m_Orient )
244  m_out->Print( 0, " (%s %s)", getTokenName( T_rotate ),
245  double2Str(aItem->m_Orient ).c_str() );
246 
247  // Write font info, only if it is not the default setup
248  bool write_size = aItem->m_TextSize.x != 0.0 || aItem->m_TextSize.y != 0.0;
249  bool write_thickness = aItem->m_LineWidth != 0.0;
250 
251  if( write_thickness || write_size || aItem->IsBold() || aItem->IsItalic() )
252  {
253  m_out->Print( 0, " (%s", getTokenName( T_font ) );
254 
255  if( write_thickness )
256  {
257  m_out->Print( 0, " (%s %s)", getTokenName( T_linewidth ),
258  double2Str(aItem->m_LineWidth ).c_str() );
259  }
260 
261  if( write_size )
262  {
263  m_out->Print( 0, " (%s %s %s)", getTokenName( T_size ),
264  double2Str(aItem->m_TextSize.x ).c_str(),
265  double2Str(aItem->m_TextSize.y ).c_str() );
266  }
267  if( aItem->IsBold() )
268  m_out->Print( 0, " %s", getTokenName( T_bold ) );
269 
270  if( aItem->IsItalic() )
271  m_out->Print( 0, " %s", getTokenName( T_italic ) );
272 
273  m_out->Print( 0, ")" );
274  }
275 
276  // Write text justification
277  if( aItem->m_Hjustify != GR_TEXT_HJUSTIFY_LEFT ||
279  {
280  m_out->Print( 0, " (%s", getTokenName( T_justify ) );
281 
282  // Write T_center opt first, because it is
283  // also a center for both m_Hjustify and m_Vjustify
284  if( aItem->m_Hjustify == GR_TEXT_HJUSTIFY_CENTER )
285  m_out->Print( 0, " %s", getTokenName( T_center ) );
286 
287  if( aItem->m_Hjustify == GR_TEXT_HJUSTIFY_RIGHT )
288  m_out->Print( 0, " %s", getTokenName( T_right ) );
289 
290  if( aItem->m_Vjustify == GR_TEXT_VJUSTIFY_TOP )
291  m_out->Print( 0, " %s", getTokenName( T_top ) );
292 
293  if( aItem->m_Vjustify == GR_TEXT_VJUSTIFY_BOTTOM )
294  m_out->Print( 0, " %s", getTokenName( T_bottom ) );
295 
296  m_out->Print( 0, ")" );
297  }
298 
299  // write constraints
300  if( aItem->m_BoundingBoxSize.x )
301  m_out->Print( 0, " (%s %s)", getTokenName( T_maxlen ),
302  double2Str(aItem->m_BoundingBoxSize.x ).c_str() );
303 
304  if( aItem->m_BoundingBoxSize.y )
305  m_out->Print( 0, " (%s %s)", getTokenName( T_maxheight ),
306  double2Str(aItem->m_BoundingBoxSize.y ).c_str() );
307 
308  formatRepeatParameters( aItem );
309 
310  m_out->Print( 0, ")\n" );
311 }
#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
throw (IO_ERROR
)
private

Definition at line 313 of file page_layout_writer.cpp.

References double2Str, getTokenName(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), 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.

315 {
316  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_RECT )
317  m_out->Print( aNestLevel, "(%s", getTokenName( T_rect ) );
318  else
319  m_out->Print( aNestLevel, "(%s", getTokenName( T_line ) );
320 
321  m_out->Print( 0, " (%s %s)", getTokenName( T_name ),
322  m_out->Quotew( aItem->m_Name ).c_str() );
323 
326  formatOptions( aItem );
327 
328  if( aItem->m_LineWidth && aItem->m_LineWidth != aItem->m_DefaultLineWidth )
329  m_out->Print( 0, " (linewidth %s)", double2Str( aItem->m_LineWidth ).c_str() );
330 
331  formatRepeatParameters( aItem );
332 
333  m_out->Print( 0, ")\n" );
334 }
#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
throw (IO_ERROR
)
private

Definition at line 337 of file page_layout_writer.cpp.

References double2Str, getTokenName(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), 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.

339 {
340  m_out->Print( aNestLevel, "(%s", getTokenName( T_polygon ) );
341  m_out->Print( 0, " (%s %s)", getTokenName( T_name ),
342  m_out->Quotew( aItem->m_Name ).c_str() );
344  formatOptions( aItem );
345 
346  formatRepeatParameters( aItem );
347 
348  if( aItem->m_Orient )
349  m_out->Print( 0, " (%s %s)", getTokenName( T_rotate ),
350  double2Str(aItem->m_Orient ).c_str() );
351 
352  if( aItem->m_LineWidth )
353  m_out->Print( 0, " (linewidth %s)\n", double2Str( aItem->m_LineWidth ).c_str() );
354 
355  // Write polygon corners list
356  for( int kk = 0; kk < aItem->GetPolyCount(); kk++ )
357  {
358  m_out->Print( aNestLevel+1, "(%s", getTokenName( T_pts ) );
359  // Create current polygon corners list
360  unsigned ist = aItem->GetPolyIndexStart( kk );
361  unsigned iend = aItem->GetPolyIndexEnd( kk );
362  int ii = 0;
363 
364  while( ist <= iend )
365  {
366  DPOINT pos = aItem->m_Corners[ist++];
367  int nestLevel = 0;
368 
369  if( ii++ > 4)
370  {
371  m_out->Print( 0, "\n" );
372  nestLevel = aNestLevel+2;
373  ii = 0;
374  }
375 
376  m_out->Print( nestLevel, " (%s %s %s)", getTokenName( T_xy ),
377  double2Str( pos.x ).c_str(),
378  double2Str( pos.y ).c_str() );
379  }
380 
381  m_out->Print( 0, ")\n" );
382  }
383 
384  m_out->Print( aNestLevel, ")\n" );
385 }
#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
throw (IO_ERROR
)
private

Definition at line 388 of file page_layout_writer.cpp.

References double2Str, getTokenName(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), 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.

390 {
391  m_out->Print( aNestLevel, "(%s", getTokenName( T_bitmap ) );
392  m_out->Print( 0, " (%s %s)", getTokenName( T_name ),
393  m_out->Quotew( aItem->m_Name ).c_str() );
395  formatOptions( aItem );
396 
397  m_out->Print( 0, " (%s %s)", getTokenName( T_scale ),
398  double2Str( aItem->m_ImageBitmap->GetScale() ).c_str() );
399 
400  formatRepeatParameters( aItem );
401  m_out->Print( 0,"\n");
402 
403  // Write image in png readable format
404  m_out->Print( aNestLevel, "(%s\n", getTokenName( T_pngdata ) );
405  wxArrayString pngStrings;
406  aItem->m_ImageBitmap->SaveData( pngStrings );
407 
408  for( unsigned ii = 0; ii < pngStrings.GetCount(); ii++ )
409  m_out->Print( aNestLevel+1, "(data \"%s\")\n", TO_UTF8(pngStrings[ii]) );
410 
411  m_out->Print( aNestLevel+1, ")\n" );
412 
413  m_out->Print( aNestLevel, ")\n" );
414 }
#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
throw (IO_ERROR
)
private

Definition at line 417 of file page_layout_writer.cpp.

References double2Str, getTokenName(), LB_CORNER, LT_CORNER, OUTPUTFORMATTER::Print(), RB_CORNER, RT_CORNER, TB_READER_T::T_lbcorner, TB_READER_T::T_ltcorner, and TB_READER_T::T_rtcorner.

420 {
421  m_out->Print( 0, " (%s %s %s", aToken,
422  double2Str( aCoord.m_Pos.x ).c_str(),
423  double2Str( aCoord.m_Pos.y ).c_str() );
424 
425  switch( aCoord.m_Anchor )
426  {
427  case RB_CORNER:
428  break;
429 
430  case LT_CORNER:
431  m_out->Print( 0, " %s", getTokenName( T_ltcorner ) );
432  break;
433 
434  case LB_CORNER:
435  m_out->Print( 0, " %s", getTokenName( T_lbcorner ) );
436  break;
437 
438  case RT_CORNER:
439  m_out->Print( 0, " %s", getTokenName( T_rtcorner ) );
440  break;
441  }
442 
443  m_out->Print( 0, ")" );
444 }
#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
throw (IO_ERROR
)
private

Definition at line 467 of file page_layout_writer.cpp.

References getTokenName(), OUTPUTFORMATTER::Print(), TB_READER_T::T_notonpage1, TB_READER_T::T_option, and TB_READER_T::T_page1only.

469 {
470  switch( aItem->GetPage1Option() )
471  {
472  default:
473  case 0:
474  break;
475 
476  case 1:
477  m_out->Print( 0, " (%s %s)", getTokenName( T_option ),
479  break;
480 
481  case -1:
482  m_out->Print( 0, " (%s %s)", getTokenName( T_option ), getTokenName( T_notonpage1 ) );
483  break;
484  }
485 }
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
throw (IO_ERROR
)
private

Definition at line 447 of file page_layout_writer.cpp.

References double2Str, OUTPUTFORMATTER::Print(), and WORKSHEET_DATAITEM::WS_TEXT.

449 {
450  if( aItem->m_RepeatCount <= 1 )
451  return;
452 
453  m_out->Print( 0, " (repeat %d)", aItem->m_RepeatCount );
454 
455  if( aItem->m_IncrementVector.x )
456  m_out->Print( 0, " (incrx %s)", double2Str(aItem-> m_IncrementVector.x ).c_str() );
457 
458  if( aItem->m_IncrementVector.y )
459  m_out->Print( 0, " (incry %s)", double2Str( aItem->m_IncrementVector.y ).c_str() );
460 
461  if( aItem->m_IncrementLabel != 1 &&
463  m_out->Print( 0, " (incrlabel %d)", aItem->m_IncrementLabel );
464 }
#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: