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% ----------------------------------------------------------------------
24:-module(vis_options).
25
26:-export(add_options/3).
27:-export(default_options/2).
28
29:-use_module(vis_structures).
30
31add_options(Options,ObjectType,Handle):-
32        (foreach(Attr:Value,Options),
33         param(ObjectType,Handle) do
34            (argument_number(ObjectType,Attr,Arg,_) ->
35                arg(Arg,Handle,Slot),
36                (var(Slot) ->
37                    Slot = Value
38                ;
39                    (Slot == Value ->
40                        true
41                    ;
42                        writeln(already_fixed(ObjectType,Attr,Slot,Value))
43                    )
44                )            
45            ;
46                writeln(unknown_attr(ObjectType,Attr,Value))
47            )
48        ).
49
50default_options(Handle,ObjectType):-
51        (foreacharg(X,Handle),
52         count(J,1,_),
53         param(Handle,ObjectType) do
54            default_option(X,J,Handle,ObjectType)
55        ).
56
57default_option(X,_,_,_):-
58        nonvar(X),
59        !.
60default_option(X,J,Handle,ObjectType):-
61        (argument_number(ObjectType,Attr,J,Default) ->
62            (Default = required(_) ->
63                writeln(required_attr_missing(ObjectType,Attr,J))
64            ; Default = system(_) ->
65                true
66            ;
67                X = Default
68            )
69        ;
70            writeln(missing_default_attr(ObjectType,J,Handle))
71        ).
72
73