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  /// Open a performance monitor thread-breakdown tooltip in a popup
76  /// window.
77  virtual void openPerfMonTooltipWindow(
78  const char *title, const char *text,
79  const UT_Array<std::pair<UT_StringHolder,
80  fpreal>> &bars,
81  int x, int y, int w, int h)
82  const override;
83 
84  /// Close all tooltip popup windows.
85  /// Do nothing if there are no open tooltip popup windows.
86  virtual void closeAllTooltipWindows() const override;
87 
88  /// Obtains a tool tip from the help page pointed to by the URL.
89  bool getTooltip(const char *url,
90  UT_String &tooltip) override;
91 
92  /// Obtains a tool tip for the specified parameter.
93  bool getTooltip(const PRM_Parm *parm,
94  UT_String &tooltip) override;
95 
96  /// Obtains a tool tip conained by the full help text. The url serves
97  /// as a caching key.
98  bool getParsedTooltip(const char *url_key,
99  const char *full_help,
100  UT_String &tooltip) override;
101 
102  /// Obtains a plain text version of the help page pointed to by the URL
103  /// (e.g. 'vex:attrib').
104  bool getTextHelp(const char *url,
105  UT_String &text_help) override;
106 
107  /// Return the text help for the given hscript command.
108  UT_StringHolder getCommandHelp(const char *command) override;
109 
110  /// Return the text help for the given hscript expression command.
111  UT_StringHolder getExprCommandHelp(const char *command) override;
112 
113  /// Return an array of hscript commands whose text help contain
114  /// a match for the given keyword.
115  UT_StringArray getCommandsForHelpKeyword(const char *keyword) override;
116 
117  /// Return an array of hscript expression commands whose text help
118  /// conotain a match for the given keyword.
119  UT_StringArray getExprCommandsForHelpKeyword(const char *keyword) override;
120 
121  // Convenience functions for opening the help cards for operators,
122  // nodes, shelf tools, states, etc.
123  virtual void openHelpCard(OP_Node *node) override;
124  virtual void openHelpCard(
125  OP_Operator *op,
126  const char *node_path=nullptr) override;
127  virtual void openHelpCard(BM_State *state) override;
128  virtual void openHelpCard(SHLF_Tool *tool) override;
129  virtual void openHelpCard(
130  const PYP_Interface *interface) override;
131  virtual void openHelpCard(OP_GalleryEntry *entry)
132  override;
133  virtual void openHelpCard(
134  const PRM_ScriptParm *prop) override;
135 
136  // Obtains a URL that points to the help server web page for the given
137  // operator, state, tool, or topic id.
138  void getHelpCardURL(OP_Operator *op,
139  UT_String &str) override;
140  void getHelpCardURL(BM_State *state,
141  UT_String &url) override;
142  void getHelpCardURL(SHLF_Tool *tool,
143  UT_String &url) override;
144  void getHelpCardURL(const PYP_Interface *interface,
145  UT_String &url) override;
146  void getHelpCardURL(OP_GalleryEntry *entry,
147  UT_String &url) override;
148  void getHelpCardURL(const PRM_ScriptParm *prop,
149  UT_String &url) override;
150  void getHelpCardURL(const char *helpTopicId,
151  UT_String &url) override;
152  void getHelpCardURL(const PRM_Parm* parm,
153  UT_String &help_path) override;
154 
155  /// Sets the base URI that is used to disambiguate the relative URLs.
156  void setBaseURI(const char *base_uri) override;
157 
158  /// Returns the baseURI.
159  const UT_String &getBaseURI() const override
160  { return myBaseURI; }
161 
162  /// Returns true if the help manager is using an external help server.
163  /// Returns false otherwise.
164  bool getUseExternalHelp() const override
165  { return myUseExternalHelp; }
166 
167  /// Sets whether the help manager should use an external help server or not.
168  void setUseExternalHelp(bool use_external) override;
169 
170  /// Sets the address the help server should bind to.
171  void setHelpAddress(const char* help_address) override;
172  const UT_StringHolder &getHelpAddress() const override
173  { return myHelpAddress; }
174 
175  /// Sets if the help server can use ipv6
176  void setUseIPv6(bool use_ipv6) override;
177  bool getUseIPv6() const override
178  { return myUseIPv6; }
179 
180  /// Returns the base url for the external help server.
181  /// Returns "" if no external help server is used.
182  const UT_String &getExternalHelpURL() const override
183  { return myExternalHelpURL; };
184 
185  /// Sets the url to the external help server.
186  void setExternalHelpURL(
187  const char *ext_help_url) override;
188 
189  /// Returns the base URL for all of Houdini's help.
190  const UT_String &getHelpBaseURL() override;
191 
192  /// Returns the url for the help startup page.
193  const UT_String &getStartupURL() override;
194 
195  /// Closes the help pane.
196  virtual void closeFloatingPane() override;
197 
198 protected:
199  /// Format used by getHelpCardURL(const PRM_Parm*, UT_String&).
200  MOT_ParmHelpURLFormat myParmHelpURLFormat
202 
203  /// Helper function for getTooltip(const char *, UT_String&).
204  /// Attempts to extract an operator, gallery entry or parameter
205  /// tooltip from the given url.
206  virtual bool extractTooltip(const char *url,
207  UT_String &tooltip);
208 
209  /// Updates all opened web browsers with the current
210  /// help base URL.
211  virtual void updateBaseURLInHelpBrowsersSubclass();
212 
213  /// Count help cards opening times for FS_datalogger.
214  void countHelpCardPress(const char *message);
215 
216  /// Checks whether the help server has the help page under the given URL.
217  bool getServerHasHelp(const char *url);
218 
219  UT_StringArray &getURLStack() { return myURLStack; }
220 
221  /// Prefixes `help_path` with the help server's base url and
222  /// passes back the final url in `url`.
223  void prefixWithHelpBaseURL(const char *help_path,
224  UT_String &url);
225 
226  /// Parses URL and tries to obtain the entity.
227  OP_Operator *getOpFromURL(const char *url);
228  OP_GalleryEntry *getGalleryEntryFromURL(const char *url);
229  const PRM_ScriptParm *getPropFromURL(const char *url);
230 
231  /// Resolve specified help path by expanding variables and translating
232  /// help protocols to help paths.
233  void resolveHelpPath(
234  const char *help_path,
235  UT_String &resolved_path);
236 
237 private:
238 
239  /// Parses the wiki text into an html text.
240  /// NB: the url is needed for caching key by the help server.
241  virtual void parseWikiToHtml(const char *url_key,
242  const char *wiki_help,
243  UT_String & html_help);
244 
245  /// Builds the legacy URL with the label embedded in the path.
246  void buildEmbeddedParmHelpURL(
247  const PRM_Parm *parm, UT_String &url);
248  /// Builds the structured URL with label and path as query string args.
249  void buildStructuredParmHelpURL(
250  const PRM_Parm *parm, UT_String &url);
251 
252  /// Helper methods to obtain tool tip from the operator or tool.
253  bool getTooltip(OP_Operator *op,
254  UT_String &tooltip);
255  bool getTooltip(OP_GalleryEntry *entry,
256  UT_String &tooltip);
257  bool getTooltip(const PRM_ScriptParm *prop,
258  UT_String &tooltip);
259 
260  /// Helper for running python code (eg evaluating expression and obtaining
261  /// the result of that expression) within the help python context.
262  /// Returns true evaluation went ok, or false if error occured or the
263  /// returned value type does not match the desired type.
264  // NB: the expression can be only a single python statement; no multiline
265  // scripts are allowed (for now at least).
266  bool runPythonExpr(const char *expr,
267  PY_Result::Type desired_result_type,
268  PY_Result &py_result,
269  PY_EvaluationContext *context=nullptr);
270  bool evalPythonExpr(const char *expr,
271  UT_String &result);
272  bool evalPythonExpr(const char *expr,
274  bool evalPythonExpr(const char *expr, int &result);
275  bool evalPythonExpr(const char *expr,
277 
278  /// Initialize the help server using the houdinihelp Python module.
279  bool initializeHelpServer();
280 
281  /// Initialize the help server if we haven't already tried to / do so, and
282  //return whether or not it could be initialized.
283  bool canAccessHelpServer();
284 
285  /// Returns the listen port of the help server.
286  /// Starts the help server if necessary.
287  int getHelpServerPort();
288 
289  bool myCouldInitializeHelpServer;
290  UT_StringArray myURLStack; // followed url links
291  UT_String myBaseURI; // base URI for relative
292  bool myUseExternalHelp;
293  UT_String myExternalHelpURL;
294  UT_String myHelpBaseURL; // html links
295  UT_String myStartupHelpURL;
296 
297  UT_StringHolder myHelpAddress;
298  bool myUseIPv6;
299 
300  /// The help server's listen port number.
301  static int theHelpServerPort;
302 
303  /// The help server's broken pipe signal handler.
304  static UT_Signal *theHelpServerSigHandler;
305 };
306 
307 #endif
308 
309 
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 openPerfMonTooltipWindow(const char *title, const char *text, const UT_Array< std::pair< UT_StringHolder, fpreal >> &bars, int x, int y, int w, int h) const =0
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
fpreal64 fpreal
Definition: SYS_Types.h:283
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