Browse Source
ADDED: Implement Drag and Drop
ADDED: Implement Drag and Drop
dropping files to Kicad manager : *.kicad_pro, *.pro -> open project; gerber and job files -> open in Gerbview editor; Eagle and Cadstar files -> open project. dropping file to schematic editor -> append schematic; dropping library file to Symbol editor -> add library; dropping board file to PCB editor -> append board; dropping library or footprint file to Footprint editor -> add library or import footprint; dropping ZIP file or gerber files to Gerbview editor -> open files; dropping sheet file to Drawing Sheet editor -> open sheet. Fixes https://gitlab.com/kicad/code/kicad/-/issues/116387.0
committed by
Seth Hillbrand
48 changed files with 962 additions and 167 deletions
-
2common/CMakeLists.txt
-
30common/eda_base_frame.cpp
-
53common/eda_tools.cpp
-
4common/tool/actions.cpp
-
30common/wildcards_and_files_ext.cpp
-
10eeschema/files-io.cpp
-
7eeschema/sch_edit_frame.cpp
-
10eeschema/sch_edit_frame.h
-
41eeschema/symbol_editor/symbol_edit_frame.cpp
-
5eeschema/symbol_editor/symbol_edit_frame.h
-
4eeschema/tools/ee_actions.cpp
-
3eeschema/tools/ee_actions.h
-
9eeschema/tools/sch_edit_tool.cpp
-
3eeschema/tools/sch_edit_tool.h
-
12eeschema/tools/symbol_editor_control.cpp
-
2eeschema/tools/symbol_editor_control.h
-
3gerbview/events_called_functions.cpp
-
25gerbview/files.cpp
-
7gerbview/gerbview_frame.cpp
-
2gerbview/gerbview_frame.h
-
7gerbview/tools/gerbview_actions.cpp
-
4gerbview/tools/gerbview_actions.h
-
43gerbview/tools/gerbview_control.cpp
-
4gerbview/tools/gerbview_control.h
-
23include/eda_base_frame.h
-
55include/eda_tools.h
-
3include/tool/actions.h
-
15include/wildcards_and_files_ext.h
-
1kicad/CMakeLists.txt
-
207kicad/import_proj.cpp
-
56kicad/import_proj.h
-
138kicad/import_project.cpp
-
70kicad/kicad_manager_frame.cpp
-
6kicad/kicad_manager_frame.h
-
11kicad/project_tree_pane.cpp
-
11kicad/tools/kicad_manager_actions.cpp
-
3kicad/tools/kicad_manager_actions.h
-
109kicad/tools/kicad_manager_control.cpp
-
9kicad/tools/kicad_manager_control.h
-
6pagelayout_editor/files.cpp
-
7pagelayout_editor/pl_editor_frame.cpp
-
2pagelayout_editor/pl_editor_frame.h
-
10pcbnew/footprint_edit_frame.cpp
-
8pcbnew/pcb_edit_frame.cpp
-
7pcbnew/tools/pcb_actions.cpp
-
4pcbnew/tools/pcb_actions.h
-
43pcbnew/tools/pcb_control.cpp
-
5pcbnew/tools/pcb_control.h
@ -0,0 +1,53 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr |
|||
* Copyright (C) 2013 CERN (www.cern.ch) |
|||
* Copyright (C) 2004-2021 KiCad Developers, see change_log.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <eda_tools.h>
|
|||
#include <wx/textfile.h>
|
|||
|
|||
bool IsFileFromEDATool( const wxFileName& aFileName, const EDA_TOOLS aTool ) |
|||
{ |
|||
wxTextFile textFile; |
|||
|
|||
if( textFile.Open( aFileName.GetFullPath() ) ) |
|||
{ |
|||
switch( aTool ) |
|||
{ |
|||
case EAGLE: |
|||
if( textFile.GetLineCount() > 2 |
|||
&& textFile[1].StartsWith( wxT( "<!DOCTYPE eagle SYSTEM" ) ) |
|||
&& textFile[2].StartsWith( wxT( "<eagle version" ) ) ) |
|||
{ |
|||
textFile.Close(); |
|||
return true; |
|||
} |
|||
break; |
|||
|
|||
default: break; |
|||
} |
|||
textFile.Close(); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com> |
|||
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* Copyright (C) 2018 CERN |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
/** |
|||
* @file eda_tools.h |
|||
* @brief Enums and utilities for different EDA tools. |
|||
*/ |
|||
|
|||
|
|||
#ifndef EDA_TOOLS_H |
|||
#define EDA_TOOLS_H |
|||
|
|||
#include <wx/filename.h> |
|||
|
|||
/** |
|||
* Enumeration of tools |
|||
*/ |
|||
enum EDA_TOOLS |
|||
{ |
|||
EAGLE |
|||
}; |
|||
|
|||
/** |
|||
* Check if aFileName is a aTool file |
|||
* As an example, can be used to check if a .sch file is an EAGLE file |
|||
* (may be a legacy KICAD file) |
|||
* @param aFileName name of file to check. Must be given with full path |
|||
* @param aTool EDA tool |
|||
* @return true if the file is an EDA_TOOL file type, false if not or file does not exist |
|||
*/ |
|||
bool IsFileFromEDATool( const wxFileName& aFileName, const EDA_TOOLS aTool ); |
|||
|
|||
#endif |
|||
@ -0,0 +1,207 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2019 CERN |
|||
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* Free Software Foundation, either version 3 of the License, or (at your |
|||
* option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, but |
|||
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
* General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License along |
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
#include "import_proj.h"
|
|||
#include <kiway.h>
|
|||
#include <kiway_player.h>
|
|||
#include <wildcards_and_files_ext.h>
|
|||
#include <macros.h>
|
|||
#include <richio.h>
|
|||
|
|||
#include <wx/msgdlg.h>
|
|||
|
|||
|
|||
IMPORT_PROJ_HELPER::IMPORT_PROJ_HELPER( KICAD_MANAGER_FRAME* aFrame, |
|||
const wxString& aFile, |
|||
const wxString& aSchFileExtension, |
|||
const wxString& aPcbFileExtension ) : |
|||
m_frame( aFrame ), |
|||
m_sch( aFile ), m_pcb( m_sch ), m_pro( m_sch ) |
|||
{ |
|||
m_sch.SetExt( aSchFileExtension ); |
|||
m_pcb.SetExt( aPcbFileExtension ); |
|||
m_pro.SetExt( ProjectFileExtension ); |
|||
} |
|||
|
|||
|
|||
const wxFileName& IMPORT_PROJ_HELPER::GetProj() |
|||
{ |
|||
return m_pro; |
|||
} |
|||
|
|||
|
|||
wxString IMPORT_PROJ_HELPER::GetProjPath() |
|||
{ |
|||
return m_pro.GetPath(); |
|||
} |
|||
|
|||
|
|||
void IMPORT_PROJ_HELPER::SetProjPath( const wxString aPath ) |
|||
{ |
|||
m_pro.SetPath( aPath ); |
|||
} |
|||
|
|||
|
|||
wxString IMPORT_PROJ_HELPER::GetProjFullPath() |
|||
{ |
|||
return m_pro.GetFullPath(); |
|||
} |
|||
|
|||
|
|||
wxString IMPORT_PROJ_HELPER::GetProjName() |
|||
{ |
|||
return m_pro.GetName(); |
|||
} |
|||
|
|||
|
|||
void IMPORT_PROJ_HELPER::CreateEmptyDirForProject() |
|||
{ |
|||
// Append a new directory with the same name of the project file
|
|||
// Keep iterating until we find an empty directory
|
|||
wxString newDir = m_pro.GetName(); |
|||
int attempt = 0; |
|||
|
|||
m_pro.AppendDir( newDir ); |
|||
|
|||
while( m_pro.DirExists() ) |
|||
{ |
|||
m_pro.RemoveLastDir(); |
|||
wxString suffix = wxString::Format( "_%d", ++attempt ); |
|||
m_pro.AppendDir( newDir + suffix ); |
|||
} |
|||
} |
|||
|
|||
|
|||
void IMPORT_PROJ_HELPER::SetProjAbsolutePath() |
|||
{ |
|||
m_pro.SetExt( ProjectFileExtension ); |
|||
if( !m_pro.IsAbsolute() ) |
|||
m_pro.MakeAbsolute(); |
|||
} |
|||
|
|||
|
|||
bool IMPORT_PROJ_HELPER::CopyImportedFile( KICAD_T aFT, bool displayError ) |
|||
{ |
|||
wxASSERT( m_pro.GetExt() == ProjectFileExtension ); |
|||
|
|||
wxFileName fileCopy( m_pro ); |
|||
|
|||
wxFileName src, dest; |
|||
switch( aFT ) |
|||
{ |
|||
case SCHEMATIC_T: src = m_sch; break; |
|||
|
|||
case PCB_T: src = m_pcb; break; |
|||
|
|||
default: break; |
|||
} |
|||
|
|||
fileCopy.SetExt( src.GetExt() ); |
|||
|
|||
if( src.Exists() && !fileCopy.SameAs( src ) ) |
|||
{ |
|||
if( !wxCopyFile( src.GetFullPath(), fileCopy.GetFullPath(), true ) ) |
|||
{ |
|||
if( displayError ) |
|||
OutputCopyError( src, fileCopy ); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
switch( aFT ) |
|||
{ |
|||
case SCHEMATIC_T: m_shCopy = fileCopy; break; |
|||
|
|||
case PCB_T: m_pcbCopy = fileCopy; break; |
|||
|
|||
default: break; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
bool IMPORT_PROJ_HELPER::CopyImportedFiles( bool displayError ) |
|||
{ |
|||
return CopyImportedFile( SCHEMATIC_T, displayError ) && CopyImportedFile( PCB_T, displayError ); |
|||
} |
|||
|
|||
void IMPORT_PROJ_HELPER::OutputCopyError( const wxFileName& aSrc, const wxFileName& aFileCopy ) |
|||
{ |
|||
wxString msg; |
|||
msg.Printf( _( "Cannot copy file '%s'\n" |
|||
"to '%s'\n" |
|||
"The project cannot be imported." ), |
|||
aSrc.GetFullPath(), aFileCopy.GetFullPath() ); |
|||
|
|||
wxMessageDialog fileCopyErrorDlg( m_frame, msg, _( "Error" ), wxOK_DEFAULT | wxICON_ERROR ); |
|||
fileCopyErrorDlg.ShowModal(); |
|||
} |
|||
|
|||
|
|||
void IMPORT_PROJ_HELPER::AssociateFileWithProj( KICAD_T aFT, int aImportedFileType ) |
|||
{ |
|||
wxFileName fileCopy, importedFile; |
|||
FRAME_T frame_type; |
|||
switch( aFT ) |
|||
{ |
|||
case SCHEMATIC_T: |
|||
importedFile = m_sch; |
|||
fileCopy = m_shCopy; |
|||
frame_type = FRAME_SCH; |
|||
break; |
|||
|
|||
case PCB_T: |
|||
importedFile = m_pcb; |
|||
fileCopy = m_pcbCopy; |
|||
frame_type = FRAME_PCB_EDITOR; |
|||
break; |
|||
|
|||
default: return; |
|||
} |
|||
|
|||
if( fileCopy.FileExists() ) |
|||
{ |
|||
KIWAY_PLAYER* frame = m_frame->Kiway().Player( frame_type, true ); |
|||
|
|||
std::string packet = |
|||
StrPrintf( "%d\n%s", aImportedFileType, TO_UTF8( fileCopy.GetFullPath() ) ); |
|||
frame->Kiway().ExpressMail( frame_type, MAIL_IMPORT_FILE, packet, m_frame ); |
|||
|
|||
if( !frame->IsShown() ) |
|||
frame->Show( true ); |
|||
|
|||
// On Windows, Raise() does not bring the window on screen, when iconized
|
|||
if( frame->IsIconized() ) |
|||
frame->Iconize( false ); |
|||
|
|||
frame->Raise(); |
|||
|
|||
if( !fileCopy.SameAs( importedFile ) ) // Do not delete the original file!
|
|||
wxRemoveFile( fileCopy.GetFullPath() ); |
|||
} |
|||
} |
|||
|
|||
|
|||
void IMPORT_PROJ_HELPER::AssociateFilesWithProj( int aImportedSchFileType, |
|||
int aImportedPcbFileType ) |
|||
{ |
|||
AssociateFileWithProj( SCHEMATIC_T, aImportedSchFileType ); |
|||
AssociateFileWithProj( PCB_T, aImportedPcbFileType ); |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
#ifndef IMPORT_PROJ_H |
|||
#define IMPORT_PROJ_H |
|||
|
|||
#include "kicad_manager_frame.h" |
|||
#include <wx/filename.h> |
|||
#include <core/typeinfo.h> |
|||
|
|||
/** |
|||
* A helper class to import non Kicad project. |
|||
* */ |
|||
class IMPORT_PROJ_HELPER |
|||
{ |
|||
public: |
|||
IMPORT_PROJ_HELPER( KICAD_MANAGER_FRAME* aframe, const wxString& aFile, |
|||
const wxString& aSchFileExtension, const wxString& aPcbFileExtension ); |
|||
const wxFileName& GetProj(); |
|||
wxString GetProjPath(); |
|||
void SetProjPath( const wxString aPath ); |
|||
wxString GetProjFullPath(); |
|||
wxString GetProjName(); |
|||
|
|||
/** |
|||
* @brief Appends a new directory with the name of the project file |
|||
* Keep iterating until an empty directory is found |
|||
*/ |
|||
void CreateEmptyDirForProject(); |
|||
|
|||
void SetProjAbsolutePath(); |
|||
|
|||
/** |
|||
* @brief Copies project files to the destination directory |
|||
* @param displayError calls OutputCopyError() if true |
|||
*/ |
|||
bool CopyImportedFiles( bool displayError = true ); |
|||
|
|||
/** |
|||
* @brief Converts imported files to kicad type files. |
|||
* Types of imported files are needed for conversion |
|||
* @param aImportedSchFileType type of the imported schematic |
|||
* @param aImportedPcbFileType type of the imported PCB |
|||
*/ |
|||
void AssociateFilesWithProj( int aImportedSchFileType, int aImportedPcbFileType ); |
|||
|
|||
private: |
|||
KICAD_MANAGER_FRAME* m_frame; |
|||
wxFileName m_sch; |
|||
wxFileName m_shCopy; |
|||
wxFileName m_pcb; |
|||
wxFileName m_pcbCopy; |
|||
wxFileName m_pro; |
|||
bool CopyImportedFile( KICAD_T aKicad_T, bool displayError = true ); |
|||
void OutputCopyError( const wxFileName& aSrc, const wxFileName& aFileCopy ); |
|||
void AssociateFileWithProj( KICAD_T aKicad_T, int aImportedFileType ); |
|||
}; |
|||
|
|||
#endif |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue