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 <tools/tool_event_utils.h>
#include <board_commit.h>
#include <scoped_set_reset.h>
#include <bitmaps.h>
#include <painter.h>
#include <board.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, wxPoint origin, PCB_LAYER_ID aLayer, wxPoint *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,
wxPoint  origin,
PCB_LAYER_ID  aLayer,
wxPoint *  aTableSize,
bool  aDrawFrame = true 
)
static

Definition at line 50 of file drawing_stackup_table_tool.cpp.

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

References Millimeter2iu(), EDA_SHAPE::SetEndX(), EDA_SHAPE::SetEndY(), BOARD_ITEM::SetLayer(), EDA_SHAPE::SetStartX(), and EDA_SHAPE::SetStartY().

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