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

388 {
389  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
390  WORKSHEET_DATAITEM *item = screen->GetCurItem();
391 
392  if( item->GetFlags() & NEW_ITEM )
393  {
394  PL_EDITOR_FRAME* plframe = (PL_EDITOR_FRAME*) aPanel->GetParent();
395  plframe->RemoveLastCommandInUndoList();
397  pglayout.Remove( item );
398  plframe->RebuildDesignTree();
399  }
400  else
401  {
402  if( (item->GetFlags() & LOCATE_STARTPOINT) )
403  {
405  }
406  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
407  {
409  }
410  else
411  item->MoveTo( initialPosition );
412  }
413 
414  aPanel->SetMouseCapture( NULL, NULL );
415  screen->SetCurItem( NULL );
416  aPanel->Refresh();
417 }
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
Definition: draw_panel.cpp:326
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:175
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:188
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 ) );
52  _( "Append Page Layout Descr File" ),
53  KiBitmap( import_xpm ) );
55  _( "Add Bitmap" ),
56  KiBitmap( image_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: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 104 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.

119 {
120  int id = event.GetId();
121  int idx;
122  wxString msg;
124  WORKSHEET_DATAITEM* item = NULL;
125  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
126  cmd.SetEventObject( this );
127 
128  switch( id )
129  {
130  case ID_NO_TOOL_SELECTED:
131  SetNoToolSelected();
132  break;
133 
134  case ID_ZOOM_SELECTION:
135  // This tool is located on the main toolbar: switch it on or off on click
136  if( GetToolId() != ID_ZOOM_SELECTION )
137  SetToolID( ID_ZOOM_SELECTION, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
138  else
139  SetNoToolSelected();
140  break;
141 
143  m_canvas->Refresh();
144  break;
145 
146  case ID_SHEET_SET:
147  {
148  DIALOG_PAGES_SETTINGS dlg( this );
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  break;
160 
163  case wxID_CUT:
164  // Delete item, and select the previous item
165  item = m_treePagelayout->GetPageLayoutSelectedItem();
166 
167  if( item == NULL )
168  break;
169 
170  SaveCopyInUndoList();
171  idx = pglayout.GetItemIndex( item );
172  pglayout.Remove( item );
173  RebuildDesignTree();
174 
176  {
177  item = pglayout.GetItem( (unsigned) (idx-1) );
178 
179  if( item )
180  m_treePagelayout->SelectCell( item );
181  }
182 
183  item = NULL;
184  OnModify();
185  m_canvas->Refresh();
186  break;
187 
189  SaveCopyInUndoList();
190  idx = m_treePagelayout->GetSelectedItemIndex();
191  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_SEGMENT, idx );
192 
193  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
194  {
195  RemoveLastCommandInUndoList();
196  pglayout.Remove( item );
197  RebuildDesignTree();
198  item = NULL;
199  }
200  else
201  {
202  // Put the new item in move mode, after putting the cursor
203  // on the start point:
204  wxPoint position = item->GetStartPosUi();
205  SetCrossHairPosition( position, false );
206  position = GetCrossHairPosition();
207 
208  if( m_canvas->IsPointOnDisplay( position ) )
209  m_canvas->MoveCursorToCrossHair();
210  else
211  RedrawScreen( position, true );
212 
213  item->SetFlags( NEW_ITEM );
214  MoveItem( item );
215  }
216  break;
217 
219  SaveCopyInUndoList();
220  idx = m_treePagelayout->GetSelectedItemIndex();
221  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_RECT, idx );
222 
223  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
224  {
225  RemoveLastCommandInUndoList();
226  pglayout.Remove( item );
227  RebuildDesignTree();
228  item = NULL;
229  }
230  else
231  {
232  // Put the new item in move mode, after putting the cursor
233  // on the start point:
234  wxPoint position = item->GetStartPosUi();
235  SetCrossHairPosition( position, false );
236  position = GetCrossHairPosition();
237 
238  if( m_canvas->IsPointOnDisplay( position ) )
239  m_canvas->MoveCursorToCrossHair();
240  else
241  RedrawScreen( position, true );
242 
243  item->SetFlags( NEW_ITEM );
244  MoveItem( item );
245  }
246  break;
247 
249  SaveCopyInUndoList();
250  idx = m_treePagelayout->GetSelectedItemIndex();
251  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_TEXT, idx );
252  if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
253  {
254  RemoveLastCommandInUndoList();
255  pglayout.Remove( item );
256  RebuildDesignTree();
257  item = NULL;
258  }
259  else
260  {
261  // Put the new text in move mode:
263  MoveItem( item );
264  }
265  break;
266 
268  SaveCopyInUndoList();
269  idx = m_treePagelayout->GetSelectedItemIndex();
270  item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_BITMAP, idx );
271  if( item && InvokeDialogNewItem( this, item ) == wxID_CANCEL )
272  {
273  RemoveLastCommandInUndoList();
274  pglayout.Remove( item );
275  RebuildDesignTree();
276  item = NULL;
277  }
278  if( item )
279  {
280  // Put the new text in move mode:
282  MoveItem( item );
283  }
284  break;
285 
287  cmd.SetId( ID_APPEND_DESCR_FILE );
288  wxPostEvent( this, cmd );
289  break;
290 
291  case ID_POPUP_ITEM_PLACE:
292  item = GetScreen()->GetCurItem();
293  PlaceItem( item );
294  break;
295 
297  if( m_canvas->IsMouseCaptured() )
298  m_canvas->EndMouseCapture();
299  break;
300 
302  item = m_treePagelayout->GetPageLayoutSelectedItem();
303  // Ensure flags are properly set
304  item->ClearFlags( LOCATE_ENDPOINT );
305  item->SetFlags( LOCATE_STARTPOINT );
306  MoveItem( item );
307  break;
308 
310  item = m_treePagelayout->GetPageLayoutSelectedItem();
311  // Ensure flags are properly set
312  item->ClearFlags( LOCATE_STARTPOINT );
313  item->SetFlags( LOCATE_ENDPOINT );
314  MoveItem( item );
315  break;
316 
317  case ID_POPUP_ITEM_MOVE:
318  item = m_treePagelayout->GetPageLayoutSelectedItem();
320  MoveItem( item );
321  break;
322 
323  default:
324  wxMessageBox( wxT( "PL_EDITOR_FRAME::Process_Special_Functions error" ) );
325  break;
326  }
327 
328  if( item )
329  {
330  OnModify();
331  m_propertiesPagelayout->CopyPrmsFromItemToPanel( item );
332  m_treePagelayout->SelectCell( item );
333  }
334 
335 }
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 347 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().

348 {
349  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
350  WORKSHEET_DATAITEM *item = screen->GetCurItem();
351 
352  wxCHECK_RET( (item != NULL), wxT( "Cannot move NULL item." ) );
353  wxPoint position = aPanel->GetParent()->GetCrossHairPosition()
355  wxPoint previous_position;
356 
357  if( (item->GetFlags() & LOCATE_STARTPOINT) )
358  {
359  previous_position = item->GetStartPosUi();
360  item->MoveStartPointToUi( position );
361  }
362  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
363  {
364  previous_position = item->GetEndPosUi();
365  item->MoveEndPointToUi( position );
366  }
367  else
368  {
369  previous_position = item->GetStartPosUi();
370  item->MoveToUi( position );
371  }
372 
373  // Draw the item item at it's new position, if it is modified,
374  // (does not happen each time the mouse is moved, because the
375  // item is placed on grid)
376  // to avoid useless computation time.
377  if( previous_position != position )
378  aPanel->Refresh();
379 }
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
Definition: draw_panel.cpp:326
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:175
#define LOCATE_STARTPOINT
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
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 345 of file events_functions.cpp.

DPOINT initialPosition

Definition at line 343 of file events_functions.cpp.

wxPoint initialPositionUi

Definition at line 344 of file events_functions.cpp.

Referenced by moveItem().