KiCad PCB EDA Suite
properties_frame.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <fctsys.h>
27 #include <ws_draw_item.h>
28 #include <ws_data_model.h>
29 #include <properties_frame.h>
30 #include <tool/tool_manager.h>
32 #include <pl_draw_panel_gal.h>
33 
35  PANEL_PROPERTIES_BASE( aParent )
36 {
37  m_parent = aParent;
38 
39  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
40  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
41  m_staticTextSizeInfo->SetFont( infoFont );
42  infoFont.SetSymbolicSize( wxFONTSIZE_X_SMALL );
43  m_staticTextInfoThickness->SetFont( infoFont );
44 
45  m_buttonOK->SetDefault();
46 }
47 
48 
50 {
51 }
52 
53 
54 void PROPERTIES_FRAME::OnPageChanged( wxNotebookEvent& event )
55 {
56  if( event.GetSelection() == 0 )
57  m_buttonOK->SetDefault();
58  else
59  m_buttonGeneralOptsOK->SetDefault();
60 
61  event.Skip();
62 }
63 
64 
66 {
67  return wxSize( 150, -1 );
68 }
69 
70 
71 // Data transfert from general properties to widgets
73 {
75  wxString msg;
76 
77  // Set default parameters
78  msg.Printf( wxT("%.3f"), model.m_DefaultLineWidth );
79  m_textCtrlDefaultLineWidth->SetValue( msg );
80 
81  msg.Printf( wxT("%.3f"), model.m_DefaultTextSize.x );
82  m_textCtrlDefaultTextSizeX->SetValue( msg );
83  msg.Printf( wxT("%.3f"), model.m_DefaultTextSize.y );
84  m_textCtrlDefaultTextSizeY->SetValue( msg );
85 
86  msg.Printf( wxT("%.3f"), model.m_DefaultTextThickness );
87  m_textCtrlDefaultTextThickness->SetValue( msg );
88 
89  // Set page margins values
90  msg.Printf( wxT("%.3f"), model.GetRightMargin() );
91  m_textCtrlRightMargin->SetValue( msg );
92  msg.Printf( wxT("%.3f"), model.GetBottomMargin() );
93  m_textCtrlDefaultBottomMargin->SetValue( msg );
94 
95  msg.Printf( wxT("%.3f"), model.GetLeftMargin() );
96  m_textCtrlLeftMargin->SetValue( msg );
97  msg.Printf( wxT("%.3f"), model.GetTopMargin() );
98  m_textCtrlTopMargin->SetValue( msg );
99 }
100 
101 // Data transfert from widgets to general properties
103 {
105  wxString msg;
106 
107  // Import default parameters from widgets
108  msg = m_textCtrlDefaultLineWidth->GetValue();
110 
111  msg = m_textCtrlDefaultTextSizeX->GetValue();
113  msg = m_textCtrlDefaultTextSizeY->GetValue();
115 
116  msg = m_textCtrlDefaultTextThickness->GetValue();
118 
119  // Get page margins values
120  msg = m_textCtrlRightMargin->GetValue();
122  msg = m_textCtrlDefaultBottomMargin->GetValue();
124 
125  // cordinates of the left top corner are the left and top margins
126  msg = m_textCtrlLeftMargin->GetValue();
128  msg = m_textCtrlTopMargin->GetValue();
130 
131  return true;
132 }
133 
134 
135 // Data transfert from item to widgets in properties frame
137 {
138  if( !aItem )
139  {
140  m_SizerItemProperties->Show( false );
141  return;
142  }
143 
144  wxString msg;
145 
146  // Set parameters common to all WS_DATA_ITEM types
147  m_staticTextType->SetLabel( aItem->GetClassName() );
148  m_textCtrlComment->SetValue( aItem->m_Info );
149 
150  switch( aItem->GetPage1Option() )
151  {
152  default:
153  case ALL_PAGES: m_choicePageOpt->SetSelection( 0 ); break;
154  case FIRST_PAGE_ONLY: m_choicePageOpt->SetSelection( 1 ); break;
155  case SUBSEQUENT_PAGES: m_choicePageOpt->SetSelection( 2 ); break;
156  }
157 
158  // Position/ start point
159  msg.Printf( wxT("%.3f"), aItem->m_Pos.m_Pos.x );
160  m_textCtrlPosX->SetValue( msg );
161  msg.Printf( wxT("%.3f"), aItem->m_Pos.m_Pos.y );
162  m_textCtrlPosY->SetValue( msg );
163 
164  switch( aItem->m_Pos.m_Anchor )
165  {
166  case RB_CORNER: m_comboBoxCornerPos->SetSelection( 2 ); break;
167  case RT_CORNER: m_comboBoxCornerPos->SetSelection( 0 ); break;
168  case LB_CORNER: m_comboBoxCornerPos->SetSelection( 3 ); break;
169  case LT_CORNER: m_comboBoxCornerPos->SetSelection( 1 ); break;
170  }
171 
172  // End point
173  msg.Printf( wxT("%.3f"), aItem->m_End.m_Pos.x );
174  m_textCtrlEndX->SetValue( msg );
175  msg.Printf( wxT("%.3f"), aItem->m_End.m_Pos.y );
176  m_textCtrlEndY->SetValue( msg );
177 
178  switch( aItem->m_End.m_Anchor )
179  {
180  case RB_CORNER: m_comboBoxCornerEnd->SetSelection( 2 ); break;
181  case RT_CORNER: m_comboBoxCornerEnd->SetSelection( 0 ); break;
182  case LB_CORNER: m_comboBoxCornerEnd->SetSelection( 3 ); break;
183  case LT_CORNER: m_comboBoxCornerEnd->SetSelection( 1 ); break;
184  }
185 
186  msg.Printf( wxT("%.3f"), aItem->m_LineWidth );
187  m_textCtrlThickness->SetValue( msg );
188 
189  // Now, set prms more specific to WS_DATA_ITEM types
190  // For a given type, disable widgets which are not relevant,
191  // and be sure widgets which are relevant are enabled
192  if( aItem->GetType() == WS_DATA_ITEM::WS_TEXT )
193  {
194  WS_DATA_ITEM_TEXT* item = (WS_DATA_ITEM_TEXT*) aItem;
195  item->m_FullText = item->m_TextBase;
196  // Replace our '\' 'n' sequence by the EOL char
197  item->ReplaceAntiSlashSequence();
198  m_textCtrlText->SetValue( item->m_FullText );
199 
200  msg.Printf( wxT("%d"), item->m_IncrementLabel );
201  m_textCtrlTextIncrement->SetValue( msg );
202 
203  // Rotation (poly and text)
204  msg.Printf( wxT("%.3f"), item->m_Orient );
205  m_textCtrlRotation->SetValue( msg );
206 
207  // Constraints:
208  msg.Printf( wxT("%.3f"), item->m_BoundingBoxSize.x );
209  m_textCtrlConstraintX->SetValue( msg );
210  msg.Printf( wxT("%.3f"), item->m_BoundingBoxSize.y );
211  m_textCtrlConstraintY->SetValue( msg );
212 
213  // Font Options
214  m_checkBoxBold->SetValue( item->m_Bold );
215  m_checkBoxItalic->SetValue( item->m_Italic );
216 
217  switch( item->m_Hjustify )
218  {
219  case GR_TEXT_HJUSTIFY_LEFT: m_choiceHjustify->SetSelection( 0 ); break;
220  case GR_TEXT_HJUSTIFY_CENTER: m_choiceHjustify->SetSelection( 1 ); break;
221  case GR_TEXT_HJUSTIFY_RIGHT: m_choiceHjustify->SetSelection( 2 ); break;
222  }
223 
224  switch( item->m_Vjustify )
225  {
226  case GR_TEXT_VJUSTIFY_TOP: m_choiceVjustify->SetSelection( 0 ); break;
227  case GR_TEXT_VJUSTIFY_CENTER: m_choiceVjustify->SetSelection( 1 ); break;
228  case GR_TEXT_VJUSTIFY_BOTTOM: m_choiceVjustify->SetSelection( 2 ); break;
229  }
230 
231  // Text size
232  msg.Printf( wxT("%.3f"), item->m_TextSize.x );
233  m_textCtrlTextSizeX->SetValue( msg );
234  msg.Printf( wxT("%.3f"), item->m_TextSize.y );
235  m_textCtrlTextSizeY->SetValue( msg );
236  }
237 
238  if( aItem->GetType() == WS_DATA_ITEM::WS_POLYPOLYGON )
239  {
241  // Rotation (poly and text)
242  msg.Printf( wxT("%.3f"), item->m_Orient );
243  m_textCtrlRotation->SetValue( msg );
244  }
245 
246  if( aItem->GetType() == WS_DATA_ITEM::WS_BITMAP )
247  {
248  WS_DATA_ITEM_BITMAP* item = (WS_DATA_ITEM_BITMAP*) aItem;
249  // select definition in PPI
250  msg.Printf( wxT("%d"), item->GetPPI() );
251  m_textCtrlBitmapPPI->SetValue( msg );
252  }
253 
254  m_SizerItemProperties->Show( true );
255 
256  m_SizerTextOptions->Show( aItem->GetType() == WS_DATA_ITEM::WS_TEXT );
257 
259  || aItem->GetType() == WS_DATA_ITEM::WS_RECT );
260 
262  // Polygons have no defaut value for line width
264 
266  || aItem->GetType() == WS_DATA_ITEM::WS_POLYPOLYGON );
267 
268  m_SizerPPI->Show( aItem->GetType() == WS_DATA_ITEM::WS_BITMAP );
269 
272 
273  // Repeat parameters
274  msg.Printf( wxT("%d"), aItem->m_RepeatCount );
275  m_textCtrlRepeatCount->SetValue( msg );
276  msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.x );
277  m_textCtrlStepX->SetValue( msg );
278  msg.Printf( wxT("%.3f"), aItem->m_IncrementVector.y );
279  m_textCtrlStepY->SetValue( msg );
280 
281  // The number of widgets was modified
282  m_swItemProperties->Layout();
283  m_swItemProperties->Refresh();
284 }
285 
286 
287 // Event function called by clicking on the OK button
288 void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event )
289 {
291  PL_SELECTION& selection = selTool->GetSelection();
292 
294 
295  WS_DRAW_ITEM_BASE* drawItem = (WS_DRAW_ITEM_BASE*) selection.Front();
296 
297  if( drawItem )
298  {
299  WS_DATA_ITEM* dataItem = drawItem->GetPeer();
300  CopyPrmsFromPanelToItem( dataItem );
301  // Be sure what is displayed is what is set for item
302  // (mainly, texts can be modified if they contain "\n")
303  CopyPrmsFromItemToPanel( dataItem );
304  m_parent->GetCanvas()->GetView()->Update( drawItem );
305  }
306 
308 
309  // Refresh values, exactly as they are converted, to avoid any mistake
311 
312  m_parent->OnModify();
313 
314  // Rebuild the draw list with the new parameters
316  m_parent->GetCanvas()->Refresh();
317 }
318 
319 
320 void PROPERTIES_FRAME::OnSetDefaultValues( wxCommandEvent& event )
321 {
323 
325  model.m_DefaultLineWidth = 0.15;
326  model.m_DefaultTextThickness = 0.15;
327 
329 
330  // Rebuild the draw list with the new parameters
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: aItem->SetPage1Option( ALL_PAGES ); break;
351  case 1: aItem->SetPage1Option( FIRST_PAGE_ONLY ); break;
352  case 2: aItem->SetPage1Option( SUBSEQUENT_PAGES ); break;
353  }
354 
355  // Import thickness
356  msg = m_textCtrlThickness->GetValue();
358 
359  // Import Start point
360  msg = m_textCtrlPosX->GetValue();
362 
363  msg = m_textCtrlPosY->GetValue();
365 
366  switch( m_comboBoxCornerPos->GetSelection() )
367  {
368  case 2: aItem->m_Pos.m_Anchor = RB_CORNER; break;
369  case 0: aItem->m_Pos.m_Anchor = RT_CORNER; break;
370  case 3: aItem->m_Pos.m_Anchor = LB_CORNER; break;
371  case 1: aItem->m_Pos.m_Anchor = LT_CORNER; break;
372  }
373 
374  // Import End point
375  msg = m_textCtrlEndX->GetValue();
377 
378  msg = m_textCtrlEndY->GetValue();
380 
381  switch( m_comboBoxCornerEnd->GetSelection() )
382  {
383  case 2: aItem->m_End.m_Anchor = RB_CORNER; break;
384  case 0: aItem->m_End.m_Anchor = RT_CORNER; break;
385  case 3: aItem->m_End.m_Anchor = LB_CORNER; break;
386  case 1: aItem->m_End.m_Anchor = LT_CORNER; break;
387  }
388 
389  // Import Repeat prms
390  long itmp;
391  msg = m_textCtrlRepeatCount->GetValue();
392  msg.ToLong( &itmp );
393  aItem->m_RepeatCount = itmp;
394 
395  msg = m_textCtrlStepX->GetValue();
397 
398  msg = m_textCtrlStepY->GetValue();
400 
401  if( aItem->GetType() == WS_DATA_ITEM::WS_TEXT )
402  {
403  WS_DATA_ITEM_TEXT* item = (WS_DATA_ITEM_TEXT*) aItem;
404 
405  item->m_TextBase = m_textCtrlText->GetValue();
406 
407  msg = m_textCtrlTextIncrement->GetValue();
408  msg.ToLong( &itmp );
409  item->m_IncrementLabel = itmp;
410 
411  item->m_Bold = m_checkBoxBold->IsChecked();
412  item->m_Italic = m_checkBoxItalic->IsChecked();
413 
414  switch( m_choiceHjustify->GetSelection() )
415  {
416  case 0: item->m_Hjustify = GR_TEXT_HJUSTIFY_LEFT; break;
417  case 1: item->m_Hjustify = GR_TEXT_HJUSTIFY_CENTER; break;
418  case 2: item->m_Hjustify = GR_TEXT_HJUSTIFY_RIGHT; break;
419  }
420 
421  switch( m_choiceVjustify->GetSelection() )
422  {
423  case 0: item->m_Vjustify = GR_TEXT_VJUSTIFY_TOP; break;
424  case 1: item->m_Vjustify = GR_TEXT_VJUSTIFY_CENTER; break;
425  case 2: item->m_Vjustify = GR_TEXT_VJUSTIFY_BOTTOM; break;
426  }
427 
428  msg = m_textCtrlRotation->GetValue();
430 
431  // Import text size
432  msg = m_textCtrlTextSizeX->GetValue();
434 
435  msg = m_textCtrlTextSizeY->GetValue();
437 
438  // Import constraints:
439  msg = m_textCtrlConstraintX->GetValue();
441 
442  msg = m_textCtrlConstraintY->GetValue();
444  }
445 
446  if( aItem->GetType() == WS_DATA_ITEM::WS_POLYPOLYGON )
447  {
449 
450  msg = m_textCtrlRotation->GetValue();
452  }
453 
454  if( aItem->GetType() == WS_DATA_ITEM::WS_BITMAP )
455  {
456  WS_DATA_ITEM_BITMAP* item = (WS_DATA_ITEM_BITMAP*) aItem;
457  // Set definition in PPI
458  long value;
459  msg = m_textCtrlBitmapPPI->GetValue();
460  if( msg.ToLong( &value ) )
461  item->SetPPI( (int)value );
462  }
463 
464  return true;
465 }
466 
bool CopyPrmsFromPanelToItem(WS_DATA_ITEM *aItem)
WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block.
Definition: ws_data_model.h:39
WS_DATA_ITEM * GetPeer() const
Definition: ws_draw_item.h:66
void SaveCopyInUndoList(bool aSavePageSettingsAndTitleBlock=false)
Save a copy of the description (in a S expr string) for Undo/redo commands.
wxTextCtrl * m_textCtrlDefaultTextThickness
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
double GetTopMargin()
Definition: ws_data_model.h:90
PL_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
wxScrolledWindow * m_swItemProperties
Work sheet structure type definitions.
Definition: ws_data_item.h:93
wxTextCtrl * m_textCtrlDefaultBottomMargin
wxStaticText * m_staticTextInclabel
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
POINT_COORD m_End
Definition: ws_data_item.h:116
void SetPage1Option(PAGE_OPTION aChoice)
Definition: ws_data_item.h:154
#define TB_DEFAULT_TEXTSIZE
Definition: ws_data_item.h:41
void OnPageChanged(wxNotebookEvent &event) override
void DisplayWorksheet()
Build and update the list of WS_DRAW_ITEM_xxx showing the frame layout.
wxString m_Info
Definition: ws_data_item.h:113
wxTextCtrl * m_textCtrlDefaultLineWidth
DSIZE m_DefaultTextSize
Definition: ws_data_model.h:56
PL_SELECTION & GetSelection()
Function GetSelection()
EDA_TEXT_HJUSTIFY_T m_Hjustify
Definition: ws_data_item.h:304
double GetBottomMargin()
Definition: ws_data_model.h:93
bool ReplaceAntiSlashSequence()
Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText.
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
wxTextCtrl * m_textCtrlDefaultTextSizeY
void OnModify()
Must be called after a change in order to set the "modify" flag.
void CopyPrmsFromItemToPanel(WS_DATA_ITEM *aItem)
DPOINT m_Pos
Definition: ws_data_item.h:71
double GetRightMargin()
Definition: ws_data_model.h:87
double DoubleValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:307
void SetLeftMargin(double aMargin)
Definition: ws_data_model.h:85
void SetTopMargin(double aMargin)
Definition: ws_data_model.h:91
EDA_TEXT_VJUSTIFY_T m_Vjustify
Definition: ws_data_item.h:305
wxSize GetMinSize() const override
virtual KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
const wxString GetClassName() const
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1540
DPOINT m_IncrementVector
Definition: ws_data_item.h:119
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
WS_ITEM_TYPE GetType() const
Definition: ws_data_item.h:147
double m_LineWidth
Definition: ws_data_item.h:117
PROPERTIES_FRAME(PL_EDITOR_FRAME *aParent)
void SetBottomMargin(double aMargin)
Definition: ws_data_model.h:94
wxStaticText * m_staticTextInfoThickness
double m_DefaultLineWidth
Definition: ws_data_model.h:55
double GetLeftMargin()
Definition: ws_data_model.h:84
PL_EDITOR_FRAME * m_parent
double m_DefaultTextThickness
Definition: ws_data_model.h:57
wxStaticText * m_staticTextSizeInfo
void CopyPrmsFromGeneralToPanel()
int m_IncrementLabel
Definition: ws_data_item.h:121
void SetPPI(int aBitmapPPI)
POINT_COORD m_Pos
Definition: ws_data_item.h:115
void OnSetDefaultValues(wxCommandEvent &event) override
void SetRightMargin(double aMargin)
Definition: ws_data_model.h:88
PAGE_OPTION GetPage1Option() const
Definition: ws_data_item.h:153
wxTextCtrl * m_textCtrlDefaultTextSizeX
Class PANEL_PROPERTIES_BASE.