Browse Source

sch: add group tool

revert-0c36e162
Mike Williams 9 months ago
parent
commit
d6e7970738
  1. 1
      common/eda_item.cpp
  2. 1
      eeschema/CMakeLists.txt
  3. 2
      eeschema/sch_edit_frame.cpp
  4. 4
      eeschema/sch_group.cpp
  5. 2
      eeschema/sch_group.h
  6. 168
      eeschema/tools/sch_group_tool.cpp
  7. 17
      eeschema/tools/sch_group_tool.h

1
common/eda_item.cpp

@ -433,6 +433,7 @@ static struct EDA_ITEM_DESC
.Map( SCH_PIN_T, _HKI( "Pin" ) )
.Map( SCH_SHEET_PIN_T, _HKI( "Sheet Pin" ) )
.Map( SCH_SHEET_T, _HKI( "Sheet" ) )
.Map( SCH_GROUP_T, _HKI( "Group" ) )
// Synthetic search tokens don't need to be included...
//.Map( SCH_FIELD_LOCATE_REFERENCE_T, _HKI( "Field Locate Reference" ) )

1
eeschema/CMakeLists.txt

@ -453,6 +453,7 @@ set( EESCHEMA_SRCS
tools/sch_editor_control.cpp
tools/sch_editor_conditions.cpp
tools/sch_find_replace_tool.cpp
tools/sch_group_tool.cpp
tools/sch_inspection_tool.cpp
tools/sch_line_wire_bus_tool.cpp
tools/sch_move_tool.cpp

2
eeschema/sch_edit_frame.cpp

@ -84,6 +84,7 @@
#include <tools/sch_edit_table_tool.h>
#include <tools/sch_editor_conditions.h>
#include <tools/sch_editor_control.h>
#include <tools/sch_group_tool.h>
#include <tools/sch_line_wire_bus_tool.h>
#include <tools/sch_move_tool.h>
#include <tools/sch_navigate_tool.h>
@ -542,6 +543,7 @@ void SCH_EDIT_FRAME::setupTools()
m_toolManager->RegisterTool( new SCH_MOVE_TOOL );
m_toolManager->RegisterTool( new SCH_EDIT_TOOL );
m_toolManager->RegisterTool( new SCH_EDIT_TABLE_TOOL );
m_toolManager->RegisterTool( new SCH_GROUP_TOOL );
m_toolManager->RegisterTool( new SCH_INSPECTION_TOOL );
m_toolManager->RegisterTool( new SCH_DESIGN_BLOCK_CONTROL );
m_toolManager->RegisterTool( new SCH_EDITOR_CONTROL );

4
eeschema/sch_group.cpp

@ -26,6 +26,7 @@
#include <geometry/shape_compound.h>
#include <sch_item.h>
#include <sch_group.h>
#include <sch_screen.h>
#include <sch_symbol.h>
#include <symbol.h>
#include <confirm.h>
@ -42,6 +43,9 @@ SCH_GROUP::SCH_GROUP( SCH_ITEM* aParent ) : SCH_ITEM( aParent, SCH_GROUP_T )
{
}
SCH_GROUP::SCH_GROUP( SCH_SCREEN* aParent ) : SCH_ITEM( aParent, SCH_GROUP_T )
{
}
bool SCH_GROUP::IsGroupableType( KICAD_T aType )
{

2
eeschema/sch_group.h

@ -55,6 +55,8 @@ public:
SCH_GROUP( SCH_ITEM* aParent );
SCH_GROUP( SCH_SCREEN* aParent );
EDA_ITEM* AsEdaItem() override { return this; }
static inline bool ClassOf( const EDA_ITEM* aItem ) { return aItem && SCH_GROUP_T == aItem->Type(); }

168
eeschema/tools/sch_group_tool.cpp

@ -0,0 +1,168 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The 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 <tool/actions.h>
#include <frame_type.h>
#include <eda_draw_frame.h>
#include <symbol_edit_frame.h>
#include <sch_edit_frame.h>
#include <sch_screen.h>
#include <kiplatform/ui.h>
#include <tool/tool_manager.h>
#include <tool/picker_tool.h>
#include <tools/sch_group_tool.h>
#include <tools/sch_selection_tool.h>
#include <status_popup.h>
#include <sch_commit.h>
#include <dialogs/dialog_group_properties.h>
#include <sch_group.h>
#include <symbol.h>
int SCH_GROUP_TOOL::PickNewMember( const TOOL_EVENT& aEvent )
{
bool isSymbolEditor = m_frame->GetFrameType() == FRAME_SCH_SYMBOL_EDITOR;
SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
STATUS_TEXT_POPUP statusPopup( m_frame );
bool done = false;
if( m_propertiesDialog )
m_propertiesDialog->Show( false );
Activate();
statusPopup.SetText( _( "Click on new member..." ) );
picker->SetClickHandler(
[&]( const VECTOR2D& aPoint ) -> bool
{
m_toolMgr->RunAction( ACTIONS::selectionClear );
const SCH_SELECTION& sel = selTool->RequestSelection();
if( sel.Empty() )
return true; // still looking for an item
statusPopup.Hide();
if( m_propertiesDialog )
{
EDA_ITEM* elem = sel.Front();
if( !isSymbolEditor )
{
while( elem->GetParent() && elem->GetParent()->Type() != SCHEMATIC_T )
elem = elem->GetParent();
}
m_propertiesDialog->DoAddMember( elem );
m_propertiesDialog->Show( true );
}
return false; // got our item; don't need any more
} );
picker->SetMotionHandler(
[&]( const VECTOR2D& aPos )
{
statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, -50 ) );
} );
picker->SetCancelHandler(
[&]()
{
if( m_propertiesDialog )
m_propertiesDialog->Show( true );
statusPopup.Hide();
} );
picker->SetFinalizeHandler(
[&]( const int& aFinalState )
{
done = true;
} );
statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, -50 ) );
statusPopup.Popup();
m_frame->GetCanvas()->SetStatusPopup( statusPopup.GetPanel() );
m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
while( !done )
{
// Pass events unless we receive a null event, then we must shut down
if( TOOL_EVENT* evt = Wait() )
evt->SetPassEvent();
else
break;
}
m_frame->GetCanvas()->SetStatusPopup( nullptr );
return 0;
}
int SCH_GROUP_TOOL::Group( const TOOL_EVENT& aEvent )
{
bool isSymbolEditor = m_frame->GetFrameType() == FRAME_SCH_SYMBOL_EDITOR;
SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
SCH_SELECTION selection = selTool->RequestSelection();
for( EDA_ITEM* item : selection.GetItems() )
{
if( !SCH_GROUP::IsGroupableType( item->Type() ) )
selection.Remove( item );
if( isSymbolEditor && static_cast<SCH_ITEM*>( item )->GetParentSymbol() )
selection.Remove( item );
}
if( selection.Empty() )
return 0;
SCH_GROUP* group = new SCH_GROUP;
SCH_SCREEN* screen = static_cast<SCH_BASE_FRAME*>( m_frame )->GetScreen();
if( isSymbolEditor )
group->SetParent( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol() );
else
group->SetParent( screen );
m_commit->Add( group, screen );
for( EDA_ITEM* eda_item : selection )
m_commit->Stage( eda_item, CHT_GROUP, screen );
m_commit->Push( _( "Group Items" ) );
m_toolMgr->RunAction( ACTIONS::selectionClear );
m_toolMgr->RunAction( ACTIONS::selectItem, group->AsEdaItem() );
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
m_frame->OnModify();
return 0;
}

17
eeschema/tools/sch_group_tool.h

@ -0,0 +1,17 @@
#include <tool/group_tool.h>
#include <sch_commit.h>
class SCH_GROUP_TOOL : public GROUP_TOOL
{
public:
/**
* Invoke the picker tool to select a new member of the group.
*/
int PickNewMember( const TOOL_EVENT& aEvent ) override;
///< Group selected items.
int Group( const TOOL_EVENT& aEvent ) override;
protected:
std::unique_ptr<COMMIT> createCommit() override { return std::make_unique<SCH_COMMIT>( m_toolMgr ); }
};
Loading…
Cancel
Save