Commit c793d8a2 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

load assembler from file

parent 923cda7e
......@@ -97,17 +97,23 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel
},
selectMachine: function(){
var machineName = this.get("machineName");
if (this.get("assembler")){
if (this.get("assembler").getID() == machineName) return;
else {
this.get("assembler").destroy();
this.set("assembler", null);
selectMachine: function(json){
var machineJSON = json;
if (machineJSON === undefined){
var machineName = this.get("machineName");
if (this.get("assembler")){
if (this.get("assembler").getID() == machineName) return;
else {
this.get("assembler").destroy();
this.set("assembler", null);
}
}
machineJSON = camPlist.allMachines[machineName];
} else {
machineName = "customMachine";
this.set("machineName", machineName, {silent:true});
}
var machineJSON = camPlist.allMachines[machineName];
if (machineJSON.defaults) this._setMachineDefaults(machineJSON.defaults);
if (machineJSON.lattice) this._setLatticeDefaults(machineJSON.lattice)
......@@ -126,7 +132,8 @@ define(['underscore', 'three', 'backbone', 'appState', 'latticeCAM', 'threeModel
_setMachineDefaults: function(defaults){
var self = this;
_.each(defaults, function(value, key){
self.set(key, value, {silent:true});
if (value.x !== undefined && value.x !== null) self.set(key, new THREE.Vector3(value.x, value.y, value.z), {silent:true});
else self.set(key, value, {silent:true});
});
},
......
......@@ -238,9 +238,6 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
}
var startingPos = this.components.xAxis.getPosition().add(this.components.frame.getPosition().add(this.components.zAxis.getPosition()));//this.components.zAxis.getAbsolutePosition();//get position of end effector
console.log("here");
console.log(startingPos);//this.components.zAxis.applyAbsoluteRotation(
console.log(position);
speed = this._normalizeSpeed(startingPos, position, new THREE.Vector3(speed, speed, speed));//todo fix this
this.components.xAxis.moveTo(position, speed.x, sketchyCallback);
......@@ -279,9 +276,14 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
var self = this;
_.each(this.components, function(component, index){
component.destroy();
self[index] = null;
self.components[index] = null;
});
_.each(this.stock, function(thisStock, index){
thisStock.destroy();
self.stock[index] = null;
});
this.components = null;
this.stock = null;
three.sceneRemove(this.object3D);
this.stock = null;
this.components.zAxis = null;
......@@ -309,7 +311,7 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
rapidSpeeds: cam.get("rapidSpeeds"),
feedRate: cam.get("feedRate")
};
return json;
return {assembler: json};
};
Assembler.prototype.toJSON = function(){
......@@ -321,10 +323,18 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
_.each(this.stock, function(thisStock, id){
stockJSON[id] = thisStock.toJSON();
});
return {
name: this.name,
var json = this.basicJSON();
_.extend(json, {
components: componentsJSON,
stock: stockJSON,
tree: this.tree || this.buildComponentTree()
});
return json;
};
Assembler.prototype.basicJSON = function(){
return {
name: this.name,
translation: this.translation,
scale: this.scale,
rotation: this.rotation,
......@@ -332,7 +342,6 @@ define(['underscore', 'appState', 'lattice', 'stlLoader', 'threeModel', 'cam', '
relative: this.relative,
camProcesses: this.camProcesses,
numMaterials: this.numMaterials,
tree: this.tree || this.buildComponentTree()
}
};
......
......@@ -22,7 +22,6 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
if (json.motionVector) this.motionVector.set(json.motionVector.x, json.motionVector.y, json.motionVector.z);
this.stlJSON = json.stl;
this.postReset();
}
......@@ -297,7 +296,7 @@ define(['underscore', 'cam', 'three'], function(_, cam, THREE){
parent: this.parent || "",
translation: this.object3D.position,
scale: this.object3D.scale.x,
rotation: this.object3D.rotation,
rotation: this.object3D.rotation.toVector3(),
isStatic: this.isStatic,
rotary: this.rotary,
motionVector: this.motionVector,
......
......@@ -11,10 +11,12 @@ define(['underscore', 'cam', 'three', 'component', 'lattice', 'threeModel'],
Component.call(this, id, json);
//material
this.object3D.position.set(json.translation.x, json.translation.y, json.translation.z);
if (json.rotation) this.object3D.rotation.set(json.rotation.x, json.rotation.y, json.rotation.z);
var self = this;
this._makeCell(json.description, function(cell){
self.cell = cell;
self._setPosition(cell, json.translation, json.rotation);
self.object3D.add(cell.getObject3D());
});
}
......@@ -28,12 +30,6 @@ define(['underscore', 'cam', 'three', 'component', 'lattice', 'threeModel'],
lattice.makeCellForLatticeType(json, callback);
};
StockComponent.prototype._setPosition = function(cell, position, rotation){
var object3D = cell.getObject3D();//todo need this?
if (position) object3D.position.set(position.x, position.y, position.z);
if (rotation) object3D.rotation.set(rotation.x, rotation.y, rotation.z);
};
StockComponent.prototype.getPosition = function(){
return this.cell.getPosition();
};
......@@ -55,6 +51,7 @@ define(['underscore', 'cam', 'three', 'component', 'lattice', 'threeModel'],
StockComponent.prototype.show = function(){
this.cell.show();
console.log(this.cell);
};
StockComponent.prototype.hide = function(){
......@@ -75,7 +72,8 @@ define(['underscore', 'cam', 'three', 'component', 'lattice', 'threeModel'],
StockComponent.prototype.destroy = function(){
Component.prototype.destroy.call(this);
this.cell.destroy();
this.cell = null;
};
......
......@@ -36,7 +36,10 @@ define(['jquery', 'underscore', 'menuParent', 'camPlist', 'cam', 'lattice', 'mat
},
_makeTemplateJSON: function(){
return _.extend(this.model.toJSON(), cam.toJSON(), lattice.toJSON(), camPlist, {materials:materials.list});
var assembler = cam.get("assembler");
if (assembler) assembler = assembler.basicJSON();
else assembler = camPlist.allMachines[cam.get("machineName")];
return _.extend(this.model.toJSON(), {thisAssembler: assembler}, cam.toJSON(), lattice.toJSON(), camPlist, {materials:materials.list});
},
template: _.template(template)
......
<% if (numCells == 0){ %>
<div class="inlineWarning">No cells in assembly!</div>
<% } %>
<a href="#" class="importJSON btn btn-block btn-lg btn-default">Load Assembler From File</a><br/>
Machine: &nbsp;&nbsp;
<div class="btn-group">
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allMachines[machineName].name %><span class="caret"></span></button>
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= thisAssembler.name %><span class="caret"></span></button>
<ul role="menu" class="dropdown-menu">
<% _.each(machineTypesForLattice[cellType][connectionType], function(machine){ %>
<li><a class="assembler dropdownSelector" data-property="machineName" data-value="<%= machine %>" href="#"><%= allMachines[machine].name %></a></li>
......@@ -11,15 +12,15 @@ Machine: &nbsp;&nbsp;
</ul>
</div><br/>
<label class="checkbox" for="relativeAssembler">
<input id="relativeAssembler" data-property="relative" type="checkbox" <% if (allMachines[machineName].relative){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="machine custom-checkbox">
<input id="relativeAssembler" data-property="relative" type="checkbox" <% if (thisAssembler.relative){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="machine custom-checkbox">
<span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
Relative Assembler</label>
<label class="checkbox" for="stockAttached">
<input id="stockAttached" data-property="shouldPickUpStock" type="checkbox" <% if (allMachines[machineName].shouldPickUpStock){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="machine custom-checkbox">
<input id="stockAttached" data-property="shouldPickUpStock" type="checkbox" <% if (thisAssembler.shouldPickUpStock){ %> checked="checked"<% } %> value="" data-toggle="checkbox" class="machine custom-checkbox">
<span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
Separate Stock Position</label>
<% if (allMachines[machineName].numMaterials > -1){ %>
Num Materials: &nbsp;&nbsp;<%= allMachines[machineName].numMaterials %><br/>
<% if (thisAssembler.numMaterials > -1){ %>
Num Materials: &nbsp;&nbsp;<%= thisAssembler.numMaterials %><br/>
<% } %><br/>
Strategy: &nbsp;&nbsp;
<div class="btn-group">
......@@ -33,8 +34,8 @@ Strategy: &nbsp;&nbsp;
<% if (camStrategy == "raster"){ %>
Raster Order: &nbsp;&nbsp;<input value="<%= placementOrder %>" placeholder="Placement Order" class="form-control placementOrder halfWidth" type="text"><br/><br/>
<% } %>
<% if (allMachines[machineName].numMaterials > -1 && allMachines[machineName].numMaterials < allCAMMaterialTypes.length){ %>
<div class="inlineWarning">Number of materials in assembly exceeds available materials ( <%= allMachines[machineName].numMaterials %> ) for assembler type.</div>
<% if (thisAssembler.numMaterials > -1 && thisAssembler.numMaterials < allCAMMaterialTypes.length){ %>
<div class="inlineWarning">Number of materials in assembly exceeds available materials ( <%= thisAssembler.numMaterials %> ) for assembler type.</div>
<% } %>
Num Materials in Assembly: &nbsp;&nbsp;<%= allCAMMaterialTypes.length %><br/>
<% _.each(allCAMMaterialTypes, function(material){ %>
......
......@@ -76,6 +76,10 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
}
function loadFile(data){//parsed json todo make this better - load composite
if (data.assembler) {
_loadAssembler(data.assembler);
return;
}
if (!data.materials){
console.warn("no material definitions in this file");
return;
......@@ -95,6 +99,13 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
menuWrapper.render();
}
function _loadAssembler(data){
require(['cam'], function(cam){
cam.selectMachine(data);
console.log("loaded");
});
}
function loadUser(data){
_setData(data);
}
......
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