Gitlab CSE Unil

Commit 7c0eeae6 authored by M. Chardon's avatar M. Chardon
Browse files

maj bug mantis 230

parent e83e6dc7
......@@ -35,33 +35,33 @@ define([
"adim/category",
"env/shortcuts"
],
function($, _, paper, Signal, config, view, attributes, io, tools, ui, category, shortcuts){
function ($, _, paper, Signal, config, view, attributes, io, tools, ui, category, shortcuts) {
/**
* Signal binding specific to anodate environment
* @private
*/
function _initSignalRouting(){
function _initSignalRouting() {
console.info("_initSignalRouting from env/geomo");
io.events.annotableLoaded.add(function(annotableData){
io.events.annotableLoaded.add(function (annotableData) {
// p.raster is a paper.Raster
view.events.annotationRemoved.add(function(annotation){
view.events.annotationRemoved.add(function (annotation) {
/*if (annotation.data.type === 'rectanglegeo') {
}*/
});
view.events.imageLoaded.add(function(p){
view.events.imageLoaded.add(function (p) {
// Here we initilize tools that needs some image properties
});
}, 100);
// called after all other handlers
view.events.annotationsLoaded.add(function() {
view.events.annotationsLoaded.add(function () {
}, -100);
ui.events.modeChanged.add(function(opts) {
ui.events.modeChanged.add(function (opts) {
var mode = opts.mode;
if (mode === 'edit') {
$("#annotation-display-panel").hide();
......@@ -80,11 +80,11 @@ define([
* @private
*/
function _initUI(params) {
category.init({'env':env.name});
category.init({'env': env.name});
// Init Type Display Selector
$(".adim-display-type-selector").find("button").on('click', function(event) {
$(".adim-display-type-selector").find("button").on('click', function (event) {
var $but = $(this);
var activate = !$but.hasClass("active");
var category = $but.data('category');
......@@ -114,18 +114,20 @@ define([
function displayAltCol(show) {
//sideCol.toggleClass("col-sm-1", !show)
// .toggleClass("col-sm-2", show);
// .toggleClass("col-sm-2", show);
altSideColPanelGroup.toggleClass("hidden", !show);
sideColPanelGroup.toggleClass("col-xs-12", !show)
.toggleClass("col-xs-6", show);
.toggleClass("col-xs-6", show);
}
function displayAltColAndLabels(show) {
displayAltCol(show && sharedAnnotationMarkersPanel.find(".panel-collapse").hasClass("in"));
sharedAnnotationMarkersPanel.toggleClass("hidden", !show);
}
displayAltColAndLabels(params.mode === 'review');
ui.events.modeChanged.add(function(opts) {
ui.events.modeChanged.add(function (opts) {
var mode = opts.mode;
displayAltColAndLabels(mode === 'review');
ui.updateReservedSpace();
......@@ -151,7 +153,6 @@ define([
}
/**
* Define initial strokeColor from the forth color of the current color palette.
* This has to be define as a getter function as we cannot compute the color before
......@@ -173,4 +174,4 @@ define([
Object.defineProperty(env, 'style', {get: _getStyle});
return env;
});
\ No newline at end of file
});
\ No newline at end of file
......@@ -20,200 +20,202 @@
*/
define([
"underscore",
"signals",
// ----- The tools
"tools/select",
"tools/pan",
"tools/drawing",
"tools/lines",
"tools/ellipse",
"tools/rectangle",
"tools/text",
"tools/arrow",
// ----- CIMAF specific tools
"tools/fieldedges",
"tools/concordantstr",
"tools/discordantstr",
"tools/cmsarea",
// ----- ANODATE tool
"tools/marker",
// ----- GEOMO tool
"tools/drawinggeo",
"tools/linesgeo",
"tools/ellipsegeo",
"tools/rectanglegeo",
"tools/arrowgeo",
"tools/textgeo"
],
function(_, Signal){
// ----- Locale variables -----------------------------
var _tools = {}, // A dictionary of the active tools, using the name as key
_activeTool = null, // The name of the current active tool
_ro = null, // Local ReadOnly value
_noop = function(){}; // A no-op function;
var _events = {
activated: new Signal(),
annotationAdded: new Signal(),
annotationChanged: new Signal(),
annotationSelected: new Signal(),
annotationCheckCancel: new Signal()
};
// ----- Initialisations ------------------------------
function defaultImportJson(jsonStr, layer) {
return layer.importJSON(jsonStr);
}
function defaultExportJson(p) {
return this.exportJSON(p);
}
// Store the tools in the dictionary, the tools are passed as arguments to the function
for (var i=1, t; t = arguments[i]; i++) {
_tools[t.name] = {
tool: t.tool,
importJSON: t.importJSON || defaultImportJson,
exportJSON: t.exportJSON || defaultExportJson,
setRo: t.setRo || _noop,
listeners: t.listeners || {},
events: t.events || {}
"underscore",
"signals",
// ----- The tools
"tools/select",
"tools/pan",
"tools/drawing",
"tools/lines",
"tools/ellipse",
"tools/rectangle",
"tools/text",
"tools/arrow",
// ----- CIMAF specific tools
"tools/fieldedges",
"tools/concordantstr",
"tools/discordantstr",
"tools/cmsarea",
// ----- ANODATE tool
"tools/marker",
// ----- GEOMO tool
"tools/drawinggeo",
"tools/linesgeo",
"tools/ellipsegeo",
"tools/rectanglegeo",
"tools/arrowgeo",
"tools/textgeo"
],
function (_, Signal) {
// ----- Locale variables -----------------------------
var _tools = {}, // A dictionary of the active tools, using the name as key
_activeTool = null, // The name of the current active tool
_ro = null, // Local ReadOnly value
_noop = function () {
}; // A no-op function;
var _events = {
activated: new Signal(),
annotationAdded: new Signal(),
annotationChanged: new Signal(),
annotationSelected: new Signal(),
annotationCheckCancel: new Signal()
};
// Register annotationAdded event
if (typeof t.registerEvent === 'function') {
t.registerEvent('annotationAdded', _events.annotationAdded);
t.registerEvent('annotationChanged', _events.annotationChanged);
t.registerEvent('annotationSelected', _events.annotationSelected);
// ----- Initialisations ------------------------------
function defaultImportJson(jsonStr, layer) {
return layer.importJSON(jsonStr);
}
// If the tool define a listener for the 'activated' event, add it to the corresponding signal controller
if (t.listeners && typeof t.listeners.onToolActivated === 'function') {
_events.activated.add(t.listeners.onToolActivated);
function defaultExportJson(p) {
return this.exportJSON(p);
}
}
(function buildNoopTool() {
var noopTool = new paper.Tool({
onMouseDown: _noop,
onMouseUp: _noop,
onMouseDrag: _noop,
onKeyDown: _noop,
// Store the tools in the dictionary, the tools are passed as arguments to the function
for (var i = 1, t; t = arguments[i]; i++) {
_tools[t.name] = {
tool: t.tool,
importJSON: t.importJSON || defaultImportJson,
exportJSON: t.exportJSON || defaultExportJson,
setRo: t.setRo || _noop,
listeners: t.listeners || {},
events: t.events || {}
};
// Register annotationAdded event
if (typeof t.registerEvent === 'function') {
t.registerEvent('annotationAdded', _events.annotationAdded);
t.registerEvent('annotationChanged', _events.annotationChanged);
t.registerEvent('annotationSelected', _events.annotationSelected);
}
// If the tool define a listener for the 'activated' event, add it to the corresponding signal controller
if (t.listeners && typeof t.listeners.onToolActivated === 'function') {
_events.activated.add(t.listeners.onToolActivated);
}
}
(function buildNoopTool() {
var noopTool = new paper.Tool({
onMouseDown: _noop,
onMouseUp: _noop,
onMouseDrag: _noop,
onKeyDown: _noop,
onKeyUp: _noop
});
noopTool.activate();
})();
// ----- Functions ------------------------------------
/**
* Getter, return the name of the currently active tool
* @returns {*}
*/
function getActiveTool() {
return _activeTool;
}
/**
* Getter, return a tool by it's name
*
* @param toolName
* @returns {*}
*/
function getTool(toolName) {
return _tools[toolName] ? _tools[toolName].tool : null;
}
/**
* Activate a tool given by it's name
* @param toolName
*
*/
function activateTool(toolName) {
if (!toolName || !_tools[toolName]) { return }
var oldTool = getTool(_activeTool);
if(oldTool){
_events.annotationCheckCancel.dispatch(oldTool);
});
noopTool.activate();
})();
// ----- Functions ------------------------------------
/**
* Getter, return the name of the currently active tool
* @returns {*}
*/
function getActiveTool() {
return _activeTool;
}
/**
* Getter, return a tool by it's name
*
* @param toolName
* @returns {*}
*/
function getTool(toolName) {
return _tools[toolName] ? _tools[toolName].tool : null;
}
/**
* Activate a tool given by it's name
* @param toolName
*
*/
function activateTool(toolName) {
if (!toolName || !_tools[toolName]) {
return
}
var oldTool = getTool(_activeTool);
if (oldTool) {
_events.annotationCheckCancel.dispatch(oldTool);
}
var theTool = getTool(toolName);
if (theTool) {
_activeTool = toolName;
theTool.activate();
// Dispatch the 'activated' event
_events.activated.dispatch(toolName);
} else {
console && console.warn && console.warn("Tool «" + toolName + "» not activated");
}
}
var theTool = getTool(toolName);
if (theTool) {
_activeTool = toolName;
theTool.activate();
// Dispatch the 'activated' event
_events.activated.dispatch(toolName);
} else {
console && console.warn && console.warn("Tool «" + toolName + "» not activated");
/**
* Return a function used to import a serialized item for the tool
* given by it's name
* If a tool cannot be found, return a noop function
*
* @param toolName
* @returns {importJSON}
*/
function getToolJSONImporter(toolName) {
return (_tools[toolName] && typeof _tools[toolName].importJSON === 'function')
? _tools[toolName].importJSON
: _noop
}
}
/**
* Return a function used to import a serialized item for the tool
* given by it's name
* If a tool cannot be found, return a noop function
*
* @param toolName
* @returns {importJSON}
*/
function getToolJSONImporter(toolName) {
return (_tools[toolName] && typeof _tools[toolName].importJSON === 'function')
? _tools[toolName].importJSON
: _noop
}
/**
* Return a function used to serialize item from the tool
* given by it's name
* If a tool cannot be found, return a noop function
*
* @param toolName
* @returns {exportJSON}
*/
function getToolJSONExporter(toolName) {
return (_tools[toolName] && typeof _tools[toolName].exportJSON === 'function')
? _tools[toolName].exportJSON
: _noop
}
function serializeItem(item, param) {
var exporter = getToolJSONExporter(item.data.type);
return exporter.call(item, $.extend({asString:true},param) );
}
/**
* Set ReadOnly state for all tools
* @param {boolean} ro - The ReadOnly value, true == ReadOnly or false == Writable
*/
function setRo(ro) {
if (ro === _ro) {
return;
/**
* Return a function used to serialize item from the tool
* given by it's name
* If a tool cannot be found, return a noop function
*
* @param toolName
* @returns {exportJSON}
*/
function getToolJSONExporter(toolName) {
return (_tools[toolName] && typeof _tools[toolName].exportJSON === 'function')
? _tools[toolName].exportJSON
: _noop
}
_ro = ro;
_.invoke(_tools, 'setRo', ro);
}
// ----- Returned Module ------------------------------
return {
events: _events,
tools: _tools,
getTool: getTool,
getToolJSONImporter: getToolJSONImporter,
getToolJSONExporter: getToolJSONExporter,
activateTool: activateTool,
getActiveTool: getActiveTool,
serializeItem: serializeItem,
setRo: setRo
};
});
function serializeItem(item, param) {
var exporter = getToolJSONExporter(item.data.type);
return exporter.call(item, $.extend({asString: true}, param));
}
/**
* Set ReadOnly state for all tools
* @param {boolean} ro - The ReadOnly value, true == ReadOnly or false == Writable
*/
function setRo(ro) {
if (ro === _ro) {
return;
}
_ro = ro;
_.invoke(_tools, 'setRo', ro);
}
// ----- Returned Module ------------------------------
return {
events: _events,
tools: _tools,
getTool: getTool,
getToolJSONImporter: getToolJSONImporter,
getToolJSONExporter: getToolJSONExporter,
activateTool: activateTool,
getActiveTool: getActiveTool,
serializeItem: serializeItem,
setRo: setRo
};
});
......@@ -113,7 +113,7 @@ define(["paper"], function (paper) {
new paper.Segment([20, -5])
],
strokeJoin: 'round',
strokeScaling: false,
strokeScaling: true,
closed: true
});
_arrowLeftMostPt = 1;
......
......@@ -18,7 +18,8 @@
*
*/
define(["paper", "tools/Shape.class","adim/category"], function (paper,Shape, Category) {
define(["paper", "tools/Shape.class", "adim/category"], function (paper, Shape, Category) {
// ----- Const ----------------------------------------
var TOOL_TYPE = 'arrowgeo';
var _ro = false;
......@@ -39,17 +40,17 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper,Shape, Ca
fill: true
};
var _transparent = new paper.Color([0,0,0,0]);
var _transparent = new paper.Color([0, 0, 0, 0]);
// ----- Serialization ---------------------------------
function exportJSON(param) {
var json = this.exportJSON({asString:false});
var json = this.exportJSON({asString: false});
try {
json[1][1].data.from = [this.data.from.x, this.data.from.y];
json[1][1].data.to = [this.data.to.x, this.data.to.y];
} catch(e) {
} catch (e) {
console.error(e);
}
......@@ -73,7 +74,7 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper,Shape, Ca
var newArrow = createNewArrow({
from: new paper.Point(item.data.from),
prop: item.data.prop,
scale: item.data.scale || {h:1, v:1}
scale: item.data.scale || {h: 1, v: 1}
}, listening);
newArrow.opacity = opacity;
......@@ -87,6 +88,7 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper,Shape, Ca
});
curLayer.activate();
return newArrow;
}
......@@ -97,6 +99,7 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper,Shape, Ca
_arrowHeadLeftMostPt,
_arrowRightMostPt,
_arrowMinLength;
function initArrowSymbol() {
if (_arrowSymbol)
return;
......@@ -104,15 +107,15 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper,Shape, Ca
var defPath = new paper.Path({
segments: [
[0, -5],
[0 , 5],
[0, 5],
new paper.Segment([20, 5]),
[10, 30],
new paper.Segment([50, 0]),
new paper.Segment([50, 0]),
[10, -30],
new paper.Segment([20, -5])
],
strokeJoin: 'round',
strokeScaling: false,
strokeScaling: true,
closed: true
});
_arrowLeftMostPt = 1;
......@@ -152,14 +155,14 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper,Shape, Ca
* @returns {M.PlacedSymbol}
*/
function createNewArrow(params, eventListening) {
var newArrow, width, from ,to, scale;
var newArrow, width, from, to, scale;
initArrowSymbol();
newArrow = new paper.PlacedSymbol(_arrowSymbol.clone());
width = newArrow.symbol.definition.bounds.width;
from = new paper.Point(params.from);
to = new paper.Point([from.x + width, from.y]);
scale = params.scale || {h:1, v:1};
scale = params.scale || {h: 1, v: 1};
// Extend tool's item properties with default values
params.prop = (typeof params.prop === 'object') ? params.prop : {};
......@@ -168,10 +171,9 @@ define(["paper", "tools/Shape.class","adim/category"], function (paper,Shape, Ca
params.prop[p] = defaultProperties[p];
}
newArrow.pivot = [-width/2, 0];
newArrow.pivot = [-width / 2, 0];
drawArrow(newArrow, {from: from, to: to});
_scaleArrow.call(newArrow, scale);
console.log(params.prop.fill +' - '+_getColorBg(params.prop.category) +" - "+_getColor(params.prop.category));
_setFill.call(newArrow, params.prop.fill, _getColorBg(params.prop.category));