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

◆ abortMoveItem()

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

Definition at line 396 of file events_functions.cpp.

397 {
398  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
399  WORKSHEET_DATAITEM *item = screen->GetCurItem();
400 
401  if( item->GetFlags() & NEW_ITEM )
402  {
403  PL_EDITOR_FRAME* plframe = (PL_EDITOR_FRAME*) aPanel->GetParent();
404  plframe->RemoveLastCommandInUndoList();
406  pglayout.Remove( item );
407  plframe->RebuildDesignTree();
408  }
409  else
410  {
411  if( (item->GetFlags() & LOCATE_STARTPOINT) )
412  {
414  }
415  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
416  {
418  }
419  else
420  item->MoveTo( initialPosition );
421  }
422 
423  aPanel->SetMouseCapture( NULL, NULL );
424  screen->SetCurItem( NULL );
425  aPanel->Refresh();
426 }
virtual BASE_SCREEN * GetScreen()=0
void RemoveLastCommandInUndoList()
Remove the last command in Undo List.
Class PL_EDITOR_FRAME is the main window used in the page layout editor.
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...
WORKSHEET_DATAITEM * GetCurItem() const
Function GetCurItem returns the currently selected WORKSHEET_DATAITEM, overriding BASE_SCREEN::GetCur...
#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
virtual EDA_DRAW_FRAME * GetParent() const =0
DPOINT initialPosition
bool Remove(unsigned aIdx)
Remove the item to the list of items at position aIdx.
virtual 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 MoveTo(DPOINT aPosition)
move item to a new position
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
void RebuildDesignTree()
Function RebuildDesignTree Re creates the design graphic tree list items, and ensures each item has a...
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)

References PL_EDITOR_SCREEN::GetCurItem(), WORKSHEET_DATAITEM::GetFlags(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), WORKSHEET_LAYOUT::GetTheInstance(), initialPosition, 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().

◆ AddNewItemsCommand()

void AddNewItemsCommand ( wxMenu *  aMainMenu)

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

45 {
46  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_LINE, _( "Add Line..." ),
47  KiBitmap( add_dashed_line_xpm ) );
48  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_RECT, _( "Add Rectangle..." ),
49  KiBitmap( add_rectangle_xpm ) );
50  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_TEXT, _( "Add Text..." ),
51  KiBitmap( text_xpm ) );
52  AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "Add Bitmap..." ),
53  KiBitmap( image_xpm ) );
55  _( "Append Existing Page Layout Design File..." ),
56  KiBitmap( pagelayout_load_xpm ) );
57 }
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:251
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
static const char * text_xpm[]

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

◆ EVT_MENU_RANGE()

Definition at line 103 of file events_functions.cpp.

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  {
149  dlg.SetWksFileName( GetCurrFileName() );
150  dlg.EnableWksFileNamePicker( false );
151  dlg.ShowModal();
152 
153  cmd.SetId( ID_ZOOM_PAGE );
154  wxPostEvent( this, cmd );
155  }
156  break;
157 
159  if( m_canvas->IsMouseCaptured() )
160  {
161  m_canvas->EndMouseCapture();
162  SetToolID( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString );
163  }
164  else
165  {
166  SetNoToolSelected();
167  }
168  break;
169 
172  case wxID_DELETE:
173  // Delete item, and select the previous item
174  item = m_treePagelayout->GetPageLayoutSelectedItem();
175 
176  if( item == NULL )
177  break;
178 
179  SaveCopyInUndoList();
180  idx = pglayout.GetItemIndex( item );
181  pglayout.Remove( item );
182  RebuildDesignTree();
183 
185  {
186  item = pglayout.GetItem( (unsigned) (idx-1) );
187 
188  if( item )
189  m_treePagelayout->SelectCell( item );
190  }
191 
192  item = NULL;
193  OnModify();
194  m_canvas->Refresh();
195  break;
196 
198  SaveCopyInUndoList();
199  idx = m_treePagelayout->GetSelectedItemIndex();
200  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_SEGMENT, idx );
201 
202  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
203  {
204  RemoveLastCommandInUndoList();
205  pglayout.Remove( item );
206  RebuildDesignTree();
207  item = NULL;
208  }
209  else
210  {
211  // Put the new item in move mode, after putting the cursor
212  // on the start point:
213  wxPoint position = item->GetStartPosUi();
214  SetCrossHairPosition( position, false );
215  position = GetCrossHairPosition();
216 
217  if( m_canvas->IsPointOnDisplay( position ) )
218  m_canvas->MoveCursorToCrossHair();
219  else
220  RedrawScreen( position, true );
221 
222  item->SetFlags( NEW_ITEM );
223  MoveItem( item );
224  }
225  break;
226 
228  SaveCopyInUndoList();
229  idx = m_treePagelayout->GetSelectedItemIndex();
230  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_RECT, idx );
231 
232  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
233  {
234  RemoveLastCommandInUndoList();
235  pglayout.Remove( item );
236  RebuildDesignTree();
237  item = NULL;
238  }
239  else
240  {
241  // Put the new item in move mode, after putting the cursor
242  // on the start point:
243  wxPoint position = item->GetStartPosUi();
244  SetCrossHairPosition( position, false );
245  position = GetCrossHairPosition();
246 
247  if( m_canvas->IsPointOnDisplay( position ) )
248  m_canvas->MoveCursorToCrossHair();
249  else
250  RedrawScreen( position, true );
251 
252  item->SetFlags( NEW_ITEM );
253  MoveItem( item );
254  }
255  break;
256 
258  SaveCopyInUndoList();
259  idx = m_treePagelayout->GetSelectedItemIndex();
260  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_TEXT, idx );
261  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
262  {
263  RemoveLastCommandInUndoList();
264  pglayout.Remove( item );
265  RebuildDesignTree();
266  item = NULL;
267  }
268  else
269  {
270  // Put the new text in move mode:
272  MoveItem( item );
273  }
274  break;
275 
277  SaveCopyInUndoList();
278  idx = m_treePagelayout->GetSelectedItemIndex();
279  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_BITMAP, idx );
280  if( item && InvokeDialogNewItem( this, item ) == wxID_CANCEL )
281  {
282  RemoveLastCommandInUndoList();
283  pglayout.Remove( item );
284  RebuildDesignTree();
285  item = NULL;
286  }
287  if( item )
288  {
289  // Put the new text in move mode:
291  MoveItem( item );
292  }
293  break;
294 
296  cmd.SetId( ID_APPEND_DESCR_FILE );
297  wxPostEvent( this, cmd );
298  break;
299 
300  case ID_POPUP_ITEM_PLACE:
301  item = GetScreen()->GetCurItem();
302  PlaceItem( item );
303  break;
304 
306  if( m_canvas->IsMouseCaptured() )
307  m_canvas->EndMouseCapture();
308  break;
309 
311  item = m_treePagelayout->GetPageLayoutSelectedItem();
312  // Ensure flags are properly set
313  item->ClearFlags( LOCATE_ENDPOINT );
314  item->SetFlags( LOCATE_STARTPOINT );
315  MoveItem( item );
316  break;
317 
319  item = m_treePagelayout->GetPageLayoutSelectedItem();
320  // Ensure flags are properly set
321  item->ClearFlags( LOCATE_STARTPOINT );
322  item->SetFlags( LOCATE_ENDPOINT );
323  MoveItem( item );
324  break;
325 
326  case ID_POPUP_ITEM_MOVE:
327  item = m_treePagelayout->GetPageLayoutSelectedItem();
329  MoveItem( item );
330  break;
331 
332  default:
333  wxMessageBox( wxT( "PL_EDITOR_FRAME::Process_Special_Functions error" ) );
334  break;
335  }
336 
337  if( item )
338  {
339  OnModify();
340  m_propertiesPagelayout->CopyPrmsFromItemToPanel( item );
341  m_treePagelayout->SelectCell( item );
342  }
343 
344 }
int GetItemIndex(WORKSHEET_DATAITEM *aItem) const
const wxPoint GetStartPosUi(int ii=0) const
#define LOCATE_STARTPOINT
void ClearFlags(int aMask)
#define LOCATE_ENDPOINT
static WORKSHEET_LAYOUT & GetTheInstance()
static function: returns the instance of WORKSHEET_LAYOUT used in the application
#define NEW_ITEM
void SetFlags(int aMask)
bool Remove(unsigned aIdx)
Remove the item to the list of items at position aIdx.
WORKSHEET_DATAITEM * GetItem(unsigned aIdx) const
#define MAX_PAGE_SIZE_EDITORS_MILS
Definition: page_info.h:41
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.

References WORKSHEET_DATAITEM::ClearFlags(), DIALOG_PAGES_SETTINGS::EnableWksFileNamePicker(), WORKSHEET_LAYOUT::GetItem(), WORKSHEET_LAYOUT::GetItemIndex(), WORKSHEET_DATAITEM::GetStartPosUi(), WORKSHEET_LAYOUT::GetTheInstance(), ID_APPEND_DESCR_FILE, ID_NO_TOOL_SELECTED, 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_SELECT_PAGE_NUMBER, ID_SHEET_SET, ID_ZOOM_PAGE, ID_ZOOM_SELECTION, InvokeDialogNewItem(), LOCATE_ENDPOINT, LOCATE_STARTPOINT, MAX_PAGE_SIZE_EDITORS_MILS, 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.

◆ moveItem()

static void moveItem ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint &  aPosition,
bool  aErase 
)
static

Definition at line 356 of file events_functions.cpp.

357 {
358  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
359  WORKSHEET_DATAITEM *item = screen->GetCurItem();
360 
361  wxCHECK_RET( (item != NULL), wxT( "Cannot move NULL item." ) );
362  wxPoint position = aPanel->GetParent()->GetCrossHairPosition()
364  wxPoint previous_position;
365 
366  if( (item->GetFlags() & LOCATE_STARTPOINT) )
367  {
368  previous_position = item->GetStartPosUi();
369  item->MoveStartPointToUi( position );
370  }
371  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
372  {
373  previous_position = item->GetEndPosUi();
374  item->MoveEndPointToUi( position );
375  }
376  else
377  {
378  previous_position = item->GetStartPosUi();
379  item->MoveToUi( position );
380  }
381 
382  // Draw the item item at it's new position, if it is modified,
383  // (does not happen each time the mouse is moved, because the
384  // item is placed on grid)
385  // to avoid useless computation time.
386  if( previous_position != position )
387  aPanel->Refresh();
388 }
virtual BASE_SCREEN * GetScreen()=0
const wxPoint GetStartPosUi(int ii=0) const
#define LOCATE_STARTPOINT
WORKSHEET_DATAITEM * GetCurItem() const
Function GetCurItem returns the currently selected WORKSHEET_DATAITEM, overriding BASE_SCREEN::GetCur...
#define LOCATE_ENDPOINT
virtual EDA_DRAW_FRAME * GetParent() const =0
void MoveToUi(wxPoint aPosition)
move item to a new position
wxPoint initialPositionUi
wxPoint initialCursorPosition
const wxPoint GetEndPosUi(int ii=0) const
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...
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void MoveStartPointToUi(wxPoint aPosition)
move the starting point of the item to a new position
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.

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(), initialCursorPosition, 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().

Variable Documentation

◆ initialCursorPosition

wxPoint initialCursorPosition

Definition at line 354 of file events_functions.cpp.

Referenced by moveItem(), and PL_EDITOR_FRAME::MoveItem().

◆ initialPosition

DPOINT initialPosition

◆ initialPositionUi

wxPoint initialPositionUi

Definition at line 353 of file events_functions.cpp.

Referenced by moveItem(), and PL_EDITOR_FRAME::MoveItem().