2007-06-05 12:10:51 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* hierarch.cpp: Gestion de la hierarchie: navigation dans les feuilles */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "bitmaps.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
|
|
|
|
#include "wx/imaglist.h"
|
|
|
|
#include "wx/treectrl.h"
|
|
|
|
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
static bool UpdateScreenFromSheet( WinEDA_SchematicFrame* frame );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
enum {
|
2008-07-31 15:30:57 +00:00
|
|
|
ID_TREECTRL_HIERARCHY = 1600
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class WinEDA_HierFrame;
|
|
|
|
|
2009-01-07 20:09:03 +00:00
|
|
|
/* This class derived from wxTreeItemData stores the DrawSheetPath of each sheet in hierarcy
|
|
|
|
* in each TreeItem, in its associated data buffer
|
|
|
|
*/
|
2008-07-31 15:30:57 +00:00
|
|
|
class TreeItemData : public wxTreeItemData
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-01-07 20:09:03 +00:00
|
|
|
DrawSheetPath m_SheetPath;
|
2008-07-31 15:30:57 +00:00
|
|
|
TreeItemData( DrawSheetPath sheet ) : wxTreeItemData()
|
|
|
|
{
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/* Classe de l'arbre de hierarchie */
|
|
|
|
class WinEDA_Tree : public wxTreeCtrl
|
|
|
|
{
|
|
|
|
private:
|
2008-07-31 15:30:57 +00:00
|
|
|
WinEDA_HierFrame* m_Parent;
|
|
|
|
wxImageList* imageList;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2008-07-31 15:30:57 +00:00
|
|
|
WinEDA_Tree() { }
|
|
|
|
WinEDA_Tree( WinEDA_HierFrame* parent );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS( WinEDA_Tree )
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
2008-07-31 15:30:57 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS( WinEDA_Tree, wxTreeCtrl )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
WinEDA_Tree::WinEDA_Tree( WinEDA_HierFrame* parent ) :
|
|
|
|
wxTreeCtrl( (wxWindow*)parent, ID_TREECTRL_HIERARCHY,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
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
|
|
|
|
imageList = new wxImageList( 16, 15, TRUE, 2 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
imageList->Add( wxBitmap( tree_nosel_xpm ) );
|
|
|
|
imageList->Add( wxBitmap( 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
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Classe definissant la fenetre d'affichage de la hierarchie */
|
|
|
|
class WinEDA_HierFrame : public wxDialog
|
|
|
|
{
|
|
|
|
public:
|
2008-07-31 15:30:57 +00:00
|
|
|
WinEDA_SchematicFrame* m_Parent;
|
|
|
|
WinEDA_Tree* m_Tree;
|
|
|
|
int m_nbsheets;
|
|
|
|
wxDC* m_DC;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
private:
|
2008-07-31 15:30:57 +00:00
|
|
|
wxSize m_TreeSize; // Taille de l'arbre de hierarchie
|
|
|
|
int maxposx;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2008-07-31 15:30:57 +00:00
|
|
|
WinEDA_HierFrame( WinEDA_SchematicFrame* parent, wxDC* DC, const wxPoint& pos );
|
2009-01-04 18:52:57 +00:00
|
|
|
void BuildSheetsTree( DrawSheetPath* list, wxTreeItemId* previousmenu );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
~WinEDA_HierFrame();
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
BEGIN_EVENT_TABLE( WinEDA_HierFrame, wxDialog )
|
|
|
|
EVT_TREE_ITEM_ACTIVATED( ID_TREECTRL_HIERARCHY,
|
|
|
|
WinEDA_HierFrame::OnSelect )
|
2007-06-05 12:10:51 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
2008-07-31 15:30:57 +00:00
|
|
|
void WinEDA_SchematicFrame::InstallHierarchyFrame( wxDC* DC, wxPoint& pos )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
WinEDA_HierFrame* treeframe = new WinEDA_HierFrame( this, DC, pos );
|
|
|
|
|
|
|
|
treeframe->ShowModal(); treeframe->Destroy();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
WinEDA_HierFrame::WinEDA_HierFrame( WinEDA_SchematicFrame* parent, wxDC* DC,
|
|
|
|
const wxPoint& pos ) :
|
|
|
|
wxDialog( parent, -1, _( "Navigator" ), pos, wxSize( 110, 50 ),
|
|
|
|
DIALOG_STYLE )
|
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;
|
|
|
|
m_Tree = new WinEDA_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 );
|
|
|
|
m_Tree->SetItemBold( cellule, TRUE );
|
|
|
|
DrawSheetPath list;
|
|
|
|
list.Push( g_RootSheet );
|
|
|
|
m_Tree->SetItemData( cellule, new TreeItemData( list ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
wxRect itemrect;
|
2007-06-05 12:10:51 +00:00
|
|
|
#ifdef __UNIX__
|
2008-07-31 15:30:57 +00:00
|
|
|
itemrect.SetWidth( 100 );
|
|
|
|
itemrect.SetHeight( 20 );
|
2007-06-05 12:10:51 +00:00
|
|
|
#else
|
2008-07-31 15:30:57 +00:00
|
|
|
m_Tree->GetBoundingRect( cellule, itemrect );
|
2007-06-05 12:10:51 +00:00
|
|
|
#endif
|
2008-07-31 15:30:57 +00:00
|
|
|
m_TreeSize.x = itemrect.GetWidth() + 10;
|
|
|
|
m_TreeSize.y = 20;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
if( m_Parent->GetSheet()->Last() == g_RootSheet )
|
|
|
|
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
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
if( m_nbsheets > 1 )
|
|
|
|
{
|
|
|
|
m_Tree->Expand( cellule );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
// Reajustage de la taille de la frame a une valeur optimale
|
|
|
|
m_TreeSize.y += m_nbsheets * itemrect.GetHeight();
|
|
|
|
m_TreeSize.x = MIN( m_TreeSize.x, 250 );
|
|
|
|
m_TreeSize.y = MIN( m_TreeSize.y, 350 );
|
|
|
|
SetClientSize( m_TreeSize );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
WinEDA_HierFrame::~WinEDA_HierFrame()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
2008-07-31 15:30:57 +00:00
|
|
|
void WinEDA_HierFrame::OnQuit( wxCommandEvent& WXUNUSED (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
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************************/
|
2009-01-04 18:52:57 +00:00
|
|
|
void WinEDA_HierFrame::BuildSheetsTree( DrawSheetPath* list,
|
2008-07-31 15:30:57 +00:00
|
|
|
wxTreeItemId* previousmenu )
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************************/
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine de creation de l'arbre de navigation dans la hierarchy
|
2008-07-31 15:30:57 +00:00
|
|
|
* schematique
|
|
|
|
* Cette routine est Reentrante !
|
|
|
|
*/
|
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++;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxposx += m_Tree->GetIndent();
|
2009-01-07 17:33:18 +00:00
|
|
|
SCH_ITEM* schitem = list->LastDrawList();
|
|
|
|
while( schitem && m_nbsheets < NB_MAX_SHEET )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2009-01-07 17:33:18 +00:00
|
|
|
if( schitem->Type() == DRAW_SHEET_STRUCT_TYPE )
|
2008-07-31 15:30:57 +00:00
|
|
|
{
|
2009-01-07 17:33:18 +00:00
|
|
|
DrawSheetStruct* sheet = (DrawSheetStruct*) schitem;
|
2008-07-31 15:30:57 +00:00
|
|
|
m_nbsheets++;
|
2009-01-07 17:33:18 +00:00
|
|
|
menu = m_Tree->AppendItem( *previousmenu, sheet->m_SheetName, 0, 1 );
|
|
|
|
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();
|
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;
|
|
|
|
m_TreeSize.x = MAX( m_TreeSize.x, ll );
|
|
|
|
m_TreeSize.y += 1;
|
|
|
|
if( *list == *( m_Parent->GetSheet() ) )
|
|
|
|
{
|
|
|
|
m_Tree->EnsureVisible( menu );
|
|
|
|
m_Tree->SelectItem( menu );
|
|
|
|
}
|
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();
|
|
|
|
}
|
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-07-31 15:30:57 +00:00
|
|
|
void WinEDA_HierFrame::OnSelect( wxTreeEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************/
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2008-02-28 19:27:25 +00:00
|
|
|
/* Called on a double-click on a tree item:
|
2008-07-31 15:30:57 +00:00
|
|
|
* Open the selected sheet, and display the corresponding screen
|
|
|
|
*/
|
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
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
*(m_Parent->m_CurrentSheet) =
|
2009-01-07 20:09:03 +00:00
|
|
|
( (TreeItemData*) m_Tree->GetItemData( ItemSel ) )->m_SheetPath;
|
2008-07-31 15:30:57 +00:00
|
|
|
UpdateScreenFromSheet( m_Parent );
|
|
|
|
Close( TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************************/
|
2008-02-12 21:12:46 +00:00
|
|
|
void WinEDA_SchematicFrame::InstallPreviousSheet()
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************************/
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Set the current screen to display the parent sheet of the current displayed sheet
|
2008-07-31 15:30:57 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
if( m_CurrentSheet->Last() == g_RootSheet )
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_ItemToRepeat = NULL;
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2008-07-31 15:30:57 +00:00
|
|
|
|
|
|
|
//make a copy for testing purposes.
|
|
|
|
DrawSheetPath listtemp = *m_CurrentSheet;
|
|
|
|
listtemp.Pop();
|
|
|
|
if( listtemp.LastScreen() == NULL )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "InstallPreviousScreen() Error: Sheet not found" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_CurrentSheet->Pop();
|
|
|
|
UpdateScreenFromSheet( this );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************************/
|
2008-07-31 15:30:57 +00:00
|
|
|
void WinEDA_SchematicFrame::InstallNextScreen( DrawSheetStruct* Sheet )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************************/
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine d'installation de l'ecran correspondant au symbole Sheet pointe
|
2008-07-31 15:30:57 +00:00
|
|
|
* par la souris
|
|
|
|
* have to be careful here because the DrawSheetStructs within the EEDrawList
|
|
|
|
* don't actually have a valid m_AssociatedScreen (on purpose -- you need the m_SubSheet hierarchy
|
|
|
|
* to maintain path info (well, this is but one way to maintain path info..)
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
if( Sheet == NULL )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "InstallNextScreen() error" ) ); return;
|
|
|
|
}
|
|
|
|
m_CurrentSheet->Push( Sheet );
|
|
|
|
g_ItemToRepeat = NULL;
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2008-07-31 15:30:57 +00:00
|
|
|
UpdateScreenFromSheet( this );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-07-31 15:30:57 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/**************************************************************/
|
2008-07-31 15:30:57 +00:00
|
|
|
static bool UpdateScreenFromSheet( WinEDA_SchematicFrame* frame )
|
2007-06-05 12:10:51 +00:00
|
|
|
/**************************************************************/
|
|
|
|
|
|
|
|
/* Recherche et installe de l'ecran relatif au sheet symbole Sheet.
|
2008-07-31 15:30:57 +00:00
|
|
|
* Si Sheet == NULL installation de l'ecran de base ( Root ).
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
{
|
2008-07-31 15:30:57 +00:00
|
|
|
SCH_SCREEN* NewScreen;
|
|
|
|
|
|
|
|
NewScreen = frame->m_CurrentSheet->LastScreen();
|
|
|
|
if( !NewScreen )
|
|
|
|
{
|
|
|
|
DisplayError( frame, wxT( "Screen not found for this sheet" ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reinit des parametres d'affichage du nouvel ecran
|
|
|
|
// assumes m_CurrentSheet has already been updated.
|
2009-10-14 19:43:31 +00:00
|
|
|
frame->ClearMsgPanel();
|
2009-01-29 14:26:20 +00:00
|
|
|
frame->DrawPanel->SetScrollbars( NewScreen->m_ZoomScalar,
|
|
|
|
NewScreen->m_ZoomScalar,
|
|
|
|
NewScreen->m_ScrollbarNumber.x,
|
|
|
|
NewScreen->m_ScrollbarNumber.y,
|
|
|
|
NewScreen->m_ScrollbarPos.x,
|
|
|
|
NewScreen->m_ScrollbarPos.y, TRUE );
|
2008-07-31 15:30:57 +00:00
|
|
|
|
|
|
|
//update the References
|
|
|
|
frame->m_CurrentSheet->UpdateAllScreenReferences();
|
2008-04-30 17:04:22 +00:00
|
|
|
frame->SetSheetNumberAndCount();
|
2008-07-31 15:30:57 +00:00
|
|
|
frame->DrawPanel->m_CanStartBlock = -1;
|
|
|
|
ActiveScreen = frame->m_CurrentSheet->LastScreen();
|
|
|
|
if( NewScreen->m_FirstRedraw )
|
|
|
|
{
|
|
|
|
NewScreen->m_FirstRedraw = FALSE;
|
|
|
|
frame->Zoom_Automatique( TRUE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frame->DrawPanel->MouseToCursorSchema();
|
|
|
|
}
|
2009-02-27 07:54:51 +00:00
|
|
|
|
|
|
|
frame->DrawPanel->Refresh();
|
2008-07-31 15:30:57 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|