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 <schframe.h>
34 #include <erc.h>
35 
36 #include <class_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 
69  SetStatusText( "selected net: " + m_SelectedNetName );
71  m_canvas->Refresh();
72 
73  return buildNetlistOk;
74 }
75 
76 
78 {
80 
81  // Disable highlight flag on all items in the current screen
82  for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() )
83  {
84  ptr->SetState( BRIGHTENED, false );
85 
86  if( ptr->Type() == SCH_SHEET_T )
87  {
88  for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() )
89  pin.SetState( BRIGHTENED, false );
90  }
91  }
92 
93  if( m_SelectedNetName == "" )
94  return true;
95 
96  if( TestDuplicateSheetNames( false ) > 0 )
97  return false;
98 
99  // Build netlist info to get the proper netnames
100  std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase( false ) );
101 
102  // highlight the items belonging to this net
103  for( auto obj1 : *objectsConnectedList )
104  {
105  if( obj1->m_SheetPath == *m_CurrentSheet &&
106  obj1->GetNetName( true ) == m_SelectedNetName && obj1->m_Comp )
107  {
108  obj1->m_Comp->SetState( BRIGHTENED, true );
109 
110  //if a bus is associated with this net highlight it as well
111  if( obj1->m_BusNetCode )
112  {
113  for( auto obj2 : *objectsConnectedList )
114  {
115  if( obj2 && obj2->m_Comp && obj2->m_SheetPath == *m_CurrentSheet &&
116  obj1->m_BusNetCode == obj2->m_BusNetCode )
117  obj2->m_Comp->SetState( BRIGHTENED, true );
118  }
119  }
120  }
121  }
122 
123  return true;
124 }
NETLIST_OBJECT_LIST * BuildNetListBase(bool updateStatusText=true)
Create a flat list which stores all connected objects.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
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:586
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.
Definition: schframe.cpp:532
SCH_SHEET_PATH * m_CurrentSheet
which sheet we are presently working on.
Definition: schframe.h:121
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:544
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:151
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
Definition of the NETLIST_OBJECT class.
wxString m_SelectedNetName
Definition: schframe.h:123
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
SCH_ITEM * GetDrawItems() const
void SetState(int type, int state)
Definition: base_struct.h:256
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...