libgeda

o_embed.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * libgeda - gEDA's library
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00025 #include <config.h>
00026 
00027 #include <stdio.h>
00028 
00029 #include "libgeda_priv.h"
00030 
00031 #ifdef HAVE_LIBDMALLOC
00032 #include <dmalloc.h>
00033 #endif
00034 
00035 
00045 void o_embed(TOPLEVEL *toplevel, OBJECT *o_current)
00046 {
00047   PAGE *page = o_get_page_compat (toplevel, o_current);
00048   int page_modified = 0;
00049 
00050   /* check o_current is a complex and is not already embedded */
00051   if (o_current->type == OBJ_COMPLEX &&
00052       !o_complex_is_embedded (o_current))
00053   {
00054 
00055     /* set the embedded flag */
00056     o_current->complex_embedded = TRUE;
00057 
00058     s_log_message (_("Component [%s] has been embedded\n"),
00059                    o_current->complex_basename);
00060     page_modified = 1;
00061   }
00062 
00063   /* If it's a picture and it's not embedded */
00064   if ( (o_current->type == OBJ_PICTURE) &&
00065        !o_picture_is_embedded (toplevel, o_current) ) {
00066     o_picture_embed (toplevel, o_current);
00067 
00068     page_modified = 1;
00069   }
00070 
00071   if (page_modified && page != NULL) {
00072     /* page content has been modified */
00073     page->CHANGED = 1;
00074   }
00075 }
00076 
00086 void o_unembed(TOPLEVEL *toplevel, OBJECT *o_current)
00087 {
00088   const CLibSymbol *sym;
00089   PAGE *page = o_get_page_compat (toplevel, o_current);
00090   int page_modified = 0;
00091   
00092   /* check o_current is an embedded complex */
00093   if (o_current->type == OBJ_COMPLEX &&
00094       o_complex_is_embedded (o_current))
00095   {
00096         
00097     /* search for the symbol in the library */
00098     sym = s_clib_get_symbol_by_name (o_current->complex_basename);
00099 
00100     if (sym == NULL) {
00101       /* symbol not found in the symbol library: signal an error */
00102       s_log_message (_("Could not find component [%s], while trying to "
00103                        "unembed. Component is still embedded\n"),
00104                      o_current->complex_basename);
00105       
00106     } else {
00107       /* clear the embedded flag */
00108       o_current->complex_embedded = FALSE;
00109 
00110       s_log_message (_("Component [%s] has been successfully unembedded\n"),
00111                      o_current->complex_basename);
00112       
00113       page_modified = 1;
00114     }
00115   }
00116 
00117   /* If it's a picture and it's embedded */
00118   if ( (o_current->type == OBJ_PICTURE) &&
00119        o_picture_is_embedded (toplevel, o_current)) {
00120     o_picture_unembed (toplevel, o_current);
00121 
00122     page_modified = 1;
00123   }
00124 
00125   if (page_modified && page != NULL) {
00126     page->CHANGED = 1;
00127   }
00128 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines