transformToolManager.vwf.yaml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  2. # Secretary of Defense (Personnel & Readiness).
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5. # in compliance with the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the License
  10. # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  11. # or implied. See the License for the specific language governing permissions and limitations under
  12. # the License.
  13. ## The component representation of a control behavior
  14. ##
  15. ## @name control.vwf
  16. ## @namespace
  17. ---
  18. properties:
  19. transformTool-enabled:
  20. set: |
  21. this["transformTool-enabled"] = Boolean( value );
  22. value: true
  23. events:
  24. pointerClick:
  25. methods:
  26. select:
  27. createTool:
  28. scripts:
  29. - |
  30. this.initialize = function() {
  31. this.tt = undefined;
  32. this.clickedID = undefined;
  33. this.selectedObject = undefined;
  34. this.previousParent = undefined;
  35. }
  36. this.pointerClick = function( pointerInfo, pickInfo ) {
  37. this.clickedID = pickInfo.pickID;
  38. if ( this["transformTool-enabled"] ) {
  39. this.select( pickInfo.pickID );
  40. }
  41. }
  42. this.select = function( id ) {
  43. //console.info( "this.select( "+id+" )" );
  44. if ( this["transformTool-enabled"] && id ) {
  45. if ( this.transformTool === undefined ) {
  46. this.createTool();
  47. } else {
  48. var clickedNode = this.findByID( this, id );
  49. if ( clickedNode ) {
  50. //console.info( " valid clickedNode: " + clickedNode.id );
  51. var self = this;
  52. var selectNode = function() {
  53. //console.info( " selectNode: " + clickedNode.id );
  54. var wt;
  55. if ( self.selectedObject !== undefined ) {
  56. wt = self.transformTool.worldTransform;
  57. self.selectedObject.parent_ = self.previousParent;
  58. self.selectedObject.worldTransform = wt;
  59. //self.transformTool.removeChildren();
  60. self.transformTool.deleteGeometry();
  61. }
  62. self.selectedObject = clickedNode;
  63. self.previousParent = clickedNode.parent;
  64. wt = self.selectedObject.worldTransform;
  65. clickedNode.parent_ = self.transformTool;
  66. self.transformTool.worldTransform = wt;
  67. self.selectedObject.transform = [ 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 ];
  68. //console.info( " tt calling to select to generate tool: " );
  69. self.transformTool.objectSelected( self.selectedObject );
  70. };
  71. if ( !this.isChildOf( clickedNode, this.transformTool ) ) {
  72. selectNode();
  73. }
  74. }
  75. }
  76. }
  77. }
  78. this.createTool = function() {
  79. var self = this;
  80. var tt = { "includes": "http://vwf.example.com/tools/transform/transformTool.vwf" }
  81. this.children.create( "transformTool", tt, function( child ) {
  82. self.select( self.clickedID );
  83. } );
  84. } //@ sourceURL=transformToolManager.vwf