KiCad PCB EDA Suite
drawing_stackup_table_tool.cpp File Reference
#include "drawing_tool.h"
#include "pcb_actions.h"
#include <pcb_edit_frame.h>
#include <view/view.h>
#include <tool/tool_manager.h>
#include <board_commit.h>
#include <scoped_set_reset.h>
#include <painter.h>
#include <tools/zone_filler_tool.h>
#include <board_design_settings.h>
#include <footprint.h>
#include <fp_shape.h>
#include <pcb_group.h>
#include <pcb_text.h>
#include <string_utils.h>
#include <wx/utils.h>

Go to the source code of this file.

Typedefs

using SCOPED_DRAW_MODE = SCOPED_SET_RESET< DRAWING_TOOL::MODE >
 

Functions

static std::vector< BOARD_ITEM * > initTextTable (std::vector< std::vector< PCB_TEXT * > > aContent, VECTOR2I origin, PCB_LAYER_ID aLayer, VECTOR2I *aTableSize, bool aDrawFrame=true)
 

Typedef Documentation

◆ SCOPED_DRAW_MODE

Function Documentation

◆ initTextTable()

static std::vector< BOARD_ITEM * > initTextTable ( std::vector< std::vector< PCB_TEXT * > >  aContent,
VECTOR2I  origin,
PCB_LAYER_ID  aLayer,
VECTOR2I aTableSize,
bool  aDrawFrame = true 
)
static

Definition at line 46 of file drawing_stackup_table_tool.cpp.

49{
50 int i;
51 int j;
52
53 int nbCols = aContent.size();
54 int nbRows = 0;
55
56 for( const std::vector<PCB_TEXT*>& col : aContent )
57 nbRows = std::max( nbRows, static_cast<int>( col.size() ) );
58
59 // Limit the number of cells
60 nbCols = std::min( nbCols, 99 );
61 nbRows = std::min( nbRows, 99 );
62
63 int rowHeight[99];
64 int colWidth[99];
65
66 std::vector<BOARD_ITEM*> table;
67
68 // xmargin and ymargin are margins between the text and the table lines.
69 //
70 // +--------------------------------+
71 // | ^ |
72 // | | ymargin |
73 // | v |
74 // |<------->TEXT_TEXT_TEXT<------->|
75 // | xmargin ^ xmargin |
76 // | | ymargin |
77 // | v |
78 // +--------------------------------+
79 //
80
81 int xmargin = pcbIUScale.mmToIU( 0.75 );
82 int ymargin = pcbIUScale.mmToIU( 0.75 );
83
84 // Init table
85 for( i = 0; i < nbRows; i++ )
86 rowHeight[i] = 0;
87
88 for( i = 0; i < nbCols; i++ )
89 colWidth[i] = 0;
90
91 // First, we determine what the height/Width should be for every cell
92 i = 0;
93
94 for( const std::vector<PCB_TEXT*>& col : aContent )
95 {
96 j = 0;
97
98 if( i >= nbCols )
99 break;
100
101 for( const PCB_TEXT* cell : col )
102 {
103 if( j >= nbRows )
104 break;
105
106 int height = cell->GetBoundingBox().GetHeight() + 2 * ymargin;
107 int width = cell->GetBoundingBox().GetWidth() + 2 * xmargin;
108 rowHeight[j] = rowHeight[j] > height ? rowHeight[j] : height;
109 colWidth[i] = colWidth[i] > width ? colWidth[i] : width;
110 j++;
111 }
112
113 i++;
114 }
115
116 // get table size
117 int height = std::accumulate( rowHeight, rowHeight + nbRows, 0 );
118 int width = std::accumulate( colWidth, colWidth + nbCols, 0 );
119
120 aTableSize->x = width;
121 aTableSize->y = height;
122 // Draw the frame
123
124 if( aDrawFrame )
125 {
126 int y = origin.y;
127 PCB_SHAPE* line;
128
129 for( i = 0; i < nbRows; i++ )
130 {
131 line = new PCB_SHAPE;
132 line->SetLayer( aLayer );
133 line->SetStart( VECTOR2I( origin.x, y ) );
134 line->SetEnd( VECTOR2I( origin.x + width, y ) );
135 y += rowHeight[i];
136 table.push_back( line );
137 }
138
139 line = new PCB_SHAPE;
140 line->SetLayer( aLayer );
141 line->SetStart( VECTOR2I( origin.x, y ) );
142 line->SetEnd( VECTOR2I( origin.x + width, y ) );
143 table.push_back( line );
144 int x = origin.x;
145
146 for( i = 0; i < nbCols; i++ )
147 {
148 line = new PCB_SHAPE;
149 line->SetLayer( aLayer );
150 line->SetStart( VECTOR2I( x, origin.y ) );
151 line->SetEnd( VECTOR2I( x, origin.y + height ) );
152 x += colWidth[i];
153 table.push_back( line );
154 }
155
156 line = new PCB_SHAPE;
157 line->SetLayer( aLayer );
158 line->SetStart( VECTOR2I( x, origin.y ) );
159 line->SetEnd( VECTOR2I( x, origin.y + height ) );
160 table.push_back( line );
161 }
162
163 //Now add the text
164 i = 0;
165 VECTOR2I pos( origin.x + xmargin, origin.y + ymargin );
166
167 for( std::vector<PCB_TEXT*>& col : aContent )
168 {
169 j = 0;
170
171 if( i >= nbCols )
172 break;
173
174 pos.y = origin.y + ymargin;
175
176 for( PCB_TEXT* cell : col )
177 {
178 if( j >= nbRows )
179 break;
180
181 cell->SetTextPos( pos );
182 cell->SetLayer( aLayer );
183 pos.y = pos.y + rowHeight[j];
184 table.push_back( cell );
185 j++;
186 }
187
188 pos.x = pos.x + colWidth[i];
189 i++;
190 }
191
192 return table;
193}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:226
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:124
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:149
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

References EDA_IU_SCALE::mmToIU(), pcbIUScale, EDA_SHAPE::SetEnd(), BOARD_ITEM::SetLayer(), EDA_SHAPE::SetStart(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DRAWING_TOOL::DrawBoardCharacteristics(), and DRAWING_TOOL::DrawSpecificationStackup().