//---------------------------------------------------------------------------- // EgalTech 2014-2015 //---------------------------------------------------------------------------- // File : EXE_GeoSnap.cpp Data : 05.05.15 Versione : 1.6e1 // Contenuto : Funzioni di snap ad oggetti del DB geometrico per EXE. // // // // Modifiche : 02.10.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "EXE_Const.h" #include "EXE_Macro.h" #include "GeoTools.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeConst.h" #include "/EgtDev/Include/EGkGeoPoint3d.h" #include "/EgtDev/Include/EGkGeoVector3d.h" #include "/EgtDev/Include/EGkVolZmap.h" #include "/EgtDev/Include/EGkExtText.h" #include "/EgtDev/Include/EGkDistPointCurve.h" #include "/EgtDev/Include/EGkIntersCurves.h" //---------------------------------------------------------------------------- bool ExeStartPoint( int nId, int nRefId, Point3d& ptP) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) return false ; // se punto if ( pGObj->GetType() == GEO_PNT3D) { // recupero il geo-punto const IGeoPoint3d* pGP = GetGeoPoint3d( pGObj) ; // assegno il punto ptP = pGP->GetPoint() ; } // se vettore else if ( pGObj->GetType() == GEO_VECT3D) { // recupero il geo-vettore const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ; // assegno il punto ptP = pGV->GetBase() ; } // se frame else if ( pGObj->GetType() == GEO_FRAME3D) { // recupero il frame const IGeoFrame3d* pGF = GetGeoFrame3d( pGObj) ; // assegno il punto ptP = pGF->GetFrame().Orig() ; } // se curva else if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // assegno il punto if ( pCrv == nullptr || ! pCrv->GetStartPoint( ptP)) return false ; } // se testo else if ( pGObj->GetType() == EXT_TEXT) { // recupero il testo const IExtText* pTxt = GetExtText( pGObj) ; // assegno il punto if ( pTxt == nullptr || ! pTxt->GetStartPoint( ptP)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId, nRefId, ptP) ; } //---------------------------------------------------------------------------- bool ExeEndPoint( int nId, int nRefId, Point3d& ptP) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) return false ; // se vettore if ( pGObj->GetType() == GEO_VECT3D) { // recupero il geo-vettore const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ; // assegno il punto ptP = pGV->GetBase() + pGV->GetVector() ; } // se curva else if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; if ( pCrv == nullptr || ! pCrv->GetEndPoint( ptP)) return false ; } // se testo else if ( pGObj->GetType() == EXT_TEXT) { // recupero il testo const IExtText* pTxt = GetExtText( pGObj) ; if ( pTxt == nullptr || ! pTxt->GetEndPoint( ptP)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId, nRefId, ptP) ; } //---------------------------------------------------------------------------- bool ExeMidPoint( int nId, int nRefId, Point3d& ptP) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) return false ; // se curva if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // assegno il punto if ( pCrv == nullptr || ! pCrv->GetMidPoint( ptP)) return false ; } // se testo else if ( pGObj->GetType() == EXT_TEXT) { // recupero il testo const IExtText* pTxt = GetExtText( pGObj) ; // assegno il punto if ( pTxt == nullptr || ! pTxt->GetMidPoint( ptP)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId, nRefId, ptP) ; } //---------------------------------------------------------------------------- bool ExeCenterPoint( int nId, int nRefId, Point3d& ptP) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) return false ; // se curva if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // assegno il punto if ( pCrv == nullptr || ! pCrv->GetCenterPoint( ptP)) return false ; } // se superficie regione piana else if ( pGObj->GetType() == SRF_FLATRGN) { // recupero la regione const ISurfFlatRegion* pSfr = GetSurfFlatRegion( pGObj) ; // assegno il punto if ( pSfr == nullptr || ! pSfr->GetCentroid( ptP)) return false ; } // se testo else if ( pGObj->GetType() == EXT_TEXT) { // recupero il testo const IExtText* pTxt = GetExtText( pGObj) ; // assegno il punto if ( pTxt == nullptr || ! pTxt->GetCenterPoint( ptP)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId, nRefId, ptP) ; } //---------------------------------------------------------------------------- bool ExeCentroid( int nId, int nRefId, Point3d& ptP) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) return false ; // se curva if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // assegno il punto if ( pCrv == nullptr || ! pCrv->GetCentroid( ptP)) return false ; } // se superficie else if ( ( pGObj->GetType() & GEO_SURF) != 0) { // recupero la superficie const ISurf* pSrf = GetSurf( pGObj) ; // assegno il punto if ( pSrf == nullptr || ! pSrf->GetCentroid( ptP)) return false ; } // se testo else if ( pGObj->GetType() == EXT_TEXT) { // recupero il testo const IExtText* pTxt = GetExtText( pGObj) ; // assegno il punto if ( pTxt == nullptr || ! pTxt->GetCenterPoint( ptP)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId, nRefId, ptP) ; } //---------------------------------------------------------------------------- bool ExeAtParamPoint( int nId, double dU, int nRefId, Point3d& ptP) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) return false ; // se curva if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; if ( pCrv == nullptr || ! pCrv->GetPointD1D2( dU, ICurve::FROM_MINUS, ptP)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId, nRefId, ptP) ; } //---------------------------------------------------------------------------- bool ExeNearPoint( int nId, const Point3d& ptNear, int nRefId, Point3d& ptP) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ; if ( pGObj == nullptr) return false ; // porto il punto near nel riferimento dell'entità Point3d ptNearL = ptNear ; if ( ! InvTransformPoint( pGeomDB, nId, nRefId, ptNearL)) return false ; // se curva if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // calcolo il punto della curva più vicino al punto di riferimento DistPointCurve dstPC( ptNearL, *pCrv) ; int nFlag ; if ( ! dstPC.GetMinDistPoint( 0, ptP, nFlag)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId, nRefId, ptP) ; } //---------------------------------------------------------------------------- bool ExeIntersectionPoint( int nId1, int nId2, const Point3d& ptNear, int nRefId, Point3d& ptP) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se auto-intersezione if ( nId1 == nId2) { // deve essere entità geometriche const IGeoObj* pGObj1 ; if ( ( pGObj1 = pGeomDB->GetGeoObj( nId1)) == nullptr) return false ; // se curva if ( ( pGObj1->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv1 = GetCurve( pGObj1) ; // porto il punto Near nel riferimento dell'entità Point3d ptNearL = ptNear ; if ( ! InvTransformPoint( pGeomDB, nId1, nRefId, ptNearL)) return false ; // calcolo il punto di auto-intersezione sulla curva più vicino al punto di riferimento SelfIntersCurve sintC( *pCrv1) ; if ( ! sintC.GetIntersPointNearTo( ptNearL, ptP)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId1, nRefId, ptP) ; } // devono essere entità geometriche const IGeoObj* pGObj1 ; if ( ( pGObj1 = pGeomDB->GetGeoObj( nId1)) == nullptr) return false ; const IGeoObj* pGObj2 ; if ( ( pGObj2 = pGeomDB->GetGeoObj( nId2)) == nullptr) return false ; // se curve if ( ( pGObj1->GetType() & GEO_CURVE) != 0 && ( pGObj2->GetType() & GEO_CURVE) != 0) { // recupero le curve const ICurve* pCrv1 = GetCurve( pGObj1) ; const ICurve* pCrv2 = GetCurve( pGObj2) ; // recupero i riferimenti in cui sono immerse Frame3d frEnt1 ; if ( ! pGeomDB->GetGlobFrame( nId1, frEnt1)) return false ; Frame3d frEnt2 ; if ( ! pGeomDB->GetGlobFrame( nId2, frEnt2)) return false ; // se il riferimento della seconda curva è diverso da quello della prima entità, devo trasformarla PtrOwner pcrvTrans ; if ( ! AreSameFrame( frEnt1, frEnt2)) { pcrvTrans.Set( pCrv2->Clone()) ; if ( IsNull( pcrvTrans)) return false ; pcrvTrans->LocToLoc( frEnt2, frEnt1) ; pCrv2 = pcrvTrans ; } // porto il punto Near nel riferimento della prima entità Point3d ptNearL = ptNear ; if ( ! InvTransformPoint( pGeomDB, nId1, nRefId, ptNearL)) return false ; // calcolo il punto di intersezione sulla prima curva più vicino al punto di riferimento IntersCurveCurve intCC( *pCrv1, *pCrv2, true) ; if ( ! intCC.GetIntersPointNearTo( 0, ptNearL, ptP)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformPoint( pGeomDB, nId1, nRefId, ptP) ; } //---------------------------------------------------------------------------- bool ExeStartVector( int nId, int nRefId, Vector3d& vtV) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ; if ( pGObj == nullptr) return false ; // se vettore if ( pGObj->GetType() == GEO_VECT3D) { // recupero il geo-vettore const IGeoVector3d* pGV = GetGeoVector3d( pGObj) ; // assegno il vettore vtV = pGV->GetVector() ; } // se curva else if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // assegno il vettore if ( ! pCrv->GetStartDir( vtV)) return false ; } // se testo else if ( pGObj->GetType() == EXT_TEXT) { // recupero il testo const IExtText* pTxt = GetExtText( pGObj) ; // assegno il vettore vtV = pTxt->GetDirVersor() ; } else return false ; // gestione trasformazione ( eventuale) return TransformVector( pGeomDB, nId, nRefId, vtV) ; } //---------------------------------------------------------------------------- bool ExeEndVector( int nId, int nRefId, Vector3d& vtV) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj = pGeomDB->GetGeoObj( nId) ; if ( pGObj == nullptr) return false ; // se curva if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // assegno il vettore if ( ! pCrv->GetEndDir( vtV)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformVector( pGeomDB, nId, nRefId, vtV) ; } //---------------------------------------------------------------------------- bool ExeMidVector( int nId, int nRefId, Vector3d& vtV) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) return false ; // se curva if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // assegno il vettore if ( ! pCrv->GetMidDir( vtV)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformVector( pGeomDB, nId, nRefId, vtV) ; } //---------------------------------------------------------------------------- bool ExeAtParamVector( int nId, double dU, int nSide, int nRefId, Vector3d& vtV) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se non è entità geometrica const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) == nullptr) return false ; // se curva if ( ( pGObj->GetType() & GEO_CURVE) != 0) { // recupero la curva const ICurve* pCrv = GetCurve( pGObj) ; // assegno il lato di approccio ICurve::Side nCrvSide = ( nSide > 0 ? ICurve::FROM_PLUS : ICurve::FROM_MINUS) ; // recupero la direzione Point3d ptP ; if ( ! pCrv->GetPointTang( dU, nCrvSide, ptP, vtV)) return false ; } else return false ; // gestione trasformazione ( eventuale) return TransformVector( pGeomDB, nId, nRefId, vtV) ; } //---------------------------------------------------------------------------- bool ExeFrame( int nId, int nRefId, Frame3d& frFrame) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se gruppo if ( pGeomDB->GetGroupFrame( nId, frFrame)) // gestione trasformazione ( eventuale) return TransformFrame( pGeomDB, nId, nRefId, frFrame) ; // se geo frame const IGeoObj* pGObj ; if ( ( pGObj = pGeomDB->GetGeoObj( nId)) != nullptr && pGObj->GetType() == GEO_FRAME3D) { frFrame = GetGeoFrame3d( pGObj)->GetFrame() ; // gestione trasformazione ( eventuale) return TransformFrame( pGeomDB, nId, nRefId, frFrame) ; } // errore return false ; } //------------------------------------------------------------------------------- // Geo Transforms //------------------------------------------------------------------------------- bool ExePointToIdGlob( Point3d& ptP, int nId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se griglia if ( nId == GDB_ID_GRID) return ptP.ToGlob( pGeomDB->GetGridFrame()) ; // recupero il riferimento // se gruppo -> il suo proprio espresso in globale // se oggetto -> quello del gruppo cui appartiene in globale Frame3d frRef ; if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) && ! pGeomDB->GetGlobFrame( nId, frRef)) return false ; // eseguo la trasformazione return ptP.ToGlob( frRef) ; } //------------------------------------------------------------------------------- bool ExePointToIdLoc( Point3d& ptP, int nId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se griglia if ( nId == GDB_ID_GRID) return ptP.ToLoc( pGeomDB->GetGridFrame()) ; // recupero il riferimento // se gruppo -> il suo proprio espresso in globale // se oggetto -> quello del gruppo cui appartiene in globale Frame3d frRef ; if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) && ! pGeomDB->GetGlobFrame( nId, frRef)) return false ; // eseguo la trasformazione return ptP.ToLoc( frRef) ; } //------------------------------------------------------------------------------- bool ExeVectorToIdGlob( Vector3d& vtV, int nId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se griglia if ( nId == GDB_ID_GRID) return vtV.ToGlob( pGeomDB->GetGridFrame()) ; // recupero il riferimento // se gruppo -> il suo proprio espresso in globale // se oggetto -> quello del gruppo cui appartiene in globale Frame3d frRef ; if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) && ! pGeomDB->GetGlobFrame( nId, frRef)) return false ; // eseguo la trasformazione return vtV.ToGlob( frRef) ; } //------------------------------------------------------------------------------- bool ExeVectorToIdLoc( Vector3d& vtV, int nId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // se griglia if ( nId == GDB_ID_GRID) return vtV.ToLoc( pGeomDB->GetGridFrame()) ; // recupero il riferimento // se gruppo -> il suo proprio espresso in globale // se oggetto -> quello del gruppo cui appartiene in globale Frame3d frRef ; if ( ! pGeomDB->GetGroupGlobFrame( nId, frRef) && ! pGeomDB->GetGlobFrame( nId, frRef)) return false ; // eseguo la trasformazione return vtV.ToLoc( frRef) ; }