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>
|
2016-11-16 12:09:34 +00:00
|
|
|
#include <erc.h>
|
|
|
|
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <netlist_object.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
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// find which connected item is selected
|
|
|
|
EDA_ITEMS nodeList;
|
|
|
|
wxPoint gridPosition = GetGridPosition( aPosition );
|
|
|
|
|
|
|
|
if( GetScreen()->GetNode( gridPosition,nodeList ) )
|
|
|
|
{
|
|
|
|
if( TestDuplicateSheetNames( false ) > 0 )
|
|
|
|
wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet. Fix it" ) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Build netlist info to get the proper netnames of connected items
|
|
|
|
std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase() );
|
|
|
|
buildNetlistOk = true;
|
|
|
|
|
|
|
|
for( auto obj : *objectsConnectedList )
|
|
|
|
{
|
|
|
|
if( obj->m_SheetPath == *m_CurrentSheet && obj->m_Comp == nodeList[0] )
|
|
|
|
{
|
|
|
|
m_SelectedNetName = obj->GetNetName( true );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-06 20:50:49 +00:00
|
|
|
SendCrossProbeNetName( m_SelectedNetName );
|
2016-11-16 12:09:34 +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
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = m_CurrentSheet->LastScreen();
|
|
|
|
|
2018-12-08 15:53:16 +00:00
|
|
|
if( !screen )
|
|
|
|
return true;
|
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
// Disable highlight flag on all items in the current screen
|
|
|
|
for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() )
|
|
|
|
{
|
2018-12-04 19:55:59 +00:00
|
|
|
if( ptr->GetState( BRIGHTENED ) && aItemsToRedrawList )
|
|
|
|
aItemsToRedrawList->push_back( ptr );
|
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
ptr->SetState( BRIGHTENED, false );
|
|
|
|
|
2018-12-04 19:55:59 +00:00
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
if( ptr->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() )
|
2018-12-04 19:55:59 +00:00
|
|
|
{
|
|
|
|
if( ptr->GetState( BRIGHTENED ) && aItemsToRedrawList )
|
|
|
|
aItemsToRedrawList->push_back( &pin );
|
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
pin.SetState( BRIGHTENED, false );
|
2018-12-04 19:55:59 +00:00
|
|
|
}
|
2016-11-16 12:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_SelectedNetName == "" )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( TestDuplicateSheetNames( false ) > 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Build netlist info to get the proper netnames
|
|
|
|
std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase( false ) );
|
|
|
|
|
|
|
|
// highlight the items belonging to this net
|
|
|
|
for( auto obj1 : *objectsConnectedList )
|
|
|
|
{
|
|
|
|
if( obj1->m_SheetPath == *m_CurrentSheet &&
|
|
|
|
obj1->GetNetName( true ) == m_SelectedNetName && obj1->m_Comp )
|
|
|
|
{
|
|
|
|
obj1->m_Comp->SetState( BRIGHTENED, true );
|
|
|
|
|
2018-12-04 19:55:59 +00:00
|
|
|
if( aItemsToRedrawList )
|
|
|
|
aItemsToRedrawList->push_back( obj1->m_Comp );
|
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
//if a bus is associated with this net highlight it as well
|
|
|
|
if( obj1->m_BusNetCode )
|
|
|
|
{
|
|
|
|
for( auto obj2 : *objectsConnectedList )
|
|
|
|
{
|
|
|
|
if( obj2 && obj2->m_Comp && obj2->m_SheetPath == *m_CurrentSheet &&
|
|
|
|
obj1->m_BusNetCode == obj2->m_BusNetCode )
|
2018-12-04 19:55:59 +00:00
|
|
|
{
|
|
|
|
if( aItemsToRedrawList )
|
|
|
|
aItemsToRedrawList->push_back( obj2->m_Comp );
|
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
obj2->m_Comp->SetState( BRIGHTENED, true );
|
2018-12-04 19:55:59 +00:00
|
|
|
}
|
2016-11-16 12:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|