From 194715260d8f142ced01fddb948ae199cc60b3fa Mon Sep 17 00:00:00 2001 From: Oleg Sh Date: Sun, 15 May 2022 22:02:14 +0200 Subject: [PATCH] Add special actions for edges. --- lang/bg/home.php | 5 ++++ lang/ch/home.php | 7 ++++- lang/de/home.php | 7 ++++- lang/el/home.php | 7 ++++- lang/en/home.php | 7 ++++- lang/es/home.php | 7 ++++- lang/fr/home.php | 7 ++++- lang/nl/home.php | 7 ++++- lang/pt/home.php | 7 ++++- lang/ru/home.php | 8 +++++- lang/sv/home.php | 7 ++++- script/EventHandlers.js | 50 ++++++++++++++++++++++++++++++++ script/Graph.js | 63 ++++++++++++++++++++++++++++++++++++++++- script/texts.js | 12 +++++++- tpl/home.php | 10 +++++-- 15 files changed, 197 insertions(+), 14 deletions(-) diff --git a/lang/bg/home.php b/lang/bg/home.php index f4b58ef..023e697 100644 --- a/lang/bg/home.php +++ b/lang/bg/home.php @@ -280,4 +280,9 @@ We have added Dutch translation 🇳🇱. Thank you Willie de Wit"; $g_lang['find_longest_path'] = "Find the longest path"; $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/lang/ch/home.php b/lang/ch/home.php index 9e707df..e67517d 100644 --- a/lang/ch/home.php +++ b/lang/ch/home.php @@ -279,5 +279,10 @@ $g_lang['use_context_menu'] = "Use context menu for additional actions."; $g_lang['find_longest_path'] = "Find the longest path"; - $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/lang/de/home.php b/lang/de/home.php index f6efe5d..96443cb 100644 --- a/lang/de/home.php +++ b/lang/de/home.php @@ -242,5 +242,10 @@ $g_lang['use_context_menu'] = "Use context menu for additional actions."; $g_lang['find_longest_path'] = "Find the longest path"; - $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/lang/el/home.php b/lang/el/home.php index e32b86d..3aa1f1e 100644 --- a/lang/el/home.php +++ b/lang/el/home.php @@ -280,5 +280,10 @@ $g_lang['use_context_menu'] = "Use context menu for additional actions."; $g_lang['find_longest_path'] = "Find the longest path"; - $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/lang/en/home.php b/lang/en/home.php index a70f5f6..f673968 100755 --- a/lang/en/home.php +++ b/lang/en/home.php @@ -279,5 +279,10 @@ We have added Dutch translation 🇳🇱. Thank you Willie de Wit"; $g_lang['use_context_menu'] = "Use context menu for additional actions."; $g_lang['find_longest_path'] = "Find the longest path"; - $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/lang/es/home.php b/lang/es/home.php index 96e4acf..cd60c6f 100755 --- a/lang/es/home.php +++ b/lang/es/home.php @@ -279,5 +279,10 @@ Tenemos traducciones en griego 🇬🇷. diff --git a/lang/fr/home.php b/lang/fr/home.php index 386f949..f07b78b 100644 --- a/lang/fr/home.php +++ b/lang/fr/home.php @@ -247,5 +247,10 @@ $g_lang['use_context_menu'] = "Use context menu for additional actions."; $g_lang['find_longest_path'] = "Find the longest path"; - $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/lang/nl/home.php b/lang/nl/home.php index 2f7cfc1..14e248e 100644 --- a/lang/nl/home.php +++ b/lang/nl/home.php @@ -244,5 +244,10 @@ $g_lang['use_context_menu'] = "Use context menu for additional actions."; $g_lang['find_longest_path'] = "Find the longest path"; - $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/lang/pt/home.php b/lang/pt/home.php index 2c676c5..db8fbd7 100644 --- a/lang/pt/home.php +++ b/lang/pt/home.php @@ -245,5 +245,10 @@ $g_lang['use_context_menu'] = "Use context menu for additional actions."; $g_lang['find_longest_path'] = "Find the longest path"; - $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/lang/ru/home.php b/lang/ru/home.php index b3ab72f..e51cdb7 100755 --- a/lang/ru/home.php +++ b/lang/ru/home.php @@ -280,5 +280,11 @@ $g_lang['use_context_menu'] = "Используйте контекстное меню для дополнительных действий."; $g_lang['find_longest_path'] = "Поиск самого длинного пути"; - $g_lang['length_of_longest_path_from'] = "Длина самого длинного пути ровна "; + $g_lang['length_of_longest_path_from'] = "Длина самого длинного пути ровна "; + + + $g_lang['additionl_actions'] = "Особые действия"; + $g_lang['reverse_all_edges'] = "Поменять направление всех дуг"; + $g_lang['make_all_undirected'] = "Сделать все дуги неориентированными"; + $g_lang['make_all_directed'] = "Сделать все дуги ориентированными"; ?> diff --git a/lang/sv/home.php b/lang/sv/home.php index 672815b..6fa028c 100644 --- a/lang/sv/home.php +++ b/lang/sv/home.php @@ -241,5 +241,10 @@ $g_lang['use_context_menu'] = "Use context menu for additional actions."; $g_lang['find_longest_path'] = "Find the longest path"; - $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + $g_lang['length_of_longest_path_from'] = "Length of the longest path from "; + + $g_lang['additionl_actions'] = "Special actions"; + $g_lang['reverse_all_edges'] = "Reverse all edges"; + $g_lang['make_all_undirected'] = "Make all edges undirected"; + $g_lang['make_all_directed'] = "Make all edges directed"; ?> diff --git a/script/EventHandlers.js b/script/EventHandlers.js index 260db22..e0e87c2 100644 --- a/script/EventHandlers.js +++ b/script/EventHandlers.js @@ -1035,6 +1035,8 @@ ConnectionGraphHandler.prototype.SelectVertex = function(selectedObject) ConnectionGraphHandler.prototype.MouseDown = function(pos) { + $('#message').unbind(); + var selectedObject = this.GetSelectedGraph(pos); if (selectedObject && (selectedObject instanceof BaseVertex)) { @@ -1055,7 +1057,55 @@ ConnectionGraphHandler.prototype.GetSelectedGroup = function(object) ConnectionGraphHandler.prototype.SelectFirst = function() { this.firstObject = null; + + let hasEdges = this.app.graph.hasEdges(); + let hasDirectedEdges = this.app.graph.hasDirectEdge(); + let hasUndirectedEdges = this.app.graph.hasUndirectEdge(); + this.message = g_selectFisrtVertexToConnect + this.GetSelect2VertexMenu(); + + if (!hasEdges) { + return; + } + + this.message = + ".
" + + " " + + "" + + "
" + this.message; + + let handler = this; + + $('#message').on('click', '#reverseAll', function() { + handler.app.PushToStack("ReverseAllEdges"); + + handler.app.graph.reverseAllEdges(); + handler.app.redrawGraph(); + + userAction("ReverseAllEdges"); + }); + $('#message').on('click', '#makeAllUndirected', function(){ + handler.app.PushToStack("makeAllEdgesUndirected"); + + handler.app.graph.makeAllEdgesUndirected(); + handler.app.redrawGraph(); + + userAction("makeAllEdgesUndirected"); + }); + $('#message').on('click', '#makeAllDirected', function(){ + handler.app.PushToStack("makeAllEdgesDirected"); + + handler.app.graph.makeAllEdgesDirected(); + handler.app.redrawGraph(); + + userAction("makeAllEdgesDirected"); + }); } ConnectionGraphHandler.prototype.SelectSecond = function(selectedObject) diff --git a/script/Graph.js b/script/Graph.js index e7b8127..452e870 100644 --- a/script/Graph.js +++ b/script/Graph.js @@ -986,6 +986,26 @@ Graph.prototype.hasDirectEdge = function () return res; } +Graph.prototype.hasUndirectEdge = function () +{ + var res = false; + for (var i = 0; i < this.edges.length; i++) + { + if(!this.edges[i].isDirect) + { + res = true; + break; + } + } + + return res; +} + +Graph.prototype.hasEdges = function () +{ + return this.edges.length > 0; +} + Graph.prototype.clampPositions = function (viewportSize) { var diameter = (new VertexModel()).diameter; @@ -1178,4 +1198,45 @@ Graph.prototype.GetAvalibleCruvledValue = function(neighbourEdges, originalEdge) } return defaultValue; -} \ No newline at end of file +} + +Graph.prototype.reverseAllEdges = function () +{ + for (var i = 0; i < this.edges.length; i++) + { + if(this.edges[i].isDirect) + { + let v1 = this.edges[i].vertex1; + this.edges[i].vertex1 = this.edges[i].vertex2; + this.edges[i].vertex2 = v1; + } + } + + this.isMultiGraph = this.checkMutiGraph(); +} + +Graph.prototype.makeAllEdgesDirected = function () +{ + for (var i = 0; i < this.edges.length; i++) + { + if(!this.edges[i].isDirect) + { + this.edges[i].isDirect = true; + } + } + + this.isMultiGraph = this.checkMutiGraph(); +} + +Graph.prototype.makeAllEdgesUndirected = function () +{ + for (var i = 0; i < this.edges.length; i++) + { + if(this.edges[i].isDirect) + { + this.edges[i].isDirect = false; + } + } + + this.isMultiGraph = this.checkMutiGraph(); +} diff --git a/script/texts.js b/script/texts.js index bf55230..6941995 100644 --- a/script/texts.js +++ b/script/texts.js @@ -189,6 +189,11 @@ var g_useContextMenuText = "Use context menu for addition actions." var g_findLongestPath = "Find the longest path"; var g_LengthOfLongestPathFrom = "Length of the longest path from "; +var g_additionlActions = "Additional actions"; +var g_reverseAllEdges = "Reverse all edges"; +var g_makeAllUndirected = "Make all edges undirected"; +var g_makeAllDirected = "Make all edges directed"; + function loadTexts() { g_textsSelectAndMove = document.getElementById("SelectAndMoveObject").innerHTML; @@ -384,5 +389,10 @@ function loadTexts() g_useContextMenuText = document.getElementById("UseContextMenuText").innerHTML; g_findLongestPath = document.getElementById("findLongestPath").innerHTML; - g_LengthOfLongestPathFrom = document.getElementById("LengthOfLongestPathFrom").innerHTML; + g_LengthOfLongestPathFrom = document.getElementById("LengthOfLongestPathFrom").innerHTML; + + g_additionlActions = document.getElementById("additionlActions").innerHTML; + g_reverseAllEdges = document.getElementById("reverseAllEdges").innerHTML; + g_makeAllUndirected = document.getElementById("makeAllUndirected").innerHTML; + g_makeAllDirected = document.getElementById("makeAllDirected").innerHTML; } diff --git a/tpl/home.php b/tpl/home.php index 2f98d8c..502b748 100755 --- a/tpl/home.php +++ b/tpl/home.php @@ -10,7 +10,7 @@ - + @@ -838,7 +838,13 @@

-

+

+ +

+

+

+

+