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>
35 #include <worksheet_dataitem.h>
37 
39 {
41 
42 public:
44 
45 private:
46  void OnOKClick( wxCommandEvent& event ) override;
47 
48  void initDlg();
49 };
50 
51 
53 {
54  DIALOG_NEW_DATAITEM dlg( aCaller, aItem );
55  return dlg.ShowModal();
56 }
57 
59  WORKSHEET_DATAITEM* aItem )
60  : DIALOG_NEW_DATAITEM_BASE( aCaller )
61 {
62  m_item = aItem;
63  initDlg();
64 
65  GetSizer()->SetSizeHints( this );
66  Centre();
67 }
68 
69 
70 void DIALOG_NEW_DATAITEM::OnOKClick( wxCommandEvent& event )
71 {
73  {
75  text->m_TextBase = m_textCtrlText->GetValue();
76  // For multiline texts, replace the '\n' char by the "\\n" sequence",
77  // in internal string
78  text->m_TextBase.Replace( wxT("\n"), wxT("\\n") );
79  }
80 
81  wxString msg;
82 
83  // Import Start point
84  double dtmp;
85  msg = m_textCtrlPosX->GetValue();
86  msg.ToDouble( &dtmp );
87  m_item->m_Pos.m_Pos.x = dtmp;
88 
89  msg = m_textCtrlPosY->GetValue();
90  msg.ToDouble( &dtmp );
91  m_item->m_Pos.m_Pos.y = dtmp;
92 
93  switch( m_choiceCornerPos->GetSelection() )
94  {
95  case 2: m_item->m_Pos.m_Anchor = RB_CORNER; break;
96  case 0: m_item->m_Pos.m_Anchor = RT_CORNER; break;
97  case 3: m_item->m_Pos.m_Anchor = LB_CORNER; break;
98  case 1: m_item->m_Pos.m_Anchor = LT_CORNER; break;
99  }
100 
101  // Import End point
102  msg = m_textCtrlEndX->GetValue();
103  msg.ToDouble( &dtmp );
104  m_item->m_End.m_Pos.x = dtmp;
105 
106  msg = m_textCtrlEndY->GetValue();
107  msg.ToDouble( &dtmp );
108  m_item->m_End.m_Pos.y = dtmp;
109 
110  switch( m_choiceCornerEnd->GetSelection() )
111  {
112  case 2: m_item->m_End.m_Anchor = RB_CORNER; break;
113  case 0: m_item->m_End.m_Anchor = RT_CORNER; break;
114  case 3: m_item->m_End.m_Anchor = LB_CORNER; break;
115  case 1: m_item->m_End.m_Anchor = LT_CORNER; break;
116  }
117 
118  EndModal( wxID_OK);
119 }
120 
122 {
123  // Disable useless widgets, depending on WORKSHEET_DATAITEM type
124  switch( m_item->GetType() )
125  {
128  m_textCtrlText->Enable( false );
129  break;
130 
133  m_textCtrlText->Enable( false );
134  // fall through
136  m_textCtrlEndX->Enable( false );
137  m_textCtrlEndY->Enable( false );
138  m_choiceCornerEnd->Enable( false );
139  break;
140  }
141 
142  wxString msg;
143 
144  // Position/ start point
145  msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.x );
146  m_textCtrlPosX->SetValue( msg );
147  msg.Printf( wxT("%.3f"), m_item->m_Pos.m_Pos.y );
148  m_textCtrlPosY->SetValue( msg );
149  switch( m_item->m_Pos.m_Anchor )
150  {
151  case RB_CORNER: // right bottom corner
152  m_choiceCornerPos->SetSelection( 2 ); break;
153  case RT_CORNER: // right top corner
154  m_choiceCornerPos->SetSelection( 0 ); break;
155  case LB_CORNER: // left bottom corner
156  m_choiceCornerPos->SetSelection( 3 ); break;
157  case LT_CORNER: // left top corner
158  m_choiceCornerPos->SetSelection( 1 ); break;
159  }
160 
161  // End point
162  msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.x );
163  m_textCtrlEndX->SetValue( msg );
164  msg.Printf( wxT("%.3f"), m_item->m_End.m_Pos.y );
165  m_textCtrlEndY->SetValue( msg );
166  switch( m_item->m_End.m_Anchor )
167  {
168  case RB_CORNER: // right bottom corner
169  m_choiceCornerEnd->SetSelection( 2 ); break;
170  case RT_CORNER: // right top corner
171  m_choiceCornerEnd->SetSelection( 0 ); break;
172  case LB_CORNER: // left bottom corner
173  m_choiceCornerEnd->SetSelection( 3 ); break;
174  case LT_CORNER: // left top corner
175  m_choiceCornerEnd->SetSelection( 1 ); break;
176  }
177 
179  m_textCtrlText->SetValue( ((WORKSHEET_DATAITEM_TEXT*)m_item)->m_TextBase );
180 }
Class PL_EDITOR_FRAME is the main window used in the page layout editor.
Class DIALOG_NEW_DATAITEM_BASE.
description of graphic items and texts to build a title block
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)