KiCad PCB EDA Suite
dialog_new_dataitem.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 CERN
5  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
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 #include <fctsys.h>
26 #include <common.h>
27 #include <pl_editor_frame.h>
28 #include <ws_data_item.h>
30 
31 
33 {
35 
36 public:
38 
39 private:
40  void OnOKClick( wxCommandEvent& event ) override;
41 
42  void initDlg();
43 };
44 
45 
47 {
48  DIALOG_NEW_DATAITEM dlg( aCaller, aItem );
49  return dlg.ShowModal();
50 }
51 
52 
54  : DIALOG_NEW_DATAITEM_BASE( aCaller )
55 {
56  m_item = aItem;
57  initDlg();
58 
59  GetSizer()->SetSizeHints( this );
60  Centre();
61 }
62 
63 
64 void DIALOG_NEW_DATAITEM::OnOKClick( wxCommandEvent& event )
65 {
67  {
69  text->m_TextBase = m_textCtrlText->GetValue();
70  // For multiline texts, replace the '\n' char by the "\\n" sequence",
71  // in internal string
72  text->m_TextBase.Replace( wxT("\n"), wxT("\\n") );
73  }
74 
75  wxString msg;
76 
77  // Import Start point
78  double dtmp;
79  msg = m_textCtrlPosX->GetValue();
80  msg.ToDouble( &dtmp );
81  m_item->m_Pos.m_Pos.x = dtmp;
82 
83  msg = m_textCtrlPosY->GetValue();
84  msg.ToDouble( &dtmp );
85  m_item->m_Pos.m_Pos.y = dtmp;
86 
87  switch( m_choiceCornerPos->GetSelection() )
88  {
89  case 2: m_item->m_Pos.m_Anchor = RB_CORNER; break;
90  case 0: m_item->m_Pos.m_Anchor = RT_CORNER; break;
91  case 3: m_item->m_Pos.m_Anchor = LB_CORNER; break;
92  case 1: m_item->m_Pos.m_Anchor = LT_CORNER; break;
93  }
94 
95  // Import End point
96  msg = m_textCtrlEndX->GetValue();
97  msg.ToDouble( &dtmp );
98  m_item->m_End.m_Pos.x = dtmp;
99 
100  msg = m_textCtrlEndY->GetValue();
101  msg.ToDouble( &dtmp );
102  m_item->m_End.m_Pos.y = dtmp;
103 
104  switch( m_choiceCornerEnd->GetSelection() )
105  {
106  case 2: m_item->m_End.m_Anchor = RB_CORNER; break;
107  case 0: m_item->m_End.m_Anchor = RT_CORNER; break;
108  case 3: m_item->m_End.m_Anchor = LB_CORNER; break;
109  case 1: m_item->m_End.m_Anchor = LT_CORNER; break;
110  }
111 
112  EndModal( wxID_OK);
113 }
114 
116 {
117  // Disable useless widgets, depending on WS_DATA_ITEM type
118  switch( m_item->GetType() )
119  {
122  m_textCtrlText->Enable( false );
123  break;
124 
127  m_textCtrlText->Enable( false );
128  // fall through
130  m_textCtrlEndX->Enable( false );
131  m_textCtrlEndY->Enable( false );
132  m_choiceCornerEnd->Enable( false );
133  break;
134  }
135 
136  wxString msg;
137 
138  // Position/ start point
139  msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.x );
140  m_textCtrlPosX->SetValue( msg );
141  msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.y );
142  m_textCtrlPosY->SetValue( msg );
143 
144  switch( m_item->m_Pos.m_Anchor )
145  {
146  case RB_CORNER: m_choiceCornerPos->SetSelection( 2 ); break;
147  case RT_CORNER: m_choiceCornerPos->SetSelection( 0 ); break;
148  case LB_CORNER: m_choiceCornerPos->SetSelection( 3 ); break;
149  case LT_CORNER: m_choiceCornerPos->SetSelection( 1 ); break;
150  }
151 
152  // End point
153  msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.x );
154  m_textCtrlEndX->SetValue( msg );
155  msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.y );
156  m_textCtrlEndY->SetValue( msg );
157 
158  switch( m_item->m_End.m_Anchor )
159  {
160  case RB_CORNER: m_choiceCornerEnd->SetSelection( 2 ); break;
161  case RT_CORNER: m_choiceCornerEnd->SetSelection( 0 ); break;
162  case LB_CORNER: m_choiceCornerEnd->SetSelection( 3 ); break;
163  case LT_CORNER: m_choiceCornerEnd->SetSelection( 1 ); break;
164  }
165 
167  m_textCtrlText->SetValue( ((WS_DATA_ITEM_TEXT*)m_item)->m_TextBase );
168 }
Work sheet structure type definitions.
Definition: ws_data_item.h:93
Class PL_EDITOR_FRAME is the main window used in the page layout editor.
POINT_COORD m_End
Definition: ws_data_item.h:116
DIALOG_NEW_DATAITEM(PL_EDITOR_FRAME *aCaller, WS_DATA_ITEM *aItem)
Class DIALOG_NEW_DATAITEM_BASE.
DPOINT m_Pos
Definition: ws_data_item.h:71
WS_ITEM_TYPE GetType() const
Definition: ws_data_item.h:147
int InvokeDialogNewItem(PL_EDITOR_FRAME *aCaller, WS_DATA_ITEM *aItem)
Create and show DIALOG_NEW_DATAITEM and return whatever DIALOG_NEW_DATAITEM::ShowModal() returns.
void OnOKClick(wxCommandEvent &event) override
The common library.
POINT_COORD m_Pos
Definition: ws_data_item.h:115