Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:16:08

0001 // Created on: 1994-07-27
0002 // Created by: Remi LEQUETTE
0003 // Copyright (c) 1994-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_Window_HeaderFile
0018 #define Draw_Window_HeaderFile
0019 
0020 #if defined(_WIN32)
0021   #include <windows.h>
0022 #endif
0023 
0024 #include <Aspect_Drawable.hxx>
0025 #include <NCollection_Vec2.hxx>
0026 #include <TCollection_AsciiString.hxx>
0027 
0028 #include <memory>
0029 
0030 const int MAXCOLOR = 15;
0031 
0032 //! Segment definition.
0033 struct Draw_XSegment
0034 {
0035   NCollection_Vec2<short> Points[2]; // same as XSegment
0036 
0037   NCollection_Vec2<short>& operator[](int theIndex) { return Points[theIndex]; }
0038 
0039   const NCollection_Vec2<short>& operator[](int theIndex) const { return Points[theIndex]; }
0040 
0041   void Init(int theXStart, int theYStart, int theXEnd, int theYEnd)
0042   {
0043     Points[0].SetValues((short)theXStart, (short)theYStart);
0044     Points[1].SetValues((short)theXEnd, (short)theYEnd);
0045   }
0046 };
0047 
0048 #if defined(_WIN32)
0049 
0050   #define DRAWCLASS L"DRAWWINDOW"
0051   #define DRAWTITLE L"Draw View"
0052 
0053 enum console_semaphore_value
0054 {
0055   STOP_CONSOLE,
0056   WAIT_CONSOLE_COMMAND,
0057   HAS_CONSOLE_COMMAND
0058 };
0059 
0060 // global variable describing console state
0061 extern console_semaphore_value volatile console_semaphore;
0062 
0063   // Console command buffer
0064   #define DRAW_COMMAND_SIZE 1000
0065 extern wchar_t console_command[DRAW_COMMAND_SIZE + 1];
0066 
0067 // PROCEDURE DE DRAW WINDOW
0068 Standard_EXPORT bool Init_Appli(HINSTANCE, HINSTANCE, int, HWND&);
0069 Standard_EXPORT void Run_Appli(HWND);
0070 Standard_EXPORT void Destroy_Appli(HINSTANCE);
0071 
0072 #else
0073 
0074 //! Run the application.
0075 //! interp will be called to interpret a command and return True if the command is complete.
0076 void Run_Appli(bool (*inteprete)(const char*));
0077 
0078 //! Initialize application.
0079 bool Init_Appli();
0080 
0081 //! Destroy application.
0082 void Destroy_Appli();
0083 
0084   #if defined(HAVE_XLIB)
0085 
0086 typedef unsigned long Window;
0087 typedef unsigned long Pixmap;
0088 typedef unsigned long Drawable;
0089 
0090   #elif defined(__APPLE__)
0091     #ifdef __OBJC__
0092 @class NSView;
0093 @class NSWindow;
0094 @class NSImage;
0095 @class Draw_CocoaView;
0096     #else
0097 struct NSView;
0098 struct NSWindow;
0099 struct NSImage;
0100 struct Draw_CocoaView;
0101     #endif
0102   #endif
0103 
0104 #endif
0105 
0106 //! Draw window.
0107 class Draw_Window
0108 {
0109 public:
0110   //! Type of the callback function that is to be passed to the method AddCallbackBeforeTerminate().
0111   typedef void (*FCallbackBeforeTerminate)();
0112 
0113   //! This method registers a callback function that will be called just before exit.
0114   //! This is useful especially for Windows platform, on which Draw is normally self-terminated
0115   //! instead of exiting.
0116   Standard_EXPORT static void AddCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
0117 
0118   //! Just in case method for un-registering a callback previously registered by
0119   //! AddCallbackBeforeTerminate().
0120   Standard_EXPORT static void RemoveCallbackBeforeTerminate(FCallbackBeforeTerminate theCB);
0121 
0122   //! @sa SetColor()
0123   Standard_EXPORT static bool DefineColor(const int theIndex, const char* theColorName);
0124 
0125   //! XFlush() wrapper (X11), has no effect on other platforms.
0126   Standard_EXPORT static void Flush();
0127 
0128 public:
0129   //! Destructor.
0130   Standard_EXPORT virtual ~Draw_Window();
0131 
0132   //! Get window position.
0133   Standard_EXPORT void GetPosition(int& thePosX, int& thePosY);
0134 
0135   //! Set window position.
0136   Standard_EXPORT void SetPosition(int theNewXpos, int theNewYpos);
0137 
0138   //! Return window height.
0139   Standard_EXPORT int HeightWin() const;
0140 
0141   //! Return window width.
0142   Standard_EXPORT int WidthWin() const;
0143 
0144   //! Set window dimensions.
0145   Standard_EXPORT void SetDimension(int theNewDx, int theNewDy);
0146 
0147   //! Return window title.
0148   Standard_EXPORT TCollection_AsciiString GetTitle() const;
0149 
0150   //! Set window title.
0151   Standard_EXPORT void SetTitle(const TCollection_AsciiString& theTitle);
0152 
0153   //! Return true if window is displayed on the screen.
0154   Standard_EXPORT bool IsMapped() const;
0155 
0156   //! Display window on the screen.
0157   Standard_EXPORT void DisplayWindow();
0158 
0159   //! Hide window.
0160   Standard_EXPORT void Hide();
0161 
0162   //! Destroy window.
0163   Standard_EXPORT void Destroy();
0164 
0165   //! Clear window content.
0166   Standard_EXPORT void Clear();
0167 
0168   //! Returns true if off-screen image buffer is being used
0169   bool GetUseBuffer() const { return myUseBuffer; }
0170 
0171   // Turns on/off usage of off-screen image buffer (can be used for redrawing optimization)
0172   Standard_EXPORT void SetUseBuffer(bool theToUse);
0173 
0174   //! Set active color index for further paintings.
0175   //! @sa DefineColor()
0176   Standard_EXPORT void SetColor(int theColor);
0177 
0178   //! Set active paint mode (3 for COPY; 6 for XOR).
0179   Standard_EXPORT void SetMode(int theMode);
0180 
0181   //! Draw the string.
0182   Standard_EXPORT void DrawString(int theX, int theY, const char* theText);
0183 
0184   //! Draw array of segments.
0185   Standard_EXPORT void DrawSegments(const Draw_XSegment* theSegments, int theNumberOfElements);
0186 
0187   //! Redraw window content.
0188   Standard_EXPORT void Redraw();
0189 
0190   //! Save snapshot.
0191   Standard_EXPORT bool Save(const char* theFileName) const;
0192 
0193   //! Perform window exposing.
0194   virtual void WExpose() = 0;
0195 
0196   //! (Re)initializes off-screen image buffer according to current window size.
0197   Standard_EXPORT void InitBuffer();
0198 
0199 protected:
0200   //! Main constructor.
0201   //! @param[in] theTitle   window title
0202   //! @param[in] theXY      top-left position
0203   //! @param[in] theSize    window dimensions
0204   //! @param[in] theParent  optional native parent window
0205   //! @param[in] theWin     optional native window
0206   Standard_EXPORT Draw_Window(const char*                  theTitle,
0207                               const NCollection_Vec2<int>& theXY,
0208                               const NCollection_Vec2<int>& theSize,
0209                               Aspect_Drawable              theParent,
0210                               Aspect_Drawable              theWin);
0211 
0212   //! Initialize the window.
0213   Standard_EXPORT void init(const NCollection_Vec2<int>& theXY,
0214                             const NCollection_Vec2<int>& theSize);
0215 
0216 public:
0217 #if defined(_WIN32)
0218   bool IsEqualWindows(HANDLE theWindow) { return myWindow == theWindow; }
0219 
0220   Standard_EXPORT static void SelectWait(HANDLE& theWindow, int& theX, int& theY, int& theButton);
0221   Standard_EXPORT static void SelectNoWait(HANDLE& theWindow, int& theX, int& theY, int& theButton);
0222   // Procedure de fenetre
0223   Standard_EXPORT static LRESULT APIENTRY DrawProc(HWND, UINT, WPARAM, LPARAM);
0224   static HWND                             hWndClientMDI;
0225 #elif defined(HAVE_XLIB)
0226   bool IsEqualWindows(Window theWindow) { return myWindow == theWindow; }
0227 
0228   //! Event structure.
0229   struct Draw_XEvent
0230   {
0231     int    type;
0232     Window window;
0233     int    button;
0234     int    x;
0235     int    y;
0236   };
0237 
0238   //! Retrieve event.
0239   static void GetNextEvent(Draw_XEvent& theEvent);
0240 
0241   void Wait(bool theToWait = true);
0242 #elif defined(__APPLE__)
0243   bool IsEqualWindows(const long theWindowNumber);
0244 
0245   static void GetNextEvent(bool  theWait,
0246                            long& theWindowNumber,
0247                            int&  theX,
0248                            int&  theY,
0249                            int&  theButton);
0250 #endif
0251 
0252 private:
0253 #if defined(_WIN32)
0254   Standard_EXPORT static HWND createDrawWindow(HWND, int);
0255   Standard_EXPORT HDC         getMemDC(HDC theWinDC);
0256   Standard_EXPORT void        releaseMemDC(HDC theMemDC);
0257 #elif defined(HAVE_XLIB)
0258   Drawable GetDrawable() const { return myUseBuffer ? myImageBuffer : myWindow; }
0259   struct Base_Window; // opaque structure with extra Xlib parameters
0260 #endif
0261 
0262 private:
0263 #if defined(_WIN32)
0264   HWND    myWindow; //!< native window
0265   HBITMAP myMemHbm;
0266   HBITMAP myOldHbm;
0267   int     myCurrPen;
0268   int     myCurrMode;
0269 #elif defined(HAVE_XLIB)
0270   Window                       myWindow; //!< native window
0271   Window                       myMother; //!< parent native window
0272   Pixmap                       myImageBuffer;
0273   std::unique_ptr<Base_Window> myBase;
0274 #elif defined(__APPLE__)
0275   NSWindow*       myWindow; //!< native window
0276   Draw_CocoaView* myView;
0277   NSImage*        myImageBuffer;
0278 #else
0279   Aspect_Drawable myWindow;
0280 #endif
0281   int  myCurrentColor;
0282   bool myUseBuffer;
0283 };
0284 
0285 #endif // Draw_Window_HeaderFile