指南
- 开始
- 指南
- 基础绘图
- 交互绘图
- 图纸编辑
- 数据库
- 最佳实践
MxCAD API 文档
- 类
- 2d.Color
- 2d.McAppType
- 2d.McCmColor
- 2d.McDbAlignedDimension
- 2d.McDbArc
- 2d.McDbAttribute
- 2d.McDbAttributeDefinition
- 2d.McDbBlockReference
- 2d.McDbBlockTable
- 2d.McDbBlockTableRecord
- 2d.McDbCircle
- 2d.McDbCurve
- 2d.McDbDatabase
- 2d.McDbDimension
- 2d.McDbEllipse
- 2d.McDbEntity
- 2d.McDbHatch
- 2d.McDbLayerTable
- 2d.McDbLayerTableRecord
- 2d.McDbLine
- 2d.McDbLinetypeTable
- 2d.McDbLinetypeTableRecord
- 2d.McDbMText
- 2d.McDbObject
- 2d.McDbObjectArray
- 2d.McDbPoint
- 2d.McDbPolyline
- 2d.McDbProxyEntity
- 2d.McDbRasterImage
- 2d.McDbRasterImageDef
- 2d.McDbRotatedDimension
- 2d.McDbText
- 2d.McDbTextStyleTable
- 2d.McDbTextStyleTableRecord
- 2d.McGeLongArray
- 2d.McGeMatrix3d
- 2d.McGePoint3d
- 2d.McGePoint3dArray
- 2d.McGeStringArray
- 2d.McGeVector3d
- 2d.McObject
- 2d.McObjectId
- 2d.McRxObject
- 2d.MdGeDoubleArray
- 2d.MxCADResbuf
- 2d.MxCADSelectionSet
- 2d.MxCADUiPrAngle
- 2d.MxCADUiPrBase
- 2d.MxCADUiPrDist
- 2d.MxCADUiPrEntity
- 2d.MxCADUiPrInt
- 2d.MxCADUiPrKeyWord
- 2d.MxCADUiPrPoint
- 2d.MxCADUiPrString
- 2d.MxCADUtilityClass
- 2d.MxCppType
- 2d.MxPropertiesWindowCustom
- 2d.MxPropertiesWindowCustomValue
- 2d.ObjectInheritance
- 3d.MdGeAngleDim
- 3d.MdGeArray1OfInteger
- 3d.MdGeArray1OfPnt
- 3d.MdGeArray1OfReal
- 3d.MdGeArray2OfPnt
- 3d.MdGeArray2OfReal
- 3d.MdGeArrowAspect
- 3d.MdGeAxis
- 3d.MdGeBezierCurve
- 3d.MdGeBezierSurface
- 3d.MdGeBox
- 3d.MdGeBRep
- 3d.MdGeBSplineCurve
- 3d.MdGeBSplineSurface
- 3d.MdGeChamfer
- 3d.MdGeCircle
- 3d.MdGeColor
- 3d.MdGeCompound
- 3d.MdGeCompSolid
- 3d.MdGeCone
- 3d.MdGeCSYS
- 3d.MdGeCSYSR
- 3d.MdGeCylinder
- 3d.MdGeDiameterDim
- 3d.MdGeDimAspect
- 3d.MdGeDir
- 3d.MdGeEdge
- 3d.MdGeEllipse
- 3d.MdGeExplorer
- 3d.MdGeFace
- 3d.MdGeFillet
- 3d.MdGeHGeomPlane
- 3d.MdGeHGeomSurface
- 3d.MdGeHypr
- 3d.MdGeInterpolateBSpl
- 3d.MdGeLengthDim
- 3d.MdGeLight
- 3d.MdGeLine
- 3d.MdGeLineAspect
- 3d.MdGeListIteratorOfListOfShape
- 3d.MdGeListOfShape
- 3d.MdGeLoft
- 3d.MdGeMakeArcOfCircle
- 3d.MdGeMakeFace
- 3d.MdGeMakeThickSolid
- 3d.MdGeMakeWires
- 3d.MdGeMat
- 3d.MdGeMaterialAspect
- 3d.MdGeObject
- 3d.MdGeParab
- 3d.MdGePipe
- 3d.MdGePlane
- 3d.MdGePoint
- 3d.MdGePointsToBSpl
- 3d.MdGePointsToBSplSurface
- 3d.MdGePrism
- 3d.MdGeRadiusDim
- 3d.MdGeRect
- 3d.MdGeRevol
- 3d.MdGeSequenceIteratorOfSequenceOfShape
- 3d.MdGeSequenceOfShape
- 3d.MdGeShape
- 3d.MdGeShell
- 3d.MdGeSolid
- 3d.MdGeSphere
- 3d.MdGeText
- 3d.MdGeTextAspect
- 3d.MdGeTextLabel
- 3d.MdGeTopo
- 3d.MdGeTorus
- 3d.MdGeTransform
- 3d.MdGeTrsf
- 3d.MdGeVec
- 3d.MdGeVertex
- 3d.MdGeWedge
- 3d.MdGeWire
- 3d.MdGeXYZ
- 3d.MxDraw3d
- Color
- McAppType
- McCmColor
- McDbAlignedDimension
- McDbArc
- McDbAttribute
- McDbAttributeDefinition
- McDbBlockReference
- McDbBlockTable
- McDbBlockTableRecord
- McDbCircle
- McDbCurve
- McDbDatabase
- McDbDimension
- McDbEllipse
- McDbEntity
- McDbHatch
- McDbLayerTable
- McDbLayerTableRecord
- McDbLine
- McDbLinetypeTable
- McDbLinetypeTableRecord
- McDbMText
- McDbObject
- McDbObjectArray
- McDbPoint
- McDbPolyline
- McDbProxyEntity
- McDbRasterImage
- McDbRasterImageDef
- McDbRotatedDimension
- McDbText
- McDbTextStyleTable
- McDbTextStyleTableRecord
- McGeLongArray
- McGeMatrix3d
- McGePoint3d
- McGePoint3dArray
- McGeStringArray
- McGeVector3d
- McObject
- McObjectId
- McRxObject
- MdGeAngleDim
- MdGeArray1OfInteger
- MdGeArray1OfPnt
- MdGeArray1OfReal
- MdGeArray2OfPnt
- MdGeArray2OfReal
- MdGeArrowAspect
- MdGeAxis
- MdGeBezierCurve
- MdGeBezierSurface
- MdGeBox
- MdGeBRep
- MdGeBSplineCurve
- MdGeBSplineSurface
- MdGeChamfer
- MdGeCircle
- MdGeColor
- MdGeCompound
- MdGeCompSolid
- MdGeCone
- MdGeCSYS
- MdGeCSYSR
- MdGeCylinder
- MdGeDiameterDim
- MdGeDimAspect
- MdGeDir
- MdGeDoubleArray
- MdGeEdge
- MdGeEllipse
- MdGeExplorer
- MdGeFace
- MdGeFillet
- MdGeHGeomPlane
- MdGeHGeomSurface
- MdGeHypr
- MdGeInterpolateBSpl
- MdGeLengthDim
- MdGeLight
- MdGeLine
- MdGeLineAspect
- MdGeListIteratorOfListOfShape
- MdGeListOfShape
- MdGeLoft
- MdGeMakeArcOfCircle
- MdGeMakeFace
- MdGeMakeThickSolid
- MdGeMakeWires
- MdGeMat
- MdGeMaterialAspect
- MdGeObject
- MdGeParab
- MdGePipe
- MdGePlane
- MdGePoint
- MdGePointsToBSpl
- MdGePointsToBSplSurface
- MdGePrism
- MdGeRadiusDim
- MdGeRect
- MdGeRevol
- MdGeSequenceIteratorOfSequenceOfShape
- MdGeSequenceOfShape
- MdGeShape
- MdGeShell
- MdGeSolid
- MdGeSphere
- MdGeText
- MdGeTextAspect
- MdGeTextLabel
- MdGeTopo
- MdGeTorus
- MdGeTransform
- MdGeTrsf
- MdGeVec
- MdGeVertex
- MdGeWedge
- MdGeWire
- MdGeXYZ
- MxCADResbuf
- MxCADSelectionSet
- MxCADUiPrAngle
- MxCADUiPrBase
- MxCADUiPrDist
- MxCADUiPrEntity
- MxCADUiPrInt
- MxCADUiPrKeyWord
- MxCADUiPrPoint
- MxCADUiPrString
- MxCADUtilityClass
- MxCppType
- MxDraw3d
- MxPropertiesWindowCustom
- MxPropertiesWindowCustomValue
- ObjectInheritance
- 2d.ColorIndexType
- 2d.ColorMethod
- 2d.FetchAttributes
- 2d.McDb.AttachmentPoint
- 2d.McDb.ClipBoundaryType
- 2d.McDb.HatchEdgeType
- 2d.McDb.HatchLoopType
- 2d.McDb.HatchPatternType
- 2d.McDb.HatchStyle
- 2d.McDb.Intersect
- 2d.McDb.LineWeight
- 2d.McDb.TextHorzMode
- 2d.McDb.TextVertMode
- 2d.McObjectIdType
- 2d.MxCADResbufDataType
- 2d.MxCADSelectionSetStatus
- 2d.MxPropertiesWindowCustomValueType
- 3d.MdGe.MxCameraProjection
- 3d.MdGe.MxCF3dFilletShapeEnum
- 3d.MdGe.MxCFDSChamfMode
- 3d.MdGe.MxDimensionArrowOrientation
- 3d.MdGe.MxDimensionTextHorizontalPosition
- 3d.MdGe.MxDimensionTextVerticalPosition
- 3d.MdGe.MxDisplayMode
- 3d.MdGe.MxFontAspect
- 3d.MdGe.MxGAJoinTypeEnum
- 3d.MdGe.MxGAShapeEnum
- 3d.MdGe.MxGFTrihedron
- 3d.MdGe.MxHorizontalTextAlignment
- 3d.MdGe.MxKindOfDimension
- 3d.MdGe.MxNameOfColor
- 3d.MdGe.MxNameOfMaterial
- 3d.MdGe.MxOffsetModeEnum
- 3d.MdGe.MxShapeEnum
- 3d.MdGe.MxTextPath
- 3d.MdGe.MxTypeOfAngle
- 3d.MdGe.MxTypeOfAngleArrowVisibility
- 3d.MdGe.MxTypeOfColor
- 3d.MdGe.MxTypeOfDisplayText
- 3d.MdGe.MxTypeOfLightSource
- 3d.MdGe.MxTypeOfLine
- 3d.MdGe.MxTypeOfMaterial
- 3d.MdGe.MxTypeOfReflection
- 3d.MdGe.MxV3dTypeOfOrientation
- 3d.MdGe.MxVerticalTextAlignment
- 枚举
- ColorIndexType
- ColorMethod
- FetchAttributes
- McDb.AttachmentPoint
- McDb.ClipBoundaryType
- McDb.HatchEdgeType
- McDb.HatchLoopType
- McDb.HatchPatternType
- McDb.HatchStyle
- McDb.Intersect
- McDb.LineWeight
- McDb.TextHorzMode
- McDb.TextVertMode
- McObjectIdType
- MdGe.MxCameraProjection
- MdGe.MxCF3dFilletShapeEnum
- MdGe.MxCFDSChamfMode
- MdGe.MxDimensionArrowOrientation
- MdGe.MxDimensionTextHorizontalPosition
- MdGe.MxDimensionTextVerticalPosition
- MdGe.MxDisplayMode
- MdGe.MxFontAspect
- MdGe.MxGAJoinTypeEnum
- MdGe.MxGAShapeEnum
- MdGe.MxGFTrihedron
- MdGe.MxHorizontalTextAlignment
- MdGe.MxKindOfDimension
- MdGe.MxNameOfColor
- MdGe.MxNameOfMaterial
- MdGe.MxOffsetModeEnum
- MdGe.MxShapeEnum
- MdGe.MxTextPath
- MdGe.MxTypeOfAngle
- MdGe.MxTypeOfAngleArrowVisibility
- MdGe.MxTypeOfColor
- MdGe.MxTypeOfDisplayText
- MdGe.MxTypeOfLightSource
- MdGe.MxTypeOfLine
- MdGe.MxTypeOfMaterial
- MdGe.MxTypeOfReflection
- MdGe.MxV3dTypeOfOrientation
- MdGe.MxVerticalTextAlignment
- MxCADResbufDataType
- MxCADSelectionSetStatus
- MxPropertiesWindowCustomValueType
- 2d.MxCadConfig
- 2d.MxCADUI
- 3d.MxDraw3dConfig
- 3d.WasmConfig
- 接口
- 模块
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
9. 自定义实体
自定义实体
在 mxcad 中,我们支持用户自定义实体,可以根据具体的需求来创建和管理自定义实体。我们可以通过从自定义实体类 McDbCustomEntity() 中继承实体的名称、属性、方法等,也可结合自身需求对自定义实体类中的属性或方法进行重写。下面以自定义一条直线为例:
通过重写 dwgInFields() 函数读取自定义实体数据,dwgOutFields() 函数写入自定义实体数据(在从文件读取实体或把实体写入文件时,复制实体等地方都会调用这两个函数)。
getGripPoints() 方法是在点击这个渲染好的图形时提供一个操作点位,即返回自定义的编辑夹点,并在点击操作点移动的回调函数moveGripPointsAt() 中处理夹点编辑结果。
动态绘制 worldDraw() 方法能够绘制自定义实体的显示效果。
每次触发动态绘制worldDraw,就会将原本的实例对象删掉(同时也会删除渲染的three.js物体对象),通过create方法重新创建实例。
点击 McDbCustomEntity 查看详细属性和方法说明。
import { IMcDbDwgFiler, McDbCustomEntity, McDbLine, McGePoint3d, McGePoint3dArray, MxCADUiPrPoint, MxCADWorldDraw, MxCpp } from "mxcad";
import { MxFun } from "mxdraw";
class McDbTestLineCustomEntity extends McDbCustomEntity {
private pt1: McGePoint3d = new McGePoint3d();
private pt2: McGePoint3d = new McGePoint3d();
constructor(imp?: any) {
super(imp);
}
public create(imp: any) {
return new McDbTestLineCustomEntity(imp)
}
public getTypeName(): string {
return "McDbTestLineCustomEntity";
}
public dwgInFields(filter: IMcDbDwgFiler): boolean {
this.pt1 = filter.readPoint("pt1").pt;
this.pt2 = filter.readPoint("pt2").pt;
return true;
}
public dwgOutFields(filter: IMcDbDwgFiler): boolean {
filter.writePoint("pt1", this.pt1);
filter.writePoint("pt2", this.pt2);
return true;
}
public moveGripPointsAt(iIndex: number, dXOffset: number, dYOffset: number, dZOffset: number) {
this.assertWrite();
if (iIndex == 0) {
this.pt1.x += dXOffset;
this.pt1.y += dYOffset;
this.pt1.z += dZOffset;
}
else if (iIndex == 1) {
this.pt2.x += dXOffset;
this.pt2.y += dYOffset;
this.pt2.z += dZOffset;
}
};
public getGripPoints(): McGePoint3dArray {
let ret = new McGePoint3dArray()
ret.append(this.pt1);
ret.append(this.pt2);
return ret;
};
public worldDraw(draw: MxCADWorldDraw): void {
let tmpline = new McDbLine(this.pt1, this.pt2);
draw.drawEntity(tmpline);
}
public setPoint1(pt1: McGePoint3d) {
this.assertWrite();
this.pt1 = pt1.clone();
}
public setPoint2(pt2: McGePoint3d) {
this.assertWrite();
this.pt2 = pt2.clone();
}
public getPoint1() {
return this.pt1;
}
public getPoint2() {
return this.pt2;
}
}
async function MxTest_DrawCustomEntity() {
let mxcad = MxCpp.getCurrentMxCAD();
const getPoint = new MxCADUiPrPoint();
getPoint.setMessage("\n指定一点:");
let pt1 = (await getPoint.go());
if (!pt1) return;
getPoint.setBasePt(pt1);
getPoint.setUseBasePt(true);
getPoint.setMessage("\n指定二点:");
let pt2 = (await getPoint.go());
if (!pt2) return;
let myline = new McDbTestLineCustomEntity();
new McDbTestLineCustomEntity().rxInit();
myline.setPoint1(pt1);
myline.setPoint2(pt2);
mxcad.drawEntity(myline);
}
MxTest_DrawCustomEntity()
:::demo
import { IMcDbDwgFiler, McDbCustomEntity, McDbLine, McGePoint3d, McGePoint3dArray, MxCADUiPrPoint, MxCADWorldDraw, McObject } from "mxcad";
import { MxFun } from "mxdraw";
export default () => {
const mxcad = new McObject()
mxcad.create({
canvas: "#myCanvas",
locateFile: (fileName: string)=> {
// CDN 加载必须使用wasm/2d-st中的资源、因为github的限制无法使用wasm/2d 资源
// 需要使用wasm/2d需要遵循浏览器同源策略或使用其他手段规避浏览器同源策略
return "https://unpkg.com/mxcad/dist/wasm/2d-st/" + fileName
},
// 加载字体的目录位置
fontspath: self.location.origin + "/mxcad_docs/fonts",
// 加载转换后的图纸文件
fileUrl: self.location.origin + "/mxcad_docs/test2.mxweb",
})
class McDbTestLineCustomEntity extends McDbCustomEntity {
private pt1: McGePoint3d = new McGePoint3d();
private pt2: McGePoint3d = new McGePoint3d();
constructor(imp?: any) {
super(imp);
}
public create(imp: any) {
return new McDbTestLineCustomEntity(imp)
}
public getTypeName(): string {
return "McDbTestLineCustomEntity";
}
public dwgInFields(filter: IMcDbDwgFiler): boolean {
this.pt1 = filter.readPoint("pt1").pt;
this.pt2 = filter.readPoint("pt2").pt;
return true;
}
public dwgOutFields(filter: IMcDbDwgFiler): boolean {
filter.writePoint("pt1", this.pt1);
filter.writePoint("pt2", this.pt2);
return true;
}
public moveGripPointsAt(iIndex: number, dXOffset: number, dYOffset: number, dZOffset: number) {
this.assertWrite();
if (iIndex == 0) {
this.pt1.x += dXOffset;
this.pt1.y += dYOffset;
this.pt1.z += dZOffset;
}
else if (iIndex == 1) {
this.pt2.x += dXOffset;
this.pt2.y += dYOffset;
this.pt2.z += dZOffset;
}
};
public getGripPoints(): McGePoint3dArray {
let ret = new McGePoint3dArray()
ret.append(this.pt1);
ret.append(this.pt2);
return ret;
};
public worldDraw(draw: MxCADWorldDraw): void {
let tmpline = new McDbLine(this.pt1, this.pt2);
draw.drawEntity(tmpline);
}
public setPoint1(pt1: McGePoint3d) {
this.assertWrite();
this.pt1 = pt1.clone();
}
public setPoint2(pt2: McGePoint3d) {
this.assertWrite();
this.pt2 = pt2.clone();
}
public getPoint1() {
return this.pt1;
}
public getPoint2() {
return this.pt2;
}
}
async function MxTest_DrawCustomEntity() {
const getPoint = new MxCADUiPrPoint();
getPoint.setMessage("\n指定一点:");
let pt1 = (await getPoint.go());
if (!pt1) return;
getPoint.setBasePt(pt1);
getPoint.setUseBasePt(true);
getPoint.setMessage("\n指定二点:");
let pt2 = (await getPoint.go());
if (!pt2) return;
let myline = new McDbTestLineCustomEntity();
new McDbTestLineCustomEntity().rxInit();
myline.setPoint1(pt1);
myline.setPoint2(pt2);
mxcad.drawEntity(myline);
}
return (<div style="height: 500px; overflow: hidden;">
<button style="height:30px;border:1px solid #ccc;padding:0px 5px;margin-bottom:10px"
id="myBtn" onClick={()=>MxTest_DrawCustomEntity()}>绘自定义直线</button>
<div style="height: 400px;"><canvas id="myCanvas" style="height: 300px"></canvas></div>
</div>)
}
:::
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论