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>
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  bool found = false;
48 
49  if( aTypeloc == CURSEUR_ON_GRILLE )
50  ref = GetNearestGridPosition( ref );
51 
52  int layer = getActiveLayer();
53  GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
54 
55  GERBER_DRAW_ITEM* gerb_item = NULL;
56 
57  // Search first on active layer
58  // A not used graphic layer can be selected. So gerber can be NULL
59  if( gerber && IsLayerVisible( layer ) )
60  {
61  for( gerb_item = gerber->GetItemsList(); gerb_item; gerb_item = gerb_item->Next() )
62  {
63  if( gerb_item->HitTest( ref ) )
64  {
65  found = true;
66  break;
67  }
68  }
69  }
70 
71  if( !found ) // Search on all layers
72  {
73  for( layer = 0; layer < (int)ImagesMaxCount(); ++layer )
74  {
75  gerber = GetGbrImage( layer );
76 
77  if( gerber == NULL ) // Graphic layer not yet used
78  continue;
79 
80  if( !IsLayerVisible( layer ) )
81  continue;
82 
83  for( gerb_item = gerber->GetItemsList(); gerb_item; gerb_item = gerb_item->Next() )
84  {
85  if( gerb_item->HitTest( ref ) )
86  {
87  found = true;
88  break;
89  }
90  }
91 
92  if( found )
93  break;
94  }
95  }
96 
97  if( found && gerb_item )
98  {
99  MSG_PANEL_ITEMS items;
100  gerb_item->GetMsgPanelInfo( items );
101  SetMsgPanel( items );
102  return gerb_item;
103  }
104 
105  return NULL;
106 }
#define CURSEUR_ON_GRILLE
Definition: pcbnew.h:46
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
unsigned ImagesMaxCount() const
The max number of file images.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:754
EDA_MSG_PANEL * m_messagePanel
Panel used to display information at the bottom of the main window.
Definition: draw_frame.h:128
GERBER_DRAW_ITEM * Next() const
void EraseMsgBox()
Definition: msgpanel.cpp:215
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible tests whether a given layer is visible.
GERBER_DRAW_ITEM * Locate(const wxPoint &aPosition, int typeloc)
Definition: locate.cpp:43
wxPoint GetNearestGridPosition(const wxPoint &aPosition, wxRealPoint *aGridSize=NULL) const
Function GetNearestGridPosition returns the nearest aGridSize location to aPosition.
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
int getActiveLayer()
Function getActiveLayer returns the active layer.
The common library.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
bool HitTest(const wxPoint &aRefPos) const override
Function HitTest tests if the given wxPoint is within the bounds of this object.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx) const
Message panel definition file.