diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 9d178b7da4d92b50db08ba337a934eac526312ea..92252eae98cd9313054befc06ae6e3fc0e2d0aab 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -140,3 +140,29 @@ std::string ConvertFileToString(std::string fileName) fclose(fp); return out; } + +void ConvertToHTML(std::string &in) +{ + while(1){ + int pos = in.find("<"); + if(pos == std::string::npos) break; + in.replace(pos, 1, "<"); + } + while(1){ + int pos = in.find(">"); + if(pos == std::string::npos) break; + in.replace(pos, 1, ">"); + } + while(1){ + const char n2[3] = {'\n', '\n', '\0'}; + int pos = in.find(n2); + if(pos == std::string::npos) break; + in.replace(pos, 2, "<p>"); + } + while(1){ + const char n1[2] = {'\n', '\0'}; + int pos = in.find(n1); + if(pos == std::string::npos) break; + in.replace(pos, 1, "<br>"); + } +} diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 9e66463848a3d242086b1bb388c557f62701d362..93328fdd40f5d1f6ec3f5d5d10609edecc129481 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -19,5 +19,6 @@ std::vector<std::string> SplitFileName(std::string fileName); std::vector<std::string> SplitWhiteSpace(std::string in, unsigned int len); std::string ReplacePercentS(std::string in, std::string val); std::string ConvertFileToString(std::string fileName); +void ConvertToHTML(std::string &in); #endif diff --git a/Fltk/fieldWindow.cpp b/Fltk/fieldWindow.cpp index 1f072c3fccfe67658d7f622bb0c29844f02a65d6..adec0197c5040a6d726e0c07ff5217ae8db74905 100644 --- a/Fltk/fieldWindow.cpp +++ b/Fltk/fieldWindow.cpp @@ -26,6 +26,7 @@ #include "GmshMessage.h" #include "Field.h" #include "GeoStringInterface.h" +#include "StringUtils.h" #include "Options.h" #include "Context.h" @@ -164,7 +165,9 @@ fieldWindow::fieldWindow(int deltaFontSize) : _deltaFontSize(deltaFontSize) options_tab->end(); Fl_Group *help_tab = new Fl_Group(x, y, w, h, "Help"); - help_display = new Fl_Browser(x, y + WB, w, h - 2 * WB); + help_display = new Fl_Help_View(x, y + WB, w, h - 2 * WB); + help_display->textfont(FL_HELVETICA); + help_display->textsize(FL_NORMAL_SIZE); help_tab->end(); tabs->end(); @@ -345,19 +348,16 @@ void fieldWindow::editField(Field *f) options_scroll->begin(); int xx = options_scroll->x(); int yy = options_scroll->y(); - help_display->clear(); - help_display->add("\n"); - add_multiline_in_browser(help_display, "", f->getDescription().c_str(), 100); - help_display->add("\n"); - help_display->add("@b@cOptions"); + + std::string help = f->getDescription(); + ConvertToHTML(help); + help += std::string("<p><center><b>Options</b></center>"); for(std::map<std::string, FieldOption*>::iterator it = f->options.begin(); it != f->options.end(); it++){ Fl_Widget *input; - help_display->add("\n"); - help_display->add(("@b" + it->first).c_str()); - help_display->add(("@i" + it->second->getTypeName()).c_str()); - add_multiline_in_browser - (help_display, "", it->second->getDescription().c_str(), 100); + help += std::string("<p><b>") + it->first + "</b>"; + help += " (<em>" + it->second->getTypeName() + "</em>): "; + help += it->second->getDescription(); switch(it->second->getType()){ case FIELD_OPTION_INT: case FIELD_OPTION_DOUBLE: @@ -390,6 +390,7 @@ void fieldWindow::editField(Field *f) options_widget.push_back(input); yy += BH; } + help_display->value(help.c_str()); options_scroll->end(); FL_NORMAL_SIZE += _deltaFontSize; diff --git a/Fltk/fieldWindow.h b/Fltk/fieldWindow.h index f0274934174c3f2915de8ce5ca56d7755e3d97cd..f850b5c95cba8d65e66a3d262031ab924f3d26a5 100644 --- a/Fltk/fieldWindow.h +++ b/Fltk/fieldWindow.h @@ -8,8 +8,8 @@ #include <list> #include <FL/Fl_Window.H> -#include <FL/Fl_Browser.H> #include <FL/Fl_Hold_Browser.H> +#include <FL/Fl_Help_View.H> #include <FL/Fl_Widget.H> #include <FL/Fl_Button.H> #include <FL/Fl_Group.H> @@ -31,7 +31,7 @@ class fieldWindow{ Fl_Box *title, *empty_message; Fl_Button *background_btn; Fl_Menu_Button *put_on_view_btn; - Fl_Browser *help_display; + Fl_Help_View *help_display; Fl_Button *delete_btn; int selected_id; public: diff --git a/Fltk/pluginWindow.cpp b/Fltk/pluginWindow.cpp index 2995ae4f884af666a9015604debab67e90213eed..b1869ea7159b9b8a403ae69c7e215f1f73c7974d 100644 --- a/Fltk/pluginWindow.cpp +++ b/Fltk/pluginWindow.cpp @@ -24,6 +24,7 @@ #include "MVertex.h" #include "Context.h" #include "GeoStringInterface.h" +#include "StringUtils.h" #define MAX_PLUGIN_OPTIONS 50 class PluginDialogBox{ @@ -216,32 +217,6 @@ static void plugin_create_new_view_cb(Fl_Widget *w, void *data) drawContext::global()->draw(); } -static void htmlize(std::string &in) -{ - while(1){ - int pos = in.find("<"); - if(pos == std::string::npos) break; - in.replace(pos, 1, "<"); - } - while(1){ - int pos = in.find(">"); - if(pos == std::string::npos) break; - in.replace(pos, 1, ">"); - } - while(1){ - const char n2[3] = {'\n', '\n', '\0'}; - int pos = in.find(n2); - if(pos == std::string::npos) break; - in.replace(pos, 2, "<p>"); - } - while(1){ - const char n1[2] = {'\n', '\0'}; - int pos = in.find(n1); - if(pos == std::string::npos) break; - in.replace(pos, 1, "<br>"); - } -} - void pluginWindow::_createDialogBox(GMSH_Plugin *p, int x, int y, int width, int height) { @@ -309,7 +284,7 @@ void pluginWindow::_createDialogBox(GMSH_Plugin *p, int x, int y, Fl_Help_View *o = new Fl_Help_View (x + WB, y + top + BH + WB, width - 2 * WB, height - top - 2 * BH - 3 * WB); std::string help = p->getHelp(); - htmlize(help); + ConvertToHTML(help); help += std::string("<p><em>Author: ") + p->getAuthor() + "</em>"; help += std::string("<br><em>Copyright: ") + p->getCopyright() + "</em>"; o->value(help.c_str()); diff --git a/Mesh/Field.cpp b/Mesh/Field.cpp index d8a1a71f59cc882e0595422cf3bbd00a3e8b08ff..79bb11022ffc8aac006fdea4ab9c227677515e8c 100644 --- a/Mesh/Field.cpp +++ b/Mesh/Field.cpp @@ -215,14 +215,14 @@ class StructuredField : public Field (file_name, "Name of the input file", &update_needed); text_format = false; options["TextFormat"] = new FieldOptionBool - (text_format, "True for ASCII input files, false for binary files (4 bite\n" + (text_format, "True for ASCII input files, false for binary files (4 bite " "signed integers for n, double precision floating points for v, D and O)", &update_needed); data = 0; } std::string getDescription() { - return "Linearly interpolate between data provided on a 3D rectangular\n" + return "Linearly interpolate between data provided on a 3D rectangular " "structured grid.\n\n" "The format of the input file is:\n\n" " Ox Oy Oz \n" @@ -233,8 +233,8 @@ class StructuredField : public Field " v(0,2,0) v(0,2,1) v(0,2,2) ... \n" " ... ... ... \n" " v(1,0,0) ... ... \n\n" - "where O are the coordinates of the first node, D are the distances\n" - "between nodes in each direction, n are the numbers of nodes in each\n" + "where O are the coordinates of the first node, D are the distances " + "between nodes in each direction, n are the numbers of nodes in each " "direction, and v are the values on each node."; } const char *getName() @@ -323,7 +323,7 @@ class UTMField : public Field public: std::string getDescription() { - return "Evaluate Field[IField] in Universal Transverse Mercator coordinates.\n" + return "Evaluate Field[IField] in Universal Transverse Mercator coordinates.\n\n" "The formulas for the coordinates transformation are taken from:\n\n" " http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM"; } @@ -436,7 +436,7 @@ class BoxField : public Field public: std::string getDescription() { - return "The value of this field is VIn inside the box, VOut outside the box.\n" + return "The value of this field is VIn inside the box, VOut outside the box. " "The box is given by\n\n" " Xmin <= x <= XMax &&\n" " YMin <= y <= YMax &&\n" @@ -483,7 +483,7 @@ class CylinderField : public Field public: std::string getDescription() { - return "The value of this field is VIn inside a frustrated cylinder, VOut outside.\n" + return "The value of this field is VIn inside a frustrated cylinder, VOut outside. " "The cylinder is given by\n\n" " ||dX||^2 < R^2 &&\n" " (X-X0).A < ||A||^2\n" @@ -576,10 +576,10 @@ class ThresholdField : public Field options["LcMax"] = new FieldOptionDouble (lcmax, "Element size outside DistMax"); options["Sigmoid"] = new FieldOptionBool - (sigmoid, "True to interpolate between LcMin and LcMax using a sigmoid,\n" + (sigmoid, "True to interpolate between LcMin and LcMax using a sigmoid, " "false to interpolate linearly"); options["StopAtDistMax"] = new FieldOptionBool - (stopAtDistMax, "True to not impose element size outside DistMax (i.e.,\n" + (stopAtDistMax, "True to not impose element size outside DistMax (i.e., " "F = a very big value if Field[IField] > DistMax)"); } double operator() (double x, double y, double z, GEntity *ge=0) @@ -614,8 +614,8 @@ public: } virtual std::string getDescription() { - return "F = LCMin if Field[IField] <= DistMin,\n" - "F = LCMax if Field[IField] >= DistMax,\n" + return "F = LCMin if Field[IField] <= DistMin, " + "F = LCMax if Field[IField] >= DistMax, " "F = interpolation between LcMin and LcMax if DistMin < Field[IField] < DistMax"; } virtual void operator() (double x, double y, double z, SMetric3 &metr, GEntity *ge=0) @@ -689,7 +689,7 @@ class GradientField : public Field std::string getDescription() { return "Compute the finite difference gradient of Field[IField]:\n\n" - " F = (Field[IField](X + Delta/2) -\n" + " F = (Field[IField](X + Delta/2) - " " Field[IField](X - Delta/2)) / Delta"; } GradientField() : iField(0), kind(3), delta(CTX::instance()->lc / 1e4) @@ -700,7 +700,7 @@ class GradientField : public Field options["IField"] = new FieldOptionInt (iField, "Field index"); options["Kind"] = new FieldOptionInt - (kind, "Component of the gradient to evaluate: 0 for X, 1 for Y, 2 for Z,\n" + (kind, "Component of the gradient to evaluate: 0 for X, 1 for Y, 2 for Z, " "3 for the norm"); options["Delta"] = new FieldOptionDouble (delta, "Finite difference step"); @@ -800,7 +800,7 @@ class MaxEigenHessianField : public Field } std::string getDescription() { - return "Compute the maximum eigenvalue of the Hessian matrix of\n" + return "Compute the maximum eigenvalue of the Hessian matrix of " "Field[IField], with the gradients evaluated by finite differences:\n\n" " F = max(eig(grad(grad(Field[IField]))))"; } @@ -1003,8 +1003,8 @@ class MathEvalField : public Field } std::string getDescription() { - return "Evaluate a mathematical expression. The expression can contain\n" - "x, y, z for spatial coordinates, F0, F1, ... for field values, and\n" + return "Evaluate a mathematical expression. The expression can contain " + "x, y, z for spatial coordinates, F0, F1, ... for field values, and " "and mathematical functions."; } }; @@ -1031,7 +1031,7 @@ class ParametricField : public Field { return "Evaluate Field IField in parametric coordinates:\n\n" " F = Field[IField](FX,FY,FZ)\n\n" - "See the MathEval Field help to get a description of valid FX, FY\n" + "See the MathEval Field help to get a description of valid FX, FY " "and FZ expressions."; } double operator() (double x, double y, double z, GEntity *ge=0) @@ -1095,7 +1095,7 @@ class PostViewField : public Field (view_index, "Post-processing view index", &update_needed); crop_negative_values = true; options["CropNegativeValues"] = new FieldOptionBool - (crop_negative_values, "return LC_MAX instead of a negative value (this\n" + (crop_negative_values, "return LC_MAX instead of a negative value (this " "option is needed for backward compatibility with the BackgroundMesh option", &update_needed); } @@ -1177,7 +1177,7 @@ class RestrictField : public Field } std::string getDescription() { - return "Restrict the application of a field to a given list of geometrical\n" + return "Restrict the application of a field to a given list of geometrical " "curves, surfaces or volumes."; } double operator() (double x, double y, double z, GEntity *ge=0) @@ -1224,7 +1224,7 @@ class AttractorField : public Field (n_nodes_by_edge, "Number of nodes used to discretized each curve", &update_needed); options["FacesList"] = new FieldOptionList - (faces_id, "Indices of surfaces in the geometric model (Warning: might\n" + (faces_id, "Indices of surfaces in the geometric model (Warning: might " "give strange results for complex surfaces)", &update_needed); } ~AttractorField() @@ -1240,9 +1240,9 @@ class AttractorField : public Field } std::string getDescription() { - return "Compute the distance from the nearest node in a list. It can also\n" - "be used to compute the distance from curves, in which case each curve\n" - "is replaced by NNodesByEdge equidistant nodes and the distance from those\n" + return "Compute the distance from the nearest node in a list. It can also " + "be used to compute the distance from curves, in which case each curve " + "is replaced by NNodesByEdge equidistant nodes and the distance from those " "nodes is computed."; } virtual double operator() (double X, double Y, double Z, GEntity *ge=0)