Skip to content
Snippets Groups Projects
Commit e6185865 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when clicking on compartment border compartment is highlighted

parent 3364e660
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!513Resolve "Compartment annotation"
Pipeline #7523 passed
......@@ -3,6 +3,7 @@
/* exported logger */
var logger = require('../../logger');
var Functions = require('../../Functions');
var Promise = require("bluebird");
......@@ -11,6 +12,7 @@ var Alias = require('../data/Alias');
var ConfigurationType = require('../../ConfigurationType');
var IdentifiedElement = require('../data/IdentifiedElement');
var InvalidArgumentException = require('../../InvalidArgumentError');
var Point = require('../canvas/Point');
var Reaction = require('../data/Reaction');
var SearchBioEntityGroup = require('../data/SearchBioEntityGroup');
......@@ -92,14 +94,45 @@ SearchDbOverlay.prototype.getElementsByQuery = function (query) {
});
};
/**
*
* @param {Point} coordinates
* @param {IdentifiedElement} compartment
* @param {number} maxDistance
* @returns {Promise}
* @private
*/
SearchDbOverlay.prototype._returnCompartmentIfClickOnBorder = function (coordinates, compartment, maxDistance) {
var model = this.getMap().getSubmapById(compartment.getModelId()).getModel();
return model.getByIdentifiedElement(compartment).then(function (result) {
var p1 = new Point(result.getX(), result.getY());
var p2 = new Point(result.getX() + result.getWidth(), result.getY());
var p3 = new Point(result.getX() + result.getWidth(), result.getY() + result.getHeight());
var p4 = new Point(result.getX(), result.getY() + result.getHeight());
var distance = Functions.distance(coordinates, {start: p1, end: p2});
distance = Math.min(distance, Functions.distance(coordinates, {start: p2, end: p3}));
distance = Math.min(distance, Functions.distance(coordinates, {start: p3, end: p4}));
distance = Math.min(distance, Functions.distance(coordinates, {start: p4, end: p1}));
if (maxDistance>distance) {
return compartment;
} else {
return undefined;
}
});
};
/**
*
* @param {IdentifiedElement} identifiedElement
* @param {number} zoomLevel
* @param {Point} coordinates
* @returns {Promise}
* @private
*/
SearchDbOverlay.prototype._getFirstVisibleParentOrObject = function (identifiedElement, zoomLevel) {
SearchDbOverlay.prototype._getFirstVisibleParentOrObject = function (identifiedElement, zoomLevel, coordinates) {
if (identifiedElement === undefined) {
return Promise.resolve();
}
......@@ -110,7 +143,8 @@ SearchDbOverlay.prototype._getFirstVisibleParentOrObject = function (identifiedE
if (fullElement instanceof Alias) {
//transparent compartments shouldn't be clickable
if (fullElement.getTransparencyLevel() <= zoomLevel && fullElement.getType() === "Compartment") {
return undefined;
var maxDistance = self.computeMaxDistance(model, zoomLevel);
return self._returnCompartmentIfClickOnBorder(coordinates, identifiedElement, maxDistance);
}
}
return identifiedElement;
......@@ -129,7 +163,7 @@ SearchDbOverlay.prototype._getFirstVisibleParentOrObject = function (identifiedE
type: "ALIAS",
modelId: identifiedElement.getModelId()
});
return self._getFirstVisibleParentOrObject(parent, zoomLevel);
return self._getFirstVisibleParentOrObject(parent, zoomLevel, coordinates);
} else {
logger.warn("Cannot find visible parent for object. (zoomLevel=" + zoomLevel + ")");
logger.warn(fullElement);
......@@ -155,6 +189,35 @@ SearchDbOverlay.prototype.computeMaxDistance = function (model, zoom) {
return distance;
};
/**
*
* @param {Point} coordinates
* @param {number} zoom
* @param {MapModel} model
* @param {number} maxDistance
* @returns {PromiseLike<T | never> | Promise<T | never>}
*/
SearchDbOverlay.prototype.findCompartmentByCoordinates = function (coordinates, zoom, model, maxDistance) {
var self = this;
return ServerConnector.getClosestElementsByCoordinates({
modelId: model.getId(),
coordinates: coordinates,
count: 1,
type: ["Compartment"]
}).then(function (elements) {
var nestedOverlay = "Pathways and compartments";
if (elements.length === 0) {
return undefined;
} else {
if (self.getMap().getBackgroundDataOverlay().getName() === nestedOverlay) {
return self._getFirstVisibleParentOrObject(elements[0], zoom - model.getMinZoom(), coordinates);
} else {
return self._returnCompartmentIfClickOnBorder(coordinates, elements[0], maxDistance);
}
}
});
};
/**
*
* @param {Object} params
......@@ -201,7 +264,7 @@ SearchDbOverlay.prototype.searchByCoordinates = function (params) {
return undefined;
} else {
if (self.getMap().getBackgroundDataOverlay().getName() === nestedOverlay) {
return self._getFirstVisibleParentOrObject(elements[0], zoom - model.getMinZoom());
return self._getFirstVisibleParentOrObject(elements[0], zoom - model.getMinZoom(), coordinates);
} else {
return elements[0];
}
......@@ -234,23 +297,7 @@ SearchDbOverlay.prototype.searchByCoordinates = function (params) {
if (distance <= maxDistance) {
self._elementsByQuery[query] = searchResult;
} else {
return ServerConnector.getClosestElementsByCoordinates({
modelId: modelId,
coordinates: coordinates,
count: 1,
type: ["Compartment"]
}).then(function (elements) {
var nestedOverlay = "Pathways and compartments";
if (elements.length === 0) {
return undefined;
} else {
if (self.getMap().getBackgroundDataOverlay().getName() === nestedOverlay) {
return self._getFirstVisibleParentOrObject(elements[0], zoom - model.getMinZoom());
} else {
return undefined;
}
}
}).then(function (visibleObject) {
return self.findCompartmentByCoordinates(coordinates, zoom, model, maxDistance).then(function (visibleObject) {
if (visibleObject !== undefined) {
self._elementsByQuery[query] = [visibleObject];
} else {
......
......@@ -462,7 +462,7 @@ Helper.prototype.createAbstractCustomMap = function () {
/**
*
* @param project
* @param {Project} [project]
* @returns {CustomMap}
*/
Helper.prototype.createCustomMap = function (project) {
......
t"use strict";
"use strict";
var logger = require('../../logger');
require("../../mocha-config");
......@@ -153,6 +153,28 @@ describe('SearchDbOverlay', function () {
});
});
it("on compartment border", function () {
helper.setUrl("http://test/?id=complex_model_with_submaps");
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
return map.openDataOverlay(14961);
}).then(function () {
var searchDb = helper.createSearchDbOverlay(map);
var searchParams = {
modelId: map.getModel().getId(),
coordinates: new Point(104.36, 182.81),
zoom: 4
};
return searchDb.searchByCoordinates(searchParams);
}).then(function (result) {
assert.equal(result.length, 1);
});
});
it("on hidden nested object", function () {
return ServerConnector.getProject().then(function (project) {
......@@ -242,4 +264,5 @@ describe('SearchDbOverlay', function () {
});
});
})
;
[{"id":345331,"modelId":16728,"type":"ALIAS"}]
\ No newline at end of file
[{"id":345323,"modelId":16728,"type":"ALIAS"}]
\ No newline at end of file
[{"bounds":{"height":142.0,"width":144.0,"x":35.0,"y":45.0},"id":345323,"linkedSubmodel":null,"modelId":16728}]
\ No newline at end of file
[{"abbreviation":null,"boundaryCondition":null,"bounds":{"height":142.0,"width":144.0,"x":35.0,"y":45.0},"compartmentId":null,"complexId":null,"constant":null,"elementId":"ca1","formerSymbols":[],"formula":null,"fullName":null,"hierarchyVisibilityLevel":"0","id":345323,"initialAmount":null,"initialConcentration":null,"linkedSubmodel":null,"modelId":16728,"name":"c1","notes":"","other":{"modifications":[],"structuralState":null,"structures":{}},"references":[],"symbol":null,"synonyms":[],"transparencyLevel":"2","type":"Compartment"}]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment