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.

148 lines
4.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2019-2021 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. * @file board_stackup_reporter.cpp
  26. */
  27. #include "wx/string.h"
  28. #include <base_units.h>
  29. #include <locale_io.h>
  30. #include "board_stackup.h"
  31. #include "stackup_predefined_prms.h"
  32. #include "board_stackup_reporter.h"
  33. wxString BuildStackupReport( BOARD_STACKUP& aStackup, EDA_UNITS aUnits )
  34. {
  35. // Build a ascii representation of stackup and copy it in the clipboard
  36. wxString report;
  37. wxString txt;
  38. LOCALE_IO toggle; // toggles on the C locale to write floating values, then off.
  39. for( const BOARD_STACKUP_ITEM* item : aStackup.GetList() )
  40. {
  41. // Skip stackup items useless for the current board
  42. if( !item->IsEnabled() )
  43. continue;
  44. if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC )
  45. {
  46. wxString sublayer_text;
  47. if( item->GetSublayersCount() )
  48. sublayer_text.Printf( "\n sublayer \"1/%d\"", item->GetSublayersCount() );
  49. txt.Printf( "layer \"%s\" type \"%s\"%s",
  50. item->FormatDielectricLayerName(),
  51. item->GetTypeName(), sublayer_text );
  52. }
  53. else
  54. txt.Printf( "layer \"%s\" type \"%s\"", item->GetLayerName(),
  55. item->GetTypeName() );
  56. report << txt;
  57. if( item->IsColorEditable() )
  58. {
  59. txt.Printf( " Color \"%s\"", item->GetColor() );
  60. report << txt;
  61. }
  62. for( int idx = 0; idx < item->GetSublayersCount(); idx++ )
  63. {
  64. if( idx ) // not printed for the main (first) layer.
  65. {
  66. txt.Printf( "\n sublayer \"%d/%d\"", idx+1, item->GetSublayersCount() );
  67. report << txt;
  68. }
  69. if( item->IsThicknessEditable() )
  70. {
  71. txt.Printf( " Thickness %s",
  72. StringFromValue( aUnits, item->GetThickness( idx ), true ) );
  73. report << txt;
  74. if( item->GetType() == BS_ITEM_TYPE_DIELECTRIC && item->IsThicknessLocked( idx ) )
  75. {
  76. txt.Printf( " Locked" );
  77. report << txt;
  78. }
  79. }
  80. if( item->IsMaterialEditable() )
  81. {
  82. txt.Printf( " Material \"%s\"", item->GetMaterial( idx ) );
  83. report << txt;
  84. }
  85. if( item->HasEpsilonRValue() )
  86. {
  87. txt.Printf( " EpsilonR %s", item->FormatEpsilonR( idx ) );
  88. report << txt;
  89. }
  90. if( item->HasLossTangentValue() )
  91. {
  92. txt.Printf( " LossTg %s", item->FormatLossTangent( idx ) );
  93. report << txt;
  94. }
  95. }
  96. report << '\n';
  97. }
  98. // Finish and other options:
  99. txt.Printf( "Finish \"%s\"", aStackup.m_FinishType );
  100. report << txt;
  101. if( aStackup.m_HasDielectricConstrains )
  102. report << " Option \"Impedance Controlled\"";
  103. if( aStackup.m_EdgePlating )
  104. report << " Option \"Plated edges\"";
  105. if( aStackup.m_CastellatedPads )
  106. report << " Option \"Castellated Pads\"";
  107. if( aStackup.m_EdgeConnectorConstraints != BS_EDGE_CONNECTOR_NONE )
  108. {
  109. wxString conn_txt = "yes";
  110. if( aStackup.m_EdgeConnectorConstraints == BS_EDGE_CONNECTOR_BEVELLED )
  111. conn_txt << ",bevelled";
  112. txt.Printf( " EdgeConnector \"%s\"", conn_txt );
  113. report << txt;
  114. }
  115. report << '\n';
  116. return report;
  117. }