KiCad PCB EDA Suite
dialog_graphic_item_properties.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) 2010 Jean-Pierre Charras <jp.charras@wanadoo.fr>
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 /* Edit parameters values of graphic items type DRAWSEGMENTS:
30  * Lines
31  * Circles
32  * Arcs
33  * used as graphic elements found on non copper layers in boards
34  * items on edge layers are considered as graphic items
35  * Pcb texts are not always graphic items and are not handled here
36  */
37 #include <fctsys.h>
38 #include <macros.h>
39 #include <gr_basic.h>
40 #include <confirm.h>
41 #include <class_drawpanel.h>
42 #include <pcbnew.h>
43 #include <wxPcbStruct.h>
45 #include <base_units.h>
46 #include <wx/valnum.h>
47 #include <board_commit.h>
48 
49 #include <class_board.h>
50 #include <class_drawsegment.h>
51 
54 #include <html_messagebox.h>
55 
56 
58 {
59 private:
61  wxDC* m_DC;
64 
65  wxFloatingPointValidator<double> m_AngleValidator;
66  double m_AngleValue;
67 
68 public:
69  DIALOG_GRAPHIC_ITEM_PROPERTIES( PCB_EDIT_FRAME* aParent, DRAWSEGMENT* aItem, wxDC* aDC );
71 
72 private:
73  bool TransferDataToWindow() override;
74  bool TransferDataFromWindow() override;
75  void OnLayerChoice( wxCommandEvent& event );
76 
77  void OnInitDlg( wxInitDialogEvent& event ) override
78  {
79  // Call the default wxDialog handler of a wxInitDialogEvent
81 
82  // Now all widgets have the size fixed, call FinishDialogSettings
84  }
85 
86  bool Validate() override;
87 };
88 
90  DRAWSEGMENT* aItem, wxDC* aDC ):
92  m_AngleValidator( 1, &m_AngleValue ),
93  m_AngleValue( 0.0 )
94 {
95  m_parent = aParent;
96  m_DC = aDC;
97  m_item = aItem;
99 
100  m_AngleValidator.SetRange( -360.0, 360.0 );
101  m_AngleCtrl->SetValidator( m_AngleValidator );
102  m_AngleValidator.SetWindow( m_AngleCtrl );
103 
104  m_StandardButtonsSizerOK->SetDefault();
105 
106 }
107 
108 
110 {
111  wxCHECK_RET( aItem != NULL, wxT( "InstallGraphicItemPropertiesDialog() error: NULL item" ) );
112 
114  DIALOG_GRAPHIC_ITEM_PROPERTIES dlg( this, aItem, aDC );
115  dlg.ShowModal();
117  m_canvas->SetIgnoreMouseEvents( false );
118 }
119 
120 
122 {
123  // Set unit symbol
124  wxStaticText* texts_unit[] =
125  {
132  };
133 
134  for( size_t ii = 0; ii < DIM( texts_unit ); ii++ )
135  {
136  texts_unit[ii]->SetLabel( GetAbbreviatedUnitsLabel() );
137  }
138 
139  wxString msg;
140 
141  // Change texts according to the segment shape:
142  switch( m_item->GetShape() )
143  {
144  case S_CIRCLE:
145  SetTitle( _( "Circle Properties" ) );
146  m_StartPointXLabel->SetLabel( _( "Center X:" ) );
147  m_StartPointYLabel->SetLabel( _( "Center Y:" ) );
148  m_EndPointXLabel->SetLabel( _( "Point X:" ) );
149  m_EndPointYLabel->SetLabel( _( "Point Y:" ) );
150  m_AngleText->Show( false );
151  m_AngleCtrl->Show( false );
152  m_AngleUnit->Show( false );
153  break;
154 
155  case S_ARC:
156  SetTitle( _( "Arc Properties" ) );
157  m_StartPointXLabel->SetLabel( _( "Center X:" ) );
158  m_StartPointYLabel->SetLabel( _( "Center Y:" ) );
159  m_EndPointXLabel->SetLabel( _( "Start Point X:" ) );
160  m_EndPointYLabel->SetLabel( _( "Start Point Y:" ) );
161 
162  m_AngleValue = m_item->GetAngle() / 10.0;
163  break;
164 
165  case S_SEGMENT:
166  SetTitle( _( "Line Segment Properties" ) );
167 
168  // Fall through.
169  default:
170  m_AngleText->Show( false );
171  m_AngleCtrl->Show( false );
172  m_AngleUnit->Show( false );
173  break;
174  }
175 
177 
179 
181 
183 
185 
186  int thickness;
187 
188  if( m_item->GetLayer() == Edge_Cuts )
189  thickness = m_brdSettings.m_EdgeSegmentWidth;
190  else
191  thickness = m_brdSettings.m_DrawSegmentWidth;
192 
194 
195  // Configure the layers list selector
200 
202  {
203  wxMessageBox( _( "This item was on an unknown layer.\n"
204  "It has been moved to the drawings layer. Please fix it." ) );
206  }
207 
208  return DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::TransferDataToWindow();
209 }
210 
211 
213 {
214  int thickness;
215 
217  thickness = m_brdSettings.m_EdgeSegmentWidth;
218  else
219  thickness = m_brdSettings.m_DrawSegmentWidth;
220 
222 }
223 
224 
226 {
227  if( !DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::TransferDataFromWindow() )
228  return false;
229 
230  BOARD_COMMIT commit( m_parent );
231  commit.Modify( m_item );
232 
233  wxString msg;
234 
235  if( m_DC )
237 
238  msg = m_Center_StartXCtrl->GetValue();
240 
241  msg = m_Center_StartYCtrl->GetValue();
243 
244  msg = m_EndX_Radius_Ctrl->GetValue();
246 
247  msg = m_EndY_Ctrl->GetValue();
249 
250  msg = m_ThicknessCtrl->GetValue();
252 
253  msg = m_DefaultThicknessCtrl->GetValue();
254  int thickness = ValueFromString( g_UserUnit, msg );
255 
257 
258  if( m_item->GetLayer() == Edge_Cuts )
259  m_brdSettings.m_EdgeSegmentWidth = thickness;
260  else
261  m_brdSettings.m_DrawSegmentWidth = thickness;
262 
263  if( m_item->GetShape() == S_ARC )
264  {
265  m_item->SetAngle( m_AngleValue * 10.0 );
266  }
267 
268  commit.Push( _( "Modify drawing properties" ) );
269 
270  if( m_DC )
272 
274 
276 
277  return true;
278 }
279 
280 
282 {
283  wxArrayString error_msgs;
284 
285  if( !DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::Validate() )
286  return false;
287 
288  // Load the start and end points -- all types use these in the checks.
289  int startx = ValueFromString( g_UserUnit, m_Center_StartXCtrl->GetValue() );
290  int starty = ValueFromString( g_UserUnit, m_Center_StartYCtrl->GetValue() );
291  int endx = ValueFromString( g_UserUnit, m_EndX_Radius_Ctrl->GetValue() );
292  int endy = ValueFromString( g_UserUnit, m_EndY_Ctrl->GetValue() );
293 
294  // Type specific checks.
295  switch( m_item->GetShape() )
296  {
297  case S_ARC:
298  // Check angle of arc.
299  if( m_AngleValue == 0.0 )
300  {
301  error_msgs.Add( _( "The arc angle must be greater than zero." ) );
302  }
303 
304  // Fall through.
305  case S_CIRCLE:
306 
307  // Check radius.
308  if( (startx == endx) && (starty == endy) )
309  {
310  error_msgs.Add( _( "The radius must be greater than zero." ) );
311  }
312 
313  break;
314 
315  default:
316 
317  // Check start and end are not the same.
318  if( (startx == endx) && (starty == endy) )
319  {
320  error_msgs.Add( _( "The start and end points cannot be the same." ) );
321  }
322 
323  break;
324  }
325 
326  // Check the item thickness.
327  int thickness = ValueFromString( g_UserUnit, m_ThicknessCtrl->GetValue() );
328 
329  if( thickness <= 0 )
330  error_msgs.Add( _( "The item thickness must be greater than zero." ) );
331 
332  // And the default thickness.
333  thickness = ValueFromString( g_UserUnit, m_DefaultThicknessCtrl->GetValue() );
334 
335  if( thickness <= 0 )
336  error_msgs.Add( _( "The default thickness must be greater than zero." ) );
337 
338  if( error_msgs.GetCount() )
339  {
340  HTML_MESSAGE_BOX dlg( this, _( "Error List" ) );
341  dlg.ListSet( error_msgs );
342  dlg.ShowModal();
343  }
344 
345  return error_msgs.GetCount() == 0;
346 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
#define DIM(x)
of elements in an array
Definition: macros.h:98
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
Implementation of conversion functions that require both schematic and board internal units...
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
void SetStartY(int y)
Class BOARD to handle a board.
DIALOG_GRAPHIC_ITEM_PROPERTIES(PCB_EDIT_FRAME *aParent, DRAWSEGMENT *aItem, wxDC *aDC)
void InstallGraphicItemPropertiesDialog(DRAWSEGMENT *aItem, wxDC *aDC)
virtual void SetLayer(LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
usual segment : line with rounded ends
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:348
LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
wxFloatingPointValidator< double > m_AngleValidator
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true) override
Executes the changes.
This file contains miscellaneous commonly used macros and functions.
STROKE_T GetShape() const
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:751
void ListSet(const wxString &aList)
Function ListSet Add a list of items.
Arcs (with rounded ends)
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit)
Definition: base_units.cpp:479
Subclass of DIALOG_DISPLAY_HTML_TEXT_BASE, which is generated by wxFormBuilder.
int m_DrawSegmentWidth
current graphic line width (not EDGE layer)
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:368
void SetEndY(int y)
int SetLayerSelection(LAYER_NUM layer)
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
Class HTML_MESSAGE_BOX.
bool SetLayersHotkeys(bool value)
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
Definition: gr_basic.h:42
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void PutValueInLocalUnits(wxTextCtrl &aTextCtr, int aValue)
Function PutValueInLocalUnits converts aValue from internal units to user units and append the units ...
Definition: base_units.cpp:265
double GetAngle() const
LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:766
Class to handle a graphic segment.
virtual void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings)
void SetIgnoreMouseEvents(bool aIgnore)
LAYER_NUM GetLayerSelection() const
int GetWidth() const
void SetEndX(int x)
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
void SetStartX(int x)
Class DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE.
int m_EdgeSegmentWidth
current graphic line width (EDGE layer only)
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
void OnInitDlg(wxInitDialogEvent &event) override
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void SetWidth(int aWidth)