kicad/pcbnew/ratsnest_viewitem.cpp

124 lines
3.7 KiB
C++
Raw Normal View History

2013-11-25 15:50:03 +00:00
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file ratsnest_viewitem.cpp
* @brief Class that draws missing connections on a PCB.
*/
#include <ratsnest_viewitem.h>
#include <ratsnest_data.h>
#include <gal/graphics_abstraction_layer.h>
#include <pcb_painter.h>
2013-11-25 15:50:03 +00:00
#include <layers_id_colors_and_visibility.h>
#include <view/view.h>
2013-11-25 15:50:03 +00:00
namespace KIGFX {
2013-11-25 15:50:03 +00:00
RATSNEST_VIEWITEM::RATSNEST_VIEWITEM( RN_DATA* aData ) :
EDA_ITEM( NOT_USED ), m_data( aData )
{
}
const BOX2I RATSNEST_VIEWITEM::ViewBBox() const
{
// Make it always visible
BOX2I bbox;
bbox.SetMaximum();
return bbox;
}
void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
2013-11-25 15:50:03 +00:00
{
auto gal = aView->GetGAL();
gal->SetIsStroke( true );
gal->SetIsFill( false );
gal->SetLineWidth( 1.0 );
auto rs = aView->GetPainter()->GetSettings();
auto color = rs->GetColor( NULL, LAYER_RATSNEST );
int highlightedNet = rs->GetHighlightNetCode();
2013-11-25 15:50:03 +00:00
// Dynamic ratsnest (for e.g. dragged items)
for( int i = 1; i < m_data->GetNetCount(); ++i )
2013-11-25 15:50:03 +00:00
{
RN_NET& net = m_data->GetNet( i );
2013-11-25 15:50:03 +00:00
if( !net.IsVisible() )
continue;
// Set brighter color for the temporary ratsnest
gal->SetStrokeColor( color.Brightened( 0.8 ) );
// Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved)
for( const RN_NODE_PTR& node : net.GetSimpleNodes() )
2013-11-25 15:50:03 +00:00
{
// Skipping nodes with higher reference count avoids displaying redundant lines
if( node->GetRefCount() > 1 )
continue;
RN_NODE_PTR dest = net.GetClosestNode( node, LINE_TARGET() );
2013-11-25 15:50:03 +00:00
if( dest )
2013-11-25 15:50:03 +00:00
{
VECTOR2D origin( node->GetX(), node->GetY() );
VECTOR2D end( dest->GetX(), dest->GetY() );
gal->DrawLine( origin, end );
2013-11-25 15:50:03 +00:00
}
}
// Draw the "static" ratsnest
if( i != highlightedNet )
gal->SetStrokeColor( color ); // using the default ratsnest color for not highlighted
const std::vector<RN_EDGE_MST_PTR>* edges = net.GetUnconnected();
2013-11-25 15:50:03 +00:00
if( edges == NULL )
continue;
for( const RN_EDGE_MST_PTR& edge : *edges )
2013-11-25 15:50:03 +00:00
{
const RN_NODE_PTR& sourceNode = edge->GetSourceNode();
const RN_NODE_PTR& targetNode = edge->GetTargetNode();
VECTOR2D source( sourceNode->GetX(), sourceNode->GetY() );
2013-11-25 15:50:03 +00:00
VECTOR2D target( targetNode->GetX(), targetNode->GetY() );
gal->DrawLine( source, target );
2013-11-25 15:50:03 +00:00
}
}
}
void RATSNEST_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 1;
aLayers[0] = LAYER_RATSNEST;
2013-11-25 15:50:03 +00:00
}
}