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

382 {
383  PL_EDITOR_SCREEN* screen = (PL_EDITOR_SCREEN*) aPanel->GetScreen();
384  WORKSHEET_DATAITEM *item = screen->GetCurItem();
385 
386  if( item->GetFlags() & NEW_ITEM )
387  {
388  PL_EDITOR_FRAME* plframe = (PL_EDITOR_FRAME*) aPanel->GetParent();
389  plframe->RemoveLastCommandInUndoList();
391  pglayout.Remove( item );
392  plframe->RebuildDesignTree();
393  }
394  else
395  {
396  if( (item->GetFlags() & LOCATE_STARTPOINT) )
397  {
399  }
400  else if( (item->GetFlags() & LOCATE_ENDPOINT) )
401  {
403  }
404  else
405  item->MoveTo( initialPosition );
406  }
407 
408  aPanel->SetMouseCapture( NULL, NULL );
409  screen->SetCurItem( NULL );
410  aPanel->Refresh();
411 }
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, and KiBitmap().

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( add_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

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.

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

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

DPOINT initialPosition

Definition at line 337 of file events_functions.cpp.

wxPoint initialPositionUi

Definition at line 338 of file events_functions.cpp.

Referenced by moveItem().