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.
20 #include "connectionpoint_ops.h"
21 #include "object_ops.h"
24 static Color connectionpoint_color
= { 0.4, 0.4, 1.0 };
26 #define CP_SZ (CONNECTIONPOINT_SIZE/2)
29 connectionpoint_draw(ConnectionPoint
*conpoint
,
33 Point
*point
= &conpoint
->pos
;
34 Renderer
*renderer
= ddisp
->renderer
;
36 ddisplay_transform_coords(ddisp
, point
->x
, point
->y
, &x
, &y
);
38 (renderer
->ops
->set_linewidth
)(renderer
, 0.0);
39 (renderer
->ops
->set_linestyle
)(renderer
, LINESTYLE_SOLID
);
41 (renderer
->interactive_ops
->draw_pixel_line
)(renderer
,
44 &connectionpoint_color
);
46 (renderer
->interactive_ops
->draw_pixel_line
)(renderer
,
49 &connectionpoint_color
);
54 connectionpoint_add_update(ConnectionPoint
*conpoint
,
57 diagram_add_update_pixels(dia
, &conpoint
->pos
,
58 CONNECTIONPOINT_SIZE
, CONNECTIONPOINT_SIZE
);
61 /* run diagram_update_connections_object on all selected objects. */
63 diagram_update_connections_selection(Diagram
*dia
)
65 GList
*list
= dia
->data
->selected
;
68 Object
* selected_obj
= (Object
*) list
->data
;
70 diagram_update_connections_object(dia
, selected_obj
, TRUE
);
72 list
= g_list_next(list
);
76 /* Updates all objects connected to the 'obj' object.
77 Calls this function recursively for objects modified.
79 If update_nonmoved is TRUE, also objects that have not
80 moved since last time is updated. This is not propagated
84 diagram_update_connections_object(Diagram
*dia
, Object
*obj
,
90 Object
*connected_obj
;
93 for (i
=0;i
<obj
->num_connections
;i
++) {
94 cp
= obj
->connections
[i
];
95 if ((update_nonmoved
) ||
96 (distance_point_point_manhattan(&cp
->pos
, &cp
->last_pos
) > CHANGED_TRESHOLD
)) {
97 cp
->last_pos
= cp
->pos
;
101 connected_obj
= (Object
*) list
->data
;
104 for (j
=0;j
<connected_obj
->num_handles
;j
++) {
105 if (connected_obj
->handles
[j
]->connected_to
== cp
)
106 handle
= connected_obj
->handles
[j
];
108 assert(handle
!=NULL
);
110 object_add_updates(connected_obj
, dia
);
111 connected_obj
->ops
->move_handle(connected_obj
, handle
,
112 &cp
->pos
, HANDLE_MOVE_CONNECTED
,0);
113 object_add_updates(connected_obj
, dia
);
115 diagram_update_connections_object(dia
, connected_obj
, FALSE
);
117 list
= g_list_next(list
);
126 ddisplay_connect_selected(DDisplay
*ddisp
)
129 Object
*selected_obj
;
132 list
= ddisp
->diagram
->data
->selected
;
135 selected_obj
= (Object
*) list
->data
;
137 for (i
=0; i
<selected_obj
->num_handles
; i
++) {
138 if (selected_obj
->handles
[i
]->connect_type
!= HANDLE_NONCONNECTABLE
) {
139 object_connect_display(ddisp
, selected_obj
, selected_obj
->handles
[i
]);
143 list
= g_list_next(list
);
148 diagram_unconnect_selected(Diagram
*dia
)
151 Object
*selected_obj
;
155 list
= dia
->data
->selected
;
158 selected_obj
= (Object
*) list
->data
;
160 for (i
=0; i
<selected_obj
->num_handles
; i
++) {
161 handle
= selected_obj
->handles
[i
];
163 if ((handle
->connected_to
!= NULL
) &&
164 (handle
->connect_type
== HANDLE_CONNECTABLE
)){
165 /* don't do this if type is HANDLE_CONNECTABLE_BREAK */
166 if (!diagram_is_selected(dia
, handle
->connected_to
->object
)) {
167 Change
*change
= undo_unconnect(dia
, selected_obj
, handle
);
168 (change
->apply
)(change
, dia
);
173 list
= g_list_next(list
);