HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MOT_HelpManager.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: MOT_HelpManager.h ( BR Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __MOT_HelpManager__
12 #define __MOT_HelpManager__
13 
14 #include "MOT_API.h"
15 #include <UT/UT_HelpManager.h>
16 #include <UT/UT_StringArray.h>
17 #include <PY/PY_Result.h>
18 
20 class UT_Signal;
21 class OP_Node;
22 class PRM_Parm;
23 
24 /// Format used when building a parameter's help-card URL.
26 {
27  Embedded,
28  Structured,
29 };
30 
32 {
33 public:
35  ~MOT_HelpManager() override;
36 
37  /// Opens the table of contenst help page.
38  virtual void openContents() override;
39 
40  /// Opens the special essential-skills page on startup.
41  virtual void openStartup() override;
42 
43  /// Opens a help page defined by the file.
44  virtual void openFile(const char *path) override;
45 
46  /// Opens a URL in the help browser (url can be of forms
47  /// "http://u.r.l", "hdox://u.r.l", "operator:table/name", "tool:name" etc)
48  virtual void openURL(const char *url) override;
49 
50  virtual void openHelpPath(const char *help_path) override;
51 
52  /// Displays the buffer data in help browser.
53  virtual void displayData(const char *data,
54  bool is_html) override;
55 
56  /// Open the requested tooltip in a popup window.
57  /// You can either pass the tooltip's help URL, the tooltip's help text,
58  /// or both.
59  ///
60  /// x,y,w,h represents the native screen position and size of the
61  /// source feel that the tooltip is for. If there is no source feel,
62  /// then pass in (0,0,0,0) for x,y,w,h.
63  ///
64  /// You can optionally pass in additional information to appear
65  /// in the tooltip -- help title, hotkey symbol, resolved hotkey string.
66  virtual void openTooltipWindow(
67  const char *url, const char *help,
68  int x, int y, int w, int h,
69  const char *title=nullptr,
70  const char *hotkey_symbol=nullptr,
71  const char *hotkey_str=nullptr,
72  bool use_fixed_font=false)
73  const override;
74 
75  /// Close all tooltip popup windows.
76  /// Do nothing if there are no open tooltip popup windows.
77  virtual void closeAllTooltipWindows() const override;
78 
79  /// Obtains a tool tip from the help page pointed to by the URL.
80  bool getTooltip(const char *url,
81  UT_String &tooltip) override;
82 
83  /// Obtains a tool tip for the specified parameter.
84  bool getTooltip(const PRM_Parm *parm,
85  UT_String &tooltip) override;
86 
87  /// Obtains a tool tip conained by the full help text. The url serves
88  /// as a caching key.
89  bool getParsedTooltip(const char *url_key,
90  const char *full_help,
91  UT_String &tooltip) override;
92 
93  /// Obtains a plain text version of the help page pointed to by the URL
94  /// (e.g. 'vex:attrib').
95  bool getTextHelp(const char *url,
96  UT_String &text_help) override;
97 
98  /// Return the text help for the given hscript command.
99  UT_StringHolder getCommandHelp(const char *command) override;
100 
101  /// Return the text help for the given hscript expression command.
102  UT_StringHolder getExprCommandHelp(const char *command) override;
103 
104  /// Return an array of hscript commands whose text help contain
105  /// a match for the given keyword.
106  UT_StringArray getCommandsForHelpKeyword(const char *keyword) override;
107 
108  /// Return an array of hscript expression commands whose text help
109  /// conotain a match for the given keyword.
110  UT_StringArray getExprCommandsForHelpKeyword(const char *keyword) override;
111 
112  // Convenience functions for opening the help cards for operators,
113  // nodes, shelf tools, states, etc.
114  virtual void openHelpCard(OP_Node *node) override;
115  virtual void openHelpCard(
116  OP_Operator *op,
117  const char *node_path=nullptr) override;
118  virtual void openHelpCard(BM_State *state) override;
119  virtual void openHelpCard(SHLF_Tool *tool) override;
120  virtual void openHelpCard(
121  const PYP_Interface *interface) override;
122  virtual void openHelpCard(OP_GalleryEntry *entry)
123  override;
124  virtual void openHelpCard(
125  const PRM_ScriptParm *prop) override;
126 
127  // Obtains a URL that points to the help server web page for the given
128  // operator, state, tool, or topic id.
129  void getHelpCardURL(OP_Operator *op,
130  UT_String &str) override;
131  void getHelpCardURL(BM_State *state,
132  UT_String &url) override;
133  void getHelpCardURL(SHLF_Tool *tool,
134  UT_String &url) override;
135  void getHelpCardURL(const PYP_Interface *interface,
136  UT_String &url) override;
137  void getHelpCardURL(OP_GalleryEntry *entry,
138  UT_String &url) override;
139  void getHelpCardURL(const PRM_ScriptParm *prop,
140  UT_String &url) override;
141  void getHelpCardURL(const char *helpTopicId,
142  UT_String &url) override;
143  void getHelpCardURL(const PRM_Parm* parm,
144  UT_String &help_path) override;
145 
146  /// Sets the base URI that is used to disambiguate the relative URLs.
147  void setBaseURI(const char *base_uri) override;
148 
149  /// Returns the baseURI.
150  const UT_String &getBaseURI() const override
151  { return myBaseURI; }
152 
153  /// Returns true if the help manager is using an external help server.
154  /// Returns false otherwise.
155  bool getUseExternalHelp() const override
156  { return myUseExternalHelp; }
157 
158  /// Sets whether the help manager should use an external help server or not.
159  void setUseExternalHelp(bool use_external) override;
160 
161  /// Sets the address the help server should bind to.
162  void setHelpAddress(const char* help_address) override;
163  const UT_StringHolder &getHelpAddress() const override
164  { return myHelpAddress; }
165 
166  /// Sets if the help server can use ipv6
167  void setUseIPv6(bool use_ipv6) override;
168  bool getUseIPv6() const override
169  { return myUseIPv6; }
170 
171  /// Returns the base url for the external help server.
172  /// Returns "" if no external help server is used.
173  const UT_String &getExternalHelpURL() const override
174  { return myExternalHelpURL; };
175 
176  /// Sets the url to the external help server.
177  void setExternalHelpURL(
178  const char *ext_help_url) override;
179 
180  /// Returns the base URL for all of Houdini's help.
181  const UT_String &getHelpBaseURL() override;
182 
183  /// Returns the url for the help startup page.
184  const UT_String &getStartupURL() override;
185 
186  /// Closes the help pane.
187  virtual void closeFloatingPane() override;
188 
189 protected:
190  /// Format used by getHelpCardURL(const PRM_Parm*, UT_String&).
191  MOT_ParmHelpURLFormat myParmHelpURLFormat
193 
194  /// Helper function for getTooltip(const char *, UT_String&).
195  /// Attempts to extract an operator, gallery entry or parameter
196  /// tooltip from the given url.
197  virtual bool extractTooltip(const char *url,
198  UT_String &tooltip);
199 
200  /// Updates all opened web browsers with the current
201  /// help base URL.
202  virtual void updateBaseURLInHelpBrowsersSubclass();
203 
204  /// Count help cards opening times for FS_datalogger.
205  void countHelpCardPress(const char *message);
206 
207  /// Checks whether the help server has the help page under the given URL.
208  bool getServerHasHelp(const char *url);
209 
210  UT_StringArray &getURLStack() { return myURLStack; }
211 
212  /// Prefixes `help_path` with the help server's base url and
213  /// passes back the final url in `url`.
214  void prefixWithHelpBaseURL(const char *help_path,
215  UT_String &url);
216 
217  /// Parses URL and tries to obtain the entity.
218  OP_Operator *getOpFromURL(const char *url);
219  OP_GalleryEntry *getGalleryEntryFromURL(const char *url);
220  const PRM_ScriptParm *getPropFromURL(const char *url);
221 
222  /// Resolve specified help path by expanding variables and translating
223  /// help protocols to help paths.
224  void resolveHelpPath(
225  const char *help_path,
226  UT_String &resolved_path);
227 
228 private:
229 
230  /// Parses the wiki text into an html text.
231  /// NB: the url is needed for caching key by the help server.
232  virtual void parseWikiToHtml(const char *url_key,
233  const char *wiki_help,
234  UT_String & html_help);
235 
236  /// Builds the legacy URL with the label embedded in the path.
237  void buildEmbeddedParmHelpURL(
238  const PRM_Parm *parm, UT_String &url);
239  /// Builds the structured URL with label and path as query string args.
240  void buildStructuredParmHelpURL(
241  const PRM_Parm *parm, UT_String &url);
242 
243  /// Helper methods to obtain tool tip from the operator or tool.
244  bool getTooltip(OP_Operator *op,
245  UT_String &tooltip);
246  bool getTooltip(OP_GalleryEntry *entry,
247  UT_String &tooltip);
248  bool getTooltip(const PRM_ScriptParm *prop,
249  UT_String &tooltip);
250 
251  /// Helper for running python code (eg evaluating expression and obtaining
252  /// the result of that expression) within the help python context.
253  /// Returns true evaluation went ok, or false if error occured or the
254  /// returned value type does not match the desired type.
255  // NB: the expression can be only a single python statement; no multiline
256  // scripts are allowed (for now at least).
257  bool runPythonExpr(const char *expr,
258  PY_Result::Type desired_result_type,
259  PY_Result &py_result,
260  PY_EvaluationContext *context=nullptr);
261  bool evalPythonExpr(const char *expr,
262  UT_String &result);
263  bool evalPythonExpr(const char *expr,
265  bool evalPythonExpr(const char *expr, int &result);
266  bool evalPythonExpr(const char *expr,
268 
269  /// Initialize the help server using the houdinihelp Python module.
270  bool initializeHelpServer();
271 
272  /// Initialize the help server if we haven't already tried to / do so, and
273  //return whether or not it could be initialized.
274  bool canAccessHelpServer();
275 
276  /// Returns the listen port of the help server.
277  /// Starts the help server if necessary.
278  int getHelpServerPort();
279 
280  bool myCouldInitializeHelpServer;
281  UT_StringArray myURLStack; // followed url links
282  UT_String myBaseURI; // base URI for relative
283  bool myUseExternalHelp;
284  UT_String myExternalHelpURL;
285  UT_String myHelpBaseURL; // html links
286  UT_String myStartupHelpURL;
287 
288  UT_StringHolder myHelpAddress;
289  bool myUseIPv6;
290 
291  /// The help server's listen port number.
292  static int theHelpServerPort;
293 
294  /// The help server's broken pipe signal handler.
295  static UT_Signal *theHelpServerSigHandler;
296 };
297 
298 #endif
299 
300 
virtual void openFile(const char *path)=0
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
virtual void setHelpAddress(const char *address)=0
Sets the address the server should bind to.
virtual void setBaseURI(const char *base_uri)=0
virtual bool getTextHelp(const char *url, UT_String &text_help)=0
virtual bool getTooltip(const char *url, UT_String &tooltip)=0
Obtains a tool tip from the help page pointed to by the URL.
const UT_StringHolder & getHelpAddress() const override
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
GLint y
Definition: glcorearb.h:103
virtual void setUseExternalHelp(bool use_external)=0
virtual UT_StringArray getExprCommandsForHelpKeyword(const char *keyword)=0
**But if you need a result
Definition: thread.h:622
std::string help(const App *app, const Error &e)
Printout the full help string on error (if this fn is set, the old default for CLI11) ...
Definition: CLI11.h:8978
virtual void openHelpPath(const char *help_path)=0
UT_StringArray & getURLStack()
#define MOT_API
Definition: MOT_API.h:10
virtual const UT_String & getStartupURL()=0
virtual UT_StringArray getCommandsForHelpKeyword(const char *keyword)=0
virtual bool getParsedTooltip(const char *url_key, const char *full_help, UT_String &tooltip)=0
GLint GLenum GLint x
Definition: glcorearb.h:409
virtual void getHelpCardURL(OP_Operator *op, UT_String &str)=0
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
virtual void displayData(const char *data, bool is_html)=0
virtual void openHelpCard(OP_Node *node)=0
virtual const UT_String & getHelpBaseURL()=0
virtual void openStartup()=0
virtual void closeFloatingPane()=0
MOT_ParmHelpURLFormat
Format used when building a parameter's help-card URL.
bool getUseExternalHelp() const override
virtual void openContents()=0
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
virtual void setUseIPv6(bool use_ipv6)=0
Whether the help server should use ipv6 or not.
const UT_String & getExternalHelpURL() const override
const UT_String & getBaseURI() const override
Returns the baseURI.
virtual void openTooltipWindow(const char *url, const char *help, int x, int y, int w, int h, const char *title=nullptr, const char *hotkey_symbol=nullptr, const char *hotkey_str=nullptr, bool use_fixed_font=false) const =0
virtual UT_StringHolder getExprCommandHelp(const char *command)=0
Return the text help for the given hscript expression command.
bool getUseIPv6() const override
state
Definition: core.h:2289
virtual void openURL(const char *url)=0
Definition: format.h:1821
virtual UT_StringHolder getCommandHelp(const char *command)=0
Return the text help for the given hscript command.
virtual void closeAllTooltipWindows() const =0
virtual void setExternalHelpURL(const char *ext_help_url)=0