1 /* like a heapmodel, but we represent a class in the heap 2 */ 3 4 /* 5 6 Copyright (C) 1991-2003 The National Gallery 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License along 19 with this program; if not, write to the Free Software Foundation, Inc., 20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ 23 24 /* 25 26 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk 27 28 */ 29 30 /* Member types we automate. 31 */ 32 typedef enum { 33 CLASSMODEL_MEMBER_INT, 34 CLASSMODEL_MEMBER_ENUM, /* Like int, but extent has max value */ 35 CLASSMODEL_MEMBER_BOOLEAN, 36 CLASSMODEL_MEMBER_DOUBLE, 37 CLASSMODEL_MEMBER_STRING, 38 CLASSMODEL_MEMBER_STRING_LIST, 39 CLASSMODEL_MEMBER_REALVEC_FIXED,/* Eg. Colour's triplet */ 40 CLASSMODEL_MEMBER_MATRIX, 41 CLASSMODEL_MEMBER_OPTIONS, 42 CLASSMODEL_MEMBER_IMAGE 43 } ClassmodelMemberType; 44 45 /* A matrix value. 46 */ 47 typedef struct _MatrixValue { 48 double *coeff; /* Base coeffs */ 49 int width; /* Size of matrix */ 50 int height; 51 } MatrixValue; 52 53 /* An image value. 54 */ 55 typedef struct { 56 Imageinfo *ii; 57 58 /* Can get "changed" for reload if the file changes behind our backs. 59 * Recalc the classmodel if this happens. 60 */ 61 guint file_changed_sid; 62 Classmodel *classmodel; 63 } ImageValue; 64 65 /* A member needing automation. 66 */ 67 typedef struct { 68 ClassmodelMemberType type; 69 void *details; /* eg. the set of allowed options */ 70 int extent; /* Vector length, enum max, etc. */ 71 72 const char *member_name; /* Name as known in nip class defs */ 73 const char *save_name; /* As known in save files */ 74 const char *user_name; /* i18n'd name for dialogs */ 75 76 guint offset; /* Struct offset */ 77 } ClassmodelMember; 78 79 #define TYPE_CLASSMODEL (classmodel_get_type()) 80 #define CLASSMODEL( obj ) \ 81 (G_TYPE_CHECK_INSTANCE_CAST( (obj), TYPE_CLASSMODEL, Classmodel )) 82 #define CLASSMODEL_CLASS( klass ) \ 83 (G_TYPE_CHECK_CLASS_CAST( (klass), TYPE_CLASSMODEL, ClassmodelClass)) 84 #define IS_CLASSMODEL( obj ) \ 85 (G_TYPE_CHECK_INSTANCE_TYPE( (obj), TYPE_CLASSMODEL )) 86 #define IS_CLASSMODEL_CLASS( klass ) \ 87 (G_TYPE_CHECK_CLASS_TYPE( (klass), TYPE_CLASSMODEL )) 88 #define CLASSMODEL_GET_CLASS( obj ) \ 89 (G_TYPE_INSTANCE_GET_CLASS( (obj), TYPE_CLASSMODEL, ClassmodelClass )) 90 91 struct _Classmodel { 92 Heapmodel parent_class; 93 94 /* Set if we have graphic mods applied which should be saved. 95 */ 96 gboolean edited; 97 98 /* xtras for Region/Arrow/etc. 99 */ 100 GSList *iimages; /* All the iimage we are defined on */ 101 GSList *views; /* All the regionview we have made */ 102 103 /* For things which have been loaded or saved from files (eg. image 104 * and matrix). Used to set the filename for the "save" dialog. 105 */ 106 char *filename; 107 }; 108 109 typedef struct _ClassmodelClass { 110 HeapmodelClass parent_class; 111 112 /* Get a pointer to the class instance vars ... just used by 113 * iarrow/iregion for code sharing. 114 */ 115 void *(*get_instance)( Classmodel * ); 116 117 /* Read from heap into model, and create new heap class from model. 118 */ 119 gboolean (*class_get)( Classmodel *, PElement *root ); 120 gboolean (*class_new)( Classmodel *, PElement *fn, PElement *out ); 121 122 /* Save and replace graphic displays ... eg. image/matrix. 123 */ 124 gboolean (*graphic_save)( Classmodel *, GtkWidget *, const char * ); 125 gboolean (*graphic_replace)( Classmodel *, GtkWidget *, const char * ); 126 127 FileselFileType **filetype; 128 const char *filetype_pref; 129 130 ClassmodelMember *members; 131 int n_members; 132 void (*reset)( Classmodel * ); 133 } ClassmodelClass; 134 135 void image_value_init( ImageValue *image, Classmodel *classmodel ); 136 void image_value_destroy( ImageValue *image ); 137 void image_value_set( ImageValue *image, Imageinfo *ii ); 138 void image_value_caption( ImageValue *value, VipsBuf *buf ); 139 140 void *classmodel_get_instance( Classmodel *classmodel ); 141 void classmodel_graphic_save( Classmodel *classmodel, GtkWidget *parent ); 142 void classmodel_graphic_replace( Classmodel *classmodel, GtkWidget *parent ); 143 144 void *classmodel_iimage_unlink( Classmodel *classmodel, iImage *iimage ); 145 void classmodel_iimage_update( Classmodel *classmodel, Imageinfo *ii ); 146 147 gboolean classmodel_update_members( Classmodel *classmodel, PElement *root ); 148 149 GType classmodel_get_type( void ); 150 151 void classmodel_update( Classmodel *classmodel ); 152 void classmodel_set_edited( Classmodel *classmodel, gboolean edited ); 153 154 Classmodel *classmodel_new_classmodel( GType type, Rhs *rhs ); 155