diff --git a/EGkGdbIterator.h b/EGkGdbIterator.h index ec3a281..cdda32f 100644 --- a/EGkGdbIterator.h +++ b/EGkGdbIterator.h @@ -55,7 +55,7 @@ class __declspec( novtable) IGdbIterator virtual bool GoToPrevGroup( void) = 0 ; virtual bool EraseAndGoToNextGroup( void) = 0 ; virtual bool EraseAndGoToPrevGroup( void) = 0 ; - + // Gets virtual int GetGdbType( void) const = 0 ; virtual int GetGeoType( void) const = 0 ; virtual IGeoObj* GetGeoObj( void) = 0 ; @@ -71,6 +71,26 @@ class __declspec( novtable) IGdbIterator virtual bool GetLocalBBox( BBox3d& b3Loc, int nFlag = BBF_STANDARD) const = 0 ; virtual bool GetGlobalBBox( BBox3d& b3Glob, int nFlag = BBF_STANDARD) const = 0 ; virtual bool GetRefBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag = BBF_STANDARD) const = 0 ; + // Transformations + virtual bool Translate( const Vector3d& vtMove) = 0 ; + virtual bool TranslateGlob( const Vector3d& vtMove) = 0 ; + virtual bool TranslateGroup( const Vector3d& vtMove) = 0 ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) = 0 ; + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) = 0 ; + virtual bool RotateGlob( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) = 0 ; + virtual bool RotateGlob( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) = 0 ; + virtual bool RotateGroup( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) = 0 ; + virtual bool RotateGroup( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) = 0 ; + virtual bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) = 0 ; + virtual bool ScaleGlob( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) = 0 ; + virtual bool ScaleGroup( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) = 0 ; + virtual bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) = 0 ; + virtual bool MirrorGlob( const Point3d& ptOn, const Vector3d& vtNorm) = 0 ; + virtual bool MirrorGroup( const Point3d& ptOn, const Vector3d& vtNorm) = 0 ; + virtual bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) = 0 ; + virtual bool ShearGlob( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) = 0 ; + virtual bool ShearGroup( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) = 0 ; + // Attributes virtual bool SetLevel( int nLevel) = 0 ; virtual bool RevertLevel( void) = 0 ; virtual bool GetLevel( int& nLevel) const = 0 ; @@ -122,6 +142,11 @@ class __declspec( novtable) IGdbIterator virtual bool GetInfo( const std::string& sKey, STRVECTOR& vsInfo) const = 0 ; virtual bool ExistsInfo( const std::string& sKey) const = 0 ; virtual bool RemoveInfo( const std::string& sKey) = 0 ; + // UserObj + virtual bool SetUserObj( IUserObj* pUserObj) = 0 ; + virtual IUserObj* GetUserObj( void) = 0 ; + virtual const IUserObj* GetUserObj( void) const = 0 ; + virtual bool RemoveUserObj( void) = 0 ; } ; //----------------------------------------------------------------------------- diff --git a/EGkGeomDB.h b/EGkGeomDB.h index c392f3a..5133883 100644 --- a/EGkGeomDB.h +++ b/EGkGeomDB.h @@ -20,7 +20,7 @@ #include "/EgtDev/Include/EGkGeoFrame3d.h" #include "/EgtDev/Include/EGkGeoObj.h" #include "/EgtDev/Include/EGkMaterial.h" -#include "/EgtDev/Include/EGkObjUser.h" +#include "/EgtDev/Include/EGkUserObj.h" #include "/EgtDev/Include/EgtNumCollection.h" #include "/EgtDev/Include/EgtStringBase.h" #include "/EgtDev/Include/EgtILogger.h" @@ -170,12 +170,13 @@ class __declspec( novtable) IGeomDB virtual bool GetInfo( int nId, const std::string& sKey, STRVECTOR& vsInfo) const = 0 ; virtual bool ExistsInfo( int nId, const std::string& sKey) const = 0 ; virtual bool RemoveInfo( int nId, const std::string& sKey) = 0 ; - // ObjUser - virtual bool SetObjUser( int nId, IObjUser* pObjUser) = 0 ; - virtual IObjUser* GetObjUser( int nId) = 0 ; - virtual const IObjUser* GetObjUser( int nId) const = 0 ; - virtual bool DumpObjUser( int nId, std::string& sOut, const char* szNewLine) const = 0 ; - virtual bool CopyObjUser( int nIdSou, int nIdDest) = 0 ; + // UserObj + virtual bool SetUserObj( int nId, IUserObj* pUserObj) = 0 ; + virtual IUserObj* GetUserObj( int nId) = 0 ; + virtual const IUserObj* GetUserObj( int nId) const = 0 ; + virtual bool DumpUserObj( int nId, std::string& sOut, const char* szNewLine) const = 0 ; + virtual bool CopyUserObj( int nIdSou, int nIdDest) = 0 ; + virtual bool RemoveUserObj( int nId) = 0 ; // Material library virtual int AddMaterial( const std::string& sName, const Material& matM) = 0 ; virtual int FindMaterial( const std::string& sName) const = 0 ; diff --git a/EGkLuaAux.h b/EGkLuaAux.h index 8b17fcc..1fafa2e 100644 --- a/EGkLuaAux.h +++ b/EGkLuaAux.h @@ -18,6 +18,7 @@ #include "/EgtDev/Include/EGkBBox3d.h" #include "/EgtDev/Include/EGkColor.h" #include "/EgtDev/Include/EGkGeoCollection.h" +#include "/EgtDev/Include/EGkSelection.h" #include "/EgtDev/Include/EgnLuaAux.h" using namespace std ; @@ -205,6 +206,47 @@ LuaGetParam( lua_State* L, int nInd, PNTUVECTOR& vParW) return false ; } +//---------------------------------------------------------------------------- +inline bool +LuaGetParam( lua_State* L, int nInd, SELVECTOR& vSel) +{ + vSel.clear() ; + int nId ; + if ( LuaGetParam( L, nInd, nId)) { + vSel.emplace_back( nId) ; + return true ; + } + else if ( lua_istable( L, nInd)) { + // lunghezza della tavola + lua_len( L, nInd) ; + if ( ! lua_isnumber( L, -1)) + return false ; + int nLen = int( lua_tointeger( L, -1)) ; + lua_pop( L, 1) ; + // recupero il contenuto della tavola + vSel.reserve( nLen) ; + for ( int i = 1 ; i <= nLen ; ++ i) { + lua_rawgeti( L, nInd, i) ; + int nId ; + if ( LuaGetParam( L, -1, nId)) { + vSel.emplace_back( nId) ; + lua_pop( L, 1) ; + } + else { + SelData Id ; + if ( ! LuaGetParam( L, -1, Id.v)) + return false ; + vSel.emplace_back( Id) ; + lua_pop( L, 1) ; + } + POINTU ptPW ; + } + return true ; + } + else + return false ; +} + //---------------------------------------------------------------------------- inline bool LuaSetReturn( lua_State* L, const Vector3d& vtPar) diff --git a/EGkObjUser.h b/EGkObjUser.h deleted file mode 100644 index addac8a..0000000 --- a/EGkObjUser.h +++ /dev/null @@ -1,35 +0,0 @@ -//---------------------------------------------------------------------------- -// EgalTech 2015-2015 -//---------------------------------------------------------------------------- -// File : EGkObjUser.h Data : 22.05.15 Versione : 1.6e3 -// Contenuto : Dichiarazione della interfaccia IObjUser. -// -// -// -// Modifiche : 22.05.15 DS Creazione modulo. -// -// -//---------------------------------------------------------------------------- - -#pragma once - -#include "/EgtDev/Include/EgtStringBase.h" - -class IGeomDB ; - -//---------------------------------------------------------------------------- -class __declspec( novtable) IObjUser -{ - public : - virtual ~IObjUser( void) {} - virtual IObjUser* Clone( void) const = 0 ; - virtual bool IsDefault(void) const { return false ; } - virtual const std::string& GetClassName( void) const = 0 ; - virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const = 0 ; - virtual bool ToSave( void) const { return false ; } - virtual bool Save( STRVECTOR& vString) const { return false ; } - virtual bool Load( const STRVECTOR& vString) { return false ; } - virtual bool SetOwner( int nId, IGeomDB* pGDB) = 0 ; - virtual int GetOwner( void) const = 0 ; - virtual IGeomDB* GetGeomDB( void) const = 0 ; -} ; diff --git a/EGkSelection.h b/EGkSelection.h new file mode 100644 index 0000000..057f2d9 --- /dev/null +++ b/EGkSelection.h @@ -0,0 +1,68 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : EgkSelection.h Data : 11.06.15 Versione : 1.6f2 +// Contenuto : Strutture e raccolte per indici di selezione, +// con funzioni di conversione da e verso stringhe. +// +// +// Modifiche : 11.06.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkGdbConst.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include +#include + +//---------------------------------------------------------------------------- +// costante per indicare che è selezionato tutto l'oggetto (le parti hanno indice 0-based) +const int SEL_SUB_ALL = - 1 ; +// Struttura per selezione di oggetto o di sua parte +struct SelData { + union { + struct { + int nId ; + int nSub ; + } ; + int v[2] ; + } ; + SelData( void) + : nId( GDB_ID_NULL), nSub( SEL_SUB_ALL) {} + SelData( int nI) + : nId( nI), nSub( SEL_SUB_ALL) {} + SelData( int nI, int nS) + : nId( nI), nSub( nS) {} +} ; + +//---------------------------------------------------------------------------- +// Raccolte di SelData +typedef std::vector SELVECTOR ; // vettore di SelData +typedef std::list SELLIST ; // lista di SelData + +//---------------------------------------------------------------------------- +// Conversione di SelData da e verso stringhe +inline bool FromString( const std::string& sVal, SelData& Val) + { return FromString( sVal, Val.v) ; } +inline const std::string ToString( const SelData& Val, int nPrec = 1) + { return ToString( Val.v, nPrec) ; } + +//---------------------------------------------------------------------------- +// Conversione di vettori di SelData da e verso stringhe +inline bool FromString( const std::string& sVal, SELVECTOR& vVal) + { INTVECTOR vI ; + if ( ! FromString( sVal, vI) || ( vI.size() % 2) != 0) + return false ; + vVal.reserve( vI.size() / 2) ; + for ( size_t i = 0 ; i < vI.size() ; i += 2) + vVal.emplace_back( vI[i], vI[i+1]) ; + return true ; } +inline const std::string ToString( const SELVECTOR& vVal, int nPrec = 1) + { std::string sDest ; sDest.reserve( 2 * 8 * vVal.size()) ; + for ( const auto& Val : vVal) + sDest += ToString( Val.nId, nPrec) + "," + ToString( Val.nSub, nPrec) + "," ; + sDest.pop_back() ; + return sDest ; } diff --git a/EGkUserObj.h b/EGkUserObj.h new file mode 100644 index 0000000..feb1d0b --- /dev/null +++ b/EGkUserObj.h @@ -0,0 +1,49 @@ +//---------------------------------------------------------------------------- +// EgalTech 2015-2015 +//---------------------------------------------------------------------------- +// File : EGkUserObj.h Data : 22.05.15 Versione : 1.6e3 +// Contenuto : Dichiarazione della interfaccia IUserObj. +// +// +// +// Modifiche : 22.05.15 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkPolyLine.h" +#include "/EgtDev/Include/EgtStringBase.h" + +class IGeomDB ; + +//---------------------------------------------------------------------------- +class __declspec( novtable) IUserObj +{ + public : // standard + virtual ~IUserObj( void) {} + virtual IUserObj* Clone( void) const = 0 ; + virtual const std::string& GetClassName( void) const = 0 ; + virtual bool Dump( std::string& sOut, const char* szNewLine = "\n") const = 0 ; + virtual bool SetOwner( int nId, IGeomDB* pGDB) = 0 ; + virtual int GetOwner( void) const = 0 ; + virtual IGeomDB* GetGeomDB( void) const = 0 ; + public : // save & load + virtual bool ToSave( void) const { return false ; } + virtual bool Save( STRVECTOR& vString) const { return false ; } + virtual bool Load( const STRVECTOR& vString) { return false ; } + public : // show & transform geometry (only if with a GeoObj) + virtual bool GetDrawPolyLines( POLYLINELIST& lstPL) const { return false ; } + virtual bool Translate( const Vector3d& vtMove) { return true ; } + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg) { return true ; } + virtual bool Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng) { return true ; } + virtual bool Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ) { return true ; } + virtual bool Mirror( const Point3d& ptOn, const Vector3d& vtNorm) { return true ; } + virtual bool Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff) { return true ; } + virtual bool ToGlob( const Frame3d& frRef) { return true ; } + virtual bool ToLoc( const Frame3d& frRef) { return true ; } + virtual bool LocToLoc( const Frame3d& frOri, const Frame3d& frDest) { return true ; } + public : // reserved + virtual bool IsDefault(void) const { return false ; } +} ; diff --git a/EGkObjUserFactory.h b/EGkUserObjFactory.h similarity index 65% rename from EGkObjUserFactory.h rename to EGkUserObjFactory.h index 5a829e0..f6a6bbb 100644 --- a/EGkObjUserFactory.h +++ b/EGkUserObjFactory.h @@ -1,8 +1,8 @@ //---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- -// File : EGkObjUserFactory.h Data : 22.05.15 Versione : 1.6e3 -// Contenuto : Factory della classe IObjUser. +// File : EGkUserObjFactory.h Data : 22.05.15 Versione : 1.6e3 +// Contenuto : Factory della classe IUserObj. // // // @@ -13,7 +13,7 @@ #pragma once -#include "/EgtDev/Include/EGkObjUser.h" +#include "/EgtDev/Include/EGkUserObj.h" #include #include @@ -26,53 +26,53 @@ #endif //---------------------------------------------------------------------------- -#define OBJUSER_REGISTER( sName, T) static const bool bReg_##T = \ - ObjUserRegister::DoRegister( sName) -#define OBJUSER_GETNAME( T) ObjUserRegister::GetName() -#define OBJUSER_CREATE( sName) ObjUserFactory::Create( sName) -#define OBJUSER_GETLIST( vsList) ObjUserFactory::GetList( vsList) +#define USEROBJ_REGISTER( sName, T) static const bool bReg_##T = \ + UserObjRegister::DoRegister( sName) +#define USEROBJ_GETNAME( T) UserObjRegister::GetName() +#define USEROBJ_CREATE( sName) UserObjFactory::Create( sName) +#define USEROBJ_GETLIST( vsList) UserObjFactory::GetList( vsList) //---------------------------------------------------------------------------- template -class ObjUserRegister +class UserObjRegister { public : static bool DoRegister( const std::string& sName) - { if ( ! ObjUserFactory::Register( sName, Create)) + { if ( ! UserObjFactory::Register( sName, Create)) return false ; GetNamePrivate() = sName ; return true ; } - static IObjUser* Create( void) + static IUserObj* Create( void) { return new(nothrow) T ; } static const std::string& GetName( void) { return GetNamePrivate() ; } private : - ObjUserRegister( void) {} - ~ObjUserRegister( void) {} + UserObjRegister( void) {} + ~UserObjRegister( void) {} static std::string& GetNamePrivate( void) { static std::string s_sName ; return s_sName ; } } ; //---------------------------------------------------------------------------- -class ObjUserFactory +class UserObjFactory { public : // definizione del tipo funzione di creazione - typedef IObjUser* ( *ObjUserCreator) ( void) ; + typedef IUserObj* ( *UserObjCreator) ( void) ; // per registrare le funzioni di creazione - EGK_EXPORT static bool Register( const std::string& sName, ObjUserCreator Creator) ; + EGK_EXPORT static bool Register( const std::string& sName, UserObjCreator Creator) ; // per creare l'oggetto richiesto - EGK_EXPORT static IObjUser* Create( const std::string& sName) ; + EGK_EXPORT static IUserObj* Create( const std::string& sName) ; // per restituire la lista degli oggetti registrati EGK_EXPORT static bool GetList( STRVECTOR& vsList) ; private : - ObjUserFactory( void) {} - ~ObjUserFactory( void) {} + UserObjFactory( void) {} + ~UserObjFactory( void) {} // definizione del tipo mappa con coppie nome, funzione di creazione - typedef std::unordered_map CreatorMap ; + typedef std::unordered_map CreatorMap ; // metodo di accesso alla mappa statica static CreatorMap& GetCreatorMap( void) ; } ; diff --git a/EGnLuaAux.h b/EGnLuaAux.h index 0af3300..7f66832 100644 --- a/EGnLuaAux.h +++ b/EGnLuaAux.h @@ -62,6 +62,24 @@ LuaGetParam( lua_State* L, int nInd, std::string& sPar) return true ; } +//---------------------------------------------------------------------------- +template +bool +LuaGetParam( lua_State* L, int nInd, int (&nVal)[size]) +{ + if ( ! lua_istable( L, nInd)) + return false ; + for ( int i = 1 ; i <= size ; ++ i) { + lua_rawgeti( L, nInd, i) ; + if ( ! lua_isnumber( L, -1)) + return false ; + double dVal = lua_tonumber( L, -1) ; + nVal[i-1] = int( dVal + (( dVal > 0) ? 0.5 : - 0.5)) ; + lua_pop( L, 1) ; + } + return true ; +} + //---------------------------------------------------------------------------- template bool diff --git a/EGnStringUtils.h b/EGnStringUtils.h index 0b817c4..1471187 100644 --- a/EGnStringUtils.h +++ b/EGnStringUtils.h @@ -165,6 +165,13 @@ ToString( int nVal, int nPrec = 1) sBuff.insert( 0, ( nPrec - nLen), '0') ; return sBuff ; } +template +const std::string ToString( const int (&nVal)[size], int nPrec = 1) + { std::string sDest ; sDest.reserve( 8 * size) ; + for ( const auto& nV : nVal) + sDest += ToString( nV, nPrec) + "," ; + sDest.pop_back() ; + return sDest ; } inline const std::string ToString( bool bVal) { return std::string( ( bVal ? "1" : "0")) ; } @@ -172,8 +179,8 @@ EGN_EXPORT const std::string ToString( double dVal, int nPrec = 6) ; template const std::string ToString( const double (&dVal)[size], int nPrec = 6) { std::string sDest ; sDest.reserve( 14 * size) ; - for ( int i = 0 ; i < size ; ++ i) - sDest += ToString( dVal[i], nPrec) + "," ; + for ( const auto& dV : dVal) + sDest += ToString( dV, nPrec) + "," ; sDest.pop_back() ; return sDest ; } EGN_EXPORT const std::string ToString( const INTVECTOR& vnVal, int nPrec = 1) ; diff --git a/EMkMachMgr.h b/EMkMachMgr.h index a1da5bb..3dbd777 100644 --- a/EMkMachMgr.h +++ b/EMkMachMgr.h @@ -14,6 +14,7 @@ #pragma once #include "/EgtDev/Include/EGkGeomDB.h" +#include "/EgtDev/Include/EGkSelection.h" //----------------------- Macro per import/export ---------------------------- #undef EMK_EXPORT @@ -67,7 +68,7 @@ class __declspec( novtable) IMachMgr virtual bool RotatePartInRawPart( int nPartId, const Vector3d& vtAx, double dAngRotDeg) = 0 ; // Tables and Fixtures virtual bool SetTable( const std::string& sTable) = 0 ; - virtual int AddSubPiece( const std::string& sName, const Point3d& ptPos) = 0 ; + virtual int AddSubPiece( const std::string& sName, const Point3d& ptPos, double dAngRotDeg) = 0 ; // Machine virtual bool SetAxisPos( const std::string& sAxis, double dVal) = 0 ; virtual bool GetAxisPos( const std::string& sAxis, double& dVal) = 0 ; @@ -83,8 +84,9 @@ class __declspec( novtable) IMachMgr int& nStat, double& dX, double& dY, double& dZ) = 0 ; virtual bool VerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) = 0 ; // Operations - virtual int AddDrilling( const std::string& sName) = 0 ; - + virtual int AddMachining( const std::string& sName, const std::string& sMachining) = 0 ; + virtual bool SetMachiningGeometry( const SELVECTOR& vIds) = 0 ; + virtual bool Apply( void) = 0 ; } ; //----------------------------------------------------------------------------- diff --git a/EXeExecutor.h b/EXeExecutor.h index 4c3ae5e..007cbb4 100644 --- a/EXeExecutor.h +++ b/EXeExecutor.h @@ -17,6 +17,7 @@ #include "/EgtDev/Include/EGkColor.h" #include "/EgtDev/Include/EGkPolyLine.h" #include "/EgtDev/Include/EGkPolyArc.h" +#include "/EgtDev/Include/EGkSelection.h" #define NOMINMAX #include @@ -417,7 +418,7 @@ EXE_EXPORT bool ExeRemovePartFromRawPart( int nPartId) ; EXE_EXPORT bool ExeTranslatePartInRawPart( int nPartId, const Vector3d& vtMove) ; EXE_EXPORT bool ExeRotatePartInRawPart( int nPartId, const Vector3d& vtAx, double dAngRotDeg) ; EXE_EXPORT bool ExeSetTable( const std::string& sTable) ; -EXE_EXPORT int ExeAddSubPiece( const std::string& sName, const Point3d& ptPos) ; +EXE_EXPORT int ExeAddSubPiece( const std::string& sName, const Point3d& ptPos, double dAngRotDeg) ; EXE_EXPORT bool ExeSetAxisPos( const std::string& sAxis, double dVal) ; EXE_EXPORT bool ExeGetAxisPos( const std::string& sAxis, double* pdVal) ; EXE_EXPORT bool ExeGetAxisHomePos( const std::string& sAxis, double* pdHomeVal) ; @@ -431,7 +432,9 @@ EXE_EXPORT bool ExeGetCalcAngles( const Vector3d& vtDirT, const Vector3d& vtDirA EXE_EXPORT bool ExeGetCalcPositions( const Point3d& ptP, double dAngA, double dAngB, int& nStat, double& dX, double& dY, double& dZ) ; EXE_EXPORT bool ExeVerifyOutOfStroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) ; -EXE_EXPORT int ExeAddDrilling( const std::string& sName) ; +EXE_EXPORT int ExeAddMachining( const std::string& sName, const std::string& sMachining) ; +EXE_EXPORT bool ExeSetMachiningGeometry( const SELVECTOR& vIds) ; +EXE_EXPORT bool ExeApplyMachining( void) ; // Scene EXE_EXPORT bool ExeInitScene( HWND hWnd, int nDriver, bool b2Buff, int nColorBits, int nDepthBits) ;