index.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //import 'core-js'
  2. import {BasicCAD as CADTS, AttachCAD} from './core/index'
  3. import CAD from './core/base/cad'
  4. import {attachInsert} from './core/additional/insert'
  5. import {attachGauge} from './core/additional/label'
  6. import {attachSign} from './core/additional/sign'
  7. import {attachScreenshot} from './core/additional/screenshot'
  8. import {autoPreservation, attchTransform, attchStack} from './core/additional/dataHandle'
  9. import {attchDOMTranform} from './core/additional/transform'
  10. import {attachDisabled} from './core/additional/disabled'
  11. import {attachRote} from './core/additional/rote'
  12. import {attachStyle} from './core/additional/styleSet'
  13. import eleAttr from './eleAttr'
  14. import {other, Other} from './other'
  15. import Column from './core/architecture/column'
  16. import Door from './core/architecture/door/index'
  17. import Casement from './core/architecture/casement'
  18. import { CADElement } from './core/core/element'
  19. import Rote from './core/label/route'
  20. import screenAdapt from './screenAdapt'
  21. import toCanvas from './toCanvas'
  22. {
  23. const listen = CADElement.prototype.listen
  24. CADElement.prototype.listen = function (...args) {
  25. if (this.render.edit || this instanceof Rote) {
  26. listen.call(this, ...args)
  27. }
  28. }
  29. const addEvent = Column.prototype.addEvent
  30. Column.prototype.addEvent = function (...args) {
  31. this.render.edit && addEvent.call(this, ...args)
  32. }
  33. }
  34. export type EXPCAD = CADTS & Other & {toCanvas: (cb: Function) => void}
  35. export interface Args {
  36. data: Data,
  37. layer: HTMLElement,
  38. edit: boolean,
  39. padding?: number
  40. }
  41. import Point from './core/core/fixedpoint'
  42. import { Data } from './core/base/processing'
  43. export function structureCAD({data, layer, edit = true, padding = 20}: Args): EXPCAD {
  44. let cad = new CAD({ dom: layer, padding }) as AttachCAD
  45. cad.processing.render.edit = edit
  46. if (edit) {
  47. attachInsert(cad)
  48. attchTransform(cad)
  49. attchStack(cad)
  50. autoPreservation(cad)
  51. attchDOMTranform(cad)
  52. attachDisabled(cad)
  53. eleAttr(cad)
  54. } else {
  55. attchTransform(cad)
  56. attchDOMTranform(cad)
  57. }
  58. attachStyle(cad)
  59. attachScreenshot(cad)
  60. attachSign(cad)
  61. attachGauge(cad)
  62. attachRote(cad)
  63. if (edit) {
  64. cad.openMouseHandle()
  65. cad.showGauge()
  66. }
  67. other(cad as any)
  68. screenAdapt(cad as any)
  69. cad.loadData(data);
  70. (cad as unknown as EXPCAD).toCanvas = (cb) => toCanvas((cad as unknown as EXPCAD), cb)
  71. return cad as any
  72. }
  73. export default structureCAD
  74. export {
  75. Column,
  76. Door,
  77. Casement
  78. }
  79. declare global { interface Window { structureCAD: any; THREE: any; test: Array<Point> } }
  80. window.structureCAD = structureCAD