2011-12-08 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file hierarch.cpp
|
|
|
|
*/
|
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>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wxEeschemaStruct.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* This class derived from wxTreeItemData stores the SCH_SHEET_PATH of each
|
2009-11-04 20:46:53 +00:00
|
|
|
* sheet in hierarchy in each TreeItem, in its associated data buffer
|
2009-01-07 20:09:03 +00:00
|
|
|
*/
|
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;
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Class to handle hierarchy tree. */
|
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:
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_TREE() { }
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
class HIERARCHY_NAVIG_DLG : public wxDialog
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_EDIT_FRAME* m_Parent;
|
2013-04-06 12:28:02 +00:00
|
|
|
HIERARCHY_TREE* m_Tree;
|
2010-12-08 20:12:46 +00:00
|
|
|
int m_nbsheets;
|
|
|
|
wxDC* m_DC;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2009-11-04 20:46:53 +00:00
|
|
|
wxSize m_TreeSize;
|
2008-07-31 15:30:57 +00:00
|
|
|
int maxposx;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* parent, wxDC* DC, const wxPoint& pos );
|
2009-12-02 21:44:03 +00:00
|
|
|
void BuildSheetsTree( SCH_SHEET_PATH* list, wxTreeItemId* previousmenu );
|
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
|
|
|
|
|
|
|
void OnSelect( wxTreeEvent& event );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2008-07-31 15:30:57 +00:00
|
|
|
void OnQuit( wxCommandEvent& event );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
BEGIN_EVENT_TABLE( HIERARCHY_NAVIG_DLG, wxDialog )
|
|
|
|
EVT_TREE_ITEM_ACTIVATED( ID_TREECTRL_HIERARCHY, HIERARCHY_NAVIG_DLG::OnSelect )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::InstallHierarchyFrame( wxDC* DC, wxPoint& pos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_NAVIG_DLG* treeframe = new HIERARCHY_NAVIG_DLG( this, DC, pos );
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
treeframe->ShowModal();
|
|
|
|
treeframe->Destroy();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
HIERARCHY_NAVIG_DLG::HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* parent, wxDC* DC, const wxPoint& pos ) :
|
2013-11-15 09:28:31 +00:00
|
|
|
wxDialog( parent, -1, _( "Navigator" ), pos, wxSize( 110, 50 ),
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
wxTreeItemId cellule;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
m_DC = DC;
|
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
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
cellule = m_Tree->AddRoot( _( "Root" ), 0, 1 );
|
2011-10-07 14:41:30 +00:00
|
|
|
m_Tree->SetItemBold( cellule, true );
|
2012-07-10 12:26:26 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH list;
|
2008-07-31 15:30:57 +00:00
|
|
|
list.Push( g_RootSheet );
|
|
|
|
m_Tree->SetItemData( cellule, new TreeItemData( list ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-08 21:05:43 +00:00
|
|
|
if( m_Parent->GetCurrentSheet().Last() == g_RootSheet )
|
2008-07-31 15:30:57 +00:00
|
|
|
m_Tree->SelectItem( cellule ); //root.
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
maxposx = 15;
|
2009-01-04 18:52:57 +00:00
|
|
|
BuildSheetsTree( &list, &cellule );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-07-10 12:26:26 +00:00
|
|
|
m_Tree->Expand( cellule );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-07-10 12:26:26 +00:00
|
|
|
wxRect itemrect;
|
|
|
|
m_Tree->GetBoundingRect( cellule, itemrect );
|
|
|
|
|
|
|
|
// Set dialog window size to be large enough
|
|
|
|
m_TreeSize.x = itemrect.GetWidth() + 20;
|
2013-12-13 16:27:30 +00:00
|
|
|
m_TreeSize.x = std::max( m_TreeSize.x, 250 );
|
2012-07-10 12:26:26 +00:00
|
|
|
|
|
|
|
// Readjust the size of the frame to an optimal value.
|
|
|
|
m_TreeSize.y = m_nbsheets * itemrect.GetHeight();
|
|
|
|
m_TreeSize.y += 10;
|
|
|
|
|
|
|
|
SetClientSize( m_TreeSize );
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
void HIERARCHY_NAVIG_DLG::OnQuit( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
// true is to force the frame to close
|
2008-07-31 15:30:57 +00:00
|
|
|
Close( true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2011-02-17 13:56:54 +00:00
|
|
|
/* Routine to create the hierarchical tree of the schematic
|
2009-11-04 20:46:53 +00:00
|
|
|
* This routine is re-entrant!
|
|
|
|
*/
|
2011-02-17 13:56:54 +00:00
|
|
|
void HIERARCHY_NAVIG_DLG::BuildSheetsTree( SCH_SHEET_PATH* list, wxTreeItemId* previousmenu )
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
wxTreeItemId menu;
|
|
|
|
|
|
|
|
if( m_nbsheets > NB_MAX_SHEET )
|
|
|
|
{
|
|
|
|
if( m_nbsheets == (NB_MAX_SHEET + 1) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2009-01-04 18:52:57 +00:00
|
|
|
msg << wxT( "BuildSheetsTree: Error: nbsheets > " ) << NB_MAX_SHEET;
|
2008-07-31 15:30:57 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
m_nbsheets++;
|
|
|
|
}
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxposx += m_Tree->GetIndent();
|
2009-01-07 17:33:18 +00:00
|
|
|
SCH_ITEM* schitem = list->LastDrawList();
|
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++;
|
2011-12-08 15:45:01 +00:00
|
|
|
menu = m_Tree->AppendItem( *previousmenu, sheet->GetName(), 0, 1 );
|
2009-01-07 17:33:18 +00:00
|
|
|
list->Push( sheet );
|
2008-07-31 15:30:57 +00:00
|
|
|
m_Tree->SetItemData( menu, new TreeItemData( *list ) );
|
|
|
|
int ll = m_Tree->GetItemText( menu ).Len();
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#ifdef __WINDOWS__
|
2008-07-31 15:30:57 +00:00
|
|
|
ll *= 9; // * char width
|
2007-06-05 12:10:51 +00:00
|
|
|
#else
|
2008-07-31 15:30:57 +00:00
|
|
|
ll *= 12; // * char width
|
2007-06-05 12:10:51 +00:00
|
|
|
#endif
|
2008-07-31 15:30:57 +00:00
|
|
|
ll += maxposx + 20;
|
2012-09-22 11:19:37 +00:00
|
|
|
m_TreeSize.x = std::max( m_TreeSize.x, ll );
|
2008-07-31 15:30:57 +00:00
|
|
|
m_TreeSize.y += 1;
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2011-12-08 21:05:43 +00:00
|
|
|
if( *list == m_Parent->GetCurrentSheet() )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
|
|
|
m_Tree->EnsureVisible( menu );
|
|
|
|
m_Tree->SelectItem( menu );
|
|
|
|
}
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
BuildSheetsTree( list, &menu );
|
2008-07-31 15:30:57 +00:00
|
|
|
m_Tree->Expand( menu );
|
|
|
|
list->Pop();
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
maxposx -= m_Tree->GetIndent();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 19:27:25 +00:00
|
|
|
/* Called on a double-click on a tree item:
|
2009-11-04 20:46:53 +00:00
|
|
|
* Open the selected sheet, and display the corresponding screen
|
2008-07-31 15:30:57 +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();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2011-12-08 21:05:43 +00:00
|
|
|
m_Parent->SetCurrentSheet(( (TreeItemData*) m_Tree->GetItemData( ItemSel ) )->m_SheetPath );
|
2011-02-05 02:21:11 +00:00
|
|
|
m_Parent->DisplayCurrentSheet();
|
|
|
|
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
|
2011-02-05 02:21:11 +00:00
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
|
|
|
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();
|
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
|
|
|
|
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
|
|
|
}
|