API Docs for: 2.0.0
Show:

File: src/viewer/effects/effect.js

  1. /**
  2. An **Effect** is a the base class for visual effects that are applied to {{#crossLink "ObjectSet"}}ObjectSets{{/crossLink}}.
  3.  
  4. ## Overview
  5.  
  6. <ul>
  7. <li>Effect is subclassed by {{#crossLink "HighlightEffect"}}{{/crossLink}}, {{#crossLink "IsolateEffect"}}{{/crossLink}} and {{#crossLink "XRayEffect"}}{{/crossLink}}.</li>
  8. <li>Multiple Effects can share the same {{#crossLink "ObjectSet"}}{{/crossLink}} if required.</li>
  9. <li>An Effect will provide its own default {{#crossLink "ObjectSet"}}{{/crossLink}} when you don't configure it with one.</li>
  10. </ul>
  11.  
  12. @class Effect
  13. @module BIMSURFER
  14. @submodule effect
  15. @constructor
  16. @param [viewer] {Viewer} Parent {{#crossLink "Viewer"}}{{/crossLink}}.
  17. @param [cfg] {*} Configs
  18. @param [cfg.id] {String} Optional ID, unique among all components in the parent viewer, generated automatically when omitted.
  19. @param [cfg.meta] {String:Object} Optional map of user-defined metadata to attach to this Effect.
  20. @param [cfg.objectSet] {ObjectSet} The {{#crossLink "ObjectSet"}}{{/crossLink}} to apply this Effect to.
  21. @extends Component
  22. */
  23. (function () {
  24.  
  25. "use strict";
  26.  
  27. BIMSURFER.Effect = BIMSURFER.Component.extend({
  28.  
  29. /**
  30. JavaScript class name for this Component.
  31.  
  32. @property className
  33. @type String
  34. @final
  35. */
  36. className: "BIMSURFER.Effect",
  37.  
  38. _init: function (cfg) {
  39.  
  40. /**
  41. * The {{#crossLink "ObjectSet"}}{{/crossLink}} that this Effect applies to.
  42. *
  43. * @property objectSet
  44. * @type ObjectSet
  45. */
  46. this.objectSet = cfg.objectSet || new BIMSURFER.ObjectSet(this.viewer);
  47.  
  48. this._dirty = true;
  49.  
  50. var self = this;
  51.  
  52. this._onObjectSetUpdated = this.objectSet.on("updated",
  53. function () {
  54. self._dirty = true;
  55. });
  56.  
  57. this.invert = cfg.invert;
  58.  
  59. this.active = cfg.active !== false;
  60. },
  61.  
  62. _props: {
  63.  
  64. /**
  65. * Flag which indicates whether this Effect is active or not.
  66. *
  67. * Fires an {{#crossLink "Effect/active:event"}}{{/crossLink}} event on change.
  68. *
  69. * @property active
  70. * @type Boolean
  71. */
  72. active: {
  73.  
  74. set: function (value) {
  75.  
  76. if (this._active === value) {
  77. return;
  78. }
  79.  
  80. if (value) {
  81.  
  82. var self = this;
  83.  
  84.  
  85. this._tickSub = this.viewer.on("tick",
  86. function () {
  87.  
  88. if (self._dirty) {
  89.  
  90. if (self._apply) {
  91. self._apply();
  92. }
  93.  
  94. if (self._applyObject) {
  95.  
  96. // Apply effect to Objects in the Viewer
  97. self.viewer.withClasses(["BIMSURFER.Object"],
  98. function (object) {
  99. self._applyObject.call(self, object);
  100. });
  101.  
  102. self.viewer.withClasses(["BIMSURFER.BoxObject"],
  103. function (object) {
  104. self._applyObject.call(self, object);
  105. });
  106.  
  107. }
  108.  
  109. self._dirty = false;
  110. }
  111. });
  112.  
  113. } else {
  114.  
  115. this.viewer.off(this._tickSub);
  116. }
  117.  
  118. /**
  119. * Fired whenever this Effect's {{#crossLink "Effect/active:property"}}{{/crossLink}} property changes.
  120. * @event active
  121. * @param value The property's new value
  122. */
  123. this.fire('active', this._active = value);
  124.  
  125. this._dirty = true;
  126. },
  127.  
  128. get: function () {
  129. return this._active;
  130. }
  131. },
  132.  
  133. /**
  134. * Flag which inverts the {{#crossLink "Object"}}Objects{{/crossLink}} that this Effect applies to.
  135. *
  136. * <ul>
  137. * <li>When true, this Effect applies to {{#crossLink "Object"}}Objects{{/crossLink}} that are in
  138. * the {{#crossLink "Component/viewer:property"}}{{/crossLink}} but **not** in the {{#crossLink "Effect/objectSet:property"}}{{/crossLink}}.</li>
  139. *
  140. * <li>When false, this Effect applies to {{#crossLink "Object"}}Objects{{/crossLink}} that are in
  141. * the {{#crossLink "Component/viewer:property"}}{{/crossLink}} and **also** in the {{#crossLink "Effect/objectSet:property"}}{{/crossLink}}.</li>
  142. * </ul>
  143. *
  144. * Fires an {{#crossLink "Effect/invert:event"}}{{/crossLink}} event on change.
  145. *
  146. * @property invert
  147. * @type Boolean
  148. */
  149. invert: {
  150.  
  151. set: function (value) {
  152.  
  153. value = !!value;
  154.  
  155. if (this._invert === value) {
  156. return;
  157. }
  158.  
  159. this._dirty = false;
  160.  
  161. /**
  162. * Fired whenever this Effect's {{#crossLink "Effect/invert:property"}}{{/crossLink}} property changes.
  163. * @event invert
  164. * @param value The property's new value
  165. */
  166. this.fire('invert', this._invert = value);
  167. },
  168.  
  169. get: function () {
  170. return this._invert;
  171. }
  172. }
  173. },
  174.  
  175. _destroy: function () {
  176.  
  177. this.objectSet.off(this._onObjectSetUpdated);
  178.  
  179. this.active = false;
  180. }
  181.  
  182. });
  183.  
  184. })();