00001 #include <stdio.h>
00002 #include <string.h>
00003 #include "vapi.h"
00004 #include "vapiString.h"
00005 #include "vapiMacroList.h"
00006 #include "vapiMacro.h"
00007 #include "vapiMacroXML.h"
00008 #include <highgui.h>
00009
00010
00011 vMacroList *
00012 vapiMacroListNew ()
00013 {
00014 return (vMacroList *) v_list_new ();
00015 }
00016
00017 void
00018 vapiMacroListAddItem (vMacroList * MacroList, vMacroHeader * MacroHeader)
00019 {
00020 v_list_append ((vList *) MacroList, MacroHeader);
00021 }
00022
00023
00024 int
00025 vapiMacroListCountElements (vMacroList * MacroList)
00026 {
00027 return v_list_count_elements ((vList *) MacroList);
00028 }
00029
00030 void
00031 vapiMacroListDeleteItem (vMacroList * MacroList, int Delete)
00032 {
00033 v_list_delete_item ((vList *) MacroList,
00034 (vFreeFunction *) & vapiMacroDelete, Delete);
00035 }
00036
00037 vMacroHeader *
00038 vapiMacroListSelectItem (vMacroList * MacroList, int Item)
00039 {
00040 return ((vMacroHeader *) v_list_get ((vList *) MacroList, Item));
00041 }
00042
00043 void
00044 vapiMacroListToText (vMacroList * MacroList)
00045 {
00046 vMacroHeader *Item;
00047 int i, MacroListSize;
00048 MacroListSize = vapiMacroListCountElements (MacroList);
00049 v_debug ("Numero de Macros na Lista: %d", MacroListSize);
00050
00051 for (i = 0; i < MacroListSize; i++)
00052 {
00053
00054
00055
00056 Item = vapiMacroListSelectItem (MacroList, i);
00057
00058
00059
00060
00061 v_debug ("O Número %d: %s", i, Item->MacroName);
00062
00063
00064
00065 }
00066 }
00067
00068 void
00069 vapiLoadExampleMacros (vMacroList * MacroList, vOperationList * OperationList)
00070 {
00071 int numberOfExampleMacros = 8, i;
00072 char *ExampleMacros[8];
00073
00074 ExampleMacros[0] = "Macros_exemplo/fusivel_azul.xml";
00075 ExampleMacros[1] = "Macros_exemplo/fusivelermelho.xml";
00076 ExampleMacros[2] = "Macros_exemplo/fusivel_rosa.xml";
00077 ExampleMacros[3] = "Macros_exemplo/DetectarFusiveis.xml";
00078 ExampleMacros[4] = "Macros_exemplo/comprimidos.xml";
00079 ExampleMacros[5] = "Macros_exemplo/OCRermelho.xml";
00080 ExampleMacros[6] = "Macros_exemplo/pattern_match.xml";
00081 ExampleMacros[7] = "Macros_exemplo/pattern_search.xml";
00082
00083
00084 for (i = 0; i < numberOfExampleMacros; i++)
00085 {
00086
00087 vapiMacroXMLLoadToList (MacroList, OperationList,
00088 ExampleMacros[i]);
00089 }
00090
00091
00092 }
00093
00099 int
00100 vapiMacroListMacroExist (vMacroList * MacroList, char *string,
00101 int WhatToReturn)
00102 {
00103
00104 int i, ListSize;
00105 vMacroHeader *MacroHeader;
00106
00107
00108
00109
00110 ListSize = vapiMacroListCountElements ((vMacroList *) MacroList);
00111 for (i = 0; i < ListSize; i++)
00112 {
00113 MacroHeader =
00114 vapiMacroListSelectItem ((vMacroList *) MacroList, i);
00115 if (!strcmp (MacroHeader->MacroName, string))
00116 {
00117 if (WhatToReturn)
00118 {
00119 return -1;
00120 }
00121 else
00122 {
00123 return i;
00124 }
00125 }
00126 }
00127 if (!WhatToReturn)
00128 {
00129 return -3;
00130 }
00131
00132 return -2;
00133 }