/////////////////////////////////////////////////////////////////////////////// // 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 "DgnImportArc.h" #include "DgnImportCommon.h" #include "DgnImportContext.h" #include #include #include #include #include namespace TD_DGN_IMPORT { //--------------------------------------------------------------------------------------------------- void OdDgnArc2dImportPE::subImportElement(OdDgElement* e, OdDbBlockTableRecord* owner) { OdDgArc2d* arc = (OdDgArc2d*)e; double a1 = arc->getPrimaryAxis(); double a2 = arc->getSecondaryAxis(); OdGePoint2d o = arc->getOrigin(); double startAng = arc->getStartAngle(); double sweep = arc->getSweepAngle(); OdDbEntityPtr dbEnt; if (OdEqual(a1, a2)) { if (OdEqual(fabs(sweep), Oda2PI)) { OdDbCirclePtr dbArc = OdDbCircle::createObject(); dbArc->setCenter(OdGePoint3d(o.x, o.y, 0.0)); dbArc->setRadius(a1); dbArc->setThickness(arc->getThickness()); dbArc->setNormal(OdGeVector3d::kZAxis); dbEnt = dbArc; } else { OdDbArcPtr dbArc = OdDbArc::createObject(); dbArc->setCenter(OdGePoint3d(o.x, o.y, 0.0)); dbArc->setRadius(a1); dbArc->setThickness(arc->getThickness()); double a = arc->getRotationAngle(); if (sweep < 0) { dbArc->setStartAngle(startAng + sweep + a); dbArc->setEndAngle(startAng + a); } else { dbArc->setStartAngle(startAng + a); dbArc->setEndAngle(startAng + sweep + a); } dbArc->setNormal(OdGeVector3d::kZAxis); dbEnt = dbArc; } } else { if (odmax(a1, a2) < 1e-6) // DB ellipse cannot accept axis shorter than 1e-6 return; if (OdZero(a1) || OdZero(a2)) { OdGeEllipArc2d ellipArc = arc->getEllipArc(); OdDbLinePtr dbLine = OdDbLine::createObject(); OdGePoint2d ptCenter2d = ellipArc.center(); OdGeVector2d vrMajor2d = ellipArc.majorAxis()*ellipArc.majorRadius(); OdGePoint3d ptCenter3d(ptCenter2d.x, ptCenter2d.y, 0.0); OdGeVector3d vrMajor3d(vrMajor2d.x, vrMajor2d.y, 0.0); dbLine->setStartPoint(ptCenter3d + vrMajor3d); dbLine->setEndPoint(ptCenter3d - vrMajor3d); dbEnt = dbLine; } else { OdGeEllipArc3d ellipArc; double majR = arc->getPrimaryAxis(); double minR = arc->getSecondaryAxis(); OdGePoint2d origin2d = arc->getOrigin(); OdGePoint3d origin3d(origin2d.x, origin2d.y, 0.); double strtang = arc->getStartAngle(); double swpang = arc->getSweepAngle(); double rotation = arc->getRotationAngle(); OdGeVector3d temp(1., 0., 0.); OdGeVector3d majAxis = temp.rotateBy(rotation, OdGeVector3d::kZAxis); temp.set(0., 1., 0.); OdGeVector3d minAxis = temp.rotateBy(rotation, OdGeVector3d::kZAxis); //make a positive shift for the angle if (swpang < 0.) { ellipArc.set(origin3d, majAxis, minAxis, majR, minR, strtang + swpang, strtang); OdGeVector3d majorAxis = ellipArc.majorAxis(); majorAxis.negate(); ellipArc.setAxes(majorAxis, ellipArc.minorAxis()); OdGeInterval interval; ellipArc.getInterval(interval); ellipArc.setAngles(OdaPI - interval.upperBound(), OdaPI - interval.lowerBound()); } else { ellipArc.set(origin3d, majAxis, minAxis, majR, minR, strtang, strtang + swpang); } OdDbEllipsePtr dbArc = OdDbEllipse::createObject(); dbArc->setFromOdGeCurve(ellipArc); dbEnt = dbArc; } } dbEnt->setDatabaseDefaults(owner->database()); owner->database()->addOdDbObject(dbEnt, owner->objectId()); copyEntityProperties(arc, dbEnt); owner->appendOdDbEntity(dbEnt); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_idPath.objectIds().push_back( dbEnt->objectId() ); dwgPath.m_bExists = true; OdDgnImportContext::addObjectPath( arc->elementId(), dwgPath ); } //--------------------------------------------------------------------------------------------------- void OdDgnArc3dImportPE::subImportElement(OdDgElement* e, OdDbBlockTableRecord* owner) { OdDgArc3d* arc = (OdDgArc3d*)e; double a1 = arc->getPrimaryAxis(); double a2 = arc->getSecondaryAxis(); bool bImportThroughDraw = false; if (!OdZero(arc->getThickness())) { bImportThroughDraw = true; if (OdEqual(a1, a2)) { if (arc->getThicknessDirection() != OdGeVector3d::kIdentity) { OdGeVector3d normal = OdGeVector3d::kZAxis; arc->getRotation().rotateOpposite(normal); if (arc->getThicknessDirection().isParallelTo(normal)) bImportThroughDraw = false; } else bImportThroughDraw = false; } } if (bImportThroughDraw) { OdDgnImportPE::subImportElement(e, owner); return; } OdDbEntityPtr dbEnt; if( (a1 < 0) || (a2 < 0) ) { OdGeEllipArc3d ellipArc = arc->getEllipArc(); if( ellipArc.isCircular() && ellipArc.isClosed()) { OdDbCirclePtr dbArc = OdDbCircle::createObject(); dbArc->setDatabaseDefaults(owner->database()); dbArc->setCenter(ellipArc.center()); dbArc->setRadius(ellipArc.majorRadius()); dbArc->setThickness(arc->getThickness()); dbArc->setNormal(arc->getNormal()); dbEnt = dbArc; if ((arc->getThicknessDirection() != OdGeVector3d::kIdentity) && !arc->getNormal().isCodirectionalTo(arc->getThicknessDirection())) dbArc->setThickness(-arc->getThickness()); else dbArc->setThickness(arc->getThickness()); } else { OdDbEllipsePtr dbArc = OdDbEllipse::createObject(); dbArc->setDatabaseDefaults(owner->database()); dbArc->setFromOdGeCurve(ellipArc); dbEnt = dbArc; } } else { OdGePoint3d o = arc->getOrigin(); double startAng = arc->getStartAngle(); double sweep = arc->getSweepAngle(); if (OdEqual(a1, a2)) { if (OdEqual(fabs(sweep), Oda2PI)) { OdDbCirclePtr dbArc = OdDbCircle::createObject(); dbArc->setDatabaseDefaults(owner->database()); dbArc->setCenter(o); dbArc->setRadius(a1); dbArc->setThickness(arc->getThickness()); dbArc->setNormal(arc->getNormal()); dbEnt = dbArc; if ((arc->getThicknessDirection() != OdGeVector3d::kIdentity) && !arc->getNormal().isCodirectionalTo(arc->getThicknessDirection())) dbArc->setThickness(-arc->getThickness()); else dbArc->setThickness(arc->getThickness()); } else { OdDbArcPtr dbArc = OdDbArc::createObject(); dbArc->setDatabaseDefaults(owner->database()); dbArc->setCenter(o); dbArc->setRadius(a1); dbArc->setThickness(arc->getThickness()); OdGeVector3d normal = arc->getNormal(); OdGePlane p(o, normal); OdGeVector3d refvector = normal.perpVector(); OdGeVector3d refvector1 = OdGeVector3d::kXAxis; arc->getRotation().rotateOpposite(refvector1); double a = refvector1.angleOnPlane(p) - refvector.angleOnPlane(p); if (sweep < 0) { dbArc->setStartAngle(startAng + sweep + a); dbArc->setEndAngle(startAng + a); } else { dbArc->setStartAngle(startAng + a); dbArc->setEndAngle(startAng + sweep + a); } dbArc->setNormal(normal); if ((arc->getThicknessDirection() != OdGeVector3d::kIdentity) && !normal.isCodirectionalTo(arc->getThicknessDirection())) dbArc->setThickness(-arc->getThickness()); else dbArc->setThickness(arc->getThickness()); dbEnt = dbArc; } } else { if (odmax(a1, a2) < 1e-6) // DB ellipse cannot accept axis shorter than 1e-6 return; if( OdZero(a1) || OdZero(a2) ) { OdGeEllipArc3d ellipArc = arc->getEllipArc(); OdDbLinePtr dbLine = OdDbLine::createObject(); dbLine->setDatabaseDefaults(owner->database()); dbLine->setStartPoint(ellipArc.center() + ellipArc.majorAxis()*ellipArc.majorRadius()); dbLine->setEndPoint(ellipArc.center() - ellipArc.majorAxis()*ellipArc.majorRadius()); dbEnt = dbLine; } else { OdDbEllipsePtr dbArc = OdDbEllipse::createObject(); dbArc->setDatabaseDefaults(owner->database()); dbArc->setFromOdGeCurve(arc->getEllipArc()); dbEnt = dbArc; } } } owner->database()->addOdDbObject(dbEnt, owner->objectId()); copyEntityProperties(arc, dbEnt); owner->appendOdDbEntity(dbEnt); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_idPath.objectIds().push_back( dbEnt->objectId() ); dwgPath.m_bExists = true; OdDgnImportContext::addObjectPath( arc->elementId(), dwgPath ); } //--------------------------------------------------------------------------------------------------- }