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.

120 lines
3.7 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  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 ratsnest_viewitem.cpp
  26. * @brief Class that draws missing connections on a PCB.
  27. */
  28. #include <ratsnest_viewitem.h>
  29. #include <ratsnest_data.h>
  30. #include <gal/graphics_abstraction_layer.h>
  31. #include <pcb_painter.h>
  32. #include <layers_id_colors_and_visibility.h>
  33. #include <boost/foreach.hpp>
  34. using namespace KIGFX;
  35. RATSNEST_VIEWITEM::RATSNEST_VIEWITEM( RN_DATA* aData ) :
  36. EDA_ITEM( NOT_USED ), m_data( aData )
  37. {
  38. }
  39. const BOX2I RATSNEST_VIEWITEM::ViewBBox() const
  40. {
  41. // Make it always visible
  42. BOX2I bbox;
  43. bbox.SetMaximum();
  44. return bbox;
  45. }
  46. void RATSNEST_VIEWITEM::ViewDraw( int aLayer, GAL* aGal ) const
  47. {
  48. aGal->SetIsStroke( true );
  49. aGal->SetIsFill( false );
  50. aGal->SetLineWidth( 1.0 );
  51. RENDER_SETTINGS* rs = m_view->GetPainter()->GetSettings();
  52. COLOR4D color = rs->GetColor( NULL, ITEM_GAL_LAYER( RATSNEST_VISIBLE ) );
  53. int highlightedNet = rs->GetHighlightNetCode();
  54. // Dynamic ratsnest (for e.g. dragged items)
  55. for( int i = 1; i < m_data->GetNetCount(); ++i )
  56. {
  57. RN_NET& net = m_data->GetNet( i );
  58. if( !net.IsVisible() )
  59. continue;
  60. // Set brighter color for the temporary ratsnest
  61. aGal->SetStrokeColor( color.Brightened( 0.8 ) );
  62. // Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved)
  63. BOOST_FOREACH( const RN_NODE_PTR& node, net.GetSimpleNodes() )
  64. {
  65. // Skipping nodes with higher reference count avoids displaying redundant lines
  66. if( node->GetRefCount() > 1 )
  67. continue;
  68. RN_NODE_PTR dest = net.GetClosestNode( node, WITHOUT_FLAG() );
  69. if( dest )
  70. {
  71. VECTOR2D origin( node->GetX(), node->GetY() );
  72. VECTOR2D end( dest->GetX(), dest->GetY() );
  73. aGal->DrawLine( origin, end );
  74. }
  75. }
  76. // Draw the "static" ratsnest
  77. if( i != highlightedNet )
  78. aGal->SetStrokeColor( color ); // using the default ratsnest color for not highlighted
  79. const std::vector<RN_EDGE_MST_PTR>* edges = net.GetUnconnected();
  80. if( edges == NULL )
  81. continue;
  82. BOOST_FOREACH( const RN_EDGE_MST_PTR& edge, *edges )
  83. {
  84. const RN_NODE_PTR& sourceNode = edge->GetSourceNode();
  85. const RN_NODE_PTR& targetNode = edge->GetTargetNode();
  86. VECTOR2D source( sourceNode->GetX(), sourceNode->GetY() );
  87. VECTOR2D target( targetNode->GetX(), targetNode->GetY() );
  88. aGal->DrawLine( source, target );
  89. }
  90. }
  91. }
  92. void RATSNEST_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
  93. {
  94. aCount = 1;
  95. aLayers[0] = ITEM_GAL_LAYER( RATSNEST_VISIBLE );
  96. }