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>
|
|
|
|
* Copyright (C) 2004-2017 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
2015-07-11 07:37:52 +00:00
|
|
|
* @file hierarch.cpp
|
2011-10-07 14:41:30 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#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>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
#include <schframe.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_sheet_path.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/imaglist.h>
|
|
|
|
#include <wx/treectrl.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-11-16 10:07:02 +00:00
|
|
|
#include <class_netlist_object.h>
|
|
|
|
#include <sch_sheet_path.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
enum
|
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
ID_TREECTRL_HIERARCHY = 1600
|
2007-06-05 12:10:51 +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
|
|
|
};
|
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle hierarchy tree control.
|
|
|
|
*/
|
2011-02-17 13:56:54 +00:00
|
|
|
class HIERARCHY_TREE : public wxTreeCtrl
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
private:
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_NAVIG_DLG* m_Parent;
|
2008-07-31 15:30:57 +00:00
|
|
|
wxImageList* imageList;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2015-02-28 20:50:35 +00:00
|
|
|
HIERARCHY_TREE()
|
|
|
|
{
|
|
|
|
m_Parent = NULL;
|
|
|
|
imageList = NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_TREE( HIERARCHY_NAVIG_DLG* parent );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS( HIERARCHY_TREE )
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS( HIERARCHY_TREE, wxTreeCtrl )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_TREE::HIERARCHY_TREE( HIERARCHY_NAVIG_DLG* parent ) :
|
2011-02-05 02:21:11 +00:00
|
|
|
wxTreeCtrl( (wxWindow*)parent, ID_TREECTRL_HIERARCHY, wxDefaultPosition, wxDefaultSize,
|
2009-12-02 21:44:03 +00:00
|
|
|
wxTR_HAS_BUTTONS, wxDefaultValidator, wxT( "HierachyTreeCtrl" ) )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-07-31 15:30:57 +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.
|
|
|
|
wxBitmap tree_nosel_bm( KiBitmap( tree_nosel_xpm ) );
|
2012-07-12 14:59:06 +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 );
|
2011-08-28 20:02:27 +00:00
|
|
|
imageList->Add( KiBitmap( tree_sel_xpm ) );
|
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
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
class HIERARCHY_NAVIG_DLG : public DIALOG_SHIM
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-04-06 12:28:02 +00:00
|
|
|
HIERARCHY_TREE* m_Tree;
|
2010-12-08 20:12:46 +00:00
|
|
|
int m_nbsheets;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2017-12-04 11:45:54 +00:00
|
|
|
SCH_SHEET_PATH m_currSheet; // The currently opened scheet in hierarchy
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2015-07-11 07:37:52 +00:00
|
|
|
HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* aParent, const wxPoint& aPos );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
~HIERARCHY_NAVIG_DLG();
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
/**
|
|
|
|
* Create the hierarchical tree of the schematic.
|
|
|
|
*
|
2017-12-04 11:45:54 +00:00
|
|
|
* This routine is reentrant!
|
|
|
|
* @param aList = the SCH_SHEET_PATH* list to explore
|
|
|
|
* @param aPreviousmenu = the wxTreeItemId used as parent to add sub items
|
2017-09-20 12:44:52 +00:00
|
|
|
*/
|
2017-12-04 11:45:54 +00:00
|
|
|
void BuildTree( SCH_SHEET_PATH* aList, wxTreeItemId* aPreviousmenu );
|
2017-09-20 12:44:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the selected sheet and display the corresponding screen when a tree item is
|
|
|
|
* selected.
|
|
|
|
*/
|
2008-07-31 15:30:57 +00:00
|
|
|
void OnSelect( wxTreeEvent& event );
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-11 07:37:52 +00:00
|
|
|
void SCH_EDIT_FRAME::InstallHierarchyFrame( wxPoint& pos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-07-11 07:37:52 +00:00
|
|
|
HIERARCHY_NAVIG_DLG* treeframe = new HIERARCHY_NAVIG_DLG( this, pos );
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
treeframe->ShowQuasiModal();
|
2009-12-02 21:44:03 +00:00
|
|
|
treeframe->Destroy();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-11 07:37:52 +00:00
|
|
|
HIERARCHY_NAVIG_DLG::HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* aParent, const wxPoint& aPos ) :
|
2017-09-20 12:44:52 +00:00
|
|
|
DIALOG_SHIM( aParent, wxID_ANY, _( "Navigator" ), wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
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-04 11:45:54 +00:00
|
|
|
m_currSheet = aParent->GetCurrentSheet();
|
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
wxTreeItemId root;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
m_Tree = new HIERARCHY_TREE( this );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
m_nbsheets = 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
root = m_Tree->AddRoot( _( "Root" ), 0, 1 );
|
|
|
|
m_Tree->SetItemBold( root, true );
|
2012-07-10 12:26:26 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH list;
|
2016-02-27 19:35:45 +00:00
|
|
|
list.push_back( g_RootSheet );
|
2017-09-20 12:44:52 +00:00
|
|
|
m_Tree->SetItemData( root, new TreeItemData( list ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
if( dynamic_cast< SCH_EDIT_FRAME* >( aParent )->GetCurrentSheet().Last() == g_RootSheet )
|
|
|
|
m_Tree->SelectItem( root ); //root.
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
BuildTree( &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-04 11:45:54 +00:00
|
|
|
#if 1
|
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();
|
|
|
|
tree_size.y += 10;
|
2012-07-10 12:26:26 +00:00
|
|
|
|
2017-12-04 11:45:54 +00:00
|
|
|
SetClientSize( tree_size );
|
|
|
|
#endif
|
2017-09-20 12:44:52 +00:00
|
|
|
|
2017-12-04 11:45:54 +00:00
|
|
|
// Manage double click on a selection:
|
2017-09-20 12:44:52 +00:00
|
|
|
Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_DLG::OnSelect, this );
|
2017-12-04 11:45:54 +00:00
|
|
|
// Manage a simple click on a selection, if the selection changes
|
|
|
|
Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_DLG::OnSelect, this );
|
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-09-20 12:44:52 +00:00
|
|
|
Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_DLG::OnSelect, this );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-04 11:45:54 +00:00
|
|
|
void HIERARCHY_NAVIG_DLG::BuildTree( SCH_SHEET_PATH* aList, wxTreeItemId* aPreviousmenu )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
wxTreeItemId menu;
|
|
|
|
|
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
|
|
|
|
2017-12-04 11:45:54 +00:00
|
|
|
SCH_ITEM* schitem = aList->LastDrawList();
|
|
|
|
|
|
|
|
wxClientDC currdc( this ); // usefull to calculate the width of texts to display
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2009-01-07 17:33:18 +00:00
|
|
|
while( schitem && m_nbsheets < NB_MAX_SHEET )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( schitem->Type() == SCH_SHEET_T )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) schitem;
|
2008-07-31 15:30:57 +00:00
|
|
|
m_nbsheets++;
|
2017-12-04 11:45:54 +00:00
|
|
|
menu = m_Tree->AppendItem( *aPreviousmenu, sheet->GetName(), 0, 1 );
|
|
|
|
aList->push_back( sheet );
|
|
|
|
m_Tree->SetItemData( menu, new TreeItemData( *aList ) );
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2017-12-04 11:45:54 +00:00
|
|
|
if( *aList == m_currSheet )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
|
|
|
m_Tree->EnsureVisible( menu );
|
|
|
|
m_Tree->SelectItem( menu );
|
|
|
|
}
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2017-12-04 11:45:54 +00:00
|
|
|
BuildTree( aList, &menu );
|
|
|
|
|
|
|
|
aList->pop_back();
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2009-01-07 17:33:18 +00:00
|
|
|
schitem = schitem->Next();
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
void HIERARCHY_NAVIG_DLG::OnSelect( wxTreeEvent& event )
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
wxTreeItemId ItemSel = m_Tree->GetSelection();
|
2017-12-04 11:45:54 +00:00
|
|
|
SCH_EDIT_FRAME* parent = static_cast< SCH_EDIT_FRAME* >( GetParent() );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2017-09-20 12:44:52 +00:00
|
|
|
parent->SetCurrentSheet(( (TreeItemData*) m_Tree->GetItemData( ItemSel ) )->m_SheetPath );
|
|
|
|
parent->DisplayCurrentSheet();
|
2011-02-05 02:21:11 +00:00
|
|
|
Close( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
void SCH_EDIT_FRAME::DisplayCurrentSheet()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-08-05 21:02:41 +00:00
|
|
|
SetRepeatItem( NULL );
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
SCH_SCREEN* screen = m_CurrentSheet->LastScreen();
|
2011-01-30 22:22:38 +00:00
|
|
|
|
2014-02-02 19:51:50 +00:00
|
|
|
// Switch to current sheet,
|
|
|
|
// and update the grid size, because it can be modified in latest screen
|
2011-02-05 02:21:11 +00:00
|
|
|
SetScreen( screen );
|
2014-02-02 19:51:50 +00:00
|
|
|
GetScreen()->SetGrid( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 );
|
2010-02-14 18:14:33 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// update the References
|
2016-02-15 20:17:51 +00:00
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
2011-02-05 02:21:11 +00:00
|
|
|
SetSheetNumberAndCount();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetCanStartBlock( -1 );
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2011-01-30 22:22:38 +00:00
|
|
|
if( screen->m_FirstRedraw )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2011-03-01 18:45:21 +00:00
|
|
|
Zoom_Automatique( false );
|
2011-01-30 22:22:38 +00:00
|
|
|
screen->m_FirstRedraw = false;
|
2013-08-03 05:15:23 +00:00
|
|
|
SetCrossHairPosition( GetScrollCenterPosition() );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2017-11-27 19:27:24 +00:00
|
|
|
|
|
|
|
// Ensure the schematic is fully segmented on first display
|
|
|
|
BreakSegmentsOnJunctions();
|
|
|
|
SchematicCleanUp( true );
|
|
|
|
screen->ClearUndoORRedoList( screen->m_UndoList, 1 );
|
|
|
|
|
|
|
|
screen->TestDanglingEnds();
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
RedrawScreen( GetScrollCenterPosition(), true );
|
2008-07-31 15:30:57 +00:00
|
|
|
}
|
2011-03-01 18:45:21 +00:00
|
|
|
|
2016-11-16 12:09:34 +00:00
|
|
|
// Some items (wires, labels) can be highlighted. So prepare the highlight flag:
|
|
|
|
SetCurrentSheetHighlightFlags();
|
2016-11-16 10:07:02 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
// Now refresh m_canvas. Should be not necessary, but because screen has changed
|
2011-03-01 18:45:21 +00:00
|
|
|
// the previous refresh has set all new draw parameters (scroll position ..)
|
|
|
|
// but most of time there were some inconsitencies about cursor parameters
|
|
|
|
// ( previous position of cursor ...) and artefacts can happen
|
|
|
|
// mainly when sheet size has changed
|
|
|
|
// This second refresh clears artefacts because at this point,
|
|
|
|
// all parameters are now updated
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|