AcGe 持久性示例
以下是具有具体子类的 的读取和写入示例。在本示例中,序列化文件管理器是 DWG 文件管理器。因此,它通过读取和写入 DWG 格式来提供持久性:AcGeExternalSurfaceAcGeFiler #include "gefiler.h" class AcDbDwgFiler; class AcGeDwgFiler : public AcGeFiler { public: // Construct the filer with DWG filer. // All read and write methods are implemented // by delegating to this filer. AcGeDwgFiler (AcDbDwgFiler* = NULL); // Read/write methods. // Acad::ErrorStatus readBoolean(Adesk::Boolean*); Acad::ErrorStatus writeBoolean(Adesk::Boolean); Acad::ErrorStatus readBool(bool*); Acad::ErrorStatus writeBool(bool); Acad::ErrorStatus readChar(char*); Acad::ErrorStatus writeChar(char); Acad::ErrorStatus readShort(short*); Acad::ErrorStatus writeShort(short); Acad::ErrorStatus readLong(long*); Acad::ErrorStatus writeLong(long); Acad::ErrorStatus readUChar(unsigned char*); Acad::ErrorStatus writeUChar(unsigned char); Acad::ErrorStatus readUShort(unsigned short*); Acad::ErrorStatus writeUShort(unsigned short); Acad::ErrorStatus readULong(unsigned long*); Acad::ErrorStatus writeULong(unsigned long); Acad::ErrorStatus readDouble(double*); Acad::ErrorStatus writeDouble(double); Acad::ErrorStatus readPoint2d(AcGePoint2d*); Acad::ErrorStatus writePoint2d(const AcGePoint2d&); Acad::ErrorStatus readPoint3d(AcGePoint3d*); Acad::ErrorStatus writePoint3d(const AcGePoint3d&); Acad::ErrorStatus readVector2d(AcGeVector2d*); Acad::ErrorStatus writeVector2d(const AcGeVector2d&); Acad::ErrorStatus readVector3d(AcGeVector3d*); Acad::ErrorStatus writeVector3d(const AcGeVector3d&); // Set/Get methods // AcGeDwgFiler& setDwgFiler (AcDbDwgFiler*); AcDbDwgFiler* dwgFiler (); protected: AcDbDwgFiler* mpFiler; }; // Inline methods. // inline AcGeDwgFiler::AcGeDwgFiler(AcDbDwgFiler* filer) : mpFiler(filer) {} inline AcGeDwgFiler& AcGeDwgFiler::setDwgFiler(AcDbDwgFiler* filer) { mpFiler = filer; return *this; } inline AcDbDwgFiler* AcGeDwgFiler::dwgFiler() { return mpFiler; } 下一个代码片段演示了几个函数的实现。其他函数以相同的方式实现: Acad::ErrorStatus AcGeDwgFiler::readBoolean(Adesk::Boolean* data) { return mpFiler ? mpFiler->readBoolean(data) : Acad::eNoDatabase; } Acad::ErrorStatus AcGeDwgFiler::writeBoolean(Adesk::Boolean data) { return mpFiler ? mpFiler->writeBoolean(data) : Acad::eNoDatabase; } 下一个示例演示一个使用 .类声明后面的代码说明了外表面类的读取和写入。特别要注意的是 AcGeExternalSurface AcGe::gLibVersion在写入或读取外表面类之前先写出,然后先读取: class AcGeExternalCurve2d; class AcGeExternalCurve3d; class AcGeExternalBoundedSurface; class AcGeExternalSurface; class AcGePersistentXEnt : public AcDbObject { public: ACRX_DECLARE_MEMBERS (AcGePersistentXEnt); AcGePersistentXEnt (); ~AcGePersistentXEnt (); Acad::ErrorStatus dwgOutFields (AcDbDwgFiler*) const; Acad::ErrorStatus dwgInFields (AcDbDwgFiler*); AcGeExternalSurface* mpXSrf; }; 此类的实现如下:
ACRX_DXF_DEFINE_MEMBERS( AcGePersistentXEnt, AcDbObject, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 0, GEPERSISTENT, "GeometryLib"); Acad::ErrorStatus AcGePersistentXEnt::dwgOutFields(AcDbDwgFiler* filer) const { assertReadEnabled(); Acad::ErrorStatus stat = AcDbObject::dwgOutFields(filer); if (stat != Acad::eOk) { ADS_ASSERT(0); return stat; } // Only interested in a file filer. // if (filer->filerType() != AcDb::kFileFiler) return stat; AcGeDwgFiler geDwgFiler(filer); stat = AcGeFileIO::outFields( &geDwgFiler, AcGe::gLibVersion); if ((stat = AcGeFileIO::outFields(&geDwgFiler, *mpXSrf)) != Acad::eOk) return stat; return stat; } Acad::ErrorStatus AcGePersistentXEnt::dwgInFields(AcDbDwgFiler* filer) { assertWriteEnabled(); Acad::ErrorStatus stat = AcDbObject::dwgInFields(filer); if (stat != Acad::eOk) { ADS_ASSERT(0); return stat; } // Only interested in a file filer. // if (filer->filerType() != AcDb::kFileFiler) return stat; AcGeDwgFiler geDwgFiler(filer); AcGeLibVersion gelibVersion; if ((stat = AcGeFileIO::inFields(&geDwgFiler, gelibVersion)) != Acad::eOk) return stat; acutPrintf("\n... Reading External Surface\n"); mpXSrf = new AcGeExternalSurface; ADS_ASSERT(mpXSrf); if ((stat = AcGeFileIO::inFields(&geDwgFiler, *mpXSrf, gelibVersion)) != Acad::eOk) return stat; return stat; } 父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2024-12-15 12:44
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.