diff options
| author | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
|---|---|---|
| committer | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
| commit | 9fe033ea88c2f705ec18c232873d056e0c229d72 (patch) | |
| tree | 0647dc8c51610c7336c88c04de2068ea14b21e17 /sem_4/Algo/TP7/SortieLatex.cpp | |
Initial commit
Diffstat (limited to 'sem_4/Algo/TP7/SortieLatex.cpp')
| -rw-r--r-- | sem_4/Algo/TP7/SortieLatex.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/sem_4/Algo/TP7/SortieLatex.cpp b/sem_4/Algo/TP7/SortieLatex.cpp new file mode 100644 index 0000000..e5354e6 --- /dev/null +++ b/sem_4/Algo/TP7/SortieLatex.cpp @@ -0,0 +1,101 @@ +//SortieLatex.cpp + +#include <iostream> +#include <fstream> +#include <sstream> + +typedef int Valeur; + +class SommetABR; + +typedef SommetABR* ABR; + +void SortieLatex(ABR Ar); + +class SommetABR { + protected: + Valeur racine; + ABR Pere,SAG, SAD; + + int hauteur,balanceGmoinsD; + + public: + SommetABR(Valeur v); + SommetABR(SommetABR& s); + + ABR remonterToutEnHaut(); + + void GrefferSAG(ABR g); + void GrefferSAD(ABR d); + + void SupprimerSAG(); + void SupprimerSAD(); + + bool FeuilleP(); + + void RemplacerPourLePerePar(ABR); + + friend std::string* TikzRecursABR(int ligne,int gauche, int droite, int numeroPere, int typeFils, ABR Ar); + + +}; + +std::string* TikzRecursABR(int ligne,int gauche, int droite, int numeroPere, int typeFils, ABR Ar); + + + +std::string * TikzRecursABR(int ligne,int gauche, int droite, int numeroPere, int typeFils, ABR Ar){ + std::ostringstream ossnum, osslign,osscol,ossnumPere, ossbal, ossnum2Pere,ossnumRac; + + std::string stres(""); + + if (Ar) { + ossnumPere<<numeroPere; + ossnumRac<<Ar->racine; + if (Ar->Pere )ossnum2Pere<<Ar->Pere->racine; else ossnum2Pere<<0; + int numero; + if (typeFils==-1) numero=1; else numero= 2*numeroPere + typeFils; + ossnum<<numero; + osslign<<ligne; + int mil = (gauche + droite)/2; + osscol<<mil; + + stres="\\node[draw] (SZ" + ossnum.str() + ") at (" + osscol.str() + ", " + osslign.str() + ") { " + ossnumRac.str() + "};\n"; + + if (typeFils!=-1) stres+="\\draw (SZ"+ossnumPere.str()+") -- (SZ"+ossnum.str() +");\n"; + if (Ar->SAG) stres+=*TikzRecursABR(ligne -1 ,gauche,mil-1, numero,0,Ar->SAG); + if (Ar->SAD) stres+=*TikzRecursABR(ligne - 1,mil+1,droite, numero,1,Ar->SAD); + } + return new std::string(stres); +} + +std::string * TikzABR(ABR Ar){ + return TikzRecursABR(1,1,10,1, -1,Ar); +} + + + void SortieLatex(ABR Ar, std::string filepath){ //don't insert garbage in filepath, its std::system-ised. + std::ofstream fichier(filepath.c_str(), std::ios::out | std::ios::trunc); + std::string preamb ("\\documentclass{article} \n \\usepackage{tikz} \n \\begin{document} \n \\resizebox{300pt}{!}{\n \\begin{tikzpicture}\n"); + std::cout<<preamb<<"\n"; +std::string post("\\end{tikzpicture}\n } \\end{document} \n"); //rsz box end? + std::cout<<post<<"\n"; + std::cout<<*TikzAB(Ar)<<"\n"; +std::string res1(preamb + *TikzAB(Ar)); + std::string res(res1 + post); + //std::cout<<res1<<"\n"; + fichier <<res<<"\n"; + fichier.close(); + + std::ostringstream system_CARE; + // /dev/null 2>&1 isnt enough to mute pdflatex... + system_CARE << "mkdir pdflatex_temp > /dev/null 2>&1;" + << "init_texlive;"<< "pdflatex -output-directory=\"./pdflatex_temp\" -interaction=nonstopmode \"" << filepath << "\" >/dev/null 2>&1;" + <<"mv ./pdflatex_temp/*.pdf ./ > /dev/null 2>&1;"; + std::system(system_CARE.str().c_str()); + return; +} + + + +// g++ -c SortieLatex.cpp |
