From 9fe033ea88c2f705ec18c232873d056e0c229d72 Mon Sep 17 00:00:00 2001 From: Gaspard Coulet Date: Wed, 28 Apr 2021 23:05:53 +0200 Subject: Initial commit --- sem_4/Algo/TP4/SortieLatex.cpp | 110 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 sem_4/Algo/TP4/SortieLatex.cpp (limited to 'sem_4/Algo/TP4/SortieLatex.cpp') diff --git a/sem_4/Algo/TP4/SortieLatex.cpp b/sem_4/Algo/TP4/SortieLatex.cpp new file mode 100644 index 0000000..b400d1a --- /dev/null +++ b/sem_4/Algo/TP4/SortieLatex.cpp @@ -0,0 +1,110 @@ +//SortieLatex.cpp + +#include +#include +#include +#include +#include + +typedef int Valeur; + +class Sommet; + +typedef Sommet* AB; + +void SortieLatex(AB Ar, std::string filepath); + +class Sommet { + protected: + Valeur racine; + AB Pere,SAG,SAD; + bool FGP; + + // Unused: + // int hauteur,balanceGmoinsD; + + public: + Sommet(Valeur v); + Sommet(Sommet& s); + + AB remonterToutEnHaut(); + + void GrefferSAG(AB g); + void GrefferSAD(AB d); + + void SupprimerSAG(); + void SupprimerSAD(); + + bool FeuilleP(); + + void RemplacerPourLePerePar(AB); + + friend std::string* TikzRecursAB(int ligne,int gauche, int droite, int numeroPere, int typeFils, AB Ar); + + +}; + +std::string* TikzRecursAB(int ligne,int gauche, int droite, int numeroPere, int typeFils, AB Ar); + + + +std::string * TikzRecursAB(int ligne,int gauche, int droite, int numeroPere, int typeFils, AB Ar){ + std::ostringstream ossnum, osslign,osscol,ossnumPere, ossbal, ossnum2Pere,ossnumRac; + + std::string stres(""); + + if (Ar) { + ossnumPere<racine << "})\\\\this=\\textcolor{red}{" <Pere << "} (FGP=\\textcolor{red}{" << (Ar->FGP?"Gauche":"Droit") <<"})"; + + if (Ar->Pere )ossnum2Pere<Pere->racine; else ossnum2Pere<<0; + + int numero; + if (typeFils==-1) { numero=1; } else { numero= 2*numeroPere + typeFils; } + ossnum<SAG) stres+=*TikzRecursAB(ligne-3,gauche,mil-13,numero,0,Ar->SAG); + if (Ar->SAD) stres+=*TikzRecursAB(ligne-3,mil+13,droite,numero,1,Ar->SAD); + } + return new std::string(stres); +} + +std::string * TikzAB(AB Ar){ + return TikzRecursAB(1,1,10,1,-1,Ar); +} + + void SortieLatex(AB 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<&1 isnt enough to mute pdflatex... + system_CARE << "mkdir pdflatex_temp > /dev/null 2>&1;" + << "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 -- cgit v1.2.3