1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  CPViz Constraint Visualization System
15// The Initial Developer of the Original Code is  Helmut Simonis
16// Portions created by the Initial Developer are
17// Copyright (C) 2009-2010 Helmut Simonis
18//
19// Contributor(s): 	Helmut Simonis, 4C, Univerity College Cork, Cork
20//
21//
22// END LICENSE BLOCK
23// ----------------------------------------------------------------------
24package ie.ucc.cccc.viz;
25
26import java.io.PrintWriter;
27
28public class VisualizerVectorWaterfall extends VisualizerDrawer {
29
30	public VisualizerVectorWaterfall(VisualContext context) {
31		super(context);
32	}
33
34	public void draw(PrintWriter out, VisualState visualState) {
35		FullDomain[] vars = visualState.getEntries().asDomainArray();
36		standardGrid(out);
37		int line = 1;
38		while (visualState.getParent()!= null){
39			VisualState old = visualState.getParent();
40			FullDomain[] oldVars = old.getEntries().asDomainArray();
41			compare(out,line,vars,oldVars);
42			vars = oldVars;
43			visualState = old;
44			line++;
45		}
46	}
47
48	public void compare(PrintWriter out, int line,FullDomain[] vars,FullDomain[] old){
49		for(int i =1; i < vars.length; i++){
50			Colors color;
51			if (old[i].isFixed()){
52				// previously fixed
53				color = Colors.OLD_ASSIGN_COLOR;
54			} else if (vars[i].isFixed()){
55				// newly fixed
56				color = Colors.ASSIGN_COLOR;
57			} else if (vars[i].size() == old[i].size()){
58				// unchanged
59				color = Colors.UNCHANGED_COLOR;
60			} else{
61				int varsMin = vars[i].getMin();
62				int varsMax = vars[i].getMax();
63				int oldMin = old[i].getMin();
64				int oldMax = old[i].getMax();
65				assert varsMin >= oldMin;
66				assert varsMax <= oldMax;
67				if (varsMin > oldMin && varsMax < oldMax){
68					// updated min max
69					color = Colors.CHANGED_MINMAX_COLOR;
70				} else if (varsMin > oldMin){
71					// updated min
72					color = Colors.CHANGED_MIN_COLOR;
73				} else if (varsMax < oldMax) {
74					// updated max
75					color = Colors.CHANGED_MAX_COLOR;
76				} else {
77					// updated size only
78					color = Colors.CHANGED_SIZE_COLOR;
79				}
80			}
81			unitSquareSVG(out,posX(i),posY(line),color);
82		}
83	}
84
85}
86