EgtExchange :

- aggiunta info ai layer e export punti, per file 3dm.
This commit is contained in:
Daniele Bariletti
2023-10-04 13:04:14 +02:00
parent 9f7bdb2202
commit e9dff179e0
2 changed files with 38 additions and 12 deletions
+37 -12
View File
@@ -26,6 +26,7 @@
#include "/EgtDev/Include/EGkCurveComposite.h"
#include "/EgtDev/Include/EGkGdbIterator.h"
#include "/EgtDev/Include/EGkGeoObjType.h"
#include "/EgtDev/Include/EGkGeoPoint3d.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/SELkKeyProc.h"
#include "/EgtDev/Include/EgtKeyCodes.h"
@@ -34,6 +35,7 @@
#include <fstream>
#include "C:/EgtDev/opennurbs/opennurbs.h"
#include <map>
#include "/EgtDev/Include/EGnStringUtils.h"
using namespace std ;
class ON_Color ;
@@ -121,7 +123,6 @@ Export3dm::Export( IGeomDB* pGDB, int nId, const string& sFile)
return false ;
}
//// file settings ( units, tolerances, views, ...)
//// OPTIONAL - change values from defaults
m_model.m_settings.m_ModelUnitsAndTolerances.m_unit_system = ON::LengthUnitSystem::Meters ;
@@ -184,6 +185,11 @@ Export3dm::ExportObject( const IGdbIterator& iIter, const int& nLayer)
sName = ToString( iIter.GetId()) ;
// emetto l'oggetto
switch ( pGeoObj->GetType()) {
case GEO_PNT3D: {
if ( ! ExportPnt( sName, pGeoObj, frFrame, cCol, nLayer))
return false ;
break ;
}
case SRF_BEZIER: {
if ( ! ExportSrfBz( sName, pGeoObj, frFrame, cCol, nLayer))
return false ;
@@ -231,7 +237,11 @@ Export3dm::ExportObject( const IGdbIterator& iIter, const int& nLayer)
}
// creo il layer e setto le proprietà
ON_Layer* layer = new ON_Layer() ;
std::string sLayName = "Layer " + ToString( nLayer) ;
std::string sLayName ;
iIter.GetName( sLayName) ;
if ( sLayName == "" ) {
sLayName = "Layer " + ToString( nLayer) ;
}
layer->SetName( ConvertString( sLayName).c_str()) ;
bool bDone = layer->SetIndex( nLayer) ;
ON_Color onCol( 0, 0, 0, 0) ; // black
@@ -244,6 +254,14 @@ Export3dm::ExportObject( const IGdbIterator& iIter, const int& nLayer)
const ON_Layer* onParLay = ON_Layer::Cast( m_model.LayerFromIndex( m_mLayer[nParent]).ModelComponent()) ;
layer->SetParentLayerId( onParLay->Id()) ;
}
// copio le info
STRVECTOR vStrInfo, vStrInfo_split ;
iIter.GetAllInfo( vStrInfo) ;
for ( string sInfo : vStrInfo) {
Tokenize( sInfo, "=", vStrInfo_split) ;
layer->SetUserString( ConvertString( vStrInfo_split[0]).c_str(), ConvertString( vStrInfo_split[1]).c_str()) ;
}
// aggiungo il layer
ON_ModelComponentReference mcr = m_model.AddManagedModelComponent( layer) ;
int nIndex = mcr.ModelComponentIndex() ;
@@ -326,6 +344,22 @@ Export3dm::TestFilter( int nLev, int nMode, int nStat)
return true ;
}
//----------------------------------------------------------------------------
bool
Export3dm::ExportPnt(const string& sName, const IGeoObj* pGeoObj, const Frame3d& frFrame, const Color& cCol, const int& nLayer)
{
// verifico oggetto
IGeoPoint3d* pGeoPnt = GetGeoPoint3d( pGeoObj->Clone()) ;
if ( pGeoPnt == nullptr)
return false ;
// lo porto nel riferimento globale
pGeoPnt->ToGlob( frFrame) ;
Point3d pt = pGeoPnt->GetPoint() ;
ON_Point* onPt = new ON_Point(ConvertPoint( pt)) ;
AddObjectToModel( onPt, nLayer, sName, cCol) ;
return true ;
}
//----------------------------------------------------------------------------
bool
Export3dm::ExportSrfBz( const string& sName, const IGeoObj* pGeoObj, const Frame3d& frFrame, const Color& cCol, const int& nLayer)
@@ -498,7 +532,6 @@ Export3dm::ConvertCrvBezier( ICurveBezier* pCrvBz)
return Release( onNurbsCrv) ;
}
//----------------------------------------------------------------------------
bool
Export3dm::ExportCrvBezier( const string& sName, const IGeoObj* pGeoObj, const Frame3d& frFrame, const Color& cCol, const int& nLayer)
@@ -510,7 +543,6 @@ Export3dm::ExportCrvBezier( const string& sName, const IGeoObj* pGeoObj, const F
bool bOk = true ;
// lo porto nel riferimento globale
pCrvBz->ToGlob( frFrame) ;
ON_NurbsCurve* onNurbsCrv = ConvertCrvBezier( pCrvBz) ;
return AddObjectToModel( onNurbsCrv, nLayer, sName, cCol) ;
}
@@ -554,14 +586,7 @@ Export3dm::ExportCrvCompo( const string& sName, const IGeoObj* pGeoObj, const Fr
}
}
// creo il vettore estrusione
Vector3d vtExtr ;
pCrvCompo->GetExtrusion( vtExtr) ;
std::string sExtr = ToString( vtExtr.x) + "," + ToString( vtExtr.y) + "," + ToString( vtExtr.z) ;
ON_3dmObjectAttributes* pOnAttr = new ON_3dmObjectAttributes() ;
pOnAttr->SetUserString( ConvertString( "vtExtr").c_str(), ConvertString( sExtr).c_str()) ;
return AddObjectToModel( onPolyCrv, nLayer, sName, cCol, pOnAttr) ;
return AddObjectToModel( onPolyCrv, nLayer, sName, cCol) ;
}
//----------------------------------------------------------------------------
+1
View File
@@ -55,6 +55,7 @@ private :
ON_NurbsCurve* ConvertCrvBezier( ICurveBezier* pCrvBz) ;
ON_ArcCurve* ConvertCrvArc( ICurveArc* pCrvArc) ;
ON_LineCurve* ConvertCrvLine( ICurveLine* pCrvL) ;
bool ExportPnt( const std::string& sName, const IGeoObj* pGeoObj, const Frame3d& frFrame, const Color& cCol, const int& nLayer) ;
bool ExportSrfBz( const std::string& sName, const IGeoObj* pGeoObj, const Frame3d& frFrame, const Color& cCol, const int& nLayer) ;
bool ExportSFR( const std::string& sName, const IGeoObj* pGeoObj, const Frame3d& frFrame, const Color& cCol, const int& nLayer) ;
bool ExportSTM( const std::string& sName, const IGeoObj* pGeoObj, const Frame3d& frFrame, const Color& cCol, const int& nLayer) ;