KiCad PCB EDA Suite
properties_frame.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2013 CERN
9  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <fctsys.h>
30 #include <wxstruct.h>
31 #include <class_drawpanel.h>
34 #include <properties_frame.h>
35 
37  PANEL_PROPERTIES_BASE( aParent )
38 {
39  m_parent = aParent;
40 }
41 
42 
44 {
45 }
46 
48 {
49  return wxSize( 150, -1 );
50 }
51 
52 
53 // Data transfert from general properties to widgets
55 {
56  wxString msg;
57 
58  // Set default parameters
59  msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultLineWidth );
60  m_textCtrlDefaultLineWidth->SetValue( msg );
61 
62  msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultTextSize.x );
63  m_textCtrlDefaultTextSizeX->SetValue( msg );
64  msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultTextSize.y );
65  m_textCtrlDefaultTextSizeY->SetValue( msg );
66 
67  msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultTextThickness );
68  m_textCtrlDefaultTextThickness->SetValue( msg );
69 
70  // Set page margins values
72  msg.Printf( wxT("%.3f"), pglayout.GetRightMargin() );
73  m_textCtrlRightMargin->SetValue( msg );
74  msg.Printf( wxT("%.3f"), pglayout.GetBottomMargin() );
75  m_textCtrlDefaultBottomMargin->SetValue( msg );
76 
77  msg.Printf( wxT("%.3f"), pglayout.GetLeftMargin() );
78  m_textCtrlLeftMargin->SetValue( msg );
79  msg.Printf( wxT("%.3f"), pglayout.GetTopMargin() );
80  m_textCtrlTopMargin->SetValue( msg );
81 }
82 
83 // Data transfert from widgets to general properties
85 {
86  wxString msg;
87 
88  // Import default parameters from widgets
89  msg = m_textCtrlDefaultLineWidth->GetValue();
91 
92  msg = m_textCtrlDefaultTextSizeX->GetValue();
94  msg = m_textCtrlDefaultTextSizeY->GetValue();
96 
97  msg = m_textCtrlDefaultTextThickness->GetValue();
99 
100  // Get page margins values
102 
103  msg = m_textCtrlRightMargin->GetValue();
105  msg = m_textCtrlDefaultBottomMargin->GetValue();
107 
108  // cordinates of the left top corner are the left and top margins
109  msg = m_textCtrlLeftMargin->GetValue();
111  msg = m_textCtrlTopMargin->GetValue();
113 
114  return true;
115 }
116 
117 // Data transfert from item to widgets in properties frame
119 {
120  wxString msg;
121 
122  // Set parameters common to all WORKSHEET_DATAITEM types
123  m_textCtrlType->SetValue( aItem->GetClassName() );
124  m_textCtrlComment->SetValue( aItem->m_Info );
125 
126  switch( aItem->GetPage1Option() )
127  {
128  default:
129  case 0:
130  m_choicePageOpt->SetSelection( 0 );
131  break;
132 
133  case 1:
134  m_choicePageOpt->SetSelection( 1 );
135  break;
136 
137  case -1:
138  m_choicePageOpt->SetSelection( 2 );
139  break;
140  }
141 
142  // Position/ start point
143  msg.Printf( wxT("%.3f"), aItem->m_Pos.m_Pos.x );
144  m_textCtrlPosX->SetValue( msg );
145  msg.Printf( wxT("%.3f"), aItem->m_Pos.m_Pos.y );
146  m_textCtrlPosY->SetValue( msg );
147 
148  switch( aItem->m_Pos.m_Anchor )
149  {
150  case RB_CORNER: // right bottom corner
151  m_comboBoxCornerPos->SetSelection( 2 ); break;
152  case RT_CORNER: // right top corner
153  m_comboBoxCornerPos->SetSelection( 0 ); break;
154  case LB_CORNER: // left bottom corner
155  m_comboBoxCornerPos->SetSelection( 3 ); break;
156  case LT_CORNER: // left top corner
157  m_comboBoxCornerPos->SetSelection( 1 ); break;
158  }
159 
160  // End point
161  msg.Printf( wxT("%.3f"), aItem->m_End.m_Pos.x );
162  m_textCtrlEndX->SetValue( msg );
163  msg.Printf( wxT("%.3f"), aItem->m_End.m_Pos.y );
164  m_textCtrlEndY->SetValue( msg );
165 
166  switch( aItem->m_End.m_Anchor )
167  {
168  case RB_CORNER: // right bottom corner
169  m_comboBoxCornerEnd->SetSelection( 2 ); break;
170  case RT_CORNER: // right top corner
171  m_comboBoxCornerEnd->SetSelection( 0 ); break;
172  case LB_CORNER: // left bottom corner
173  m_comboBoxCornerEnd->SetSelection( 3 ); break;
174  case LT_CORNER: // left top corner
175  m_comboBoxCornerEnd->SetSelection( 1 ); break;
176  }
177 
178  msg.Printf( wxT("%.3f"), aItem->m_LineWidth );
179  m_textCtrlThickness->SetValue( msg );
180 
181  // Now, set prms more specific to WORKSHEET_DATAITEM types
182  // For a given type, disable widgets which are not relevant,
183  // and be sure widgets which are relevant are enabled
184  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
185  {
186  m_SizerTextOptions->Show(true);
187  m_SizerTextIncrementLabel->Show( true );
188 
190  item->m_FullText = item->m_TextBase;
191  // Replace our '\' 'n' sequence by the EOL char
192  item->ReplaceAntiSlashSequence();
193  m_textCtrlText->SetValue( item->m_FullText );
194 
195  msg.Printf( wxT("%d"), item->m_IncrementLabel );
196  m_textCtrlTextIncrement->SetValue( msg );
197 
198  // Rotation (poly and text)
199  msg.Printf( wxT("%.3f"), item->m_Orient );
200  m_textCtrlRotation->SetValue( msg );
201 
202  // Constraints:
203  msg.Printf( wxT("%.3f"), item->m_BoundingBoxSize.x );
204  m_textCtrlConstraintX->SetValue( msg );
205  msg.Printf( wxT("%.3f"), item->m_BoundingBoxSize.y );
206  m_textCtrlConstraintY->SetValue( msg );
207 
208  // Font Options
209  m_checkBoxBold->SetValue( item->IsBold() );
210  m_checkBoxItalic->SetValue( item->IsItalic() );
211  switch( item->m_Hjustify )
212  {
213  case GR_TEXT_HJUSTIFY_LEFT: m_choiceHjustify->SetSelection( 0 ); break;
214  case GR_TEXT_HJUSTIFY_CENTER: m_choiceHjustify->SetSelection( 1 ); break;
215  case GR_TEXT_HJUSTIFY_RIGHT: m_choiceHjustify->SetSelection( 2 ); break;
216  }
217  switch( item->m_Vjustify )
218  {
219  case GR_TEXT_VJUSTIFY_TOP: m_choiceVjustify->SetSelection( 0 ); break;
220  case GR_TEXT_VJUSTIFY_CENTER: m_choiceVjustify->SetSelection( 1 ); break;
221  case GR_TEXT_VJUSTIFY_BOTTOM: m_choiceVjustify->SetSelection( 2 ); break;
222  }
223 
224  // Text size
225  msg.Printf( wxT("%.3f"), item->m_TextSize.x );
226  m_textCtrlTextSizeX->SetValue( msg );
227  msg.Printf( wxT("%.3f"), item->m_TextSize.y );
228  m_textCtrlTextSizeY->SetValue( msg );
229  }
230  else
231  {
232  m_SizerTextOptions->Show(false);
233  m_SizerTextIncrementLabel->Show(false);
234  }
235 
237  {
239  // Rotation (poly and text)
240  msg.Printf( wxT("%.3f"), item->m_Orient );
241  m_textCtrlRotation->SetValue( msg );
242  }
243 
244  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_BITMAP )
245  {
247  // select definition in PPI
248  msg.Printf( wxT("%d"), item->GetPPI() );
249  m_textCtrlBitmapPPI->SetValue( msg );
250  }
251 
252  switch( aItem->GetType() )
253  {
256  m_SizerBitmapPPI->Show( false );
257  m_SizerLineThickness->Show( true );
258  m_staticTextInfoThickness->Show( true );
259  m_SizerRotation->Show( false );
260  m_SizerEndPosition->Show(true);
261  break;
262 
264  m_SizerBitmapPPI->Show( false );
265  m_SizerLineThickness->Show( true );
266  m_staticTextInfoThickness->Show( true );
267  m_SizerRotation->Show( true );
268  m_SizerEndPosition->Show(false);
269  break;
270 
272  m_SizerBitmapPPI->Show( false );
273  m_SizerLineThickness->Show( true );
274  m_staticTextInfoThickness->Show( false ); // No defaut value for thickness
275  m_SizerRotation->Show( true );
276  m_SizerEndPosition->Show(false);
277  break;
278 
280  m_SizerBitmapPPI->Show( true );
281  m_SizerLineThickness->Show( false );
282  m_SizerRotation->Show( false );
283  m_SizerEndPosition->Show(false);
284  break;
285  }
286 
287  // Repeat parameters
288  msg.Printf( wxT("%d"), aItem->m_RepeatCount );
289  m_textCtrlRepeatCount->SetValue( msg );
290  msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.x );
291  m_textCtrlStepX->SetValue( msg );
292  msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.y );
293  m_textCtrlStepY->SetValue( msg );
294 
295  // The number of widgets was modified
296  m_swItemProperties->Layout();
297  m_swItemProperties->Refresh();
298 }
299 
300 // Event function called by clicking on the OK button
301 void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event )
302 {
304 
306  if( item )
307  {
308  CopyPrmsFromPanelToItem( item );
309  // Be sure what is displayed is what is set for item
310  // (mainly, texts can be modified if they contain "\n")
311  CopyPrmsFromItemToPanel( item );
312  }
313 
315 
316  // Refresh values, exactly as they are converted, to avoid any mistake
318 
319  m_parent->OnModify();
320  m_parent->GetCanvas()->Refresh();
321 }
322 
323 void PROPERTIES_FRAME::OnSetDefaultValues( wxCommandEvent& event )
324 {
327  // default thickness in mm
330 
332  m_parent->GetCanvas()->Refresh();
333 }
334 
335 
336 // Data transfert from properties frame to item parameters
338 {
339  if( aItem == NULL )
340  return false;
341 
342  wxString msg;
343 
344  // Import common parameters:
345  aItem->m_Info = m_textCtrlComment->GetValue();
346 
347  switch( m_choicePageOpt->GetSelection() )
348  {
349  default:
350  case 0:
351  aItem->SetPage1Option( 0 );
352  break;
353 
354  case 1:
355  aItem->SetPage1Option( 1 );
356  break;
357 
358  case 2:
359  aItem->SetPage1Option( -1 );
360  break;
361  }
362 
363  // Import thickness
364  msg = m_textCtrlThickness->GetValue();
366 
367  // Import Start point
368  msg = m_textCtrlPosX->GetValue();
370 
371  msg = m_textCtrlPosY->GetValue();
373 
374  switch( m_comboBoxCornerPos->GetSelection() )
375  {
376  case 2: aItem->m_Pos.m_Anchor = RB_CORNER; break;
377  case 0: aItem->m_Pos.m_Anchor = RT_CORNER; break;
378  case 3: aItem->m_Pos.m_Anchor = LB_CORNER; break;
379  case 1: aItem->m_Pos.m_Anchor = LT_CORNER; break;
380  }
381 
382  // Import End point
383  msg = m_textCtrlEndX->GetValue();
385 
386  msg = m_textCtrlEndY->GetValue();
388 
389  switch( m_comboBoxCornerEnd->GetSelection() )
390  {
391  case 2: aItem->m_End.m_Anchor = RB_CORNER; break;
392  case 0: aItem->m_End.m_Anchor = RT_CORNER; break;
393  case 3: aItem->m_End.m_Anchor = LB_CORNER; break;
394  case 1: aItem->m_End.m_Anchor = LT_CORNER; break;
395  }
396 
397  // Import Repeat prms
398  long itmp;
399  msg = m_textCtrlRepeatCount->GetValue();
400  msg.ToLong( &itmp );
401  aItem->m_RepeatCount = itmp;
402 
403  msg = m_textCtrlStepX->GetValue();
405 
406  msg = m_textCtrlStepY->GetValue();
408 
409  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
410  {
412 
413  item->m_TextBase = m_textCtrlText->GetValue();
414 
415  msg = m_textCtrlTextIncrement->GetValue();
416  msg.ToLong( &itmp );
417  item->m_IncrementLabel = itmp;
418 
419  item->SetBold( m_checkBoxBold->IsChecked() );
420  item->SetItalic( m_checkBoxItalic->IsChecked() );
421 
422  switch( m_choiceHjustify->GetSelection() )
423  {
424  case 0: item->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT; break;
425  case 1: item->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER; break;
426  case 2: item->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT; break;
427  }
428  switch( m_choiceVjustify->GetSelection() )
429  {
430  case 0: item->m_Vjustify = GR_TEXT_VJUSTIFY_TOP; break;
431  case 1: item->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER; break;
432  case 2: item->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; break;
433  }
434 
435  msg = m_textCtrlRotation->GetValue();
437 
438  // Import text size
439  msg = m_textCtrlTextSizeX->GetValue();
441 
442  msg = m_textCtrlTextSizeY->GetValue();
444 
445  // Import constraints:
446  msg = m_textCtrlConstraintX->GetValue();
448 
449  msg = m_textCtrlConstraintY->GetValue();
451  }
452 
454  {
456 
457  msg = m_textCtrlRotation->GetValue();
459  }
460 
461  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_BITMAP )
462  {
464  // Set definition in PPI
465  long value;
466  msg = m_textCtrlBitmapPPI->GetValue();
467  if( msg.ToLong( &value ) )
468  item->SetPPI( (int)value );
469  }
470 
471  return true;
472 }
473 
wxTextCtrl * m_textCtrlDefaultTextThickness
wxScrolledWindow * m_swItemProperties
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:324
wxTextCtrl * m_textCtrlDefaultBottomMargin
void CopyPrmsFromItemToPanel(WORKSHEET_DATAITEM *aItem)
void OnAcceptPrms(wxCommandEvent &event) override
DPOINT DSIZE
Definition: vector2d.h:596
#define TB_DEFAULT_TEXTSIZE
description of graphic items and texts to build a title block
wxTextCtrl * m_textCtrlDefaultLineWidth
void SetLeftMargin(double aMargin)
void SetTopMargin(double aMargin)
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application ...
wxTextCtrl * m_textCtrlDefaultTextSizeY
void OnModify()
Must be called after a change in order to set the "modify" flag of the current screen.
void SetBottomMargin(double aMargin)
bool CopyPrmsFromPanelToItem(WORKSHEET_DATAITEM *aItem)
void SetItalic(bool aState)
Function SetItalic Toggles on/off the italic option flag.
Base window classes and related definitions.
bool CopyPrmsFromPanelToGeneral()
wxSize GetMinSize() const override
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
void SetPPI(int aBitmapPPI)
adjust the PPI of the bitmap
static double m_DefaultTextThickness
PROPERTIES_FRAME(PL_EDITOR_FRAME *aParent)
wxStaticText * m_staticTextInfoThickness
wxBoxSizer * m_SizerTextIncrementLabel
WORKSHEET_DATAITEM * GetSelectedItem()
Function GetSelectedItem.
WS_ItemType GetType() const
PL_EDITOR_FRAME * m_parent
void SetBold(bool aState)
Function SetBold Toggles on/off the bold option flag.
void SaveCopyInUndoList()
Save a copy of the description (in a S expr string) for Undo/redo commands.
classes and function to generate graphics to plt or draw titles blocks and frame references ...
void CopyPrmsFromGeneralToPanel()
void SetPage1Option(int aChoice)
Set the option for page 1.
void OnSetDefaultValues(wxCommandEvent &event) override
double DoubleValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:301
bool ReplaceAntiSlashSequence()
Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText...
wxTextCtrl * m_textCtrlDefaultTextSizeX
const wxString GetClassName() const
void SetRightMargin(double aMargin)
Class PANEL_PROPERTIES_BASE.