~cern-kicad/kicad/kicad-pns-tom

« back to all changes in this revision

Viewing changes to common/page_layout/title_block_shapes.cpp

  • Committer: Maciej Suminski
  • Date: 2013-08-02 13:57:24 UTC
  • mfrom: (4024.1.238 kicad)
  • mto: This revision was merged to the branch mainline in revision 4221.
  • Revision ID: maciej.suminski@cern.ch-20130802135724-gix6orezshkukodv
Upstream merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file title_block_shape.cpp
 
3
 * @brief description of graphic items and texts to build a title block
 
4
 */
 
5
 
 
6
/*
 
7
 * This program source code file is part of KiCad, a free EDA CAD application.
 
8
 *
 
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.
 
11
 *
 
12
 *
 
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.
 
17
 *
 
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.
 
22
 *
 
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
 
29
 */
 
30
 
 
31
 
 
32
/*
 
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.
 
38
 *
 
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)
 
41
 
 
42
 * The list of these items is stored in a WORKSHEET_LAYOUT instance.
 
43
 *
 
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
 
49
 *
 
50
 * the WORKSHEET_LAYOUT is created only once.
 
51
 * the WS_DRAW_ITEM_LIST is created each time the page layout is plot/drawn
 
52
 *
 
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).
 
55
 */
 
56
 
 
57
#include <fctsys.h>
 
58
#include <drawtxt.h>
 
59
#include <worksheet.h>
 
60
#include <class_title_block.h>
 
61
#include <worksheet_shape_builder.h>
 
62
#include <class_worksheet_dataitem.h>
 
63
 
 
64
 
 
65
// Temporary include. Will be removed when a GOST page layout descr file is available
 
66
#ifdef KICAD_GOST
 
67
#include "title_block_shapes_gost.cpp"
 
68
#endif
 
69
 
 
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 )
 
74
{
 
75
    WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
 
76
 
 
77
// Ugly hack: will be removed when a GOST page layout descr file is available
 
78
#ifdef KICAD_GOST
 
79
    if( pglayout.IsDefaultDescr() )
 
80
    {
 
81
        ((WS_DRAW_ITEM_LIST_GOST*)this)->BuildWorkSheetGraphicListGOST( aPageInfo,
 
82
                aTitleBlock, aColor, aAltColor );
 
83
        return;
 
84
    }
 
85
#endif
 
86
 
 
87
    #define milsTomm (25.4/1000)
 
88
 
 
89
    m_titleBlock = &aTitleBlock;
 
90
    m_paperFormat = &aPageInfo.GetType();
 
91
 
 
92
    wxPoint LTmargin( Mm2mils( pglayout.GetLeftMargin() ),
 
93
                      Mm2mils( pglayout.GetTopMargin() ) );
 
94
    wxPoint RBmargin( Mm2mils( pglayout.GetRightMargin() ),
 
95
                      Mm2mils( pglayout.GetBottomMargin() ) );
 
96
 
 
97
    SetMargins( LTmargin, RBmargin );
 
98
    SetPageSize( aPageInfo.GetSizeMils() );
 
99
 
 
100
    // Build the basic layout shape, if the layout list is empty
 
101
    if( pglayout.GetCount() == 0 && !pglayout.VoidListAllowed() )
 
102
        pglayout.SetPageLayout();
 
103
 
 
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
 
107
 
 
108
    // Left top corner position
 
109
    DPOINT lt_corner;
 
110
    lt_corner.x = pglayout.GetLeftMargin();
 
111
    lt_corner.y = pglayout.GetTopMargin();
 
112
    WORKSHEET_DATAITEM::m_LT_Corner = lt_corner;
 
113
 
 
114
    // Right bottom corner position
 
115
    DPOINT rb_corner;
 
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;
 
119
 
 
120
    WS_DRAW_ITEM_TEXT* gtext;
 
121
    int pensize;
 
122
 
 
123
    for( unsigned ii = 0; ; ii++ )
 
124
    {
 
125
        WORKSHEET_DATAITEM*  wsItem = pglayout.GetItem( ii );
 
126
 
 
127
        if( wsItem == NULL )
 
128
            break;
 
129
 
 
130
        // Generate it only if the page option allows this
 
131
        if( wsItem->GetPage1Option() < 0    // Not on page 1
 
132
            && m_sheetNumber <= 1 )
 
133
            continue;
 
134
 
 
135
        if( wsItem->GetPage1Option() > 0    // Only on page 1
 
136
            && m_sheetNumber > 1 )
 
137
            continue;
 
138
 
 
139
        EDA_COLOR_T color = wsItem->GetItemColor();
 
140
 
 
141
        pensize = wsItem->GetPenSizeUi();
 
142
 
 
143
        switch( wsItem->GetType() )
 
144
        {
 
145
        case WORKSHEET_DATAITEM::WS_TEXT:
 
146
        {
 
147
            WORKSHEET_DATAITEM_TEXT * wsText = (WORKSHEET_DATAITEM_TEXT*)wsItem;
 
148
            bool multilines = false;
 
149
 
 
150
            if( wsText->m_SpecialMode )
 
151
                wsText->m_FullText = wsText->m_TextBase;
 
152
            else
 
153
            {
 
154
                wsText->m_FullText = BuildFullText( wsText->m_TextBase );
 
155
                if( wsText->m_FullText.Replace( wxT("\\n" ), wxT("\n") ) > 0 )
 
156
                    multilines = true;
 
157
            }
 
158
 
 
159
            if( wsText->m_FullText.IsEmpty() )
 
160
                break;
 
161
 
 
162
            if( pensize == 0 )
 
163
                pensize = m_penSize;
 
164
 
 
165
            wsText->SetConstrainedTextSize();
 
166
            wxSize textsize;
 
167
 
 
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 );
 
172
 
 
173
            if( wsText->IsBold())
 
174
                pensize = GetPenSizeForBold( std::min( textsize.x, textsize.y ) );
 
175
 
 
176
            for( int jj = 0; jj < wsText->m_RepeatCount; jj++)
 
177
            {
 
178
                if( jj && ! wsText->IsInsidePage( jj ) )
 
179
                    continue;
 
180
 
 
181
                Append( gtext = new WS_DRAW_ITEM_TEXT( wsText, wsText->m_FullText,
 
182
                                                       wsText->GetStartPosUi( jj ),
 
183
                                                       textsize,
 
184
                                                       pensize, color,
 
185
                                                       wsText->IsItalic(),
 
186
                                                       wsText->IsBold() ) );
 
187
                gtext->SetMultilineAllowed( multilines );
 
188
                wsText->TransfertSetupToGraphicText( gtext );
 
189
 
 
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);
 
194
            }
 
195
        }
 
196
            break;
 
197
 
 
198
        case WORKSHEET_DATAITEM::WS_SEGMENT:
 
199
            if( pensize == 0 )
 
200
                pensize = m_penSize;
 
201
 
 
202
            for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
 
203
            {
 
204
                if( jj && ! wsItem->IsInsidePage( jj ) )
 
205
                    continue;
 
206
                Append( new WS_DRAW_ITEM_LINE( wsItem, wsItem->GetStartPosUi( jj ),
 
207
                                               wsItem->GetEndPosUi( jj ),
 
208
                                               pensize, color ) );
 
209
            }
 
210
            break;
 
211
 
 
212
        case WORKSHEET_DATAITEM::WS_RECT:
 
213
            if( pensize == 0 )
 
214
                pensize = m_penSize;
 
215
 
 
216
            for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
 
217
            {
 
218
                if( jj && ! wsItem->IsInsidePage( jj ) )
 
219
                    break;
 
220
 
 
221
                Append( new WS_DRAW_ITEM_RECT( wsItem, wsItem->GetStartPosUi( jj ),
 
222
                                               wsItem->GetEndPosUi( jj ),
 
223
                                               pensize, color ) );
 
224
            }
 
225
            break;
 
226
 
 
227
        case WORKSHEET_DATAITEM::WS_POLYPOLYGON:
 
228
        {
 
229
            WORKSHEET_DATAITEM_POLYPOLYGON * wspoly =
 
230
                (WORKSHEET_DATAITEM_POLYPOLYGON*) wsItem;
 
231
            for( int jj = 0; jj < wsItem->m_RepeatCount; jj++ )
 
232
            {
 
233
                if( jj && ! wsItem->IsInsidePage( jj ) )
 
234
                    continue;
 
235
 
 
236
                for( int kk = 0; kk < wspoly->GetPolyCount(); kk++ )
 
237
                {
 
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 );
 
242
                    Append( poly );
 
243
 
 
244
                    // Create polygon outline
 
245
                    unsigned ist = wspoly->GetPolyIndexStart( kk );
 
246
                    unsigned iend = wspoly->GetPolyIndexEnd( kk );
 
247
                    while( ist <= iend )
 
248
                        poly->m_Corners.push_back(
 
249
                            wspoly->GetCornerPositionUi( ist++, jj ) );
 
250
 
 
251
                }
 
252
            }
 
253
        }
 
254
            break;
 
255
        }
 
256
    }
 
257
}
 
258