You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

861 lines
29 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <fctsys.h>
  24. #include <common.h>
  25. #include <plotter.h>
  26. #include <base_struct.h>
  27. #include <draw_graphic_text.h>
  28. #include <trigo.h>
  29. #include <macros.h>
  30. #include <pcb_base_frame.h>
  31. #include <class_board.h>
  32. #include <class_module.h>
  33. #include <class_track.h>
  34. #include <class_edge_mod.h>
  35. #include <class_pcb_text.h>
  36. #include <class_zone.h>
  37. #include <class_drawsegment.h>
  38. #include <class_pcb_target.h>
  39. #include <class_dimension.h>
  40. #include <convert_basic_shapes_to_polygon.h>
  41. #include <pcbnew.h>
  42. #include <pcbplot.h>
  43. #include <gbr_metadata.h>
  44. /* class BRDITEMS_PLOTTER is a helper class to plot board items
  45. * and a group of board items
  46. */
  47. COLOR4D BRDITEMS_PLOTTER::getColor( LAYER_NUM aLayer )
  48. {
  49. COLOR4D color = m_board->Colors().GetLayerColor( aLayer );
  50. // A hack to avoid plotting ahite itmen in white color, expecting the paper
  51. // is also white: use a non white color:
  52. if( color == COLOR4D::WHITE )
  53. color = COLOR4D( LIGHTGRAY );
  54. return color;
  55. }
  56. void BRDITEMS_PLOTTER::PlotPad( D_PAD* aPad, COLOR4D aColor, EDA_DRAW_MODE_T aPlotMode )
  57. {
  58. wxPoint shape_pos = aPad->ShapePos();
  59. GBR_METADATA gbr_metadata;
  60. bool isOnCopperLayer = ( m_layerMask & LSET::AllCuMask() ).any();
  61. bool isOnExternalCopperLayer = ( m_layerMask & LSET::ExternalCuMask() ).any();
  62. bool isPadOnBoardTechLayers = ( aPad->GetLayerSet() & LSET::AllBoardTechMask() ).any();
  63. gbr_metadata.SetCmpReference( aPad->GetParent()->GetReference() );
  64. if( isOnCopperLayer )
  65. {
  66. gbr_metadata.SetNetAttribType( GBR_NETINFO_ALL );
  67. gbr_metadata.SetCopper( true );
  68. if( isOnExternalCopperLayer )
  69. gbr_metadata.SetPadName( aPad->GetName() );
  70. gbr_metadata.SetNetName( aPad->GetNetname() );
  71. // Some pads are mechanical pads ( through hole or smd )
  72. // when this is the case, they have no pad name and/or are not plated.
  73. // In this case gerber files have slightly different attributes.
  74. if( aPad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ||
  75. aPad->GetName().IsEmpty() )
  76. gbr_metadata.m_NetlistMetadata.m_NotInNet = true;
  77. if( !isOnExternalCopperLayer || !isPadOnBoardTechLayers )
  78. {
  79. // On internal layers one cannot use the GBR_NETLIST_METADATA::GBR_INFO_FLASHED_PAD
  80. // attribute when the component is on an external layer (most of the case)
  81. // Also, if a SMD pad is not on a tech layer (masks) use also net+cmp attribute, because
  82. // it is not really a pad (can be a "pad", actually a node in a virtual component)
  83. gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_NET |
  84. GBR_NETLIST_METADATA::GBR_NETINFO_CMP );
  85. if( !isPadOnBoardTechLayers )
  86. // such a pad is not soldered and is not a connecting point.
  87. // Just set aperture attribute as conductor
  88. // If it is a through hole pad, it will be adjusted later
  89. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CONDUCTOR );
  90. switch( aPad->GetAttribute() )
  91. {
  92. case PAD_ATTRIB_HOLE_NOT_PLATED: // Mechanical pad through hole
  93. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_WASHERPAD );
  94. break;
  95. case PAD_ATTRIB_STANDARD : // Pad through hole, a hole is also expected
  96. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_VIAPAD );
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. else // Some attributes are reserved to the external copper layers
  103. {
  104. switch( aPad->GetAttribute() )
  105. {
  106. case PAD_ATTRIB_HOLE_NOT_PLATED: // Mechanical pad through hole
  107. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_WASHERPAD );
  108. break;
  109. case PAD_ATTRIB_STANDARD : // Pad through hole, a hole is also expected
  110. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_COMPONENTPAD );
  111. break;
  112. case PAD_ATTRIB_CONN: // Connector pads have no solder paste.
  113. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CONNECTORPAD );
  114. break;
  115. case PAD_ATTRIB_SMD: // SMD pads (One external copper layer only) with solder paste
  116. if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // perhaps a BGA pad
  117. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_BGAPAD_CUDEF );
  118. else
  119. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_SMDPAD_CUDEF );
  120. break;
  121. }
  122. }
  123. if( aPad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
  124. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_WASHERPAD );
  125. }
  126. else
  127. {
  128. gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_CMP );
  129. }
  130. // Set plot color (change WHITE to LIGHTGRAY because
  131. // the white items are not seen on a white paper or screen
  132. m_plotter->SetColor( aColor != WHITE ? aColor : LIGHTGRAY);
  133. switch( aPad->GetShape() )
  134. {
  135. case PAD_SHAPE_CIRCLE:
  136. m_plotter->FlashPadCircle( shape_pos, aPad->GetSize().x, aPlotMode, &gbr_metadata );
  137. break;
  138. case PAD_SHAPE_OVAL:
  139. m_plotter->FlashPadOval( shape_pos, aPad->GetSize(),
  140. aPad->GetOrientation(), aPlotMode, &gbr_metadata );
  141. break;
  142. case PAD_SHAPE_TRAPEZOID:
  143. {
  144. wxPoint coord[4];
  145. aPad->BuildPadPolygon( coord, wxSize(0,0), 0 );
  146. m_plotter->FlashPadTrapez( shape_pos, coord,
  147. aPad->GetOrientation(), aPlotMode, &gbr_metadata );
  148. }
  149. break;
  150. case PAD_SHAPE_ROUNDRECT:
  151. m_plotter->FlashPadRoundRect( shape_pos, aPad->GetSize(), aPad->GetRoundRectCornerRadius(),
  152. aPad->GetOrientation(), aPlotMode, &gbr_metadata );
  153. break;
  154. case PAD_SHAPE_CHAMFERED_RECT:
  155. {
  156. SHAPE_POLY_SET polygons;
  157. const int corner_radius = aPad->GetRoundRectCornerRadius( aPad->GetSize() );
  158. TransformRoundChamferedRectToPolygon( polygons, shape_pos, aPad->GetSize(),
  159. aPad->GetOrientation(), corner_radius, aPad->GetChamferRectRatio(),
  160. aPad->GetChamferPositions(), m_board->GetDesignSettings().m_MaxError );
  161. if( polygons.OutlineCount() == 0 )
  162. break;
  163. int min_dim = std::min( aPad->GetSize().x, aPad->GetSize().y ) /2;
  164. m_plotter->FlashPadCustom( shape_pos,wxSize( min_dim, min_dim ), &polygons, aPlotMode, &gbr_metadata );
  165. }
  166. break;
  167. case PAD_SHAPE_CUSTOM:
  168. {
  169. SHAPE_POLY_SET polygons;
  170. aPad->MergePrimitivesAsPolygon( &polygons );
  171. if( polygons.OutlineCount() == 0 )
  172. break;
  173. aPad->CustomShapeAsPolygonToBoardPosition( &polygons, shape_pos, aPad->GetOrientation() );
  174. m_plotter->FlashPadCustom( shape_pos, aPad->GetSize(), &polygons, aPlotMode, &gbr_metadata );
  175. }
  176. break;
  177. case PAD_SHAPE_RECT:
  178. default:
  179. m_plotter->FlashPadRect( shape_pos, aPad->GetSize(),
  180. aPad->GetOrientation(), aPlotMode, &gbr_metadata );
  181. break;
  182. }
  183. }
  184. bool BRDITEMS_PLOTTER::PlotAllTextsModule( MODULE* aModule )
  185. {
  186. TEXTE_MODULE* textModule = &aModule->Reference();
  187. LAYER_NUM textLayer = textModule->GetLayer();
  188. if( GetPlotReference() && m_layerMask[textLayer]
  189. && ( textModule->IsVisible() || GetPlotInvisibleText() ) )
  190. {
  191. PlotTextModule( textModule, getColor( textLayer ) );
  192. }
  193. textModule = &aModule->Value();
  194. textLayer = textModule->GetLayer();
  195. if( GetPlotValue() && m_layerMask[textLayer]
  196. && ( textModule->IsVisible() || GetPlotInvisibleText() ) )
  197. {
  198. PlotTextModule( textModule, getColor( textLayer ) );
  199. }
  200. for( BOARD_ITEM* item = aModule->GraphicalItemsList().GetFirst(); item; item = item->Next() )
  201. {
  202. textModule = dyn_cast<TEXTE_MODULE*>( item );
  203. if( !textModule )
  204. continue;
  205. if( !textModule->IsVisible() )
  206. continue;
  207. textLayer = textModule->GetLayer();
  208. if( textLayer >= PCB_LAYER_ID_COUNT )
  209. return false;
  210. if( !m_layerMask[textLayer] )
  211. continue;
  212. if( textModule->GetText() == wxT( "%R" ) && !GetPlotReference() )
  213. continue;
  214. if( textModule->GetText() == wxT( "%V" ) && !GetPlotValue() )
  215. continue;
  216. PlotTextModule( textModule, getColor( textLayer ) );
  217. }
  218. return true;
  219. }
  220. // plot items like text and graphics, but not tracks and module
  221. void BRDITEMS_PLOTTER::PlotBoardGraphicItems()
  222. {
  223. for( auto item : m_board->Drawings() )
  224. {
  225. switch( item->Type() )
  226. {
  227. case PCB_LINE_T: PlotDrawSegment( (DRAWSEGMENT*) item); break;
  228. case PCB_TEXT_T: PlotTextePcb( (TEXTE_PCB*) item ); break;
  229. case PCB_DIMENSION_T: PlotDimension( (DIMENSION*) item ); break;
  230. case PCB_TARGET_T: PlotPcbTarget( (PCB_TARGET*) item ); break;
  231. default: break;
  232. }
  233. }
  234. }
  235. void BRDITEMS_PLOTTER::PlotTextModule( TEXTE_MODULE* pt_texte, COLOR4D aColor )
  236. {
  237. wxSize size;
  238. wxPoint pos;
  239. double orient;
  240. int thickness;
  241. if( aColor == COLOR4D::WHITE )
  242. aColor = COLOR4D( LIGHTGRAY );
  243. m_plotter->SetColor( aColor );
  244. // calculate some text parameters :
  245. size = pt_texte->GetTextSize();
  246. pos = pt_texte->GetTextPos();
  247. orient = pt_texte->GetDrawRotation();
  248. thickness = pt_texte->GetThickness();
  249. if( pt_texte->IsMirrored() )
  250. size.x = -size.x; // Text is mirrored
  251. // Non bold texts thickness is clamped at 1/6 char size by the low level draw function.
  252. // but in Pcbnew we do not manage bold texts and thickness up to 1/4 char size
  253. // (like bold text) and we manage the thickness.
  254. // So we set bold flag to true
  255. bool allow_bold = pt_texte->IsBold() || thickness;
  256. GBR_METADATA gbr_metadata;
  257. gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_CMP );
  258. MODULE* parent = static_cast<MODULE*> ( pt_texte->GetParent() );
  259. gbr_metadata.SetCmpReference( parent->GetReference() );
  260. m_plotter->Text( pos, aColor, pt_texte->GetShownText(), orient, size,
  261. pt_texte->GetHorizJustify(), pt_texte->GetVertJustify(),
  262. thickness, pt_texte->IsItalic(), allow_bold, false, &gbr_metadata );
  263. }
  264. void BRDITEMS_PLOTTER::PlotDimension( DIMENSION* aDim )
  265. {
  266. if( !m_layerMask[aDim->GetLayer()] )
  267. return;
  268. DRAWSEGMENT draw;
  269. draw.SetWidth( aDim->GetWidth() );
  270. draw.SetLayer( aDim->GetLayer() );
  271. COLOR4D color = m_board->Colors().GetLayerColor( aDim->GetLayer() );
  272. // Set plot color (change WHITE to LIGHTGRAY because
  273. // the white items are not seen on a white paper or screen
  274. m_plotter->SetColor( color != WHITE ? color : LIGHTGRAY);
  275. PlotTextePcb( &aDim->Text() );
  276. draw.SetStart( aDim->m_crossBarO );
  277. draw.SetEnd( aDim->m_crossBarF );
  278. PlotDrawSegment( &draw );
  279. draw.SetStart( aDim->m_featureLineGO);
  280. draw.SetEnd( aDim->m_featureLineGF );
  281. PlotDrawSegment( &draw );
  282. draw.SetStart( aDim->m_featureLineDO );
  283. draw.SetEnd( aDim->m_featureLineDF );
  284. PlotDrawSegment( &draw );
  285. draw.SetStart( aDim->m_crossBarF );
  286. draw.SetEnd( aDim->m_arrowD1F );
  287. PlotDrawSegment( &draw );
  288. draw.SetStart( aDim->m_crossBarF );
  289. draw.SetEnd( aDim->m_arrowD2F );
  290. PlotDrawSegment( &draw );
  291. draw.SetStart( aDim->m_crossBarO );
  292. draw.SetEnd( aDim->m_arrowG1F );
  293. PlotDrawSegment( &draw );
  294. draw.SetStart( aDim->m_crossBarO );
  295. draw.SetEnd( aDim->m_arrowG2F );
  296. PlotDrawSegment( &draw );
  297. }
  298. void BRDITEMS_PLOTTER::PlotPcbTarget( PCB_TARGET* aMire )
  299. {
  300. int dx1, dx2, dy1, dy2, radius;
  301. if( !m_layerMask[aMire->GetLayer()] )
  302. return;
  303. m_plotter->SetColor( getColor( aMire->GetLayer() ) );
  304. DRAWSEGMENT draw;
  305. draw.SetShape( S_CIRCLE );
  306. draw.SetWidth( aMire->GetWidth() );
  307. draw.SetLayer( aMire->GetLayer() );
  308. draw.SetStart( aMire->GetPosition() );
  309. radius = aMire->GetSize() / 3;
  310. if( aMire->GetShape() ) // shape X
  311. radius = aMire->GetSize() / 2;
  312. // Draw the circle
  313. draw.SetEnd( wxPoint( draw.GetStart().x + radius, draw.GetStart().y ));
  314. PlotDrawSegment( &draw );
  315. draw.SetShape( S_SEGMENT );
  316. radius = aMire->GetSize() / 2;
  317. dx1 = radius;
  318. dy1 = 0;
  319. dx2 = 0;
  320. dy2 = radius;
  321. if( aMire->GetShape() ) // Shape X
  322. {
  323. dx1 = dy1 = radius;
  324. dx2 = dx1;
  325. dy2 = -dy1;
  326. }
  327. wxPoint mirePos( aMire->GetPosition() );
  328. // Draw the X or + shape:
  329. draw.SetStart( wxPoint( mirePos.x - dx1, mirePos.y - dy1 ));
  330. draw.SetEnd( wxPoint( mirePos.x + dx1, mirePos.y + dy1 ));
  331. PlotDrawSegment( &draw );
  332. draw.SetStart( wxPoint( mirePos.x - dx2, mirePos.y - dy2 ));
  333. draw.SetEnd( wxPoint( mirePos.x + dx2, mirePos.y + dy2 ));
  334. PlotDrawSegment( &draw );
  335. }
  336. // Plot footprints graphic items (outlines)
  337. void BRDITEMS_PLOTTER::Plot_Edges_Modules()
  338. {
  339. for( MODULE* module = m_board->m_Modules; module; module = module->Next() )
  340. {
  341. for( BOARD_ITEM* item = module->GraphicalItemsList().GetFirst(); item; item = item->Next() )
  342. {
  343. EDGE_MODULE* edge = dyn_cast<EDGE_MODULE*>( item );
  344. if( edge && m_layerMask[edge->GetLayer()] )
  345. Plot_1_EdgeModule( edge );
  346. }
  347. }
  348. }
  349. //* Plot a graphic item (outline) relative to a footprint
  350. void BRDITEMS_PLOTTER::Plot_1_EdgeModule( EDGE_MODULE* aEdge )
  351. {
  352. int type_trace; // Type of item to plot.
  353. int thickness; // Segment thickness.
  354. int radius; // Circle radius.
  355. if( aEdge->Type() != PCB_MODULE_EDGE_T )
  356. return;
  357. m_plotter->SetColor( getColor( aEdge->GetLayer() ) );
  358. type_trace = aEdge->GetShape();
  359. thickness = aEdge->GetWidth();
  360. wxPoint pos( aEdge->GetStart() );
  361. wxPoint end( aEdge->GetEnd() );
  362. GBR_METADATA gbr_metadata;
  363. gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_CMP );
  364. MODULE* parent = static_cast<MODULE*> ( aEdge->GetParent() );
  365. gbr_metadata.SetCmpReference( parent->GetReference() );
  366. bool isOnCopperLayer = ( m_layerMask & LSET::AllCuMask() ).any();
  367. if( isOnCopperLayer )
  368. {
  369. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_ETCHEDCMP );
  370. gbr_metadata.SetCopper( true );
  371. }
  372. else if( aEdge->GetLayer() == Edge_Cuts ) // happens also when plotting copper layers
  373. {
  374. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_NONCONDUCTOR );
  375. }
  376. switch( type_trace )
  377. {
  378. case S_SEGMENT:
  379. m_plotter->ThickSegment( pos, end, thickness, GetPlotMode(), &gbr_metadata );
  380. break;
  381. case S_CIRCLE:
  382. radius = KiROUND( GetLineLength( end, pos ) );
  383. m_plotter->ThickCircle( pos, radius * 2, thickness, GetPlotMode(), &gbr_metadata );
  384. break;
  385. case S_ARC:
  386. {
  387. radius = KiROUND( GetLineLength( end, pos ) );
  388. double startAngle = ArcTangente( end.y - pos.y, end.x - pos.x );
  389. double endAngle = startAngle + aEdge->GetAngle();
  390. // when startAngle == endAngle ThickArc() doesn't know whether it's 0 deg and 360 deg
  391. if( std::abs( aEdge->GetAngle() ) == 3600.0 )
  392. m_plotter->ThickCircle( pos, radius * 2, thickness, GetPlotMode(), &gbr_metadata );
  393. else
  394. m_plotter->ThickArc( pos, -endAngle, -startAngle, radius, thickness, GetPlotMode(), &gbr_metadata );
  395. }
  396. break;
  397. case S_POLYGON:
  398. if( aEdge->IsPolyShapeValid() )
  399. {
  400. const std::vector<wxPoint>& polyPoints = aEdge->BuildPolyPointsList();
  401. // We must compute true coordinates from m_PolyList
  402. // which are relative to module position, orientation 0
  403. MODULE* module = aEdge->GetParentModule();
  404. std::vector< wxPoint > cornerList;
  405. cornerList.reserve( polyPoints.size() );
  406. for( wxPoint corner : polyPoints )
  407. {
  408. if( module )
  409. {
  410. RotatePoint( &corner, module->GetOrientation() );
  411. corner += module->GetPosition();
  412. }
  413. cornerList.push_back( corner );
  414. }
  415. if( !aEdge->IsPolygonFilled() )
  416. {
  417. for( size_t i = 1; i < cornerList.size(); i++ )
  418. {
  419. m_plotter->ThickSegment( cornerList[i-1], cornerList[i], thickness,
  420. GetPlotMode(), &gbr_metadata );
  421. }
  422. m_plotter->ThickSegment( cornerList.back(), cornerList.front(), thickness,
  423. GetPlotMode(), &gbr_metadata );
  424. }
  425. else
  426. {
  427. m_plotter->PlotPoly( cornerList, FILLED_SHAPE, thickness, &gbr_metadata );
  428. }
  429. }
  430. break;
  431. }
  432. }
  433. // Plot a PCB Text, i.e. a text found on a copper or technical layer
  434. void BRDITEMS_PLOTTER::PlotTextePcb( TEXTE_PCB* pt_texte )
  435. {
  436. double orient;
  437. int thickness;
  438. wxPoint pos;
  439. wxSize size;
  440. wxString shownText( pt_texte->GetShownText() );
  441. if( shownText.IsEmpty() )
  442. return;
  443. if( !m_layerMask[pt_texte->GetLayer()] )
  444. return;
  445. GBR_METADATA gbr_metadata;
  446. if( IsCopperLayer( pt_texte->GetLayer() ) )
  447. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_NONCONDUCTOR );
  448. COLOR4D color = getColor( pt_texte->GetLayer() );
  449. m_plotter->SetColor( color );
  450. size = pt_texte->GetTextSize();
  451. pos = pt_texte->GetTextPos();
  452. orient = pt_texte->GetTextAngle();
  453. thickness = pt_texte->GetThickness();
  454. if( pt_texte->IsMirrored() )
  455. size.x = -size.x;
  456. // Non bold texts thickness is clamped at 1/6 char size by the low level draw function.
  457. // but in Pcbnew we do not manage bold texts and thickness up to 1/4 char size
  458. // (like bold text) and we manage the thickness.
  459. // So we set bold flag to true
  460. bool allow_bold = pt_texte->IsBold() || thickness;
  461. if( pt_texte->IsMultilineAllowed() )
  462. {
  463. std::vector<wxPoint> positions;
  464. wxArrayString strings_list;
  465. wxStringSplit( shownText, strings_list, '\n' );
  466. positions.reserve( strings_list.Count() );
  467. pt_texte->GetPositionsOfLinesOfMultilineText( positions, strings_list.Count() );
  468. for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
  469. {
  470. wxString& txt = strings_list.Item( ii );
  471. m_plotter->Text( positions[ii], color, txt, orient, size,
  472. pt_texte->GetHorizJustify(), pt_texte->GetVertJustify(),
  473. thickness, pt_texte->IsItalic(), allow_bold, false, &gbr_metadata );
  474. }
  475. }
  476. else
  477. {
  478. m_plotter->Text( pos, color, shownText, orient, size,
  479. pt_texte->GetHorizJustify(), pt_texte->GetVertJustify(),
  480. thickness, pt_texte->IsItalic(), allow_bold, false, &gbr_metadata );
  481. }
  482. }
  483. /* Plot areas (given by .m_FilledPolysList member) in a zone
  484. */
  485. void BRDITEMS_PLOTTER::PlotFilledAreas( ZONE_CONTAINER* aZone )
  486. {
  487. const SHAPE_POLY_SET& polysList = aZone->GetFilledPolysList();
  488. if( polysList.IsEmpty() )
  489. return;
  490. GBR_METADATA gbr_metadata;
  491. bool isOnCopperLayer = aZone->IsOnCopperLayer();
  492. if( isOnCopperLayer )
  493. {
  494. gbr_metadata.SetNetName( aZone->GetNetname() );
  495. gbr_metadata.SetCopper( true );
  496. // Zones with no net name can exist.
  497. // they are not used to connect items, so the aperture attribute cannot
  498. // be set as conductor
  499. if( aZone->GetNetname().IsEmpty() )
  500. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_NONCONDUCTOR );
  501. else
  502. {
  503. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CONDUCTOR );
  504. gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_NET );
  505. }
  506. }
  507. // We need a buffer to store corners coordinates:
  508. static std::vector< wxPoint > cornerList;
  509. cornerList.clear();
  510. m_plotter->SetColor( getColor( aZone->GetLayer() ) );
  511. /* Plot all filled areas: filled areas have a filled area and a thick
  512. * outline we must plot the filled area itself ( as a filled polygon
  513. * OR a set of segments ) and plot the thick outline itself
  514. *
  515. * in non filled mode the outline is plotted, but not the filling items
  516. */
  517. for( auto ic = polysList.CIterate(); ic; ++ic )
  518. {
  519. wxPoint pos( ic->x, ic->y );
  520. cornerList.push_back( pos );
  521. if( ic.IsEndContour() ) // Plot the current filled area outline
  522. {
  523. // First, close the outline
  524. if( cornerList[0] != cornerList[cornerList.size() - 1] )
  525. cornerList.push_back( cornerList[0] );
  526. // Plot the current filled area and its outline
  527. if( GetPlotMode() == FILLED )
  528. {
  529. m_plotter->PlotPoly( cornerList, FILLED_SHAPE, aZone->GetMinThickness(), &gbr_metadata );
  530. }
  531. else
  532. {
  533. if( aZone->GetMinThickness() > 0 )
  534. {
  535. for( unsigned jj = 1; jj < cornerList.size(); jj++ )
  536. {
  537. m_plotter->ThickSegment( cornerList[jj -1], cornerList[jj],
  538. aZone->GetMinThickness(),
  539. GetPlotMode(), &gbr_metadata );
  540. }
  541. }
  542. m_plotter->SetCurrentLineWidth( -1 );
  543. }
  544. cornerList.clear();
  545. }
  546. }
  547. }
  548. /* Plot items type DRAWSEGMENT on layers allowed by aLayerMask
  549. */
  550. void BRDITEMS_PLOTTER::PlotDrawSegment( DRAWSEGMENT* aSeg )
  551. {
  552. if( !m_layerMask[aSeg->GetLayer()] )
  553. return;
  554. int radius = 0;
  555. double StAngle = 0, EndAngle = 0;
  556. int thickness = aSeg->GetWidth();
  557. m_plotter->SetColor( getColor( aSeg->GetLayer() ) );
  558. wxPoint start( aSeg->GetStart() );
  559. wxPoint end( aSeg->GetEnd() );
  560. GBR_METADATA gbr_metadata;
  561. bool isOnCopperLayer = ( m_layerMask & LSET::AllCuMask() ).any();
  562. if( isOnCopperLayer && aSeg->GetLayer() == Edge_Cuts ) // can happens when plotting copper layers
  563. gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_NONCONDUCTOR );
  564. switch( aSeg->GetShape() )
  565. {
  566. case S_CIRCLE:
  567. radius = KiROUND( GetLineLength( end, start ) );
  568. m_plotter->ThickCircle( start, radius * 2, thickness, GetPlotMode(), &gbr_metadata );
  569. break;
  570. case S_ARC:
  571. radius = KiROUND( GetLineLength( end, start ) );
  572. StAngle = ArcTangente( end.y - start.y, end.x - start.x );
  573. EndAngle = StAngle + aSeg->GetAngle();
  574. // when startAngle == endAngle ThickArc() doesn't know whether it's 0 deg and 360 deg
  575. if( std::abs( aSeg->GetAngle() ) == 3600.0 )
  576. m_plotter->ThickCircle( start, radius * 2, thickness, GetPlotMode(), &gbr_metadata );
  577. else
  578. m_plotter->ThickArc( start, -EndAngle, -StAngle, radius, thickness, GetPlotMode(), &gbr_metadata );
  579. break;
  580. case S_CURVE:
  581. {
  582. m_plotter->SetCurrentLineWidth( thickness, &gbr_metadata );
  583. const std::vector<wxPoint>& bezierPoints = aSeg->GetBezierPoints();
  584. for( unsigned i = 1; i < bezierPoints.size(); i++ )
  585. {
  586. m_plotter->ThickSegment( bezierPoints[i - 1], bezierPoints[i],
  587. thickness, GetPlotMode(), &gbr_metadata );
  588. }
  589. }
  590. break;
  591. case S_POLYGON:
  592. {
  593. if( !aSeg->IsPolygonFilled() )
  594. {
  595. for( auto it = aSeg->GetPolyShape().IterateSegments( 0 ); it; it++ )
  596. {
  597. auto seg = it.Get();
  598. m_plotter->ThickSegment( wxPoint( seg.A ), wxPoint( seg.B ),
  599. thickness, GetPlotMode(), &gbr_metadata );
  600. }
  601. }
  602. else
  603. {
  604. m_plotter->SetCurrentLineWidth( thickness, &gbr_metadata );
  605. // Draw the polygon: only one polygon is expected
  606. // However we provide a multi polygon shape drawing
  607. // ( for the future or to show a non expected shape )
  608. // This must be simplified and fractured to prevent overlapping polygons
  609. // from generating invalid Gerber files
  610. auto tmpPoly = SHAPE_POLY_SET( aSeg->GetPolyShape() );
  611. tmpPoly.Fracture( SHAPE_POLY_SET::PM_FAST );
  612. for( int jj = 0; jj < tmpPoly.OutlineCount(); ++jj )
  613. {
  614. SHAPE_LINE_CHAIN& poly = tmpPoly.Outline( jj );
  615. m_plotter->PlotPoly( poly, FILLED_SHAPE, thickness, &gbr_metadata );
  616. }
  617. }
  618. }
  619. break;
  620. default:
  621. m_plotter->ThickSegment( start, end, thickness, GetPlotMode(), &gbr_metadata );
  622. }
  623. }
  624. /** Helper function to plot a single drill mark. It compensate and clamp
  625. * the drill mark size depending on the current plot options
  626. */
  627. void BRDITEMS_PLOTTER::plotOneDrillMark( PAD_DRILL_SHAPE_T aDrillShape, const wxPoint &aDrillPos,
  628. wxSize aDrillSize, const wxSize &aPadSize,
  629. double aOrientation, int aSmallDrill )
  630. {
  631. // Small drill marks have no significance when applied to slots
  632. if( aSmallDrill && aDrillShape == PAD_DRILL_SHAPE_CIRCLE )
  633. aDrillSize.x = std::min( aSmallDrill, aDrillSize.x );
  634. // Round holes only have x diameter, slots have both
  635. aDrillSize.x -= getFineWidthAdj();
  636. aDrillSize.x = Clamp( 1, aDrillSize.x, aPadSize.x - 1 );
  637. if( aDrillShape == PAD_DRILL_SHAPE_OBLONG )
  638. {
  639. aDrillSize.y -= getFineWidthAdj();
  640. aDrillSize.y = Clamp( 1, aDrillSize.y, aPadSize.y - 1 );
  641. m_plotter->FlashPadOval( aDrillPos, aDrillSize, aOrientation, GetPlotMode(), NULL );
  642. }
  643. else
  644. m_plotter->FlashPadCircle( aDrillPos, aDrillSize.x, GetPlotMode(), NULL );
  645. }
  646. void BRDITEMS_PLOTTER::PlotDrillMarks()
  647. {
  648. /* If small drills marks were requested prepare a clamp value to pass
  649. to the helper function */
  650. int small_drill = (GetDrillMarksType() == PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE) ?
  651. SMALL_DRILL : 0;
  652. /* In the filled trace mode drill marks are drawn white-on-black to scrape
  653. the underlying pad. This works only for drivers supporting color change,
  654. obviously... it means that:
  655. - PS, SVG and PDF output is correct (i.e. you have a 'donut' pad)
  656. - In HPGL you can't see them
  657. - In gerbers you can't see them, too. This is arguably the right thing to
  658. do since having drill marks and high speed drill stations is a sure
  659. recipe for broken tools and angry manufacturers. If you *really* want them
  660. you could start a layer with negative polarity to scrape the film.
  661. - In DXF they go into the 'WHITE' layer. This could be useful.
  662. */
  663. if( GetPlotMode() == FILLED )
  664. m_plotter->SetColor( WHITE );
  665. for( TRACK* pts = m_board->m_Track; pts != NULL; pts = pts->Next() )
  666. {
  667. const VIA* via = dyn_cast<const VIA*>( pts );
  668. if( via )
  669. {
  670. plotOneDrillMark( PAD_DRILL_SHAPE_CIRCLE, via->GetStart(),
  671. wxSize( via->GetDrillValue(), 0 ),
  672. wxSize( via->GetWidth(), 0 ), 0, small_drill );
  673. }
  674. }
  675. for( MODULE* Module = m_board->m_Modules; Module != NULL; Module = Module->Next() )
  676. {
  677. for( D_PAD* pad = Module->PadsList(); pad != NULL; pad = pad->Next() )
  678. {
  679. if( pad->GetDrillSize().x == 0 )
  680. continue;
  681. plotOneDrillMark( pad->GetDrillShape(),
  682. pad->GetPosition(), pad->GetDrillSize(),
  683. pad->GetSize(), pad->GetOrientation(),
  684. small_drill );
  685. }
  686. }
  687. if( GetPlotMode() == FILLED )
  688. m_plotter->SetColor( GetColor() );
  689. }