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>
|
2017-11-15 17:33:06 +00:00
|
|
|
#include <connectivity_data.h>
|
2013-11-25 15:50:03 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2014-01-31 10:16:01 +00:00
|
|
|
#include <pcb_painter.h>
|
2013-11-25 15:50:03 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
#include <memory>
|
2017-09-23 09:20:10 +00:00
|
|
|
#include <utility>
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2016-05-28 16:57:19 +00:00
|
|
|
namespace KIGFX {
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
RATSNEST_VIEWITEM::RATSNEST_VIEWITEM( std::shared_ptr<CONNECTIVITY_DATA> aData ) :
|
2017-09-23 09:20:10 +00:00
|
|
|
EDA_ITEM( NOT_USED ), m_data( std::move(aData) )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const BOX2I RATSNEST_VIEWITEM::ViewBBox() const
|
|
|
|
{
|
|
|
|
// Make it always visible
|
|
|
|
BOX2I bbox;
|
|
|
|
bbox.SetMaximum();
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2017-12-14 22:49:46 +00:00
|
|
|
if( !m_data->TryLock() )
|
|
|
|
return;
|
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
constexpr int CROSS_SIZE = 200000;
|
2017-03-22 13:43:10 +00:00
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
auto gal = aView->GetGAL();
|
2017-03-22 13:43:10 +00:00
|
|
|
gal->SetIsStroke( true );
|
2016-12-02 17:58:12 +00:00
|
|
|
gal->SetIsFill( false );
|
|
|
|
gal->SetLineWidth( 1.0 );
|
|
|
|
auto rs = aView->GetPainter()->GetSettings();
|
2017-03-13 03:19:33 +00:00
|
|
|
auto color = rs->GetColor( NULL, LAYER_RATSNEST );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
int highlightedNet = rs->GetHighlightNetCode();
|
2014-01-29 14:24:19 +00:00
|
|
|
|
2017-12-18 13:58:06 +00:00
|
|
|
gal->SetStrokeColor( color.Brightened(0.5) );
|
2014-01-31 10:16:01 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
// Draw the "dynamic" ratsnest (i.e. for objects that may be currently being moved)
|
|
|
|
for( const auto& l : m_data->GetDynamicRatsnest() )
|
|
|
|
{
|
|
|
|
if ( l.a == l.b )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
gal->DrawLine( VECTOR2I( l.a.x - CROSS_SIZE, l.a.y - CROSS_SIZE ), VECTOR2I( l.b.x + CROSS_SIZE, l.b.y + CROSS_SIZE ) );
|
|
|
|
gal->DrawLine( VECTOR2I( l.a.x - CROSS_SIZE, l.a.y + CROSS_SIZE ), VECTOR2I( l.b.x + CROSS_SIZE, l.b.y - CROSS_SIZE ) );
|
2017-03-22 13:43:10 +00:00
|
|
|
} else {
|
|
|
|
gal->DrawLine( l.a, l.b );
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
for( int i = 1; i < m_data->GetNetCount(); ++i )
|
|
|
|
{
|
|
|
|
RN_NET* net = m_data->GetRatsnestForNet( i );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2017-06-29 22:45:50 +00:00
|
|
|
if( !net )
|
|
|
|
continue;
|
|
|
|
|
2013-11-25 15:50:03 +00:00
|
|
|
// Draw the "static" ratsnest
|
2014-05-13 09:22:51 +00:00
|
|
|
if( i != highlightedNet )
|
2016-12-02 17:58:12 +00:00
|
|
|
gal->SetStrokeColor( color ); // using the default ratsnest color for not highlighted
|
2017-12-18 13:58:06 +00:00
|
|
|
else
|
|
|
|
gal->SetStrokeColor( color.Brightened(0.8) );
|
2014-01-31 10:16:01 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
for( const auto& edge : net->GetUnconnected() )
|
2013-11-25 15:50:03 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
//if ( !edge.IsVisible() )
|
|
|
|
// continue;
|
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
const auto& sourceNode = edge.GetSourceNode();
|
|
|
|
const auto& targetNode = edge.GetTargetNode();
|
|
|
|
const VECTOR2I source( sourceNode->Pos() );
|
|
|
|
const VECTOR2I target( targetNode->Pos() );
|
2013-11-25 15:50:03 +00:00
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
bool enable = !sourceNode->GetNoLine() && !targetNode->GetNoLine();
|
|
|
|
bool show = sourceNode->Parent()->GetLocalRatsnestVisible() || targetNode->Parent()->GetLocalRatsnestVisible();
|
|
|
|
|
|
|
|
if ( enable && show )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
|
|
|
if ( source == target )
|
|
|
|
{
|
|
|
|
gal->DrawLine( VECTOR2I( source.x - CROSS_SIZE, source.y - CROSS_SIZE ), VECTOR2I( source.x + CROSS_SIZE, source.y + CROSS_SIZE ) );
|
|
|
|
gal->DrawLine( VECTOR2I( source.x - CROSS_SIZE, source.y + CROSS_SIZE ), VECTOR2I( source.x + CROSS_SIZE, source.y - CROSS_SIZE ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gal->DrawLine( source, target );
|
|
|
|
}
|
|
|
|
}
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-14 22:49:46 +00:00
|
|
|
|
|
|
|
m_data->Unlock();
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RATSNEST_VIEWITEM::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
aCount = 1;
|
2017-03-13 03:19:33 +00:00
|
|
|
aLayers[0] = LAYER_RATSNEST;
|
2013-11-25 15:50:03 +00:00
|
|
|
}
|
2016-05-28 16:57:19 +00:00
|
|
|
|
|
|
|
}
|