Refactor hierarch.cpp: remove old dead code and clean current code.
This commit is contained in:
parent
c0a539959e
commit
cd3122d8cd
|
@ -121,8 +121,7 @@ public:
|
||||||
int m_nbsheets;
|
int m_nbsheets;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxSize m_TreeSize;
|
SCH_SHEET_PATH m_currSheet; // The currently opened scheet in hierarchy
|
||||||
int maxposx;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* aParent, const wxPoint& aPos );
|
HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* aParent, const wxPoint& aPos );
|
||||||
|
@ -132,18 +131,17 @@ public:
|
||||||
/**
|
/**
|
||||||
* Create the hierarchical tree of the schematic.
|
* Create the hierarchical tree of the schematic.
|
||||||
*
|
*
|
||||||
* This routine is re-entrant!
|
* This routine is reentrant!
|
||||||
|
* @param aList = the SCH_SHEET_PATH* list to explore
|
||||||
|
* @param aPreviousmenu = the wxTreeItemId used as parent to add sub items
|
||||||
*/
|
*/
|
||||||
void BuildTree( SCH_SHEET_PATH* list, wxTreeItemId* previousmenu );
|
void BuildTree( SCH_SHEET_PATH* aList, wxTreeItemId* aPreviousmenu );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the selected sheet and display the corresponding screen when a tree item is
|
* Open the selected sheet and display the corresponding screen when a tree item is
|
||||||
* selected.
|
* selected.
|
||||||
*/
|
*/
|
||||||
void OnSelect( wxTreeEvent& event );
|
void OnSelect( wxTreeEvent& event );
|
||||||
|
|
||||||
private:
|
|
||||||
void OnQuit( wxCommandEvent& event );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,6 +160,8 @@ HIERARCHY_NAVIG_DLG::HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* aParent, const wxPoint
|
||||||
{
|
{
|
||||||
wxASSERT( dynamic_cast< SCH_EDIT_FRAME* >( aParent ) );
|
wxASSERT( dynamic_cast< SCH_EDIT_FRAME* >( aParent ) );
|
||||||
|
|
||||||
|
m_currSheet = aParent->GetCurrentSheet();
|
||||||
|
|
||||||
wxTreeItemId root;
|
wxTreeItemId root;
|
||||||
|
|
||||||
m_Tree = new HIERARCHY_TREE( this );
|
m_Tree = new HIERARCHY_TREE( this );
|
||||||
|
@ -178,25 +178,31 @@ HIERARCHY_NAVIG_DLG::HIERARCHY_NAVIG_DLG( SCH_EDIT_FRAME* aParent, const wxPoint
|
||||||
if( dynamic_cast< SCH_EDIT_FRAME* >( aParent )->GetCurrentSheet().Last() == g_RootSheet )
|
if( dynamic_cast< SCH_EDIT_FRAME* >( aParent )->GetCurrentSheet().Last() == g_RootSheet )
|
||||||
m_Tree->SelectItem( root ); //root.
|
m_Tree->SelectItem( root ); //root.
|
||||||
|
|
||||||
maxposx = 15;
|
|
||||||
BuildTree( &list, &root );
|
BuildTree( &list, &root );
|
||||||
|
|
||||||
m_Tree->Expand( root );
|
m_Tree->ExpandAll();
|
||||||
|
|
||||||
|
#if 1
|
||||||
wxRect itemrect;
|
wxRect itemrect;
|
||||||
|
wxSize tree_size;
|
||||||
|
|
||||||
m_Tree->GetBoundingRect( root, itemrect );
|
m_Tree->GetBoundingRect( root, itemrect );
|
||||||
|
|
||||||
// Set dialog window size to be large enough
|
// Set dialog window size to be large enough
|
||||||
m_TreeSize.x = itemrect.GetWidth() + 20;
|
tree_size.x = itemrect.GetWidth() + 20;
|
||||||
m_TreeSize.x = std::max( m_TreeSize.x, 250 );
|
tree_size.x = std::max( tree_size.x, 250 );
|
||||||
|
|
||||||
// Readjust the size of the frame to an optimal value.
|
// Readjust the size of the frame to an optimal value.
|
||||||
m_TreeSize.y = m_nbsheets * itemrect.GetHeight();
|
tree_size.y = m_nbsheets * itemrect.GetHeight();
|
||||||
m_TreeSize.y += 10;
|
tree_size.y += 10;
|
||||||
|
|
||||||
SetClientSize( m_TreeSize );
|
SetClientSize( tree_size );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Manage double click on a selection:
|
||||||
Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_DLG::OnSelect, this );
|
Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_DLG::OnSelect, this );
|
||||||
|
// Manage a simple click on a selection, if the selection changes
|
||||||
|
Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_DLG::OnSelect, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -206,22 +212,15 @@ HIERARCHY_NAVIG_DLG::~HIERARCHY_NAVIG_DLG()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HIERARCHY_NAVIG_DLG::OnQuit( wxCommandEvent& event )
|
void HIERARCHY_NAVIG_DLG::BuildTree( SCH_SHEET_PATH* aList, wxTreeItemId* aPreviousmenu )
|
||||||
{
|
|
||||||
// true is to force the frame to close
|
|
||||||
Close( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void HIERARCHY_NAVIG_DLG::BuildTree( SCH_SHEET_PATH* list, wxTreeItemId* previousmenu )
|
|
||||||
|
|
||||||
{
|
{
|
||||||
wxTreeItemId menu;
|
wxTreeItemId menu;
|
||||||
|
|
||||||
wxCHECK_RET( m_nbsheets < NB_MAX_SHEET, "Maximum number of sheets exceeded." );
|
wxCHECK_RET( m_nbsheets < NB_MAX_SHEET, "Maximum number of sheets exceeded." );
|
||||||
|
|
||||||
maxposx += m_Tree->GetIndent();
|
SCH_ITEM* schitem = aList->LastDrawList();
|
||||||
SCH_ITEM* schitem = list->LastDrawList();
|
|
||||||
|
wxClientDC currdc( this ); // usefull to calculate the width of texts to display
|
||||||
|
|
||||||
while( schitem && m_nbsheets < NB_MAX_SHEET )
|
while( schitem && m_nbsheets < NB_MAX_SHEET )
|
||||||
{
|
{
|
||||||
|
@ -229,37 +228,23 @@ void HIERARCHY_NAVIG_DLG::BuildTree( SCH_SHEET_PATH* list, wxTreeItemId* previo
|
||||||
{
|
{
|
||||||
SCH_SHEET* sheet = (SCH_SHEET*) schitem;
|
SCH_SHEET* sheet = (SCH_SHEET*) schitem;
|
||||||
m_nbsheets++;
|
m_nbsheets++;
|
||||||
menu = m_Tree->AppendItem( *previousmenu, sheet->GetName(), 0, 1 );
|
menu = m_Tree->AppendItem( *aPreviousmenu, sheet->GetName(), 0, 1 );
|
||||||
list->push_back( sheet );
|
aList->push_back( sheet );
|
||||||
m_Tree->SetItemData( menu, new TreeItemData( *list ) );
|
m_Tree->SetItemData( menu, new TreeItemData( *aList ) );
|
||||||
int ll = m_Tree->GetItemText( menu ).Len();
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
if( *aList == m_currSheet )
|
||||||
ll *= 9; // * char width
|
|
||||||
#else
|
|
||||||
ll *= 12; // * char width
|
|
||||||
#endif
|
|
||||||
ll += maxposx + 20;
|
|
||||||
m_TreeSize.x = std::max( m_TreeSize.x, ll );
|
|
||||||
m_TreeSize.y += 1;
|
|
||||||
|
|
||||||
SCH_EDIT_FRAME* parent = dynamic_cast< SCH_EDIT_FRAME* >( GetParent() );
|
|
||||||
|
|
||||||
if( parent && *list == parent->GetCurrentSheet() )
|
|
||||||
{
|
{
|
||||||
m_Tree->EnsureVisible( menu );
|
m_Tree->EnsureVisible( menu );
|
||||||
m_Tree->SelectItem( menu );
|
m_Tree->SelectItem( menu );
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildTree( list, &menu );
|
BuildTree( aList, &menu );
|
||||||
m_Tree->Expand( menu );
|
|
||||||
list->pop_back();
|
aList->pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
schitem = schitem->Next();
|
schitem = schitem->Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
maxposx -= m_Tree->GetIndent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -267,10 +252,7 @@ void HIERARCHY_NAVIG_DLG::OnSelect( wxTreeEvent& event )
|
||||||
|
|
||||||
{
|
{
|
||||||
wxTreeItemId ItemSel = m_Tree->GetSelection();
|
wxTreeItemId ItemSel = m_Tree->GetSelection();
|
||||||
SCH_EDIT_FRAME* parent = dynamic_cast< SCH_EDIT_FRAME* >( GetParent() );
|
SCH_EDIT_FRAME* parent = static_cast< SCH_EDIT_FRAME* >( GetParent() );
|
||||||
|
|
||||||
wxCHECK2_MSG( parent, Close( true ),
|
|
||||||
"Parent window of hierarchy dialog is not SCH_EDIT_FRAME." );
|
|
||||||
|
|
||||||
parent->SetCurrentSheet(( (TreeItemData*) m_Tree->GetItemData( ItemSel ) )->m_SheetPath );
|
parent->SetCurrentSheet(( (TreeItemData*) m_Tree->GetItemData( ItemSel ) )->m_SheetPath );
|
||||||
parent->DisplayCurrentSheet();
|
parent->DisplayCurrentSheet();
|
||||||
|
|
Loading…
Reference in New Issue