diff --git a/EXE_Photo.cpp b/EXE_Photo.cpp index 19c6e08..95289af 100644 --- a/EXE_Photo.cpp +++ b/EXE_Photo.cpp @@ -16,16 +16,18 @@ #include "PhotoObj.h" #include "EXE.h" #include "EXE_Macro.h" +#include "AuxTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" using namespace std ; //---------------------------------------------------------------------------- int -ExeAddPhoto( const string& sName, const string& sPath, - const Point3d& ptOri, const Point3d& ptCen, double dMMxPixel, - int nParentId, const Point3d& ptMin, const Point3d& ptMax) +MyAddPhoto( const string& sName, const string& sPath, + const Point3d& ptOri, const Point3d& ptCen, double dMMxPixel, + int nParentId, const Point3d& ptMin, const Point3d& ptMax) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) @@ -59,12 +61,38 @@ ExeAddPhoto( const string& sName, const string& sPath, // Installo e inizializzo il gestore della foto PhotoObj* pPhoto = new( nothrow) PhotoObj ; if ( pPhoto == nullptr) { + pGeomDB->Erase( nId) ; pScene->UnloadTexture( sName) ; return GDB_ID_NULL ; } pPhoto->Set( sName, sPath, ptOri, ptCen, dDimX, dDimY) ; pGeomDB->SetUserObj( nId, pPhoto) ; + return nId ; +} + +//---------------------------------------------------------------------------- +int +ExeAddPhoto( const string& sName, const string& sPath, + const Point3d& ptOri, const Point3d& ptCen, double dMMxPixel, + int nParentId, const Point3d& ptMin, const Point3d& ptMax) +{ + // lancio esecuzione + int nId = MyAddPhoto( sName, sPath, ptOri, ptCen, dMMxPixel, nParentId, ptMin, ptMax) ; ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtAddPhoto('" + StringToLuaString( sName) + "','" + + StringToLuaString( sPath) + "',{" + + ToString( ptOri) + "},{" + + ToString( ptCen) + "}," + + ToString( dMMxPixel) + "," + + IdToString( nParentId) + ",{" + + ToString( ptMin) + "},{" + + ToString( ptMax) + "})" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato return nId ; } @@ -103,6 +131,7 @@ ExeAddPhoto( const string& sName, const string& sPath, // Installo e inizializzo il gestore della foto PhotoObj* pPhoto = new( nothrow) PhotoObj ; if ( pPhoto == nullptr) { + pGeomDB->Erase( nId) ; pScene->UnloadTexture( sName) ; return GDB_ID_NULL ; } @@ -137,6 +166,7 @@ ExeMovePhoto( int nId, const Vector3d& vtMove) pPhoto->GetOrigin( ptOrig) ; ptOrig.Translate( vtMove) ; pPhoto->ChangeOrigin( ptOrig) ; + ExeSetModified() ; return true ; } @@ -165,6 +195,7 @@ ExeRotatePhoto( int nId, const Point3d& ptAx, const Vector3d& vtAx, double dAngD pPhoto->GetOrigin( ptOrig) ; ptOrig.Rotate( ptAx, vtAx, dAngDeg) ; pPhoto->ChangeOrigin( ptOrig) ; + ExeSetModified() ; return true ; } @@ -190,10 +221,19 @@ ExeChangePhotoPath( int nId, const string& sPath) VERIFY_GEOMDB( pGeomDB, false) // recupero il gestore dei dati della fotografia dell'oggetto PhotoObj* pPhoto = dynamic_cast( pGeomDB->GetUserObj( nId)) ; - if ( pPhoto == nullptr) - return false ; + bool bOk = ( pPhoto != nullptr) ; // imposto la nuova path della fotografia - return pPhoto->ChangePath( sPath) ; + bOk = bOk && pPhoto->ChangePath( sPath) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtChangePhotoPath(" + IdToString( nId) + ",'" + + StringToLuaString( sPath) + "')" + + " -- Ok=" + ToString( bOk) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return bOk ; } //---------------------------------------------------------------------------- diff --git a/EXE_Picture.cpp b/EXE_Picture.cpp new file mode 100644 index 0000000..6f92f4c --- /dev/null +++ b/EXE_Picture.cpp @@ -0,0 +1,85 @@ +//---------------------------------------------------------------------------- +// EgalTech 2017-2017 +//---------------------------------------------------------------------------- +// File : EXE_Picture.cpp Data : 26.12.17 Versione : 1.8l3 +// Contenuto : Funzioni per gestione immagine. +// +// +// +// Modifiche : 26.12.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "PictureObj.h" +#include "EXE.h" +#include "EXE_Macro.h" +#include "AuxTools.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +int +MyAddPicture( int nParentId, const string& sName, const string& sPath, + double dDimX, double dDimY, int nRefType) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + IEGrScene* pScene = GetCurrScene() ; + VERIFY_SCENE( pScene, GDB_ID_NULL) + // Carico la texture + if ( ! pScene->UnloadTexture( sName) || + ! pScene->LoadTexture( sName, sPath, 0, dDimX, dDimY, TXR_CLAMP)) + return GDB_ID_NULL ; + // Inserisco la regione rettangolare della foto (tutti i dati sono in Globale) + Point3d ptIni = ORIG ; + Point3d ptCross = ptIni + Vector3d( dDimX, dDimY, 0) ; + int nId = ExeCreateSurfFrRectangle( nParentId, ptIni, ptCross, nRefType) ; + if ( nId == GDB_ID_NULL) { + pScene->UnloadTexture( sName) ; + return GDB_ID_NULL ; + } + // Assegno gli attributi + pGeomDB->SetMaterial( nId, WHITE) ; + pGeomDB->SetName( nId, sName) ; + // Assegno i dati della texture + pGeomDB->SetTextureName( nId, sName) ; + pGeomDB->SetTextureFrame( nId, Frame3d()) ; + // Installo e inizializzo il gestore della foto + PictureObj* pPic = new( nothrow) PictureObj ; + if ( pPic == nullptr) { + pGeomDB->Erase( nId) ; + pScene->UnloadTexture( sName) ; + return GDB_ID_NULL ; + } + pPic->Set( sName, sPath, dDimX, dDimY) ; + pGeomDB->SetUserObj( nId, pPic) ; + return nId ; +} + +//---------------------------------------------------------------------------- +int +ExeAddPicture( int nParentId, const string& sName, const string& sPath, + double dDimX, double dDimY, int nRefType) +{ + // lancio esecuzione + int nId = MyAddPicture( nParentId, sName, sPath, dDimX, dDimY, nRefType) ; + ExeSetModified() ; + // se richiesto, salvo il comando Lua equivalente + if ( IsCmdLog()) { + string sLua = "EgtAddPicture(" + IdToString( nParentId) + ",'" + + StringToLuaString( sName) + "','" + + StringToLuaString( sPath) + "'," + + ToString( dDimX) + "," + + ToString( dDimY) + "," + + IdToString( nParentId) + ")" + + " -- Id=" + ToString( nId) ; + LOG_INFO( GetCmdLogger(), sLua.c_str()) ; + } + // restituisco risultato + return nId ; +} diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 36616f7..cb9796c 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/EgtExecutor.vcxproj b/EgtExecutor.vcxproj index 95517ff..7dfc57b 100644 --- a/EgtExecutor.vcxproj +++ b/EgtExecutor.vcxproj @@ -224,6 +224,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -257,6 +258,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -269,6 +271,8 @@ copy $(TargetPath) \EgtProg\Dll64 + + diff --git a/EgtExecutor.vcxproj.filters b/EgtExecutor.vcxproj.filters index f948661..2f050e1 100644 --- a/EgtExecutor.vcxproj.filters +++ b/EgtExecutor.vcxproj.filters @@ -102,6 +102,9 @@ File di intestazione + + File di intestazione + @@ -302,6 +305,15 @@ File di origine\LUA + + File di origine\UserCustom + + + File di origine\EXE + + + File di origine\LUA + diff --git a/LUA.h b/LUA.h index b41770e..64a985c 100644 --- a/LUA.h +++ b/LUA.h @@ -81,6 +81,9 @@ bool LuaInstallScene( LuaMgr& luaMgr) ; //-------------------------- Photo ------------------------------------------- bool LuaInstallPhoto( LuaMgr& luaMgr) ; +//-------------------------- Picture ----------------------------------------- +bool LuaInstallPicture( LuaMgr& luaMgr) ; + //-------------------------- Image ------------------------------------------- bool LuaInstallImage( LuaMgr& luaMgr) ; diff --git a/LUA_Base.cpp b/LUA_Base.cpp index a137ac2..c8e3e40 100644 --- a/LUA_Base.cpp +++ b/LUA_Base.cpp @@ -114,6 +114,10 @@ LuaInstallEgtFunctions( LuaMgr& LuaMgr) LOG_ERROR( GetLogger(), "Error in LuaInstallPhoto (" __FUNCTION__ ")") return false ; } + if ( ! LuaInstallPicture( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallPicture (" __FUNCTION__ ")") + return false ; + } if ( ! LuaInstallImage( LuaMgr)) { LOG_ERROR( GetLogger(), "Error in LuaInstallImage (" __FUNCTION__ ")") return false ; diff --git a/LUA_Photo.cpp b/LUA_Photo.cpp index 561fa8a..e1270ab 100644 --- a/LUA_Photo.cpp +++ b/LUA_Photo.cpp @@ -75,7 +75,7 @@ LuaGetPhotoPath( lua_State* L) static int LuaChangePhotoPath( lua_State* L) { - // 2 parametri : nId, + // 2 parametri : nId, sPath int nId ; LuaCheckParam( L, 1, nId) string sPath ; diff --git a/LUA_Picture.cpp b/LUA_Picture.cpp new file mode 100644 index 0000000..5f7b3c8 --- /dev/null +++ b/LUA_Picture.cpp @@ -0,0 +1,59 @@ +//---------------------------------------------------------------------------- +// EgalTech 2017-2017 +//---------------------------------------------------------------------------- +// File : LUA_Picture.cpp Data : 26.12.17 Versione : 1.8l3 +// Contenuto : Funzioni sulla immagine per LUA. +// +// +// +// Modifiche : 26.12.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EXeConst.h" +#include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EgnStringUtils.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaAddPicture( lua_State* L) +{ + // 5 o 6 parametri : nParentId, nome per la texture, path della immagine, dDimX, dDimY [, nRefType] + int nParentId ; + LuaCheckParam( L, 1, nParentId) + string sName ; + LuaCheckParam( L, 2, sName) + string sPath ; + LuaCheckParam( L, 3, sPath) + double dDimX ; + LuaCheckParam( L, 4, dDimX) + double dDimY ; + LuaCheckParam( L, 5, dDimY) + int nRefType = RTY_DEFAULT ; + LuaGetParam( L, 6, nRefType) ; + LuaClearStack( L) ; + // inserisco l'immagine + int nId = ExeAddPicture( nParentId, sName, sPath, dDimX, dDimY, nRefType) ; + // restituisco il risultato + if ( nId != GDB_ID_NULL) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallPicture( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtAddPicture", LuaAddPicture) ; + return bOk ; +} diff --git a/PhotoObj.cpp b/PhotoObj.cpp index 15fe222..a6447cf 100644 --- a/PhotoObj.cpp +++ b/PhotoObj.cpp @@ -97,10 +97,14 @@ PhotoObj::Save( STRVECTOR& vString) const string sFilePath ; ExeGetCurrFilePath( sFilePath) ; string sFileDir = GetDirectory( sFilePath) ; + ReplaceString( sFileDir, "/", "\\") ; + ToUpper( sFileDir) ; 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) ; + ReplaceString( sDir, "/", "\\") ; + ToUpper( sDir) ; string sName = GetFileName( sPath) ; ReplaceString( sDir, sFileDir, SUB_PROJECT_DIR) ; ReplaceString( sName, sFileTitle, SUB_PROJECT_TITLE) ; @@ -250,7 +254,7 @@ PhotoObj::Set( const string& sName, const string& sPath, //---------------------------------------------------------------------------- bool -PhotoObj::GetName( string& sName) +PhotoObj::GetName( string& sName) const { sName = m_sName ; return true ; @@ -258,7 +262,7 @@ PhotoObj::GetName( string& sName) //---------------------------------------------------------------------------- bool -PhotoObj::GetPath( string& sPath) +PhotoObj::GetPath( string& sPath) const { sPath = m_sPath ; return true ; @@ -274,7 +278,7 @@ PhotoObj::ChangePath( const string& sPath) //---------------------------------------------------------------------------- bool -PhotoObj::GetOrigin( Point3d& ptOri) +PhotoObj::GetOrigin( Point3d& ptOri) const { ptOri = m_ptOri ; return true ; @@ -290,7 +294,7 @@ PhotoObj::ChangeOrigin( const Point3d& ptOri) //---------------------------------------------------------------------------- bool -PhotoObj::GetCenter( Point3d& ptCen) +PhotoObj::GetCenter( Point3d& ptCen) const { ptCen = m_ptCen ; return true ; @@ -306,7 +310,7 @@ PhotoObj::ChangeCenter( const Point3d& ptCen) //---------------------------------------------------------------------------- bool -PhotoObj::GetDimensions( double& dDimX, double& dDimY) +PhotoObj::GetDimensions( double& dDimX, double& dDimY) const { dDimX = m_dDimX ; dDimY = m_dDimY ; diff --git a/PhotoObj.h b/PhotoObj.h index 0121a10..980c0e8 100644 --- a/PhotoObj.h +++ b/PhotoObj.h @@ -20,28 +20,28 @@ class PhotoObj : public IUserObj { public : // IUserObj - virtual PhotoObj* Clone( void) const ; - virtual const std::string& GetClassName( void) const ; - virtual bool Dump( std::string& sOut, bool bMM = true, const char* szNewLine = "\n") const ; - virtual bool ToSave( void) const { return true ; } - virtual bool Save( STRVECTOR& vString) const ; - virtual bool Load( const STRVECTOR& vString, int nBaseGdbId) ; - virtual bool SetOwner( int nId, IGeomDB* pGDB) ; - virtual int GetOwner( void) const ; - virtual IGeomDB* GetGeomDB( void) const ; + PhotoObj* Clone( void) const override ; + const std::string& GetClassName( void) const override ; + bool Dump( std::string& sOut, bool bMM = true, const char* szNewLine = "\n") const override ; + bool ToSave( void) const override { return true ; } + bool Save( STRVECTOR& vString) const override ; + bool Load( const STRVECTOR& vString, int nBaseGdbId) override ; + bool SetOwner( int nId, IGeomDB* pGDB) override ; + int GetOwner( void) const override ; + IGeomDB* GetGeomDB( void) const override ; public : PhotoObj( void) ; bool Set( const std::string& sName, const std::string& sPath, const Point3d& ptOri, const Point3d& ptCen, double dDimX, double dDimY) ; - bool GetName( std::string& sName) ; - bool GetPath( std::string& sPath) ; + bool GetName( std::string& sName) const ; + bool GetPath( std::string& sPath) const ; bool ChangePath( const std::string& sPath) ; - bool GetOrigin( Point3d& ptOri) ; + bool GetOrigin( Point3d& ptOri) const ; bool ChangeOrigin( const Point3d& ptOri) ; - bool GetCenter( Point3d& ptCen) ; + bool GetCenter( Point3d& ptCen) const ; bool ChangeCenter( const Point3d& ptCen) ; - bool GetDimensions( double& dDimX, double& dDimY) ; + bool GetDimensions( double& dDimX, double& dDimY) const ; private : int m_nOwnerId ; diff --git a/PictureObj.cpp b/PictureObj.cpp new file mode 100644 index 0000000..f18a6a3 --- /dev/null +++ b/PictureObj.cpp @@ -0,0 +1,361 @@ +//---------------------------------------------------------------------------- +// EgalTech 2017-2017 +//---------------------------------------------------------------------------- +// File : PictureObj.cpp Data : 26.12.17 Versione : 1.8l3 +// Contenuto : Oggetto custom Picture. +// Viene attaccato ad una Region rettangolare. +// +// +// Modifiche : 26.12.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "PictureObj.h" +#include "GseContext.h" +#include "EXE.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" +// per far dimenticare macro di WinUser.h +#undef GetClassName + +using namespace std ; + +//---------------------------------------------------------------------------- +static const int NKEY = 4 ; +static const string KEY_NAME = "N" ; +static const string KEY_PATH = "P" ; +static const string KEY_DIMX = "DX" ; +static const string KEY_DIMY = "DY" ; + +//---------------------------------------------------------------------------- +USEROBJ_REGISTER( "EXePicture", PictureObj) ; + +//---------------------------------------------------------------------------- +const string& +PictureObj::GetClassName( void) const +{ + return USEROBJ_GETNAME( PictureObj) ; +} + +//---------------------------------------------------------------------------- +PictureObj* +PictureObj::Clone( void) const +{ + // alloco oggetto + PictureObj* pImage = new( nothrow) PictureObj ; + // eseguo copia dei dati + if ( pImage != nullptr) { + try { + pImage->m_nOwnerId = GDB_ID_NULL ; + pImage->m_pGeomDB = nullptr ; + pImage->m_sPath = m_sPath ; + } + catch( ...) { + delete pImage ; + return nullptr ; + } + } + // ritorno l'oggetto + return pImage ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::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 += "Dim=" + ToString( m_dDimX) + "," + ToString( m_dDimY) + szNewLine ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::Save( STRVECTOR& vString) const +{ + // recupero nome del progetto corrente + string sFilePath ; + ExeGetCurrFilePath( sFilePath) ; + string sFileDir = GetDirectory( sFilePath) ; + ReplaceString( sFileDir, "/", "\\") ; + ToUpper( sFileDir) ; + 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) ; + ReplaceString( sDir, "/", "\\") ; + ToUpper( sDir) ; + 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_DIMX, m_dDimX, vString[2])) + return false ; + if ( ! SetVal( KEY_DIMY, m_dDimY, vString[3])) + return false ; + } + catch( ...) { + return false ; + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::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_DIMX, m_dDimX)) + return false ; + if ( ! GetVal( vString[3], KEY_DIMY, m_dDimY)) + return false ; + // se caricata scena, carico la texture + if ( GetCurrScene() != nullptr) { + // 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)) { + if ( ! ExeLoadTexture( m_sName, m_sPath, 0, m_dDimX, m_dDimY, TXR_CLAMP)) { + string sOut = "Error loading image " + m_sPath ; + LOG_ERROR( GetLogger(), sOut.c_str()) + } + return true ; + } + // provo dalla path del progetto corrente + string sOtherPath = sFileDir + "\\" + GetFileName( m_sPath) ; + if ( ExistsFile( sOtherPath)) { + if ( ! ExeLoadTexture( m_sName, sOtherPath, 0, m_dDimX, m_dDimY, TXR_CLAMP)) { + string sOut = "Error loading image " + sOtherPath ; + LOG_ERROR( GetLogger(), sOut.c_str()) + } + } + else { + string sOut = "Error missing image " + sOtherPath ; + LOG_ERROR( GetLogger(), sOut.c_str()) + } + return true ; + } + // altrimenti ne verifico solo l'esistenza + else { + // 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 true ; + // provo dalla path del progetto corrente + string sOtherPath = sFileDir + "\\" + GetFileName( m_sPath) ; + if ( ! ExistsFile( sOtherPath)) { + string sOut = "Error missing image " + sOtherPath ; + LOG_ERROR( GetLogger(), sOut.c_str()) + } + return true ; + } +} + +//---------------------------------------------------------------------------- +bool +PictureObj::SetOwner( int nId, IGeomDB* pGDB) +{ + m_nOwnerId = nId ; + m_pGeomDB = pGDB ; + return ( m_nOwnerId != GDB_ID_NULL && m_pGeomDB != nullptr) ; +} + +//---------------------------------------------------------------------------- +int +PictureObj::GetOwner( void) const +{ + return m_nOwnerId ; +} + +//---------------------------------------------------------------------------- +IGeomDB* +PictureObj::GetGeomDB( void) const +{ + return m_pGeomDB ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::Translate( const Vector3d& vtMove) +{ + if ( m_pGeomDB == nullptr || m_nOwnerId == GDB_ID_NULL) + return false ; + // traslo il riferimento della texture + Frame3d frTxt ; + m_pGeomDB->GetTextureFrame( m_nOwnerId, frTxt) ; + frTxt.Translate( vtMove) ; + m_pGeomDB->SetTextureFrame( m_nOwnerId, frTxt) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) +{ + if ( m_pGeomDB == nullptr || m_nOwnerId == GDB_ID_NULL) + return false ; + // ruoto il riferimento della texture + Frame3d frTxt ; + m_pGeomDB->GetTextureFrame( m_nOwnerId, frTxt) ; + frTxt.Rotate( ptAx, vtAx, dCosAng, dSinAng) ; + m_pGeomDB->SetTextureFrame( m_nOwnerId, frTxt) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) +{ + IEGrScene* pScene = GetCurrScene() ; + if ( m_pGeomDB == nullptr || m_nOwnerId == GDB_ID_NULL || pScene == nullptr) + return false ; + // recupero il riferimento della texture + Frame3d frTxt ; + m_pGeomDB->GetTextureFrame( m_nOwnerId, frTxt) ; + // determino i vettori dimensioni della texture + double dDimX, dDimY ; + pScene->GetTextureDimensions( m_sName, dDimX, dDimY) ; + Vector3d vtDimX = frTxt.VersX() * dDimX ; + Vector3d vtDimY = frTxt.VersY() * dDimY ; + // pseudoscalo il riferimento della texture + frTxt.PseudoScale( frRef, dCoeffX, dCoeffY, dCoeffZ) ; + m_pGeomDB->SetTextureFrame( m_nOwnerId, frTxt) ; + // scalo le dimensioni della texture + vtDimX.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ; + vtDimY.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ; + pScene->ChangeTextureDimensions( m_sName, vtDimX.Len(), vtDimY.Len()) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::ToGlob( const Frame3d& frRef) +{ + if ( m_pGeomDB == nullptr || m_nOwnerId == GDB_ID_NULL) + return false ; + // porto in globale il riferimento della texture + Frame3d frTxt ; + m_pGeomDB->GetTextureFrame( m_nOwnerId, frTxt) ; + frTxt.ToGlob( frRef) ; + m_pGeomDB->SetTextureFrame( m_nOwnerId, frTxt) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::ToLoc( const Frame3d& frRef) +{ + if ( m_pGeomDB == nullptr || m_nOwnerId == GDB_ID_NULL) + return false ; + // porto in locale il riferimento della texture + Frame3d frTxt ; + m_pGeomDB->GetTextureFrame( m_nOwnerId, frTxt) ; + frTxt.ToLoc( frRef) ; + m_pGeomDB->SetTextureFrame( m_nOwnerId, frTxt) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::LocToLoc( const Frame3d& frOri, const Frame3d& frDest) +{ + if ( m_pGeomDB == nullptr || m_nOwnerId == GDB_ID_NULL) + return false ; + // porto da un locale all'altro il riferimento della texture + Frame3d frTxt ; + m_pGeomDB->GetTextureFrame( m_nOwnerId, frTxt) ; + frTxt.LocToLoc( frOri, frDest) ; + m_pGeomDB->SetTextureFrame( m_nOwnerId, frTxt) ; + return true ; +} + +//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +PictureObj::PictureObj( void) + : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr) +{ +} + +//---------------------------------------------------------------------------- +bool +PictureObj::Set( const std::string& sName, const std::string& sPath, double dDimX, double dDimY) +{ + m_sName = sName ; + m_sPath = sPath ; + m_dDimX = dDimX ; + m_dDimY = dDimY ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::GetName( string& sName) const +{ + sName = m_sName ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::GetPath( string& sPath) const +{ + sPath = m_sPath ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::ChangePath( const string& sPath) +{ + m_sPath = sPath ; + return ( ! m_sPath.empty()) ; +} + +//---------------------------------------------------------------------------- +bool +PictureObj::GetDimensions( double& dDimX, double& dDimY) const +{ + dDimX = m_dDimX ; + dDimY = m_dDimY ; + return true ; +} diff --git a/PictureObj.h b/PictureObj.h new file mode 100644 index 0000000..999f605 --- /dev/null +++ b/PictureObj.h @@ -0,0 +1,59 @@ +//---------------------------------------------------------------------------- +// EgalTech 2017-2017 +//---------------------------------------------------------------------------- +// File : PictureObj.h Data : 26.12.17 Versione : 1.8l3 +// Contenuto : Dichiarazione della classe PictureObj. +// +// +// +// Modifiche : 26.12.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkUserObj.h" +#include "/EgtDev/Include/EGkPoint3d.h" + +//---------------------------------------------------------------------------- +class PictureObj : public IUserObj +{ + public : // IUserObj + PictureObj* Clone( void) const override ; + const std::string& GetClassName( void) const override ; + bool Dump( std::string& sOut, bool bMM = true, const char* szNewLine = "\n") const override ; + bool ToSave( void) const override { return true ; } + bool Save( STRVECTOR& vString) const override ; + bool Load( const STRVECTOR& vString, int nBaseGdbId) override ; + bool SetOwner( int nId, IGeomDB* pGDB) override ; + int GetOwner( void) const override ; + IGeomDB* GetGeomDB( void) const override ; + bool Translate( const Vector3d& vtMove) override ; + bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) override + { double dAngRad = dAngDeg * DEGTORAD ; + return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ; } + bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) override ; + bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) override ; + bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) override { return true ; } + bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) override { return true ; } + bool ToGlob( const Frame3d& frRef) override ; + bool ToLoc( const Frame3d& frRef) override ; + bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) override ; + + public : + PictureObj( void) ; + bool Set( const std::string& sName, const std::string& sPath, double dDimX, double dDimY) ; + bool GetName( std::string& sName) const ; + bool GetPath( std::string& sPath) const ; + bool ChangePath( const std::string& sPath) ; + bool GetDimensions( double& dDimX, double& dDimY) const ; + + private : + int m_nOwnerId ; + IGeomDB* m_pGeomDB ; + std::string m_sName ; + std::string m_sPath ; + double m_dDimX ; + double m_dDimY ; +} ; \ No newline at end of file