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 <class_drawpanel.h>
32 #include <worksheet_dataitem.h>
33 #include <properties_frame.h>
34 
36  PANEL_PROPERTIES_BASE( aParent )
37 {
38  m_parent = aParent;
39 }
40 
41 
43 {
44 }
45 
47 {
48  return wxSize( 150, -1 );
49 }
50 
51 
52 // Data transfert from general properties to widgets
54 {
55  wxString msg;
56 
57  // Set default parameters
58  msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultLineWidth );
59  m_textCtrlDefaultLineWidth->SetValue( msg );
60 
61  msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultTextSize.x );
62  m_textCtrlDefaultTextSizeX->SetValue( msg );
63  msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultTextSize.y );
64  m_textCtrlDefaultTextSizeY->SetValue( msg );
65 
66  msg.Printf( wxT("%.3f"), WORKSHEET_DATAITEM::m_DefaultTextThickness );
67  m_textCtrlDefaultTextThickness->SetValue( msg );
68 
69  // Set page margins values
71  msg.Printf( wxT("%.3f"), pglayout.GetRightMargin() );
72  m_textCtrlRightMargin->SetValue( msg );
73  msg.Printf( wxT("%.3f"), pglayout.GetBottomMargin() );
74  m_textCtrlDefaultBottomMargin->SetValue( msg );
75 
76  msg.Printf( wxT("%.3f"), pglayout.GetLeftMargin() );
77  m_textCtrlLeftMargin->SetValue( msg );
78  msg.Printf( wxT("%.3f"), pglayout.GetTopMargin() );
79  m_textCtrlTopMargin->SetValue( msg );
80 }
81 
82 // Data transfert from widgets to general properties
84 {
85  wxString msg;
86 
87  // Import default parameters from widgets
88  msg = m_textCtrlDefaultLineWidth->GetValue();
90 
91  msg = m_textCtrlDefaultTextSizeX->GetValue();
93  msg = m_textCtrlDefaultTextSizeY->GetValue();
95 
96  msg = m_textCtrlDefaultTextThickness->GetValue();
98 
99  // Get page margins values
101 
102  msg = m_textCtrlRightMargin->GetValue();
104  msg = m_textCtrlDefaultBottomMargin->GetValue();
106 
107  // cordinates of the left top corner are the left and top margins
108  msg = m_textCtrlLeftMargin->GetValue();
110  msg = m_textCtrlTopMargin->GetValue();
112 
113  return true;
114 }
115 
116 // Data transfert from item to widgets in properties frame
118 {
119  wxString msg;
120 
121  // Set parameters common to all WORKSHEET_DATAITEM types
122  m_textCtrlType->SetValue( aItem->GetClassName() );
123  m_textCtrlComment->SetValue( aItem->m_Info );
124 
125  switch( aItem->GetPage1Option() )
126  {
127  default:
128  case 0:
129  m_choicePageOpt->SetSelection( 0 );
130  break;
131 
132  case 1:
133  m_choicePageOpt->SetSelection( 1 );
134  break;
135 
136  case -1:
137  m_choicePageOpt->SetSelection( 2 );
138  break;
139  }
140 
141  // Position/ start point
142  msg.Printf( wxT("%.3f"), aItem->m_Pos.m_Pos.x );
143  m_textCtrlPosX->SetValue( msg );
144  msg.Printf( wxT("%.3f"), aItem->m_Pos.m_Pos.y );
145  m_textCtrlPosY->SetValue( msg );
146 
147  switch( aItem->m_Pos.m_Anchor )
148  {
149  case RB_CORNER: // right bottom corner
150  m_comboBoxCornerPos->SetSelection( 2 ); break;
151  case RT_CORNER: // right top corner
152  m_comboBoxCornerPos->SetSelection( 0 ); break;
153  case LB_CORNER: // left bottom corner
154  m_comboBoxCornerPos->SetSelection( 3 ); break;
155  case LT_CORNER: // left top corner
156  m_comboBoxCornerPos->SetSelection( 1 ); break;
157  }
158 
159  // End point
160  msg.Printf( wxT("%.3f"), aItem->m_End.m_Pos.x );
161  m_textCtrlEndX->SetValue( msg );
162  msg.Printf( wxT("%.3f"), aItem->m_End.m_Pos.y );
163  m_textCtrlEndY->SetValue( msg );
164 
165  switch( aItem->m_End.m_Anchor )
166  {
167  case RB_CORNER: // right bottom corner
168  m_comboBoxCornerEnd->SetSelection( 2 ); break;
169  case RT_CORNER: // right top corner
170  m_comboBoxCornerEnd->SetSelection( 0 ); break;
171  case LB_CORNER: // left bottom corner
172  m_comboBoxCornerEnd->SetSelection( 3 ); break;
173  case LT_CORNER: // left top corner
174  m_comboBoxCornerEnd->SetSelection( 1 ); break;
175  }
176 
177  msg.Printf( wxT("%.3f"), aItem->m_LineWidth );
178  m_textCtrlThickness->SetValue( msg );
179 
180  // Now, set prms more specific to WORKSHEET_DATAITEM types
181  // For a given type, disable widgets which are not relevant,
182  // and be sure widgets which are relevant are enabled
183  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
184  {
185  m_SizerTextOptions->Show(true);
186  m_SizerTextIncrementLabel->Show( true );
187 
189  item->m_FullText = item->m_TextBase;
190  // Replace our '\' 'n' sequence by the EOL char
191  item->ReplaceAntiSlashSequence();
192  m_textCtrlText->SetValue( item->m_FullText );
193 
194  msg.Printf( wxT("%d"), item->m_IncrementLabel );
195  m_textCtrlTextIncrement->SetValue( msg );
196 
197  // Rotation (poly and text)
198  msg.Printf( wxT("%.3f"), item->m_Orient );
199  m_textCtrlRotation->SetValue( msg );
200 
201  // Constraints:
202  msg.Printf( wxT("%.3f"), item->m_BoundingBoxSize.x );
203  m_textCtrlConstraintX->SetValue( msg );
204  msg.Printf( wxT("%.3f"), item->m_BoundingBoxSize.y );
205  m_textCtrlConstraintY->SetValue( msg );
206 
207  // Font Options
208  m_checkBoxBold->SetValue( item->IsBold() );
209  m_checkBoxItalic->SetValue( item->IsItalic() );
210  switch( item->m_Hjustify )
211  {
212  case GR_TEXT_HJUSTIFY_LEFT: m_choiceHjustify->SetSelection( 0 ); break;
213  case GR_TEXT_HJUSTIFY_CENTER: m_choiceHjustify->SetSelection( 1 ); break;
214  case GR_TEXT_HJUSTIFY_RIGHT: m_choiceHjustify->SetSelection( 2 ); break;
215  }
216  switch( item->m_Vjustify )
217  {
218  case GR_TEXT_VJUSTIFY_TOP: m_choiceVjustify->SetSelection( 0 ); break;
219  case GR_TEXT_VJUSTIFY_CENTER: m_choiceVjustify->SetSelection( 1 ); break;
220  case GR_TEXT_VJUSTIFY_BOTTOM: m_choiceVjustify->SetSelection( 2 ); break;
221  }
222 
223  // Text size
224  msg.Printf( wxT("%.3f"), item->m_TextSize.x );
225  m_textCtrlTextSizeX->SetValue( msg );
226  msg.Printf( wxT("%.3f"), item->m_TextSize.y );
227  m_textCtrlTextSizeY->SetValue( msg );
228  }
229  else
230  {
231  m_SizerTextOptions->Show(false);
232  m_SizerTextIncrementLabel->Show(false);
233  }
234 
236  {
238  // Rotation (poly and text)
239  msg.Printf( wxT("%.3f"), item->m_Orient );
240  m_textCtrlRotation->SetValue( msg );
241  }
242 
243  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_BITMAP )
244  {
246  // select definition in PPI
247  msg.Printf( wxT("%d"), item->GetPPI() );
248  m_textCtrlBitmapPPI->SetValue( msg );
249  }
250 
251  switch( aItem->GetType() )
252  {
255  m_SizerBitmapPPI->Show( false );
256  m_SizerLineThickness->Show( true );
257  m_staticTextInfoThickness->Show( true );
258  m_SizerRotation->Show( false );
259  m_SizerEndPosition->Show(true);
260  break;
261 
263  m_SizerBitmapPPI->Show( false );
264  m_SizerLineThickness->Show( true );
265  m_staticTextInfoThickness->Show( true );
266  m_SizerRotation->Show( true );
267  m_SizerEndPosition->Show(false);
268  break;
269 
271  m_SizerBitmapPPI->Show( false );
272  m_SizerLineThickness->Show( true );
273  m_staticTextInfoThickness->Show( false ); // No defaut value for thickness
274  m_SizerRotation->Show( true );
275  m_SizerEndPosition->Show(false);
276  break;
277 
279  m_SizerBitmapPPI->Show( true );
280  m_SizerLineThickness->Show( false );
281  m_SizerRotation->Show( false );
282  m_SizerEndPosition->Show(false);
283  break;
284  }
285 
286  // Repeat parameters
287  msg.Printf( wxT("%d"), aItem->m_RepeatCount );
288  m_textCtrlRepeatCount->SetValue( msg );
289  msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.x );
290  m_textCtrlStepX->SetValue( msg );
291  msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.y );
292  m_textCtrlStepY->SetValue( msg );
293 
294  // The number of widgets was modified
295  m_swItemProperties->Layout();
296  m_swItemProperties->Refresh();
297 }
298 
299 // Event function called by clicking on the OK button
300 void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event )
301 {
303 
305  if( item )
306  {
307  CopyPrmsFromPanelToItem( item );
308  // Be sure what is displayed is what is set for item
309  // (mainly, texts can be modified if they contain "\n")
310  CopyPrmsFromItemToPanel( item );
311  }
312 
314 
315  // Refresh values, exactly as they are converted, to avoid any mistake
317 
318  m_parent->OnModify();
319  m_parent->GetCanvas()->Refresh();
320 }
321 
322 void PROPERTIES_FRAME::OnSetDefaultValues( wxCommandEvent& event )
323 {
326  // default thickness in mm
329 
331  m_parent->GetCanvas()->Refresh();
332 }
333 
334 
335 // Data transfert from properties frame to item parameters
337 {
338  if( aItem == NULL )
339  return false;
340 
341  wxString msg;
342 
343  // Import common parameters:
344  aItem->m_Info = m_textCtrlComment->GetValue();
345 
346  switch( m_choicePageOpt->GetSelection() )
347  {
348  default:
349  case 0:
350  aItem->SetPage1Option( 0 );
351  break;
352 
353  case 1:
354  aItem->SetPage1Option( 1 );
355  break;
356 
357  case 2:
358  aItem->SetPage1Option( -1 );
359  break;
360  }
361 
362  // Import thickness
363  msg = m_textCtrlThickness->GetValue();
365 
366  // Import Start point
367  msg = m_textCtrlPosX->GetValue();
369 
370  msg = m_textCtrlPosY->GetValue();
372 
373  switch( m_comboBoxCornerPos->GetSelection() )
374  {
375  case 2: aItem->m_Pos.m_Anchor = RB_CORNER; break;
376  case 0: aItem->m_Pos.m_Anchor = RT_CORNER; break;
377  case 3: aItem->m_Pos.m_Anchor = LB_CORNER; break;
378  case 1: aItem->m_Pos.m_Anchor = LT_CORNER; break;
379  }
380 
381  // Import End point
382  msg = m_textCtrlEndX->GetValue();
384 
385  msg = m_textCtrlEndY->GetValue();
387 
388  switch( m_comboBoxCornerEnd->GetSelection() )
389  {
390  case 2: aItem->m_End.m_Anchor = RB_CORNER; break;
391  case 0: aItem->m_End.m_Anchor = RT_CORNER; break;
392  case 3: aItem->m_End.m_Anchor = LB_CORNER; break;
393  case 1: aItem->m_End.m_Anchor = LT_CORNER; break;
394  }
395 
396  // Import Repeat prms
397  long itmp;
398  msg = m_textCtrlRepeatCount->GetValue();
399  msg.ToLong( &itmp );
400  aItem->m_RepeatCount = itmp;
401 
402  msg = m_textCtrlStepX->GetValue();
404 
405  msg = m_textCtrlStepY->GetValue();
407 
408  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
409  {
411 
412  item->m_TextBase = m_textCtrlText->GetValue();
413 
414  msg = m_textCtrlTextIncrement->GetValue();
415  msg.ToLong( &itmp );
416  item->m_IncrementLabel = itmp;
417 
418  item->SetBold( m_checkBoxBold->IsChecked() );
419  item->SetItalic( m_checkBoxItalic->IsChecked() );
420 
421  switch( m_choiceHjustify->GetSelection() )
422  {
423  case 0: item->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT; break;
424  case 1: item->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER; break;
425  case 2: item->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT; break;
426  }
427  switch( m_choiceVjustify->GetSelection() )
428  {
429  case 0: item->m_Vjustify = GR_TEXT_VJUSTIFY_TOP; break;
430  case 1: item->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER; break;
431  case 2: item->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; break;
432  }
433 
434  msg = m_textCtrlRotation->GetValue();
436 
437  // Import text size
438  msg = m_textCtrlTextSizeX->GetValue();
440 
441  msg = m_textCtrlTextSizeY->GetValue();
443 
444  // Import constraints:
445  msg = m_textCtrlConstraintX->GetValue();
447 
448  msg = m_textCtrlConstraintY->GetValue();
450  }
451 
453  {
455 
456  msg = m_textCtrlRotation->GetValue();
458  }
459 
460  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_BITMAP )
461  {
463  // Set definition in PPI
464  long value;
465  msg = m_textCtrlBitmapPPI->GetValue();
466  if( msg.ToLong( &value ) )
467  item->SetPPI( (int)value );
468  }
469 
470  return true;
471 }
472 
static DSIZE m_DefaultTextSize
EDA_TEXT_HJUSTIFY_T m_Hjustify
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:338
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:351
wxTextCtrl * m_textCtrlDefaultBottomMargin
EDA_TEXT_VJUSTIFY_T m_Vjustify
void CopyPrmsFromItemToPanel(WORKSHEET_DATAITEM *aItem)
void OnAcceptPrms(wxCommandEvent &event) override
DPOINT DSIZE
Definition: vector2d.h:595
wxTextCtrl * m_textCtrlDefaultLineWidth
void SetLeftMargin(double aMargin)
void SetTopMargin(double aMargin)
#define TB_DEFAULT_TEXTSIZE
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.
bool CopyPrmsFromPanelToGeneral()
description of graphic items and texts to build a title block
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
static double m_DefaultLineWidth
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:303
bool ReplaceAntiSlashSequence()
Replace the &#39;\&#39;&#39;n&#39; sequence by EOL and the sequence &#39;\&#39;&#39;\&#39; by only one &#39;\&#39; inside m_FullText...
wxTextCtrl * m_textCtrlDefaultTextSizeX
const wxString GetClassName() const
void SetRightMargin(double aMargin)
Class PANEL_PROPERTIES_BASE.