Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| da418dfe2e |
@@ -1352,7 +1352,7 @@ ESPICE::ESPICE( wxXmlNode* aSpice, IO_BASE* aIo ) :
|
||||
* <!ELEMENT spice (pinmapping, model)>
|
||||
*/
|
||||
pinmapping = std::move( std::make_unique<EPINMAPPING>( aSpice ) );
|
||||
model = std::move( std::make_unique<EMODEL>( aSpice ) );
|
||||
//model = std::move( std::make_unique<EMODEL>( aSpice ) );
|
||||
|
||||
AdvanceProgressPhase();
|
||||
}
|
||||
@@ -1456,7 +1456,13 @@ ELAYER::ELAYER( wxXmlNode* aLayer, IO_BASE* aIo ) :
|
||||
|
||||
number = parseRequiredAttribute<int>( aLayer, "number" );
|
||||
name = parseRequiredAttribute<wxString>( aLayer, "name" );
|
||||
color = parseRequiredAttribute<int>( aLayer, "color" );
|
||||
|
||||
auto old_color = parseOptionalAttribute<int>( aLayer, "color" );
|
||||
if (old_color) {
|
||||
color = old_color.Get();
|
||||
} else {
|
||||
color = parseOptionalAttribute<int>( aLayer, "coloredcolor" ); // Autodesk fusion
|
||||
}
|
||||
fill = 1; // Temporary value.
|
||||
visible = parseOptionalAttribute<bool>( aLayer, "visible" );
|
||||
active = parseOptionalAttribute<bool>( aLayer, "active" );
|
||||
@@ -2311,8 +2317,8 @@ EPACKAGE3D::EPACKAGE3D( wxXmlNode* aPackage3d, IO_BASE* aIo ) :
|
||||
name = parseRequiredAttribute<wxString>( aPackage3d, "name" );
|
||||
urn = parseRequiredAttribute<wxString>( aPackage3d, "urn" );
|
||||
type = parseRequiredAttribute<wxString>( aPackage3d, "type" );
|
||||
library_version = parseRequiredAttribute<int>( aPackage3d, "alibrary_version" );
|
||||
library_locally_modified = parseRequiredAttribute<bool>( aPackage3d,
|
||||
library_version = parseOptionalAttribute<int>( aPackage3d, "alibrary_version" );
|
||||
library_locally_modified = parseOptionalAttribute<bool>( aPackage3d,
|
||||
"library_locally_modified" );
|
||||
|
||||
for( wxXmlNode* child = aPackage3d->GetChildren(); child; child = child->GetNext() )
|
||||
|
||||
@@ -86,6 +86,9 @@ set( EESCHEMA_SCH_IO
|
||||
# EasyEDA Pro IO plugin
|
||||
sch_io/easyedapro/sch_easyedapro_parser.cpp
|
||||
sch_io/easyedapro/sch_io_easyedapro.cpp
|
||||
|
||||
# Autodesk Fusion IO plugin
|
||||
sch_io/fusion/sch_io_fusion.cpp
|
||||
)
|
||||
|
||||
set( EESCHEMA_DLGS
|
||||
|
||||
@@ -1380,6 +1380,7 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType,
|
||||
case SCH_IO_MGR::SCH_LTSPICE:
|
||||
case SCH_IO_MGR::SCH_EASYEDA:
|
||||
case SCH_IO_MGR::SCH_EASYEDAPRO:
|
||||
case SCH_IO_MGR::SCH_FUSION:
|
||||
{
|
||||
// We insist on caller sending us an absolute path, if it does not, we say it's a bug.
|
||||
wxCHECK_MSG( filename.IsAbsolute(), false,
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 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 <sch_io/fusion/sch_io_fusion.h>
|
||||
|
||||
#include <memory>
|
||||
#include <wx/filename.h>
|
||||
|
||||
#include <sch_sheet.h>
|
||||
#include <sch_screen.h>
|
||||
#include <schematic.h>
|
||||
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <progress_reporter.h>
|
||||
#include <wx/zipstrm.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/mstream.h>
|
||||
#include "project_sch.h"
|
||||
#include "locale_io.h"
|
||||
|
||||
SCH_IO_FUSION::SCH_IO_FUSION() : SCH_IO( wxS( "Autodesk Fusion" ) ),
|
||||
m_rootSheet( nullptr ),
|
||||
m_schematic( nullptr )//,
|
||||
//m_module( nullptr ),
|
||||
//m_sheetIndex( 1 )
|
||||
{
|
||||
m_reporter = &WXLOG_REPORTER::GetInstance();
|
||||
}
|
||||
|
||||
|
||||
SCH_IO_FUSION::~SCH_IO_FUSION()
|
||||
{
|
||||
}
|
||||
|
||||
bool SCH_IO_FUSION::CanReadSchematicFile( const wxString& aFileName ) const
|
||||
{
|
||||
if( !SCH_IO::CanReadSchematicFile( aFileName ) )
|
||||
return false;
|
||||
|
||||
return true;// TODO: checkHeader( aFileName );
|
||||
}
|
||||
|
||||
bool SCH_IO_FUSION::CanReadLibrary( const wxString& aFileName ) const {
|
||||
return false; // not implemented
|
||||
}
|
||||
|
||||
int SCH_IO_FUSION::GetModifyHash() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
nlohmann::json ReadProjectFile( const wxString& aZipFileName )
|
||||
{
|
||||
std::shared_ptr<wxZipEntry> entry;
|
||||
wxFFileInputStream in( aZipFileName );
|
||||
wxZipInputStream zip( in );
|
||||
|
||||
std::cerr << "ReadProjectFile: " << aZipFileName << std::endl;
|
||||
|
||||
while( entry.reset( zip.GetNextEntry() ), entry.get() != NULL )
|
||||
{
|
||||
wxString name = entry->GetName();
|
||||
std::cerr << "read: " << name << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
if( name == wxS( "DesignDescription.json" ) )
|
||||
{
|
||||
wxMemoryOutputStream memos;
|
||||
memos << zip;
|
||||
wxStreamBuffer* buf = memos.GetOutputStreamBuffer();
|
||||
|
||||
wxString str =
|
||||
wxString::FromUTF8( (char*) buf->GetBufferStart(), buf->GetBufferSize() );
|
||||
|
||||
std::cerr << "read: " << str << std::endl;
|
||||
|
||||
return nlohmann::json::parse( str );
|
||||
}
|
||||
}
|
||||
catch( nlohmann::json::exception& e )
|
||||
{
|
||||
THROW_IO_ERROR(
|
||||
wxString::Format( _( "JSON error reading '%s': %s" ), name, e.what() ) );
|
||||
}
|
||||
catch( std::exception& e )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Error reading '%s': %s" ), name, e.what() ) );
|
||||
}
|
||||
}
|
||||
|
||||
THROW_IO_ERROR( wxString::Format(
|
||||
_( "'%s' does not appear to be a valid Autodesk Fusion "
|
||||
"project or schematic file. Cannot find project.json or device.json." ),
|
||||
aZipFileName ) );
|
||||
}
|
||||
|
||||
nlohmann::json ReadSchematicFile( const wxString& aZipFileName )
|
||||
{
|
||||
std::shared_ptr<wxZipEntry> entry;
|
||||
wxFFileInputStream in( aZipFileName );
|
||||
wxZipInputStream zip( in );
|
||||
|
||||
std::cerr << "ReadProjectFile: " << aZipFileName << std::endl;
|
||||
|
||||
while( entry.reset( zip.GetNextEntry() ), entry.get() != NULL )
|
||||
{
|
||||
wxString name = entry->GetName();
|
||||
std::cerr << "read: " << name << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
if( name == wxS( "Manifest.dat" ) )
|
||||
{
|
||||
wxMemoryOutputStream memos;
|
||||
memos << zip;
|
||||
wxStreamBuffer* buf = memos.GetOutputStreamBuffer();
|
||||
|
||||
wxString str =
|
||||
wxString::FromUTF8( (char*) buf->GetBufferStart(), buf->GetBufferSize() );
|
||||
|
||||
std::cerr << "read: " << str << std::endl;
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
catch( nlohmann::json::exception& e )
|
||||
{
|
||||
THROW_IO_ERROR(
|
||||
wxString::Format( _( "JSON error reading '%s': %s" ), name, e.what() ) );
|
||||
}
|
||||
catch( std::exception& e )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Error reading '%s': %s" ), name, e.what() ) );
|
||||
}
|
||||
}
|
||||
|
||||
THROW_IO_ERROR( wxString::Format(
|
||||
_( "'%s' does not appear to be a valid Autodesk Fusion "
|
||||
"project or schematic file. Cannot find project.json or device.json." ),
|
||||
aZipFileName ) );
|
||||
}
|
||||
|
||||
SCH_SHEET* SCH_IO_FUSION::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe,
|
||||
const STRING_UTF8_MAP* aProperties ) {
|
||||
wxASSERT( !aFileName || aSchematic != nullptr );
|
||||
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
||||
|
||||
m_filename = aFileName;
|
||||
m_schematic = aSchematic;
|
||||
|
||||
std::cerr << "start loading!!" << aFileName << " - " << m_filename.GetExt() << std::endl;
|
||||
|
||||
if( m_progressReporter )
|
||||
{
|
||||
m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
|
||||
|
||||
if( !m_progressReporter->KeepRefreshing() )
|
||||
THROW_IO_ERROR( ( "Open canceled by user." ) );
|
||||
}
|
||||
|
||||
if( m_filename.GetExt() == "f3z" )
|
||||
{
|
||||
ReadProjectFile( m_filename.GetFullPath() );
|
||||
}
|
||||
if( m_filename.GetExt() == "fsch" )
|
||||
{
|
||||
ReadSchematicFile( m_filename.GetFullPath() );
|
||||
}
|
||||
|
||||
// TODO: lead ZIP file: m_filename.GetFullPath()
|
||||
|
||||
// Load the document
|
||||
/*wxXmlDocument xmlDocument = loadXmlDocument( m_filename.GetFullPath() );
|
||||
|
||||
// Retrieve the root as current node
|
||||
wxXmlNode* currentNode = xmlDocument.GetRoot();
|
||||
|
||||
if( m_progressReporter )
|
||||
m_progressReporter->SetNumPhases( static_cast<int>( GetNodeCount( currentNode ) ) );
|
||||
*/
|
||||
// Delete on exception, if I own m_rootSheet, according to aAppendToMe
|
||||
std::unique_ptr<SCH_SHEET> deleter( aAppendToMe ? nullptr : m_rootSheet );
|
||||
|
||||
wxFileName newFilename( m_filename );
|
||||
newFilename.SetExt( FILEEXT::KiCadSchematicFileExtension );
|
||||
|
||||
if( aAppendToMe )
|
||||
{
|
||||
wxCHECK_MSG( aSchematic->IsValid(), nullptr,
|
||||
wxT( "Can't append to a schematic with no root!" ) );
|
||||
|
||||
m_rootSheet = &aSchematic->Root();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_rootSheet = new SCH_SHEET( aSchematic );
|
||||
m_rootSheet->SetFileName( newFilename.GetFullPath() );
|
||||
aSchematic->SetRoot( m_rootSheet );
|
||||
}
|
||||
|
||||
if( !m_rootSheet->GetScreen() )
|
||||
{
|
||||
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
|
||||
screen->SetFileName( newFilename.GetFullPath() );
|
||||
m_rootSheet->SetScreen( screen );
|
||||
|
||||
// Virtual root sheet UUID must be the same as the schematic file UUID.
|
||||
const_cast<KIID&>( m_rootSheet->m_Uuid ) = screen->GetUuid();
|
||||
}
|
||||
|
||||
SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
|
||||
|
||||
wxCHECK_MSG( libTable, nullptr, wxT( "Could not load symbol lib table." ) );
|
||||
|
||||
/*
|
||||
m_pi.reset( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
|
||||
m_properties = std::make_unique<STRING_UTF8_MAP>();
|
||||
( *m_properties )[SCH_IO_KICAD_LEGACY::PropBuffering] = "";
|
||||
|
||||
/// @note No check is being done here to see if the existing symbol library exists so this
|
||||
/// will overwrite the existing one.
|
||||
if( !libTable->HasLibrary( getLibName() ) )
|
||||
{
|
||||
// Create a new empty symbol library.
|
||||
m_pi->CreateLibrary( getLibFileName().GetFullPath() );
|
||||
wxString libTableUri = wxT( "${KIPRJMOD}/" ) + getLibFileName().GetFullName();
|
||||
|
||||
// Add the new library to the project symbol library table.
|
||||
libTable->InsertRow( new SYMBOL_LIB_TABLE_ROW( getLibName(), libTableUri,
|
||||
wxT( "KiCad" ) ) );
|
||||
|
||||
// Save project symbol library table.
|
||||
wxFileName fn( m_schematic->Prj().GetProjectPath(),
|
||||
SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
||||
|
||||
// So output formatter goes out of scope and closes the file before reloading.
|
||||
{
|
||||
FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
|
||||
libTable->Format( &formatter, 0 );
|
||||
}
|
||||
|
||||
// Reload the symbol library table.
|
||||
m_schematic->Prj().SetElem( PROJECT::ELEM_SYMBOL_LIB_TABLE, nullptr );
|
||||
PROJECT_SCH::SchSymbolLibTable( &m_schematic->Prj() );
|
||||
}
|
||||
|
||||
m_eagleDoc = std::make_unique<EAGLE_DOC>( currentNode, this );
|
||||
|
||||
// If the attribute is found, store the Eagle version;
|
||||
// otherwise, store the dummy "0.0" version.
|
||||
m_version = ( m_eagleDoc->version.IsEmpty() ) ? wxString( wxS( "0.0" ) ) : m_eagleDoc->version;
|
||||
|
||||
// Load drawing
|
||||
loadDrawing( m_eagleDoc->drawing );
|
||||
|
||||
m_pi->SaveLibrary( getLibFileName().GetFullPath() );
|
||||
|
||||
SCH_SCREENS allSheets( m_rootSheet );
|
||||
allSheets.UpdateSymbolLinks(); // Update all symbol library links for all sheets.*/
|
||||
|
||||
return m_rootSheet;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 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/>.
|
||||
*/
|
||||
|
||||
#ifndef SCH_IO_FUSION_H_
|
||||
#define SCH_IO_FUSION_H_
|
||||
|
||||
#include <sch_io/sch_io.h>
|
||||
#include <sch_io/sch_io_mgr.h>
|
||||
|
||||
#include <wx/filename.h>
|
||||
#include "sch_sheet_path.h"
|
||||
|
||||
class SCH_SHEET;
|
||||
class SCHEMATIC;
|
||||
|
||||
/**
|
||||
* A #SCH_IO derivation for loading Autodesk Fusion schematic files.
|
||||
*
|
||||
* As with all #SCH_IO objects there are no UI dependencies i.e. windowing calls allowed.
|
||||
*/
|
||||
class SCH_IO_FUSION : public SCH_IO
|
||||
{
|
||||
public:
|
||||
SCH_IO_FUSION();
|
||||
~SCH_IO_FUSION();
|
||||
|
||||
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
|
||||
{
|
||||
return IO_BASE::IO_FILE_DESC( _HKI( "Autodesk Fusion schematic files" ), { "fsch", "f3z" } );
|
||||
}
|
||||
|
||||
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
|
||||
{
|
||||
return IO_BASE::IO_FILE_DESC( wxEmptyString, { } );
|
||||
}
|
||||
|
||||
bool CanReadSchematicFile( const wxString& aFileName ) const override;
|
||||
bool CanReadLibrary( const wxString& aFileName ) const override;
|
||||
|
||||
int GetModifyHash() const override;
|
||||
|
||||
SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
|
||||
SCH_SHEET* aAppendToMe = nullptr,
|
||||
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
||||
|
||||
private:
|
||||
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded
|
||||
SCH_SHEET_PATH m_sheetPath; ///< The current sheet path of the schematic being loaded.
|
||||
wxString m_version; ///< Eagle file version.
|
||||
wxFileName m_filename;
|
||||
SCHEMATIC* m_schematic; ///< Passed to Load(), the schematic object being loaded
|
||||
};
|
||||
|
||||
#endif // SCH_IO_FUSION_H_
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <sch_io/cadstar/sch_io_cadstar_archive.h>
|
||||
#include <sch_io/easyeda/sch_io_easyeda.h>
|
||||
#include <sch_io/easyedapro/sch_io_easyedapro.h>
|
||||
#include <sch_io/fusion/sch_io_fusion.h>
|
||||
#include <sch_io/database/sch_io_database.h>
|
||||
#include <sch_io/ltspice/sch_io_ltspice.h>
|
||||
#include <sch_io/http_lib/sch_io_http_lib.h>
|
||||
@@ -73,6 +74,7 @@ SCH_IO* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType )
|
||||
case SCH_EAGLE: return new SCH_IO_EAGLE();
|
||||
case SCH_EASYEDA: return new SCH_IO_EASYEDA();
|
||||
case SCH_EASYEDAPRO: return new SCH_IO_EASYEDAPRO();
|
||||
case SCH_FUSION: return new SCH_IO_FUSION();
|
||||
case SCH_LTSPICE: return new SCH_IO_LTSPICE();
|
||||
case SCH_HTTP: return new SCH_IO_HTTP_LIB();
|
||||
default: return nullptr;
|
||||
@@ -96,6 +98,7 @@ const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType )
|
||||
case SCH_EAGLE: return wxString( wxT( "EAGLE" ) );
|
||||
case SCH_EASYEDA: return wxString( wxT( "EasyEDA (JLCEDA) Std" ) );
|
||||
case SCH_EASYEDAPRO: return wxString( wxT( "EasyEDA (JLCEDA) Pro" ) );
|
||||
case SCH_FUSION: return wxString( wxT( "Autodesk Fusion" ) );
|
||||
case SCH_LTSPICE: return wxString( wxT( "LTspice" ) );
|
||||
case SCH_HTTP: return wxString( wxT( "HTTP" ) );
|
||||
default: return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ),
|
||||
@@ -126,6 +129,8 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr( const wxString& aType )
|
||||
return SCH_EASYEDA;
|
||||
else if( aType == wxT( "EasyEDA (JLCEDA) Pro" ) )
|
||||
return SCH_EASYEDAPRO;
|
||||
else if( aType == wxT( "Autodesk Fusion" ) )
|
||||
return SCH_FUSION;
|
||||
else if( aType == wxT( "LTspice" ) )
|
||||
return SCH_LTSPICE;
|
||||
else if( aType == wxT( "HTTP" ) )
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
SCH_EAGLE, ///< Autodesk Eagle file format
|
||||
SCH_EASYEDA, ///< EasyEDA Std schematic file
|
||||
SCH_EASYEDAPRO, ///< EasyEDA Pro archive
|
||||
SCH_FUSION, ///< Autodesk Fusion file format
|
||||
SCH_LTSPICE, ///< LtSpice Schematic format
|
||||
SCH_HTTP, ///< KiCad HTTP library
|
||||
|
||||
|
||||
Reference in New Issue
Block a user