Gitlab CSE Unil

Commit 977e011e authored by M. Chardon's avatar M. Chardon
Browse files

nettoyage divers

parent 6ac3fb35
......@@ -22,9 +22,7 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
// Properties
var defaultProperties = {
comment: "",
//labelComment: "",
category: "cat_geo_1",
remplissage: 1,
fill:true
};
......@@ -42,15 +40,13 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
function exportJSON(param) {
var json = this.exportJSON({asString:false});
// Apply some cleanup
//json[1].data.origin.splice(0,1);
return (param && param.asString) ? JSON.stringify(json) : json;
}
function importJSON(itemDef, layer, listening) {
// Sanitize data
var item = itemDef[1];
var itemData = itemDef[1].data;
var itemData = item.data;
var curLayer = paper.project.activeLayer;
layer.activate();
......@@ -75,7 +71,7 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
// ----- Item -----------------------------------------
function createRectangleGeo(origin, config, eventListening) {
var newRecGeo = new paper.Path.Rectangle(origin); //Shape("rectangle", _events);
var newRecGeo = new paper.Path.Rectangle(origin);
// Extend tool's item properties with default values
var properties = (config && typeof config.prop === 'object') ? config.prop : {};
......@@ -83,7 +79,6 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
if (!properties.hasOwnProperty(p))
properties[p] = defaultProperties[p];
}
//newRecGeo.style = confidenceStyle[o.prop.confidence];
newRecGeo.data = {
tId: "a" + newRecGeo._id,
......@@ -93,6 +88,7 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
prop: properties,
setCategory: _setCategory,
getColorBgD: _getColorBgD,
origin: origin,
......@@ -100,26 +96,10 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
itemMouseDrag: itemMouseDrag,
itemMouseUp: itemMouseUp,
itemMouseDown: itemMouseDown,
// General attributes handlers
//setColor: _noop, //_setColor,
//getColor: _noop, //_getColor,
//setFill: _noop,
//setStrokeWidth: _setStrokeWidth,
//getStrokeWidth: _getStrokeWidth,
getColorBgD: _getColorBgD
};
// Add event listeners
//if (eventListening) {
// newRecGeo.onMouseDown = itemMouseDown;
// newRecGeo.itemMouseDrag = itemMouseDrag;
//newRecGeo.onKeyDown = itemKeyDown;
//}
newRecGeo.onMouseDown = itemMouseDown;
newRecGeo.itemMouseDrag = itemMouseDrag;
newRecGeo.onMouseDown = itemMouseDown;
newRecGeo.itemMouseDrag = itemMouseDrag;
newRecGeo.onPropertyChange = itemPropertyChange;
newRecGeo.style = {
......@@ -133,43 +113,16 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
newRecGeo._boundsSelected = true;
return newRecGeo;
//marker._boundsSelected = true;
//marker._selectChildren = false;
/*if (eventListening) {
marker.onPropertyChange = itemPropertyChange;
marker.onMouseDown = itemMouseDown;
}*/
//drawMarker(marker);
// Add the marker to the list of markers. Only if in editing mode.
/*if (eventListening) {
_.some(_markers, function (m, idx) {
if (label < m.data.label) {
_markers.splice(idx, 0, marker);
return true;
}
return false;
}) || _markers.push(marker);
}*/
//return marker;
}
function drawRecGeo(rectgeo, event) {
// data passed in prop obj
prop = /*prop ||*/ {};
if (rectgeo.data) {
var category = rectgeo.data.prop.category || 'default';
var remplissage = rectgeo.data.prop.remplissage || 1;
var fill = rectgeo.data.prop.fill || "checked";
} else {
var category = 'default';
var remplissage = 1;
var fill = "checked";
}
......@@ -178,9 +131,9 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
var colorbg = cat && cat.colorbg ||"grey";
if (!_drawingLine) {
_drawingLine = new paper.Path.Rectangle(_startPoint, event.point); //Shape("rectangle", _events); //new paper.Path.Line({from: _startPoint, to: event.point});
_drawingLine = new paper.Path.Rectangle(_startPoint, event.point);
if (fill == "checked") {
drawingLine.fillColor = colorbg;
_drawingLine.fillColor = colorbg;
}
_drawingLine.color=color;
}
......@@ -192,10 +145,6 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
}
function _terminateCreate(event) {
//var dstPoint = _drawingLine ? _drawingLine.segments[1].point.clone() : null;
/*if (!validatePosition(_startPoint, dstPoint))
return;
*/
if (_drawingLine) {
_drawingLine.remove();
_drawingLine = null;
......@@ -207,20 +156,6 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
create = false;
}
/* function itemMouseUp(event) {
if (!event.tool) // catches only tool's events
return;
if (_editedRecGeo) {
if (_recGeoChanged) {
_events.annotationChanged.dispatch([_editedRecGeo]);
_recGeoChanged = false;
}
}
_editedSegmentIdx = _editedStriaLeftIdx = _editedStriaRightIdx = _editedRecGeo = _editedSegmentXLimit = null;
}*/
function itemMouseDown(event) {
var hitItem = this;
_editedRecGeo = this;
......@@ -231,40 +166,22 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
hitItem.selected = true;
_events.annotationSelected.dispatch(hitItem);
console.log("tutu");
_editedSegmentIdx = null;
console.log(hitResult);
if (hitResult) {
console.log(hitResult.type);
}
if (hitResult && hitResult.type === 'segment') {
_editedSegmentIdx = hitResult.segment.index;
} else {
}
/*_editedSegmentIdx = _editedStriaLeftIdx = _editedStriaRightIdx = _editedSegmentXLimit = null;
if (hitResult.type === 'segment') {
_editedSegmentIdx = hitResult.segment.index;
_editedSegmentXLimit = _cutPosition + (
(_editedStria.segments[1-_editedSegmentIdx].point.x < _cutPosition ? 1 : -1) * _cutThreshold
);
} else {
_editedStriaLeftIdx = (_editedStria.getFirstSegment().point.x < _cutPosition) ? 0 : 1;
_editedStriaRightIdx = 1 - _editedStriaLeftIdx;
}*/
_redGeoChanged = false;
_recGeoChanged = false;
_events.annotationSelected.dispatch(hitItem);
}
function itemMouseDrag(event) {
console.log("itemmousedrag");
// Handle only event forwarded by tools
if (!event.tool)
return;
if (_editedSegmentIdx !== null) {
console.log(_editedSegmentIdx);
var dstPoint = event.point.clone();
_editedRecGeo.segments[_editedSegmentIdx].point = dstPoint;
var deltaPoint = event.delta
......@@ -294,8 +211,6 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
this.data.origin.to.y += deltaPoint.y;
break;
}
//if (event.event.shiftKey)
// _horizontalize(_editedRecGeo, _editedSegmentIdx);
} else {
this.translate(event.delta);
this.data.origin.from.x += event.delta.x;
......@@ -321,7 +236,7 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
if (property === 'category') {
_setCategory.call(this, value);
this.style = {
fillColor: _getColorBg(value),
fillColor: _getColorBg(value),
strokeColor: _getColor(value)
};
paper.view.draw();
......@@ -335,15 +250,7 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
create = false;
}
/*function validatePosition(from, to){
// A concordant stria should cross the cut
return (from.x <= _cutPosition && to.x >= (_cutPosition + _cutThreshold) ) ||
(from.x >= _cutPosition && to.x <= (_cutPosition - _cutThreshold) );
}*/
// ----- Tool Def -------------------------------------
//var toolDef = new Shape("rectangle", _events);
var toolDef = {
onMouseDown: function(event) {
......@@ -352,7 +259,6 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
_terminateCreate();
}
} else {
var hitResult = paper.project.activeLayer.hitTest(event.point, hitOptions);
if (!hitResult) {
paper.project.deselectAll();
......@@ -370,25 +276,17 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
} else {
hitResult.item.onMouseDown(event);
}
}
},
onMouseDrag: function(event) {
console.info("onMouseDrag");
if (create && _startPoint) {
terminateOnRelease = true;
drawRecGeo(this,event);
_//editedRecGeo = _drawingLine;
}
/*if (_editedRecGeo) {
itemMouseDrag(event);
}*/
},
onMouseMove: function(event) {
console.info("onMouseMove");
if (create && _startPoint) {
drawRecGeo(this,event);
}
......@@ -400,92 +298,24 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
drawRecGeo(this,event);
_terminateCreate(event);
}
}/* else {
if (_editedRecGeo) {
_editedRecGeo.data.itemMouseUp(event);
}
}*/
}
_editedSegmentIdx = _editedRecGeo = null;
},
onKeyDown: function(event) {
//console.log( event.key );
switch (event.key) {
/*case "enter":
if (create)
_terminateCreate(event);
break;*/
case "escape":
if (create)
cancelCreate();
break;
/*case "shift":
if (_drawingLine) {
_horizontalize(_drawingLine, 1);
} else if (_editedRecGeo && _editedSegmentIdx !== null) {
_horizontalize(_editedRecGeo, _editedSegmentIdx);
}
break;*/
/*case "up":
case"down":
var items = paper.project.getSelectedItems();
for (var i=0,item;item=items[i];i++){
if (item.data.type && typeof item.onKeyDown === 'function') {
item.onKeyDown(event);
break;
}
}
break;*/
}
},
/*onKeyUp: function (event) {
//console.log( event.key );
switch (event.key) {
case "shift":
if (_drawingLine) {
_horizontalize(_drawingLine, 1, true);
} else if (_editedRecGeo && _editedSegmentIdx) {
_horizontalize(_editedRecGeo, _editedSegmentIdx, true);
}
break;
case "up":
case"down":
var items = paper.project.getSelectedItems();
for (var i=0,item;item=items[i];i++){
if (item.data.type && typeof item.onKeyUp === 'function') {
item.onKeyUp(event);
break;
}
}
break;
}
}*/
}
};
//var exportJSON = toolDef.exportJSON;
//delete(toolDef.exportJSON);
//var importJSON = toolDef.importJSON;
//delete(toolDef.importJSON);
// ----- Initialisations ------------------------------
// ----- Functions ------------------------------------
function _setCategory(catId) {
var category = Category.getCategory(catId),
color = (category && category.color) || "#000000";
//_setColor.call(this, color);
defaultProperties.category = catId;
}
......@@ -502,9 +332,13 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper, Shape, C
}
function _getColorBgD() {
var category = Category.getCategory(this.prop.category),
color = (category && category.colorbg) || "#000000";
return color;
if (this.prop){
var category = Category.getCategory(this.prop.category),
color = (category && category.colorbg) || "#000000";
return color;
} else {
return "#000000";
}
}
......
......@@ -1525,41 +1525,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
var catBut = this.el.find(".btn-cat.active");
return catBut.length === 1 ? catBut.data('category') : "";
}
},
'remplissage': {
el: "#prop-annot-remplissage",
enable: function(status) {
status = (status !== void(0)) ? !!status : true;
//if (config.mode !== config.MODE_EDIT)
if ((config.mode === 'review') ||
(config.annotable && config.annotable.locked))
status = false;
if (status) {
this.el.removeAttr("disabled");
} else {
this.el.attr("disabled","disabled");
}
this.el.closest(".property-group").toggleClass("disabled", !status);
return this;
},
setValue: function(value) { this.el.val(value); return this; },
getValue: function() { return this.el.val(); },
init: function() {
var me = this;
var intervalId = null;
me.el.on('keyup', function(event) {
if (intervalId)
clearTimeout(intervalId);
intervalId = setTimeout(function(){
updateSelectedItemProp('remplissage');
intervalId = null;
}, 500);
});
}
},
}
};
......
......@@ -11,7 +11,8 @@ import os
import sys
__all__ = ('application', )
_virtualenv_path = "//anaconda/envs/adim"
#_virtualenv_path = "//anaconda/envs/adim"
_virtualenv_path = "/home/kury/PycharmProjects/adim/workspace/adim.env"
_settings_module = "adim_project.settings.local"
_project_settings = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
......
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