KiCad PCB EDA Suite
highlight_connection.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
31 #include <fctsys.h>
32 #include <class_drawpanel.h>
33 #include <sch_edit_frame.h>
34 #include <erc.h>
35 
36 #include <netlist_object.h>
37 
38 
40 {
41  m_SelectedNetName = "";
42  bool buildNetlistOk = false;
43 
44  // find which connected item is selected
45  EDA_ITEMS nodeList;
46  wxPoint gridPosition = GetGridPosition( aPosition );
47 
48  if( GetScreen()->GetNode( gridPosition,nodeList ) )
49  {
50  if( TestDuplicateSheetNames( false ) > 0 )
51  wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet. Fix it" ) );
52  else
53  {
54  // Build netlist info to get the proper netnames of connected items
55  std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase() );
56  buildNetlistOk = true;
57 
58  for( auto obj : *objectsConnectedList )
59  {
60  if( obj->m_SheetPath == *m_CurrentSheet && obj->m_Comp == nodeList[0] )
61  {
62  m_SelectedNetName = obj->GetNetName( true );
63  break;
64  }
65  }
66  }
67  }
68 
70  SetStatusText( "selected net: " + m_SelectedNetName );
72  m_canvas->Refresh();
73 
74  return buildNetlistOk;
75 }
76 
77 
79 {
81 
82  // Disable highlight flag on all items in the current screen
83  for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() )
84  {
85  ptr->SetState( BRIGHTENED, false );
86 
87  if( ptr->Type() == SCH_SHEET_T )
88  {
89  for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() )
90  pin.SetState( BRIGHTENED, false );
91  }
92  }
93 
94  if( m_SelectedNetName == "" )
95  return true;
96 
97  if( TestDuplicateSheetNames( false ) > 0 )
98  return false;
99 
100  // Build netlist info to get the proper netnames
101  std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase( false ) );
102 
103  // highlight the items belonging to this net
104  for( auto obj1 : *objectsConnectedList )
105  {
106  if( obj1->m_SheetPath == *m_CurrentSheet &&
107  obj1->GetNetName( true ) == m_SelectedNetName && obj1->m_Comp )
108  {
109  obj1->m_Comp->SetState( BRIGHTENED, true );
110 
111  //if a bus is associated with this net highlight it as well
112  if( obj1->m_BusNetCode )
113  {
114  for( auto obj2 : *objectsConnectedList )
115  {
116  if( obj2 && obj2->m_Comp && obj2->m_SheetPath == *m_CurrentSheet &&
117  obj1->m_BusNetCode == obj2->m_BusNetCode )
118  obj2->m_Comp->SetState( BRIGHTENED, true );
119  }
120  }
121  }
122  }
123 
124  return true;
125 }
NETLIST_OBJECT_LIST * BuildNetListBase(bool updateStatusText=true)
Create a flat list which stores all connected objects.
void SendCrossProbeNetName(const wxString &aNetName)
Sends a net name to eeschema for highlighting.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
wxPoint GetGridPosition(const wxPoint &aPosition) const
Function GetGridPosition returns the nearest grid position to aPosition if a screen is defined and sn...
Definition: draw_frame.cpp:630
SCH_SCREEN * LastScreen() const
Function LastScreen.
SCH_ITEM * Next() const
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH * m_CurrentSheet
which sheet we are presently working on.
int TestDuplicateSheetNames(bool aCreateMarker)
Function TestDuplicateSheetNames( ) inside a given sheet, one cannot have sheets with duplicate names...
Definition: erc.cpp:177
bool HighlightConnectionAtPosition(wxPoint aPosition)
Highlight the connection found at aPosition.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:541
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:133
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
wxString m_SelectedNetName
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:106
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:138
void SetState(int type, int state)
Definition: base_struct.h:253
Definition of the NETLIST_OBJECT class.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
bool SetCurrentSheetHighlightFlags()
Set or reset the BRIGHTENED of connected objects inside the current sheet, according to the highlight...