@mlightcad/data-model
Version:
The data-model package provides the core classes for interacting with AutoCAD's database and entities. This package mimics AutoCAD ObjectARX's AcDb (Database) classes and implements the drawing database structure that AutoCAD developers are familiar with.
110 lines • 4.28 kB
JavaScript
import { AcDbBlockTableRecord } from '../database/AcDbBlockTableRecord';
import { AcDbLayout, AcDbRasterImageDef } from '../object';
/**
* Converts DXF objects to AcDbObject instances.
*
* This class provides functionality to convert various DXF object types
* (such as layouts and image definitions) into their corresponding
* AcDbObject instances.
*
* @example
* ```typescript
* const converter = new AcDbObjectConverter();
* const layout = converter.convertLayout(dxfLayout);
* const imageDef = converter.convertImageDef(dxfImageDef);
* ```
*/
var AcDbObjectConverter = /** @class */ (function () {
function AcDbObjectConverter() {
}
/**
* Converts a DXF layout object to an AcDbLayout.
*
* @param layout - The DXF layout object to convert
* @returns The converted AcDbLayout instance
*
* @example
* ```typescript
* const dxfLayout = { layoutName: 'Model', tabOrder: 1, ... };
* const acDbLayout = converter.convertLayout(dxfLayout);
* ```
*/
AcDbObjectConverter.prototype.convertLayout = function (layout, model) {
var _a, _b;
var dbObject = new AcDbLayout();
dbObject.layoutName = layout.layoutName;
dbObject.tabOrder = layout.tabOrder;
if (layout.layoutName === 'Model') {
// Upper case model space name
var modelSpaceName_1 = AcDbBlockTableRecord.MODEL_SPACE_NAME;
(_a = model.tables.BLOCK_RECORD) === null || _a === void 0 ? void 0 : _a.entries.some(function (btr) {
if (btr.name.toUpperCase() === modelSpaceName_1) {
dbObject.blockTableRecordId = btr.handle;
return true;
}
return false;
});
}
else {
// layout.paperSpaceTableId doesn't point to the block table record asscicated with
// this layout. So let's get the assocated block table record id from block table.
(_b = model.tables.BLOCK_RECORD) === null || _b === void 0 ? void 0 : _b.entries.some(function (btr) {
if (btr.layoutObjects === layout.handle) {
dbObject.blockTableRecordId = btr.handle;
return true;
}
return false;
});
// If blockTableRecordId value is still invalid, let's try to use
// layout.paperSpaceTableId finally
if (!dbObject.blockTableRecordId) {
dbObject.blockTableRecordId = layout.paperSpaceTableId;
}
}
dbObject.limits.min.copy(layout.minLimit);
dbObject.limits.max.copy(layout.maxLimit);
dbObject.extents.min.copy(layout.minExtent);
dbObject.extents.max.copy(layout.maxExtent);
this.processCommonAttrs(layout, dbObject);
return dbObject;
};
/**
* Converts a DXF image definition object to an AcDbRasterImageDef.
*
* @param image - The DXF image definition object to convert
* @returns The converted AcDbRasterImageDef instance
*
* @example
* ```typescript
* const dxfImageDef = { fileName: 'image.jpg', ... };
* const acDbImageDef = converter.convertImageDef(dxfImageDef);
* ```
*/
AcDbObjectConverter.prototype.convertImageDef = function (image) {
var dbObject = new AcDbRasterImageDef();
dbObject.sourceFileName = image.fileName;
this.processCommonAttrs(image, dbObject);
return dbObject;
};
/**
* Processes common attributes from a DXF object to an AcDbObject.
*
* This method copies common properties like object ID and owner ID
* from the DXF object to the corresponding AcDbObject.
*
* @param object - The source DXF object
* @param dbObject - The target AcDbObject to populate
*
* @example
* ```typescript
* converter.processCommonAttrs(dxfObject, acDbObject);
* ```
*/
AcDbObjectConverter.prototype.processCommonAttrs = function (object, dbObject) {
dbObject.objectId = object.handle;
dbObject.ownerId = object.ownerObjectId;
};
return AcDbObjectConverter;
}());
export { AcDbObjectConverter };
//# sourceMappingURL=AcDbObjectConverter.js.map