2
* @file title_block_shape.cpp
3
* @brief description of graphic items and texts to build a title block
7
* This program source code file is part of KiCad, a free EDA CAD application.
9
* Copyright (C) 1992-2013 Jean-Pierre Charras <jp.charras at wanadoo.fr>.
10
* Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
13
* This program is free software; you can redistribute it and/or
14
* modify it under the terms of the GNU General Public License
15
* as published by the Free Software Foundation; either version 2
16
* of the License, or (at your option) any later version.
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* You should have received a copy of the GNU General Public License
24
* along with this program; if not, you may find one here:
25
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
26
* or you may search the http://www.gnu.org website for the version 2 license,
27
* or you may write to the Free Software Foundation, Inc.,
28
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
33
* the class WORKSHEET_DATAITEM (and WORKSHEET_DATAITEM_TEXT) defines
34
* a basic shape of a page layout ( frame references and title block )
35
* Basic shapes are line, rect and texts
36
* the WORKSHEET_DATAITEM coordinates units is the mm, and are relative to
37
* one of 4 page corners.
39
* These items cannot be drawn or plot "as this". they should be converted
40
* to a "draw list" (WS_DRAW_ITEM_BASE and derived items)
42
* The list of these items is stored in a WORKSHEET_LAYOUT instance.
44
* When building the draw list:
45
* the WORKSHEET_LAYOUT is used to create a WS_DRAW_ITEM_LIST
46
* coordinates are converted to draw/plot coordinates.
47
* texts are expanded if they contain format symbols.
48
* Items with m_RepeatCount > 1 are created m_RepeatCount times
50
* the WORKSHEET_LAYOUT is created only once.
51
* the WS_DRAW_ITEM_LIST is created each time the page layout is plot/drawn
53
* the WORKSHEET_LAYOUT instance is created from a S expression which
54
* describes the page layout (can be the default page layout or a custom file).
59
#include <worksheet.h>
60
#include <class_title_block.h>
61
#include <worksheet_shape_builder.h>
62
#include <class_worksheet_dataitem.h>
65
// Temporary include. Will be removed when a GOST page layout descr file is available
67
#include "title_block_shapes_gost.cpp"
70
void WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(
71
const PAGE_INFO& aPageInfo,
72
const TITLE_BLOCK& aTitleBlock,
73
EDA_COLOR_T aColor, EDA_COLOR_T aAltColor )
75
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
77
// Ugly hack: will be removed when a GOST page layout descr file is available
79
if( pglayout.IsDefaultDescr() )
81
((WS_DRAW_ITEM_LIST_GOST*)this)->BuildWorkSheetGraphicListGOST( aPageInfo,
82
aTitleBlock, aColor, aAltColor );
87
#define milsTomm (25.4/1000)
89
m_titleBlock = &aTitleBlock;
90
m_paperFormat = &aPageInfo.GetType();
92
wxPoint LTmargin( Mm2mils( pglayout.GetLeftMargin() ),
93
Mm2mils( pglayout.GetTopMargin() ) );
94
wxPoint RBmargin( Mm2mils( pglayout.GetRightMargin() ),
95
Mm2mils( pglayout.GetBottomMargin() ) );
97
SetMargins( LTmargin, RBmargin );
98
SetPageSize( aPageInfo.GetSizeMils() );
100
// Build the basic layout shape, if the layout list is empty
101
if( pglayout.GetCount() == 0 && !pglayout.VoidListAllowed() )
102
pglayout.SetPageLayout();
104
WORKSHEET_DATAITEM::m_WSunits2Iu = m_milsToIu / milsTomm;
105
WORKSHEET_DATAITEM::m_Color = aColor; // the default color to draw items
106
WORKSHEET_DATAITEM::m_AltColor = aAltColor; // an alternate color to draw items
108
// Left top corner position
110
lt_corner.x = pglayout.GetLeftMargin();
111
lt_corner.y = pglayout.GetTopMargin();
112
WORKSHEET_DATAITEM::m_LT_Corner = lt_corner;
114
// Right bottom corner position
116
rb_corner.x = (m_pageSize.x*milsTomm) - pglayout.GetRightMargin();
117
rb_corner.y = (m_pageSize.y*milsTomm) - pglayout.GetBottomMargin();
118
WORKSHEET_DATAITEM::m_RB_Corner = rb_corner;
120
WS_DRAW_ITEM_TEXT* gtext;
123
for( unsigned ii = 0; ; ii++ )
125
WORKSHEET_DATAITEM* wsItem = pglayout.GetItem( ii );
130
// Generate it only if the page option allows this
131
if( wsItem->GetPage1Option() < 0 // Not on page 1
132
&& m_sheetNumber <= 1 )
135
if( wsItem->GetPage1Option() > 0 // Only on page 1
136
&& m_sheetNumber > 1 )
139
EDA_COLOR_T color = wsItem->GetItemColor();
141
pensize = wsItem->GetPenSizeUi();
143
switch( wsItem->GetType() )
145
case WORKSHEET_DATAITEM::WS_TEXT:
147
WORKSHEET_DATAITEM_TEXT * wsText = (WORKSHEET_DATAITEM_TEXT*)wsItem;
148
bool multilines = false;
150
if( wsText->m_SpecialMode )
151
wsText->m_FullText = wsText->m_TextBase;
154
wsText->m_FullText = BuildFullText( wsText->m_TextBase );
155
if( wsText->m_FullText.Replace( wxT("\\n" ), wxT("\n") ) > 0 )
159
if( wsText->m_FullText.IsEmpty() )
165
wsText->SetConstrainedTextSize();
168
textsize.x = KiROUND( wsText->m_ConstrainedTextSize.x
169
* WORKSHEET_DATAITEM::m_WSunits2Iu );
170
textsize.y = KiROUND( wsText->m_ConstrainedTextSize.y
171
* WORKSHEET_DATAITEM::m_WSunits2Iu );
173
if( wsText->IsBold())
174
pensize = GetPenSizeForBold( std::min( textsize.x, textsize.y ) );
176
for( int jj = 0; jj < wsText->m_RepeatCount; jj++)
178
if( jj && ! wsText->IsInsidePage( jj ) )
181
Append( gtext = new WS_DRAW_ITEM_TEXT( wsText, wsText->m_FullText,
182
wsText->GetStartPosUi( jj ),
186
wsText->IsBold() ) );
187
gtext->SetMultilineAllowed( multilines );
188
wsText->TransfertSetupToGraphicText( gtext );
190
// Increment label for the next text
191
// (has no meaning for multiline texts)
192
if( wsText->m_RepeatCount > 1 && !multilines )
193
wsText->IncrementLabel( (jj+1)*wsText->m_IncrementLabel);
198
case WORKSHEET_DATAITEM::WS_SEGMENT:
202
for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
204
if( jj && ! wsItem->IsInsidePage( jj ) )
206
Append( new WS_DRAW_ITEM_LINE( wsItem, wsItem->GetStartPosUi( jj ),
207
wsItem->GetEndPosUi( jj ),
212
case WORKSHEET_DATAITEM::WS_RECT:
216
for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
218
if( jj && ! wsItem->IsInsidePage( jj ) )
221
Append( new WS_DRAW_ITEM_RECT( wsItem, wsItem->GetStartPosUi( jj ),
222
wsItem->GetEndPosUi( jj ),
227
case WORKSHEET_DATAITEM::WS_POLYPOLYGON:
229
WORKSHEET_DATAITEM_POLYPOLYGON * wspoly =
230
(WORKSHEET_DATAITEM_POLYPOLYGON*) wsItem;
231
for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
233
if( jj && ! wsItem->IsInsidePage( jj ) )
236
for( int kk = 0; kk < wspoly->GetPolyCount(); kk++ )
238
const bool fill = true;
239
WS_DRAW_ITEM_POLYGON* poly = new WS_DRAW_ITEM_POLYGON( wspoly,
240
wspoly->GetStartPosUi( jj ),
241
fill, pensize, color );
244
// Create polygon outline
245
unsigned ist = wspoly->GetPolyIndexStart( kk );
246
unsigned iend = wspoly->GetPolyIndexEnd( kk );
248
poly->m_Corners.push_back(
249
wspoly->GetCornerPositionUi( ist++, jj ) );