diff options
Diffstat (limited to 'js/panels/Materials/materials-popup.reel/materials-popup.js')
-rwxr-xr-x | js/panels/Materials/materials-popup.reel/materials-popup.js | 378 |
1 files changed, 129 insertions, 249 deletions
diff --git a/js/panels/Materials/materials-popup.reel/materials-popup.js b/js/panels/Materials/materials-popup.reel/materials-popup.js index 40f07509..9b7b031b 100755 --- a/js/panels/Materials/materials-popup.reel/materials-popup.js +++ b/js/panels/Materials/materials-popup.reel/materials-popup.js | |||
@@ -6,7 +6,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | Component = require("montage/ui/component").Component, | 8 | Component = require("montage/ui/component").Component, |
9 | MaterialsModel = require("js/models/materials-model").MaterialsModel; | 9 | MaterialsModel = require("js/models/materials-model").MaterialsModel, |
10 | NJUtils = require("js/lib/NJUtils").NJUtils, | ||
11 | World = require("js/lib/drawing/world").World, | ||
12 | Rectangle = require("js/lib/geom/rectangle").Rectangle; | ||
10 | 13 | ||
11 | //////////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////////// |
12 | //Exporting as MaterialsPopup | 15 | //Exporting as MaterialsPopup |
@@ -22,11 +25,35 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
22 | serializable: true | 25 | serializable: true |
23 | }, | 26 | }, |
24 | 27 | ||
28 | saveAsButton: { | ||
29 | value: null, | ||
30 | serializable: true | ||
31 | }, | ||
32 | |||
33 | resetButton: { | ||
34 | value: null, | ||
35 | serializable: true | ||
36 | }, | ||
37 | |||
38 | materialsLibraryRef: { | ||
39 | value: null | ||
40 | }, | ||
41 | |||
25 | materialTitle: { | 42 | materialTitle: { |
26 | value: null, | 43 | value: null, |
27 | serializable: true | 44 | serializable: true |
28 | }, | 45 | }, |
29 | 46 | ||
47 | previewCanvas: { | ||
48 | value: null, | ||
49 | serializable: true | ||
50 | }, | ||
51 | |||
52 | previewShape: { | ||
53 | value: null, | ||
54 | serializable: true | ||
55 | }, | ||
56 | |||
30 | // Material Properties | 57 | // Material Properties |
31 | _materialName: { | 58 | _materialName: { |
32 | enumerable: true, | 59 | enumerable: true, |
@@ -42,11 +69,11 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
42 | switch(event._currentTarget.label) | 69 | switch(event._currentTarget.label) |
43 | { | 70 | { |
44 | case "Cancel": | 71 | case "Cancel": |
45 | console.log("Cancel material edit"); | 72 | // console.log("Cancel material edit"); |
46 | this.revertToOriginalValues(); | 73 | this.revertToOriginalValues(); |
47 | break; | 74 | break; |
48 | case "OK": | 75 | case "OK": |
49 | console.log("Committing material with the following values:"); | 76 | // console.log("Committing material with the following values:"); |
50 | for(var i=0, len=this.materialsProperties.childComponents.length; i< len; i++) | 77 | for(var i=0, len=this.materialsProperties.childComponents.length; i< len; i++) |
51 | { | 78 | { |
52 | var childControl = this.materialsProperties.childComponents[i]; | 79 | var childControl = this.materialsProperties.childComponents[i]; |
@@ -65,6 +92,12 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
65 | 92 | ||
66 | } | 93 | } |
67 | break; | 94 | break; |
95 | case "Save As...": | ||
96 | this.saveAs(); | ||
97 | break; | ||
98 | case "Reset": | ||
99 | this.reset(); | ||
100 | break; | ||
68 | } | 101 | } |
69 | 102 | ||
70 | // Notify Materials Library to close popup | 103 | // Notify Materials Library to close popup |
@@ -72,6 +105,28 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
72 | } | 105 | } |
73 | }, | 106 | }, |
74 | 107 | ||
108 | saveAs: | ||
109 | { | ||
110 | value: function() | ||
111 | { | ||
112 | // console.log("Save As..."); | ||
113 | var materialCopy = prompt("Save material as", this._materialName + "_Copy"); | ||
114 | |||
115 | if (materialCopy) | ||
116 | { | ||
117 | this.materialsLibraryRef.duplicateMaterial(materialCopy); | ||
118 | } | ||
119 | } | ||
120 | }, | ||
121 | |||
122 | reset: | ||
123 | { | ||
124 | value: function() | ||
125 | { | ||
126 | // console.log("Reset"); | ||
127 | } | ||
128 | }, | ||
129 | |||
75 | revertToOriginalValues: | 130 | revertToOriginalValues: |
76 | { | 131 | { |
77 | value: function() | 132 | value: function() |
@@ -131,15 +186,15 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
131 | { | 186 | { |
132 | value: function(event) | 187 | value: function(event) |
133 | { | 188 | { |
134 | if(typeof event.propertyValue === "object") | 189 | // if(typeof event.propertyValue === "object") |
135 | { | 190 | // { |
136 | console.log(event.propertyLabel + " changing to "); | 191 | // console.log(event.propertyLabel + " changing to "); |
137 | console.dir(event.propertyValue); | 192 | // console.dir(event.propertyValue); |
138 | } | 193 | // } |
139 | else | 194 | // else |
140 | { | 195 | // { |
141 | console.log(event.propertyLabel + " changing to " + event.propertyValue); | 196 | // console.log(event.propertyLabel + " changing to " + event.propertyValue); |
142 | } | 197 | // } |
143 | 198 | ||
144 | if (event.propertyLabel && event.propertyValue) | 199 | if (event.propertyLabel && event.propertyValue) |
145 | this.applyProperty( event.propertyLabel, event.propertyValue ); | 200 | this.applyProperty( event.propertyLabel, event.propertyValue ); |
@@ -151,15 +206,15 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
151 | value: function(theEvent) | 206 | value: function(theEvent) |
152 | { | 207 | { |
153 | var event = theEvent._event; | 208 | var event = theEvent._event; |
154 | if(typeof event.propertyValue === "object") | 209 | // if(typeof event.propertyValue === "object") |
155 | { | 210 | // { |
156 | console.log(event.propertyLabel + " changed to "); | 211 | // console.log(event.propertyLabel + " changed to "); |
157 | console.dir(event.propertyValue); | 212 | // console.dir(event.propertyValue); |
158 | } | 213 | // } |
159 | else | 214 | // else |
160 | { | 215 | // { |
161 | console.log(event.propertyLabel + " changed to " + event.propertyValue); | 216 | // console.log(event.propertyLabel + " changed to " + event.propertyValue); |
162 | } | 217 | // } |
163 | 218 | ||
164 | if (event.propertyLabel) | 219 | if (event.propertyLabel) |
165 | this.applyProperty( event.propertyLabel, event.propertyValue ); | 220 | this.applyProperty( event.propertyLabel, event.propertyValue ); |
@@ -195,9 +250,10 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
195 | this._material.setProperty( this._propNames[index], value ); | 250 | this._material.setProperty( this._propNames[index], value ); |
196 | } | 251 | } |
197 | 252 | ||
253 | var obj, matArray, matTypeArray, nMats, iMat, world; | ||
198 | if (this._useSelection) | 254 | if (this._useSelection) |
199 | { | 255 | { |
200 | console.log( "apply to selection" ); | 256 | // console.log( "apply to selection" ); |
201 | 257 | ||
202 | var selection = this.application.ninja.selectedElements; | 258 | var selection = this.application.ninja.selectedElements; |
203 | if (selection && (selection.length > 0)) | 259 | if (selection && (selection.length > 0)) |
@@ -206,25 +262,38 @@ exports.MaterialsPopup = Montage.create(Component, { | |||
206 | for (var iObj=0; iObj<nObjs; iObj++) | 262 | for (var iObj=0; iObj<nObjs; iObj++) |
207 | { | 263 | { |
208 | var canvas = selection[iObj]; | 264 | var canvas = selection[iObj]; |
209 | var obj; | ||
210 | if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj; | 265 | if (canvas.elementModel && canvas.elementModel.shapeModel) obj = canvas.elementModel.shapeModel.GLGeomObj; |
211 | if (obj) | 266 | if (obj) |
212 | { | 267 | { |
213 | var matArray = obj._materialArray; | 268 | matArray = obj._materialArray; |
214 | var matTypeArray = obj._materialTypeArray; | 269 | matTypeArray = obj._materialTypeArray; |
215 | var nMats = matArray.length; | 270 | nMats = matArray.length; |
216 | for (var iMat=0; iMat<nMats; iMat++) |