SelectByNameTool.js 1005 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * SelectByNameTool.js
  3. *
  4. * @author realor
  5. */
  6. import { Tool } from './Tool.js'
  7. class SelectByNameTool extends Tool {
  8. constructor(application, options) {
  9. super(application)
  10. this.name = 'select_by_name'
  11. this.label = 'tool.select_by_name.label'
  12. this.className = 'select_by_name'
  13. this.propertyName = 'Representation'
  14. this.immediate = true
  15. this.setOptions(options)
  16. }
  17. execute() {
  18. const selection = this.application.selection
  19. let objects = selection.objects
  20. objects = objects.map(object => this.getNamedChild(object)).filter(object => object)
  21. selection.set(...objects)
  22. }
  23. getNamedChild(object) {
  24. const children = object.children
  25. for (let i = 0; i < children.length; i++) {
  26. let child = children[i]
  27. if (child.name === this.propertyName) return child
  28. }
  29. return null
  30. }
  31. }
  32. export { SelectByNameTool }