1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <string.h> /* memcpy() */
24 #include "connection.h"
28 connection_move_handle(Connection
*conn
, HandleId id
,
29 Point
*to
, HandleMoveReason reason
)
32 case HANDLE_MOVE_STARTPOINT
:
33 conn
->endpoints
[0] = *to
;
35 case HANDLE_MOVE_ENDPOINT
:
36 conn
->endpoints
[1] = *to
;
39 message_error("Internal error in connection_move_handle.\n");
45 connection_update_handles(Connection
*conn
)
47 conn
->endpoint_handles
[0].id
= HANDLE_MOVE_STARTPOINT
;
48 conn
->endpoint_handles
[0].pos
= conn
->endpoints
[0];
50 conn
->endpoint_handles
[1].id
= HANDLE_MOVE_ENDPOINT
;
51 conn
->endpoint_handles
[1].pos
= conn
->endpoints
[1];
55 connection_update_boundingbox(Connection
*conn
)
59 line_bbox(&conn
->endpoints
[0],&conn
->endpoints
[1],
60 &conn
->extra_spacing
,&conn
->object
.bounding_box
);
63 /* Needs to have at least 2 handles
64 The two first of each are used. */
66 connection_init(Connection
*conn
, int num_handles
, int num_connections
)
73 assert(num_handles
>=2);
75 object_init(obj
, num_handles
, num_connections
);
77 assert(obj
->handles
!=NULL
);
80 obj
->handles
[i
] = &conn
->endpoint_handles
[i
];
81 obj
->handles
[i
]->type
= HANDLE_MAJOR_CONTROL
;
82 obj
->handles
[i
]->connect_type
= HANDLE_CONNECTABLE
;
83 obj
->handles
[i
]->connected_to
= NULL
;
89 connection_copy(Connection
*from
, Connection
*to
)
96 fromobj
= &from
->object
;
98 object_copy(fromobj
, toobj
);
101 to
->endpoints
[i
] = from
->endpoints
[i
];
106 to
->endpoint_handles
[i
] = from
->endpoint_handles
[i
];
107 to
->endpoint_handles
[i
].connected_to
= NULL
;
108 toobj
->handles
[i
] = &to
->endpoint_handles
[i
];
110 memcpy(&to
->extra_spacing
,&from
->extra_spacing
,sizeof(to
->extra_spacing
));
114 connection_destroy(Connection
*conn
)
116 object_destroy(&conn
->object
);
121 connection_save(Connection
*conn
, ObjectNode obj_node
)
125 object_save(&conn
->object
, obj_node
);
127 attr
= new_attribute(obj_node
, "conn_endpoints");
128 data_add_point(attr
, &conn
->endpoints
[0]);
129 data_add_point(attr
, &conn
->endpoints
[1]);
133 connection_load(Connection
*conn
, ObjectNode obj_node
)
138 object_load(&conn
->object
, obj_node
);
140 attr
= object_find_attribute(obj_node
, "conn_endpoints");
142 data
= attribute_first_data(attr
);
143 data_point( data
, &conn
->endpoints
[0] );
144 data
= data_next(data
);
145 data_point( data
, &conn
->endpoints
[1] );