committed by
dsa-t
10 changed files with 581 additions and 16 deletions
-
7pcbnew/CMakeLists.txt
-
2pcbnew/pcb_edit_frame.cpp
-
40pcbnew/router/pns_kicad_iface.cpp
-
7pcbnew/router/pns_kicad_iface.h
-
6pcbnew/router/pns_tool_base.cpp
-
2pcbnew/router/pns_tool_base.h
-
269pcbnew/tools/generator_tool.cpp
-
70pcbnew/tools/generator_tool.h
-
144pcbnew/tools/generator_tool_pns_proxy.cpp
-
50pcbnew/tools/generator_tool_pns_proxy.h
@ -0,0 +1,269 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Alex Shvartzkop <dudesuchamazing@gmail.com> |
|||
* Copyright (C) 2023 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 "generator_tool.h"
|
|||
|
|||
#include <collectors.h>
|
|||
#include <tool/tool_manager.h>
|
|||
#include <tools/pcb_selection_tool.h>
|
|||
#include <tools/pcb_actions.h>
|
|||
|
|||
#include <dialog_generators.h>
|
|||
|
|||
|
|||
GENERATOR_TOOL::GENERATOR_TOOL() : |
|||
GENERATOR_TOOL_PNS_PROXY( "pcbnew.Generators" ), |
|||
m_mgrDialog( nullptr ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
GENERATOR_TOOL::~GENERATOR_TOOL() |
|||
{ |
|||
} |
|||
|
|||
|
|||
void GENERATOR_TOOL::Reset( RESET_REASON aReason ) |
|||
{ |
|||
GENERATOR_TOOL_PNS_PROXY::Reset( aReason ); |
|||
} |
|||
|
|||
|
|||
void GENERATOR_TOOL::DestroyManagerDialog() |
|||
{ |
|||
if( m_mgrDialog ) |
|||
{ |
|||
m_mgrDialog->Destroy(); |
|||
m_mgrDialog = nullptr; |
|||
} |
|||
} |
|||
|
|||
|
|||
int GENERATOR_TOOL::ShowGeneratorsManager( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
PCB_EDIT_FRAME* pcbFrame = static_cast<PCB_EDIT_FRAME*>( frame() ); |
|||
|
|||
if( !pcbFrame ) |
|||
return 0; |
|||
|
|||
if( !m_mgrDialog ) |
|||
{ |
|||
m_mgrDialog = new DIALOG_GENERATORS( pcbFrame, pcbFrame ); |
|||
} |
|||
else |
|||
{ |
|||
m_mgrDialog->RebuildModels(); |
|||
} |
|||
|
|||
m_mgrDialog->Show( true ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int GENERATOR_TOOL::ShowGeneratorProperties( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); |
|||
PCB_GENERATOR* gen = aEvent.Parameter<PCB_GENERATOR*>(); |
|||
|
|||
gen->ShowPropertiesDialog( editFrame ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int GENERATOR_TOOL::RegenerateAll( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
BOARD_COMMIT localCommit( this ); |
|||
BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() ); |
|||
|
|||
if( !commit ) |
|||
commit = &localCommit; |
|||
|
|||
GENERATORS generators = board()->Generators(); |
|||
|
|||
std::sort( generators.begin(), generators.end(), |
|||
[]( const PCB_GENERATOR* a, const PCB_GENERATOR* b ) -> bool |
|||
{ |
|||
return a->GetUpdateOrder() < b->GetUpdateOrder(); |
|||
} ); |
|||
|
|||
for( PCB_GENERATOR* gen : generators ) |
|||
{ |
|||
gen->EditStart( this, board(), frame(), commit ); |
|||
gen->Update( this, board(), frame(), commit ); |
|||
gen->EditPush( this, board(), frame(), commit ); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int GENERATOR_TOOL::RegenerateOutdated( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
BOARD_COMMIT localCommit( this ); |
|||
BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() ); |
|||
|
|||
if( !commit ) |
|||
commit = &localCommit; |
|||
|
|||
GENERATORS generators = board()->Generators(); |
|||
|
|||
std::sort( generators.begin(), generators.end(), |
|||
[]( const PCB_GENERATOR* a, const PCB_GENERATOR* b ) -> bool |
|||
{ |
|||
return a->GetUpdateOrder() < b->GetUpdateOrder(); |
|||
} ); |
|||
|
|||
for( PCB_GENERATOR* gen : generators ) |
|||
{ |
|||
gen->EditStart( this, board(), frame(), commit ); |
|||
gen->Update( this, board(), frame(), commit ); |
|||
gen->EditPush( this, board(), frame(), commit ); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int GENERATOR_TOOL::RegenerateSelected( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
BOARD_COMMIT localCommit( this ); |
|||
BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() ); |
|||
|
|||
if( !commit ) |
|||
commit = &localCommit; |
|||
|
|||
PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>(); |
|||
|
|||
PCB_SELECTION sel = selTool->RequestSelection( |
|||
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) |
|||
{ |
|||
// Iterate from the back so we don't have to worry about removals.
|
|||
for( int i = aCollector.GetCount() - 1; i >= 0; --i ) |
|||
{ |
|||
BOARD_ITEM* item = aCollector[i]; |
|||
|
|||
if( item->Type() != PCB_GENERATOR_T ) |
|||
aCollector.Remove( item ); |
|||
} |
|||
} ); |
|||
|
|||
GENERATORS generators; |
|||
|
|||
for( EDA_ITEM* item : sel ) |
|||
{ |
|||
if( PCB_GENERATOR* gen = dynamic_cast<PCB_GENERATOR*>( item ) ) |
|||
generators.push_back( gen ); |
|||
} |
|||
|
|||
std::sort( generators.begin(), generators.end(), |
|||
[]( const PCB_GENERATOR* a, const PCB_GENERATOR* b ) -> bool |
|||
{ |
|||
return a->GetUpdateOrder() < b->GetUpdateOrder(); |
|||
} ); |
|||
|
|||
for( PCB_GENERATOR* gen : generators ) |
|||
{ |
|||
gen->EditStart( this, board(), frame(), commit ); |
|||
gen->Update( this, board(), frame(), commit ); |
|||
gen->EditPush( this, board(), frame(), commit ); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int GENERATOR_TOOL::RegenerateItem( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
BOARD_COMMIT localCommit( this ); |
|||
BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() ); |
|||
|
|||
if( !commit ) |
|||
commit = &localCommit; |
|||
|
|||
PCB_GENERATOR* gen = aEvent.Parameter<PCB_GENERATOR*>(); |
|||
|
|||
gen->EditStart( this, board(), frame(), commit ); |
|||
gen->Update( this, board(), frame(), commit ); |
|||
gen->EditPush( this, board(), frame(), commit ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int GENERATOR_TOOL::GenEditAction( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() ); |
|||
|
|||
wxCHECK( commit, 0 ); |
|||
|
|||
PCB_GENERATOR* gen = aEvent.Parameter<PCB_GENERATOR*>(); |
|||
|
|||
if( aEvent.IsAction( &PCB_ACTIONS::genStartEdit ) ) |
|||
{ |
|||
gen->EditStart( this, board(), frame(), commit ); |
|||
} |
|||
else if( aEvent.IsAction( &PCB_ACTIONS::genUpdateEdit ) ) |
|||
{ |
|||
gen->Update( this, board(), frame(), commit ); |
|||
} |
|||
else if( aEvent.IsAction( &PCB_ACTIONS::genPushEdit ) ) |
|||
{ |
|||
gen->EditPush( this, board(), frame(), commit ); |
|||
|
|||
wxASSERT( commit->Empty() ); |
|||
} |
|||
else if( aEvent.IsAction( &PCB_ACTIONS::genRevertEdit ) ) |
|||
{ |
|||
gen->EditRevert( this, board(), frame(), commit ); |
|||
|
|||
wxASSERT( commit->Empty() ); |
|||
} |
|||
else if( aEvent.IsAction( &PCB_ACTIONS::genRemove ) ) |
|||
{ |
|||
gen->Remove( this, board(), frame(), commit ); |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void GENERATOR_TOOL::setTransitions() |
|||
{ |
|||
// Generator actions
|
|||
Go( &GENERATOR_TOOL::ShowGeneratorsManager, PCB_ACTIONS::generatorsShowManager.MakeEvent() ); |
|||
Go( &GENERATOR_TOOL::ShowGeneratorProperties, PCB_ACTIONS::generatorProperties.MakeEvent() ); |
|||
|
|||
Go( &GENERATOR_TOOL::RegenerateAll, PCB_ACTIONS::regenerateAll.MakeEvent() ); |
|||
Go( &GENERATOR_TOOL::RegenerateOutdated, PCB_ACTIONS::regenerateOutdated.MakeEvent() ); |
|||
Go( &GENERATOR_TOOL::RegenerateSelected, PCB_ACTIONS::regenerateSelected.MakeEvent() ); |
|||
Go( &GENERATOR_TOOL::RegenerateItem, PCB_ACTIONS::regenerateItem.MakeEvent() ); |
|||
|
|||
Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genStartEdit.MakeEvent() ); |
|||
Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genUpdateEdit.MakeEvent() ); |
|||
Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genPushEdit.MakeEvent() ); |
|||
Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genRevertEdit.MakeEvent() ); |
|||
Go( &GENERATOR_TOOL::GenEditAction, PCB_ACTIONS::genRemove.MakeEvent() ); |
|||
} |
@ -0,0 +1,70 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Alex Shvartzkop <dudesuchamazing@gmail.com> |
|||
* Copyright (C) 2023 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 GENERATOR_TOOL_H |
|||
#define GENERATOR_TOOL_H |
|||
|
|||
#include <tools/generator_tool_pns_proxy.h> |
|||
#include <pcb_generator.h> |
|||
|
|||
|
|||
class DIALOG_GENERATORS; |
|||
class PCB_EDIT_FRAME; |
|||
class PROGRESS_REPORTER; |
|||
class WX_PROGRESS_REPORTER; |
|||
|
|||
|
|||
/** |
|||
* Handle actions specific to filling copper zones. |
|||
*/ |
|||
class GENERATOR_TOOL : public GENERATOR_TOOL_PNS_PROXY |
|||
{ |
|||
public: |
|||
GENERATOR_TOOL(); |
|||
~GENERATOR_TOOL(); |
|||
|
|||
/// @copydoc TOOL_INTERACTIVE::Reset() |
|||
void Reset( RESET_REASON aReason ) override; |
|||
|
|||
void DestroyManagerDialog(); |
|||
|
|||
int ShowGeneratorsManager( const TOOL_EVENT& aEvent ); |
|||
int ShowGeneratorProperties( const TOOL_EVENT& aEvent ); |
|||
|
|||
int RegenerateSelected( const TOOL_EVENT& aEvent ); |
|||
int RegenerateAll( const TOOL_EVENT& aEvent ); |
|||
int RegenerateOutdated( const TOOL_EVENT& aEvent ); |
|||
int RegenerateItem( const TOOL_EVENT& aEvent ); |
|||
int GenEditAction( const TOOL_EVENT& aEvent ); |
|||
|
|||
private: |
|||
///< Set up handlers for various events. |
|||
void setTransitions() override; |
|||
|
|||
DIALOG_GENERATORS* m_mgrDialog; |
|||
|
|||
private: |
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,144 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Alex Shvartzkop <dudesuchamazing@gmail.com> |
|||
* Copyright (C) 2023 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 "generator_tool_pns_proxy.h"
|
|||
|
|||
#include <pad.h>
|
|||
#include <pcb_shape.h>
|
|||
#include <tools/pcb_grid_helper.h>
|
|||
|
|||
#include <router/pns_kicad_iface.h>
|
|||
#include <router/pns_solid.h>
|
|||
#include <router/pns_router.h>
|
|||
|
|||
|
|||
class PNS_KICAD_IFACE_GENERATOR : public PNS_KICAD_IFACE |
|||
{ |
|||
public: |
|||
void Commit() override {} |
|||
|
|||
void SetHostTool( PCB_TOOL_BASE* aTool ) override |
|||
{ |
|||
m_tool = aTool; |
|||
m_commit = nullptr; |
|||
m_addedItems.clear(); |
|||
m_removedItems.clear(); |
|||
} |
|||
|
|||
void AddItem( PNS::ITEM* aItem ) override |
|||
{ |
|||
BOARD_ITEM* brdItem = createBoardItem( aItem ); |
|||
m_addedItems.emplace( brdItem ); |
|||
} |
|||
|
|||
void UpdateItem( PNS::ITEM* aItem ) override |
|||
{ //
|
|||
modifyBoardItem( aItem ); |
|||
} |
|||
|
|||
void RemoveItem( PNS::ITEM* aItem ) override |
|||
{ |
|||
BOARD_ITEM* parent = aItem->Parent(); |
|||
|
|||
if( aItem->OfKind( PNS::ITEM::SOLID_T ) ) |
|||
{ |
|||
PAD* pad = static_cast<PAD*>( parent ); |
|||
VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos(); |
|||
|
|||
m_fpOffsets[pad].p_old = pos; |
|||
return; |
|||
} |
|||
|
|||
if( parent ) |
|||
{ |
|||
m_removedItems.emplace( parent ); |
|||
} |
|||
} |
|||
|
|||
std::set<BOARD_ITEM*>& AddedItems() { return m_addedItems; } |
|||
std::set<BOARD_ITEM*>& RemovedItems() { return m_removedItems; } |
|||
|
|||
private: |
|||
std::set<BOARD_ITEM*> m_addedItems; |
|||
std::set<BOARD_ITEM*> m_removedItems; |
|||
}; |
|||
|
|||
|
|||
void GENERATOR_TOOL_PNS_PROXY::ClearRouterCommit() |
|||
{ |
|||
static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->AddedItems().clear(); |
|||
static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->RemovedItems().clear(); |
|||
} |
|||
|
|||
|
|||
const std::set<BOARD_ITEM*>& GENERATOR_TOOL_PNS_PROXY::GetRouterCommitAddedItems() |
|||
{ |
|||
return static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->AddedItems(); |
|||
} |
|||
|
|||
|
|||
const std::set<BOARD_ITEM*>& GENERATOR_TOOL_PNS_PROXY::GetRouterCommitRemovedItems() |
|||
{ |
|||
return static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->RemovedItems(); |
|||
} |
|||
|
|||
|
|||
GENERATOR_TOOL_PNS_PROXY::GENERATOR_TOOL_PNS_PROXY( const std::string& aToolName ) : |
|||
PNS::TOOL_BASE( aToolName ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
GENERATOR_TOOL_PNS_PROXY::~GENERATOR_TOOL_PNS_PROXY() |
|||
{ |
|||
} |
|||
|
|||
|
|||
void GENERATOR_TOOL_PNS_PROXY::Reset( RESET_REASON aReason ) |
|||
{ |
|||
delete m_gridHelper; |
|||
delete m_iface; |
|||
delete m_router; |
|||
|
|||
m_iface = new PNS_KICAD_IFACE_GENERATOR; |
|||
m_iface->SetBoard( board() ); |
|||
m_iface->SetView( getView() ); |
|||
m_iface->SetHostTool( this ); |
|||
|
|||
m_router = new PNS::ROUTER; |
|||
m_router->SetInterface( m_iface ); |
|||
m_router->ClearWorld(); |
|||
m_router->SyncWorld(); |
|||
|
|||
m_router->UpdateSizes( m_savedSizes ); |
|||
|
|||
PCBNEW_SETTINGS* settings = frame()->GetPcbNewSettings(); |
|||
|
|||
if( !settings->m_PnsSettings ) |
|||
settings->m_PnsSettings = std::make_unique<PNS::ROUTING_SETTINGS>( settings, "tools.pns" ); |
|||
|
|||
m_router->LoadSettings( settings->m_PnsSettings.get() ); |
|||
|
|||
m_gridHelper = new PCB_GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() ); |
|||
} |
@ -0,0 +1,50 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Alex Shvartzkop <dudesuchamazing@gmail.com> |
|||
* Copyright (C) 2023 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 GENERATOR_TOOL_PNS_PROXY_H |
|||
#define GENERATOR_TOOL_PNS_PROXY_H |
|||
|
|||
#include <router/pns_tool_base.h> |
|||
|
|||
class BOARD_ITEM; |
|||
|
|||
|
|||
/** |
|||
* A proxy class to allow access to the PNS router from the generator tool. |
|||
*/ |
|||
class GENERATOR_TOOL_PNS_PROXY : public PNS::TOOL_BASE |
|||
{ |
|||
public: |
|||
GENERATOR_TOOL_PNS_PROXY( const std::string& aToolName ); |
|||
~GENERATOR_TOOL_PNS_PROXY(); |
|||
|
|||
/// @copydoc TOOL_INTERACTIVE::Reset() |
|||
void Reset( RESET_REASON aReason ) override; |
|||
|
|||
void ClearRouterCommit(); |
|||
const std::set<BOARD_ITEM*>& GetRouterCommitAddedItems(); |
|||
const std::set<BOARD_ITEM*>& GetRouterCommitRemovedItems(); |
|||
}; |
|||
|
|||
#endif // GENERATOR_TOOL_PNS_PROXY_H |
Write
Preview
Loading…
Cancel
Save
Reference in new issue