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
21 * \file gschem_options.c
37 #include "actions.decl.x"
45 PROP_GSCHEM_TOPLEVEL
= 1,
48 PROP_MAGNETIC_NET_MODE
,
49 PROP_NET_RUBBER_BAND_MODE
,
57 class_init (GschemOptionsClass
*klass
);
60 get_property (GObject
*object
, guint param_id
, GValue
*value
, GParamSpec
*pspec
);
63 instance_init (GschemOptions
*adapter
);
66 set_property (GObject
*object
, guint param_id
, const GValue
*value
, GParamSpec
*pspec
);
70 /*! \brief Cycle grid mode to the next option
72 * \param options These options
75 gschem_options_cycle_grid_mode (GschemOptions
*options
)
77 GRID_MODE next_grid_mode
;
79 g_return_if_fail (options
!= NULL
);
81 next_grid_mode
= (options
->grid_mode
+ 1) % GRID_MODE_COUNT
;
83 gschem_options_set_grid_mode (options
, next_grid_mode
);
88 /*! \brief Cycle show origin to the next option
90 * \param options These options
93 gschem_options_cycle_show_origin (GschemOptions
*options
)
95 gboolean next_show_origin
;
97 g_return_if_fail (options
!= NULL
);
99 next_show_origin
= !options
->show_origin
;
101 gschem_options_set_show_origin (options
, next_show_origin
);
106 /*! \brief Cycle magnetic net mode to the next option
108 * \param options These options
111 gschem_options_cycle_magnetic_net_mode (GschemOptions
*options
)
113 gboolean next_magnetic_net_mode
;
115 g_return_if_fail (options
!= NULL
);
117 next_magnetic_net_mode
= !options
->magnetic_net_mode
;
119 gschem_options_set_magnetic_net_mode (options
, next_magnetic_net_mode
);
124 /*! \brief Cycle net rubber band mode to the next option
126 * \param options These options
129 gschem_options_cycle_net_rubber_band_mode (GschemOptions
*options
)
131 gboolean next_net_rubber_band_mode
;
133 g_return_if_fail (options
!= NULL
);
135 next_net_rubber_band_mode
= !options
->net_rubber_band_mode
;
137 gschem_options_set_net_rubber_band_mode (options
, next_net_rubber_band_mode
);
142 /*! \brief Cycle snap mode to the next option
144 * \param options These options
147 gschem_options_cycle_snap_mode (GschemOptions
*options
)
149 SNAP_STATE next_snap_mode
;
151 g_return_if_fail (options
!= NULL
);
153 /* toggle to the next snap state */
154 next_snap_mode
= (options
->snap_mode
+ 1) % SNAP_STATE_COUNT
;
156 gschem_options_set_snap_mode (options
, next_snap_mode
);
161 /*! \brief Get the grid mode
163 * \param [in] options These options
164 * \return The grid mode
167 gschem_options_get_grid_mode (GschemOptions
*options
)
169 g_return_val_if_fail (options
!= NULL
, GRID_MODE_MESH
);
171 return options
->grid_mode
;
176 /*! \brief Get whether to show origin
178 * \param [in] options These options
179 * \return Whether to show the origin
182 gschem_options_get_show_origin (GschemOptions
*options
)
184 g_return_val_if_fail (options
!= NULL
, DEFAULT_SHOW_ORIGIN
);
186 return options
->show_origin
;
191 /*! \brief Get the magnetic net mode
193 * \param [in] options These options
194 * \return The magnetic net mode
197 gschem_options_get_magnetic_net_mode (GschemOptions
*options
)
199 g_return_val_if_fail (options
!= NULL
, DEFAULT_MAGNETIC_NET_MODE
);
201 return options
->magnetic_net_mode
;
206 /*! \brief Get the net rubber band mode
208 * \param [in] options These options
209 * \return The net rubber band mode
212 gschem_options_get_net_rubber_band_mode (GschemOptions
*options
)
214 g_return_val_if_fail (options
!= NULL
, DEFAULT_NET_RUBBER_BAND_MODE
);
216 return options
->net_rubber_band_mode
;
221 /*! \brief Get the snap mode
223 * \param [in] options These options
224 * \return The snap mode
227 gschem_options_get_snap_mode (GschemOptions
*options
)
229 g_return_val_if_fail (options
!= NULL
, SNAP_GRID
);
231 return options
->snap_mode
;
236 /*! \brief Get the snap size
238 * \param [in] options These options
239 * \return The snap size
242 gschem_options_get_snap_size (GschemOptions
*options
)
244 g_return_val_if_fail (options
!= NULL
, DEFAULT_SNAP_SIZE
);
246 return options
->snap_size
;
251 /*! \brief Get/register GschemSelection type.
254 gschem_options_get_type ()
256 static GType type
= 0;
259 static const GTypeInfo info
= {
260 sizeof(GschemOptionsClass
),
261 NULL
, /* base_init */
262 NULL
, /* base_finalize */
263 (GClassInitFunc
) class_init
,
264 NULL
, /* class_finalize */
265 NULL
, /* class_data */
266 sizeof(GschemOptions
),
268 (GInstanceInitFunc
) instance_init
,
271 type
= g_type_register_static (G_TYPE_OBJECT
, "GschemOptions", &info
, 0);
279 /*! \brief Create a new gschem options
281 * \returns A new set of options
284 gschem_options_new (GschemToplevel
*w_current
)
286 return g_object_new (GSCHEM_TYPE_OPTIONS
,
287 "gschem-toplevel", w_current
,
292 /*! \brief Scale the snap size down
294 * \param [in] options These options
297 gschem_options_scale_snap_down (GschemOptions
*options
)
299 g_return_if_fail (options
!= NULL
);
301 if ((options
->snap_size
% 2) == 0) {
302 gschem_options_set_snap_size (options
, options
->snap_size
/ 2);
308 /*! \brief Scale the snap size up
310 * \param [in] options These options
313 gschem_options_scale_snap_up (GschemOptions
*options
)
315 g_return_if_fail (options
!= NULL
);
317 gschem_options_set_snap_size (options
, options
->snap_size
* 2);
322 /*! \brief Set the grid mode
324 * If the grid mode is invalid the default grid mode is set.
326 * \param [in] options These options
327 * \param [in] grid_mode The grid mode
330 gschem_options_set_grid_mode (GschemOptions
*options
, GRID_MODE grid_mode
)
332 g_return_if_fail (options
!= NULL
);
338 options
->grid_mode
= grid_mode
;
341 options
->grid_mode
= default_grid_mode
;
345 gschem_action_set_active (action_options_grid_none
,
346 options
->grid_mode
== GRID_MODE_NONE
,
348 gschem_action_set_active (action_options_grid_dots
,
349 options
->grid_mode
== GRID_MODE_DOTS
,
351 gschem_action_set_active (action_options_grid_mesh
,
352 options
->grid_mode
== GRID_MODE_MESH
,
355 g_object_notify (G_OBJECT (options
), "grid-mode");
360 /*! \brief Set whether to show origin
362 * \param [in] options These options
363 * \param [in] show_origin Whether to show the origin
366 gschem_options_set_show_origin (GschemOptions
*options
, gboolean show_origin
)
368 g_return_if_fail (options
!= NULL
);
370 options
->show_origin
= show_origin
;
372 gschem_action_set_active (action_view_show_origin
,
373 options
->show_origin
,
376 g_object_notify (G_OBJECT (options
), "show-origin");
381 /*! \brief Set the magnetic net mode
383 * \param [in] options These options
384 * \param [in] enabled Magnetic net mode
387 gschem_options_set_magnetic_net_mode (GschemOptions
*options
, gboolean enabled
)
389 g_return_if_fail (options
!= NULL
);
391 options
->magnetic_net_mode
= enabled
;
393 gschem_action_set_active (action_options_magneticnet
,
394 options
->magnetic_net_mode
,
397 g_object_notify (G_OBJECT (options
), "magnetic-net-mode");
402 /*! \brief Set the net rubber band mode
404 * Sets whether nets rubberband as you move them (or connecting comps)
406 * \param [in] options These options
407 * \param [in] enabled Net rubber band mode
410 gschem_options_set_net_rubber_band_mode (GschemOptions
*options
, gboolean enabled
)
412 g_return_if_fail (options
!= NULL
);
414 options
->net_rubber_band_mode
= enabled
;
416 gschem_action_set_active (action_options_rubberband
,
417 options
->net_rubber_band_mode
,
420 g_object_notify (G_OBJECT (options
), "net-rubber-band-mode");
425 /*! \brief Set the snap mode
427 * \param [in] options These options
428 * \param [in] snap_mode The snap mode
431 gschem_options_set_snap_mode (GschemOptions
*options
, SNAP_STATE snap_mode
)
433 g_return_if_fail (options
!= NULL
);
435 options
->snap_mode
= snap_mode
;
437 gschem_action_set_active (action_options_snap_off
,
438 options
->snap_mode
== SNAP_OFF
,
440 gschem_action_set_active (action_options_snap_grid
,
441 options
->snap_mode
== SNAP_GRID
,
443 gschem_action_set_active (action_options_snap_resnap
,
444 options
->snap_mode
== SNAP_RESNAP
,
447 g_object_notify (G_OBJECT (options
), "snap-mode");
452 /*! \brief Set the snap size
454 * If the snap size is outside the range of valid values, the value will be
455 * assigned to the closest limit.
457 * \param [in] options These options
458 * \param [in] snap_size The snap size
461 gschem_options_set_snap_size (GschemOptions
*options
, int snap_size
)
463 g_return_if_fail (options
!= NULL
);
465 if (snap_size
< MINIMUM_SNAP_SIZE
) {
466 snap_size
= MINIMUM_SNAP_SIZE
;
469 if (snap_size
> MAXIMUM_SNAP_SIZE
) {
470 snap_size
= MAXIMUM_SNAP_SIZE
;
473 options
->snap_size
= snap_size
;
475 g_object_notify (G_OBJECT (options
), "snap-size");
481 * \brief Initialize gschem options class
483 * \param [in] klass The class for the gschem options
486 class_init (GschemOptionsClass
*klass
)
488 G_OBJECT_CLASS (klass
)->get_property
= get_property
;
489 G_OBJECT_CLASS (klass
)->set_property
= set_property
;
491 g_object_class_install_property (G_OBJECT_CLASS (klass
),
492 PROP_GSCHEM_TOPLEVEL
,
493 g_param_spec_pointer ("gschem-toplevel",
496 G_PARAM_CONSTRUCT_ONLY
| G_PARAM_READWRITE
));
498 g_object_class_install_property (G_OBJECT_CLASS (klass
),
500 g_param_spec_int ("grid-mode",
504 (GRID_MODE_COUNT
- 1),
506 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT
));
508 g_object_class_install_property (G_OBJECT_CLASS (klass
),
510 g_param_spec_boolean ("show-origin",
514 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT
));
516 g_object_class_install_property (G_OBJECT_CLASS (klass
),
517 PROP_MAGNETIC_NET_MODE
,
518 g_param_spec_boolean ("magnetic-net-mode",
521 DEFAULT_MAGNETIC_NET_MODE
,
522 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT
));
524 g_object_class_install_property (G_OBJECT_CLASS (klass
),
525 PROP_NET_RUBBER_BAND_MODE
,
526 g_param_spec_boolean ("net-rubber-band-mode",
527 "Net Rubber Band Mode",
528 "Net Rubber Band Mode",
529 DEFAULT_NET_RUBBER_BAND_MODE
,
530 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT
));
532 g_object_class_install_property (G_OBJECT_CLASS (klass
),
534 g_param_spec_int ("snap-mode",
538 SNAP_STATE_COUNT
- 1,
540 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT
));
542 g_object_class_install_property (G_OBJECT_CLASS (klass
),
544 g_param_spec_int ("snap-size",
550 G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT
));
556 * \brief Get a property
559 * \param [in] param_id
560 * \param [in,out] value
564 get_property (GObject
*object
, guint param_id
, GValue
*value
, GParamSpec
*pspec
)
566 GschemOptions
*options
= GSCHEM_OPTIONS (object
);
569 case PROP_GSCHEM_TOPLEVEL
:
570 g_value_set_pointer (value
, options
->w_current
);
574 g_value_set_int (value
, gschem_options_get_grid_mode (options
));
577 case PROP_SHOW_ORIGIN
:
578 g_value_set_boolean (value
, gschem_options_get_show_origin (options
));
581 case PROP_MAGNETIC_NET_MODE
:
582 g_value_set_boolean (value
, gschem_options_get_magnetic_net_mode (options
));
585 case PROP_NET_RUBBER_BAND_MODE
:
586 g_value_set_boolean (value
, gschem_options_get_net_rubber_band_mode (options
));
590 g_value_set_int (value
, gschem_options_get_snap_mode (options
));
594 g_value_set_int (value
, gschem_options_get_snap_size (options
));
598 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);
604 /*! \brief Initialize GschemOptions instance
606 * \param [in,out] selection
609 instance_init (GschemOptions
*options
)
615 /*! \brief Set a property
617 * \param [in,out] object
618 * \param [in] param_id
623 set_property (GObject
*object
, guint param_id
, const GValue
*value
, GParamSpec
*pspec
)
625 GschemOptions
*options
= GSCHEM_OPTIONS (object
);
628 case PROP_GSCHEM_TOPLEVEL
:
629 options
->w_current
= GSCHEM_TOPLEVEL (g_value_get_pointer (value
));
633 gschem_options_set_grid_mode (options
, g_value_get_int (value
));
636 case PROP_SHOW_ORIGIN
:
637 gschem_options_set_show_origin (options
, g_value_get_boolean (value
));
640 case PROP_MAGNETIC_NET_MODE
:
641 gschem_options_set_magnetic_net_mode (options
, g_value_get_boolean (value
));
644 case PROP_NET_RUBBER_BAND_MODE
:
645 gschem_options_set_net_rubber_band_mode (options
, g_value_get_boolean (value
));
649 gschem_options_set_snap_mode (options
, g_value_get_int (value
));
653 gschem_options_set_snap_size (options
, g_value_get_int (value
));
657 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, pspec
);