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.

150 lines
4.1 KiB

10 years ago
10 years ago
10 years ago
  1. /*
  2. * KiRouter - a push-and-(sometimes-)shove PCB router
  3. *
  4. * Copyright (C) 2013-2014 CERN
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  7. *
  8. * This program is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, either version 3 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "pns_logger.h"
  22. #include "pns_item.h"
  23. #include "pns_via.h"
  24. #include <wx/log.h>
  25. namespace PNS {
  26. LOGGER::LOGGER( )
  27. {
  28. }
  29. LOGGER::~LOGGER()
  30. {
  31. }
  32. void LOGGER::Clear()
  33. {
  34. m_events.clear();
  35. }
  36. void LOGGER::LogM( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, std::vector<ITEM*> items,
  37. const SIZES_SETTINGS* sizes, int aLayer )
  38. {
  39. LOGGER::EVENT_ENTRY ent;
  40. ent.type = evt;
  41. ent.p = pos;
  42. ent.layer = aLayer;
  43. if( sizes )
  44. {
  45. ent.sizes = *sizes;
  46. }
  47. for( auto& item : items )
  48. {
  49. if( item && item->Parent() )
  50. ent.uuids.push_back( item->Parent()->m_Uuid );
  51. }
  52. m_events.push_back( ent );
  53. }
  54. void LOGGER::Log( LOGGER::EVENT_TYPE evt, const VECTOR2I& pos, const ITEM* item,
  55. const SIZES_SETTINGS* sizes, int aLayer )
  56. {
  57. std::vector<ITEM*> items;
  58. items.push_back( const_cast<ITEM*>( item ) );
  59. LogM( evt, pos, items, sizes, aLayer );
  60. }
  61. wxString LOGGER::FormatLogFileAsString( int aMode,
  62. const std::vector<ITEM*>& aAddedItems,
  63. const std::set<KIID>& aRemovedItems,
  64. const std::vector<ITEM*>& aHeads,
  65. const std::vector<LOGGER::EVENT_ENTRY>& aEvents )
  66. {
  67. wxString result = wxString::Format( "mode %d\n", aMode );
  68. for( const EVENT_ENTRY& evt : aEvents )
  69. result += PNS::LOGGER::FormatEvent( evt );
  70. for( const KIID& uuid : aRemovedItems )
  71. result += wxString::Format( "removed %s\n", uuid.AsString().c_str() );
  72. for( ITEM* item : aAddedItems )
  73. result += wxString::Format( "added %s\n", item->Format().c_str() );
  74. for( ITEM* item : aHeads )
  75. result += wxString::Format( "head %s\n", item->Format().c_str() );
  76. return result;
  77. }
  78. wxString LOGGER::FormatEvent( const LOGGER::EVENT_ENTRY& aEvent )
  79. {
  80. wxString str = wxString::Format( "event %d %d %d %d %d ", aEvent.p.x, aEvent.p.y, aEvent.type, aEvent.layer, (int)aEvent.uuids.size() );
  81. for( int i = 0; i < aEvent.uuids.size(); i++ )
  82. {
  83. str.Append( aEvent.uuids[i].AsString() );
  84. str.Append( wxT(" ") );
  85. }
  86. str.Append( wxString::Format( "%d %d %d %d %d %d %d",
  87. aEvent.sizes.TrackWidth(),
  88. aEvent.sizes.ViaDiameter(),
  89. aEvent.sizes.ViaDrill(),
  90. aEvent.sizes.TrackWidthIsExplicit() ? 1 : 0,
  91. aEvent.sizes.GetLayerBottom(),
  92. aEvent.sizes.GetLayerTop(),
  93. static_cast<int>( aEvent.sizes.ViaType() ) ) );
  94. str.Append( wxT("\n") );
  95. return str;
  96. }
  97. LOGGER::EVENT_ENTRY LOGGER::ParseEvent( const wxString& aLine )
  98. {
  99. wxStringTokenizer tokens( aLine );
  100. wxString cmd = tokens.GetNextToken();
  101. int n_uuids = 0;
  102. wxCHECK_MSG( cmd == wxT( "event" ), EVENT_ENTRY(), "Line doesn't contain an event!" );
  103. EVENT_ENTRY evt;
  104. evt.p.x = wxAtoi( tokens.GetNextToken() );
  105. evt.p.y = wxAtoi( tokens.GetNextToken() );
  106. evt.type = (PNS::LOGGER::EVENT_TYPE) wxAtoi( tokens.GetNextToken() );
  107. evt.layer = wxAtoi( tokens.GetNextToken() );
  108. n_uuids = wxAtoi( tokens.GetNextToken() );
  109. for( int i = 0; i < n_uuids; i++)
  110. evt.uuids.push_back( KIID( tokens.GetNextToken() ) );
  111. return evt;
  112. }
  113. }