p Voxel
p WNT
p Xw
+p Cocoa
r FontMFT
r Textures
t TKMeshVS
--- /dev/null
+// Copyright (c) 2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#ifndef __Cocoa_LocalPool_h_
+#define __Cocoa_LocalPool_h_
+
+//! Auxiliary class to create
+class Cocoa_LocalPool
+{
+
+public:
+
+ Cocoa_LocalPool();
+ ~Cocoa_LocalPool();
+
+private:
+
+ void* myPoolObj;
+
+};
+
+#endif // __Cocoa_LocalPool_h_
--- /dev/null
+// Copyright (c) 2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#if (defined(__APPLE__))
+
+#include <Cocoa_LocalPool.hxx>
+
+#import <Cocoa/Cocoa.h>
+
+// =======================================================================
+// function : Cocoa_LocalPool
+// purpose :
+// =======================================================================
+Cocoa_LocalPool::Cocoa_LocalPool()
+: myPoolObj ([[NSAutoreleasePool alloc] init])
+{
+ //
+}
+
+// =======================================================================
+// function : ~Cocoa_LocalPool
+// purpose :
+// =======================================================================
+Cocoa_LocalPool::~Cocoa_LocalPool()
+{
+ NSAutoreleasePool* aPool = (NSAutoreleasePool* )myPoolObj;
+ //[aPool drain];
+ [aPool release];
+}
+
+#endif // __APPLE__
--- /dev/null
+// Created on: 2012-11-12
+// Created by: Kirill GAVRILOV
+// Copyright (c) 2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 65 (the "License") You may not use the content of this file
+// except in compliance with the License Please obtain a copy of the License
+// at http://wwwopencascadeorg and read it completely before using this file
+//
+// The Initial Developer of the Original Code is Open CASCADE SAS, having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License
+
+#ifndef _Cocoa_Window_H__
+#define _Cocoa_Window_H__
+
+#ifdef __OBJC__
+ @class NSView;
+ @class NSWindow;
+#else
+ struct NSView;
+ struct NSWindow;
+#endif
+
+#include <Aspect_Window.hxx>
+
+#include <Standard.hxx>
+#include <Standard_DefineHandle.hxx>
+
+#include <Aspect_FillMethod.hxx>
+#include <Aspect_GradientFillMethod.hxx>
+#include <Aspect_Handle.hxx>
+#include <Aspect_TypeOfResize.hxx>
+#include <Quantity_NameOfColor.hxx>
+#include <Quantity_Parameter.hxx>
+#include <Quantity_Ratio.hxx>
+
+class Aspect_WindowDefinitionError;
+class Aspect_WindowError;
+class Aspect_Background;
+class Quantity_Color;
+class Aspect_GradientBackground;
+
+//! This class defines Cocoa window
+class Cocoa_Window : public Aspect_Window
+{
+
+public:
+
+ //! Creates a NSWindow and NSView defined by his position and size in pixels
+ Standard_EXPORT Cocoa_Window (const Standard_CString theTitle,
+ const Standard_Integer thePxLeft,
+ const Standard_Integer thePxTop,
+ const Standard_Integer thePxWidth,
+ const Standard_Integer thePxHeight);
+
+ //! Creates a wrapper over existing NSView handle
+ Standard_EXPORT Cocoa_Window (NSView* theViewNS);
+
+ //! Destroies the Window and all resourses attached to it
+ Standard_EXPORT virtual void Destroy();
+
+ ~Cocoa_Window()
+ {
+ Destroy();
+ }
+
+ //! Modifies the window background
+ Standard_EXPORT virtual void SetBackground (const Aspect_Background& theBackground);
+
+ //! Modifies the window background
+ Standard_EXPORT virtual void SetBackground (const Quantity_NameOfColor theBackColor);
+
+ //! Modifies the window background
+ Standard_EXPORT virtual void SetBackground (const Quantity_Color& theColor);
+
+ //! Modifies the window background
+ Standard_EXPORT void SetBackground (const Aspect_Handle theBackPixmap);
+
+ //! Loads the window background from an image file
+ Standard_EXPORT Standard_Boolean SetBackground (const Standard_CString theName,
+ const Aspect_FillMethod theMethod = Aspect_FM_CENTERED);
+
+ //! Modifies the window gradient background
+ Standard_EXPORT virtual void SetBackground (const Aspect_GradientBackground& theBackground);
+
+ //! Modifies the window gradient background
+ Standard_EXPORT void SetBackground (const Quantity_Color& theCol1,
+ const Quantity_Color& theCol2,
+ const Aspect_GradientFillMethod theMethod = Aspect_GFM_HOR);
+
+ //! Activates/Deactivates the Double Buffering capability for this window
+ Standard_EXPORT virtual void SetDoubleBuffer (const Standard_Boolean theDBmode);
+
+ //! Flushes all graphics to the screen and Swap the Double buffer
+ Standard_EXPORT virtual void Flush() const;
+
+ //! Opens the window <me>
+ Standard_EXPORT virtual void Map() const;
+
+ //! Closes the window <me>
+ Standard_EXPORT virtual void Unmap() const;
+
+ //! Applies the resizing to the window <me>
+ Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const;
+
+ //! Apply the mapping change to the window <me>
+ Standard_EXPORT virtual Standard_Boolean DoMapping() const;
+
+ //! Clears the Window in the Background color
+ Standard_EXPORT virtual void Clear() const;
+
+ //! Clears the Window Area defined by his center and PIXEL size in the Background color
+ Standard_EXPORT virtual void ClearArea (const Standard_Integer theCenterX,
+ const Standard_Integer theCenterY,
+ const Standard_Integer theWidth,
+ const Standard_Integer theHeight) const;
+
+ //! Restores The Window from the BackingStored Window
+ Standard_EXPORT virtual void Restore() const;
+
+ //! Restores The Window Area defined by his center and PIXEL size from the BackingStored Window
+ Standard_EXPORT virtual void RestoreArea (const Standard_Integer theCenterX,
+ const Standard_Integer theCenterY,
+ const Standard_Integer theWidth,
+ const Standard_Integer theHeight) const;
+
+ //! Dumps the Window to file
+ Standard_EXPORT virtual Standard_Boolean Dump (const Standard_CString theFilename,
+ const Standard_Real theGammaValue = 1.0) const;
+
+ //! Dumps the Window Area defined by his center and PIXEL size to an image file
+ Standard_EXPORT virtual Standard_Boolean DumpArea (const Standard_CString theFilename,
+ const Standard_Integer theCenterX,
+ const Standard_Integer theCenterY,
+ const Standard_Integer theWidth,
+ const Standard_Integer theHeight,
+ const Standard_Real theGammaValue = 1.0) const;
+
+ //! Loads the image file to this Window
+ //! @return TRUE if the loading occurs normaly
+ Standard_EXPORT virtual Standard_Boolean Load (const Standard_CString theFilename) const;
+
+ //! Loads the image file to Window Area
+ Standard_EXPORT virtual Standard_Boolean LoadArea (const Standard_CString theFilename,
+ const Standard_Integer theCenterX,
+ const Standard_Integer theCenterY,
+ const Standard_Integer theWidth,
+ const Standard_Integer theHeight) const;
+
+ //! Returns the BackingStore capability for this Window
+ Standard_EXPORT virtual Standard_Boolean BackingStore() const;
+
+ //! Returns the DoubleBuffer state
+ Standard_EXPORT virtual Standard_Boolean DoubleBuffer() const;
+
+ //! Returns True if the window <me> is opened
+ Standard_EXPORT virtual Standard_Boolean IsMapped() const;
+
+ //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
+ Standard_EXPORT virtual Quantity_Ratio Ratio() const;
+
+ //! Returns The Window POSITION in DSU
+ Standard_EXPORT virtual void Position (Quantity_Parameter& X1,
+ Quantity_Parameter& Y1,
+ Quantity_Parameter& X2,
+ Quantity_Parameter& Y2) const;
+
+ //! Returns The Window POSITION in PIXEL
+ Standard_EXPORT virtual void Position (Standard_Integer& X1,
+ Standard_Integer& Y1,
+ Standard_Integer& X2,
+ Standard_Integer& Y2) const;
+
+ //! Returns The Window SIZE in DSU
+ Standard_EXPORT virtual void Size (Quantity_Parameter& theWidth,
+ Quantity_Parameter& theHeight) const;
+
+ //! Returns The Window SIZE in PIXEL
+ Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
+ Standard_Integer& theHeight) const;
+
+ //! Returns The Window SIZE in MM
+ Standard_EXPORT virtual void MMSize (Standard_Real& theWidth,
+ Standard_Real& theHeight) const;
+
+ //! Returns the DSU value depending of the PIXEL value
+ Standard_EXPORT virtual Quantity_Parameter Convert (const Standard_Integer PV) const;
+
+ //! Returns the PIXEL value depending of the DSU value
+ Standard_EXPORT virtual Standard_Integer Convert (const Quantity_Parameter DV) const;
+
+ //! Returns the DSU position depending of the PIXEL position
+ Standard_EXPORT virtual void Convert (const Standard_Integer PX,
+ const Standard_Integer PY,
+ Quantity_Parameter& DX,
+ Quantity_Parameter& DY) const;
+
+ //! Returns the PIXEL position depending of the DSU position
+ Standard_EXPORT virtual void Convert (const Quantity_Parameter DX,
+ const Quantity_Parameter DY,
+ Standard_Integer& PX,
+ Standard_Integer& PY) const;
+
+ //! @return associated NSView
+ Standard_EXPORT NSView* HView() const;
+
+ //! Setup new NSView.
+ Standard_EXPORT void SetHView (NSView* theView);
+
+protected:
+
+ NSWindow* myHWindow;
+ NSView* myHView;
+ Standard_Integer myXLeft;
+ Standard_Integer myYTop;
+ Standard_Integer myXRight;
+ Standard_Integer myYBottom;
+
+public:
+
+ DEFINE_STANDARD_RTTI(Cocoa_Window)
+
+};
+
+DEFINE_STANDARD_HANDLE(Cocoa_Window, Aspect_Window)
+
+#endif // _Cocoa_Window_H__
--- /dev/null
+// Created on: 2012-11-12
+// Created by: Kirill GAVRILOV
+// Copyright (c) 2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#import <Cocoa/Cocoa.h>
+
+#include <Cocoa_Window.hxx>
+
+#include <Cocoa_LocalPool.hxx>
+
+#include <Image_AlienPixMap.hxx>
+#include <Aspect_Convert.hxx>
+#include <Aspect_GraphicDevice.hxx>
+#include <Aspect_WindowDefinitionError.hxx>
+
+IMPLEMENT_STANDARD_HANDLE (Cocoa_Window, Aspect_Window)
+IMPLEMENT_STANDARD_RTTIEXT(Cocoa_Window, Aspect_Window)
+
+//! Dummy device class implementation
+class Cocoa_GraphicDevice : public Aspect_GraphicDevice
+{
+
+public:
+
+ virtual Handle_Aspect_GraphicDriver GraphicDriver() const
+ {
+ return NULL;
+ }
+
+ DEFINE_STANDARD_RTTI(Cocoa_GraphicDevice)
+
+};
+
+DEFINE_STANDARD_HANDLE(Cocoa_GraphicDevice, Aspect_GraphicDevice)
+
+IMPLEMENT_STANDARD_HANDLE (Cocoa_GraphicDevice, Aspect_GraphicDevice)
+IMPLEMENT_STANDARD_RTTIEXT(Cocoa_GraphicDevice, Aspect_GraphicDevice)
+
+static Standard_Integer getScreenBottom()
+{
+ Cocoa_LocalPool aLocalPool;
+ NSArray* aScreens = [NSScreen screens];
+ if (aScreens == NULL || [aScreens count] == 0)
+ {
+ return 0;
+ }
+
+ NSScreen* aScreen = (NSScreen* )[aScreens objectAtIndex: 0];
+ NSDictionary* aDict = [aScreen deviceDescription];
+ NSNumber* aNumber = [aDict objectForKey: @"NSScreenNumber"];
+ if (aNumber == NULL
+ || [aNumber isKindOfClass: [NSNumber class]] == NO)
+ {
+ return 0;
+ }
+
+ CGDirectDisplayID aDispId = [aNumber unsignedIntValue];
+ CGRect aRect = CGDisplayBounds(aDispId);
+ return Standard_Integer(aRect.origin.y + aRect.size.height);
+}
+
+// =======================================================================
+// function : Cocoa_Window
+// purpose :
+// =======================================================================
+Cocoa_Window::Cocoa_Window (const Standard_CString theTitle,
+ const Standard_Integer thePxLeft,
+ const Standard_Integer thePxTop,
+ const Standard_Integer thePxWidth,
+ const Standard_Integer thePxHeight)
+: Aspect_Window (new Cocoa_GraphicDevice()),
+ myHWindow (NULL),
+ myHView (NULL),
+ myXLeft (thePxLeft),
+ myYTop (thePxTop),
+ myXRight (thePxLeft + thePxWidth),
+ myYBottom (thePxTop + thePxHeight)
+{
+ if (thePxWidth <= 0 || thePxHeight <= 0)
+ {
+ Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range");
+ }
+ else if (NSApp == NULL)
+ {
+ Aspect_WindowDefinitionError::Raise ("Cocoa application should be instantiated before window");
+ return;
+ }
+
+ // convert top-bottom coordinates to bottom-top (Cocoa)
+ myYTop = getScreenBottom() - myYBottom;
+ myYBottom = myYTop + thePxHeight;
+
+ Cocoa_LocalPool aLocalPool;
+ NSUInteger aWinStyle = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
+ NSRect aRectNs = NSMakeRect (float(myXLeft), float(myYTop), float(thePxWidth), float(thePxHeight));
+ myHWindow = [[NSWindow alloc] initWithContentRect: aRectNs
+ styleMask: aWinStyle
+ backing: NSBackingStoreBuffered
+ defer: NO];
+ if (myHWindow == NULL)
+ {
+ Aspect_WindowDefinitionError::Raise ("Unable to create window");
+ }
+ myHView = [[myHWindow contentView] retain];
+
+ NSString* aTitleNs = [[NSString alloc] initWithUTF8String: theTitle];
+ [myHWindow setTitle: aTitleNs];
+ [aTitleNs release];
+
+ // do not destroy NSWindow on close - we didn't handle it!
+ [myHWindow setReleasedWhenClosed: NO];
+}
+
+// =======================================================================
+// function : Cocoa_Window
+// purpose :
+// =======================================================================
+Cocoa_Window::Cocoa_Window (NSView* theViewNS)
+: Aspect_Window (new Cocoa_GraphicDevice()),
+ myHWindow (NULL),
+ myHView ([theViewNS retain]),
+ myXLeft (0),
+ myYTop (0),
+ myXRight (512),
+ myYBottom (512)
+{
+ DoResize();
+}
+
+// =======================================================================
+// function : Destroy
+// purpose :
+// =======================================================================
+void Cocoa_Window::Destroy()
+{
+ Cocoa_LocalPool aLocalPool;
+ if (myHWindow != NULL)
+ {
+ //[myHWindow close];
+ [myHWindow release];
+ myHWindow = NULL;
+ }
+ if (myHView != NULL)
+ {
+ [myHView release];
+ myHView = NULL;
+ }
+}
+
+// =======================================================================
+// function : HView
+// purpose :
+// =======================================================================
+NSView* Cocoa_Window::HView() const
+{
+ return myHView;
+}
+
+// =======================================================================
+// function : SetHView
+// purpose :
+// =======================================================================
+void Cocoa_Window::SetHView (NSView* theView)
+{
+ if (myHWindow != NULL)
+ {
+ [myHWindow setContentView: theView];
+ }
+ if (myHView != NULL)
+ {
+ [myHView release];
+ myHView = NULL;
+ }
+ myHView = [theView retain];
+}
+
+// =======================================================================
+// function : DoubleBuffer
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::DoubleBuffer() const
+{
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SetBackground
+// purpose :
+// =======================================================================
+void Cocoa_Window::SetBackground (const Aspect_Background& theBackground)
+{
+ SetBackground (theBackground.Color());
+}
+
+// =======================================================================
+// function : SetBackground
+// purpose :
+// =======================================================================
+void Cocoa_Window::SetBackground (const Quantity_NameOfColor theBackColor)
+{
+ SetBackground (Quantity_Color (theBackColor));
+}
+
+// =======================================================================
+// function : SetBackground
+// purpose :
+// =======================================================================
+void Cocoa_Window::SetBackground (const Aspect_Handle theBackPixmap)
+{
+ //
+}
+
+// =======================================================================
+// function : SetBackground
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::SetBackground (const Standard_CString theFileName,
+ const Aspect_FillMethod theMethod)
+{
+ return Standard_False;
+}
+
+// =======================================================================
+// function : SetBackground
+// purpose :
+// =======================================================================
+void Cocoa_Window::SetBackground (const Quantity_Color& theColor)
+{
+ //
+}
+
+// =======================================================================
+// function : SetBackground
+// purpose :
+// =======================================================================
+void Cocoa_Window::SetBackground (const Aspect_GradientBackground& theGrBackground)
+{
+ Quantity_Color aColor1, aColor2;
+ theGrBackground.Colors (aColor1, aColor2);
+ SetBackground (aColor1, aColor2, theGrBackground.BgGradientFillMethod());
+}
+
+// =======================================================================
+// function : SetBackground
+// purpose :
+// =======================================================================
+void Cocoa_Window::SetBackground (const Quantity_Color& theColor1,
+ const Quantity_Color& theColor2,
+ const Aspect_GradientFillMethod theMethod)
+{
+ //
+}
+
+// =======================================================================
+// function : SetDoubleBuffer
+// purpose :
+// =======================================================================
+void Cocoa_Window::SetDoubleBuffer (const Standard_Boolean )
+{
+ //
+}
+
+// =======================================================================
+// function : Flush
+// purpose :
+// =======================================================================
+void Cocoa_Window::Flush() const
+{
+ Restore();
+}
+
+// =======================================================================
+// function : IsMapped
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::IsMapped() const
+{
+ if (IsVirtual())
+ {
+ return Standard_True;
+ }
+
+ return (myHView != NULL) && [[myHView window] isVisible];
+}
+
+// =======================================================================
+// function : Map
+// purpose :
+// =======================================================================
+void Cocoa_Window::Map() const
+{
+ if (IsVirtual())
+ {
+ return;
+ }
+
+ if (myHView != NULL)
+ {
+ [[myHView window] orderFront: NULL];
+ }
+}
+
+// =======================================================================
+// function : Unmap
+// purpose :
+// =======================================================================
+void Cocoa_Window::Unmap() const
+{
+ if (myHView != NULL)
+ {
+ [[myHView window] orderOut: NULL];
+ }
+}
+
+// =======================================================================
+// function : DoResize
+// purpose :
+// =======================================================================
+Aspect_TypeOfResize Cocoa_Window::DoResize() const
+{
+ if (myHView == NULL)
+ {
+ return Aspect_TOR_UNKNOWN;
+ }
+
+ NSRect aBounds = [myHView bounds];
+ Standard_Integer aMask = 0;
+ Aspect_TypeOfResize aMode = Aspect_TOR_UNKNOWN;
+
+ if (Abs ((Standard_Integer )aBounds.origin.x - myXLeft ) > 2) aMask |= 1;
+ if (Abs ((Standard_Integer )(aBounds.origin.x + aBounds.size.width) - myXRight ) > 2) aMask |= 2;
+ if (Abs ((Standard_Integer )aBounds.origin.y - myYTop ) > 2) aMask |= 4;
+ if (Abs ((Standard_Integer )(aBounds.origin.y + aBounds.size.height) - myYBottom) > 2) aMask |= 8;
+ switch (aMask)
+ {
+ case 0: aMode = Aspect_TOR_NO_BORDER; break;
+ case 1: aMode = Aspect_TOR_LEFT_BORDER; break;
+ case 2: aMode = Aspect_TOR_RIGHT_BORDER; break;
+ case 4: aMode = Aspect_TOR_TOP_BORDER; break;
+ case 5: aMode = Aspect_TOR_LEFT_AND_TOP_BORDER; break;
+ case 6: aMode = Aspect_TOR_TOP_AND_RIGHT_BORDER; break;
+ case 8: aMode = Aspect_TOR_BOTTOM_BORDER; break;
+ case 9: aMode = Aspect_TOR_BOTTOM_AND_LEFT_BORDER; break;
+ case 10: aMode = Aspect_TOR_RIGHT_AND_BOTTOM_BORDER; break;
+ default: break;
+ }
+
+ *((Standard_Integer* )&myXLeft ) = (Standard_Integer )aBounds.origin.x;
+ *((Standard_Integer* )&myXRight ) = (Standard_Integer )(aBounds.origin.x + aBounds.size.width);
+ *((Standard_Integer* )&myYTop ) = (Standard_Integer )aBounds.origin.y;
+ *((Standard_Integer* )&myYBottom ) = (Standard_Integer )(aBounds.origin.y + aBounds.size.height);
+ return aMode;
+}
+
+// =======================================================================
+// function : DoMapping
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::DoMapping() const
+{
+ return Standard_True;
+}
+
+// =======================================================================
+// function : Clear
+// purpose :
+// =======================================================================
+void Cocoa_Window::Clear() const
+{
+ //
+}
+
+// =======================================================================
+// function : ClearArea
+// purpose :
+// =======================================================================
+void Cocoa_Window::ClearArea (const Standard_Integer Xc,
+ const Standard_Integer Yc,
+ const Standard_Integer Width,
+ const Standard_Integer Height) const
+{
+ //
+}
+
+// =======================================================================
+// function : Restore
+// purpose :
+// =======================================================================
+void Cocoa_Window::Restore() const
+{
+ //
+}
+
+// =======================================================================
+// function : RestoreArea
+// purpose :
+// =======================================================================
+void Cocoa_Window::RestoreArea (const Standard_Integer Xc,
+ const Standard_Integer Yc,
+ const Standard_Integer Width,
+ const Standard_Integer Height) const
+{
+ //
+}
+
+// =======================================================================
+// function : Dump
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::Dump (const Standard_CString theFilename,
+ const Standard_Real theGammaValue) const
+{
+ /*Image_AlienPixMap anImg;
+ if (!ToPixMap (anImg) || anImg.IsEmpty())
+ {
+ return Standard_False;
+ }
+ if (Abs (theGammaValue - 1.0) > 0.001)
+ {
+ anImg.AdjustGamma (theGammaValue);
+ }
+ return anImg.Save (theFilename);*/
+ return Standard_False;
+}
+
+// =======================================================================
+// function : DumpArea
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::DumpArea (const Standard_CString theFilename,
+ const Standard_Integer theCenterX,
+ const Standard_Integer theCenterY,
+ const Standard_Integer theWidth,
+ const Standard_Integer theHeight,
+ const Standard_Real theGammaValue) const
+{
+ return Standard_False;
+}
+
+// =======================================================================
+// function : ToPixMap
+// purpose :
+// =======================================================================
+/*Standard_Boolean Cocoa_Window::ToPixMap (Image_PixMap& thePixMap) const
+{
+ return Standard_False;
+}*/
+
+// =======================================================================
+// function : Load
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::Load (const Standard_CString theFilename) const
+{
+ return Standard_False;
+}
+
+// =======================================================================
+// function : LoadArea
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::LoadArea (const Standard_CString theFilename,
+ const Standard_Integer theCenterX,
+ const Standard_Integer theCenterY,
+ const Standard_Integer theWidth,
+ const Standard_Integer theHeight) const
+{
+ return Standard_False;
+}
+
+// =======================================================================
+// function : BackingStore
+// purpose :
+// =======================================================================
+Standard_Boolean Cocoa_Window::BackingStore() const
+{
+ return Standard_False;
+}
+
+// =======================================================================
+// function : Ratio
+// purpose :
+// =======================================================================
+Quantity_Ratio Cocoa_Window::Ratio() const
+{
+ if (myHView == NULL)
+ {
+ return 1.0;
+ }
+
+ NSRect aBounds = [myHView bounds];
+ return Quantity_Ratio (aBounds.size.width / aBounds.size.height);
+}
+
+// =======================================================================
+// function : Position
+// purpose :
+// =======================================================================
+void Cocoa_Window::Position (Quantity_Parameter& X1, Quantity_Parameter& Y1,
+ Quantity_Parameter& X2, Quantity_Parameter& Y2) const
+{
+ //
+}
+
+// =======================================================================
+// function : Position
+// purpose :
+// =======================================================================
+void Cocoa_Window::Position (Standard_Integer& X1, Standard_Integer& Y1,
+ Standard_Integer& X2, Standard_Integer& Y2) const
+{
+ //
+}
+
+// =======================================================================
+// function : Size
+// purpose :
+// =======================================================================
+void Cocoa_Window::Size (Quantity_Parameter& theWidth,
+ Quantity_Parameter& theHeight) const
+{
+ //
+}
+
+// =======================================================================
+// function : Size
+// purpose :
+// =======================================================================
+void Cocoa_Window::Size (Standard_Integer& theWidth,
+ Standard_Integer& theHeight) const
+{
+ if (myHView == NULL)
+ {
+ return;
+ }
+
+ NSRect aBounds = [myHView bounds];
+ theWidth = (Standard_Integer )aBounds.size.width;
+ theHeight = (Standard_Integer )aBounds.size.height;
+}
+
+// =======================================================================
+// function : MMSize
+// purpose :
+// =======================================================================
+void Cocoa_Window::MMSize (Standard_Real& theWidth,
+ Standard_Real& theHeight) const
+{
+ //
+}
+
+// =======================================================================
+// function : Convert
+// purpose :
+// =======================================================================
+Quantity_Parameter Cocoa_Window::Convert (const Standard_Integer PV) const
+{
+ return 0.0; ///
+}
+
+// =======================================================================
+// function : Convert
+// purpose :
+// =======================================================================
+Standard_Integer Cocoa_Window::Convert (const Quantity_Parameter DV) const
+{
+ return 0; ////
+}
+
+// =======================================================================
+// function : Convert
+// purpose :
+// =======================================================================
+void Cocoa_Window::Convert (const Standard_Integer PX,
+ const Standard_Integer PY,
+ Quantity_Parameter& DX,
+ Quantity_Parameter& DY) const
+{
+ //
+}
+
+// =======================================================================
+// function : Convert
+// purpose :
+// =======================================================================
+void Cocoa_Window::Convert (const Quantity_Parameter DX,
+ const Quantity_Parameter DY,
+ Standard_Integer& PX,
+ Standard_Integer& PY) const
+{
+ //
+}
--- /dev/null
+CSF_objc
+CSF_Appkit
+CSF_IOKit
--- /dev/null
+Cocoa_LocalPool.hxx
+Cocoa_LocalPool.mm
+Cocoa_Window.hxx
+Cocoa_Window.mm
InterfaceGraphic_Visual3d.hxx
InterfaceGraphic_WNT.hxx
InterfaceGraphic_X11.hxx
+InterfaceGraphic_Cocoa.hxx
InterfaceGraphic_XWD.hxx
InterfaceGraphic_wntio.hxx
InterfaceGraphic_cPrintf.cxx
// and conditions governing the rights and limitations under the License.
#ifndef __INTERFACE_GRAPHIC_HXX
-# define __INTERFACE_GRAPHIC_HXX
+#define __INTERFACE_GRAPHIC_HXX
#ifdef WNT
-# include <InterfaceGraphic_WNT.hxx>
+ #include <InterfaceGraphic_WNT.hxx>
+#elif defined(__APPLE__)
+ #include <InterfaceGraphic_Cocoa.hxx>
#else
-# include <InterfaceGraphic_X11.hxx>
-#endif //WNT
+ #include <InterfaceGraphic_X11.hxx>
+#endif
-#endif /* __INTERFACE_GRAPHIC_HXX */
+#endif // __INTERFACE_GRAPHIC_HXX
--- /dev/null
+// Copyright (c) 2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#ifdef __APPLE__
+
+#ifndef InterfaceGraphic_CocoaHeader
+#define InterfaceGraphic_CocoaHeader
+
+#include <stdio.h>
+
+#define WINDOW void*
+#define DISPLAY void*
+#define GLCONTEXT void*
+#define GLDRAWABLE void*
+
+#define GET_GL_CONTEXT() NULL
+#define GET_GLDEV_CONTEXT() NULL
+#define GL_MAKE_CURRENT(a,b,c) {}
+
+#ifndef EXPORT
+ #define EXPORT
+#endif
+
+#endif InterfaceGraphic_CocoaHeader
+
+#endif // __APPLE__
CSF_gdi32
CSF_opengl32
CSF_glu32
+CSF_objc
+CSF_Appkit
+CSF_IOKit
CSF_OpenGlLibs
CSF_AviLibs
CSF_FREETYPE
Handle_OpenGl_Window.hxx
OpenGl_Window.hxx
OpenGl_Window.cxx
+OpenGl_Window_1.mm
OpenGl_PriorityList.hxx
OpenGl_PriorityList.cxx
OpenGl_AVIWriter.hxx
Handle_OpenGl_Context.hxx
OpenGl_Context.hxx
OpenGl_Context.cxx
+OpenGl_Context_1.mm
OpenGl_ArbIns.hxx
OpenGl_ArbTBO.hxx
OpenGl_ArbVBO.hxx
// Created on: 2012-01-26
// Created by: Kirill GAVRILOV
-// Copyright (c) 2012-2012 OPEN CASCADE SAS
+// Copyright (c) 2012 OPEN CASCADE SAS
//
// The content of this file is subject to the Open CASCADE Technology Public
// License Version 6.5 (the "License"). You may not use the content of this file
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
-
#if (defined(_WIN32) || defined(__WIN32__))
#include <windows.h>
#endif
}
}
+#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
+
// =======================================================================
// function : IsCurrent
// purpose :
#endif
}
+#endif // __APPLE__
+
// =======================================================================
// function : findProc
// purpose :
return Standard_False;
}
+#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
+
// =======================================================================
// function : Init
// purpose :
return Standard_True;
}
+#endif // __APPLE__
+
// =======================================================================
// function : Init
// purpose :
Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow,
const Aspect_Handle theWindowDC,
const Aspect_RenderingContext theGContext)
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+Standard_Boolean OpenGl_Context::Init (const void* theGContext)
#else
Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow,
const Aspect_Display theDisplay,
#endif
{
Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!");
-
+#if (defined(_WIN32) || defined(__WIN32__))
myWindow = theWindow;
myGContext = theGContext;
-#if (defined(_WIN32) || defined(__WIN32__))
myWindowDC = theWindowDC;
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+ myGContext = (void* )theGContext;
#else
+ myWindow = theWindow;
+ myGContext = theGContext;
myDisplay = theDisplay;
#endif
if (myGContext == NULL || !MakeCurrent())
Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow,
const Aspect_Handle theWindowDC,
const Aspect_RenderingContext theGContext);
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+ Standard_EXPORT Standard_Boolean Init (const void* theGContext);
#else
Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theWindow,
const Aspect_Display theDisplay,
Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND
Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC
Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+ void* myGContext; //!< Rendering Context handle : NSOpenGLContext
#else
Aspect_Drawable myWindow; //!< window handle (owner of GL context) : GLXDrawable
Aspect_Display myDisplay; //!< connection to the X-server : Display*
--- /dev/null
+// Created on: 2012-11-12
+// Created by: Kirill GAVRILOV
+// Copyright (c) 2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+
+#import <Cocoa/Cocoa.h>
+
+#include <OpenGl_GlCore11.hxx>
+#include <OpenGl_Context.hxx>
+
+#include <Standard_ProgramError.hxx>
+
+// =======================================================================
+// function : IsCurrent
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Context::IsCurrent() const
+{
+ return myGContext != NULL
+ && [NSOpenGLContext currentContext] == (NSOpenGLContext* )myGContext;
+}
+
+// =======================================================================
+// function : MakeCurrent
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Context::MakeCurrent()
+{
+ if (myGContext == NULL)
+ {
+ Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
+ return Standard_False;
+ }
+
+ [(NSOpenGLContext* )myGContext makeCurrentContext];
+ return Standard_True;
+}
+
+// =======================================================================
+// function : SwapBuffers
+// purpose :
+// =======================================================================
+void OpenGl_Context::SwapBuffers()
+{
+ if (myGContext != NULL)
+ {
+ glFinish();
+ [(NSOpenGLContext* )myGContext flushBuffer];
+ }
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+Standard_Boolean OpenGl_Context::Init()
+{
+ if (myIsInitialized)
+ {
+ return Standard_True;
+ }
+
+ myGContext = [NSOpenGLContext currentContext];
+ if (myGContext == NULL)
+ {
+ return Standard_False;
+ }
+
+ init();
+ myIsInitialized = Standard_True;
+ return Standard_True;
+}
+
+#endif // __APPLE__
#include <OpenGl_Light.hxx>
-#if (!defined(_WIN32) && !defined(__WIN32__))
+#if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
#include <X11/Xlib.h> // XOpenDisplay()
#endif
namespace
{
- #if (defined(_WIN32) || defined(__WIN32__))
+ #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
static char* TheDummyDisplay = "DISPLAY";
#endif
myFont(-1),
myFontSize(-1)
{
-#if (defined(_WIN32) || defined(__WIN32__))
+#if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
myDisplay = TheDummyDisplay;
#else
if (theDisplay != NULL && *theDisplay != '\0')
{
if (myDisplay != NULL)
{
- #if (!defined(_WIN32) && !defined(__WIN32__))
+ #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
XSynchronize ((Display* )myDisplay, (getenv("CALL_SYNCHRO_X") != NULL) ? 1 : 0);
if (getenv("CSF_GraphicSync") != NULL)
else
{
TCollection_AsciiString msg("OpenGl_Display::Init");
- #if (!defined(_WIN32) && !defined(__WIN32__))
+ #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
msg += " : Cannot connect to X server ";
msg += XDisplayName ((char*) NULL);
#endif
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
+#include <OpenGl_GlCore11.hxx>
#include <InterfaceGraphic.hxx>
#include <OpenGl_Display.hxx>
/*-----------------------------------------------------------------------------*/
/*
* Prototypes variables statiques
-*/
+*/
+
+struct FontMapNode
+{
+ const char * EnumName;
+ const char * FontName;
+ Font_FontAspect FontAspect;
+};
+
+static const FontMapNode myFontMap[] =
+{
+
+#ifdef WNT
+
+ { "Courier" , "Courier New" , Font_FA_Regular },
+ { "Times-Roman" , "Times New Roman", Font_FA_Regular },
+ { "Times-Bold" , "Times New Roman", Font_FA_Bold },
+ { "Times-Italic" , "Times New Roman", Font_FA_Italic },
+ { "Times-BoldItalic" , "Times New Roman", Font_FA_BoldItalic },
+ { "ZapfChancery-MediumItalic", "Script" , Font_FA_Regular },
+ { "Symbol" , "Symbol" , Font_FA_Regular },
+ { "ZapfDingbats" , "WingDings" , Font_FA_Regular },
+ { "Rock" , "Arial" , Font_FA_Regular },
+ { "Iris" , "Lucida Console" , Font_FA_Regular }
+
+#else //X11
+
+ { "Courier" , "Courier" , Font_FA_Regular },
+ { "Times-Roman" , "Times" , Font_FA_Regular },
+ { "Times-Bold" , "Times" , Font_FA_Bold },
+ { "Times-Italic" , "Times" , Font_FA_Italic },
+ { "Times-BoldItalic" , "Times" , Font_FA_BoldItalic },
+ { "Arial" , "Helvetica" , Font_FA_Regular },
+ { "ZapfChancery-MediumItalic", "-adobe-itc zapf chancery-medium-i-normal--*-*-*-*-*-*-iso8859-1" , Font_FA_Regular },
+ { "Symbol" , "-adobe-symbol-medium-r-normal--*-*-*-*-*-*-adobe-fontspecific" , Font_FA_Regular },
+ { "ZapfDingbats" , "-adobe-itc zapf dingbats-medium-r-normal--*-*-*-*-*-*-adobe-fontspecific" , Font_FA_Regular },
+ { "Rock" , "-sgi-rock-medium-r-normal--*-*-*-*-p-*-iso8859-1" , Font_FA_Regular },
+ { "Iris" , "--iris-medium-r-normal--*-*-*-*-m-*-iso8859-1" , Font_FA_Regular }
+#endif
+
+};
+
+#define NUM_FONT_ENTRIES (sizeof(myFontMap)/sizeof(FontMapNode))
/*-----------------------------------------------------------------------------*/
#ifdef HAVE_GL2PS
void OpenGl_Display::getGL2PSFontName (const char *src_font, char *ps_font)
{
- /*
+ /*
Convert font name used for rendering to some "good" font names
- that produce good vector text
+ that produce good vector text
*/
static char const *family[] = {"Helvetica", "Courier", "Times"};
static char const *italic[] = {"Oblique", "Oblique", "Italic"};
/*-----------------------------------------------------------------------------*/
/*
-* Fonctions publiques
+* Fonctions publiques
*/
/*-----------------------------------------------------------------------------*/
-Standard_Integer OpenGl_Display::FindFont (Standard_CString theFontName,
- const Font_FontAspect theFontAspect,
- const Standard_Integer theBestSize,
- const Standard_ShortReal theXScale,
- const Standard_ShortReal theYScale)
+int OpenGl_Display::FindFont (const char* AFontName, const Font_FontAspect AFontAspect,
+ const int ABestSize, const float AXScale, const float AYScale)
{
- if (!theFontName)
+ if (!AFontName)
return -1;
- if (theBestSize != -1)
- myFontSize = theBestSize;
+ if (ABestSize != -1)
+ myFontSize = ABestSize;
+
+ OpenGl_FontMgr* mgr = OpenGl_FontMgr::instance();
+
+ Handle(TCollection_HAsciiString) family_name = new TCollection_HAsciiString(AFontName);
+ myFont = mgr->request_font( family_name, AFontAspect, myFontSize );
- OpenGl_FontMgr* anOpenGlFontMgr = OpenGl_FontMgr::instance();
+ if( myFont == -1 )
+ {
+ //try to use font names mapping
+ FontMapNode newTempFont = myFontMap[0];
+ for ( int i = 0; i < NUM_FONT_ENTRIES; ++i )
+ {
+ if ( TCollection_AsciiString(myFontMap[i].EnumName).IsEqual( family_name->ToCString() ) )
+ {
+ newTempFont = myFontMap[i];
+ break;
+ }
+ }
+ family_name = new TCollection_HAsciiString(newTempFont.FontName);
+ myFont = mgr->request_font( family_name, newTempFont.FontAspect, myFontSize );
+ }
- Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (theFontName);
- myFont = anOpenGlFontMgr->request_font (aFontName, theFontAspect, myFontSize);
+ // Requested family name not found -> serach for any font family with given aspect and height
+ if ( myFont == -1 )
+ {
+ family_name = new TCollection_HAsciiString( "" );
+ myFont = mgr->request_font( family_name, AFontAspect, myFontSize );
+ }
- if (myFont != -1)
- anOpenGlFontMgr->setCurrentScale (theXScale, theYScale);
+ // The last resort: trying to use ANY font available in the system
+ if ( myFont == -1 )
+ {
+ myFont = mgr->request_font( family_name, Font_FA_Undefined, -1 );
+ }
+
+ if ( myFont != -1 )
+ mgr->setCurrentScale( AXScale, AYScale );
return myFont;
}
{
private:
- Standard_Integer myLFNum; // Number of '\n' (Line Feed) '\x00\x0A'
+ Standard_Integer myLFNum; // Number of '\n' (Line Feed) '\x00\x0A'
Standard_Integer myCurrPos; // Position of the current substring
- Standard_Integer myNewStrLen; // Length of the new string
+ Standard_Integer myNewStrLen; // Length of the new string
Standard_Integer mySubstrNum; // Number of substrings
wchar_t *myNewStr; // New string
const wchar_t *myStrPtr; // Pointer to the original string
anIndex2 += aHelpIndex - 1;
aTimeVar = 0;
}
- else
+ else
{
myNewStr[anIndex2] = *(myStrPtr + anIndex1);
}
case Graphic3d_VTA_CENTER:
if ( (myLFNum%2) == 0 ) // An odd number of strings
{
- theYdis = (GLdouble)((myLFNum/2.0) * theFnt->FaceSize()) + theDescentFont;
+ theYdis = (GLdouble)((myLFNum/2.0) * theFnt->FaceSize()) + theDescentFont;
}
else // An even number of strings
{
OpenGl_FontMgr* mgr = OpenGl_FontMgr::instance();
const FTFont* fnt = mgr->fontById( myFont );
if ( !fnt )
- return;
+ return;
// FTFont changes texture state when it renders and computes size for the text
glPushAttrib(GL_TEXTURE_BIT);
(GLint*)viewport,
&wx, &wy, &wz );
glLoadIdentity();
- gluUnProject( wx, wy, wz,
+ gluUnProject( wx, wy, wz,
(GLdouble*)identityMatrix, (GLdouble*)projMatrix, (GLint*)viewport,
- &x1, &y1 , &z1 );
+ &x1, &y1 , &z1 );
GLdouble h = (GLdouble)fnt->FaceSize();
h = (y2-y1)/h;
- glTranslated( x1, y1 , z1 );
+ glTranslated( x1, y1 , z1 );
glRotated(aspect->Angle(), 0, 0, 1);
- glTranslated(xdis, ydis, 0);
+ glTranslated(xdis, ydis, 0);
if( !aspect->IsZoomable() )
{
#ifdef WNT
// if the context has assigned printer context, use it's parameters
- OpenGl_PrinterContext* aPrinterContext =
+ OpenGl_PrinterContext* aPrinterContext =
OpenGl_PrinterContext::GetPrinterContext( GET_GL_CONTEXT() );
if( aPrinterContext )
{
// get printing scaling in x and y dimensions
GLfloat aTextScalex = 1, aTextScaley = 1;
aPrinterContext->GetScale( aTextScalex, aTextScaley );
-
+
// text should be scaled in all directions with same
// factor to save its proportions, so use height (y) scaling
// as it is better for keeping text/3d graphics proportions
}
}
- GLint renderMode;
+ GLint renderMode;
glGetIntegerv(GL_RENDER_MODE, &renderMode);
- if ( renderMode == GL_FEEDBACK )
+ if ( renderMode == GL_FEEDBACK )
{
#ifdef HAVE_GL2PS
export_h = (float)fnt->FaceSize() / export_h;
#define GLAPI extern
#endif
-// current TKOpenGl implementation is incompatible with native OpenGL on MacOS X
-#define MACOSX_USE_GLX
-
// exclude modern definitions and system-provided glext.h, should be defined before gl.h inclusion
#define GL_GLEXT_LEGACY
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
-
#include <InterfaceGraphic.hxx>
#include <OpenGl_Window.hxx>
IMPLEMENT_STANDARD_HANDLE(OpenGl_Window,MMgt_TShared)
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Window,MMgt_TShared)
+#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
+
namespace
{
static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } };
#endif
}
+#endif // !__APPLE__
+
// =======================================================================
// function : Activate
// purpose :
return myGlContext->MakeCurrent();
}
+#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
+
// =======================================================================
// function : Resize
// purpose : call_subr_resize
Init();
}
+#endif // !__APPLE__
+
// =======================================================================
// function : ReadDepths
// purpose : TelReadDepths
myBgColor.rgb[2] = theB;
}
+#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
+
// =======================================================================
// function : Init
// purpose :
glDrawBuffer (GL_BACK);
}
+#endif // !__APPLE__
+
// =======================================================================
// function : EnablePolygonOffset
// purpose : call_subr_enable_polygon_offset
--- /dev/null
+// Created on: 2012-11-12
+// Created by: Kirill Gavrilov
+// Copyright (c) 2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+
+#import <Cocoa/Cocoa.h>
+
+#include <InterfaceGraphic.hxx>
+
+#include <OpenGl_Window.hxx>
+
+#include <OpenGl_Context.hxx>
+#include <OpenGl_Display.hxx>
+#include <Aspect_GraphicDeviceDefinitionError.hxx>
+#include <Cocoa_LocalPool.hxx>
+#include <TCollection_AsciiString.hxx>
+
+namespace
+{
+ static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } };
+ static const NSOpenGLPixelFormatAttribute THE_DOUBLE_BUFF[] = {
+ //NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute )32,
+ NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute )24,
+ NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute )8,
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAAccelerated,
+ 0
+ };
+
+};
+
+// =======================================================================
+// function : OpenGl_Window
+// purpose :
+// =======================================================================
+OpenGl_Window::OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
+ const CALL_DEF_WINDOW& theCWindow,
+ Aspect_RenderingContext theGContext,
+ const Handle(OpenGl_Context)& theShareCtx)
+: myDisplay (theDisplay),
+ myGlContext (new OpenGl_Context()),
+ myOwnGContext (theGContext == 0),
+ myWidth ((Standard_Integer )theCWindow.dx),
+ myHeight ((Standard_Integer )theCWindow.dy),
+ myBgColor (THE_DEFAULT_BG_COLOR),
+ myDither (theDisplay->Dither()),
+ myBackDither (theDisplay->BackDither())
+{
+ myBgColor.rgb[0] = theCWindow.Background.r;
+ myBgColor.rgb[1] = theCWindow.Background.g;
+ myBgColor.rgb[2] = theCWindow.Background.b;
+
+ Cocoa_LocalPool aLocalPool;
+ //NSOpenGLContext* aGContext = (NSOpenGLContext* )theGContext;
+
+ // all GL context within one OpenGl_GraphicDriver should be shared!
+ NSOpenGLContext* aGLCtxShare = theShareCtx.IsNull() ? NULL : (NSOpenGLContext* )theShareCtx->myGContext;
+ NSOpenGLPixelFormat* aGLFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes: THE_DOUBLE_BUFF] autorelease];
+ NSOpenGLContext* aGLContext = [[NSOpenGLContext alloc] initWithFormat: aGLFormat
+ shareContext: aGLCtxShare];
+ if (aGLContext == NULL)
+ {
+ TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: NSOpenGLContext creation failed");
+ Aspect_GraphicDeviceDefinitionError::Raise (aMsg.ToCString());
+ return;
+ }
+
+ NSView* aView = (NSView* )theCWindow.XWindow;
+ [aGLContext setView: aView];
+
+ myGlContext->Init (aGLContext);
+ myGlContext->Share (theShareCtx);
+ Init();
+}
+
+// =======================================================================
+// function : ~OpenGl_Window
+// purpose :
+// =======================================================================
+OpenGl_Window::~OpenGl_Window()
+{
+ NSOpenGLContext* aGLCtx = (NSOpenGLContext* )myGlContext->myGContext;
+ myGlContext.Nullify();
+
+ [NSOpenGLContext clearCurrentContext];
+ if (myOwnGContext)
+ {
+ [aGLCtx clearDrawable];
+ [aGLCtx release];
+ }
+}
+
+// =======================================================================
+// function : Resize
+// purpose : call_subr_resize
+// =======================================================================
+void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow)
+{
+ DISPLAY* aDisp = (DISPLAY* )myDisplay->GetDisplay();
+ if (aDisp == NULL)
+ {
+ return;
+ }
+
+ // If the size is not changed - do nothing
+ if ((myWidth == theCWindow.dx) && (myHeight == theCWindow.dy))
+ {
+ return;
+ }
+
+ myWidth = (Standard_Integer )theCWindow.dx;
+ myHeight = (Standard_Integer )theCWindow.dy;
+
+ Init();
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+void OpenGl_Window::Init()
+{
+ if (!Activate())
+ {
+ return;
+ }
+
+ NSOpenGLContext* aGLCtx = (NSOpenGLContext* )myGlContext->myGContext;
+ NSRect aBounds = [[aGLCtx view] bounds];
+
+ // we should call this method each time when window is resized
+ [aGLCtx update];
+
+ myWidth = Standard_Integer(aBounds.size.width);
+ myHeight = Standard_Integer(aBounds.size.height);
+
+ glMatrixMode (GL_MODELVIEW);
+ glViewport (0, 0, myWidth, myHeight);
+
+ glDisable (GL_SCISSOR_TEST);
+ glDrawBuffer (GL_BACK);
+}
+
+#endif // __APPLE__
# include <config.h>
#endif
-#ifdef HAVE_FREEIMAGE
+#if (defined(_WIN32) || defined(__WIN32__)) && defined(HAVE_FREEIMAGE)
#include <NCollection_Handle.hxx>
#include <FreeImagePlus.h>
#ifdef _MSC_VER
- #pragma comment( lib, "FreeImage.lib" )
- #pragma comment( lib, "FreeImagePlus.lib" )
+ #pragma comment( lib, "FreeImage.lib" )
+ #pragma comment( lib, "FreeImagePlus.lib" )
#endif
typedef NCollection_Handle<fipImage> FipHandle;
#endif
GLint aTexDim = 2048;
glGetIntegerv (GL_MAX_VIEWPORT_DIMS, (GLint*) &aVpDim);
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &aTexDim);
- (aVpDim[0] >= aTexDim) ? aMaxX = (GLsizei) aTexDim :
+ (aVpDim[0] >= aTexDim) ? aMaxX = (GLsizei) aTexDim :
aMaxX = getNearestPowOfTwo((GLsizei)aVpDim[0]);
(aVpDim[1] >= aTexDim) ? aMaxY = (GLsizei) aTexDim :
aMaxY = getNearestPowOfTwo((GLsizei)aVpDim[1]);
// ---------------------------------------------------------------
// Function: getDimensionsTiling
-// Purpose: calculate maximum possible dimensions for framebuffer
+// Purpose: calculate maximum possible dimensions for framebuffer
// in tiling mode according to the view size
// ---------------------------------------------------------------
static void getDimensionsTiling (Standard_Integer& theFrameWidth,
Standard_Real aWidthRate = (Standard_Real)theFrameWidth /theViewWidth;
Standard_Real aHeightRate = (Standard_Real)theFrameHeight/theViewHeight;
- if ((aWidthRate > 1 && aHeightRate > 1 && aWidthRate >= aHeightRate) ||
+ if ((aWidthRate > 1 && aHeightRate > 1 && aWidthRate >= aHeightRate) ||
(aWidthRate > 1 && aHeightRate <= 1))
{
theFrameWidth = (Standard_Integer)(theFrameWidth /aWidthRate);
// Purpose: copy the data from image buffer to the device context
// ---------------------------------------------------------------
static bool imagePasteDC(HDC theDstDC, FipHandle theImage, int theOffsetX,
- int theOffsetY, int theWidth, int theHeight,
+ int theOffsetY, int theWidth, int theHeight,
int theLeft = 0, int theTop = 0)
{
// get image parameters
BITMAPINFO* aBitmapData = theImage->getInfo ();
SetStretchBltMode (theDstDC, STRETCH_HALFTONE);
-
+
// organize blocks data passing if memory isn't enough to pass all the data
// at once
int aLinesComplete = 0, aMaxBlockWidth = theHeight, aBlockWidth = 0,
unsigned int heightPx = theImage->getHeight ();
BITMAPINFO* aBitmapData = theImage->getInfo ();
SetStretchBltMode (theDstDC, STRETCH_HALFTONE);
-
+
// pass lines and check if operation is succesfull
int aPassed = 0;
aPassed = StretchDIBits (theDstDC, theOffsetX, theOffsetY, theWidth,
if (aPassed != heightPx)
return false;
-
+
return true;
}
#endif
//call_togl_print
Standard_Boolean OpenGl_Workspace::Print
- (const Graphic3d_CView& ACView,
- const Aspect_CLayer2d& ACUnderLayer,
+ (const Graphic3d_CView& ACView,
+ const Aspect_CLayer2d& ACUnderLayer,
const Aspect_CLayer2d& ACOverLayer,
const Aspect_Handle hPrintDC,// const Aspect_Drawable hPrintDC,
const Standard_Boolean showBackground,
}
#else
// try to allocate compatible bitmap and necessary resources
- initBitmapBuffer (hMemDC, hViewBitmap,
+ initBitmapBuffer (hMemDC, hViewBitmap,
aFrameWidth, aFrameHeight, aViewBuffer);
if (!aViewBuffer)
{
break;
#else
// try to allocate compatible bitmap and necessary resources
- initBitmapBuffer (hMemDC, hViewBitmap,
+ initBitmapBuffer (hMemDC, hViewBitmap,
aFrameWidth, aFrameHeight, aViewBuffer);
if (!aViewBuffer)
{
aMaxHeight = aMaxHeight >> 1;
}
- // check if there are proper dimensions
+ // check if there are proper dimensions
if (aMaxWidth <= 1 || aMaxHeight <= 1)
{
MessageBox (NULL, "Print failed: can't allocate buffer for printing.",
}
// setup printing context and viewport
- GLint aViewPortBack[4];
+ GLint aViewPortBack[4];
GLint anAlignBack = 1;
OpenGl_PrinterContext aPrinterContext (GetGContext());
// calculate total count of frames and cropping size
Standard_Integer aPxCropx = 0;
Standard_Integer aPxCropy = 0;
- Standard_Integer aTotalx =
+ Standard_Integer aTotalx =
(Standard_Integer)floor ((float)width /aFrameWidth);
- Standard_Integer aTotaly =
+ Standard_Integer aTotaly =
(Standard_Integer)floor ((float)height/aFrameHeight);
if (width %aFrameWidth != 0)
{
// stop operation if errors
if (!isDone)
break;
-
+
// calculate new view offset for x-coordinate
aOffsetx += 2.0;
aSubLeft += aRight-aLeft;
if (GetObjectType (hPrnDC) == OBJ_DC)
AbortDoc (hPrnDC);
}
-
+
// return OpenGl to the previous state
aPrinterContext.Deactivate ();
glPixelStorei (GL_PACK_ALIGNMENT, anAlignBack);
aFrameBuffer->UnbindBuffer (GetGlContext());
- glViewport (aViewPortBack[0], aViewPortBack[1],
+ glViewport (aViewPortBack[0], aViewPortBack[1],
aViewPortBack[2], aViewPortBack[3]);
if (aPrevBuffer)
{
#else // not WNT
return Standard_False;
-#endif
+#endif
}
/*----------------------------------------------------------------------*/
//redrawView
-void OpenGl_Workspace::Redraw1 (const Graphic3d_CView& ACView,
- const Aspect_CLayer2d& ACUnderLayer,
+void OpenGl_Workspace::Redraw1 (const Graphic3d_CView& ACView,
+ const Aspect_CLayer2d& ACUnderLayer,
const Aspect_CLayer2d& ACOverLayer,
const int aswap)
{
GLsizei width = myWidth+1, height = myHeight+1;
Tfloat xmr = 0, ymr = 0;
- if (flag)
+ if (flag)
{
if (!myView.IsNull()) //szvgl: use vid here!
{
TKService
TKV3d
CSF_OpenGlLibs
+CSF_objc
+CSF_Appkit
+CSF_IOKit
CSF_FREETYPE
CSF_FTGL
CSF_GL2PS
CSF_XwLibs
CSF_dpsLibs
CSF_XmuLibs
+CSF_objc
+CSF_Appkit
+CSF_IOKit
CSF_FreeImagePlus
CSF_FREETYPE
PlotMgt
ImageUtility
WNT
+Cocoa
TColQuantity
Font
+
CSF_user32
CSF_gdi32
CSF_OpenGlLibs
+CSF_objc
+CSF_Appkit
+CSF_IOKit
--- /dev/null
+CSF_objc
+CSF_Appkit
+CSF_IOKit
+EXTERNLIB
ViewerTest_CMPLRS.edl
ViewerTest_AviCommands.cxx
ViewerTest_ViewerCommands.cxx
ViewerTest_FilletCommands.cxx
ViewerTest_VoxelCommands.cxx
ViewerTest_OpenGlCommands.cxx
+ViewerTest_ViewerCommands_1.mm
#include <Visual3d_Layer.hxx>
#include <cstdlib>
-#ifndef WNT
-#include <Graphic3d_GraphicDevice.hxx>
-#include <Xw_GraphicDevice.hxx>
-#include <Xw_WindowQuality.hxx>
-#include <Xw_Window.hxx>
-#include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
-#include <X11/Xutil.h>
-#include <tk.h>
-
+#if defined(_WIN32) || defined(__WIN32__)
+ #include <Graphic3d_WNTGraphicDevice.hxx>
+ #include <WNT_WClass.hxx>
+ #include <WNT_Window.hxx>
+
+ #if defined(_MSC_VER)
+ #define _CRT_SECURE_NO_DEPRECATE
+ #pragma warning (disable:4996)
+ #endif
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+ #include <Graphic3d_GraphicDevice.hxx>
+ #include <Cocoa_Window.hxx>
+ #include <tk.h>
#else
-
-#include <Graphic3d_WNTGraphicDevice.hxx>
-#include <WNT_WClass.hxx>
-#include <WNT_Window.hxx>
-
-#define _CRT_SECURE_NO_DEPRECATE
-#pragma warning (disable:4996)
-
+ #include <Graphic3d_GraphicDevice.hxx>
+ #include <Xw_GraphicDevice.hxx>
+ #include <Xw_WindowQuality.hxx>
+ #include <Xw_Window.hxx>
+ #include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
+ #include <X11/Xutil.h>
+ #include <tk.h>
#endif
-#define OCC120
-
//==============================================================================
//==============================================================================
Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
extern const Handle(NIS_InteractiveContext)& TheNISContext();
-#ifdef WNT
+#if defined(_WIN32) || defined(__WIN32__)
static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
static Handle(Graphic3d_WNTGraphicDevice) GD;
return GD;
static Handle(WNT_Window) WNTWin;
return WNTWin;
}
-
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+static Handle(Graphic3d_GraphicDevice)& GetG3dDevice()
+{
+ static Handle(Graphic3d_GraphicDevice) aGraphicDevice;
+ return aGraphicDevice;
+}
+static Handle(Cocoa_Window)& VT_GetWindow()
+{
+ static Handle(Cocoa_Window) aWindow;
+ return aWindow;
+}
+extern void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow);
#else
static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
static Handle(Graphic3d_GraphicDevice) GD;
static void VProcessEvents(ClientData,int);
#endif
-#ifdef OCC120
static Standard_Boolean DegenerateMode = Standard_True;
-#endif
#define ZCLIPWIDTH 1.
static int Start_Rot = 0;
static int ZClipIsOn = 0;
-static int X_Motion= 0,Y_Motion=0; // Current cursor position
-static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress position
-
+int X_Motion = 0; // Current cursor position
+int Y_Motion = 0;
+int X_ButtonPress = 0; // Last ButtonPress position
+int Y_ButtonPress = 0;
+Standard_Boolean IsDragged = Standard_False;
+Standard_Boolean DragFirst;
//==============================================================================
const Handle(MMgt_TShared)& ViewerTest::WClass()
{
static Handle(MMgt_TShared) theWClass;
-#ifdef WNT
- if (theWClass.IsNull()) {
+#if defined(_WIN32) || defined(__WIN32__)
+ if (theWClass.IsNull())
+ {
theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
CS_VREDRAW | CS_HREDRAW, 0, 0,
::LoadCursor (NULL, IDC_ARROW));
static Standard_Boolean isFirst = Standard_True;
// Default position and dimension of the viewer window.
- // Note that left top corner is set to be sufficiently small to have
+ // Note that left top corner is set to be sufficiently small to have
// window fit in the small screens (actual for remote desktops, see #23003).
- // The position corresponds to the window's client area, thus some
+ // The position corresponds to the window's client area, thus some
// gap is added for window frame to be visible.
Standard_Integer aPxLeft = 20;
Standard_Integer aPxTop = 40;
if (isFirst)
{
// Create the Graphic device
-#ifdef WNT
+#if defined(_WIN32) || defined(__WIN32__)
if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
if (VT_GetWindow().IsNull())
{
aPxLeft, aPxTop,
aPxWidth, aPxHeight,
Quantity_NOC_BLACK);
- VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
+ }
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+ if (GetG3dDevice().IsNull())
+ {
+ GetG3dDevice() = new Graphic3d_GraphicDevice (getenv ("DISPLAY"), Xw_TOM_READONLY);
+ }
+ if (VT_GetWindow().IsNull())
+ {
+ VT_GetWindow() = new Cocoa_Window ("Test3d",
+ aPxLeft, aPxTop,
+ aPxWidth, aPxHeight);
+ ViewerTest_SetCocoaEventManagerView (VT_GetWindow());
}
#else
if (GetG3dDevice().IsNull()) GetG3dDevice() =
aPxWidth, aPxHeight,
Xw_WQ_3DQUALITY,
Quantity_NOC_BLACK);
- VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
}
#endif
+ VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
Handle(V3d_Viewer) a3DViewer, a3DCollector;
// Viewer and View creation
Handle (V3d_View) V = ViewerTest::CurrentView();
V->SetDegenerateModeOn();
-#ifdef OCC120
DegenerateMode = V->DegenerateModeIsOn();
-#endif
// V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
V->SetZClippingDepth(0.5);
a3DViewer->SetDefaultLights();
a3DViewer->SetLightOn();
-#ifndef WNT
-#if TCL_MAJOR_VERSION < 8
+ #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
+ #if TCL_MAJOR_VERSION < 8
Tk_CreateFileHandler((void*)ConnectionNumber(display),
TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
-#else
+ #else
Tk_CreateFileHandler(ConnectionNumber(display),
TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
-#endif
-#endif
+ #endif
+ #endif
isFirst = Standard_False;
}
+
VT_GetWindow()->Map();
+ ViewerTest::CurrentView()->Redraw();
}
//==============================================================================
}
//==============================================================================
-//function : ProcessKeyPress
+//function : VT_ProcessKeyPress
//purpose : Handle KeyPress event from a CString
//==============================================================================
-
-static void ProcessKeyPress( char *buf_ret )
+void VT_ProcessKeyPress (const char* buf_ret)
{
//cout << "KeyPress" << endl;
const Handle(V3d_View) aView = ViewerTest::CurrentView();
else if ( !strcasecmp(buf_ret, "H") ) {
// HLR
cout << "HLR" << endl;
-#ifdef OCC120
+
if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
else aView->SetDegenerateModeOn();
DegenerateMode = aView->DegenerateModeIsOn();
-#else
- ViewerTest::CurrentView()->SetDegenerateModeOff();
-#endif
}
else if ( !strcasecmp(buf_ret, "S") ) {
// SHADING
cout << "passage en mode 1 (shading pour les shapes)" << endl;
-#ifndef OCC120
- ViewerTest::CurrentView()->SetDegenerateModeOn();
-#endif
+
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
Ctx->NbSelected()==0)
else if ( !strcasecmp(buf_ret, "U") ) {
// Unset display mode
cout<<"passage au mode par defaut"<<endl;
-#ifndef OCC120
- ViewerTest::CurrentView()->SetDegenerateModeOn();
-#endif
+
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
Ctx->NbSelected()==0)
else if ( !strcasecmp(buf_ret, "W") ) {
// WIREFRAME
-#ifndef OCC120
- ViewerTest::CurrentView()->SetDegenerateModeOn();
-#endif
cout << "passage en mode 0 (filaire pour les shapes)" << endl;
-#ifndef OCC120
- ViewerTest::CurrentView()->SetDegenerateModeOn();
-#endif
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 ||
Ctx->NbSelected()==0)
}
//==============================================================================
-//function : ProcessExpose
+//function : VT_ProcessExpose
//purpose : Redraw the View on an Expose Event
//==============================================================================
-
-static void ProcessExpose( )
-{ //cout << "Expose" << endl;
- ViewerTest::CurrentView()->Redraw();
+void VT_ProcessExpose()
+{
+ Handle(V3d_View) aView3d = ViewerTest::CurrentView();
+ if (!aView3d.IsNull())
+ {
+ aView3d->Redraw();
+ }
}
//==============================================================================
-//function : ProcessConfigure
+//function : VT_ProcessConfigure
//purpose : Resize the View on an Configure Event
//==============================================================================
-
-static void ProcessConfigure()
+void VT_ProcessConfigure()
{
- Handle(V3d_View) V = ViewerTest::CurrentView();
- V->MustBeResized();
- V->Update();
- V->Redraw();
+ Handle(V3d_View) aView3d = ViewerTest::CurrentView();
+ if (aView3d.IsNull())
+ {
+ return;
+ }
+
+ aView3d->MustBeResized();
+ aView3d->Update();
+ aView3d->Redraw();
}
//==============================================================================
-//function : ProcessButton1Press
+//function : VT_ProcessButton1Press
//purpose : Picking
//==============================================================================
-
-static Standard_Boolean ProcessButton1Press(
+Standard_Boolean VT_ProcessButton1Press(
Standard_Integer ,
- const char** argv,
+ const char** argv,
Standard_Boolean pick,
- Standard_Boolean shift )
+ Standard_Boolean shift)
{
Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
if ( pick ) {
}
//==============================================================================
-//function : ProcessButton3Press
-//purpose : Start Rotation
+//function : VT_ProcessButton1Release
+//purpose : End selecting
//==============================================================================
+void VT_ProcessButton1Release (Standard_Boolean theIsShift)
+{
+ if (IsDragged)
+ {
+ IsDragged = Standard_False;
+ Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
+ if (theIsShift)
+ {
+ EM->ShiftSelect (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
+ Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
+ }
+ else
+ {
+ EM->Select (Min (X_ButtonPress, X_Motion), Max (Y_ButtonPress, Y_Motion),
+ Max (X_ButtonPress, X_Motion), Min (Y_ButtonPress, Y_Motion));
+ }
+ }
+}
-static void ProcessButton3Press()
-
-{ // Start rotation
+//==============================================================================
+//function : VT_ProcessButton3Press
+//purpose : Start Rotation
+//==============================================================================
+void VT_ProcessButton3Press()
+{
Start_Rot = 1;
ViewerTest::CurrentView()->SetDegenerateModeOn();
ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
-
}
+
//==============================================================================
-//function : ProcessButtonRelease
-//purpose : Start Rotation
+//function : VT_ProcessButton3Release
+//purpose : End rotation
//==============================================================================
-
-static void ProcessButtonRelease()
-
-{ // End rotation
-#ifdef OCC120
- if (Start_Rot) {
+void VT_ProcessButton3Release()
+{
+ if (Start_Rot)
+ {
Start_Rot = 0;
if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
}
-#else
- Start_Rot = 0;
- ViewerTest::CurrentView()->SetDegenerateModeOff();
-#endif
}
//==============================================================================
}
//==============================================================================
-//function : ProcessControlButton2Motion
-//purpose : Pann
+//function : VT_ProcessControlButton2Motion
+//purpose : Panning
//==============================================================================
-
-static void ProcessControlButton2Motion()
+void VT_ProcessControlButton2Motion()
{
Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_ButtonPress);
}
//==============================================================================
-//function : ProcessControlButton3Motion
+//function : VT_ProcessControlButton3Motion
//purpose : Rotation
//==============================================================================
-
-static void ProcessControlButton3Motion()
+void VT_ProcessControlButton3Motion()
{
- if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion);
+ if (Start_Rot)
+ {
+ ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
+ }
}
//==============================================================================
-//function : ProcessPointerMotion
-//purpose : Rotation
+//function : VT_ProcessMotion
+//purpose :
//==============================================================================
-
-static void ProcessMotion()
+void VT_ProcessMotion()
{
//pre-hilights detected objects at mouse position
static int ViewProject(Draw_Interpretor& di, const V3d_TypeOfOrientation ori)
{
- if ( ViewerTest::CurrentView().IsNull() )
+ if ( ViewerTest::CurrentView().IsNull() )
{
di<<"Call vinit before this command, please"<<"\n";
return 1;
return 0;
}
-Standard_Boolean IsDragged = Standard_False;
-
-Standard_Integer xx1, yy1, xx2, yy2;
-//the first and last point in viewer co-ordinates
-
-Standard_Boolean DragFirst;
-
-
#ifdef WNT
static Standard_Boolean Ppick = 0;
HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
SetROP2( hdc, R2_NOT );
- Rectangle( hdc, xx1, yy1, xx2, yy2 );
+ Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
ReleaseDC( hwnd, hdc );
const Handle(ViewerTest_EventManager) EM =
ViewerTest::CurrentEventManager();
if ( fwKeys & MK_SHIFT )
- EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ),
- max( xx1, xx2 ), min( yy1, yy2 ));
+ EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
+ max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
else
- EM->Select( min( xx1, xx2 ), max( yy1, yy2 ),
- max( xx1, xx2 ), min( yy1, yy2 ));
+ EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
+ max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
}
return ViewerWindowProc( hwnd, Msg, wParam, lParam );
{
IsDragged = Standard_True;
DragFirst = Standard_True;
- xx1 = LOWORD(lParam);
- yy1 = HIWORD(lParam);
+ X_ButtonPress = LOWORD(lParam);
+ Y_ButtonPress = HIWORD(lParam);
}
return ViewerWindowProc( hwnd, Msg, wParam, lParam );
SetROP2( hdc, R2_NOT );
if( !DragFirst )
- Rectangle( hdc, xx1, yy1, xx2, yy2 );
+ Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
DragFirst = Standard_False;
- xx2 = LOWORD(lParam);
- yy2 = HIWORD(lParam);
+ X_Motion = LOWORD(lParam);
+ Y_Motion = HIWORD(lParam);
- Rectangle( hdc, xx1, yy1, xx2, yy2 );
+ Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
SelectObject( hdc, anObj );
VT_GetWindow()->Unmap();
return 0;
case WM_PAINT:
- //cout << "\t WM_PAINT" << endl;
BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
- ProcessExpose();
+ VT_ProcessExpose();
break;
case WM_SIZE:
- //cout << "\t WM_SIZE" << endl;
- ProcessConfigure();
+ VT_ProcessConfigure();
break;
case WM_KEYDOWN:
- //cout << "\t WM_KEYDOWN " << (int) wParam << endl;
-
- if ( (wParam != VK_SHIFT) && (wParam != VK_CONTROL) ) {
+ if ((wParam != VK_SHIFT) && (wParam != VK_CONTROL))
+ {
char c[2];
c[0] = (char) wParam;
c[1] = '\0';
- ProcessKeyPress( c);
+ VT_ProcessKeyPress (c);
}
break;
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
- //cout << "\t WM_xBUTTONUP" << endl;
Up = 1;
- ProcessButtonRelease();
+ VT_ProcessButton3Release();
break;
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
{
- //cout << "\t WM_xBUTTONDOWN" << endl;
WPARAM fwKeys = wParam;
Up = 0;
X_ButtonPress = LOWORD(lParam);
Y_ButtonPress = HIWORD(lParam);
- if ( Msg == WM_LBUTTONDOWN) {
- if(fwKeys & MK_CONTROL) {
- Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
- } else
- ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) );
+ if (Msg == WM_LBUTTONDOWN)
+ {
+ if (fwKeys & MK_CONTROL)
+ {
+ Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
+ }
+ else
+ {
+ VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
+ }
}
- else if ( Msg == WM_RBUTTONDOWN ) {
+ else if (Msg == WM_RBUTTONDOWN)
+ {
// Start rotation
- ProcessButton3Press( );
+ VT_ProcessButton3Press();
}
}
break;
if ( fwKeys & MK_RBUTTON ) {
// Start rotation
- ProcessButton3Press();
+ VT_ProcessButton3Press();
}
}
else if ( fwKeys & MK_MBUTTON ||
((fwKeys&MK_LBUTTON) &&
(fwKeys&MK_RBUTTON) ) ){
- ProcessControlButton2Motion();
+ VT_ProcessControlButton2Motion();
}
else if ( fwKeys & MK_RBUTTON ) {
- ProcessControlButton3Motion();
+ VT_ProcessControlButton3Motion();
}
}
#ifdef BUG
}
#endif
else
- if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){
+ if ((fwKeys & MK_MBUTTON
+ || ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
+ {
ProcessZClipMotion();
}
- else {
- ProcessMotion();
+ else
+ {
+ VT_ProcessMotion();
}
}
break;
//while ( Ppick == -1 ) {
while ( Ppick == 1 ) {
- // Wait for a ProcessButton1Press() to toggle pick to 1 or 0
+ // Wait for a VT_ProcessButton1Press() to toggle pick to 1 or 0
if (GetMessage(&msg, NULL, 0, 0) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
return Ppick;
}
-
-#else
+#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
int min( int a, int b )
{
switch ( report.type ) {
case Expose:
{
- ProcessExpose();
+ VT_ProcessExpose();
}
break;
case ConfigureNotify:
{
- ProcessConfigure();
+ VT_ProcessConfigure();
}
break;
case KeyPress:
buf_ret[ret_len] = '\0' ;
- if ( ret_len ) {
- ProcessKeyPress( buf_ret);
+ if (ret_len)
+ {
+ VT_ProcessKeyPress (buf_ret);
}
}
break;
X_ButtonPress = report.xbutton.x;
Y_ButtonPress = report.xbutton.y;
- if ( report.xbutton.button == Button1 )
- if( report.xbutton.state & ControlMask )
- pick = ProcessButton1Press( argc, argv, pick,
- ( report.xbutton.state & ShiftMask) );
+ if (report.xbutton.button == Button1)
+ {
+ if (report.xbutton.state & ControlMask)
+ {
+ pick = VT_ProcessButton1Press (argc, argv, pick, (report.xbutton.state & ShiftMask));
+ }
else
{
IsDragged = Standard_True;
- xx1 = X_ButtonPress;
- yy1 = Y_ButtonPress;
+ X_ButtonPress = X_ButtonPress;
+ Y_ButtonPress = Y_ButtonPress;
DragFirst = Standard_True;
}
- else if ( report.xbutton.button == Button3 )
+ }
+ else if (report.xbutton.button == Button3)
+ {
// Start rotation
- ProcessButton3Press();
+ VT_ProcessButton3Press();
+ }
}
break;
case ButtonRelease:
Aspect_Handle aWindow = VT_GetWindow()->XWindow();
GC gc = XCreateGC( display, aWindow, 0, 0 );
// XSetFunction( display, gc, GXinvert );
- XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
+ XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
}
Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
else
if( ShiftPressed )
{
- aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ),
- max( xx1, xx2 ), max( yy1, yy2 ),
+ aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
+ max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
ViewerTest::CurrentView());
// cout << "shift select" << endl;
}
else
{
- aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ),
- max( xx1, xx2 ), max( yy1, yy2 ),
+ aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
+ max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
ViewerTest::CurrentView() );
// cout << "select" << endl;
}
else
- ProcessButtonRelease();
+ VT_ProcessButton3Release();
IsDragged = Standard_False;
}
else
- ProcessButtonRelease();
+ VT_ProcessButton3Release();
}
break;
case MotionNotify:
XSetFunction( display, gc, GXinvert );
if( !DragFirst )
- XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
+ XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
- xx2 = X_Motion;
- yy2 = Y_Motion;
+ X_Motion = X_Motion;
+ Y_Motion = Y_Motion;
DragFirst = Standard_False;
- //cout << "draw rect : " << xx2 << ", " << yy2 << endl;
- XDrawRectangle( display, aWindow, gc, min( xx1, xx2 ), min( yy1, yy2 ), abs( xx2-xx1 ), abs( yy2-yy1 ) );
+ //cout << "draw rect : " << X_Motion << ", " << Y_Motion << endl;
+ XDrawRectangle( display, aWindow, gc, min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ), abs( X_Motion-X_ButtonPress ), abs( Y_Motion-Y_ButtonPress ) );
}
else
{
ProcessControlButton1Motion();
}
else if ( report.xmotion.state & Button2Mask ) {
- ProcessControlButton2Motion();
+ VT_ProcessControlButton2Motion();
}
else if ( report.xmotion.state & Button3Mask ) {
- ProcessControlButton3Motion();
+ VT_ProcessControlButton3Motion();
}
}
- else {
- ProcessMotion();
+ else
+ {
+ VT_ProcessMotion();
}
}
}
static void OSWindowSetup()
{
-#ifndef WNT
+#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
// X11
Window window = VT_GetWindow()->XWindow();
return 0;
}
-
-
//==============================================================================
//function : InitViewerTest
//purpose : initialisation de toutes les variables static de ViewerTest (dp)
ViewerTest::ResetEventManager();
Handle(Aspect_GraphicDevice) device = viewer->Device();
Handle(Aspect_Window) window = view->Window();
-#ifndef WNT
+#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
// X11
VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
#endif
}
-
//==============================================================================
//function : VSetBg
//purpose : Load image as background
// Create 3D view if it doesn't exist
if ( aV3dView.IsNull() )
{
- ViewerTest::ViewerInit();
+ ViewerTest::ViewerInit();
aV3dView = ViewerTest::CurrentView();
if( aV3dView.IsNull() )
{
//purpose : Test printing algorithm, print the view to image file with given
// width and height. Printing implemented only for WNT.
//==============================================================================
-static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
+static int VPrintView (Draw_Interpretor& di, Standard_Integer argc,
const char** argv)
{
#ifndef WNT
Standard_Boolean isSaved = Standard_False, isPrinted = Standard_False;
if (aBitsOut != NULL)
- {
+ {
if (aMode == 0)
isPrinted = aView->Print(anDC,1,1,0,Aspect_PA_STRETCH);
else
// render item
void V3d_TextItem::RedrawLayerPrs ()
-{
+{
if (myLayer.IsNull ())
return;
DEFINE_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem)
// The Visual3d_LayerItem line item for "vlayerline" command
-// it provides a presentation of line with user-defined
+// it provides a presentation of line with user-defined
// linewidth, linetype and transparency.
-class V3d_LineItem : public Visual3d_LayerItem
+class V3d_LineItem : public Visual3d_LayerItem
{
public:
// CASCADE RTTI
- DEFINE_STANDARD_RTTI(V3d_LineItem)
-
+ DEFINE_STANDARD_RTTI(V3d_LineItem)
+
// constructor
Standard_EXPORT V3d_LineItem(Standard_Real X1, Standard_Real Y1,
Standard_Real X2, Standard_Real Y2,
IMPLEMENT_STANDARD_RTTIEXT(V3d_LineItem, Visual3d_LayerItem)
// default constructor for line item
-V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
+V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1,
Standard_Real X2, Standard_Real Y2,
V3d_LayerMgrPointer theLayerMgr,
Aspect_TypeOfLine theType,
void V3d_LineItem::RedrawLayerPrs ()
{
Handle (Visual3d_Layer) aOverlay;
-
+
if (myLayerMgr)
aOverlay = myLayerMgr->Overlay();
if (argc > 7)
{
aTransparency = atof(argv[7]);
- if (aTransparency < 0 || aTransparency > 1.0)
+ if (aTransparency < 0 || aTransparency > 1.0)
aTransparency = 1.0;
}
aView->SetLayerMgr(aMgr);
// add line item
- Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
+ Handle (V3d_LineItem) anItem = new V3d_LineItem(X1, Y1, X2, Y2,
aMgr.operator->(),
- aLineType, aWidth,
+ aLineType, aWidth,
aTransparency);
// update view
di << "(default=255.0 255.0 255.0)\n";
return 1;
}
-
+
TCollection_AsciiString aText (argv[1]);
Standard_Real aPosX = atof(argv[2]);
Standard_Real aPosY = atof(argv[3]);
aView->SetLayerMgr (aMgr);
}
- Quantity_Color aTextColor (aColorRed, aColorGreen,
+ Quantity_Color aTextColor (aColorRed, aColorGreen,
aColorBlue, Quantity_TOC_RGB);
- Quantity_Color aSubtColor (aSubRed, aSubGreen,
+ Quantity_Color aSubtColor (aSubRed, aSubGreen,
aSubBlue, Quantity_TOC_RGB);
// add text item
--- /dev/null
+// Copyright (c) 2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+#if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+
+#import <Cocoa/Cocoa.h>
+
+#include <Cocoa_Window.hxx>
+#include <ViewerTest.hxx>
+#include <V3d_View.hxx>
+#include <V3d_Viewer.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <NIS_View.hxx>
+
+//! Custom Cocoa view to handle events
+@interface ViewerTest_CocoaEventManagerView : NSView
+@end
+
+extern void VT_ProcessExpose();
+extern void VT_ProcessConfigure();
+extern void VT_ProcessKeyPress (const char* theBuffer);
+extern void VT_ProcessMotion();
+extern void VT_ProcessButton3Press();
+extern void VT_ProcessButton3Release();
+extern void VT_ProcessControlButton2Motion();
+extern void VT_ProcessControlButton3Motion();
+extern Standard_Boolean VT_ProcessButton1Press (Standard_Integer theArgsNb,
+ const char** theArgsVec,
+ Standard_Boolean theToPick,
+ Standard_Boolean theIsShift);
+extern void VT_ProcessButton1Release(Standard_Boolean theIsShift);
+
+extern int X_Motion; // Current cursor position
+extern int Y_Motion;
+extern int X_ButtonPress; // Last ButtonPress position
+extern int Y_ButtonPress;
+extern Standard_Boolean IsDragged;
+
+// =======================================================================
+// function : ViewerMainLoop
+// purpose :
+// =======================================================================
+int ViewerMainLoop (Standard_Integer, const char** )
+{
+ // unused
+ return 0;
+}
+
+// =======================================================================
+// function : ViewerTest_SetCocoaEventManagerView
+// purpose :
+// =======================================================================
+void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow)
+{
+ if (theWindow.IsNull())
+ {
+ return;
+ }
+
+ NSWindow* aWin = [theWindow->HView() window];
+ NSRect aBounds = [[aWin contentView] bounds];
+
+ ViewerTest_CocoaEventManagerView* aView = [[ViewerTest_CocoaEventManagerView alloc] initWithFrame: aBounds];
+
+ // replace content view in the window
+ theWindow->SetHView (aView);
+
+ // make view as first responder in winow to capture all useful events
+ [aWin makeFirstResponder: aView];
+ [aWin setAcceptsMouseMovedEvents: YES];
+
+ // should be retained by parent NSWindow
+ [aView release];
+}
+
+// =======================================================================
+// function : getMouseCoords
+// purpose : Retrieve cursor position
+// =======================================================================
+static void getMouseCoords (NSView* theView,
+ NSEvent* theEvent,
+ Standard_Integer& theX,
+ Standard_Integer& theY)
+{
+ NSPoint aMouseLoc = [theView convertPoint: [theEvent locationInWindow] fromView: nil];
+ NSRect aBounds = [theView bounds];
+
+ theX = Standard_Integer(aMouseLoc.x);
+ theY = Standard_Integer(aBounds.size.height - aMouseLoc.y);
+}
+
+@implementation ViewerTest_CocoaEventManagerView
+
+// =======================================================================
+// function : setFrameSize
+// purpose :
+// =======================================================================
+- (void )setFrameSize: (NSSize )theNewSize
+{
+ [super setFrameSize: theNewSize];
+ VT_ProcessConfigure();
+}
+
+// =======================================================================
+// function : drawRect
+// purpose :
+// =======================================================================
+- (void )drawRect: (NSRect )theDirtyRect
+{
+ VT_ProcessExpose();
+}
+
+// =======================================================================
+// function : mouseMoved
+// purpose :
+// =======================================================================
+- (void )mouseMoved: (NSEvent* )theEvent
+{
+ getMouseCoords (self, theEvent, X_Motion, Y_Motion);
+ VT_ProcessMotion();
+}
+
+// =======================================================================
+// function : acceptsFirstResponder
+// purpose :
+// =======================================================================
+- (BOOL )acceptsFirstResponder
+{
+ return YES;
+}
+
+// =======================================================================
+// function : mouseDown
+// purpose :
+// =======================================================================
+- (void )mouseDown: (NSEvent* )theEvent
+{
+ getMouseCoords (self, theEvent, X_ButtonPress, Y_ButtonPress);
+ VT_ProcessButton1Press (0, NULL, Standard_False, [theEvent modifierFlags] & NSShiftKeyMask);
+}
+
+// =======================================================================
+// function : mouseUp
+// purpose :
+// =======================================================================
+- (void )mouseUp: (NSEvent* )theEvent
+{
+ getMouseCoords (self, theEvent, X_Motion, Y_Motion);
+ VT_ProcessButton1Release([theEvent modifierFlags] & NSShiftKeyMask);
+}
+
+
+// =======================================================================
+// function : mouseDragged
+// purpose :
+// =======================================================================
+- (void )mouseDragged: (NSEvent* )theEvent
+{
+ IsDragged = Standard_True;
+ if ([theEvent modifierFlags] & NSControlKeyMask)
+ {
+ getMouseCoords (self, theEvent, X_Motion, Y_Motion);
+ VT_ProcessControlButton2Motion();
+ }
+}
+
+// =======================================================================
+// function : rightMouseDown
+// purpose :
+// =======================================================================
+- (void )rightMouseDown: (NSEvent* )theEvent
+{
+ getMouseCoords (self, theEvent, X_ButtonPress, Y_ButtonPress);
+ VT_ProcessButton3Press(); // Start rotation
+}
+
+// =======================================================================
+// function : rightMouseUp
+// purpose :
+// =======================================================================
+- (void )rightMouseUp: (NSEvent* )theEvent
+{
+ VT_ProcessButton3Release();
+}
+
+// =======================================================================
+// function : rightMouseDragged
+// purpose :
+// =======================================================================
+- (void )rightMouseDragged: (NSEvent* )theEvent
+{
+ if ([theEvent modifierFlags] & NSControlKeyMask)
+ {
+ getMouseCoords (self, theEvent, X_Motion, Y_Motion);
+ VT_ProcessControlButton3Motion();
+ }
+}
+
+// =======================================================================
+// function : scrollWheel
+// purpose :
+// =======================================================================
+- (void )scrollWheel: (NSEvent* )theEvent
+{
+ float aDelta = [theEvent deltaY];
+ if (Abs (aDelta) < 0.001)
+ {
+ // a lot of values near zero can be generated by touchpad
+ return;
+ }
+
+ ViewerTest::CurrentView()->Zoom (0, 0, aDelta, aDelta);
+}
+
+// =======================================================================
+// function : keyDown
+// purpose :
+// =======================================================================
+- (void )keyDown: (NSEvent* )theEvent
+{
+ NSString* aStringNs = [theEvent characters];
+ if (aStringNs == NULL || [aStringNs length] == 0)
+ {
+ return;
+ }
+
+ const Standard_CString aString = [aStringNs UTF8String];
+ VT_ProcessKeyPress (aString);
+}
+
+@end
+
+#endif
#include <TColStd_HArray2OfReal.hxx>
-#ifndef WNT
-# include <Xw_Window.hxx>
+#if (defined(_WIN32) || defined(__WIN32__))
+ #include <WNT_Window.hxx>
+#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
+ #include <Cocoa_Window.hxx>
#else
-# include <WNT_Window.hxx>
-#endif // WNT
+ #include <Xw_Window.hxx>
+#endif
#include <float.h>
}
// RIC120302
-void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow) {
+void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
+{
if (IsDeleted ()) return;
if (IsDefined ())
Visual3d_ViewDefinitionError::Raise ("Window already defined");
- MyWindow = AWindow;
+ MyWindow = theWindow;
MyCView.WsId = MyCView.ViewId;
MyCView.DefWindow.IsDefined = 1;
-#ifndef WNT
-const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AWindow;
- MyCView.DefWindow.XWindow = theWindow->XWindow ();
-#ifdef RIC120302
- MyCView.DefWindow.XParentWindow = theWindow->XParentWindow ();
-#endif
+
+#if (defined(_WIN32) || defined(__WIN32__))
+ const Handle(WNT_Window) aWin = Handle(WNT_Window)::DownCast (theWindow);
+ MyCView.DefWindow.XWindow = (HWND )(aWin->HWindow());
+ MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow());
+ WNT_WindowData* aWinData = (WNT_WindowData* )GetWindowLongPtr ((HWND )(aWin->HWindow()), GWLP_USERDATA);
+ aWinData->WNT_WDriver_Ptr = (void* )this;
+ aWinData->WNT_VMgr = (void* )MyPtrViewManager;
+#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
+ const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow);
+ MyCView.DefWindow.XWindow = (Aspect_Drawable )aWin->HView();
+ MyCView.DefWindow.XParentWindow = NULL;
+ //MyCView.DefWindow.XParentWindow = aWin->HParentWindow();
#else
-WNT_WindowData* wd;
-const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AWindow;
- MyCView.DefWindow.XWindow = ( HWND )(theWindow->HWindow());
-#ifdef RIC120302
- MyCView.DefWindow.XParentWindow = ( HWND )(theWindow->HParentWindow());
+ const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow);
+ MyCView.DefWindow.XWindow = aWin->XWindow();
+ MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
#endif
- wd = ( WNT_WindowData* )GetWindowLongPtr (( HWND )(theWindow->HWindow()), GWLP_USERDATA);
- wd -> WNT_WDriver_Ptr = ( void* )this;
- wd -> WNT_VMgr = ( void* )MyPtrViewManager;
-#endif /* WNT */
Standard_Integer Width, Height;
- AWindow->Size (Width, Height);
+ theWindow->Size (Width, Height);
MyCView.DefWindow.dx = float( Width );
MyCView.DefWindow.dy = float( Height );