KiCad PCB EDA Suite
ratsnest_viewitem.cpp
Go to the documentation of this file.
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 
30 #include <ratsnest_viewitem.h>
31 #include <ratsnest_data.h>
32 #include <connectivity.h>
34 #include <pcb_painter.h>
36 
37 #include <memory>
38 
39 #include <view/view.h>
40 
41 namespace KIGFX {
42 
43 RATSNEST_VIEWITEM::RATSNEST_VIEWITEM( std::shared_ptr<CONNECTIVITY_DATA> aData ) :
44  EDA_ITEM( NOT_USED ), m_data( aData )
45 {
46 }
47 
48 
50 {
51  // Make it always visible
52  BOX2I bbox;
53  bbox.SetMaximum();
54 
55  return bbox;
56 }
57 
58 void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
59 {
60  constexpr int CROSS_SIZE = 200000;
61 
62  auto gal = aView->GetGAL();
63  gal->SetIsStroke( true );
64  gal->SetIsFill( false );
65  gal->SetLineWidth( 1.0 );
66  auto rs = aView->GetPainter()->GetSettings();
67  auto color = rs->GetColor( NULL, LAYER_RATSNEST );
68 
69  int highlightedNet = rs->GetHighlightNetCode();
70 
71  gal->SetStrokeColor( color.Brightened(0.8) );
72 
73  // Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved)
74  for( const auto& l : m_data->GetDynamicRatsnest() )
75  {
76  if ( l.a == l.b )
77  {
78  gal->DrawLine( VECTOR2I( l.a.x - CROSS_SIZE, l.a.y - CROSS_SIZE ), VECTOR2I( l.b.x + CROSS_SIZE, l.b.y + CROSS_SIZE ) );
79  gal->DrawLine( VECTOR2I( l.a.x - CROSS_SIZE, l.a.y + CROSS_SIZE ), VECTOR2I( l.b.x + CROSS_SIZE, l.b.y - CROSS_SIZE ) );
80  } else {
81  gal->DrawLine( l.a, l.b );
82  }
83  }
84 
85  for( int i = 1; i < m_data->GetNetCount(); ++i )
86  {
87  RN_NET* net = m_data->GetRatsnestForNet( i );
88 
89  if( !net )
90  continue;
91 
92  // Draw the "static" ratsnest
93  if( i != highlightedNet )
94  gal->SetStrokeColor( color ); // using the default ratsnest color for not highlighted
95 
96  for( const auto& edge : net->GetUnconnected() )
97  {
98  //if ( !edge.IsVisible() )
99  // continue;
100 
101  const auto& sourceNode = edge.GetSourceNode();
102  const auto& targetNode = edge.GetTargetNode();
103  const VECTOR2I source( sourceNode->Pos() );
104  const VECTOR2I target( targetNode->Pos() );
105 
106  bool enable = !sourceNode->GetNoLine() && !targetNode->GetNoLine();
107  bool show = sourceNode->Parent()->GetLocalRatsnestVisible() || targetNode->Parent()->GetLocalRatsnestVisible();
108 
109  if ( enable && show )
110  {
111  if ( source == target )
112  {
113  gal->DrawLine( VECTOR2I( source.x - CROSS_SIZE, source.y - CROSS_SIZE ), VECTOR2I( source.x + CROSS_SIZE, source.y + CROSS_SIZE ) );
114  gal->DrawLine( VECTOR2I( source.x - CROSS_SIZE, source.y + CROSS_SIZE ), VECTOR2I( source.x + CROSS_SIZE, source.y - CROSS_SIZE ) );
115  }
116  else
117  {
118  gal->DrawLine( source, target );
119  }
120  }
121  }
122  }
123 }
124 
125 
126 void RATSNEST_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
127 {
128  aCount = 1;
129  aLayers[0] = LAYER_RATSNEST;
130 }
131 
132 }
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers. ...
Class that draws missing connections on a PCB.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
RATSNEST_VIEWITEM(std::shared_ptr< CONNECTIVITY_DATA > aData)
std::shared_ptr< CONNECTIVITY_DATA > m_data
Object containing ratsnest data.
Class that computes missing connections on a PCB.
the 3d code uses this value
Definition: typeinfo.h:92
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
void SetMaximum()
Definition: box2.h:61
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
const std::vector< CN_EDGE > GetUnconnected() const
Function GetUnconnected() Returns pointer to a vector of edges that makes ratsnest for a given net...
Definition: ratsnest_data.h:98
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on...
Board layer functions and definitions.
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
Function ViewDraw() Draws the parts of the object belonging to layer aLayer.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
Class RN_NET Describes ratsnest for a single net.
Definition: ratsnest_data.h:59
Class VIEW.
Definition: view.h:58
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.