1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013 CERN
* 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.or/licenses/>.
*/
#include <gal/color4d.h>
#include "class_track.h"
#include <pcb_painter.h>
#include "router_preview_item.h"
#include "pns_line.h"
#include "pns_segment.h"
#include "pns_via.h"
using namespace KIGFX;
ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS_ITEM* aItem, VIEW_GROUP* aParent ) :
EDA_ITEM( NOT_USED )
{
m_Flags = 0;
m_parent = aParent;
if( aItem )
Update( aItem );
}
ROUTER_PREVIEW_ITEM::~ROUTER_PREVIEW_ITEM()
{
}
void ROUTER_PREVIEW_ITEM::Update( const PNS_ITEM* aItem )
{
m_layer = aItem->GetLayers().Start();
m_color = getLayerColor( m_layer );
m_color.a = 0.8;
switch( aItem->GetKind() )
{
case PNS_ITEM::LINE:
m_type = PR_LINE;
m_width = static_cast<const PNS_LINE*>(aItem)->GetWidth();
m_line = *static_cast<const SHAPE_LINE_CHAIN*>( aItem->GetShape() );
break;
case PNS_ITEM::SEGMENT:
m_type = PR_LINE;
m_width = static_cast<const PNS_SEGMENT*>(aItem)->GetWidth();
m_line = *static_cast<const SHAPE_LINE_CHAIN*>( aItem->GetShape() );
break;
case PNS_ITEM::VIA:
m_type = PR_VIA;
m_color = COLOR4D( 0.7, 0.7, 0.7, 0.8 );
m_width = static_cast<const PNS_VIA*>(aItem)->GetDiameter();
m_viaCenter = static_cast<const PNS_VIA*>(aItem)->GetPos();
break;
default:
break;
}
ViewSetVisible( true );
ViewUpdate( GEOMETRY | APPEARANCE );
}
void ROUTER_PREVIEW_ITEM::MarkAsHead()
{
if( m_type != PR_VIA )
m_color.Saturate( 1.0 );
}
const BOX2I ROUTER_PREVIEW_ITEM::ViewBBox() const
{
BOX2I bbox;
switch( m_type )
{
case PR_LINE:
bbox = m_line.BBox();
bbox.Inflate( m_width / 2 );
return bbox;
case PR_VIA:
bbox = BOX2I( m_viaCenter, VECTOR2I( 0, 0 ) );
bbox.Inflate( m_width / 2 );
return bbox;
default:
break;
}
return bbox;
}
void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::GAL* aGal ) const
{
switch( m_type )
{
case PR_LINE:
aGal->SetLayerDepth( -100.0 );
aGal->SetLineWidth( m_width );
aGal->SetStrokeColor( m_color );
aGal->SetIsStroke( true );
aGal->SetIsFill( false );
for( int s = 0; s < m_line.SegmentCount(); s++ )
aGal->DrawLine( m_line.CSegment( s ).A, m_line.CSegment( s ).B );
if( m_line.IsClosed() )
aGal->DrawLine( m_line.CSegment( -1 ).B, m_line.CSegment( 0 ).A );
break;
case PR_VIA:
aGal->SetLayerDepth( -101.0 );
aGal->SetIsStroke( false );
aGal->SetIsFill( true );
aGal->SetFillColor( m_color );
aGal->DrawCircle( m_viaCenter, m_width / 2 );
break;
default:
break;
}
}
void ROUTER_PREVIEW_ITEM::DebugLine( const SHAPE_LINE_CHAIN& aLine, int aWidth, int aStyle )
{
#if 0
m_line = aLine;
m_width = aWidth;
m_color = assignColor( aStyle );
m_type = PR_LINE;
ViewUpdate( GEOMETRY | APPEARANCE );
#endif
}
void ROUTER_PREVIEW_ITEM::DebugBox( const BOX2I& aBox, int aStyle )
{
#if 0
assert( false );
m_line.Clear();
m_line.Append( aBox.GetX(), aBox.GetY() );
m_line.Append( aBox.GetX() + aBox.GetWidth(), aBox.GetY() + aBox.GetHeight() );
m_line.Append( aBox.GetX() + aBox.GetWidth(), aBox.GetY() + aBox.GetHeight() );
m_line.Append( aBox.GetX(), aBox.GetY() + aBox.GetHeight() );
m_line.SetClosed( true );
m_width = 20000;
m_color = assignColor( aStyle );
m_type = PR_LINE;
ViewUpdate( GEOMETRY | APPEARANCE );
#endif
}
const COLOR4D ROUTER_PREVIEW_ITEM::getLayerColor( int aLayer ) const
{
// assert (m_view != NULL);
PCB_RENDER_SETTINGS* settings =
static_cast <PCB_RENDER_SETTINGS*> ( m_parent->GetView()->GetPainter()->GetSettings() );
return settings->GetLayerColor( aLayer );
}
const COLOR4D ROUTER_PREVIEW_ITEM::assignColor( int aStyle ) const
{
COLOR4D color;
switch( aStyle )
{
case 0:
color = COLOR4D( 0, 1, 0, 1 ); break;
case 1:
color = COLOR4D( 1, 0, 0, 0.3 ); break;
case 2:
color = COLOR4D( 1, 0.5, 0.5, 1 ); break;
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:
color = COLOR4D( 0, 0, 1, 0.5 ); break;
default:
break;
}
return color;
}