Add Feature: synchronize hierarchical labels and sheet pins
This commit is contained in:
parent
d939004bbd
commit
be81bce637
|
@ -103,6 +103,7 @@ __pycache__
|
|||
.editorconfig
|
||||
CMakeSettings.json
|
||||
.vscode/
|
||||
compile_commands.json
|
||||
/vcpkg_installed
|
||||
|
||||
# Sublime Text
|
||||
|
|
|
@ -316,6 +316,17 @@ set( EESCHEMA_PRINTING
|
|||
printing/sch_printout.cpp
|
||||
)
|
||||
|
||||
set( SYNC_SHEET_PIN_SRCS
|
||||
sync_sheet_pin/dialog_sync_sheet_pins.cpp
|
||||
sync_sheet_pin/dialog_sync_sheet_pins_base.cpp
|
||||
sync_sheet_pin/panel_sync_sheet_pins.cpp
|
||||
sync_sheet_pin/panel_sync_sheet_pins_base.cpp
|
||||
sync_sheet_pin/sheet_synchronization_agent.cpp
|
||||
sync_sheet_pin/sheet_synchronization_item.cpp
|
||||
sync_sheet_pin/sheet_synchronization_notifier.cpp
|
||||
sync_sheet_pin/sheet_synchronization_model.cpp
|
||||
)
|
||||
|
||||
set( EESCHEMA_SRCS
|
||||
${EESCHEMA_DLGS}
|
||||
${EESCHEMA_LIBEDIT_SRCS}
|
||||
|
@ -323,6 +334,7 @@ set( EESCHEMA_SRCS
|
|||
${EESCHEMA_SIM_SRCS}
|
||||
${EESCHEMA_WIDGETS}
|
||||
${EESCHEMA_IMPORT_GFX}
|
||||
${SYNC_SHEET_PIN_SRCS}
|
||||
annotate.cpp
|
||||
autoplace_fields.cpp
|
||||
bom_plugins.cpp
|
||||
|
|
|
@ -254,7 +254,8 @@ void SCH_EDIT_FRAME::doReCreateMenuBar()
|
|||
placeMenu->AppendSeparator();
|
||||
placeMenu->Add( EE_ACTIONS::placeHierLabel );
|
||||
placeMenu->Add( EE_ACTIONS::drawSheet );
|
||||
placeMenu->Add( EE_ACTIONS::importSheetPin );
|
||||
placeMenu->Add( EE_ACTIONS::placeSheetPin );
|
||||
placeMenu->Add( EE_ACTIONS::syncAllSheetsPins );
|
||||
|
||||
placeMenu->AppendSeparator();
|
||||
placeMenu->Add( EE_ACTIONS::placeSchematicText );
|
||||
|
|
|
@ -726,7 +726,8 @@ void SCH_EDIT_FRAME::setupUIConditions()
|
|||
CURRENT_TOOL( EE_ACTIONS::placeGlobalLabel );
|
||||
CURRENT_TOOL( EE_ACTIONS::placeHierLabel );
|
||||
CURRENT_TOOL( EE_ACTIONS::drawSheet );
|
||||
CURRENT_TOOL( EE_ACTIONS::importSheetPin );
|
||||
CURRENT_TOOL( EE_ACTIONS::placeSheetPin );
|
||||
CURRENT_TOOL( EE_ACTIONS::syncSheetPins );
|
||||
CURRENT_TOOL( EE_ACTIONS::drawRectangle );
|
||||
CURRENT_TOOL( EE_ACTIONS::drawCircle );
|
||||
CURRENT_TOOL( EE_ACTIONS::drawArc );
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 "dialog_sync_sheet_pins.h"
|
||||
#include "panel_sync_sheet_pins.h"
|
||||
#include "sch_item.h"
|
||||
#include "sch_label.h"
|
||||
#include "sheet_synchronization_model.h"
|
||||
#include "sync_sheet_pin_preference.h"
|
||||
#include "sheet_synchronization_notifier.h"
|
||||
#include "sheet_synchronization_agent.h"
|
||||
#include "sheet_synchronization_item.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sch_sheet_pin.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <unordered_map>
|
||||
#include <sch_drawing_tools.h>
|
||||
|
||||
DIALOG_SYNC_SHEET_PINS::DIALOG_SYNC_SHEET_PINS(
|
||||
wxWindow* aParent, std::list<SCH_SHEET_PATH> aSheetPath,
|
||||
std::shared_ptr<SHEET_SYNCHRONIZATION_AGENT> aAgent ) :
|
||||
DIALOG_SYNC_SHEET_PINS_BASE( aParent ),
|
||||
m_agent( std::move( aAgent ) ), m_lastEditSheet( nullptr ),
|
||||
m_placeItemKind( PlaceItemKind::UNDEFINED ), m_placementTemplate( nullptr )
|
||||
{
|
||||
wxImageList* imageList = new wxImageList( SYNC_SHEET_PIN_PREFERENCE::NORMAL_WIDTH,
|
||||
SYNC_SHEET_PIN_PREFERENCE::NORMAL_HEIGHT );
|
||||
|
||||
for( const auto [icon_idx, bitmap] : SYNC_SHEET_PIN_PREFERENCE::GetBookctrlPageIcon() )
|
||||
{
|
||||
imageList->Add( KiBitmap( bitmap, SYNC_SHEET_PIN_PREFERENCE::NORMAL_HEIGHT ) );
|
||||
}
|
||||
|
||||
m_notebook->AssignImageList( imageList );
|
||||
int count = -1;
|
||||
std::unordered_map<wxString, std::list<PANEL_SYNC_SHEET_PINS*>> sheet_instances;
|
||||
|
||||
for( const auto& sheet_path : aSheetPath )
|
||||
{
|
||||
auto sheet = sheet_path.Last();
|
||||
wxString fileName = sheet->GetFileName();
|
||||
PANEL_SYNC_SHEET_PINS* page = new PANEL_SYNC_SHEET_PINS( m_notebook, sheet, m_notebook,
|
||||
++count, *m_agent, sheet_path );
|
||||
m_notebook->AddPage( page, sheet->GetShownName( true ), {}, page->HasUndefinedSheetPing() );
|
||||
page->UpdateForms();
|
||||
|
||||
if( sheet_instances.find( fileName ) == sheet_instances.end() )
|
||||
{
|
||||
sheet_instances.try_emplace( fileName, std::list<PANEL_SYNC_SHEET_PINS*>{ page } );
|
||||
}
|
||||
else
|
||||
{
|
||||
sheet_instances[fileName].push_back( page );
|
||||
}
|
||||
|
||||
m_panels.try_emplace( sheet, page );
|
||||
}
|
||||
|
||||
for( auto& [sheet_name, panel_list] : sheet_instances )
|
||||
{
|
||||
if( panel_list.size() > 1 )
|
||||
{
|
||||
std::list<std::shared_ptr<SHEET_SYNCHRONIZATION_NOTIFIER>> sheet_change_notifiers;
|
||||
std::list<SHEET_SYNCHRONIZATION_MODEL*> sheet_sync_models;
|
||||
|
||||
for( auto& panel : panel_list )
|
||||
{
|
||||
SHEET_SYNCHRONIZATION_MODEL* model =
|
||||
panel->GetModel( SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL ).get();
|
||||
sheet_sync_models.push_back( model );
|
||||
sheet_change_notifiers.push_back(
|
||||
std::make_shared<SHEET_FILE_CHANGE_NOTIFIER>( model, panel ) );
|
||||
}
|
||||
|
||||
for( auto& notifier : sheet_change_notifiers )
|
||||
{
|
||||
for( auto& other : sheet_sync_models )
|
||||
{
|
||||
if( notifier->GetOwner() != other )
|
||||
{
|
||||
other->AddNotifier( notifier );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_sizerMain->Layout();
|
||||
m_sizerMain->Fit( this );
|
||||
Bind( wxEVT_CLOSE_WINDOW, &DIALOG_SYNC_SHEET_PINS::OnClose, this );
|
||||
}
|
||||
|
||||
|
||||
DIALOG_SYNC_SHEET_PINS::~DIALOG_SYNC_SHEET_PINS() = default;
|
||||
|
||||
|
||||
void DIALOG_SYNC_SHEET_PINS::OnCloseBtnClick( wxCommandEvent& event )
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void DIALOG_SYNC_SHEET_PINS::OnClose( wxCloseEvent& aEvent )
|
||||
{
|
||||
aEvent.Skip();
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_SYNC_SHEET_PINS::EndPlaceItem( EDA_ITEM* aNewItem )
|
||||
{
|
||||
auto post_end_place_item = std::shared_ptr<nullptr_t>( nullptr,
|
||||
[&]( nullptr_t )
|
||||
{
|
||||
m_placeItemKind =
|
||||
PlaceItemKind::UNDEFINED;
|
||||
m_placementTemplate = nullptr;
|
||||
} );
|
||||
|
||||
if( !aNewItem )
|
||||
return;
|
||||
|
||||
if( m_lastEditSheet && m_panels.find( m_lastEditSheet ) != m_panels.end() )
|
||||
{
|
||||
auto& panel = m_panels[m_lastEditSheet];
|
||||
auto template_item = static_cast<SCH_HIERLABEL*>( m_placementTemplate );
|
||||
auto new_item = static_cast<SCH_HIERLABEL*>( aNewItem );
|
||||
|
||||
//Usr may edit the name or shape while placing the new item , do sync if either differs
|
||||
if( template_item->GetText() != new_item->GetText()
|
||||
|| template_item->GetShape() != new_item->GetShape() )
|
||||
{
|
||||
m_agent->ModifyItem(
|
||||
template_item,
|
||||
[&]()
|
||||
{
|
||||
template_item->SetText( new_item->GetText() );
|
||||
template_item->SetShape( new_item->GetShape() );
|
||||
},
|
||||
panel->GetSheetPath(),
|
||||
PlaceItemKind::SHEET_PIN == m_placeItemKind
|
||||
? SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL
|
||||
: SHEET_SYNCHRONIZATION_ITEM_KIND::SHEET_PIN );
|
||||
}
|
||||
|
||||
panel->UpdateForms();
|
||||
|
||||
if( PlaceItemKind::HIERLABEL == m_placeItemKind )
|
||||
panel->GetModel( SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL )->DoNotify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_SYNC_SHEET_PINS::BeginPlaceItem( SCH_SHEET* aSheet, PlaceItemKind aKind,
|
||||
EDA_ITEM* aTemplate )
|
||||
{
|
||||
m_lastEditSheet = aSheet;
|
||||
m_placeItemKind = aKind;
|
||||
m_placementTemplate = aTemplate;
|
||||
}
|
||||
|
||||
|
||||
SCH_HIERLABEL* DIALOG_SYNC_SHEET_PINS::GetPlacementTemplate() const
|
||||
{
|
||||
if( !m_placementTemplate )
|
||||
return {};
|
||||
|
||||
return static_cast<SCH_HIERLABEL*>( m_placementTemplate );
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 DIALOG_SYNC_SHEET_PINS_H
|
||||
#define DIALOG_SYNC_SHEET_PINS_H
|
||||
|
||||
#include "dialog_sync_sheet_pins_base.h"
|
||||
|
||||
#include <sch_sheet_path.h>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
class SCH_SHEET;
|
||||
class EDA_ITEM;
|
||||
class SHEET_SYNCHRONIZATION_AGENT;
|
||||
class PANEL_SYNC_SHEET_PINS;
|
||||
class SCH_HIERLABEL;
|
||||
class DIALOG_SYNC_SHEET_PINS : public DIALOG_SYNC_SHEET_PINS_BASE
|
||||
{
|
||||
public:
|
||||
enum class PlaceItemKind
|
||||
{
|
||||
UNDEFINED,
|
||||
SHEET_PIN,
|
||||
HIERLABEL
|
||||
};
|
||||
|
||||
DIALOG_SYNC_SHEET_PINS( wxWindow* aParent, std::list<SCH_SHEET_PATH> aSheetPath,
|
||||
std::shared_ptr<SHEET_SYNCHRONIZATION_AGENT> aAgent );
|
||||
|
||||
~DIALOG_SYNC_SHEET_PINS() override;
|
||||
|
||||
void OnCloseBtnClick( wxCommandEvent& event ) override;
|
||||
|
||||
void OnClose( wxCloseEvent& aEvent );
|
||||
|
||||
void EndPlaceItem( EDA_ITEM* aNewItem );
|
||||
|
||||
/**
|
||||
* @brief Start place a new SHEET_PIN / HIERLABEL
|
||||
*
|
||||
* @param aSheet The sheet instance
|
||||
* @param aKind SHEET_PIN / HIERLABEL
|
||||
* @param aTemplate The template used for the new SHEET_PIN / HIERLABEL
|
||||
*/
|
||||
void BeginPlaceItem( SCH_SHEET* aSheet, PlaceItemKind aKind, EDA_ITEM* aTemplate );
|
||||
|
||||
/**
|
||||
* @brief Get the Placement Template SHEET_PIN / HIERLABEL used for place a new HIERLABEL/SHEET_PIN
|
||||
*
|
||||
* @return SCH_HIERLABEL*
|
||||
*/
|
||||
SCH_HIERLABEL* GetPlacementTemplate() const;
|
||||
|
||||
|
||||
private:
|
||||
//It's the agent that performs modification and placement
|
||||
std::shared_ptr<SHEET_SYNCHRONIZATION_AGENT> m_agent;
|
||||
SCH_SHEET* m_lastEditSheet;
|
||||
//The same sheet may have mutiple instances
|
||||
std::unordered_map<SCH_SHEET*, PANEL_SYNC_SHEET_PINS*> m_panels;
|
||||
PlaceItemKind m_placeItemKind;
|
||||
EDA_ITEM* m_placementTemplate;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,63 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "dialog_sync_sheet_pins_base.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DIALOG_SYNC_SHEET_PINS_BASE::DIALOG_SYNC_SHEET_PINS_BASE( wxWindow* parent, wxWindowID id,
|
||||
const wxString& title, const wxPoint& pos,
|
||||
const wxSize& size, long style ) :
|
||||
DIALOG_SHIM( parent, id, title, pos, size, style )
|
||||
{
|
||||
this->SetSizeHints( wxSize( -1, -1 ), wxDefaultSize );
|
||||
|
||||
m_sizerMain = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
|
||||
|
||||
m_sizerMain->Add( m_notebook, 1, wxEXPAND | wxALL, 5 );
|
||||
|
||||
wxBoxSizer* bSizer8;
|
||||
bSizer8 = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
|
||||
bSizer8->Add( 0, 0, 1, wxEXPAND, 5 );
|
||||
|
||||
m_labelTip = new wxStaticText( this, wxID_ANY,
|
||||
_( "Changes made in this dialog occur immediately, use Undo in "
|
||||
"each affected document to undo them" ),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_labelTip->Wrap( -1 );
|
||||
bSizer8->Add( m_labelTip, 0, wxALL, 5 );
|
||||
|
||||
m_btnClose = new wxButton( this, wxID_ANY, _( "Close" ), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bSizer8->Add( m_btnClose, 0, wxALL, 5 );
|
||||
|
||||
|
||||
m_sizerMain->Add( bSizer8, 0, wxEXPAND, 5 );
|
||||
|
||||
|
||||
this->SetSizer( m_sizerMain );
|
||||
this->Layout();
|
||||
m_sizerMain->Fit( this );
|
||||
|
||||
this->Centre( wxBOTH );
|
||||
|
||||
// Connect Events
|
||||
m_btnClose->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( DIALOG_SYNC_SHEET_PINS_BASE::OnCloseBtnClick ),
|
||||
NULL, this );
|
||||
}
|
||||
|
||||
DIALOG_SYNC_SHEET_PINS_BASE::~DIALOG_SYNC_SHEET_PINS_BASE()
|
||||
{
|
||||
// Disconnect Events
|
||||
m_btnClose->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( DIALOG_SYNC_SHEET_PINS_BASE::OnCloseBtnClick ),
|
||||
NULL, this );
|
||||
}
|
|
@ -0,0 +1,286 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<wxFormBuilder_Project>
|
||||
<FileVersion major="1" minor="17"/>
|
||||
<object class="Project" expanded="true">
|
||||
<property name="class_decoration"></property>
|
||||
<property name="code_generation">C++</property>
|
||||
<property name="disconnect_events">1</property>
|
||||
<property name="disconnect_mode">source_name</property>
|
||||
<property name="disconnect_php_events">0</property>
|
||||
<property name="disconnect_python_events">0</property>
|
||||
<property name="embedded_files_path">res</property>
|
||||
<property name="encoding">UTF-8</property>
|
||||
<property name="event_generation">connect</property>
|
||||
<property name="file">dialog_sync_sheet_pins_base</property>
|
||||
<property name="first_id">1000</property>
|
||||
<property name="help_provider">none</property>
|
||||
<property name="image_path_wrapper_function_name"></property>
|
||||
<property name="indent_with_spaces"></property>
|
||||
<property name="internationalize">1</property>
|
||||
<property name="name">dialog_sync_sheet_pins_base</property>
|
||||
<property name="namespace"></property>
|
||||
<property name="path">.</property>
|
||||
<property name="precompiled_header"></property>
|
||||
<property name="relative_path">1</property>
|
||||
<property name="skip_lua_events">1</property>
|
||||
<property name="skip_php_events">1</property>
|
||||
<property name="skip_python_events">1</property>
|
||||
<property name="ui_table">UI</property>
|
||||
<property name="use_array_enum">0</property>
|
||||
<property name="use_enum">0</property>
|
||||
<property name="use_microsoft_bom">0</property>
|
||||
<object class="Dialog" expanded="true">
|
||||
<property name="aui_managed">0</property>
|
||||
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
|
||||
<property name="bg"></property>
|
||||
<property name="center">wxBOTH</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="drag_accept_files">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="event_handler">impl_virtual</property>
|
||||
<property name="extra_style"></property>
|
||||
<property name="fg"></property>
|
||||
<property name="font"></property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="minimum_size">-1,-1</property>
|
||||
<property name="name">DIALOG_SYNC_SHEET_PINS_BASE</property>
|
||||
<property name="pos"></property>
|
||||
<property name="size">-1,-1</property>
|
||||
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
|
||||
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
|
||||
<property name="title">Synchronize sheet pins and hierarchical labels</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="two_step_creation">0</property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<object class="wxBoxSizer" expanded="true">
|
||||
<property name="minimum_size"></property>
|
||||
<property name="name">m_sizerMain</property>
|
||||
<property name="orient">wxVERTICAL</property>
|
||||
<property name="permission">protected</property>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxEXPAND | wxALL</property>
|
||||
<property name="proportion">1</property>
|
||||
<object class="wxNotebook" expanded="true">
|
||||
<property name="BottomDockable">1</property>
|
||||
<property name="LeftDockable">1</property>
|
||||
<property name="RightDockable">1</property>
|
||||
<property name="TopDockable">1</property>
|
||||
<property name="aui_layer"></property>
|
||||
<property name="aui_name"></property>
|
||||
<property name="aui_position"></property>
|
||||
<property name="aui_row"></property>
|
||||
<property name="best_size"></property>
|
||||
<property name="bg"></property>
|
||||
<property name="bitmapsize"></property>
|
||||
<property name="caption"></property>
|
||||
<property name="caption_visible">1</property>
|
||||
<property name="center_pane">0</property>
|
||||
<property name="close_button">1</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="default_pane">0</property>
|
||||
<property name="dock">Dock</property>
|
||||
<property name="dock_fixed">0</property>
|
||||
<property name="docking">Left</property>
|
||||
<property name="drag_accept_files">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="fg"></property>
|
||||
<property name="floatable">1</property>
|
||||
<property name="font"></property>
|
||||
<property name="gripper">0</property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="max_size"></property>
|
||||
<property name="maximize_button">0</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="min_size"></property>
|
||||
<property name="minimize_button">0</property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="moveable">1</property>
|
||||
<property name="name">m_notebook</property>
|
||||
<property name="pane_border">1</property>
|
||||
<property name="pane_position"></property>
|
||||
<property name="pane_size"></property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="pin_button">1</property>
|
||||
<property name="pos"></property>
|
||||
<property name="resize">Resizable</property>
|
||||
<property name="show">1</property>
|
||||
<property name="size"></property>
|
||||
<property name="style"></property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxEXPAND</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxBoxSizer" expanded="true">
|
||||
<property name="minimum_size"></property>
|
||||
<property name="name">bSizer8</property>
|
||||
<property name="orient">wxHORIZONTAL</property>
|
||||
<property name="permission">none</property>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxEXPAND</property>
|
||||
<property name="proportion">1</property>
|
||||
<object class="spacer" expanded="true">
|
||||
<property name="height">0</property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="width">0</property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxALL</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxStaticText" expanded="true">
|
||||
<property name="BottomDockable">1</property>
|
||||
<property name="LeftDockable">1</property>
|
||||
<property name="RightDockable">1</property>
|
||||
<property name="TopDockable">1</property>
|
||||
<property name="aui_layer"></property>
|
||||
<property name="aui_name"></property>
|
||||
<property name="aui_position"></property>
|
||||
<property name="aui_row"></property>
|
||||
<property name="best_size"></property>
|
||||
<property name="bg"></property>
|
||||
<property name="caption"></property>
|
||||
<property name="caption_visible">1</property>
|
||||
<property name="center_pane">0</property>
|
||||
<property name="close_button">1</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="default_pane">0</property>
|
||||
<property name="dock">Dock</property>
|
||||
<property name="dock_fixed">0</property>
|
||||
<property name="docking">Left</property>
|
||||
<property name="drag_accept_files">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="fg"></property>
|
||||
<property name="floatable">1</property>
|
||||
<property name="font"></property>
|
||||
<property name="gripper">0</property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="label">Changes made in this dialog occur immediately, use Undo in each affected document to undo them</property>
|
||||
<property name="markup">0</property>
|
||||
<property name="max_size"></property>
|
||||
<property name="maximize_button">0</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="min_size"></property>
|
||||
<property name="minimize_button">0</property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="moveable">1</property>
|
||||
<property name="name">m_labelTip</property>
|
||||
<property name="pane_border">1</property>
|
||||
<property name="pane_position"></property>
|
||||
<property name="pane_size"></property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="pin_button">1</property>
|
||||
<property name="pos"></property>
|
||||
<property name="resize">Resizable</property>
|
||||
<property name="show">1</property>
|
||||
<property name="size"></property>
|
||||
<property name="style"></property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<property name="wrap">-1</property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxALL</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxButton" expanded="true">
|
||||
<property name="BottomDockable">1</property>
|
||||
<property name="LeftDockable">1</property>
|
||||
<property name="RightDockable">1</property>
|
||||
<property name="TopDockable">1</property>
|
||||
<property name="aui_layer"></property>
|
||||
<property name="aui_name"></property>
|
||||
<property name="aui_position"></property>
|
||||
<property name="aui_row"></property>
|
||||
<property name="auth_needed">0</property>
|
||||
<property name="best_size"></property>
|
||||
<property name="bg"></property>
|
||||
<property name="bitmap"></property>
|
||||
<property name="caption"></property>
|
||||
<property name="caption_visible">1</property>
|
||||
<property name="center_pane">0</property>
|
||||
<property name="close_button">1</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="current"></property>
|
||||
<property name="default">0</property>
|
||||
<property name="default_pane">0</property>
|
||||
<property name="disabled"></property>
|
||||
<property name="dock">Dock</property>
|
||||
<property name="dock_fixed">0</property>
|
||||
<property name="docking">Left</property>
|
||||
<property name="drag_accept_files">0</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="fg"></property>
|
||||
<property name="floatable">1</property>
|
||||
<property name="focus"></property>
|
||||
<property name="font"></property>
|
||||
<property name="gripper">0</property>
|
||||
<property name="hidden">0</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="label">Close</property>
|
||||
<property name="margins"></property>
|
||||
<property name="markup">0</property>
|
||||
<property name="max_size"></property>
|
||||
<property name="maximize_button">0</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="min_size"></property>
|
||||
<property name="minimize_button">0</property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="moveable">1</property>
|
||||
<property name="name">m_btnClose</property>
|
||||
<property name="pane_border">1</property>
|
||||
<property name="pane_position"></property>
|
||||
<property name="pane_size"></property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="pin_button">1</property>
|
||||
<property name="pos"></property>
|
||||
<property name="position"></property>
|
||||
<property name="pressed"></property>
|
||||
<property name="resize">Resizable</property>
|
||||
<property name="show">1</property>
|
||||
<property name="size"></property>
|
||||
<property name="style"></property>
|
||||
<property name="subclass">; ; forward_declare</property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="validator_data_type"></property>
|
||||
<property name="validator_style">wxFILTER_NONE</property>
|
||||
<property name="validator_type">wxDefaultValidator</property>
|
||||
<property name="validator_variable"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
<event name="OnButtonClick">OnCloseBtnClick</event>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</wxFormBuilder_Project>
|
|
@ -0,0 +1,55 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wx/artprov.h>
|
||||
#include <wx/xrc/xmlres.h>
|
||||
#include <wx/intl.h>
|
||||
#include "dialog_shim.h"
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/notebook.h>
|
||||
#include <wx/font.h>
|
||||
#include <wx/colour.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/button.h>
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/image.h>
|
||||
#include <wx/icon.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/dialog.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// Class DIALOG_SYNC_SHEET_PINS_BASE
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class DIALOG_SYNC_SHEET_PINS_BASE : public DIALOG_SHIM
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
wxBoxSizer* m_sizerMain;
|
||||
wxNotebook* m_notebook;
|
||||
wxStaticText* m_labelTip;
|
||||
wxButton* m_btnClose;
|
||||
|
||||
// Virtual event handlers, override them in your derived class
|
||||
virtual void OnCloseBtnClick( wxCommandEvent& event ) { event.Skip(); }
|
||||
|
||||
|
||||
public:
|
||||
DIALOG_SYNC_SHEET_PINS_BASE(
|
||||
wxWindow* parent, wxWindowID id = wxID_ANY,
|
||||
const wxString& title = _( "Synchronize sheet pins and hierarchical labels" ),
|
||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1, -1 ),
|
||||
long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER );
|
||||
|
||||
~DIALOG_SYNC_SHEET_PINS_BASE();
|
||||
};
|
|
@ -0,0 +1,380 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 "panel_sync_sheet_pins.h"
|
||||
#include "sch_sheet_pin.h"
|
||||
#include "sheet_synchronization_model.h"
|
||||
#include "sheet_synchronization_item.h"
|
||||
#include "sync_sheet_pin_preference.h"
|
||||
#include "sheet_synchronization_agent.h"
|
||||
|
||||
#include <bitmaps.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sch_label.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <sch_pin.h>
|
||||
#include <sch_screen.h>
|
||||
#include <wx/bookctrl.h>
|
||||
#include <eda_item.h>
|
||||
|
||||
PANEL_SYNC_SHEET_PINS::PANEL_SYNC_SHEET_PINS( wxWindow* aParent, SCH_SHEET* aSheet,
|
||||
wxNotebook* aNoteBook, int aIndex,
|
||||
SHEET_SYNCHRONIZATION_AGENT& aAgent,
|
||||
SCH_SHEET_PATH aPath ) :
|
||||
PANEL_SYNC_SHEET_PINS_BASE( aParent ),
|
||||
m_sheet( aSheet ), m_noteBook( aNoteBook ), m_index( aIndex ),
|
||||
m_sheetFileName( aSheet->GetFileName() ), m_agent( aAgent ), m_path( std::move( aPath ) )
|
||||
{
|
||||
m_btnUsePinAsTemplate->SetBitmap( KiBitmapBundle( BITMAPS::add_hierar_pin ) );
|
||||
m_btnUseLabelAsTemplate->SetBitmap( KiBitmapBundle( BITMAPS::add_hierarchical_label ) );
|
||||
m_btnUndo->SetBitmap( KiBitmapBundle( BITMAPS::left ) );
|
||||
|
||||
m_labelSheetName->SetLabel( aSheet->GetFileName() );
|
||||
m_labelSymName->SetLabel( aSheet->GetShownName( true ) );
|
||||
|
||||
|
||||
for( wxDataViewCtrl* view : { m_viewAssociated, m_viewSheetLabels, m_viewSheetPins } )
|
||||
{
|
||||
for( int col : { SHEET_SYNCHRONIZATION_MODEL::NAME, SHEET_SYNCHRONIZATION_MODEL::SHAPE } )
|
||||
{
|
||||
switch( col )
|
||||
{
|
||||
case SHEET_SYNCHRONIZATION_MODEL::NAME:
|
||||
view->AppendIconTextColumn( SHEET_SYNCHRONIZATION_MODEL::GetColName( col ), col );
|
||||
break;
|
||||
case SHEET_SYNCHRONIZATION_MODEL::SHAPE:
|
||||
view->AppendTextColumn( SHEET_SYNCHRONIZATION_MODEL::GetColName( col ), col );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::map<int, wxDataViewCtrl*> view_idx = std::map<int, wxDataViewCtrl*>{
|
||||
{ SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL, m_viewSheetLabels },
|
||||
{ SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN, m_viewSheetPins },
|
||||
{ SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED, m_viewAssociated },
|
||||
};
|
||||
|
||||
for( auto& [idx, view] : view_idx )
|
||||
{
|
||||
auto model = wxObjectDataPtr<SHEET_SYNCHRONIZATION_MODEL>(
|
||||
new SHEET_SYNCHRONIZATION_MODEL( m_agent, m_sheet, m_path ) );
|
||||
view->AssociateModel( model.get() );
|
||||
m_models.try_emplace( idx, std::move( model ) );
|
||||
}
|
||||
|
||||
for( auto& [idx, view] : view_idx )
|
||||
PostProcessModelSelection( idx, {} );
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::UpdateForms()
|
||||
{
|
||||
SHEET_SYNCHRONIZATION_ITEM_LIST labels_list, pins_list, associated_list;
|
||||
auto labels_ori = m_sheet->GetScreen()->Items().OfType( SCH_HIER_LABEL_T );
|
||||
std::vector<SCH_SHEET_PIN*> pins_ori = m_sheet->GetPins();
|
||||
|
||||
auto check_matched = [&]( SCH_HIERLABEL* label )
|
||||
{
|
||||
for( size_t i = 0; i < pins_ori.size(); i++ )
|
||||
{
|
||||
SCH_SHEET_PIN* cur_pin = pins_ori[i];
|
||||
if( label->GetText() == cur_pin->GetText() && label->GetShape() == cur_pin->GetShape() )
|
||||
{
|
||||
associated_list.push_back(
|
||||
std::make_shared<ASSOCIATED_SCH_LABEL_PIN>( label, cur_pin ) );
|
||||
pins_ori.erase( pins_ori.begin() + i );
|
||||
return;
|
||||
}
|
||||
}
|
||||
labels_list.push_back(
|
||||
std::make_shared<SCH_HIERLABEL_SYNCHRONIZATION_ITEM>( label, m_sheet ) );
|
||||
};
|
||||
|
||||
|
||||
for( const auto& item : labels_ori )
|
||||
check_matched( static_cast<SCH_HIERLABEL*>( item ) );
|
||||
|
||||
for( const auto& pin : pins_ori )
|
||||
pins_list.push_back( std::make_shared<SCH_SHEET_PIN_SYNCHRONIZATION_ITEM>(
|
||||
static_cast<SCH_SHEET_PIN*>( pin ), m_sheet ) );
|
||||
|
||||
for( const auto& [idx, model] : m_models )
|
||||
{
|
||||
switch( idx )
|
||||
{
|
||||
case SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL:
|
||||
model->UpdateItems( std::move( labels_list ) );
|
||||
break;
|
||||
case SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN:
|
||||
model->UpdateItems( std::move( pins_list ) );
|
||||
break;
|
||||
case SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED:
|
||||
model->UpdateItems( std::move( associated_list ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UpdatePageImage();
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_MODEL_PTR
|
||||
PANEL_SYNC_SHEET_PINS::GetModel( int aKind ) const
|
||||
{
|
||||
return m_models.at( aKind );
|
||||
}
|
||||
|
||||
|
||||
const wxString& PANEL_SYNC_SHEET_PINS::GetSheetFileName() const
|
||||
{
|
||||
return m_sheetFileName;
|
||||
}
|
||||
|
||||
|
||||
PANEL_SYNC_SHEET_PINS::~PANEL_SYNC_SHEET_PINS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool PANEL_SYNC_SHEET_PINS::HasUndefinedSheetPing() const
|
||||
{
|
||||
return !m_models.at( SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL )->GetCount()
|
||||
&& !m_models.at( SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN )->GetCount();
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnBtnAddLabelsClicked( wxCommandEvent& aEvent )
|
||||
{
|
||||
WXUNUSED( aEvent )
|
||||
|
||||
if( auto idx = m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->GetSelectedIndex();
|
||||
idx.has_value() )
|
||||
if( SHEET_SYNCHRONIZATION_ITE_PTR item =
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->GetSynchronizationItem(
|
||||
*idx ) )
|
||||
m_agent.PlaceHieraLable( m_sheet, m_path,
|
||||
static_cast<SCH_SHEET_PIN*>( item->GetItem() ) );
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnBtnAddSheetPinsClicked( wxCommandEvent& aEvent )
|
||||
{
|
||||
WXUNUSED( aEvent )
|
||||
|
||||
if( auto idx = m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->GetSelectedIndex();
|
||||
idx.has_value() )
|
||||
if( SHEET_SYNCHRONIZATION_ITE_PTR item =
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->GetSynchronizationItem(
|
||||
*idx ) )
|
||||
m_agent.PlaceSheetPin( m_sheet, m_path,
|
||||
static_cast<SCH_HIERLABEL*>( item->GetItem() ) );
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::GenericSync( SYNC_DIRECTION direction )
|
||||
{
|
||||
wxDataViewItem labelIdx = m_viewSheetLabels->GetSelection();
|
||||
wxDataViewItem pinIdx = m_viewSheetPins->GetSelection();
|
||||
|
||||
for( auto& idx : { labelIdx, pinIdx } )
|
||||
if( !idx.IsOk() )
|
||||
return;
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITE_PTR labelItem =
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->TakeItem( labelIdx );
|
||||
SHEET_SYNCHRONIZATION_ITE_PTR pinItem =
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->TakeItem( pinIdx );
|
||||
|
||||
for( const auto& item : { labelItem, pinItem } )
|
||||
if( !item )
|
||||
return;
|
||||
|
||||
auto label_ptr =
|
||||
std::static_pointer_cast<SCH_HIERLABEL_SYNCHRONIZATION_ITEM>( labelItem )->GetLabel();
|
||||
auto pin_ptr =
|
||||
std::static_pointer_cast<SCH_SHEET_PIN_SYNCHRONIZATION_ITEM>( pinItem )->GetPin();
|
||||
|
||||
switch( direction )
|
||||
{
|
||||
case SYNC_DIRECTION::USE_LABEL_AS_TEMPLATE:
|
||||
m_agent.ModifyItem(
|
||||
*pinItem,
|
||||
[&]()
|
||||
{
|
||||
pin_ptr->SetText( label_ptr->GetText() );
|
||||
pin_ptr->SetShape( label_ptr->GetShape() );
|
||||
},
|
||||
m_path );
|
||||
break;
|
||||
case SYNC_DIRECTION::USE_PIN_AS_TEMPLATE:
|
||||
m_agent.ModifyItem(
|
||||
*labelItem,
|
||||
[&]()
|
||||
{
|
||||
label_ptr->SetText( pin_ptr->GetText() );
|
||||
label_ptr->SetShape( pin_ptr->GetShape() );
|
||||
},
|
||||
m_path );
|
||||
break;
|
||||
}
|
||||
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED]->AppendItem(
|
||||
std::make_shared<ASSOCIATED_SCH_LABEL_PIN>( label_ptr, pin_ptr ) );
|
||||
UpdatePageImage();
|
||||
|
||||
for( auto idx :
|
||||
{ SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL, SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN } )
|
||||
PostProcessModelSelection( idx, {} );
|
||||
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->DoNotify();
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::UpdatePageImage() const
|
||||
{
|
||||
m_noteBook->SetPageImage( m_index, HasUndefinedSheetPing()
|
||||
? SYNC_SHEET_PIN_PREFERENCE::HAS_UNMATCHED
|
||||
: SYNC_SHEET_PIN_PREFERENCE::ALL_MATCHED );
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnBtnUsePinAsTemplateClicked( wxCommandEvent& aEvent )
|
||||
{
|
||||
WXUNUSED( aEvent )
|
||||
return GenericSync( SYNC_DIRECTION::USE_PIN_AS_TEMPLATE );
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnBtnUseLabelAsTemplateClicked( wxCommandEvent& aEvent )
|
||||
{
|
||||
WXUNUSED( aEvent )
|
||||
return GenericSync( SYNC_DIRECTION::USE_LABEL_AS_TEMPLATE );
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnBtnRmPinsClicked( wxCommandEvent& aEvent )
|
||||
{
|
||||
WXUNUSED( aEvent )
|
||||
wxDataViewItemArray array;
|
||||
m_viewSheetPins->GetSelections( array );
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->RemoveItems( array );
|
||||
PostProcessModelSelection( SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN, {} );
|
||||
UpdatePageImage();
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnBtnRmLabelsClicked( wxCommandEvent& aEvent )
|
||||
{
|
||||
WXUNUSED( aEvent )
|
||||
wxDataViewItemArray array;
|
||||
m_viewSheetLabels->GetSelections( array );
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->RemoveItems( array );
|
||||
PostProcessModelSelection( SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL, {} );
|
||||
UpdatePageImage();
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnBtnUndoClicked( wxCommandEvent& aEvent )
|
||||
{
|
||||
WXUNUSED( aEvent )
|
||||
wxDataViewItemArray indexes;
|
||||
m_viewAssociated->GetSelections( indexes );
|
||||
auto items = m_models[SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED]->TakeItems( indexes );
|
||||
|
||||
if( !items.size() )
|
||||
return;
|
||||
|
||||
for( auto& item : items )
|
||||
{
|
||||
auto associated = std::static_pointer_cast<ASSOCIATED_SCH_LABEL_PIN>( item );
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->AppendItem(
|
||||
std::make_shared<SCH_HIERLABEL_SYNCHRONIZATION_ITEM>( associated->GetLabel(),
|
||||
m_sheet ) );
|
||||
m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->AppendItem(
|
||||
std::make_shared<SCH_SHEET_PIN_SYNCHRONIZATION_ITEM>( associated->GetPin(),
|
||||
m_sheet ) );
|
||||
}
|
||||
PostProcessModelSelection( SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED, {} );
|
||||
UpdatePageImage();
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::PostProcessModelSelection( int aIdex, wxDataViewItem const& aItem )
|
||||
{
|
||||
if( aItem.IsOk() )
|
||||
m_models[aIdex]->OnRowSelected( m_models[aIdex]->GetRow( aItem ) );
|
||||
else
|
||||
m_models[aIdex]->OnRowSelected( {} );
|
||||
|
||||
switch( aIdex )
|
||||
{
|
||||
case SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN:
|
||||
{
|
||||
for( auto btn : { m_btnAddLabels, m_btnRmPins } )
|
||||
btn->Enable( m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->HasSelectedIndex() );
|
||||
break;
|
||||
}
|
||||
case SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL:
|
||||
{
|
||||
for( auto btn : { m_btnAddSheetPins, m_btnRmLabels } )
|
||||
btn->Enable( m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->HasSelectedIndex() );
|
||||
break;
|
||||
}
|
||||
case SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED:
|
||||
{
|
||||
m_btnUndo->Enable( m_models[SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED]->HasSelectedIndex() );
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
if( aIdex != SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED )
|
||||
{
|
||||
for( auto btn : { m_btnUsePinAsTemplate, m_btnUseLabelAsTemplate } )
|
||||
{
|
||||
btn->Enable( m_models[SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN]->HasSelectedIndex()
|
||||
&& m_models[SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL]->HasSelectedIndex() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnViewSheetLabelCellClicked( wxDataViewEvent& aEvent )
|
||||
{
|
||||
PostProcessModelSelection( SHEET_SYNCHRONIZATION_MODEL::HIRE_LABEL, aEvent.GetItem() );
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnViewSheetPinCellClicked( wxDataViewEvent& aEvent )
|
||||
{
|
||||
PostProcessModelSelection( SHEET_SYNCHRONIZATION_MODEL::SHEET_PIN, aEvent.GetItem() );
|
||||
}
|
||||
|
||||
|
||||
void PANEL_SYNC_SHEET_PINS::OnViewMatchedCellClicked( wxDataViewEvent& aEvent )
|
||||
{
|
||||
PostProcessModelSelection( SHEET_SYNCHRONIZATION_MODEL::ASSOCIATED, aEvent.GetItem() );
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 PANEL_SYNC_SHEET_PINS_H
|
||||
#define PANEL_SYNC_SHEET_PINS_H
|
||||
|
||||
#include "panel_sync_sheet_pins_base.h"
|
||||
#include "sch_sheet_path.h"
|
||||
|
||||
#include <map>
|
||||
#include <wx/dataview.h>
|
||||
|
||||
class SCH_SHEET;
|
||||
class wxNotebook;
|
||||
class SCH_HIERLABEL;
|
||||
class SCH_SHEET_PIN;
|
||||
class SHEET_SYNCHRONIZATION_MODEL;
|
||||
class EDA_ITEM;
|
||||
class SHEET_SYNCHRONIZATION_AGENT;
|
||||
using SHEET_SYNCHRONIZATION_MODEL_PTR = wxObjectDataPtr<SHEET_SYNCHRONIZATION_MODEL>;
|
||||
|
||||
using SYNC_SHEET_PINT_MODELS = std::map<int, SHEET_SYNCHRONIZATION_MODEL_PTR>;
|
||||
|
||||
class PANEL_SYNC_SHEET_PINS : public PANEL_SYNC_SHEET_PINS_BASE
|
||||
{
|
||||
public:
|
||||
enum class SYNC_DIRECTION
|
||||
{
|
||||
USE_LABEL_AS_TEMPLATE,
|
||||
USE_PIN_AS_TEMPLATE
|
||||
};
|
||||
|
||||
|
||||
PANEL_SYNC_SHEET_PINS( wxWindow* aParent, SCH_SHEET* aSheet, wxNotebook* aNoteBook, int aIndex,
|
||||
SHEET_SYNCHRONIZATION_AGENT& aAgent, SCH_SHEET_PATH aPath );
|
||||
|
||||
~PANEL_SYNC_SHEET_PINS() override;
|
||||
|
||||
bool HasUndefinedSheetPing() const;
|
||||
|
||||
void UpdateForms();
|
||||
|
||||
SHEET_SYNCHRONIZATION_MODEL_PTR GetModel( int aKind ) const;
|
||||
|
||||
const wxString& GetSheetFileName() const;
|
||||
|
||||
SCH_SHEET_PATH const& GetSheetPath() const { return m_path; }
|
||||
|
||||
protected:
|
||||
void OnViewSheetPinCellClicked( wxDataViewEvent& event ) override;
|
||||
|
||||
void OnBtnAddSheetPinsClicked( wxCommandEvent& event ) override;
|
||||
|
||||
void OnBtnRmPinsClicked( wxCommandEvent& event ) override;
|
||||
|
||||
void OnBtnUsePinAsTemplateClicked( wxCommandEvent& event ) override;
|
||||
|
||||
void OnBtnUseLabelAsTemplateClicked( wxCommandEvent& event ) override;
|
||||
|
||||
void OnBtnUndoClicked( wxCommandEvent& event ) override;
|
||||
|
||||
void OnViewSheetLabelCellClicked( wxDataViewEvent& event ) override;
|
||||
|
||||
void OnBtnAddLabelsClicked( wxCommandEvent& event ) override;
|
||||
|
||||
void OnBtnRmLabelsClicked( wxCommandEvent& event ) override;
|
||||
|
||||
void OnViewMatchedCellClicked( wxDataViewEvent& event ) override;
|
||||
|
||||
void PostProcessModelSelection( int aIdex, wxDataViewItem const& aItem );
|
||||
|
||||
void GenericSync( SYNC_DIRECTION direction );
|
||||
|
||||
void UpdatePageImage() const;
|
||||
|
||||
|
||||
private:
|
||||
SCH_SHEET* m_sheet;
|
||||
wxNotebook* m_noteBook;
|
||||
int m_index;
|
||||
wxString m_sheetFileName;
|
||||
SYNC_SHEET_PINT_MODELS m_models;
|
||||
SHEET_SYNCHRONIZATION_AGENT& m_agent;
|
||||
SCH_SHEET_PATH m_path;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,250 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "panel_sync_sheet_pins_base.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PANEL_SYNC_SHEET_PINS_BASE::PANEL_SYNC_SHEET_PINS_BASE( wxWindow* parent, wxWindowID id,
|
||||
const wxPoint& pos, const wxSize& size,
|
||||
long style, const wxString& name ) :
|
||||
wxPanel( parent, id, pos, size, style, name )
|
||||
{
|
||||
wxBoxSizer* bSizer3;
|
||||
bSizer3 = new wxBoxSizer( wxHORIZONTAL );
|
||||
|
||||
m_panel11 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* bSizer41;
|
||||
bSizer41 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
wxBoxSizer* bSizer61;
|
||||
bSizer61 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_labelSymName = new wxStaticText( m_panel11, wxID_ANY, _( "Symbol name" ), wxDefaultPosition,
|
||||
wxDefaultSize, wxALIGN_CENTER_HORIZONTAL | wxBORDER_THEME );
|
||||
m_labelSymName->Wrap( -1 );
|
||||
bSizer61->Add( m_labelSymName, 0, wxALL | wxEXPAND, 0 );
|
||||
|
||||
m_viewSheetPins = new wxDataViewCtrl( m_panel11, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||
wxDV_HORIZ_RULES | wxDV_MULTIPLE | wxDV_ROW_LINES
|
||||
| wxDV_VERT_RULES );
|
||||
bSizer61->Add( m_viewSheetPins, 1, wxALL | wxEXPAND, 0 );
|
||||
|
||||
wxBoxSizer* bSizer51;
|
||||
bSizer51 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_btnAddLabels = new wxButton( m_panel11, wxID_ANY, _( "Add Hierarchical Labels" ),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bSizer51->Add( m_btnAddLabels, 0, wxBOTTOM | wxEXPAND | wxTOP, 5 );
|
||||
|
||||
m_btnRmPins = new wxButton( m_panel11, wxID_ANY, _( "Delete Sheet Pins" ), wxDefaultPosition,
|
||||
wxDefaultSize, 0 );
|
||||
bSizer51->Add( m_btnRmPins, 0, wxBOTTOM | wxEXPAND | wxTOP, 5 );
|
||||
|
||||
|
||||
bSizer61->Add( bSizer51, 0, wxEXPAND, 5 );
|
||||
|
||||
|
||||
bSizer41->Add( bSizer61, 1, wxEXPAND, 5 );
|
||||
|
||||
|
||||
m_panel11->SetSizer( bSizer41 );
|
||||
m_panel11->Layout();
|
||||
bSizer41->Fit( m_panel11 );
|
||||
bSizer3->Add( m_panel11, 1, wxEXPAND | wxALL, 5 );
|
||||
|
||||
m_panel1 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* bSizer4;
|
||||
bSizer4 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
wxBoxSizer* bSizer6;
|
||||
bSizer6 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_labelSheetName =
|
||||
new wxStaticText( m_panel1, wxID_ANY, _( "Sheet name" ), wxDefaultPosition,
|
||||
wxDefaultSize, wxALIGN_CENTER_HORIZONTAL | wxBORDER_THEME );
|
||||
m_labelSheetName->Wrap( -1 );
|
||||
bSizer6->Add( m_labelSheetName, 0, wxALL | wxEXPAND, 0 );
|
||||
|
||||
m_viewSheetLabels = new wxDataViewCtrl( m_panel1, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||
wxDV_HORIZ_RULES | wxDV_MULTIPLE | wxDV_ROW_LINES
|
||||
| wxDV_VERT_RULES );
|
||||
bSizer6->Add( m_viewSheetLabels, 1, wxALL | wxEXPAND, 0 );
|
||||
|
||||
wxBoxSizer* bSizer5;
|
||||
bSizer5 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_btnAddSheetPins = new wxButton( m_panel1, wxID_ANY, _( "Add Sheet Pins" ), wxDefaultPosition,
|
||||
wxDefaultSize, 0 );
|
||||
bSizer5->Add( m_btnAddSheetPins, 0, wxBOTTOM | wxEXPAND | wxTOP, 5 );
|
||||
|
||||
m_btnRmLabels = new wxButton( m_panel1, wxID_ANY, _( "Delete Hierarchical Labels" ),
|
||||
wxDefaultPosition, wxDefaultSize, 0 );
|
||||
bSizer5->Add( m_btnRmLabels, 0, wxBOTTOM | wxEXPAND | wxTOP, 5 );
|
||||
|
||||
|
||||
bSizer6->Add( bSizer5, 0, wxEXPAND, 5 );
|
||||
|
||||
|
||||
bSizer4->Add( bSizer6, 1, wxEXPAND, 5 );
|
||||
|
||||
|
||||
m_panel1->SetSizer( bSizer4 );
|
||||
m_panel1->Layout();
|
||||
bSizer4->Fit( m_panel1 );
|
||||
bSizer3->Add( m_panel1, 1, wxEXPAND | wxALL, 5 );
|
||||
|
||||
m_panel3 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* bSizer13;
|
||||
bSizer13 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
|
||||
bSizer13->Add( 0, 0, 1, wxEXPAND, 5 );
|
||||
|
||||
m_panel8 = new wxPanel( m_panel3, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* bSizer14;
|
||||
bSizer14 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_btnUseLabelAsTemplate = new wxBitmapButton(
|
||||
m_panel8, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW | 0 );
|
||||
m_btnUseLabelAsTemplate->SetToolTip( _( "Change sheet pin to hierarchical label" ) );
|
||||
|
||||
bSizer14->Add( m_btnUseLabelAsTemplate, 0, wxBOTTOM | wxEXPAND | wxLEFT | wxRIGHT, 5 );
|
||||
|
||||
m_btnUsePinAsTemplate = new wxBitmapButton( m_panel8, wxID_ANY, wxNullBitmap, wxDefaultPosition,
|
||||
wxDefaultSize, wxBU_AUTODRAW | 0 );
|
||||
m_btnUsePinAsTemplate->SetToolTip( _( "Change hierarchical label to sheet pin" ) );
|
||||
|
||||
bSizer14->Add( m_btnUsePinAsTemplate, 0, wxALL | wxEXPAND, 5 );
|
||||
|
||||
m_btnUndo = new wxBitmapButton( m_panel8, wxID_ANY, wxNullBitmap, wxDefaultPosition,
|
||||
wxDefaultSize, wxBU_AUTODRAW | 0 );
|
||||
m_btnUndo->SetToolTip( _( "Break sheet pin and hierarchical label association(s)" ) );
|
||||
|
||||
bSizer14->Add( m_btnUndo, 0, wxALL | wxBOTTOM | wxLEFT | wxRIGHT, 5 );
|
||||
|
||||
|
||||
m_panel8->SetSizer( bSizer14 );
|
||||
m_panel8->Layout();
|
||||
bSizer14->Fit( m_panel8 );
|
||||
bSizer13->Add( m_panel8, 0, wxEXPAND | wxALL, 0 );
|
||||
|
||||
|
||||
bSizer13->Add( 0, 0, 2, wxEXPAND, 5 );
|
||||
|
||||
|
||||
m_panel3->SetSizer( bSizer13 );
|
||||
m_panel3->Layout();
|
||||
bSizer13->Fit( m_panel3 );
|
||||
bSizer3->Add( m_panel3, 0, wxEXPAND | wxALL, 0 );
|
||||
|
||||
m_panel4 = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* bSizer15;
|
||||
bSizer15 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
wxBoxSizer* bSizer16;
|
||||
bSizer16 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_viewAssociated = new wxDataViewCtrl( m_panel4, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||
wxDV_HORIZ_RULES | wxDV_MULTIPLE | wxDV_ROW_LINES
|
||||
| wxDV_VERT_RULES );
|
||||
bSizer16->Add( m_viewAssociated, 1, wxALL | wxEXPAND, 5 );
|
||||
|
||||
|
||||
bSizer15->Add( bSizer16, 1, wxEXPAND, 5 );
|
||||
|
||||
|
||||
m_panel4->SetSizer( bSizer15 );
|
||||
m_panel4->Layout();
|
||||
bSizer15->Fit( m_panel4 );
|
||||
bSizer3->Add( m_panel4, 1, wxEXPAND | wxALL, 5 );
|
||||
|
||||
|
||||
this->SetSizer( bSizer3 );
|
||||
this->Layout();
|
||||
|
||||
// Connect Events
|
||||
m_viewSheetPins->Connect(
|
||||
wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,
|
||||
wxDataViewEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnViewSheetPinCellClicked ), NULL,
|
||||
this );
|
||||
m_btnAddLabels->Connect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnAddLabelsClicked ), NULL,
|
||||
this );
|
||||
m_btnRmPins->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnRmPinsClicked ),
|
||||
NULL, this );
|
||||
m_viewSheetLabels->Connect(
|
||||
wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,
|
||||
wxDataViewEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnViewSheetLabelCellClicked ), NULL,
|
||||
this );
|
||||
m_btnAddSheetPins->Connect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnAddSheetPinsClicked ), NULL,
|
||||
this );
|
||||
m_btnRmLabels->Connect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnRmLabelsClicked ), NULL, this );
|
||||
m_btnUseLabelAsTemplate->Connect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnUseLabelAsTemplateClicked ),
|
||||
NULL, this );
|
||||
m_btnUsePinAsTemplate->Connect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnUsePinAsTemplateClicked ), NULL,
|
||||
this );
|
||||
m_btnUndo->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnUndoClicked ), NULL,
|
||||
this );
|
||||
m_viewAssociated->Connect(
|
||||
wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,
|
||||
wxDataViewEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnViewMatchedCellClicked ), NULL,
|
||||
this );
|
||||
}
|
||||
|
||||
PANEL_SYNC_SHEET_PINS_BASE::~PANEL_SYNC_SHEET_PINS_BASE()
|
||||
{
|
||||
// Disconnect Events
|
||||
m_viewSheetPins->Disconnect(
|
||||
wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,
|
||||
wxDataViewEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnViewSheetPinCellClicked ), NULL,
|
||||
this );
|
||||
m_btnAddLabels->Disconnect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnAddLabelsClicked ), NULL,
|
||||
this );
|
||||
m_btnRmPins->Disconnect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnRmPinsClicked ), NULL, this );
|
||||
m_viewSheetLabels->Disconnect(
|
||||
wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,
|
||||
wxDataViewEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnViewSheetLabelCellClicked ), NULL,
|
||||
this );
|
||||
m_btnAddSheetPins->Disconnect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnAddSheetPinsClicked ), NULL,
|
||||
this );
|
||||
m_btnRmLabels->Disconnect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnRmLabelsClicked ), NULL, this );
|
||||
m_btnUseLabelAsTemplate->Disconnect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnUseLabelAsTemplateClicked ),
|
||||
NULL, this );
|
||||
m_btnUsePinAsTemplate->Disconnect(
|
||||
wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnUsePinAsTemplateClicked ), NULL,
|
||||
this );
|
||||
m_btnUndo->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
|
||||
wxCommandEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnBtnUndoClicked ),
|
||||
NULL, this );
|
||||
m_viewAssociated->Disconnect(
|
||||
wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,
|
||||
wxDataViewEventHandler( PANEL_SYNC_SHEET_PINS_BASE::OnViewMatchedCellClicked ), NULL,
|
||||
this );
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wx/artprov.h>
|
||||
#include <wx/xrc/xmlres.h>
|
||||
#include <wx/intl.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/font.h>
|
||||
#include <wx/colour.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/dataview.h>
|
||||
#include <wx/button.h>
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/image.h>
|
||||
#include <wx/icon.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/bmpbuttn.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// Class PANEL_SYNC_SHEET_PINS_BASE
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class PANEL_SYNC_SHEET_PINS_BASE : public wxPanel
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
wxPanel* m_panel11;
|
||||
wxStaticText* m_labelSymName;
|
||||
wxDataViewCtrl* m_viewSheetPins;
|
||||
wxButton* m_btnAddLabels;
|
||||
wxButton* m_btnRmPins;
|
||||
wxPanel* m_panel1;
|
||||
wxStaticText* m_labelSheetName;
|
||||
wxDataViewCtrl* m_viewSheetLabels;
|
||||
wxButton* m_btnAddSheetPins;
|
||||
wxButton* m_btnRmLabels;
|
||||
wxPanel* m_panel3;
|
||||
wxPanel* m_panel8;
|
||||
wxBitmapButton* m_btnUseLabelAsTemplate;
|
||||
wxBitmapButton* m_btnUsePinAsTemplate;
|
||||
wxBitmapButton* m_btnUndo;
|
||||
wxPanel* m_panel4;
|
||||
wxDataViewCtrl* m_viewAssociated;
|
||||
|
||||
// Virtual event handlers, override them in your derived class
|
||||
virtual void OnViewSheetPinCellClicked( wxDataViewEvent& event ) { event.Skip(); }
|
||||
virtual void OnBtnAddLabelsClicked( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void OnBtnRmPinsClicked( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void OnViewSheetLabelCellClicked( wxDataViewEvent& event ) { event.Skip(); }
|
||||
virtual void OnBtnAddSheetPinsClicked( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void OnBtnRmLabelsClicked( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void OnBtnUseLabelAsTemplateClicked( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void OnBtnUsePinAsTemplateClicked( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void OnBtnUndoClicked( wxCommandEvent& event ) { event.Skip(); }
|
||||
virtual void OnViewMatchedCellClicked( wxDataViewEvent& event ) { event.Skip(); }
|
||||
|
||||
|
||||
public:
|
||||
PANEL_SYNC_SHEET_PINS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxSize( 666, 414 ),
|
||||
long style = wxTAB_TRAVERSAL,
|
||||
const wxString& name = wxEmptyString );
|
||||
|
||||
~PANEL_SYNC_SHEET_PINS_BASE();
|
||||
};
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 "sheet_synchronization_agent.h"
|
||||
#include "sheet_synchronization_item.h"
|
||||
|
||||
#include <sch_base_frame.h>
|
||||
#include <sch_commit.h>
|
||||
#include <sch_edit_frame.h>
|
||||
#include <sch_sheet_pin.h>
|
||||
|
||||
SHEET_SYNCHRONIZATION_AGENT::SHEET_SYNCHRONIZATION_AGENT( DO_MODIFY_ITEM aDoModify,
|
||||
DO_DELETE_ITEM aNotifyItemChange,
|
||||
DO_PLACE_ITEM aPlaceItem,
|
||||
TOOL_MANAGER* aToolManager,
|
||||
SCH_EDIT_FRAME* a_frame ) :
|
||||
m_doModify( std::move( aDoModify ) ),
|
||||
m_doDelete( std::move( aNotifyItemChange ) ), m_doPlaceItem( std::move( aPlaceItem ) ),
|
||||
m_toolManager( aToolManager ), m_frame( a_frame )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_AGENT::~SHEET_SYNCHRONIZATION_AGENT() = default;
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_AGENT::ModifyItem( SHEET_SYNCHRONIZATION_ITEM& aItem,
|
||||
std::function<void()> aDoModify,
|
||||
SCH_SHEET_PATH const& aPath )
|
||||
{
|
||||
return ModifyItem( aItem.GetItem(), aDoModify, aPath, aItem.GetKind() );
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_AGENT::ModifyItem( SCH_ITEM* sch_item, std::function<void()> aDoModify,
|
||||
SCH_SHEET_PATH const& aPath,
|
||||
SHEET_SYNCHRONIZATION_ITEM_KIND aKind )
|
||||
{
|
||||
if( !aDoModify )
|
||||
return;
|
||||
|
||||
switch( aKind )
|
||||
{
|
||||
case SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL:
|
||||
{
|
||||
m_doModify( sch_item, aPath, aDoModify );
|
||||
break;
|
||||
}
|
||||
case SHEET_SYNCHRONIZATION_ITEM_KIND::SHEET_PIN:
|
||||
|
||||
{
|
||||
SCH_SHEET_PATH path_cp = aPath;
|
||||
path_cp.pop_back();
|
||||
m_doModify( sch_item, path_cp, aDoModify );
|
||||
break;
|
||||
}
|
||||
case SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL_AND_SHEET_PIN: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_AGENT::RemoveItem( SHEET_SYNCHRONIZATION_ITEM& aItem, SCH_SHEET* aSheet,
|
||||
SCH_SHEET_PATH const& aPath )
|
||||
{
|
||||
if( !aSheet )
|
||||
return;
|
||||
|
||||
switch( aItem.GetKind() )
|
||||
{
|
||||
case SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL:
|
||||
{
|
||||
m_doDelete( aItem.GetItem(), aPath );
|
||||
break;
|
||||
}
|
||||
case SHEET_SYNCHRONIZATION_ITEM_KIND::SHEET_PIN:
|
||||
|
||||
{
|
||||
SCH_SHEET_PATH path_cp = aPath;
|
||||
path_cp.pop_back();
|
||||
m_doDelete( aItem.GetItem(), path_cp );
|
||||
break;
|
||||
}
|
||||
case SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL_AND_SHEET_PIN: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_AGENT::PlaceSheetPin( SCH_SHEET* aSheet, SCH_SHEET_PATH const& aPath,
|
||||
SCH_HIERLABEL* aLabel )
|
||||
{
|
||||
SCH_SHEET_PATH cp = aPath;
|
||||
cp.pop_back();
|
||||
m_doPlaceItem( aSheet, cp, SHEET_SYNCHRONIZATION_PLACEMENT::PLACE_SHEET_PIN, aLabel );
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_AGENT::PlaceHieraLable( SCH_SHEET* aSheet, SCH_SHEET_PATH const& aPath,
|
||||
SCH_SHEET_PIN* aPin )
|
||||
{
|
||||
m_doPlaceItem( aSheet, aPath, SHEET_SYNCHRONIZATION_PLACEMENT::PLACE_HIERLABEL, aPin );
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 SHEET_SYNCHRONIZATION_AGENT_H
|
||||
#define SHEET_SYNCHRONIZATION_AGENT_H
|
||||
|
||||
#include <functional>
|
||||
#include <sch_sheet_path.h>
|
||||
|
||||
class EDA_ITEM;
|
||||
class SCH_HIERLABEL;
|
||||
class SCH_SHEET_PIN;
|
||||
class TOOL_MANAGER;
|
||||
class SHEET_SYNCHRONIZATION_ITEM;
|
||||
class SCH_SHEET;
|
||||
class SCH_EDIT_FRAME;
|
||||
class SCH_SHEET_PATH;
|
||||
class SCH_ITEM;
|
||||
enum class SHEET_SYNCHRONIZATION_ITEM_KIND;
|
||||
|
||||
/**
|
||||
* @brief Agent for all the modifications while syncing the sheet pin and hierlabel
|
||||
*
|
||||
*/
|
||||
class SHEET_SYNCHRONIZATION_AGENT
|
||||
{
|
||||
public:
|
||||
enum SHEET_SYNCHRONIZATION_PLACEMENT
|
||||
{
|
||||
PLACE_SHEET_PIN,
|
||||
PLACE_HIERLABEL
|
||||
};
|
||||
|
||||
using DO_DELETE_ITEM = std::function<void( EDA_ITEM*, SCH_SHEET_PATH )>;
|
||||
|
||||
using MODIFICATION = std::function<void()>;
|
||||
|
||||
using DO_MODIFY_ITEM = std::function<void( EDA_ITEM*, SCH_SHEET_PATH, MODIFICATION )>;
|
||||
|
||||
using DO_PLACE_ITEM = std::function<void( SCH_SHEET*, SCH_SHEET_PATH,
|
||||
SHEET_SYNCHRONIZATION_PLACEMENT, EDA_ITEM* )>;
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_AGENT( DO_MODIFY_ITEM aDoModify, DO_DELETE_ITEM aDoDelete,
|
||||
DO_PLACE_ITEM aPlaceItem, TOOL_MANAGER* aToolManager,
|
||||
SCH_EDIT_FRAME* a_frame );
|
||||
~SHEET_SYNCHRONIZATION_AGENT();
|
||||
|
||||
void ModifyItem( SHEET_SYNCHRONIZATION_ITEM& aItem, std::function<void()> aDoModify,
|
||||
SCH_SHEET_PATH const& aPath );
|
||||
|
||||
void ModifyItem( SCH_ITEM* aItem, std::function<void()> aDoModify, SCH_SHEET_PATH const& aPath,
|
||||
SHEET_SYNCHRONIZATION_ITEM_KIND aKind );
|
||||
|
||||
void RemoveItem( SHEET_SYNCHRONIZATION_ITEM& aItem, SCH_SHEET* aSheet,
|
||||
SCH_SHEET_PATH const& aPath );
|
||||
|
||||
void PlaceSheetPin( SCH_SHEET* aSheet, SCH_SHEET_PATH const& aPath, SCH_HIERLABEL* aLabel );
|
||||
|
||||
void PlaceHieraLable( SCH_SHEET* aSheet, SCH_SHEET_PATH const& aPath, SCH_SHEET_PIN* aPin );
|
||||
|
||||
|
||||
private:
|
||||
DO_MODIFY_ITEM m_doModify;
|
||||
DO_DELETE_ITEM m_doDelete;
|
||||
DO_PLACE_ITEM m_doPlaceItem;
|
||||
TOOL_MANAGER* m_toolManager;
|
||||
SCH_EDIT_FRAME* m_frame;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 "sheet_synchronization_item.h"
|
||||
#include "bitmaps/bitmap_types.h"
|
||||
#include "sync_sheet_pin/sheet_synchronization_item.h"
|
||||
#include "sync_sheet_pin/sync_sheet_pin_preference.h"
|
||||
#include <sch_label.h>
|
||||
#include <sch_sheet_pin.h>
|
||||
#include <bitmaps/bitmaps_list.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <sch_screen.h>
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/image.h>
|
||||
|
||||
|
||||
SCH_HIERLABEL_SYNCHRONIZATION_ITEM::SCH_HIERLABEL_SYNCHRONIZATION_ITEM( SCH_HIERLABEL* aLabel,
|
||||
SCH_SHEET* aSheet ) :
|
||||
m_label( aLabel ),
|
||||
m_sheet( aSheet )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
wxString SCH_HIERLABEL_SYNCHRONIZATION_ITEM::GetName() const
|
||||
{
|
||||
return m_label->GetShownText( true );
|
||||
}
|
||||
|
||||
|
||||
int SCH_HIERLABEL_SYNCHRONIZATION_ITEM::GetShape() const
|
||||
{
|
||||
return m_label->GetShape();
|
||||
}
|
||||
|
||||
|
||||
wxBitmap& SCH_HIERLABEL_SYNCHRONIZATION_ITEM::GetBitmap() const
|
||||
{
|
||||
static wxBitmap bitMap =
|
||||
KiBitmap( BITMAPS::add_hierarchical_label, SYNC_SHEET_PIN_PREFERENCE::NORMAL_HEIGHT );
|
||||
return bitMap;
|
||||
}
|
||||
|
||||
|
||||
SCH_ITEM* SCH_HIERLABEL_SYNCHRONIZATION_ITEM::GetItem() const
|
||||
{
|
||||
return m_label;
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITEM_KIND SCH_HIERLABEL_SYNCHRONIZATION_ITEM::GetKind() const
|
||||
{
|
||||
return SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL;
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET_PIN_SYNCHRONIZATION_ITEM::SCH_SHEET_PIN_SYNCHRONIZATION_ITEM( SCH_SHEET_PIN* aPin,
|
||||
SCH_SHEET* aSheet ) :
|
||||
m_pin( aPin ),
|
||||
m_sheet( aSheet )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
wxString SCH_SHEET_PIN_SYNCHRONIZATION_ITEM::GetName() const
|
||||
{
|
||||
return m_pin->GetShownText( true );
|
||||
}
|
||||
|
||||
|
||||
int SCH_SHEET_PIN_SYNCHRONIZATION_ITEM::GetShape() const
|
||||
{
|
||||
return m_pin->GetShape();
|
||||
}
|
||||
|
||||
|
||||
wxBitmap& SCH_SHEET_PIN_SYNCHRONIZATION_ITEM::GetBitmap() const
|
||||
{
|
||||
static wxBitmap bitMap =
|
||||
KiBitmap( BITMAPS::add_hierar_pin, SYNC_SHEET_PIN_PREFERENCE::NORMAL_HEIGHT );
|
||||
return bitMap;
|
||||
}
|
||||
|
||||
|
||||
SCH_ITEM* SCH_SHEET_PIN_SYNCHRONIZATION_ITEM::GetItem() const
|
||||
{
|
||||
return m_pin;
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITEM_KIND SCH_SHEET_PIN_SYNCHRONIZATION_ITEM::GetKind() const
|
||||
{
|
||||
return SHEET_SYNCHRONIZATION_ITEM_KIND::SHEET_PIN;
|
||||
}
|
||||
|
||||
|
||||
ASSOCIATED_SCH_LABEL_PIN::ASSOCIATED_SCH_LABEL_PIN( SCH_HIERLABEL* aLabel, SCH_SHEET_PIN* aPin ) :
|
||||
m_label( aLabel ), m_pin( aPin )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ASSOCIATED_SCH_LABEL_PIN::ASSOCIATED_SCH_LABEL_PIN( SCH_HIERLABEL_SYNCHRONIZATION_ITEM* aLabel,
|
||||
SCH_SHEET_PIN_SYNCHRONIZATION_ITEM* aPin ) :
|
||||
ASSOCIATED_SCH_LABEL_PIN( aLabel->GetLabel(), aPin->GetPin() )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
wxString ASSOCIATED_SCH_LABEL_PIN::GetName() const
|
||||
{
|
||||
return m_label->GetShownText( true );
|
||||
}
|
||||
|
||||
|
||||
int ASSOCIATED_SCH_LABEL_PIN::GetShape() const
|
||||
{
|
||||
return m_label->GetShape();
|
||||
}
|
||||
|
||||
|
||||
wxBitmap& ASSOCIATED_SCH_LABEL_PIN::GetBitmap() const
|
||||
{
|
||||
static auto label_and_pin_icon = ( []{
|
||||
wxBitmap left = KiBitmap( BITMAPS::add_hierar_pin, SYNC_SHEET_PIN_PREFERENCE::NORMAL_HEIGHT );
|
||||
wxBitmap right =
|
||||
KiBitmap( BITMAPS::add_hierarchical_label, SYNC_SHEET_PIN_PREFERENCE::NORMAL_HEIGHT );
|
||||
wxImage img( wxSize{ SYNC_SHEET_PIN_PREFERENCE::NORMAL_WIDTH * 2,
|
||||
SYNC_SHEET_PIN_PREFERENCE::NORMAL_HEIGHT } );
|
||||
img.Paste( left.ConvertToImage(), 0, 0 );
|
||||
img.Paste( right.ConvertToImage(), SYNC_SHEET_PIN_PREFERENCE::NORMAL_WIDTH, 0 );
|
||||
return wxBitmap(img);
|
||||
} )();
|
||||
|
||||
return label_and_pin_icon;
|
||||
}
|
||||
|
||||
|
||||
SCH_ITEM* ASSOCIATED_SCH_LABEL_PIN::GetItem() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITEM_KIND ASSOCIATED_SCH_LABEL_PIN::GetKind() const
|
||||
{
|
||||
return SHEET_SYNCHRONIZATION_ITEM_KIND::HIERLABEL_AND_SHEET_PIN;
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 SHEET_SYNCHRONIZATION_ITEM_H
|
||||
#define SHEET_SYNCHRONIZATION_ITEM_H
|
||||
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/string.h>
|
||||
#include <functional>
|
||||
|
||||
class EDA_ITEM;
|
||||
class SCH_HIERLABEL;
|
||||
class SCH_SHEET_PIN;
|
||||
class SCH_SHEET;
|
||||
class SCH_COMMIT;
|
||||
class SCH_ITEM;
|
||||
|
||||
enum class SHEET_SYNCHRONIZATION_ITEM_KIND
|
||||
{
|
||||
HIERLABEL,
|
||||
SHEET_PIN,
|
||||
HIERLABEL_AND_SHEET_PIN
|
||||
};
|
||||
|
||||
using SCREEN_UPDATER = std::function<void( EDA_ITEM* )>;
|
||||
class SHEET_SYNCHRONIZATION_ITEM
|
||||
{
|
||||
public:
|
||||
virtual ~SHEET_SYNCHRONIZATION_ITEM() = default;
|
||||
|
||||
virtual wxString GetName() const = 0;
|
||||
|
||||
virtual int GetShape() const = 0;
|
||||
|
||||
virtual wxBitmap& GetBitmap() const = 0;
|
||||
|
||||
virtual SCH_ITEM* GetItem() const = 0;
|
||||
|
||||
virtual SHEET_SYNCHRONIZATION_ITEM_KIND GetKind() const = 0;
|
||||
};
|
||||
|
||||
class SCH_HIERLABEL_SYNCHRONIZATION_ITEM : public SHEET_SYNCHRONIZATION_ITEM
|
||||
{
|
||||
public:
|
||||
SCH_HIERLABEL_SYNCHRONIZATION_ITEM( SCH_HIERLABEL* aLabel, SCH_SHEET* aSheet );
|
||||
|
||||
SCH_HIERLABEL* GetLabel() const { return m_label; }
|
||||
|
||||
wxString GetName() const override;
|
||||
|
||||
int GetShape() const override;
|
||||
|
||||
wxBitmap& GetBitmap() const override;
|
||||
|
||||
SCH_ITEM* GetItem() const override;
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITEM_KIND GetKind() const override;
|
||||
|
||||
private:
|
||||
SCH_HIERLABEL* m_label;
|
||||
SCH_SHEET* m_sheet;
|
||||
};
|
||||
|
||||
|
||||
class SCH_SHEET_PIN_SYNCHRONIZATION_ITEM : public SHEET_SYNCHRONIZATION_ITEM
|
||||
{
|
||||
public:
|
||||
SCH_SHEET_PIN_SYNCHRONIZATION_ITEM( SCH_SHEET_PIN* aPin, SCH_SHEET* aSheet );
|
||||
|
||||
SCH_SHEET_PIN* GetPin() const { return m_pin; }
|
||||
|
||||
wxString GetName() const override;
|
||||
|
||||
int GetShape() const override;
|
||||
|
||||
wxBitmap& GetBitmap() const override;
|
||||
|
||||
SCH_ITEM* GetItem() const override;
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITEM_KIND GetKind() const override;
|
||||
|
||||
private:
|
||||
SCH_SHEET_PIN* m_pin;
|
||||
SCH_SHEET* m_sheet;
|
||||
};
|
||||
|
||||
|
||||
class ASSOCIATED_SCH_LABEL_PIN : public SHEET_SYNCHRONIZATION_ITEM
|
||||
{
|
||||
public:
|
||||
ASSOCIATED_SCH_LABEL_PIN( SCH_HIERLABEL* aLabel, SCH_SHEET_PIN* aPin );
|
||||
|
||||
ASSOCIATED_SCH_LABEL_PIN( SCH_HIERLABEL_SYNCHRONIZATION_ITEM* aLabel,
|
||||
SCH_SHEET_PIN_SYNCHRONIZATION_ITEM* aPin );
|
||||
|
||||
SCH_HIERLABEL* GetLabel() const { return m_label; }
|
||||
|
||||
SCH_SHEET_PIN* GetPin() const { return m_pin; }
|
||||
|
||||
wxString GetName() const override;
|
||||
|
||||
int GetShape() const override;
|
||||
|
||||
wxBitmap& GetBitmap() const override;
|
||||
|
||||
SCH_ITEM* GetItem() const override;
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITEM_KIND GetKind() const override;
|
||||
|
||||
private:
|
||||
SCH_HIERLABEL* m_label;
|
||||
SCH_SHEET_PIN* m_pin;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 "sheet_synchronization_model.h"
|
||||
#include "sheet_synchronization_item.h"
|
||||
#include "sheet_synchronization_notifier.h"
|
||||
#include "sheet_synchronization_agent.h"
|
||||
|
||||
#include <sch_label.h>
|
||||
#include <sch_sheet_pin.h>
|
||||
#include <wx/colour.h>
|
||||
#include <wx/variant.h>
|
||||
|
||||
|
||||
// sch_label.cpp
|
||||
extern wxString getElectricalTypeLabel( LABEL_FLAG_SHAPE aType );
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_MODEL::SHEET_SYNCHRONIZATION_MODEL( SHEET_SYNCHRONIZATION_AGENT& aAgent,
|
||||
SCH_SHEET* aSheet,
|
||||
SCH_SHEET_PATH aPath ) :
|
||||
m_selectedIndex( std::optional<unsigned>() ),
|
||||
m_agent( aAgent ), m_sheet( aSheet ), m_path( std::move( aPath ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_MODEL::~SHEET_SYNCHRONIZATION_MODEL() = default;
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_MODEL::GetValueByRow( wxVariant& aVariant, unsigned row,
|
||||
unsigned col ) const
|
||||
{
|
||||
const std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM>& item = m_items[row];
|
||||
|
||||
switch( col )
|
||||
{
|
||||
case NAME: aVariant << wxDataViewIconText( item->GetName(), item->GetBitmap() ); break;
|
||||
case SHAPE:
|
||||
aVariant = getElectricalTypeLabel( static_cast<LABEL_FLAG_SHAPE>( item->GetShape() ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SHEET_SYNCHRONIZATION_MODEL::SetValueByRow( const wxVariant& aVariant, unsigned row,
|
||||
unsigned col )
|
||||
{
|
||||
WXUNUSED( aVariant )
|
||||
WXUNUSED( row )
|
||||
WXUNUSED( col )
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
bool SHEET_SYNCHRONIZATION_MODEL::GetAttrByRow( unsigned row, unsigned int col,
|
||||
wxDataViewItemAttr& attr ) const
|
||||
{
|
||||
if( m_selectedIndex.has_value() && row == m_selectedIndex )
|
||||
{
|
||||
attr.SetBold( true );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_MODEL::RemoveItems( wxDataViewItemArray const& aItems )
|
||||
{
|
||||
if( aItems.empty() )
|
||||
return;
|
||||
|
||||
for( const auto& item : TakeItems( aItems ) )
|
||||
m_agent.RemoveItem( *item, m_sheet, m_path );
|
||||
|
||||
DoNotify();
|
||||
}
|
||||
|
||||
|
||||
bool SHEET_SYNCHRONIZATION_MODEL::AppendNewItem( std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> aItem )
|
||||
{
|
||||
m_items.push_back( std::move( aItem ) );
|
||||
RowAppended();
|
||||
DoNotify();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SHEET_SYNCHRONIZATION_MODEL::AppendItem( std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> aItem )
|
||||
{
|
||||
m_items.push_back( std::move( aItem ) );
|
||||
RowAppended();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITEM_LIST
|
||||
SHEET_SYNCHRONIZATION_MODEL::TakeItems( wxDataViewItemArray const& aItems )
|
||||
{
|
||||
if( aItems.size() == 1 )
|
||||
return { TakeItem( aItems[0] ) };
|
||||
|
||||
std::set<unsigned> rowsToBeRemove;
|
||||
SHEET_SYNCHRONIZATION_ITEM_LIST items_remain;
|
||||
SHEET_SYNCHRONIZATION_ITEM_LIST items_token;
|
||||
|
||||
for( const auto& item : aItems )
|
||||
{
|
||||
if( item.IsOk() )
|
||||
{
|
||||
unsigned int idx = GetRow( item );
|
||||
rowsToBeRemove.insert( idx );
|
||||
}
|
||||
}
|
||||
|
||||
for( unsigned i = 0; i < m_items.size(); i++ )
|
||||
{
|
||||
if( rowsToBeRemove.find( i ) == rowsToBeRemove.end() )
|
||||
items_remain.push_back( m_items[i] );
|
||||
else
|
||||
{
|
||||
items_token.push_back( m_items[i] );
|
||||
}
|
||||
}
|
||||
|
||||
UpdateItems( std::move( items_remain ) );
|
||||
OnRowSelected( {} );
|
||||
return items_token;
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITE_PTR SHEET_SYNCHRONIZATION_MODEL::TakeItem( wxDataViewItem const& aItem )
|
||||
{
|
||||
const unsigned int row = GetRow( aItem );
|
||||
|
||||
if( row + 1 > m_items.size() )
|
||||
return {};
|
||||
|
||||
std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> item = m_items[row];
|
||||
m_items.erase( m_items.begin() + row );
|
||||
OnRowSelected( {} );
|
||||
RowDeleted( row );
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITE_PTR
|
||||
SHEET_SYNCHRONIZATION_MODEL::GetSynchronizationItem( unsigned aIndex ) const
|
||||
{
|
||||
if( aIndex < m_items.size() )
|
||||
return m_items[aIndex];
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_MODEL::OnRowSelected( std::optional<unsigned> aRow )
|
||||
{
|
||||
m_selectedIndex = aRow;
|
||||
|
||||
if( aRow.has_value() && m_items.size() > *aRow )
|
||||
{
|
||||
if( wxDataViewItem item = GetItem( *aRow ); item.IsOk() )
|
||||
ItemChanged( item );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_MODEL::UpdateItems( SHEET_SYNCHRONIZATION_ITEM_LIST aItems )
|
||||
{
|
||||
m_items = std::move( aItems );
|
||||
Reset( m_items.size() );
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_MODEL::AddNotifier(
|
||||
std::shared_ptr<SHEET_SYNCHRONIZATION_NOTIFIER> aNotifier )
|
||||
{
|
||||
m_notifiers.push_back( std::move( aNotifier ) );
|
||||
}
|
||||
|
||||
|
||||
void SHEET_SYNCHRONIZATION_MODEL::DoNotify()
|
||||
{
|
||||
for( const auto& notifier : m_notifiers )
|
||||
notifier->Notify();
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 SHEET_SYNCHRONIZATION_MODEL_H
|
||||
#define SHEET_SYNCHRONIZATION_MODEL_H
|
||||
|
||||
#include <sch_sheet_path.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <list>
|
||||
#include <wx/dataview.h>
|
||||
#include <wx/string.h>
|
||||
|
||||
class SHEET_SYNCHRONIZATION_ITEM;
|
||||
using SHEET_SYNCHRONIZATION_ITE_PTR = std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM>;
|
||||
using SHEET_SYNCHRONIZATION_ITEM_LIST = std::vector<SHEET_SYNCHRONIZATION_ITE_PTR>;
|
||||
|
||||
class SHEET_SYNCHRONIZATION_NOTIFIER;
|
||||
class SHEET_SYNCHRONIZATION_AGENT;
|
||||
class SCH_SHEET;
|
||||
class SCH_SHEET_PATH;
|
||||
class SHEET_SYNCHRONIZATION_MODEL : public wxDataViewVirtualListModel
|
||||
{
|
||||
public:
|
||||
enum SHEET_SYNCHRONIZATION_COL
|
||||
{
|
||||
NAME,
|
||||
SHAPE,
|
||||
COL_COUNT
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
HIRE_LABEL,
|
||||
SHEET_PIN,
|
||||
ASSOCIATED,
|
||||
MODEL_COUNT
|
||||
};
|
||||
|
||||
static wxString GetColName( int col )
|
||||
{
|
||||
switch( col )
|
||||
{
|
||||
case NAME: return _( "Name" );
|
||||
case SHAPE: return _( "Shape" );
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SHEET_SYNCHRONIZATION_MODEL( SHEET_SYNCHRONIZATION_AGENT& aAgent, SCH_SHEET* aSheet,
|
||||
SCH_SHEET_PATH aPath );
|
||||
~SHEET_SYNCHRONIZATION_MODEL() override;
|
||||
|
||||
void GetValueByRow( wxVariant& variant, unsigned row, unsigned col ) const override;
|
||||
|
||||
bool SetValueByRow( const wxVariant& variant, unsigned row, unsigned col ) override;
|
||||
|
||||
bool GetAttrByRow( unsigned row, unsigned int col, wxDataViewItemAttr& attr ) const override;
|
||||
|
||||
void RemoveItems( wxDataViewItemArray const& aItems );
|
||||
|
||||
/**
|
||||
* @brief Add a new item, the notifiers are notified
|
||||
*/
|
||||
bool AppendNewItem( std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> aItem );
|
||||
|
||||
/**
|
||||
* @brief Just append item to the list, the notifiers are not notified
|
||||
*/
|
||||
bool AppendItem( std::shared_ptr<SHEET_SYNCHRONIZATION_ITEM> aItem );
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITEM_LIST TakeItems( wxDataViewItemArray const& aItems );
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITE_PTR TakeItem( wxDataViewItem const& aItem );
|
||||
|
||||
SHEET_SYNCHRONIZATION_ITE_PTR GetSynchronizationItem( unsigned aIndex ) const;
|
||||
|
||||
void OnRowSelected( std::optional<unsigned> aRow );
|
||||
|
||||
void UpdateItems( SHEET_SYNCHRONIZATION_ITEM_LIST aItems );
|
||||
|
||||
void AddNotifier( std::shared_ptr<SHEET_SYNCHRONIZATION_NOTIFIER> aNotifier );
|
||||
|
||||
void DoNotify();
|
||||
|
||||
bool HasSelectedIndex() const { return m_selectedIndex.has_value(); }
|
||||
|
||||
std::optional<unsigned int> GetSelectedIndex() const { return m_selectedIndex; }
|
||||
|
||||
private:
|
||||
SHEET_SYNCHRONIZATION_ITEM_LIST m_items;
|
||||
std::optional<unsigned> m_selectedIndex;
|
||||
std::list<std::shared_ptr<SHEET_SYNCHRONIZATION_NOTIFIER>> m_notifiers;
|
||||
SHEET_SYNCHRONIZATION_AGENT& m_agent;
|
||||
SCH_SHEET* m_sheet;
|
||||
SCH_SHEET_PATH m_path;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 "sheet_synchronization_notifier.h"
|
||||
#include "panel_sync_sheet_pins.h"
|
||||
#include "sheet_synchronization_model.h"
|
||||
|
||||
SHEET_SYNCHRONIZATION_NOTIFIER::SHEET_SYNCHRONIZATION_NOTIFIER(
|
||||
SHEET_SYNCHRONIZATION_MODEL* aOwner ) :
|
||||
m_owner( aOwner )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SHEET_FILE_CHANGE_NOTIFIER::SHEET_FILE_CHANGE_NOTIFIER( SHEET_SYNCHRONIZATION_MODEL* aOwner,
|
||||
PANEL_SYNC_SHEET_PINS* aPanel ) :
|
||||
SHEET_SYNCHRONIZATION_NOTIFIER( aOwner ),
|
||||
m_panel( aPanel )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool SHEET_FILE_CHANGE_NOTIFIER::ShouldIgnore() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void SHEET_FILE_CHANGE_NOTIFIER::Sync()
|
||||
{
|
||||
m_panel->UpdateForms();
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 SHEET_SYNCHRONIZATION_NOTIFIER_H
|
||||
#define SHEET_SYNCHRONIZATION_NOTIFIER_H
|
||||
|
||||
class SHEET_SYNCHRONIZATION_MODEL;
|
||||
class PANEL_SYNC_SHEET_PINS;
|
||||
class SHEET_SYNCHRONIZATION_NOTIFIER
|
||||
{
|
||||
public:
|
||||
SHEET_SYNCHRONIZATION_NOTIFIER( SHEET_SYNCHRONIZATION_MODEL* aOwner );
|
||||
|
||||
virtual ~SHEET_SYNCHRONIZATION_NOTIFIER() = default;
|
||||
|
||||
void Notify()
|
||||
{
|
||||
if( !ShouldIgnore() )
|
||||
Sync();
|
||||
}
|
||||
|
||||
SHEET_SYNCHRONIZATION_MODEL* GetOwner() const { return m_owner; }
|
||||
|
||||
protected:
|
||||
virtual bool ShouldIgnore() const = 0;
|
||||
|
||||
virtual void Sync() = 0;
|
||||
|
||||
|
||||
private:
|
||||
SHEET_SYNCHRONIZATION_MODEL* m_owner;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Used to sync the modifications between the mutiple instances of a sheet file
|
||||
*
|
||||
*/
|
||||
class SHEET_FILE_CHANGE_NOTIFIER : public SHEET_SYNCHRONIZATION_NOTIFIER
|
||||
{
|
||||
public:
|
||||
SHEET_FILE_CHANGE_NOTIFIER( SHEET_SYNCHRONIZATION_MODEL* aOwner,
|
||||
PANEL_SYNC_SHEET_PINS* aPanel );
|
||||
|
||||
protected:
|
||||
bool ShouldIgnore() const override;
|
||||
|
||||
void Sync() override;
|
||||
|
||||
private:
|
||||
PANEL_SYNC_SHEET_PINS* m_panel;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2023 Ethan Chien <liangtie.qian@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 SYNC_SHEET_PIN_PREFERENCE_H
|
||||
#define SYNC_SHEET_PIN_PREFERENCE_H
|
||||
|
||||
#include <bitmaps/bitmap_types.h>
|
||||
#include <bitmaps/bitmaps_list.h>
|
||||
#include <map>
|
||||
#include <wx/colour.h>
|
||||
|
||||
class SYNC_SHEET_PIN_PREFERENCE
|
||||
{
|
||||
public:
|
||||
enum ICON_SIZE
|
||||
{
|
||||
NORMAL_WIDTH = 16,
|
||||
NORMAL_HEIGHT = 16
|
||||
|
||||
};
|
||||
|
||||
enum BOOKCTRL_ICON_INDEX
|
||||
{
|
||||
HAS_UNMATCHED,
|
||||
ALL_MATCHED
|
||||
};
|
||||
|
||||
static const std::map<BOOKCTRL_ICON_INDEX, BITMAPS>& GetBookctrlPageIcon()
|
||||
{
|
||||
static std::map<BOOKCTRL_ICON_INDEX, BITMAPS> mapping = {
|
||||
{ HAS_UNMATCHED, BITMAPS::erc_green }, { ALL_MATCHED, BITMAPS::ercwarn }
|
||||
};
|
||||
return mapping;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -163,7 +163,8 @@ void SCH_EDIT_FRAME::ReCreateVToolbar()
|
|||
m_drawToolBar->Add( EE_ACTIONS::placeGlobalLabel, ACTION_TOOLBAR::TOGGLE );
|
||||
m_drawToolBar->Add( EE_ACTIONS::placeHierLabel, ACTION_TOOLBAR::TOGGLE );
|
||||
m_drawToolBar->Add( EE_ACTIONS::drawSheet, ACTION_TOOLBAR::TOGGLE );
|
||||
m_drawToolBar->Add( EE_ACTIONS::importSheetPin, ACTION_TOOLBAR::TOGGLE );
|
||||
m_drawToolBar->Add( EE_ACTIONS::placeSheetPin, ACTION_TOOLBAR::TOGGLE );
|
||||
m_drawToolBar->Add( EE_ACTIONS::syncAllSheetsPins, ACTION_TOOLBAR::TOGGLE );
|
||||
|
||||
m_drawToolBar->AddScaledSeparator( this );
|
||||
m_drawToolBar->Add( EE_ACTIONS::placeSchematicText, ACTION_TOOLBAR::TOGGLE );
|
||||
|
|
|
@ -489,13 +489,31 @@ TOOL_ACTION EE_ACTIONS::drawSheet( TOOL_ACTION_ARGS()
|
|||
.Flags( AF_ACTIVATE )
|
||||
.Parameter( SCH_SHEET_T ) );
|
||||
|
||||
TOOL_ACTION EE_ACTIONS::importSheetPin( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.InteractiveDrawing.importSheetPin" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Import Sheet Pin" ) )
|
||||
.Tooltip( _( "Import hierarchical sheet pins" ) )
|
||||
.Icon( BITMAPS::import_hierarchical_label )
|
||||
.Flags( AF_ACTIVATE ) );
|
||||
TOOL_ACTION EE_ACTIONS::placeSheetPin( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.InteractiveDrawing.placeSheetPin" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Add Sheet Pin" ) )
|
||||
.Tooltip( _( "Add sheet pins" ) )
|
||||
.Icon( BITMAPS::add_hierar_pin )
|
||||
.Flags( AF_ACTIVATE ) );
|
||||
|
||||
TOOL_ACTION EE_ACTIONS::syncSheetPins(
|
||||
TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.InteractiveDrawing.syncSheetPins" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Sync Sheet Pins" ) )
|
||||
.Tooltip( _( "Synchronize sheet pins and hierarchical labels”" ) )
|
||||
.Icon( BITMAPS::import_hierarchical_label )
|
||||
.Flags( AF_ACTIVATE ) );
|
||||
|
||||
TOOL_ACTION EE_ACTIONS::syncAllSheetsPins(
|
||||
TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.InteractiveDrawing.syncAllSheetsPins" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Sync Sheet Pins" ) )
|
||||
.Tooltip( _( "Synchronize sheet pins and hierarchical labels”" ) )
|
||||
.Icon( BITMAPS::import_hierarchical_label )
|
||||
.Flags( AF_ACTIVATE ) );
|
||||
|
||||
TOOL_ACTION EE_ACTIONS::placeGlobalLabel( TOOL_ACTION_ARGS()
|
||||
.Name( "eeschema.InteractiveDrawing.placeGlobalLabel" )
|
||||
|
|
|
@ -89,7 +89,11 @@ public:
|
|||
static TOOL_ACTION placeGlobalLabel;
|
||||
static TOOL_ACTION placeHierLabel;
|
||||
static TOOL_ACTION drawSheet;
|
||||
static TOOL_ACTION importSheetPin;
|
||||
static TOOL_ACTION placeSheetPin;
|
||||
// Sync sheet pins for selected sheet symbol
|
||||
static TOOL_ACTION syncSheetPins;
|
||||
// Sync sheet pins for all sheet symbols
|
||||
static TOOL_ACTION syncAllSheetsPins;
|
||||
static TOOL_ACTION placeSchematicText;
|
||||
static TOOL_ACTION drawTextBox;
|
||||
static TOOL_ACTION drawTable;
|
||||
|
|
|
@ -305,7 +305,8 @@ bool EE_SELECTION_TOOL::Init()
|
|||
menu.AddItem( EE_ACTIONS::placeHierLabel, wireOrBusSelection && EE_CONDITIONS::Idle, 250 );
|
||||
menu.AddItem( EE_ACTIONS::breakWire, linesSelection && EE_CONDITIONS::Idle, 250 );
|
||||
menu.AddItem( EE_ACTIONS::slice, linesSelection && EE_CONDITIONS::Idle, 250 );
|
||||
menu.AddItem( EE_ACTIONS::importSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
||||
menu.AddItem( EE_ACTIONS::placeSheetPin, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
||||
menu.AddItem( EE_ACTIONS::syncSheetPins, sheetSelection && EE_CONDITIONS::Idle, 250 );
|
||||
menu.AddItem( EE_ACTIONS::assignNetclass, connectedSelection && EE_CONDITIONS::Idle, 250 );
|
||||
menu.AddItem( EE_ACTIONS::editPageNumber, schEditSheetPageNumberCondition, 250 );
|
||||
|
||||
|
|
|
@ -22,9 +22,11 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include "sch_sheet_path.h"
|
||||
#include <memory>
|
||||
|
||||
#include <kiplatform/ui.h>
|
||||
#include <optional>
|
||||
#include <project_sch.h>
|
||||
#include <tools/sch_drawing_tools.h>
|
||||
#include <tools/sch_line_wire_bus_tool.h>
|
||||
|
@ -49,6 +51,7 @@
|
|||
#include <sch_tablecell.h>
|
||||
#include <sch_sheet.h>
|
||||
#include <sch_sheet_pin.h>
|
||||
#include <sch_label.h>
|
||||
#include <sch_bitmap.h>
|
||||
#include <schematic.h>
|
||||
#include <sch_commit.h>
|
||||
|
@ -59,6 +62,7 @@
|
|||
#include <dialogs/dialog_wire_bus_properties.h>
|
||||
#include <dialogs/dialog_junction_props.h>
|
||||
#include <import_gfx/dialog_import_gfx_sch.h>
|
||||
#include <sync_sheet_pin/sheet_synchronization_agent.h>
|
||||
#include <string_utils.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <wx/filedlg.h>
|
||||
|
@ -1336,35 +1340,14 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType
|
|||
return textItem;
|
||||
}
|
||||
|
||||
|
||||
SCH_HIERLABEL* SCH_DRAWING_TOOLS::importHierLabel( SCH_SHEET* aSheet )
|
||||
{
|
||||
if( !aSheet->GetScreen() )
|
||||
return nullptr;
|
||||
|
||||
for( EDA_ITEM* item : aSheet->GetScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
|
||||
{
|
||||
SCH_HIERLABEL* label = static_cast<SCH_HIERLABEL*>( item );
|
||||
|
||||
/* A global label has been found: check if there a corresponding sheet label. */
|
||||
if( !aSheet->HasPin( label->GetText() ) )
|
||||
return label;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET_PIN* SCH_DRAWING_TOOLS::createNewSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel,
|
||||
const VECTOR2I& aPosition )
|
||||
SCH_SHEET_PIN* SCH_DRAWING_TOOLS::createNewSheetPin( SCH_SHEET* aSheet, const VECTOR2I& aPosition )
|
||||
{
|
||||
SCHEMATIC_SETTINGS& settings = aSheet->Schematic()->Settings();
|
||||
SCH_SHEET_PIN* pin = new SCH_SHEET_PIN( aSheet );
|
||||
|
||||
pin->SetFlags( IS_NEW | IS_MOVING );
|
||||
pin->SetText( aLabel->GetText() );
|
||||
pin->SetText( std::to_string( aSheet->GetPins().size() + 1 ) );
|
||||
pin->SetTextSize( VECTOR2I( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
|
||||
pin->SetShape( aLabel->GetShape() );
|
||||
pin->SetPosition( aPosition );
|
||||
pin->ClearSelected();
|
||||
|
||||
|
@ -1394,7 +1377,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
|
|||
bool isHierLabel = aEvent.IsAction( &EE_ACTIONS::placeHierLabel );
|
||||
bool isClassLabel = aEvent.IsAction( &EE_ACTIONS::placeClassLabel );
|
||||
bool isNetLabel = aEvent.IsAction( &EE_ACTIONS::placeLabel );
|
||||
bool isSheetPin = aEvent.IsAction( &EE_ACTIONS::importSheetPin );
|
||||
bool isSheetPin = aEvent.IsAction( &EE_ACTIONS::placeSheetPin );
|
||||
|
||||
GRID_HELPER_GRIDS snapGrid = isText ? GRID_TEXT : GRID_CONNECTABLE;
|
||||
|
||||
|
@ -1539,7 +1522,29 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
else if( isHierLabel )
|
||||
{
|
||||
item = createNewText( cursorPos, LAYER_HIERLABEL );
|
||||
if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
|
||||
{
|
||||
auto pin = static_cast<SCH_HIERLABEL*>(
|
||||
m_dialogSyncSheetPin->GetPlacementTemplate() );
|
||||
SCH_HIERLABEL* label = new SCH_HIERLABEL( cursorPos );
|
||||
SCHEMATIC* schematic = getModel<SCHEMATIC>();
|
||||
label->SetText( pin->GetText() );
|
||||
label->SetShape( pin->GetShape() );
|
||||
label->SetAutoRotateOnPlacement( m_lastAutoLabelRotateOnPlacement );
|
||||
label->SetParent( schematic );
|
||||
label->SetBold( m_lastTextBold );
|
||||
label->SetItalic( m_lastTextItalic );
|
||||
label->SetSpinStyle( m_lastTextOrientation );
|
||||
label->SetTextSize( VECTOR2I( schematic->Settings().m_DefaultTextSize,
|
||||
schematic->Settings().m_DefaultTextSize ) );
|
||||
label->SetFlags( IS_NEW | IS_MOVING );
|
||||
item = label;
|
||||
}
|
||||
else
|
||||
{
|
||||
item = createNewText( cursorPos, LAYER_HIERLABEL );
|
||||
}
|
||||
|
||||
description = _( "Add Hierarchical Label" );
|
||||
}
|
||||
else if( isNetLabel )
|
||||
|
@ -1576,22 +1581,15 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
else
|
||||
{
|
||||
SCH_HIERLABEL* label = importHierLabel( sheet );
|
||||
|
||||
if( !label )
|
||||
item = createNewSheetPin( sheet, cursorPos );
|
||||
if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
|
||||
{
|
||||
m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
|
||||
m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
|
||||
m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition()
|
||||
+ wxPoint( 20, 20 ) );
|
||||
m_statusPopup->PopupFor( 2000 );
|
||||
item = nullptr;
|
||||
|
||||
m_frame->PopTool( aEvent );
|
||||
break;
|
||||
auto label = static_cast<SCH_HIERLABEL*>(
|
||||
m_dialogSyncSheetPin->GetPlacementTemplate() );
|
||||
auto pin = static_cast<SCH_HIERLABEL*>( item );
|
||||
pin->SetText( label->GetText() );
|
||||
pin->SetShape( label->GetShape() );
|
||||
}
|
||||
|
||||
item = createNewSheetPin( sheet, label, cursorPos );
|
||||
}
|
||||
|
||||
description = _( "Add Sheet Pin" );
|
||||
|
@ -1619,10 +1617,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
|
|||
item->SetFlags( IS_NEW | IS_MOVING );
|
||||
item->AutoplaceFields( nullptr, false /* aManual */ );
|
||||
updatePreview();
|
||||
|
||||
if( item->Type() != SCH_SHEET_PIN_T )
|
||||
m_selectionTool->AddItemToSel( item );
|
||||
|
||||
m_selectionTool->AddItemToSel( item );
|
||||
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
||||
|
||||
// update the cursor so it looks correct before another event
|
||||
|
@ -1657,27 +1652,25 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
|
|||
|
||||
commit.Push( description );
|
||||
|
||||
item = nullptr;
|
||||
m_view->ClearPreview();
|
||||
|
||||
if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
|
||||
{
|
||||
m_dialogSyncSheetPin->EndPlaceItem( item );
|
||||
m_dialogSyncSheetPin->Show( true );
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
item = nullptr;
|
||||
}
|
||||
|
||||
if( isSheetPin )
|
||||
{
|
||||
SCH_HIERLABEL* label = importHierLabel( sheet );
|
||||
|
||||
if( !label )
|
||||
{
|
||||
m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
|
||||
m_statusPopup->SetText( _( "No new hierarchical labels found." ) );
|
||||
m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition()
|
||||
+ wxPoint( 20, 20 ) );
|
||||
m_statusPopup->PopupFor( 2000 );
|
||||
item = nullptr;
|
||||
|
||||
m_frame->PopTool( aEvent );
|
||||
break;
|
||||
}
|
||||
|
||||
item = createNewSheetPin( sheet, label, cursorPos );
|
||||
item = createNewSheetPin( sheet, cursorPos );
|
||||
item->SetPosition( cursorPos );
|
||||
m_selectionTool->ClearSelection();
|
||||
m_selectionTool->AddItemToSel( item );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1747,6 +1740,13 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
|
|||
controls->CaptureCursor( false );
|
||||
controls->ForceCursorPosition( false );
|
||||
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
||||
|
||||
if( m_dialogSyncSheetPin && m_dialogSyncSheetPin->GetPlacementTemplate() )
|
||||
{
|
||||
m_dialogSyncSheetPin->EndPlaceItem( nullptr );
|
||||
m_dialogSyncSheetPin->Show(true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2471,6 +2471,142 @@ void SCH_DRAWING_TOOLS::sizeSheet( SCH_SHEET* aSheet, const VECTOR2I& aPos )
|
|||
}
|
||||
|
||||
|
||||
int SCH_DRAWING_TOOLS::doSyncSheetsPins( std::list<SCH_SHEET_PATH> sheetPaths )
|
||||
{
|
||||
if( !sheetPaths.size() )
|
||||
return 0;
|
||||
|
||||
m_dialogSyncSheetPin = std::make_unique<DIALOG_SYNC_SHEET_PINS>(
|
||||
m_frame, std::move( sheetPaths ),
|
||||
std::make_shared<SHEET_SYNCHRONIZATION_AGENT>(
|
||||
[&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath,
|
||||
SHEET_SYNCHRONIZATION_AGENT::MODIFICATION aModify )
|
||||
{
|
||||
SCH_COMMIT commit( m_toolMgr );
|
||||
|
||||
if( auto pin = dynamic_cast<SCH_SHEET_PIN*>( aItem ) )
|
||||
{
|
||||
commit.Modify( pin->GetParent(), aPath.LastScreen() );
|
||||
aModify();
|
||||
commit.Push( _( "Modify sch item" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
commit.Modify( aItem, aPath.LastScreen() );
|
||||
aModify();
|
||||
commit.Push( _( "Modify sch item" ), SKIP_CONNECTIVITY );
|
||||
}
|
||||
|
||||
updateItem( aItem, true );
|
||||
m_frame->OnModify();
|
||||
},
|
||||
[&]( EDA_ITEM* aItem, SCH_SHEET_PATH aPath )
|
||||
{
|
||||
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>(
|
||||
EE_ACTIONS::changeSheet, &aPath );
|
||||
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
||||
selectionTool->UnbrightenItem( aItem );
|
||||
selectionTool->AddItemToSel( aItem, true );
|
||||
m_toolMgr->RunAction( ACTIONS::doDelete );
|
||||
},
|
||||
[&]( SCH_SHEET* aItem, SCH_SHEET_PATH aPath,
|
||||
SHEET_SYNCHRONIZATION_AGENT::SHEET_SYNCHRONIZATION_PLACEMENT aOp,
|
||||
EDA_ITEM* aTemplate )
|
||||
{
|
||||
switch( aOp )
|
||||
{
|
||||
case SHEET_SYNCHRONIZATION_AGENT::PLACE_HIERLABEL:
|
||||
{
|
||||
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
|
||||
m_dialogSyncSheetPin->Hide();
|
||||
m_dialogSyncSheetPin->BeginPlaceItem(
|
||||
sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::HIERLABEL,
|
||||
aTemplate );
|
||||
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>(
|
||||
EE_ACTIONS::changeSheet, &aPath );
|
||||
m_toolMgr->RunAction( EE_ACTIONS::placeHierLabel );
|
||||
break;
|
||||
}
|
||||
case SHEET_SYNCHRONIZATION_AGENT::PLACE_SHEET_PIN:
|
||||
{
|
||||
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
|
||||
m_dialogSyncSheetPin->Hide();
|
||||
m_dialogSyncSheetPin->BeginPlaceItem(
|
||||
sheet, DIALOG_SYNC_SHEET_PINS::PlaceItemKind::SHEET_PIN,
|
||||
aTemplate );
|
||||
m_frame->GetToolManager()->RunAction<SCH_SHEET_PATH*>(
|
||||
EE_ACTIONS::changeSheet, &aPath );
|
||||
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->SyncSelection( {}, nullptr,
|
||||
{ sheet } );
|
||||
m_toolMgr->RunAction( EE_ACTIONS::placeSheetPin );
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
m_toolMgr, m_frame ) );
|
||||
m_dialogSyncSheetPin->Show( true );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int SCH_DRAWING_TOOLS::SyncSheetsPins( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( m_selectionTool->GetSelection().Front() );
|
||||
|
||||
if( !sheet )
|
||||
{
|
||||
VECTOR2I cursorPos = getViewControls()->GetMousePosition();
|
||||
|
||||
if( EDA_ITEM* i = nullptr; static_cast<void>(m_selectionTool->SelectPoint( cursorPos, { SCH_SHEET_T }, &i )) , i != nullptr )
|
||||
{
|
||||
sheet = dynamic_cast<SCH_SHEET*>( i );
|
||||
}
|
||||
}
|
||||
|
||||
if ( sheet )
|
||||
{
|
||||
SCH_SHEET_PATH current = m_frame->GetCurrentSheet();
|
||||
current.push_back( sheet );
|
||||
return doSyncSheetsPins( { current } );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int SCH_DRAWING_TOOLS::SyncAllSheetsPins( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
static const std::function<void( std::list<SCH_SHEET_PATH>&, SCH_SCREEN*,
|
||||
std::set<SCH_SCREEN*>&, SCH_SHEET_PATH const& )>
|
||||
getSheetChildren = []( std::list<SCH_SHEET_PATH>& aPaths, SCH_SCREEN* aScene,
|
||||
std::set<SCH_SCREEN*>& aVisited, SCH_SHEET_PATH const& aCurPath )
|
||||
{
|
||||
if( ! aScene || aVisited.find(aScene) != aVisited.end() )
|
||||
return ;
|
||||
|
||||
std::vector<SCH_ITEM*> sheetChildren;
|
||||
aScene->GetSheets( &sheetChildren );
|
||||
aVisited.insert(aScene);
|
||||
|
||||
for( SCH_ITEM* child : sheetChildren)
|
||||
{
|
||||
SCH_SHEET_PATH cp = aCurPath;
|
||||
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( child );
|
||||
cp.push_back(sheet);
|
||||
aPaths.push_back( cp );
|
||||
getSheetChildren(aPaths , sheet->GetScreen() , aVisited ,cp);
|
||||
}
|
||||
};
|
||||
|
||||
std::list<SCH_SHEET_PATH> sheetPaths;
|
||||
std::set<SCH_SCREEN*> visited;
|
||||
SCH_SHEET_PATH current;
|
||||
current.push_back(&m_frame->Schematic().Root());
|
||||
getSheetChildren(sheetPaths , m_frame->Schematic().Root().GetScreen() ,visited ,current );
|
||||
return doSyncSheetsPins( sheetPaths );
|
||||
}
|
||||
|
||||
|
||||
void SCH_DRAWING_TOOLS::setTransitions()
|
||||
{
|
||||
Go( &SCH_DRAWING_TOOLS::PlaceSymbol, EE_ACTIONS::placeSymbol.MakeEvent() );
|
||||
|
@ -2483,7 +2619,7 @@ void SCH_DRAWING_TOOLS::setTransitions()
|
|||
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeHierLabel.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeGlobalLabel.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::DrawSheet, EE_ACTIONS::drawSheet.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::importSheetPin.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSheetPin.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::TwoClickPlace, EE_ACTIONS::placeSchematicText.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawRectangle.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::DrawShape, EE_ACTIONS::drawCircle.MakeEvent() );
|
||||
|
@ -2492,4 +2628,6 @@ void SCH_DRAWING_TOOLS::setTransitions()
|
|||
Go( &SCH_DRAWING_TOOLS::DrawTable, EE_ACTIONS::drawTable.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::PlaceImage, EE_ACTIONS::placeImage.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::ImportGraphics, EE_ACTIONS::importGraphics.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::SyncSheetsPins, EE_ACTIONS::syncSheetPins.MakeEvent() );
|
||||
Go( &SCH_DRAWING_TOOLS::SyncAllSheetsPins, EE_ACTIONS::syncAllSheetsPins.MakeEvent() );
|
||||
}
|
||||
|
|
|
@ -25,15 +25,18 @@
|
|||
#ifndef SCH_DRAWING_TOOLS_H
|
||||
#define SCH_DRAWING_TOOLS_H
|
||||
|
||||
#include "sch_sheet_path.h"
|
||||
#include <tools/ee_tool_base.h>
|
||||
#include <sch_base_frame.h>
|
||||
#include <sch_label.h>
|
||||
#include <status_popup.h>
|
||||
#include <sync_sheet_pin/dialog_sync_sheet_pins.h>
|
||||
|
||||
class SCH_SYMBOL;
|
||||
class SCH_BUS_WIRE_ENTRY;
|
||||
class SCH_EDIT_FRAME;
|
||||
class EE_SELECTION_TOOL;
|
||||
class DIALOG_SYNC_SHEET_PINS;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -57,16 +60,15 @@ public:
|
|||
int DrawSheet( const TOOL_EVENT& aEvent );
|
||||
int PlaceImage( const TOOL_EVENT& aEvent );
|
||||
int ImportGraphics( const TOOL_EVENT& aEvent );
|
||||
int SyncSheetsPins( const TOOL_EVENT& aEvent );
|
||||
int SyncAllSheetsPins( const TOOL_EVENT& aEvent );
|
||||
|
||||
private:
|
||||
SCH_LINE* findWire( const VECTOR2I& aPosition );
|
||||
|
||||
SCH_TEXT* createNewText( const VECTOR2I& aPosition, int aType );
|
||||
|
||||
SCH_HIERLABEL* importHierLabel( SCH_SHEET* aSheet );
|
||||
|
||||
SCH_SHEET_PIN* createNewSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel,
|
||||
const VECTOR2I& aPosition );
|
||||
SCH_SHEET_PIN* createNewSheetPin( SCH_SHEET* aSheet, const VECTOR2I& aPosition );
|
||||
|
||||
void sizeSheet( SCH_SHEET* aSheet, const VECTOR2I& aPos );
|
||||
|
||||
|
@ -75,6 +77,8 @@ private:
|
|||
///< Set up handlers for various events.
|
||||
void setTransitions() override;
|
||||
|
||||
int doSyncSheetsPins( std::list<SCH_SHEET_PATH> aSheets );
|
||||
|
||||
std::vector<PICKED_SYMBOL> m_symbolHistoryList;
|
||||
std::vector<PICKED_SYMBOL> m_powerHistoryList;
|
||||
|
||||
|
@ -99,8 +103,9 @@ private:
|
|||
wxString m_mruPath;
|
||||
bool m_lastAutoLabelRotateOnPlacement;
|
||||
|
||||
bool m_inDrawingTool; // Re-entrancy guard
|
||||
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
|
||||
bool m_inDrawingTool; // Re-entrancy guard
|
||||
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
|
||||
std::unique_ptr<DIALOG_SYNC_SHEET_PINS> m_dialogSyncSheetPin;
|
||||
};
|
||||
|
||||
#endif /* SCH_DRAWING_TOOLS_H */
|
||||
|
|
Loading…
Reference in New Issue