1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 /* \brief Invalidate temporary origin marker.
28 o_ognrst_invalidate_rubber (GschemToplevel
*w_current
)
30 g_return_if_fail (w_current
!= NULL
);
32 GschemPageView
*page_view
= gschem_toplevel_get_current_page_view (w_current
);
33 gschem_page_view_invalidate_all (page_view
);
36 /*! \brief Perform an origin reset operation.
38 * Ends the process of interactively resetting the origin of the
39 * current sheet by translating all objects, panning the view
40 * accordingly, and leaving origin reset mode. If the old origin is
41 * selected, origin reset mode is left without performing an operation.
43 * The arguments \a w_x and \w_y are discarded; the last coordinates
44 * saved in \b w_current->first_wx and \b w_current->first_wy are used
48 o_ognrst_end (GschemToplevel
*w_current
, int w_x
, int w_y
)
50 if (w_current
->first_wx
== 0 && w_current
->first_wy
== 0) {
51 s_log_message (_("Not translating schematic\n"));
52 o_ognrst_invalidate_rubber (w_current
);
53 i_action_stop (w_current
);
54 i_set_state (w_current
, SELECT
);
58 GschemPageView
*page_view
= gschem_toplevel_get_current_page_view (w_current
);
59 g_return_if_fail (page_view
!= NULL
);
61 PAGE
*page
= gschem_page_view_get_page (page_view
);
62 g_return_if_fail (page
!= NULL
);
64 TOPLEVEL
*toplevel
= page
->toplevel
;
65 g_return_if_fail (toplevel
!= NULL
);
67 gschem_bottom_widget_set_coordinates (
68 GSCHEM_BOTTOM_WIDGET (w_current
->bottom_widget
), 0, 0);
71 /* translate schematic */
72 for (const GList
*l
= s_page_objects (page
); l
!= NULL
; l
= l
->next
)
73 s_conn_remove_object_connections (toplevel
, (OBJECT
*) l
->data
);
75 s_log_message (_("Translating schematic [%d %d]\n"), -w_current
->first_wx
,
76 -w_current
->first_wy
);
77 o_glist_translate_world (s_page_objects (page
), -w_current
->first_wx
,
78 -w_current
->first_wy
);
80 for (const GList
*l
= s_page_objects (page
); l
!= NULL
; l
= l
->next
)
81 s_conn_update_object (page
, (OBJECT
*) l
->data
);
85 GschemPageGeometry
*geometry
=
86 gschem_page_view_get_page_geometry (page_view
);
87 gschem_page_view_pan_general (
89 (geometry
->viewport_right
+
90 geometry
->viewport_left
) / 2 - w_current
->first_wx
,
91 (geometry
->viewport_top
+
92 geometry
->viewport_bottom
) / 2 - w_current
->first_wy
, 1.);
93 gschem_page_view_invalidate_all (page_view
);
96 gschem_toplevel_page_content_changed (w_current
, page
);
97 o_undo_savestate (w_current
, page
, UNDO_ALL
, _("Place Origin"));
98 if (page
->undo_current
!= NULL
) {
99 page
->undo_current
->tx
= -w_current
->first_wx
;
100 page
->undo_current
->ty
= -w_current
->first_wy
;
103 i_action_stop (w_current
);
104 i_set_state (w_current
, SELECT
);
107 /*! \brief Draw temporary origin while moving the mouse cursor.
109 * Manages the erase/update/draw process of the temporary origin while
110 * moving the mouse in origin reset mode.
112 * \param [in] w_current The GschemToplevel object.
113 * \param [in] w_x Current X coordinate of pointer in world units.
114 * \param [in] w_y Current Y coordinate of pointer in world units.
117 o_ognrst_motion (GschemToplevel
*w_current
, int w_x
, int w_y
)
119 if (w_current
->rubber_visible
)
120 o_ognrst_invalidate_rubber (w_current
);
122 /* The coordinates of the temporary origin marker are updated. Its
123 * new coordinates are in \b w_x and \b w_y parameters and saved to
124 * \b w_current->first_wx and \b w_current->first_wy, respectively. */
125 w_current
->first_wx
= w_x
;
126 w_current
->first_wy
= w_y
;
128 o_ognrst_invalidate_rubber (w_current
);
129 w_current
->rubber_visible
= 1;
132 /*! \brief Draw temporary origin marker.
134 * Draws a temporary origin marker at the point (\b
135 * w_current->first_wx, \b w_current->first_wy).
138 o_ognrst_draw_rubber (GschemToplevel
*w_current
, EdaRenderer
*renderer
,
139 int x
, int y
, int width
, int height
)
141 GschemPageView
*page_view
=
142 gschem_toplevel_get_current_page_view (w_current
);
143 if (page_view
!= NULL
&& page_view
->doing_pan
)
146 cairo_t
*cr
= eda_renderer_get_cairo_context (renderer
);
148 double x_start
= x
- 1;
149 double y_start
= y
+ height
+ 1;
150 double x_end
= x
+ width
+ 1;
151 double y_end
= y
- 1;
152 cairo_device_to_user (cr
, &x_start
, &y_start
);
153 cairo_device_to_user (cr
, &x_end
, &y_end
);
155 cairo_matrix_t user_to_device_matrix
;
156 cairo_get_matrix (cr
, &user_to_device_matrix
);
159 cairo_identity_matrix (cr
);
160 cairo_translate (cr
, .5, .5);
162 COLOR
*c
= x_color_lookup (PLACE_ORIGIN_COLOR
);
163 cairo_set_source_rgba (cr
, (double)c
->r
/ 255.,
166 (double)c
->a
/ 255.);
167 cairo_set_line_width (cr
, 1.);
168 cairo_set_line_cap (cr
, CAIRO_LINE_CAP_SQUARE
);
170 double x0
, y0
, x1
, y1
;
172 x0
= floor (x_start
);
173 y0
= w_current
->first_wy
;
175 y1
= w_current
->first_wy
;
177 cairo_matrix_transform_point (&user_to_device_matrix
, &x0
, &y0
);
178 cairo_matrix_transform_point (&user_to_device_matrix
, &x1
, &y1
);
180 cairo_move_to (cr
, (int)(x0
+ .5), (int)(y0
+ .5));
181 cairo_line_to (cr
, (int)(x1
+ .5), (int)(y1
+ .5));
184 x0
= w_current
->first_wx
;
185 y0
= floor (y_start
);
186 x1
= w_current
->first_wx
;
189 cairo_matrix_transform_point (&user_to_device_matrix
, &x0
, &y0
);
190 cairo_matrix_transform_point (&user_to_device_matrix
, &x1
, &y1
);
192 cairo_move_to (cr
, (int)(x0
+ .5), (int)(y0
+ .5));
193 cairo_line_to (cr
, (int)(x1
+ .5), (int)(y1
+ .5));