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

« back to all changes in this revision

Viewing changes to pagelayout_editor/dialogs/dialog_new_dataitem.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) 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 dialog_new_dataitem.cpp
 
27
 * @brief a dialog called on creating a new plage layout data item.
 
28
*/
 
29
 
 
30
#include <fctsys.h>
 
31
#include <common.h>
 
32
#include <class_drawpanel.h>
 
33
 
 
34
#include <pl_editor_frame.h>
 
35
#include <class_worksheet_dataitem.h>
 
36
#include <dialog_new_dataitem_base.h>
 
37
 
 
38
class DIALOG_NEW_DATAITEM : public DIALOG_NEW_DATAITEM_BASE
 
39
{
 
40
    WORKSHEET_DATAITEM* m_item;
 
41
 
 
42
public:
 
43
    DIALOG_NEW_DATAITEM( PL_EDITOR_FRAME* aCaller, WORKSHEET_DATAITEM* aItem );
 
44
 
 
45
private:
 
46
        void OnCancelClick( wxCommandEvent& event );
 
47
        void OnOKClick( wxCommandEvent& event );
 
48
 
 
49
    void initDlg();
 
50
};
 
51
 
 
52
 
 
53
int InvokeDialogNewItem( PL_EDITOR_FRAME* aCaller, WORKSHEET_DATAITEM* aItem )
 
54
{
 
55
    DIALOG_NEW_DATAITEM dlg( aCaller, aItem );
 
56
    return dlg.ShowModal();
 
57
}
 
58
 
 
59
DIALOG_NEW_DATAITEM::DIALOG_NEW_DATAITEM( PL_EDITOR_FRAME* aCaller,
 
60
                                          WORKSHEET_DATAITEM* aItem )
 
61
    : DIALOG_NEW_DATAITEM_BASE( aCaller )
 
62
{
 
63
    m_item = aItem;
 
64
    initDlg();
 
65
 
 
66
    GetSizer()->SetSizeHints( this );
 
67
    Centre();
 
68
}
 
69
 
 
70
void DIALOG_NEW_DATAITEM::OnCancelClick( wxCommandEvent& event )
 
71
{
 
72
    EndModal( wxID_CANCEL);
 
73
}
 
74
 
 
75
void DIALOG_NEW_DATAITEM::OnOKClick( wxCommandEvent& event )
 
76
{
 
77
    if( m_item->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
 
78
    {
 
79
        WORKSHEET_DATAITEM_TEXT* text = ((WORKSHEET_DATAITEM_TEXT*)m_item);
 
80
        text->m_TextBase = m_textCtrlText->GetValue();
 
81
        // For multiline texts, replace the '\n' char by the "\\n" sequence",
 
82
        // in internal string
 
83
        text->m_TextBase.Replace( wxT("\n"), wxT("\\n") );
 
84
    }
 
85
 
 
86
    wxString msg;
 
87
 
 
88
    // Import Start point
 
89
    double dtmp;
 
90
    msg = m_textCtrlPosX->GetValue();
 
91
    msg.ToDouble( &dtmp );
 
92
    m_item->m_Pos.m_Pos.x = dtmp;
 
93
 
 
94
    msg = m_textCtrlPosY->GetValue();
 
95
    msg.ToDouble( &dtmp );
 
96
    m_item->m_Pos.m_Pos.y = dtmp;
 
97
 
 
98
    switch( m_choiceCornerPos->GetSelection() )
 
99
    {
 
100
        case 2: m_item->m_Pos.m_Anchor = RB_CORNER; break;
 
101
        case 0: m_item->m_Pos.m_Anchor = RT_CORNER; break;
 
102
        case 3: m_item->m_Pos.m_Anchor = LB_CORNER; break;
 
103
        case 1: m_item->m_Pos.m_Anchor = LT_CORNER; break;
 
104
    }
 
105
 
 
106
    // Import End point
 
107
    msg = m_textCtrlEndX->GetValue();
 
108
    msg.ToDouble( &dtmp );
 
109
    m_item->m_End.m_Pos.x = dtmp;
 
110
 
 
111
    msg = m_textCtrlEndY->GetValue();
 
112
    msg.ToDouble( &dtmp );
 
113
    m_item->m_End.m_Pos.y = dtmp;
 
114
 
 
115
    switch( m_choiceCornerEnd->GetSelection() )
 
116
    {
 
117
        case 2: m_item->m_End.m_Anchor = RB_CORNER; break;
 
118
        case 0: m_item->m_End.m_Anchor = RT_CORNER; break;
 
119
        case 3: m_item->m_End.m_Anchor = LB_CORNER; break;
 
120
        case 1: m_item->m_End.m_Anchor = LT_CORNER; break;
 
121
    }
 
122
 
 
123
    EndModal( wxID_OK);
 
124
}
 
125
 
 
126
void DIALOG_NEW_DATAITEM::initDlg()
 
127
{
 
128
    // Disable useless widgets, depending on WORKSHEET_DATAITEM type
 
129
    switch( m_item->GetType() )
 
130
    {
 
131
        case WORKSHEET_DATAITEM::WS_SEGMENT:
 
132
        case WORKSHEET_DATAITEM::WS_RECT:
 
133
            m_textCtrlText->Enable( false );
 
134
            break;
 
135
 
 
136
        case WORKSHEET_DATAITEM::WS_POLYPOLYGON:
 
137
            m_textCtrlText->Enable( false );
 
138
            // fall through
 
139
        case WORKSHEET_DATAITEM::WS_TEXT:
 
140
            m_textCtrlEndX->Enable( false );
 
141
            m_textCtrlEndY->Enable( false );
 
142
            break;
 
143
    }
 
144
 
 
145
    wxString msg;
 
146
 
 
147
    // Position/ start point
 
148
    msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.x );
 
149
    m_textCtrlPosX->SetValue( msg );
 
150
    msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.y );
 
151
    m_textCtrlPosY->SetValue( msg );
 
152
    switch(  m_item->m_Pos.m_Anchor )
 
153
    {
 
154
        case RB_CORNER:      // right bottom corner
 
155
            m_choiceCornerPos->SetSelection( 2 ); break;
 
156
        case RT_CORNER:      // right top corner
 
157
            m_choiceCornerPos->SetSelection( 0 ); break;
 
158
        case LB_CORNER:      // left bottom corner
 
159
            m_choiceCornerPos->SetSelection( 3 ); break;
 
160
        case LT_CORNER:      // left top corner
 
161
            m_choiceCornerPos->SetSelection( 1 ); break;
 
162
    }
 
163
 
 
164
    // End point
 
165
    msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.x );
 
166
    m_textCtrlEndX->SetValue( msg );
 
167
    msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.y );
 
168
    m_textCtrlEndY->SetValue( msg );
 
169
    switch( m_item->m_End.m_Anchor )
 
170
    {
 
171
        case RB_CORNER:      // right bottom corner
 
172
            m_choiceCornerEnd->SetSelection( 2 ); break;
 
173
        case RT_CORNER:      // right top corner
 
174
            m_choiceCornerEnd->SetSelection( 0 ); break;
 
175
        case LB_CORNER:      // left bottom corner
 
176
            m_choiceCornerEnd->SetSelection( 3 ); break;
 
177
        case LT_CORNER:      // left top corner
 
178
            m_choiceCornerEnd->SetSelection( 1 ); break;
 
179
    }
 
180
 
 
181
    if( m_item->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
 
182
        m_textCtrlText->SetValue( ((WORKSHEET_DATAITEM_TEXT*)m_item)->m_TextBase );
 
183
}