From 549f3d47bd2d2f508ccca1f5552993b65eca0567 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Thu, 3 Aug 2023 10:18:12 +0200 Subject: [PATCH] EgtExchange: - aggiunto l'import per file 3dm. --- EgtExchange.vcxproj | 9 +- EgtExchange.vcxproj.filters | 6 + ExcExecutor.cpp | 35 +++ ExcExecutor.h | 1 + Import3dm.cpp | 467 ++++++++++++++++++++++++++++++++++++ Import3dm.h | 43 ++++ Import3dmEnts.cpp | 34 +++ stdafx.h | 1 + 8 files changed, 593 insertions(+), 3 deletions(-) create mode 100644 Import3dm.cpp create mode 100644 Import3dm.h create mode 100644 Import3dmEnts.cpp diff --git a/EgtExchange.vcxproj b/EgtExchange.vcxproj index 8bea75f..3195301 100644 --- a/EgtExchange.vcxproj +++ b/EgtExchange.vcxproj @@ -35,7 +35,7 @@ DynamicLibrary true Unicode - ClangCL + v143 DynamicLibrary @@ -131,12 +131,13 @@ copy $(TargetPath) \EgtProg\DllD32 stdcpp17 - -Wno-tautological-undefined-compare + + Windows true - C:\EgtDev\Extern\OxySec\Lib\x64\xnodus.obj;%(AdditionalDependencies) + C:\EgtDev\Extern\OxySec\Lib\x64\xnodus.obj;C:/EgtDev/opennurbs/bin/x64/Debug/opennurbs_public.lib;%(AdditionalDependencies) copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ @@ -326,6 +327,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -363,6 +365,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtExchange.vcxproj.filters b/EgtExchange.vcxproj.filters index 5fa4640..3edad39 100644 --- a/EgtExchange.vcxproj.filters +++ b/EgtExchange.vcxproj.filters @@ -375,6 +375,9 @@ File di intestazione\Include + + File di intestazione + @@ -455,6 +458,9 @@ File di origine + + File di origine + diff --git a/ExcExecutor.cpp b/ExcExecutor.cpp index f713637..df4432a 100644 --- a/ExcExecutor.cpp +++ b/ExcExecutor.cpp @@ -22,6 +22,7 @@ #include "/EgtDev/Include/EExImportCnc.h" #include "/EgtDev/Include/EExImportDxf.h" #include "/EgtDev/Include/EExImportStl.h" +#include "/EgtDev/Include/EExImport3dm.h" using namespace std ; @@ -43,6 +44,7 @@ ExcExecutor::ExcExecutor( void) m_ExecMgr.Insert( "IMPORTCNC", &ExcExecutor::ExecuteImportCnc) ; m_ExecMgr.Insert( "IMPORTDXF", &ExcExecutor::ExecuteImportDxf) ; m_ExecMgr.Insert( "IMPORTSTL", &ExcExecutor::ExecuteImportStl) ; + m_ExecMgr.Insert( "IMPORT3DM", &ExcExecutor::ExecuteImport3dm) ; } //---------------------------------------------------------------------------- @@ -234,3 +236,36 @@ ExcExecutor::ExecuteImportStl( const string& sCmd2, const STRVECTOR& vsParams) return bOk ; } + +//---------------------------------------------------------------------------- +bool +ExcExecutor::ExecuteImport3dm( const string& sCmd2, const STRVECTOR& vsParams) +{ + // 2 o 3 parametri : nome del file, Id del gruppo[, ScaleFactor] + if ( vsParams.size() != 2 && vsParams.size() != 3) + return false ; + // eventuale conversione di token nel nome file + string sFile = vsParams[0] ; + m_pParser->DirReplace( sFile) ; + // recupero l'Id + int nId = m_pParser->GetIdParam( vsParams[1]) ; + if ( nId == CMD_ID_ERROR) + return false ; + // gestisco ScaleFactor + double dScaleFactor = 1 ; + if ( vsParams.size() >= 3) + FromString( vsParams[2], dScaleFactor) ; + + // preparo l'importatore + IImport3dm* pImp3dm = CreateImport3dm() ; + if ( pImp3dm == nullptr) { + LOG_ERROR( GetEExLogger(), "Error : CreateImportStl") + return false ; + } + // eseguo l'importazione + bool bOk = pImp3dm->Import( sFile, m_pGDB, nId, dScaleFactor) ; + // cancello l'importatore + delete pImp3dm ; + + return bOk ; +} diff --git a/ExcExecutor.h b/ExcExecutor.h index 4c405e1..43a659b 100644 --- a/ExcExecutor.h +++ b/ExcExecutor.h @@ -40,6 +40,7 @@ class ExcExecutor : public IExcExecutor bool ExecuteImportDxf( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool ExecuteImportCnc( const std::string& sCmd2, const STRVECTOR& vsParams) ; bool ExecuteImportStl( const std::string& sCmd2, const STRVECTOR& vsParams) ; + bool ExecuteImport3dm( const std::string& sCmd2, const STRVECTOR& vsParams) ; private : IGeomDB* m_pGDB ; diff --git a/Import3dm.cpp b/Import3dm.cpp new file mode 100644 index 0000000..164a90d --- /dev/null +++ b/Import3dm.cpp @@ -0,0 +1,467 @@ +//---------------------------------------------------------------------------- +// EgalTech 2023 +//---------------------------------------------------------------------------- +// File : Import3dm.cpp Data : 23.06.23 Versione : 2.5f1 +// Contenuto : Implementazione della classe per l'importazione di 3dm. +// +// +// +// Modifiche : 23.06.23 DB Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "Import3dm.h" +#include "DllMain.h" +#include "/EgtDev/Include/EExDllMain.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/SELkKeyProc.h" +#include "/EgtDev/Include/EgtKeyCodes.h" +#include "/EgtDev/Include/EgtPointerOwner.h" +#include "/EgtDev/Include/EGkGeoPoint3d.h" +#include "/EgtDev/Include/EGkCurveLine.h" +#include "/EgtDev/Include/EGkArcSpecial.h" +#include "/EgtDev/Include/EGkCurveComposite.h" +#include "/EgtDev/Include/EGkCurveBezier.h" +#include "/EgtDev/Include/EGkCurveAux.h" +#include "/EgtDev/Include/EGkSurf.h" +#include "/EgtDev/Include/EGkStmFromCurves.h" +#include "C:/EgtDev/opennurbs/opennurbs.h" + +using namespace std ; + +class ON_ClassId ; + +//---------------------------------------------------------------------------- +IImport3dm* +CreateImport3dm( void) +{ + // verifico la chiave e le opzioni + if ( ! VerifyKey( KEYOPT_EEX_INPBASE)) + return nullptr ; + // creo l'oggetto + return static_cast ( new(nothrow) Import3dm) ; +} + +//---------------------------------------------------------------------------- +bool +Import3dm::Import( const string& sFile__, IGeomDB* pGDB, int nIdGroup, double dScaleFactor) +{ + // verifico il DB geometrico + if ( pGDB == nullptr) { + LOG_ERROR( GetEExLogger(), "Import3dm : Error on GeomDB") + return false ; + } + m_pGDB = pGDB ; + + // verifico l'Id di gruppo + if ( ! m_pGDB->ExistsObj( nIdGroup)) { + LOG_ERROR( GetEExLogger(), "Import3dm : Error on IdGroup") + return false ; + } + m_nIdGroup = nIdGroup ; + + // verifico il fattore di scala + if ( dScaleFactor < EPS_SMALL) { + LOG_ERROR( GetEExLogger(), "Import3dm : Error on ScaleFactor too small (minimum 0.001).") + return false ; + } + m_dScaleFactor = dScaleFactor ; + + // scorro l'archivio fino ad arrivare agli elementi geometrici + std::string sFile = "C:\\EgtDev\\opennurbs\\example_files\\V6\\my_points.3dm" ; + //std::string sFile = "C:\\EgtDev\\opennurbs\\example_files\\V6\\my_curves.3dm" ; + //std::string sFile = "C:\\EgtDev\\opennurbs\\example_files\\V5\\v5_rhino_logo.3dm" ; + + ONX_Model model; + + std::wstring widestr = std::wstring(sFile.begin(), sFile.end()) ; + const wchar_t* sFileName = widestr.c_str() ; + FILE* archive_fp = ON::OpenFile( sFileName, L"rb") ; + if ( !archive_fp ) + { + LOG_ERROR( GetEExLogger(), "Unable to open file." ) ; + return false; + } + + // create achive object from file pointer + ON_BinaryFile archive( ON::archive_mode::read3dm, archive_fp ) ; + + // read the contents of the file into "model" + ON_TextLog dump ; + bool rc = model.Read( archive, &dump ) ; + + if ( ! rc) + LOG_ERROR( GetEExLogger(), "Unable to read file." ) ; + + // close the file + ON::CloseFile( archive_fp ) ; + + ON_ModelComponent::Type component_type = ON_ModelComponent::Type::ModelGeometry ; + //const ON_wString type_name_string = ON_ModelComponent::ComponentTypeToString(component_type) ; + + + //////// aggiungo gli elementi geometrici al GeomDB + //for ( + // const ONX_ModelComponentReferenceLink* link = model.Internal_ComponentListConst(component_type).m_first_mcr_link; + // nullptr != link; + // link = link->m_next + // ) + //{ + //int a=0 ; + //} + + // devo trovare il numero di oggetti geometrici + //int nCount = model.Internal_ComponentListConst(ON_ModelComponent::Type::ModelGeometry).m_count ; + //int component_model_index = 10 ; + //ON_ModelComponentReference mcr = model.ComponentFromIndex( component_type, component_model_index) ; + + //while ( ! mcr.IsEmpty()) { + //int component_model_index = 114 ; + //ON_ModelComponentReference mcr = model.ComponentFromIndex( component_type, component_model_index) ; + //unsigned int limit = model.ComponentIndexLimit( ON_ModelComponent::Type::ModelGeometry) ; + //const ON_ComponentManifest& manifest = model.Manifest() ; + //const ON_ManifestMap map = model.ModelToOriginalMap() ; + //int count = manifest.TotalComponentCount( ON_ModelComponent::Type::ModelGeometry) ; + //ON_SimpleArray component_index_array ; + //archive.Read3dmReferencedComponentIndexArray( ON_ModelComponent::Type::ModelGeometry, component_index_array) ; + + ONX_ModelComponentIterator component_iterator ( model, ON_ModelComponent::Type::ModelGeometry) ; + int count = component_iterator.ActiveComponentCount() ; + //ON_ModelComponentReference mcr = component_iterator.FirstComponentReference() ; + //const ON_ModelGeometryComponent* mgc = ON_ModelGeometryComponent::Cast( mcr.ModelComponent()) ; + const ON_ModelComponent* mc = component_iterator.FirstComponent() ; + const ON_ModelGeometryComponent* mgc = ON_ModelGeometryComponent::Cast( mc) ; + + //ON_ModelComponentReference mcr = model.ComponentFromIndex( ON_ModelComponent::Type::ModelGeometry, component_model_index) ; + //const ON_ModelGeometryComponent* mgc = ON_ModelGeometryComponent::Cast( mcr.ModelComponent()) ; + + //while( ! mgc->IsEmpty()) { + for( const ON_ModelComponent* mc = component_iterator.FirstComponent() ; nullptr != mc ; mc = component_iterator.NextComponent()) { + const ON_ModelGeometryComponent* mgc = ON_ModelGeometryComponent::Cast( mc) ; + const ON_Object* oGeometry = mgc->Geometry( nullptr) ; + // individuo a che layer appartiene l'oggetto + const ON_3dmObjectAttributes* attributes = mgc->Attributes(nullptr); + int nLayer = attributes->m_layer_index ; + // aggiungo al GeomDB + ON::object_type type = oGeometry->ObjectType() ; + // se non riesco a convertire un oggetto, lo scarto e alla fine della conversione segnalo che ho balzato TOT oggetti di tipo PIPPO + switch ( type) { + case ON::object_type::point_object : { + /*ON_Point Point = oGeometry-> ;*/ + /*ON_3dPoint* Point( oGeometry) ;*/ + const ON_Point* oPoint = static_cast( oGeometry) ; // qui potrei mettere anche dynamic_cast + Point3d pt ; + ConvertPoint( *oPoint, pt) ; + // lo aggiungo al GeomDB nel layer corretto + PtrOwner pGeoPnt( CreateGeoPoint3d()) ; + pGeoPnt->Set( pt) ; + m_pGDB->AddGeoObj( GDB_ID_NULL, nLayer, Release(pGeoPnt)) ; + break ; + } + case ON::object_type::pointset_object : { + const ON_PointCloud* pc = ON_PointCloud::Cast( oGeometry); + if ( nullptr == pc ) + return false ; + int count = pc->PointCount() ; + for ( int i = 0; i < count ; i++ ) { + ON_Point onPoint( pc->m_P[i]) ; + Point3d pt ; + ConvertPoint( onPoint, pt) ; + // lo aggiungo al GeomDB nel layer corretto + PtrOwner pGeoPnt( CreateGeoPoint3d()) ; + pGeoPnt->Set( pt) ; + m_pGDB->AddGeoObj( GDB_ID_NULL, nLayer, Release( pGeoPnt)) ; + } + break ; + } + case ON::object_type::curve_object : { + const ON_Curve* onCurve = static_cast( oGeometry) ; + ICurve* pCurve = nullptr ; + ConvertCurve( onCurve, pCurve) ; + if ( pCurve == nullptr) + return false ; + m_pGDB->AddGeoObj( GDB_ID_NULL, nLayer, pCurve) ; + break ; + } + case ON::object_type::surface_object : + /*ConvertSurface( oGeometry)*/ + break ; + case ON::object_type::brep_object : + break ; + case ON::object_type::extrusion_object : { + const ON_Extrusion* onExtrusion = ON_Extrusion::Cast( oGeometry) ; + Point3d ptStart, ptEnd ; + ConvertPoint( onExtrusion->PathStart(), ptStart) ; + ConvertPoint( onExtrusion->PathEnd(), ptEnd) ; + int nIsCapped = onExtrusion->IsCapped() ; // 0: no or profile is open /1: bottom cap /2: top cap /3: both ends capped. + //int nProfiles = onExtrusion->ProfileCount() ; + ON_SimpleArray onSaProfile ; + int nProfiles = onExtrusion->GetProfileCurves( onSaProfile) ; + CICURVEPVECTOR vCrvProfile ; + for (int i = 0 ; i < nProfiles ; ++i ) { + const ON_Curve* onCurve = onSaProfile[i] ; + ICurve* pCurve = nullptr ; + ConvertCurve( onCurve, pCurve) ; + vCrvProfile.push_back( pCurve) ; + } + Vector3d vDir = ptEnd - ptStart ; + //ISurfTriMesh* pSurfTm = GetSurfTriMeshByExtrusion( vCrvProfile, vDir) ; + //m_pGDB->AddGeoObj( GDB_ID_NULL, nLayer, pSurfTm) ; + + // CONVERSIONE DELL'EXTRUSION AD UN'ALTRA SUPERFICIE RHINO PRIMA DI ESSERE CONVERTITA + //const ON_Extrusion* onExtrusion = ON_Extrusion::Cast( oGeometry) ; + //if (nullptr == onExtrusion) + // return false ; + //ON_Object* onObject = nullptr; + //if ( onExtrusion->IsCapped() || onExtrusion->ProfileCount() >= 2) + // onObject = onExtrusion->BrepForm(0) ; + //if ( nullptr == onObject) + // onObject = onExtrusion->SumSurfaceForm(0) ; + //if ( nullptr == onObject) + // onObject = onExtrusion->NurbsSurface(0) ; + //if ( nullptr == onObject) + // return false ; + //ON_Surface* onSurface = static_cast( onObject) ; + //ISurf* pSurf = nullptr ; + //ConvertSurface( onSurface, pSurf) ; + break ; + } + case ON::object_type::mesh_object : + break ; + case ON::object_type::loop_object : + break ; + default : + break ; + } + + //++ component_model_index ; + //mcr = model.ComponentFromIndex( component_type, component_model_index) ; + //mgc = ON_ModelGeometryComponent::Cast( mcr.ModelComponent()) ; + //ON_ModelComponentReference mcr = component_iterator.NextComponentReference() ; + //const ON_ModelGeometryComponent* mgc = ON_ModelGeometryComponent::Cast( mcr.ModelComponent()) ; + + //const ON_ModelComponent* mc = component_iterator.NextComponent() ; + //const ON_ModelGeometryComponent* mgc = ON_ModelGeometryComponent::Cast( mc) ; + + } + + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Import3dm::ConvertPoint( const ON_Point& onPoint, Point3d& pt) +{ + double x = onPoint.point.x ; + double y = onPoint.point.y ; + double z = onPoint.point.z ; + // creo il punto nel nostro kernel + pt.Set( x, y, z) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Import3dm::ConvertPoint( const ON_3dPoint* on3dPoint, Point3d& pt) +{ + double x = on3dPoint->x ; + double y = on3dPoint->y ; + double z = on3dPoint->z ; + // creo il punto nel nostro kernel + pt.Set( x, y, z) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +ConvertVector( const ON_3dVector& onVector, Vector3d& vt) +{ + vt.x = onVector.x ; + vt.y = onVector.y ; + vt.z = onVector.z ; + return true ; +} + +//---------------------------------------------------------------------------- +ON::eCurveType +ON_CurveType( const ON_Curve* curve) +{ + //const ON_ClassId* curve_id = &ON_CLASS_RTTI(ON_Curve); + //const ON_ClassId* id = curve->ClassId(); + + //// "fake virtual" handling of fast/easy special cases + //while (0 != id && curve_id != id ) + //{ + // if ( &ON_CLASS_RTTI(ON_ArcCurve) == id ) + // return ON::ctArc; + // if ( &ON_CLASS_RTTI(ON_LineCurve) == id ) + // return ON::ctLine; + // if ( &ON_CLASS_RTTI(ON_PolylineCurve) == id ) + // return ON::ctPolyline; + // if ( &ON_CLASS_RTTI(ON_CurveProxy) == id ) + // return ON::ctProxy; + // if ( &ON_CLASS_RTTI(ON_PolyCurve) == id ) + // return ON::ctPolycurve; + // if ( &ON_CLASS_RTTI(ON_NurbsCurve) == id ) + // return ON::ctNurbs; + // if ( &ON_CLASS_RTTI(ON_CurveOnSurface) == id ) + // return ON::ctOnsurface; + // id = id->BaseClass(); + //} + + return ON::ctCurve; +} + +//---------------------------------------------------------------------------- +bool +Import3dm::ConvertCurve( const ON_Curve* onCurve, ICurve* pCurve, PolyLine* pPL) +{ + //const ON_Curve* on_curve = ON_Curve::Cast( oGeometry) ; + //const ON_Curve* onCurve = static_cast( oCurve) ; // qui potrei mettere anche dynamic_cast + + ON::eCurveType curve_type = ON_CurveType( onCurve) ; + + switch ( curve_type) { + case ON::eCurveType::ctArc : { + const ON_ArcCurve* onArc = static_cast( onCurve) ; + Point3d ptCenter, ptStart, ptEnd ; + ConvertPoint( onArc->m_arc.plane.origin, ptCenter) ; + ConvertPoint( onArc->m_arc.PointAt( onArc->m_arc.Domain().Min()), ptStart) ; + ConvertPoint( onArc->m_arc.PointAt( onArc->m_arc.Domain().Max()), ptEnd) ; + Vector3d vtN ; + ON_3dVector on_vtN = onArc->m_arc.plane.zaxis ; + ConvertVector( on_vtN, vtN) ; + ICurveArc* pCurveArc( CreateCurveArc()) ; + pCurveArc->SetC2PN( ptCenter, ptStart, ptEnd, vtN) ; + pCurve = pCurveArc ; + break ; + } + case ON::eCurveType::ctCircle : { + const ON_ArcCurve* onCircle = static_cast( onCurve) ; + Point3d ptCenter ; + ConvertPoint( onCircle->m_arc.plane.origin, ptCenter) ; + Vector3d vtN ; + ON_3dVector on_vtN = onCircle->m_arc.plane.zaxis ; + ConvertVector( on_vtN, vtN) ; + double dRad = onCircle->m_arc.Radius() ; + ICurveArc* pCurveArc( CreateCurveArc()) ; + pCurveArc->Set( ptCenter, vtN, dRad) ; + pCurve = pCurveArc ; + break ; + } + case ON::eCurveType::ctLine : { + const ON_LineCurve* onCurveLine = static_cast( onCurve) ; + Point3d ptStart, ptEnd ; + ConvertPoint( onCurveLine->m_line.from, ptStart) ; + ConvertPoint( onCurveLine->m_line.to, ptEnd) ; + ICurveLine* pCurveLine ( CreateCurveLine()) ; + pCurveLine->Set( ptStart, ptEnd) ; + pCurve = pCurveLine ; + break ; + } + case ON::eCurveType::ctNurbs : { + // da trasformare in una bezier + const ON_NurbsCurve* onNurbsCurve = static_cast( onCurve) ; + bool bIsRational = onNurbsCurve->IsRational() ; + CNurbsData nuCurve ; + nuCurve.bRat = bIsRational ; + nuCurve.nDeg = onNurbsCurve->Order() - 1 ; + int nCount = onNurbsCurve->CVCount() ; + if ( bIsRational) { + // vettore dei punti di controllo + PNTVECTOR vPtCtrl ; + // vettore dei pesi + DBLVECTOR vWeCtrl ; + for( int i = 0 ; i < nCount; ++i) { + ON_4dPoint o4dPoint ; + onNurbsCurve->GetCV( i, o4dPoint) ; + ON_3dPoint o3dPoint( o4dPoint) ; + Point3d ptCtrl ; + ConvertPoint( o3dPoint, ptCtrl) ; + vPtCtrl.push_back( ptCtrl) ; + vWeCtrl.push_back( o4dPoint.w) ; + } + nuCurve.vCP = vPtCtrl ; + nuCurve.vW = vWeCtrl ; + } + else { + // vettore dei punti di controllo + PNTVECTOR vPtCtrl ; + for( int i = 0 ; i < nCount; ++i) { + ON_3dPoint o3dPoint ; + onNurbsCurve->GetCV( i, o3dPoint) ; + Point3d ptCtrl ; + ConvertPoint( o3dPoint, ptCtrl) ; + vPtCtrl.push_back( ptCtrl) ; + } + nuCurve.vCP = vPtCtrl ; + } + + // vettore dei nodi + DBLVECTOR vU ; + int nKnot = onNurbsCurve->KnotCount() ; + for ( int j = 0 ; j < nKnot ; ++j ) { + onNurbsCurve->Knot( j) ; + vU.push_back( j) ; + } + nuCurve.vU = vU ; + nuCurve.bClosed = onNurbsCurve->IsClosed() ; + nuCurve.bPeriodic = onNurbsCurve->IsPeriodic() ; + // ora che ho riempito la Nurbs con tutti i dati la converto in Bezier + pCurve = NurbsToBezierCurve( nuCurve) ; + break ; + } + case ON::eCurveType::ctOnsurface :{ + const ON_CurveOnSurface* onProxyCurve = static_cast( onCurve) ; + // + break ; + } + case ON::eCurveType::ctProxy :{ + const ON_CurveProxy* onProxyCurve = static_cast( onCurve) ; + ON_Curve* onCurveToConvert = onProxyCurve->ProxyCurve()->Duplicate() ; + // devo fare le dovute modifiche alla curva per ottenere la curva proxy + if ( onProxyCurve->ProxyCurveIsReversed()) + onCurveToConvert->Reverse() ; + onCurveToConvert->SetDomain( onProxyCurve->ProxyCurveDomain()) ; + ConvertCurve( onCurveToConvert, pCurve) ; + break ; + } + case ON::eCurveType::ctPolycurve : { + const ON_PolyCurve* onPolyline = static_cast( onCurve) ; + int nCurves = onPolyline->Count() ; + ICurveComposite* pCrvCompo( CreateCurveComposite()) ; + for ( int i = 0 ; i < nCurves; ++i) { + ICurve* pCurveToAdd = nullptr ; + ON_Curve* onCurveToAdd = onPolyline->SegmentCurve( i) ; + ConvertCurve( onCurveToAdd, pCurveToAdd) ; + pCrvCompo->AddCurve( pCurveToAdd) ; + } + pCurve = pCrvCompo ; + break ; + } + case ON::eCurveType::ctPolyline : { + const ON_PolylineCurve* onPolyline = static_cast( onCurve) ; + int nPoints = onPolyline->PointCount() ; + for ( int i = 0 ; i < nPoints ; ++i ) { + Point3d pt ; + ConvertPoint( onPolyline->m_pline[i], pt) ; + pPL->AddUPoint( i, pt) ; + } + break ; + } + default : + break ; + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +ConvertSurface( const ON_Surface* onSurf, ISurf* pSurf) +{ + return false ; +} diff --git a/Import3dm.h b/Import3dm.h new file mode 100644 index 0000000..a994d4e --- /dev/null +++ b/Import3dm.h @@ -0,0 +1,43 @@ +//---------------------------------------------------------------------------- +// EgalTech 2023 +//---------------------------------------------------------------------------- +// File : Import3dm.h Data : 23.06.23 Versione : 2.5f1 +// Contenuto : Dichiarazione della classe Import3dm. +// +// +// +// Modifiche : 23.06.23 DB Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EExImport3dm.h" +//#include "/EgtDev/opennurbs/opennurbs.h" + +class ON_Point ; +class ON_Object ; +class ON_3dPoint ; +class ON_Curve ; +class ON_Surface ; +class ICurve ; +class ISurf ; + +//---------------------------------------------------------------------------- +class Import3dm : public IImport3dm +{ +public : + virtual bool Import( const std::string& sFile, IGeomDB* pGDB, int nIdGroup, double dScaleFactor = 1) ; + +private : + bool ConvertPoint( const ON_Point& onPoint, Point3d& pt) ; + bool ConvertPoint( const ON_3dPoint* on3dPoint, Point3d& pt) ; + bool ConvertCurve( const ON_Curve* onCurve, ICurve* pCurve, PolyLine* pPL = nullptr) ; + bool ConvertSurface( const ON_Surface* onSurface, ISurf* pSurf) ; + +private : + IGeomDB* m_pGDB ; + int m_nIdGroup ; + double m_dScaleFactor ; +} ; \ No newline at end of file diff --git a/Import3dmEnts.cpp b/Import3dmEnts.cpp new file mode 100644 index 0000000..7cc455b --- /dev/null +++ b/Import3dmEnts.cpp @@ -0,0 +1,34 @@ +//---------------------------------------------------------------------------- +// EgalTech 2023 +//---------------------------------------------------------------------------- +// File : Import3dmEnts.cpp Data : 27.06.23 Versione : 2.5f1 +// Contenuto : Implementazione di Import3dm : gestione delle entità. +// +// +// +// Modifiche : 27.06.23 DB Creazione modulo. +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "Import3dm.h" +#include "DllMain.h" +#include "/EgtDev/Include/EGkStringUtils3d.h" +#include "/EgtDev/Include/EGkGeoPoint3d.h" +#include "/EgtDev/Include/EGkGeoVector3d.h" +#include "/EgtDev/Include/EGkCurveLine.h" +#include "/EgtDev/Include/EGkCurveArc.h" +#include "/EgtDev/Include/EGkCurveComposite.h" +#include "/EgtDev/Include/EGkCurveAux.h" +#include "/EgtDev/Include/EGkCurveByInterp.h" +#include "/EgtDev/Include/EGkSurfTriMesh.h" +#include "/EgtDev/Include/EGkExtText.h" +#include "/EgtDev/Include/EGkGdbIterator.h" +#include "/EgtDev/Include/EGnStringKeyVal.h" +#include "/EgtDev/Include/EgtStringEncoder.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + + diff --git a/stdafx.h b/stdafx.h index d49ee15..1866a70 100644 --- a/stdafx.h +++ b/stdafx.h @@ -34,5 +34,6 @@ #pragma comment(lib, EGTLIBDIR "SEgtLock" EGTLIBVER ".lib") #pragma comment(lib, EGTEXTDIR "/libzip/Lib/zip" EGTLIBVER ".lib") #pragma comment(lib, EGTEXTDIR "/lib3mf/Lib/lib3mf" EGTLIBVER ".lib") +//#pragma comment(lib, EGTEXTDIR "opennurbs_public.lib")