client/js/renderer/scene.js
changeset 537 88703fb5aaaf
parent 534 c25e7c9e26a0
child 541 05ad3a6f58e5
equal deleted inserted replaced
536:a18716c2c4c0 537:88703fb5aaaf
   290         };
   290         };
   291 
   291 
   292         var _thRedraw = _.throttle(function() {
   292         var _thRedraw = _.throttle(function() {
   293             _this.redraw();
   293             _this.redraw();
   294         },50);
   294         },50);
   295            
   295 
   296         this.addRepresentations("Node", this.renkan.project.get("nodes"));
   296         this.addRepresentations("Node", this.renkan.project.get("nodes"));
   297         this.addRepresentations("Edge", this.renkan.project.get("edges"));
   297         this.addRepresentations("Edge", this.renkan.project.get("edges"));
   298         this.renkan.project.on("change:title", function() {
   298         this.renkan.project.on("change:title", function() {
   299             _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title"));
   299             _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title"));
   300         });
   300         });
   374                 }
   374                 }
   375             } else {
   375             } else {
   376                 el.text(_title);
   376                 el.text(_title);
   377             }
   377             }
   378         });
   378         });
   379         
   379 
   380         //register router events
   380         //register router events
       
   381         console.log("Register view parameters");
   381         this.renkan.router.on("router", function(_params){
   382         this.renkan.router.on("router", function(_params){
   382             _this.parameters(_params);
   383             _this.setViewparameters(_params);
   383         });
   384         });
   384 
   385 
   385         if (_renkan.options.size_bug_fix) {
   386         if (_renkan.options.size_bug_fix) {
   386             var _delay = (
   387             var _delay = (
   387                     typeof _renkan.options.size_bug_fix === "number" ?
   388                     typeof _renkan.options.size_bug_fix === "number" ?
   684         },
   685         },
   685         addRepresentation: function(_type, _model) {
   686         addRepresentation: function(_type, _model) {
   686             var RendererType = requtils.getRenderer()[_type];
   687             var RendererType = requtils.getRenderer()[_type];
   687             var _repr = new RendererType(this, _model);
   688             var _repr = new RendererType(this, _model);
   688             this.representations.push(_repr);
   689             this.representations.push(_repr);
   689             return _repr;                
   690             return _repr;
   690         },
   691         },
   691         addRepresentations: function(_type, _collection) {
   692         addRepresentations: function(_type, _collection) {
   692             var _this = this;
   693             var _this = this;
   693             _collection.forEach(function(_model) {
   694             _collection.forEach(function(_model) {
   694                 _this.addRepresentation(_type, _model);
   695                 _this.addRepresentation(_type, _model);
  1199           var projectJSONStr = JSON.stringify(projectJSON, null, 2);
  1200           var projectJSONStr = JSON.stringify(projectJSON, null, 2);
  1200           var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"});
  1201           var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"});
  1201           filesaver(blob,fileNameToSaveAs);
  1202           filesaver(blob,fileNameToSaveAs);
  1202 
  1203 
  1203         },
  1204         },
  1204         parameters: function(_params){
  1205         setViewparameters: function(_params){
  1205             this.removeRepresentationsOfType("View");
  1206             this.removeRepresentationsOfType("View");
  1206             if ($.isEmptyObject(_params)){
  1207             if ($.isEmptyObject(_params)){
  1207                 this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view)));
  1208                 this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view)));
  1208                 if (!this.renkan.options.default_view){
  1209                 if (!this.renkan.options.default_view){
  1209                     this.view.autoScale();
  1210                     this.view.autoScale();
  1229                 if (this.view){
  1230                 if (this.view){
  1230                     this.view.setScale(params.zoom_level, new paper.Point(params.offset));
  1231                     this.view.setScale(params.zoom_level, new paper.Point(params.offset));
  1231                 } else{
  1232                 } else{
  1232                     this.view = this.addRepresentation("View", null);
  1233                     this.view = this.addRepresentation("View", null);
  1233                     this.view.params = params;
  1234                     this.view.params = params;
  1234                     this.view.init();                    
  1235                     this.view.init();
  1235                 }
  1236                 }
  1236             }
  1237             }
  1237             if (!this.view){
  1238             if (!this.view){
  1238                 this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view)));
  1239                 this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view)));
  1239                 this.view.autoScale();
  1240                 this.view.autoScale();
  1240             }
  1241             }
  1241             //other parameters must go after because most of them depends on a view that must be initialize before
  1242             //other parameters must go after because most of them depends on a view that must be initialize before
  1242             this.unhighlightAll();
  1243             this.unhighlightAll();
  1243             if (typeof _params.idNode !== 'undefined'){
  1244             if (typeof _params.idNode !== 'undefined'){
  1244                 this.highlightModel(this.renkan.project.get("nodes").get(_params.idNode));                 
  1245                 this.highlightModel(this.renkan.project.get("nodes").get(_params.idNode));
  1245             }
  1246             }
  1246         },
  1247         },
  1247         validViewIndex: function(index){
  1248         validViewIndex: function(index){
  1248             //check if the view index exist (negative index is from the end) and return the correct index or false if doesn't exist
  1249             //check if the view index exist (negative index is from the end) and return the correct index or false if doesn't exist
  1249             var _index = parseInt(index);
  1250             var _index = parseInt(index);
  1250             var validIndex = 0;
  1251             var validIndex = 0;
  1251             if (_index < 0){
  1252             if (_index < 0){
  1252                 validIndex = this.renkan.project.get("views").length + _index;
  1253                 validIndex = this.renkan.project.get("views").length + _index;
  1253             } else {
  1254             } else {
  1254                 validIndex = _index; 
  1255                 validIndex = _index;
  1255             }
  1256             }
  1256             if (typeof this.renkan.project.get("views").at(_index) === 'undefined'){
  1257             if (typeof this.renkan.project.get("views").at(_index) === 'undefined'){
  1257                 validIndex = 0;
  1258                 validIndex = 0;
  1258             }
  1259             }
  1259             return validIndex;
  1260             return validIndex;