diff --git a/cvpcb/tools/cvpcb_selection_tool.cpp b/cvpcb/tools/cvpcb_selection_tool.cpp index 90820c074f..c7d7d7c095 100644 --- a/cvpcb/tools/cvpcb_selection_tool.cpp +++ b/cvpcb/tools/cvpcb_selection_tool.cpp @@ -205,18 +205,6 @@ int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) return 0; } -const BOX2I SELECTION::ViewBBox() const -{ - return BOX2I(); -} - - -const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const -{ - return std::vector(); -} - - void CVPCB_SELECTION_TOOL::setTransitions() { Go( &CVPCB_SELECTION_TOOL::Main, CVPCB_ACTIONS::selectionActivate.MakeEvent() ); diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 9ad830681a..a777b7c002 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -226,6 +226,7 @@ set( EESCHEMA_SRCS tools/ee_inspection_tool.cpp tools/ee_picker_tool.cpp tools/ee_point_editor.cpp + tools/ee_selection.cpp tools/ee_selection_tool.cpp tools/lib_control.cpp tools/lib_drawing_tools.cpp @@ -237,7 +238,6 @@ set( EESCHEMA_SRCS tools/sch_editor_control.cpp tools/sch_wire_bus_tool.cpp tools/sch_move_tool.cpp - tools/selection.cpp ) diff --git a/eeschema/tools/ee_inspection_tool.cpp b/eeschema/tools/ee_inspection_tool.cpp index 88454f1aec..51a1fdda67 100644 --- a/eeschema/tools/ee_inspection_tool.cpp +++ b/eeschema/tools/ee_inspection_tool.cpp @@ -21,9 +21,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include -#include #include #include #include @@ -33,8 +30,11 @@ #include #include #include -#include #include +#include +#include +#include +#include #include #include #include @@ -300,7 +300,7 @@ int EE_INSPECTION_TOOL::ShowDatasheet( const TOOL_EVENT& aEvent ) } else if( m_frame->IsType( FRAME_SCH ) ) { - SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); if( selection.Empty() ) return 0; @@ -323,7 +323,7 @@ int EE_INSPECTION_TOOL::ShowDatasheet( const TOOL_EVENT& aEvent ) int EE_INSPECTION_TOOL::ShowMarkerInfo( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->GetSelection(); + EE_SELECTION& selection = m_selectionTool->GetSelection(); if( selection.Empty() ) return 0; @@ -340,7 +340,7 @@ int EE_INSPECTION_TOOL::ShowMarkerInfo( const TOOL_EVENT& aEvent ) int EE_INSPECTION_TOOL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - SELECTION& selection = selTool->GetSelection(); + EE_SELECTION& selection = selTool->GetSelection(); if( selection.GetSize() == 1 ) { diff --git a/eeschema/tools/ee_point_editor.cpp b/eeschema/tools/ee_point_editor.cpp index ad0f05ba35..4bcf9fd791 100644 --- a/eeschema/tools/ee_point_editor.cpp +++ b/eeschema/tools/ee_point_editor.cpp @@ -252,7 +252,7 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) if( !m_selectionTool ) return 0; - const SELECTION& selection = m_selectionTool->GetSelection(); + const EE_SELECTION& selection = m_selectionTool->GetSelection(); if( selection.Size() != 1 || !selection.Front()->IsType( pointTypes ) ) return 0; diff --git a/eeschema/tools/selection.cpp b/eeschema/tools/ee_selection.cpp similarity index 69% rename from eeschema/tools/selection.cpp rename to eeschema/tools/ee_selection.cpp index 578509aaea..e8ad1c6aa5 100644 --- a/eeschema/tools/selection.cpp +++ b/eeschema/tools/ee_selection.cpp @@ -22,40 +22,12 @@ */ #include - #include -#include +#include #include #include -VECTOR2I SELECTION::GetPosition() const -{ - return static_cast( GetBoundingBox().GetPosition() ); -} - - -VECTOR2I SELECTION::GetCenter() const -{ - return static_cast( GetBoundingBox().Centre() ); -} - - -EDA_RECT SELECTION::GetBoundingBox() const -{ - EDA_RECT bbox; - - bbox = Front()->GetBoundingBox(); - auto i = m_items.begin(); - ++i; - - for( ; i != m_items.end(); ++i ) - bbox.Merge( (*i)->GetBoundingBox() ); - - return bbox; -} - - -EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const +EDA_ITEM* EE_SELECTION::GetTopLeftItem( bool onlyModules ) const { EDA_ITEM* topLeftItem = nullptr; wxPoint topLeftPos; @@ -83,22 +55,3 @@ EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const return static_cast( topLeftItem ); } - - -const BOX2I SELECTION::ViewBBox() const -{ - BOX2I r; - r.SetMaximum(); - return r; -} - - -const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const -{ - std::vector items; - - for( auto item : m_items ) - items.push_back( item ); - - return items; -} diff --git a/eeschema/tools/ee_selection.h b/eeschema/tools/ee_selection.h new file mode 100644 index 0000000000..6fc8309124 --- /dev/null +++ b/eeschema/tools/ee_selection.h @@ -0,0 +1,36 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see CHANGELOG.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 EE_SELECTION_H +#define EE_SELECTION_H + +#include + + +class EE_SELECTION : public SELECTION +{ +public: + EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const override; +}; + +#endif // EE_SELECTION_H \ No newline at end of file diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index e2d02bd362..d198a1e0b2 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -460,7 +460,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } -SELECTION& EE_SELECTION_TOOL::GetSelection() +EE_SELECTION& EE_SELECTION_TOOL::GetSelection() { return m_selection; } @@ -582,7 +582,7 @@ void EE_SELECTION_TOOL::guessSelectionCandidates( EE_COLLECTOR& collector, const } -SELECTION& EE_SELECTION_TOOL::RequestSelection( const KICAD_T aFilterList[] ) +EE_SELECTION& EE_SELECTION_TOOL::RequestSelection( const KICAD_T aFilterList[] ) { // Filter an existing selection if( !m_selection.Empty() ) @@ -1125,7 +1125,7 @@ void EE_SELECTION_TOOL::unselect( EDA_ITEM* aItem ) } -void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup ) +void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup ) { KICAD_T itemType = aItem->Type(); @@ -1182,7 +1182,7 @@ void EE_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup } -void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup ) +void EE_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, EE_SELECTION* aGroup ) { KICAD_T itemType = aItem->Type(); diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index 89600444c8..e3739819c4 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -26,8 +26,8 @@ #include #include -#include #include +#include #include #include @@ -79,7 +79,7 @@ public: * * Returns the set of currently selected items. */ - SELECTION& GetSelection(); + EE_SELECTION& GetSelection(); /** * Function RequestSelection() @@ -87,7 +87,7 @@ public: * Returns either an existing selection (filtered), or the selection at the current * cursor if the existing selection is empty. */ - SELECTION& RequestSelection( const KICAD_T* aFilterList = EE_COLLECTOR::AllItems ); + EE_SELECTION& RequestSelection( const KICAD_T* aFilterList = EE_COLLECTOR::AllItems ); /** * Function selectPoint() @@ -209,7 +209,7 @@ private: * @param aHighlightMode should be either SELECTED or BRIGHTENED * @param aGroup is the group to add the item to in the BRIGHTENED mode. */ - void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ); + void highlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr ); /** * Function unhighlight() @@ -218,7 +218,7 @@ private: * @param aHighlightMode should be either SELECTED or BRIGHTENED * @param aGroup is the group to remove the item from. */ - void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ); + void unhighlight( EDA_ITEM* aItem, int aHighlightMode, EE_SELECTION* aGroup = nullptr ); /** * Sets the reference point to the anchor of the top-left item. @@ -237,18 +237,18 @@ private: void setTransitions() override; private: - SCH_BASE_FRAME* m_frame; // Pointer to the parent frame - SELECTION m_selection; // Current state of selection + SCH_BASE_FRAME* m_frame; // Pointer to the parent frame + EE_SELECTION m_selection; // Current state of selection - bool m_additive; // Items should be added to selection (instead of replacing) - bool m_subtractive; // Items should be removed from selection - bool m_multiple; // Multiple selection mode is active - bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor + bool m_additive; // Items should be added to selection (instead of replacing) + bool m_subtractive; // Items should be removed from selection + bool m_multiple; // Multiple selection mode is active + bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor - bool m_isLibEdit; // True when libedit is the parent frame - bool m_isLibView; // True when libview is the parent frame - int m_unit; // Fixed unit filter (for symbol editor) - int m_convert; // Fixed DeMorgan filter (for symbol editor) + bool m_isLibEdit; // True when libedit is the parent frame + bool m_isLibView; // True when libview is the parent frame + int m_unit; // Fixed unit filter (for symbol editor) + int m_convert; // Fixed DeMorgan filter (for symbol editor) }; #endif //KICAD_SCH_SELECTION_TOOL_H diff --git a/eeschema/tools/ee_tool_base.h b/eeschema/tools/ee_tool_base.h index 4a3ff73468..af401d3fca 100644 --- a/eeschema/tools/ee_tool_base.h +++ b/eeschema/tools/ee_tool_base.h @@ -36,7 +36,7 @@ #include -class SELECTION; +class EE_SELECTION; /** * Class EE_TOOL_BASE diff --git a/eeschema/tools/lib_edit_tool.cpp b/eeschema/tools/lib_edit_tool.cpp index 37e2d5c642..2b60477cc8 100644 --- a/eeschema/tools/lib_edit_tool.cpp +++ b/eeschema/tools/lib_edit_tool.cpp @@ -124,7 +124,7 @@ bool LIB_EDIT_TOOL::Init() int LIB_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection(); + EE_SELECTION& selection = m_selectionTool->RequestSelection(); if( selection.GetSize() == 0 ) return 0; @@ -164,7 +164,7 @@ int LIB_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) int LIB_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection(); + EE_SELECTION& selection = m_selectionTool->RequestSelection(); if( selection.GetSize() == 0 ) return 0; @@ -319,7 +319,7 @@ int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent ) int LIB_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection(); + EE_SELECTION& selection = m_selectionTool->RequestSelection(); if( selection.Empty() || aEvent.IsAction( &EE_ACTIONS::symbolProperties ) ) { @@ -550,8 +550,8 @@ int LIB_EDIT_TOOL::Cut( const TOOL_EVENT& aEvent ) int LIB_EDIT_TOOL::Copy( const TOOL_EVENT& aEvent ) { - LIB_PART* part = m_frame->GetCurPart(); - SELECTION& selection = m_selectionTool->RequestSelection( nonFields ); + LIB_PART* part = m_frame->GetCurPart(); + EE_SELECTION& selection = m_selectionTool->RequestSelection( nonFields ); if( !part || !selection.GetSize() ) return 0; @@ -591,7 +591,7 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent ) if( !part ) return 0; - SELECTION& selection = m_selectionTool->GetSelection(); + EE_SELECTION& selection = m_selectionTool->GetSelection(); std::string text = m_toolMgr->GetClipboard(); STRING_LINE_READER reader( text, "Clipboard" ); LIB_PART* newPart; @@ -641,8 +641,8 @@ int LIB_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent ) int LIB_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) { - LIB_PART* part = m_frame->GetCurPart(); - SELECTION& selection = m_selectionTool->RequestSelection( nonFields ); + LIB_PART* part = m_frame->GetCurPart(); + EE_SELECTION& selection = m_selectionTool->RequestSelection( nonFields ); if( selection.GetSize() == 0 ) return 0; diff --git a/eeschema/tools/lib_move_tool.cpp b/eeschema/tools/lib_move_tool.cpp index eed35f41ce..2c02c8fc75 100644 --- a/eeschema/tools/lib_move_tool.cpp +++ b/eeschema/tools/lib_move_tool.cpp @@ -83,8 +83,8 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can move. If there's no selection try // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection). - SELECTION& selection = m_selectionTool->RequestSelection(); - bool unselect = selection.IsHover(); + EE_SELECTION& selection = m_selectionTool->RequestSelection(); + bool unselect = selection.IsHover(); if( selection.Empty() ) return 0; @@ -297,7 +297,7 @@ void LIB_MOVE_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta ) } -bool LIB_MOVE_TOOL::updateModificationPoint( SELECTION& aSelection ) +bool LIB_MOVE_TOOL::updateModificationPoint( EE_SELECTION& aSelection ) { if( m_moveInProgress && aSelection.HasReferencePoint() ) return false; diff --git a/eeschema/tools/lib_move_tool.h b/eeschema/tools/lib_move_tool.h index 9037e0c41f..98bfc9ae29 100644 --- a/eeschema/tools/lib_move_tool.h +++ b/eeschema/tools/lib_move_tool.h @@ -55,7 +55,7 @@ private: ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. - bool updateModificationPoint( SELECTION& aSelection ); + bool updateModificationPoint( EE_SELECTION& aSelection ); ///> Sets up handlers for various events. void setTransitions() override; diff --git a/eeschema/tools/lib_pin_tool.cpp b/eeschema/tools/lib_pin_tool.cpp index 4f523aad3c..46c656a247 100644 --- a/eeschema/tools/lib_pin_tool.cpp +++ b/eeschema/tools/lib_pin_tool.cpp @@ -294,9 +294,9 @@ void LIB_PIN_TOOL::CreateImagePins( LIB_PIN* aPin ) int LIB_PIN_TOOL::PushPinProperties( const TOOL_EVENT& aEvent ) { - LIB_PART* part = m_frame->GetCurPart(); - SELECTION& selection = m_selectionTool->GetSelection(); - LIB_PIN* sourcePin = dynamic_cast( selection.Front() ); + LIB_PART* part = m_frame->GetCurPart(); + EE_SELECTION& selection = m_selectionTool->GetSelection(); + LIB_PIN* sourcePin = dynamic_cast( selection.Front() ); if( !sourcePin ) return 0; diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 9686d980ad..515f7a900f 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -173,8 +173,8 @@ bool SCH_DRAWING_TOOLS::Init() int SCH_DRAWING_TOOLS::AddJunction( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->GetSelection(); - SCH_LINE* wire = dynamic_cast( selection.Front() ); + EE_SELECTION& selection = m_selectionTool->GetSelection(); + SCH_LINE* wire = dynamic_cast( selection.Front() ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); @@ -216,7 +216,7 @@ int SCH_DRAWING_TOOLS::AddLabel( const TOOL_EVENT& aEvent ) int SCH_DRAWING_TOOLS::AddSheetPin( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->GetSelection(); + EE_SELECTION& selection = m_selectionTool->GetSelection(); SCH_SHEET* sheet = dynamic_cast( selection.Front() ); SCH_HIERLABEL* label = nullptr; @@ -771,7 +771,7 @@ int SCH_DRAWING_TOOLS::doTwoClickPlace( KICAD_T aType ) else if( item && TOOL_EVT_UTILS::IsSelectionEvent( evt.get() ) ) { // This happens if our text was replaced out from under us by ConvertTextType() - SELECTION& selection = m_selectionTool->GetSelection(); + EE_SELECTION& selection = m_selectionTool->GetSelection(); if( selection.GetSize() == 1 ) { diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 0602fbf7fa..de8b165628 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -203,7 +203,7 @@ private: void update() override { EE_SELECTION_TOOL* selTool = getToolManager()->GetTool(); - SELECTION& selection = selTool->GetSelection(); + EE_SELECTION& selection = selTool->GetSelection(); SCH_COMPONENT* component = dynamic_cast( selection.Front() ); if( !component ) @@ -450,7 +450,7 @@ bool SCH_EDIT_TOOL::Init() int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::RotatableItems ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::RotatableItems ); if( selection.GetSize() == 0 ) return 0; @@ -620,7 +620,7 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::RotatableItems ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::RotatableItems ); if( selection.GetSize() == 0 ) return 0; @@ -818,7 +818,7 @@ int SCH_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) EOT }; - SELECTION& selection = m_selectionTool->RequestSelection( duplicatableItems ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( duplicatableItems ); if( selection.GetSize() == 0 ) return 0; @@ -1079,7 +1079,7 @@ int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent ) else if( aEvent.IsAction( &EE_ACTIONS::editFootprint ) ) filter = CmpOrFootprint; - SELECTION& selection = m_selectionTool->RequestSelection( filter ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( filter ); if( selection.Empty() ) return 0; @@ -1108,7 +1108,7 @@ int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); if( selection.Empty() ) return 0; @@ -1146,7 +1146,7 @@ int SCH_EDIT_TOOL::UpdateFields( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ConvertDeMorgan( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); if( selection.Empty() ) return 0; @@ -1175,7 +1175,7 @@ int SCH_EDIT_TOOL::ConvertDeMorgan( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::EditableItems ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::EditableItems ); if( selection.Empty() ) return 0; @@ -1267,8 +1267,8 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ChangeShape( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->GetSelection(); - char shape; + EE_SELECTION& selection = m_selectionTool->GetSelection(); + char shape; if( aEvent.IsAction( &EE_ACTIONS::toShapeSlash ) ) shape = '/'; @@ -1302,9 +1302,9 @@ int SCH_EDIT_TOOL::ChangeShape( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) { - KICAD_T allTextTypes[] = { SCH_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, EOT }; - SELECTION& selection = m_selectionTool->RequestSelection( allTextTypes ); - KICAD_T convertTo; + KICAD_T allTextTypes[] = { SCH_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, EOT }; + EE_SELECTION& selection = m_selectionTool->RequestSelection( allTextTypes ); + KICAD_T convertTo; if( aEvent.IsAction( &EE_ACTIONS::toLabel ) ) convertTo = SCH_LABEL_T; @@ -1347,8 +1347,8 @@ int SCH_EDIT_TOOL::BreakWire( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::CleanupSheetPins( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::SheetsOnly ); - SCH_SHEET* sheet = (SCH_SHEET*) selection.Front(); + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::SheetsOnly ); + SCH_SHEET* sheet = (SCH_SHEET*) selection.Front(); if( !sheet ) return 0; diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 3b91c01ad5..b2a48b1787 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -332,11 +332,11 @@ int SCH_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent ) return FindAndReplace( ACTIONS::find.MakeEvent() ); } - bool searchAllSheets = !( data->GetFlags() & FR_CURRENT_SHEET_ONLY ); - SELECTION& selection = m_selectionTool->GetSelection(); - SCH_SCREEN* afterScreen = m_frame->GetScreen(); - EDA_ITEM* afterItem = selection.Front(); - EDA_ITEM* item = nullptr; + bool searchAllSheets = !( data->GetFlags() & FR_CURRENT_SHEET_ONLY ); + EE_SELECTION& selection = m_selectionTool->GetSelection(); + SCH_SCREEN* afterScreen = m_frame->GetScreen(); + EDA_ITEM* afterItem = selection.Front(); + EDA_ITEM* item = nullptr; if( wrapAroundTimer.IsRunning() ) { @@ -490,14 +490,14 @@ void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aF if( aForce ) { - SELECTION& selection = selTool->RequestSelection(); + EE_SELECTION& selection = selTool->RequestSelection(); if( selection.GetSize() >= 1 ) item = (SCH_ITEM*) selection.Front(); } else { - SELECTION& selection = selTool->GetSelection(); + EE_SELECTION& selection = selTool->GetSelection(); if( selection.GetSize() >= 1 ) item = (SCH_ITEM*) selection.Front(); @@ -861,7 +861,7 @@ int SCH_EDITOR_CONTROL::Redo( const TOOL_EVENT& aEvent ) bool SCH_EDITOR_CONTROL::doCopy() { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - SELECTION& selection = selTool->GetSelection(); + EE_SELECTION& selection = selTool->GetSelection(); if( !selection.GetSize() ) return false; @@ -1025,7 +1025,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &loadedItems ); - SELECTION& selection = selTool->GetSelection(); + EE_SELECTION& selection = selTool->GetSelection(); if( !selection.Empty() ) { @@ -1042,7 +1042,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::EditWithLibEdit( const TOOL_EVENT& aEvent ) { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); + EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); SCH_COMPONENT* sym = nullptr; LIB_EDIT_FRAME* libEdit; @@ -1126,8 +1126,8 @@ int SCH_EDITOR_CONTROL::ShowBusManager( const TOOL_EVENT& aEvent ) int SCH_EDITOR_CONTROL::EnterSheet( const TOOL_EVENT& aEvent ) { - EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - const SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SheetsOnly ); + EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + const EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SheetsOnly ); if( selection.GetSize() == 1 ) { diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 7cb2dd85bd..b64571860b 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -165,8 +165,8 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can move. If there's no selection try // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection). - SELECTION& selection = m_selectionTool->RequestSelection( movableItems ); - bool unselect = selection.IsHover(); + EE_SELECTION& selection = m_selectionTool->RequestSelection( movableItems ); + bool unselect = selection.IsHover(); if( selection.Empty() ) return 0; @@ -548,7 +548,7 @@ void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aOriginalItem, wxPoint aPoi } -void SCH_MOVE_TOOL::addJunctionsIfNeeded( SELECTION& aSelection ) +void SCH_MOVE_TOOL::addJunctionsIfNeeded( EE_SELECTION& aSelection ) { std::vector< wxPoint > pts; std::vector< wxPoint > connections; @@ -641,7 +641,7 @@ void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta, bool isDrag ) } -bool SCH_MOVE_TOOL::updateModificationPoint( SELECTION& aSelection ) +bool SCH_MOVE_TOOL::updateModificationPoint( EE_SELECTION& aSelection ) { if( m_moveInProgress && aSelection.HasReferencePoint() ) return false; diff --git a/eeschema/tools/sch_move_tool.h b/eeschema/tools/sch_move_tool.h index 20b190213b..7cfc67266e 100644 --- a/eeschema/tools/sch_move_tool.h +++ b/eeschema/tools/sch_move_tool.h @@ -58,11 +58,11 @@ private: ///> Adds junctions if needed to each item in the list after they have been ///> moved. - void addJunctionsIfNeeded( SELECTION& aSelection ); + void addJunctionsIfNeeded( EE_SELECTION& aSelection ); ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. - bool updateModificationPoint( SELECTION& aSelection ); + bool updateModificationPoint( EE_SELECTION& aSelection ); ///> Sets up handlers for various events. void setTransitions() override; diff --git a/eeschema/tools/sch_wire_bus_tool.cpp b/eeschema/tools/sch_wire_bus_tool.cpp index 912a3c8fc3..4f27f33928 100644 --- a/eeschema/tools/sch_wire_bus_tool.cpp +++ b/eeschema/tools/sch_wire_bus_tool.cpp @@ -123,7 +123,7 @@ private: SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) getToolManager()->GetEditFrame(); EE_SELECTION_TOOL* selTool = getToolManager()->GetTool(); KICAD_T busType[] = { SCH_LINE_LOCATE_BUS_T, EOT }; - SELECTION& selection = selTool->RequestSelection( busType ); + EE_SELECTION& selection = selTool->RequestSelection( busType ); SCH_LINE* bus = (SCH_LINE*) selection.Front(); Clear(); diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index f02512edad..1f4ed4b2b4 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -63,6 +63,7 @@ set( GERBVIEW_SRCS gerbview_painter.cpp tools/gerbview_actions.cpp + tools/gerbview_selection.cpp tools/gerbview_selection_tool.cpp tools/gerbview_control.cpp gerber_collectors.cpp diff --git a/gerbview/tools/gerbview_control.cpp b/gerbview/tools/gerbview_control.cpp index 3b5211df0d..acd9b6e2d6 100644 --- a/gerbview/tools/gerbview_control.cpp +++ b/gerbview/tools/gerbview_control.cpp @@ -246,7 +246,7 @@ int GERBVIEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent ) int GERBVIEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) { GERBVIEW_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - SELECTION& selection = selTool->GetSelection(); + GERBVIEW_SELECTION& selection = selTool->GetSelection(); if( selection.GetSize() == 1 ) { diff --git a/gerbview/tools/gerbview_selection.cpp b/gerbview/tools/gerbview_selection.cpp new file mode 100644 index 0000000000..406600830a --- /dev/null +++ b/gerbview/tools/gerbview_selection.cpp @@ -0,0 +1,70 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 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 3 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, see . + */ + +#include +#include +#include +#include + +VECTOR2I GERBVIEW_SELECTION::GetCenter() const +{ + VECTOR2I centre; + + if( Size() == 1 ) + { + centre = static_cast( Front() )->GetPosition(); + } + else + { + EDA_RECT bbox = Front()->GetBoundingBox(); + auto i = m_items.begin(); + ++i; + + for( ; i != m_items.end(); ++i ) + bbox.Merge( (*i)->GetBoundingBox() ); + + centre = bbox.Centre(); + } + + return centre; +} + + +const BOX2I GERBVIEW_SELECTION::ViewBBox() const +{ + EDA_RECT eda_bbox; + + if( Size() == 1 ) + { + eda_bbox = Front()->GetBoundingBox(); + } + else if( Size() > 1 ) + { + eda_bbox = Front()->GetBoundingBox(); + auto i = m_items.begin(); + ++i; + + for( ; i != m_items.end(); ++i ) + eda_bbox.Merge( (*i)->GetBoundingBox() ); + } + + return BOX2I( eda_bbox.GetOrigin(), eda_bbox.GetSize() ); +} + + diff --git a/gerbview/tools/gerbview_selection.h b/gerbview/tools/gerbview_selection.h new file mode 100644 index 0000000000..b33ac27adf --- /dev/null +++ b/gerbview/tools/gerbview_selection.h @@ -0,0 +1,38 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see CHANGELOG.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 GERBVIEW_SELECTION_H +#define GERBVIEW_SELECTION_H + +#include + + +class GERBVIEW_SELECTION : public SELECTION +{ +public: + VECTOR2I GetCenter() const override; + + const BOX2I ViewBBox() const override; +}; + +#endif // GERBVIEW_SELECTION_H \ No newline at end of file diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index 32e23377c1..77d12eea14 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2017 Jon Evans - * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2019 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 @@ -19,15 +19,12 @@ */ #include - #include using namespace std::placeholders; #include #include - #include - #include #include #include @@ -41,10 +38,8 @@ using namespace std::placeholders; #include #include #include - #include #include - #include "gerbview_selection_tool.h" #include "gerbview_actions.h" @@ -267,7 +262,7 @@ int GERBVIEW_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } -SELECTION& GERBVIEW_SELECTION_TOOL::GetSelection() +GERBVIEW_SELECTION& GERBVIEW_SELECTION_TOOL::GetSelection() { return m_selection; } @@ -868,62 +863,3 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } -VECTOR2I SELECTION::GetCenter() const -{ - VECTOR2I centre; - - if( Size() == 1 ) - { - centre = static_cast( Front() )->GetPosition(); - } - else - { - EDA_RECT bbox = Front()->GetBoundingBox(); - auto i = m_items.begin(); - ++i; - - for( ; i != m_items.end(); ++i ) - { - bbox.Merge( (*i)->GetBoundingBox() ); - } - - centre = bbox.Centre(); - } - - return centre; -} - - -const BOX2I SELECTION::ViewBBox() const -{ - EDA_RECT eda_bbox; - - if( Size() == 1 ) - { - eda_bbox = Front()->GetBoundingBox(); - } - else if( Size() > 1 ) - { - eda_bbox = Front()->GetBoundingBox(); - auto i = m_items.begin(); - ++i; - - for( ; i != m_items.end(); ++i ) - { - eda_bbox.Merge( (*i)->GetBoundingBox() ); - } - } - - return BOX2I( eda_bbox.GetOrigin(), eda_bbox.GetSize() ); -} - - -const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const -{ - std::vector items; - - for( auto item : m_items ) - items.push_back( item ); - - return items; -} diff --git a/gerbview/tools/gerbview_selection_tool.h b/gerbview/tools/gerbview_selection_tool.h index c868ad0ff0..1b24713221 100644 --- a/gerbview/tools/gerbview_selection_tool.h +++ b/gerbview/tools/gerbview_selection_tool.h @@ -18,18 +18,16 @@ * with this program. If not, see . */ -#ifndef __GERBVIEW_SELECTION_TOOL_H -#define __GERBVIEW_SELECTION_TOOL_H +#ifndef GERBVIEW_SELECTION_TOOL_H +#define GERBVIEW_SELECTION_TOOL_H #include #include - #include #include -#include #include #include - +#include #include class SELECTION_AREA; @@ -73,7 +71,7 @@ public: * * Returns the set of currently selected items. */ - SELECTION& GetSelection(); + GERBVIEW_SELECTION& GetSelection(); ///> Select a single item under cursor event handler. int CursorSelection( const TOOL_EVENT& aEvent ); @@ -215,7 +213,7 @@ private: GERBVIEW_FRAME* m_frame; /// Current state of selection. - SELECTION m_selection; + GERBVIEW_SELECTION m_selection; /// Flag saying if items should be added to the current selection or rather replace it. bool m_additive; diff --git a/include/tool/selection.h b/include/tool/selection.h index f2f0fa51b6..49e9b43aa5 100644 --- a/include/tool/selection.h +++ b/include/tool/selection.h @@ -23,11 +23,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef __SELECTION_H -#define __SELECTION_H +#ifndef SELECTION_H +#define SELECTION_H #include - +#include #include #include @@ -118,7 +118,7 @@ public: /// Checks if there is anything selected bool Empty() const { - return ( m_items.size() == 0 ); + return m_items.empty(); } /// Returns the number of selected parts @@ -131,17 +131,46 @@ public: { return m_items; } - + /// Returns the center point of the selection area bounding box. - VECTOR2I GetCenter() const; + virtual VECTOR2I GetCenter() const + { + return static_cast( GetBoundingBox().Centre() ); + } - const BOX2I ViewBBox() const override; + virtual const BOX2I ViewBBox() const override + { + BOX2I r; + r.SetMaximum(); + return r; + } /// Returns the top left point of the selection area bounding box. - VECTOR2I GetPosition() const; + VECTOR2I GetPosition() const + { + return static_cast( GetBoundingBox().GetPosition() ); + } - EDA_RECT GetBoundingBox() const; - EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const; + EDA_RECT GetBoundingBox() const + { + EDA_RECT bbox; + + bbox = Front()->GetBoundingBox(); + auto i = m_items.begin(); + ++i; + + for( ; i != m_items.end(); ++i ) + { + bbox.Merge( (*i)->GetBoundingBox() ); + } + + return bbox; + } + + virtual EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const + { + return nullptr; + } EDA_ITEM* operator[]( const size_t aIdx ) const { @@ -192,7 +221,15 @@ public: return false; } - virtual const VIEW_GROUP::ITEMS updateDrawList() const override; + virtual const VIEW_GROUP::ITEMS updateDrawList() const override + { + std::vector items; + + for( auto item : m_items ) + items.push_back( item ); + + return items; + } bool HasReferencePoint() const { @@ -214,14 +251,10 @@ public: m_referencePoint = NULLOPT; } -private: - - OPT m_referencePoint; - - /// Set of selected items +protected: + OPT m_referencePoint; std::deque m_items; - - bool m_isHover; + bool m_isHover; // mute hidden overloaded virtual function warnings using VIEW_GROUP::Add; diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt index f18fe28dc5..42a23973eb 100644 --- a/pagelayout_editor/CMakeLists.txt +++ b/pagelayout_editor/CMakeLists.txt @@ -28,13 +28,13 @@ set( PL_EDITOR_SRCS menubar.cpp toolbars_pl_editor.cpp + tools/pl_selection.cpp tools/pl_selection_tool.cpp tools/pl_drawing_tools.cpp tools/pl_edit_tool.cpp tools/pl_editor_control.cpp tools/pl_picker_tool.cpp tools/pl_point_editor.cpp - tools/selection.cpp ) set( PL_EDITOR_EXTRA_SRCS diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index a0b894def1..0770d0947f 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -113,8 +113,8 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) // Be sure that there is at least one item that we can move. If there's no selection try // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection). - SELECTION& selection = m_selectionTool->RequestSelection(); - bool unselect = selection.IsHover(); + PL_SELECTION& selection = m_selectionTool->RequestSelection(); + bool unselect = selection.IsHover(); if( selection.Empty() ) return 0; @@ -285,7 +285,7 @@ void PL_EDIT_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta ) } -bool PL_EDIT_TOOL::updateModificationPoint( SELECTION& aSelection ) +bool PL_EDIT_TOOL::updateModificationPoint( PL_SELECTION& aSelection ) { if( m_moveInProgress && aSelection.HasReferencePoint() ) return false; @@ -320,7 +320,7 @@ int PL_EDIT_TOOL::ImportWorksheetContent( const TOOL_EVENT& aEvent ) int PL_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection(); + PL_SELECTION& selection = m_selectionTool->RequestSelection(); if( selection.Size() == 0 ) return 0; @@ -412,7 +412,7 @@ int PL_EDIT_TOOL::Cut( const TOOL_EVENT& aEvent ) int PL_EDIT_TOOL::Copy( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection(); + PL_SELECTION& selection = m_selectionTool->RequestSelection(); std::vector items; WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance(); wxString sexpr; @@ -441,7 +441,7 @@ int PL_EDIT_TOOL::Copy( const TOOL_EVENT& aEvent ) int PL_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->GetSelection(); + PL_SELECTION& selection = m_selectionTool->GetSelection(); WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance(); std::string sexpr = m_toolMgr->GetClipboard(); diff --git a/pagelayout_editor/tools/pl_edit_tool.h b/pagelayout_editor/tools/pl_edit_tool.h index 87ed7f2630..3848962c67 100644 --- a/pagelayout_editor/tools/pl_edit_tool.h +++ b/pagelayout_editor/tools/pl_edit_tool.h @@ -71,7 +71,7 @@ private: ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. - bool updateModificationPoint( SELECTION& aSelection ); + bool updateModificationPoint( PL_SELECTION& aSelection ); ///> Sets up handlers for various events. void setTransitions() override; diff --git a/pagelayout_editor/tools/pl_editor_control.cpp b/pagelayout_editor/tools/pl_editor_control.cpp index daa8de2637..9cf0ffd17b 100644 --- a/pagelayout_editor/tools/pl_editor_control.cpp +++ b/pagelayout_editor/tools/pl_editor_control.cpp @@ -149,7 +149,7 @@ int PL_EDITOR_CONTROL::ToggleBackgroundColor( const TOOL_EVENT& aEvent ) int PL_EDITOR_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) { PL_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - SELECTION& selection = selTool->GetSelection(); + PL_SELECTION& selection = selTool->GetSelection(); // The Properties frame will be updated. Avoid flicker during update: m_frame->GetPropertiesFrame()->Freeze(); diff --git a/pagelayout_editor/tools/pl_point_editor.cpp b/pagelayout_editor/tools/pl_point_editor.cpp index a9d5111fb0..2cc03f3741 100644 --- a/pagelayout_editor/tools/pl_point_editor.cpp +++ b/pagelayout_editor/tools/pl_point_editor.cpp @@ -150,7 +150,7 @@ int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent ) if( !m_selectionTool ) return 0; - const SELECTION& selection = m_selectionTool->GetSelection(); + const PL_SELECTION& selection = m_selectionTool->GetSelection(); if( selection.Size() != 1 || !selection.Front()->IsType( pointTypes ) ) return 0; diff --git a/pagelayout_editor/tools/selection.cpp b/pagelayout_editor/tools/pl_selection.cpp similarity index 70% rename from pagelayout_editor/tools/selection.cpp rename to pagelayout_editor/tools/pl_selection.cpp index 747578c1bf..39a7adff3e 100644 --- a/pagelayout_editor/tools/selection.cpp +++ b/pagelayout_editor/tools/pl_selection.cpp @@ -21,40 +21,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include - -#include -#include +#include #include -VECTOR2I SELECTION::GetPosition() const -{ - return static_cast( GetBoundingBox().GetPosition() ); -} - -VECTOR2I SELECTION::GetCenter() const -{ - return static_cast( GetBoundingBox().Centre() ); -} - - -EDA_RECT SELECTION::GetBoundingBox() const -{ - EDA_RECT bbox; - - bbox = Front()->GetBoundingBox(); - auto i = m_items.begin(); - ++i; - - for( ; i != m_items.end(); ++i ) - bbox.Merge( (*i)->GetBoundingBox() ); - - return bbox; -} - - -EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const +EDA_ITEM* PL_SELECTION::GetTopLeftItem( bool onlyModules ) const { WS_DRAW_ITEM_BASE* topLeftItem = nullptr; EDA_RECT topLeftItemBB; @@ -86,21 +57,3 @@ EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const return static_cast( topLeftItem ); } - -const BOX2I SELECTION::ViewBBox() const -{ - BOX2I r; - r.SetMaximum(); - return r; -} - - -const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const -{ - std::vector items; - - for( auto item : m_items ) - items.push_back( item ); - - return items; -} diff --git a/pagelayout_editor/tools/pl_selection.h b/pagelayout_editor/tools/pl_selection.h new file mode 100644 index 0000000000..a92aac92f4 --- /dev/null +++ b/pagelayout_editor/tools/pl_selection.h @@ -0,0 +1,36 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see CHANGELOG.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 PL_SELECTION_H +#define PL_SELECTION_H + +#include + + +class PL_SELECTION : public SELECTION +{ +public: + EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const override; +}; + +#endif // PL_SELECTION_H \ No newline at end of file diff --git a/pagelayout_editor/tools/pl_selection_tool.cpp b/pagelayout_editor/tools/pl_selection_tool.cpp index c0a91003fa..1e6f7b7d96 100644 --- a/pagelayout_editor/tools/pl_selection_tool.cpp +++ b/pagelayout_editor/tools/pl_selection_tool.cpp @@ -227,7 +227,7 @@ int PL_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } -SELECTION& PL_SELECTION_TOOL::GetSelection() +PL_SELECTION& PL_SELECTION_TOOL::GetSelection() { return m_selection; } @@ -307,7 +307,7 @@ void PL_SELECTION_TOOL::guessSelectionCandidates( COLLECTOR& collector, const VE } -SELECTION& PL_SELECTION_TOOL::RequestSelection() +PL_SELECTION& PL_SELECTION_TOOL::RequestSelection() { // If nothing is selected do a hover selection if( m_selection.Empty() ) @@ -660,7 +660,7 @@ void PL_SELECTION_TOOL::unselect( EDA_ITEM* aItem ) } -void PL_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup ) +void PL_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, PL_SELECTION* aGroup ) { if( aMode == SELECTED ) aItem->SetSelected(); @@ -674,7 +674,7 @@ void PL_SELECTION_TOOL::highlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup } -void PL_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, SELECTION* aGroup ) +void PL_SELECTION_TOOL::unhighlight( EDA_ITEM* aItem, int aMode, PL_SELECTION* aGroup ) { if( aMode == SELECTED ) aItem->ClearSelected(); diff --git a/pagelayout_editor/tools/pl_selection_tool.h b/pagelayout_editor/tools/pl_selection_tool.h index 962ca8c9aa..42903bf767 100644 --- a/pagelayout_editor/tools/pl_selection_tool.h +++ b/pagelayout_editor/tools/pl_selection_tool.h @@ -25,9 +25,8 @@ #define PL_SELECTION_TOOL_H #include -#include #include -#include +#include class PL_EDITOR_FRAME; class SCH_ITEM; @@ -72,7 +71,7 @@ public: * * Returns the set of currently selected items. */ - SELECTION& GetSelection(); + PL_SELECTION& GetSelection(); /** * Function RequestSelection() @@ -80,7 +79,7 @@ public: * Returns either an existing selection (filtered), or the selection at the current * cursor if the existing selection is empty. */ - SELECTION& RequestSelection(); + PL_SELECTION& RequestSelection(); /** * Function selectPoint() @@ -178,7 +177,7 @@ private: * @param aHighlightMode should be either SELECTED or BRIGHTENED * @param aGroup is the group to add the item to in the BRIGHTENED mode. */ - void highlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ); + void highlight( EDA_ITEM* aItem, int aHighlightMode, PL_SELECTION* aGroup = nullptr ); /** * Function unhighlight() @@ -187,7 +186,7 @@ private: * @param aHighlightMode should be either SELECTED or BRIGHTENED * @param aGroup is the group to remove the item from. */ - void unhighlight( EDA_ITEM* aItem, int aHighlightMode, SELECTION* aGroup = nullptr ); + void unhighlight( EDA_ITEM* aItem, int aHighlightMode, PL_SELECTION* aGroup = nullptr ); /** * Function selectionContains() @@ -202,7 +201,7 @@ private: private: PL_EDITOR_FRAME* m_frame; // Pointer to the parent frame - SELECTION m_selection; // Current state of selection + PL_SELECTION m_selection; // Current state of selection bool m_additive; // Items should be added to selection (instead of replacing) bool m_subtractive; // Items should be removed from selection diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 967e70d7f7..2ed5c5f23d 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -305,10 +305,10 @@ set( PCBNEW_CLASS_SRCS tools/pcb_tool_base.cpp tools/pcbnew_control.cpp tools/pcbnew_picker_tool.cpp + tools/pcbnew_selection.cpp tools/placement_tool.cpp tools/point_editor.cpp tools/position_relative_tool.cpp - tools/selection.cpp tools/selection_tool.cpp tools/tool_event_utils.cpp tools/zone_create_helper.cpp diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index d8dfc9cad0..94d5352714 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -538,7 +538,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) GRID_HELPER grid( m_frame ); // Add a VIEW_GROUP that serves as a preview for the new item - SELECTION preview; + PCBNEW_SELECTION preview; m_view->Add( &preview ); @@ -802,7 +802,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) m_frame->SetNoToolSelected(); // Add a VIEW_GROUP that serves as a preview for the new item - SELECTION preview; + PCBNEW_SELECTION preview; BOARD_COMMIT commit( m_frame ); // Build the undo list & add items to the current view @@ -975,7 +975,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPTSetActiveLayer( getDrawingLayer() ); // Add a VIEW_GROUP that serves as a preview for the new item - SELECTION preview; + PCBNEW_SELECTION preview; m_view->Add( &preview ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); @@ -1209,7 +1209,7 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic ) KIGFX::PREVIEW::ARC_ASSISTANT arcAsst( arcManager, m_frame->GetUserUnits() ); // Add a VIEW_GROUP that serves as a preview for the new item - SELECTION preview; + PCBNEW_SELECTION preview; m_view->Add( &preview ); m_view->Add( &arcAsst ); GRID_HELPER grid( m_frame ); @@ -1341,8 +1341,8 @@ bool DRAWING_TOOL::getSourceZoneForAction( ZONE_MODE aMode, ZONE_CONTAINER*& aZo if( aMode == ZONE_MODE::ADD || aMode == ZONE_MODE::GRAPHIC_POLYGON ) return true; - SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - const SELECTION& selection = selTool->GetSelection(); + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + const PCBNEW_SELECTION& selection = selTool->GetSelection(); if( selection.Empty() ) { diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index a6ab2e581b..86434e6b5d 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -579,7 +579,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) return 0; } -bool EDIT_TOOL::changeTrackWidthOnClick( const SELECTION& selection ) +bool EDIT_TOOL::changeTrackWidthOnClick( const PCBNEW_SELECTION& selection ) { if ( selection.Size() == 1 && frame()->Settings().g_EditHotkeyChangesTrackWidth ) { @@ -875,7 +875,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) std::vector lockedItems; // get a copy instead of reference (as we're going to clear the selection before removing items) - SELECTION selectionCopy; + PCBNEW_SELECTION selectionCopy; bool isCut = aEvent.Parameter() == static_cast( PCB_ACTIONS::REMOVE_FLAGS::CUT ); bool isAlt = aEvent.Parameter() == static_cast( PCB_ACTIONS::REMOVE_FLAGS::ALT ); @@ -1273,7 +1273,7 @@ int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) } -bool EDIT_TOOL::updateModificationPoint( SELECTION& aSelection ) +bool EDIT_TOOL::updateModificationPoint( PCBNEW_SELECTION& aSelection ) { if( m_dragging && aSelection.HasReferencePoint() ) return false; @@ -1375,7 +1375,7 @@ int EDIT_TOOL::doCopyToClipboard( bool withAnchor ) Activate(); - SELECTION& selection = m_selectionTool->RequestSelection( + PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); } ); diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index dcae3df4d8..37daf9f545 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -202,14 +202,14 @@ private: ///> Returns the right modification point (e.g. for rotation), depending on the number of ///> selected items. - bool updateModificationPoint( SELECTION& aSelection ); + bool updateModificationPoint( PCBNEW_SELECTION& aSelection ); int EditFpInFpEditor( const TOOL_EVENT& aEvent ); bool invokeInlineRouter( int aDragMode ); bool isInteractiveDragEnabled() const; - bool changeTrackWidthOnClick( const SELECTION& selection ); + bool changeTrackWidthOnClick( const PCBNEW_SELECTION& selection ); bool pickCopyReferencePoint( VECTOR2I& aP ); std::unique_ptr m_commit; diff --git a/pcbnew/tools/footprint_editor_tools.cpp b/pcbnew/tools/footprint_editor_tools.cpp index af01bd6cea..c8dd6d5935 100644 --- a/pcbnew/tools/footprint_editor_tools.cpp +++ b/pcbnew/tools/footprint_editor_tools.cpp @@ -615,8 +615,8 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) int MODULE_EDITOR_TOOLS::ExplodePadToShapes( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); - BOARD_COMMIT commit( m_frame ); + PCBNEW_SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); + BOARD_COMMIT commit( m_frame ); if( selection.Size() != 1 ) return 0; @@ -664,7 +664,7 @@ int MODULE_EDITOR_TOOLS::ExplodePadToShapes( const TOOL_EVENT& aEvent ) int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); + PCBNEW_SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); std::unique_ptr pad( new D_PAD( board()->GetFirstModule() ) ); D_PAD *refPad = nullptr; diff --git a/pcbnew/tools/global_edit_tool.cpp b/pcbnew/tools/global_edit_tool.cpp index ffbe8ab70b..71509f5106 100644 --- a/pcbnew/tools/global_edit_tool.cpp +++ b/pcbnew/tools/global_edit_tool.cpp @@ -109,10 +109,10 @@ bool GLOBAL_EDIT_TOOL::Init() int GLOBAL_EDIT_TOOL::ExchangeFootprints( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( EDIT_TOOL::FootprintFilter ); - MODULE* mod = (selection.Empty() ? nullptr : selection.FirstOfKind () ); - bool updateMode = false; - bool currentMode = false; + PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( EDIT_TOOL::FootprintFilter ); + MODULE* mod = (selection.Empty() ? nullptr : selection.FirstOfKind () ); + bool updateMode = false; + bool currentMode = false; if( aEvent.IsAction( &PCB_ACTIONS::updateFootprint ) ) { diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 6f9281ee7c..2c232a52c2 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -30,16 +30,15 @@ #include #include #include - #include #include #include - #include -#include "pcb_actions.h" -#include "selection_tool.h" -#include "pcb_selection_conditions.h" -#include "edit_tool.h" +#include +#include +#include +#include +#include #include "pcbnew_id.h" // Pad tools @@ -128,7 +127,7 @@ private: void update() override { auto selTool = getToolManager()->GetTool(); - const SELECTION& selection = selTool->GetSelection(); + const PCBNEW_SELECTION& selection = selTool->GetSelection(); auto enablements = getEnablements( selection ); diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 8633a0dd39..7add1d634f 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -829,8 +829,8 @@ int PCB_EDITOR_CONTROL::UnlockSelected( const TOOL_EVENT& aEvent ) int PCB_EDITOR_CONTROL::modifyLockSelected( MODIFY_MODE aMode ) { - SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - const SELECTION& selection = selTool->GetSelection(); + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + const PCBNEW_SELECTION& selection = selTool->GetSelection(); if( selection.Empty() ) m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true ); @@ -999,9 +999,9 @@ static bool mergeZones( BOARD_COMMIT& aCommit, std::vector& aO int PCB_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent ) { - const SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); - BOARD* board = getModel(); - BOARD_COMMIT commit( m_frame ); + const PCBNEW_SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); + BOARD* board = getModel(); + BOARD_COMMIT commit( m_frame ); if( selection.Size() < 2 ) return 0; @@ -1115,8 +1115,8 @@ int PCB_EDITOR_CONTROL::CrossProbePcbToSch( const TOOL_EVENT& aEvent ) return 0; } - SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - const SELECTION& selection = selTool->GetSelection(); + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + const PCBNEW_SELECTION& selection = selTool->GetSelection(); if( selection.Size() == 1 ) m_frame->SendMessageToEESCHEMA( static_cast( selection.Front() ) ); @@ -1217,7 +1217,7 @@ static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition, { auto selectionTool = aToolMgr->GetTool(); - const SELECTION& selection = selectionTool->GetSelection(); + const PCBNEW_SELECTION& selection = selectionTool->GetSelection(); for( auto item : selection ) { @@ -1381,7 +1381,7 @@ static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, const VECT aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, EDIT_TOOL::PadFilter ); - SELECTION& selection = selectionTool->GetSelection(); + PCBNEW_SELECTION& selection = selectionTool->GetSelection(); if( selection.Empty() ) { diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 16c534065b..752bd1e7f0 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -50,7 +50,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer controls()->SetSnapping( true ); // Add a VIEW_GROUP that serves as a preview for the new item - SELECTION preview; + PCBNEW_SELECTION preview; view()->Add( &preview ); aPlacer->m_board = board(); @@ -246,7 +246,7 @@ PCB_DRAW_PANEL_GAL* PCB_TOOL_BASE::canvas() const } -const SELECTION& PCB_TOOL_BASE::selection() const +const PCBNEW_SELECTION& PCB_TOOL_BASE::selection() const { auto selTool = m_toolMgr->GetTool(); const auto& selection = selTool->GetSelection(); @@ -254,7 +254,7 @@ const SELECTION& PCB_TOOL_BASE::selection() const } -SELECTION& PCB_TOOL_BASE::selection() +PCBNEW_SELECTION& PCB_TOOL_BASE::selection() { auto selTool = m_toolMgr->GetTool(); auto& selection = selTool->GetSelection(); diff --git a/pcbnew/tools/pcb_tool_base.h b/pcbnew/tools/pcb_tool_base.h index d0702feb5b..4d5a1a6cb6 100644 --- a/pcbnew/tools/pcb_tool_base.h +++ b/pcbnew/tools/pcb_tool_base.h @@ -47,7 +47,7 @@ class PCB_TOOL_BASE; class PCB_EDIT_FRAME; class PCB_DISPLAY_OPTIONS; -class SELECTION; +class PCBNEW_SELECTION; struct INTERACTIVE_PLACER_BASE { @@ -144,8 +144,8 @@ protected: } PCB_DISPLAY_OPTIONS* displayOptions() const; PCB_DRAW_PANEL_GAL* canvas() const; - const SELECTION& selection() const; - SELECTION& selection(); + const PCBNEW_SELECTION& selection() const; + PCBNEW_SELECTION& selection(); bool m_editModules; }; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 558bf0caf2..fef67360c2 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -633,7 +633,7 @@ static bool deleteItem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition ) aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - const SELECTION& selection = selectionTool->RequestSelection( + const PCBNEW_SELECTION& selection = selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED ); } ); @@ -842,7 +842,7 @@ int PCBNEW_CONTROL::placeBoardItems( std::vector& aItems, bool aIsN auto selectionTool = m_toolMgr->GetTool(); auto editTool = m_toolMgr->GetTool(); - SELECTION& selection = selectionTool->GetSelection(); + PCBNEW_SELECTION& selection = selectionTool->GetSelection(); for( auto item : aItems ) { @@ -1019,8 +1019,8 @@ void PCBNEW_CONTROL::updateGrid() int PCBNEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) { - SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - SELECTION& selection = selTool->GetSelection(); + SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + PCBNEW_SELECTION& selection = selTool->GetSelection(); if( selection.GetSize() == 1 ) { diff --git a/pcbnew/tools/pcbnew_picker_tool.cpp b/pcbnew/tools/pcbnew_picker_tool.cpp index e65302ce05..1515f32bfb 100644 --- a/pcbnew/tools/pcbnew_picker_tool.cpp +++ b/pcbnew/tools/pcbnew_picker_tool.cpp @@ -110,7 +110,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_RIGHT ) ) { - SELECTION dummy; + PCBNEW_SELECTION dummy; m_menu.ShowContextMenu( dummy ); } diff --git a/pcbnew/tools/selection.cpp b/pcbnew/tools/pcbnew_selection.cpp similarity index 80% rename from pcbnew/tools/selection.cpp rename to pcbnew/tools/pcbnew_selection.cpp index e12d6a3d34..9b0b36b557 100644 --- a/pcbnew/tools/selection.cpp +++ b/pcbnew/tools/pcbnew_selection.cpp @@ -36,58 +36,26 @@ using namespace std::placeholders; #include #include #include - #include - #include #include #include #include #include #include -#include - #include #include +#include #include - #include "selection_tool.h" #include "pcb_bright_box.h" #include "pcb_actions.h" #include "kicad_plugin.h" -// TODO(JE) Only works for BOARD_ITEM -VECTOR2I SELECTION::GetPosition() const -{ - return static_cast( GetBoundingBox().GetPosition() ); -} -VECTOR2I SELECTION::GetCenter() const -{ - return static_cast( GetBoundingBox().Centre() ); -} - - -EDA_RECT SELECTION::GetBoundingBox() const -{ - EDA_RECT bbox; - - bbox = Front()->GetBoundingBox(); - auto i = m_items.begin(); - ++i; - - for( ; i != m_items.end(); ++i ) - { - bbox.Merge( (*i)->GetBoundingBox() ); - } - - return bbox; -} - - -EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const +EDA_ITEM* PCBNEW_SELECTION::GetTopLeftItem( bool onlyModules ) const { BOARD_ITEM* topLeftItem = nullptr; BOARD_ITEM* currentItem; @@ -123,15 +91,7 @@ EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const } -const BOX2I SELECTION::ViewBBox() const -{ - BOX2I r; - r.SetMaximum(); - return r; -} - - -const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const +const KIGFX::VIEW_GROUP::ITEMS PCBNEW_SELECTION::updateDrawList() const { std::vector items; diff --git a/pcbnew/tools/pcbnew_selection.h b/pcbnew/tools/pcbnew_selection.h new file mode 100644 index 0000000000..c8b7059aee --- /dev/null +++ b/pcbnew/tools/pcbnew_selection.h @@ -0,0 +1,38 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see CHANGELOG.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 PCBNEW_SELECTION_H +#define PCBNEW_SELECTION_H + +#include + + +class PCBNEW_SELECTION : public SELECTION +{ +public: + EDA_ITEM* GetTopLeftItem( bool onlyModules = false ) const override; + + const KIGFX::VIEW_GROUP::ITEMS updateDrawList() const override; +}; + +#endif // PCBNEW_SELECTION_H \ No newline at end of file diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index 5144144998..57f52ca3e6 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -184,7 +184,7 @@ template< typename T > size_t ALIGN_DISTRIBUTE_TOOL::GetSelections( ALIGNMENT_RECTS& aItems, ALIGNMENT_RECTS& aLocked, T aCompare ) { - SELECTION& selection = m_selectionTool->RequestSelection( + PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } ); @@ -435,7 +435,7 @@ int ALIGN_DISTRIBUTE_TOOL::AlignCenterY( const TOOL_EVENT& aEvent ) int ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( + PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } ); @@ -537,7 +537,7 @@ void ALIGN_DISTRIBUTE_TOOL::doDistributeCentersHorizontally( ALIGNMENT_RECTS &it int ALIGN_DISTRIBUTE_TOOL::DistributeVertically( const TOOL_EVENT& aEvent ) { - SELECTION& selection = m_selectionTool->RequestSelection( + PCBNEW_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED | EXCLUDE_TRANSIENTS ); } ); diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 20f60db4c9..81ba5c85d0 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -301,7 +301,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) if( !m_selectionTool ) return 0; - const SELECTION& selection = m_selectionTool->GetSelection(); + const PCBNEW_SELECTION& selection = m_selectionTool->GetSelection(); if( selection.Size() != 1 ) return 0; diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index bd964ed59e..ea7a38e03a 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -150,7 +150,7 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent picker->SetClickHandler( [&]( const VECTOR2D& aPoint ) -> bool { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - const SELECTION& sel = m_selectionTool->RequestSelection( + const PCBNEW_SELECTION& sel = m_selectionTool->RequestSelection( []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } ); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 035208956f..b5fb4f1fce 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -41,7 +41,6 @@ using namespace std::placeholders; #include #include #include - #include #include #include @@ -56,7 +55,6 @@ using namespace std::placeholders; #include #include #include "tool_event_utils.h" - #include "selection_tool.h" #include "pcb_bright_box.h" #include "pcb_actions.h" @@ -381,13 +379,13 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } -SELECTION& SELECTION_TOOL::GetSelection() +PCBNEW_SELECTION& SELECTION_TOOL::GetSelection() { return m_selection; } -SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aClientFilter, +PCBNEW_SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aClientFilter, std::vector* aFiltered, bool aConfirmLockedItems ) { bool selectionEmpty = m_selection.Empty(); @@ -1392,9 +1390,9 @@ int SELECTION_TOOL::SelectionMenu( const TOOL_EVENT& aEvent ) bool SELECTION_TOOL::doSelectionMenu( GENERAL_COLLECTOR* aCollector, const wxString& aTitle ) { - BOARD_ITEM* current = nullptr; - SELECTION highlightGroup; - ACTION_MENU menu; + BOARD_ITEM* current = nullptr; + PCBNEW_SELECTION highlightGroup; + ACTION_MENU menu; highlightGroup.SetLayer( LAYER_SELECT_OVERLAY ); getView()->Add( &highlightGroup ); @@ -1763,7 +1761,7 @@ void SELECTION_TOOL::unselect( BOARD_ITEM* aItem ) } -void SELECTION_TOOL::highlight( BOARD_ITEM* aItem, int aMode, SELECTION& aGroup ) +void SELECTION_TOOL::highlight( BOARD_ITEM* aItem, int aMode, PCBNEW_SELECTION& aGroup ) { if( aMode == SELECTED ) aItem->SetSelected(); @@ -1799,7 +1797,7 @@ void SELECTION_TOOL::highlight( BOARD_ITEM* aItem, int aMode, SELECTION& aGroup } -void SELECTION_TOOL::unhighlight( BOARD_ITEM* aItem, int aMode, SELECTION& aGroup ) +void SELECTION_TOOL::unhighlight( BOARD_ITEM* aItem, int aMode, PCBNEW_SELECTION& aGroup ) { if( aMode == SELECTED ) aItem->ClearSelected(); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index b0d75ebde9..8a824429a9 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -32,8 +32,7 @@ #include #include #include -#include - +#include #include #include @@ -85,7 +84,7 @@ public: * * Returns the set of currently selected items. */ - SELECTION& GetSelection(); + PCBNEW_SELECTION& GetSelection(); /** * Function RequestSelection() @@ -95,7 +94,7 @@ public: * If the set is empty, performs the legacy-style hover selection. * @param aFiltered is an optional vector, that is filled with items removed by the filter */ - SELECTION& RequestSelection( CLIENT_SELECTION_FILTER aClientFilter, + PCBNEW_SELECTION& RequestSelection( CLIENT_SELECTION_FILTER aClientFilter, std::vector* aFiltered = nullptr, bool aConfirmLockedItems = false ); ///> Checks if the user has agreed to modify locked items for the given selection. @@ -298,7 +297,7 @@ private: * @param aHighlightMode should be either SELECTED or BRIGHTENED * @param aGroup is the group to add the item to in the BRIGHTENED mode. */ - void highlight( BOARD_ITEM* aItem, int aHighlightMode, SELECTION& aGroup ); + void highlight( BOARD_ITEM* aItem, int aHighlightMode, PCBNEW_SELECTION& aGroup ); /** * Function unhighlight() @@ -307,7 +306,7 @@ private: * @param aHighlightMode should be either SELECTED or BRIGHTENED * @param aGroup is the group to remove the item from. */ - void unhighlight( BOARD_ITEM* aItem, int aHighlightMode, SELECTION& aGroup ); + void unhighlight( BOARD_ITEM* aItem, int aHighlightMode, PCBNEW_SELECTION& aGroup ); /** * Function selectionContains() @@ -339,14 +338,14 @@ private: const GENERAL_COLLECTORS_GUIDE getCollectorsGuide() const; private: - PCB_BASE_FRAME* m_frame; // Pointer to the parent frame - SELECTION m_selection; // Current state of selection + PCB_BASE_FRAME* m_frame; // Pointer to the parent frame + PCBNEW_SELECTION m_selection; // Current state of selection - bool m_additive; // Items should be added to selection (instead of replacing) - bool m_subtractive; // Items should be removed from selection - bool m_multiple; // Multiple selection mode is active - bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor - bool m_locked; // Other tools are not allowed to modify locked items + bool m_additive; // Items should be added to selection (instead of replacing) + bool m_subtractive; // Items should be removed from selection + bool m_multiple; // Multiple selection mode is active + bool m_skip_heuristics; // Heuristics are not allowed when choosing item under cursor + bool m_locked; // Other tools are not allowed to modify locked items /// Private state (opaque pointer/compilation firewall) class PRIV; diff --git a/qa/gal/gal_pixel_alignment/CMakeLists.txt b/qa/gal/gal_pixel_alignment/CMakeLists.txt index c3d4d32a3e..f680e93939 100644 --- a/qa/gal/gal_pixel_alignment/CMakeLists.txt +++ b/qa/gal/gal_pixel_alignment/CMakeLists.txt @@ -39,7 +39,7 @@ add_executable(test_gal_pixel_alignment WIN32 ../../qa_utils/mocks.cpp ../../../common/base_units.cpp ../../../pcbnew/tools/pcb_tool_base.cpp - ../../../pcbnew/tools/selection.cpp + ../../../pcbnew/tools/pcbnew_selection.cpp ../../../pcbnew/tools/selection_tool.cpp ../../../pcbnew/tools/tool_event_utils.cpp #../../pcbnew/tools/outline_editor.cpp