Browse Source

Support vector graphics drag-and-drop in PCB and schematic editors.

This just shows the import dialogs with filename pre-populated.
master
Alex Shvartzkop 3 weeks ago
parent
commit
89af3c34b9
  1. 2
      common/eda_base_frame.cpp
  2. 18
      eeschema/import_gfx/dialog_import_gfx_sch.cpp
  3. 8
      eeschema/import_gfx/dialog_import_gfx_sch.h
  4. 2
      eeschema/sch_edit_frame.cpp
  5. 5
      eeschema/tools/sch_actions.cpp
  6. 1
      eeschema/tools/sch_actions.h
  7. 8
      eeschema/tools/sch_drawing_tools.cpp
  8. 18
      pcbnew/import_gfx/dialog_import_graphics.cpp
  9. 8
      pcbnew/import_gfx/dialog_import_graphics.h
  10. 2
      pcbnew/pcb_edit_frame.cpp
  11. 6
      pcbnew/tools/drawing_tool.cpp
  12. 2
      pcbnew/tools/drawing_tool.h
  13. 6
      pcbnew/tools/pcb_actions.cpp
  14. 1
      pcbnew/tools/pcb_actions.h

2
common/eda_base_frame.cpp

@ -1438,6 +1438,8 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent
void EDA_BASE_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
{
Raise();
wxString* files = aEvent.GetFiles();
for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )

18
eeschema/import_gfx/dialog_import_gfx_sch.cpp

@ -157,6 +157,24 @@ DIALOG_IMPORT_GFX_SCH::~DIALOG_IMPORT_GFX_SCH()
}
void DIALOG_IMPORT_GFX_SCH::SetFilenameOverride( const wxString& aFilenameOverride )
{
m_filenameOverride = aFilenameOverride;
}
bool DIALOG_IMPORT_GFX_SCH::TransferDataToWindow()
{
DIALOG_SHIM::TransferDataToWindow();
// We have to set the filename field value here, otherwise it gets overwritten by state loading
if( !m_filenameOverride.IsEmpty() )
m_textCtrlFileName->SetValue( m_filenameOverride );
return true;
}
void DIALOG_IMPORT_GFX_SCH::onFilename( wxCommandEvent& event )
{
bool enableDXFControls = true;

8
eeschema/import_gfx/dialog_import_gfx_sch.h

@ -55,6 +55,12 @@ public:
*/
bool IsPlacementInteractive() { return m_placementInteractive; }
/**
* Set the filename override to be applied in TransferDataToWindow.
*/
void SetFilenameOverride( const wxString& aFilenameOverride );
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
private:
@ -85,6 +91,8 @@ private:
static bool m_placementInteractive;
static double m_importScale; // a scale factor to change the size of imported
// items m_importScale =1.0 means keep original size
wxString m_filenameOverride;
};
#endif // __DIALOG_IMPORT_GFX_SCH_H__

2
eeschema/sch_edit_frame.cpp

@ -423,6 +423,8 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_acceptedExts.emplace( FILEEXT::PngFileExtension, &SCH_ACTIONS::ddAddImage );
m_acceptedExts.emplace( FILEEXT::JpegFileExtension, &SCH_ACTIONS::ddAddImage );
m_acceptedExts.emplace( wxS( "jpeg" ), &SCH_ACTIONS::ddAddImage );
m_acceptedExts.emplace( wxS( "dxf" ), &SCH_ACTIONS::ddImportGraphics );
m_acceptedExts.emplace( FILEEXT::SVGFileExtension, &SCH_ACTIONS::ddImportGraphics );
DragAcceptFiles( true );
// Ensure the window is on top

5
eeschema/tools/sch_actions.cpp

@ -1511,10 +1511,15 @@ TOOL_ACTION SCH_ACTIONS::saveCurrSheetCopyAs( TOOL_ACTION_ARGS()
TOOL_ACTION SCH_ACTIONS::ddAppendFile( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.ddAppendFile" )
.Scope( AS_GLOBAL ) );
TOOL_ACTION SCH_ACTIONS::ddAddImage( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.ddAddImage" )
.Scope( AS_GLOBAL ) );
TOOL_ACTION SCH_ACTIONS::ddImportGraphics( TOOL_ACTION_ARGS()
.Name( "eeschema.EditorControl.ddImportGraphics" )
.Scope( AS_GLOBAL ) );
// SIMULATOR
TOOL_ACTION SCH_ACTIONS::newAnalysisTab( TOOL_ACTION_ARGS()
.Name( "eeschema.Simulation.newAnalysisTab" )

1
eeschema/tools/sch_actions.h

@ -302,6 +302,7 @@ public:
// Drag and drop
static TOOL_ACTION ddAppendFile;
static TOOL_ACTION ddAddImage;
static TOOL_ACTION ddImportGraphics;
struct PLACE_SYMBOL_PARAMS
{

8
eeschema/tools/sch_drawing_tools.cpp

@ -1287,7 +1287,12 @@ int SCH_DRAWING_TOOLS::ImportGraphics( const TOOL_EVENT& aEvent )
// Note: PlaceImportedGraphics() will convert PCB_SHAPE_T and PCB_TEXT_T to footprint
// items if needed
DIALOG_IMPORT_GFX_SCH dlg( m_frame );
int dlgResult = dlg.ShowModal();
// Set filename on drag-and-drop
if( aEvent.HasParameter() )
dlg.SetFilenameOverride( *aEvent.Parameter<wxString*>() );
int dlgResult = dlg.ShowModal();
std::list<std::unique_ptr<EDA_ITEM>>& list = dlg.GetImportedItems();
@ -3720,6 +3725,7 @@ void SCH_DRAWING_TOOLS::setTransitions()
Go( &SCH_DRAWING_TOOLS::DrawTable, SCH_ACTIONS::drawTable.MakeEvent() );
Go( &SCH_DRAWING_TOOLS::PlaceImage, SCH_ACTIONS::placeImage.MakeEvent() );
Go( &SCH_DRAWING_TOOLS::ImportGraphics, SCH_ACTIONS::importGraphics.MakeEvent() );
Go( &SCH_DRAWING_TOOLS::ImportGraphics, SCH_ACTIONS::ddImportGraphics.MakeEvent() );
Go( &SCH_DRAWING_TOOLS::SyncSheetsPins, SCH_ACTIONS::syncSheetPins.MakeEvent() );
Go( &SCH_DRAWING_TOOLS::SyncAllSheetsPins, SCH_ACTIONS::syncAllSheetsPins.MakeEvent() );
Go( &SCH_DRAWING_TOOLS::AutoPlaceAllSheetPins, SCH_ACTIONS::autoplaceAllSheetPins.MakeEvent() );

18
pcbnew/import_gfx/dialog_import_graphics.cpp

@ -100,6 +100,24 @@ DIALOG_IMPORT_GRAPHICS::~DIALOG_IMPORT_GRAPHICS()
}
void DIALOG_IMPORT_GRAPHICS::SetFilenameOverride( const wxString& aFilenameOverride )
{
m_filenameOverride = aFilenameOverride;
}
bool DIALOG_IMPORT_GRAPHICS::TransferDataToWindow()
{
DIALOG_SHIM::TransferDataToWindow();
// We have to set the filename field value here, otherwise it gets overwritten by state loading
if( !m_filenameOverride.IsEmpty() )
m_textCtrlFileName->SetValue( m_filenameOverride );
return true;
}
void DIALOG_IMPORT_GRAPHICS::onFilename( wxCommandEvent& event )
{
bool enableDXFControls = true;

8
pcbnew/import_gfx/dialog_import_graphics.h

@ -66,6 +66,12 @@ public:
*/
bool ShouldGroupItems() { return m_cbGroupItems->IsChecked(); }
/**
* Set the filename override to be applied in TransferDataToWindow.
*/
void SetFilenameOverride( const wxString& aFilenameOverride );
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
private:
@ -83,4 +89,6 @@ private:
UNIT_BINDER m_yOrigin;
UNIT_BINDER m_defaultLineWidth;
UNIT_BINDER m_tolerance;
wxString m_filenameOverride;
};

2
pcbnew/pcb_edit_frame.cpp

@ -569,6 +569,8 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_acceptedExts.emplace( FILEEXT::KiCadPcbFileExtension, &PCB_ACTIONS::ddAppendBoard );
m_acceptedExts.emplace( FILEEXT::LegacyPcbFileExtension, &PCB_ACTIONS::ddAppendBoard );
m_acceptedExts.emplace( wxS( "dxf" ), &PCB_ACTIONS::ddImportGraphics );
m_acceptedExts.emplace( FILEEXT::SVGFileExtension, &PCB_ACTIONS::ddImportGraphics );
DragAcceptFiles( true );
Bind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &PCB_EDIT_FRAME::onCloseModelessBookReporterDialogs, this );

6
pcbnew/tools/drawing_tool.cpp

@ -1872,6 +1872,11 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inDrawingTool );
DIALOG_IMPORT_GRAPHICS dlg( m_frame );
// Set filename on drag-and-drop
if( aEvent.HasParameter() )
dlg.SetFilenameOverride( *aEvent.Parameter<wxString*>() );
int dlgResult = dlg.ShowModal();
std::list<std::unique_ptr<EDA_ITEM>>& list = dlg.GetImportedItems();
@ -4216,6 +4221,7 @@ void DRAWING_TOOL::setTransitions()
Go( &DRAWING_TOOL::DrawTable, PCB_ACTIONS::drawTable.MakeEvent() );
Go( &DRAWING_TOOL::DrawRectangle, PCB_ACTIONS::drawTextBox.MakeEvent() );
Go( &DRAWING_TOOL::PlaceImportedGraphics, PCB_ACTIONS::placeImportedGraphics.MakeEvent() );
Go( &DRAWING_TOOL::PlaceImportedGraphics, PCB_ACTIONS::ddImportGraphics.MakeEvent() );
Go( &DRAWING_TOOL::SetAnchor, PCB_ACTIONS::setAnchor.MakeEvent() );
Go( &DRAWING_TOOL::PlaceTuningPattern, PCB_ACTIONS::tuneSingleTrack.MakeEvent() );

2
pcbnew/tools/drawing_tool.h

@ -194,7 +194,7 @@ public:
int DrawVia( const TOOL_EVENT& aEvent );
/**
* Place a drawing imported from a DXF or SVG file in footprint editor.
* Place a drawing imported from a DXF or SVG file.
*/
int PlaceImportedGraphics( const TOOL_EVENT& aEvent );

6
pcbnew/tools/pcb_actions.cpp

@ -2692,15 +2692,19 @@ TOOL_ACTION PCB_ACTIONS::lengthTunerSettings( TOOL_ACTION_ARGS()
.Tooltip( _( "Displays tuning pattern properties dialog" ) )
.Icon( BITMAPS::router_len_tuner_setup ) );
// Drag and drop
TOOL_ACTION PCB_ACTIONS::ddAppendBoard( TOOL_ACTION_ARGS()
.Name( "pcbnew.Control.DdAppendBoard" )
.Scope( AS_GLOBAL ) );
TOOL_ACTION PCB_ACTIONS::ddImportFootprint( TOOL_ACTION_ARGS()
.Name( "pcbnew.Control.ddImportFootprint" )
.Scope( AS_GLOBAL ) );
TOOL_ACTION PCB_ACTIONS::ddImportGraphics( TOOL_ACTION_ARGS()
.Name( "pcbnew.InteractiveDrawing.ddImportGraphics" )
.Scope( AS_GLOBAL ) );
// actions for footprint wizard frame
TOOL_ACTION PCB_ACTIONS::showWizards( TOOL_ACTION_ARGS()
.Name( "pcbnew.FpWizard.showWizards" )

1
pcbnew/tools/pcb_actions.h

@ -599,6 +599,7 @@ public:
/// Drag and drop
static TOOL_ACTION ddAppendBoard;
static TOOL_ACTION ddImportFootprint;
static TOOL_ACTION ddImportGraphics;
static TOOL_ACTION repeatLayout;
static TOOL_ACTION generatePlacementRuleAreas;

Loading…
Cancel
Save