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 // List of items having the highlight option modified, therefore need to be redrawn
40 
42 {
43  std::vector<EDA_ITEM*> itemsToRedraw;
44  m_SelectedNetName = "";
45  bool buildNetlistOk = false;
46 
47  // find which connected item is selected
48  EDA_ITEMS nodeList;
49  wxPoint gridPosition = GetGridPosition( aPosition );
50 
51  if( GetScreen()->GetNode( gridPosition,nodeList ) )
52  {
53  if( TestDuplicateSheetNames( false ) > 0 )
54  wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet. Fix it" ) );
55  else
56  {
57  // Build netlist info to get the proper netnames of connected items
58  std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase() );
59  buildNetlistOk = true;
60 
61  for( auto obj : *objectsConnectedList )
62  {
63  if( obj->m_SheetPath == *m_CurrentSheet && obj->m_Comp == nodeList[0] )
64  {
65  m_SelectedNetName = obj->GetNetName( true );
66  break;
67  }
68  }
69  }
70  }
71 
73  SetStatusText( "selected net: " + m_SelectedNetName );
74  SetCurrentSheetHighlightFlags( &itemsToRedraw );
75 
76  // Be sure hightlight change will be redrawn
77  KIGFX::VIEW* view = GetGalCanvas()->GetView();
78 
79  for( auto item : itemsToRedraw )
81 
82  //view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
83  GetGalCanvas()->Refresh();
84  return buildNetlistOk;
85 }
86 
87 
88 bool SCH_EDIT_FRAME::SetCurrentSheetHighlightFlags( std::vector<EDA_ITEM*>* aItemsToRedrawList )
89 {
91 
92  if( !screen )
93  return true;
94 
95  // Disable highlight flag on all items in the current screen
96  for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() )
97  {
98  if( ptr->GetState( BRIGHTENED ) && aItemsToRedrawList )
99  aItemsToRedrawList->push_back( ptr );
100 
101  ptr->SetState( BRIGHTENED, false );
102 
103 
104  if( ptr->Type() == SCH_SHEET_T )
105  {
106  for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() )
107  {
108  if( ptr->GetState( BRIGHTENED ) && aItemsToRedrawList )
109  aItemsToRedrawList->push_back( &pin );
110 
111  pin.SetState( BRIGHTENED, false );
112  }
113  }
114  }
115 
116  if( m_SelectedNetName == "" )
117  return true;
118 
119  if( TestDuplicateSheetNames( false ) > 0 )
120  return false;
121 
122  // Build netlist info to get the proper netnames
123  std::unique_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( BuildNetListBase( false ) );
124 
125  // highlight the items belonging to this net
126  for( auto obj1 : *objectsConnectedList )
127  {
128  if( obj1->m_SheetPath == *m_CurrentSheet &&
129  obj1->GetNetName( true ) == m_SelectedNetName && obj1->m_Comp )
130  {
131  obj1->m_Comp->SetState( BRIGHTENED, true );
132 
133  if( aItemsToRedrawList )
134  aItemsToRedrawList->push_back( obj1->m_Comp );
135 
136  //if a bus is associated with this net highlight it as well
137  if( obj1->m_BusNetCode )
138  {
139  for( auto obj2 : *objectsConnectedList )
140  {
141  if( obj2 && obj2->m_Comp && obj2->m_SheetPath == *m_CurrentSheet &&
142  obj1->m_BusNetCode == obj2->m_BusNetCode )
143  {
144  if( aItemsToRedrawList )
145  aItemsToRedrawList->push_back( obj2->m_Comp );
146 
147  obj2->m_Comp->SetState( BRIGHTENED, true );
148  }
149  }
150  }
151  }
152  }
153 
154  return true;
155 }
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.
SCH_ITEM * Next() const
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:934
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:84
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.
Item is being added to the view.
Definition: view_item.h:60
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:550
wxPoint GetGridPosition(const wxPoint &aPosition) const
Return the nearest grid position to aPosition if a screen is defined and snap to grid is enabled...
#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
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1539
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxString m_SelectedNetName
void SetState(int type, int state)
Definition: base_struct.h:245
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Class VIEW.
Definition: view.h:61
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...
SCH_SCREEN * LastScreen() const
Function LastScreen.
bool SetCurrentSheetHighlightFlags(std::vector< EDA_ITEM *> *aItemsToRedrawList)
Set or reset the BRIGHTENED of connected objects inside the current sheet, according to the highlight...
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:160