2014-05-14 13:53:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 CERN
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-05-14 13:53:54 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 "pns_logger.h"
|
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_via.h"
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_segment.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_rect.h>
|
|
|
|
#include <geometry/shape_circle.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <geometry/shape_simple.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LOGGER::LOGGER( )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
m_groupOpened = false;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LOGGER::~LOGGER()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LOGGER::Clear()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
m_theLog.str( std::string() );
|
|
|
|
m_groupOpened = false;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LOGGER::NewGroup( const std::string& aName, int aIter )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_groupOpened )
|
|
|
|
m_theLog << "endgroup" << std::endl;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_theLog << "group " << aName << " " << aIter << std::endl;
|
|
|
|
m_groupOpened = true;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LOGGER::EndGroup()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_groupOpened )
|
|
|
|
return;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_groupOpened = false;
|
|
|
|
m_theLog << "endgroup" << std::endl;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
void LOGGER::Log ( const ITEM* aItem, int aKind, const std::string& aName )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-03-02 16:20:48 +00:00
|
|
|
m_theLog << "item " << aKind << " " << aName << " ";
|
2015-02-18 16:53:46 +00:00
|
|
|
m_theLog << aItem->Net() << " " << aItem->Layers().Start() << " " <<
|
|
|
|
aItem->Layers().End() << " " << aItem->Marker() << " " << aItem->Rank();
|
|
|
|
|
|
|
|
switch( aItem->Kind() )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::LINE_T:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE* l = (LINE*) aItem;
|
2015-10-05 16:28:41 +00:00
|
|
|
m_theLog << " line ";
|
|
|
|
m_theLog << l->Width() << " " << ( l->EndsWithVia() ? 1 : 0 ) << " ";
|
|
|
|
dumpShape ( l->Shape() );
|
|
|
|
m_theLog << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::VIA_T:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
|
|
|
m_theLog << " via 0 0 ";
|
|
|
|
dumpShape ( aItem->Shape() );
|
|
|
|
m_theLog << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SEGMENT_T:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
SEGMENT* s =(SEGMENT*) aItem;
|
2015-10-05 16:28:41 +00:00
|
|
|
m_theLog << " line ";
|
|
|
|
m_theLog << s->Width() << " 0 linechain 2 0 " << s->Seg().A.x << " " <<
|
|
|
|
s->Seg().A.y << " " << s->Seg().B.x << " " <<s->Seg().B.y << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SOLID_T:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
SOLID* s = (SOLID*) aItem;
|
2015-10-05 16:28:41 +00:00
|
|
|
m_theLog << " solid 0 0 ";
|
|
|
|
dumpShape( s->Shape() );
|
|
|
|
m_theLog << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2017-09-23 09:20:10 +00:00
|
|
|
void LOGGER::Log( const SHAPE_LINE_CHAIN *aL, int aKind, const std::string& aName )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
m_theLog << "item " << aKind << " " << aName << " ";
|
|
|
|
m_theLog << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0;
|
|
|
|
m_theLog << " line ";
|
|
|
|
m_theLog << 0 << " " << 0 << " ";
|
|
|
|
dumpShape( aL );
|
|
|
|
m_theLog << std::endl;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LOGGER::Log( const VECTOR2I& aStart, const VECTOR2I& aEnd,
|
2017-09-23 09:20:10 +00:00
|
|
|
int aKind, const std::string& aName)
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LOGGER::dumpShape( const SHAPE* aSh )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( aSh->Type() )
|
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN* lc = (const SHAPE_LINE_CHAIN*) aSh;
|
|
|
|
m_theLog << "linechain " << lc->PointCount() << " " << ( lc->IsClosed() ? 1 : 0 ) << " ";
|
|
|
|
|
|
|
|
for( int i = 0; i < lc->PointCount(); i++ )
|
|
|
|
m_theLog << lc->CPoint( i ).x << " " << lc->CPoint( i ).y << " ";
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_CIRCLE:
|
|
|
|
{
|
|
|
|
const SHAPE_CIRCLE *c = (const SHAPE_CIRCLE*) aSh;
|
|
|
|
m_theLog << "circle " << c->GetCenter().x << " " << c->GetCenter().y << " " << c->GetRadius();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_RECT:
|
|
|
|
{
|
|
|
|
const SHAPE_RECT* r = (const SHAPE_RECT*) aSh;
|
|
|
|
m_theLog << "rect " << r->GetPosition().x << " " << r->GetPosition().y << " " <<
|
|
|
|
r->GetSize().x << " " <<r->GetSize().y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_SEGMENT:
|
|
|
|
{
|
|
|
|
const SHAPE_SEGMENT* s = (const SHAPE_SEGMENT*) aSh;
|
|
|
|
m_theLog << "linechain 2 0 " << s->GetSeg().A.x << " " << s->GetSeg().A.y << " " <<
|
|
|
|
s->GetSeg().B.x << " " << s->GetSeg().B.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-03 17:52:42 +00:00
|
|
|
case SH_SIMPLE:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2018-05-03 17:52:42 +00:00
|
|
|
const SHAPE_SIMPLE* c = (const SHAPE_SIMPLE*) aSh;
|
2015-10-05 16:28:41 +00:00
|
|
|
m_theLog << "convex " << c->PointCount() << " ";
|
|
|
|
|
|
|
|
for( int i = 0; i < c->PointCount(); i++ )
|
|
|
|
m_theLog << c->CPoint( i ).x << " " << c->CPoint( i ).y << " ";
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LOGGER::Save( const std::string& aFilename )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
EndGroup();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
FILE* f = fopen( aFilename.c_str(), "wb" );
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "Saving to '%s' [%p]", aFilename.c_str(), f );
|
2015-02-18 16:53:46 +00:00
|
|
|
const std::string s = m_theLog.str();
|
|
|
|
fwrite( s.c_str(), 1, s.length(), f );
|
|
|
|
fclose( f );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|