From f87d371b8b6af08e3579a1779671bb2ef8ad2b16 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 6 May 2019 03:32:01 +0100 Subject: [PATCH] Move to shared COLLECTORS for sch and lib. --- eeschema/CMakeLists.txt | 1 - eeschema/class_libentry.cpp | 16 ++ eeschema/class_libentry.h | 5 +- .../dialogs/dialog_lib_edit_draw_item.cpp | 1 + eeschema/lib_collectors.cpp | 144 ------------------ eeschema/lib_collectors.h | 138 ----------------- eeschema/libedit/controller.cpp | 23 +-- eeschema/libedit/lib_edit_frame.cpp | 18 ++- eeschema/libedit/lib_edit_frame.h | 6 +- eeschema/libedit/libedit_onleftclick.cpp | 2 +- eeschema/sch_collectors.cpp | 34 ++++- eeschema/sch_collectors.h | 13 +- eeschema/sch_screen.cpp | 32 ++-- eeschema/sch_screen.h | 4 +- eeschema/tools/sch_selection_tool.cpp | 34 ++++- eeschema/tools/sch_selection_tool.h | 4 + include/base_struct.h | 3 + include/core/typeinfo.h | 3 + 18 files changed, 149 insertions(+), 332 deletions(-) delete mode 100644 eeschema/lib_collectors.cpp delete mode 100644 eeschema/lib_collectors.h diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 731c604a86..e63e95238e 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -167,7 +167,6 @@ set( EESCHEMA_SRCS lib_arc.cpp lib_bezier.cpp lib_circle.cpp - lib_collectors.cpp lib_draw_item.cpp lib_field.cpp lib_pin.cpp diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 651b1dc276..3aca4b2cc7 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -964,6 +964,22 @@ LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, } +SEARCH_RESULT LIB_PART::Visit( INSPECTOR aInspector, void* aTestData, const KICAD_T aFilterTypes[] ) +{ + // The part itself is never inspected, only its children + for( LIB_ITEM& item : m_drawings ) + { + if( item.IsType( aFilterTypes ) ) + { + if( aInspector( &item, aTestData ) == SEARCH_QUIT ) + return SEARCH_QUIT; + } + } + + return SEARCH_CONTINUE; +} + + void LIB_PART::SetUnitCount( int aCount ) { if( m_unitCount == aCount ) diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 370e984bcd..38eee744c2 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -276,7 +276,6 @@ public: } virtual void SetName( const wxString& aName ); - const wxString& GetName() const; const LIB_ID& GetLibId() const { return m_libId; } @@ -285,7 +284,6 @@ public: const wxString GetLibraryName(); PART_LIB* GetLib() { return m_library; } - void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; } wxArrayString GetAliasNames( bool aIncludeRoot = true ) const; @@ -295,7 +293,6 @@ public: size_t GetAliasCount() const { return m_aliases.size(); } LIB_ALIAS* GetAlias( size_t aIndex ); - LIB_ALIAS* GetAlias( const wxString& aName ); timestamp_t GetDateLastEdition() const { return m_dateLastEdition; } @@ -620,6 +617,8 @@ public: return m_drawings; } + SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; + /** * Set the units per part count. * diff --git a/eeschema/dialogs/dialog_lib_edit_draw_item.cpp b/eeschema/dialogs/dialog_lib_edit_draw_item.cpp index 1307efd839..a1abdcbbf5 100644 --- a/eeschema/dialogs/dialog_lib_edit_draw_item.cpp +++ b/eeschema/dialogs/dialog_lib_edit_draw_item.cpp @@ -26,6 +26,7 @@ */ #include +#include #include #include diff --git a/eeschema/lib_collectors.cpp b/eeschema/lib_collectors.cpp deleted file mode 100644 index e8ac195710..0000000000 --- a/eeschema/lib_collectors.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 2004-2011 KiCad Developers, see AUTHORS.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 -#include -#include -#include - - -const KICAD_T LIB_COLLECTOR::AllItems[] = { - LIB_ARC_T, - LIB_CIRCLE_T, - LIB_TEXT_T, - LIB_RECTANGLE_T, - LIB_POLYLINE_T, - LIB_BEZIER_T, - LIB_PIN_T, - LIB_FIELD_T, - EOT -}; - - -const KICAD_T LIB_COLLECTOR::AllItemsButPins[] = { - LIB_ARC_T, - LIB_CIRCLE_T, - LIB_TEXT_T, - LIB_RECTANGLE_T, - LIB_POLYLINE_T, - LIB_BEZIER_T, - LIB_FIELD_T, - EOT -}; - - -const KICAD_T LIB_COLLECTOR::EditableItems[] = { - LIB_ARC_T, - LIB_CIRCLE_T, - LIB_TEXT_T, - LIB_RECTANGLE_T, - LIB_POLYLINE_T, - LIB_BEZIER_T, - LIB_PIN_T, - LIB_FIELD_T, - EOT -}; - - -const KICAD_T LIB_COLLECTOR::MovableItems[] = { - LIB_ARC_T, - LIB_CIRCLE_T, - LIB_TEXT_T, - LIB_RECTANGLE_T, - LIB_POLYLINE_T, - LIB_BEZIER_T, - LIB_PIN_T, - LIB_FIELD_T, - EOT -}; - - -const KICAD_T LIB_COLLECTOR::RotatableItems[] = { - LIB_ARC_T, - LIB_CIRCLE_T, - LIB_TEXT_T, - LIB_RECTANGLE_T, - LIB_POLYLINE_T, - LIB_BEZIER_T, - LIB_PIN_T, - LIB_FIELD_T, - EOT -}; - - -const KICAD_T LIB_COLLECTOR::DoubleClickItems[] = { - LIB_PIN_T, - LIB_ARC_T, - LIB_CIRCLE_T, - LIB_RECTANGLE_T, - LIB_POLYLINE_T, - LIB_TEXT_T, - LIB_FIELD_T, - LIB_BEZIER_T, - EOT -}; - - -SEARCH_RESULT LIB_COLLECTOR::Inspect( EDA_ITEM* aItem, void* testData ) -{ - LIB_ITEM* item = (LIB_ITEM*) aItem; - -// wxLogDebug( wxT( "Inspecting item %s, unit %d, convert %d" ), -// GetChars( item->GetSelectMenuText() ), item->GetUnit(), item->GetConvert() ); - - if( ( m_data.m_unit && item->GetUnit() && ( m_data.m_unit != item->GetUnit() ) ) - || ( m_data.m_convert && item->GetConvert() && ( m_data.m_convert != item->GetConvert() ) ) - || !item->HitTest( m_RefPos ) ) - return SEARCH_CONTINUE; - - Append( aItem ); - - return SEARCH_CONTINUE; -} - - -void LIB_COLLECTOR::Collect( LIB_ITEMS_CONTAINER& aItems, const KICAD_T aFilterList[], - const wxPoint& aPosition, int aUnit, int aConvert ) -{ - 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 ); - - m_data.m_unit = aUnit; - m_data.m_convert = aConvert; - - for( LIB_ITEM& item : aItems ) - { - if( SEARCH_QUIT == item.Visit( m_inspector, NULL, m_ScanTypes ) ) - break; - } -} diff --git a/eeschema/lib_collectors.h b/eeschema/lib_collectors.h deleted file mode 100644 index 06c46a3cff..0000000000 --- a/eeschema/lib_collectors.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 2011 KiCad Developers, see AUTHORS.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 _LIB_COLLECTORS_H_ -#define _LIB_COLLECTORS_H_ - - -#include -#include - -class LIB_COLLECTOR; - -class LIB_COLLECTOR_DATA -{ - int m_unit; - int m_convert; - - friend class LIB_COLLECTOR; - -public: - LIB_COLLECTOR_DATA() : - m_unit( 0 ), - m_convert( 0 ) {} -}; - - -/** - * Class LIB_COLLECTOR - */ -class LIB_COLLECTOR : public COLLECTOR -{ - LIB_COLLECTOR_DATA m_data; - -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 rotatable schematic items. - */ - static const KICAD_T RotatableItems[]; - - /** - * A scan list for all double-clickable library items. - */ - static const KICAD_T DoubleClickItems[]; - - /** - * A scan list for all schematic items except pins. - */ - static const KICAD_T AllItemsButPins[]; - - /** - * Constructor LIB_COLLECTOR - */ - LIB_COLLECTOR( const KICAD_T* aScanTypes = LIB_COLLECTOR::AllItems ) - { - SetScanTypes( aScanTypes ); - } - - /** - * Operator [] - * overloads COLLECTOR::operator[](int) to return a LIB_ITEM* instead of - * an EDA_ITEM* type. - * @param aIndex The index into the list. - * @return LIB_ITEM* at \a aIndex or NULL. - */ - LIB_ITEM* operator[]( int aIndex ) const override - { - if( (unsigned)aIndex < (unsigned)GetCount() ) - return (LIB_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, void* aTestData ) override; - - /** - * 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. - * @param aUnit The unit of the items to collect or zero if all units. - * @param aConvert The convert of the items to collect or zero if all conversions. - */ - void Collect( LIB_ITEMS_CONTAINER& aItem, const KICAD_T aFilterList[], const wxPoint& aPosition, - int aUnit = 0, int aConvert = 0 ); -}; - - -#endif // _LIB_COLLECTORS_H_ diff --git a/eeschema/libedit/controller.cpp b/eeschema/libedit/controller.cpp index 506678f1b6..58d40e3ef8 100644 --- a/eeschema/libedit/controller.cpp +++ b/eeschema/libedit/controller.cpp @@ -47,6 +47,9 @@ bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey ) { + bool keyHandled = false; + wxPoint pos = aPosition; + // Filter out the 'fake' mouse motion after a keyboard movement if( !aHotKey && m_movingCursorWithKeyboard ) { @@ -54,28 +57,16 @@ bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KE return false; } - // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed - // for next cursor position - // ( shift or ctrl key down are PAN command with mouse wheel) - bool snapToGrid = true; - - if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) ) - snapToGrid = false; - - // Cursor is left off grid only if no block in progress - if( GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK ) - snapToGrid = true; - - wxPoint pos = aPosition; - bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, snapToGrid ); + if( aHotKey ) + keyHandled = GeneralControlKeyMovement( aHotKey, &pos, true ); if( GetToolId() == ID_NO_TOOL_SELECTED ) m_canvas->CrossHairOff( aDC ); else m_canvas->CrossHairOn( aDC ); - GetGalCanvas()->GetViewControls()->SetSnapping( snapToGrid ); - SetCrossHairPosition( pos, snapToGrid ); + GetGalCanvas()->GetViewControls()->SetSnapping( false ); + SetCrossHairPosition( pos, false ); if( m_canvas->IsMouseCaptured() ) m_canvas->CallMouseCapture( aDC, aPosition, true ); diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 082fb3f930..946330f06e 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -338,9 +338,12 @@ void LIB_EDIT_FRAME::setupTools() m_toolManager->InitTools(); // Run the selection tool, it is supposed to be always active + // JEY TODO: not ready for modern toolset event processing yet.... +#if 0 m_toolManager->InvokeTool( "eeschema.InteractiveSelection" ); GetCanvas()->SetEventDispatcher( m_toolDispatcher ); +#endif } @@ -1326,9 +1329,13 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF if( !part ) return NULL; +#if 0 + SCH_SELECTION_TOOL* selTool = m_toolManager->GetTool(); + EDA_ITEM* item = selTool->SelectPoint( aPosition, aFilterList ); +#else LIB_ITEM* item = NULL; - m_collectedItems.Collect( part->GetDrawItems(), aFilterList, aPosition, m_unit, m_convert ); + m_collectedItems.Collect( part, aFilterList, aPosition, m_unit, m_convert ); if( m_collectedItems.GetCount() == 0 ) { @@ -1336,7 +1343,7 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF } else if( m_collectedItems.GetCount() == 1 ) { - item = m_collectedItems[0]; + item = (LIB_ITEM*) m_collectedItems[0]; } else { @@ -1363,6 +1370,7 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF m_canvas->MoveCursorToCrossHair(); item = GetDrawItem(); } +#endif if( item ) { @@ -1375,7 +1383,7 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF ClearMsgPanel(); } - return item; + return (LIB_ITEM*) item; } @@ -1453,9 +1461,9 @@ void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent ) if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END) && (index >= 0 && index < m_collectedItems.GetCount()) ) { - LIB_ITEM* item = m_collectedItems[index]; + EDA_ITEM* item = m_collectedItems[index]; m_canvas->SetAbortRequest( false ); - SetDrawItem( item ); + SetDrawItem( (LIB_ITEM*) item ); } } diff --git a/eeschema/libedit/lib_edit_frame.h b/eeschema/libedit/lib_edit_frame.h index f57cc75394..c2f25d4315 100644 --- a/eeschema/libedit/lib_edit_frame.h +++ b/eeschema/libedit/lib_edit_frame.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include class SCH_EDIT_FRAME; @@ -52,7 +52,7 @@ class LIB_EDIT_FRAME : public SCH_BASE_FRAME { LIB_PART* m_my_part; ///< a part I own, it is not in any library, but a copy could be. LIB_PART* m_tempCopyComponent; ///< temp copy of a part during edit, I own it here. - LIB_COLLECTOR m_collectedItems; ///< Used for hit testing. + SCH_COLLECTOR m_collectedItems; ///< Used for hit testing. wxComboBox* m_partSelectBox; ///< a Box to select a part to edit (if any) SYMBOL_TREE_PANE* m_treePane; ///< component search tree widget LIB_MANAGER* m_libMgr; ///< manager taking care of temporary modificatoins @@ -596,7 +596,7 @@ private: void EditGraphicSymbol( wxDC* DC, LIB_ITEM* DrawItem ); void EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem ); LIB_ITEM* LocateItemUsingCursor( const wxPoint& aPosition, - const KICAD_T aFilterList[] = LIB_COLLECTOR::AllItems ); + const KICAD_T aFilterList[] = SCH_COLLECTOR::LibItems ); void EditField( LIB_FIELD* Field ); void refreshSchematic(); diff --git a/eeschema/libedit/libedit_onleftclick.cpp b/eeschema/libedit/libedit_onleftclick.cpp index d31c1854a6..4d31fdb875 100644 --- a/eeschema/libedit/libedit_onleftclick.cpp +++ b/eeschema/libedit/libedit_onleftclick.cpp @@ -159,7 +159,7 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition ) if( !item || !item->InEditMode() ) { // We can locate an item - item = LocateItemUsingCursor( aPosition, LIB_COLLECTOR::DoubleClickItems ); + item = LocateItemUsingCursor( aPosition, SCH_COLLECTOR::LibItems ); if( item == NULL ) { diff --git a/eeschema/sch_collectors.cpp b/eeschema/sch_collectors.cpp index bc22194e93..2b9a64ecd7 100644 --- a/eeschema/sch_collectors.cpp +++ b/eeschema/sch_collectors.cpp @@ -54,6 +54,19 @@ const KICAD_T SCH_COLLECTOR::AllItems[] = { }; +const KICAD_T SCH_COLLECTOR::LibItems[] = { + LIB_ARC_T, + LIB_CIRCLE_T, + LIB_TEXT_T, + LIB_RECTANGLE_T, + LIB_POLYLINE_T, + LIB_BEZIER_T, + LIB_PIN_T, + LIB_FIELD_T, + EOT +}; + + const KICAD_T SCH_COLLECTOR::AllItemsButPins[] = { SCH_MARKER_T, SCH_JUNCTION_T, @@ -126,6 +139,17 @@ const KICAD_T SCH_COLLECTOR::SheetsAndSheetLabels[] = { SEARCH_RESULT SCH_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData ) { + if( m_Unit || m_Convert ) + { + LIB_ITEM* lib_item = dynamic_cast( aItem ); + + if( m_Unit && lib_item && lib_item->GetUnit() && lib_item->GetUnit() != m_Unit ) + return SEARCH_CONTINUE; + + if( m_Convert && lib_item && lib_item->GetConvert() != m_Convert ) + return SEARCH_CONTINUE; + } + if( aItem->HitTest( m_RefPos ) ) Append( aItem ); @@ -133,16 +157,22 @@ SEARCH_RESULT SCH_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData ) } -void SCH_COLLECTOR::Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPos ) +void SCH_COLLECTOR::Collect( EDA_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPos, + int aUnit, int aConvert ) { Empty(); // empty the collection just in case SetScanTypes( aFilterList ); + m_Unit = aUnit; + m_Convert = aConvert; // remember where the snapshot was taken from and pass refPos to the Inspect() function. SetRefPos( aPos ); - EDA_ITEM::IterateForward( aItem, m_inspector, NULL, m_ScanTypes ); + if( aItem->Type() == LIB_PART_T ) + static_cast( aItem )->Visit( m_inspector, nullptr, m_ScanTypes ); + else + EDA_ITEM::IterateForward( aItem, m_inspector, nullptr, m_ScanTypes ); } diff --git a/eeschema/sch_collectors.h b/eeschema/sch_collectors.h index da27b9fe79..39dcedfd24 100644 --- a/eeschema/sch_collectors.h +++ b/eeschema/sch_collectors.h @@ -39,6 +39,7 @@ class SCH_COLLECTOR : public COLLECTOR { public: static const KICAD_T AllItems[]; + static const KICAD_T LibItems[]; static const KICAD_T EditableItems[]; static const KICAD_T RotatableItems[]; static const KICAD_T AllItemsButPins[]; @@ -73,14 +74,17 @@ public: /** * Function Collect - * scans a SCH_ITEM using this class's Inspector method, which does the collection. - * @param aItem A SCH_ITEM to scan. + * scans a EDA_ITEM using this class's Inspector method, which does the collection. + * @param aItem A EDA_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 aPos A wxPoint to use in hit-testing. + * @param aUnit A symbol unit filter (for symbol editor) + * @param aConvert A DeMorgan filter (for symbol editor) */ - void Collect( SCH_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPos ); + void Collect( EDA_ITEM* aItem, const KICAD_T aFilterList[], const wxPoint& aPos, + int aUnit = 0, int aConvert = 0 ); /** * Function IsCorner @@ -105,6 +109,9 @@ public: bool IsDraggableJunction() const; public: + int m_Unit; // Fixed symbol unit filter (for symbol editor) + int m_Convert; // Fixed DeMorgan filter (for symbol editor) + wxString m_MenuTitle; // The title of selection disambiguation menu (if needed) bool m_MenuCancelled; // Indicates selection disambiguation menu was cancelled }; diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 619a6a962a..4f09656a88 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -60,6 +60,7 @@ #include #include #include +#include // TODO(JE) Debugging only #include @@ -235,9 +236,13 @@ bool SCH_SCREEN::CheckIfOnDrawList( SCH_ITEM* aItem ) SCH_ITEM* SCH_SCREEN::GetItem( const wxPoint& aPosition, int aAccuracy, KICAD_T aType ) const { + KICAD_T types[] = { aType, EOT }; + for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() ) { - if( (aType == SCH_FIELD_T) && (item->Type() == SCH_COMPONENT_T) ) + switch( item->Type() ) + { + case SCH_COMPONENT_T: { SCH_COMPONENT* component = (SCH_COMPONENT*) item; @@ -245,24 +250,29 @@ SCH_ITEM* SCH_SCREEN::GetItem( const wxPoint& aPosition, int aAccuracy, KICAD_T { SCH_FIELD* field = component->GetField( i ); - if( field->HitTest( aPosition, aAccuracy ) ) - return (SCH_ITEM*) field; + if( field->IsType( types ) && field->HitTest( aPosition, aAccuracy ) ) + return field; } + + break; } - else if( (aType == SCH_SHEET_PIN_T) && (item->Type() == SCH_SHEET_T) ) + case SCH_SHEET_T: { SCH_SHEET* sheet = (SCH_SHEET*)item; - SCH_SHEET_PIN* label = sheet->GetPin( aPosition ); + SCH_SHEET_PIN* pin = sheet->GetPin( aPosition ); - if( label ) - return (SCH_ITEM*) label; + if( pin && pin->IsType( types ) ) + return pin; + + break; } - else if( ( ( item->Type() == aType ) || ( aType == NOT_USED ) ) - && item->HitTest( aPosition, aAccuracy ) ) - { + default: + break; + } + + if( item->IsType( types ) && item->HitTest( aPosition, aAccuracy ) ) return item; - } } return NULL; diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index a9da7d53b9..1696f6cc56 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -217,11 +217,11 @@ public: * * @param aPosition Position in drawing units. * @param aAccuracy The maximum distance within \a Position to check for an item. - * @param aType The type of item to find or #NOT_USED to find any item type. + * @param aType The type of item to find. * @return The item found that meets the search criteria or NULL if none found. */ SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0, - KICAD_T aType = NOT_USED ) const; + KICAD_T aType = SCH_LOCATE_ANY_T ) const; void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { }; diff --git a/eeschema/tools/sch_selection_tool.cpp b/eeschema/tools/sch_selection_tool.cpp index 0f8472a2f4..6d2d1344d0 100644 --- a/eeschema/tools/sch_selection_tool.cpp +++ b/eeschema/tools/sch_selection_tool.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -152,6 +153,9 @@ SCH_SELECTION_TOOL::SCH_SELECTION_TOOL() : m_subtractive( false ), m_multiple( false ), m_skip_heuristics( false ), + m_isLibEdit( false ), + m_unit( 0 ), + m_convert( 0 ), m_menu( *this ) { } @@ -165,7 +169,16 @@ SCH_SELECTION_TOOL::~SCH_SELECTION_TOOL() bool SCH_SELECTION_TOOL::Init() { - m_frame = getEditFrame(); + m_frame = getEditFrame(); + + LIB_EDIT_FRAME* libEditFrame = dynamic_cast( m_frame ); + + if( libEditFrame ) + { + m_isLibEdit = true; + m_unit = libEditFrame->GetUnit(); + m_convert = libEditFrame->GetConvert(); + } static KICAD_T wireOrBusTypes[] = { SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, EOT }; @@ -221,7 +234,7 @@ bool SCH_SELECTION_TOOL::Init() void SCH_SELECTION_TOOL::Reset( RESET_REASON aReason ) { - m_frame = getEditFrame(); + m_frame = getEditFrame(); if( aReason == TOOL_BASE::MODEL_RELOAD ) { @@ -229,6 +242,15 @@ void SCH_SELECTION_TOOL::Reset( RESET_REASON aReason ) // properties (as they are already deleted while a new sheet is loaded) m_selection.Clear(); getView()->GetPainter()->GetSettings()->SetHighlight( false ); + + LIB_EDIT_FRAME* libEditFrame = dynamic_cast( m_frame ); + + if( libEditFrame ) + { + m_isLibEdit = true; + m_unit = libEditFrame->GetUnit(); + m_convert = libEditFrame->GetConvert(); + } } else // Restore previous properties of selected items and remove them from containers @@ -382,9 +404,15 @@ SELECTION& SCH_SELECTION_TOOL::GetSelection() EDA_ITEM* SCH_SELECTION_TOOL::SelectPoint( const VECTOR2I& aWhere, const KICAD_T* aFilterList, bool* aSelectionCancelledFlag, bool aCheckLocked ) { + EDA_ITEM* start; SCH_COLLECTOR collector; - collector.Collect( m_frame->GetScreen()->GetDrawItems(), aFilterList, (wxPoint) aWhere ); + if( m_isLibEdit ) + start = static_cast( m_frame )->GetCurPart(); + else + start = m_frame->GetScreen()->GetDrawItems(); + + collector.Collect( start, aFilterList, (wxPoint) aWhere, m_unit, m_convert ); bool anyCollected = collector.GetCount() != 0; diff --git a/eeschema/tools/sch_selection_tool.h b/eeschema/tools/sch_selection_tool.h index 6c9e7dc718..99ac46ede5 100644 --- a/eeschema/tools/sch_selection_tool.h +++ b/eeschema/tools/sch_selection_tool.h @@ -236,6 +236,10 @@ private: bool m_multiple; // Multiple selection mode is active bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor + bool m_isLibEdit; + int m_unit; // Fixed unit filter (for symbol editor) + int m_convert; // Fixed DeMorgan filter (for symbol editor) + TOOL_MENU m_menu; }; diff --git a/include/base_struct.h b/include/base_struct.h index 1985613d6f..161679726c 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -283,6 +283,9 @@ public: */ virtual bool IsType( const KICAD_T aScanTypes[] ) { + if( aScanTypes[0] == SCH_LOCATE_ANY_T ) + return true; + for( const KICAD_T* p = aScanTypes; *p != EOT; ++p ) { if( m_StructType == *p ) diff --git a/include/core/typeinfo.h b/include/core/typeinfo.h index 1dc3b3a74c..5641a2f225 100644 --- a/include/core/typeinfo.h +++ b/include/core/typeinfo.h @@ -133,6 +133,9 @@ enum KICAD_T SCH_LINE_LOCATE_WIRE_T, SCH_LINE_LOCATE_BUS_T, + // matches any type + SCH_LOCATE_ANY_T, + // General SCH_SCREEN_T,