aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Materials/materials-popup.reel/materials-popup.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/Materials/materials-popup.reel/materials-popup.js')
-rwxr-xr-xjs/panels/Materials/materials-popup.reel/materials-popup.js1148
1 files changed, 540 insertions, 608 deletions
diff --git a/js/panels/Materials/materials-popup.reel/materials-popup.js b/js/panels/Materials/materials-popup.reel/materials-popup.js
index 7c5493c6..501df282 100755
--- a/js/panels/Materials/materials-popup.reel/materials-popup.js
+++ b/js/panels/Materials/materials-popup.reel/materials-popup.js
@@ -30,7 +30,11 @@ POSSIBILITY OF SUCH DAMAGE.
30 30
31var Montage = require("montage/core/core").Montage, 31var Montage = require("montage/core/core").Montage,
32 Component = require("montage/ui/component").Component, 32 Component = require("montage/ui/component").Component,
33 MaterialsModel = require("js/models/materials-model").MaterialsModel; 33 MaterialsModel = require("js/models/materials-model").MaterialsModel,
34 NJUtils = require("js/lib/NJUtils").NJUtils,
35 World = require("js/lib/drawing/world").World,
36 Rectangle = require("js/lib/geom/rectangle").Rectangle,
37 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController;
34 38
35//////////////////////////////////////////////////////////////////////// 39////////////////////////////////////////////////////////////////////////
36//Exporting as MaterialsPopup 40//Exporting as MaterialsPopup
@@ -46,31 +50,55 @@ exports.MaterialsPopup = Montage.create(Component, {
46 serializable: true 50 serializable: true
47 }, 51 },
48 52
53 saveAsButton: {
54 value: null,
55 serializable: true
56 },
57
58 resetButton: {
59 value: null,
60 serializable: true
61 },
62
63 materialsLibraryRef: {
64 value: null
65 },
66
49 materialTitle: { 67 materialTitle: {
50 value: null, 68 value: null,
51 serializable: true 69 serializable: true
52 }, 70 },
53 71
54 // Material Properties 72 previewCanvas: {
73 value: null,
74 serializable: true
75 },
76
77 previewShape: {
78 value: null,
79 serializable: true
80 },
81
82 // Material Properties
55 _materialName: { 83 _materialName: {
56 enumerable: true, 84 enumerable: true,
57 value: "" 85 value: ""
58 }, 86 },
59 87
60 _useSelection: { value: false, enumerable: true }, 88 _useSelection: { value: false, enumerable: true },
61 _whichMaterial: { value: "fill", enumerable: true }, 89 _whichMaterial: { value: "fill", enumerable: true },
62 _originalValues: {value: null, enumerable: true }, 90 _originalValues: {value: null, enumerable: true },
63 91
64 captureAction: { 92 captureAction: {
65 value:function(event) { 93 value:function(event) {
66 switch(event._currentTarget.label) 94 switch(event._currentTarget.label)
67 { 95 {
68 case "Cancel": 96 case "Cancel":
69 console.log("Cancel material edit"); 97// console.log("Cancel material edit");
70 this.revertToOriginalValues(); 98 this.revertToOriginalValues();
71 break; 99 break;
72 case "OK": 100 case "OK":
73 console.log("Committing material with the following values:"); 101// console.log("Committing material with the following values:");
74 for(var i=0, len=this.materialsProperties.childComponents.length; i< len; i++) 102 for(var i=0, len=this.materialsProperties.childComponents.length; i< len; i++)
75 { 103 {
76 var childControl = this.materialsProperties.childComponents[i]; 104 var childControl = this.materialsProperties.childComponents[i];
@@ -88,53 +116,81 @@ exports.MaterialsPopup = Montage.create(Component, {
88 console.log("--------------"); 116 console.log("--------------");
89 117
90 } 118 }
91 break; 119 break;
92 } 120 case "Save As...":
121 this.saveAs();
122 break;
123 case "Reset":
124 this.reset();
125 break;
126 }
93 127
94 // Notify Materials Library to close popup 128 // Notify Materials Library to close popup
95 NJevent("hideMaterialPopup"); 129 NJevent("hideMaterialPopup");
96 } 130 }
97 }, 131 },
98 132
99 revertToOriginalValues: 133 saveAs:
100 { 134 {
101 value: function() 135 value: function()
102 { 136 {
103 if (this._originalValues) 137// console.log("Save As...");
104 { 138 var materialCopy = prompt("Save material as", this._materialName + "_Copy");
105 this._material.importJSON( this._originalValues ); 139
106 140 if (materialCopy)
107 if (this._useSelection) 141 {
108 { 142 this.materialsLibraryRef.duplicateMaterial(materialCopy);
109 var selection = this.application.ninja.selectedElements; 143 }
110 if (selection && (selection.length > 0)) 144 }
111 { 145 },
112 var nObjs = selection.length; 146
113 for (var iObj=0; iObj<nObjs; iObj++) 147 reset:
114 { 148 {
115 var canvas = selection[iObj]; 149 value: function()
116 var obj; 150 {
117 if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj; 151// console.log("Reset");
118 if (obj) 152 }
119 { 153 },
120 var matArray = obj._materialArray; 154
121 var matTypeArray = obj._materialTypeArray; 155 revertToOriginalValues:
122 var nMats = matArray.length; 156 {
123 for (var iMat=0; iMat<nMats; iMat++) 157 value: function()
124 { 158 {
125 if (matTypeArray[iMat] === this._whichMaterial) 159 if (this._originalValues)
126 matArray[iMat].importJSON( this._originalValues ); 160 {
127 } 161 this._material.importJSON( this._originalValues );
128 var world = obj.getWorld(); 162
129 if (world) 163 if (this._useSelection)
130 world.restartRenderLoop(); 164 {
131 } 165 var selection = this.application.ninja.selectedElements;
132 } 166 if (selection && (selection.length > 0))
133 } 167 {
134 } 168 var nObjs = selection.length;
135 } 169 for (var iObj=0; iObj<nObjs; iObj++)
136 } 170 {
137 }, 171 var canvas = selection[iObj];
172 var obj;
173 if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj;
174 if (obj)
175 {
176 var matArray = obj._materialArray;
177 var matTypeArray = obj._materialTypeArray;
178 var nMats = matArray.length;
179 for (var iMat=0; iMat<nMats; iMat++)
180 {
181 if (matTypeArray[iMat] === this._whichMaterial)
182 matArray[iMat].importJSON( this._originalValues );
183 }
184 var world = obj.getWorld();
185 if (world)
186 world.restartRenderLoop();
187 }
188 }
189 }
190 }
191 }
192 }
193 },
138 194
139 updatePreview: 195 updatePreview:
140 { 196 {
@@ -155,346 +211,384 @@ exports.MaterialsPopup = Montage.create(Component, {
155 { 211 {