KiCad PCB EDA Suite
dialog_graphic_item_properties_for_Modedit.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) 2012-2014 Jean-Pierre Charras, jean-pierre.charras at 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 in a footprint body:
30  * Lines
31  * Circles
32  * Arcs
33  * used as graphic elements found on non copper layers in boards
34  * Footprint texts are not graphic items and are not handled here
35  */
36 #include <fctsys.h>
37 #include <macros.h>
38 #include <confirm.h>
39 #include <class_drawpanel.h>
40 #include <pcbnew.h>
41 #include <wxPcbStruct.h>
43 #include <module_editor_frame.h>
44 #include <base_units.h>
45 #include <wx/valnum.h>
46 #include <board_commit.h>
47 
48 #include <class_board.h>
49 #include <class_module.h>
50 #include <class_edge_mod.h>
51 
54 #include <html_messagebox.h>
55 
57 {
58 private:
63 
64  wxFloatingPointValidator<double> m_AngleValidator;
65  double m_AngleValue;
66 
67 public:
69  EDGE_MODULE* aItem );
71 
72 private:
73  bool TransferDataToWindow() override;
74  bool TransferDataFromWindow() override;
75  void OnLayerChoice( wxCommandEvent& event );
76  bool Validate() override;
77 };
78 
80  FOOTPRINT_EDIT_FRAME* aParent,
81  EDGE_MODULE * aItem ):
83  m_AngleValidator( 1, &m_AngleValue ),
84  m_AngleValue( 0.0 )
85 {
86  m_parent = aParent;
87  m_item = aItem;
90 
91  m_AngleValidator.SetRange( -360.0, 360.0 );
92  m_AngleCtrl->SetValidator( m_AngleValidator );
93  m_AngleValidator.SetWindow( m_AngleCtrl );
94 
95  SetFocus();
96  m_StandardButtonsSizerOK->SetDefault();
97 
98  Layout();
99  GetSizer()->SetSizeHints( this );
100  Centre();
101 }
102 
103 
104 /*
105  * Dialog to edit a graphic item of a footprint body.
106  */
108 {
109  if( aItem == NULL )
110  {
111  wxMessageBox( wxT( "InstallGraphicItemPropertiesDialog() error: NULL item" ) );
112  return;
113  }
114 
117  new DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES( this, aItem );
118  dialog->ShowModal();
119  dialog->Destroy();
121  m_canvas->SetIgnoreMouseEvents( false );
122 }
123 
124 
126 {
127  // Set unit symbol
128  wxStaticText* texts_unit[] =
129  {
136  };
137 
138  for( size_t ii = 0; ii < DIM( texts_unit ); ii++ )
139  {
140  texts_unit[ii]->SetLabel( GetAbbreviatedUnitsLabel() );
141  }
142 
143  wxString msg;
144 
145  // Change texts according to the segment shape:
146  switch( m_item->GetShape() )
147  {
148  case S_CIRCLE:
149  SetTitle( _( "Circle Properties" ) );
150  m_StartPointXLabel->SetLabel( _( "Center X" ) );
151  m_StartPointYLabel->SetLabel( _( "Center Y" ) );
152  m_EndPointXLabel->SetLabel( _( "Point X" ) );
153  m_EndPointYLabel->SetLabel( _( "Point Y" ) );
154  m_AngleText->Show( false );
155  m_AngleCtrl->Show( false );
156  m_AngleUnit->Show( false );
157  break;
158 
159  case S_ARC:
160  SetTitle( _( "Arc Properties" ) );
161  m_StartPointXLabel->SetLabel( _( "Center X" ) );
162  m_StartPointYLabel->SetLabel( _( "Center Y" ) );
163  m_EndPointXLabel->SetLabel( _( "Start Point X" ) );
164  m_EndPointYLabel->SetLabel( _( "Start Point Y" ) );
165 
166  m_AngleValue = m_item->GetAngle() / 10.0;
167  break;
168 
169  case S_SEGMENT:
170  SetTitle( _( "Line Segment Properties" ) );
171 
172  // Fall through.
173  default:
174  m_AngleText->Show( false );
175  m_AngleCtrl->Show( false );
176  m_AngleUnit->Show( false );
177  break;
178  }
179 
181 
183 
185 
187 
189 
191 
192  // Configure the layers list selector
197 
199  {
200  wxMessageBox( _( "This item was on an unknown layer.\n"
201  "It has been moved to the front silk screen layer. Please fix it." ) );
203  }
204 
205  return DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::TransferDataToWindow();
206 }
207 
208 
210 {
211 }
212 
213 
215 {
216  BOARD_COMMIT commit( m_parent );
217  commit.Modify( m_module );
218 
219  if( !DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::TransferDataFromWindow() )
220  return false;
221 
223 
224  if( IsCopperLayer( layer ) )
225  {
226  /* an edge is put on a copper layer: this it is very dangerous. a
227  * confirmation is requested */
228  if( !IsOK( NULL,
229  _( "The graphic item will be on a copper layer. This is very dangerous. Are you sure?" ) ) )
230  return false;
231  }
232 
233  wxString msg;
234  wxPoint coord;
235 
236  msg = m_Center_StartXCtrl->GetValue();
237  coord.x = ValueFromString( g_UserUnit, msg );
238  msg = m_Center_StartYCtrl->GetValue();
239  coord.y = ValueFromString( g_UserUnit, msg );
240  m_item->SetStart( coord );
241  m_item->SetStart0( coord );
242 
243  msg = m_EndX_Radius_Ctrl->GetValue();
244  coord.x = ValueFromString( g_UserUnit, msg );
245  msg = m_EndY_Ctrl->GetValue();
246  coord.y = ValueFromString( g_UserUnit, msg );
247  m_item->SetEnd( coord );
248  m_item->SetEnd0( coord );
249 
250  msg = m_ThicknessCtrl->GetValue();
252 
253  msg = m_DefaultThicknessCtrl->GetValue();
254  int thickness = ValueFromString( g_UserUnit, msg );
257 
258  m_item->SetLayer( ToLAYER_ID( layer ) );
259 
260  if( m_item->GetShape() == S_ARC )
261  {
262  m_item->SetAngle( m_AngleValue * 10.0 );
263  }
264 
265  commit.Push( _( "Modify module graphic item" ) );
266 
268 
269  return true;
270 }
271 
272 
274 {
275  wxArrayString error_msgs;
276 
277  if( !DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE::Validate() )
278  return false;
279 
280  // Load the start and end points -- all types use these in the checks.
281  int startx = ValueFromString( g_UserUnit, m_Center_StartXCtrl->GetValue() );
282  int starty = ValueFromString( g_UserUnit, m_Center_StartYCtrl->GetValue() );
283  int endx = ValueFromString( g_UserUnit, m_EndX_Radius_Ctrl->GetValue() );
284  int endy = ValueFromString( g_UserUnit, m_EndY_Ctrl->GetValue() );
285 
286  // Type specific checks.
287  switch( m_item->GetShape() )
288  {
289  case S_ARC:
290  // Check angle of arc.
291  double angle;
292  m_AngleCtrl->GetValue().ToDouble( &angle );
293  angle = NormalizeAngle360( angle );
294 
295  if( angle == 0 )
296  {
297  error_msgs.Add( _( "The arc angle must be greater than zero." ) );
298  }
299 
300  // Fall through.
301  case S_CIRCLE:
302 
303  // Check radius.
304  if( (startx == endx) && (starty == endy) )
305  error_msgs.Add( _( "The radius must be greater than zero." ) );
306 
307  break;
308 
309  default:
310 
311  // Check start and end are not the same.
312  if( (startx == endx) && (starty == endy) )
313  error_msgs.Add( _( "The start and end points cannot be the same." ) );
314 
315  break;
316  }
317 
318  // Check the item thickness.
319  int thickness = ValueFromString( g_UserUnit, m_ThicknessCtrl->GetValue() );
320 
321  if( thickness <= 0 )
322  error_msgs.Add( _( "The item thickness must be greater than zero." ) );
323 
324  // And the default thickness.
325  thickness = ValueFromString( g_UserUnit, m_DefaultThicknessCtrl->GetValue() );
326 
327  if( thickness <= 0 )
328  error_msgs.Add( _( "The default thickness must be greater than zero." ) );
329 
330  if( error_msgs.GetCount() )
331  {
332  HTML_MESSAGE_BOX dlg( this, _( "Error list" ) );
333  dlg.ListSet( error_msgs );
334  dlg.ShowModal();
335  }
336 
337  return error_msgs.GetCount() == 0;
338 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
void SetEnd0(const wxPoint &aPoint)
Definition of class FOOTPRINT_EDIT_FRAME.
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Implementation of conversion functions that require both schematic and board internal units...
This file is part of the common library.
int m_ModuleSegmentWidth
Default width for all graphic lines.
Class BOARD to handle a board.
BOARD * GetBoard() const
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
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:773
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 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
static LSET InternalCuMask()
Function InternalCuMask() returns a complete set of internal copper layers, which is all Cu layers ex...
Definition: lset.cpp:599
int SetLayerSelection(LAYER_NUM layer)
Class HTML_MESSAGE_BOX.
bool SetLayersHotkeys(bool value)
void SetStart(const wxPoint &aStart)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings) override
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
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
double GetAngle() const
DLIST< MODULE > m_Modules
Definition: class_board.h:245
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetIgnoreMouseEvents(bool aIgnore)
LAYER_NUM GetLayerSelection() const
void SetStart0(const wxPoint &aPoint)
int GetWidth() const
void SetEnd(const wxPoint &aEnd)
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
Module description (excepted pads)
Class DIALOG_GRAPHIC_ITEM_PROPERTIES_BASE.
EDGE_MODULE class definition.
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
void InstallFootprintBodyItemPropertiesDlg(EDGE_MODULE *aItem)
Function InstallFootprintBodyItemPropertiesDlg Install a dialog to edit a graphic item of a footprint...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:129
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:767
T NormalizeAngle360(T Angle)
Normalize angle to be in the -360.0 .. 360.0:
Definition: trigo.h:202
DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES(FOOTPRINT_EDIT_FRAME *aParent, EDGE_MODULE *aItem)
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
void SetWidth(int aWidth)