Update project template system for new format
This commit is contained in:
parent
12b4a55ae8
commit
b592a4169f
|
@ -267,102 +267,6 @@ void PROJECT::SetElem( ELEM_T aIndex, _ELEM* aElem )
|
|||
}
|
||||
|
||||
|
||||
static bool copy_pro_file_template( const SEARCH_STACK& aSearchS, const wxString& aDestination )
|
||||
{
|
||||
if( aDestination.IsEmpty() )
|
||||
{
|
||||
wxLogTrace( tracePathsAndFiles, "%s: destination is empty.", __func__ );
|
||||
return false;
|
||||
}
|
||||
|
||||
wxString templateFile = wxT( "kicad." ) + LegacyProjectFileExtension;
|
||||
|
||||
wxString kicad_pro_template = aSearchS.FindValidPath( templateFile );
|
||||
|
||||
if( !kicad_pro_template )
|
||||
{
|
||||
wxLogTrace( tracePathsAndFiles, "%s: template file '%s' not found using search paths.",
|
||||
__func__, TO_UTF8( templateFile ) );
|
||||
|
||||
wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
|
||||
wxT( "kicad" ), LegacyProjectFileExtension );
|
||||
|
||||
if( !templ.IsFileReadable() )
|
||||
{
|
||||
wxString msg = wxString::Format( _(
|
||||
"Unable to find \"%s\" template config file." ),
|
||||
GetChars( templateFile ) );
|
||||
|
||||
DisplayErrorMessage( nullptr, _( "Error copying project file template" ), msg );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
kicad_pro_template = templ.GetFullPath();
|
||||
}
|
||||
|
||||
wxLogTrace( tracePathsAndFiles, "%s: using template file '%s' as project file.",
|
||||
__func__, TO_UTF8( kicad_pro_template ) );
|
||||
|
||||
// Verify aDestination can be created. if this is not the case, wxCopyFile
|
||||
// will generate a crappy log error message, and we *do not want* this kind
|
||||
// of stupid message
|
||||
wxFileName fn( aDestination );
|
||||
bool success = true;
|
||||
|
||||
if( fn.IsOk() && fn.IsDirWritable() )
|
||||
success = wxCopyFile( kicad_pro_template, aDestination );
|
||||
else
|
||||
{
|
||||
wxLogMessage( _( "Cannot create prj file \"%s\" (Directory not writable)" ),
|
||||
GetChars( aDestination) );
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList,
|
||||
const wxString& aGroupName, const wxString& aProjectFileName )
|
||||
{
|
||||
wxConfigBase* cfg = 0;
|
||||
wxString cur_pro_fn = !aProjectFileName ? GetProjectFullName() : aProjectFileName;
|
||||
|
||||
wxFileName filename( cur_pro_fn );
|
||||
|
||||
if( filename.GetExt() == ProjectFileExtension )
|
||||
{
|
||||
filename.SetExt( LegacyProjectFileExtension );
|
||||
cur_pro_fn = filename.GetFullPath();
|
||||
}
|
||||
|
||||
// If we do not have a project name or specified name, choose an empty file to store the
|
||||
// temporary configuration data in.
|
||||
if( cur_pro_fn.IsEmpty() )
|
||||
cur_pro_fn = wxFileName::CreateTempFileName( GetProjectPath() );
|
||||
|
||||
if( wxFileName( cur_pro_fn ).IsFileReadable() )
|
||||
{
|
||||
// Note: currently, aGroupName is not used.
|
||||
// Previoulsy, the version of aGroupName was tested, but it
|
||||
// was useless, and if the version is important,
|
||||
// this is not the right place here, because configCreate does know anything
|
||||
// about info stored in this config file.
|
||||
cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
|
||||
return cfg;
|
||||
}
|
||||
|
||||
// No suitable pro file was found, either does not exist, or not readable.
|
||||
// Use the template kicad.pro file. Find it by using caller's SEARCH_STACK.
|
||||
copy_pro_file_template( aSList, cur_pro_fn );
|
||||
|
||||
cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
|
||||
const wxString PROJECT::AbsolutePath( const wxString& aFileName ) const
|
||||
{
|
||||
wxFileName fn = aFileName;
|
||||
|
|
|
@ -316,17 +316,6 @@ private:
|
|||
m_localSettings = aSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function configCreate
|
||||
* loads a *.pro file and returns a wxConfigBase.
|
||||
*
|
||||
* @param aSList is the KIFACE or PGM's SEARCH_STACK
|
||||
* @param aGroupName is the default config file subset to use.
|
||||
* @param aProjectFileName is the *.pro file to open.
|
||||
*/
|
||||
wxConfigBase* configCreate( const SEARCH_STACK& aSList,
|
||||
const wxString& aGroupName, const wxString& aProjectFileName = wxEmptyString );
|
||||
|
||||
/**
|
||||
* Return the full path and file name of the project specific library table \a aLibTableName..
|
||||
*/
|
||||
|
|
|
@ -77,7 +77,7 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event )
|
|||
|
||||
wxFileName pro = sch;
|
||||
|
||||
pro.SetExt( LegacyProjectFileExtension );
|
||||
pro.SetExt( ProjectFileExtension );
|
||||
|
||||
wxString protitle = _( "KiCad Project Destination" );
|
||||
|
||||
|
@ -115,7 +115,7 @@ void KICAD_MANAGER_FRAME::OnImportEagleFiles( wxCommandEvent& event )
|
|||
}
|
||||
|
||||
wxFileName pcb( sch );
|
||||
pro.SetExt( LegacyProjectFileExtension ); // enforce extension
|
||||
pro.SetExt( ProjectFileExtension );
|
||||
pcb.SetExt( LegacyPcbFileExtension ); // enforce extension
|
||||
|
||||
if( !pro.IsAbsolute() )
|
||||
|
|
|
@ -370,20 +370,33 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxFileName& aProjectFileName )
|
|||
// Init project filename. This clears all elements from the project object.
|
||||
SetProjectFileName( aProjectFileName.GetFullPath() );
|
||||
|
||||
// Copy kicad.pro file from template folder.
|
||||
// If the project is legacy, convert it
|
||||
if( !aProjectFileName.FileExists() )
|
||||
{
|
||||
// TODO(JE) PROJECT provide in new format
|
||||
wxString srcFileName = sys_search().FindValidPath( "kicad.pro" );
|
||||
wxFileName legacyPro( aProjectFileName );
|
||||
legacyPro.SetExt( LegacyProjectFileExtension );
|
||||
|
||||
wxFileName destFileName( aProjectFileName );
|
||||
destFileName.SetExt( LegacyProjectFileExtension );
|
||||
|
||||
// Create a minimal project (.pro) file if the template project file could not be copied.
|
||||
if( !wxFileName::FileExists( srcFileName )
|
||||
|| !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
|
||||
if( legacyPro.FileExists() )
|
||||
{
|
||||
Pgm().GetSettingsManager().SaveProject();
|
||||
GetSettingsManager()->LoadProject( legacyPro.GetFullPath() );
|
||||
GetSettingsManager()->SaveProject();
|
||||
|
||||
wxRemoveFile( legacyPro.GetFullPath() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy template project file from template folder.
|
||||
wxString srcFileName = sys_search().FindValidPath( "kicad.kicad_pro" );
|
||||
|
||||
wxFileName destFileName( aProjectFileName );
|
||||
destFileName.SetExt( ProjectFileExtension );
|
||||
|
||||
// Create a minimal project file if the template project file could not be copied
|
||||
if( !wxFileName::FileExists( srcFileName )
|
||||
|| !wxCopyFile( srcFileName, destFileName.GetFullPath() ) )
|
||||
{
|
||||
Pgm().GetSettingsManager().SaveProject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2012 Brian Sidebotham <brian.sidebotham@gmail.com>
|
||||
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2020 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
|
||||
|
@ -29,6 +29,7 @@
|
|||
#include <wx/wfstream.h>
|
||||
#include <wx/log.h>
|
||||
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include "project_template.h"
|
||||
|
||||
|
||||
|
@ -128,7 +129,7 @@ size_t PROJECT_TEMPLATE::GetDestinationFiles( const wxFileName& aNewProjectPath,
|
|||
|
||||
for( wxFileName& file : srcFiles )
|
||||
{
|
||||
if( file.GetExt() == wxT( "pro" ) )
|
||||
if( file.GetExt() == ProjectFileExtension || file.GetExt() == LegacyProjectFileExtension )
|
||||
{
|
||||
basename = file.GetName();
|
||||
projectCount++;
|
||||
|
@ -174,7 +175,7 @@ bool PROJECT_TEMPLATE::CreateProject( wxFileName& aNewProjectPath, wxString* aEr
|
|||
|
||||
for( wxFileName& file : srcFiles )
|
||||
{
|
||||
if( file.GetExt() == wxT( "pro" ) )
|
||||
if( file.GetExt() == ProjectFileExtension || file.GetExt() == LegacyProjectFileExtension )
|
||||
{
|
||||
basename = file.GetName();
|
||||
projectCount++;
|
||||
|
|
|
@ -192,11 +192,10 @@ int KICAD_MANAGER_CONTROL::NewFromTemplate( const TOOL_EVENT& aEvent )
|
|||
|
||||
// wxFileName automatically extracts an extension. But if it isn't
|
||||
// a .pro extension, we should keep it as part of the filename
|
||||
if( !fn.GetExt().IsEmpty()
|
||||
&& fn.GetExt().ToStdString() != LegacyProjectFileExtension )
|
||||
if( !fn.GetExt().IsEmpty() && fn.GetExt().ToStdString() != ProjectFileExtension )
|
||||
fn.SetName( fn.GetName() + wxT( "." ) + fn.GetExt() );
|
||||
|
||||
fn.SetExt( LegacyProjectFileExtension ); // enforce extension
|
||||
fn.SetExt( ProjectFileExtension );
|
||||
|
||||
if( !fn.IsAbsolute() )
|
||||
fn.MakeAbsolute();
|
||||
|
|
|
@ -509,7 +509,7 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
|
|||
fn.Clear();
|
||||
fn.SetPath( wxStandardPaths::Get().GetDocumentsDir() );
|
||||
fn.SetName( NAMELESS_PROJECT );
|
||||
fn.SetExt( LegacyProjectFileExtension );
|
||||
fn.SetExt( ProjectFileExtension );
|
||||
}
|
||||
|
||||
bool prjOpened = fn.FileExists();
|
||||
|
|
|
@ -56,7 +56,7 @@ bool DIALOG_IMPORT_SETTINGS::TransferDataToWindow()
|
|||
void DIALOG_IMPORT_SETTINGS::OnBrowseClicked( wxCommandEvent& event )
|
||||
{
|
||||
wxFileName fn = m_frame->GetBoard()->GetFileName();
|
||||
fn.SetExt( LegacyProjectFileExtension );
|
||||
fn.SetExt( ProjectFileExtension );
|
||||
|
||||
wxFileDialog dlg( this, _( "Import Settings From" ), fn.GetPath(), fn.GetFullName(),
|
||||
PcbFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
install( FILES
|
||||
kicad.pro
|
||||
kicad.kicad_pro
|
||||
|
||||
DESTINATION ${KICAD_TEMPLATE}
|
||||
COMPONENT resources
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"board": {
|
||||
"design_settings": {
|
||||
"defaults": {
|
||||
"board_outline_line_width": 0.1,
|
||||
"copper_line_width": 0.2,
|
||||
"copper_text_size_h": 1.5,
|
||||
"copper_text_size_v": 1.5,
|
||||
"copper_text_thickness": 0.3,
|
||||
"other_line_width": 0.15,
|
||||
"silk_line_width": 0.15,
|
||||
"silk_text_size_h": 1.0,
|
||||
"silk_text_size_v": 1.0,
|
||||
"silk_text_thickness": 0.15
|
||||
},
|
||||
"diff_pair_dimensions": [],
|
||||
"drc_exclusions": [],
|
||||
"rules": {
|
||||
"min_copper_edge_clearance": 0.0,
|
||||
"solder_mask_clearance": 0.0,
|
||||
"solder_mask_min_width": 0.0
|
||||
},
|
||||
"track_widths": [],
|
||||
"via_dimensions": []
|
||||
}
|
||||
},
|
||||
"boards": [],
|
||||
"libraries": {
|
||||
"pinned_footprint_libs": [],
|
||||
"pinned_symbol_libs": []
|
||||
},
|
||||
"meta": {
|
||||
"filename": "kicad.kicad_pro",
|
||||
"version": 1
|
||||
},
|
||||
"net_settings": {
|
||||
"classes": [
|
||||
{
|
||||
"clearance": 0.2,
|
||||
"diff_pair_gap": 0.25,
|
||||
"diff_pair_via_gap": 0.25,
|
||||
"diff_pair_width": 0.2,
|
||||
"microvia_diameter": 0.3,
|
||||
"microvia_drill": 0.1,
|
||||
"name": "Default",
|
||||
"nets": [],
|
||||
"track_width": 0.25,
|
||||
"via_diameter": 0.8,
|
||||
"via_drill": 0.4
|
||||
}
|
||||
],
|
||||
"meta": {
|
||||
"version": 0
|
||||
}
|
||||
},
|
||||
"pcbnew": {
|
||||
"page_layout_descr_file": ""
|
||||
},
|
||||
"sheets": [],
|
||||
"text_variables": {}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
update=05/04/2019 20:44:53
|
||||
version=1
|
||||
last_client=kicad
|
||||
[general]
|
||||
version=1
|
||||
RootSch=
|
||||
BoardNm=
|
||||
[pcbnew]
|
||||
version=1
|
||||
LastNetListRead=
|
||||
UseCmpFile=1
|
||||
PadDrill=0.600000000000
|
||||
PadDrillOvalY=0.600000000000
|
||||
PadSizeH=1.500000000000
|
||||
PadSizeV=1.500000000000
|
||||
PcbTextSizeV=1.500000000000
|
||||
PcbTextSizeH=1.500000000000
|
||||
PcbTextThickness=0.300000000000
|
||||
ModuleTextSizeV=1.000000000000
|
||||
ModuleTextSizeH=1.000000000000
|
||||
ModuleTextSizeThickness=0.150000000000
|
||||
SolderMaskClearance=0.000000000000
|
||||
SolderMaskMinWidth=0.000000000000
|
||||
DrawSegmentWidth=0.200000000000
|
||||
BoardOutlineThickness=0.100000000000
|
||||
ModuleOutlineThickness=0.150000000000
|
||||
CopperEdgeClearance=0.000000000000
|
||||
[cvpcb]
|
||||
version=1
|
||||
NetIExt=net
|
||||
[eeschema]
|
||||
version=1
|
||||
LibDir=
|
||||
[eeschema/libraries]
|
Loading…
Reference in New Issue