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.

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