Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 09:14:08

0001 // Created on: 1991-04-24
0002 // Created by: Arnaud BOUZY
0003 // Copyright (c) 1991-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Draw_HeaderFile
0018 #define _Draw_HeaderFile
0019 
0020 #include <Draw_Interpretor.hxx>
0021 #include <NCollection_Map.hxx>
0022 #include <Quantity_ColorRGBA.hxx>
0023 #include <Standard_Handle.hxx>
0024 
0025 class Draw_Drawable3D;
0026 class Draw_ProgressIndicator;
0027 
0028 //! MAQUETTE DESSIN MODELISATION
0029 class Draw
0030 {
0031 public:
0032   DEFINE_STANDARD_ALLOC
0033 
0034   //! (Re)Load a Draw Harness plugin.
0035   //! @param[in][out] theDI    Tcl interpreter to append loaded commands
0036   //! @param[in] theKey  plugin code name to be resolved in resource file
0037   //! @param[in] theResourceFileName    description file name
0038   //! @param[in] theDefaultsDirectory   default folder for looking description file
0039   //! @param[in] theUserDefaultsDirectory  user folder for looking description file
0040   //! @param[in] theIsVerbose  print verbose messages
0041   Standard_EXPORT static void Load(Draw_Interpretor&              theDI,
0042                                    const TCollection_AsciiString& theKey,
0043                                    const TCollection_AsciiString& theResourceFileName,
0044                                    const TCollection_AsciiString& theDefaultsDirectory,
0045                                    const TCollection_AsciiString& theUserDefaultsDirectory,
0046                                    const bool                     theIsVerbose = false);
0047 
0048 public: //! @name Tcl variables management tools
0049   //! Sets a variable. Display it if <Disp> is true.
0050   Standard_EXPORT static void Set(const char* const                   Name,
0051                                   const occ::handle<Draw_Drawable3D>& D,
0052                                   const bool                          Disp);
0053 
0054   //! Sets a variable, a null handle clear the
0055   //! vartiable. Automatic display is context driven.
0056   Standard_EXPORT static void Set(const char* const Name, const occ::handle<Draw_Drawable3D>& D);
0057 
0058   //! Sets a numeric variable.
0059   Standard_EXPORT static void Set(const char* const Name, const double val);
0060 
0061   //! Returns main DRAW interpreter.
0062   Standard_EXPORT static Draw_Interpretor& GetInterpretor();
0063 
0064   //! Returns a variable value.
0065   //! The name "." does a graphic selection; in this case theName will be is overwritten with the
0066   //! name of the variable.
0067   static occ::handle<Draw_Drawable3D> Get(const char*& theName)
0068   {
0069     return getDrawable(theName, true);
0070   }
0071 
0072   //! Returns a variable value.
0073   static occ::handle<Draw_Drawable3D> GetExisting(const char* const theName)
0074   {
0075     const char* aName = theName;
0076     return getDrawable(aName, false);
0077   }
0078 
0079   //! Gets a numeric variable. Returns True if the
0080   //! variable exist.
0081   Standard_EXPORT static bool Get(const char* const Name, double& val);
0082 
0083   //! Sets a TCL string variable
0084   Standard_EXPORT static void Set(const char* const Name, const char* const val);
0085 
0086   //! Returns a map of Draw_Drawable3D variables.
0087   Standard_EXPORT static const NCollection_Map<occ::handle<Draw_Drawable3D>>& Drawables();
0088 
0089 public: //! @name argument parsing tools
0090   //! Converts numeric expression, that can involve DRAW
0091   //! variables, to real value.
0092   Standard_EXPORT static double Atof(const char* const Name);
0093 
0094   //! Converts the numeric expression, that can involve DRAW variables, to a real value
0095   //! @param theExpressionString the strings that contains the expression involving DRAW variables
0096   //! to be parsed
0097   //! @param theParsedRealValue a real value that is a result of parsing
0098   //! @return true if parsing was successful, or false otherwise
0099   Standard_EXPORT static bool ParseReal(const char* const theExpressionString,
0100                                         double&           theParsedRealValue);
0101 
0102   //! Converts numeric expression, that can involve DRAW
0103   //! variables, to integer value.
0104   //! Implemented as cast of Atof() to integer.
0105   Standard_EXPORT static int Atoi(const char* const Name);
0106 
0107   //! Converts the numeric expression, that can involve DRAW variables, to an integer value
0108   //! @param theExpressionString the strings that contains the expression involving DRAW variables
0109   //! to be parsed
0110   //! @param theParsedIntegerValue an integer value that is a result of parsing
0111   //! @return true if parsing was successful, or false otherwise
0112   Standard_EXPORT static bool ParseInteger(const char* const theExpressionString,
0113                                            int&              theParsedIntegerValue);
0114 
0115   //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and
0116   //! theArgVec[3]. Handles either color specified by name (single argument) or by RGB(A) components
0117   //! (3-4 arguments) in range 0..1. The result is stored in theColor on success.
0118   //!
0119   //! Usage code sample for command argument in form "cmd -color {ColorName|R G B [A]|ColorHex}":
0120   //! @code
0121   //!   for (int anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
0122   //!   {
0123   //!     TCollection_AsciiString aParam (theArgVec[anArgIter]);
0124   //!     aParam.LowerCase();
0125   //!     if (aParam == "-color")
0126   //!     {
0127   //!       Quantity_ColorRGBA aColor;
0128   //!       int aNbParsed = Draw::ParseColor (theArgNb  - anArgIter - 1,
0129   //!                                                      theArgVec + anArgIter + 1, aColor);
0130   //!       anArgIter += aNbParsed;
0131   //!       if (aNbParsed == 0) { std::cerr << "Syntax error at '" << aParam << "'"; return 1; }
0132   //!       // process color
0133   //!     }
0134   //!   }
0135   //! @endcode
0136   //!
0137   //! @param[in] theArgNb   number of available arguments in theArgVec (array limits)
0138   //! @param[in] theArgVec  argument list
0139   //! @param[out] theColor  retrieved color
0140   //! @return number of handled arguments (1, 2, 3 or 4) or 0 on syntax error
0141   static int ParseColor(const int                theArgNb,
0142                         const char* const* const theArgVec,
0143                         Quantity_ColorRGBA&      theColor)
0144   {
0145     return parseColor(theArgNb, theArgVec, theColor, true);
0146   }
0147 
0148   //! Parses RGB color argument(s).
0149   //! @param[in] theArgNb   number of available arguments in theArgVec (array limits)
0150   //! @param[in] theArgVec  argument list
0151   //! @param[out] theColor  retrieved color
0152   //! @return number of handled arguments (1 or 3) or 0 on syntax error.
0153   static int ParseColor(const int                theArgNb,
0154                         const char* const* const theArgVec,
0155                         Quantity_Color&          theColor)
0156   {
0157     Quantity_ColorRGBA anRgba;
0158     const int          aNbParsed = parseColor(theArgNb, theArgVec, anRgba, false);
0159     if (aNbParsed != 0)
0160     {
0161       theColor = anRgba.GetRGB();
0162     }
0163     return aNbParsed;
0164   }
0165 
0166   //! Parses boolean argument. Handles either flag specified by 0|1 or on|off.
0167   //!
0168   //! Usage code sample for command argument in form "cmd -usefeature [on|off|1|0]=on":
0169   //! @code
0170   //!   for (int anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
0171   //!   {
0172   //!     TCollection_AsciiString aParam (theArgVec[anArgIter]);
0173   //!     aParam.LowerCase();
0174   //!     if (aParam == "-usefeature")
0175   //!     {
0176   //!       bool toUseFeature = true;
0177   //!       if (anArgIter + 1 < theNbArgs && Draw::ParseOnOff (theArgVec[anArgIter + 1]))
0178   //!       {
0179   //!         ++anArgIter;
0180   //!       }
0181   //!       // process feature
0182   //!     }
0183   //!   }
0184   //! @endcode
0185   //!
0186   //! @param[in] theArg    argument value
0187   //! @param[out] theIsOn  decoded Boolean flag
0188   //! @return FALSE on syntax error
0189   Standard_EXPORT static bool ParseOnOff(const char* theArg, bool& theIsOn);
0190 
0191   //! Parses boolean argument at specified iterator position with optional on/off coming next.
0192   //!
0193   //! Usage code sample for command argument in form "cmd -usefeature [on|off|1|0]=on":
0194   //! @code
0195   //!   for (int anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
0196   //!   {
0197   //!     if (strcasecmp (theArgVec[anArgIter], "-usefeature") == 0)
0198   //!     {
0199   //!       bool toUseFeature = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
0200   //!       // process feature
0201   //!     }
0202   //!   }
0203   //! @endcode
0204   //!
0205   //! @param[in] theArgsNb  overall number of arguments
0206   //! @param[in] theArgVec  vector of arguments
0207   //! @param[in][out] theArgIter   argument position to parse
0208   //! @return flag value
0209   Standard_EXPORT static bool ParseOnOffIterator(int          theArgsNb,
0210                                                  const char** theArgVec,
0211                                                  int&         theArgIter);
0212 
0213   //! Parses boolean argument at specified iterator position with optional on/off coming next.
0214   //! Similar to ParseOnOffIterator() but also reverses returned value if argument name starts with
0215   //! "no" prefix. E.g. if nominal argument is "cmd -usefeature [on|off|1|0]=on", then
0216   //! "-nousefeature" argument will return FALSE.
0217   //! @param[in] theArgsNb  overall number of arguments
0218   //! @param[in] theArgVec  vector of arguments
0219   //! @param[in][out] theArgIter   argument position to parse
0220   //! @return flag value
0221   Standard_EXPORT static bool ParseOnOffNoIterator(int          theArgsNb,
0222                                                    const char** theArgVec,
0223                                                    int&         theArgIter);
0224 
0225 public:
0226   //! Returns last graphic selection description.
0227   Standard_EXPORT static void LastPick(int& view, int& X, int& Y, int& button);
0228 
0229   //! Asks to repaint the screen after the current command.
0230   Standard_EXPORT static void Repaint();
0231 
0232   //! sets progress indicator
0233   Standard_EXPORT static void SetProgressBar(
0234     const occ::handle<Draw_ProgressIndicator>& theProgress);
0235 
0236   //! gets progress indicator
0237   Standard_EXPORT static occ::handle<Draw_ProgressIndicator> GetProgressBar();
0238 
0239 public: //! @name methods loading standard command sets
0240   //! Defines all Draw commands
0241   Standard_EXPORT static void Commands(Draw_Interpretor& I);
0242 
0243   //! Defines Draw basic commands
0244   Standard_EXPORT static void BasicCommands(Draw_Interpretor& I);
0245 
0246   //! Defines Draw message commands
0247   Standard_EXPORT static void MessageCommands(Draw_Interpretor& I);
0248 
0249   //! Defines Draw variables handling commands.
0250   Standard_EXPORT static void VariableCommands(Draw_Interpretor& I);
0251 
0252   //! Defines Draw variables handling commands.
0253   Standard_EXPORT static void GraphicCommands(Draw_Interpretor& I);
0254 
0255   //! Defines Loads Draw plugins commands.
0256   Standard_EXPORT static void PloadCommands(Draw_Interpretor& I);
0257 
0258   //! Defines Draw unit commands
0259   Standard_EXPORT static void UnitCommands(Draw_Interpretor& I);
0260 
0261 protected:
0262   //! Returns a variable value.
0263   //! @param[in][out] theName   variable name, or "." to activate picking
0264   //! @param[in] theToAllowPick  when TRUE, "." name will activate picking
0265   Standard_EXPORT static occ::handle<Draw_Drawable3D> getDrawable(const char*& theName,
0266                                                                   bool         theToAllowPick);
0267 
0268   //! Parses RGB(A) color argument(s) specified within theArgVec[0], theArgVec[1], theArgVec[2] and
0269   //! theArgVec[3]. Handles either color specified by name (single argument) or by RGB(A) components
0270   //! (3-4 arguments) in range 0..1. The result is stored in theColor on success. Returns number of
0271   //! handled arguments (1, 2, 3 or 4) or 0 on syntax error.
0272   Standard_EXPORT static int parseColor(int                 theArgNb,
0273                                         const char* const*  theArgVec,
0274                                         Quantity_ColorRGBA& theColor,
0275                                         bool                theToParseAlpha);
0276 };
0277 
0278 #endif // _Draw_HeaderFile