pcbnew: copy/paste code cleanup & formatting

This commit is contained in:
Kristoffer Ödmark 2017-09-29 11:44:05 +02:00 committed by Tomasz Włostowski
parent c6a0ad895b
commit 4a5d400ec2
2 changed files with 30 additions and 20 deletions

View File

@ -1,14 +1,8 @@
/**
* @file kicad_clipboard.cpp
* @brief Kicad clipboard plugin that piggybacks on the kicad_plugin
*
* @author Kristoffer Ödmark
* @version 1.0
* @date 2017-05-03
*
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors.
* @author Kristoffer Ödmark
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -46,22 +40,26 @@ CLIPBOARD_IO::CLIPBOARD_IO():
m_out = &m_formatter;
}
CLIPBOARD_IO::~CLIPBOARD_IO(){}
STRING_FORMATTER* CLIPBOARD_IO::GetFormatter()
{
return &m_formatter;
}
void CLIPBOARD_IO::SetBoard( BOARD* aBoard )
{
m_board = aBoard;
}
void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
VECTOR2I refPoint(0, 0);
VECTOR2I refPoint( 0, 0 );
// dont even start if the selection is empty
if( aSelected.Empty() )
@ -105,7 +103,7 @@ void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
}
// locate the reference point at (0, 0) in the copied items
newModule.Move( wxPoint(-refPoint.x, -refPoint.y ) );
newModule.Move( wxPoint( -refPoint.x, -refPoint.y ) );
Format( static_cast<BOARD_ITEM*>( &newModule ) );
}
@ -147,8 +145,8 @@ void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
{
// we will fake being a .kicad_pcb to get the full parser kicking
// This means we also need layers and nets
m_formatter.Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n", SEXPR_BOARD_FILE_VERSION,
m_formatter.Quotew( GetBuildVersion() ).c_str() );
m_formatter.Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n",
SEXPR_BOARD_FILE_VERSION, m_formatter.Quotew( GetBuildVersion() ).c_str() );
m_formatter.Print( 0, "\n" );
@ -180,11 +178,13 @@ void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
}
if( wxTheClipboard->Open() )
{
wxTheClipboard->SetData( new wxTextDataObject( wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
wxTheClipboard->SetData( new wxTextDataObject(
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
wxTheClipboard->Close();
}
}
BOARD_ITEM* CLIPBOARD_IO::Parse()
{
std::string result;
@ -213,6 +213,7 @@ BOARD_ITEM* CLIPBOARD_IO::Parse()
return item;
}
void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
const PROPERTIES* aProperties )
{
@ -238,13 +239,16 @@ void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
if( wxTheClipboard->Open() )
{
wxTheClipboard->SetData( new wxTextDataObject( wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
wxTheClipboard->SetData( new wxTextDataObject(
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
wxTheClipboard->Close();
}
}
BOARD* CLIPBOARD_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
BOARD* CLIPBOARD_IO::Load( const wxString& aFileName,
BOARD* aAppendToMe, const PROPERTIES* aProperties )
{
std::string result;

View File

@ -571,7 +571,8 @@ void PCB_IO::formatSetup( BOARD* aBoard, int aNestLevel ) const
// Save used non-copper layers in the order they are defined.
// desired sequence for non Cu BOARD layers.
static const PCB_LAYER_ID non_cu[] = {
static const PCB_LAYER_ID non_cu[] =
{
B_Adhes, // 32
F_Adhes,
B_Paste,
@ -720,6 +721,7 @@ void PCB_IO::formatSetup( BOARD* aBoard, int aNestLevel ) const
m_out->Print( aNestLevel, ")\n\n" );
}
void PCB_IO::formatGeneral( BOARD* aBoard, int aNestLevel ) const
{
const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
@ -741,6 +743,7 @@ void PCB_IO::formatGeneral( BOARD* aBoard, int aNestLevel ) const
aBoard->GetTitleBlock().Format( m_out, aNestLevel, m_ctl );
}
void PCB_IO::formatBoardLayers( BOARD* aBoard, int aNestLevel ) const
{
m_out->Print( aNestLevel, "(layers\n" );
@ -764,7 +767,8 @@ void PCB_IO::formatBoardLayers( BOARD* aBoard, int aNestLevel ) const
// Save used non-copper layers in the order they are defined.
// desired sequence for non Cu BOARD layers.
static const PCB_LAYER_ID non_cu[] = {
static const PCB_LAYER_ID non_cu[] =
{
B_Adhes, // 32
F_Adhes,
B_Paste,
@ -801,6 +805,7 @@ void PCB_IO::formatBoardLayers( BOARD* aBoard, int aNestLevel ) const
m_out->Print( aNestLevel, ")\n\n" );
}
void PCB_IO::formatNetInformation( BOARD* aBoard, int aNestLevel ) const
{
const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
@ -830,11 +835,12 @@ void PCB_IO::formatNetInformation( BOARD* aBoard, int aNestLevel ) const
}
}
void PCB_IO::formatHeader( BOARD* aBoard, int aNestLevel ) const
{
formatGeneral(aBoard);
formatGeneral( aBoard );
// Layers.
formatBoardLayers(aBoard);
formatBoardLayers( aBoard );
// Setup
formatSetup( aBoard, aNestLevel );
// Save net codes and names
@ -1640,7 +1646,7 @@ void PCB_IO::format( TRACK* aTrack, int aNestLevel ) const
{
PCB_LAYER_ID layer1, layer2;
const VIA* via = static_cast<const VIA*>(aTrack);
const VIA* via = static_cast<const VIA*>( aTrack );
BOARD* board = (BOARD*) via->GetParent();
wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText() +