1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
5 *
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.
10 *
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.
15 *
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
19 */
20
21 /*! \file o_embed.c
22 * \brief functions to embed and unembed symbols
23 */
24
25 #include <config.h>
26
27 #include <stdio.h>
28
29 #include "libgeda_priv.h"
30
31 #ifdef HAVE_LIBDMALLOC
32 #include <dmalloc.h>
33 #endif
34
35
36 /*! \brief embed an object into a schematic
37 * \par Function Description
38 * This functions embeds an object \a o_current into a
39 * libgeda. Currently complex objects are just marked to
40 * be embedded later. Picture objects are embedded immediatly.
41 *
42 * \param toplevel The TOPLEVEL object
43 * \param o_current The OBJECT to embed
44 */
o_embed(TOPLEVEL * toplevel,OBJECT * o_current)45 void o_embed(TOPLEVEL *toplevel, OBJECT *o_current)
46 {
47 PAGE *page = o_get_page_compat (toplevel, o_current);
48 int page_modified = 0;
49
50 /* check o_current is a complex and is not already embedded */
51 if (o_current->type == OBJ_COMPLEX &&
52 !o_complex_is_embedded (o_current))
53 {
54
55 /* set the embedded flag */
56 o_current->complex_embedded = TRUE;
57
58 s_log_message (_("Component [%s] has been embedded\n"),
59 o_current->complex_basename);
60 page_modified = 1;
61 }
62
63 /* If it's a picture and it's not embedded */
64 if ( (o_current->type == OBJ_PICTURE) &&
65 !o_picture_is_embedded (toplevel, o_current) ) {
66 o_picture_embed (toplevel, o_current);
67
68 page_modified = 1;
69 }
70
71 if (page_modified && page != NULL) {
72 /* page content has been modified */
73 page->CHANGED = 1;
74 }
75 }
76
77 /*! \brief unembed an object from a schematic
78 * \par Function Description
79 * This functions unembeds an object \a o_current from a
80 * libgeda structure. Complex objects are just marked to
81 * be not embedded. Picture objects are unembeded immediatly.
82 *
83 * \param toplevel The TOPLEVEL object
84 * \param o_current The OBJECT to unembed
85 */
o_unembed(TOPLEVEL * toplevel,OBJECT * o_current)86 void o_unembed(TOPLEVEL *toplevel, OBJECT *o_current)
87 {
88 const CLibSymbol *sym;
89 PAGE *page = o_get_page_compat (toplevel, o_current);
90 int page_modified = 0;
91
92 /* check o_current is an embedded complex */
93 if (o_current->type == OBJ_COMPLEX &&
94 o_complex_is_embedded (o_current))
95 {
96
97 /* search for the symbol in the library */
98 sym = s_clib_get_symbol_by_name (o_current->complex_basename);
99
100 if (sym == NULL) {
101 /* symbol not found in the symbol library: signal an error */
102 s_log_message (_("Could not find component [%s], while trying to "
103 "unembed. Component is still embedded\n"),
104 o_current->complex_basename);
105
106 } else {
107 /* clear the embedded flag */
108 o_current->complex_embedded = FALSE;
109
110 s_log_message (_("Component [%s] has been successfully unembedded\n"),
111 o_current->complex_basename);
112
113 page_modified = 1;
114 }
115 }
116
117 /* If it's a picture and it's embedded */
118 if ( (o_current->type == OBJ_PICTURE) &&
119 o_picture_is_embedded (toplevel, o_current)) {
120 o_picture_unembed (toplevel, o_current);
121
122 page_modified = 1;
123 }
124
125 if (page_modified && page != NULL) {
126 page->CHANGED = 1;
127 }
128 }
129