Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:25

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