f33513bdc5
- aggiunte funzioni Exe e Lua AddPicture - migliorie alla gestione di Photo.
319 lines
10 KiB
C++
319 lines
10 KiB
C++
//----------------------------------------------------------------------------
|
|
// 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 "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 = 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 {
|
|
pPhoto->m_nOwnerId = GDB_ID_NULL ;
|
|
pPhoto->m_pGeomDB = nullptr ;
|
|
pPhoto->m_sName = m_sName ;
|
|
pPhoto->m_sPath = m_sPath ;
|
|
pPhoto->m_ptOri = m_ptOri ;
|
|
pPhoto->m_ptCen = m_ptCen ;
|
|
pPhoto->m_dDimX = m_dDimX ;
|
|
pPhoto->m_dDimY = m_dDimY ;
|
|
}
|
|
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) ;
|
|
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<const string&>( 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 ;
|
|
// 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
|
|
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) const
|
|
{
|
|
sName = m_sName ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
PhotoObj::GetPath( string& sPath) const
|
|
{
|
|
sPath = m_sPath ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
PhotoObj::ChangePath( const string& sPath)
|
|
{
|
|
m_sPath = sPath ;
|
|
return ( ! m_sPath.empty()) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
PhotoObj::GetOrigin( Point3d& ptOri) const
|
|
{
|
|
ptOri = m_ptOri ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
PhotoObj::ChangeOrigin( const Point3d& ptOri)
|
|
{
|
|
m_ptOri = ptOri ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
PhotoObj::GetCenter( Point3d& ptCen) const
|
|
{
|
|
ptCen = m_ptCen ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
PhotoObj::ChangeCenter( const Point3d& ptCen)
|
|
{
|
|
m_ptCen = ptCen ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
PhotoObj::GetDimensions( double& dDimX, double& dDimY) const
|
|
{
|
|
dDimX = m_dDimX ;
|
|
dDimY = m_dDimY ;
|
|
return true ;
|
|
}
|