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 <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 398 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().

399 {
400  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
401  WORKSHEET_DATAITEM *item = screen->GetCurItem();
402 
403  if( item->GetFlags() & NEW_ITEM )
404  {
405  PL_EDITOR_FRAME* plframe = (PL_EDITOR_FRAME*) aPanel->GetParent();
406  plframe->RemoveLastCommandInUndoList();
408  pglayout.Remove( item );
409  plframe->RebuildDesignTree();
410  }
411  else
412  {
413  if( (item->GetFlags() & LOCATE_STARTPOINT) )
414  {
416  }
417  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
418  {
420  }
421  else
422  item->MoveTo( initialPosition );
423  }
424 
425  aPanel->SetMouseCapture( NULL, NULL );
426  screen->SetCurItem( NULL );
427  aPanel->Refresh();
428 }
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:338
void RemoveLastCommandInUndoList()
Remove the last command in Undo List.
void SetCurItem(WORKSHEET_DATAITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
#define LOCATE_STARTPOINT
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...
#define LOCATE_ENDPOINT
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application ...
#define NEW_ITEM
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:180
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:193
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...
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(), PL_EDITOR_FRAME::OnTreeMiddleClick(), 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:174
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
static const char * text_xpm[]

Definition at line 105 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_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.

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

Definition at line 358 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().

359 {
360  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
361  WORKSHEET_DATAITEM *item = screen->GetCurItem();
362 
363  wxCHECK_RET( (item != NULL), wxT( "Cannot move NULL item." ) );
364  wxPoint position = aPanel->GetParent()->GetCrossHairPosition()
366  wxPoint previous_position;
367 
368  if( (item->GetFlags() & LOCATE_STARTPOINT) )
369  {
370  previous_position = item->GetStartPosUi();
371  item->MoveStartPointToUi( position );
372  }
373  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
374  {
375  previous_position = item->GetEndPosUi();
376  item->MoveEndPointToUi( position );
377  }
378  else
379  {
380  previous_position = item->GetStartPosUi();
381  item->MoveToUi( position );
382  }
383 
384  // Draw the item item at it's new position, if it is modified,
385  // (does not happen each time the mouse is moved, because the
386  // item is placed on grid)
387  // to avoid useless computation time.
388  if( previous_position != position )
389  aPanel->Refresh();
390 }
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:338
#define LOCATE_STARTPOINT
const wxPoint GetStartPosUi(int ii=0) const
#define LOCATE_ENDPOINT
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:180
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:193
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...
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 356 of file events_functions.cpp.

DPOINT initialPosition

Definition at line 354 of file events_functions.cpp.

wxPoint initialPositionUi

Definition at line 355 of file events_functions.cpp.

Referenced by moveItem().