Add connection highlight to eeschema, step 1.

This commit is contained in:
Nox_firegalaxy 2016-11-16 11:07:02 +01:00 committed by jean-pierre charras
parent d3af42d5de
commit 44b8533d4d
17 changed files with 118 additions and 16 deletions

View File

@ -345,7 +345,7 @@ bool NETLIST_OBJECT::IsLabelBusMemberType() const
/*
* return the net name of the item
*/
wxString NETLIST_OBJECT::GetNetName() const
wxString NETLIST_OBJECT::GetNetName( bool adoptTimestamp ) const
{
if( m_netNameCandidate == NULL )
return wxEmptyString;
@ -353,7 +353,7 @@ wxString NETLIST_OBJECT::GetNetName() const
wxString netName;
if( m_netNameCandidate->m_Type == NET_PIN )
return GetShortNetName();
return GetShortNetName( adoptTimestamp );
if( !m_netNameCandidate->IsLabelGlobal() )
{
@ -371,7 +371,7 @@ wxString NETLIST_OBJECT::GetNetName() const
* from the "best" label without any prefix.
* 2 different nets can have the same short name
*/
wxString NETLIST_OBJECT::GetShortNetName() const
wxString NETLIST_OBJECT::GetShortNetName( bool adoptTimestamp ) const
{
if( m_netNameCandidate == NULL )
return wxEmptyString;
@ -385,6 +385,10 @@ wxString NETLIST_OBJECT::GetShortNetName() const
{
netName = wxT("Net-(");
netName << link->GetRef( &m_netNameCandidate->m_SheetPath );
if( adoptTimestamp && netName.Last() == '?' )
netName << link->GetTimeStamp();
netName << wxT("-Pad")
<< LIB_PIN::PinStringNum( m_netNameCandidate->m_PinNum )
<< wxT(")");

View File

@ -240,18 +240,20 @@ public:
/**
* Function GetNetName
* @param adoptTimestamp if annotation is not done (i.e. GetRef returns something with an ? at the end)
* @return the full net name of the item, i.e. the net name
* from the "best" label, prefixed by the sheet path
*/
wxString GetNetName() const;
wxString GetNetName( bool adoptTimestamp = false ) const;
/**
* Function GetShortNetName
* @param adoptTimestamp if annotation is not done (i.e. GetRef returns something with an ? at the end)
* @return the short net name of the item i.e. the net name
* from the "best" label without any prefix.
* 2 different nets can have the same short name
*/
wxString GetShortNetName() const;
wxString GetShortNetName( bool adoptTimestamp = false ) const;
/**
* Function ConvertBusToNetListItems

View File

@ -211,6 +211,7 @@ static PARAM_CFG_ARRAY& cfg_params()
CLR( "ColorErcEEx", LAYER_ERC_ERR, RED )
CLR( "ColorGridEx", LAYER_GRID, DARKGRAY )
CLR( "ColorBgCanvasEx", LAYER_BACKGROUND, WHITE )
CLR( "ColorBrighenedEx", LAYER_BRIGHTENED, PUREMAGENTA )
}
return ca;

View File

@ -74,6 +74,7 @@ enum id_eeschema_frm
/* Schematic editor veritcal toolbar IDs */
ID_SCHEMATIC_VERTICAL_TOOLBAR_START,
ID_HIGHLIGHT,
ID_HIERARCHY_PUSH_POP_BUTT,
ID_SCH_PLACE_COMPONENT,
ID_PLACE_POWER_BUTT,

View File

@ -97,6 +97,7 @@ typedef enum {
LAYER_DEVICE_BACKGROUND,
LAYER_GRID,
LAYER_BACKGROUND,
LAYER_BRIGHTENED,
LAYERSCH_ID_COUNT
} LAYERSCH_ID;

View File

@ -40,6 +40,8 @@
#include <wx/imaglist.h>
#include <wx/treectrl.h>
#include <class_netlist_object.h>
#include <sch_sheet_path.h>
enum
{
@ -49,6 +51,9 @@ enum
class HIERARCHY_NAVIG_DLG;
//Imported function:
int TestDuplicateSheetNames( bool aCreateMarker );
/* This class derived from wxTreeItemData stores the SCH_SHEET_PATH of each
* sheet in hierarchy in each TreeItem, in its associated data buffer
*/
@ -302,6 +307,49 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet()
RedrawScreen( GetScrollCenterPosition(), true );
}
// Disable highlight on all items (Note: might be the wrong call if needed for something else than net highlighting)
for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() )
{
ptr->SetState( BRIGHTENED, false );
if( ptr->Type() == SCH_SHEET_T )
{
for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() )
pin.SetState( BRIGHTENED, false );
}
}
//avoid selection of buses as they are nameless
if( m_SelectedNetName != "" )
{
if( TestDuplicateSheetNames( false ) )
SetStatusText( "duplicated sheets names prevent net highlighting" );
else
{
// Build netlist info to get the proper netnames
std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase( false ) );
// highlight the new items
for( auto obj1 : *objectsConnectedList )
{
if( obj1->m_SheetPath == *m_CurrentSheet && obj1->GetNetName( true ) == m_SelectedNetName && obj1->m_Comp )
{
obj1->m_Comp->SetState( BRIGHTENED, true );
//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 )
obj2->m_Comp->SetState( BRIGHTENED, true );
}
}
}
}
}
}
// Now refresh m_canvas. Should be not necessary, but because screen has changed
// the previous refresh has set all new draw parameters (scroll position ..)
// but most of time there were some inconsitencies about cursor parameters

View File

@ -155,7 +155,7 @@ void NETLIST_OBJECT_LIST::SortListbySheet()
}
NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase()
NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase( bool updateStatusText )
{
// I own this list until I return it to the new owner.
std::unique_ptr<NETLIST_OBJECT_LIST> ret( new NETLIST_OBJECT_LIST() );
@ -168,13 +168,15 @@ NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase()
if( !success )
{
SetStatusText( _( "No Objects" ) );
if( updateStatusText )
SetStatusText( _( "No Objects" ) );
return ret.release();
}
wxString msg = wxString::Format( _( "Net count = %d" ), int( ret->size() ) );
SetStatusText( msg );
if( updateStatusText )
SetStatusText( msg );
return ret.release();
}

View File

@ -31,6 +31,7 @@
#include <kiway.h>
#include <eeschema_id.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <schframe.h>
#include <sim/sim_plot_frame.h>
#include <menus_helpers.h>
@ -49,6 +50,8 @@
#include <class_netlist_object.h>
#include <class_library.h> // fo class SCHLIB_FILTER to filter power parts
//Imported function:
int TestDuplicateSheetNames( bool aCreateMarker );
// TODO(hzeller): These pairs of elmenets should be represented by an object, but don't want
// to refactor too much right now to not get in the way with other code changes.
@ -110,6 +113,34 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_NO_TOOL_SELECTED:
break;
case ID_HIGHLIGHT:
{
m_SelectedNetName = "";
//find which item is selected
EDA_ITEMS nodeList;
if( GetScreen()->GetNode( gridPosition,nodeList )
&& ( !TestDuplicateSheetNames( false )
|| IsOK( NULL, _( "Error: duplicate sheet names. Continue?" ) ) ) )
{
// Build netlist info to get the proper netnames
std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase() );
for( auto obj : *objectsConnectedList )
{
if( obj->m_SheetPath == *m_CurrentSheet && obj->m_Comp == nodeList[0] )
{
m_SelectedNetName = obj->GetNetName( true );
break;
}
}
}
SetStatusText( "selected net: " + m_SelectedNetName );
DisplayCurrentSheet();
}break;
case ID_HIERARCHY_PUSH_POP_BUTT:
if( ( item && item->GetFlags() ) || ( g_RootSheet->CountSheets() == 0 ) )
break;

View File

@ -189,7 +189,7 @@ void SCH_BUS_ENTRY_BASE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
if( aColor >= 0 )
color = aColor;
else
color = GetLayerColor( m_Layer );
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
GRSetDrawMode( aDC, aDrawMode );

View File

@ -117,7 +117,7 @@ void SCH_JUNCTION::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffs
if( aColor >= 0 )
color = aColor;
else
color = GetLayerColor( m_Layer );
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
GRSetDrawMode( aDC, aDrawMode );

View File

@ -220,7 +220,7 @@ void SCH_LINE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
if( Color >= 0 )
color = Color;
else
color = GetLayerColor( m_Layer );
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
GRSetDrawMode( DC, DrawMode );
@ -559,7 +559,7 @@ bool SCH_LINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy )
EDA_RECT rect = aRect;
if ( aAccuracy )
rect.Inflate( aAccuracy );
rect.Inflate( aAccuracy );
if( aContained )
return rect.Contains( m_start ) && rect.Contains( m_end );

View File

@ -354,7 +354,7 @@ void SCH_TEXT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& aOffset,
if( Color >= 0 )
color = Color;
else
color = GetLayerColor( m_Layer );
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
GRSetDrawMode( DC, DrawMode );
@ -1238,7 +1238,7 @@ void SCH_GLOBALLABEL::Draw( EDA_DRAW_PANEL* panel,
if( Color >= 0 )
color = Color;
else
color = GetLayerColor( m_Layer );
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
GRSetDrawMode( DC, DrawMode );
@ -1591,7 +1591,7 @@ void SCH_HIERLABEL::Draw( EDA_DRAW_PANEL* panel,
if( Color >= 0 )
color = Color;
else
color = GetLayerColor( m_Layer );
color = GetLayerColor( GetState( BRIGHTENED ) ? LAYER_BRIGHTENED : m_Layer );
GRSetDrawMode( DC, DrawMode );

View File

@ -529,6 +529,10 @@ void SCH_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
SetToolID( id, m_canvas->GetDefaultCursor(), _( "No tool selected" ) );
break;
case ID_HIGHLIGHT:
SetToolID( id, m_canvas->GetDefaultCursor(), _("click to highlight") );
break;
case ID_ZOOM_SELECTION:
SetToolID( id, wxCURSOR_MAGNIFIER, _( "Zoom to selection" ) );
break;

View File

@ -278,6 +278,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
// Tools and buttons for vertical toolbar.
EVT_TOOL( ID_NO_TOOL_SELECTED, SCH_EDIT_FRAME::OnSelectTool )
EVT_TOOL( ID_HIGHLIGHT, SCH_EDIT_FRAME::OnSelectTool )
EVT_TOOL( ID_ZOOM_SELECTION, SCH_EDIT_FRAME::OnSelectTool )
EVT_TOOL_RANGE( ID_SCHEMATIC_VERTICAL_TOOLBAR_START, ID_SCHEMATIC_VERTICAL_TOOLBAR_END,
SCH_EDIT_FRAME::OnSelectTool )
@ -319,6 +320,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_UPDATE_UI( ID_TB_OPTIONS_HIDDEN_PINS, SCH_EDIT_FRAME::OnUpdateHiddenPins )
EVT_UPDATE_UI( ID_TB_OPTIONS_BUS_WIRES_ORIENT, SCH_EDIT_FRAME::OnUpdateBusOrientation )
EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, SCH_EDIT_FRAME::OnUpdateSelectTool )
EVT_UPDATE_UI( ID_HIGHLIGHT, SCH_EDIT_FRAME::OnUpdateSelectTool )
EVT_UPDATE_UI( ID_ZOOM_SELECTION, SCH_EDIT_FRAME::OnUpdateSelectTool )
EVT_UPDATE_UI_RANGE( ID_SCHEMATIC_VERTICAL_TOOLBAR_START, ID_SCHEMATIC_VERTICAL_TOOLBAR_END,
SCH_EDIT_FRAME::OnUpdateSelectTool )

View File

@ -119,6 +119,7 @@ class SCH_EDIT_FRAME : public SCH_BASE_FRAME
private:
SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on.
wxString m_DefaultSchematicFileName;
wxString m_SelectedNetName;
PARAM_CFG_ARRAY m_projectFileParams;
PARAM_CFG_ARRAY m_configSettings;
@ -490,9 +491,10 @@ public:
* netlist generation:
* Creates a flat list which stores all connected objects, and mainly
* pins and labels.
* @param updateStatusText = decides if window StatusText should be modified
* @return NETLIST_OBJECT_LIST* - caller owns the object.
*/
NETLIST_OBJECT_LIST* BuildNetListBase();
NETLIST_OBJECT_LIST* BuildNetListBase( bool updateStatusText = true );
/**
* Function CreateNetlist

View File

@ -190,6 +190,9 @@ void SCH_EDIT_FRAME::ReCreateVToolbar()
m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiBitmap( cursor_xpm ),
wxEmptyString, wxITEM_CHECK );
m_drawToolBar->AddTool( ID_HIGHLIGHT, wxEmptyString, KiBitmap( net_highlight_xpm ),
_( "Click to highlight net" ), wxITEM_CHECK );
m_drawToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiBitmap( zoom_area_xpm ),
_( "Zoom to selection" ), wxITEM_CHECK );

View File

@ -94,6 +94,7 @@ static COLORBUTTON miscColorButtons[] = {
{ _( "ERC warning" ), LAYER_ERC_WARN },
{ _( "ERC error" ), LAYER_ERC_ERR },
{ _( "Grid" ), LAYER_GRID },
{ _( "Brightened" ), LAYER_BRIGHTENED },
{ wxT( "" ), -1 } // Sentinel marking end of list.
};