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"
|
|
|
|
|
#include "program.h"
|
|
|
|
|
#include "libcmp.h"
|
|
|
|
|
#include "general.h"
|
|
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
2008-02-27 19:38:16 +00:00
|
|
|
|
#include "schframe.h"
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
#include "wx/image.h"
|
|
|
|
|
#include "wx/imaglist.h"
|
|
|
|
|
#include "wx/treectrl.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "../bitmaps/treesel.xpm"
|
|
|
|
|
#include "../bitmaps/treensel.xpm"
|
|
|
|
|
|
|
|
|
|
|
2008-02-28 19:27:25 +00:00
|
|
|
|
static bool UpdateScreenFromSheet(WinEDA_SchematicFrame * frame);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
ID_TREECTRL_HIERARCHY = 1600
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WinEDA_HierFrame;
|
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
/* Cette classe permet de memoriser la feuille (sheet) associ<63>e a l'item
|
2007-06-05 12:10:51 +00:00
|
|
|
|
pour l'arbre de hierarchie */
|
|
|
|
|
class TreeItemData: public wxTreeItemData
|
|
|
|
|
{
|
|
|
|
|
public:
|
2008-02-28 19:27:25 +00:00
|
|
|
|
DrawSheetPath m_SheetList;
|
|
|
|
|
TreeItemData(DrawSheetPath sheet) :wxTreeItemData()
|
2008-02-12 21:12:46 +00:00
|
|
|
|
{
|
|
|
|
|
m_SheetList = sheet;
|
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Classe de l'arbre de hierarchie */
|
|
|
|
|
class WinEDA_Tree : public wxTreeCtrl
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
WinEDA_HierFrame * m_Parent;
|
|
|
|
|
wxImageList *imageList;
|
|
|
|
|
|
|
|
|
|
public:
|
2007-09-13 11:55:46 +00:00
|
|
|
|
WinEDA_Tree() { }
|
2007-06-05 12:10:51 +00:00
|
|
|
|
WinEDA_Tree(WinEDA_HierFrame *parent);
|
|
|
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(WinEDA_Tree)
|
|
|
|
|
};
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(WinEDA_Tree, wxTreeCtrl)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WinEDA_Tree::WinEDA_Tree(WinEDA_HierFrame *parent) :
|
|
|
|
|
wxTreeCtrl( (wxWindow*)parent, ID_TREECTRL_HIERARCHY,
|
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
|
wxTR_HAS_BUTTONS, wxDefaultValidator, wxT("HierachyTreeCtrl"))
|
|
|
|
|
{
|
|
|
|
|
m_Parent = parent;
|
|
|
|
|
// Make an image list containing small icons
|
|
|
|
|
imageList = new wxImageList(16, 15, TRUE, 2);
|
|
|
|
|
|
|
|
|
|
imageList->Add(wxBitmap(tree_nosel_xpm));
|
|
|
|
|
imageList->Add(wxBitmap(tree_sel_xpm));
|
|
|
|
|
|
|
|
|
|
AssignImageList(imageList);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Classe definissant la fenetre d'affichage de la hierarchie */
|
|
|
|
|
class WinEDA_HierFrame : public wxDialog
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
WinEDA_SchematicFrame * m_Parent;
|
|
|
|
|
WinEDA_Tree * m_Tree;
|
2008-02-12 21:12:46 +00:00
|
|
|
|
int m_nbsheets;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
wxDC * m_DC;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
wxSize m_TreeSize; // Taille de l'arbre de hierarchie
|
|
|
|
|
int maxposx;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
WinEDA_HierFrame(WinEDA_SchematicFrame *parent, wxDC * DC, const wxPoint& pos);
|
2008-02-28 19:27:25 +00:00
|
|
|
|
void BuildSheetList(DrawSheetPath * list, wxTreeItemId * previousmenu);
|
2007-09-13 11:55:46 +00:00
|
|
|
|
~WinEDA_HierFrame();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
void OnSelect(wxTreeEvent& event);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(WinEDA_HierFrame, wxDialog)
|
|
|
|
|
EVT_TREE_ITEM_ACTIVATED(ID_TREECTRL_HIERARCHY,
|
|
|
|
|
WinEDA_HierFrame::OnSelect)
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
void WinEDA_SchematicFrame::InstallHierarchyFrame(wxDC * DC, wxPoint &pos)
|
|
|
|
|
/*************************************************************************/
|
|
|
|
|
{
|
|
|
|
|
WinEDA_HierFrame * treeframe = new WinEDA_HierFrame(this, DC, pos);
|
|
|
|
|
treeframe->ShowModal(); treeframe->Destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WinEDA_HierFrame::WinEDA_HierFrame(WinEDA_SchematicFrame *parent, wxDC * DC,
|
|
|
|
|
const wxPoint& pos):
|
|
|
|
|
wxDialog(parent, -1, _("Navigator"), pos, wxSize(110,50),
|
|
|
|
|
DIALOG_STYLE)
|
|
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
|
wxTreeItemId cellule;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
m_Parent = parent;
|
|
|
|
|
m_DC = DC;
|
|
|
|
|
m_Tree = new WinEDA_Tree(this);
|
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
m_nbsheets = 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
cellule = m_Tree->AddRoot(_("Root"), 0, 1);
|
|
|
|
|
m_Tree->SetItemBold(cellule, TRUE);
|
2008-02-28 19:27:25 +00:00
|
|
|
|
DrawSheetPath list;
|
2008-02-12 21:12:46 +00:00
|
|
|
|
list.Push(g_RootSheet);
|
|
|
|
|
m_Tree->SetItemData( cellule, new TreeItemData(list) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
wxRect itemrect;
|
|
|
|
|
#ifdef __UNIX__
|
|
|
|
|
itemrect.SetWidth(100);
|
|
|
|
|
itemrect.SetHeight(20);
|
|
|
|
|
#else
|
|
|
|
|
m_Tree->GetBoundingRect(cellule,itemrect);
|
|
|
|
|
#endif
|
|
|
|
|
m_TreeSize.x = itemrect.GetWidth() + 10;
|
|
|
|
|
m_TreeSize.y = 20;
|
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
if( m_Parent->GetSheet()->Last() == g_RootSheet )
|
|
|
|
|
m_Tree->SelectItem(cellule); //root.
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
maxposx = 15;
|
2008-02-12 21:12:46 +00:00
|
|
|
|
BuildSheetList(&list, &cellule);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
if ( m_nbsheets > 1)
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
|
|
|
|
m_Tree->Expand(cellule);
|
|
|
|
|
|
|
|
|
|
// Reajustage de la taille de la frame a une valeur optimale
|
2008-02-12 21:12:46 +00:00
|
|
|
|
m_TreeSize.y += m_nbsheets * itemrect.GetHeight();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
m_TreeSize.x = MIN(m_TreeSize.x, 250);
|
|
|
|
|
m_TreeSize.y = MIN( m_TreeSize.y, 350);
|
|
|
|
|
SetClientSize(m_TreeSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
WinEDA_HierFrame::~WinEDA_HierFrame()
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
void WinEDA_HierFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
{
|
|
|
|
|
// true is to force the frame to close
|
|
|
|
|
Close(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
2008-02-28 19:27:25 +00:00
|
|
|
|
void WinEDA_HierFrame::BuildSheetList(DrawSheetPath* list,
|
2007-06-05 12:10:51 +00:00
|
|
|
|
wxTreeItemId * previousmenu)
|
|
|
|
|
/********************************************************************/
|
|
|
|
|
/* Routine de creation de l'arbre de navigation dans la hierarchy
|
|
|
|
|
schematique
|
|
|
|
|
Cette routine est Reentrante !
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
wxTreeItemId menu;
|
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
if( m_nbsheets > NB_MAX_SHEET ){
|
|
|
|
|
if( m_nbsheets == (NB_MAX_SHEET + 1) ){
|
2007-06-05 12:10:51 +00:00
|
|
|
|
wxString msg;
|
|
|
|
|
msg << wxT("BuildSheetList: Error: nbsheets > ") << NB_MAX_SHEET;
|
|
|
|
|
DisplayError(this, msg);
|
2008-02-12 21:12:46 +00:00
|
|
|
|
m_nbsheets++;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
maxposx += m_Tree->GetIndent();
|
|
|
|
|
EDA_BaseStruct* bs = list->LastDrawList();
|
|
|
|
|
while(bs && m_nbsheets < NB_MAX_SHEET){
|
|
|
|
|
if(bs->Type() == DRAW_SHEET_STRUCT_TYPE){
|
|
|
|
|
DrawSheetStruct* ss = (DrawSheetStruct*)bs;
|
|
|
|
|
m_nbsheets++;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
menu = m_Tree->AppendItem(*previousmenu,
|
2008-02-12 21:12:46 +00:00
|
|
|
|
ss->m_SheetName, 0 , 1 );
|
|
|
|
|
list->Push(ss);
|
|
|
|
|
m_Tree->SetItemData( menu, new TreeItemData(*list) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
int ll = m_Tree->GetItemText(menu).Len();
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
|
ll *= 9; // * char width
|
|
|
|
|
#else
|
|
|
|
|
ll *= 12; // * char width
|
|
|
|
|
#endif
|
|
|
|
|
ll += maxposx + 20;
|
|
|
|
|
m_TreeSize.x = MAX(m_TreeSize.x, ll);
|
|
|
|
|
m_TreeSize.y += 1;
|
2008-02-12 21:12:46 +00:00
|
|
|
|
if ( *list == *(m_Parent->GetSheet()) ){
|
2007-06-05 12:10:51 +00:00
|
|
|
|
m_Tree->EnsureVisible(menu);
|
|
|
|
|
m_Tree->SelectItem(menu);
|
|
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
|
BuildSheetList(list, &menu);
|
|
|
|
|
m_Tree->Expand(menu);
|
|
|
|
|
list->Pop();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
|
bs = bs->Pnext;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
maxposx -= m_Tree->GetIndent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************/
|
|
|
|
|
void WinEDA_HierFrame::OnSelect(wxTreeEvent& event)
|
|
|
|
|
/***************************************************/
|
2008-02-28 19:27:25 +00:00
|
|
|
|
/* Called on a double-click on a tree item:
|
|
|
|
|
Open the selected sheet, and display the corresponding screen
|
2007-06-05 12:10:51 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
wxTreeItemId ItemSel = m_Tree->GetSelection();
|
2008-02-28 19:27:25 +00:00
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
*(m_Parent->m_CurrentSheet) =
|
|
|
|
|
((TreeItemData*)(m_Tree->GetItemData(ItemSel)))->m_SheetList;
|
|
|
|
|
wxString path = m_Parent->m_CurrentSheet->PathHumanReadable();
|
|
|
|
|
printf("changing to sheet %s\n", CONV_TO_UTF8(path));
|
|
|
|
|
UpdateScreenFromSheet(m_Parent);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
Close(TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************/
|
2008-02-12 21:12:46 +00:00
|
|
|
|
void WinEDA_SchematicFrame::InstallPreviousSheet()
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/******************************************************/
|
|
|
|
|
/* Set the current screen to display the parent sheet of the current displayed sheet
|
|
|
|
|
*/
|
|
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
|
if( m_CurrentSheet->Last() == g_RootSheet ) return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
g_ItemToRepeat = NULL;
|
|
|
|
|
MsgPanel->EraseMsgBox();
|
2008-02-12 21:12:46 +00:00
|
|
|
|
//make a copy for testing purposes.
|
2008-02-28 19:27:25 +00:00
|
|
|
|
DrawSheetPath listtemp = *m_CurrentSheet;
|
2008-02-12 21:12:46 +00:00
|
|
|
|
listtemp.Pop();
|
|
|
|
|
if ( listtemp.LastScreen() == NULL ){
|
|
|
|
|
DisplayError( this, wxT("InstallPreviousScreen() Error: Sheet not found"));
|
2007-06-05 12:10:51 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
|
m_CurrentSheet->Pop();
|
|
|
|
|
UpdateScreenFromSheet(this);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
void WinEDA_SchematicFrame::InstallNextScreen(DrawSheetStruct * Sheet)
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
/* Routine d'installation de l'ecran correspondant au symbole Sheet pointe
|
|
|
|
|
par la souris
|
2008-02-12 21:12:46 +00:00
|
|
|
|
have to be careful here because the DrawSheetStructs within the EEDrawList
|
2008-02-26 19:19:54 +00:00
|
|
|
|
don't actually have a valid m_AssociatedScreen (on purpose -- you need the m_SubSheet hierarchy
|
2008-02-12 21:12:46 +00:00
|
|
|
|
to maintain path info (well, this is but one way to maintain path info..)
|
2007-06-05 12:10:51 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
if( Sheet == NULL)
|
|
|
|
|
{
|
|
|
|
|
DisplayError(this,wxT("InstallNextScreen() error")); return;
|
|
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
|
m_CurrentSheet->Push(Sheet);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
g_ItemToRepeat = NULL;
|
|
|
|
|
MsgPanel->EraseMsgBox();
|
2008-02-12 21:12:46 +00:00
|
|
|
|
UpdateScreenFromSheet(this);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************************/
|
2008-02-28 19:27:25 +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.
|
|
|
|
|
Si Sheet == NULL installation de l'ecran de base ( Root ).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
|
SCH_SCREEN * NewScreen;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
NewScreen = frame->m_CurrentSheet->LastScreen();
|
|
|
|
|
if(!NewScreen)
|
2008-02-28 19:27:25 +00:00
|
|
|
|
{
|
|
|
|
|
DisplayError(frame, wxT("Screen not found for this sheet"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
|
|
|
|
|
|
// Reinit des parametres d'affichage du nouvel ecran
|
|
|
|
|
// assumes m_CurrentSheet has already been updated.
|
|
|
|
|
frame->MsgPanel->EraseMsgBox();
|
|
|
|
|
frame->DrawPanel->SetScrollbars( frame->DrawPanel->m_Scroll_unit,
|
|
|
|
|
frame->DrawPanel->m_Scroll_unit,
|
|
|
|
|
NewScreen->m_ScrollbarNumber.x,
|
|
|
|
|
NewScreen->m_ScrollbarNumber.y,
|
|
|
|
|
NewScreen->m_ScrollbarPos.x,
|
|
|
|
|
NewScreen->m_ScrollbarPos.y,TRUE);
|
|
|
|
|
|
|
|
|
|
//update the References
|
|
|
|
|
frame->m_CurrentSheet->UpdateAllScreenReferences();
|
|
|
|
|
frame->DrawPanel->m_CanStartBlock = -1;
|
|
|
|
|
if ( NewScreen->m_FirstRedraw ){
|
|
|
|
|
NewScreen->m_FirstRedraw = FALSE;
|
|
|
|
|
frame->Zoom_Automatique(TRUE);
|
|
|
|
|
}else{
|
|
|
|
|
frame->ReDrawPanel();
|
|
|
|
|
frame->DrawPanel->MouseToCursorSchema();
|
|
|
|
|
}
|
|
|
|
|
ActiveScreen = frame->m_CurrentSheet->LastScreen();
|
2008-02-28 19:27:25 +00:00
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|