From 4fe56619213b38f852e55d0cff034b0ee9a5bfc4 Mon Sep 17 00:00:00 2001 From: bugmaster Date: Mon, 24 Dec 2012 17:46:07 +0400 Subject: [PATCH] 0023243: Adapt OpenGL viewer for using in Cocoa applications on Mac OS X Cocoa_Window draft OpenGl_Context and OpenGl_Window - added support for Cocoa OpenGL context TKV3d - accept Cocoa_Window Draft version of ViewerInit method for Mac OS X Added ViewerTest_CocoaEventManagerView ViewerTest - attach events to Cocoa window Cocoa_Window - disable autorelease on close Fix for OpenGl_Context::Init method Cocoa_Window - convert top-left coordinates to bottom-left Added selection with rubber band (rubber band drawing still should be implemented) Fixed OpenGl_Display initialization on Mac OS X Fixed OpenGl includes --- adm/UDLIST | 1 + src/Cocoa/Cocoa_LocalPool.hxx | 36 ++ src/Cocoa/Cocoa_LocalPool.mm | 45 ++ src/Cocoa/Cocoa_Window.hxx | 234 +++++++ src/Cocoa/Cocoa_Window.mm | 607 ++++++++++++++++++ src/Cocoa/EXTERNLIB | 3 + src/Cocoa/FILES | 4 + src/InterfaceGraphic/FILES | 1 + src/InterfaceGraphic/InterfaceGraphic.hxx | 12 +- .../InterfaceGraphic_Cocoa.hxx | 40 ++ src/OpenGl/EXTERNLIB | 3 + src/OpenGl/FILES | 2 + src/OpenGl/OpenGl_Context.cxx | 20 +- src/OpenGl/OpenGl_Context.hxx | 4 + src/OpenGl/OpenGl_Context_1.mm | 90 +++ src/OpenGl/OpenGl_Display.cxx | 10 +- src/OpenGl/OpenGl_Display_1.cxx | 129 +++- src/OpenGl/OpenGl_GlCore11.hxx | 3 - src/OpenGl/OpenGl_Window.cxx | 13 +- src/OpenGl/OpenGl_Window_1.mm | 160 +++++ src/OpenGl/OpenGl_Workspace_2.cxx | 50 +- src/TKOpenGl/EXTERNLIB | 3 + src/TKService/EXTERNLIB | 3 + src/TKService/PACKAGES | 2 + src/TKViewerTest/EXTERNLIB | 3 + src/ViewerTest/EXTERNLIB | 3 + src/ViewerTest/FILES | 2 + src/ViewerTest/ViewerTest_ViewerCommands.cxx | 435 +++++++------ src/ViewerTest/ViewerTest_ViewerCommands_1.mm | 247 +++++++ src/Visual3d/Visual3d_View.cxx | 48 +- 30 files changed, 1916 insertions(+), 297 deletions(-) create mode 100644 src/Cocoa/Cocoa_LocalPool.hxx create mode 100644 src/Cocoa/Cocoa_LocalPool.mm create mode 100644 src/Cocoa/Cocoa_Window.hxx create mode 100644 src/Cocoa/Cocoa_Window.mm create mode 100755 src/Cocoa/EXTERNLIB create mode 100755 src/Cocoa/FILES create mode 100755 src/InterfaceGraphic/InterfaceGraphic_Cocoa.hxx create mode 100644 src/OpenGl/OpenGl_Context_1.mm create mode 100644 src/OpenGl/OpenGl_Window_1.mm create mode 100755 src/ViewerTest/EXTERNLIB create mode 100644 src/ViewerTest/ViewerTest_ViewerCommands_1.mm diff --git a/adm/UDLIST b/adm/UDLIST index e8ec8abe6d..cc72240f8c 100644 --- a/adm/UDLIST +++ b/adm/UDLIST @@ -241,6 +241,7 @@ p Visual3d p Voxel p WNT p Xw +p Cocoa r FontMFT r Textures t TKMeshVS diff --git a/src/Cocoa/Cocoa_LocalPool.hxx b/src/Cocoa/Cocoa_LocalPool.hxx new file mode 100644 index 0000000000..829e8ef4ee --- /dev/null +++ b/src/Cocoa/Cocoa_LocalPool.hxx @@ -0,0 +1,36 @@ +// 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_ diff --git a/src/Cocoa/Cocoa_LocalPool.mm b/src/Cocoa/Cocoa_LocalPool.mm new file mode 100644 index 0000000000..b0124c30e8 --- /dev/null +++ b/src/Cocoa/Cocoa_LocalPool.mm @@ -0,0 +1,45 @@ +// 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 + +#import + +// ======================================================================= +// 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__ diff --git a/src/Cocoa/Cocoa_Window.hxx b/src/Cocoa/Cocoa_Window.hxx new file mode 100644 index 0000000000..b13986da16 --- /dev/null +++ b/src/Cocoa/Cocoa_Window.hxx @@ -0,0 +1,234 @@ +// 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +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 + Standard_EXPORT virtual void Map() const; + + //! Closes the window + Standard_EXPORT virtual void Unmap() const; + + //! Applies the resizing to the window + Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const; + + //! Apply the mapping change to the window + 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 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__ diff --git a/src/Cocoa/Cocoa_Window.mm b/src/Cocoa/Cocoa_Window.mm new file mode 100644 index 0000000000..8966e59d8d --- /dev/null +++ b/src/Cocoa/Cocoa_Window.mm @@ -0,0 +1,607 @@ +// 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 + +#include + +#include + +#include +#include +#include +#include + +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 +{ + // +} diff --git a/src/Cocoa/EXTERNLIB b/src/Cocoa/EXTERNLIB new file mode 100755 index 0000000000..321718aa05 --- /dev/null +++ b/src/Cocoa/EXTERNLIB @@ -0,0 +1,3 @@ +CSF_objc +CSF_Appkit +CSF_IOKit diff --git a/src/Cocoa/FILES b/src/Cocoa/FILES new file mode 100755 index 0000000000..39258e33e3 --- /dev/null +++ b/src/Cocoa/FILES @@ -0,0 +1,4 @@ +Cocoa_LocalPool.hxx +Cocoa_LocalPool.mm +Cocoa_Window.hxx +Cocoa_Window.mm diff --git a/src/InterfaceGraphic/FILES b/src/InterfaceGraphic/FILES index 93ca56a517..0e5a9514c9 100755 --- a/src/InterfaceGraphic/FILES +++ b/src/InterfaceGraphic/FILES @@ -6,6 +6,7 @@ InterfaceGraphic_Portability.hxx InterfaceGraphic_Visual3d.hxx InterfaceGraphic_WNT.hxx InterfaceGraphic_X11.hxx +InterfaceGraphic_Cocoa.hxx InterfaceGraphic_XWD.hxx InterfaceGraphic_wntio.hxx InterfaceGraphic_cPrintf.cxx diff --git a/src/InterfaceGraphic/InterfaceGraphic.hxx b/src/InterfaceGraphic/InterfaceGraphic.hxx index 4d3cc60df3..1fc806987e 100755 --- a/src/InterfaceGraphic/InterfaceGraphic.hxx +++ b/src/InterfaceGraphic/InterfaceGraphic.hxx @@ -17,12 +17,14 @@ // 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 + #include +#elif defined(__APPLE__) + #include #else -# include -#endif //WNT + #include +#endif -#endif /* __INTERFACE_GRAPHIC_HXX */ +#endif // __INTERFACE_GRAPHIC_HXX diff --git a/src/InterfaceGraphic/InterfaceGraphic_Cocoa.hxx b/src/InterfaceGraphic/InterfaceGraphic_Cocoa.hxx new file mode 100755 index 0000000000..8b74bcf22c --- /dev/null +++ b/src/InterfaceGraphic/InterfaceGraphic_Cocoa.hxx @@ -0,0 +1,40 @@ +// 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 + +#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__ diff --git a/src/OpenGl/EXTERNLIB b/src/OpenGl/EXTERNLIB index 886cdef569..8779a608df 100755 --- a/src/OpenGl/EXTERNLIB +++ b/src/OpenGl/EXTERNLIB @@ -2,6 +2,9 @@ CSF_user32 CSF_gdi32 CSF_opengl32 CSF_glu32 +CSF_objc +CSF_Appkit +CSF_IOKit CSF_OpenGlLibs CSF_AviLibs CSF_FREETYPE diff --git a/src/OpenGl/FILES b/src/OpenGl/FILES index 240d9e0abf..cf3db3db39 100755 --- a/src/OpenGl/FILES +++ b/src/OpenGl/FILES @@ -77,6 +77,7 @@ OpenGl_Display_2.cxx Handle_OpenGl_Window.hxx OpenGl_Window.hxx OpenGl_Window.cxx +OpenGl_Window_1.mm OpenGl_PriorityList.hxx OpenGl_PriorityList.cxx OpenGl_AVIWriter.hxx @@ -100,6 +101,7 @@ OpenGl_tgl_funcs.hxx Handle_OpenGl_Context.hxx OpenGl_Context.hxx OpenGl_Context.cxx +OpenGl_Context_1.mm OpenGl_ArbIns.hxx OpenGl_ArbTBO.hxx OpenGl_ArbVBO.hxx diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 998c817668..25fd6b0d2a 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -1,6 +1,6 @@ // 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 @@ -17,7 +17,6 @@ // 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 #endif @@ -166,6 +165,8 @@ void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx) } } +#if !defined(__APPLE__) || defined(MACOSX_USE_GLX) + // ======================================================================= // function : IsCurrent // purpose : @@ -265,6 +266,8 @@ void OpenGl_Context::SwapBuffers() #endif } +#endif // __APPLE__ + // ======================================================================= // function : findProc // purpose : @@ -335,6 +338,8 @@ Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const return Standard_False; } +#if !defined(__APPLE__) || defined(MACOSX_USE_GLX) + // ======================================================================= // function : Init // purpose : @@ -364,6 +369,8 @@ Standard_Boolean OpenGl_Context::Init() return Standard_True; } +#endif // __APPLE__ + // ======================================================================= // function : Init // purpose : @@ -372,6 +379,8 @@ Standard_Boolean OpenGl_Context::Init() 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, @@ -379,12 +388,15 @@ Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow, #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()) diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index 9752680fa4..a125ad487c 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -100,6 +100,8 @@ public: 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, @@ -253,6 +255,8 @@ private: // system-dependent fields 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* diff --git a/src/OpenGl/OpenGl_Context_1.mm b/src/OpenGl/OpenGl_Context_1.mm new file mode 100644 index 0000000000..4a9a99ff0a --- /dev/null +++ b/src/OpenGl/OpenGl_Context_1.mm @@ -0,0 +1,90 @@ +// 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 + +#include +#include + +#include + +// ======================================================================= +// 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__ diff --git a/src/OpenGl/OpenGl_Display.cxx b/src/OpenGl/OpenGl_Display.cxx index 5ba209fd75..12b44a87ba 100644 --- a/src/OpenGl/OpenGl_Display.cxx +++ b/src/OpenGl/OpenGl_Display.cxx @@ -28,7 +28,7 @@ #include -#if (!defined(_WIN32) && !defined(__WIN32__)) +#if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))) #include // XOpenDisplay() #endif @@ -39,7 +39,7 @@ Handle(OpenGl_Display) openglDisplay; namespace { - #if (defined(_WIN32) || defined(__WIN32__)) + #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) static char* TheDummyDisplay = "DISPLAY"; #endif @@ -65,7 +65,7 @@ OpenGl_Display::OpenGl_Display (const Standard_CString theDisplay) 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') @@ -257,7 +257,7 @@ void OpenGl_Display::Init() { 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) @@ -276,7 +276,7 @@ void OpenGl_Display::Init() 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 diff --git a/src/OpenGl/OpenGl_Display_1.cxx b/src/OpenGl/OpenGl_Display_1.cxx index 43680f1acc..0e954ebffd 100644 --- a/src/OpenGl/OpenGl_Display_1.cxx +++ b/src/OpenGl/OpenGl_Display_1.cxx @@ -17,6 +17,7 @@ // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. +#include #include #include @@ -39,7 +40,49 @@ /*-----------------------------------------------------------------------------*/ /* * 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)) /*-----------------------------------------------------------------------------*/ @@ -50,9 +93,9 @@ #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"}; @@ -107,30 +150,56 @@ void OpenGl_Display::getGL2PSFontName (const char *src_font, char *ps_font) /*-----------------------------------------------------------------------------*/ /* -* 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; } @@ -162,9 +231,9 @@ class MultilineTextRenderer { 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 @@ -326,7 +395,7 @@ class MultilineTextRenderer anIndex2 += aHelpIndex - 1; aTimeVar = 0; } - else + else { myNewStr[anIndex2] = *(myStrPtr + anIndex1); } @@ -378,7 +447,7 @@ class MultilineTextRenderer 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 { @@ -432,7 +501,7 @@ void OpenGl_Display::RenderText (const wchar_t* str, const int is2d, const float 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); @@ -488,9 +557,9 @@ void OpenGl_Display::RenderText (const wchar_t* str, const int is2d, const float (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(); @@ -500,22 +569,22 @@ void OpenGl_Display::RenderText (const wchar_t* str, const int is2d, const float 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 @@ -530,9 +599,9 @@ void OpenGl_Display::RenderText (const wchar_t* str, const int is2d, const float } } - 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; diff --git a/src/OpenGl/OpenGl_GlCore11.hxx b/src/OpenGl/OpenGl_GlCore11.hxx index 6932fdf273..9a62a05dfd 100644 --- a/src/OpenGl/OpenGl_GlCore11.hxx +++ b/src/OpenGl/OpenGl_GlCore11.hxx @@ -38,9 +38,6 @@ #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 diff --git a/src/OpenGl/OpenGl_Window.cxx b/src/OpenGl/OpenGl_Window.cxx index f0a3a49174..614f725379 100644 --- a/src/OpenGl/OpenGl_Window.cxx +++ b/src/OpenGl/OpenGl_Window.cxx @@ -17,7 +17,6 @@ // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. - #include #include @@ -33,6 +32,8 @@ 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 } }; @@ -437,6 +438,8 @@ OpenGl_Window::~OpenGl_Window() #endif } +#endif // !__APPLE__ + // ======================================================================= // function : Activate // purpose : @@ -446,6 +449,8 @@ Standard_Boolean OpenGl_Window::Activate() return myGlContext->MakeCurrent(); } +#if !defined(__APPLE__) || defined(MACOSX_USE_GLX) + // ======================================================================= // function : Resize // purpose : call_subr_resize @@ -471,6 +476,8 @@ void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow) Init(); } +#endif // !__APPLE__ + // ======================================================================= // function : ReadDepths // purpose : TelReadDepths @@ -507,6 +514,8 @@ void OpenGl_Window::SetBackgroundColor (const Standard_ShortReal theR, myBgColor.rgb[2] = theB; } +#if !defined(__APPLE__) || defined(MACOSX_USE_GLX) + // ======================================================================= // function : Init // purpose : @@ -540,6 +549,8 @@ void OpenGl_Window::Init() glDrawBuffer (GL_BACK); } +#endif // !__APPLE__ + // ======================================================================= // function : EnablePolygonOffset // purpose : call_subr_enable_polygon_offset diff --git a/src/OpenGl/OpenGl_Window_1.mm b/src/OpenGl/OpenGl_Window_1.mm new file mode 100644 index 0000000000..dce08ac5d9 --- /dev/null +++ b/src/OpenGl/OpenGl_Window_1.mm @@ -0,0 +1,160 @@ +// 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 + +#include + +#include + +#include +#include +#include +#include +#include + +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__ diff --git a/src/OpenGl/OpenGl_Workspace_2.cxx b/src/OpenGl/OpenGl_Workspace_2.cxx index edd0231b63..03c3a3320c 100644 --- a/src/OpenGl/OpenGl_Workspace_2.cxx +++ b/src/OpenGl/OpenGl_Workspace_2.cxx @@ -28,12 +28,12 @@ # include #endif -#ifdef HAVE_FREEIMAGE +#if (defined(_WIN32) || defined(__WIN32__)) && defined(HAVE_FREEIMAGE) #include #include #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 FipHandle; #endif @@ -71,7 +71,7 @@ static void getMaxFrameSize(Standard_Integer& theWidth, 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]); @@ -99,7 +99,7 @@ static void fitDimensionsRatio (Standard_Integer& theWidth, // --------------------------------------------------------------- // 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, @@ -134,7 +134,7 @@ static void initBufferStretch (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); @@ -204,13 +204,13 @@ static void initBitmapBuffer (const HDC theMemoryDC, // 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, @@ -279,7 +279,7 @@ static bool imageStretchDC(HDC theDstDC, FipHandle theImage, int theOffsetX, 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, @@ -288,7 +288,7 @@ static bool imageStretchDC(HDC theDstDC, FipHandle theImage, int theOffsetX, if (aPassed != heightPx) return false; - + return true; } #endif @@ -299,8 +299,8 @@ static bool imageStretchDC(HDC theDstDC, FipHandle theImage, int theOffsetX, //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, @@ -423,7 +423,7 @@ Standard_Boolean OpenGl_Workspace::Print } #else // try to allocate compatible bitmap and necessary resources - initBitmapBuffer (hMemDC, hViewBitmap, + initBitmapBuffer (hMemDC, hViewBitmap, aFrameWidth, aFrameHeight, aViewBuffer); if (!aViewBuffer) { @@ -493,7 +493,7 @@ Standard_Boolean OpenGl_Workspace::Print break; #else // try to allocate compatible bitmap and necessary resources - initBitmapBuffer (hMemDC, hViewBitmap, + initBitmapBuffer (hMemDC, hViewBitmap, aFrameWidth, aFrameHeight, aViewBuffer); if (!aViewBuffer) { @@ -515,7 +515,7 @@ Standard_Boolean OpenGl_Workspace::Print 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.", @@ -533,7 +533,7 @@ Standard_Boolean OpenGl_Workspace::Print } // setup printing context and viewport - GLint aViewPortBack[4]; + GLint aViewPortBack[4]; GLint anAlignBack = 1; OpenGl_PrinterContext aPrinterContext (GetGContext()); @@ -620,9 +620,9 @@ Standard_Boolean OpenGl_Workspace::Print // 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) { @@ -722,7 +722,7 @@ Standard_Boolean OpenGl_Workspace::Print // stop operation if errors if (!isDone) break; - + // calculate new view offset for x-coordinate aOffsetx += 2.0; aSubLeft += aRight-aLeft; @@ -742,12 +742,12 @@ Standard_Boolean OpenGl_Workspace::Print 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) { @@ -776,14 +776,14 @@ Standard_Boolean OpenGl_Workspace::Print #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) { @@ -866,7 +866,7 @@ void OpenGl_Workspace::CopyBuffers (Tint vid, int FrontToBack, Tfloat xm, Tfloat GLsizei width = myWidth+1, height = myHeight+1; Tfloat xmr = 0, ymr = 0; - if (flag) + if (flag) { if (!myView.IsNull()) //szvgl: use vid here! { diff --git a/src/TKOpenGl/EXTERNLIB b/src/TKOpenGl/EXTERNLIB index 8b6922e94f..e510118c08 100755 --- a/src/TKOpenGl/EXTERNLIB +++ b/src/TKOpenGl/EXTERNLIB @@ -2,6 +2,9 @@ TKernel TKService TKV3d CSF_OpenGlLibs +CSF_objc +CSF_Appkit +CSF_IOKit CSF_FREETYPE CSF_FTGL CSF_GL2PS diff --git a/src/TKService/EXTERNLIB b/src/TKService/EXTERNLIB index f363a3d056..7268b178a0 100755 --- a/src/TKService/EXTERNLIB +++ b/src/TKService/EXTERNLIB @@ -3,5 +3,8 @@ TKMath CSF_XwLibs CSF_dpsLibs CSF_XmuLibs +CSF_objc +CSF_Appkit +CSF_IOKit CSF_FreeImagePlus CSF_FREETYPE diff --git a/src/TKService/PACKAGES b/src/TKService/PACKAGES index 228e8aee78..4cdc1f2097 100755 --- a/src/TKService/PACKAGES +++ b/src/TKService/PACKAGES @@ -11,5 +11,7 @@ Image PlotMgt ImageUtility WNT +Cocoa TColQuantity Font + diff --git a/src/TKViewerTest/EXTERNLIB b/src/TKViewerTest/EXTERNLIB index f4bc379ae5..d610db899b 100755 --- a/src/TKViewerTest/EXTERNLIB +++ b/src/TKViewerTest/EXTERNLIB @@ -25,3 +25,6 @@ CSF_TclTkLibs CSF_user32 CSF_gdi32 CSF_OpenGlLibs +CSF_objc +CSF_Appkit +CSF_IOKit diff --git a/src/ViewerTest/EXTERNLIB b/src/ViewerTest/EXTERNLIB new file mode 100755 index 0000000000..321718aa05 --- /dev/null +++ b/src/ViewerTest/EXTERNLIB @@ -0,0 +1,3 @@ +CSF_objc +CSF_Appkit +CSF_IOKit diff --git a/src/ViewerTest/FILES b/src/ViewerTest/FILES index bbe254bd8b..066ac39f60 100755 --- a/src/ViewerTest/FILES +++ b/src/ViewerTest/FILES @@ -1,3 +1,4 @@ +EXTERNLIB ViewerTest_CMPLRS.edl ViewerTest_AviCommands.cxx ViewerTest_ViewerCommands.cxx @@ -6,3 +7,4 @@ ViewerTest_ObjectCommands.cxx ViewerTest_FilletCommands.cxx ViewerTest_VoxelCommands.cxx ViewerTest_OpenGlCommands.cxx +ViewerTest_ViewerCommands_1.mm diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 11643aedbf..cb4a9dcc01 100755 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -61,28 +61,29 @@ #include #include -#ifndef WNT -#include -#include -#include -#include -#include /* contains some dangerous #defines such as Status, True etc. */ -#include -#include - +#if defined(_WIN32) || defined(__WIN32__) + #include + #include + #include + + #if defined(_MSC_VER) + #define _CRT_SECURE_NO_DEPRECATE + #pragma warning (disable:4996) + #endif +#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) + #include + #include + #include #else - -#include -#include -#include - -#define _CRT_SECURE_NO_DEPRECATE -#pragma warning (disable:4996) - + #include + #include + #include + #include + #include /* contains some dangerous #defines such as Status, True etc. */ + #include + #include #endif -#define OCC120 - //============================================================================== //============================================================================== @@ -94,7 +95,7 @@ Standard_IMPORT Standard_Boolean Draw_VirtualWindows; 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; @@ -104,7 +105,18 @@ static Handle(WNT_Window)& VT_GetWindow() { 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; @@ -119,9 +131,7 @@ static Display *display; static void VProcessEvents(ClientData,int); #endif -#ifdef OCC120 static Standard_Boolean DegenerateMode = Standard_True; -#endif #define ZCLIPWIDTH 1. @@ -133,9 +143,12 @@ static void OSWindowSetup(); 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; //============================================================================== @@ -161,8 +174,9 @@ static LRESULT WINAPI AdvViewerWindowProc( 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)); @@ -182,9 +196,9 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I 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; @@ -201,7 +215,7 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I if (isFirst) { // Create the Graphic device -#ifdef WNT +#if defined(_WIN32) || defined(__WIN32__) if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice(); if (VT_GetWindow().IsNull()) { @@ -214,7 +228,18 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I 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() = @@ -227,9 +252,9 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I 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 @@ -266,9 +291,7 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I 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); @@ -276,19 +299,21 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I 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(); } //============================================================================== @@ -308,11 +333,10 @@ static int VInit (Draw_Interpretor& , Standard_Integer argc, const char** argv) } //============================================================================== -//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(); @@ -337,20 +361,15 @@ static void ProcessKeyPress( char *buf_ret ) 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) @@ -370,9 +389,7 @@ static void ProcessKeyPress( char *buf_ret ) else if ( !strcasecmp(buf_ret, "U") ) { // Unset display mode cout<<"passage au mode par defaut"<SetDegenerateModeOn(); -#endif + Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); if(Ctx->NbCurrents()==0 || Ctx->NbSelected()==0) @@ -409,13 +426,7 @@ static void ProcessKeyPress( char *buf_ret ) 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) @@ -467,38 +478,44 @@ static void ProcessKeyPress( char *buf_ret ) } //============================================================================== -//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 ) { @@ -520,35 +537,50 @@ static Standard_Boolean ProcessButton1Press( } //============================================================================== -//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 } //============================================================================== @@ -605,11 +637,10 @@ static void ProcessControlButton1Motion() } //============================================================================== -//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); @@ -623,21 +654,22 @@ static void ProcessControlButton2Motion() } //============================================================================== -//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 @@ -658,7 +690,7 @@ void ViewerTest::GetMousePosition(Standard_Integer& Xpix,Standard_Integer& Ypix) 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; @@ -790,14 +822,6 @@ static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** ) 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; @@ -824,17 +848,17 @@ static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, 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 ); @@ -843,8 +867,8 @@ static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, { 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 ); @@ -860,13 +884,13 @@ static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd, 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 ); @@ -905,41 +929,36 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd, 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; @@ -947,15 +966,21 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd, 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; @@ -975,7 +1000,7 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd, if ( fwKeys & MK_RBUTTON ) { // Start rotation - ProcessButton3Press(); + VT_ProcessButton3Press(); } } @@ -986,10 +1011,10 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd, else if ( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) ){ - ProcessControlButton2Motion(); + VT_ProcessControlButton2Motion(); } else if ( fwKeys & MK_RBUTTON ) { - ProcessControlButton3Motion(); + VT_ProcessControlButton3Motion(); } } #ifdef BUG @@ -1003,11 +1028,14 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd, } #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; @@ -1051,7 +1079,7 @@ static int ViewerMainLoop(Standard_Integer argc, const char** argv) //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); @@ -1064,8 +1092,7 @@ static int ViewerMainLoop(Standard_Integer argc, const char** argv) return Ppick; } - -#else +#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX) int min( int a, int b ) { @@ -1098,12 +1125,12 @@ XNextEvent( display, &report ); switch ( report.type ) { case Expose: { - ProcessExpose(); + VT_ProcessExpose(); } break; case ConfigureNotify: { - ProcessConfigure(); + VT_ProcessConfigure(); } break; case KeyPress: @@ -1121,8 +1148,9 @@ switch ( report.type ) { buf_ret[ret_len] = '\0' ; - if ( ret_len ) { - ProcessKeyPress( buf_ret); + if (ret_len) + { + VT_ProcessKeyPress (buf_ret); } } break; @@ -1132,20 +1160,25 @@ switch ( report.type ) { 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: @@ -1161,7 +1194,7 @@ switch ( report.type ) { 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(); @@ -1187,25 +1220,25 @@ switch ( report.type ) { 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: @@ -1222,14 +1255,14 @@ switch ( report.type ) { 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 { @@ -1273,14 +1306,15 @@ switch ( report.type ) { ProcessControlButton1Motion(); } else if ( report.xmotion.state & Button2Mask ) { - ProcessControlButton2Motion(); + VT_ProcessControlButton2Motion(); } else if ( report.xmotion.state & Button3Mask ) { - ProcessControlButton3Motion(); + VT_ProcessControlButton3Motion(); } } - else { - ProcessMotion(); + else + { + VT_ProcessMotion(); } } } @@ -1316,7 +1350,7 @@ static void VProcessEvents(ClientData,int) static void OSWindowSetup() { -#ifndef WNT +#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) // X11 Window window = VT_GetWindow()->XWindow(); @@ -1424,8 +1458,6 @@ while (ViewerMainLoop( argc, argv)) { return 0; } - - //============================================================================== //function : InitViewerTest //purpose : initialisation de toutes les variables static de ViewerTest (dp) @@ -1441,7 +1473,7 @@ void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context) 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); @@ -1460,7 +1492,6 @@ void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context) #endif } - //============================================================================== //function : VSetBg //purpose : Load image as background @@ -2023,7 +2054,7 @@ static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, cons // Create 3D view if it doesn't exist if ( aV3dView.IsNull() ) { - ViewerTest::ViewerInit(); + ViewerTest::ViewerInit(); aV3dView = ViewerTest::CurrentView(); if( aV3dView.IsNull() ) { @@ -2099,7 +2130,7 @@ static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, cons //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 @@ -2178,7 +2209,7 @@ static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, 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 @@ -2376,7 +2407,7 @@ V3d_TextItem::V3d_TextItem (const TCollection_AsciiString& theText, // render item void V3d_TextItem::RedrawLayerPrs () -{ +{ if (myLayer.IsNull ()) return; @@ -2388,14 +2419,14 @@ void V3d_TextItem::RedrawLayerPrs () 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, @@ -2420,7 +2451,7 @@ IMPLEMENT_STANDARD_HANDLE(V3d_LineItem, Visual3d_LayerItem) 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, @@ -2437,7 +2468,7 @@ V3d_LineItem::V3d_LineItem(Standard_Real X1, Standard_Real Y1, void V3d_LineItem::RedrawLayerPrs () { Handle (Visual3d_Layer) aOverlay; - + if (myLayerMgr) aOverlay = myLayerMgr->Overlay(); @@ -2505,7 +2536,7 @@ static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** if (argc > 7) { aTransparency = atof(argv[7]); - if (aTransparency < 0 || aTransparency > 1.0) + if (aTransparency < 0 || aTransparency > 1.0) aTransparency = 1.0; } @@ -2534,9 +2565,9 @@ static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** 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 @@ -2572,7 +2603,7 @@ static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char 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]); @@ -2627,9 +2658,9 @@ static int VOverlayText (Draw_Interpretor& di, Standard_Integer argc, const char 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 diff --git a/src/ViewerTest/ViewerTest_ViewerCommands_1.mm b/src/ViewerTest/ViewerTest_ViewerCommands_1.mm new file mode 100644 index 0000000000..2120b040e7 --- /dev/null +++ b/src/ViewerTest/ViewerTest_ViewerCommands_1.mm @@ -0,0 +1,247 @@ +// 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 + +#include +#include +#include +#include +#include +#include + +//! 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 diff --git a/src/Visual3d/Visual3d_View.cxx b/src/Visual3d/Visual3d_View.cxx index 93af9d2e2c..c8e33cce2f 100755 --- a/src/Visual3d/Visual3d_View.cxx +++ b/src/Visual3d/Visual3d_View.cxx @@ -165,11 +165,13 @@ #include -#ifndef WNT -# include +#if (defined(_WIN32) || defined(__WIN32__)) + #include +#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) + #include #else -# include -#endif // WNT + #include +#endif #include @@ -458,36 +460,38 @@ void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow, } // 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 ); -- 2.20.1