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_data.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  if( !m_data->TryLock() )
61  return;
62 
63  constexpr int CROSS_SIZE = 200000;
64 
65  auto gal = aView->GetGAL();
66  gal->SetIsStroke( true );
67  gal->SetIsFill( false );
68  gal->SetLineWidth( 1.0 );
69  auto rs = aView->GetPainter()->GetSettings();
70  auto color = rs->GetColor( NULL, LAYER_RATSNEST );
71 
72  int highlightedNet = rs->GetHighlightNetCode();
73 
74  gal->SetStrokeColor( color.Brightened(0.8) );
75 
76  // Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved)
77  for( const auto& l : m_data->GetDynamicRatsnest() )
78  {
79  if ( l.a == l.b )
80  {
81  gal->DrawLine( VECTOR2I( l.a.x - CROSS_SIZE, l.a.y - CROSS_SIZE ), VECTOR2I( l.b.x + CROSS_SIZE, l.b.y + CROSS_SIZE ) );
82  gal->DrawLine( VECTOR2I( l.a.x - CROSS_SIZE, l.a.y + CROSS_SIZE ), VECTOR2I( l.b.x + CROSS_SIZE, l.b.y - CROSS_SIZE ) );
83  } else {
84  gal->DrawLine( l.a, l.b );
85  }
86  }
87 
88  for( int i = 1; i < m_data->GetNetCount(); ++i )
89  {
90  RN_NET* net = m_data->GetRatsnestForNet( i );
91 
92  if( !net )
93  continue;
94 
95  // Draw the "static" ratsnest
96  if( i != highlightedNet )
97  gal->SetStrokeColor( color ); // using the default ratsnest color for not highlighted
98 
99  for( const auto& edge : net->GetUnconnected() )
100  {
101  //if ( !edge.IsVisible() )
102  // continue;
103 
104  const auto& sourceNode = edge.GetSourceNode();
105  const auto& targetNode = edge.GetTargetNode();
106  const VECTOR2I source( sourceNode->Pos() );
107  const VECTOR2I target( targetNode->Pos() );
108 
109  bool enable = !sourceNode->GetNoLine() && !targetNode->GetNoLine();
110  bool show = sourceNode->Parent()->GetLocalRatsnestVisible() || targetNode->Parent()->GetLocalRatsnestVisible();
111 
112  if ( enable && show )
113  {
114  if ( source == target )
115  {
116  gal->DrawLine( VECTOR2I( source.x - CROSS_SIZE, source.y - CROSS_SIZE ), VECTOR2I( source.x + CROSS_SIZE, source.y + CROSS_SIZE ) );
117  gal->DrawLine( VECTOR2I( source.x - CROSS_SIZE, source.y + CROSS_SIZE ), VECTOR2I( source.x + CROSS_SIZE, source.y - CROSS_SIZE ) );
118  }
119  else
120  {
121  gal->DrawLine( source, target );
122  }
123  }
124  }
125  }
126 
127  m_data->Unlock();
128 }
129 
130 
131 void RATSNEST_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
132 {
133  aCount = 1;
134  aLayers[0] = LAYER_RATSNEST;
135 }
136 
137 }
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:57
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:80
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
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:178
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.