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.

144 lines
4.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019-2021 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 <string>
  24. #include <common.h>
  25. #include <profile.h>
  26. #include <wx/cmdline.h>
  27. #include <property_mgr.h>
  28. #include <pcbnew_utils/board_file_utils.h>
  29. #include <pcbnew/drc/drc_engine.h>
  30. #include <pcbnew/board.h>
  31. #include <pcbnew/drc/drc_rule_parser.h>
  32. #include <pcbnew/drc/drc_test_provider.h>
  33. #include <pcbnew/pcb_expr_evaluator.h>
  34. #include <board_design_settings.h>
  35. #include <string_utils.h>
  36. #include <connectivity/connectivity_data.h>
  37. #include <connectivity/connectivity_algo.h>
  38. #include <reporter.h>
  39. #include <widgets/progress_reporter_base.h>
  40. #include <project.h>
  41. #include <settings/settings_manager.h>
  42. #include <wildcards_and_files_ext.h>
  43. #include <pgm_base.h>
  44. #include <kiway.h>
  45. #include <kiface_ids.h>
  46. #include "drc_proto.h"
  47. PROJECT_CONTEXT loadKicadProject( const wxString& filename, OPT<wxString> rulesFilePath )
  48. {
  49. PROJECT_CONTEXT rv;
  50. auto &manager = Pgm().GetSettingsManager();
  51. wxFileName pro( filename );
  52. wxFileName brdName ( filename );
  53. wxFileName schName ( filename );
  54. wxFileName ruleFileName ( filename );
  55. pro.SetExt( ProjectFileExtension );
  56. brdName.SetExt( KiCadPcbFileExtension );
  57. schName.SetExt( KiCadSchematicFileExtension );
  58. ruleFileName.SetExt( DesignRulesFileExtension );
  59. brdName.MakeAbsolute();
  60. schName.MakeAbsolute();
  61. ruleFileName.MakeAbsolute();
  62. pro.MakeAbsolute();
  63. manager.LoadProject( pro.GetFullPath() );
  64. rv.project = &manager.Prj();
  65. rv.board.reset( KI_TEST::ReadBoardFromFileOrStream(
  66. std::string( brdName.GetFullPath().ToUTF8() ) ).release() );
  67. rv.board->SetProject( rv.project );
  68. if( rulesFilePath )
  69. rv.rulesFilePath = *rulesFilePath;
  70. else
  71. rv.rulesFilePath = ruleFileName.GetFullPath();
  72. if( wxFileExists( schName.GetFullPath() ) )
  73. {
  74. //printf("Generating SCH netlist for '%s'\n", (const char*) schName.GetFullPath() );
  75. //rv.netlist.reset( new NETLIST );
  76. //generateSchematicNetlist( schName.GetFullPath(), *rv.netlist.get() );
  77. }
  78. return rv;
  79. }
  80. int runDRCProto( PROJECT_CONTEXT project, std::shared_ptr<KIGFX::VIEW_OVERLAY> aDebugOverlay )
  81. {
  82. std::shared_ptr<DRC_ENGINE> drcEngine( new DRC_ENGINE );
  83. CONSOLE_LOG consoleLog;
  84. project.board->GetDesignSettings().m_DRCEngine = drcEngine;
  85. drcEngine->SetBoard( project.board.get() );
  86. drcEngine->SetDesignSettings( &project.board->GetDesignSettings() );
  87. drcEngine->SetLogReporter( new CONSOLE_MSG_REPORTER ( &consoleLog ) );
  88. drcEngine->SetProgressReporter( new CONSOLE_PROGRESS_REPORTER ( &consoleLog ) );
  89. drcEngine->SetViolationHandler(
  90. [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, PCB_LAYER_ID aLayer )
  91. {
  92. // fixme
  93. } );
  94. drcEngine->InitEngine( project.rulesFilePath );
  95. drcEngine->SetDebugOverlay( aDebugOverlay );
  96. for( auto provider : drcEngine->GetTestProviders() )
  97. {
  98. //if( provider->GetName() == "diff_pair_coupling" )
  99. // provider->Enable(true);
  100. //else
  101. // provider->Enable(false);
  102. }
  103. try
  104. {
  105. drcEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
  106. }
  107. catch( const ClipperLib::clipperException& e )
  108. {
  109. consoleLog.Print( wxString::Format( "Clipper exception %s occurred.", e.what() ) );
  110. }
  111. return 0;
  112. }