1 /*  Part of XPCE --- The SWI-Prolog GUI toolkit
2 
3     Author:        Jan Wielemaker and Anjo Anjewierden
4     E-mail:        jan@swi.psy.uva.nl
5     WWW:           http://www.swi.psy.uva.nl/projects/xpce/
6     Copyright (c)  1985-2002, University of Amsterdam
7     All rights reserved.
8 
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions
11     are met:
12 
13     1. Redistributions of source code must retain the above copyright
14        notice, this list of conditions and the following disclaimer.
15 
16     2. Redistributions in binary form must reproduce the above copyright
17        notice, this list of conditions and the following disclaimer in
18        the documentation and/or other materials provided with the
19        distribution.
20 
21     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25     COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32     POSSIBILITY OF SUCH DAMAGE.
33 */
34 
35 #include <h/kernel.h>
36 #include <h/graphics.h>
37 
38 static status
initialiseLink(Link link,Name from,Name to,Line line,Class cl)39 initialiseLink(Link link, Name from, Name to, Line line, Class cl)
40 { if ( isDefault(from) )
41     from = NAME_link;
42 
43   assign(link, from, from);
44   assign(link, to, isDefault(to) ? from : to);
45   assign(link, line, isDefault(line) ? (Line) newObject(ClassLine, EAV) :	line);
46   assign(link, connection_class, cl);
47 
48   succeed;
49 }
50 
51 
52 		 /*******************************
53 		 *	     CONNECTION		*
54 		 *******************************/
55 
56 					/* lazy binding: fixes save/load! */
57 
58 static Connection
getConnectionLink(Link link,Graphical gr,Graphical gr2,Name from,Name to)59 getConnectionLink(Link link, Graphical gr, Graphical gr2, Name from, Name to)
60 { if ( !instanceOfObject(link->connection_class, ClassClass) )
61     assign(link, connection_class, ClassConnection);
62 
63   return newObject(link->connection_class, gr, gr2, link, from, to, EAV);
64 }
65 
66 
67 		 /*******************************
68 		 *	 CLASS DECLARATION	*
69 		 *******************************/
70 
71 /* Type declarations */
72 
73 static char *T_connection[] =
74         { "from=graphical", "to=graphical", "from_handle=[name]", "to_handle=[name]" };
75 static char *T_initialise[] =
76         { "handle_kind1=[name]", "handle_kind2=[name]", "line=[line]", "connection_class=[class]" };
77 
78 /* Instance Variables */
79 
80 static vardecl var_link[] =
81 { IV(NAME_line, "line", IV_GET,
82      NAME_appearance, "Line (with pen, arrows, etc.)"),
83   IV(NAME_from, "name", IV_BOTH,
84      NAME_relation, "Name of valid handles at `from' side"),
85   IV(NAME_to, "name", IV_BOTH,
86      NAME_relation, "Name of valid handles at `to' side"),
87   IV(NAME_connectionClass, "[class]", IV_BOTH,
88      NAME_relation, "Class used by <-connection")
89 };
90 
91 /* Send Methods */
92 
93 static senddecl send_link[] =
94 { SM(NAME_initialise, 4, T_initialise, initialiseLink,
95      DEFAULT, "Create from handle names, line")
96 };
97 
98 /* Get Methods */
99 
100 static getdecl get_link[] =
101 { GM(NAME_connection, 4, "connection", T_connection, getConnectionLink,
102      NAME_relation, "Instantiate the link by creating a connection")
103 };
104 
105 /* Resources */
106 
107 #define rc_link NULL
108 /*
109 static classvardecl rc_link[] =
110 {
111 };
112 */
113 
114 /* Class Declaration */
115 
116 static Name link_termnames[] = { NAME_from, NAME_to, NAME_line };
117 
118 ClassDecl(link_decls,
119           var_link, send_link, get_link, rc_link,
120           3, link_termnames,
121           "$Rev$");
122 
123 
124 status
makeClassLink(Class class)125 makeClassLink(Class class)
126 { declareClass(class, &link_decls);
127   delegateClass(class, NAME_line);
128 
129   succeed;
130 }
131 
132