Author: Lars Michelsen <[email protected]>
Date: Sat Dec 24 14:50:51 2011 +0100
Committer: Lars Michelsen <[email protected]>
Commit-Date: Sat Dec 24 14:50:51 2011 +0100
Bugfix: Preventing loops in relative coords
---
ChangeLog | 4 ++
TODO | 3 --
share/frontend/nagvis-js/js/edit.js | 53 ++++++++++++++++++++++++++++++++--
3 files changed, 53 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ac30946..77116f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+1.6.3
+Frontend
+ * Bugfix: Preventing loops in relative coords
+
1.6.2
Core
* Switched CRITICAL and UNREACHABLE state weights. CRITICAL now overlaps the
diff --git a/TODO b/TODO
index 9faaf47..88f63c6 100644
--- a/TODO
+++ b/TODO
@@ -5,9 +5,6 @@ Probleme:
Relative Koordinaten:
- Wie funktionieren Linien zu Linien Referenzen? Geht das überhaupt?
- - Loop in relativen Koordinaten erkennen und verhindern
- - In WUI Fehler anzeigen
- - Beim Config Parsen Fehlermeldung erzeugen
- Sidebar Folder auf/zu klappbar
- In Sidebar/Dropdown die aktuelle Map highlighten
diff --git a/share/frontend/nagvis-js/js/edit.js
b/share/frontend/nagvis-js/js/edit.js
index 9a0b92c..1218768 100644
--- a/share/frontend/nagvis-js/js/edit.js
+++ b/share/frontend/nagvis-js/js/edit.js
@@ -156,6 +156,9 @@ function makeDragable(objects, dragStopHandler,
dragMoveHandler) {
len = null;
}
+/**
+ * This function is called once an object is picked for dragging
+ */
function dragStart(event) {
if(!event)
event = window.event;
@@ -207,6 +210,9 @@ function dragStart(event) {
return true;
}
+/**
+ * This function is called repeated while the object is being dragged
+ */
function dragObject(event) {
if(!event)
event = window.event;
@@ -241,9 +247,12 @@ function dragObject(event) {
// when dropping the object the currently moved object will be positioned
// relative to this object.
if(event.ctrlKey) {
+ // Unhighlight all other objects
for(var i in oMapObjects)
oMapObjects[i].highlight(false);
- var o = getNearestObject(draggingObject.id, newLeft, newTop)
+
+ // Find the nearest object to the current position and highlight it
+ var o = getNearestObject(draggingObject, newLeft, newTop)
if(o) {
o.highlight(true);
o = null;
@@ -256,7 +265,12 @@ function dragObject(event) {
oParent = null;
}
-function getNearestObject(id, x, y) {
+/**
+ * Is called to find the nearest object to the given position. This must
+ * check if there is a direct or indirect reference to the current object
+ * in order to prevent relative coordinate loops.
+ */
+function getNearestObject(draggingObject, x, y) {
var nearest = null;
var min = null;
var dist;
@@ -266,7 +280,7 @@ function getNearestObject(id, x, y) {
obj = oMapObjects[i];
// Skip own object
- if(id.split('-')[0] == obj.conf.object_id)
+ if(draggingObject.id.split('-')[0] == obj.conf.object_id)
continue;
// FIXME: Also handle lines
@@ -277,6 +291,10 @@ function getNearestObject(id, x, y) {
var objY = obj.parseCoord(obj.conf.y, 'y');
dist = Math.sqrt(((objX - x) * (objX - x)) + ((objY - y) * (objY -
y)));
if(min === null || dist < min) {
+ // Got a nearer one. Ok. But does it have a reference to us?
+ if(coordsReferTo(obj, draggingObject.id.split('-')[0])) {
+ continue;
+ }
min = dist;
nearest = obj;
}
@@ -288,6 +306,33 @@ function getNearestObject(id, x, y) {
return nearest;
}
+/**
+ * This function checks wether or not the source object coords refert to
+ * the target object directly or indirectly
+ */
+function coordsReferTo(obj, target_object_id) {
+ eventlog("edit", "info", "Parent: " + obj.conf.object_id);
+ if (obj.conf.object_id == target_object_id) {
+ return true;
+ }
+
+ if (isRelativeCoord(obj.conf.x)) {
+ var xParent = getMapObjByDomObjId(obj.getCoordParent(obj.conf.x, -1));
+ if(coordsReferTo(xParent, target_object_id)) {
+ return true;
+ }
+ }
+
+ if (isRelativeCoord(obj.conf.y)) {
+ var yParent = getMapObjByDomObjId(obj.getCoordParent(obj.conf.y, -1));
+ if(coordsReferTo(yParent, target_object_id)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
function moveRelativeObject(parentId, parentTop, parentLeft) {
var sLabelName = parentId.replace('box_', 'rel_label_');
if(typeof dragObjectChilds[sLabelName] !== 'undefined') {
@@ -332,7 +377,7 @@ function dragStop(event) {
var oParent = null;
if(event.ctrlKey) {
- var oParent = getNearestObject(draggingObject.id, draggingObject.x,
draggingObject.y)
+ var oParent = getNearestObject(draggingObject, draggingObject.x,
draggingObject.y)
oParent.highlight(false);
}
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins