EgtExchange 1.5h5 :

- export DXF di curve di Bezier piane ora come archi
- export DXF di STM ora POLYMESH se vert. e facce < 16567, altrimenti 3DFACE
- import DXF migliorato controlli su SPLINE collassate in un punto.
This commit is contained in:
Dario Sassi
2014-08-19 20:22:28 +00:00
parent 3657faed50
commit 7bdf2e9c7f
5 changed files with 154 additions and 100 deletions
BIN
View File
Binary file not shown.
+125 -73
View File
@@ -199,7 +199,7 @@ ExportDxf::WriteLayersTable( IGeomDB* pGDB, int nId)
// ciclo di ricerca dei layer
// creo un iteratore
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( pGDB)) ;
if ( ! ::IsValid( pIter))
if ( IsNull( pIter))
return false ;
pIter->GoTo( nId) ;
// eseguo la ricerca
@@ -259,7 +259,7 @@ ExportDxf::FindLayers( const IGdbIterator& iIter, const string& sLay, LAYDATVECT
vLayDat.push_back( make_pair( sNewLay, nCol)) ;
// scandisco il gruppo alla ricerca di sottogruppi
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( iIter.GetGDB())) ;
if ( ! ::IsValid( pIter))
if ( IsNull( pIter))
return false ;
bool bOk = true ;
for ( bool bNext = pIter->GoToFirstInGroup( iIter) ;
@@ -304,7 +304,7 @@ ExportDxf::ExportEntities( IGeomDB* pGDB, int nId)
// creo un iteratore
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( pGDB)) ;
if ( ! ::IsValid( pIter))
if ( IsNull( pIter))
return false ;
pIter->GoTo( nId) ;
// esporto l'oggetto e i suoi eventuali figli
@@ -400,7 +400,7 @@ ExportDxf::ExportGdbGroup( const IGdbIterator& iIter, const string& sLay)
{
// creo un iteratore
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( iIter.GetGDB())) ;
if ( ! ::IsValid( pIter))
if ( IsNull( pIter))
return false ;
// aggiorno nome layer
string sNewLay = UpdateLayerName( iIter, sLay) ;
@@ -482,6 +482,13 @@ ExportDxf::ExportCrvBezier( const string& sLay, int nCol, const IGeoObj* pGeoObj
const ICurveBezier* pCBez = GetCurveBezier( pGeoObj) ;
if ( pCBez == nullptr)
return false ;
// verifico se piana
Plane3d plPlane ;
if ( pCBez->IsFlat( plPlane)) {
Frame3d frPlane ;
frPlane.Set( ( ORIG + plPlane.dDist * plPlane.vtN), plPlane.vtN) ;
return WriteCurve2d( sLay, nCol, pCBez, frPlane, frFrame) ;
}
// esporto come polilinea 3d
return WriteCurve3d( sLay, nCol, pCBez, frFrame) ;
}
@@ -513,88 +520,133 @@ ExportDxf::ExportSTM( const string& sLay, int nCol, const IGeoObj* pGeoObj, cons
const ISurfTriMesh* pSTM = GetSurfTriMesh( pGeoObj) ;
if ( pSTM == nullptr)
return false ;
// identificativo entità
if ( ! WriteItem( 0, "POLYLINE"))
return false ;
// layer
if ( ! WriteItem( 8, sLay))
return false ;
// colore
if ( ! WriteItem( 62, nCol))
return false ;
// flag segnalazione entità successive dipendenti (vertex)
if ( ! WriteItem( 66, 1))
return false ;
// punto inutile ma obbligatorio
if ( ! WriteItem( 10, 0) ||
! WriteItem( 20, 0) ||
! WriteItem( 30, 0))
return false ;
// flag (polyface mesh 3d)
if ( ! WriteItem( 70, 64))
return false ;
// numero di vertici
if ( ! WriteItem( 71, pSTM->GetVertexNum()))
return false ;
// numero di facce
if ( ! WriteItem( 72, pSTM->GetTriangleNum()))
return false ;
// ciclo sui vertici
Point3d ptP ;
for ( int nId = pSTM->GetFirstVertex( ptP) ;
nId != SVT_NULL ;
nId = pSTM->GetNextVertex( nId, ptP)) {
// entità vertice
if ( ! WriteItem( 0, "VERTEX"))
// posso esportare come unica polymesh solo se il numero dei vertici e dei triangoli è inferiore a 32767
if ( pSTM->GetVertexNum() < SHRT_MAX && pSTM->GetTriangleNum() < SHRT_MAX) {
// identificativo entità
if ( ! WriteItem( 0, "POLYLINE"))
return false ;
// layer
if ( ! WriteItem( 8, sLay))
return false ;
// punto corrente
ptP.ToGlob( frFrame) ;
if ( ! WriteItem( 10, ptP.x) ||
! WriteItem( 20, ptP.y) ||
! WriteItem( 30, ptP.z))
return false ;
// flag (3d polygon mesh + polyface mesh vertex)
if ( ! WriteItem( 70, 64 + 128))
return false ;
}
// ciclo sui triangoli
int nIdVert[3] ;
for ( int nId = pSTM->GetFirstTriangle( nIdVert) ;
nId != SVT_NULL ;
nId = pSTM->GetNextTriangle( nId, nIdVert)) {
// entità vertice
if ( ! WriteItem( 0, "VERTEX"))
return false ;
// layer
if ( ! WriteItem( 8, sLay))
return false ;
// colore (unico colore riconosciuto)
// colore
if ( ! WriteItem( 62, nCol))
return false ;
// flag segnalazione entità successive dipendenti (vertex)
if ( ! WriteItem( 66, 1))
return false ;
// punto inutile ma obbligatorio
if ( ! WriteItem( 10, 0) ||
! WriteItem( 20, 0) ||
! WriteItem( 30, 0))
return false ;
// flag (polyface mesh vertex)
if ( ! WriteItem( 70, 128))
// flag (polyface mesh 3d)
if ( ! WriteItem( 70, 64))
return false ;
// indici dei vertici (1-based)
if ( ! WriteItem( 71, nIdVert[0] + 1) ||
! WriteItem( 72, nIdVert[1] + 1) ||
! WriteItem( 73, nIdVert[2] + 1))
// numero di vertici
if ( ! WriteItem( 71, pSTM->GetVertexNum()))
return false ;
// numero di facce
if ( ! WriteItem( 72, pSTM->GetTriangleNum()))
return false ;
// ciclo sui vertici
Point3d ptP ;
for ( int nId = pSTM->GetFirstVertex( ptP) ;
nId != SVT_NULL ;
nId = pSTM->GetNextVertex( nId, ptP)) {
// entità vertice
if ( ! WriteItem( 0, "VERTEX"))
return false ;
// layer
if ( ! WriteItem( 8, sLay))
return false ;
// punto corrente
ptP.ToGlob( frFrame) ;
if ( ! WriteItem( 10, ptP.x) ||
! WriteItem( 20, ptP.y) ||
! WriteItem( 30, ptP.z))
return false ;
// flag (3d polygon mesh + polyface mesh vertex)
if ( ! WriteItem( 70, 64 + 128))
return false ;
}
// ciclo sui triangoli
int nIdVert[3] ;
for ( int nId = pSTM->GetFirstTriangle( nIdVert) ;
nId != SVT_NULL ;
nId = pSTM->GetNextTriangle( nId, nIdVert)) {
// entità vertice
if ( ! WriteItem( 0, "VERTEX"))
return false ;
// layer
if ( ! WriteItem( 8, sLay))
return false ;
// colore (unico colore riconosciuto)
if ( ! WriteItem( 62, nCol))
return false ;
// punto inutile ma obbligatorio
if ( ! WriteItem( 10, 0) ||
! WriteItem( 20, 0) ||
! WriteItem( 30, 0))
return false ;
// flag (polyface mesh vertex)
if ( ! WriteItem( 70, 128))
return false ;
// indici dei vertici (1-based)
if ( ! WriteItem( 71, nIdVert[0] + 1) ||
! WriteItem( 72, nIdVert[1] + 1) ||
! WriteItem( 73, nIdVert[2] + 1))
return false ;
}
// entità termine dei vertici
if ( ! WriteItem( 0, "SEQEND"))
return false ;
// layer
if ( ! WriteItem( 8, sLay))
return false ;
return true ;
}
// altrimenti devo esportare come insieme di facce triangolari
else {
// ciclo sui triangoli
Triangle3d Tria ;
for ( int nId = pSTM->GetFirstTriangle( Tria) ;
nId != SVT_NULL ;
nId = pSTM->GetNextTriangle( nId, Tria)) {
// entità 3dface
if ( ! WriteItem( 0, "3DFACE"))
return false ;
// layer
if ( ! WriteItem( 8, sLay))
return false ;
// colore (unico colore riconosciuto)
if ( ! WriteItem( 62, nCol))
return false ;
// primo vertice
if ( ! WriteItem( 10, Tria.GetP(0).x) ||
! WriteItem( 20, Tria.GetP(0).y) ||
! WriteItem( 30, Tria.GetP(0).z))
return false ;
// secondo vertice
if ( ! WriteItem( 11, Tria.GetP(1).x) ||
! WriteItem( 21, Tria.GetP(1).y) ||
! WriteItem( 31, Tria.GetP(1).z))
return false ;
// terzo vertice
if ( ! WriteItem( 12, Tria.GetP(2).x) ||
! WriteItem( 22, Tria.GetP(2).y) ||
! WriteItem( 32, Tria.GetP(2).z))
return false ;
// quarto vertice (ripete il terzo)
if ( ! WriteItem( 13, Tria.GetP(2).x) ||
! WriteItem( 23, Tria.GetP(2).y) ||
! WriteItem( 33, Tria.GetP(2).z))
return false ;
// flag (default)
if ( ! WriteItem( 70, 0))
return false ;
}
return true ;
}
// entità termine dei vertici
if ( ! WriteItem( 0, "SEQEND"))
return false ;
// layer
if ( ! WriteItem( 8, sLay))
return false ;
return true ;
}
//----------------------------------------------------------------------------
@@ -773,7 +825,7 @@ ExportDxf::WriteCurve2d( const string& sLay, int nCol, const ICurve* pCrv,
if ( ! AreSameFrame( frPlane, GLOB_FRM)) {
// creo una copia della curva (da buttare alla fine)
PtrOwner<ICurve> pModCrv( pCrv->Clone()) ;
if ( ! IsValid( pModCrv))
if ( IsNull( pModCrv))
return false ;
// eseguo la trasformazione
pModCrv->ToLoc( frPlane) ;
+2 -2
View File
@@ -65,7 +65,7 @@ ExportStl::Export( IGeomDB* pGDB, int nId, const string& sFile)
// creo un iteratore
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( pGDB)) ;
if ( ! ::IsValid( pIter))
if ( IsNull( pIter))
return false ;
pIter->GoTo( nId) ;
// esporto l'oggetto e i suoi eventuali figli
@@ -200,7 +200,7 @@ ExportStl::ScanGroup( const IGdbIterator& iIter, ofstream& OutFile)
{
// creo un iteratore
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( iIter.GetGDB())) ;
if ( ! ::IsValid( pIter))
if ( IsNull( pIter))
return false ;
// scandisco il gruppo
bool bOk = true ;
+4 -4
View File
@@ -173,10 +173,10 @@ ImportDxf::SolveBlockReferences( void)
{
// creo gli iteratori
PtrOwner<IGdbIterator> pIBlo( CreateGdbIterator( m_pGDB)) ;
if ( ! IsValid( pIBlo))
if ( IsNull( pIBlo))
return false ;
PtrOwner<IGdbIterator> pIEnt( CreateGdbIterator( m_pGDB)) ;
if ( ! IsValid( pIEnt))
if ( IsNull( pIEnt))
return false ;
// si ripete più volte, fino a completa soluzione o max iterazioni
@@ -283,7 +283,7 @@ ImportDxf::InsertBlockInBlock( int nIdDest, int nIdIns, const InsertData& insDat
}
// copio tutte le entità del blocco, trasformandole opportunamente
PtrOwner<IGdbIterator> pIEnt( CreateGdbIterator( m_pGDB)) ;
if ( ! IsValid( pIEnt))
if ( IsNull( pIEnt))
return false ;
bool bFound = pIEnt->GoToFirstInGroup( nIdIns) ;
while ( bFound) {
@@ -296,7 +296,7 @@ ImportDxf::InsertBlockInBlock( int nIdDest, int nIdIns, const InsertData& insDat
continue ;
}
PtrOwner<IGeoObj> pGeo( pGeoS->Clone()) ;
if ( ! IsValid( pGeo))
if ( IsNull( pGeo))
return false ;
// inserisco l'entità nel DB
int nIdE = m_pGDB->InsertGeoObj( GDB_ID_NULL, nIdDest, GDB_BEFORE, Release( pGeo)) ;
+23 -21
View File
@@ -362,7 +362,7 @@ ImportDxf::Read3dFace( bool& bFileEnd)
// inserisco la faccia nel DB geometrico
// creo la trimesh
PtrOwner<ISurfTriMesh> pSTM( CreateSurfTriMesh()) ;
if ( ! IsValid( pSTM))
if ( IsNull( pSTM))
return false ;
// costruisco la geometria della trimesh
if ( ! pSTM->Init( 4, 2))
@@ -495,7 +495,7 @@ ImportDxf::ReadArc( bool& bFileEnd)
// inserisco l'arco nel DB geometrico
// creo l'arco
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
if ( ! IsValid( pCrvArc))
if ( IsNull( pCrvArc))
return false ;
// setto l'arco
if ( ! pCrvArc->Set( ptCen, vtExtr, dRadius, vtStart, dCentAng, 0))
@@ -595,7 +595,7 @@ ImportDxf::ReadCircle( bool& bFileEnd)
// inserisco il cerchio nel DB geometrico
// creo il cerchio
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
if ( ! IsValid( pCrvArc))
if ( IsNull( pCrvArc))
return false ;
// setto il cerchio
if ( ! pCrvArc->Set( ptCen, vtExtr, dRadius))
@@ -716,7 +716,7 @@ ImportDxf::ReadEllipse( bool& bFileEnd)
// inserisco l'arco nel DB geometrico
// creo l'arco
PtrOwner<ICurveArc> pCrvArc( CreateCurveArc()) ;
if ( ! IsValid( pCrvArc))
if ( IsNull( pCrvArc))
return false ;
// setto l'arco
if ( ! pCrvArc->Set( ptCen, vtExtr, dMajorAx, vtStart, dCentAng, 0))
@@ -856,7 +856,7 @@ ImportDxf::ReadInsert( bool& bFileEnd)
Vector3d vtMove = insData.ptP - ptBase ;
// copio tutte le entità del blocco, trasformandole opportunamente
PtrOwner<IGdbIterator> pIter( CreateGdbIterator( m_pGDB)) ;
if ( ! IsValid( pIter))
if ( IsNull( pIter))
return false ;
bool bFound = pIter->GoToFirstInGroup( nIdBlock) ;
while ( bFound) {
@@ -865,7 +865,7 @@ ImportDxf::ReadInsert( bool& bFileEnd)
if ( pGeoS == nullptr)
return false ;
PtrOwner<IGeoObj> pGeo( pGeoS->Clone()) ;
if ( ! IsValid( pGeo))
if ( IsNull( pGeo))
return false ;
// inserisco l'entità nel DB
int nId = m_pGDB->AddGeoObj( GDB_ID_NULL, GetGroupId( insData.sLayer), Release( pGeo)) ;
@@ -1020,7 +1020,7 @@ ImportDxf::ReadLine( bool& bFileEnd)
// inserisco la linea nel DB geometrico
// creo la linea
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
if ( ! IsValid( pCrvLine))
if ( IsNull( pCrvLine))
return false ;
// setto la linea
if ( ! pCrvLine->Set( ptStart, ptEnd))
@@ -1108,7 +1108,7 @@ ImportDxf::ReadRayXline( bool bIsRay, bool& bFileEnd)
// inserisco la linea nel DB geometrico
// creo la linea
PtrOwner<ICurveLine> pCrvLine( CreateCurveLine()) ;
if ( ! IsValid( pCrvLine))
if ( IsNull( pCrvLine))
return false ;
// setto la linea
Point3d ptStart = ptRef ;
@@ -1235,7 +1235,7 @@ ImportDxf::ReadLwPolyLine( bool& bFileEnd)
PA.ToLoc( m_frGroup) ;
// Creo la curva composita
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
if ( ! IsValid( pCrvCompo))
if ( IsNull( pCrvCompo))
return false ;
// Inserisco i punti con bulge nella curva composita come linee e archi
if ( ! pCrvCompo->FromPolyArc( PA))
@@ -1328,7 +1328,7 @@ ImportDxf::ReadPoint( bool& bFileEnd)
if ( fabs( dThick) < EPS_SMALL) {
// creo il punto
PtrOwner<IGeoPoint3d> pGeoPnt( CreateGeoPoint3d()) ;
if ( ! IsValid( pGeoPnt))
if ( IsNull( pGeoPnt))
return false ;
// setto il punto
if ( ! pGeoPnt->Set( ptP))
@@ -1339,7 +1339,7 @@ ImportDxf::ReadPoint( bool& bFileEnd)
else {
// creo il vettore con punto base
PtrOwner<IGeoVector3d> pGeoVect( CreateGeoVector3d()) ;
if ( ! IsValid( pGeoVect))
if ( IsNull( pGeoVect))
return false ;
// setto il punto
if ( ! pGeoVect->Set( dThick * vtExtr, ptP))
@@ -1513,7 +1513,7 @@ ImportDxf::CompletePolyLine( const string& sLayer, int nColor, int nFlag, bool b
PA.ToLoc( m_frGroup) ;
// Creo la curva composita
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
if ( ! IsValid( pCrvCompo))
if ( IsNull( pCrvCompo))
return false ;
// Inserisco i punti con bulge nella curva composita come linee e archi
if ( ! pCrvCompo->FromPolyArc( PA))
@@ -1576,7 +1576,7 @@ ImportDxf::CompletePolygonMesh( const string& sLayer, int nColor, int nFlag, boo
{
// creo la superficie
PtrOwner<ISurfTriMesh> pSTM( CreateSurfTriMesh()) ;
if ( ! IsValid( pSTM))
if ( IsNull( pSTM))
return false ;
// la inizializzo
int nNumVert = nNumVertM * nNumVertN ;
@@ -1728,7 +1728,7 @@ ImportDxf::CompletePolyfaceMesh( const string& sLayer, int nColor, int nFlag, bo
{
// creo la superficie
PtrOwner<ISurfTriMesh> pSTM( CreateSurfTriMesh()) ;
if ( ! IsValid( pSTM))
if ( IsNull( pSTM))
return false ;
// la inizializzo
if ( ! pSTM->Init( 3, 1))
@@ -2009,7 +2009,7 @@ ImportDxf::ReadSolid( bool& bFileEnd)
// inserisco la faccia nel DB geometrico
// creo la trimesh
PtrOwner<ISurfTriMesh> pSTM( CreateSurfTriMesh()) ;
if ( ! IsValid( pSTM))
if ( IsNull( pSTM))
return false ;
// costruisco la geometria della trimesh
if ( ! pSTM->Init( 4, 2))
@@ -2177,7 +2177,7 @@ ImportDxf::ReadSpline( bool& bFileEnd)
crvByInterp.AddPoint( vIntPnt[i]) ;
crvByInterp.End() ;
PtrOwner<ICurve> pCrv( crvByInterp.GetCurve( CurveByInterp::BESSEL, CurveByInterp::CUBIC_BEZIERS)) ;
if ( ! ::IsValid( pCrv))
if ( IsNull( pCrv))
return false ;
// Inserisco la curva nel DB
int nId = m_pGDB->AddGeoObj( GDB_ID_NULL, GetGroupId( sLayer), Release( pCrv)) ;
@@ -2214,11 +2214,13 @@ ImportDxf::ReadSpline( bool& bFileEnd)
if ( ! NurbsCurveCanonicalize( cnData))
return false ;
// creo la curva equivalente alla Nurbs
ICurve* pCrv = NurbsToBezierCurve( cnData) ;
if ( pCrv == nullptr)
PtrOwner<ICurve> pCrv( NurbsToBezierCurve( cnData)) ;
if ( IsNull( pCrv))
return false ;
if ( ! pCrv->IsValid())
return true ;
// Inserisco la curva composita nel DB
int nId = m_pGDB->AddGeoObj( GDB_ID_NULL, GetGroupId( sLayer), pCrv) ;
int nId = m_pGDB->AddGeoObj( GDB_ID_NULL, GetGroupId( sLayer), Release( pCrv)) ;
if ( nId == GDB_ID_NULL)
return false ;
// eventuale assegnazione del colore
@@ -2344,7 +2346,7 @@ ImportDxf::ReadText( int nGroupId, bool& bFileEnd)
// inserisco il testo nel DB geometrico
// creo il testo
PtrOwner<IExtText> pTXT( CreateExtText()) ;
if ( ! IsValid( pTXT))
if ( IsNull( pTXT))
return false ;
// setto il testo
if ( ! pTXT->Set( sText, ptP, vtExtr, vtDir, sFont, 400, false, dH, dRat, 0, ETXT_IPBL))
@@ -2549,7 +2551,7 @@ ImportDxf::ReadMText( bool& bFileEnd)
// inserisco il testo nel DB geometrico
// creo il testo
PtrOwner<IExtText> pTXT( CreateExtText()) ;
if ( ! IsValid( pTXT))
if ( IsNull( pTXT))
return false ;
// setto il testo
if ( ! pTXT->Set( sText, ptP, vtExtr, vtDirG, sFont, 400, false, dH, dRatStyle, 0, nInsPos))