KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drawing_stackup_table_tool.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014-2017 CERN
5 * Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include "drawing_tool.h"
26#include <kiplatform/ui.h>
27#include "pcb_actions.h"
28#include <pcb_edit_frame.h>
29#include <view/view.h>
30#include <tool/tool_manager.h>
31#include <board_commit.h>
32#include <scoped_set_reset.h>
33#include <gal/painter.h>
36#include <footprint.h>
37#include <pcb_shape.h>
38#include <pcb_group.h>
39#include <pcb_text.h>
40#include <string_utils.h>
41#include <wx/utils.h>
42
43
45
46
47static std::vector<BOARD_ITEM*> initTextTable( std::vector<std::vector<PCB_TEXT*>> aContent,
48 VECTOR2I origin, PCB_LAYER_ID aLayer,
49 VECTOR2I* aTableSize, bool aDrawFrame = true )
50{
51 int i;
52 int j;
53
54 int nbCols = aContent.size();
55 int nbRows = 0;
56
57 for( const std::vector<PCB_TEXT*>& col : aContent )
58 nbRows = std::max( nbRows, static_cast<int>( col.size() ) );
59
60 // Limit the number of cells
61 nbCols = std::min( nbCols, 99 );
62 nbRows = std::min( nbRows, 99 );
63
64 int rowHeight[99];
65 int colWidth[99];
66
67 std::vector<BOARD_ITEM*> table;
68
69 // xmargin and ymargin are margins between the text and the table lines.
70 //
71 // +--------------------------------+
72 // | ^ |
73 // | | ymargin |
74 // | v |
75 // |<------->TEXT_TEXT_TEXT<------->|
76 // | xmargin ^ xmargin |
77 // | | ymargin |
78 // | v |
79 // +--------------------------------+
80 //
81
82 int xmargin = pcbIUScale.mmToIU( 0.75 );
83 int ymargin = pcbIUScale.mmToIU( 0.75 );
84
85 // Init table
86 for( i = 0; i < nbRows; i++ )
87 rowHeight[i] = 0;
88
89 for( i = 0; i < nbCols; i++ )
90 colWidth[i] = 0;
91
92 // First, we determine what the height/Width should be for every cell
93 i = 0;
94
95 for( const std::vector<PCB_TEXT*>& col : aContent )
96 {
97 j = 0;
98
99 if( i >= nbCols )
100 break;
101
102 for( const PCB_TEXT* cell : col )
103 {
104 if( j >= nbRows )
105 break;
106
107 int height = cell->GetBoundingBox().GetHeight() + 2 * ymargin;
108 int width = cell->GetBoundingBox().GetWidth() + 2 * xmargin;
109 rowHeight[j] = rowHeight[j] > height ? rowHeight[j] : height;
110 colWidth[i] = colWidth[i] > width ? colWidth[i] : width;
111 j++;
112 }
113
114 i++;
115 }
116
117 // get table size
118 int height = std::accumulate( rowHeight, rowHeight + nbRows, 0 );
119 int width = std::accumulate( colWidth, colWidth + nbCols, 0 );
120
121 aTableSize->x = width;
122 aTableSize->y = height;
123 // Draw the frame
124
125 if( aDrawFrame )
126 {
127 int y = origin.y;
128 PCB_SHAPE* line;
129
130 for( i = 0; i < nbRows; i++ )
131 {
132 line = new PCB_SHAPE;
133 line->SetLayer( aLayer );
134 line->SetStart( VECTOR2I( origin.x, y ) );
135 line->SetEnd( VECTOR2I( origin.x + width, y ) );
136 y += rowHeight[i];
137 table.push_back( line );
138 }
139
140 line = new PCB_SHAPE;
141 line->SetLayer( aLayer );
142 line->SetStart( VECTOR2I( origin.x, y ) );
143 line->SetEnd( VECTOR2I( origin.x + width, y ) );
144 table.push_back( line );
145 int x = origin.x;
146
147 for( i = 0; i < nbCols; i++ )
148 {
149 line = new PCB_SHAPE;
150 line->SetLayer( aLayer );
151 line->SetStart( VECTOR2I( x, origin.y ) );
152 line->SetEnd( VECTOR2I( x, origin.y + height ) );
153 x += colWidth[i];
154 table.push_back( line );
155 }
156
157 line = new PCB_SHAPE;
158 line->SetLayer( aLayer );
159 line->SetStart( VECTOR2I( x, origin.y ) );
160 line->SetEnd( VECTOR2I( x, origin.y + height ) );
161 table.push_back( line );
162 }
163
164 //Now add the text
165 i = 0;
166 VECTOR2I pos( origin.x + xmargin, origin.y + ymargin );
167
168 for( std::vector<PCB_TEXT*>& col : aContent )
169 {
170 j = 0;
171
172 if( i >= nbCols )
173 break;
174
175 pos.y = origin.y + ymargin;
176
177 for( PCB_TEXT* cell : col )
178 {
179 if( j >= nbRows )
180 break;
181
182 cell->SetTextPos( pos );
183 cell->SetLayer( aLayer );
184 pos.y = pos.y + rowHeight[j];
185 table.push_back( cell );
186 j++;
187 }
188
189 pos.x = pos.x + colWidth[i];
190 i++;
191 }
192
193 return table;
194}
195
196
197std::vector<BOARD_ITEM*> DRAWING_TOOL::DrawSpecificationStackup( const VECTOR2I& aOrigin,
198 PCB_LAYER_ID aLayer,
199 bool aDrawNow,
200 VECTOR2I* tableSize )
201{
202 BOARD_COMMIT commit( m_frame );
203 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( m_frame->GetModel() );
204
205 std::vector<std::vector<PCB_TEXT*>> texts;
206
207 // Style : Header
208 std::unique_ptr<PCB_TEXT> headStyle = std::make_unique<PCB_TEXT>( footprint );
209 headStyle->SetLayer( Eco1_User );
210 headStyle->SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
211 headStyle->SetTextThickness( pcbIUScale.mmToIU( 0.3 ) );
212 headStyle->SetItalic( false );
213 headStyle->SetTextPos( VECTOR2I( 0, 0 ) );
214 headStyle->SetText( _( "Layer" ) );
215 headStyle->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
216 headStyle->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
217
218 // Style : data
219 std::unique_ptr<PCB_TEXT> dataStyle = std::make_unique<PCB_TEXT>( footprint );
220 dataStyle->SetLayer( Eco1_User );
221 dataStyle->SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
222 dataStyle->SetTextThickness( pcbIUScale.mmToIU( 0.1 ) );
223 dataStyle->SetItalic( false );
224 dataStyle->SetTextPos( VECTOR2I( 0, 0 ) );
225 dataStyle->SetText( _( "Layer" ) );
226 dataStyle->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
227 dataStyle->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
228
229 //Get Layer names
231 BOARD_STACKUP& stackup = dsnSettings.GetStackupDescriptor();
232 stackup.SynchronizeWithBoard( &dsnSettings );
233
234 std::vector<BOARD_STACKUP_ITEM*> layers = stackup.GetList();
235
236 std::vector<PCB_TEXT*> colLayer;
237 std::vector<PCB_TEXT*> colType;
238 std::vector<PCB_TEXT*> colMaterial;
239 std::vector<PCB_TEXT*> colThickness;
240 std::vector<PCB_TEXT*> colColor;
241 std::vector<PCB_TEXT*> colEpsilon;
242 std::vector<PCB_TEXT*> colTanD;
243 PCB_TEXT* t;
244
245 t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
246 t->SetText( _( "Layer Name" ) );
247 colLayer.push_back( t );
248
249 t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
250 t->SetText( _( "Type" ) );
251 colType.push_back( t );
252
253 t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
254 t->SetText( _( "Material" ) );
255 colMaterial.push_back( t );
256
257 t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
258
259 switch( m_frame->GetUserUnits() )
260 {
261 case EDA_UNITS::MILLIMETRES: t->SetText( _( "Thickness (mm)" ) ); break;
262 case EDA_UNITS::INCHES: t->SetText( _( "Thickness (inches)" ) ); break;
263 case EDA_UNITS::MILS: t->SetText( _( "Thickness (mils)" ) ); break;
264 default: wxFAIL_MSG( wxT( "Unhandled unit type" ) );
265 }
266
267 colThickness.push_back( t );
268
269 t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
270 t->SetText( _( "Color" ) );
271 colColor.push_back( t );
272
273 t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
274 t->SetText( _( "Epsilon R" ) );
275 colEpsilon.push_back( t );
276
277 t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
278 t->SetText( _( "Loss Tangent" ) );
279 colTanD.push_back( t );
280
281 for( int i = 0; i < stackup.GetCount(); i++ )
282 {
283 BOARD_STACKUP_ITEM* stackup_item = layers.at( i );
284
285 for( int sublayer_id = 0; sublayer_id < stackup_item->GetSublayersCount(); sublayer_id++ )
286 {
287 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
288
289 // Layer names are empty until we close at least once the board setup dialog.
290 // If the user did not open the dialog, then get the names from the board.
291 // But dielectric layer names will be missing.
292 // In this case, for dielectric, a dummy name will be used
293 if( stackup_item->GetLayerName().IsEmpty() )
294 {
295 wxString ly_name;
296
297 if( IsValidLayer( stackup_item->GetBrdLayerId() ) )
298 ly_name = m_frame->GetBoard()->GetLayerName( stackup_item->GetBrdLayerId() );
299
300 if( ly_name.IsEmpty() && stackup_item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
301 ly_name = _( "Dielectric" );
302
303 t->SetText( ly_name );
304 }
305 else
306 {
307 t->SetText( stackup_item->GetLayerName() );
308 }
309
310 colLayer.push_back( t );
311
312 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
313 t->SetText( stackup_item->GetTypeName() );
314 colType.push_back( t );
315
316 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
317 t->SetText( stackup_item->GetMaterial( sublayer_id ) );
318 colMaterial.push_back( t );
319
320 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
321 t->SetText( m_frame->StringFromValue( stackup_item->GetThickness( sublayer_id ), true ) );
322 colThickness.push_back( t );
323
324 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
325 t->SetText( stackup_item->GetColor( sublayer_id ) );
326 colColor.push_back( t );
327
328 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
330 stackup_item->GetEpsilonR( sublayer_id ), false ) );
331 colEpsilon.push_back( t );
332
333 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
335 stackup_item->GetLossTangent( sublayer_id ), false ) );
336 colTanD.push_back( t );
337 }
338 }
339
340 texts.push_back( colLayer );
341 texts.push_back( colType );
342 texts.push_back( colMaterial );
343 texts.push_back( colThickness );
344 texts.push_back( colColor );
345 texts.push_back( colEpsilon );
346 texts.push_back( colTanD );
347 std::vector<BOARD_ITEM*> table = initTextTable( texts, aOrigin, aLayer, tableSize, true );
348
349 if( aDrawNow )
350 {
351 for( BOARD_ITEM* item : table )
352 commit.Add( item );
353
354 commit.Push( _( "Insert board stackup table" ) );
355 }
356
357 return table;
358}
359
360
361std::vector<BOARD_ITEM*> DRAWING_TOOL::DrawBoardCharacteristics( const VECTOR2I& aOrigin,
362 PCB_LAYER_ID aLayer,
363 bool aDrawNow,
364 VECTOR2I* tableSize )
365{
366 BOARD_COMMIT commit( m_frame );
367 std::vector<BOARD_ITEM*> objects;
369 BOARD_STACKUP& stackup = settings.GetStackupDescriptor();
370
371 VECTOR2I cursorPos = aOrigin;
372
373 // Style : Section header
374 std::unique_ptr<PCB_TEXT> headStyle =
375 std::make_unique<PCB_TEXT>( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
376 headStyle->SetLayer( Eco1_User );
377 headStyle->SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 2.0 ), pcbIUScale.mmToIU( 2.0 ) ) );
378 headStyle->SetTextThickness( pcbIUScale.mmToIU( 0.4 ) );
379 headStyle->SetItalic( false );
380 headStyle->SetTextPos( VECTOR2I( 0, 0 ) );
381 headStyle->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
382 headStyle->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
383
384 // Style : Data
385 std::unique_ptr<PCB_TEXT> dataStyle =
386 std::make_unique<PCB_TEXT>( static_cast<FOOTPRINT*>( m_frame->GetModel() ) );
387 dataStyle->SetLayer( Eco1_User );
388 dataStyle->SetTextSize( VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
389 dataStyle->SetTextThickness( pcbIUScale.mmToIU( 0.2 ) );
390 dataStyle->SetItalic( false );
391 dataStyle->SetTextPos( VECTOR2I( 0, 0 ) );
392 dataStyle->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
393 dataStyle->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
394
395 PCB_TEXT* t;
396
397 t = static_cast<PCB_TEXT*>( headStyle->Duplicate() );
398 t->SetText( _( "BOARD CHARACTERISTICS" ) );
399 t->SetPosition( cursorPos );
400 objects.push_back( t );
401
402 cursorPos.y = cursorPos.y + t->GetBoundingBox().GetHeight()
403 + EDA_UNIT_UTILS::UI::FromUserUnit( pcbIUScale, EDA_UNITS::MILLIMETRES, 1.0 );
404
405 std::vector<std::vector<PCB_TEXT*>> texts;
406 std::vector<PCB_TEXT*> colLabel1;
407 std::vector<PCB_TEXT*> colData1;
408 std::vector<PCB_TEXT*> colbreak;
409 std::vector<PCB_TEXT*> colLabel2;
410 std::vector<PCB_TEXT*> colData2;
411
412 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
413 t->SetText( _( "Copper Layer Count: " ) );
414 colLabel1.push_back( t );
415
416 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
418 settings.GetCopperLayerCount(), false ) );
419 colData1.push_back( t );
420
421 SHAPE_POLY_SET outline;
423 BOX2I size = outline.BBox();
424 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
425 t->SetText( _( "Board overall dimensions: " ) );
426 colLabel1.push_back( t );
427
428 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
429 t->SetText( wxString::Format( wxT( "%s x %s" ),
430 m_frame->MessageTextFromValue( size.GetWidth(), true ),
431 m_frame->MessageTextFromValue( size.GetHeight(), true ) ) );
432 colData1.push_back( t );
433
434 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
435 t->SetText( _( "Min track/spacing: " ) );
436 colLabel1.push_back( t );
437
438 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
439 t->SetText( wxString::Format( wxT( "%s / %s" ),
441 m_frame->MessageTextFromValue( settings.m_MinClearance, true ) ) );
442 colData1.push_back( t );
443
444 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
445 t->SetText( _( "Copper Finish: " ) );
446 colLabel1.push_back( t );
447
448 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
449 t->SetText( stackup.m_FinishType );
450 colData1.push_back( t );
451
452 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
453 t->SetText( _( "Castellated pads: " ) );
454 colLabel1.push_back( t );
455
456 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
457 t->SetText( stackup.m_CastellatedPads ? _( "Yes" ) : _( "No" ) );
458 colData1.push_back( t );
459
460 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
461 t->SetText( _( "Board Thickness: " ) );
462 colLabel2.push_back( t );
463
464 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
465 t->SetText( m_frame->MessageTextFromValue( settings.GetBoardThickness(), true ) );
466 colData2.push_back( t );
467
468 // some empty cells
469 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
470 colLabel2.push_back( t );
471 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
472 colData2.push_back( t );
473
474 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
475 t->SetText( _( "Min hole diameter: " ) );
476 colLabel2.push_back( t );
477 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
478
479 double holeSize = std::min( settings.m_MinThroughDrill, settings.m_ViasMinSize );
480 t->SetText( m_frame->MessageTextFromValue( holeSize, true ) );
481 colData2.push_back( t );
482
483 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
484 t->SetText( _( "Impedance Control: " ) );
485 colLabel2.push_back( t );
486
487 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
488 t->SetText( stackup.m_HasDielectricConstrains ? _( "Yes" ) : _( "No" ) );
489 colData2.push_back( t );
490
491 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
492 t->SetText( _( "Plated Board Edge: " ) );
493 colLabel2.push_back( t );
494
495 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
496 t->SetText( stackup.m_EdgePlating ? _( "Yes" ) : _( "No" ) );
497 colData2.push_back( t );
498
499 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
500 t->SetText( _( "Edge card connectors: " ) );
501 colLabel1.push_back( t );
502
503 t = static_cast<PCB_TEXT*>( dataStyle->Duplicate() );
504 switch( stackup.m_EdgeConnectorConstraints )
505 {
506 case BS_EDGE_CONNECTOR_NONE: t->SetText( _( "No" ) ); break;
507 case BS_EDGE_CONNECTOR_IN_USE: t->SetText( _( "Yes" ) ); break;
508 case BS_EDGE_CONNECTOR_BEVELLED: t->SetText( _( "Yes, Bevelled" ) ); break;
509 }
510 colData1.push_back( t );
511
512 texts.push_back( colLabel1 );
513 texts.push_back( colData1 );
514 texts.push_back( colbreak );
515 texts.push_back( colLabel2 );
516 texts.push_back( colData2 );
517 VECTOR2I tableSize2;
518
519 std::vector<BOARD_ITEM*> table = initTextTable( texts, cursorPos, Eco1_User, &tableSize2,
520 false );
521
522 for( BOARD_ITEM* item : table )
523 objects.push_back( item );
524
525 if( aDrawNow )
526 {
527 for( BOARD_ITEM* item : objects )
528 commit.Add( item );
529
530 commit.Push( wxT( "Board Characteristics" ) );
531 }
532
533 tableSize->x = tableSize2.x;
534 tableSize->y = cursorPos.y + tableSize2.y
535 + EDA_UNIT_UTILS::UI::FromUserUnit( pcbIUScale, EDA_UNITS::MILLIMETRES, 2.0 );
536
537 return objects;
538}
539
540
542 std::vector<BOARD_ITEM*>& aItems,
543 std::vector<BOARD_ITEM*>& aPreview,
544 LSET* aLayers )
545{
547 return -1;
548
549 bool cancelled = false;
550
551 BOARD_COMMIT commit( m_frame );
552
554
555 // do not capture or auto-pan until we start placing the table
556 SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT );
557
558 m_frame->PushTool( aEvent );
559
560 Activate();
561 // Must be done after Activate() so that it gets set into the correct context
562 m_controls->ShowCursor( true );
563
564 if( aEvent.HasPosition() )
565 m_toolMgr->PrimeTool( aEvent.Position() );
566
567 // Main loop: keep receiving events
568 VECTOR2I cursorPosition;
569 VECTOR2I previousCursorPosition;
570
571 view()->ClearPreview();
572 view()->InitPreview();
573
574 for( BOARD_ITEM* item : aPreview )
575 {
576 item->Move( cursorPosition - previousCursorPosition );
577 view()->AddToPreview( item );
578 }
579
580 while( TOOL_EVENT* evt = Wait() )
581 {
582 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
583 cursorPosition = m_controls->GetCursorPosition();
584
585 if( evt->IsCancelInteractive() )
586 {
587 m_frame->PopTool( aEvent );
588 cancelled = true;
589 break;
590 }
591 else if( evt->IsMotion() )
592 {
593 view()->ShowPreview( false );
594
595 for( BOARD_ITEM* item : aPreview )
596 item->Move( cursorPosition - previousCursorPosition );
597
598 view()->ShowPreview( true );
599
600 previousCursorPosition = cursorPosition;
601 }
602 else if( evt->IsActivate() )
603 {
604 if( evt->IsMoveTool() )
605 {
606 // leave ourselves on the stack so we come back after the move
607 cancelled = true;
608 break;
609 }
610 else
611 {
612 m_frame->PopTool( aEvent );
613 cancelled = true;
614 break;
615 }
616 }
617 else if( evt->IsClick( BUT_RIGHT ) )
618 {
620 }
621 else if( evt->IsClick( BUT_LEFT ) )
622 {
623 if( aLayers != nullptr )
624 {
625 PCB_LAYER_ID destLayer =
626 frame()->SelectOneLayer( PCB_LAYER_ID::PCB_LAYER_ID_COUNT, *aLayers,
628
629 view()->ClearPreview();
630
631 if( destLayer == PCB_LAYER_ID::UNDEFINED_LAYER )
632 {
633 // The user did not pick any layer.
634 m_frame->PopTool( aEvent );
635 cancelled = true;
636 break;
637 }
638
639 for( BOARD_ITEM* item : aItems )
640 {
641 if( item->Type() == PCB_GROUP_T )
642 static_cast<PCB_GROUP*>( item )->SetLayerRecursive( destLayer, 200 );
643 else
644 item->SetLayer( destLayer );
645 }
646 }
647
648 for( BOARD_ITEM* item : aItems )
649 {
650 item->Move( cursorPosition );
651 commit.Add( item );
652 }
653
654 commit.Push( wxT( "Placing items" ) );
655 m_frame->PopTool( aEvent );
656
657 break;
658 }
659 // TODO: It'd be nice to be able to say "don't allow any non-trivial editing actions",
660 // but we don't at present have that, so we just knock out some of the egregious ones.
661 else if( ZONE_FILLER_TOOL::IsZoneFillAction( evt ) )
662 {
663 wxBell();
664 }
665 else
666 {
667 evt->SetPassEvent();
668 }
669 }
670
671 view()->ClearPreview();
672 frame()->SetMsgPanel( board() );
673
674 if( cancelled )
675 return -1;
676
677 return 0;
678}
679
680
682{
683 VECTOR2I tableSize;
684
685 LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() );
686 layerSet = layerSet.set( Edge_Cuts ).set( Margin );
687 layerSet = layerSet.reset( F_Fab ).reset( B_Fab );
688
690
691 if( ( layerSet & LSET( layer ) ).count() ) // if layer is a forbidden layer
693
694 std::vector<BOARD_ITEM*> table = DrawBoardCharacteristics( { 0, 0 }, m_frame->GetActiveLayer(),
695 false, &tableSize );
696 std::vector<BOARD_ITEM*> preview;
697 std::vector<BOARD_ITEM*> items;
698
699 PCB_SHAPE* line1 = new PCB_SHAPE;
700 PCB_SHAPE* line2 = new PCB_SHAPE;
701 PCB_SHAPE* line3 = new PCB_SHAPE;
702 PCB_SHAPE* line4 = new PCB_SHAPE;
703
704 line1->SetStart( VECTOR2I( 0, 0 ) );
705 line1->SetEnd( VECTOR2I( tableSize.x, 0 ) );
706
707 line2->SetStart( VECTOR2I( 0, 0 ) );
708 line2->SetEnd( VECTOR2I( 0, tableSize.y ) );
709
710 line3->SetStart( VECTOR2I( tableSize.x, 0 ) );
711 line3->SetEnd( tableSize );
712
713 line4->SetStart( VECTOR2I( 0, tableSize.y ) );
714 line4->SetEnd( tableSize );
715
716 line1->SetLayer( m_frame->GetActiveLayer() );
717 line2->SetLayer( m_frame->GetActiveLayer() );
718 line3->SetLayer( m_frame->GetActiveLayer() );
719 line4->SetLayer( m_frame->GetActiveLayer() );
720
721 preview.push_back( line1 );
722 preview.push_back( line2 );
723 preview.push_back( line3 );
724 preview.push_back( line4 );
725
727 group->SetName("group-boardCharacteristics");
728
729 for( auto item : table )
730 group->AddItem( static_cast<BOARD_ITEM*>( item ) );
731
732 items.push_back( static_cast<BOARD_ITEM*>( group ) );
733
734 if( InteractivePlaceWithPreview( aEvent, items, preview, &layerSet ) == -1 )
735 m_frame->SetActiveLayer( layer );
736 else
737 m_frame->SetActiveLayer( table.front()->GetLayer() );
738
739 return 0;
740}
741
742
744{
745 VECTOR2I tableSize;
746
747 LSET layerSet = ( layerSet.AllCuMask() | layerSet.AllTechMask() );
748 layerSet = layerSet.set( Edge_Cuts ).set( Margin );
749 layerSet = layerSet.reset( F_Fab ).reset( B_Fab );
750
752 PCB_LAYER_ID savedLayer = layer;
753
754 if( ( layerSet & LSET( layer ) ).count() ) // if layer is a forbidden layer
755 {
757 layer = Cmts_User;
758 }
759
760 std::vector<BOARD_ITEM*> table = DrawSpecificationStackup( VECTOR2I( 0, 0 ),
761 m_frame->GetActiveLayer(), false,
762 &tableSize );
763 std::vector<BOARD_ITEM*> preview;
764 std::vector<BOARD_ITEM*> items;
765
766 PCB_SHAPE* line1 = new PCB_SHAPE;
767 PCB_SHAPE* line2 = new PCB_SHAPE;
768 PCB_SHAPE* line3 = new PCB_SHAPE;
769 PCB_SHAPE* line4 = new PCB_SHAPE;
770
771 line1->SetStart( VECTOR2I( 0, 0 ) );
772 line1->SetEnd( VECTOR2I( tableSize.x, 0 ) );
773
774 line2->SetStart( VECTOR2I( 0, 0 ) );
775 line2->SetEnd( VECTOR2I( 0, tableSize.y ) );
776
777 line3->SetStart( VECTOR2I( tableSize.x, 0 ) );
778 line3->SetEnd( tableSize );
779
780 line4->SetStart( VECTOR2I( 0, tableSize.y ) );
781 line4->SetEnd( tableSize );
782
783 line1->SetLayer( m_frame->GetActiveLayer() );
784 line2->SetLayer( m_frame->GetActiveLayer() );
785 line3->SetLayer( m_frame->GetActiveLayer() );
786 line4->SetLayer( m_frame->GetActiveLayer() );
787
788 preview.push_back( line1 );
789 preview.push_back( line2 );
790 preview.push_back( line3 );
791 preview.push_back( line4 );
792
794 group->SetName( "group-boardStackUp" );
795
796 for( BOARD_ITEM* item : table )
797 group->AddItem( item );
798
799 items.push_back( static_cast<BOARD_ITEM*>( group ) );
800
801 if( InteractivePlaceWithPreview( aEvent, items, preview, &layerSet ) == -1 )
802 m_frame->SetActiveLayer( savedLayer );
803 else
804 m_frame->SetActiveLayer( table.front()->GetLayer() );
805
806 return 0;
807}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:112
@ BS_EDGE_CONNECTOR_BEVELLED
Definition: board_stackup.h:57
@ BS_EDGE_CONNECTOR_NONE
Definition: board_stackup.h:55
@ BS_EDGE_CONNECTOR_IN_USE
Definition: board_stackup.h:56
@ BS_ITEM_TYPE_DIELECTRIC
Definition: board_stackup.h:44
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Container for design settings for a BOARD object.
int GetBoardThickness() const
The full thickness of the board including copper and masks.
BOARD_STACKUP & GetStackupDescriptor()
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Manage one layer needed to make a physical board.
Definition: board_stackup.h:91
wxString GetTypeName() const
int GetSublayersCount() const
double GetEpsilonR(int aDielectricSubLayer=0) const
wxString GetColor(int aDielectricSubLayer=0) const
wxString GetLayerName() const
PCB_LAYER_ID GetBrdLayerId() const
int GetThickness(int aDielectricSubLayer=0) const
BOARD_STACKUP_ITEM_TYPE GetType() const
wxString GetMaterial(int aDielectricSubLayer=0) const
double GetLossTangent(int aDielectricSubLayer=0) const
Manage layers needed to make a physical board.
bool m_CastellatedPads
True if castellated pads exist.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
int GetCount() const
bool SynchronizeWithBoard(BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
bool m_HasDielectricConstrains
True if some layers have impedance controlled tracks or have specific constrains for micro-wave appli...
bool m_EdgePlating
True if the edge board is plated.
BS_EDGE_CONNECTOR_CONSTRAINTS m_EdgeConnectorConstraints
If the board has edge connector cards, some constrains can be specified in job file: BS_EDGE_CONNECTO...
wxString m_FinishType
The name of external copper finish.
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:2201
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:536
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:766
coord_type GetHeight() const
Definition: box2.h:189
coord_type GetWidth() const
Definition: box2.h:188
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition: commit.h:78
KIGFX::VIEW_CONTROLS * m_controls
Definition: drawing_tool.h:347
int PlaceCharacteristics(const TOOL_EVENT &aEvent)
int PlaceStackup(const TOOL_EVENT &aEvent)
int InteractivePlaceWithPreview(const TOOL_EVENT &aEvent, std::vector< BOARD_ITEM * > &aItems, std::vector< BOARD_ITEM * > &aPreview, LSET *aLayers)
Interactively place a set of BOARD_ITEM.
std::vector< BOARD_ITEM * > DrawBoardCharacteristics(const VECTOR2I &origin, PCB_LAYER_ID aLayer, bool aDrawNow, VECTOR2I *tablesize)
std::vector< BOARD_ITEM * > DrawSpecificationStackup(const VECTOR2I &origin, PCB_LAYER_ID aLayer, bool aDrawNow, VECTOR2I *tablesize)
BOARD * m_board
Definition: drawing_tool.h:348
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:349
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:130
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:155
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:183
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
void ShowPreview(bool aShow=true)
Definition: view.cpp:1676
void InitPreview()
Definition: view.cpp:1655
void ClearPreview()
Definition: view.cpp:1640
void AddToPreview(VIEW_ITEM *aItem, bool aTakeOwnership=true)
Definition: view.cpp:1662
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:556
static LSET AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
Definition: lset.cpp:850
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:782
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
PCB_LAYER_ID SelectOneLayer(PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask=LSET(), wxPoint aDlgPosition=wxDefaultPosition)
Show the dialog box for a layer selection.
Definition: sel_layer.cpp:285
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:51
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_group.h:126
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_shape.cpp:97
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_text.cpp:284
virtual void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_text.h:84
KIGFX::PCB_VIEW * view() const
PCB_BASE_EDIT_FRAME * frame() const
BOARD * board() const
bool m_isFootprintEditor
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
RAII class that sets an value at construction and resets it to the original value at destruction.
Represent a set of closed polygons.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
virtual void PopTool(const TOOL_EVENT &aEvent)
Pops a tool from the stack.
virtual void PushTool(const TOOL_EVENT &aEvent)
NB: the definition of "tool" is different at the user level.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
Generic, UI-independent tool event.
Definition: tool_event.h:167
bool HasPosition() const
Definition: tool_event.h:256
const VECTOR2D Position() const
Returns the point where dragging has started.
Definition: tool_event.h:285
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
void Activate()
Run the tool.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:145
void PrimeTool(const VECTOR2D &aPosition)
"Prime" a tool by sending a cursor left-click event with the mouse position set to the passed in posi...
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:57
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
EDA_UNITS GetUserUnits() const
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aValue in internal units into a united string.
static bool IsZoneFillAction(const TOOL_EVENT *aEvent)
static std::vector< BOARD_ITEM * > initTextTable(std::vector< std::vector< PCB_TEXT * > > aContent, VECTOR2I origin, PCB_LAYER_ID aLayer, VECTOR2I *aTableSize, bool aDrawFrame=true)
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ Edge_Cuts
Definition: layer_ids.h:114
@ Cmts_User
Definition: layer_ids.h:111
@ Eco1_User
Definition: layer_ids.h:112
@ F_Fab
Definition: layer_ids.h:121
@ Margin
Definition: layer_ids.h:115
@ B_Fab
Definition: layer_ids.h:120
bool IsValidLayer(int aLayerId)
Test whether a given integer is a valid layer index, i.e.
Definition: layer_ids.h:831
KICOMMON_API double FromUserUnit(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnit, double aValue)
Return in internal units the value aValue given in a real unit such as "in", "mm",...
Definition: eda_units.cpp:499
KICOMMON_API wxString StringFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Returns the string from aValue according to aUnits (inch, mm ...) for display.
Definition: eda_units.cpp:284
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
Definition: gtk/ui.cpp:588
Class to handle a set of BOARD_ITEMs.
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_TOP
@ BUT_LEFT
Definition: tool_event.h:131
@ BUT_RIGHT
Definition: tool_event.h:132
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588