//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : PhotoObj.cpp Data : 05.10.15 Versione : 1.6j1 // Contenuto : Oggetto custom Photo. // Viene attaccato ad una Region rettangolare. // // // Modifiche : 05.10.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "PhotoObj.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGrScene.h" #include "/EgtDev/Include/EGkGdbConst.h" #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EGnStringKeyVal.h" #include "/EgtDev/Include/EGnFileUtils.h" #undef GetClassName using namespace std ; //---------------------------------------------------------------------------- static const int NKEY = 6 ; static const string KEY_NAME = "N" ; static const string KEY_PATH = "P" ; static const string KEY_ORIG = "O" ; static const string KEY_CEN = "C" ; static const string KEY_DIMX = "DX" ; static const string KEY_DIMY = "DY" ; //---------------------------------------------------------------------------- USEROBJ_REGISTER( "EXePhoto", PhotoObj) ; //---------------------------------------------------------------------------- const string& PhotoObj::GetClassName( void) const { return USEROBJ_GETNAME( PhotoObj) ; } //---------------------------------------------------------------------------- PhotoObj* PhotoObj::Clone( void) const { // alloco oggetto PhotoObj* pPhoto = new(nothrow) PhotoObj ; // eseguo copia dei dati if ( pPhoto != nullptr) { try { } catch( ...) { delete pPhoto ; return nullptr ; } } // ritorno l'oggetto return pPhoto ; } //---------------------------------------------------------------------------- bool PhotoObj::Dump( string& sOut, bool bMM, const char* szNewLine) const { sOut += GetClassName() + szNewLine ; sOut += "Id=" + ToString( m_nOwnerId) + szNewLine ; sOut += "Name=" + m_sName + szNewLine ; sOut += "Path=" + m_sPath + szNewLine ; sOut += "Orig=" + ToString( m_ptOri) + szNewLine ; sOut += "Cen=" + ToString( m_ptCen) + szNewLine ; sOut += "Dim=" + ToString( m_dDimX) + "," + ToString( m_dDimY) + szNewLine ; return true ; } //---------------------------------------------------------------------------- bool PhotoObj::Save( STRVECTOR& vString) const { // recupero nome del progetto corrente string sFilePath ; ExeGetCurrFilePath( sFilePath) ; string sFileDir = GetDirectory( sFilePath) ; string sFileTitle = GetFileTitleEgt( sFilePath) ; // sostituzione degli eventuali riferimenti al direttorio e al nome del progetto nella path string sPath = m_sPath ; string sDir = GetDirectory( sPath) ; string sName = GetFileName( sPath) ; ReplaceString( sDir, sFileDir, SUB_PROJECT_DIR) ; ReplaceString( sName, sFileTitle, SUB_PROJECT_TITLE) ; sPath = sDir + "\\" + sName ; try { vString.insert( vString.begin(), NKEY, "") ; if ( ! SetVal( KEY_NAME, m_sName, vString[0])) return false ; if ( ! SetVal( KEY_PATH, const_cast( sPath), vString[1])) return false ; if ( ! SetVal( KEY_ORIG, m_ptOri, vString[2])) return false ; if ( ! SetVal( KEY_CEN, m_ptCen, vString[3])) return false ; if ( ! SetVal( KEY_DIMX, m_dDimX, vString[4])) return false ; if ( ! SetVal( KEY_DIMY, m_dDimY, vString[5])) return false ; } catch( ...) { return false ; } return true ; } //---------------------------------------------------------------------------- bool PhotoObj::Load( const STRVECTOR& vString, int nBaseGdbId) { if ( int( vString.size()) < NKEY) return false ; if ( ! GetVal( vString[0], KEY_NAME, m_sName)) return false ; if ( ! GetVal( vString[1], KEY_PATH, m_sPath)) return false ; if ( ! GetVal( vString[2], KEY_ORIG, m_ptOri)) return false ; if ( ! GetVal( vString[3], KEY_CEN, m_ptCen)) return false ; if ( ! GetVal( vString[4], KEY_DIMX, m_dDimX)) return false ; if ( ! GetVal( vString[5], KEY_DIMY, m_dDimY)) return false ; // verifico l'esistenza della texture if ( ExeExistsTexture( m_sName)) return true ; // recupero nome e direttorio del progetto corrente string sFilePath ; ExeGetCurrFilePath( sFilePath) ; string sFileDir = GetDirectory( sFilePath) ; string sFileTitle = GetFileTitleEgt( sFilePath) ; // sostituzione dell'eventuale riferimento al direttorio del progetto nella path ReplaceString( m_sPath, SUB_PROJECT_DIR, sFileDir) ; // sostituzione dell'eventuale riferimento al nome del progetto nella path ReplaceString( m_sPath, SUB_PROJECT_TITLE, sFileTitle) ; // carico la texture dalla path indicata if ( ExistsFile( m_sPath)) return ExeLoadTexture( m_sName, m_sPath, 0, m_dDimX, m_dDimY, TXR_CLAMP) ; // provo dalla path del progetto corrente string sName = GetFileName( m_sPath) ; return ExeLoadTexture( m_sName, sFileDir + "\\" + sName, 0, m_dDimX, m_dDimY, TXR_CLAMP) ; } //---------------------------------------------------------------------------- bool PhotoObj::SetOwner( int nId, IGeomDB* pGDB) { m_nOwnerId = nId ; m_pGeomDB = pGDB ; return ( m_nOwnerId != GDB_ID_NULL && m_pGeomDB != nullptr) ; } //---------------------------------------------------------------------------- int PhotoObj::GetOwner( void) const { return m_nOwnerId ; } //---------------------------------------------------------------------------- IGeomDB* PhotoObj::GetGeomDB( void) const { return m_pGeomDB ; } //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- PhotoObj::PhotoObj( void) : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr) { } //---------------------------------------------------------------------------- bool PhotoObj::Set( const string& sName, const string& sPath, const Point3d& ptOri, const Point3d& ptCen, double dDimX, double dDimY) { m_sName = sName ; m_sPath = sPath ; m_ptOri = ptOri ; m_ptCen = ptCen ; m_dDimX = dDimX ; m_dDimY = dDimY ; return true ; } //---------------------------------------------------------------------------- bool PhotoObj::GetName( string& sName) { sName = m_sName ; return true ; } //---------------------------------------------------------------------------- bool PhotoObj::GetPath( string& sPath) { sPath = m_sPath ; return true ; } //---------------------------------------------------------------------------- bool PhotoObj::ChangePath( const string& sPath) { m_sPath = sPath ; return ( ! m_sPath.empty()) ; } //---------------------------------------------------------------------------- bool PhotoObj::GetOrigin( Point3d& ptOri) { ptOri = m_ptOri ; return true ; } //---------------------------------------------------------------------------- bool PhotoObj::GetCenter( Point3d& ptCen) { ptCen = m_ptCen ; return true ; } //---------------------------------------------------------------------------- bool PhotoObj::GetDimensions( double& dDimX, double& dDimY) { dDimX = m_dDimX ; dDimY = m_dDimY ; return true ; }