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.
22 #include "connectionpoint_ops.h"
23 #include "object_ops.h"
26 static Color connectionpoint_color
= { 0.4, 0.4, 1.0 };
28 #define CP_SZ (CONNECTIONPOINT_SIZE/2)
31 connectionpoint_draw(ConnectionPoint
*conpoint
,
35 Point
*point
= &conpoint
->pos
;
36 DiaRenderer
*renderer
= ddisp
->renderer
;
37 DiaRendererClass
*renderer_ops
= DIA_RENDERER_GET_CLASS (ddisp
->renderer
);
38 DiaInteractiveRendererInterface
*irenderer
=
39 DIA_GET_INTERACTIVE_RENDERER_INTERFACE (ddisp
->renderer
);
41 ddisplay_transform_coords(ddisp
, point
->x
, point
->y
, &x
, &y
);
43 renderer_ops
->set_linewidth (renderer
, 0.0);
44 renderer_ops
->set_linestyle (renderer
, LINESTYLE_SOLID
);
46 irenderer
->draw_pixel_line (renderer
,
49 &connectionpoint_color
);
51 irenderer
->draw_pixel_line (renderer
,
54 &connectionpoint_color
);
58 connectionpoint_add_update(ConnectionPoint
*conpoint
,
61 diagram_add_update_pixels(dia
, &conpoint
->pos
,
62 CONNECTIONPOINT_SIZE
, CONNECTIONPOINT_SIZE
);
65 /* run diagram_update_connections_object on all selected objects. */
67 diagram_update_connections_selection(Diagram
*dia
)
69 GList
*list
= dia
->data
->selected
;
72 Object
* selected_obj
= (Object
*) list
->data
;
74 diagram_update_connections_object(dia
, selected_obj
, TRUE
);
76 list
= g_list_next(list
);
80 /* Updates all objects connected to the 'obj' object.
81 Calls this function recursively for objects modified.
83 If update_nonmoved is TRUE, also objects that have not
84 moved since last time is updated. This is not propagated
88 diagram_update_connections_object(Diagram
*dia
, Object
*obj
,
94 Object
*connected_obj
;
97 for (i
=0;i
<obj
->num_connections
;i
++) {
98 cp
= obj
->connections
[i
];
99 if ((update_nonmoved
) ||
100 (distance_point_point_manhattan(&cp
->pos
, &cp
->last_pos
) > CHANGED_TRESHOLD
)) {
101 cp
->last_pos
= cp
->pos
;
103 list
= cp
->connected
;
105 connected_obj
= (Object
*) list
->data
;
107 object_add_updates(connected_obj
, dia
);
109 for (j
=0;j
<connected_obj
->num_handles
;j
++) {
110 if (connected_obj
->handles
[j
]->connected_to
== cp
) {
111 handle
= connected_obj
->handles
[j
];
112 connected_obj
->ops
->move_handle(connected_obj
, handle
,
113 &cp
->pos
, HANDLE_MOVE_CONNECTED
,0);
116 object_add_updates(connected_obj
, dia
);
118 diagram_update_connections_object(dia
, connected_obj
, FALSE
);
120 list
= g_list_next(list
);
129 ddisplay_connect_selected(DDisplay
*ddisp
)
132 Object
*selected_obj
;
135 list
= ddisp
->diagram
->data
->selected
;
138 selected_obj
= (Object
*) list
->data
;
140 for (i
=0; i
<selected_obj
->num_handles
; i
++) {
141 if (selected_obj
->handles
[i
]->connect_type
!= HANDLE_NONCONNECTABLE
) {
142 object_connect_display(ddisp
, selected_obj
, selected_obj
->handles
[i
]);
146 list
= g_list_next(list
);
151 diagram_unconnect_selected(Diagram
*dia
)
154 Object
*selected_obj
;
158 list
= dia
->data
->selected
;
161 selected_obj
= (Object
*) list
->data
;
163 for (i
=0; i
<selected_obj
->num_handles
; i
++) {
164 handle
= selected_obj
->handles
[i
];
166 if ((handle
->connected_to
!= NULL
) &&
167 (handle
->connect_type
== HANDLE_CONNECTABLE
)){
168 /* don't do this if type is HANDLE_CONNECTABLE_BREAK */
169 if (!diagram_is_selected(dia
, handle
->connected_to
->object
)) {
170 Change
*change
= undo_unconnect(dia
, selected_obj
, handle
);
171 (change
->apply
)(change
, dia
);
176 list
= g_list_next(list
);