Skip to content
Snippets Groups Projects
Commit d5439751 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

better display of Field help

parent 2107179a
No related branches found
No related tags found
No related merge requests found
...@@ -140,3 +140,29 @@ std::string ConvertFileToString(std::string fileName) ...@@ -140,3 +140,29 @@ std::string ConvertFileToString(std::string fileName)
fclose(fp); fclose(fp);
return out; return out;
} }
void ConvertToHTML(std::string &in)
{
while(1){
int pos = in.find("<");
if(pos == std::string::npos) break;
in.replace(pos, 1, "&lt;");
}
while(1){
int pos = in.find(">");
if(pos == std::string::npos) break;
in.replace(pos, 1, "&gt;");
}
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>");
}
}
...@@ -19,5 +19,6 @@ std::vector<std::string> SplitFileName(std::string fileName); ...@@ -19,5 +19,6 @@ std::vector<std::string> SplitFileName(std::string fileName);
std::vector<std::string> SplitWhiteSpace(std::string in, unsigned int len); std::vector<std::string> SplitWhiteSpace(std::string in, unsigned int len);
std::string ReplacePercentS(std::string in, std::string val); std::string ReplacePercentS(std::string in, std::string val);
std::string ConvertFileToString(std::string fileName); std::string ConvertFileToString(std::string fileName);
void ConvertToHTML(std::string &in);
#endif #endif
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "GmshMessage.h" #include "GmshMessage.h"
#include "Field.h" #include "Field.h"
#include "GeoStringInterface.h" #include "GeoStringInterface.h"
#include "StringUtils.h"
#include "Options.h" #include "Options.h"
#include "Context.h" #include "Context.h"
...@@ -164,7 +165,9 @@ fieldWindow::fieldWindow(int deltaFontSize) : _deltaFontSize(deltaFontSize) ...@@ -164,7 +165,9 @@ fieldWindow::fieldWindow(int deltaFontSize) : _deltaFontSize(deltaFontSize)
options_tab->end(); options_tab->end();
Fl_Group *help_tab = new Fl_Group(x, y, w, h, "Help"); 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(); help_tab->end();
tabs->end(); tabs->end();
...@@ -345,19 +348,16 @@ void fieldWindow::editField(Field *f) ...@@ -345,19 +348,16 @@ void fieldWindow::editField(Field *f)
options_scroll->begin(); options_scroll->begin();
int xx = options_scroll->x(); int xx = options_scroll->x();
int yy = options_scroll->y(); int yy = options_scroll->y();
help_display->clear();
help_display->add("\n"); std::string help = f->getDescription();
add_multiline_in_browser(help_display, "", f->getDescription().c_str(), 100); ConvertToHTML(help);
help_display->add("\n"); help += std::string("<p><center><b>Options</b></center>");
help_display->add("@b@cOptions");
for(std::map<std::string, FieldOption*>::iterator it = f->options.begin(); for(std::map<std::string, FieldOption*>::iterator it = f->options.begin();
it != f->options.end(); it++){ it != f->options.end(); it++){
Fl_Widget *input; Fl_Widget *input;
help_display->add("\n"); help += std::string("<p><b>") + it->first + "</b>";
help_display->add(("@b" + it->first).c_str()); help += " (<em>" + it->second->getTypeName() + "</em>): ";
help_display->add(("@i" + it->second->getTypeName()).c_str()); help += it->second->getDescription();
add_multiline_in_browser
(help_display, "", it->second->getDescription().c_str(), 100);
switch(it->second->getType()){ switch(it->second->getType()){
case FIELD_OPTION_INT: case FIELD_OPTION_INT:
case FIELD_OPTION_DOUBLE: case FIELD_OPTION_DOUBLE:
...@@ -390,6 +390,7 @@ void fieldWindow::editField(Field *f) ...@@ -390,6 +390,7 @@ void fieldWindow::editField(Field *f)
options_widget.push_back(input); options_widget.push_back(input);
yy += BH; yy += BH;
} }
help_display->value(help.c_str());
options_scroll->end(); options_scroll->end();
FL_NORMAL_SIZE += _deltaFontSize; FL_NORMAL_SIZE += _deltaFontSize;
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <list> #include <list>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/Fl_Browser.H>
#include <FL/Fl_Hold_Browser.H> #include <FL/Fl_Hold_Browser.H>
#include <FL/Fl_Help_View.H>
#include <FL/Fl_Widget.H> #include <FL/Fl_Widget.H>
#include <FL/Fl_Button.H> #include <FL/Fl_Button.H>
#include <FL/Fl_Group.H> #include <FL/Fl_Group.H>
...@@ -31,7 +31,7 @@ class fieldWindow{ ...@@ -31,7 +31,7 @@ class fieldWindow{
Fl_Box *title, *empty_message; Fl_Box *title, *empty_message;
Fl_Button *background_btn; Fl_Button *background_btn;
Fl_Menu_Button *put_on_view_btn; Fl_Menu_Button *put_on_view_btn;
Fl_Browser *help_display; Fl_Help_View *help_display;
Fl_Button *delete_btn; Fl_Button *delete_btn;
int selected_id; int selected_id;
public: public:
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "MVertex.h" #include "MVertex.h"
#include "Context.h" #include "Context.h"
#include "GeoStringInterface.h" #include "GeoStringInterface.h"
#include "StringUtils.h"
#define MAX_PLUGIN_OPTIONS 50 #define MAX_PLUGIN_OPTIONS 50
class PluginDialogBox{ class PluginDialogBox{
...@@ -216,32 +217,6 @@ static void plugin_create_new_view_cb(Fl_Widget *w, void *data) ...@@ -216,32 +217,6 @@ static void plugin_create_new_view_cb(Fl_Widget *w, void *data)
drawContext::global()->draw(); 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, "&lt;");
}
while(1){
int pos = in.find(">");
if(pos == std::string::npos) break;
in.replace(pos, 1, "&gt;");
}
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, void pluginWindow::_createDialogBox(GMSH_Plugin *p, int x, int y,
int width, int height) int width, int height)
{ {
...@@ -309,7 +284,7 @@ void pluginWindow::_createDialogBox(GMSH_Plugin *p, int x, int y, ...@@ -309,7 +284,7 @@ void pluginWindow::_createDialogBox(GMSH_Plugin *p, int x, int y,
Fl_Help_View *o = new Fl_Help_View Fl_Help_View *o = new Fl_Help_View
(x + WB, y + top + BH + WB, width - 2 * WB, height - top - 2 * BH - 3 * WB); (x + WB, y + top + BH + WB, width - 2 * WB, height - top - 2 * BH - 3 * WB);
std::string help = p->getHelp(); std::string help = p->getHelp();
htmlize(help); ConvertToHTML(help);
help += std::string("<p><em>Author: ") + p->getAuthor() + "</em>"; help += std::string("<p><em>Author: ") + p->getAuthor() + "</em>";
help += std::string("<br><em>Copyright: ") + p->getCopyright() + "</em>"; help += std::string("<br><em>Copyright: ") + p->getCopyright() + "</em>";
o->value(help.c_str()); o->value(help.c_str());
......
...@@ -215,14 +215,14 @@ class StructuredField : public Field ...@@ -215,14 +215,14 @@ class StructuredField : public Field
(file_name, "Name of the input file", &update_needed); (file_name, "Name of the input file", &update_needed);
text_format = false; text_format = false;
options["TextFormat"] = new FieldOptionBool 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)", "signed integers for n, double precision floating points for v, D and O)",
&update_needed); &update_needed);
data = 0; data = 0;
} }
std::string getDescription() 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" "structured grid.\n\n"
"The format of the input file is:\n\n" "The format of the input file is:\n\n"
" Ox Oy Oz \n" " Ox Oy Oz \n"
...@@ -233,8 +233,8 @@ class StructuredField : public Field ...@@ -233,8 +233,8 @@ class StructuredField : public Field
" v(0,2,0) v(0,2,1) v(0,2,2) ... \n" " v(0,2,0) v(0,2,1) v(0,2,2) ... \n"
" ... ... ... \n" " ... ... ... \n"
" v(1,0,0) ... ... \n\n" " v(1,0,0) ... ... \n\n"
"where O are the coordinates of the first node, D are the distances\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\n" "between nodes in each direction, n are the numbers of nodes in each "
"direction, and v are the values on each node."; "direction, and v are the values on each node.";
} }
const char *getName() const char *getName()
...@@ -323,7 +323,7 @@ class UTMField : public Field ...@@ -323,7 +323,7 @@ class UTMField : public Field
public: public:
std::string getDescription() 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" "The formulas for the coordinates transformation are taken from:\n\n"
" http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM"; " http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM";
} }
...@@ -436,7 +436,7 @@ class BoxField : public Field ...@@ -436,7 +436,7 @@ class BoxField : public Field
public: public:
std::string getDescription() 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" "The box is given by\n\n"
" Xmin <= x <= XMax &&\n" " Xmin <= x <= XMax &&\n"
" YMin <= y <= YMax &&\n" " YMin <= y <= YMax &&\n"
...@@ -483,7 +483,7 @@ class CylinderField : public Field ...@@ -483,7 +483,7 @@ class CylinderField : public Field
public: public:
std::string getDescription() 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" "The cylinder is given by\n\n"
" ||dX||^2 < R^2 &&\n" " ||dX||^2 < R^2 &&\n"
" (X-X0).A < ||A||^2\n" " (X-X0).A < ||A||^2\n"
...@@ -576,10 +576,10 @@ class ThresholdField : public Field ...@@ -576,10 +576,10 @@ class ThresholdField : public Field
options["LcMax"] = new FieldOptionDouble options["LcMax"] = new FieldOptionDouble
(lcmax, "Element size outside DistMax"); (lcmax, "Element size outside DistMax");
options["Sigmoid"] = new FieldOptionBool 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"); "false to interpolate linearly");
options["StopAtDistMax"] = new FieldOptionBool 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)"); "F = a very big value if Field[IField] > DistMax)");
} }
double operator() (double x, double y, double z, GEntity *ge=0) double operator() (double x, double y, double z, GEntity *ge=0)
...@@ -614,8 +614,8 @@ public: ...@@ -614,8 +614,8 @@ public:
} }
virtual std::string getDescription() virtual std::string getDescription()
{ {
return "F = LCMin if Field[IField] <= DistMin,\n" return "F = LCMin if Field[IField] <= DistMin, "
"F = LCMax if Field[IField] >= DistMax,\n" "F = LCMax if Field[IField] >= DistMax, "
"F = interpolation between LcMin and LcMax if DistMin < 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) virtual void operator() (double x, double y, double z, SMetric3 &metr, GEntity *ge=0)
...@@ -689,7 +689,7 @@ class GradientField : public Field ...@@ -689,7 +689,7 @@ class GradientField : public Field
std::string getDescription() std::string getDescription()
{ {
return "Compute the finite difference gradient of Field[IField]:\n\n" 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"; " Field[IField](X - Delta/2)) / Delta";
} }
GradientField() : iField(0), kind(3), delta(CTX::instance()->lc / 1e4) GradientField() : iField(0), kind(3), delta(CTX::instance()->lc / 1e4)
...@@ -700,7 +700,7 @@ class GradientField : public Field ...@@ -700,7 +700,7 @@ class GradientField : public Field
options["IField"] = new FieldOptionInt options["IField"] = new FieldOptionInt
(iField, "Field index"); (iField, "Field index");
options["Kind"] = new FieldOptionInt 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"); "3 for the norm");
options["Delta"] = new FieldOptionDouble options["Delta"] = new FieldOptionDouble
(delta, "Finite difference step"); (delta, "Finite difference step");
...@@ -800,7 +800,7 @@ class MaxEigenHessianField : public Field ...@@ -800,7 +800,7 @@ class MaxEigenHessianField : public Field
} }
std::string getDescription() 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" "Field[IField], with the gradients evaluated by finite differences:\n\n"
" F = max(eig(grad(grad(Field[IField]))))"; " F = max(eig(grad(grad(Field[IField]))))";
} }
...@@ -1003,8 +1003,8 @@ class MathEvalField : public Field ...@@ -1003,8 +1003,8 @@ class MathEvalField : public Field
} }
std::string getDescription() std::string getDescription()
{ {
return "Evaluate a mathematical expression. The expression can contain\n" return "Evaluate a mathematical expression. The expression can contain "
"x, y, z for spatial coordinates, F0, F1, ... for field values, and\n" "x, y, z for spatial coordinates, F0, F1, ... for field values, and "
"and mathematical functions."; "and mathematical functions.";
} }
}; };
...@@ -1031,7 +1031,7 @@ class ParametricField : public Field ...@@ -1031,7 +1031,7 @@ class ParametricField : public Field
{ {
return "Evaluate Field IField in parametric coordinates:\n\n" return "Evaluate Field IField in parametric coordinates:\n\n"
" F = Field[IField](FX,FY,FZ)\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."; "and FZ expressions.";
} }
double operator() (double x, double y, double z, GEntity *ge=0) double operator() (double x, double y, double z, GEntity *ge=0)
...@@ -1095,7 +1095,7 @@ class PostViewField : public Field ...@@ -1095,7 +1095,7 @@ class PostViewField : public Field
(view_index, "Post-processing view index", &update_needed); (view_index, "Post-processing view index", &update_needed);
crop_negative_values = true; crop_negative_values = true;
options["CropNegativeValues"] = new FieldOptionBool 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", "option is needed for backward compatibility with the BackgroundMesh option",
&update_needed); &update_needed);
} }
...@@ -1177,7 +1177,7 @@ class RestrictField : public Field ...@@ -1177,7 +1177,7 @@ class RestrictField : public Field
} }
std::string getDescription() 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."; "curves, surfaces or volumes.";
} }
double operator() (double x, double y, double z, GEntity *ge=0) double operator() (double x, double y, double z, GEntity *ge=0)
...@@ -1224,7 +1224,7 @@ class AttractorField : public Field ...@@ -1224,7 +1224,7 @@ class AttractorField : public Field
(n_nodes_by_edge, "Number of nodes used to discretized each curve", (n_nodes_by_edge, "Number of nodes used to discretized each curve",
&update_needed); &update_needed);
options["FacesList"] = new FieldOptionList 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); "give strange results for complex surfaces)", &update_needed);
} }
~AttractorField() ~AttractorField()
...@@ -1240,9 +1240,9 @@ class AttractorField : public Field ...@@ -1240,9 +1240,9 @@ class AttractorField : public Field
} }
std::string getDescription() std::string getDescription()
{ {
return "Compute the distance from the nearest node in a list. It can also\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\n" "be used to compute the distance from curves, in which case each curve "
"is replaced by NNodesByEdge equidistant nodes and the distance from those\n" "is replaced by NNodesByEdge equidistant nodes and the distance from those "
"nodes is computed."; "nodes is computed.";
} }
virtual double operator() (double X, double Y, double Z, GEntity *ge=0) virtual double operator() (double X, double Y, double Z, GEntity *ge=0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment