2016-11-16 12:09:34 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 highlight_connection.cpp
|
|
|
|
* @brief This file contains basic functions related to the command to
|
|
|
|
* highlight a connection (wires and labels) in a schematic
|
|
|
|
* (that can be a simple or a complex hierarchy)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
2018-10-11 12:17:01 +00:00
|
|
|
#include <sch_view.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2019-03-08 00:16:59 +00:00
|
|
|
#include <sch_component.h>
|
2016-11-16 12:09:34 +00:00
|
|
|
#include <erc.h>
|
|
|
|
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <netlist_object.h>
|
2019-03-11 21:32:05 +00:00
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_sheet.h>
|
2016-11-16 12:09:34 +00:00
|
|
|
|
2018-12-04 19:55:59 +00:00
|
|
|
// List of items having the highlight option modified, therefore need to be redrawn
|
2016-11-16 12:09:34 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
// TODO(JE) Probably use netcode rather than connection name here eventually
|
2016-11-16 12:09:34 +00:00
|
|
|
bool SCH_EDIT_FRAME::HighlightConnectionAtPosition( wxPoint aPosition )
|
|
|
|
{
|
2018-12-04 19:55:59 +00:00
|
|
|
std::vector<EDA_ITEM*> itemsToRedraw;
|
2016-11-16 12:09:34 +00:00
|
|
|
m_SelectedNetName = "";
|
|
|
|
bool buildNetlistOk = false;
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
SetStatusText( "" );
|
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
// find which connected item is selected
|
|
|
|
EDA_ITEMS nodeList;
|
|
|
|
wxPoint gridPosition = GetGridPosition( aPosition );
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
if( GetScreen()->GetNode( gridPosition, nodeList ) )
|
2016-11-16 12:09:34 +00:00
|
|
|
{
|
|
|
|
if( TestDuplicateSheetNames( false ) > 0 )
|
|
|
|
wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet. Fix it" ) );
|
|
|
|
else
|
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
if( auto item = dynamic_cast<SCH_ITEM*>( nodeList[0] ) )
|
2016-11-16 12:09:34 +00:00
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
if( item->Connection( *g_CurrentSheet ) )
|
2016-11-16 12:09:34 +00:00
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
m_SelectedNetName = item->Connection( *g_CurrentSheet )->Name();
|
|
|
|
SetStatusText( _( "Highlighted net: " ) + m_SelectedNetName );
|
2016-11-16 12:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-06 20:50:49 +00:00
|
|
|
SendCrossProbeNetName( m_SelectedNetName );
|
2019-03-11 21:32:05 +00:00
|
|
|
SetStatusText( _( "Selected net: " ) + m_SelectedNetName );
|
2018-12-04 19:55:59 +00:00
|
|
|
SetCurrentSheetHighlightFlags( &itemsToRedraw );
|
2016-11-16 12:09:34 +00:00
|
|
|
|
2018-12-04 19:55:59 +00:00
|
|
|
// Be sure hightlight change will be redrawn
|
|
|
|
KIGFX::VIEW* view = GetGalCanvas()->GetView();
|
|
|
|
|
|
|
|
for( auto item : itemsToRedraw )
|
|
|
|
view->Update( (KIGFX::VIEW_ITEM*)item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
|
|
|
|
|
|
|
|
//view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
|
|
|
|
GetGalCanvas()->Refresh();
|
2016-11-16 12:09:34 +00:00
|
|
|
return buildNetlistOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-04 19:55:59 +00:00
|
|
|
bool SCH_EDIT_FRAME::SetCurrentSheetHighlightFlags( std::vector<EDA_ITEM*>* aItemsToRedrawList )
|
2016-11-16 12:09:34 +00:00
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
SCH_SCREEN* screen = g_CurrentSheet->LastScreen();
|
2016-11-16 12:09:34 +00:00
|
|
|
|
2018-12-08 15:53:16 +00:00
|
|
|
if( !screen )
|
|
|
|
return true;
|
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() )
|
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
auto conn = ptr->Connection( *g_CurrentSheet );
|
2019-03-08 00:16:59 +00:00
|
|
|
bool redraw = ptr->GetState( BRIGHTENED );
|
2018-12-04 19:55:59 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
ptr->SetState( BRIGHTENED, ( conn && conn->Name() == m_SelectedNetName ) );
|
2016-11-16 12:09:34 +00:00
|
|
|
|
2019-03-08 00:16:59 +00:00
|
|
|
redraw |= ptr->GetState( BRIGHTENED );
|
|
|
|
|
|
|
|
if( ptr->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( ptr );
|
|
|
|
|
|
|
|
redraw |= comp->HasBrightenedPins();
|
|
|
|
|
|
|
|
comp->ClearBrightenedPins();
|
|
|
|
std::vector<LIB_PIN*> pins;
|
|
|
|
comp->GetPins( pins );
|
|
|
|
|
|
|
|
for( LIB_PIN* pin : pins )
|
|
|
|
{
|
|
|
|
auto pin_conn = comp->GetConnectionForPin( pin, *g_CurrentSheet );
|
2018-12-04 19:55:59 +00:00
|
|
|
|
2019-03-08 00:16:59 +00:00
|
|
|
if( pin_conn && pin_conn->Name( false, true ) == m_SelectedNetName )
|
|
|
|
{
|
|
|
|
comp->BrightenPin( pin );
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( ptr->Type() == SCH_SHEET_T )
|
2016-11-16 12:09:34 +00:00
|
|
|
{
|
|
|
|
for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() )
|
2018-12-04 19:55:59 +00:00
|
|
|
{
|
2019-03-11 21:32:05 +00:00
|
|
|
auto pin_conn = pin.Connection( *g_CurrentSheet );
|
2019-03-08 00:16:59 +00:00
|
|
|
bool redrawPin = pin.GetState( BRIGHTENED );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-03-08 00:16:59 +00:00
|
|
|
pin.SetState( BRIGHTENED, ( pin_conn && pin_conn->Name() == m_SelectedNetName ) );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-03-08 00:16:59 +00:00
|
|
|
redrawPin |= pin.GetState( BRIGHTENED );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2019-03-08 00:16:59 +00:00
|
|
|
if( redrawPin && aItemsToRedrawList )
|
2019-03-11 21:32:05 +00:00
|
|
|
aItemsToRedrawList->push_back( &pin );
|
2018-12-04 19:55:59 +00:00
|
|
|
}
|
2016-11-16 12:09:34 +00:00
|
|
|
}
|
2019-03-08 00:16:59 +00:00
|
|
|
|
|
|
|
if( redraw && aItemsToRedrawList )
|
|
|
|
aItemsToRedrawList->push_back( ptr );
|
2016-11-16 12:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_SelectedNetName == "" )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( TestDuplicateSheetNames( false ) > 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|