2
* This program source code file is part of KiCad, a free EDA CAD application.
4
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5
* Copyright (C) 2013 KiCad Developers, see AUTHORS.txt for contributors.
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.
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.
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
26
* @file dialog_new_dataitem.cpp
27
* @brief a dialog called on creating a new plage layout data item.
32
#include <class_drawpanel.h>
34
#include <pl_editor_frame.h>
35
#include <class_worksheet_dataitem.h>
36
#include <dialog_new_dataitem_base.h>
38
class DIALOG_NEW_DATAITEM : public DIALOG_NEW_DATAITEM_BASE
40
WORKSHEET_DATAITEM* m_item;
43
DIALOG_NEW_DATAITEM( PL_EDITOR_FRAME* aCaller, WORKSHEET_DATAITEM* aItem );
46
void OnCancelClick( wxCommandEvent& event );
47
void OnOKClick( wxCommandEvent& event );
53
int InvokeDialogNewItem( PL_EDITOR_FRAME* aCaller, WORKSHEET_DATAITEM* aItem )
55
DIALOG_NEW_DATAITEM dlg( aCaller, aItem );
56
return dlg.ShowModal();
59
DIALOG_NEW_DATAITEM::DIALOG_NEW_DATAITEM( PL_EDITOR_FRAME* aCaller,
60
WORKSHEET_DATAITEM* aItem )
61
: DIALOG_NEW_DATAITEM_BASE( aCaller )
66
GetSizer()->SetSizeHints( this );
70
void DIALOG_NEW_DATAITEM::OnCancelClick( wxCommandEvent& event )
72
EndModal( wxID_CANCEL);
75
void DIALOG_NEW_DATAITEM::OnOKClick( wxCommandEvent& event )
77
if( m_item->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
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",
83
text->m_TextBase.Replace( wxT("\n"), wxT("\\n") );
90
msg = m_textCtrlPosX->GetValue();
91
msg.ToDouble( &dtmp );
92
m_item->m_Pos.m_Pos.x = dtmp;
94
msg = m_textCtrlPosY->GetValue();
95
msg.ToDouble( &dtmp );
96
m_item->m_Pos.m_Pos.y = dtmp;
98
switch( m_choiceCornerPos->GetSelection() )
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;
107
msg = m_textCtrlEndX->GetValue();
108
msg.ToDouble( &dtmp );
109
m_item->m_End.m_Pos.x = dtmp;
111
msg = m_textCtrlEndY->GetValue();
112
msg.ToDouble( &dtmp );
113
m_item->m_End.m_Pos.y = dtmp;
115
switch( m_choiceCornerEnd->GetSelection() )
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;
126
void DIALOG_NEW_DATAITEM::initDlg()
128
// Disable useless widgets, depending on WORKSHEET_DATAITEM type
129
switch( m_item->GetType() )
131
case WORKSHEET_DATAITEM::WS_SEGMENT:
132
case WORKSHEET_DATAITEM::WS_RECT:
133
m_textCtrlText->Enable( false );
136
case WORKSHEET_DATAITEM::WS_POLYPOLYGON:
137
m_textCtrlText->Enable( false );
139
case WORKSHEET_DATAITEM::WS_TEXT:
140
m_textCtrlEndX->Enable( false );
141
m_textCtrlEndY->Enable( false );
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 )
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;
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 )
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;
181
if( m_item->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
182
m_textCtrlText->SetValue( ((WORKSHEET_DATAITEM_TEXT*)m_item)->m_TextBase );