00001 #include <gtk/gtk.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include "vapiOperationsDefault.h"
00005 #include "vapiString.h"
00006 #include "vapiAux.h"
00007 #include "vapiGroups.h"
00008 #include "vapiImagesAux.h"
00009 #include "vapiCameraAcquisition.h"
00010 #include "vapiOperationOptions.h"
00011 #include "vapiTypes.h"
00012 #include "vapiGtkInterface.h"
00013 #include "vapiGtkAux.h"
00014 #include "vapiCameraSettings.h"
00015 #include "vapiOperationList.h"
00016 #include "vapiGtkMemory.h"
00017 #include "vapiCameraAcquisition.h"
00018 #include "vapiGtkAuxWindow.h"
00019 #include "vapiGtkImages.h"
00020 #include "vapiGtkMacrosTables.h"
00021
00022 void
00023 vapiRefreshImage (vRefreshImage * RefreshImage)
00024 {
00025 vCameraSettings *CameraSettings = RefreshImage->Temp->CameraSettings;
00026 vImages *tempImages = vImagesInit ();
00027 tempImages->Original =
00028 vapiImagesCopy (RefreshImage->Temp->Images->Original);
00029 v_info ("iniciar a Câmara\n");
00030
00031 do
00032 {
00033 if (vapiCameraSettingsGetType (CameraSettings) ==
00034 vCameraLocalFile)
00035 {
00036 continue;
00037 }
00038 else
00039 {
00040 vImagesFreeOriginal (tempImages);
00041 if (!vapiGetSnapshot (tempImages, CameraSettings))
00042 {
00043
00044
00045
00046
00047
00048
00049 vapiGtkImagesFastUpdateInterface
00050 (tempImages->Original, gtkImOriginal);
00051
00052 }
00053
00054 g_usleep (10);
00055 }
00056 }
00057 while (RefreshImage->STOP == 0);
00058 if (vapiCameraSettingsGetType (CameraSettings) != vCameraLocalFile)
00059 {
00060 vapiOriginal2Actual (tempImages);
00061 vapiGtkImagesUpdateInterface (tempImages, gtkImActual);
00062 vapiGtkImagesUpdateInterface (tempImages, gtkImWork);
00063 vapiGtkImagesUpdateInterface (tempImages, gtkImOriginal);
00064 }
00065 free (tempImages);
00066 g_thread_exit (NULL);
00067 }
00068
00069 void
00070 vapiCamStop (GtkWidget * widget, vRefreshImage * RefreshImage)
00071 {
00072 if (!gtk_toggle_tool_button_get_active
00073 ((GtkToggleToolButton *) RefreshImage->Temp->Widgets->cbCam))
00074 {
00075 gtk_tool_button_set_label ((GtkToolButton *) RefreshImage->
00076 Temp->Widgets->cbCam,
00077 "Verificar Câmara");
00078 RefreshImage->STOP = 1;
00079 }
00080 else
00081 {
00082 gtk_tool_button_set_label ((GtkToolButton *) RefreshImage->
00083 Temp->Widgets->cbCam,
00084 "Aceitar Imagem");
00085 }
00086 }
00087
00088 int
00089 vapiCheckOperations (vEffect * Operation,
00090 vOptions * options, vMacroList * MacroList)
00091 {
00092 vMacroHeader *MacroHeader;
00093 vEffectSettings *OperationSettings =
00094 Operation->OptionsSettings->CustomOptionsSettings;
00095 vEffectOptions *OperationOptions = options->CustomOptions;
00096 int MacroNumber, i;
00097 if (!strcmp (Operation->name, "Executar Tarefa"))
00098 {
00099 if ((MacroNumber =
00100 vapiMacroListMacroExist (MacroList,
00101 options->chars[0].ch, 0)) >= 0
00102 && strcmp (options->chars[0].ch, ""))
00103 {
00104 MacroHeader =
00105 vapiMacroListSelectItem ((vMacroList
00106 *)
00107 MacroList,
00108 MacroNumber);
00109 v_debug ("nome da macro %s\n",
00110 MacroHeader->MacroName);
00111 OperationOptions->Macros = MacroHeader;
00112 }
00113 else
00114 {
00115 v_debug ("Não existe a Macro desejada %s",
00116 options->chars[0].ch);
00117 OperationOptions->Macros = NULL;
00118 return 1;
00119 }
00120 }
00121 if (Operation->OptionsSettings->charsNumber)
00122 {
00123 for (i = 0; i < Operation->OptionsSettings->charsNumber; i++)
00124 {
00125 if (strlen (options->chars[i].ch) == 0)
00126 {
00127 return 1;
00128 }
00129 }
00130
00131 }
00132 if (OperationSettings->NeedOfAuxImage == NeedTemplate)
00133 {
00134 vOptionsFreeTemplate (options);
00135 ((vEffectOptions *) options->CustomOptions)->Template =
00136 cvLoadImage (options->chars[0].ch, 3);
00137 }
00138
00139 return 0;
00140 }
00141
00142
00143 gint
00144 gtk_utils_get_selected_radio_index (GSList * radio_button_group)
00145 {
00146 int k;
00147 int length = g_slist_length (radio_button_group);
00148 for (k = 0; radio_button_group;
00149 k++, radio_button_group = radio_button_group->next)
00150 {
00151 gpointer *radio_button = radio_button_group->data;
00152 if (gtk_check_menu_item_get_active
00153 ((GtkCheckMenuItem *) radio_button))
00154 return (length - 1) - k;
00155 }
00156
00157 return -1;
00158 }
00159
00160 vImages *
00161 vapiGtkAuxActual2Work (vImages * Images)
00162 {
00163 vImages *tempImages = vImagesInit ();
00164 tempImages->Original = Images->Original;
00165 tempImages->Actual =
00166 vapiImagesSameSize (Images->Actual,
00167 Images->Actual->nChannels);
00168 cvCopy (Images->Actual, tempImages->Actual, NULL);
00169 return tempImages;
00170 }
00171
00172 GtkWidget *
00173 vapiAuxCreateIcon (const char *filename)
00174 {
00175 GtkWidget *icon;
00176 GtkIconSource *icon_source;
00177 GtkIconSet *icon_set;
00178 icon_set = gtk_icon_set_new ();
00179 icon_source = gtk_icon_source_new ();
00180 gtk_icon_source_set_filename (icon_source, filename);
00181 gtk_icon_set_add_source (icon_set, icon_source);
00182 icon = gtk_image_new_from_icon_set (icon_set,
00183 GTK_ICON_SIZE_LARGE_TOOLBAR);
00184 return icon;
00185 }
00186
00187 void
00188 vapiGtkAuxStepInProgressBar (const char *Message, double Step)
00189 {
00190
00191
00192 gtk_label_set_text ((GtkLabel *) LoadScreenMessage, Message);
00193 gtk_progress_bar_set_fraction ((GtkProgressBar *)
00194 LoadScreenProgress, Step);
00195
00196
00197
00198
00199
00200 if (!MainLoadDone)
00201 {
00202
00203 while (g_main_context_pending (NULL))
00204 {
00205 g_main_context_iteration (NULL, TRUE);
00206 }
00207 }
00208 else
00209 {
00210 v_error ("%f main load not done\n", Step);
00211 }
00212
00213
00214 }
00215
00216 vEffect *
00217 vapiGetOperationFromTxtOperation (GtkWidget * txtOperation, vOperationList * OperationList)
00218 {
00219 char *OperationName;
00220 vEffect *Operation;
00221 OperationName =
00222 (char *) gtk_entry_get_text ((GtkEntry *) txtOperation);
00223 Operation =
00224 vapiOperationListSelectOperation (OperationList,
00225 OperationName);
00226 return Operation;
00227 }
00228
00229 gboolean
00230 vapiRefreshOriginal (vRefreshImage * RefreshImage)
00231 {
00232 vapiGtkPutImage (RefreshImage->Temp->Widgets->
00233 imOriginal, RefreshImage->Temp->Images->Original);
00234 RefreshImage->gate = 0;
00235 return TRUE;
00236 }
00237
00238 void
00239 v_gtk_message (const char *Message)
00240 {
00241
00242
00243
00244
00245 printf (" ");
00246 }
00247
00248 void
00249 vapiGtkGroupButtons (vGroupList * GroupList,
00250 GList ** GroupButtonList,
00251 GtkWidget * vBoxGroups, GCallback callback,
00252 gpointer data)
00253 {
00254 int NumberOfGroups, i;
00255 GtkWidget *GroupToggleButton;
00256
00257 char *GroupName;
00258
00259
00260 NumberOfGroups = vapiGroupListCountElements (GroupList);
00261
00262 if (NumberOfGroups == 0)
00263 {
00264 return;
00265 }
00266
00267 for (i = 0; i < NumberOfGroups; i++)
00268 {
00269 GroupName = vapiGroupListSelectItem (GroupList, i);
00270
00271 GroupToggleButton =
00272 gtk_toggle_button_new_with_label (GroupName);
00273 g_signal_connect (G_OBJECT (GroupToggleButton), "toggled",
00274 callback, data);
00275 if (i == 0)
00276 {
00277 gtk_toggle_button_set_active ((GtkToggleButton *)
00278 GroupToggleButton,
00279 TRUE);
00280 }
00281 *GroupButtonList =
00282 g_list_append (*GroupButtonList, GroupToggleButton);
00283 gtk_box_pack_start ((GtkBox *) vBoxGroups,
00284 GroupToggleButton, FALSE, FALSE, 2);
00285
00286 }
00287 gtk_widget_show_all (vBoxGroups);
00288 }
00289
00290 int
00291 vapiGtkSelectGroupButton (GtkWidget * ActiveButton,
00292 vGroupList * GroupList, GList ** GroupButtonList)
00293 {
00294 char *GroupName;
00295 GtkWidget *GroupButton;
00296 int i, NumberOfGroups, selected = 0;
00297 if (!gtk_toggle_button_get_active ((GtkToggleButton *) ActiveButton))
00298 {
00299 return -1;
00300 }
00301
00302 GroupName =
00303 (char *) gtk_button_get_label ((GtkButton *) ActiveButton);
00304
00305 NumberOfGroups = g_list_length (*GroupButtonList);
00306
00307
00308 for (i = 0; i < NumberOfGroups; i++)
00309 {
00310 GroupButton = g_list_nth_data (*GroupButtonList, i);
00311 if (GroupButton != ActiveButton)
00312 {
00313
00314
00315 gtk_toggle_button_set_active ((GtkToggleButton *)
00316 GroupButton, FALSE);
00317 }
00318 else
00319 {
00320 selected = i;
00321 }
00322 }
00323 return selected;
00324 }
00325
00326 vBoolean
00327 vapiGtkAuxCheckOperation (vEffect * Operation)
00328 {
00329 if (Operation == NULL)
00330 {
00331 v_error_ui("Nenhuma Operação seleccionada.");
00332 return vTRUE;
00333 }
00334 return vFALSE;
00335 }