示例#1
0
        // Given a SpecificLayout, sets any necessary properties to make it suitable to return to the caller of GetBestLayout(LayoutQuery)
        protected SpecificLayout prepareLayoutForQuery(SpecificLayout layout, LayoutQuery query)
        {
            if (layout != null)
            {
                if (layout.Width < 0 || layout.Height < 0)
                {
                    ErrorReporter.ReportParadox("Illegal layout size: " + layout.Size);
                    this.GetBestLayout(query);
                }
            }
            int numMatches;

            //if (query.Debug)
            {
                if (query.ProposedSolution_ForDebugging != null)
                {
                    if (!query.Accepts(query.ProposedSolution_ForDebugging))
                    {
                        ErrorReporter.ReportParadox("Error: the proposed solution was not valid");
                    }
                }
                if (layout != null && !query.Accepts(layout))
                {
                    ErrorReporter.ReportParadox("Error: the returned layout was not valid");
                    LayoutQuery query2 = query.DebugClone();
                    this.GetBestLayout(query2);
                }
            }

            if (layout != null)
            {
                //layout.Set_SourceParent(this);

                numMatches = 0;

                /*foreach (LayoutChoice_Set ancestor in layout.GetAncestors())
                 * {
                 *  if (ancestor == this)
                 *      numMatches++;
                 * }
                 * if (numMatches == 0)
                 *  ErrorReporter.ReportParadox("Error: the returned layout did not come from this layout");
                 * if (numMatches > 1)
                 *  ErrorReporter.ReportParadox("Error: the returned layout contained multiple ancestors matching this one");
                 */
                layout.SourceQuery = query;
            }

            if (this.parents.Count < 1 && !(this is ViewManager))
            {
                throw new InvalidOperationException("No parents assigned to " + this);
            }

            query.OnAnswered(this);

            return(layout);
        }
示例#2
0
        public override SpecificLayout GetBestLayout(LayoutQuery query)
        {
            SpecificLayout best_specificLayout = null;
            SpecificLayout debugResult         = query.ProposedSolution_ForDebugging;

            if (debugResult != null)
            {
                debugResult = debugResult.Clone();
            }
            List <LayoutChoice_Set> good_sourceLayouts = new List <LayoutChoice_Set>();
            LayoutQuery             originalQuery      = query;

            foreach (LayoutChoice_Set layoutSet in this.layoutOptions)
            {
                if (best_specificLayout != null)
                {
                    // make the query more strict, so we will only ever get dimensions that are at least as good as this
                    // TODO: figure out why it's not better to use OptimizedPastExample
                    query = query.OptimizedUsingExample(best_specificLayout);
                }
                SpecificLayout currentLayout;
                if (query.Debug)
                {
                    // if the proposed layout is an option, then be sure to consider it
                    if (debugResult != null && debugResult.GetAncestors().Contains(layoutSet))
                    {
                        query.ProposedSolution_ForDebugging = debugResult;
                        currentLayout = layoutSet.GetBestLayout(query);
                        query.ProposedSolution_ForDebugging = debugResult;
                        return(this.prepareLayoutForQuery(currentLayout, query));
                    }
                }
                currentLayout = layoutSet.GetBestLayout(query);

                if (currentLayout != null && query.PreferredLayout(currentLayout, best_specificLayout) == currentLayout)
                {
                    // keep track of this query (which must be the best so far)
                    best_specificLayout = currentLayout;
                    good_sourceLayouts.Add(layoutSet);

                    if (query.Debug && query.ProposedSolution_ForDebugging != null)
                    {
                        if (query.PreferredLayout(query.ProposedSolution_ForDebugging, best_specificLayout) != query.ProposedSolution_ForDebugging)
                        {
                            ErrorReporter.ReportParadox("Error; query " + query + " prefers " + best_specificLayout + " over proposed debug solution " + query.ProposedSolution_ForDebugging);
                            LayoutQuery debugQuery = query.DebugClone();
                            layoutSet.GetBestLayout(debugQuery);
                        }
                    }
                }
            }
            originalQuery.ProposedSolution_ForDebugging = debugResult;
            return(this.prepareLayoutForQuery(best_specificLayout, originalQuery));
        }