diff --git a/GeomDBTree.cpp b/GeomDBTree.cpp new file mode 100644 index 0000000..daba5d5 --- /dev/null +++ b/GeomDBTree.cpp @@ -0,0 +1,266 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2014 +//---------------------------------------------------------------------------- +// File : GeomDbTree.cpp Data : 29.01.14 Versione : 1.5b8 +// Contenuto : Metodi del dialogo principale per albero di GeomDB. +// +// +// +// Modifiche : 27.02.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "TestEGrDlg.h" +#include "resource.h" +#include "/EgtDev/Include/EgtPointerOwner.h" +#include "/EgtDev/Include/EGnStringConverter.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGkGdbIterator.h" +#include "/EgtDev/Include/EGkCurveLine.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +//--------------------------- Constants -------------------------------------- +// indici icone per Tree +enum { ICO_NOGEO = 0, ICO_GROUP, ICO_VECTOR, ICO_POINT, ICO_FRAME, + ICO_LINE, ICO_ARC, ICO_CBEZIER, ICO_CCOMPO} ; + + +//---------------------------------------------------------------------------- +bool +CTestEGrDlg::PrepareTree( void) +{ + // collego l'oggetto al control + m_Tree.SubclassDlgItem( IDC_TREE, this) ; + + // carico le immagini + m_pImgList = new CImageList ; + if ( m_pImgList == nullptr) + return false ; + m_pImgList->Create( 16, 16, ILC_COLOR, 10, 4) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_NOGEO)) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_GROUP)) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_VECTOR)) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_POINT)) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_FRAME)) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_LINE)) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_ARC)) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_CBEZIER)) ; + m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_CCOMPO)) ; + m_Tree.SetImageList( m_pImgList, TVSIL_NORMAL) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +CTestEGrDlg::LoadTree( void) +{ + // svuoto l'albero + m_Tree.DeleteAllItems() ; + OutData( "") ; + + // disabilito aggiornamento + m_Tree.SetRedraw( FALSE) ; + + // ciclo su GeomDB + InsertGroupOnTree( GDB_ID_ROOT, TVI_ROOT) ; + + // riabilito aggiornamento + m_Tree.SetRedraw( TRUE) ; + m_Tree.Invalidate() ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +CTestEGrDlg::InsertGroupOnTree( int nId, HTREEITEM hParent) +{ + // inserisco il gruppo nell'albero (se non è la radice) + HTREEITEM hGroup ; + if ( nId == GDB_ID_ROOT) + hGroup = hParent ; + else { + string sGroup = "Group " + ToString( nId) ; + hGroup = m_Tree.InsertItem( stringtoW( sGroup), ICO_GROUP, ICO_GROUP, hParent) ; + if ( hGroup == nullptr || m_Tree.SetItemData( hGroup, nId) == 0) + return false ; + } + + // creo un iteratore + PtrOwner pIter( CreateGdbIterator()) ; + if ( ! ::IsValid( pIter)) + return false ; + // scandisco il gruppo + pIter->SetGDB( m_pGeomDB) ; + bool bNext = pIter->GoToFirstInGroup( nId) ; + while ( bNext) { + // leggo il tipo di nodo + int nGdbType = pIter->GetGdbType() ; + // se gruppo + if ( nGdbType == GDB_GROUP) { + // lo inserisco nell'albero + if ( ! InsertGroupOnTree( pIter->GetId(), hGroup)) + return false ; + } + // se oggetto geometrico + else if ( nGdbType == GDB_GEO) { + // lo inserisco nell'albero + if ( ! InsertGeoObjOnTree( pIter->GetId(), pIter->GetGeoObj(), hGroup)) + return false ; + } + // passo al successivo + bNext = pIter->GoToNext() ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +CTestEGrDlg::InsertGeoObjOnTree( int nId, IGeoObj* pGeoObj, HTREEITEM hParent) +{ + int nImage ; + string sName ; + + if ( pGeoObj != nullptr) { + sName = pGeoObj->GetTitle() + " " + ToString( nId) ; + nImage = GetGeoObjImage( pGeoObj->GetType()) ; + } + else { + nImage = ICO_NOGEO ; + sName = "Null " + ToString( nId) ; + } + + HTREEITEM hItem = m_Tree.InsertItem( stringtoW( sName), nImage, nImage, hParent) ; + return ( hItem != nullptr && m_Tree.SetItemData( hItem, nId) != 0) ; +} + +//---------------------------------------------------------------------------- +int +CTestEGrDlg::GetGeoObjImage( int nType) +{ + switch ( nType) { + case GEO_VECT3D : return ICO_VECTOR ; + case GEO_PNT3D : return ICO_POINT ; + case GEO_FRAME3D : return ICO_FRAME ; + case CRV_LINE : return ICO_LINE ; + case CRV_ARC : return ICO_ARC ; + case CRV_BEZ : return ICO_CBEZIER ; + case CRV_COMPO : return ICO_CCOMPO ; + } + return ICO_NOGEO ; +} + +//---------------------------------------------------------------------------- +void +CTestEGrDlg::OnTreeSelChanged( NMHDR* pNMHDR, LRESULT* pResult) +{ + // assegno il risultato + *pResult = 0 ; + // recupero l'Id dell'oggetto selezionato + LPNMTREEVIEW pNMTreeView = reinterpret_cast( pNMHDR) ; + HTREEITEM hItem = pNMTreeView->itemNew.hItem ; + int nId = GDB_ID_NULL ; + if ( hItem != nullptr) + nId = int( m_Tree.GetItemData( hItem)) ; + // in base al tipo di nodo + switch ( m_pGeomDB->GetGdbType( nId)) { + case GDB_GROUP : + OutGroupData( nId) ; + break ; + case GDB_GEO : + OutGeoObjData( nId) ; + break ; + } +} + +//---------------------------------------------------------------------------- +void +CTestEGrDlg::OutGroupData( int nId) +{ + string sOut = "Group " + ToString( nId) + "\r\n" ; + // numero di nodi (figli) + int nNodes = m_pGeomDB->GetGroupNodes( nId) ; + sOut += "Nodes : " + ToString( nNodes) + "\r\n" ; + // riferimento in globale + Frame3d frGlob ; + if ( m_pGeomDB->GetGroupGlobFrame( nId, frGlob)) { + sOut += "GlobFrame :\r\n" ; + sOut += " O(" + ToString( frGlob.Orig()) + ")\r\n" ; + sOut += " X(" + ToString( frGlob.VersX()) + ")\r\n" ; + sOut += " Y(" + ToString( frGlob.VersY()) + ")\r\n" ; + sOut += " Z(" + ToString( frGlob.VersZ()) + ")\r\n" ; + } + // ingombro in globale + BBox3d b3Glob ; + if ( m_pGeomDB->GetGlobalBBox( nId, b3Glob)) { + sOut += "GlobBBox :\r\n" ; + sOut += " m(" + ToString( b3Glob.GetMin()) + ")\r\n" ; + sOut += " M(" + ToString( b3Glob.GetMax()) + ")\r\n" ; + } + + OutData( sOut) ; +} + +//---------------------------------------------------------------------------- +void +CTestEGrDlg::OutGeoObjData( int nId) +{ + // recupero l'oggetto geometrico + const IGeoObj* pGObj ; + if ( ( pGObj = m_pGeomDB->GetGeoObj( nId)) == nullptr) + return ; + string sOut ; + // preparo l'intestazione + sOut += pGObj->GetTitle() + " " + ToString( nId) + "\r\n" ; + //DumpCaptionData( pGObj->GetType(), nId, sOut) ; + // preparo i dati + pGObj->Dump( sOut, "\r\n") ; + // emissione + OutData( sOut) ; +} + +//---------------------------------------------------------------------------- +void +CTestEGrDlg::DumpCaptionData( int nType, int nId, string& sOut) +{ + // a seconda del tipo + switch ( nType) { + case GEO_VECT3D : + sOut += "Vector " ; + break ; + case GEO_PNT3D : + sOut += "Point " ; + break ; + case GEO_FRAME3D : + sOut += "Frame " ; + break ; + case CRV_LINE : + sOut += "Line " ; + break ; + case CRV_ARC : + sOut += "Arc " ; + break ; + case CRV_BEZ : + sOut += "CBezier " ; + break ; + case CRV_COMPO : + sOut += "CComposite " ; + break ; + default : + sOut += "NULL " ; + break ; + } + + sOut += ToString( nId) + "\r\n" ; +} \ No newline at end of file diff --git a/TestEGr.rc b/TestEGr.rc index 2e0e535..4063648 100644 Binary files a/TestEGr.rc and b/TestEGr.rc differ diff --git a/TestEGr.vcxproj b/TestEGr.vcxproj index 595504c..63ae67d 100644 --- a/TestEGr.vcxproj +++ b/TestEGr.vcxproj @@ -197,18 +197,30 @@ + + + + + + + + + + + + @@ -219,6 +231,7 @@ + Create Create diff --git a/TestEGr.vcxproj.filters b/TestEGr.vcxproj.filters index 138b45f..95bba3d 100644 --- a/TestEGr.vcxproj.filters +++ b/TestEGr.vcxproj.filters @@ -36,6 +36,36 @@ File di risorse + + File di risorse + + + File di risorse + + + File di risorse + + + File di risorse + + + File di risorse + + + File di risorse + + + File di risorse + + + File di risorse + + + File di risorse + + + File di risorse + @@ -71,6 +101,12 @@ File di intestazione + + File di intestazione + + + File di intestazione + @@ -88,6 +124,9 @@ File di origine + + File di origine + diff --git a/TestEGrDlg.cpp b/TestEGrDlg.cpp index f538c50..fe1d6f1 100644 --- a/TestEGrDlg.cpp +++ b/TestEGrDlg.cpp @@ -21,8 +21,7 @@ #include "/EgtDev/Include/EgtILogger.h" #include "/EgtDev/Include/EgtPerfCounter.h" #include "/EgtDev/Include/EgtPointerOwner.h" -#include "/EgtDev/Include/EgnCmdParser.h" -#include "/EgtDev/Include/EGkDllMain.h" +#include "/EgtDev/Include/EGnCmdParser.h" #include "/EgtDev/Include/EGkGeomDB.h" #include "/EgtDev/Include/EGkGdbExecutor.h" #include "/EgtDev/Include/EGrScene.h" @@ -85,14 +84,22 @@ CTestEGrDlg::CTestEGrDlg( ILogger* pLogger, CWnd* pParent) m_hIcon = AfxGetApp()->LoadIcon( IDR_MAINFRAME) ; // memorizzo il puntatore al logger m_pLogger = pLogger ; + // inizializzazioni varie + m_pGeomDB = nullptr ; + m_pImgList = nullptr ; } //---------------------------------------------------------------------------- CTestEGrDlg::~CTestEGrDlg( void) { + // cancello GeomDB if ( m_pGeomDB != nullptr) delete m_pGeomDB ; m_pGeomDB = nullptr ; + // cancello ImgList + if ( m_pImgList != nullptr) + delete m_pImgList ; + m_pImgList = nullptr ; } //---------------------------------------------------------------------------- @@ -108,6 +115,7 @@ BEGIN_MESSAGE_MAP( CTestEGrDlg, CDialog) ON_CONTROL_RANGE( BN_CLICKED, IDC_ZOOM_ALL, IDC_ZOOM_OUT, OnZoom) ON_CONTROL_RANGE( BN_CLICKED, IDC_VIEW_TOP, IDC_VIEW_ISO, OnView) ON_BN_CLICKED( IDC_CLOSE, OnClose) + ON_NOTIFY( TVN_SELCHANGED, IDC_TREE, OnTreeSelChanged) END_MESSAGE_MAP() //---------------------------------------------------------------------------- @@ -149,7 +157,8 @@ CTestEGrDlg::OnInitDialog( void) CRect rectView ; GetDlgItem( IDC_SCENE)->GetWindowRect( rectView) ; ScreenToClient( &rectView) ; - m_nSideBarW = rectClient.right - rectView.right ; + m_nLeftBarW = rectView.left - rectClient.left ; + m_nRightBarW = rectClient.right - rectView.right ; m_nBottomBarH = rectClient.bottom - rectView.bottom ; // creo il DB geometrico @@ -204,6 +213,9 @@ CTestEGrDlg::OnInitDialog( void) if ( GetIniWinPlace( "General", "WinPlace", winPlace)) SetWindowPlacement( &winPlace) ; + // preparo il Tree + PrepareTree() ; + return TRUE ; // return TRUE unless you set the focus to a control } @@ -358,12 +370,22 @@ CTestEGrDlg::OnSize( UINT nType, int cx, int cy) MoveDlgItem( IDC_VIEW_LEFT, IP_TR, cx, cy) ; MoveDlgItem( IDC_VIEW_RIGHT, IP_TR, cx, cy) ; MoveDlgItem( IDC_VIEW_ISO, IP_TR, cx, cy) ; - MoveDlgItem( IDC_CLOSE, IP_TR, cx, cy) ; + MoveDlgItem( IDC_CLOSE, IP_BR, cx, cy) ; + // spostamento e adattamento tree e associati + MoveDlgItem( IDC_TREE, IP_TL, cx, cy) ; + MoveDlgItem( IDC_DATA, IP_TL, cx, cy) ; + CRect rectData ; + if ( GetWindowRect( GetDlgItem( IDC_DATA), rectData)) + ReshapeDlgItem( IDC_DATA, IR_H, 0, cy - rectData.top - m_nBottomBarH) ; + // spostamento e adattamento barre sotto MoveDlgItem( IDC_INFO, IP_BL, cx, cy) ; - ReshapeDlgItem( IDC_INFO, IR_W, cx - m_nSideBarW, 0) ; + ReshapeDlgItem( IDC_INFO, IR_W, cx - m_nLeftBarW - m_nRightBarW, 0) ; MoveDlgItem( IDC_COORD, IP_BR, cx, cy) ; - // adattamento finestra - m_View.Reshape( 0, 0, cx - m_nSideBarW, cy - m_nBottomBarH) ; + // adattamento vista della scena + CRect rectView ; + if ( GetWindowRect( &m_View, rectView)) + m_View.Reshape( m_nLeftBarW, rectView.top, + cx - m_nLeftBarW - m_nRightBarW, cy - m_nBottomBarH - rectView.top) ; // salvo la nuova dimensione m_nPrevCx = cx ; m_nPrevCy = cy ; @@ -440,6 +462,18 @@ CTestEGrDlg::ReshapeDlgItem( int nID, int nFlag, int nW, int nH) return ( pBtn->SetWindowPos( NULL, 0, 0, nWu, nHu, SWP_NOMOVE | SWP_NOZORDER) != 0) ; } +//---------------------------------------------------------------------------- +bool +CTestEGrDlg::GetWindowRect( CWnd* pWnd, CRect& rect) +{ + if ( pWnd == nullptr || ! ::IsWindow( pWnd->m_hWnd)) + return false ; + + pWnd->GetWindowRect( rect) ; + ScreenToClient( &rect) ; + return true ; +} + //---------------------------------------------------------------------------- void CTestEGrDlg::OutInfo( const string& sOut, bool bLog) @@ -452,6 +486,18 @@ CTestEGrDlg::OutInfo( const string& sOut, bool bLog) LOG_INFO( m_pLogger, sOut.c_str()) } +//---------------------------------------------------------------------------- +void +CTestEGrDlg::OutData( const string& sOut, bool bLog) +{ + CWnd* pWnd = GetDlgItem( IDC_DATA) ; + if ( pWnd != nullptr) + pWnd->SetWindowText( stringtoW( sOut)) ; + + if ( bLog) + LOG_INFO( m_pLogger, sOut.c_str()) +} + //---------------------------------------------------------------------------- void CTestEGrDlg::OnClose( void) @@ -482,6 +528,8 @@ CTestEGrDlg::OnFileNew( void) m_pGeomDB->Init() ; // visualizzo con zoom all m_View.Zoom( IDC_ZOOM_ALL) ; + // aggiorno l'albero delle entità + LoadTree() ; } //---------------------------------------------------------------------------- @@ -537,6 +585,8 @@ CTestEGrDlg::OnFileOpen( void) string sOut = "First ZoomAll time = " + ToString( Counter.GetTime(), 2) + " ms" ; // emetto info ::OutInfo( sOut) ; + // aggiorno l'albero delle entità + LoadTree() ; } //---------------------------------------------------------------------------- @@ -602,6 +652,9 @@ CTestEGrDlg::OnFileExec( void) AfxMessageBox( L"Error on Parser.Run (look at Log file)", MB_ICONSTOP|MB_OK) ; return ; } + + // aggiorno l'albero delle entità + LoadTree() ; } //---------------------------------------------------------------------------- diff --git a/TestEGrDlg.h b/TestEGrDlg.h index 74b837d..2d40341 100644 --- a/TestEGrDlg.h +++ b/TestEGrDlg.h @@ -16,9 +16,9 @@ #include "TestEgrView.h" #include "/EgtDev/Include/EGkColor.h" - class ILogger ; class IGeomDB ; +class IGeoObj ; //---------------------------------------------------------------------------- class CTestEGrDlg : public CDialog @@ -43,6 +43,7 @@ class CTestEGrDlg : public CDialog afx_msg void OnZoom( UINT nID) ; afx_msg void OnView( UINT nID) ; afx_msg void OnClose( void) ; + afx_msg void OnTreeSelChanged(NMHDR *pNMHDR, LRESULT *pResult) ; private : enum ItemPos { IP_TR = 1, IP_TL, IP_BR, IP_BL} ; @@ -52,18 +53,31 @@ class CTestEGrDlg : public CDialog bool GetIniBackColor( const char* szSection, const char* szKey, Color& colBack) ; bool GetIniZoomWinAttrib( const char* szSection, const char* szKey, bool& bOutline, Color& colRect) ; - bool GetIniWinPlace( const char* szSection, const char* szKey, WINDOWPLACEMENT& winPlace) ; + bool GetIniWinPlace( const char* szSection, const char* szKey, WINDOWPLACEMENT& winPlace) ; bool MoveDlgItem( int nID, int nPos, int cx, int cy) ; bool ReshapeDlgItem( int nID, int nFlag, int nW, int nH) ; + bool GetWindowRect( CWnd* pWnd, CRect& rect) ; + void OutData( const std::string& sOut, bool bLog = false) ; + bool PrepareTree( void) ; + bool LoadTree( void) ; + bool InsertGroupOnTree( int nId, HTREEITEM hParent) ; + bool InsertGeoObjOnTree( int nId, IGeoObj* pGeoObj, HTREEITEM hParent) ; + int GetGeoObjImage( int nType) ; + void OutGroupData( int nId) ; + void OutGeoObjData( int nId) ; + void DumpCaptionData( int nType, int nId, std::string& sOut) ; private : IGeomDB* m_pGeomDB ; ILogger* m_pLogger ; TestEgrView m_View ; HICON m_hIcon ; + CTreeCtrl m_Tree ; + CImageList* m_pImgList ; int m_nPrevCx ; int m_nPrevCy ; - int m_nSideBarW ; + int m_nLeftBarW ; + int m_nRightBarW ; int m_nBottomBarH ; DECLARE_MESSAGE_MAP() diff --git a/res/Arc.ico b/res/Arc.ico new file mode 100644 index 0000000..832587c Binary files /dev/null and b/res/Arc.ico differ diff --git a/res/CBezier.ico b/res/CBezier.ico new file mode 100644 index 0000000..d15a834 Binary files /dev/null and b/res/CBezier.ico differ diff --git a/res/CCompo.ico b/res/CCompo.ico new file mode 100644 index 0000000..2f9070c Binary files /dev/null and b/res/CCompo.ico differ diff --git a/res/Frame.ico b/res/Frame.ico new file mode 100644 index 0000000..20ebd0c Binary files /dev/null and b/res/Frame.ico differ diff --git a/res/Group.ico b/res/Group.ico new file mode 100644 index 0000000..79a6648 Binary files /dev/null and b/res/Group.ico differ diff --git a/res/Line.ico b/res/Line.ico new file mode 100644 index 0000000..dacfe48 Binary files /dev/null and b/res/Line.ico differ diff --git a/res/NoGeo.ico b/res/NoGeo.ico new file mode 100644 index 0000000..9caefc1 Binary files /dev/null and b/res/NoGeo.ico differ diff --git a/res/Point.ico b/res/Point.ico new file mode 100644 index 0000000..eb41161 Binary files /dev/null and b/res/Point.ico differ diff --git a/res/Vector.ico b/res/Vector.ico new file mode 100644 index 0000000..6133cb7 Binary files /dev/null and b/res/Vector.ico differ diff --git a/resource.h b/resource.h index 41bbf22..5a12648 100644 Binary files a/resource.h and b/resource.h differ