KiCad PCB EDA Suite
dialog_import_gfx.cpp File Reference
#include "dialog_import_gfx.h"
#include <advanced_config.h>
#include <convert_to_biu.h>
#include <kiface_i.h>
#include <pcb_layer_box_selector.h>
#include <wildcards_and_files_ext.h>
#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
#include <class_text_mod.h>
#include <class_pcb_text.h>

Go to the source code of this file.

Macros

#define IMPORT_GFX_LAYER_OPTION_KEY   "GfxImportBrdLayer"
 
#define IMPORT_GFX_PLACEMENT_INTERACTIVE_KEY   "GfxImportPlacementInteractive"
 
#define IMPORT_GFX_LAST_FILE_KEY   "GfxImportLastFile"
 
#define IMPORT_GFX_POSITION_UNITS_KEY   "GfxImportPositionUnits"
 
#define IMPORT_GFX_POSITION_X_KEY   "GfxImportPositionX"
 
#define IMPORT_GFX_POSITION_Y_KEY   "GfxImportPositionY"
 
#define IMPORT_GFX_LINEWIDTH_UNITS_KEY   "GfxImportLineWidthUnits"
 
#define IMPORT_GFX_LINEWIDTH_KEY   "GfxImportLineWidth"
 

Functions

bool InvokeDialogImportGfxBoard (PCB_BASE_FRAME *aCaller)
 Shows the modal DIALOG_IMPORT_GFX for importing a DXF file to a board. More...
 
bool InvokeDialogImportGfxModule (PCB_BASE_FRAME *aCaller, MODULE *aModule)
 shows the modal DIALOG_IMPORT_GFX for importing a DXF file as footprint outlines. More...
 

Macro Definition Documentation

◆ IMPORT_GFX_LAST_FILE_KEY

#define IMPORT_GFX_LAST_FILE_KEY   "GfxImportLastFile"

Definition at line 47 of file dialog_import_gfx.cpp.

◆ IMPORT_GFX_LAYER_OPTION_KEY

#define IMPORT_GFX_LAYER_OPTION_KEY   "GfxImportBrdLayer"

Definition at line 45 of file dialog_import_gfx.cpp.

◆ IMPORT_GFX_LINEWIDTH_KEY

#define IMPORT_GFX_LINEWIDTH_KEY   "GfxImportLineWidth"

Definition at line 52 of file dialog_import_gfx.cpp.

◆ IMPORT_GFX_LINEWIDTH_UNITS_KEY

#define IMPORT_GFX_LINEWIDTH_UNITS_KEY   "GfxImportLineWidthUnits"

Definition at line 51 of file dialog_import_gfx.cpp.

◆ IMPORT_GFX_PLACEMENT_INTERACTIVE_KEY

#define IMPORT_GFX_PLACEMENT_INTERACTIVE_KEY   "GfxImportPlacementInteractive"

Definition at line 46 of file dialog_import_gfx.cpp.

◆ IMPORT_GFX_POSITION_UNITS_KEY

#define IMPORT_GFX_POSITION_UNITS_KEY   "GfxImportPositionUnits"

Definition at line 48 of file dialog_import_gfx.cpp.

◆ IMPORT_GFX_POSITION_X_KEY

#define IMPORT_GFX_POSITION_X_KEY   "GfxImportPositionX"

Definition at line 49 of file dialog_import_gfx.cpp.

◆ IMPORT_GFX_POSITION_Y_KEY

#define IMPORT_GFX_POSITION_Y_KEY   "GfxImportPositionY"

Definition at line 50 of file dialog_import_gfx.cpp.

Function Documentation

◆ InvokeDialogImportGfxBoard()

bool InvokeDialogImportGfxBoard ( PCB_BASE_FRAME aCaller)

Shows the modal DIALOG_IMPORT_GFX for importing a DXF file to a board.

Parameters
aCalleris the wxTopLevelWindow which is invoking the dialog.
Returns
true if the import was made.

Definition at line 338 of file dialog_import_gfx.cpp.

339 {
340  DIALOG_IMPORT_GFX dlg( aCaller );
341 
342  if( dlg.ShowModal() != wxID_OK )
343  return false;
344 
345  auto& list = dlg.GetImportedItems();
346 
347  // Ensure the list is not empty:
348  if( list.empty() )
349  {
350  wxMessageBox( _( "No graphic items found in file to import") );
351  return false;
352  }
353 
354  PICKED_ITEMS_LIST picklist; // the pick list for undo command
355  ITEM_PICKER item_picker( nullptr, UR_NEW );
356  BOARD* board = aCaller->GetBoard();
357 
358  // Now prepare a block move command to place the new items, if interactive placement,
359  // and prepare the undo command.
360  EDA_RECT bbox; // the new items bounding box, for block move if interactive placement.
361  bool bboxInit = true; // true until the bounding box is initialized
362  BLOCK_SELECTOR& blockmove = aCaller->GetScreen()->m_BlockLocate;
363 
364  if( dlg.IsPlacementInteractive() )
365  aCaller->HandleBlockBegin( NULL, BLOCK_PRESELECT_MOVE, wxPoint( 0, 0) );
366 
367  PICKED_ITEMS_LIST& blockitemsList = blockmove.GetItems();
368 
369  for( auto it = list.begin(); it != list.end(); ++it )
370  {
371  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->release() );
372 
373  if( dlg.IsPlacementInteractive() )
374  item->SetFlags( IS_MOVED );
375 
376  board->Add( item );
377 
378  item_picker.SetItem( item );
379  picklist.PushItem( item_picker );
380 
381  if( dlg.IsPlacementInteractive() )
382  {
383  blockitemsList.PushItem( item_picker );
384 
385  if( bboxInit )
386  bbox = item->GetBoundingBox();
387  else
388  bbox.Merge( item->GetBoundingBox() );
389 
390  bboxInit = false;
391  }
392  }
393 
394  aCaller->SaveCopyInUndoList( picklist, UR_NEW, wxPoint( 0, 0 ) );
395  aCaller->OnModify();
396 
397  if( dlg.IsPlacementInteractive() )
398  {
399  // Finish block move command:
400  wxPoint cpos = aCaller->GetNearestGridPosition( bbox.Centre() );
401  blockmove.SetOrigin( bbox.GetOrigin() );
402  blockmove.SetSize( bbox.GetSize() );
403  blockmove.SetLastCursorPosition( cpos );
404  aCaller->HandleBlockEnd( NULL );
405  }
406 
407  return true;
408 }
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
virtual bool HandleBlockBegin(wxDC *aDC, EDA_KEY aKey, const wxPoint &aPosition, int aExplicitCommand=0)
Initialize a block command.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
virtual bool HandleBlockEnd(wxDC *DC)
Handle the "end" of a block command, i.e.
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Return the nearest aGridSize location to aPosition.
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
void SetSize(const wxSize &size)
Definition: eda_rect.h:126
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))=0
Function SaveCopyInUndoList (virtual pure) Creates a new entry in undo list of commands.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
wxPoint Centre() const
Definition: eda_rect.h:60
PICKED_ITEMS_LIST & GetItems()
BOARD * GetBoard() const
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
void SetLastCursorPosition(const wxPoint &aPosition)
Function SetLastCursorPosition sets the last cursor position to aPosition.
const wxSize GetSize() const
Definition: eda_rect.h:101
#define IS_MOVED
Item being moved.
Definition: base_struct.h:113

References BOARD::Add(), BLOCK_PRESELECT_MOVE, EDA_RECT::Centre(), PCB_BASE_FRAME::GetBoard(), EDA_ITEM::GetBoundingBox(), DIALOG_IMPORT_GFX::GetImportedItems(), BLOCK_SELECTOR::GetItems(), EDA_DRAW_FRAME::GetNearestGridPosition(), EDA_RECT::GetOrigin(), PCB_BASE_FRAME::GetScreen(), EDA_RECT::GetSize(), EDA_DRAW_FRAME::HandleBlockBegin(), EDA_DRAW_FRAME::HandleBlockEnd(), IS_MOVED, DIALOG_IMPORT_GFX::IsPlacementInteractive(), BASE_SCREEN::m_BlockLocate, EDA_RECT::Merge(), PCB_BASE_FRAME::OnModify(), PICKED_ITEMS_LIST::PushItem(), PCB_BASE_FRAME::SaveCopyInUndoList(), EDA_ITEM::SetFlags(), ITEM_PICKER::SetItem(), BLOCK_SELECTOR::SetLastCursorPosition(), EDA_RECT::SetOrigin(), EDA_RECT::SetSize(), and UR_NEW.

Referenced by PCB_EDIT_FRAME::Process_Special_Functions().

◆ InvokeDialogImportGfxModule()

bool InvokeDialogImportGfxModule ( PCB_BASE_FRAME aCaller,
MODULE aModule 
)

shows the modal DIALOG_IMPORT_GFX for importing a DXF file as footprint outlines.

Parameters
aCalleris the wxTopLevelWindow which is invoking the dialog.
aModuleis the footprint currently edited.
Returns
true if the import was made.

Definition at line 412 of file dialog_import_gfx.cpp.

413 {
414  if( !aModule )
415  return false;
416 
417  DIALOG_IMPORT_GFX dlg( aCaller, true );
418 
419  if( dlg.ShowModal() != wxID_OK )
420  return false;
421 
422  auto& list = dlg.GetImportedItems();
423 
424  // Ensure the list is not empty:
425  if( list.empty() )
426  {
427  wxMessageBox( _( "No graphic items found in file to import") );
428  return false;
429  }
430 
431  aCaller->SaveCopyInUndoList( aModule, UR_CHANGED );
432 
433  PICKED_ITEMS_LIST picklist; // the pick list for undo command
434  ITEM_PICKER item_picker( nullptr, UR_NEW );
435 
436  // Now prepare a block move command to place the new items, if interactive placement,
437  // and prepare the undo command.
438  EDA_RECT bbox; // the new items bounding box, for block move if interactive placement.
439  bool bboxInit = true; // true until the bounding box is initialized
440  BLOCK_SELECTOR& blockmove = aCaller->GetScreen()->m_BlockLocate;
441 
442  if( dlg.IsPlacementInteractive() )
443  aCaller->HandleBlockBegin( nullptr, BLOCK_PRESELECT_MOVE, wxPoint( 0, 0) );
444 
445  PICKED_ITEMS_LIST& blockitemsList = blockmove.GetItems();
446 
447  for( auto it = list.begin(); it != list.end(); ++it )
448  {
449  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->release() );
450  aModule->Add( item );
451 
452  if( dlg.IsPlacementInteractive() )
453  {
454  item->SetFlags( IS_MOVED );
455  item_picker.SetItem( item );
456  blockitemsList.PushItem( item_picker );
457 
458  if( bboxInit )
459  bbox = item->GetBoundingBox();
460  else
461  bbox.Merge( item->GetBoundingBox() );
462 
463  bboxInit = false;
464  }
465  }
466 
467  aCaller->OnModify();
468 
469  if( dlg.IsPlacementInteractive() )
470  {
471  // Finish block move command:
472  wxPoint cpos = aCaller->GetNearestGridPosition( bbox.Centre() );
473  blockmove.SetOrigin( bbox.GetOrigin() );
474  blockmove.SetSize( bbox.GetSize() );
475  blockmove.SetLastCursorPosition( cpos );
476  aCaller->HandleBlockEnd( NULL );
477  }
478 
479  return true;
480 }
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
virtual bool HandleBlockBegin(wxDC *aDC, EDA_KEY aKey, const wxPoint &aPosition, int aExplicitCommand=0)
Initialize a block command.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
virtual bool HandleBlockEnd(wxDC *DC)
Handle the "end" of a block command, i.e.
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Return the nearest aGridSize location to aPosition.
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
void SetSize(const wxSize &size)
Definition: eda_rect.h:126
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))=0
Function SaveCopyInUndoList (virtual pure) Creates a new entry in undo list of commands.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
wxPoint Centre() const
Definition: eda_rect.h:60
PICKED_ITEMS_LIST & GetItems()
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
void SetLastCursorPosition(const wxPoint &aPosition)
Function SetLastCursorPosition sets the last cursor position to aPosition.
const wxSize GetSize() const
Definition: eda_rect.h:101
#define IS_MOVED
Item being moved.
Definition: base_struct.h:113

References MODULE::Add(), BLOCK_PRESELECT_MOVE, EDA_RECT::Centre(), EDA_ITEM::GetBoundingBox(), DIALOG_IMPORT_GFX::GetImportedItems(), BLOCK_SELECTOR::GetItems(), EDA_DRAW_FRAME::GetNearestGridPosition(), EDA_RECT::GetOrigin(), PCB_BASE_FRAME::GetScreen(), EDA_RECT::GetSize(), EDA_DRAW_FRAME::HandleBlockBegin(), EDA_DRAW_FRAME::HandleBlockEnd(), IS_MOVED, DIALOG_IMPORT_GFX::IsPlacementInteractive(), BASE_SCREEN::m_BlockLocate, EDA_RECT::Merge(), PCB_BASE_FRAME::OnModify(), PICKED_ITEMS_LIST::PushItem(), PCB_BASE_FRAME::SaveCopyInUndoList(), EDA_ITEM::SetFlags(), ITEM_PICKER::SetItem(), BLOCK_SELECTOR::SetLastCursorPosition(), EDA_RECT::SetOrigin(), EDA_RECT::SetSize(), UR_CHANGED, and UR_NEW.

Referenced by FOOTPRINT_EDIT_FRAME::Process_Special_Functions().