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 <sch_view.h>
33 #include <sch_draw_panel.h>
34 #include <sch_edit_frame.h>
35 #include <erc.h>
36 
37 #include <netlist_object.h>
38 
39 
41 {
42  m_SelectedNetName = "";
43  bool buildNetlistOk = false;
44 
45  // find which connected item is selected
46  EDA_ITEMS nodeList;
47  wxPoint gridPosition = GetGridPosition( aPosition );
48 
49  if( GetScreen()->GetNode( gridPosition,nodeList ) )
50  {
51  if( TestDuplicateSheetNames( false ) > 0 )
52  wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet. Fix it" ) );
53  else
54  {
55  // Build netlist info to get the proper netnames of connected items
56  std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase() );
57  buildNetlistOk = true;
58 
59  for( auto obj : *objectsConnectedList )
60  {
61  if( obj->m_SheetPath == *m_CurrentSheet && obj->m_Comp == nodeList[0] )
62  {
63  m_SelectedNetName = obj->GetNetName( true );
64  break;
65  }
66  }
67  }
68  }
69 
71  SetStatusText( "selected net: " + m_SelectedNetName );
73  // Be sure hightlight change will be redrawn in any case
76 
77  return buildNetlistOk;
78 }
79 
80 
82 {
84 
85  // Disable highlight flag on all items in the current screen
86  for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() )
87  {
88  ptr->SetState( BRIGHTENED, false );
89 
90  if( ptr->Type() == SCH_SHEET_T )
91  {
92  for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() )
93  pin.SetState( BRIGHTENED, false );
94  }
95  }
96 
97  if( m_SelectedNetName == "" )
98  return true;
99 
100  if( TestDuplicateSheetNames( false ) > 0 )
101  return false;
102 
103  // Build netlist info to get the proper netnames
104  std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase( false ) );
105 
106  // highlight the items belonging to this net
107  for( auto obj1 : *objectsConnectedList )
108  {
109  if( obj1->m_SheetPath == *m_CurrentSheet &&
110  obj1->GetNetName( true ) == m_SelectedNetName && obj1->m_Comp )
111  {
112  obj1->m_Comp->SetState( BRIGHTENED, true );
113 
114  //if a bus is associated with this net highlight it as well
115  if( obj1->m_BusNetCode )
116  {
117  for( auto obj2 : *objectsConnectedList )
118  {
119  if( obj2 && obj2->m_Comp && obj2->m_SheetPath == *m_CurrentSheet &&
120  obj1->m_BusNetCode == obj2->m_BusNetCode )
121  obj2->m_Comp->SetState( BRIGHTENED, true );
122  }
123  }
124  }
125  }
126 
127  return true;
128 }
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.
wxPoint GetGridPosition(const wxPoint &aPosition) const
Return the nearest grid position to aPosition if a screen is defined and snap to grid is enabled...
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1383
SCH_SCREEN * LastScreen() const
Function LastScreen.
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
SCH_ITEM * Next() const
Auxiliary rendering target (noncached)
Definition: definitions.h:42
SCH_SCREEN * GetScreen() const override
Return 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.
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target &#39;dirty&#39; flag.
Definition: view.h:596
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:550
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:138
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
wxString m_SelectedNetName
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:160
void SetState(int type, int state)
Definition: base_struct.h:245
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:908
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...