import{formatString}from"../../tools/formatting";import McGiWorldDrawType from"../McGiWorldDrawType";import MxDbEntity from"../MxDbEntity";import MxThreeJS from"../MxThreeJS";export default class MxDbText extends MxDbEntity{constructor(){super(...arguments),this.position=new THREE.Vector3,this.text="",this.height=1,this.angle=0}getTypeName(){return"MxDbText"}worldDraw(t){if(this.text.length>0&&(t.drawText(this.text,this.height,this.angle,this.position),t.getType()===McGiWorldDrawType.kSelectDraw)){let i=MxThreeJS.creatTextSprite(this.text,this.position,this.height,this.angle,16777215);if(i){const e=new THREE.Box3;e.expandByObject(i);const n=e.min,o=e.max,s={x:n.x,y:o.y},r={x:o.x,y:n.y};t.drawLine(n.x,n.y,s.x,s.y),t.drawLine(s.x,s.y,o.x,o.y),t.drawLine(o.x,o.y,r.x,r.y),t.drawLine(r.x,r.y,n.x,n.y)}}}getGripPoints(){return[this.position]}moveGripPointsAt(t,i){return 0===t&&this.position.add(i),!0}create(){return new MxDbText}dwgIn(t){return this.onDwgIn(t),this.position.copy(t.position),this.text=t.text.substr(0),this.height=t.height,this.angle=t.angle,!0}dwgOut(t){return this.onDwgOut(t),t.position=this.position,t.text=this.text,t.height=this.height,t.angle=this.angle,t}getGeomExtents(){var t=document.createElement("canvas").getContext("2d");if(null==t)return null;var i=formatString("normal {0}px Arial","256");t.font=i;let e=t.measureText(this.text).width/256,n=this.position.x-e*this.height*.5,o=this.position.y-.5*this.height,s=this.position.x+e*this.height*.5,r=this.position.y+.5*this.height;return new THREE.Box3(new THREE.Vector3(n,o,this.position.z),new THREE.Vector3(s,r,this.position.z))}};