KiCad PCB EDA Suite
locate.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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <fctsys.h>
30 #include <common.h>
31 #include <msgpanel.h>
32 
33 #include <gerbview.h>
34 #include <gerbview_frame.h>
35 #include <gerber_file_image.h>
36 #include <gerber_file_image_list.h>
37 
38 
39 /* locate a gerber item and return a pointer to it.
40  * Display info about this item
41  * Items on non visible layers are not taken in account
42  */
43 GERBER_DRAW_ITEM* GERBVIEW_FRAME::Locate( const wxPoint& aPosition, int aTypeloc )
44 {
46  wxPoint ref = aPosition;
47 
48  if( aTypeloc == CURSEUR_ON_GRILLE )
49  ref = GetNearestGridPosition( ref );
50 
51  int layer = GetActiveLayer();
52  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
53 
54  GERBER_DRAW_ITEM* gerb_item = nullptr;
55 
56  // Search first on active layer
57  // A not used graphic layer can be selected. So gerber can be NULL
58  if( gerber && gerber->m_IsVisible )
59  {
60  for( auto item = gerber->GetItemsList(); item; item = item->Next() )
61  {
62  if( item->HitTest( ref ) )
63  {
64  gerb_item = item;
65  break;
66  }
67  }
68  }
69 
70  if( gerb_item == nullptr ) // Search on all layers
71  {
72  for( layer = 0; layer < (int)ImagesMaxCount(); ++layer )
73  {
74  gerber = GetGbrImage( layer );
75 
76  if( gerber == nullptr ) // Graphic layer not yet used
77  continue;
78 
79  if( !gerber->m_IsVisible )
80  continue;
81 
82  if( layer == GetActiveLayer() )
83  continue;
84 
85  for( auto item = gerber->GetItemsList(); item; item = item->Next() )
86  {
87  if( item->HitTest( ref ) )
88  {
89  gerb_item = item;
90  break;
91  }
92  }
93 
94  if( gerb_item )
95  break;
96  }
97  }
98 
99  if( gerb_item )
100  {
101  MSG_PANEL_ITEMS items;
102  gerb_item->GetMsgPanelInfo( m_UserUnits, items );
103  SetMsgPanel( items );
104  }
105 
106  return gerb_item;
107 }
#define CURSEUR_ON_GRILLE
Definition: pcbnew.h:50
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
int GetActiveLayer()
Function SetActiveLayer returns the active layer.
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
unsigned ImagesMaxCount() const
The max number of file images.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
EDA_MSG_PANEL * m_messagePanel
Panel used to display information at the bottom of the main window.
Definition: draw_frame.h:163
GERBER_DRAW_ITEM * Next() const
void EraseMsgBox()
Definition: msgpanel.cpp:216
GERBER_DRAW_ITEM * Locate(const wxPoint &aPosition, int typeloc)
Definition: locate.cpp:43
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Return the nearest aGridSize location to aPosition.
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
The common library.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
Message panel definition file.
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:120