00001 #include "display.h"
00002 #include "exception.h"
00003 #include <iostream>
00004
00005 #ifdef WIN32
00006 #include <windows.h>
00007 #else
00008
00009 #endif
00010
00011 namespace Display
00012 {
00013
00018 void texEndl(std::ostream& s)
00019 {
00020 if(globconfig->writeMode==Configuration::LATEX)
00021 s << "\\\\" << endl;
00022 }
00023
00028 void texDi(std::ostream& s)
00029 {
00030 if(globconfig->writeMode==Configuration::NORMAL)
00031 s << "#";
00032 }
00033
00038 void texHspace(std::ostream& s)
00039 {
00040 if(globconfig->writeMode==Configuration::LATEX)
00041 s << "\\hspace{20pt}";
00042 }
00043
00047 void Head(Configuration *config)
00048 {
00049 if(config->writeMode==Configuration::LATEX)
00050 {
00051 (*mycout) << "\\documentclass[a4paper,10pt]{article}" << endl;
00052 (*mycout) << "\\newcommand{\\noi}{\\noindent}" << endl;
00053 (*mycout) << "\\newcommand{\\II}{\\mbox{\\large 1\\hskip -0,353em 1}}" << endl;
00054 (*mycout) << "\\newcommand{\\MR}{\\mathcal{R}}" << endl;
00055 (*mycout) << "\\newcommand{\\RR} {\\mbox{I \\hskip -0.55 em R}}" << endl;
00056 (*mycout) << "\\usepackage[utf8]{inputenc}" << endl;
00057 (*mycout) << "\\usepackage{amsmath,amssymb}" << endl;
00058 (*mycout) << "\\usepackage{fullpage}" << endl;
00059 (*mycout) << "\\usepackage{graphicx}" << endl;
00060 (*mycout) << "\\begin{document}" << endl;
00061 }
00062 }
00063
00067 void Foot(Configuration *config)
00068 {
00069 if(config->writeMode==Configuration::LATEX)
00070 {
00071 (*mycout) << "\\end{document}" << endl;
00072 }
00073 }
00074
00078 void displayResult(Unification *unification)
00079 {
00080 if(unification->result)
00081 {
00082 Display::texEndl(*mycout);
00083 (*mycout) << endl;
00084 Display::texDi(*mycout);
00085 (*mycout) << "Unification Succeeds";
00086 Display::texDi(*mycout);
00087 Display::texEndl(*mycout);
00088 (*mycout) << endl << endl;
00089
00090 if(unification->configuration->disjonction)
00091 {
00092 (*mycout) << "Number of main solution : " << unification->solutions.size();
00093 Display::texEndl(*mycout);
00094 (*mycout) << endl << endl;
00095 list<Solution*>::iterator it = unification->solutions.begin();
00096 int num = 0;
00097 while(it!=unification->solutions.end())
00098 {
00099 num++;
00100 (*mycout) << "solution " << num ;
00101 Display::texEndl(*mycout);
00102 (*mycout) << endl;
00103 (*it)->display(*mycout);
00104 if(unification->configuration->writeMode==Configuration::LATEX)
00105 (*mycout) << "\\null";
00106 Display::texEndl(*mycout);
00107 (*mycout) << endl;
00108 it++;
00109 }
00110 }
00111
00112 if(unification->configuration->beep!=0)
00113 {
00114 if(unification->configuration->beep==3)
00115 {
00116 beep(1046,250);beep(1046,250);
00117 beep(1175,500);beep(1046,500);
00118 beep(1397,500);beep(1318,1000);
00119 beep(1046,250);beep(1046,250);
00120 beep(1175,500);beep(1046,500);
00121 beep(1568,500);beep(1397,1000);
00122 beep(1046,250);beep(1046,250);
00123 beep(2093,500);beep(1760,500);
00124 beep(1397,500);beep(1318,500);
00125 beep(1175,1000);beep(1868,250);
00126 beep(1868,250);beep(1760,500);
00127 beep(1397,500);beep(1568,500);
00128 beep(1397,1500);
00129 }
00130 else
00131 {
00132 beep(500,100);
00133 beep(600,100);
00134 }
00135 }
00136
00137 }
00138 else
00139 {
00140 (*mycout) << endl;
00141 Display::texDi(*mycout);
00142 (*mycout) << "Unification Failed";
00143 Display::texDi(*mycout);
00144 Display::texEndl(*mycout);
00145 (*mycout) << endl;
00146 if(unification->configuration->beep!=0)
00147 {
00148 beep(50,100);
00149 beep(40,100);
00150 beep(50,100);
00151 }
00152 }
00153 }
00154
00158 void displayTime(long atime)
00159 {
00160
00161 if(atime>1000*60*60*24)
00162 {
00163 (*mycout) << (atime / (1000 * 60*60*24));
00164 (*mycout) << " day(s) ";
00165 }
00166
00167 if(atime>1000*60*60)
00168 {
00169 (*mycout) << (atime / (1000 * 60*60));
00170 (*mycout) << " hour(s) ";
00171 }
00172
00173 if(atime>1000*60)
00174 {
00175 (*mycout) << (atime / (1000 * 60));
00176 (*mycout) << " minute(s) ";
00177 }
00178
00179 (*mycout) << (((float)(atime%(1000*60)))/1000);
00180 (*mycout) << " seconde(s) ";
00181
00182 }
00183
00184 void beep(int frec,int time)
00185 {
00186 #ifdef WIN32
00187 Beep(frec,time);
00188 #else
00189 char tmp[100];
00190 sprintf(tmp,"beep -f %i -l %i",frec,time);
00191
00192
00193 system(tmp);
00194
00195
00196 #endif
00197 }
00198
00199 }
00200
00204 std::ostream& operator << (std::ostream& o, const list<unsigned int> &path)
00205 {
00206 list<unsigned int>::const_iterator it = path.begin();
00207 while(it!=path.end())
00208 {
00209 o << (*it) << " ";
00210 it++;
00211 }
00212 return o;
00213 }
00214
00215
00216