//---------------------------------------------------------------------------- // EgalTech 2015-2016 //---------------------------------------------------------------------------- // File : MachMgrParts.cpp Data : 16.04.15 Versione : 1.6d3 // Contenuto : Implementazione gestione pezzi della classe MachMgr. // // // // Modifiche : 16.04.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "DllMain.h" #include "MachMgr.h" #include "MachConst.h" #include "/EgtDev/Include/EGkGdbIterator.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; //---------------------------------------------------------------------------- int MachMgr::GetPartInRawPartCount( int nRawId) const { // verifica validità grezzo if ( ! VerifyRawPart( nRawId)) return 0 ; // conto i gruppi appartenenti al grezzo (sono i pezzi) PtrOwner pIter( CreateGdbIterator( m_pGeomDB)) ; if ( IsNull( pIter)) return 0 ; int nPartCount = 0 ; bool bIter = pIter->GoToFirstGroupInGroup( nRawId) ; while ( bIter) { ++ nPartCount ; bIter = pIter->GoToNextGroup() ; } // ritorno numero dei pezzi nel grezzo return nPartCount ; } //---------------------------------------------------------------------------- int MachMgr::GetFirstPartInRawPart( int nRawId) const { // verifica validità grezzo if ( ! VerifyRawPart( nRawId)) return GDB_ID_NULL ; // cerco il primo gruppo appartenente al grezzo return m_pGeomDB->GetFirstGroupInGroup( nRawId) ; } //---------------------------------------------------------------------------- int MachMgr::GetNextPartInRawPart( int nId) const { // verifico validita GeomDB if ( m_pGeomDB == nullptr) return GDB_ID_NULL ; // verifico che il pezzo appartenga ad un grezzo della macchinata corrente int nRawId = m_pGeomDB->GetParentId( nId) ; if ( ! VerifyRawPart( nRawId)) return GDB_ID_NULL ; // cerco il prossimo gruppo appartenente allo stesso grezzo return m_pGeomDB->GetNextGroup( nId) ; } //---------------------------------------------------------------------------- bool MachMgr::AddPartToRawPart( int nPartId, const Point3d& ptPos, int nRawId) { // verifica validità grezzo if ( ! VerifyRawPart( nRawId)) return false ; // verifico che il pezzo sia tale e non sia già usato nella macchinata corrente int nLevel ; if ( m_pGeomDB->GetGdbType( nPartId) != GDB_TY_GROUP || m_pGeomDB->GetParentId( nPartId) != GDB_ID_ROOT || ( m_pGeomDB->GetCalcLevel( nPartId, nLevel) && nLevel != GDB_LV_USER)) return false ; // recupero il box del solido del grezzo in locale int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; BBox3d b3RawSolid ; if ( ! m_pGeomDB->GetLocalBBox( nRawSolidId, b3RawSolid)) return false ; // recupero box del pezzo BBox3d b3Part ; if ( ! m_pGeomDB->GetGlobalBBox( nPartId, b3Part, BBF_EXACT)) return false ; // recupero il riferimento del pezzo Frame3d frPart ; m_pGeomDB->GetGroupGlobFrame( nPartId, frPart) ; // muovo riferimento del pezzo per posizionare correttamente nel grezzo Vector3d vtMove = b3RawSolid.GetMin() + ptPos - b3Part.GetMin() ; frPart.Translate( vtMove) ; // inserisco il pezzo int nGroup = m_pGeomDB->AddGroup( GDB_ID_NULL, nRawId, frPart) ; if ( nGroup == GDB_ID_NULL || ! m_pGeomDB->GroupSwap( nPartId, nGroup, true, true)) return false ; // impongo il livello system al gruppo m_pGeomDB->SetLevel( nGroup, GDB_LV_SYSTEM) ; // mi assicuro sia visibile il pezzo e nascosto il gruppo m_pGeomDB->SetStatus( nPartId, GDB_ST_ON) ; m_pGeomDB->SetStatus( nGroup, GDB_ST_OFF) ; return true ; } //---------------------------------------------------------------------------- int MachMgr::GetRawPartFromPart( int nPartId) { // verifico DB geometrico if ( m_pGeomDB == nullptr) return false ; // recupero l'indice del grezzo int nRawId = m_pGeomDB->GetParentId( nPartId) ; // verifica validità grezzo if ( ! VerifyRawPart( nRawId)) return GDB_ID_NULL ; return nRawId ; } //---------------------------------------------------------------------------- bool MachMgr::RemovePartFromRawPart( int nPartId) { // verifico DB geometrico if ( m_pGeomDB == nullptr) return false ; // recupero l'indice del grezzo int nRawId = m_pGeomDB->GetParentId( nPartId) ; // verifica validità grezzo if ( ! VerifyRawPart( nRawId)) return false ; // devo riportare il pezzo in lista generale int nBase ; if ( m_pGeomDB->GetInfo( nPartId, GDB_SI_BASE, nBase)) { // eseguo lo scambio m_pGeomDB->GroupSwap( nPartId, nBase, true, true) ; // mi assicuro sia nascosto m_pGeomDB->SetStatus( nPartId, GDB_ST_OFF) ; // cancello il gruppo di riferimento m_pGeomDB->Erase( nBase) ; return true ; } return false ; } //---------------------------------------------------------------------------- bool MachMgr::TranslatePartInRawPart( int nPartId, const Vector3d& vtMove) { // verifico DB geometrico if ( m_pGeomDB == nullptr) return false ; // recupero l'indice del grezzo int nRawId = m_pGeomDB->GetParentId( nPartId) ; // verifica validità grezzo if ( ! VerifyRawPart( nRawId)) return false ; // eseguo traslazione in globale return m_pGeomDB->TranslateGlob( nPartId, vtMove) ; } //---------------------------------------------------------------------------- bool MachMgr::RotatePartInRawPart( int nPartId, const Vector3d& vtAx, double dAngRotDeg) { // verifico DB geometrico if ( m_pGeomDB == nullptr) return false ; // recupero l'indice del grezzo int nRawId = m_pGeomDB->GetParentId( nPartId) ; // verifica validità grezzo if ( ! VerifyRawPart( nRawId)) return false ; // recupero riferimento globale del pezzo Frame3d frRef ; if ( ! m_pGeomDB->GetGroupGlobFrame( nPartId, frRef)) return false ; // recupero box del pezzo in locale (non cambia con la giacitura globale) BBox3d b3Box ; if ( ! m_pGeomDB->GetLocalBBox( nPartId, b3Box, BBF_EXACT)) return false ; // ne calcolo il centro e lo porto in globale Point3d ptCen ; b3Box.GetCenter( ptCen) ; ptCen.ToGlob( frRef) ; // eseguo rotazione in globale attorno al centro del pezzo return m_pGeomDB->RotateGlob( nPartId, ptCen, vtAx, dAngRotDeg) ; } //---------------------------------------------------------------------------- bool MachMgr::SwapParts( bool bToRawPart) { // recupero il gruppo dei grezzi correnti int nRawGroupId = GetCurrRawGroupId() ; if ( nRawGroupId == GDB_ID_NULL) return true ; // ciclo sui grezzi int nRawId = m_pGeomDB->GetFirstGroupInGroup( nRawGroupId) ; while ( nRawId != GDB_ID_NULL) { // sistemo i pezzi del grezzo SwapRawPartParts( nRawId, bToRawPart) ; // passo al successivo nRawId = m_pGeomDB->GetNextGroup( nRawId) ; } return true ; } //---------------------------------------------------------------------------- bool MachMgr::SwapRawPartParts( int nRawId, bool bToRawPart) { // ciclo sui gruppi nel grezzo int nId = m_pGeomDB->GetFirstGroupInGroup( nRawId) ; while ( nId != GDB_ID_NULL) { // recupero il successivo int nNextId = m_pGeomDB->GetNextGroup( nId) ; // eseguo lo swap del pezzo SwapRawPartPart( nId, bToRawPart) ; // passo al successivo nId = nNextId ; } return true ; } //---------------------------------------------------------------------------- int MachMgr::SwapRawPartPart( int nId, bool bToRawPart) { // se devo portare i pezzi dalla radice al grezzo if ( bToRawPart) { // se è un riferimento al pezzo int nSou ; if ( m_pGeomDB->GetInfo( nId, GDB_SI_SOURCE, nSou)) { m_pGeomDB->GroupSwap( nSou, nId, true, true) ; // mi assicuro sia visibile m_pGeomDB->SetStatus( nSou, GDB_ST_ON) ; return nSou ; } } // altrimenti dal grezzo alla radice else { // se è un pezzo spostato int nBase ; if ( m_pGeomDB->GetInfo( nId, GDB_SI_BASE, nBase)) { m_pGeomDB->GroupSwap( nId, nBase, true, true) ; // mi assicuro sia nascosto e di livello utente m_pGeomDB->SetStatus( nId, GDB_ST_OFF) ; m_pGeomDB->SetLevel( nId, GDB_LV_USER) ; return nBase ; } } return GDB_ID_NULL ; } //---------------------------------------------------------------------------- bool MachMgr::ShowRootParts( bool bShow) { // ciclo sui gruppi in radice int nId = m_pGeomDB->GetFirstGroupInGroup( GDB_ID_ROOT) ; while ( nId != GDB_ID_NULL) { // se pezzo, lo nascondo int nLevel ; if ( m_pGeomDB->GetCalcLevel( nId, nLevel) && nLevel == GDB_LV_USER) m_pGeomDB->SetStatus( nId, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ; // passo al successivo nId = m_pGeomDB->GetNextGroup( nId) ; } return true ; }