diff --git a/EXE_GeoInters.cpp b/EXE_GeoInters.cpp index 822a7eb..82903ca 100644 --- a/EXE_GeoInters.cpp +++ b/EXE_GeoInters.cpp @@ -1005,6 +1005,92 @@ ExePlaneCurveInters( const Point3d& ptOn, const Vector3d& vtN, const int nId, co return nFirstId ; } +//------------------------------------------------------------------------------- +int +MyCurveCurveInters( const int nId1, const int nId2, const int nDestGrpId, int& nCount) +{ + IGeomDB* pGeomDB = GetCurrGeomDB() ; + VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) + + int nFirstId = GDB_ID_NULL ; + + // recupero il riferimento del gruppo di destinazione + Frame3d frDest ; + if ( ! pGeomDB->GetGroupGlobFrame( nDestGrpId, frDest)) + return GDB_ID_NULL ; + + // recupero le curve e le porto nel riferimento del gruppo di destinazione + PtrOwner pCrv1( GetCurve( pGeomDB->GetGeoObj( nId1))->Clone()) ; + if ( IsNull( pCrv1)) + return GDB_ID_NULL ; + Frame3d frCrv1 ; + if ( ! pGeomDB->GetGlobFrame( nId1, frCrv1)) + return GDB_ID_NULL ; + pCrv1->LocToLoc( frCrv1, frDest) ; + + PtrOwner pCrv2( GetCurve( pGeomDB->GetGeoObj( nId2))->Clone()) ; + if ( IsNull( pCrv2)) + return GDB_ID_NULL ; + Frame3d frCrv2 ; + if ( ! pGeomDB->GetGlobFrame( nId2, frCrv2)) + return GDB_ID_NULL ; + pCrv2->LocToLoc( frCrv2, frDest) ; + + // intersezione fra le curve nel piano XY locale + IntersCurveCurve intCC( *pCrv1, *pCrv2, true) ; + int nInters = intCC.GetIntersCount() ; + // recupero i risultati + for ( int i = 0 ; i < nInters ; i++) { + + int nNewId = GDB_ID_NULL ; + IntCrvCrvInfo aInfo ; + intCC.GetIntCrvCrvInfo( i, aInfo) ; + if ( aInfo.bOverlap) { + // è un tratto di curva + PtrOwner pCrvRes( pCrv1->CopyParamRange( aInfo.IciA[0].dU, aInfo.IciA[1].dU)) ; + if ( IsNull( pCrvRes)) + return GDB_ID_NULL ; + // lo inserisco nel DB geometrico + nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( pCrvRes)) ; + } + else { + // è un punto + PtrOwner pGeoPnt( CreateGeoPoint3d()) ; + if ( IsNull( pGeoPnt)) + return GDB_ID_NULL ; + pGeoPnt->Set( aInfo.IciA[0].ptI) ; + // lo inserisco nel DB geometrico + nNewId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( pGeoPnt)) ; + } + + if ( nNewId == GDB_ID_NULL) + return GDB_ID_NULL ; + if ( nFirstId == GDB_ID_NULL) + nFirstId = nNewId ; + ++ nCount ; + } + + return nFirstId ; +} + +//------------------------------------------------------------------------------- +int +ExeCurveCurveInters( const int nId1, const int nId2, const int nDestGrpId, int* pnCount) +{ + // eseguo + int nCount{ 0 } ; + int nFirstId = MyCurveCurveInters( nId1, nId2, nDestGrpId, nCount) ; + // aggiorno contatori + if ( nFirstId != GDB_ID_NULL) { + if ( pnCount != nullptr) + *pnCount = nCount ; + ExeSetModified() ; + } + + // restituisco l'identificativo della prima nuova entità + return nFirstId ; +} + //------------------------------------------------------------------------------- static bool MyLineVolZmapInters( const Point3d& ptP, const Vector3d& vtDir, int nId, int nRefType, INTDBLVECTOR& vInters) diff --git a/EgtExecutor.rc b/EgtExecutor.rc index ec04b43..4ba1e12 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/LUA_GeoInters.cpp b/LUA_GeoInters.cpp index 46a6e5b..30dbdef 100644 --- a/LUA_GeoInters.cpp +++ b/LUA_GeoInters.cpp @@ -244,6 +244,30 @@ LuaPlaneCurveInters( lua_State* L) return 2 ; } +//---------------------------------------------------------------------------- +static int +LuaCurveCurveInters( lua_State* L) +{ + // 3 parametri : nId1, nId2, nDestGrpId + int nId1 ; + LuaCheckParam( L, 1, nId1) + int nId2 ; + LuaCheckParam( L, 2, nId2) + int nDestGrpId ; + LuaCheckParam( L, 3, nDestGrpId) ; + LuaClearStack( L) ; + // eseguo l'intersezione + int nCount = 0 ; + int nNewId = ExeCurveCurveInters( nId1, nId2, nDestGrpId, &nCount) ; + // restituisco il risultato + if ( nNewId != GDB_ID_NULL) + LuaSetParam( L, nNewId) ; + else + LuaSetParam( L) ; + LuaSetParam( L, nCount) ; + return 2 ; +} + //---------------------------------------------------------------------------- static int LuaLineVolZmapInters( lua_State* L) @@ -322,6 +346,7 @@ LuaInstallGeoInters( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtParPlanesSurfTmInters", LuaParPlanesSurfTmInters) ; bOk = bOk && luaMgr.RegisterFunction( "EgtSurfTmSurfTmInters", LuaSurfTmSurfTmInters) ; bOk = bOk && luaMgr.RegisterFunction( "EgtPlaneCurveInters", LuaPlaneCurveInters) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtCurveCurveInters", LuaCurveCurveInters) ; bOk = bOk && luaMgr.RegisterFunction( "EgtLineVolZmapInters", LuaLineVolZmapInters) ; bOk = bOk && luaMgr.RegisterFunction( "EgtPlaneVolZmapInters", LuaPlaneVolZmapInters) ; return bOk ;