KiCad PCB EDA Suite
events_functions.cpp File Reference

page layout editor command event functions. More...

#include <fctsys.h>
#include <wx/treectrl.h>
#include <pgm_base.h>
#include <class_drawpanel.h>
#include <common.h>
#include <macros.h>
#include <pl_editor_frame.h>
#include <kicad_device_context.h>
#include <pl_editor_id.h>
#include <dialog_helpers.h>
#include <menus_helpers.h>
#include <worksheet_shape_builder.h>
#include <class_worksheet_dataitem.h>
#include <design_tree_frame.h>
#include <properties_frame.h>
#include <dialog_page_settings.h>
#include <invoke_pl_editor_dialog.h>

Go to the source code of this file.

Functions

 EVT_MENU_RANGE (ID_POPUP_START_RANGE, ID_POPUP_END_RANGE, PL_EDITOR_FRAME::Process_Special_Functions) void PL_EDITOR_FRAME
 
static void moveItem (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 
static void abortMoveItem (EDA_DRAW_PANEL *aPanel, wxDC *aDC)
 
void AddNewItemsCommand (wxMenu *aMainMenu)
 

Variables

DPOINT initialPosition
 
wxPoint initialPositionUi
 
wxPoint initialCursorPosition
 

Detailed Description

page layout editor command event functions.

Definition in file events_functions.cpp.

Function Documentation

static void abortMoveItem ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC 
)
static

Definition at line 386 of file events_functions.cpp.

References PL_EDITOR_SCREEN::GetCurItem(), WORKSHEET_DATAITEM::GetFlags(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), WORKSHEET_LAYOUT::GetTheInstance(), LOCATE_ENDPOINT, LOCATE_STARTPOINT, WORKSHEET_DATAITEM::MoveEndPointTo(), WORKSHEET_DATAITEM::MoveStartPointTo(), WORKSHEET_DATAITEM::MoveTo(), NEW_ITEM, PL_EDITOR_FRAME::RebuildDesignTree(), EDA_DRAW_PANEL::Refresh(), WORKSHEET_LAYOUT::Remove(), PL_EDITOR_FRAME::RemoveLastCommandInUndoList(), PL_EDITOR_SCREEN::SetCurItem(), and EDA_DRAW_PANEL::SetMouseCapture().

Referenced by PL_EDITOR_FRAME::MoveItem().

387 {
388  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
389  WORKSHEET_DATAITEM *item = screen->GetCurItem();
390 
391  if( item->GetFlags() & NEW_ITEM )
392  {
393  PL_EDITOR_FRAME* plframe = (PL_EDITOR_FRAME*) aPanel->GetParent();
394  plframe->RemoveLastCommandInUndoList();
396  pglayout.Remove( item );
397  plframe->RebuildDesignTree();
398  }
399  else
400  {
401  if( (item->GetFlags() & LOCATE_STARTPOINT) )
402  {
404  }
405  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
406  {
408  }
409  else
410  item->MoveTo( initialPosition );
411  }
412 
413  aPanel->SetMouseCapture( NULL, NULL );
414  screen->SetCurItem( NULL );
415  aPanel->Refresh();
416 }
WORKSHEET_DATAITEM * GetCurItem() const
Function GetCurItem returns the currently selected WORKSHEET_DATAITEM, overriding BASE_SCREEN::GetCur...
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:325
void RemoveLastCommandInUndoList()
Remove the last command in Undo List.
void SetCurItem(WORKSHEET_DATAITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
void MoveEndPointTo(DPOINT aPosition)
move the ending point of the item to a new position has meaning only for items defined by 2 points (s...
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application ...
void MoveStartPointTo(DPOINT aPosition)
move the starting point of the item to a new position
DPOINT initialPosition
bool Remove(unsigned aIdx)
Remove the item to the list of items at position aIdx.
void MoveTo(DPOINT aPosition)
move item to a new position
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
#define NEW_ITEM
#define LOCATE_STARTPOINT
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
void RebuildDesignTree()
Function RebuildDesignTree Re creates the design graphic tree list items, and ensures each item has a...
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
#define LOCATE_ENDPOINT
void AddNewItemsCommand ( wxMenu *  aMainMenu)

Definition at line 43 of file pagelayout_editor/onrightclick.cpp.

References AddMenuItem(), ID_POPUP_ITEM_ADD_BITMAP, ID_POPUP_ITEM_ADD_LINE, ID_POPUP_ITEM_ADD_RECT, ID_POPUP_ITEM_ADD_TEXT, ID_POPUP_ITEM_APPEND_PAGE_LAYOUT, KiBitmap(), and text_xpm.

Referenced by PL_EDITOR_FRAME::OnRightClick(), and PL_EDITOR_FRAME::OnTreeRightClick().

44 {
45  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_LINE, _( "Add Line" ),
46  KiBitmap( add_dashed_line_xpm ) );
47  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_RECT, _( "Add Rectangle" ),
48  KiBitmap( add_rectangle_xpm ) );
49  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_TEXT, _( "Add Text" ),
50  KiBitmap( text_xpm ) );
51  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "Add Bitmap" ),
52  KiBitmap( image_xpm ) );
54  _( "Append Existing Page Layout Design File" ),
55  KiBitmap( pagelayout_load_xpm ) );
56 }
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:55
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
static const char * text_xpm[]

Definition at line 103 of file events_functions.cpp.

References WORKSHEET_DATAITEM::ClearFlags(), DIALOG_PAGES_SETTINGS::EnableWksFileNamePicker(), WORKSHEET_LAYOUT::GetItem(), WORKSHEET_LAYOUT::GetItemIndex(), WORKSHEET_DATAITEM::GetStartPosUi(), WORKSHEET_LAYOUT::GetTheInstance(), ID_POPUP_CANCEL_CURRENT_COMMAND, ID_POPUP_DESIGN_TREE_ITEM_DELETE, ID_POPUP_ITEM_ADD_BITMAP, ID_POPUP_ITEM_ADD_LINE, ID_POPUP_ITEM_ADD_RECT, ID_POPUP_ITEM_ADD_TEXT, ID_POPUP_ITEM_APPEND_PAGE_LAYOUT, ID_POPUP_ITEM_DELETE, ID_POPUP_ITEM_MOVE, ID_POPUP_ITEM_MOVE_END_POINT, ID_POPUP_ITEM_MOVE_START_POINT, ID_POPUP_ITEM_PLACE, ID_POPUP_ITEM_PLACE_CANCEL, ID_ZOOM_PAGE, InvokeDialogNewItem(), LOCATE_ENDPOINT, LOCATE_STARTPOINT, NEW_ITEM, WORKSHEET_LAYOUT::Remove(), WORKSHEET_DATAITEM::SetFlags(), DIALOG_PAGES_SETTINGS::SetWksFileName(), WORKSHEET_DATAITEM::WS_BITMAP, WORKSHEET_DATAITEM::WS_RECT, WORKSHEET_DATAITEM::WS_SEGMENT, and WORKSHEET_DATAITEM::WS_TEXT.

118 {
119  int id = event.GetId();
120  int idx;
121  wxString msg;
123  WORKSHEET_DATAITEM* item = NULL;
124  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
125  cmd.SetEventObject( this );
126 
127  switch( id )
128  {
129  case ID_NO_TOOL_SELECTED:
130  SetNoToolSelected();
131  break;
132 
133  case ID_ZOOM_SELECTION:
134  // This tool is located on the main toolbar: switch it on or off on click
135  if( GetToolId() != ID_ZOOM_SELECTION )
136  SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
137  else
138  SetNoToolSelected();
139  break;
140 
142  m_canvas->Refresh();
143  break;
144 
145  case ID_SHEET_SET:
146  {
147  DIALOG_PAGES_SETTINGS dlg( this );
148  dlg.SetWksFileName( GetCurrFileName() );
149  dlg.EnableWksFileNamePicker( false );
150  dlg.ShowModal();
151 
152  cmd.SetId( ID_ZOOM_PAGE );
153  wxPostEvent( this, cmd );
154  }
155  break;
156 
158  break;
159 
162  case wxID_CUT:
163  // Delete item, and select the previous item
164  item = m_treePagelayout->GetPageLayoutSelectedItem();
165 
166  if( item == NULL )
167  break;
168 
169  SaveCopyInUndoList();
170  idx = pglayout.GetItemIndex( item );
171  pglayout.Remove( item );
172  RebuildDesignTree();
173 
175  {
176  item = pglayout.GetItem( (unsigned) (idx-1) );
177 
178  if( item )
179  m_treePagelayout->SelectCell( item );
180  }
181 
182  item = NULL;
183  OnModify();
184  m_canvas->Refresh();
185  break;
186 
188  SaveCopyInUndoList();
189  idx = m_treePagelayout->GetSelectedItemIndex();
190  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_SEGMENT, idx );
191 
192  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
193  {
194  RemoveLastCommandInUndoList();
195  pglayout.Remove( item );
196  RebuildDesignTree();
197  item = NULL;
198  }
199  else
200  {
201  // Put the new item in move mode, after putting the cursor
202  // on the start point:
203  wxPoint position = item->GetStartPosUi();
204  SetCrossHairPosition( position, false );
205  position = GetCrossHairPosition();
206 
207  if( m_canvas->IsPointOnDisplay( position ) )
208  m_canvas->MoveCursorToCrossHair();
209  else
210  RedrawScreen( position, true );
211 
212  item->SetFlags( NEW_ITEM );
213  MoveItem( item );
214  }
215  break;
216 
218  SaveCopyInUndoList();
219  idx = m_treePagelayout->GetSelectedItemIndex();
220  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_RECT, idx );
221 
222  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
223  {
224  RemoveLastCommandInUndoList();
225  pglayout.Remove( item );
226  RebuildDesignTree();
227  item = NULL;
228  }
229  else
230  {
231  // Put the new item in move mode, after putting the cursor
232  // on the start point:
233  wxPoint position = item->GetStartPosUi();
234  SetCrossHairPosition( position, false );
235  position = GetCrossHairPosition();
236 
237  if( m_canvas->IsPointOnDisplay( position ) )
238  m_canvas->MoveCursorToCrossHair();
239  else
240  RedrawScreen( position, true );
241 
242  item->SetFlags( NEW_ITEM );
243  MoveItem( item );
244  }
245  break;
246 
248  SaveCopyInUndoList();
249  idx = m_treePagelayout->GetSelectedItemIndex();
250  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_TEXT, idx );
251  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
252  {
253  RemoveLastCommandInUndoList();
254  pglayout.Remove( item );
255  RebuildDesignTree();
256  item = NULL;
257  }
258  else
259  {
260  // Put the new text in move mode:
262  MoveItem( item );
263  }
264  break;
265 
267  SaveCopyInUndoList();
268  idx = m_treePagelayout->GetSelectedItemIndex();
269  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_BITMAP, idx );
270  if( item && InvokeDialogNewItem( this, item ) == wxID_CANCEL )
271  {
272  RemoveLastCommandInUndoList();
273  pglayout.Remove( item );
274  RebuildDesignTree();
275  item = NULL;
276  }
277  if( item )
278  {
279  // Put the new text in move mode:
281  MoveItem( item );
282  }
283  break;
284 
286  cmd.SetId( ID_APPEND_DESCR_FILE );
287  wxPostEvent( this, cmd );
288  break;
289 
290  case ID_POPUP_ITEM_PLACE:
291  item = GetScreen()->GetCurItem();
292  PlaceItem( item );
293  break;
294 
296  if( m_canvas->IsMouseCaptured() )
297  m_canvas->EndMouseCapture();
298  break;
299 
301  item = m_treePagelayout->GetPageLayoutSelectedItem();
302  // Ensure flags are properly set
303  item->ClearFlags( LOCATE_ENDPOINT );
304  item->SetFlags( LOCATE_STARTPOINT );
305  MoveItem( item );
306  break;
307 
309  item = m_treePagelayout->GetPageLayoutSelectedItem();
310  // Ensure flags are properly set
311  item->ClearFlags( LOCATE_STARTPOINT );
312  item->SetFlags( LOCATE_ENDPOINT );
313  MoveItem( item );
314  break;
315 
316  case ID_POPUP_ITEM_MOVE:
317  item = m_treePagelayout->GetPageLayoutSelectedItem();
319  MoveItem( item );
320  break;
321 
322  default:
323  wxMessageBox( wxT( "PL_EDITOR_FRAME::Process_Special_Functions error" ) );
324  break;
325  }
326 
327  if( item )
328  {
329  OnModify();
330  m_propertiesPagelayout->CopyPrmsFromItemToPanel( item );
331  m_treePagelayout->SelectCell( item );
332  }
333 
334 }
const wxPoint GetStartPosUi(int ii=0) const
int GetItemIndex(WORKSHEET_DATAITEM *aItem) const
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application ...
WORKSHEET_DATAITEM * GetItem(unsigned aIdx) const
bool Remove(unsigned aIdx)
Remove the item to the list of items at position aIdx.
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
#define NEW_ITEM
#define LOCATE_STARTPOINT
int InvokeDialogNewItem(PL_EDITOR_FRAME *aCaller, WORKSHEET_DATAITEM *aItem)
Create and show DIALOG_NEW_DATAITEM and return whatever DIALOG_NEW_DATAITEM::ShowModal() returns...
#define LOCATE_ENDPOINT
static void moveItem ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 346 of file events_functions.cpp.

References EDA_DRAW_FRAME::GetCrossHairPosition(), PL_EDITOR_SCREEN::GetCurItem(), WORKSHEET_DATAITEM::GetEndPosUi(), WORKSHEET_DATAITEM::GetFlags(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), WORKSHEET_DATAITEM::GetStartPosUi(), initialPositionUi, LOCATE_ENDPOINT, LOCATE_STARTPOINT, WORKSHEET_DATAITEM::MoveEndPointToUi(), WORKSHEET_DATAITEM::MoveStartPointToUi(), WORKSHEET_DATAITEM::MoveToUi(), and EDA_DRAW_PANEL::Refresh().

Referenced by PL_EDITOR_FRAME::MoveItem().

347 {
348  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
349  WORKSHEET_DATAITEM *item = screen->GetCurItem();
350 
351  wxCHECK_RET( (item != NULL), wxT( "Cannot move NULL item." ) );
352  wxPoint position = aPanel->GetParent()->GetCrossHairPosition()
354  wxPoint previous_position;
355 
356  if( (item->GetFlags() & LOCATE_STARTPOINT) )
357  {
358  previous_position = item->GetStartPosUi();
359  item->MoveStartPointToUi( position );
360  }
361  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
362  {
363  previous_position = item->GetEndPosUi();
364  item->MoveEndPointToUi( position );
365  }
366  else
367  {
368  previous_position = item->GetStartPosUi();
369  item->MoveToUi( position );
370  }
371 
372  // Draw the item item at it's new position, if it is modified,
373  // (does not happen each time the mouse is moved, because the
374  // item is placed on grid)
375  // to avoid useless computation time.
376  if( previous_position != position )
377  aPanel->Refresh();
378 }
WORKSHEET_DATAITEM * GetCurItem() const
Function GetCurItem returns the currently selected WORKSHEET_DATAITEM, overriding BASE_SCREEN::GetCur...
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:325
const wxPoint GetStartPosUi(int ii=0) const
void MoveToUi(wxPoint aPosition)
move item to a new position
wxPoint initialPositionUi
wxPoint initialCursorPosition
const wxPoint GetEndPosUi(int ii=0) const
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
#define LOCATE_STARTPOINT
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
void MoveEndPointToUi(wxPoint aPosition)
move the ending point of the item to a new position has meaning only for items defined by 2 points (s...
#define LOCATE_ENDPOINT
void MoveStartPointToUi(wxPoint aPosition)
move the starting point of the item to a new position
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...

Variable Documentation

wxPoint initialCursorPosition

Definition at line 344 of file events_functions.cpp.

DPOINT initialPosition

Definition at line 342 of file events_functions.cpp.

wxPoint initialPositionUi

Definition at line 343 of file events_functions.cpp.

Referenced by moveItem().