Added debugging code for dumping data from memory using GUI.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Tue, 14 Jan 2014 23:10:13 +0000 (00:10 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Tue, 14 Jan 2014 23:10:13 +0000 (00:10 +0100)
data/gui.glade
src/gedcom/familia_gedcom.c
src/math/positions.c
src/math/positions.h
src/storage/individual.c
src/storage/storage.c
src/storage/storage.h

index 0cd0c5474ba4a615b708ba4cd5c4231f542f5f70..1c512edfa509ec0a3d5843bcb513030f233e0116 100644 (file)
       <accelerator key="q" modifiers="GDK_CONTROL_MASK"/>
     </child>
   </object>
+  <object class="GtkImage" id="image1">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-missing-image</property>
+    <property name="icon-size">1</property>
+  </object>
+  <object class="GtkImage" id="image2">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="stock">gtk-missing-image</property>
+  </object>
   <object class="GtkWindow" id="logger-window">
     <property name="can_focus">False</property>
     <property name="window_position">center</property>
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkMenuItem" id="debug">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="right_justified">True</property>
+                <property name="label" translatable="yes">Debug</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu4">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="storage-dump">
+                        <property name="label" translatable="yes">imagemenuitem</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="image">image2</property>
+                        <property name="use_stock">False</property>
+                        <signal name="activate" handler="familia_storage_dump_all" swapped="no"/>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="stack-dump">
+                        <property name="label" translatable="yes">imagemenuitem</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="image">image1</property>
+                        <property name="use_stock">False</property>
+                        <signal name="activate" handler="familia_memory_stack_dump" swapped="no"/>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
index 740d6b2a82c5d353b3637bc80eef8660bebabf2a..dcb80328a5cfc883de9192ce3818e4da4720f234 100644 (file)
@@ -167,6 +167,29 @@ Gedcom_ctxt familia_gedcom_individual_add_family(Gedcom_elt  elt,
 
        return parent;
 }
+
+/**
+ * Adds child to the family
+ */
+Gedcom_ctxt familia_gedcom_family_add_child(Gedcom_elt  elt,
+                                       Gedcom_ctxt parent,
+                                       int         level,
+                                       char*       tag,
+                                       char*       raw_value,
+                                       int         parsed_tag,
+                                       Gedcom_val  parsed_value)
+{
+       void * object = NULL;
+       /* XREF_PTR(FAM) */
+       struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
+
+       object = familia_memory_stack_find(xr->string, FS_FAMILY);
+       /* parent: REC_INDI */
+       familia_family_add_child(object, parent);
+
+       return parent;
+}
+
 /*
 void familia_gedcom_individual_family_end(Gedcom_elt  elt,
                                        Gedcom_ctxt parent,
@@ -208,7 +231,10 @@ void familia_gedcom_init()
                                familia_gedcom_individual_last_name_start,
                                NULL);
        gedcom_subscribe_to_element(ELT_SUB_FAMS,
-                               familia_gedcom_individual_add_family,
+                               familia_gedcom_family_add_child,
+                               NULL);
+       gedcom_subscribe_to_element(ELT_SUB_FAMC,
+                               familia_gedcom_family_add_child,
                                NULL);
 
        familia_memory_stack_init();
index 4fd47bfd5d5f5bcfbd781b78e38a60b03f81dd12..dfd8fc0252a3a768e5ff821f3cc0e19c2553613c 100644 (file)
@@ -1,25 +1,3 @@
-/****************************************************************************
- *  Familia Lignum - Genealogical program                                   *
- *  Copyright (C) 2011-2012 Rafał Długołęcki <rafal@dlugolecki.net.pl>      *
- *                                                                          *
- *  This program is free software; you can redistribute it and/or modify    *
- *  it under the terms of the GNU General Public License as published by    *
- *  the Free Software Foundation; version 2 of the License.                 *
- *                                                                          *
- *  This program is distributed in the hope that it will be useful,         *
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
- *  GNU General Public License for more details.                            *
- *                                                                          *
- *  You should have received a copy of the GNU General Public License along *
- *  with this program; if not, write to the Free Software Foundation, Inc., *
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             *
- *                                                                          *
- ****************************************************************************/
-
-#ifndef _FAMILIA_MATH_POSITIONS_H
-#define _FAMILIA_MATH_POSITIONS_H
-
 #include <stdlib.h>
 
 #include "positions.h"
@@ -37,5 +15,3 @@ struct position * familia_position_calculate_family_position(struct familia_fami
 /*     TODO: Implement this function*/
        return NULL;
 }
-
-#endif /* _FAMILIA_MATH_3D_H */
index 6db7f3d40d2f9d2c63f94c66f57b5a2dd07d629b..058cfc599aa4ad943766b1f80ed7eb8ec8c8d013 100644 (file)
@@ -39,4 +39,4 @@ struct position * familia_position_calculate_individual_position(struct familia_
  */
 struct position * familia_position_calculate_family_position(struct familia_family * family);
 
-#endif /* _FAMILIA_MATH_3D_H */
+#endif /* _FAMILIA_MATH_POSITIONS_H */
index 5e55bb61a42889fabbd7a64e6f95e30cbb0592e3..856796d1f9d7767914e7dbd86e44dd04d2d9de78 100644 (file)
@@ -74,6 +74,10 @@ void familia_individual_set_first_name(struct familia_individual * individual, c
 
 char * familia_individual_get_first_name(struct familia_individual * individual)
 {
+       if (!individual) {
+               return NULL;
+       }
+
        return individual->first_name;
 }
 
index 272e6af264ce7ca41d34393a1f4b9ac6cc79e005..8b00a716308ffc9eceae0c1d8f1b88b785b904de 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include <stdlib.h>
 
 #include "storage.h"
@@ -198,3 +199,63 @@ void familia_storage_remove_family_by_id(struct familia_storage * storage, unsig
        }
 }
 
+void familia_storage_dump_all()
+{
+       int i;
+       struct familia_storage * storage = NULL;
+       struct familia_family * family = NULL;
+       struct familia_individual * individual = NULL;
+       
+       storage = familia_storage_get_current();
+       
+       for (i = 0; i < storage->individuals_no; i++) {
+               individual = storage->individuals[i];
+               printf("Individual (%d)\n", individual->id);
+               printf("\t First name: %s\n", individual->first_name);
+               printf("\t Last name: %s\n", individual->last_name);
+               if (individual->families_no > 0) {
+                       int j;
+                       struct familia_family * f = NULL;
+                       struct familia_individual * i1 = NULL;
+                       struct familia_individual * i2 = NULL;
+
+                       printf("\t Families:\n");
+                       for (j = 0; j < individual->families_no; j++) {
+                               f = individual->families[j];
+                               i1 = familia_family_get_individual(f, Individual1);
+                               i2 = familia_family_get_individual(f, Individual2);
+                               
+                               printf("\t > %s&%s\n", familia_individual_get_first_name(i1), familia_individual_get_first_name(i2));
+                       }
+                       printf("\t Parents:\n");
+                       f = familia_individual_get_parents(individual);
+                       i1 = familia_family_get_individual(f, Individual1);
+                       i2 = familia_family_get_individual(f, Individual2);
+                       
+                       printf("\t > %s&%s\n", familia_individual_get_first_name(i1), familia_individual_get_first_name(i2));
+               }
+       }
+
+
+       for (i = 0; i < storage->families_no; i++) {
+               int j;
+               struct familia_individual * i1 = NULL;
+               struct familia_individual * i2 = NULL;
+
+               family = storage->families[i];
+
+               printf("Family (%d)\n", family->id);
+               i1 = familia_family_get_individual(family, Individual1);
+               i2 = familia_family_get_individual(family, Individual2);
+               printf("\t First parent: %s\n", familia_individual_get_first_name(i1));
+               printf("\t Second parent: %s\n", familia_individual_get_first_name(i2));
+
+               printf("\t Children:\n");
+               if (family->children_no > 0) {
+                       for (j = 0; j < family->children_no; j++) {
+                               i1 = family->children[j];
+                               printf("\t > %s\n", familia_individual_get_first_name(i1));
+                       }
+               }
+       }
+}
index 49991fa946fd1740daddf607693f3a49cff413eb..880039952366e0cffe8691cd2797af8457bff3cf 100644 (file)
@@ -129,4 +129,6 @@ struct familia_family * familia_storage_get_family_by_id(struct familia_storage
  */
 void familia_storage_remove_family_by_id(struct familia_storage * storage, unsigned int id);
 
+void familia_storage_dump_all();
+
 #endif /*_FAMILIA_STORAGE_H */