/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include #include "DgnImport3dObject.h" #include "DgnImportCommon.h" #include "DgnImportContext.h" #include "DgDatabase.h" #include "DgLevelTableRecord.h" #include "Dg3DObject.h" #include "DgBSplineSurface.h" #include "DbBody.h" #include "Ge/GeSurfacePtrArray.h" #include "BrepBuilderInitialData.h" #include "BrepBuilderFillerModule.h" #include "Br/BrBrep.h" #include "DgModelerGeometryCreator.h" #include "DgBrepBuilderFilerInitPE.h" #include "DbRevolveOptions.h" #include "DbRevolvedSurface.h" #include "Ge/GeLineSeg3d.h" #include "Ge/GeCircArc3d.h" #include "Ge/GeEllipArc3d.h" #include "Ge/GeNurbCurve3d.h" #include "Ge/GeNurbSurface.h" #include "Ge/GeLineSeg2d.h" #include "Db3dPolyline.h" #include "Ge/GePolyline3d.h" TOOLKIT_EXPORT OdRxClassPtr odrxGetModelerGeometryCreatorService(); namespace TD_DGN_IMPORT { //--------------------------------------------------------------------------------------------------- bool OdDgnSolidImportPE::allowImportElement(OdDgElement* e) { bool bRet = true; OdDgSolid* pSolid = (OdDgSolid*)e; if( !OdDgnImportContext::isImportInvisible() ) { bRet = !pSolid->getInvisibleFlag(); if( bRet ) { OdUInt32 uLevelEntryId = pSolid->getLevelEntryId(); try { OdDg3dObjectHelper helper( pSolid ); OdDg3dObjectHelper::EntireObject structure; helper.extractInformation( structure ); OdDgGraphicsElementPtr pGraph; for(OdUInt32 k = 0; k < structure.size(); k++ ) { for( OdUInt32 j = 0; j < structure[k].m_boundary.size(); j++ ) { if( !structure[k].m_boundary[j].isNull() ) { pGraph = structure[k].m_boundary[j]; break; } } if( !pGraph.isNull() ) { break; } } if( !pGraph.isNull() ) { uLevelEntryId = pGraph->getLevelEntryId(); } } catch(...) { } OdDgDatabase* pDb = e->database(); if( pDb ) { OdDgLevelTablePtr pLevelTable = pDb->getLevelTable(OdDg::kForRead); if( !pLevelTable.isNull() ) { OdDgElementId idLevel = pLevelTable->getAt( uLevelEntryId ); if( !idLevel.isNull() ) { OdDgLevelTableRecordPtr pLevel = idLevel.openObject(OdDg::kForRead); if( !pLevel.isNull() ) { bRet = pLevel->getIsDisplayedFlag() && !pLevel->getIsFrozenFlag(); } } } } if( bRet && OdDgnImportContext::isLevelMask() ) { bRet = OdDgnImportContext::checkLevelMask( uLevelEntryId ); } } } return bRet; } //--------------------------------------------------------------------------------------------------- OdGeNurbCurve3d convertGeCurveToNurbsCurve(const OdGeCurve3d* pCurve) { OdGeNurbCurve3d retVal; switch (pCurve->type()) { case OdGe::kLineSeg3d: { OdGeLineSeg3d* pLineSeg = (OdGeLineSeg3d*)(pCurve); retVal = OdGeNurbCurve3d(*pLineSeg); } break; case OdGe::kCircArc3d: { OdGeCircArc3d* pArc = (OdGeCircArc3d*)(pCurve); OdGeEllipArc3d ellipArc(*pArc); retVal = OdGeNurbCurve3d(ellipArc); } break; case OdGe::kEllipArc3d: { OdGeEllipArc3d* pArc = (OdGeEllipArc3d*)(pCurve); retVal = OdGeNurbCurve3d(*pArc); } break; default: { OdGeNurbCurve3d* pNurbs = (OdGeNurbCurve3d*)(pCurve); retVal = *pNurbs; } } int iDegree; bool bRational, bPeriodic; OdGeKnotVector vrKnots; OdGePoint3dArray arrCtrlPts; OdGeDoubleArray arrWeights; retVal.getDefinitionData(iDegree, bRational, bPeriodic, vrKnots, arrCtrlPts, arrWeights); vrKnots.setRange(0.0, 1.0); retVal.set(iDegree, vrKnots, arrCtrlPts, arrWeights, bPeriodic); return retVal; } //--------------------------------------------------------------------------------------------------- OdGeNurbCurve2d createLineSegNurbCurve(const OdGeLineSeg2d& lineSeg, const OdGeInterval& domain = OdGeInterval()) { OdGeNurbCurve2d retVal; OdGePoint2dArray arrPts; arrPts.push_back(lineSeg.startPoint()); arrPts.push_back(lineSeg.endPoint()); OdGeKnotVector vrKnots; OdGeDoubleArray arrWeights; vrKnots.append(0.0); vrKnots.append(0.0); vrKnots.append(1.0); vrKnots.append(1.0); if (domain.isBounded() && !(OdEqual(domain.lowerBound(), 0.) && OdEqual(domain.upperBound(), 1.))) { const int nKt = vrKnots.logicalLength(); if (nKt != 0) { const double lenIntervalOld = vrKnots[nKt - 1] - vrKnots[0]; const double lenIntervalNew = domain.upperBound() - domain.lowerBound(); double ktPrev = vrKnots[0]; vrKnots[0] = domain.lowerBound(); int i; for (i = 1; i < nKt; ++i) { double lenSpan = vrKnots[i] - ktPrev; ktPrev = vrKnots[i]; vrKnots[i] = vrKnots[i - 1] + lenSpan * lenIntervalNew / lenIntervalOld; } } } retVal.set(1, vrKnots, arrPts, arrWeights, false); return retVal; } //--------------------------------------------------------------------------------------------------- bool createRevolveBrepDataForSurface( const OdArray& arrGeCurves, const OdGePoint3d& ptRevolveOrigin, const OdGeVector3d& vrRevolveAxis, double dRevolveAngle, BrepBuilderInitialData& surfaceData) { bool bRet = true; try { for (OdUInt32 i = 0; i < arrGeCurves.size(); i++) { OdGeCurve3dPtr pCurve = arrGeCurves[i]; if (pCurve.isNull()) return false; if ((pCurve->type() != OdGe::kLineSeg3d) && (pCurve->type() != OdGe::kCircArc3d) && (pCurve->type() != OdGe::kEllipArc3d) && (pCurve->type() != OdGe::kNurbCurve3d)) return false; OdGeNurbCurve3d baseCurve = convertGeCurveToNurbsCurve(pCurve); int iBaseDegree; bool bBaseRational, bBasePeriodic; OdGeKnotVector vrBaseKnots; OdGePoint3dArray arrBaseCtrlPts; OdGeDoubleArray arrBaseWeights; int iRevolveDegree; bool bRevolveRational, bRevolvePeriodic; OdGeKnotVector vrRevolveKnots; OdGePoint3dArray arrRevolveCtrlPts; OdGeDoubleArray arrRevolveWeights; baseCurve.getDefinitionData(iBaseDegree, bBaseRational, bBasePeriodic, vrBaseKnots, arrBaseCtrlPts, arrBaseWeights); OdGeVector3d vrRef = OdGeVector3d::kIdentity; OdGePoint3dArray arrCenterPts; OdArray arrRadius; OdUInt32 j; OdArray arrNurbSectionCtrlPts; for (j = 0; j < arrBaseCtrlPts.size(); j++) { OdGePoint3d ptRevolveStart = arrBaseCtrlPts[j]; OdGePlane basePlane = OdGePlane(ptRevolveStart, vrRevolveAxis); OdGePoint3d ptRevolveCenter = ptRevolveOrigin.project(basePlane, vrRevolveAxis); OdGeVector3d vrCurRef = ptRevolveStart - ptRevolveCenter; double dRadius = vrCurRef.length(); arrCenterPts.push_back(ptRevolveCenter); arrRadius.push_back(dRadius); if (vrRef.isZeroLength() && !OdZero(dRadius, 1e-8)) { vrRef = vrCurRef; vrRef.normalize(); OdGeCircArc3d geRevolveArc(arrCenterPts[j], vrRevolveAxis, vrRef, arrRadius[j], 0, dRevolveAngle); OdGeNurbCurve3d revolveCurve = convertGeCurveToNurbsCurve(&geRevolveArc); revolveCurve.getDefinitionData(iRevolveDegree, bRevolveRational, bRevolvePeriodic, vrRevolveKnots, arrRevolveCtrlPts, arrRevolveWeights); } } if (vrRef.isZeroLength()) return false; for (j = 0; j < arrBaseCtrlPts.size(); j++) { int iCurDegree; bool bCurRational, bCurPeriodic; OdGeKnotVector vrCurKnots; OdGePoint3dArray arrCurCtrlPts; OdGeDoubleArray arrCurWeights; if (OdZero(arrRadius[j])) { for (OdUInt32 k = 0; k < arrRevolveCtrlPts.size(); k++) arrCurCtrlPts.push_back(arrCenterPts[j]); } else { OdGeCircArc3d geRevolveArc(arrCenterPts[j], vrRevolveAxis, vrRef, arrRadius[j], 0, dRevolveAngle); OdGeNurbCurve3d revolveCurve = convertGeCurveToNurbsCurve(&geRevolveArc); revolveCurve.getDefinitionData(iCurDegree, bCurRational, bCurPeriodic, vrCurKnots, arrCurCtrlPts, arrCurWeights); if (arrCurCtrlPts.size() != arrRevolveCtrlPts.size()) return false; arrNurbSectionCtrlPts.push_back(arrCurCtrlPts); } } OdGePoint3dArray arrNurbsPts; OdGeDoubleArray arrNurbsWeights; for (j = 0; j < arrBaseCtrlPts.size(); j++) { for (OdUInt32 k = 0; k < arrRevolveCtrlPts.size(); k++) { arrNurbsPts.push_back(arrNurbSectionCtrlPts[j][k]); arrNurbsWeights.push_back(arrRevolveWeights[k]); } } int iPropsInU = OdGe::kOpen; int iPropsInV = OdGe::kOpen; if (OdZero(dRevolveAngle - Oda2PI)) iPropsInV = OdGe::kClosed; if (bBaseRational) iPropsInU |= OdGe::kRational; if (bRevolveRational) iPropsInV |= OdGe::kRational; OdGeNurbSurface newSurface; newSurface.set(iBaseDegree, iRevolveDegree, iPropsInU, iPropsInV, arrBaseCtrlPts.size(), arrRevolveCtrlPts.size(), arrNurbsPts, arrNurbsWeights, vrBaseKnots, vrRevolveKnots); BrepBuilderInitialSurface boundarySurface; boundarySurface.pSurf = new OdGeNurbSurface(newSurface); boundarySurface.direction = OdBrepBuilder::kReversed; boundarySurface.hasColor = false; boundarySurface.hasMaterialMapping = false; // Update edges. OdGeNurbCurve3d bottomCurve; OdGeNurbCurve3d topCurve; OdGeNurbCurve3d leftCurve; OdGeNurbCurve3d rightCurve; newSurface.computeVIsoLine(0, bottomCurve); newSurface.computeVIsoLine(1, topCurve); newSurface.computeUIsoLine(0, leftCurve); newSurface.computeUIsoLine(1, rightCurve); OdUInt32 uBottomIndex = surfaceData.edges.size(); OdUInt32 uLeftIndex = surfaceData.edges.size() + 1; OdUInt32 uTopIndex = surfaceData.edges.size() + 2; OdUInt32 uRightIndex = surfaceData.edges.size() + 3; BrepBuilderInitialEdge bottomEdge; bottomEdge.hasColor = false; bottomEdge.curve = new OdGeNurbCurve3d(bottomCurve); surfaceData.edges.push_back(bottomEdge); BrepBuilderInitialEdge leftEdge; leftEdge.hasColor = false; leftEdge.curve = new OdGeNurbCurve3d(leftCurve); surfaceData.edges.push_back(leftEdge); BrepBuilderInitialEdge topEdge; topEdge.hasColor = false; topEdge.curve = new OdGeNurbCurve3d(topCurve); surfaceData.edges.push_back(topEdge); BrepBuilderInitialEdge rightEdge; rightEdge.hasColor = false; rightEdge.curve = new OdGeNurbCurve3d(rightCurve); surfaceData.edges.push_back(rightEdge); // Create coedge loop. BrepBuilderInitialLoop boundaryLoop; OdGeLineSeg2d lineSegU0(OdGePoint2d(0.0, 0.0), OdGePoint2d(1.0, 0.0)); OdGeLineSeg2d lineSegV0(OdGePoint2d(0.0, 0.0), OdGePoint2d(0.0, 1.0)); OdGeLineSeg2d lineSegU1(OdGePoint2d(0.0, 1.0), OdGePoint2d(1.0, 1.0)); OdGeLineSeg2d lineSegV1(OdGePoint2d(1.0, 0.0), OdGePoint2d(1.0, 1.0)); OdGeNurbCurve2d curveSegU0 = createLineSegNurbCurve(lineSegU0); OdGeNurbCurve2d curveSegV0 = createLineSegNurbCurve(lineSegV0); OdGeNurbCurve2d curveSegU1 = createLineSegNurbCurve(lineSegU1); OdGeNurbCurve2d curveSegV1 = createLineSegNurbCurve(lineSegV1); if (!OdZero(bottomCurve.length())) { BrepBuilderInitialCoedge boundaryCoedge1; boundaryCoedge1.direction = OdBrepBuilder::kReversed; boundaryCoedge1.edgeIndex = uBottomIndex; boundaryCoedge1.curve = new OdGeNurbCurve2d(curveSegU0); boundaryLoop.coedges.push_back(boundaryCoedge1); } BrepBuilderInitialCoedge boundaryCoedge2; boundaryCoedge2.direction = OdBrepBuilder::kForward; boundaryCoedge2.edgeIndex = uLeftIndex; boundaryCoedge2.curve = new OdGeNurbCurve2d(curveSegV0); boundaryLoop.coedges.push_back(boundaryCoedge2); BrepBuilderInitialCoedge boundaryCoedge3; boundaryCoedge3.direction = OdBrepBuilder::kForward; boundaryCoedge3.edgeIndex = uTopIndex; boundaryCoedge3.curve = new OdGeNurbCurve2d(curveSegU1); boundaryLoop.coedges.push_back(boundaryCoedge3); BrepBuilderInitialCoedge boundaryCoedge4; boundaryCoedge4.direction = OdBrepBuilder::kReversed; boundaryCoedge4.edgeIndex = uRightIndex; boundaryCoedge4.curve = new OdGeNurbCurve2d(curveSegV1); boundaryLoop.coedges.push_back(boundaryCoedge4); boundarySurface.loops.push_back(boundaryLoop); if (surfaceData.complexes.size()) surfaceData.complexes.last().last().push_back(boundarySurface); else { BrepBuilderShellsArray arrShells; BrepBuilderInitialSurfaceArray arrSurfaces; arrSurfaces.push_back(boundarySurface); arrShells.push_back(arrSurfaces); surfaceData.complexes.push_back(arrShells); } } } catch (...) { bRet = false; } return bRet; } //--------------------------------------------------------------------------------------------------- bool isAxisIntersectOfRegion( const OdDbRegionPtr& pRegionEnt, const OdGePoint3d& ptOrigin, const OdGeVector3d& vrAxis, OdDbRegionPtr& pPositiveRgn, OdDbRegionPtr& pNegativeRgn ) { bool bRet = false; OdGePlane regionPlane; OdDb::Planarity planarity; if( pRegionEnt->isPlanar() && (pRegionEnt->getPlane(regionPlane, planarity) == eOk) ) { OdGePoint3d ptPrjOrigin = ptOrigin; ptPrjOrigin = ptPrjOrigin.project(regionPlane, regionPlane.normal()); OdGeVector3d vrYAxis = vrAxis; OdGeVector3d vrZAxis = regionPlane.normal(); OdGeVector3d vrXAxis = vrZAxis.crossProduct(vrYAxis); if( !vrYAxis.isZeroLength() ) { vrXAxis.normalize(); vrYAxis.normalize(); vrZAxis.normalize(); } OdGeMatrix3d matTransform; OdGeMatrix3d matTransformBack; matTransform.setCoordSystem(ptPrjOrigin, vrXAxis, vrYAxis, vrZAxis); matTransformBack = matTransform; matTransformBack = matTransformBack.invert(); OdDbRegionPtr pRegionClone = pRegionEnt->clone(); OdGeExtents3d extRegion; pRegionClone->transformBy(matTransformBack); pRegionClone->getGeomExtents(extRegion); if( OdLess(extRegion.minPoint().x, 0) && OdGreater(extRegion.maxPoint().x, 0) ) { double dDiagonalLength = extRegion.diagonal().length(); OdGePoint3dArray arrPositiveLinePts; arrPositiveLinePts.push_back(OdGePoint3d(0.0, -dDiagonalLength, 0.0)); arrPositiveLinePts.push_back(OdGePoint3d(dDiagonalLength, -dDiagonalLength, 0.0)); arrPositiveLinePts.push_back(OdGePoint3d(dDiagonalLength, dDiagonalLength, 0.0)); arrPositiveLinePts.push_back(OdGePoint3d(0.0, dDiagonalLength, 0.0)); arrPositiveLinePts.push_back(OdGePoint3d(0.0, -dDiagonalLength, 0.0)); OdGePoint3dArray arrNegativeLinePts; arrNegativeLinePts.push_back(OdGePoint3d(0.0, -dDiagonalLength, 0.0)); arrNegativeLinePts.push_back(OdGePoint3d(0.0, dDiagonalLength, 0.0)); arrNegativeLinePts.push_back(OdGePoint3d(-dDiagonalLength, dDiagonalLength, 0.0)); arrNegativeLinePts.push_back(OdGePoint3d(-dDiagonalLength, -dDiagonalLength, 0.0)); arrNegativeLinePts.push_back(OdGePoint3d(0.0, -dDiagonalLength, 0.0)); OdGePolyline3d gePositiveLine(arrPositiveLinePts); OdGePolyline3d geNegativeLine(arrNegativeLinePts); OdDb3dPolylinePtr pPositivePolyline3d = OdDb3dPolyline::createObject(); OdDb3dPolylinePtr pNegativePolyline3d = OdDb3dPolyline::createObject(); pPositivePolyline3d->setFromOdGeCurve(gePositiveLine); pNegativePolyline3d->setFromOdGeCurve(geNegativeLine); pPositivePolyline3d->transformBy(matTransform); pNegativePolyline3d->transformBy(matTransform); OdRxObjectPtrArray arrLines; OdRxObjectPtrArray arrRegions; arrLines.push_back(pPositivePolyline3d); if( (OdDbRegion::createFromCurves(arrLines, arrRegions) == eOk) && (arrRegions.size() > 0) ) pPositiveRgn = arrRegions[0]; arrLines.clear(); arrRegions.clear(); arrLines.push_back(pNegativePolyline3d); if ((OdDbRegion::createFromCurves(arrLines, arrRegions) == eOk) && (arrRegions.size() > 0)) pNegativeRgn = arrRegions[0]; if( !pPositiveRgn.isNull() && !pNegativeRgn.isNull() ) bRet = true; } } return bRet; } //--------------------------------------------------------------------------------------------------- bool convertSolidTo3dSurface(OdDgElement* pElm, OdDbBlockTableRecord* pOwner, bool bSolid ) { bool bRet = true; try { OdDg3dSolidBrepBuilderInitialDataPEPtr pSurfaceBrep = OdDgBrepBuilderInitialDataPEPtr(OdRxObjectPtr(pElm)); if( pSurfaceBrep.isNull() ) return false; if( odrxServiceDictionary()->getAt(OD_T("OdModelerGeometryCreator")).isNull() ) odrxDynamicLinker()->loadModule(OdModelerGeometryModuleName); OdBrepBuilder brepBuilder; // AcisBrepBuilder OdRxClassPtr pCreatorService = ::odrxGetModelerGeometryCreatorService(); if( pCreatorService.isNull() ) { ODA_ASSERT_ONCE(!"ModelerGeometryCreatorService has not been created."); return false; } OdModelerGeometryCreatorPtr pCreatorDWG = pCreatorService->create(); if( pCreatorDWG.isNull() ) { ODA_ASSERT_ONCE(!"OdModelerGeometryCreator has not been created."); return false; } if( pCreatorDWG->initBrepBuilder(brepBuilder, bSolid ? kSolid : kOpenShell) != eOk ) { ODA_ASSERT_ONCE(!"Brep builder has not been initialized."); return false; } OdDg3dSolidBrepBuilderInitialDataPE::OdDg3dSolidBaseType solidType = pSurfaceBrep->getDgnSolidBaseType(pElm); if( solidType == OdDg3dSolidBrepBuilderInitialDataPE::kExtrudeBased ) { BrepBuilderInitialData brepData; double dScale = 1.0; if( !pSurfaceBrep->getBrepBuilderInitialData( pElm, brepData, dScale ) ) { ODA_ASSERT_ONCE(!"Can't get solid brep builder initial data."); return false; } OdBrepBuilderFiller BBFiller; if(BBFiller.initFrom(brepBuilder, brepData) != eOk) { ODA_ASSERT_ONCE(!"Error on innitialization of edges, coedges and surfaces."); return false; } OdModelerGeometryPtr pGeometry = brepBuilder.finish(); if( pGeometry.isNull() ) { ODA_ASSERT_ONCE(!"Modeler geometry is null."); return false; } if( bSolid ) { OdDb3dSolidPtr pSolid = OdDb3dSolid::createObject(); pSolid->setBody(pGeometry); pOwner->appendOdDbEntity(pSolid); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pSolid); pSolid->transformBy( OdGeMatrix3d::scaling(dScale) ); } else { OdDbSurfacePtr pBody = OdDbSurface::createObject(); pBody->setBody(pGeometry); pOwner->appendOdDbEntity(pBody); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pBody); pBody->transformBy( OdGeMatrix3d::scaling(dScale) ); } } else if( solidType == OdDg3dSolidBrepBuilderInitialDataPE::kRevolveBased ) { OdArray arrRevolveData; if( !pSurfaceBrep->getRevolveSolidData( pElm, arrRevolveData ) ) { ODA_ASSERT_ONCE(!"Can't get solid revolve data."); return false; } for( OdUInt32 i = 0; i < arrRevolveData.size(); i++ ) { BrepBuilderInitialData brepData; OdArray arrCurvesToRevolve; bool bCreateRegion = false; if( pSurfaceBrep->createRegionData( arrRevolveData[i].m_boundary, arrRevolveData[i].m_vrBoundaryNormal, brepData ) ) { bCreateRegion = true; if( pCreatorDWG->initBrepBuilder(brepBuilder, kOpenShell) != eOk ) { ODA_ASSERT_ONCE(!"Brep builder has not been initialized."); bCreateRegion = false; } else { OdBrepBuilderFiller BBFiller; if(BBFiller.initFrom(brepBuilder, brepData) != eOk) bCreateRegion = false; else { try { OdModelerGeometryPtr pGeometry = brepBuilder.finish(); if( pGeometry.isNull() ) bCreateRegion = false; else { OdDbRegionPtr pRegion = OdDbRegion::createObject(); pRegion->setBody(pGeometry); pRegion->setDatabaseDefaults( pOwner->database() ); arrCurvesToRevolve.push_back(pRegion); } } catch(...) { bCreateRegion = false; } } } } if( !bCreateRegion && bSolid ) { bRet = false; break; } else if( !bCreateRegion ) { BrepBuilderInitialData surfaceData; if ((arrRevolveData[i].m_boundary.size() > 0) && createRevolveBrepDataForSurface(arrRevolveData[i].m_boundary[0].m_arrCurves, arrRevolveData[i].m_ptRevolveOrigin, arrRevolveData[i].m_vrRevolveAxis, arrRevolveData[i].m_dRevolveAngle, surfaceData)) { OdBrepBuilderFiller BBFiller; if (BBFiller.initFrom(brepBuilder, surfaceData) != eOk) { ODA_ASSERT_ONCE(!"Error on innitialization of edges, coedges and surfaces."); return false; } OdModelerGeometryPtr pGeometry = brepBuilder.finish(); if (pGeometry.isNull()) { ODA_ASSERT_ONCE(!"Modeler geometry is null."); bRet = false; } else { OdDbSurfacePtr pBody = OdDbSurface::createObject(); pBody->setBody(pGeometry); pOwner->appendOdDbEntity(pBody); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pBody); bRet = true; } } else bRet = false; } else if( bSolid ) { OdDbRegionPtr pPositiveRgn; OdDbRegionPtr pNegativeRgn; if( isAxisIntersectOfRegion(arrCurvesToRevolve[0], arrRevolveData[i].m_ptRevolveOrigin, arrRevolveData[i].m_vrRevolveAxis, pPositiveRgn, pNegativeRgn) ) { OdDbRegionPtr pPositiveBase = arrCurvesToRevolve[0]; OdDbRegionPtr pNegativeBase = pPositiveBase->clone(); if( pPositiveBase->booleanOper(OdDb::kBoolSubtract, pPositiveRgn) != eOk ) return false; OdDbRegionPtr pPosResult = pPositiveBase->clone(); if( pNegativeBase->booleanOper(OdDb::kBoolSubtract, pPosResult) != eOk ) return false; OdDbRevolveOptions curOptions; OdDb3dSolidPtr pSolidP = OdDb3dSolid::createObject(); OdResult retVal = pSolidP->createRevolvedSolid(pPositiveBase, arrRevolveData[i].m_ptRevolveOrigin, arrRevolveData[i].m_vrRevolveAxis, arrRevolveData[i].m_dRevolveAngle, 0, curOptions); if (retVal == eOk) { pOwner->appendOdDbEntity(pSolidP); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pSolidP); } else bRet = false; if( bRet ) { OdDb3dSolidPtr pSolidN = OdDb3dSolid::createObject(); retVal = pSolidN->createRevolvedSolid(pNegativeBase, arrRevolveData[i].m_ptRevolveOrigin, arrRevolveData[i].m_vrRevolveAxis, arrRevolveData[i].m_dRevolveAngle, 0, curOptions); if (retVal == eOk) { pOwner->appendOdDbEntity(pSolidN); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pSolidN); } else { if( !pSolidP.isNull() ) pSolidP->erase(); bRet = false; } } } else { OdDbRevolveOptions curOptions; OdDb3dSolidPtr pSolid = OdDb3dSolid::createObject(); OdResult retVal = pSolid->createRevolvedSolid(arrCurvesToRevolve[0], arrRevolveData[i].m_ptRevolveOrigin, arrRevolveData[i].m_vrRevolveAxis, arrRevolveData[i].m_dRevolveAngle, 0, curOptions); if (retVal == eOk) { pOwner->appendOdDbEntity(pSolid); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pSolid); } else bRet = false; } } else { for( OdUInt32 n = 0; n < arrCurvesToRevolve.size(); n++) { OdDbRevolveOptions curOptions; OdDbRevolvedSurfacePtr pRevolvedSurface = OdDbRevolvedSurface::createObject(); OdResult retVal = pRevolvedSurface->createRevolvedSurface( arrCurvesToRevolve[n], arrRevolveData[i].m_ptRevolveOrigin, arrRevolveData[i].m_vrRevolveAxis, arrRevolveData[i].m_dRevolveAngle, 0, curOptions ); if( retVal == eOk ) { pOwner->appendOdDbEntity(pRevolvedSurface); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pRevolvedSurface); } else { bRet = false; break; } } } } } } catch(...) { bRet = false; } return bRet; } //--------------------------------------------------------------------------------------------------- void OdDgnSolidImportPE::subImportElement(OdDgElement* pElm, OdDbBlockTableRecord* pOwner) { bool bImportThroughDraw = true; if( OdDgnImportContext::getObject3dImportMode() == 1 ) bImportThroughDraw = !convertSolidTo3dSurface(pElm, pOwner, true); if( bImportThroughDraw ) OdDgnImportPE::subImportElement(pElm, pOwner); } //--------------------------------------------------------------------------------------------------- void OdDgnSurfaceImportPE::subImportElement(OdDgElement* pElm, OdDbBlockTableRecord* pOwner) { bool bImportThroughDraw = true; if( OdDgnImportContext::getObject3dImportMode() == 1 ) bImportThroughDraw = !convertSolidTo3dSurface(pElm, pOwner, false); if( bImportThroughDraw ) OdDgnImportPE::subImportElement(pElm, pOwner); } //--------------------------------------------------------------------------------------------------- bool OdDgnSurfaceImportPE::allowImportElement(OdDgElement* e) { bool bRet = true; OdDgSurface* pSurface = (OdDgSurface*)e; if( !OdDgnImportContext::isImportInvisible() ) { bRet = !pSurface->getInvisibleFlag(); if( bRet ) { OdUInt32 uLevelEntryId = pSurface->getLevelEntryId(); try { OdDg3dObjectHelper helper( pSurface ); OdDg3dObjectHelper::EntireObject structure; helper.extractInformation( structure ); OdDgGraphicsElementPtr pGraph; for(OdUInt32 k = 0; k < structure.size(); k++ ) { for( OdUInt32 j = 0; j < structure[k].m_boundary.size(); j++ ) { if( !structure[k].m_boundary[j].isNull() ) { pGraph = structure[k].m_boundary[j]; break; } } if( !pGraph.isNull() ) { break; } } if( !pGraph.isNull() ) { uLevelEntryId = pGraph->getLevelEntryId(); } } catch(...) { } OdDgDatabase* pDb = e->database(); if( pDb ) { OdDgLevelTablePtr pLevelTable = pDb->getLevelTable(OdDg::kForRead); if( !pLevelTable.isNull() ) { OdDgElementId idLevel = pLevelTable->getAt( uLevelEntryId ); if( !idLevel.isNull() ) { OdDgLevelTableRecordPtr pLevel = idLevel.openObject(OdDg::kForRead); if( !pLevel.isNull() ) { bRet = pLevel->getIsDisplayedFlag() && !pLevel->getIsFrozenFlag(); } } } } if( bRet && OdDgnImportContext::isLevelMask() ) { bRet = OdDgnImportContext::checkLevelMask( uLevelEntryId ); } } } return bRet; } //--------------------------------------------------------------------------------------------------- bool OdDgnBSplineSurfaceImportPE::convertBSplineSurfaceTo3dSurface(OdDgElement* pElm, OdDbBlockTableRecord* pOwner) { bool bRet = true; try { OdDgBSplineSurface* pSurface = (OdDgBSplineSurface*)(pElm); OdDgBSplineSurfaceBrepBuilderInitialDataPEPtr pSurfaceBrep = OdDgBrepBuilderInitialDataPEPtr(OdRxObjectPtr(pElm)); if( pSurfaceBrep.isNull() ) return false; if( odrxServiceDictionary()->getAt(OD_T("OdModelerGeometryCreator")).isNull() ) odrxDynamicLinker()->loadModule(OdModelerGeometryModuleName); OdRxClassPtr pServiceDWG(odrxServiceDictionary()->getAt(OD_T("OdModelerGeometryCreator"))); //dwg mode geom if( pServiceDWG.isNull() ) { ODA_ASSERT_ONCE(!"OdModelerGeometryCreator has not been created."); return false; } OdBrepBuilder brepBuilder; // AcisBrepBuilder OdModelerGeometryCreatorPtr pCreatorDWG = (OdModelerGeometryCreator*)pServiceDWG->create().get(); //!!!! dwg if( pCreatorDWG.isNull() ) { ODA_ASSERT_ONCE(!"OdModelerGeometryCreator has not been created."); return false; } if( pCreatorDWG->initBrepBuilder(brepBuilder, kOpenShell) != eOk ) { ODA_ASSERT_ONCE(!"Brep builder has not been initialized."); return false; } BrepBuilderInitialData brepData; double dScale = 1.0; if( !pSurfaceBrep->getBrepBuilderInitialData( pSurface, brepData, dScale ) ) { ODA_ASSERT_ONCE(!"Can't get b-spline surface brep builder initial data."); return false; } OdBrepBuilderFiller BBFiller; if(BBFiller.initFrom(brepBuilder, brepData) != eOk) { ODA_ASSERT_ONCE(!"Error on innitialization of edges, coedges and surfaces."); return false; } OdModelerGeometryPtr pGeometry = brepBuilder.finish(); if( pGeometry.isNull() ) { ODA_ASSERT_ONCE(!"Modeler geometry is null."); return false; } OdDbSurfacePtr pDbSurface = OdDbSurface::createObject(); pDbSurface->setBody(pGeometry); pOwner->appendOdDbEntity(pDbSurface); OdUInt32 nRulesU, nRulesV; pSurface->getNumberOfSpansInU(nRulesU); pSurface->getNumberOfSpansInV(nRulesV); pDbSurface->setUIsolineDensity( static_cast(nRulesU) ); pDbSurface->setVIsolineDensity( static_cast(nRulesV) ); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pDbSurface); pDbSurface->transformBy( OdGeMatrix3d::scaling(dScale) ); } catch(...) { bRet = false; } return bRet; } //--------------------------------------------------------------------------------------------------- void OdDgnBSplineSurfaceImportPE::subImportElement(OdDgElement* pElm, OdDbBlockTableRecord* pOwner) { bool bImportThroughDraw = true; if( OdDgnImportContext::getObject3dImportMode() == 1 ) bImportThroughDraw = !convertBSplineSurfaceTo3dSurface(pElm, pOwner); if( bImportThroughDraw ) OdDgnImportPE::subImportElement(pElm, pOwner); } //--------------------------------------------------------------------------------------------------- bool OdDgnConeImportPE::convertConeTo3dSolid(OdDgElement* pElm, OdDbBlockTableRecord* pOwner) { bool bRet = true; try { OdDgCone* pCone = (OdDgCone*)(pElm); OdDgConeBrepBuilderInitialDataPEPtr pSurfaceBrep = OdDgBrepBuilderInitialDataPEPtr(OdRxObjectPtr(pElm)); if( pSurfaceBrep.isNull() ) return false; if( odrxServiceDictionary()->getAt(OD_T("OdModelerGeometryCreator")).isNull() ) odrxDynamicLinker()->loadModule(OdModelerGeometryModuleName); OdRxClassPtr pServiceDWG(odrxServiceDictionary()->getAt(OD_T("OdModelerGeometryCreator"))); //dwg mode geom if( pServiceDWG.isNull() ) { ODA_ASSERT_ONCE(!"OdModelerGeometryCreator has not been created."); return false; } OdBrepBuilder brepBuilder; // AcisBrepBuilder OdModelerGeometryCreatorPtr pCreatorDWG = (OdModelerGeometryCreator*)pServiceDWG->create().get(); //!!!! dwg if( pCreatorDWG.isNull() ) { ODA_ASSERT_ONCE(!"OdModelerGeometryCreator has not been created."); return false; } if (!pCone) { return false; } bool isSurface = pCone->getHoleFlag(); if( pCreatorDWG->initBrepBuilder(brepBuilder, isSurface ? kOpenShell : kSolid) != eOk ) { ODA_ASSERT_ONCE(!"Brep builder has not been initialized."); return false; } BrepBuilderInitialData brepData; double dScale = 1.0; if( !pSurfaceBrep->getBrepBuilderInitialData( pCone, brepData, dScale ) ) { ODA_ASSERT_ONCE(!"Can't get cone brep builder initial data."); return false; } OdBrepBuilderFiller BBFiller; if(BBFiller.initFrom(brepBuilder, brepData) != eOk) { ODA_ASSERT_ONCE(!"Error on innitialization of edges, coedges and surfaces."); return false; } OdModelerGeometryPtr pGeometry = brepBuilder.finish(); if( pGeometry.isNull() ) { ODA_ASSERT_ONCE(!"Modeler geometry is null."); return false; } if (isSurface) { OdDbSurfacePtr pBody = OdDbSurface::createObject(); pBody->setBody(pGeometry); pOwner->appendOdDbEntity(pBody); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pBody); pBody->transformBy( OdGeMatrix3d::scaling(dScale) ); } else { OdDb3dSolidPtr pSolid = OdDb3dSolid::createObject(); pSolid->setBody(pGeometry); pOwner->appendOdDbEntity(pSolid); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElm); copyEntityProperties(pGrElm, pSolid); pSolid->transformBy( OdGeMatrix3d::scaling(dScale) ); } } catch(...) { bRet = false; } return bRet; } //--------------------------------------------------------------------------------------------------- void OdDgnConeImportPE::subImportElement(OdDgElement* pElm, OdDbBlockTableRecord* pOwner) { bool bImportThroughDraw = true; if( OdDgnImportContext::getObject3dImportMode() == 1 ) bImportThroughDraw = !convertConeTo3dSolid(pElm, pOwner); if( bImportThroughDraw ) OdDgnImportPE::subImportElement(pElm, pOwner); } //--------------------------------------------------------------------------------------------------- OdDbRegionPtr createDwgRegion( OdDgElement* pElement, OdDbBlockTableRecord* pOwner ) { OdDbRegionPtr pRet; bool bRet = true; try { if( odrxServiceDictionary()->getAt(OD_T("OdModelerGeometryCreator")).isNull() ) odrxDynamicLinker()->loadModule(OdModelerGeometryModuleName); OdBrepBuilder brepBuilder; // AcisBrepBuilder OdRxClassPtr pCreatorService = ::odrxGetModelerGeometryCreatorService(); if( pCreatorService.isNull() ) { ODA_ASSERT_ONCE(!"ModelerGeometryCreatorService has not been created."); return pRet; } OdModelerGeometryCreatorPtr pCreatorDWG = pCreatorService->create(); if( pCreatorDWG.isNull() ) { ODA_ASSERT_ONCE(!"OdModelerGeometryCreator has not been created."); return pRet; } if( pCreatorDWG->initBrepBuilder(brepBuilder, kOpenShell) != eOk ) { ODA_ASSERT_ONCE(!"Brep builder has not been initialized."); return pRet; } BrepBuilderInitialData brepData; if( OdDg3dSolidBrepBuilderInitialDataPE::getRegionData( pElement, brepData ) && brepData.edges.size() < MAX_REGION_EDGES) { OdBrepBuilderFiller BBFiller; if(BBFiller.initFrom(brepBuilder, brepData) == eOk) { OdModelerGeometryPtr pGeometry = brepBuilder.finish(); if( !pGeometry.isNull() ) { pRet = OdDbRegion::createObject(); pRet->setBody(pGeometry); pRet->setDatabaseDefaults( pOwner->database() ); pOwner->appendOdDbEntity(pRet); OdDgGraphicsElement* pGrElm = (OdDgGraphicsElement*)(pElement); copyEntityProperties(pGrElm, pRet); } } } } catch(...) { bRet = false; } return pRet; } }