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_staticTextInclabel->Show( true );
187  m_textCtrlTextIncrement->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_staticTextInclabel->Show( false );
234  m_textCtrlTextIncrement->Show( false );
235  }
236 
238  {
240  // Rotation (poly and text)
241  msg.Printf( wxT("%.3f"), item->m_Orient );
242  m_textCtrlRotation->SetValue( msg );
243  }
244 
245  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_BITMAP )
246  {
248  // select definition in PPI
249  msg.Printf( wxT("%d"), item->GetPPI() );
250  m_textCtrlBitmapPPI->SetValue( msg );
251  }
252 
253  switch( aItem->GetType() )
254  {
257  m_SizerRotAndPPI->Show( false );
258  m_SizerLineThickness->Show( true );
259  m_staticTextInfoThickness->Show( true );
260  m_SizerEndPosition->Show(true);
261  break;
262 
264  m_SizerRotAndPPI->Show( true );
265  m_staticTextRot->Show( true );
266  m_textCtrlRotation->Show( true );
267  m_staticTextBitmapPPI->Show( false );
268  m_textCtrlBitmapPPI->Show( false );
269  m_SizerLineThickness->Show( true );
270  m_staticTextInfoThickness->Show( true );
271  m_SizerEndPosition->Show(false);
272  break;
273 
275  m_SizerRotAndPPI->Show( true );
276  m_staticTextRot->Show( true );
277  m_textCtrlRotation->Show( true );
278  m_staticTextBitmapPPI->Show( false );
279  m_textCtrlBitmapPPI->Show( false );
280  m_SizerLineThickness->Show( true );
281  m_staticTextInfoThickness->Show( false ); // No defaut value for thickness
282  m_SizerEndPosition->Show(false);
283  break;
284 
286  m_SizerRotAndPPI->Show( true );
287  m_staticTextRot->Show( false );
288  m_textCtrlRotation->Show( false );
289  m_staticTextBitmapPPI->Show( true );
290  m_textCtrlBitmapPPI->Show( true );
291  m_SizerLineThickness->Show( false );
292  m_SizerEndPosition->Show(false);
293  break;
294  }
295 
296  // Repeat parameters
297  msg.Printf( wxT("%d"), aItem->m_RepeatCount );
298  m_textCtrlRepeatCount->SetValue( msg );
299  msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.x );
300  m_textCtrlStepX->SetValue( msg );
301  msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.y );
302  m_textCtrlStepY->SetValue( msg );
303 
304  // The number of widgets was modified
305  m_swItemProperties->Layout();
306  m_swItemProperties->Refresh();
307 }
308 
309 // Event function called by clicking on the OK button
310 void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event )
311 {
313 
315  if( item )
316  {
317  CopyPrmsFromPanelToItem( item );
318  // Be sure what is displayed is what is set for item
319  // (mainly, texts can be modified if they contain "\n")
320  CopyPrmsFromItemToPanel( item );
321  }
322 
324 
325  // Refresh values, exactly as they are converted, to avoid any mistake
327 
328  m_parent->OnModify();
329  m_parent->GetCanvas()->Refresh();
330 }
331 
332 void PROPERTIES_FRAME::OnSetDefaultValues( wxCommandEvent& event )
333 {
336  // default thickness in mm
339 
341  m_parent->GetCanvas()->Refresh();
342 }
343 
344 
345 // Data transfert from properties frame to item parameters
347 {
348  if( aItem == NULL )
349  return false;
350 
351  wxString msg;
352 
353  // Import common parameters:
354  aItem->m_Info = m_textCtrlComment->GetValue();
355 
356  switch( m_choicePageOpt->GetSelection() )
357  {
358  default:
359  case 0:
360  aItem->SetPage1Option( 0 );
361  break;
362 
363  case 1:
364  aItem->SetPage1Option( 1 );
365  break;
366 
367  case 2:
368  aItem->SetPage1Option( -1 );
369  break;
370  }
371 
372  // Import thickness
373  msg = m_textCtrlThickness->GetValue();
375 
376  // Import Start point
377  msg = m_textCtrlPosX->GetValue();
379 
380  msg = m_textCtrlPosY->GetValue();
382 
383  switch( m_comboBoxCornerPos->GetSelection() )
384  {
385  case 2: aItem->m_Pos.m_Anchor = RB_CORNER; break;
386  case 0: aItem->m_Pos.m_Anchor = RT_CORNER; break;
387  case 3: aItem->m_Pos.m_Anchor = LB_CORNER; break;
388  case 1: aItem->m_Pos.m_Anchor = LT_CORNER; break;
389  }
390 
391  // Import End point
392  msg = m_textCtrlEndX->GetValue();
394 
395  msg = m_textCtrlEndY->GetValue();
397 
398  switch( m_comboBoxCornerEnd->GetSelection() )
399  {
400  case 2: aItem->m_End.m_Anchor = RB_CORNER; break;
401  case 0: aItem->m_End.m_Anchor = RT_CORNER; break;
402  case 3: aItem->m_End.m_Anchor = LB_CORNER; break;
403  case 1: aItem->m_End.m_Anchor = LT_CORNER; break;
404  }
405 
406  // Import Repeat prms
407  long itmp;
408  msg = m_textCtrlRepeatCount->GetValue();
409  msg.ToLong( &itmp );
410  aItem->m_RepeatCount = itmp;
411 
412  msg = m_textCtrlStepX->GetValue();
414 
415  msg = m_textCtrlStepY->GetValue();
417 
418  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_TEXT )
419  {
421 
422  item->m_TextBase = m_textCtrlText->GetValue();
423 
424  msg = m_textCtrlTextIncrement->GetValue();
425  msg.ToLong( &itmp );
426  item->m_IncrementLabel = itmp;
427 
428  item->SetBold( m_checkBoxBold->IsChecked() );
429  item->SetItalic( m_checkBoxItalic->IsChecked() );
430 
431  switch( m_choiceHjustify->GetSelection() )
432  {
433  case 0: item->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT; break;
434  case 1: item->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER; break;
435  case 2: item->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT; break;
436  }
437  switch( m_choiceVjustify->GetSelection() )
438  {
439  case 0: item->m_Vjustify = GR_TEXT_VJUSTIFY_TOP; break;
440  case 1: item->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER; break;
441  case 2: item->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; break;
442  }
443 
444  msg = m_textCtrlRotation->GetValue();
446 
447  // Import text size
448  msg = m_textCtrlTextSizeX->GetValue();
450 
451  msg = m_textCtrlTextSizeY->GetValue();
453 
454  // Import constraints:
455  msg = m_textCtrlConstraintX->GetValue();
457 
458  msg = m_textCtrlConstraintY->GetValue();
460  }
461 
463  {
465 
466  msg = m_textCtrlRotation->GetValue();
468  }
469 
470  if( aItem->GetType() == WORKSHEET_DATAITEM::WS_BITMAP )
471  {
473  // Set definition in PPI
474  long value;
475  msg = m_textCtrlBitmapPPI->GetValue();
476  if( msg.ToLong( &value ) )
477  item->SetPPI( (int)value );
478  }
479 
480  return true;
481 }
482 
static DSIZE m_DefaultTextSize
EDA_TEXT_HJUSTIFY_T m_Hjustify
wxTextCtrl * m_textCtrlDefaultTextThickness
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:388
wxScrolledWindow * m_swItemProperties
wxStaticText * m_staticTextBitmapPPI
wxTextCtrl * m_textCtrlDefaultBottomMargin
EDA_TEXT_VJUSTIFY_T m_Vjustify
wxStaticText * m_staticTextInclabel
void CopyPrmsFromItemToPanel(WORKSHEET_DATAITEM *aItem)
void OnAcceptPrms(wxCommandEvent &event) override
Class PL_EDITOR_FRAME is the main window used in the page layout editor.
DPOINT DSIZE
Definition: vector2d.h:593
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()
double DoubleValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:302
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
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()
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void SetPage1Option(int aChoice)
Set the option for page 1.
void OnSetDefaultValues(wxCommandEvent &event) override
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.