00001 #include <gtk/gtk.h>
00002 #include <string.h>
00003 #include "vapiTypes.h"
00004 #include "vapi.h"
00005 #include "vapiAux.h"
00006 #include "vapiGtkInterface.h"
00007 #include "vapiGtkAux.h"
00008 #include "vapiOperationList.h"
00009 #include "vapiGtkMemory.h"
00010 #include "vapiGtkAuxWindow.h"
00011 #include "vapiGtkCalibrateCamera.h"
00012 #include "vapiCameraCalibrate.h"
00013
00014 static GtkWidget * ErrorDialog;
00015 static GtkWidget * lblErrorMessage;
00016
00017 void
00018 vapiGtkErrorDialogInit(GladeXML * xml)
00019 {
00020 ErrorDialog = glade_xml_get_widget(xml, "ErrorDialog");
00021 lblErrorMessage = glade_xml_get_widget(xml, "lblErrorMessage");
00022 }
00023
00024 void
00025 vapiGtkErrorDialogSetMessage(const char * Message)
00026 {
00027 gtk_label_set_text((GtkLabel *) lblErrorMessage, Message);
00028 gtk_widget_show_all(ErrorDialog);
00029 }
00030 void
00031 vapiGtkDestroyParentWindow (GtkWidget * Widget, GtkWidget * ParentWindow)
00032 {
00033 gtk_widget_destroy (ParentWindow);
00034
00035 }
00036
00037 void
00038 vapiMessage (vImages * Images, vOptions * options,
00039 vMacroResult * PreviousResult)
00040 {
00041 char *texto;
00042 texto = vapiResultPrintf (options->chars[1].ch,
00043 PreviousResult);
00044 v_debug ("tal: %s\n", texto);
00045 vapiInfoMessage (options->chars[0].ch, texto);
00046 free (texto);
00047 }
00048
00049 void
00050 vapiGtkMessageWindow (const char *windowTitle, const char *infoText)
00051 {
00052 GtkWidget *InfoWindow;
00053 GtkWidget *dialog_vbox2;
00054 GtkWidget *vbox1;
00055 GtkWidget *lblInfoTitle;
00056 GtkWidget *hseparator1;
00057 GtkWidget *lblInfoText;
00058 GtkWidget *dialog_action_area2;
00059 GtkWidget *btClose;
00060 gchar *windowTitle_Changed;
00061
00062
00063
00064
00065 if (strlen (windowTitle) == 0 || strlen (infoText) == 0)
00066 {
00067 return;
00068 }
00069
00070
00071
00072
00073 windowTitle_Changed = g_strdup_printf ("INFO: %s", windowTitle);
00074 InfoWindow = gtk_dialog_new ();
00075 gtk_widget_set_size_request (InfoWindow, 300, -1);
00076 gtk_window_set_title (GTK_WINDOW (InfoWindow), windowTitle_Changed);
00077
00078 gtk_window_set_resizable (GTK_WINDOW (InfoWindow), FALSE);
00079 gtk_window_set_type_hint (GTK_WINDOW (InfoWindow),
00080 GDK_WINDOW_TYPE_HINT_DIALOG);
00081
00082 dialog_vbox2 = GTK_DIALOG (InfoWindow)->vbox;
00083 gtk_widget_show (dialog_vbox2);
00084
00085 vbox1 = gtk_vbox_new (FALSE, 0);
00086
00087 gtk_widget_show (vbox1);
00088
00089 gtk_box_pack_start (GTK_BOX (dialog_vbox2), vbox1, FALSE, FALSE, 0);
00090
00091 lblInfoTitle = gtk_label_new (windowTitle_Changed);
00092 gtk_widget_show (lblInfoTitle);
00093 gtk_box_pack_start (GTK_BOX (vbox1), lblInfoTitle, FALSE, FALSE, 0);
00094 gtk_widget_set_size_request (lblInfoTitle, -1, 50);
00095 gtk_label_set_use_markup (GTK_LABEL (lblInfoTitle), TRUE);
00096
00097 hseparator1 = gtk_hseparator_new ();
00098 gtk_widget_show (hseparator1);
00099 gtk_box_pack_start (GTK_BOX (vbox1), hseparator1, FALSE, FALSE, 0);
00100
00101
00102 lblInfoText = gtk_label_new (infoText);
00103
00104 gtk_widget_show (lblInfoText);
00105 gtk_box_pack_start (GTK_BOX (vbox1), lblInfoText, FALSE, FALSE, 0);
00106 gtk_widget_set_size_request (lblInfoText, -1, 100);
00107
00108 dialog_action_area2 = GTK_DIALOG (InfoWindow)->action_area;
00109 gtk_widget_show (dialog_action_area2);
00110 gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area2),
00111 GTK_BUTTONBOX_END);
00112
00113 btClose = gtk_button_new_with_mnemonic ("Fechar");
00114 gtk_widget_show (btClose);
00115 gtk_dialog_add_action_widget (GTK_DIALOG (InfoWindow), btClose, 0);
00116
00117 g_signal_connect (G_OBJECT (btClose), "clicked",
00118 G_CALLBACK (vapiGtkDestroyParentWindow),
00119 InfoWindow);
00120
00121 gtk_widget_show_all (InfoWindow);
00122 }
00123
00124 void
00125 vapiGtkWindowOnFocusCalibrateCamera (GtkWidget * widget,
00126 vapiCalibrateCamera * calibrateCamera)
00127 {
00128 vapiGtkPutImage (calibrateCamera->ImCalibrateOriginal,
00129 calibrateCamera->Images->Original);
00130
00131
00132 }
00133
00134 void
00135 vapiGtkWindowCalibrateCameraInitEvents (GladeXML * xml)
00136 {
00137
00138 vapiCalibrateCameraExpandersA *vapiCalibrateCameraExA =
00139 malloc (sizeof (vapiCalibrateCameraExpandersA));
00140 vapiCalibrateCameraExpandersB *vapiCalibrateCameraExB =
00141 malloc (sizeof (vapiCalibrateCameraExpandersB));
00142
00143
00144 vapiCalibrateCameraExA->exCalibrateAColour =
00145 glade_xml_get_widget (xml, "exCalibrateAColour");
00146 vapiCalibrateCameraExA->exCalibrateADistance =
00147 glade_xml_get_widget (xml, "exCalibrateADistance");
00148 vapiCalibrateCameraExA->exCalibrateAFilters =
00149 glade_xml_get_widget (xml, "exCalibrateAFilters");
00150 vapiCalibrateCameraExB->exCalibrateBColour =
00151 glade_xml_get_widget (xml, "exCalibrateBColour");
00152 vapiCalibrateCameraExB->exCalibrateBDistance =
00153 glade_xml_get_widget (xml, "exCalibrateBDistance");
00154 vapiCalibrateCameraExB->exCalibrateBFilters =
00155 glade_xml_get_widget (xml, "exCalibrateBFilters");
00156
00157
00158 g_signal_connect (G_OBJECT
00159 (vapiCalibrateCameraExA->exCalibrateAColour),
00160 "activate", G_CALLBACK (vapiGtkExpandersA),
00161 vapiCalibrateCameraExA);
00162 g_signal_connect (G_OBJECT
00163 (vapiCalibrateCameraExA->exCalibrateADistance),
00164 "activate", G_CALLBACK (vapiGtkExpandersA),
00165 vapiCalibrateCameraExA);
00166 g_signal_connect (G_OBJECT
00167 (vapiCalibrateCameraExA->exCalibrateAFilters),
00168 "activate", G_CALLBACK (vapiGtkExpandersA),
00169 vapiCalibrateCameraExA);
00170 g_signal_connect (G_OBJECT
00171 (vapiCalibrateCameraExB->exCalibrateBColour),
00172 "activate", G_CALLBACK (vapiGtkExpandersB),
00173 vapiCalibrateCameraExB);
00174 g_signal_connect (G_OBJECT
00175 (vapiCalibrateCameraExB->exCalibrateBDistance),
00176 "activate", G_CALLBACK (vapiGtkExpandersB),
00177 vapiCalibrateCameraExB);
00178 g_signal_connect (G_OBJECT
00179 (vapiCalibrateCameraExB->exCalibrateBFilters),
00180 "activate", G_CALLBACK (vapiGtkExpandersB),
00181 vapiCalibrateCameraExB);
00182
00183 }
00184
00185 void
00186 vapiGtkWindowCalibrateCameraDefines (GladeXML * xml)
00187 {
00188 GtkWidget *HueMinA, *HueMaxA;
00189 GtkWidget *SatMinA, *SatMaxA;
00190 GtkWidget *ValueMinA, *ValueMaxA;
00191 GtkWidget *ErodeTimesA, *DilateTimesA;
00192 GtkWidget *HueMinB, *HueMaxB;
00193 GtkWidget *SatMinB, *SatMaxB;
00194 GtkWidget *ValueMinB, *ValueMaxB;
00195 GtkWidget *ErodeTimesB, *DilateTimesB;
00196 GtkWidget *spinDistanceRealA, *spinDistanceRealB;
00197 HueMinA = glade_xml_get_widget (xml, "scCalibrateAHueMin");
00198 HueMaxA = glade_xml_get_widget (xml, "scCalibrateAHueMax");
00199 SatMinA = glade_xml_get_widget (xml, "scCalibrateASaturationMin");
00200 SatMaxA = glade_xml_get_widget (xml, "scCalibrateASaturationMax");
00201 ValueMinA = glade_xml_get_widget (xml, "scCalibrateAValueMin");
00202 ValueMaxA = glade_xml_get_widget (xml, "scCalibrateAValueMax");
00203 ErodeTimesA = glade_xml_get_widget (xml, "spinCalibrateATimesErode");
00204 DilateTimesA =
00205 glade_xml_get_widget (xml, "spinCalibrateATimesDilate");
00206
00207 HueMinB = glade_xml_get_widget (xml, "scCalibrateBHueMin");
00208 HueMaxB = glade_xml_get_widget (xml, "scCalibrateBHueMax");
00209 SatMinB = glade_xml_get_widget (xml, "scCalibrateBSaturationMin");
00210 SatMaxB = glade_xml_get_widget (xml, "scCalibrateBSaturationMax");
00211 ValueMinB = glade_xml_get_widget (xml, "scCalibrateBValueMin");
00212 ValueMaxB = glade_xml_get_widget (xml, "scCalibrateBValueMax");
00213 ErodeTimesB = glade_xml_get_widget (xml, "spinCalibrateBTimesErode");
00214 DilateTimesB =
00215 glade_xml_get_widget (xml, "spinCalibrateBTimesDilate");
00216 spinDistanceRealA = glade_xml_get_widget (xml, "spinDistanceRealA");
00217 spinDistanceRealB = glade_xml_get_widget (xml, "spinDistanceRealB");
00218
00219 gtk_range_set_increments ((GtkRange *) HueMinA, 0.01, 0.1);
00220 gtk_range_set_range ((GtkRange *) HueMinA, 0, 1);
00221 gtk_range_set_value ((GtkRange *) HueMinA, 0);
00222 gtk_scale_set_digits ((GtkScale *) HueMinA, 2);
00223
00224 gtk_range_set_increments ((GtkRange *) HueMaxA, 0.01, 0.1);
00225 gtk_range_set_range ((GtkRange *) HueMaxA, 0, 1);
00226 gtk_range_set_value ((GtkRange *) HueMaxA, 1);
00227 gtk_scale_set_digits ((GtkScale *) HueMaxA, 2);
00228
00229 gtk_range_set_increments ((GtkRange *) SatMinA, 0.01, 0.1);
00230 gtk_range_set_range ((GtkRange *) SatMinA, 0, 1);
00231 gtk_range_set_value ((GtkRange *) SatMinA, 0);
00232 gtk_scale_set_digits ((GtkScale *) SatMinA, 2);
00233
00234 gtk_range_set_increments ((GtkRange *) SatMaxA, 0.01, 0.1);
00235 gtk_range_set_range ((GtkRange *) SatMaxA, 0, 1);
00236 gtk_range_set_value ((GtkRange *) SatMaxA, 1);
00237 gtk_scale_set_digits ((GtkScale *) SatMaxA, 2);
00238
00239
00240 gtk_range_set_increments ((GtkRange *) ValueMinA, 0.01, 0.1);
00241 gtk_range_set_range ((GtkRange *) ValueMinA, 0, 1);
00242 gtk_range_set_value ((GtkRange *) ValueMinA, 0);
00243 gtk_scale_set_digits ((GtkScale *) ValueMinA, 2);
00244
00245 gtk_range_set_increments ((GtkRange *) ValueMaxA, 0.01, 0.1);
00246 gtk_range_set_range ((GtkRange *) ValueMaxA, 0, 1);
00247 gtk_range_set_value ((GtkRange *) ValueMaxA, 1);
00248 gtk_scale_set_digits ((GtkScale *) ValueMaxA, 2);
00249
00250 gtk_spin_button_set_increments ((GtkSpinButton *) ErodeTimesA, 1, 2);
00251 gtk_spin_button_set_range ((GtkSpinButton *) ErodeTimesA, 0, 100);
00252 gtk_spin_button_set_increments ((GtkSpinButton *) DilateTimesA, 1, 2);
00253 gtk_spin_button_set_range ((GtkSpinButton *) DilateTimesA, 0, 100);
00254
00255 gtk_range_set_increments ((GtkRange *) HueMinB, 0.01, 0.1);
00256 gtk_range_set_range ((GtkRange *) HueMinB, 0, 1);
00257 gtk_range_set_value ((GtkRange *) HueMinB, 0);
00258 gtk_scale_set_digits ((GtkScale *) HueMinB, 2);
00259 gtk_range_set_increments ((GtkRange *) HueMaxB, 0.01, 0.1);
00260 gtk_range_set_range ((GtkRange *) HueMaxB, 0, 1);
00261 gtk_range_set_value ((GtkRange *) HueMaxB, 1);
00262 gtk_scale_set_digits ((GtkScale *) HueMaxB, 2);
00263
00264 gtk_range_set_increments ((GtkRange *) SatMinB, 0.01, 0.1);
00265 gtk_range_set_range ((GtkRange *) SatMinB, 0, 1);
00266 gtk_range_set_value ((GtkRange *) SatMinB, 0);
00267 gtk_scale_set_digits ((GtkScale *) SatMinB, 2);
00268
00269 gtk_range_set_increments ((GtkRange *) SatMaxB, 0.01, 0.1);
00270 gtk_range_set_range ((GtkRange *) SatMaxB, 0, 1);
00271 gtk_range_set_value ((GtkRange *) SatMaxB, 1);
00272 gtk_scale_set_digits ((GtkScale *) SatMaxB, 2);
00273
00274 gtk_range_set_increments ((GtkRange *) ValueMinB, 0.01, 0.1);
00275 gtk_range_set_range ((GtkRange *) ValueMinB, 0, 1);
00276 gtk_range_set_value ((GtkRange *) ValueMinB, 0);
00277 gtk_scale_set_digits ((GtkScale *) ValueMinB, 2);
00278 gtk_range_set_increments ((GtkRange *) ValueMaxB, 0.01, 0.1);
00279 gtk_range_set_range ((GtkRange *) ValueMaxB, 0, 1);
00280 gtk_range_set_value ((GtkRange *) ValueMaxB, 1);
00281 gtk_scale_set_digits ((GtkScale *) ValueMaxB, 2);
00282
00283 gtk_spin_button_set_increments ((GtkSpinButton *) ErodeTimesB, 1, 2);
00284 gtk_spin_button_set_range ((GtkSpinButton *) ErodeTimesB, 0, 100);
00285 gtk_spin_button_set_increments ((GtkSpinButton *) DilateTimesB, 1, 2);
00286 gtk_spin_button_set_range ((GtkSpinButton *) DilateTimesB, 0, 100);
00287
00288
00289 gtk_spin_button_set_increments ((GtkSpinButton *) spinDistanceRealA,
00290 0.5, 10);
00291 gtk_spin_button_set_range ((GtkSpinButton *) spinDistanceRealA, 0,
00292 1000);
00293 gtk_spin_button_set_digits ((GtkSpinButton *) spinDistanceRealA, 2);
00294
00295 gtk_spin_button_set_increments ((GtkSpinButton *) spinDistanceRealB,
00296 0.5, 10);
00297 gtk_spin_button_set_range ((GtkSpinButton *) spinDistanceRealB, 0,
00298 1000);
00299 gtk_spin_button_set_digits ((GtkSpinButton *) spinDistanceRealB, 2);
00300
00301
00302 }
00303
00304 void
00305 vapiGtkWindowCalibrateCameraGetImages (vapiCalibrateCameraCalculate *
00306 CalibrateCameraCalculate,
00307 vBoolean CalculateConstant)
00308 {
00309 vapi3Options *OptionsA, *OptionsB;
00310 vapiCalibrateCameraReturn *Result;
00311 GtkWidget *imResultA, *imResultB;
00312 GtkWidget *spinDistanceRealA, *spinDistanceRealB;
00313 GtkWidget *lblResultConstant;
00314 double distanceRealA, distanceRealB;
00315 distanceRealA = 0;
00316 distanceRealB = 0;
00317
00318
00319
00320
00321 OptionsA =
00322 vapiCalibrateCameraGetColourAOptions
00323 (CalibrateCameraCalculate->OperationList,
00324 CalibrateCameraCalculate->xml);
00325
00326 OptionsB =
00327 vapiCalibrateCameraGetColourBOptions
00328 (CalibrateCameraCalculate->OperationList,
00329 CalibrateCameraCalculate->xml);
00330
00331
00332
00333 imResultA =
00334 glade_xml_get_widget (CalibrateCameraCalculate->xml,
00335 "imCalibrateResultA");
00336 imResultB =
00337 glade_xml_get_widget (CalibrateCameraCalculate->xml,
00338 "imCalibrateResultB");
00339 spinDistanceRealA =
00340 glade_xml_get_widget (CalibrateCameraCalculate->xml,
00341 "spinDistanceRealA");
00342 spinDistanceRealB =
00343 glade_xml_get_widget (CalibrateCameraCalculate->xml,
00344 "spinDistanceRealB");
00345 lblResultConstant =
00346 glade_xml_get_widget (CalibrateCameraCalculate->xml,
00347 "lblResultConstant");
00348 distanceRealA =
00349 gtk_spin_button_get_value ((GtkSpinButton *)
00350 spinDistanceRealA);
00351 distanceRealB =
00352 gtk_spin_button_get_value ((GtkSpinButton *)
00353 spinDistanceRealB);
00354 Result = vapiCalibrateCameraGetConstant (CalibrateCameraCalculate->
00355 OperationList,
00356 CalibrateCameraCalculate->
00357 Images, OptionsA, OptionsB,
00358 distanceRealA, distanceRealB,
00359 CalculateConstant);
00360
00361
00362 vapiGtkPutImage (imResultA, Result->imResultA);
00363 vapiGtkPutImage (imResultB, Result->imResultB);
00364 gtk_label_set_markup ((GtkLabel *) lblResultConstant,
00365 g_strdup_printf
00366 ("<b>Valor da Constante Calculada: %1.2f</b>",
00367 Result->constant));
00368
00369 CalibrateCameraCalculate->CameraSettings->
00370 CalibrationConstant = Result->constant;
00371
00372 vCalibrateCamerReturnFree (Result);
00373 v3OptionsFree (OptionsA);
00374 v3OptionsFree (OptionsB);
00375 }