disabled.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {AttachCAD as CAD} from '../index'
  2. import { CADElement } from '../core/element'
  3. import LineArch from '../architecture/linearch'
  4. import Column from '../architecture/column'
  5. export interface Disabled {
  6. forbidden: Function
  7. available: Function
  8. }
  9. // 启用或禁用cad
  10. export const attachDisabled = (cad: CAD) => {
  11. let editApis = ['increase', 'getStackState', 'preservation', 'previous', 'next', 'closeMouseHandle', 'showGauge', 'hideGauge']
  12. let apiFuns = []
  13. // 禁用cad所有交互取消
  14. cad.forbidden = () => {
  15. if (apiFuns.length === editApis.length) return;
  16. cad.hideGauge()
  17. cad.closeMouseHandle()
  18. CADElement.examples.get(cad.processing.render).forEach(e => e.unEvent())
  19. LineArch.attaArch.forEach(archs => {
  20. archs.forEach(arch => {
  21. arch instanceof Column && arch.delEvent()
  22. })
  23. })
  24. editApis.forEach(key => {
  25. apiFuns.push(cad[key])
  26. delete cad[key]
  27. })
  28. }
  29. // 启用cad激活操作
  30. cad.available = () => {
  31. if (apiFuns.length !== editApis.length) return;
  32. editApis.forEach((key, i) => cad[key] = apiFuns[i])
  33. apiFuns = []
  34. CADElement.examples.get(cad.processing.render).forEach(e => e.listen());
  35. LineArch.attaArch.forEach(archs => {
  36. archs.forEach(arch => arch instanceof Column && arch.addEvent())
  37. })
  38. cad.showGauge()
  39. cad.openMouseHandle()
  40. }
  41. }