2017-09-29 09:44:05 +00:00
|
|
|
/*
|
2017-04-15 16:08:23 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors.
|
2017-09-29 09:44:05 +00:00
|
|
|
* @author Kristoffer Ödmark
|
2017-04-15 16:08:23 +00:00
|
|
|
*
|
|
|
|
* 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 <wx/clipbrd.h>
|
2019-12-06 14:26:59 +00:00
|
|
|
|
|
|
|
#include <build_version.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
|
|
|
#include <pcb_text.h>
|
|
|
|
#include <fp_text.h>
|
2017-04-15 16:08:23 +00:00
|
|
|
#include <common.h>
|
2018-01-30 14:34:09 +00:00
|
|
|
#include <netinfo.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <plugins/kicad/pcb_parser.h>
|
2017-04-15 16:08:23 +00:00
|
|
|
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <plugins/kicad/kicad_plugin.h>
|
2017-04-15 16:08:23 +00:00
|
|
|
#include <kicad_clipboard.h>
|
|
|
|
|
|
|
|
CLIPBOARD_IO::CLIPBOARD_IO():
|
2020-09-24 16:48:49 +00:00
|
|
|
PCB_IO( CTL_FOR_CLIPBOARD ),
|
2017-04-15 16:08:23 +00:00
|
|
|
m_formatter(),
|
|
|
|
m_parser( new CLIPBOARD_PARSER() )
|
|
|
|
{
|
|
|
|
m_out = &m_formatter;
|
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-11-01 09:20:13 +00:00
|
|
|
CLIPBOARD_IO::~CLIPBOARD_IO()
|
|
|
|
{
|
|
|
|
delete m_parser;
|
|
|
|
}
|
2017-04-15 16:08:23 +00:00
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-04-15 16:08:23 +00:00
|
|
|
STRING_FORMATTER* CLIPBOARD_IO::GetFormatter()
|
|
|
|
{
|
|
|
|
return &m_formatter;
|
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-09-22 15:17:38 +00:00
|
|
|
void CLIPBOARD_IO::SetBoard( BOARD* aBoard )
|
2017-04-15 16:08:23 +00:00
|
|
|
{
|
|
|
|
m_board = aBoard;
|
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2020-07-27 17:56:15 +00:00
|
|
|
void CLIPBOARD_IO::SaveSelection( const PCBNEW_SELECTION& aSelected, bool isModEdit )
|
2017-04-15 16:08:23 +00:00
|
|
|
{
|
2017-09-29 09:44:05 +00:00
|
|
|
VECTOR2I refPoint( 0, 0 );
|
2017-04-15 16:08:23 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
// dont even start if the selection is empty
|
2017-04-15 16:08:23 +00:00
|
|
|
if( aSelected.Empty() )
|
|
|
|
return;
|
|
|
|
|
2017-09-22 15:17:38 +00:00
|
|
|
if( aSelected.HasReferencePoint() )
|
|
|
|
refPoint = aSelected.GetReferencePoint();
|
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
// Prepare net mapping that assures that net codes saved in a file are consecutive integers
|
|
|
|
m_mapping->SetBoard( m_board );
|
2017-04-15 16:08:23 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
if( aSelected.Size() == 1 && aSelected.Front()->Type() == PCB_MODULE_T )
|
|
|
|
{
|
|
|
|
// make the module safe to transfer to other pcbs
|
2017-09-18 23:07:28 +00:00
|
|
|
const MODULE* mod = static_cast<MODULE*>( aSelected.Front() );
|
|
|
|
// Do not modify existing board
|
2019-11-03 16:09:23 +00:00
|
|
|
MODULE newModule( *mod );
|
2017-09-18 23:07:28 +00:00
|
|
|
|
2019-11-03 16:09:23 +00:00
|
|
|
for( D_PAD* pad : newModule.Pads() )
|
|
|
|
pad->SetNetCode( 0 );
|
|
|
|
|
|
|
|
// locked means "locked in place"; copied items therefore can't be locked
|
|
|
|
newModule.SetLocked( false );
|
2017-09-17 18:29:48 +00:00
|
|
|
|
2017-09-22 15:17:38 +00:00
|
|
|
// locate the reference point at (0, 0) in the copied items
|
2017-09-29 09:44:05 +00:00
|
|
|
newModule.Move( wxPoint( -refPoint.x, -refPoint.y ) );
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2017-09-18 23:07:28 +00:00
|
|
|
Format( static_cast<BOARD_ITEM*>( &newModule ) );
|
2017-04-15 16:08:23 +00:00
|
|
|
}
|
2020-07-27 17:56:15 +00:00
|
|
|
else if( isModEdit )
|
2017-05-18 17:21:30 +00:00
|
|
|
{
|
2020-07-27 17:56:15 +00:00
|
|
|
MODULE partialModule( m_board );
|
|
|
|
|
|
|
|
for( const EDA_ITEM* item : aSelected )
|
2017-05-18 17:21:30 +00:00
|
|
|
{
|
2020-10-20 11:37:38 +00:00
|
|
|
const PCB_GROUP* group = dynamic_cast<const PCB_GROUP*>( item );
|
|
|
|
BOARD_ITEM* clone;
|
|
|
|
|
|
|
|
if( group )
|
|
|
|
clone = static_cast<BOARD_ITEM*>( group->DeepClone() );
|
|
|
|
else
|
|
|
|
clone = static_cast<BOARD_ITEM*>( item->Clone() );
|
2017-05-18 17:21:30 +00:00
|
|
|
|
|
|
|
// Do not add reference/value - convert them to the common type
|
2020-10-04 23:34:59 +00:00
|
|
|
if( FP_TEXT* text = dyn_cast<FP_TEXT*>( clone ) )
|
|
|
|
text->SetType( FP_TEXT::TEXT_is_DIVERS );
|
2017-05-18 17:21:30 +00:00
|
|
|
|
|
|
|
// If it is only a module, clear the nets from the pads
|
2019-11-03 16:09:23 +00:00
|
|
|
if( D_PAD* pad = dyn_cast<D_PAD*>( clone ) )
|
|
|
|
pad->SetNetCode( 0 );
|
2017-05-18 17:21:30 +00:00
|
|
|
|
2019-01-13 21:20:29 +00:00
|
|
|
// Add the pad to the new module before moving to ensure the local coords are correct
|
|
|
|
partialModule.Add( clone );
|
|
|
|
|
2020-10-20 11:37:38 +00:00
|
|
|
if( group )
|
|
|
|
{
|
|
|
|
static_cast<PCB_GROUP*>( clone )->RunOnDescendants(
|
|
|
|
[&]( BOARD_ITEM* descendant )
|
|
|
|
{
|
|
|
|
partialModule.Add( descendant );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2017-09-22 15:17:38 +00:00
|
|
|
// locate the reference point at (0, 0) in the copied items
|
2019-08-20 18:40:26 +00:00
|
|
|
clone->Move( (wxPoint) -refPoint );
|
2017-05-18 17:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the new relative internal local coordinates of copied items
|
2019-05-31 00:15:57 +00:00
|
|
|
MODULE* editedModule = m_board->Modules().front();
|
2017-09-18 23:07:28 +00:00
|
|
|
wxPoint moveVector = partialModule.GetPosition() + editedModule->GetPosition();
|
2017-05-18 17:21:30 +00:00
|
|
|
|
2017-09-18 23:07:28 +00:00
|
|
|
partialModule.MoveAnchorPosition( moveVector );
|
2017-05-18 17:21:30 +00:00
|
|
|
|
2017-09-18 23:07:28 +00:00
|
|
|
Format( &partialModule, 0 );
|
2017-05-18 17:21:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we will fake being a .kicad_pcb to get the full parser kicking
|
|
|
|
// This means we also need layers and nets
|
2018-11-22 16:12:41 +00:00
|
|
|
LOCALE_IO io;
|
|
|
|
|
2020-08-30 14:19:17 +00:00
|
|
|
m_formatter.Print( 0, "(kicad_pcb (version %d) (generator pcbnew)\n",
|
|
|
|
SEXPR_BOARD_FILE_VERSION );
|
2017-04-15 16:08:23 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
m_formatter.Print( 0, "\n" );
|
|
|
|
|
|
|
|
formatBoardLayers( m_board );
|
|
|
|
formatNetInformation( m_board );
|
|
|
|
|
|
|
|
m_formatter.Print( 0, "\n" );
|
|
|
|
|
2020-07-27 17:56:15 +00:00
|
|
|
for( EDA_ITEM* i : aSelected )
|
2017-05-18 17:21:30 +00:00
|
|
|
{
|
2020-07-27 17:56:15 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( i );
|
|
|
|
BOARD_ITEM* copy = nullptr;
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( item->Type() == PCB_FP_SHAPE_T )
|
2017-05-18 17:21:30 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
// Convert to PCB_SHAPE_T
|
2020-10-04 23:34:59 +00:00
|
|
|
copy = (BOARD_ITEM*) reinterpret_cast<PCB_SHAPE*>( item )->Clone();
|
2020-07-27 17:56:15 +00:00
|
|
|
copy->SetLayer( item->GetLayer() );
|
|
|
|
}
|
2020-10-04 14:19:33 +00:00
|
|
|
else if( item->Type() == PCB_FP_TEXT_T )
|
2020-07-27 17:56:15 +00:00
|
|
|
{
|
|
|
|
// Convert to PCB_TEXT_T
|
2020-10-04 23:34:59 +00:00
|
|
|
MODULE* mod = static_cast<MODULE*>( item->GetParent() );
|
|
|
|
FP_TEXT* fp_text = static_cast<FP_TEXT*>( item );
|
|
|
|
PCB_TEXT* pcb_text = new PCB_TEXT( m_board );
|
2020-07-27 17:56:15 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
if( fp_text->GetText() == "${VALUE}" )
|
2020-07-27 17:56:15 +00:00
|
|
|
pcb_text->SetText( mod->GetValue() );
|
2020-10-04 23:34:59 +00:00
|
|
|
else if( fp_text->GetText() == "${REFERENCE}" )
|
2020-07-27 17:56:15 +00:00
|
|
|
pcb_text->SetText( mod->GetReference() );
|
|
|
|
else
|
2020-10-04 23:34:59 +00:00
|
|
|
pcb_text->CopyText( *fp_text );
|
2020-07-27 17:56:15 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
pcb_text->SetEffects( *fp_text );
|
|
|
|
pcb_text->SetLayer( fp_text->GetLayer() );
|
2020-07-27 17:56:15 +00:00
|
|
|
copy = pcb_text;
|
|
|
|
}
|
|
|
|
else if( item->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
// Create a parent to own the copied pad
|
|
|
|
MODULE* mod = new MODULE( m_board );
|
|
|
|
D_PAD* pad = (D_PAD*) item->Clone();
|
|
|
|
|
|
|
|
mod->SetPosition( pad->GetPosition() );
|
|
|
|
pad->SetPos0( wxPoint() );
|
|
|
|
mod->Add( pad );
|
|
|
|
copy = mod;
|
|
|
|
}
|
2020-10-04 14:19:33 +00:00
|
|
|
else if( item->Type() == PCB_FP_ZONE_AREA_T )
|
2020-07-27 17:56:15 +00:00
|
|
|
{
|
|
|
|
// Convert to PCB_ZONE_AREA_T
|
|
|
|
ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
|
|
|
|
zone->InitDataFromSrcInCopyCtor( *static_cast<ZONE_CONTAINER*>( item ) );
|
|
|
|
copy = zone;
|
|
|
|
}
|
2020-08-11 19:37:07 +00:00
|
|
|
else if( item->Type() == PCB_GROUP_T )
|
|
|
|
{
|
2020-08-12 11:23:30 +00:00
|
|
|
copy = static_cast<PCB_GROUP*>( item )->DeepClone();
|
2020-08-11 19:37:07 +00:00
|
|
|
}
|
2020-07-27 17:56:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
copy = static_cast<BOARD_ITEM*>( item->Clone() );
|
|
|
|
}
|
2019-11-03 16:09:23 +00:00
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
auto prepItem = [&]( BOARD_ITEM* titem ) {
|
|
|
|
// locked means "locked in place"; copied items therefore can't be locked
|
|
|
|
if( MODULE* module = dyn_cast<MODULE*>( titem ) )
|
|
|
|
module->SetLocked( false );
|
|
|
|
else if( TRACK* track = dyn_cast<TRACK*>( titem ) )
|
|
|
|
track->SetLocked( false );
|
|
|
|
};
|
|
|
|
|
2020-07-27 17:56:15 +00:00
|
|
|
if( copy )
|
|
|
|
{
|
2020-08-11 19:37:07 +00:00
|
|
|
prepItem( copy );
|
|
|
|
|
2017-09-22 15:17:38 +00:00
|
|
|
// locate the reference point at (0, 0) in the copied items
|
2020-07-27 17:56:15 +00:00
|
|
|
copy->Move( (wxPoint) -refPoint );
|
|
|
|
|
|
|
|
Format( copy, 1 );
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2020-08-11 19:37:07 +00:00
|
|
|
if( copy->Type() == PCB_GROUP_T )
|
|
|
|
{
|
2020-08-12 11:23:30 +00:00
|
|
|
static_cast<PCB_GROUP*>( copy )->RunOnDescendants( prepItem );
|
|
|
|
static_cast<PCB_GROUP*>( copy )->RunOnDescendants( [&]( BOARD_ITEM* titem ) {
|
2020-08-11 19:37:07 +00:00
|
|
|
Format( titem, 1 );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2020-07-27 17:56:15 +00:00
|
|
|
delete copy;
|
2017-05-18 17:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_formatter.Print( 0, "\n)" );
|
|
|
|
}
|
2018-11-02 04:12:34 +00:00
|
|
|
|
2018-11-22 16:12:41 +00:00
|
|
|
// These are placed at the end to minimize the open time of the clipboard
|
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
|
|
|
|
|
|
|
if( !clipboardLock || !clipboard->IsOpened() )
|
|
|
|
return;
|
|
|
|
|
2018-11-02 04:12:34 +00:00
|
|
|
clipboard->SetData( new wxTextDataObject(
|
|
|
|
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
|
|
|
|
|
|
|
|
clipboard->Flush();
|
2018-11-22 16:12:41 +00:00
|
|
|
|
2020-04-03 14:54:09 +00:00
|
|
|
#ifndef __WXOSX__
|
2018-11-22 16:12:41 +00:00
|
|
|
// This section exists to return the clipboard data, ensuring it has fully
|
|
|
|
// been processed by the system clipboard. This appears to be needed for
|
|
|
|
// extremely large clipboard copies on asynchronous linux clipboard managers
|
2020-04-03 14:54:09 +00:00
|
|
|
// such as KDE's Klipper. However, a read back of the data on OSX before the
|
|
|
|
// clipboard is closed seems to cause an ASAN error (heap-buffer-overflow)
|
|
|
|
// since it uses the cached version of the clipboard data and not the system
|
|
|
|
// clipboard data.
|
2018-11-22 16:12:41 +00:00
|
|
|
{
|
|
|
|
wxTextDataObject data;
|
|
|
|
clipboard->GetData( data );
|
|
|
|
( void )data.GetText(); // Keep unused variable
|
|
|
|
}
|
2020-04-03 14:54:09 +00:00
|
|
|
#endif
|
2017-04-15 16:08:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
BOARD_ITEM* CLIPBOARD_IO::Parse()
|
|
|
|
{
|
2018-03-13 08:26:34 +00:00
|
|
|
BOARD_ITEM* item;
|
|
|
|
wxString result;
|
2017-05-18 17:21:30 +00:00
|
|
|
|
2018-11-02 04:12:34 +00:00
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
|
|
|
|
|
|
|
if( !clipboardLock )
|
|
|
|
return nullptr;
|
2017-05-18 17:21:30 +00:00
|
|
|
|
2018-11-02 04:12:34 +00:00
|
|
|
|
|
|
|
if( clipboard->IsSupported( wxDF_TEXT ) )
|
|
|
|
{
|
|
|
|
wxTextDataObject data;
|
|
|
|
clipboard->GetData( data );
|
|
|
|
result = data.GetText();
|
2017-05-18 17:21:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 15:17:38 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
item = PCB_IO::Parse( result );
|
2018-03-13 08:26:34 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2017-09-22 15:17:38 +00:00
|
|
|
item = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
2017-05-18 17:21:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
2017-04-15 16:08:23 +00:00
|
|
|
void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
|
|
|
|
const PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
m_board = aBoard; // after init()
|
|
|
|
|
|
|
|
// Prepare net mapping that assures that net codes saved in a file are consecutive integers
|
|
|
|
m_mapping->SetBoard( aBoard );
|
|
|
|
|
|
|
|
STRING_FORMATTER formatter;
|
|
|
|
|
|
|
|
m_out = &formatter;
|
|
|
|
|
2020-08-30 14:19:17 +00:00
|
|
|
m_out->Print( 0, "(kicad_pcb (version %d) (generator pcbnew)\n", SEXPR_BOARD_FILE_VERSION );
|
2017-04-15 16:08:23 +00:00
|
|
|
|
|
|
|
Format( aBoard, 1 );
|
|
|
|
|
|
|
|
m_out->Print( 0, ")\n" );
|
|
|
|
|
2018-11-22 16:12:41 +00:00
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
|
|
|
|
|
|
|
if( !clipboardLock )
|
|
|
|
return;
|
|
|
|
|
2018-11-02 04:12:34 +00:00
|
|
|
clipboard->SetData( new wxTextDataObject(
|
|
|
|
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
|
|
|
|
clipboard->Flush();
|
2018-11-22 16:12:41 +00:00
|
|
|
|
|
|
|
// This section exists to return the clipboard data, ensuring it has fully
|
|
|
|
// been processed by the system clipboard. This appears to be needed for
|
|
|
|
// extremely large clipboard copies on asynchronous linux clipboard managers
|
|
|
|
// such as KDE's Klipper
|
|
|
|
{
|
|
|
|
wxTextDataObject data;
|
|
|
|
clipboard->GetData( data );
|
|
|
|
( void )data.GetText(); // Keep unused variable
|
|
|
|
}
|
2017-04-15 16:08:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 09:44:05 +00:00
|
|
|
|
|
|
|
BOARD* CLIPBOARD_IO::Load( const wxString& aFileName,
|
|
|
|
BOARD* aAppendToMe, const PROPERTIES* aProperties )
|
2017-04-15 16:08:23 +00:00
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
|
2018-11-02 04:12:34 +00:00
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
2017-04-15 16:08:23 +00:00
|
|
|
|
2018-11-02 04:12:34 +00:00
|
|
|
if( !clipboardLock )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if( clipboard->IsSupported( wxDF_TEXT ) )
|
|
|
|
{
|
|
|
|
wxTextDataObject data;
|
|
|
|
clipboard->GetData( data );
|
2017-04-15 16:08:23 +00:00
|
|
|
|
2018-11-02 04:12:34 +00:00
|
|
|
result = data.GetText().mb_str();
|
2017-04-15 16:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STRING_LINE_READER reader(result, wxT( "clipboard" ) );
|
|
|
|
|
|
|
|
init( aProperties );
|
|
|
|
|
|
|
|
m_parser->SetLineReader( &reader );
|
|
|
|
m_parser->SetBoard( aAppendToMe );
|
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
BOARD_ITEM* item;
|
2017-04-15 16:08:23 +00:00
|
|
|
BOARD* board;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-05-18 17:21:30 +00:00
|
|
|
item = m_parser->Parse();
|
2017-04-15 16:08:23 +00:00
|
|
|
}
|
|
|
|
catch( const FUTURE_FORMAT_ERROR& )
|
|
|
|
{
|
|
|
|
// Don't wrap a FUTURE_FORMAT_ERROR in another
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch( const PARSE_ERROR& parse_error )
|
|
|
|
{
|
|
|
|
if( m_parser->IsTooRecent() )
|
|
|
|
throw FUTURE_FORMAT_ERROR( parse_error, m_parser->GetRequiredVersion() );
|
|
|
|
else
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
if( item->Type() != PCB_T )
|
2017-04-15 16:08:23 +00:00
|
|
|
{
|
|
|
|
// The parser loaded something that was valid, but wasn't a board.
|
2018-03-08 03:55:02 +00:00
|
|
|
THROW_PARSE_ERROR( _( "Clipboard content is not KiCad compatible" ),
|
2017-04-15 16:08:23 +00:00
|
|
|
m_parser->CurSource(), m_parser->CurLine(),
|
|
|
|
m_parser->CurLineNumber(), m_parser->CurOffset() );
|
|
|
|
}
|
2017-05-18 17:21:30 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
board = dynamic_cast<BOARD*>( item );
|
|
|
|
}
|
2017-11-01 09:20:13 +00:00
|
|
|
|
2017-04-15 16:08:23 +00:00
|
|
|
// Give the filename to the board if it's new
|
2017-12-04 09:20:05 +00:00
|
|
|
if( board && !aAppendToMe )
|
2017-04-15 16:08:23 +00:00
|
|
|
board->SetFileName( aFileName );
|
|
|
|
|
|
|
|
return board;
|
|
|
|
}
|