2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copyright (C) 2013-2014 CERN
|
2013-09-18 17:55:16 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +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 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
#include <deque>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <gal/color4d.h>
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2015-07-02 14:09:43 +00:00
|
|
|
#include <geometry/shape_convex.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "class_track.h"
|
|
|
|
#include <pcb_painter.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <colors.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include "router_preview_item.h"
|
|
|
|
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_segment.h"
|
|
|
|
#include "pns_via.h"
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
using namespace KIGFX;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS_ITEM* aItem, VIEW_GROUP* aParent ) :
|
|
|
|
EDA_ITEM( NOT_USED )
|
|
|
|
{
|
|
|
|
m_parent = aParent;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_shape = NULL;
|
|
|
|
m_clearance = -1;
|
2014-07-07 08:48:47 +00:00
|
|
|
m_originLayer = m_layer = ITEM_GAL_LAYER( GP_OVERLAY );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-04-20 14:59:25 +00:00
|
|
|
// initialize variables, overwritten by Update( aItem ), if aItem != NULL
|
|
|
|
m_router = NULL;
|
|
|
|
m_type = PR_SHAPE;
|
|
|
|
m_style = 0;
|
|
|
|
m_width = 0;
|
|
|
|
m_depth = 0;
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( aItem )
|
|
|
|
Update( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
ROUTER_PREVIEW_ITEM::~ROUTER_PREVIEW_ITEM()
|
|
|
|
{
|
2015-07-22 08:46:56 +00:00
|
|
|
delete m_shape;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ROUTER_PREVIEW_ITEM::Update( const PNS_ITEM* aItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
m_originLayer = aItem->Layers().Start();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-07-10 21:42:05 +00:00
|
|
|
if( aItem->OfKind( PNS_ITEM::LINE ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-10 21:42:05 +00:00
|
|
|
const PNS_LINE* l = static_cast<const PNS_LINE*>( aItem );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !l->SegmentCount() )
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( m_originLayer >= 0 );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-07-07 08:48:47 +00:00
|
|
|
m_layer = m_originLayer;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_color = getLayerColor( m_originLayer );
|
|
|
|
m_color.a = 0.8;
|
|
|
|
m_depth = BaseOverlayDepth - aItem->Layers().Start();
|
|
|
|
m_shape = aItem->Shape()->Clone();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( aItem->Kind() )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
case PNS_ITEM::LINE:
|
|
|
|
m_type = PR_SHAPE;
|
|
|
|
m_width = ( (PNS_LINE*) aItem )->Width();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_ITEM::SEGMENT:
|
|
|
|
{
|
|
|
|
PNS_SEGMENT* seg = (PNS_SEGMENT*) aItem;
|
|
|
|
m_type = PR_SHAPE;
|
|
|
|
m_width = seg->Width();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PNS_ITEM::VIA:
|
2014-11-14 18:15:58 +00:00
|
|
|
m_originLayer = m_layer = ITEM_GAL_LAYER( VIAS_VISIBLE );
|
2014-05-16 11:37:31 +00:00
|
|
|
m_type = PR_SHAPE;
|
|
|
|
m_width = 0;
|
|
|
|
m_color = COLOR4D( 0.7, 0.7, 0.7, 0.8 );
|
|
|
|
m_depth = ViaOverlayDepth;
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
case PNS_ITEM::SOLID:
|
|
|
|
m_type = PR_SHAPE;
|
|
|
|
m_width = 0;
|
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aItem->Marker() & MK_VIOLATION )
|
|
|
|
m_color = COLOR4D( 0, 1, 0, 1 );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aItem->Marker() & MK_HEAD )
|
|
|
|
m_color.Brighten( 0.7 );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
ViewSetVisible( true );
|
|
|
|
ViewUpdate( GEOMETRY | APPEARANCE );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
const BOX2I ROUTER_PREVIEW_ITEM::ViewBBox() const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
BOX2I bbox;
|
|
|
|
|
|
|
|
switch( m_type )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
case PR_SHAPE:
|
|
|
|
bbox = m_shape->BBox();
|
2013-09-26 21:53:54 +00:00
|
|
|
bbox.Inflate( m_width / 2 );
|
|
|
|
return bbox;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
case PR_POINT:
|
2014-05-16 11:37:31 +00:00
|
|
|
bbox = BOX2I ( m_pos - VECTOR2I( 100000, 100000 ), VECTOR2I( 200000, 200000 ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
return bbox;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bbox;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
void ROUTER_PREVIEW_ITEM::drawLineChain( const SHAPE_LINE_CHAIN& aL, KIGFX::GAL* aGal ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int s = 0; s < aL.SegmentCount(); s++ )
|
|
|
|
aGal->DrawLine( aL.CSegment( s ).A, aL.CSegment( s ).B );
|
|
|
|
|
|
|
|
if( aL.IsClosed() )
|
|
|
|
aGal->DrawLine( aL.CSegment( -1 ).B, aL.CSegment( 0 ).A );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::GAL* aGal ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
//col.Brighten(0.7);
|
|
|
|
aGal->SetLayerDepth( m_depth );
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_type == PR_SHAPE )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-08-10 15:50:10 +00:00
|
|
|
if( !m_shape )
|
|
|
|
return;
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
aGal->SetLineWidth( m_width );
|
|
|
|
aGal->SetStrokeColor( m_color );
|
|
|
|
aGal->SetFillColor( m_color );
|
2014-05-14 13:53:54 +00:00
|
|
|
aGal->SetIsStroke( m_width ? true : false );
|
|
|
|
aGal->SetIsFill( true );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( m_shape->Type() )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN* l = (const SHAPE_LINE_CHAIN*) m_shape;
|
|
|
|
drawLineChain( *l, aGal );
|
|
|
|
break;
|
|
|
|
}
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
case SH_SEGMENT:
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
const SHAPE_SEGMENT* s = (const SHAPE_SEGMENT*) m_shape;
|
2015-08-10 15:50:10 +00:00
|
|
|
aGal->DrawSegment( s->GetSeg().A, s->GetSeg().B, s->GetWidth() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( m_clearance > 0 )
|
|
|
|
{
|
|
|
|
aGal->SetLayerDepth( ClearanceOverlayDepth );
|
|
|
|
aGal->SetStrokeColor( COLOR4D( DARKDARKGRAY ) );
|
2015-08-10 15:50:10 +00:00
|
|
|
aGal->SetFillColor( COLOR4D( DARKDARKGRAY ) );
|
|
|
|
aGal->DrawSegment( s->GetSeg().A, s->GetSeg().B, s->GetWidth() + 2 * m_clearance );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
case SH_CIRCLE:
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
const SHAPE_CIRCLE* c = (const SHAPE_CIRCLE*) m_shape;
|
|
|
|
aGal->DrawCircle( c->GetCenter(), c->GetRadius() );
|
|
|
|
|
|
|
|
if( m_clearance > 0 )
|
|
|
|
{
|
|
|
|
aGal->SetLayerDepth( ClearanceOverlayDepth );
|
|
|
|
aGal->SetFillColor( COLOR4D( DARKDARKGRAY ) );
|
|
|
|
aGal->SetIsStroke( false );
|
|
|
|
aGal->DrawCircle( c->GetCenter(), c->GetRadius() + m_clearance );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
case SH_RECT:
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
const SHAPE_RECT* r = (const SHAPE_RECT*) m_shape;
|
|
|
|
aGal->DrawRectangle( r->GetPosition(), r->GetPosition() + r->GetSize() );
|
|
|
|
|
|
|
|
if( m_clearance > 0 )
|
|
|
|
{
|
|
|
|
aGal->SetLayerDepth( ClearanceOverlayDepth );
|
|
|
|
VECTOR2I p0( r->GetPosition() ), s( r->GetSize() );
|
|
|
|
aGal->SetStrokeColor( COLOR4D( DARKDARKGRAY ) );
|
|
|
|
aGal->SetIsStroke( true );
|
|
|
|
aGal->SetLineWidth( 2 * m_clearance );
|
|
|
|
aGal->DrawLine( p0, VECTOR2I( p0.x + s.x, p0.y ) );
|
|
|
|
aGal->DrawLine( p0, VECTOR2I( p0.x, p0.y + s.y ) );
|
|
|
|
aGal->DrawLine( p0 + s , VECTOR2I( p0.x + s.x, p0.y ) );
|
|
|
|
aGal->DrawLine( p0 + s, VECTOR2I( p0.x, p0.y + s.y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-12-23 13:01:59 +00:00
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
case SH_CONVEX:
|
|
|
|
{
|
|
|
|
const SHAPE_CONVEX* c = (const SHAPE_CONVEX*) m_shape;
|
|
|
|
std::deque<VECTOR2D> polygon = std::deque<VECTOR2D>();
|
|
|
|
for( int i = 0; i < c->PointCount(); i++ )
|
|
|
|
{
|
|
|
|
polygon.push_back( c->CDPoint( i ) );
|
|
|
|
}
|
|
|
|
aGal->DrawPolygon( polygon );
|
|
|
|
|
|
|
|
if( m_clearance > 0 )
|
|
|
|
{
|
|
|
|
aGal->SetLayerDepth( ClearanceOverlayDepth );
|
|
|
|
aGal->SetStrokeColor( COLOR4D( DARKDARKGRAY ) );
|
|
|
|
aGal->SetIsStroke( true );
|
|
|
|
aGal->SetLineWidth( 2 * m_clearance );
|
|
|
|
// need the implicit last segment to be explicit for DrawPolyline
|
|
|
|
polygon.push_back( c->CDPoint( 0 ) );
|
|
|
|
aGal->DrawPolyline( polygon );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-12 15:13:18 +00:00
|
|
|
case SH_POLY_SET:
|
2014-12-23 13:01:59 +00:00
|
|
|
case SH_COMPOUND:
|
|
|
|
break; // Not yet in use
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void ROUTER_PREVIEW_ITEM::Line( const SHAPE_LINE_CHAIN& aLine, int aWidth, int aStyle )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
m_originLayer = m_layer = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_width = aWidth;
|
|
|
|
m_color = assignColor( aStyle );
|
2014-05-14 13:53:54 +00:00
|
|
|
m_type = PR_SHAPE;
|
2015-08-12 19:12:13 +00:00
|
|
|
m_depth = -1024; // TODO gal->GetMinDepth()
|
2014-05-14 13:53:54 +00:00
|
|
|
m_shape = aLine.Clone();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
ViewSetVisible( true );
|
2013-09-26 21:53:54 +00:00
|
|
|
ViewUpdate( GEOMETRY | APPEARANCE );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
void ROUTER_PREVIEW_ITEM::Point( const VECTOR2I& aPos, int aStyle )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void ROUTER_PREVIEW_ITEM::Box( const BOX2I& aBox, int aStyle )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
const COLOR4D ROUTER_PREVIEW_ITEM::getLayerColor( int aLayer ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
PCB_RENDER_SETTINGS* settings =
|
2014-05-16 11:37:31 +00:00
|
|
|
static_cast<PCB_RENDER_SETTINGS*>( m_parent->GetView()->GetPainter()->GetSettings() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
return settings->GetLayerColor( aLayer );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
const COLOR4D ROUTER_PREVIEW_ITEM::assignColor( int aStyle ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
COLOR4D color;
|
|
|
|
|
|
|
|
switch( aStyle )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
color = COLOR4D( 0, 1, 0, 1 ); break;
|
|
|
|
|
|
|
|
case 1:
|
2014-05-14 13:53:54 +00:00
|
|
|
color = COLOR4D( 1, 0, 0, 1 ); break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
case 2:
|
2014-05-14 13:53:54 +00:00
|
|
|
color = COLOR4D( 1, 1, 0, 1 ); break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
case 3:
|
|
|
|
color = COLOR4D( 0, 0, 1, 1 ); break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
color = COLOR4D( 1, 1, 1, 1 ); break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
color = COLOR4D( 1, 1, 0, 1 ); break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
color = COLOR4D( 0, 1, 1, 1 ); break;
|
|
|
|
|
|
|
|
case 32:
|
2014-05-14 13:53:54 +00:00
|
|
|
color = COLOR4D( 0, 0, 1, 1 ); break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
default:
|
2014-05-14 13:53:54 +00:00
|
|
|
color = COLOR4D( 0.4, 0.4, 0.4, 1 ); break;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2015-03-30 19:49:30 +00:00
|
|
|
|
2015-09-09 09:56:16 +00:00
|
|
|
const int ROUTER_PREVIEW_ITEM::ClearanceOverlayDepth = -300;
|
|
|
|
const int ROUTER_PREVIEW_ITEM::BaseOverlayDepth = -310;
|
|
|
|
const int ROUTER_PREVIEW_ITEM::ViaOverlayDepth = -346;
|