From a1ee7574efeec37187bdceaf8844b90391d62cc8 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 9 Feb 2018 23:49:36 +0100 Subject: [PATCH] LocationSolver: reorganise and complete the decision logic (#1127) --- src/gui/interact/ui-location-solver.hpp | 46 ++++--- wiki/thinkPad.ichthyo.mm | 173 ++++++++++++++++++++---- 2 files changed, 173 insertions(+), 46 deletions(-) diff --git a/src/gui/interact/ui-location-solver.hpp b/src/gui/interact/ui-location-solver.hpp index b305fb7ba..ce29b2a04 100644 --- a/src/gui/interact/ui-location-solver.hpp +++ b/src/gui/interact/ui-location-solver.hpp @@ -177,35 +177,43 @@ namespace interact { * while the remaining, uncovered extension describes additional elements to be created. * When the resolution process found an already existing UI element, the returned path * is completely covered. The degree of coverage of a path can be found out with the - * help of a UICoordResolver, which also needs a LocationQuery (service) to find out - * about the currently existing UI topology. + * help of a UICoordResolver, which also needs a LocationQuery (service) to discover + * the currently existing UI topology. */ UICoord - solve (LocationRule& rule, size_t depth, Symbol elementType) + solve (LocationRule& rule, size_t depth, Symbol elementTypeID) { for (auto& clause : rule) { - if (clause.pattern.size() > depth+1) continue; + // Clauses which do not at least describe an element at parent level + // will never lead to a solution and can thus be skipped + if (depth+1 < clause.pattern.size() + or depth > clause.pattern.size()) + continue; + + // try to solve the current Clause by matching against real UI topology UICoordResolver resolver{clause.pattern, getLocationQuery()}; - resolver.coverPartially(); - if (clause.createParents) + resolver.coverPartially(); // now either holds a solution or is empty + + if (not isnil(resolver) // Solution found! + and (clause.createParents // The "create" case requires only some part to exist, + or resolver.isCoveredTotally())) // while in the default case we demand complete coverage { - if (not isnil (resolver)) - //////////////////////////////////////TODO ensure correct depth. Possibly append element itself - return move (resolver); - else - if (clause.pattern.isExplicit()) - // allow creation of a totally new path - // as long as it is complete and explicitly given - return clause.pattern; + if (depth == clause.pattern.size()) + // append ID of the new element to be created + // unless it's already there (and thus exists) + resolver.append (elementTypeID); + return move (resolver); + // use the first suitable solution and exit } else - { - if (not isnil (resolver) and resolver.isCoveredTotally()) - //////////////////////////////////////TODO ensure correct depth. Possibly append element itself - return move (resolver); - } + if (clause.createParents and clause.pattern.isExplicit()) + // allow creation of a totally new path from scratch + // as long as it is complete and explicitly given + return clause.pattern; } + //all clauses tried without success... + return UICoord(); } private: diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 330f3305e..aba2cf81c 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -2224,7 +2224,7 @@ - + @@ -2253,7 +2253,7 @@

- +
@@ -9956,28 +9956,12 @@
- - - - - - - - - - - - - - -

- Komponente falls nötig anhängen -

- - -
+ + + + @@ -10008,12 +9992,147 @@
-
- + + + + + + +

+ Komponente falls nötig anhängen +

+ +
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ ...weil wir keinen Zustand sammeln +

+

+ und daher jede Klausel von Grund auf neu lösen. +

+ + +
+ +
+ + + + + + + + + + + + + +

+ könnte man zulassen +

+ + +
+ +
+ + + +
+ + + + + + + + + + + + + + + + + +

+ not empty? UND +

+

+ Create ODER totalyCovered? +

+ +
+ + + + + + + + + + + + + + + + + + @@ -25474,8 +25593,8 @@ - - + +