CmdSetGeometryValue.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Created by Daniel on 21.07.15.
  3. */
  4. CmdSetGeometryValue = function ( object, attributeName, newValue ) {
  5. Cmd.call( this );
  6. this.type = 'CmdSetGeometryValue';
  7. this.name = 'Set Geometry.' + attributeName;
  8. this.object = object;
  9. this.attributeName = attributeName;
  10. this.oldValue = ( object !== undefined ) ? object.geometry[ attributeName ] : undefined;
  11. this.newValue = newValue;
  12. this.objectUuid = ( object !== undefined ) ? object.uuid : undefined;
  13. };
  14. CmdSetGeometryValue.prototype = {
  15. init: function () {
  16. if ( this.object === undefined ) {
  17. this.object = this.editor.objectByUuid( this.objectUuid );
  18. }
  19. },
  20. execute: function () {
  21. this.init();
  22. this.object.geometry[ this.attributeName ] = this.newValue;
  23. this.editor.signals.objectChanged.dispatch( this.object );
  24. this.editor.signals.sceneGraphChanged.dispatch();
  25. this.editor.signals.updateSidebar.dispatch();
  26. },
  27. undo: function () {
  28. this.init();
  29. this.object.geometry[ this.attributeName ] = this.oldValue;
  30. this.editor.signals.objectChanged.dispatch( this.object );
  31. this.editor.signals.sceneGraphChanged.dispatch();
  32. this.editor.signals.updateSidebar.dispatch();
  33. },
  34. toJSON: function () {
  35. var output = Cmd.prototype.toJSON.call( this );
  36. output.objectUuid = this.objectUuid;
  37. output.attributeName = this.attributeName;
  38. output.oldValue = this.oldValue;
  39. output.newValue = this.newValue;
  40. return output;
  41. },
  42. fromJSON: function ( json ) {
  43. Cmd.prototype.fromJSON.call( this, json );
  44. this.objectUuid = json.objectUuid;
  45. this.attributeName = json.attributeName;
  46. this.oldValue = json.oldValue;
  47. this.newValue = json.newValue;
  48. }
  49. };