Files
EgtExecutor/LUA_GdbModifyVol.cpp
T
Dario Sassi 93c77cb786 EgtExecutor :
- piccole migliorie stilistiche.
2019-08-06 09:31:57 +00:00

474 lines
15 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2016-2017
//----------------------------------------------------------------------------
// File : LUA_GdbModifyVol.cpp Data : 09.03.17 Versione : 1.8c4
// Contenuto : Funzioni di modifica dei solidi per LUA.
//
//
//
// Modifiche : 27.10.16 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"
using namespace std ;
//-------------------------------------------------------------------------------
static int
LuaExplodeVolume( lua_State* L)
{
// 1 parametro : Id
int nId ;
LuaCheckParam( L, 1, nId)
LuaClearStack( L) ;
// esplosione del solido
int nCount ;
int nFirstId = ExeExplodeVolume( nId, &nCount) ;
if ( nFirstId != GDB_ID_NULL)
LuaSetParam( L, nFirstId) ;
else
LuaSetParam( L) ;
LuaSetParam( L, nCount) ;
return 2 ;
}
//----------------------------------------------------------------------------
static int
LuaCopyVolZmapPart( lua_State* L)
{
// 3 parametri : Id, nPart(0-based), nDestGrpId
int nId ;
LuaCheckParam( L, 1, nId)
int nPart ;
LuaCheckParam( L, 2, nPart)
int nDestGrpId ;
LuaCheckParam( L, 3, nDestGrpId)
LuaClearStack( L) ;
// copio la parte indicata nel gruppo specificato
int nNewId = ExeCopyVolZmapPart( nId, nPart, nDestGrpId) ;
// restituisco il risultato
if ( nNewId != GDB_ID_NULL)
LuaSetParam( L, nNewId) ;
else
LuaSetParam( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaRemoveVolZmapPart( lua_State* L)
{
// 2 parametri : Id, nPart(0-based)
int nId ;
LuaCheckParam( L, 1, nId)
int nPart ;
LuaCheckParam( L, 2, nPart)
LuaClearStack( L) ;
// rimuovo la parte indicata
bool bOk = ExeRemoveVolZmapPart( nId, nPart) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapSetStdTool( lua_State* L)
{
// 5 o 6 parametri : vIds, sToolName, dLen, dDiam, dCornR, nFlag
INTVECTOR vIds ;
LuaCheckParam( L, 1, vIds)
string sToolName ;
LuaCheckParam( L, 2, sToolName)
double dLen ;
LuaCheckParam( L, 3, dLen)
double dDiam ;
LuaCheckParam( L, 4, dDiam)
double dCornR ;
LuaCheckParam( L, 5, dCornR)
int nFlag = 1 ;
LuaGetParam( L, 6, nFlag) ;
LuaClearStack( L) ;
// imposto utensile standard a Zmap indicati
bool bOk = ExeVolZmapSetStdTool( vIds, sToolName, dLen, dDiam, dCornR, nFlag) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapSetAdvTool( lua_State* L)
{
// 7 o 8 parametri : vIds, sToolName, dLen, dDiam, dTipLen, dTipDiam, dCornR, nFlag
INTVECTOR vIds ;
LuaCheckParam( L, 1, vIds)
string sToolName ;
LuaCheckParam( L, 2, sToolName)
double dLen ;
LuaCheckParam( L, 3, dLen)
double dDiam ;
LuaCheckParam( L, 4, dDiam)
double dTipLen ;
LuaCheckParam( L, 5, dTipLen)
double dTipDiam ;
LuaCheckParam( L, 6, dTipDiam)
double dCornR ;
LuaCheckParam( L, 7, dCornR)
int nFlag = 1 ;
LuaGetParam( L, 8, nFlag) ;
LuaClearStack( L) ;
// imposto utensile avanzato a Zmap indicati
bool bOk = ExeVolZmapSetAdvTool( vIds, sToolName, dLen, dDiam, dTipLen, dTipDiam, dCornR, nFlag) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapSetSawTool( lua_State* L)
{
// 7 o 8 parametri : vIds, sToolName, dLen, dDiam, dThick, dStemDiam, dCornR, nFlag
INTVECTOR vIds ;
LuaCheckParam( L, 1, vIds)
string sToolName ;
LuaCheckParam( L, 2, sToolName)
double dLen ;
LuaCheckParam( L, 3, dLen)
double dDiam ;
LuaCheckParam( L, 4, dDiam)
double dThick ;
LuaCheckParam( L, 5, dThick)
double dStemDiam ;
LuaCheckParam( L, 6, dStemDiam)
double dCornR ;
LuaCheckParam( L, 7, dCornR)
int nFlag = 1 ;
LuaGetParam( L, 8, nFlag) ;
LuaClearStack( L) ;
// imposto utensile avanzato a Zmap indicati
bool bOk = ExeVolZmapSetSawTool( vIds, sToolName, dLen, dDiam, dThick, dStemDiam, dCornR, nFlag) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapSetGenTool( lua_State* L)
{
// 3 o 4 parametri : vIds, sToolName, ToolSectId, nFlag
INTVECTOR vIds ;
LuaCheckParam( L, 1, vIds)
string sToolName ;
LuaCheckParam( L, 2, sToolName)
int nToolSectId ;
LuaCheckParam( L, 3, nToolSectId)
int nFlag = 1 ;
LuaGetParam( L, 4, nFlag) ;
LuaClearStack( L) ;
// imposto utensile generico a Zmap indicati
bool bOk = ExeVolZmapSetGenTool( vIds, sToolName, nToolSectId, nFlag) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapSetMortiserTool( lua_State* L)
{
// 6 o 7 parametri : Id, sToolName, dLen, dWidth, dThick, dCornR, nFlag
INTVECTOR vIds ;
LuaCheckParam( L, 1, vIds)
string sToolName ;
LuaCheckParam( L, 2, sToolName)
double dLen ;
LuaCheckParam( L, 3, dLen)
double dWidth ;
LuaCheckParam( L, 4, dWidth)
double dThick ;
LuaCheckParam( L, 5, dThick)
double dCornR ;
LuaCheckParam( L, 6, dCornR)
int nFlag = 1 ;
LuaGetParam( L, 7, nFlag) ;
LuaClearStack( L) ;
// imposto mortasatrice a Zmap indicati
bool bOk = ExeVolZmapSetMortiserTool( vIds, sToolName, dLen, dWidth, dThick, dCornR, nFlag) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapSetChiselTool( lua_State* L)
{
// 5 o 6 parametri : vIds, sToolName, dLen, dWidth, dThick, nFlag
INTVECTOR vIds ;
LuaCheckParam( L, 1, vIds)
string sToolName ;
LuaCheckParam( L, 2, sToolName)
double dLen ;
LuaCheckParam( L, 3, dLen)
double dWidth ;
LuaCheckParam( L, 4, dWidth)
double dThick ;
LuaCheckParam( L, 5, dThick)
int nFlag = 1 ;
LuaGetParam( L, 6, nFlag) ;
LuaClearStack( L) ;
// imposto scalpello a Zmap indicati
bool bOk = ExeVolZmapSetChiselTool( vIds, sToolName, dLen, dWidth, dThick, nFlag) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapResetTool( lua_State* L)
{
// 1 parametro : vIds
INTVECTOR vIds ;
LuaCheckParam( L, 1, vIds)
LuaClearStack( L) ;
// reset utensile a Zmap indicati
bool bOk = ExeVolZmapResetTool( vIds) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapGetToolOutline( lua_State* L)
{
// 2 o 3 parametri : nId, nDestGrpId [, bApprox]
int nId ;
LuaCheckParam( L, 1, nId)
int nDestGrpId ;
LuaCheckParam( L, 2, nDestGrpId)
bool bApprox = false ;
LuaGetParam( L, 3, bApprox) ;
LuaClearStack( L) ;
// recupero il profilo dell'utensile associato a Zmap indicato
int nNewId = ExeVolZmapGetToolOutline( nId, nDestGrpId, bApprox) ;
// restituisco il risultato
if ( nNewId != GDB_ID_NULL)
LuaSetParam( L, nNewId) ;
else
LuaSetParam( L) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapMillingStep( lua_State* L)
{
// 5 o 6 o 7 o 8 parametri : nId, ptPs, vtDs [, vtAs], ptPe, vtDe [, vtAe], [, nRefType]
int n = lua_gettop( L) ;
if ( n == 5 || n == 6) {
int nId ;
LuaCheckParam( L, 1, nId)
Point3d ptPs ;
LuaCheckParam( L, 2, ptPs)
Vector3d vtDs ;
LuaCheckParam( L, 3, vtDs)
Point3d ptPe ;
LuaCheckParam( L, 4, ptPe)
Vector3d vtDe ;
LuaCheckParam( L, 5, vtDe)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 6, nRefType) ;
LuaClearStack( L) ;
// eseguo movimento di fresatura con l'utensile già associato a Zmap
bool bOk = ExeVolZmapMillingStep( nId, ptPs, vtDs, ptPe, vtDe, nRefType) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
else {
int nId ;
LuaCheckParam( L, 1, nId)
Point3d ptPs ;
LuaCheckParam( L, 2, ptPs)
Vector3d vtDs ;
LuaCheckParam( L, 3, vtDs)
Vector3d vtAs ;
LuaCheckParam( L, 4, vtAs)
Point3d ptPe ;
LuaCheckParam( L, 5, ptPe)
Vector3d vtDe ;
LuaCheckParam( L, 6, vtDe)
Vector3d vtAe ;
LuaCheckParam( L, 7, vtAe)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 8, nRefType) ;
LuaClearStack( L) ;
// eseguo movimento di fresatura con l'utensile già associato a Zmap
bool bOk = ExeVolZmapMillingStep( nId, ptPs, vtDs, vtAs, ptPe, vtDe, vtAe, nRefType) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
}
//----------------------------------------------------------------------------
static int
LuaVolZmapGetDepth( lua_State* L)
{
// 3 o 4 o 5 parametri : nId, ptP, vtDir [, nRefType] [, bExact]
int nId ;
LuaCheckParam( L, 1, nId)
Point3d ptP ;
LuaCheckParam( L, 2, ptP)
Vector3d vtDir ;
LuaCheckParam( L, 3, vtDir)
int nRefType = RTY_DEFAULT ;
bool bExact = false ;
if ( LuaGetParam( L, 4, nRefType))
LuaGetParam( L, 5, bExact) ;
else
LuaGetParam( L, 4, bExact) ;
LuaClearStack( L) ;
// eseguo calcolo profondità dal punto lungo la direzione
double dLen1, dLen2 ;
bool bOk = ExeVolZmapGetDepth( nId, ptP, vtDir, nRefType, bExact, dLen1, dLen2) ;
// restituisco il risultato
if ( bOk) {
LuaSetParam( L, dLen1) ;
LuaSetParam( L, dLen2) ;
}
else {
LuaSetParam( L) ;
LuaSetParam( L) ;
}
return 2 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapAvoidBox( lua_State* L)
{
// 4 o 5 parametri : nId, frBox, vtDiag, dSafeDist [, nRefType]
int nId ;
LuaCheckParam( L, 1, nId)
Frame3d frBox ;
LuaCheckParam( L, 2, frBox)
Vector3d vtDiag ;
LuaCheckParam( L, 3, vtDiag)
double dSafeDist ;
LuaCheckParam( L, 4, dSafeDist)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 5, nRefType) ;
LuaClearStack( L) ;
// verifico non interferenza
bool bOk = ExeVolZmapAvoidBox( nId, frBox, vtDiag, dSafeDist, nRefType) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapAvoidCylinder( lua_State* L)
{
// 5 o 6 parametri : nId, frCyl, dL, dR, dSafeDist [, nRefType]
int nId ;
LuaCheckParam( L, 1, nId)
Frame3d frCyl ;
LuaCheckParam( L, 2, frCyl)
double dL ;
LuaCheckParam( L, 3, dL)
double dR ;
LuaCheckParam( L, 4, dR)
double dSafeDist ;
LuaCheckParam( L, 5, dSafeDist)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 6, nRefType) ;
LuaClearStack( L) ;
// verifico non interferenza
bool bOk = ExeVolZmapAvoidCylinder( nId, frCyl, dL, dR, dSafeDist, nRefType) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaVolZmapAvoidSphere( lua_State* L)
{
// 4 o 5 parametri : nId, ptCen, dRad, dSafeDist [, nRefType]
int nId ;
LuaCheckParam( L, 1, nId)
Point3d ptCen ;
LuaCheckParam( L, 2, ptCen)
double dRad ;
LuaCheckParam( L, 3, dRad)
double dSafeDist ;
LuaCheckParam( L, 4, dSafeDist)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 5, nRefType) ;
LuaClearStack( L) ;
// verifico non interferenza
bool bOk = ExeVolZmapAvoidSphere( nId, ptCen, dRad, dSafeDist, nRefType) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//----------------------------------------------------------------------------
static int
LuaCutVolZmapPlane( lua_State* L)
{
// 3 o 4 parametri : Id, ptOn, vtN [, nRefType]
int nId ;
LuaCheckParam( L, 1, nId)
Point3d ptOn ;
LuaCheckParam( L, 2, ptOn)
Vector3d vtN ;
LuaCheckParam( L, 3, vtN)
int nRefType = RTY_DEFAULT ;
LuaGetParam( L, 4, nRefType) ;
LuaClearStack( L) ;
// taglio la superficie con ilpiano
bool bOk = ExeCutVolZmapPlane( nId, ptOn, vtN, nRefType) ;
// restituisco il risultato
LuaSetParam( L, bOk) ;
return 1 ;
}
//-------------------------------------------------------------------------------
bool
LuaInstallGdbModifyVol( LuaMgr& luaMgr)
{
bool bOk = ( &luaMgr != nullptr) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtExplodeVolume", LuaExplodeVolume) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtCopyVolZmapPart", LuaCopyVolZmapPart) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtRemoveVolZmapPart", LuaRemoveVolZmapPart) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetStdTool", LuaVolZmapSetStdTool) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetAdvTool", LuaVolZmapSetAdvTool) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetSawTool", LuaVolZmapSetSawTool) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetGenTool", LuaVolZmapSetGenTool) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetMortiserTool", LuaVolZmapSetMortiserTool) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapSetChiselTool", LuaVolZmapSetChiselTool) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapResetTool", LuaVolZmapResetTool) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetToolOutline", LuaVolZmapGetToolOutline) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapMillingStep", LuaVolZmapMillingStep) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapGetDepth", LuaVolZmapGetDepth) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapAvoidBox", LuaVolZmapAvoidBox) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapAvoidCylinder", LuaVolZmapAvoidCylinder) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtVolZmapAvoidSphere", LuaVolZmapAvoidSphere) ;
bOk = bOk && luaMgr.RegisterFunction( "EgtCutVolZmapPlane", LuaCutVolZmapPlane) ;
return bOk ;
}