Commit 2169ab42 authored by amandaghassaei's avatar amandaghassaei

fixing bugs

parent 4a5cede0
......@@ -89,6 +89,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
return this.get("partType");
},
//lattice type
_getLatticePlistData: function(){
return plist.allLattices[this.get("cellType")].connection[this.get("connectionType")].type[this.get("applicationType")];
},
//setters
......@@ -232,12 +238,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
},
_setDefaultCellMode: function(){//if no part associated with this lattice type set to cell mode
var latticeData = this._getLatticePlistData();
if (!latticeData.parts){
var currentMode = appState.get("cellMode");
if (currentMode == "cell" || currentMode == "supercell") return;
appState.set("cellMode", "cell");
}
appState.set("cellMode", "cell");
},
......@@ -313,7 +314,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'materialsPlis
//events
__clearCells: function(silent){
three.removeAllCells();//todo add flag in cell destroy to avoid redundancy here
if (globals.basePlane) globals.basePlane.set("zIndex", 0, {silent:silent});
},
......
......@@ -9,7 +9,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
return Backbone.Model.extend({
defaults: {
cellsMin: null,//min position of cells matrix
cellsMax: null,//max position of cells matrix
numCells: 0
......@@ -63,7 +62,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
getCellAtIndex: function(index){
if (this._checkForIndexOutsideBounds(index)) return null;
return this._getCellAtIndex(index);
return this._getCellAtIndex(this._getCellsIndexForLatticeIndex(index));
},
_getCellAtIndex: function(index){
......@@ -78,14 +77,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
//lattice type
_getLatticePlistData: function(){
return plist.allLattices[this.get("cellType")].connection[this.get("connectionType")].type[this.get("applicationType")];
},
//add/remove cells
......@@ -144,14 +135,20 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
_addCellAtIndex: function(index, json, noCheck){
json = json || {};
if (this.getCellAtIndex(index)) {
console.warn("already a cell there");
return;
}
json = _.extend({index: index.clone(), materialID:appState.get("materialType")}, json);
var cell = this.makeCellWithJSON(json);
if (!noCheck) {
var cellOutsideCurrentBounds = this._checkForIndexOutsideBounds(index) || this._checkForIndexOutsideBounds(index);
var cellOutsideCurrentBounds = this._checkForIndexOutsideBounds(index);
if (cellOutsideCurrentBounds) this._expandCellsMatrix(index, index);
}
var latticeIndex = cell.getLatticeIndex();
var latticeIndex = this._getCellsIndexForLatticeIndex(index);
this.cells[latticeIndex.x][latticeIndex.y][latticeIndex.z] = cell;//cell index in this.cells array
this.set("numCells", this.get("numCells")+1);
},
......@@ -235,6 +232,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
_clearCells: function(silent){
if (silent === undefined) silent = false;
three.removeAllCells();//todo flag to avoid redundancy here
this._loopCells(this.cells, function(cell){//send destroy to top level
cell.destroy();
});
......@@ -282,7 +280,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
this.set("cellsMin", indicesMin);
var size = indicesMax.clone().sub(indicesMin);
this._expandArray(this.cells, size, false);
this._expandArray(this.cells, size, false);
return;
}
......@@ -291,13 +288,11 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
if (!indicesMax.equals(lastMax)) {
var size = indicesMax.clone().sub(lastMax);
this._expandArray(this.cells, size, false);
this._expandArray(this.cells, size, false);
this.set("cellsMax", indicesMax);
}
if (!indicesMin.equals(lastMin)) {
var size = lastMin.clone().sub(indicesMin);
this._expandArray(this.cells, size, true);
this._expandArray(this.cells, size, true);
this.set("cellsMin", indicesMin);
}
},
......@@ -367,8 +362,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
if (maxDiff.equals(zero) && minDiff.equals(zero)) return;
this._contractCellsArray(this.cells, false, maxDiff);
this._contractCellsArray(this.cells, false, maxDiff);
this._contractCellsArray(this.cells, true, minDiff);
this._contractCellsArray(this.cells, true, minDiff);
this.set("cellsMax", newMax, {silent:true});
......
/**
* Created by aghassaei on 6/10/15.
*/
define(['jquery', 'underscore', 'three', 'menuParent', 'compositeEditorLattice', 'materialsPlist', 'lattice', 'globals', 'materials', 'text!menus/templates/CompositeMenuView.html'],
function($, _, THREE, MenuParentView, CompositeEditorLattice, materialsPlist, lattice, globals, materials, template){
return MenuParentView.extend({
events: {
"click #newRandomColor": "_changeRandomColor",
"click #saveComposite": "_saveCompositeToFile"
},
_initialize: function(options){
var id = options.myObject;
var material;
if (id) material = materials.getMaterialForId(id);
if (material && !material.isComposite()){
console.warn("material " + id + " is not a composite");
}
var json = {};
if (material) json = material.toJSON();
else if (id == "_fromLattice"){
json.sparseCells = lattice.getSparseCellsJSON();
lattice.clearCells();
}
material = materials.newCompositeMaterial(json, {_noAdd: true});
this.material = material;
this.compositeEditor = this._setToCompositeMode(material.toJSON());
this.listenTo(this.compositeEditor, "change:numCells", this.render);
this.listenTo(this.model, "change", this.render);
},
_setToCompositeMode: function(json){
lattice.hideCells();
if (lattice.inCompositeMode()) {
console.warn("composite editor already allocated");
lattice.exitCompositeEditing();
}
var compositeLattice = new CompositeEditorLattice();
compositeLattice.setSparseCells(json.sparseCells, lattice.getOffset());
lattice.setToCompositeMode(compositeLattice);
return compositeLattice;
},
_changeRandomColor: function(e){
e.preventDefault();
this.material.changeRandomColor();
this.render();
},
getPropertyOwner: function($target){
if ($target.hasClass("compositeEditor")) return this.compositeEditor;
return null;
},
updateHex: function(hex, $target){
//update hex without rendering
$target.css("border-color", hex);
},
_saveCompositeToFile: function(e){
e.preventDefault();
this.material.set(this._buildMaterialJSON());//todo this should be a callback
var self = this;
require(['fileSaver'], function(fileSaver){
fileSaver.saveMaterial(self.material);
});
},
_buildMaterialJSON: function(){
var json = {
sparseCells: this.compositeEditor.getSparseCellsJSON(),
dimensions: this.compositeEditor.getSize()
};
if (this.compositeEditor.getNumCells() > 0){
_.extend(json, {
origin: new THREE.Vector3(0,0,0),
cellsMin: new THREE.Vector3(0,0,0),
cellsMax: this.compositeEditor.get("cellsMax").clone().sub(this.compositeEditor.get("cellsMin"))
});
} else {
console.warn("composite material has no cells");
}
return json;
},
saveExitMenu: function(){
this.stopListening();
if (!this.compositeEditor){
console.warn("lattice not in composite mode for finish composite call");
return false;
}
if (this.compositeEditor.getNumCells() > 0){
materials.setCompositeMaterial(this.material.getID(), _.extend(this.material.toJSON(), this._buildMaterialJSON()));
} else {
console.warn("no cells in composite definition, save cancelled");
}
return true;
},
deleteExitMenu: function(){
if (!this.compositeEditor){
console.warn("lattice not in composite mode for delete composite call");
return true;
}
return materials.deleteMaterialById(this.material.getID());
},
_makeTemplateJSON: function(){
var compositeParents = this.material.getParentComposites(materials);
compositeParents.push(this.material.getID());
return _.extend(this.model.toJSON(), materials.toJSON(), materialsPlist, globals, this.material.toJSON(), this.compositeEditor.toJSON(),
{
dimensions: this.compositeEditor.getSize(),
validCompositeMaterials: _.difference(materials.getAllCompositeKeys(), compositeParents)
});
},
template: _.template(template)
});
});
\ No newline at end of file
......@@ -104,9 +104,9 @@ define(['underscore', 'fileSaverLib', 'lattice', 'materials', 'ribbon', 'menuWra
return;
}
lattice.clearCells();
var sparseCells = data.assembly.sparseCells;
_setData(lattice, _.omit(data.assembly, "sparseCells"));
if (sparseCells) lattice.setSparseCells(sparseCells);
var cells = data.assembly.cells;
_setData(lattice, _.omit(data.assembly, "cells"));
if (cells) lattice.setSparseCells(cells);
ribbon.render();
menuWrapper.render();
if (data.emSim){
......
......@@ -207,7 +207,7 @@ define(['backbone', 'underscore', 'lattice', 'three', 'threeModel', 'globals', '
},
cellAtIndex: function(relIndex){
return lattice.getSparseCellAtIndex(this.get("min").clone().add(relIndex));
return lattice.getCellAtIndex(this.get("min").clone().add(relIndex));
},
finish: function(){
......
Markdown is supported
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