Browse Source
EESchema multiple item hit testing and other minor improvements.
EESchema multiple item hit testing and other minor improvements.
* Add item clarification context menu to EESchema when multiple unresolved items are found at the current cross hair position. * Add collector class SCH_COLLECTOR for supporting multiple item hit testing. * Removed bit wise masked filtering from schematic item hit testing. * Removed all old hit testing functions and methods scattered about the EESchema source code. * Move terminal point test function into SCH_SCREEN object. * Fixed bug in terminal point test when terminating a bus to a label. * Define the < operator for sorting schematic items. * Add area calculation method to EDA_Rect item. * Add method for returning an item's bitmap for menu display purposes. * Add method for returning an item's menu text for menu display purposes. * Changed EDA_ITEMS container from boost::ptr_vector to std::vector. * Factor coordinate string conversion code from EDA_DRAW_FRAME to function CoordinateToString().pull/1/head
59 changed files with 1883 additions and 1172 deletions
-
16common/base_struct.cpp
-
41common/common.cpp
-
2common/dialog_about/dialog_about.cpp
-
30common/drawframe.cpp
-
19common/sch_item_struct.cpp
-
7common/trigo.cpp
-
3cvpcb/dialogs/dialog_display_options.cpp
-
2eeschema/CMakeLists.txt
-
98eeschema/bus-wire-junction.cpp
-
219eeschema/controle.cpp
-
55eeschema/delete.cpp
-
6eeschema/dialogs/dialog_edit_label.cpp
-
105eeschema/edit_component_in_schematic.cpp
-
29eeschema/edit_label.cpp
-
12eeschema/eeschema_id.h
-
40eeschema/getpart.cpp
-
282eeschema/hotkeys.cpp
-
17eeschema/lib_pin.cpp
-
17eeschema/lib_pin.h
-
74eeschema/locate.cpp
-
8eeschema/onleftclick.cpp
-
89eeschema/onrightclick.cpp
-
6eeschema/protos.h
-
12eeschema/sch_bus_entry.cpp
-
6eeschema/sch_bus_entry.h
-
256eeschema/sch_collectors.cpp
-
154eeschema/sch_collectors.h
-
123eeschema/sch_component.cpp
-
53eeschema/sch_component.h
-
38eeschema/sch_field.cpp
-
18eeschema/sch_field.h
-
5eeschema/sch_junction.cpp
-
8eeschema/sch_junction.h
-
76eeschema/sch_line.cpp
-
14eeschema/sch_line.h
-
5eeschema/sch_marker.cpp
-
10eeschema/sch_marker.h
-
5eeschema/sch_no_connect.cpp
-
6eeschema/sch_no_connect.h
-
42eeschema/sch_polyline.cpp
-
6eeschema/sch_polyline.h
-
263eeschema/sch_screen.cpp
-
37eeschema/sch_sheet.cpp
-
51eeschema/sch_sheet.h
-
16eeschema/sch_sheet_pin.cpp
-
48eeschema/sch_text.cpp
-
65eeschema/sch_text.h
-
153eeschema/schedit.cpp
-
19eeschema/schframe.cpp
-
6eeschema/sheetlab.cpp
-
64include/base_struct.h
-
18include/class_collector.h
-
2include/class_drawpanel.h
-
131include/class_sch_screen.h
-
14include/common.h
-
46include/sch_item_struct.h
-
19include/trigo.h
-
70include/wxEeschemaStruct.h
-
19include/wxstruct.h
@ -1,74 +0,0 @@ |
|||
/******************************************************/ |
|||
/* Routines for locating an element of a schematic. */ |
|||
/******************************************************/ |
|||
|
|||
#include "fctsys.h"
|
|||
#include "common.h"
|
|||
#include "trigo.h"
|
|||
#include "macros.h"
|
|||
#include "class_sch_screen.h"
|
|||
|
|||
#include "general.h"
|
|||
#include "protos.h"
|
|||
#include "class_library.h"
|
|||
#include "sch_bus_entry.h"
|
|||
#include "sch_marker.h"
|
|||
#include "sch_junction.h"
|
|||
#include "sch_component.h"
|
|||
#include "sch_line.h"
|
|||
#include "sch_no_connect.h"
|
|||
#include "sch_polyline.h"
|
|||
#include "sch_sheet.h"
|
|||
#include "lib_pin.h"
|
|||
#include "template_fieldnames.h"
|
|||
|
|||
|
|||
/**
|
|||
* Search the smaller (considering its area) component under the mouse |
|||
* cursor or the pcb cursor |
|||
* |
|||
* If more than 1 component is found, a pointer to the smaller component is |
|||
* returned |
|||
*/ |
|||
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ) |
|||
{ |
|||
double area = 0.0; // Quiet compiler
|
|||
EDA_Rect rect; |
|||
PICKED_ITEMS_LIST itemList; |
|||
SCH_COMPONENT* component = NULL; |
|||
SCH_COMPONENT* lastcomponent = NULL; |
|||
|
|||
if( Screen->GetItems( Screen->RefPos( true ), itemList, COMPONENT_T ) == 0 ) |
|||
{ |
|||
if( Screen->GetItems( Screen->GetCrossHairPosition(), itemList, COMPONENT_T ) == 0 ) |
|||
return NULL; |
|||
} |
|||
|
|||
if( itemList.GetCount() == 1 ) |
|||
return (SCH_COMPONENT*) itemList.GetPickedItem( 0 ); |
|||
|
|||
for( size_t i = 0; i < itemList.GetCount(); i++ ) |
|||
{ |
|||
component = (SCH_COMPONENT*) itemList.GetPickedItem( i ); |
|||
|
|||
if( lastcomponent == NULL ) // First component
|
|||
{ |
|||
lastcomponent = component; |
|||
rect = lastcomponent->GetBoundingBox(); |
|||
area = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() ); |
|||
} |
|||
else |
|||
{ |
|||
rect = component->GetBoundingBox(); |
|||
double tmp = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() ); |
|||
|
|||
if( area > tmp ) // a smaller component is found
|
|||
{ |
|||
area = tmp; |
|||
lastcomponent = component; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return lastcomponent; |
|||
} |
|||
@ -0,0 +1,256 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net> |
|||
* Copyright (C) 2004-2011 Kicad Developers, see change_log.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include "general.h"
|
|||
#include "transform.h"
|
|||
#include "sch_collectors.h"
|
|||
#include "sch_component.h"
|
|||
#include "sch_line.h"
|
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::AllItems[] = { |
|||
SCH_MARKER_T, |
|||
SCH_JUNCTION_T, |
|||
SCH_NO_CONNECT_T, |
|||
SCH_BUS_ENTRY_T, |
|||
SCH_LINE_T, |
|||
SCH_POLYLINE_T, |
|||
SCH_TEXT_T, |
|||
SCH_LABEL_T, |
|||
SCH_GLOBAL_LABEL_T, |
|||
SCH_HIERARCHICAL_LABEL_T, |
|||
SCH_FIELD_T, |
|||
SCH_COMPONENT_T, |
|||
LIB_PIN_T, |
|||
SCH_SHEET_LABEL_T, |
|||
SCH_SHEET_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::AllItemsButPins[] = { |
|||
SCH_MARKER_T, |
|||
SCH_JUNCTION_T, |
|||
SCH_NO_CONNECT_T, |
|||
SCH_BUS_ENTRY_T, |
|||
SCH_LINE_T, |
|||
SCH_POLYLINE_T, |
|||
SCH_TEXT_T, |
|||
SCH_LABEL_T, |
|||
SCH_GLOBAL_LABEL_T, |
|||
SCH_HIERARCHICAL_LABEL_T, |
|||
SCH_FIELD_T, |
|||
SCH_COMPONENT_T, |
|||
SCH_SHEET_LABEL_T, |
|||
SCH_SHEET_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::EditableItems[] = { |
|||
SCH_TEXT_T, |
|||
SCH_LABEL_T, |
|||
SCH_GLOBAL_LABEL_T, |
|||
SCH_HIERARCHICAL_LABEL_T, |
|||
SCH_FIELD_T, |
|||
SCH_COMPONENT_T, |
|||
SCH_SHEET_LABEL_T, |
|||
SCH_SHEET_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::MovableItems[] = { |
|||
SCH_MARKER_T, |
|||
// SCH_JUNCTION_T,
|
|||
SCH_NO_CONNECT_T, |
|||
SCH_BUS_ENTRY_T, |
|||
// SCH_LINE_T,
|
|||
SCH_POLYLINE_T, |
|||
SCH_TEXT_T, |
|||
SCH_LABEL_T, |
|||
SCH_GLOBAL_LABEL_T, |
|||
SCH_HIERARCHICAL_LABEL_T, |
|||
SCH_FIELD_T, |
|||
SCH_COMPONENT_T, |
|||
SCH_SHEET_LABEL_T, |
|||
SCH_SHEET_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::DraggableItems[] = { |
|||
SCH_JUNCTION_T, |
|||
SCH_BUS_ENTRY_T, |
|||
SCH_LINE_T, |
|||
SCH_POLYLINE_T, |
|||
SCH_GLOBAL_LABEL_T, |
|||
SCH_HIERARCHICAL_LABEL_T, |
|||
SCH_COMPONENT_T, |
|||
SCH_SHEET_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::RotatableItems[] = { |
|||
SCH_TEXT_T, |
|||
SCH_LABEL_T, |
|||
SCH_GLOBAL_LABEL_T, |
|||
SCH_HIERARCHICAL_LABEL_T, |
|||
SCH_FIELD_T, |
|||
SCH_COMPONENT_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::ParentItems[] = { |
|||
SCH_MARKER_T, |
|||
SCH_JUNCTION_T, |
|||
SCH_NO_CONNECT_T, |
|||
SCH_BUS_ENTRY_T, |
|||
SCH_LINE_T, |
|||
SCH_POLYLINE_T, |
|||
SCH_TEXT_T, |
|||
SCH_LABEL_T, |
|||
SCH_GLOBAL_LABEL_T, |
|||
SCH_HIERARCHICAL_LABEL_T, |
|||
SCH_COMPONENT_T, |
|||
SCH_SHEET_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::ComponentsOnly[] = { |
|||
SCH_COMPONENT_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::SheetsOnly[] = { |
|||
SCH_SHEET_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
const KICAD_T SCH_COLLECTOR::SheetsAndSheetLabels[] = { |
|||
SCH_SHEET_LABEL_T, |
|||
SCH_SHEET_T, |
|||
EOT |
|||
}; |
|||
|
|||
|
|||
SEARCH_RESULT SCH_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestData ) |
|||
{ |
|||
if( aItem->Type() != LIB_PIN_T && !aItem->HitTest( m_RefPos ) ) |
|||
return SEARCH_CONTINUE; |
|||
|
|||
// Pins have special hit testing requirements that are relative to their parent
|
|||
// SCH_COMPONENT item.
|
|||
if( aItem->Type() == LIB_PIN_T ) |
|||
{ |
|||
wxCHECK_MSG( aTestData && ( (EDA_ITEM*) aTestData )->Type() == SCH_COMPONENT_T, |
|||
SEARCH_CONTINUE, wxT( "Cannot inspect invalid data. Bad programmer!" ) ); |
|||
|
|||
// Pin hit testing is relative to the components position and orientation in the
|
|||
// schematic. The hit test position must be converted to library coordinates.
|
|||
SCH_COMPONENT* component = (SCH_COMPONENT*) aTestData; |
|||
TRANSFORM transform = component->GetTransform().InverseTransform(); |
|||
wxPoint position = transform.TransformCoordinate( m_RefPos - component->m_Pos ); |
|||
|
|||
position.y *= -1; // Y axis polarity in schematic is inverted from library.
|
|||
|
|||
if( !aItem->HitTest( position ) ) |
|||
return SEARCH_CONTINUE; |
|||
} |
|||
|
|||
Append( aItem ); |
|||
|
|||
return SEARCH_CONTINUE; |
|||
} |
|||
|
|||
|
|||
void SCH_COLLECTOR::Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[], |
|||
const wxPoint& aPosition ) |
|||
{ |
|||
Empty(); // empty the collection just in case
|
|||
|
|||
SetScanTypes( aFilterList ); |
|||
|
|||
// remember where the snapshot was taken from and pass refPos to the Inspect() function.
|
|||
SetRefPos( aPosition ); |
|||
|
|||
EDA_ITEM::IterateForward( aItem, this, NULL, m_ScanTypes ); |
|||
} |
|||
|
|||
|
|||
bool SCH_COLLECTOR::IsCorner() const |
|||
{ |
|||
if( GetCount() != 2 ) |
|||
return false; |
|||
|
|||
if( (m_List[0]->Type() == SCH_LINE_T) && (m_List[1]->Type() == SCH_LINE_T) ) |
|||
return true; |
|||
|
|||
if( (m_List[0]->Type() == SCH_LINE_T) && (m_List[1]->Type() == SCH_BUS_ENTRY_T) ) |
|||
return true; |
|||
|
|||
if( (m_List[0]->Type() == SCH_BUS_ENTRY_T) && (m_List[1]->Type() == SCH_LINE_T) ) |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
|
|||
bool SCH_COLLECTOR::IsNode( bool aIncludePins ) const |
|||
{ |
|||
for( size_t i = 0; i < m_List.size(); i++ ) |
|||
{ |
|||
SCH_ITEM* item = (SCH_ITEM*) m_List[ i ]; |
|||
KICAD_T type = item->Type(); |
|||
|
|||
if( type == SCH_JUNCTION_T ) |
|||
continue; |
|||
|
|||
if( type == SCH_LINE_T ) |
|||
{ |
|||
if( item->GetLayer() != LAYER_WIRE ) |
|||
return false; |
|||
|
|||
continue; |
|||
} |
|||
|
|||
if( type == LIB_PIN_T ) |
|||
{ |
|||
if( !aIncludePins ) |
|||
return false; |
|||
|
|||
continue; |
|||
} |
|||
|
|||
// Any other item types indicate that this collection is not a node.
|
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
@ -0,0 +1,154 @@ |
|||
/* |
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net> |
|||
* Copyright (C) 2004-20011 Kicad Developers, see change_log.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef _SCH_COLLECTORS_H_ |
|||
#define _SCH_COLLECTORS_H_ |
|||
|
|||
|
|||
#include "class_collector.h" |
|||
#include "sch_item_struct.h" |
|||
|
|||
|
|||
/** |
|||
* Class SCH_COLLECTOR |
|||
*/ |
|||
class SCH_COLLECTOR : public COLLECTOR |
|||
{ |
|||
public: |
|||
|
|||
/** |
|||
* A scan list for all schematic items. |
|||
*/ |
|||
static const KICAD_T AllItems[]; |
|||
|
|||
/** |
|||
* A scan list for all editable schematic items. |
|||
*/ |
|||
static const KICAD_T EditableItems[]; |
|||
|
|||
/** |
|||
* A scan list for all movable schematic items. |
|||
*/ |
|||
static const KICAD_T MovableItems[]; |
|||
|
|||
/** |
|||
* A scan list for all draggable schematic items. |
|||
*/ |
|||
static const KICAD_T DraggableItems[]; |
|||
|
|||
/** |
|||
* A scan list for all rotatable schematic items. |
|||
*/ |
|||
static const KICAD_T RotatableItems[]; |
|||
|
|||
/** |
|||
* A scan list for only parent schematic items. |
|||
*/ |
|||
static const KICAD_T ParentItems[]; |
|||
|
|||
/** |
|||
* A scan list for all schematic items except pins. |
|||
*/ |
|||
static const KICAD_T AllItemsButPins[]; |
|||
|
|||
/** |
|||
* A scan list for schematic component items only. |
|||
*/ |
|||
static const KICAD_T ComponentsOnly[]; |
|||
|
|||
/** |
|||
* A scan list for schematic sheet items only. |
|||
*/ |
|||
static const KICAD_T SheetsOnly[]; |
|||
|
|||
/** |
|||
* A scan list for schematic sheet and sheet label items. |
|||
*/ |
|||
static const KICAD_T SheetsAndSheetLabels[]; |
|||
|
|||
/** |
|||
* Constructor SCH_COLLECTOR |
|||
*/ |
|||
SCH_COLLECTOR( const KICAD_T* aScanTypes = SCH_COLLECTOR::AllItems ) |
|||
{ |
|||
SetScanTypes( aScanTypes ); |
|||
} |
|||
|
|||
/** |
|||
* Operator [] |
|||
* overloads COLLECTOR::operator[](int) to return a SCH_ITEM* instead of |
|||
* an EDA_ITEM* type. |
|||
* @param aIndex The index into the list. |
|||
* @return SCH_ITEM* at \a aIndex or NULL. |
|||
*/ |
|||
SCH_ITEM* operator[]( int aIndex ) const |
|||
{ |
|||
if( (unsigned)aIndex < (unsigned)GetCount() ) |
|||
return (SCH_ITEM*) m_List[ aIndex ]; |
|||
|
|||
return NULL; |
|||
} |
|||
|
|||
/** |
|||
* Function Inspect |
|||
* is the examining function within the INSPECTOR which is passed to the |
|||
* Iterate function. |
|||
* |
|||
* @param aItem An EDA_ITEM to examine. |
|||
* @param aTestData is not used in this class. |
|||
* @return SEARCH_RESULT #SEARCH_QUIT if the iterator is to stop the scan, |
|||
* else #SEARCH_CONTINUE; |
|||
*/ |
|||
SEARCH_RESULT Inspect( EDA_ITEM* aItem, const void* aTestData = NULL ); |
|||
|
|||
/** |
|||
* Function Collect |
|||
* scans a SCH_ITEM using this class's Inspector method, which does the collection. |
|||
* @param aItem A SCH_ITEM to scan. |
|||
* @param aFilterList A list of #KICAD_T types with a terminating #EOT, that determines |
|||
* what is to be collected and the priority order of the resulting |
|||
* collection. |
|||
* @param aPosition A wxPoint to use in hit-testing. |
|||
*/ |
|||
void Collect( SCH_ITEM* aItem, const KICAD_T aScanList[], const wxPoint& aPositiion ); |
|||
|
|||
/** |
|||
* Function IsCorner |
|||
* tests if the collected items forms as corner of two line segments. |
|||
* @return True if the collected items form a corner of two line segments. |
|||
*/ |
|||
bool IsCorner() const; |
|||
|
|||
/** |
|||
* Function IsNode |
|||
* tests if the collected items form a node. |
|||
* |
|||
* @param aIncludePins Indicate if component pin items should be included in the test. |
|||
* @return True if the collected items form a node. |
|||
*/ |
|||
bool IsNode( bool aIncludePins = true ) const; |
|||
}; |
|||
|
|||
|
|||
#endif // _SCH_COLLECTORS_H_ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue