Commit 923cda7e authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

save assembler file

parent ec150bde
......@@ -468,12 +468,12 @@ label {
left: 245px;
}
.assemblerTree>label{
.alternatingColorList>label{
padding-right: 10px;
width: 100%;
}
.assemblerTree{
.alternatingColorList{
display: inline-block;
width: 100%;
height: 35px;
......@@ -481,6 +481,10 @@ label {
border: 1px solid #ddd;
}
.alternatingColorList.evenListItem{
background-color:#ddd;
}
.dropdown-menu>li>a{
padding: 6px 9px;
}
......
......@@ -18,6 +18,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
this.relative = json.relative;
this.camProcesses = json.camProcesses;
this.numMaterials = json.numMaterials;
this.name = json.name;
this.object3D = new THREE.Object3D();
......@@ -292,9 +293,23 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
};
Assembler.prototype.saveJSON = function(){
return {
}
var json = this.toJSON();
json.lattice = {
scale: lattice.get("scale"),
units: lattice.get("units")
};
json.defaults = {
camStrategy: cam.get("camStrategy"),
placementOrder: cam.get("placementOrder"),
camProcess: cam.get("camProcess"),
rapidHeight: cam.get("rapidHeight"),
rapidHeightRelative: cam.get("rapidHeightRelative"),
safeHeight: cam.get("safeHeight"),
originPosition: cam.get("originPosition"),
rapidSpeeds: cam.get("rapidSpeeds"),
feedRate: cam.get("feedRate")
};
return json;
};
Assembler.prototype.toJSON = function(){
......@@ -307,6 +322,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
stockJSON[id] = thisStock.toJSON();
});
return {
name: this.name,
components: componentsJSON,
stock: stockJSON,
translation: this.translation,
......
......@@ -20,6 +20,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
this.motionVector = new THREE.Vector3();
if (json.centerOfRotation) this.centerOfRotation = new THREE.Vector3(json.centerOfRotation.x, json.centerOfRotation.y, json.centerOfRotation.z);
if (json.motionVector) this.motionVector.set(json.motionVector.x, json.motionVector.y, json.motionVector.z);
this.stlJSON = json.stl;
this.postReset();
......@@ -300,7 +301,8 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
isStatic: this.isStatic,
rotary: this.rotary,
motionVector: this.motionVector,
centerOfRotation: this.centerOfRotation
centerOfRotation: this.centerOfRotation,
stl:this.stlJSON
}
};
......
......@@ -14,7 +14,7 @@ define(['underscore', 'cam', 'three', 'component', 'lattice', 'threeModel'],
var self = this;
this._makeCell(json.description, function(cell){
self.cell = cell;
self._setPosition(cell, json.position, json.rotation);
self._setPosition(cell, json.translation, json.rotation);
self.object3D.add(cell.getObject3D());
});
}
......@@ -81,7 +81,10 @@ define(['underscore', 'cam', 'three', 'component', 'lattice', 'threeModel'],
StockComponent.prototype.toJSON = function(){
var json = Component.prototype.toJSON.call(this);
json.material = this.cell.materialName
json.description = {
materialName: this.cell.materialName,
length: this.cell.getLength()
};
return json;
};
......
......@@ -11,7 +11,8 @@ define(['jquery', 'underscore', 'menuParent', 'camPlist', 'cam', 'text!assembler
events: {
"click .editMachineComponent": "_editMachineComponent",
"click .editMachineCode": "_editMachineCode",
"click #newMachineComponent": "_newComponent"
"click #newMachineComponent": "_newComponent",
"click #saveMachineConfig": "_save"
},
_initialize: function(){
......@@ -52,6 +53,13 @@ define(['jquery', 'underscore', 'menuParent', 'camPlist', 'cam', 'text!assembler
this.model.set("currentNav", "navMachineComponent");
},
_save: function(e){
e.preventDefault();
require(['fileSaver'], function(fileSaver){
fileSaver.saveMachineConfig(cam.get("assembler").saveJSON());
});
},
_makeTemplateJSON: function(){
return _.extend(this.model.toJSON(), cam.toJSON(), cam.get("assembler").toJSON());
},
......
......@@ -3,8 +3,10 @@ Parent/Child Tree:<br/><br/>
<% _.each(tree, function(level, id){ %>
<% var component = components[id] || stock[id]; %>
<% treeLevel++; %>
<div class="assemblerTree" <% if (treeLevel%2 == 0){ %> style="background-color:#ddd"<% } %> ><label style="padding-left:<%= level*10 + 20 %>px"><%= component.name %>
<a data-id="<%= id %>" class="editMachineComponent pull-right" href="#">Edit</a></label></div><br/>
<div class="alternatingColorList<% if (treeLevel%2 == 0){ %> evenListItem <% } %>">
<label style="padding-left:<%= level*10 + 20 %>px"><%= component.name %>
<a data-id="<%= id %>" class="editMachineComponent pull-right" href="#">Edit</a></label>
</div><br/>
<% }); %><br/>
<a href="#" id="newMachineComponent" class=" btn halfWidth btn-lg btn-default">+ Component</a>
<a href="#" id="addStock" class=" btn halfWidth btn-lg btn-default pull-right">+ Stock</a><br/><br/>
......@@ -16,6 +18,7 @@ Rotation (xyz):&nbsp;&nbsp;
<input data-property="rotation" data-key="x" value="<%= rotation.x %>" placeholder="X" class="form-control floatInput assembler" type="text">&nbsp;
<input data-property="rotation" data-key="y" value="<%= rotation.y %>" placeholder="Y" class="form-control floatInput assembler" type="text">&nbsp;
<input data-property="rotation" data-key="z" value="<%= rotation.z %>" placeholder="Z" class="form-control floatInput assembler" type="text"><br/><br/>
Scale: &nbsp;&nbsp;<input data-property="scale" value="<%= scale %>" placeholder="Scale" class="form-control floatInput assembler" type="text"><br/><br/>
Edit Code:<br/><br/>
Context Variables <a class="editMachineCode" data-name="customFunctionsContext" href="#">Edit</a><br/>
......@@ -27,4 +30,4 @@ Move XY <a class="editMachineCode" data-name="customMoveXY" href="#">Edit</a><br
Change Z <a class="editMachineCode" data-name="customChangeZLayer" href="#">Edit</a><br/>
Place part <a class="editMachineCode" data-name="customPlacePart" href="#">Edit</a><br/>
Footer <a class="editMachineCode" data-name="customFooter" href="#">Edit</a><br/><br/>
<a href="#" id="saveMachineToFiles" class=" btn btn-block btn-lg btn-success">Save Machine Files</a><br/>
<a href="#" id="saveMachineConfig" class=" btn btn-block btn-lg btn-success">Save Machine Files</a><br/>
......@@ -62,7 +62,7 @@ Parent: &nbsp;&nbsp;
<% } else { %>
Material: &nbsp;&nbsp;
<div class="btn-group">
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= materials[thisComponent.material].name %><span class="caret"></span></button>
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= materials[thisComponent.description.materialName].name %><span class="caret"></span></button>
<ul role="menu" class="dropdown-menu">
<% _.each(allMaterials[materialClass], function(material, key){ %>
<li><a class="stockMaterial dropdownSelector" data-id="<%= key %>" href="#">
......
......@@ -6,25 +6,25 @@
define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWrapper'], function(_, saveAs, lattice, materials, ribbon, menuWrapper){
function _saveFile(data, name, extension){
var blob = new Blob([data], {type: "text/plain;charset=utf-8"});
var blob = new Blob([JSON.stringify(data, null, '\t')], {type: "text/plain;charset=utf-8"});
saveAs(blob, name + extension);
}
// function save(name){
// if (!name || name == "" || name == undefined) name = "file";
// var data = JSON.stringify({
// var data = {
// lattice:_getLatticeDataToSave(),
//// assembler:_getAssemblerDataToSave()
// });
// };
// _saveFile(data, name, ".json");
// }
function save(name){
if (!name || name == "" || name == undefined) name = "DM Assembly";
var data = JSON.stringify({
var data = {
assembly:_getLatticeDataToSave(),
materials:_getMaterialsDataToSave()
});
};
_saveFile(data, name, ".json");
}
......@@ -36,17 +36,21 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
if (!name || name == "" || name == undefined) name = "user";
var latticeData = _.omit(_getLatticeDataToSave(), ["cells", "cellsMin", "cellsMax", "numCells"]);
var assemblerData = _.omit(_getAssemblerDataToSave(), ["dataOut", "needsPostProcessing", "editsMadeToProgram"]);
var data = JSON.stringify({
var data = {
lattice:latticeData,
assembler:assemblerData
});
};
_saveFile(data, name, ".user");
}
function saveMaterial(id, material){
var data = {materials:{}};
data.materials[id] = material || _getMaterialDataToSave(id);
_saveFile(JSON.stringify(data), data.materials[id].name, ".json");
_saveFile(data, data.materials[id].name, ".json");
}
function saveMachineConfig(data){
_saveFile(data, "Machine Config", ".json");
}
function _getAssemblerDataToSave(){
......@@ -110,6 +114,7 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
// save: save,
save: save,
saveMaterial: saveMaterial,
saveMachineConfig: saveMachineConfig,
// saveAssembler: saveAssembler,
// saveUser: saveUser,
loadFile: loadFile
......
......@@ -106,7 +106,7 @@ define(['three'], function(THREE){
},
name: "Stock 1",
parent: "zAxis",
position: {x:0,y:0,z:0}
translation: {x:0,y:0,z:0}
},
stock2: {
description:{
......@@ -115,7 +115,7 @@ define(['three'], function(THREE){
},
name: "Stock 2",
parent: "zAxis",
position: {x:26,y:0.236,z:0}
translation: {x:26,y:0.236,z:0}
}
},
lattice:{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment