0025748: Parallel version of progress indicator
[occt.git] / src / Draw / Draw.hxx
CommitLineData
42cf5bc1 1// Created on: 1991-04-24
2// Created by: Arnaud BOUZY
3// Copyright (c) 1991-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Draw_HeaderFile
18#define _Draw_HeaderFile
19
dae2a922 20#include <Draw_Interpretor.hxx>
21#include <Quantity_ColorRGBA.hxx>
42cf5bc1 22#include <Standard_Handle.hxx>
23
42cf5bc1 24class Draw_Drawable3D;
42cf5bc1 25class Draw_ProgressIndicator;
42cf5bc1 26
27//! MAQUETTE DESSIN MODELISATION
28class Draw
29{
30public:
31
32 DEFINE_STANDARD_ALLOC
33
dae2a922 34 //! (Re)Load a Draw Harness plugin.
35 //! @param theDI [in] [out] Tcl interpretor to append loaded commands
36 //! @param theKey [in] plugin code name to be resolved in resource file
37 //! @param theResourceFileName [in] description file name
38 //! @param theDefaultsDirectory [in] default folder for looking description file
39 //! @param theUserDefaultsDirectory [in] user folder for looking description file
40 //! @param theIsVerbose [in] print verbose messages
41 Standard_EXPORT static void Load (Draw_Interpretor& theDI,
42 const TCollection_AsciiString& theKey,
43 const TCollection_AsciiString& theResourceFileName,
44 const TCollection_AsciiString& theDefaultsDirectory,
45 const TCollection_AsciiString& theUserDefaultsDirectory,
46 const Standard_Boolean theIsVerbose = Standard_False);
47
48public: //! @name Tcl variables management tools
49
42cf5bc1 50 //! Sets a variable. Display it if <Disp> is true.
51 Standard_EXPORT static void Set (const Standard_CString Name, const Handle(Draw_Drawable3D)& D, const Standard_Boolean Disp);
52
53 //! Sets a variable, a null handle clear the
54 //! vartiable. Automatic display is context driven.
55 Standard_EXPORT static void Set (const Standard_CString Name, const Handle(Draw_Drawable3D)& D);
56
57 //! Sets a numeric variable.
58 Standard_EXPORT static void Set (const Standard_CString Name, const Standard_Real val);
e59839c8 59
60 //! Returns main DRAW interpretor.
61 Standard_EXPORT static Draw_Interpretor& GetInterpretor();
1c8fc6be 62
63 //! Returns a variable value.
64 //! The name "." does a graphic selection; in this case theName will be is overwritten with the name of the variable.
65 static Handle(Draw_Drawable3D) Get (Standard_CString& theName) { return getDrawable (theName, Standard_True); }
66
67 //! Returns a variable value.
68 static Handle(Draw_Drawable3D) GetExisting (const Standard_CString& theName)
69 {
70 Standard_CString aName = theName;
71 return getDrawable (aName, Standard_False);
72 }
73
42cf5bc1 74 //! Gets a numeric variable. Returns True if the
75 //! variable exist.
76 Standard_EXPORT static Standard_Boolean Get (const Standard_CString Name, Standard_Real& val);
77
78 //! Sets a TCL sting variable
79 Standard_EXPORT static void Set (const Standard_CString Name, const Standard_CString val);
dae2a922 80
81public: //! @name argument parsing tools
42cf5bc1 82
83 //! Converts numeric expression, that can involve DRAW
84 //! variables, to real value.
85 Standard_EXPORT static Standard_Real Atof (const Standard_CString Name);
f9b30c0d 86
87 //! Converts the numeric expression, that can involve DRAW variables, to a real value
dae2a922 88 //! @param theExpressionString the strings that contains the expression involving DRAW variables to be parsed
f9b30c0d 89 //! @param theParsedRealValue a real value that is a result of parsing
dae2a922 90 //! @return true if parsing was successful, or false otherwise
f9b30c0d 91 Standard_EXPORT static bool ParseReal (const Standard_CString theExpressionString, Standard_Real& theParsedRealValue);
92
42cf5bc1 93 //! Converts numeric expression, that can involve DRAW
94 //! variables, to integer value.
95 //! Implemented as cast of Atof() to integer.
96 Standard_EXPORT static Standard_Integer Atoi (const Standard_CString Name);
f9b30c0d 97
98 //! Converts the numeric expression, that can involve DRAW variables, to an integer value
dae2a922 99 //! @param theExpressionString the strings that contains the expression involving DRAW variables to be parsed
f9b30c0d 100 //! @param theParsedIntegerValue an integer value that is a result of parsing
dae2a922 101 //! @return true if parsing was successful, or false otherwise
f9b30c0d 102 Standard_EXPORT static bool ParseInteger (const Standard_CString theExpressionString,
103 Standard_Integer& theParsedIntegerValue);
104
dae2a922 105 //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and theArgVec[3].
106 //! Handles either color specified by name (single argument) or by RGB(A) components (3-4 arguments) in range 0..1.
107 //! The result is stored in theColor on success.
108 //!
109 //! Usage code sample for command argument in form "cmd -color {ColorName|R G B [A]|ColorHex}":
110 //! @code
111 //! for (int anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
112 //! {
113 //! TCollection_AsciiString aParam (theArgVec[anArgIter]);
114 //! aParam.LowerCase();
115 //! if (aParam == "-color")
116 //! {
117 //! Quantity_ColorRGBA aColor;
118 //! Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1,
119 //! theArgVec + anArgIter + 1, aColor);
120 //! anArgIter += aNbParsed;
121 //! if (aNbParsed == 0) { std::cerr << "Syntax error at '" << aParam << "'"; return 1; }
122 //! // process color
123 //! }
124 //! }
125 //! @endcode
126 //!
127 //! @param theArgNb [in] number of available arguments in theArgVec (array limits)
128 //! @param theArgVec [in] argument list
129 //! @param theColor [out] retrieved color
130 //! @return number of handled arguments (1, 2, 3 or 4) or 0 on syntax error
131 static Standard_Integer ParseColor (const Standard_Integer theArgNb,
132 const char* const* const theArgVec,
133 Quantity_ColorRGBA& theColor)
134 {
135 return parseColor (theArgNb, theArgVec, theColor, true);
136 }
137
138 //! Parses RGB color argument(s).
139 //! @param theArgNb [in] number of available arguments in theArgVec (array limits)
140 //! @param theArgVec [in] argument list
141 //! @param theColor [out] retrieved color
142 //! @return number of handled arguments (1 or 3) or 0 on syntax error.
143 static Standard_Integer ParseColor (const Standard_Integer theArgNb,
144 const char* const* const theArgVec,
145 Quantity_Color& theColor)
146 {
147 Quantity_ColorRGBA anRgba;
148 const Standard_Integer aNbParsed = parseColor (theArgNb, theArgVec, anRgba, false);
149 if (aNbParsed != 0)
150 {
151 theColor = anRgba.GetRGB();
152 }
153 return aNbParsed;
154 }
155
156 //! Parses boolean argument. Handles either flag specified by 0|1 or on|off.
157 //!
158 //! Usage code sample for command argument in form "cmd -usefeature [on|off|1|0]=on":
159 //! @code
160 //! for (int anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
161 //! {
162 //! TCollection_AsciiString aParam (theArgVec[anArgIter]);
163 //! aParam.LowerCase();
164 //! if (aParam == "-usefeature")
165 //! {
166 //! bool toUseFeature = true;
167 //! if (anArgIter + 1 < theNbArgs && Draw::ParseOnOff (theArgVec[anArgIter + 1]))
168 //! {
169 //! ++anArgIter;
170 //! }
171 //! // process feature
172 //! }
173 //! }
174 //! @endcode
175 //!
176 //! @param theArg [in] argument value
177 //! @param theIsOn [out] decoded Boolean flag
178 //! @return FALSE on syntax error
179 Standard_EXPORT static Standard_Boolean ParseOnOff (Standard_CString theArg,
180 Standard_Boolean& theIsOn);
181
182public:
183
42cf5bc1 184 //! Returns last graphic selection description.
185 Standard_EXPORT static void LastPick (Standard_Integer& view, Standard_Integer& X, Standard_Integer& Y, Standard_Integer& button);
186
187 //! Asks to repaint the screen after the current command.
188 Standard_EXPORT static void Repaint();
189
190 //! sets progress indicator
7e785937 191 Standard_EXPORT static void SetProgressBar (const Handle(Draw_ProgressIndicator)& theProgress);
42cf5bc1 192
193 //! gets progress indicator
194 Standard_EXPORT static Handle(Draw_ProgressIndicator) GetProgressBar();
dae2a922 195
196public: //! @name methods loading standard command sets
197
42cf5bc1 198 //! Defines all Draw commands
199 Standard_EXPORT static void Commands (Draw_Interpretor& I);
200
201 //! Defines Draw basic commands
202 Standard_EXPORT static void BasicCommands (Draw_Interpretor& I);
203
204 //! Defines Draw variables handling commands.
205 Standard_EXPORT static void VariableCommands (Draw_Interpretor& I);
206
207 //! Defines Draw variables handling commands.
208 Standard_EXPORT static void GraphicCommands (Draw_Interpretor& I);
209
210 //! Defines Loads Draw plugins commands.
211 Standard_EXPORT static void PloadCommands (Draw_Interpretor& I);
212
213 //! Defines Draw unit commands
214 Standard_EXPORT static void UnitCommands (Draw_Interpretor& I);
215
42cf5bc1 216protected:
217
1c8fc6be 218 //! Returns a variable value.
219 //! @param theName [in] [out] variable name, or "." to activate picking
220 //! @param theToAllowPick [in] when TRUE, "." name will activate picking
221 Standard_EXPORT static Handle(Draw_Drawable3D) getDrawable (Standard_CString& theName,
222 Standard_Boolean theToAllowPick);
42cf5bc1 223
dae2a922 224 //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and theArgVec[3].
225 //! Handles either color specified by name (single argument)
226 //! or by RGB(A) components (3-4 arguments) in range 0..1.
227 //! The result is stored in theColor on success.
228 //! Returns number of handled arguments (1, 2, 3 or 4) or 0 on syntax error.
229 Standard_EXPORT static Standard_Integer parseColor (Standard_Integer theArgNb,
230 const char* const* theArgVec,
231 Quantity_ColorRGBA& theColor,
232 bool theToParseAlpha);
42cf5bc1 233
234};
235
42cf5bc1 236#endif // _Draw_HeaderFile