2011-12-08 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-21 09:46:44 +00:00
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-09-20 12:44:52 +00:00
|
|
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
2021-01-17 08:41:49 +00:00
|
|
|
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-08 21:05:43 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2014-02-02 19:51:50 +00:00
|
|
|
#include <id.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2017-09-20 12:44:52 +00:00
|
|
|
#include <dialog_shim.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_sheet_path.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2019-04-14 00:44:05 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_actions.h>
|
2019-05-13 20:42:40 +00:00
|
|
|
#include <tools/sch_editor_control.h>
|
2016-11-16 10:07:02 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2019-10-24 17:07:01 +00:00
|
|
|
#include <hierarch.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <view/view.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-04-12 23:09:17 +00:00
|
|
|
#include "eeschema_settings.h"
|
2017-09-20 12:44:52 +00:00
|
|
|
|
2020-11-29 00:10:17 +00:00
|
|
|
#include <wx/object.h>
|
2020-09-21 18:16:32 +00:00
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
class HIERARCHY_NAVIG_DLG;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-11-16 10:07:02 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
/**
|
|
|
|
* Store an SCH_SHEET_PATH of each sheet in hierarchy.
|
|
|
|
*/
|
2008-07-31 15:30:57 +00:00
|
|
|
class TreeItemData : public wxTreeItemData
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH m_SheetPath;
|
2015-02-28 16:56:09 +00:00
|
|
|
|
|
|
|
TreeItemData( SCH_SHEET_PATH& sheet ) : wxTreeItemData()
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2009-01-07 20:09:03 +00:00
|
|
|
m_SheetPath = sheet;
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2020-11-29 00:10:17 +00:00
|
|
|
// Need to use wxRTTI macros in order for OnCompareItems to work properly
|
|
|
|
// See: https://docs.wxwidgets.org/3.1/classwx_tree_ctrl.html#ab90a465793c291ca7aa827a576b7d146
|
|
|
|
wxIMPLEMENT_ABSTRACT_CLASS( HIERARCHY_TREE, wxTreeCtrl );
|
|
|
|
|
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_TREE::HIERARCHY_TREE( HIERARCHY_NAVIG_DLG* parent ) :
|
2017-12-10 12:22:43 +00:00
|
|
|
wxTreeCtrl( (wxWindow*) parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
2009-12-02 21:44:03 +00:00
|
|
|
wxTR_HAS_BUTTONS, wxDefaultValidator, wxT( "HierachyTreeCtrl" ) )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-12-10 12:22:43 +00:00
|
|
|
m_parent = parent;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
// Make an image list containing small icons
|
2012-07-10 12:26:26 +00:00
|
|
|
// All icons are expected having the same size.
|
2021-03-08 02:59:07 +00:00
|
|
|
wxBitmap tree_nosel_bm( KiBitmap( BITMAPS::tree_nosel ) );
|
2019-04-14 00:44:05 +00:00
|
|
|
imageList = new wxImageList( tree_nosel_bm.GetWidth(), tree_nosel_bm.GetHeight(), true, 2 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-07-10 12:26:26 +00:00
|
|
|
imageList->Add( tree_nosel_bm );
|
2021-03-08 02:59:07 +00:00
|
|
|
imageList->Add( KiBitmap( BITMAPS::tree_sel ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
AssignImageList( imageList );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 00:10:17 +00:00
|
|
|
|
2019-05-02 15:01:51 +00:00
|
|
|
HIERARCHY_NAVIG_DLG::HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* aParent ) :
|
2017-09-20 12:44:52 +00:00
|
|
|
DIALOG_SHIM( aParent, wxID_ANY, _( "Navigator" ), wxDefaultPosition, wxDefaultSize,
|
2020-01-08 14:01:22 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, HIERARCHY_NAVIG_DLG_WNAME )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-09-20 12:44:52 +00:00
|
|
|
wxASSERT( dynamic_cast< SCH_EDIT_FRAME* >( aParent ) );
|
|
|
|
|
2017-12-10 12:22:43 +00:00
|
|
|
m_SchFrameEditor = aParent;
|
2017-12-04 11:45:54 +00:00
|
|
|
m_currSheet = aParent->GetCurrentSheet();
|
2011-02-17 13:56:54 +00:00
|
|
|
m_Tree = new HIERARCHY_TREE( this );
|
2008-07-31 15:30:57 +00:00
|
|
|
m_nbsheets = 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-12-10 12:22:43 +00:00
|
|
|
// root is the link to the main sheet.
|
2020-11-29 00:10:17 +00:00
|
|
|
wxTreeItemId root = m_Tree->AddRoot( getRootString(), 0, 1 );
|
2017-09-20 12:44:52 +00:00
|
|
|
m_Tree->SetItemBold( root, true );
|
2012-07-10 12:26:26 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
m_list.push_back( &m_SchFrameEditor->Schematic().Root() );
|
2019-10-24 17:07:01 +00:00
|
|
|
m_Tree->SetItemData( root, new TreeItemData( m_list ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
if( m_SchFrameEditor->GetCurrentSheet().Last() == &m_SchFrameEditor->Schematic().Root() )
|
2017-12-10 12:22:43 +00:00
|
|
|
m_Tree->SelectItem( root );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2019-10-24 17:07:01 +00:00
|
|
|
buildHierarchyTree( &m_list, &root );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-12-04 11:45:54 +00:00
|
|
|
m_Tree->ExpandAll();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-12-10 12:22:43 +00:00
|
|
|
// This bloc gives a good size to the dialog, better than the default "best" size,
|
|
|
|
// the first time the dialog is opened, during a session
|
2012-07-10 12:26:26 +00:00
|
|
|
wxRect itemrect;
|
2017-12-04 11:45:54 +00:00
|
|
|
wxSize tree_size;
|
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
m_Tree->GetBoundingRect( root, itemrect );
|
2012-07-10 12:26:26 +00:00
|
|
|
|
|
|
|
// Set dialog window size to be large enough
|
2017-12-04 11:45:54 +00:00
|
|
|
tree_size.x = itemrect.GetWidth() + 20;
|
|
|
|
tree_size.x = std::max( tree_size.x, 250 );
|
2012-07-10 12:26:26 +00:00
|
|
|
|
|
|
|
// Readjust the size of the frame to an optimal value.
|
2017-12-04 11:45:54 +00:00
|
|
|
tree_size.y = m_nbsheets * itemrect.GetHeight();
|
2017-12-10 12:22:43 +00:00
|
|
|
|
|
|
|
if( m_nbsheets < 2 )
|
|
|
|
tree_size.y += 10; // gives a better look for small trees
|
2012-07-10 12:26:26 +00:00
|
|
|
|
2017-12-04 11:45:54 +00:00
|
|
|
SetClientSize( tree_size );
|
2017-09-20 12:44:52 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// manage the ESC key to close the dialog, because there is no Cancel button
|
2017-12-10 12:22:43 +00:00
|
|
|
// in dialog
|
|
|
|
m_Tree->Connect( wxEVT_CHAR, wxKeyEventHandler( HIERARCHY_TREE::onChar ) );
|
|
|
|
|
|
|
|
// Manage double click on a selection, or the enter key:
|
|
|
|
Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_DLG::onSelectSheetPath, this );
|
2017-12-04 11:45:54 +00:00
|
|
|
// Manage a simple click on a selection, if the selection changes
|
2017-12-10 12:22:43 +00:00
|
|
|
Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_DLG::onSelectSheetPath, this );
|
2020-01-08 14:01:22 +00:00
|
|
|
|
2021-04-04 06:48:02 +00:00
|
|
|
// Connect close event for the dialog:
|
|
|
|
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( HIERARCHY_NAVIG_DLG::OnCloseNav ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_NAVIG_DLG::~HIERARCHY_NAVIG_DLG()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-12-10 12:22:43 +00:00
|
|
|
Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_DLG::onSelectSheetPath, this );
|
|
|
|
Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_DLG::onSelectSheetPath, this );
|
|
|
|
m_Tree->Disconnect( wxEVT_CHAR, wxKeyEventHandler( HIERARCHY_TREE::onChar ) );
|
2021-04-04 06:48:02 +00:00
|
|
|
Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( HIERARCHY_NAVIG_DLG::OnCloseNav ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-10 12:22:43 +00:00
|
|
|
void HIERARCHY_TREE::onChar( wxKeyEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-12-10 12:22:43 +00:00
|
|
|
if( event.GetKeyCode() == WXK_ESCAPE )
|
|
|
|
m_parent->Close( true );
|
|
|
|
else
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2020-09-21 18:16:32 +00:00
|
|
|
int HIERARCHY_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemId& item2 )
|
|
|
|
{
|
2020-11-29 00:10:17 +00:00
|
|
|
SCH_SHEET_PATH* item1Path = &static_cast<TreeItemData*>( GetItemData( item1 ) )->m_SheetPath;
|
|
|
|
SCH_SHEET_PATH* item2Path = &static_cast<TreeItemData*>( GetItemData( item2 ) )->m_SheetPath;
|
|
|
|
|
2022-01-02 23:20:01 +00:00
|
|
|
return item1Path->ComparePageNum( *item2Path );
|
2020-09-21 18:16:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-10 12:22:43 +00:00
|
|
|
void HIERARCHY_NAVIG_DLG::buildHierarchyTree( SCH_SHEET_PATH* aList, wxTreeItemId* aPreviousmenu )
|
|
|
|
{
|
2017-09-20 12:44:52 +00:00
|
|
|
wxCHECK_RET( m_nbsheets < NB_MAX_SHEET, "Maximum number of sheets exceeded." );
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2020-05-03 14:52:31 +00:00
|
|
|
std::vector<SCH_ITEM*> sheetChildren;
|
|
|
|
aList->LastScreen()->GetSheets( &sheetChildren );
|
|
|
|
|
|
|
|
for( SCH_ITEM* aItem : sheetChildren )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
|
2020-11-29 00:10:17 +00:00
|
|
|
aList->push_back( sheet );
|
|
|
|
|
|
|
|
wxString sheetName = formatPageString( sheet->GetFields()[SHEETNAME].GetShownText(),
|
2021-12-06 12:47:18 +00:00
|
|
|
sheet->GetPageNumber( *aList ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_nbsheets++;
|
|
|
|
wxTreeItemId menu;
|
2020-05-03 14:52:31 +00:00
|
|
|
menu = m_Tree->AppendItem( *aPreviousmenu, sheetName, 0, 1 );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_Tree->SetItemData( menu, new TreeItemData( *aList ) );
|
|
|
|
|
|
|
|
if( *aList == m_currSheet )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
m_Tree->EnsureVisible( menu );
|
|
|
|
m_Tree->SelectItem( menu );
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
buildHierarchyTree( aList, &menu );
|
|
|
|
aList->pop_back();
|
|
|
|
|
|
|
|
if( m_nbsheets >= NB_MAX_SHEET )
|
|
|
|
break;
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
2020-09-21 18:16:32 +00:00
|
|
|
|
|
|
|
m_Tree->SortChildren( *aPreviousmenu );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 00:10:17 +00:00
|
|
|
|
2019-10-24 17:07:01 +00:00
|
|
|
void HIERARCHY_NAVIG_DLG::UpdateHierarchyTree()
|
|
|
|
{
|
2020-01-08 14:01:22 +00:00
|
|
|
Freeze();
|
|
|
|
|
2020-11-29 00:10:17 +00:00
|
|
|
// Disable selection events
|
|
|
|
Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_DLG::onSelectSheetPath, this );
|
|
|
|
Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_DLG::onSelectSheetPath, this );
|
|
|
|
|
|
|
|
m_currSheet = m_SchFrameEditor->GetCurrentSheet();
|
|
|
|
m_Tree->DeleteAllItems();
|
|
|
|
m_nbsheets = 1;
|
|
|
|
|
|
|
|
wxTreeItemId root = m_Tree->AddRoot( getRootString(), 0, 1 );
|
|
|
|
m_Tree->SetItemBold( root, true );
|
|
|
|
|
2019-10-24 17:07:01 +00:00
|
|
|
m_list.clear();
|
2020-05-13 02:00:37 +00:00
|
|
|
m_list.push_back( &m_SchFrameEditor->Schematic().Root() );
|
2020-11-29 00:10:17 +00:00
|
|
|
m_Tree->SetItemData( root, new TreeItemData( m_list ) );
|
|
|
|
|
|
|
|
if( m_SchFrameEditor->GetCurrentSheet().Last() == &m_SchFrameEditor->Schematic().Root() )
|
|
|
|
m_Tree->SelectItem( root );
|
|
|
|
|
2019-10-24 17:07:01 +00:00
|
|
|
buildHierarchyTree( &m_list, &root );
|
2020-11-29 00:10:17 +00:00
|
|
|
m_Tree->ExpandAll();
|
|
|
|
|
|
|
|
// Enable selection events
|
|
|
|
Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_DLG::onSelectSheetPath, this );
|
|
|
|
Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_DLG::onSelectSheetPath, this );
|
2020-01-08 14:01:22 +00:00
|
|
|
|
|
|
|
Thaw();
|
2019-10-24 17:07:01 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-11-29 00:10:17 +00:00
|
|
|
|
2017-12-10 12:22:43 +00:00
|
|
|
void HIERARCHY_NAVIG_DLG::onSelectSheetPath( wxTreeEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-06-13 21:04:31 +00:00
|
|
|
m_SchFrameEditor->GetToolManager()->RunAction( ACTIONS::cancelInteractive, true );
|
|
|
|
m_SchFrameEditor->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
wxTreeItemId itemSel = m_Tree->GetSelection();
|
|
|
|
TreeItemData* itemData = static_cast<TreeItemData*>( m_Tree->GetItemData( itemSel ) );
|
|
|
|
|
2021-01-17 08:41:49 +00:00
|
|
|
// Store the current zoom level into the current screen before switching
|
|
|
|
m_SchFrameEditor->GetScreen()->m_LastZoomLevel =
|
|
|
|
m_SchFrameEditor->GetCanvas()->GetView()->GetScale();
|
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
m_SchFrameEditor->SetCurrentSheet( itemData->m_SheetPath );
|
2017-12-10 12:22:43 +00:00
|
|
|
m_SchFrameEditor->DisplayCurrentSheet();
|
2020-01-08 14:01:22 +00:00
|
|
|
|
2020-04-12 23:09:17 +00:00
|
|
|
EESCHEMA_SETTINGS* appSettings = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
|
|
|
|
|
|
|
if( !appSettings->m_Appearance.navigator_stays_open )
|
2019-10-24 17:07:01 +00:00
|
|
|
Close( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 14:01:22 +00:00
|
|
|
|
2020-11-29 00:10:17 +00:00
|
|
|
wxString HIERARCHY_NAVIG_DLG::getRootString()
|
|
|
|
{
|
|
|
|
SCH_SHEET* rootSheet = &m_SchFrameEditor->Schematic().Root();
|
|
|
|
SCH_SHEET_PATH rootPath;
|
|
|
|
rootPath.push_back( rootSheet );
|
|
|
|
|
2021-12-06 12:47:18 +00:00
|
|
|
return formatPageString ( _( "Root" ), rootSheet->GetPageNumber( rootPath ) );
|
2020-11-29 00:10:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-27 12:22:27 +00:00
|
|
|
wxString HIERARCHY_NAVIG_DLG::formatPageString( const wxString& aName, const wxString& aPage )
|
2020-11-29 00:10:17 +00:00
|
|
|
{
|
|
|
|
return aName + wxT( " " ) + wxString::Format( _( "(page %s)" ), aPage );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-08 14:01:22 +00:00
|
|
|
void HIERARCHY_NAVIG_DLG::OnCloseNav( wxCloseEvent& event )
|
2019-10-24 17:07:01 +00:00
|
|
|
{
|
2020-01-08 14:01:22 +00:00
|
|
|
Destroy();
|
2019-10-24 17:07:01 +00:00
|
|
|
}
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2020-01-08 14:01:22 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
void SCH_EDIT_FRAME::DisplayCurrentSheet()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-04-30 14:46:29 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolManager->RunAction( EE_ACTIONS::clearSelection, true );
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2020-01-18 17:21:10 +00:00
|
|
|
wxASSERT( screen );
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
SetScreen( screen );
|
2010-02-14 18:14:33 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// update the References
|
2020-05-13 02:00:37 +00:00
|
|
|
GetCurrentSheet().UpdateAllScreenReferences();
|
2011-02-05 02:21:11 +00:00
|
|
|
SetSheetNumberAndCount();
|
2009-12-02 21:44:03 +00:00
|
|
|
|
Mark null project initial screen as zoom-initialized
The variable `m_Initialized` in `BASE_SCREEN` is used by
`SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized
by the "zoom to fit screen" action. When this variable is `false`, the
function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit
screen", modifying the zoom level. This function is indirectly called in
the undo routines, so if `m_Initialized` is not set to `true`, a zoom
change will occur when the user undoes an operation, a behavior that is
undesired.
`m_Initialized` was not initialized to `true` for the null schematic
(the schematic that is loaded if no project is loaded), causing the
aforementioned undesired behavior.
To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set
`m_Initialized` to `true`, since it zooms to fit screen already. I've
moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used
only in Eeschema, and renamed it to `m_zoomInitialized`, a name I
believe that better describes what this variable does.
I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to
group the "zoom to fit screen" action with setting `m_Initialized` to
`true`, as they often should occur together.
I'd also like to say that I'm not confident whether
`SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level
initialization at this point, but I have decided to not change this
behavior for now, as the commit history suggests it's several years old.
Fixes https://gitlab.com/kicad/code/kicad/issues/7343
2021-01-30 22:47:39 +00:00
|
|
|
if( !screen->m_zoomInitialized )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
Mark null project initial screen as zoom-initialized
The variable `m_Initialized` in `BASE_SCREEN` is used by
`SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized
by the "zoom to fit screen" action. When this variable is `false`, the
function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit
screen", modifying the zoom level. This function is indirectly called in
the undo routines, so if `m_Initialized` is not set to `true`, a zoom
change will occur when the user undoes an operation, a behavior that is
undesired.
`m_Initialized` was not initialized to `true` for the null schematic
(the schematic that is loaded if no project is loaded), causing the
aforementioned undesired behavior.
To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set
`m_Initialized` to `true`, since it zooms to fit screen already. I've
moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used
only in Eeschema, and renamed it to `m_zoomInitialized`, a name I
believe that better describes what this variable does.
I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to
group the "zoom to fit screen" action with setting `m_Initialized` to
`true`, as they often should occur together.
I'd also like to say that I'm not confident whether
`SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level
initialization at this point, but I have decided to not change this
behavior for now, as the commit history suggests it's several years old.
Fixes https://gitlab.com/kicad/code/kicad/issues/7343
2021-01-30 22:47:39 +00:00
|
|
|
initScreenZoom();
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-17 08:41:49 +00:00
|
|
|
// Set zoom to last used in this screen
|
|
|
|
GetCanvas()->GetView()->SetScale( GetScreen()->m_LastZoomLevel );
|
2019-06-13 13:34:38 +00:00
|
|
|
RedrawScreen( (wxPoint) GetScreen()->m_ScrollCenter, false );
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
2011-03-01 18:45:21 +00:00
|
|
|
|
2019-03-15 12:09:04 +00:00
|
|
|
UpdateTitle();
|
|
|
|
|
2021-11-25 00:09:59 +00:00
|
|
|
HardRedraw(); // Ensure all items are redrawn (especially the drawing-sheet items)
|
|
|
|
|
2019-11-29 21:04:31 +00:00
|
|
|
SCH_EDITOR_CONTROL* editTool = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
|
|
|
|
TOOL_EVENT dummy;
|
|
|
|
editTool->UpdateNetHighlighting( dummy );
|
|
|
|
|
2021-09-23 22:14:25 +00:00
|
|
|
UpdateHierarchyNavigator();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|