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.

208 lines
5.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /*
  2. * KiRouter - a push-and-(sometimes-)shove PCB router
  3. *
  4. * Copyright (C) 2013-2014 CERN
  5. * Copyright (C) 2016 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 "pns_line.h"
  25. #include "pns_segment.h"
  26. #include "pns_solid.h"
  27. #include <geometry/shape.h>
  28. #include <geometry/shape_line_chain.h>
  29. #include <geometry/shape_rect.h>
  30. #include <geometry/shape_circle.h>
  31. #include "../../include/geometry/shape_simple.h"
  32. namespace PNS {
  33. LOGGER::LOGGER( )
  34. {
  35. m_groupOpened = false;
  36. }
  37. LOGGER::~LOGGER()
  38. {
  39. }
  40. void LOGGER::Clear()
  41. {
  42. m_theLog.str( std::string() );
  43. m_groupOpened = false;
  44. }
  45. void LOGGER::NewGroup( const std::string& aName, int aIter )
  46. {
  47. if( m_groupOpened )
  48. m_theLog << "endgroup" << std::endl;
  49. m_theLog << "group " << aName << " " << aIter << std::endl;
  50. m_groupOpened = true;
  51. }
  52. void LOGGER::EndGroup()
  53. {
  54. if( !m_groupOpened )
  55. return;
  56. m_groupOpened = false;
  57. m_theLog << "endgroup" << std::endl;
  58. }
  59. void LOGGER::Log ( const ITEM* aItem, int aKind, const std::string& aName )
  60. {
  61. m_theLog << "item " << aKind << " " << aName << " ";
  62. m_theLog << aItem->Net() << " " << aItem->Layers().Start() << " " <<
  63. aItem->Layers().End() << " " << aItem->Marker() << " " << aItem->Rank();
  64. switch( aItem->Kind() )
  65. {
  66. case ITEM::LINE_T:
  67. {
  68. LINE* l = (LINE*) aItem;
  69. m_theLog << " line ";
  70. m_theLog << l->Width() << " " << ( l->EndsWithVia() ? 1 : 0 ) << " ";
  71. dumpShape ( l->Shape() );
  72. m_theLog << std::endl;
  73. break;
  74. }
  75. case ITEM::VIA_T:
  76. {
  77. m_theLog << " via 0 0 ";
  78. dumpShape ( aItem->Shape() );
  79. m_theLog << std::endl;
  80. break;
  81. }
  82. case ITEM::SEGMENT_T:
  83. {
  84. SEGMENT* s =(SEGMENT*) aItem;
  85. m_theLog << " line ";
  86. m_theLog << s->Width() << " 0 linechain 2 0 " << s->Seg().A.x << " " <<
  87. s->Seg().A.y << " " << s->Seg().B.x << " " <<s->Seg().B.y << std::endl;
  88. break;
  89. }
  90. case ITEM::SOLID_T:
  91. {
  92. SOLID* s = (SOLID*) aItem;
  93. m_theLog << " solid 0 0 ";
  94. dumpShape( s->Shape() );
  95. m_theLog << std::endl;
  96. break;
  97. }
  98. default:
  99. break;
  100. }
  101. }
  102. void LOGGER::Log( const SHAPE_LINE_CHAIN *aL, int aKind, const std::string& aName )
  103. {
  104. m_theLog << "item " << aKind << " " << aName << " ";
  105. m_theLog << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0;
  106. m_theLog << " line ";
  107. m_theLog << 0 << " " << 0 << " ";
  108. dumpShape( aL );
  109. m_theLog << std::endl;
  110. }
  111. void LOGGER::Log( const VECTOR2I& aStart, const VECTOR2I& aEnd,
  112. int aKind, const std::string& aName)
  113. {
  114. }
  115. void LOGGER::dumpShape( const SHAPE* aSh )
  116. {
  117. switch( aSh->Type() )
  118. {
  119. case SH_LINE_CHAIN:
  120. {
  121. const SHAPE_LINE_CHAIN* lc = (const SHAPE_LINE_CHAIN*) aSh;
  122. m_theLog << "linechain " << lc->PointCount() << " " << ( lc->IsClosed() ? 1 : 0 ) << " ";
  123. for( int i = 0; i < lc->PointCount(); i++ )
  124. m_theLog << lc->CPoint( i ).x << " " << lc->CPoint( i ).y << " ";
  125. break;
  126. }
  127. case SH_CIRCLE:
  128. {
  129. const SHAPE_CIRCLE *c = (const SHAPE_CIRCLE*) aSh;
  130. m_theLog << "circle " << c->GetCenter().x << " " << c->GetCenter().y << " " << c->GetRadius();
  131. break;
  132. }
  133. case SH_RECT:
  134. {
  135. const SHAPE_RECT* r = (const SHAPE_RECT*) aSh;
  136. m_theLog << "rect " << r->GetPosition().x << " " << r->GetPosition().y << " " <<
  137. r->GetSize().x << " " <<r->GetSize().y;
  138. break;
  139. }
  140. case SH_SEGMENT:
  141. {
  142. const SHAPE_SEGMENT* s = (const SHAPE_SEGMENT*) aSh;
  143. m_theLog << "linechain 2 0 " << s->GetSeg().A.x << " " << s->GetSeg().A.y << " " <<
  144. s->GetSeg().B.x << " " << s->GetSeg().B.y;
  145. break;
  146. }
  147. case SH_SIMPLE:
  148. {
  149. const SHAPE_SIMPLE* c = (const SHAPE_SIMPLE*) aSh;
  150. m_theLog << "convex " << c->PointCount() << " ";
  151. for( int i = 0; i < c->PointCount(); i++ )
  152. m_theLog << c->CPoint( i ).x << " " << c->CPoint( i ).y << " ";
  153. break;
  154. }
  155. default:
  156. break;
  157. }
  158. }
  159. void LOGGER::Save( const std::string& aFilename )
  160. {
  161. EndGroup();
  162. FILE* f = fopen( aFilename.c_str(), "wb" );
  163. wxLogTrace( "PNS", "Saving to '%s' [%p]", aFilename.c_str(), f );
  164. const std::string s = m_theLog.str();
  165. fwrite( s.c_str(), 1, s.length(), f );
  166. fclose( f );
  167. }
  168. }