KiCad PCB EDA Suite
dialog_new_dataitem.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2013 CERN
10  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 #include <fctsys.h>
31 #include <common.h>
32 #include <class_drawpanel.h>
33 
34 #include <pl_editor_frame.h>
37 
39 {
41 
42 public:
44 
45 private:
46  void OnCancelClick( wxCommandEvent& event ) override;
47  void OnOKClick( wxCommandEvent& event ) override;
48 
49  void initDlg();
50 };
51 
52 
54 {
55  DIALOG_NEW_DATAITEM dlg( aCaller, aItem );
56  return dlg.ShowModal();
57 }
58 
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 {
78  {
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 
127 {
128  // Disable useless widgets, depending on WORKSHEET_DATAITEM type
129  switch( m_item->GetType() )
130  {
133  m_textCtrlText->Enable( false );
134  break;
135 
138  m_textCtrlText->Enable( false );
139  // fall through
141  m_textCtrlEndX->Enable( false );
142  m_textCtrlEndY->Enable( false );
143  m_choiceCornerEnd->Enable( false );
144  break;
145  }
146 
147  wxString msg;
148 
149  // Position/ start point
150  msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.x );
151  m_textCtrlPosX->SetValue( msg );
152  msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.y );
153  m_textCtrlPosY->SetValue( msg );
154  switch( m_item->m_Pos.m_Anchor )
155  {
156  case RB_CORNER: // right bottom corner
157  m_choiceCornerPos->SetSelection( 2 ); break;
158  case RT_CORNER: // right top corner
159  m_choiceCornerPos->SetSelection( 0 ); break;
160  case LB_CORNER: // left bottom corner
161  m_choiceCornerPos->SetSelection( 3 ); break;
162  case LT_CORNER: // left top corner
163  m_choiceCornerPos->SetSelection( 1 ); break;
164  }
165 
166  // End point
167  msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.x );
168  m_textCtrlEndX->SetValue( msg );
169  msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.y );
170  m_textCtrlEndY->SetValue( msg );
171  switch( m_item->m_End.m_Anchor )
172  {
173  case RB_CORNER: // right bottom corner
174  m_choiceCornerEnd->SetSelection( 2 ); break;
175  case RT_CORNER: // right top corner
176  m_choiceCornerEnd->SetSelection( 0 ); break;
177  case LB_CORNER: // left bottom corner
178  m_choiceCornerEnd->SetSelection( 3 ); break;
179  case LT_CORNER: // left top corner
180  m_choiceCornerEnd->SetSelection( 1 ); break;
181  }
182 
184  m_textCtrlText->SetValue( ((WORKSHEET_DATAITEM_TEXT*)m_item)->m_TextBase );
185 }
description of graphic items and texts to build a title block
void OnCancelClick(wxCommandEvent &event) override
Class DIALOG_NEW_DATAITEM_BASE.
WORKSHEET_DATAITEM * m_item
WS_ItemType GetType() const
void OnOKClick(wxCommandEvent &event) override
The common library.
int InvokeDialogNewItem(PL_EDITOR_FRAME *aCaller, WORKSHEET_DATAITEM *aItem)
Create and show DIALOG_NEW_DATAITEM and return whatever DIALOG_NEW_DATAITEM::ShowModal() returns...
DIALOG_NEW_DATAITEM(PL_EDITOR_FRAME *aCaller, WORKSHEET_DATAITEM *aItem)