src/vapiMacro.c

Ir para a documentação deste ficheiro.
00001 
00008 #include <stdio.h>
00009 #include <string.h>
00010 #include "vapi.h"
00011 #include "vapiLists.h"
00012 #include "vapiMacro.h"
00013 #include "vapiMacroBypass.h"
00014 #include "vapiOperationsDefault.h"
00015 #include "vapiOperationOptions.h"
00016 #include "vapiTypes.h"
00017 #include "vapiAux.h"
00018 #include "vapiImagesAux.h"
00019 #include "vapiMemory.h"
00020 #include <highgui.h>
00021 #ifndef VAPI_WITHOUT_INTERFACE
00022 #include <gtk/gtk.h>
00023 #include "vapiGtkImages.h"
00024 #include "vapiGtkEventsMacros.h"
00025 #endif
00026 
00027 // temporario
00028 #include "vapiGtkAux.h"
00029 
00030 vMacroHeader *
00031 vapiMacroNew (const char *MacroName)
00032 {
00033         vMacroHeader *MacroHeader;
00034         vMacro *Macro = malloc (sizeof (vMacro));
00035         *Macro = NULL;
00036         MacroHeader = malloc (sizeof (vMacroHeader));
00037         MacroHeader->PreviousResult = vapiMacroResultInit ();
00038         MacroHeader->MacroName = vapiReturnStringPointer (MacroName);
00039         MacroHeader->Macro = Macro;
00040         MacroHeader->MacroComment = vapiReturnStringPointer ("");
00041 
00042         return MacroHeader;
00043 }
00044 
00045 void
00046 vapiMacroAddItem (vMacro * Macro, vEffect * Operation, vOptions * Options)
00047 {
00048         vMacroItem *MacroItem;
00049 
00050         MacroItem = malloc (sizeof (vMacroItem));
00051         MacroItem->Operation = Operation;
00052         MacroItem->Options = Options;
00053         v_list_append ((vList *) Macro, MacroItem);
00054 }
00055 
00056 int
00057 vapiMacroCountElements (vMacro * Macro)
00058 {
00059         return v_list_count_elements ((vList *) Macro);
00060 }
00061 
00062 void
00063 vapiMacroDeleteItem (vMacro * Macro, int Delete)
00064 {
00065         v_list_delete_item ((vList *) Macro,
00066                             (vFreeFunction *) & vMacroItemFree, Delete);
00067 }
00068 
00069 vMacroItem *
00070 vapiMacroSelectItem (vMacro * Macro, int Item)
00071 {
00072         return (v_list_get ((vList *) Macro, Item));
00073 }
00074 
00075 void
00076 vapiMacroAddItemPositioned (vMacro * Macro, vEffect * Operation,
00077                             vOptions * Options, int position)
00078 {
00079         vMacroItem *MacroItem;
00080 
00081         MacroItem = malloc (sizeof (vMacroItem));
00082         MacroItem->Operation = Operation;
00083         MacroItem->Options = Options;
00084 
00085         v_list_insert ((vList *) Macro, MacroItem, position);
00086 
00087         vapiMacroToText (Macro);
00088 }
00089 
00090 void
00091 vapiApplyMacro (vMacroHeader * MacroHeader, vImages * Images,
00092                 vBoolean ResetResult, vBoolean SaveSequence)
00093 {
00094         vMacroItem *Item;
00095         int i = 0, MacroSize;
00096         char *filename, *macroTag;
00097         MacroSize = vapiMacroCountElements (MacroHeader->Macro);
00098         if (MacroSize == 0)
00099         {
00100                 return;
00101         }
00102         /*
00103          * Fazer Reset aos Resultados Memorizados, se existirem.
00104          */
00105         if (ResetResult)
00106         {
00107                 vResultReset ((vMacroResult *) MacroHeader->PreviousResult);
00108         }
00109         macroTag = vapiResultCheckMacroTag (MacroHeader->PreviousResult);
00110         for (i = 0; i < MacroSize; i++)
00111         {
00112                 if (!vapiGtkMacroRunningTest ())
00113                 {
00114                         return;
00115                 }
00116                 if (!v_bypass_get (macroTag, i))
00117                 {
00118                         continue;
00119                 }
00120                 vapiResultSetCurrentMacroTag (MacroHeader->PreviousResult,
00121                                               macroTag, i);
00122                 if (MacroHeader->PreviousResult->End)
00123                 {
00124 
00125                         MacroHeader->PreviousResult->End = vFALSE;
00126                         return;
00127                 }
00128                 Item = vapiMacroSelectItem (MacroHeader->Macro, i);
00129                 vapiApplyOperation (Images, (vEffect *) Item->Operation,
00130                                     (vOptions *) Item->Options,
00131                                     MacroHeader->PreviousResult);
00132                 if (v_stopby_get (macroTag, i))
00133                 {
00134                         vapiGtkImagesFastUpdateInterface (Images->Actual,
00135                                                           gtkImActual);
00136                 }
00137                 if (SaveSequence)
00138                 {
00139                         filename = v_printf ("%s_Operation_%d.jpg",
00140                                              MacroHeader->MacroName, i);
00141                         cvSaveImage (filename, Images->Actual);
00142                         free (filename);
00143 
00144                 }
00145                 if (MacroHeader->PreviousResult->JumpTo != -1)
00146                 {
00147                         i = MacroHeader->PreviousResult->JumpTo - 1;
00148                         MacroHeader->PreviousResult->JumpTo = -1;
00149                         continue;
00150                 }
00151         }
00152         free (macroTag);
00153 }
00154 
00155 void
00156 vapiMacroToText (vMacro * Macro)
00157 {
00158         vMacroItem *Item;
00159         int i, MacroSize;
00160         MacroSize = vapiMacroCountElements (Macro);
00161 
00162         for (i = 0; i < MacroSize; i++)
00163         {
00164                 /*
00165                  * Carregar os dados do Operation.
00166                  */
00167                 Item = vapiMacroSelectItem (Macro, i);
00168 
00169                 /*
00170                  * Executar o Operation com os parâmetros definidos.
00171                  */
00172 
00173         }
00174 }
00175 
00176 void
00177 vapiLoadMacro (vImages * Images, vOptions * options,
00178                vMacroResult * PreviousResult)
00179 {
00180         vMacroHeader *originalMacroHeader, *tempMacroHeader;
00181 
00182         if (((vEffectOptions *) options->CustomOptions)->Macros == NULL)
00183         {
00184                 v_error ("Macro Não seleccionada correctamente");
00185                 return;
00186         }
00187 
00188         tempMacroHeader = malloc (sizeof (vMacroHeader));
00189         originalMacroHeader =
00190                 ((vEffectOptions *) options->CustomOptions)->Macros;
00191         tempMacroHeader->Macro = originalMacroHeader->Macro;
00192         tempMacroHeader->MacroName = originalMacroHeader->MacroName;
00193         tempMacroHeader->PreviousResult = PreviousResult;
00194 #ifdef VAPI_WITHOUT_INTERFACE
00195         vapiApplyMacro (tempMacroHeader, Images, vFALSE, vFALSE);
00196 #else
00197         vapiApplyMacro (tempMacroHeader, Images, vFALSE, vFALSE);
00198 #endif
00199 
00200         free (tempMacroHeader);
00201 
00202 }
00203 
00204 void
00205 vapiMacroDelete (vMacroHeader * MacroHeader)
00206 {
00207 
00208         v_list_free (MacroHeader->Macro, (vFreeFunction *) & vMacroItemFree);
00209         free (MacroHeader->PreviousResult);
00210         free (MacroHeader);
00211 }
00212 
00213 void
00214 vapiApplyMacroUntil (vMacroHeader * MacroHeader, vImages * Images, int Until)
00215 {
00216         vMacroItem *Item;
00217         int i = 0, MacroSize;
00218         char *macroTag;
00219 
00220         MacroSize = vapiMacroCountElements (MacroHeader->Macro);
00221         if (MacroSize == 0)
00222         {
00223                 return;
00224         }
00225         macroTag = vapiResultCheckMacroTag (MacroHeader->PreviousResult);
00226         for (i = 0; i < MacroSize; i++)
00227         {
00228                 if (!vapiGtkMacroRunningTest ())
00229                 {
00230                         return;
00231                 }
00232                 if (!v_bypass_get (macroTag, i))
00233                 {
00234                         continue;
00235                 }
00236                 vapiResultSetCurrentMacroTag (MacroHeader->PreviousResult,
00237                                               macroTag, i);
00238                 if (MacroHeader->PreviousResult->End)
00239                 {
00240                         MacroHeader->PreviousResult->End = vFALSE;
00241                         return;
00242                 }
00243                 Item = vapiMacroSelectItem (MacroHeader->Macro, i);
00244                 vapiApplyOperation (Images, (vEffect *) Item->Operation,
00245                                     (vOptions *) Item->Options,
00246                                     MacroHeader->PreviousResult);
00247                 if (v_stopby_get (macroTag, i))
00248                 {
00249                         vapiGtkImagesFastUpdateInterface (Images->Actual,
00250                                                           gtkImActual);
00251                 }
00252                 if (MacroHeader->PreviousResult->JumpTo != -1)
00253                 {
00254 
00255                         i = MacroHeader->PreviousResult->JumpTo - 1;
00256                         MacroHeader->PreviousResult->JumpTo = -1;
00257                         continue;
00258                 }
00259                 if (i == Until)
00260                 {
00261                         return;
00262                 }
00263         }
00264         free (macroTag);
00265 }
00266 
00267 void
00268 vapiConditionalJump (vImages * Images, vOptions * Options,
00269                      vMacroResult * PreviousResult)
00270 {
00271         if (PreviousResult->Decision)
00272         {
00273                 v_debug ("JUMP TO TRUE");
00274                 PreviousResult->JumpTo = Options->ints[0];
00275                 PreviousResult->Decision = vFALSE;
00276 
00277         }
00278         else
00279         {
00280                 v_debug ("JUMP TO FALSE");
00281                 PreviousResult->JumpTo = Options->ints[1];
00282         }
00283 }
00284 
00285 void
00286 vMacroItemFree (vMacroItem * Free)
00287 {
00288         vOperationOptionsFree (Free->Options, Free->Operation);
00289         free (Free);
00290 }
00291 
00292 int
00293 vapiMacroGetMacroIndex (vMacro * Macro, const char *MacroName, int order)
00294 {
00295 
00296         int MacroSize, tempOrder = 0, i;
00297         vMacroItem *item;
00298 
00299         MacroSize = v_list_count_elements (Macro);
00300 
00301         for (i = 0; i < MacroSize; i++)
00302         {
00303                 item = v_list_get (Macro, i);
00304 
00305                 if (!strcmp (item->Operation->name, "Executar Tarefa"))
00306                 {
00307                         if (!strcmp (item->Options->chars[0].ch, MacroName))
00308                         {
00309                                 if (++tempOrder == order)
00310                                 {
00311                                         return i;
00312                                 }
00313                         }
00314                 }
00315         }
00316         return -1;
00317 }
00318 
00319 void
00320 vapiMacroUpdateComment (vMacroHeader * MacroHeader, const char *MacroComment)
00321 {
00322         free (MacroHeader->MacroComment);
00323         MacroHeader->MacroComment = vapiReturnStringPointer (MacroComment);
00324 }
00325 
00326 void
00327 vapiMacroUpdateName (vMacroHeader * MacroHeader, const char *MacroName)
00328 {
00329         free (MacroHeader->MacroName);
00330         MacroHeader->MacroName = vapiReturnStringPointer (MacroName);
00331 }
00332 
00333 char *
00334 vapiMacroTag (const char *previousMacroTag, int operationNumber)
00335 {
00336         return v_printf ("%s:%d", previousMacroTag, operationNumber);
00337 }

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