TestEgr 1.5d6 :

- aggiunto import di DXF e STL
- aggiunto albero per materiali custom.
This commit is contained in:
Dario Sassi
2014-04-29 07:42:52 +00:00
parent ad9e09000c
commit 1945a5cff4
9 changed files with 274 additions and 55 deletions
+91 -34
View File
@@ -32,9 +32,11 @@ static char THIS_FILE[] = __FILE__;
//--------------------------- 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, ICO_STRIMESH} ;
enum { ICO_MATERS = 0, ICO_ONEMATER, ICO_NOGEO, ICO_GROUP, ICO_VECTOR, ICO_POINT,
ICO_FRAME, ICO_LINE, ICO_ARC, ICO_CBEZIER, ICO_CCOMPO, ICO_STRIMESH} ;
// costanti per materiali custom/ geometrie
static const int GEOM = 0x0000000 ;
static const int CMAT = 0x1000000 ;
//----------------------------------------------------------------------------
bool
@@ -48,6 +50,8 @@ CTestEGrDlg::PrepareTree( void)
if ( m_pImgList == nullptr)
return false ;
m_pImgList->Create( 16, 16, ILC_COLOR, 10, 4) ;
m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_MATERS)) ;
m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_ONEMATER)) ;
m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_NOGEO)) ;
m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_GROUP)) ;
m_pImgList->Add( AfxGetApp()->LoadIcon( IDI_VECTOR)) ;
@@ -68,7 +72,7 @@ bool
CTestEGrDlg::ClearTree( void)
{
// ripristino stato eventuale ultimo oggetto selezionato
RevertOldIdOnTree() ;
RevertOldIdInTree() ;
// svuoto l'albero
m_Tree.SelectItem( NULL) ;
@@ -88,8 +92,11 @@ CTestEGrDlg::LoadTree( void)
// disabilito aggiornamento
m_Tree.SetRedraw( FALSE) ;
// ciclo sui materiali custom
InsertCustomMaterialsInTree() ;
// ciclo su GeomDB
InsertGroupOnTree( GDB_ID_ROOT, TVI_ROOT) ;
InsertGroupInTree( GDB_ID_ROOT, TVI_ROOT) ;
// riabilito aggiornamento
m_Tree.SetRedraw( TRUE) ;
@@ -100,7 +107,33 @@ CTestEGrDlg::LoadTree( void)
//----------------------------------------------------------------------------
bool
CTestEGrDlg::InsertGroupOnTree( int nId, HTREEITEM hParent)
CTestEGrDlg::InsertCustomMaterialsInTree( void)
{
// inserisco la radice dei materiali custom
HTREEITEM hMaters ;
hMaters = m_Tree.InsertItem( L"Custom Materials", ICO_MATERS, ICO_MATERS, TVI_ROOT) ;
if ( hMaters == nullptr || m_Tree.SetItemData( hMaters, CMAT | 0) == 0)
return false ;
// inserisco i materiali custom
for ( int i = 1 ; i <= m_pGeomDB->GetMaxMaterialId() ; ++i) {
bool bCustom ;
if ( m_pGeomDB->IsCustomMaterial( i, bCustom) && bCustom) {
string sName ;
m_pGeomDB->GetMaterialName( i, sName) ;
HTREEITEM hOneMater ;
hOneMater = m_Tree.InsertItem( stringtoW( sName), ICO_ONEMATER, ICO_ONEMATER, hMaters) ;
if ( hOneMater == nullptr || m_Tree.SetItemData( hOneMater, CMAT | i) == 0)
return false ;
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
CTestEGrDlg::InsertGroupInTree( int nId, HTREEITEM hParent)
{
// inserisco il gruppo nell'albero (se non è la radice)
string sGroup ;
@@ -139,13 +172,13 @@ CTestEGrDlg::InsertGroupOnTree( int nId, HTREEITEM hParent)
// se gruppo
if ( nGdbType == GDB_TY_GROUP) {
// lo inserisco nell'albero
if ( ! InsertGroupOnTree( pIter->GetId(), hGroup))
if ( ! InsertGroupInTree( pIter->GetId(), hGroup))
return false ;
}
// se oggetto geometrico
else if ( nGdbType == GDB_TY_GEO) {
// lo inserisco nell'albero
if ( ! InsertGeoObjOnTree( pIter->GetId(), pIter->GetGeoObj(), hGroup))
if ( ! InsertGeoObjInTree( pIter->GetId(), pIter->GetGeoObj(), hGroup))
return false ;
}
// passo al successivo
@@ -157,7 +190,7 @@ CTestEGrDlg::InsertGroupOnTree( int nId, HTREEITEM hParent)
//----------------------------------------------------------------------------
bool
CTestEGrDlg::InsertGeoObjOnTree( int nId, IGeoObj* pGeoObj, HTREEITEM hParent)
CTestEGrDlg::InsertGeoObjInTree( int nId, IGeoObj* pGeoObj, HTREEITEM hParent)
{
int nImage ;
string sName ;
@@ -210,30 +243,35 @@ CTestEGrDlg::OnTreeSelChanged( NMHDR* pNMHDR, LRESULT* pResult)
if ( hItemNew == nullptr)
return ;
int nIdNew = int( m_Tree.GetItemData( hItemNew)) ;
if ( ! m_pGeomDB->ExistsObj( nIdNew))
return ;
// ripristino eventuale vecchio oggetto selezionato
RevertOldIdOnTree() ;
// visualizzo i dati dell'oggetto
switch ( m_pGeomDB->GetGdbType( nIdNew)) {
case GDB_TY_GROUP :
OutGroupData( nIdNew) ;
break ;
case GDB_TY_GEO :
OutGeoObjData( nIdNew) ;
break ;
RevertOldIdInTree() ;
// se colore custom
if ( ( nIdNew & CMAT) != 0) {
OutMaterialData( nIdNew & ~CMAT) ;
}
// se oggetto geometrico
if ( m_pGeomDB->ExistsObj( nIdNew)) {
// visualizzo i dati dell'oggetto
switch ( m_pGeomDB->GetGdbType( nIdNew)) {
case GDB_TY_GROUP :
OutGroupData( nIdNew) ;
break ;
case GDB_TY_GEO :
OutGeoObjData( nIdNew) ;
break ;
}
// permetto in ogni caso la visualizzazione dell'oggetto e lo marco
int nOldMode = GDB_MD_STD ;
m_pGeomDB->GetMode( nIdNew, nOldMode) ;
int nMode = (( nOldMode == GDB_MD_HIDDEN) ? GDB_MD_STD : nOldMode) ;
m_pGeomDB->SetMode( nIdNew, nMode) ;
int nOldStatus = GDB_ST_ON ;
m_pGeomDB->GetStatus( nIdNew, nOldStatus) ;
int nStat = (( nOldStatus == GDB_ST_OFF) ? GDB_ST_ON : nOldStatus) ;
m_pGeomDB->SetStatus( nIdNew, nStat) ;
m_pGeomDB->SetMark( nIdNew) ;
m_nOldIdTree = nIdNew ;
}
// permetto in ogni caso la visualizzazione dell'oggetto e lo marco
int nOldMode = GDB_MD_STD ;
m_pGeomDB->GetMode( nIdNew, nOldMode) ;
int nMode = (( nOldMode == GDB_MD_HIDDEN) ? GDB_MD_STD : nOldMode) ;
m_pGeomDB->SetMode( nIdNew, nMode) ;
int nOldStatus = GDB_ST_ON ;
m_pGeomDB->GetStatus( nIdNew, nOldStatus) ;
int nStat = (( nOldStatus == GDB_ST_OFF) ? GDB_ST_ON : nOldStatus) ;
m_pGeomDB->SetStatus( nIdNew, nStat) ;
m_pGeomDB->SetMark( nIdNew) ;
m_nOldIdTree = nIdNew ;
// aggiorno la visualizzazione
m_View.Redraw() ;
}
@@ -262,7 +300,7 @@ CTestEGrDlg::OnTreeDoubleClick( NMHDR* pNMHDR, LRESULT* pResult)
//----------------------------------------------------------------------------
bool
CTestEGrDlg::SelectIdOnTree( int nId, HTREEITEM hParent)
CTestEGrDlg::SelectIdInTree( int nId, HTREEITEM hParent)
{
HTREEITEM hItem ;
if ( hParent == nullptr)
@@ -278,7 +316,7 @@ CTestEGrDlg::SelectIdOnTree( int nId, HTREEITEM hParent)
}
// se ci sono dei figli, li analizzo
if ( m_Tree.ItemHasChildren( hItem)) {
if ( SelectIdOnTree( nId, hItem))
if ( SelectIdInTree( nId, hItem))
return true ;
}
// passo al successivo fratello
@@ -289,7 +327,7 @@ CTestEGrDlg::SelectIdOnTree( int nId, HTREEITEM hParent)
//----------------------------------------------------------------------------
int
CTestEGrDlg::RevertOldIdOnTree( void)
CTestEGrDlg::RevertOldIdInTree( void)
{
// verifiche sul DB geometrico
if ( m_pGeomDB == nullptr)
@@ -308,6 +346,25 @@ CTestEGrDlg::RevertOldIdOnTree( void)
return nOldId ;
}
//----------------------------------------------------------------------------
void
CTestEGrDlg::OutMaterialData( int nId)
{
string sName ;
Material matM ;
if ( m_pGeomDB->GetMaterialName( nId, sName) &&
m_pGeomDB->GetMaterialData( nId, matM)) {
string sOut = "Custom material " + sName + "\r\n" ;
sOut += " AmbCol = " + ToString( matM.GetAmbient()) + "\r\n" ;
sOut += " DiffCol = " + ToString( matM.GetDiffuse()) + "\r\n" ;
sOut += " SpecCol = " + ToString( matM.GetSpecular()) + "\r\n" ;
sOut += " Shininess = " + ToString( matM.GetShininess()) + "\r\n" ;
OutData( sOut) ;
}
else
OutData( "") ;
}
//----------------------------------------------------------------------------
void
CTestEGrDlg::OutGroupData( int nId)