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

« back to all changes in this revision

Viewing changes to pagelayout_editor/properties_frame.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
 * This program source code file is part of KiCad, a free EDA CAD application.
 
3
 *
 
4
 * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
 
5
 * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU General Public License
 
9
 * as published by the Free Software Foundation; either version 2
 
10
 * of the License, or (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, you may find one here:
 
19
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 
20
 * or you may search the http://www.gnu.org website for the version 2 license,
 
21
 * or you may write to the Free Software Foundation, Inc.,
 
22
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
23
 */
 
24
 
 
25
/**
 
26
 * @file properties_frame.cpp
 
27
 */
 
28
 
 
29
#include <fctsys.h>
 
30
#include <wxstruct.h>
 
31
#include <class_drawpanel.h>
 
32
#include <worksheet_shape_builder.h>
 
33
#include <class_worksheet_dataitem.h>
 
34
#include <properties_frame.h>
 
35
 
 
36
PROPERTIES_FRAME::PROPERTIES_FRAME( PL_EDITOR_FRAME* aParent ):
 
37
    PANEL_PROPERTIES_BASE( aParent )
 
38
{
 
39
    m_parent = aParent;
 
40
}
 
41
 
 
42
 
 
43
PROPERTIES_FRAME::~PROPERTIES_FRAME()
 
44
{
 
45
}
 
46
 
 
47
wxSize PROPERTIES_FRAME::GetMinSize() const
 
48
{
 
49
    return wxSize( 150, -1 );
 
50
}
 
51
 
 
52
 
 
53
// Data transfert from general properties to widgets
 
54
void PROPERTIES_FRAME::CopyPrmsFromGeneralToPanel()
 
55
{
 
56
    wxString msg;
 
57
 
 
58
    // Set default parameters
 
59
    msg.Printf( wxT("%.3f"),  WORKSHEET_DATAITEM::m_DefaultLineWidth );
 
60
    m_textCtrlDefaultLineWidth->SetValue( msg );
 
61
 
 
62
    msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultTextSize.x );
 
63
    m_textCtrlDefaultTextSizeX->SetValue( msg );
 
64
    msg.Printf( wxT("%.3f"),  WORKSHEET_DATAITEM::m_DefaultTextSize.y );
 
65
    m_textCtrlDefaultTextSizeY->SetValue( msg );
 
66
 
 
67
    msg.Printf( wxT("%.3f"),  WORKSHEET_DATAITEM::m_DefaultTextThickness );
 
68
    m_textCtrlDefaultTextThickness->SetValue( msg );
 
69
 
 
70
    // Set page margins values
 
71
    WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
 
72
    msg.Printf( wxT("%.3f"),  pglayout.GetRightMargin() );
 
73
    m_textCtrlRightMargin->SetValue( msg );
 
74
    msg.Printf( wxT("%.3f"),  pglayout.GetBottomMargin() );
 
75
    m_textCtrlDefaultBottomMargin->SetValue( msg );
 
76
 
 
77
    msg.Printf( wxT("%.3f"),  pglayout.GetLeftMargin() );
 
78
    m_textCtrlLeftMargin->SetValue( msg );
 
79
    msg.Printf( wxT("%.3f"),  pglayout.GetTopMargin() );
 
80
    m_textCtrlTopMargin->SetValue( msg );
 
81
}
 
82
 
 
83
// Data transfert from widgets to general properties
 
84
bool PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral()
 
85
{
 
86
    double dtmp;
 
87
    wxString msg;
 
88
 
 
89
    // Import default parameters from widgets
 
90
    msg = m_textCtrlDefaultLineWidth->GetValue();
 
91
    msg.ToDouble( &dtmp );
 
92
    WORKSHEET_DATAITEM::m_DefaultLineWidth = dtmp;
 
93
 
 
94
    msg = m_textCtrlDefaultTextSizeX->GetValue();
 
95
    msg.ToDouble( &dtmp );
 
96
    WORKSHEET_DATAITEM::m_DefaultTextSize.x  = dtmp;
 
97
    msg = m_textCtrlDefaultTextSizeY->GetValue();
 
98
    msg.ToDouble( &dtmp );
 
99
    WORKSHEET_DATAITEM::m_DefaultTextSize.y  = dtmp;
 
100
 
 
101
    msg = m_textCtrlDefaultTextThickness->GetValue();
 
102
    msg.ToDouble( &dtmp );
 
103
    WORKSHEET_DATAITEM::m_DefaultTextThickness = dtmp;
 
104
 
 
105
    // Get page margins values
 
106
    WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
 
107
 
 
108
    msg = m_textCtrlRightMargin->GetValue();
 
109
    msg.ToDouble( &dtmp );
 
110
    pglayout.SetRightMargin( dtmp );
 
111
    msg = m_textCtrlDefaultBottomMargin->GetValue();
 
112
    msg.ToDouble( &dtmp );
 
113
    pglayout.SetBottomMargin( dtmp );
 
114
 
 
115
    // cordinates of the left top corner are the left and top margins
 
116
    msg = m_textCtrlLeftMargin->GetValue();
 
117
    msg.ToDouble( &dtmp );
 
118
    pglayout.SetLeftMargin( dtmp );
 
119
    msg = m_textCtrlTopMargin->GetValue();
 
120
    msg.ToDouble( &dtmp );
 
121
    pglayout.SetTopMargin( dtmp );
 
122
 
 
123
    return true;
 
124
}
 
125
 
 
126
// Data transfert from item to widgets in properties frame
 
127
void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem )
 
128
{
 
129
    wxString msg;
 
130
 
 
131
    // Set parameters common to all WORKSHEET_DATAITEM types
 
132
    m_textCtrlType->SetValue( aItem->GetClassName() );
 
133
    m_textCtrlComment->SetValue( aItem->m_Info );
 
134
 
 
135
    switch( aItem->GetPage1Option() )
 
136
    {
 
137
       default:
 
138
        case 0:
 
139
            m_choicePageOpt->SetSelection( 0 );
 
140
            break;
 
141
 
 
142
        case 1:
 
143
            m_choicePageOpt->SetSelection( 1 );
 
144
            break;
 
145
 
 
146
        case -1:
 
147
            m_choicePageOpt->SetSelection( 2 );
 
148
            break;
 
149
    }
 
150
 
 
151
    // Position/ start point
 
152
    msg.Printf( wxT("%.3f"), aItem->m_Pos.m_Pos.x );
 
153
    m_textCtrlPosX->SetValue( msg );
 
154
    msg.Printf( wxT("%.3f"), aItem->m_Pos.m_Pos.y );
 
155
    m_textCtrlPosY->SetValue( msg );
 
156
    switch(  aItem->m_Pos.m_Anchor )
 
157
    {
 
158
        case RB_CORNER:      // right bottom corner
 
159
            m_comboBoxCornerPos->SetSelection( 2 ); break;
 
160
        case RT_CORNER:      // right top corner
 
161
            m_comboBoxCornerPos->SetSelection( 0 ); break;
 
162
        case LB_CORNER:      // left bottom corner
 
163
            m_comboBoxCornerPos->SetSelection( 3 ); break;
 
164
        case LT_CORNER:      // left top corner
 
165
            m_comboBoxCornerPos->SetSelection( 1 ); break;
 
166
    }
 
167
 
 
168
    // End point
 
169
    msg.Printf( wxT("%.3f"), aItem->m_End.m_Pos.x );
 
170
    m_textCtrlEndX->SetValue( msg );
 
171
    msg.Printf( wxT("%.3f"), aItem->m_End.m_Pos.y );
 
172
    m_textCtrlEndY->SetValue( msg );
 
173
    switch( aItem->m_End.m_Anchor )
 
174
    {
 
175
        case RB_CORNER:      // right bottom corner
 
176
            m_comboBoxCornerEnd->SetSelection( 2 ); break;
 
177
        case RT_CORNER:      // right top corner
 
178
            m_comboBoxCornerEnd->SetSelection( 0 ); break;
 
179
        case LB_CORNER:      // left bottom corner
 
180
            m_comboBoxCornerEnd->SetSelection( 3 ); break;
 
181
        case LT_CORNER:      // left top corner
 
182
            m_comboBoxCornerEnd->SetSelection( 1 ); break;
 
183
    }
 
184
 
 
185
    msg.Printf( wxT("%.3f"), aItem->m_LineWidth );
 
186
    m_textCtrlThickness->SetValue( msg );
 
187
 
 
188
    // Now, set prms more specific to WORKSHEET_DATAITEM types
 
189
    // For a given type, disable widgets which are not relevant,
 
190
    // and be sure widgets which are relevant are enabled
 
191
    if( aItem->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
 
192
    {
 
193
        m_SizerTextOptions->Show(true);
 
194
        m_SizerTextIncrementLabel->Show( true );
 
195
 
 
196
        WORKSHEET_DATAITEM_TEXT* item = (WORKSHEET_DATAITEM_TEXT*) aItem;
 
197
        wxString text = item->m_TextBase;
 
198
        text.Replace(wxT("\\n"), wxT("\n") );
 
199
        m_textCtrlText->SetValue( text );
 
200
 
 
201
        msg.Printf( wxT("%d"), item->m_IncrementLabel );
 
202
        m_textCtrlTextIncrement->SetValue( msg );
 
203
 
 
204
        // Rotation (poly and text)
 
205
        msg.Printf( wxT("%.3f"), item->m_Orient );
 
206
        m_textCtrlRotation->SetValue( msg );
 
207
 
 
208
        // Constraints:
 
209
        msg.Printf( wxT("%.3f"), item->m_BoundingBoxSize.x );
 
210
        m_textCtrlConstraintX->SetValue( msg );
 
211
        msg.Printf( wxT("%.3f"), item->m_BoundingBoxSize.y );
 
212
        m_textCtrlConstraintY->SetValue( msg );
 
213
 
 
214
        // Font Options
 
215
                m_checkBoxBold->SetValue( item->IsBold() );
 
216
                m_checkBoxItalic->SetValue( item->IsItalic() );
 
217
        switch( item->m_Hjustify )
 
218
        {
 
219
            case GR_TEXT_HJUSTIFY_LEFT: m_choiceHjustify->SetSelection( 0 ); break;
 
220
            case GR_TEXT_HJUSTIFY_CENTER: m_choiceHjustify->SetSelection( 1 ); break;
 
221
            case GR_TEXT_HJUSTIFY_RIGHT: m_choiceHjustify->SetSelection( 2 ); break;
 
222
        }
 
223
        switch( item->m_Vjustify )
 
224
        {
 
225
            case GR_TEXT_VJUSTIFY_TOP: m_choiceVjustify->SetSelection( 0 ); break;
 
226
            case GR_TEXT_VJUSTIFY_CENTER: m_choiceVjustify->SetSelection( 1 ); break;
 
227
            case GR_TEXT_VJUSTIFY_BOTTOM: m_choiceVjustify->SetSelection( 2 ); break;
 
228
        }
 
229
 
 
230
        // Text size
 
231
        msg.Printf( wxT("%.3f"), item->m_TextSize.x );
 
232
        m_textCtrlTextSizeX->SetValue( msg );
 
233
        msg.Printf( wxT("%.3f"), item->m_TextSize.y );
 
234
        m_textCtrlTextSizeY->SetValue( msg );
 
235
    }
 
236
    else
 
237
    {
 
238
        m_SizerTextOptions->Show(false);
 
239
        m_SizerTextIncrementLabel->Show(false);
 
240
    }
 
241
 
 
242
    if( aItem->GetType() == WORKSHEET_DATAITEM::WS_POLYPOLYGON )
 
243
    {
 
244
        m_staticTextInfoThickness->Show( false );
 
245
 
 
246
        WORKSHEET_DATAITEM_POLYPOLYGON* item = (WORKSHEET_DATAITEM_POLYPOLYGON*) aItem;
 
247
        // Rotation (poly and text)
 
248
        msg.Printf( wxT("%.3f"), item->m_Orient );
 
249
        m_textCtrlRotation->SetValue( msg );
 
250
    }
 
251
    else
 
252
    {
 
253
        m_staticTextInfoThickness->Show( true );
 
254
    }
 
255
 
 
256
    if( aItem->GetType() == WORKSHEET_DATAITEM::WS_SEGMENT ||
 
257
        aItem->GetType() == WORKSHEET_DATAITEM::WS_RECT )
 
258
    {
 
259
        m_SizerRotation->Show( false );
 
260
        m_SizerEndPosition->Show(true);
 
261
    }
 
262
    else
 
263
    {
 
264
        m_SizerRotation->Show( true );
 
265
        m_SizerEndPosition->Show(false);
 
266
    }
 
267
 
 
268
    // Repeat parameters
 
269
    msg.Printf( wxT("%d"), aItem->m_RepeatCount );
 
270
    m_textCtrlRepeatCount->SetValue( msg );
 
271
    msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.x );
 
272
    m_textCtrlStepX->SetValue( msg );
 
273
    msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.y );
 
274
    m_textCtrlStepY->SetValue( msg );
 
275
 
 
276
    // The number of widgets was modified
 
277
    m_swItemProperties->Layout();
 
278
    m_swItemProperties->Refresh();
 
279
}
 
280
 
 
281
// Event function called by clicking on the OK button
 
282
void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event )
 
283
{
 
284
    m_parent->SaveCopyInUndoList();
 
285
 
 
286
    WORKSHEET_DATAITEM* item = m_parent->GetSelectedItem();
 
287
    if( item )
 
288
        CopyPrmsFromPanelToItem( item );
 
289
 
 
290
    CopyPrmsFromPanelToGeneral();
 
291
 
 
292
    m_parent->OnModify();
 
293
    m_parent->GetCanvas()->Refresh();
 
294
}
 
295
 
 
296
void PROPERTIES_FRAME::OnSetDefaultValues( wxCommandEvent& event )
 
297
{
 
298
    WORKSHEET_DATAITEM::m_DefaultTextSize =
 
299
            DSIZE( TB_DEFAULT_TEXTSIZE, TB_DEFAULT_TEXTSIZE );
 
300
    // default thickness in mm
 
301
    WORKSHEET_DATAITEM::m_DefaultLineWidth = 0.15;
 
302
    WORKSHEET_DATAITEM::m_DefaultTextThickness = 0.15;
 
303
 
 
304
    CopyPrmsFromGeneralToPanel();
 
305
    m_parent->GetCanvas()->Refresh();
 
306
}
 
307
 
 
308
 
 
309
// Data transfert from  properties frame to item parameters
 
310
bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WORKSHEET_DATAITEM* aItem )
 
311
{
 
312
    if( aItem == NULL )
 
313
        return false;
 
314
 
 
315
    double dtmp;
 
316
    wxString msg;
 
317
 
 
318
    // Import common parameters:
 
319
    aItem->m_Info = m_textCtrlComment->GetValue();
 
320
 
 
321
    switch( m_choicePageOpt->GetSelection() )
 
322
    {
 
323
        default:
 
324
        case 0:
 
325
            aItem->SetPage1Option( 0 );
 
326
            break;
 
327
 
 
328
        case 1:
 
329
            aItem->SetPage1Option( 1 );
 
330
            break;
 
331
 
 
332
        case 2:
 
333
            aItem->SetPage1Option( -1 );
 
334
            break;
 
335
    }
 
336
 
 
337
    // Import thickness
 
338
    msg = m_textCtrlThickness->GetValue();
 
339
    msg.ToDouble( &dtmp );
 
340
    aItem->m_LineWidth = dtmp;
 
341
 
 
342
    // Import Start point
 
343
    msg = m_textCtrlPosX->GetValue();
 
344
    msg.ToDouble( &dtmp );
 
345
    aItem->m_Pos.m_Pos.x = dtmp;
 
346
 
 
347
    msg = m_textCtrlPosY->GetValue();
 
348
    msg.ToDouble( &dtmp );
 
349
    aItem->m_Pos.m_Pos.y = dtmp;
 
350
 
 
351
    switch( m_comboBoxCornerPos->GetSelection() )
 
352
    {
 
353
        case 2: aItem->m_Pos.m_Anchor = RB_CORNER; break;
 
354
        case 0: aItem->m_Pos.m_Anchor = RT_CORNER; break;
 
355
        case 3: aItem->m_Pos.m_Anchor = LB_CORNER; break;
 
356
        case 1: aItem->m_Pos.m_Anchor = LT_CORNER; break;
 
357
    }
 
358
 
 
359
    // Import End point
 
360
    msg = m_textCtrlEndX->GetValue();
 
361
    msg.ToDouble( &dtmp );
 
362
    aItem->m_End.m_Pos.x = dtmp;
 
363
 
 
364
    msg = m_textCtrlEndY->GetValue();
 
365
    msg.ToDouble( &dtmp );
 
366
    aItem->m_End.m_Pos.y = dtmp;
 
367
 
 
368
    switch( m_comboBoxCornerEnd->GetSelection() )
 
369
    {
 
370
        case 2: aItem->m_End.m_Anchor = RB_CORNER; break;
 
371
        case 0: aItem->m_End.m_Anchor = RT_CORNER; break;
 
372
        case 3: aItem->m_End.m_Anchor = LB_CORNER; break;
 
373
        case 1: aItem->m_End.m_Anchor = LT_CORNER; break;
 
374
    }
 
375
 
 
376
    // Import Repeat prms
 
377
    long itmp;
 
378
    msg = m_textCtrlRepeatCount->GetValue();
 
379
    msg.ToLong( &itmp );
 
380
    aItem->m_RepeatCount = itmp;
 
381
 
 
382
    msg = m_textCtrlStepX->GetValue();
 
383
    msg.ToDouble( &dtmp );
 
384
    aItem->m_IncrementVector.x = dtmp;
 
385
 
 
386
    msg = m_textCtrlStepY->GetValue();
 
387
    msg.ToDouble( &dtmp );
 
388
    aItem->m_IncrementVector.y = dtmp;
 
389
 
 
390
    if( aItem->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
 
391
    {
 
392
        WORKSHEET_DATAITEM_TEXT* item = (WORKSHEET_DATAITEM_TEXT*) aItem;
 
393
 
 
394
        item->m_TextBase = m_textCtrlText->GetValue();
 
395
        item->m_TextBase.Replace( wxT("\n"), wxT("\\n") );
 
396
 
 
397
        msg = m_textCtrlTextIncrement->GetValue();
 
398
        msg.ToLong( &itmp );
 
399
        item->m_IncrementLabel = itmp;
 
400
 
 
401
        item->SetBold( m_checkBoxBold->IsChecked() );
 
402
        item->SetItalic( m_checkBoxItalic->IsChecked() );
 
403
 
 
404
        switch( m_choiceHjustify->GetSelection() )
 
405
        {
 
406
            case 0: item->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT; break;
 
407
            case 1: item->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER; break;
 
408
            case 2: item->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT; break;
 
409
        }
 
410
        switch( m_choiceVjustify->GetSelection() )
 
411
        {
 
412
            case 0: item->m_Vjustify = GR_TEXT_VJUSTIFY_TOP; break;
 
413
            case 1: item->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER; break;
 
414
            case 2: item->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; break;
 
415
        }
 
416
 
 
417
        msg = m_textCtrlRotation->GetValue();
 
418
        msg.ToDouble( &dtmp );
 
419
        item->m_Orient = dtmp;
 
420
 
 
421
        // Import text size
 
422
        msg = m_textCtrlTextSizeX->GetValue();
 
423
        msg.ToDouble( &dtmp );
 
424
        item->m_TextSize.x = dtmp;
 
425
 
 
426
        msg = m_textCtrlTextSizeY->GetValue();
 
427
        msg.ToDouble( &dtmp );
 
428
        item->m_TextSize.y = dtmp;
 
429
 
 
430
        // Import constraints:
 
431
        msg = m_textCtrlConstraintX->GetValue();
 
432
        msg.ToDouble( &dtmp );
 
433
        item->m_BoundingBoxSize.x = dtmp;
 
434
 
 
435
        msg = m_textCtrlConstraintY->GetValue();
 
436
        msg.ToDouble( &dtmp );
 
437
        item->m_BoundingBoxSize.y = dtmp;
 
438
    }
 
439
 
 
440
    if( aItem->GetType() == WORKSHEET_DATAITEM::WS_POLYPOLYGON )
 
441
    {
 
442
        WORKSHEET_DATAITEM_POLYPOLYGON* item = (WORKSHEET_DATAITEM_POLYPOLYGON*) aItem;
 
443
 
 
444
        msg = m_textCtrlRotation->GetValue();
 
445
        msg.ToDouble( &dtmp );
 
446
        item->m_Orient = dtmp;
 
447
    }
 
448
 
 
449
    return true;
 
450
}
 
451