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 #include <utility>
39 
40 #include <view/view.h>
41 
42 namespace KIGFX {
43 
44 RATSNEST_VIEWITEM::RATSNEST_VIEWITEM( std::shared_ptr<CONNECTIVITY_DATA> aData ) :
45  EDA_ITEM( NOT_USED ), m_data( std::move(aData) )
46 {
47 }
48 
49 
51 {
52  // Make it always visible
53  BOX2I bbox;
54  bbox.SetMaximum();
55 
56  return bbox;
57 }
58 
59 void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
60 {
61  if( !m_data->TryLock() )
62  return;
63 
64  constexpr int CROSS_SIZE = 200000;
65 
66  auto gal = aView->GetGAL();
67  gal->SetIsStroke( true );
68  gal->SetIsFill( false );
69  gal->SetLineWidth( 1.0 );
70  auto rs = aView->GetPainter()->GetSettings();
71  auto color = rs->GetColor( NULL, LAYER_RATSNEST );
72 
73  int highlightedNet = rs->GetHighlightNetCode();
74 
75  gal->SetStrokeColor( color.Brightened(0.5) );
76 
77  // Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved)
78  for( const auto& l : m_data->GetDynamicRatsnest() )
79  {
80  if ( l.a == l.b )
81  {
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  gal->DrawLine( VECTOR2I( l.a.x - CROSS_SIZE, l.a.y + CROSS_SIZE ), VECTOR2I( l.b.x + CROSS_SIZE, l.b.y - CROSS_SIZE ) );
84  } else {
85  gal->DrawLine( l.a, l.b );
86  }
87  }
88 
89  for( int i = 1; i < m_data->GetNetCount(); ++i )
90  {
91  RN_NET* net = m_data->GetRatsnestForNet( i );
92 
93  if( !net )
94  continue;
95 
96  // Draw the "static" ratsnest
97  if( i != highlightedNet )
98  gal->SetStrokeColor( color ); // using the default ratsnest color for not highlighted
99  else
100  gal->SetStrokeColor( color.Brightened(0.8) );
101 
102  for( const auto& edge : net->GetUnconnected() )
103  {
104  //if ( !edge.IsVisible() )
105  // continue;
106 
107  const auto& sourceNode = edge.GetSourceNode();
108  const auto& targetNode = edge.GetTargetNode();
109  const VECTOR2I source( sourceNode->Pos() );
110  const VECTOR2I target( targetNode->Pos() );
111 
112  bool enable = !sourceNode->GetNoLine() && !targetNode->GetNoLine();
113  bool show = sourceNode->Parent()->GetLocalRatsnestVisible() || targetNode->Parent()->GetLocalRatsnestVisible();
114 
115  if ( enable && show )
116  {
117  if ( source == target )
118  {
119  gal->DrawLine( VECTOR2I( source.x - CROSS_SIZE, source.y - CROSS_SIZE ), VECTOR2I( source.x + CROSS_SIZE, source.y + CROSS_SIZE ) );
120  gal->DrawLine( VECTOR2I( source.x - CROSS_SIZE, source.y + CROSS_SIZE ), VECTOR2I( source.x + CROSS_SIZE, source.y - CROSS_SIZE ) );
121  }
122  else
123  {
124  gal->DrawLine( source, target );
125  }
126  }
127  }
128  }
129 
130  m_data->Unlock();
131 }
132 
133 
134 void RATSNEST_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
135 {
136  aCount = 1;
137  aLayers[0] = LAYER_RATSNEST;
138 }
139 
140 }
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:80
int color
Definition: DXF_plotter.cpp:62
Template specialization to enable wxStrings for certain containers (e.g. unordered_map) ...
Definition: bitmap.cpp:54
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.
size_t i
Definition: json11.cpp:597
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
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.