Skip to content

Commit

Permalink
Make sure the png image is there when the preview is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
couet committed Nov 14, 2024
1 parent d03ed36 commit 8f014f5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
57 changes: 35 additions & 22 deletions documentation/doxygen/filter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ using std::string, std::ios_base, std::unique_ptr;
void FilterClass();
void FilterTutorial();
void GetClassName();
void CreateTutorialImage(bool);
int NumberOfImages();
string ImagesList(string&);
void ExecuteMacro();
Expand Down Expand Up @@ -114,6 +115,7 @@ string gOutputName; // File containing a macro std::out
bool gHeader; // True if the input file is a header
bool gSource; // True if the input file is a source file
bool gPython; // True if the input file is a Python script.
bool gImageGenerated;// True if the PNG image has been generated.
bool gImageSource; // True the source of the current macro should be shown
int gInMacro; // >0 if parsing a macro in a class documentation.
int gImageID; // Image Identifier.
Expand All @@ -131,6 +133,7 @@ int main(int argc, char *argv[])
gSource = false;
gPython = false;
gImageSource = false;
gImageGenerated= false;
gInMacro = 0;
gImageID = 0;
gMacroID = 0;
Expand Down Expand Up @@ -299,6 +302,34 @@ void FilterClass()
fclose(f);
}

////////////////////////////////////////////////////////////////////////////////
/// Create PNG tutorial image

void CreateTutorialImage(bool nobatch) {
if (gPython) {
if (nobatch) {
ExecuteCommand(StringFormat("%s makeimage.py %s %s %s 0 1 0",
gPythonExec.c_str(),
gFileName.c_str(), gImageName.c_str(), gOutDir.c_str()));
} else {
ExecuteCommand(StringFormat("%s makeimage.py %s %s %s 0 1 1",
gPythonExec.c_str(),
gFileName.c_str(), gImageName.c_str(), gOutDir.c_str()));
}
} else {
if (nobatch) {
ExecuteCommand(
StringFormat("root -l -q \"makeimage.C+O(\\\"%s\\\",\\\"%s\\\",\\\"%s\\\",false,false)\"",
gFileName.c_str(), gImageName.c_str(), gOutDir.c_str()));
} else {
ExecuteCommand(
StringFormat("root -l -b -q \"makeimage.C+O(\\\"%s\\\",\\\"%s\\\",\\\"%s\\\",false,false)\"",
gFileName.c_str(), gImageName.c_str(), gOutDir.c_str()));
}
}
gImageGenerated = true;
}

////////////////////////////////////////////////////////////////////////////////
/// Filter ROOT tutorials for Doxygen.

Expand All @@ -324,6 +355,7 @@ void FilterTutorial()
} else {
i2 = gFileName.rfind('C');
}
gImageGenerated = false;
gMacroName = gFileName.substr(i1,i2-i1+1);
gImageName = StringFormat("%s.%s", gMacroName.c_str(), gImageType.c_str()); // Image name
gOutputName = StringFormat("%s.out", gMacroName.c_str()); // output name
Expand Down Expand Up @@ -399,27 +431,7 @@ void FilterTutorial()
gFileName.c_str(), IN.c_str(), gOutDir.c_str(), gPython));
ReplaceAll(gLineString, "macro_image", StringFormat("htmlinclude %s.html",IN.c_str()));
} else {
if (gPython) {
if (nobatch) {
ExecuteCommand(StringFormat("%s makeimage.py %s %s %s 0 1 0",
gPythonExec.c_str(),
gFileName.c_str(), gImageName.c_str(), gOutDir.c_str()));
} else {
ExecuteCommand(StringFormat("%s makeimage.py %s %s %s 0 1 1",
gPythonExec.c_str(),
gFileName.c_str(), gImageName.c_str(), gOutDir.c_str()));
}
} else {
if (nobatch) {
ExecuteCommand(
StringFormat("root -l -q \"makeimage.C+O(\\\"%s\\\",\\\"%s\\\",\\\"%s\\\",false,false)\"",
gFileName.c_str(), gImageName.c_str(), gOutDir.c_str()));
} else {
ExecuteCommand(
StringFormat("root -l -b -q \"makeimage.C+O(\\\"%s\\\",\\\"%s\\\",\\\"%s\\\",false,false)\"",
gFileName.c_str(), gImageName.c_str(), gOutDir.c_str()));
}
}
if (!gImageGenerated) CreateTutorialImage(nobatch);
ReplaceAll(gLineString, "\\macro_image", ImagesList(gImageName));
remove(gOutputName.c_str());
}
Expand Down Expand Up @@ -448,8 +460,9 @@ void FilterTutorial()

// \preview found
if (gLineString.find("\\preview") != string::npos) {
if (!gImageGenerated) CreateTutorialImage(false);
string name = gMacroName;
int width = 120;
int width = 150;
ReplaceAll(name,".C","_8C.html");
ReplaceAll(gLineString, "\\preview", StringFormat("\\htmlonly <a href=\"%s\"><img src=\"pict1_%s.png\" valign=\"middle\" width=\"%d\"/></a>\\endhtmlonly",name.c_str(),gMacroName.c_str(),width));
}
Expand Down
2 changes: 1 addition & 1 deletion tutorials/graphics/accessiblecolorschemes.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// and available on [GitHub](https://github.com/mpetroff/accessible-color-cycles)
/// under the MIT License, meet these criteria.
///
/// \macro_image Hello !!
/// \macro_image
/// \macro_code
///
/// \author Olivier Couet
Expand Down
2 changes: 1 addition & 1 deletion tutorials/graphics/arrows.C
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// \file
/// \ingroup tutorial_graphics
/// \notebook -js
/// Draw arrows.
/// \preview Draw arrows.
///
/// \macro_image (tcanvas_js)
/// \macro_code
Expand Down
2 changes: 1 addition & 1 deletion tutorials/graphics/mandelbrot.C
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// \file
/// \ingroup tutorial_graphics
/// \notebook -js
/// Using TExec to handle keyboard events and TComplex to draw the Mandelbrot set.
/// \preview Using TExec to handle keyboard events and TComplex to draw the Mandelbrot set.
///
/// Pressing the keys 'z' and 'u' will zoom and unzoom the picture
/// near the mouse location, 'r' will reset to the default view.
Expand Down
2 changes: 1 addition & 1 deletion tutorials/graphics/schroedinger_hydrogen.C
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// \file
/// \ingroup tutorial_graphics
/// \notebook
/// Plot the Amplitude of a Hydrogen Atom.
/// \preview Plot the Amplitude of a Hydrogen Atom.
///
/// Visualize the Amplitude of a Hydrogen Atom in the n = 2, l = 0, m = 0 state.
/// Demonstrates how TH2F can be used in Quantum Mechanics.
Expand Down

0 comments on commit 8f014f5

Please sign in to comment.