src/interface/vapiGtkEvents.c

Ir para a documentação deste ficheiro.
00001 #include <gtk/gtk.h>
00002 #include "vapiOperationsDefault.h"
00003 #include "vapiAux.h"
00004 #include "vapiImagesAux.h"
00005 #include "vapiGtkAuxWindow.h"
00006 #include <string.h>
00007 #include "vapi.h"
00008 #include "vapiCameraAcquisition.h"
00009 #include "vapiMacro.h"
00010 #include "vapiGtkInterface.h"
00011 #include "vapiGtkAux.h"
00012 #include "vapiGtkMemory.h"
00013 #include "vapiMacroXML.h"
00014 #include "vapiGtkOptions.h"
00015 #include "vapiCameraCalibrate.h"
00016 #include "vapiGtkCalibrateCamera.h"
00017 #include "vapiCameraAcquisition.h"
00018 
00019 
00020 
00021 
00022 /*
00023  * Guardar a Imagem
00024  */
00025 
00026 void
00027 vapiGtkSaveImage (GtkWidget * widget, vImages * Images)
00028 {
00029         cvSaveImage ("save.jpg", Images->Actual);
00030 
00031 }
00032 
00033 void
00034 vapiRefreshImageThread (GtkWidget * widget, vRefreshImage * RefreshImage)
00035 {
00036         GError *Error;
00037         if (gtk_toggle_tool_button_get_active
00038             (GTK_TOGGLE_TOOL_BUTTON (RefreshImage->Temp->Widgets->cbCam)))
00039         {
00040                 if (vapiCameraSettingsGetType
00041                     (RefreshImage->Temp->CameraSettings) == vCameraLocalFile)
00042                 {
00043                         gtk_toggle_tool_button_set_active
00044                                 (GTK_TOGGLE_TOOL_BUTTON
00045                                  (RefreshImage->Temp->Widgets->cbCam), FALSE);
00046                         return;
00047                 }
00048                 RefreshImage->STOP = 0;
00049                 RefreshImage->CameraFeed =
00050                         g_thread_create ((GThreadFunc) vapiRefreshImage,
00051                                          RefreshImage, FALSE, &Error);
00052         }
00053 
00054 }
00055 
00056 void
00057 vapiGtkCbLoadStaticImage (GtkWidget * widget, vapiTemp1Struct * temp)
00058 {
00059         vImagesFreeImages (temp->Images);
00060 
00061         vapiGetSnapshot (temp->Images, temp->CameraSettings);
00062         vapiOriginal2Actual (temp->Images);
00063         vapiGtkPutImage (temp->Widgets->imOriginal, temp->Images->Original);
00064         vapiGtkPutImage (temp->Widgets->imActual, temp->Images->Actual);
00065         vapiGtkPutImage (temp->Widgets->imWork, temp->Images->Actual);
00066 }
00067 
00068 void
00069 vapiGtkGetOriginal (GtkWidget * widget, vapiTemp1Struct * temp)
00070 {
00071         vImagesFreeActual (temp->Images);
00072         vapiOriginal2Actual (temp->Images);
00073         vapiGtkPutImage (temp->Widgets->imActual, temp->Images->Actual);
00074         vapiGtkPutImage (temp->Widgets->imWork, temp->Images->Actual);
00075 
00076 }
00077 
00078 void
00079 vapiGtkToolbarStyle (GtkWidget * widget, GtkWidget * toolbar)
00080 {
00081 
00082         if (gtk_check_menu_item_get_active ((GtkCheckMenuItem *) widget))
00083         {
00084 
00085                 gtk_toolbar_set_style ((GtkToolbar *) toolbar,
00086                                        GTK_TOOLBAR_BOTH);
00087 
00088         }
00089         else
00090         {
00091                 gtk_toolbar_set_style ((GtkToolbar *) toolbar,
00092                                        GTK_TOOLBAR_ICONS);
00093 
00094         }
00095 }
00096 
00097 void
00098 vapiGtkSaveWorkImage (GtkWidget * widget, vapiTemp1Struct * temp)
00099 {
00100         if (temp->imWork == NULL)
00101         {
00102                 return;
00103         }
00104         vImagesFreeActual (temp->Images);
00105         temp->Images->Actual = temp->imWork;
00106 
00107         temp->imWork = NULL;
00108         vapiGtkPutImage (temp->Widgets->imWork, temp->Images->Actual);
00109 }
00110 
00111 void
00112 vapiGtkSelectROIActual (GtkWidget * widget,
00113                         GdkEventFocus * event, vapiTemp1Struct * temp)
00114 {
00115         vEffect *Operation;
00116         vEffectSettings *OperationSettings;
00117 
00118         Operation =
00119                 vapiGetOperationFromTxtOperation (temp->Widgets->txtOperation,
00120                                                   temp->OperationList);
00121         if (Operation == NULL)
00122         {
00123                 goto NoNeed;
00124                 return;
00125         }
00126         OperationSettings = Operation->OptionsSettings->CustomOptionsSettings;
00127         if (OperationSettings->NeedOfAuxImage == NoNeed)
00128         {
00129               NoNeed:
00130                 gtk_widget_show_all (temp->Widgets->ImageWindow);
00131                 vapiGtkPutImageNotScaled (temp->Widgets->imShowOriginalSize,
00132                                           temp->Images->Actual);
00133                 gtk_window_position ((GtkWindow *) temp->Widgets->
00134                                      ImageWindow, GTK_WIN_POS_CENTER_ALWAYS);
00135                 if (Operation == NULL)
00136                 {
00137                         return;
00138                 }
00139 
00140         }
00141         if (OperationSettings->NeedOfAuxImage == NeedRegion)
00142         {
00143                 temp->GetCoordinates->Vertice[0].x = -1;
00144                 temp->GetCoordinates->Vertice[0].y = -1;
00145                 temp->GetCoordinates->Vertice[1].x = -1;
00146                 temp->GetCoordinates->Vertice[1].y = -1;
00147                 temp->GetCoordinates->Vertice[2].x = -1;
00148                 temp->GetCoordinates->Vertice[2].y = -1;
00149                 temp->GetCoordinates->Vertice[3].x = -1;
00150                 temp->GetCoordinates->Vertice[3].y = -1;
00151 
00152                 gtk_widget_show_all (temp->Widgets->ImageWindowSelectRegion);
00153                 vapiGtkPutImageNotScaled (temp->Widgets->imSelectRegion,
00154                                           temp->Images->Actual);
00155                 gtk_window_position ((GtkWindow *) temp->Widgets->
00156                                      ImageWindowTemplate,
00157                                      GTK_WIN_POS_CENTER_ALWAYS);
00158                 return;
00159 
00160         }
00161         if (OperationSettings->NeedOfAuxImage == NeedTemplate)
00162         {
00163                 temp->GetCoordinates->Vertice[0].x = -1;
00164                 temp->GetCoordinates->Vertice[0].y = -1;
00165                 temp->GetCoordinates->Vertice[1].x = -1;
00166                 temp->GetCoordinates->Vertice[1].y = -1;
00167                 gtk_statusbar_push ((GtkStatusbar *) temp->GetCoordinates->
00168                                     stTemplateWindow, 0, " ");
00169 
00170                 gtk_widget_show_all (temp->Widgets->ImageWindowTemplate);
00171                 vapiGtkPutImageNotScaled (temp->Widgets->imSelectTemplate,
00172                                           temp->Images->Actual);
00173                 gtk_window_position ((GtkWindow *) temp->Widgets->
00174                                      ImageWindowTemplate,
00175                                      GTK_WIN_POS_CENTER_ALWAYS);
00176                 return;
00177         }
00178 }
00179 
00180 void
00181 vapiGtkGrabMouseLocation (GtkWidget * widget,
00182                           GdkDragContext * drag_context,
00183                           vapiGtkGetCoordinates * GetCoordinates)
00184 {
00185         gtk_widget_get_pointer (widget,
00186                                 &GetCoordinates->Vertice[0].x,
00187                                 &GetCoordinates->Vertice[0].y);
00188         v_debug ("Coordendas do rato, %d %d",
00189                  GetCoordinates->Vertice[0].x, GetCoordinates->Vertice[0].y);
00190         gtk_statusbar_push ((GtkStatusbar *) GetCoordinates->
00191                             stTemplateWindow, 0,
00192                             g_strdup_printf
00193                             ("Vertice[0]: (%d,%d)",
00194                              GetCoordinates->
00195                              Vertice[0].x, GetCoordinates->Vertice[0].y));
00196 }
00197 
00198 gboolean
00199 vapiGtkTemplateDrag (GtkWidget * widget,
00200                      GdkEventMotion * event,
00201                      vapiGtkGetCoordinates * GetCoordinates)
00202 {
00203         vImages *tempImages;
00204         GdkModifierType mask;
00205         gdk_window_get_pointer (gtk_widget_get_parent_window (widget),
00206                                 &GetCoordinates->Vertice[1].x,
00207                                 &GetCoordinates->Vertice[1].y, &mask);
00208         if (mask != GDK_BUTTON1_MASK)
00209         {
00210                 return FALSE;
00211         }
00212 
00213         tempImages =
00214                 vapiGtkAuxActual2Work ((vImages *) GetCoordinates->Images);
00215 
00216         gtk_statusbar_push ((GtkStatusbar *) GetCoordinates->
00217                             stTemplateWindow, 1,
00218                             g_strdup_printf
00219                             ("Vertice[0]: (%d,%d), Vertice[1]: (%d,%d)",
00220                              GetCoordinates->Vertice[0].x,
00221                              GetCoordinates->Vertice[0].y,
00222                              GetCoordinates->Vertice[1].x,
00223                              GetCoordinates->Vertice[1].y));
00224         v_debug ("Coordendas do rato, %d %d",
00225                  GetCoordinates->Vertice[1].x, GetCoordinates->Vertice[1].y);
00226         cvRectangle (tempImages->Actual,
00227                      cvPoint (GetCoordinates->Vertice[0].x,
00228                               GetCoordinates->Vertice[0].y),
00229                      cvPoint (GetCoordinates->Vertice[1].x,
00230                               GetCoordinates->Vertice[1].y),
00231                      CV_RGB (255, 0, 0), 1, 8, 0);
00232         v_debug ("passou o rectangulo");
00233         vapiGtkPutImage ((GtkWidget *) GetCoordinates->
00234                          imSelectTemplate, tempImages->Actual);
00235 
00236         vImagesFreeActual (tempImages);
00237         free (tempImages);
00238 
00239         return FALSE;
00240 
00241 }
00242 
00243 void
00244 vapiGtkSaveTemplate (GtkWidget * widget, vapiTemp1Struct * temp)
00245 {
00246         int x, y, width, height;
00247         IplImage *template;
00248         vEffect *Operation;
00249         vEffectSettings *OperationSettings;
00250         GtkWidget *txtFilename;
00251 
00252         if (temp->GetCoordinates->Vertice[0].x < 0 ||
00253             temp->GetCoordinates->Vertice[0].y < 0 ||
00254             temp->GetCoordinates->Vertice[1].x < 0 ||
00255             temp->GetCoordinates->Vertice[1].y < 0)
00256         {
00257                 return;
00258         }
00259         Operation =
00260                 vapiGetOperationFromTxtOperation (temp->Widgets->txtOperation,
00261                                                   temp->OperationList);
00262         if (Operation == NULL)
00263         {
00264                 return;
00265         }
00266 
00267         OperationSettings = Operation->OptionsSettings->CustomOptionsSettings;
00268         if (OperationSettings->NeedOfAuxImage != NeedTemplate)
00269         {
00270                 return;
00271         }
00272 
00273         txtFilename =
00274                 vapiGtkOptionsGetAssociatedWidget ("c0",
00275                                                    Operation->OptionsSettings,
00276                                                    &temp->Widgets->
00277                                                    OptionsData);
00278         /*
00279          * Por agora não foi definido uma variável que guardasse o caminho do 
00280          *  ficheiro porque aind não foi bem determinado como proceder com strings.
00281          */
00282         if (temp->GetCoordinates->Vertice[0].x <
00283             temp->GetCoordinates->Vertice[1].x)
00284         {
00285                 x = temp->GetCoordinates->Vertice[0].x;
00286                 width = temp->GetCoordinates->Vertice[1].x -
00287                         temp->GetCoordinates->Vertice[0].x;
00288         }
00289         else
00290         {
00291                 x = temp->GetCoordinates->Vertice[1].x;
00292                 width = temp->GetCoordinates->Vertice[0].x -
00293                         temp->GetCoordinates->Vertice[1].x;
00294         }
00295         if (temp->GetCoordinates->Vertice[0].y <
00296             temp->GetCoordinates->Vertice[1].y)
00297         {
00298                 y = temp->GetCoordinates->Vertice[0].y;
00299                 height = temp->GetCoordinates->Vertice[1].y -
00300                         temp->GetCoordinates->Vertice[0].y;
00301         }
00302         else
00303         {
00304                 y = temp->GetCoordinates->Vertice[1].y;
00305                 height = temp->GetCoordinates->Vertice[0].y -
00306                         temp->GetCoordinates->Vertice[1].y;
00307         }
00308 
00309         cvSetImageROI (temp->Images->Actual, cvRect (x, y, width, height));
00310         template =
00311                 cvCreateImage (cvSize (width, height), IPL_DEPTH_8U,
00312                                temp->Images->Actual->nChannels);
00313         cvCopy (temp->Images->Actual, template, NULL);
00314         cvSaveImage (g_strdup_printf
00315                      ("%s.jpg",
00316                       gtk_entry_get_text ((GtkEntry *) temp->GetCoordinates->
00317                                           txtTemplateFilename)), template);
00318         cvReleaseImage (&template);
00319         cvResetImageROI (temp->Images->Actual);
00320 
00321 
00322 
00323         gtk_entry_set_text ((GtkEntry *) txtFilename, g_strdup_printf
00324                             ("%s.jpg",
00325                              gtk_entry_get_text ((GtkEntry *) temp->
00326                                                  GetCoordinates->
00327                                                  txtTemplateFilename)));
00328         /*
00329          * Reset a todas as coordenadas
00330          */
00331         temp->GetCoordinates->Vertice[0].x = -1;
00332         temp->GetCoordinates->Vertice[0].y = -1;
00333         temp->GetCoordinates->Vertice[1].x = -1;
00334         temp->GetCoordinates->Vertice[1].y = -1;
00335         gtk_widget_hide (temp->Widgets->ImageWindowTemplate);
00336 
00337 }
00338 
00339 void
00340 vapiGtkSelectRegion (GtkWidget * widget,
00341                      GdkEventButton * event,
00342                      vapiGtkGetCoordinates * GetCoordinates)
00343 {
00344 
00345 
00346         int i, j, lineThickness = 1;
00347         char *statusBarText;
00348         vImages *tempImages;
00349         tempImages =
00350                 vapiGtkAuxActual2Work ((vImages *) GetCoordinates->Images);
00351 
00352         statusBarText = g_strdup_printf (" ");
00353         v_debug ("Select Region\n");
00354         if (event->button == 3)
00355         {
00356                 for (i = 0; i < 3; i++)
00357                 {
00358                         if (GetCoordinates->Vertice[i].x > 0
00359                             && GetCoordinates->Vertice[i + 1].x < 0)
00360                         {
00361                                 GetCoordinates->Vertice[i].x = -1;
00362                                 GetCoordinates->Vertice[i].y = -1;
00363                                 --i;
00364                                 break;
00365 
00366                         }
00367 
00368                         if (i > 0 && GetCoordinates->Vertice[i].x > 0)
00369                         {
00370                                 cvLine (tempImages->Actual,
00371                                         GetCoordinates->Vertice[i - 1],
00372                                         GetCoordinates->Vertice[i],
00373                                         CV_RGB (255, 0, 0), lineThickness, 8,
00374                                         0);
00375 
00376                         }
00377                         if (i == 2 && GetCoordinates->Vertice[i + 1].x > 0)
00378                         {
00379                                 GetCoordinates->Vertice[i + 1].x = -1;
00380                                 GetCoordinates->Vertice[i + 1].y = -1;
00381                                 break;
00382                         }
00383                 }
00384                 for (j = 0; j <= i; j++)
00385                 {
00386                         statusBarText = g_strdup_printf
00387                                 ("%s Vertice%d: (%d,%d)",
00388                                  statusBarText, j,
00389                                  GetCoordinates->Vertice[j].x,
00390                                  GetCoordinates->Vertice[j].y);
00391                 }
00392                 gtk_statusbar_push ((GtkStatusbar *) GetCoordinates->
00393                                     stSelectRegion, 0, statusBarText);
00394                 goto putImage;
00395         }
00396 
00397         if (GetCoordinates->Vertice[3].x > 0)
00398         {
00399                 GetCoordinates->Vertice[0].x = -1;
00400                 GetCoordinates->Vertice[0].y = -1;
00401                 GetCoordinates->Vertice[1].x = -1;
00402                 GetCoordinates->Vertice[1].y = -1;
00403                 GetCoordinates->Vertice[2].x = -1;
00404                 GetCoordinates->Vertice[2].y = -1;
00405                 GetCoordinates->Vertice[3].x = -1;
00406                 GetCoordinates->Vertice[3].y = -1;
00407         }
00408 
00409         for (i = 0; i < 4; i++)
00410         {
00411                 if (GetCoordinates->Vertice[i].x > 0)
00412                 {
00413                         if (i > 0)
00414                         {
00415                                 cvLine (tempImages->Actual,
00416                                         GetCoordinates->Vertice[i - 1],
00417                                         GetCoordinates->Vertice[i],
00418                                         CV_RGB (255, 0, 0), lineThickness, 8,
00419                                         0);
00420                         }
00421                         continue;
00422                 }
00423                 else
00424                 {
00425                         gtk_widget_get_pointer (widget,
00426                                                 &GetCoordinates->Vertice[i].x,
00427                                                 &GetCoordinates->Vertice[i].
00428                                                 y);
00429                         for (j = 0; j <= i; j++)
00430                         {
00431                                 statusBarText = g_strdup_printf
00432                                         ("%s Vertice%d: (%d,%d)",
00433                                          statusBarText, j,
00434                                          GetCoordinates->Vertice[j].x,
00435                                          GetCoordinates->Vertice[j].y);
00436                         }
00437                         gtk_statusbar_push ((GtkStatusbar *) GetCoordinates->
00438                                             stSelectRegion, 0, statusBarText);
00439                         if (i > 0)
00440                         {
00441                                 cvLine (tempImages->Actual,
00442                                         GetCoordinates->Vertice[i - 1],
00443                                         GetCoordinates->Vertice[i],
00444                                         CV_RGB (255, 0, 0), lineThickness, 8,
00445                                         0);
00446                         }
00447                         if (i == 3)
00448                         {
00449                                 cvLine (tempImages->Actual,
00450                                         GetCoordinates->Vertice[i],
00451                                         GetCoordinates->Vertice[0],
00452                                         CV_RGB (255, 0, 0), lineThickness, 8,
00453                                         0);
00454                         }
00455                         break;
00456                 }
00457 
00458 
00459         }
00460 
00461       putImage:
00462         vapiGtkPutImageNotScaled ((GtkWidget *) GetCoordinates->
00463                                   imSelectRegion, tempImages->Actual);
00464         vImagesFreeActual (tempImages);
00465         free (tempImages);
00466 
00467 }
00468 
00469 void
00470 vapiGtkSaveSelectedRegion (GtkWidget * widget, vapiTemp1Struct * temp)
00471 {
00472         GtkWidget *Coordinate;
00473         int i;
00474         vEffect *Operation;
00475         if (temp->GetCoordinates->Vertice[0].x < 0 ||
00476             temp->GetCoordinates->Vertice[0].y < 0 ||
00477             temp->GetCoordinates->Vertice[1].x < 0 ||
00478             temp->GetCoordinates->Vertice[1].y < 0 ||
00479             temp->GetCoordinates->Vertice[2].x < 0 ||
00480             temp->GetCoordinates->Vertice[2].y < 0 ||
00481             temp->GetCoordinates->Vertice[3].x < 0 ||
00482             temp->GetCoordinates->Vertice[3].y < 0)
00483         {
00484                 return;
00485         }
00486         Operation =
00487                 vapiGetOperationFromTxtOperation (temp->Widgets->txtOperation,
00488                                                   temp->OperationList);
00489 
00490         if (Operation == NULL)
00491         {
00492                 return;
00493         }
00494         vapiGtkOptionsBlockEvents (&temp->Widgets->OptionsEvents);
00495         for (i = 0; i < 4; i++)
00496         {
00497 
00498                 Coordinate =
00499                         vapiGtkOptionsGetAssociatedWidget
00500                         (g_strdup_printf ("d%d", i * 2),
00501                          Operation->OptionsSettings,
00502                          &temp->Widgets->OptionsData);
00503                 gtk_spin_button_set_value ((GtkSpinButton *) Coordinate,
00504                                            temp->GetCoordinates->Vertice[i].
00505                                            x);
00506                 Coordinate =
00507                         vapiGtkOptionsGetAssociatedWidget (g_strdup_printf
00508                                                            ("d%d", i * 2 + 1),
00509                                                            Operation->
00510                                                            OptionsSettings,
00511                                                            &temp->Widgets->
00512                                                            OptionsData);
00513                 gtk_spin_button_set_value ((GtkSpinButton *) Coordinate,
00514                                            temp->GetCoordinates->Vertice[i].
00515                                            y);
00516 
00517         }
00518         vapiGtkOptionsUnBlockEvents (&temp->Widgets->OptionsEvents);
00519 
00520 
00521 }
00522 
00523 void
00524 vapiGtkExpandersA (GtkWidget * widget,
00525                    vapiCalibrateCameraExpandersA * expandersA)
00526 {
00527         if (widget != expandersA->exCalibrateAColour)
00528         {
00529                 gtk_expander_set_expanded ((GtkExpander *) expandersA->
00530                                            exCalibrateAColour, FALSE);
00531 
00532         }
00533         if (widget != expandersA->exCalibrateAFilters)
00534         {
00535                 gtk_expander_set_expanded ((GtkExpander *) expandersA->
00536                                            exCalibrateAFilters, FALSE);
00537 
00538         }
00539         if (widget != expandersA->exCalibrateADistance)
00540         {
00541                 gtk_expander_set_expanded ((GtkExpander *) expandersA->
00542                                            exCalibrateADistance, FALSE);
00543 
00544         }
00545 
00546 }
00547 void
00548 vapiGtkExpandersB (GtkWidget * widget,
00549                    vapiCalibrateCameraExpandersB * expandersB)
00550 {
00551         if (widget != expandersB->exCalibrateBColour)
00552         {
00553                 gtk_expander_set_expanded ((GtkExpander *) expandersB->
00554                                            exCalibrateBColour, FALSE);
00555 
00556         }
00557         if (widget != expandersB->exCalibrateBFilters)
00558         {
00559                 gtk_expander_set_expanded ((GtkExpander *) expandersB->
00560                                            exCalibrateBFilters, FALSE);
00561 
00562         }
00563         if (widget != expandersB->exCalibrateBDistance)
00564         {
00565                 gtk_expander_set_expanded ((GtkExpander *) expandersB->
00566                                            exCalibrateBDistance, FALSE);
00567 
00568         }
00569 
00570 }
00571 
00572 void
00573 vapiGtkEventCalibrateCamera (GtkWidget * widget,
00574                              vapiCalibrateCameraCalculate *
00575                              CalibrateCameraCalculate)
00576 {
00577 
00578         vapiGtkWindowCalibrateCameraGetImages (CalibrateCameraCalculate,
00579                                                vTRUE);
00580 }
00581 
00582 void
00583 vapiGtkEventCalibrateCameraTestColourDefinitions (GtkWidget * widget,
00584                                                   vapiCalibrateCameraCalculate
00585                                                   * CalibrateCameraCalculate)
00586 {
00587 
00588         vapiGtkWindowCalibrateCameraGetImages (CalibrateCameraCalculate,
00589                                                vFALSE);
00590 }
00591 
00592 void
00593 showWidget (GtkWidget * widget1, GtkWidget * widget2)
00594 {
00595         gtk_widget_show_all (widget2);
00596 }

Gerado em Tue Jul 24 10:34:58 2007 para Vapi por  doxygen 1.5.1