1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

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
This commit is contained in:
bugmaster 2012-12-24 17:46:07 +04:00
parent 352ffd7358
commit 4fe5661921
30 changed files with 1916 additions and 297 deletions

View File

@ -241,6 +241,7 @@ p Visual3d
p Voxel p Voxel
p WNT p WNT
p Xw p Xw
p Cocoa
r FontMFT r FontMFT
r Textures r Textures
t TKMeshVS t TKMeshVS

View File

@ -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_

View File

@ -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 <Cocoa_LocalPool.hxx>
#import <Cocoa/Cocoa.h>
// =======================================================================
// function : Cocoa_LocalPool
// purpose :
// =======================================================================
Cocoa_LocalPool::Cocoa_LocalPool()
: myPoolObj ([[NSAutoreleasePool alloc] init])
{
//
}
// =======================================================================
// function : ~Cocoa_LocalPool
// purpose :
// =======================================================================
Cocoa_LocalPool::~Cocoa_LocalPool()
{
NSAutoreleasePool* aPool = (NSAutoreleasePool* )myPoolObj;
//[aPool drain];
[aPool release];
}
#endif // __APPLE__

234
src/Cocoa/Cocoa_Window.hxx Normal file
View File

@ -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 <Aspect_Window.hxx>
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <Aspect_FillMethod.hxx>
#include <Aspect_GradientFillMethod.hxx>
#include <Aspect_Handle.hxx>
#include <Aspect_TypeOfResize.hxx>
#include <Quantity_NameOfColor.hxx>
#include <Quantity_Parameter.hxx>
#include <Quantity_Ratio.hxx>
class Aspect_WindowDefinitionError;
class Aspect_WindowError;
class Aspect_Background;
class Quantity_Color;
class Aspect_GradientBackground;
//! This class defines Cocoa window
class Cocoa_Window : public Aspect_Window
{
public:
//! Creates a NSWindow and NSView defined by his position and size in pixels
Standard_EXPORT Cocoa_Window (const Standard_CString theTitle,
const Standard_Integer thePxLeft,
const Standard_Integer thePxTop,
const Standard_Integer thePxWidth,
const Standard_Integer thePxHeight);
//! Creates a wrapper over existing NSView handle
Standard_EXPORT Cocoa_Window (NSView* theViewNS);
//! Destroies the Window and all resourses attached to it
Standard_EXPORT virtual void Destroy();
~Cocoa_Window()
{
Destroy();
}
//! Modifies the window background
Standard_EXPORT virtual void SetBackground (const Aspect_Background& theBackground);
//! Modifies the window background
Standard_EXPORT virtual void SetBackground (const Quantity_NameOfColor theBackColor);
//! Modifies the window background
Standard_EXPORT virtual void SetBackground (const Quantity_Color& theColor);
//! Modifies the window background
Standard_EXPORT void SetBackground (const Aspect_Handle theBackPixmap);
//! Loads the window background from an image file
Standard_EXPORT Standard_Boolean SetBackground (const Standard_CString theName,
const Aspect_FillMethod theMethod = Aspect_FM_CENTERED);
//! Modifies the window gradient background
Standard_EXPORT virtual void SetBackground (const Aspect_GradientBackground& theBackground);
//! Modifies the window gradient background
Standard_EXPORT void SetBackground (const Quantity_Color& theCol1,
const Quantity_Color& theCol2,
const Aspect_GradientFillMethod theMethod = Aspect_GFM_HOR);
//! Activates/Deactivates the Double Buffering capability for this window
Standard_EXPORT virtual void SetDoubleBuffer (const Standard_Boolean theDBmode);
//! Flushes all graphics to the screen and Swap the Double buffer
Standard_EXPORT virtual void Flush() const;
//! Opens the window <me>
Standard_EXPORT virtual void Map() const;
//! Closes the window <me>
Standard_EXPORT virtual void Unmap() const;
//! Applies the resizing to the window <me>
Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const;
//! Apply the mapping change to the window <me>
Standard_EXPORT virtual Standard_Boolean DoMapping() const;
//! Clears the Window in the Background color
Standard_EXPORT virtual void Clear() const;
//! Clears the Window Area defined by his center and PIXEL size in the Background color
Standard_EXPORT virtual void ClearArea (const Standard_Integer theCenterX,
const Standard_Integer theCenterY,
const Standard_Integer theWidth,
const Standard_Integer theHeight) const;
//! Restores The Window from the BackingStored Window
Standard_EXPORT virtual void Restore() const;
//! Restores The Window Area defined by his center and PIXEL size from the BackingStored Window
Standard_EXPORT virtual void RestoreArea (const Standard_Integer theCenterX,
const Standard_Integer theCenterY,
const Standard_Integer theWidth,
const Standard_Integer theHeight) const;
//! Dumps the Window to file
Standard_EXPORT virtual Standard_Boolean Dump (const Standard_CString theFilename,
const Standard_Real theGammaValue = 1.0) const;
//! Dumps the Window Area defined by his center and PIXEL size to an image file
Standard_EXPORT virtual Standard_Boolean DumpArea (const Standard_CString theFilename,
const Standard_Integer theCenterX,
const Standard_Integer theCenterY,
const Standard_Integer theWidth,
const Standard_Integer theHeight,
const Standard_Real theGammaValue = 1.0) const;
//! Loads the image file to this Window
//! @return TRUE if the loading occurs normaly
Standard_EXPORT virtual Standard_Boolean Load (const Standard_CString theFilename) const;
//! Loads the image file to Window Area
Standard_EXPORT virtual Standard_Boolean LoadArea (const Standard_CString theFilename,
const Standard_Integer theCenterX,
const Standard_Integer theCenterY,
const Standard_Integer theWidth,
const Standard_Integer theHeight) const;
//! Returns the BackingStore capability for this Window
Standard_EXPORT virtual Standard_Boolean BackingStore() const;
//! Returns the DoubleBuffer state
Standard_EXPORT virtual Standard_Boolean DoubleBuffer() const;
//! Returns True if the window <me> is opened
Standard_EXPORT virtual Standard_Boolean IsMapped() const;
//! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions
Standard_EXPORT virtual Quantity_Ratio Ratio() const;
//! Returns The Window POSITION in DSU
Standard_EXPORT virtual void Position (Quantity_Parameter& X1,
Quantity_Parameter& Y1,
Quantity_Parameter& X2,
Quantity_Parameter& Y2) const;
//! Returns The Window POSITION in PIXEL
Standard_EXPORT virtual void Position (Standard_Integer& X1,
Standard_Integer& Y1,
Standard_Integer& X2,
Standard_Integer& Y2) const;
//! Returns The Window SIZE in DSU
Standard_EXPORT virtual void Size (Quantity_Parameter& theWidth,
Quantity_Parameter& theHeight) const;
//! Returns The Window SIZE in PIXEL
Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
Standard_Integer& theHeight) const;
//! Returns The Window SIZE in MM
Standard_EXPORT virtual void MMSize (Standard_Real& theWidth,
Standard_Real& theHeight) const;
//! Returns the DSU value depending of the PIXEL value
Standard_EXPORT virtual Quantity_Parameter Convert (const Standard_Integer PV) const;
//! Returns the PIXEL value depending of the DSU value
Standard_EXPORT virtual Standard_Integer Convert (const Quantity_Parameter DV) const;
//! Returns the DSU position depending of the PIXEL position
Standard_EXPORT virtual void Convert (const Standard_Integer PX,
const Standard_Integer PY,
Quantity_Parameter& DX,
Quantity_Parameter& DY) const;
//! Returns the PIXEL position depending of the DSU position
Standard_EXPORT virtual void Convert (const Quantity_Parameter DX,
const Quantity_Parameter DY,
Standard_Integer& PX,
Standard_Integer& PY) const;
//! @return associated NSView
Standard_EXPORT NSView* HView() const;
//! Setup new NSView.
Standard_EXPORT void SetHView (NSView* theView);
protected:
NSWindow* myHWindow;
NSView* myHView;
Standard_Integer myXLeft;
Standard_Integer myYTop;
Standard_Integer myXRight;
Standard_Integer myYBottom;
public:
DEFINE_STANDARD_RTTI(Cocoa_Window)
};
DEFINE_STANDARD_HANDLE(Cocoa_Window, Aspect_Window)
#endif // _Cocoa_Window_H__

607
src/Cocoa/Cocoa_Window.mm Normal file
View File

@ -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 <Cocoa/Cocoa.h>
#include <Cocoa_Window.hxx>
#include <Cocoa_LocalPool.hxx>
#include <Image_AlienPixMap.hxx>
#include <Aspect_Convert.hxx>
#include <Aspect_GraphicDevice.hxx>
#include <Aspect_WindowDefinitionError.hxx>
IMPLEMENT_STANDARD_HANDLE (Cocoa_Window, Aspect_Window)
IMPLEMENT_STANDARD_RTTIEXT(Cocoa_Window, Aspect_Window)
//! Dummy device class implementation
class Cocoa_GraphicDevice : public Aspect_GraphicDevice
{
public:
virtual Handle_Aspect_GraphicDriver GraphicDriver() const
{
return NULL;
}
DEFINE_STANDARD_RTTI(Cocoa_GraphicDevice)
};
DEFINE_STANDARD_HANDLE(Cocoa_GraphicDevice, Aspect_GraphicDevice)
IMPLEMENT_STANDARD_HANDLE (Cocoa_GraphicDevice, Aspect_GraphicDevice)
IMPLEMENT_STANDARD_RTTIEXT(Cocoa_GraphicDevice, Aspect_GraphicDevice)
static Standard_Integer getScreenBottom()
{
Cocoa_LocalPool aLocalPool;
NSArray* aScreens = [NSScreen screens];
if (aScreens == NULL || [aScreens count] == 0)
{
return 0;
}
NSScreen* aScreen = (NSScreen* )[aScreens objectAtIndex: 0];
NSDictionary* aDict = [aScreen deviceDescription];
NSNumber* aNumber = [aDict objectForKey: @"NSScreenNumber"];
if (aNumber == NULL
|| [aNumber isKindOfClass: [NSNumber class]] == NO)
{
return 0;
}
CGDirectDisplayID aDispId = [aNumber unsignedIntValue];
CGRect aRect = CGDisplayBounds(aDispId);
return Standard_Integer(aRect.origin.y + aRect.size.height);
}
// =======================================================================
// function : Cocoa_Window
// purpose :
// =======================================================================
Cocoa_Window::Cocoa_Window (const Standard_CString theTitle,
const Standard_Integer thePxLeft,
const Standard_Integer thePxTop,
const Standard_Integer thePxWidth,
const Standard_Integer thePxHeight)
: Aspect_Window (new Cocoa_GraphicDevice()),
myHWindow (NULL),
myHView (NULL),
myXLeft (thePxLeft),
myYTop (thePxTop),
myXRight (thePxLeft + thePxWidth),
myYBottom (thePxTop + thePxHeight)
{
if (thePxWidth <= 0 || thePxHeight <= 0)
{
Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range");
}
else if (NSApp == NULL)
{
Aspect_WindowDefinitionError::Raise ("Cocoa application should be instantiated before window");
return;
}
// convert top-bottom coordinates to bottom-top (Cocoa)
myYTop = getScreenBottom() - myYBottom;
myYBottom = myYTop + thePxHeight;
Cocoa_LocalPool aLocalPool;
NSUInteger aWinStyle = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
NSRect aRectNs = NSMakeRect (float(myXLeft), float(myYTop), float(thePxWidth), float(thePxHeight));
myHWindow = [[NSWindow alloc] initWithContentRect: aRectNs
styleMask: aWinStyle
backing: NSBackingStoreBuffered
defer: NO];
if (myHWindow == NULL)
{
Aspect_WindowDefinitionError::Raise ("Unable to create window");
}
myHView = [[myHWindow contentView] retain];
NSString* aTitleNs = [[NSString alloc] initWithUTF8String: theTitle];
[myHWindow setTitle: aTitleNs];
[aTitleNs release];
// do not destroy NSWindow on close - we didn't handle it!
[myHWindow setReleasedWhenClosed: NO];
}
// =======================================================================
// function : Cocoa_Window
// purpose :
// =======================================================================
Cocoa_Window::Cocoa_Window (NSView* theViewNS)
: Aspect_Window (new Cocoa_GraphicDevice()),
myHWindow (NULL),
myHView ([theViewNS retain]),
myXLeft (0),
myYTop (0),
myXRight (512),
myYBottom (512)
{
DoResize();
}
// =======================================================================
// function : Destroy
// purpose :
// =======================================================================
void Cocoa_Window::Destroy()
{
Cocoa_LocalPool aLocalPool;
if (myHWindow != NULL)
{
//[myHWindow close];
[myHWindow release];
myHWindow = NULL;
}
if (myHView != NULL)
{
[myHView release];
myHView = NULL;
}
}
// =======================================================================
// function : HView
// purpose :
// =======================================================================
NSView* Cocoa_Window::HView() const
{
return myHView;
}
// =======================================================================
// function : SetHView
// purpose :
// =======================================================================
void Cocoa_Window::SetHView (NSView* theView)
{
if (myHWindow != NULL)
{
[myHWindow setContentView: theView];
}
if (myHView != NULL)
{
[myHView release];
myHView = NULL;
}
myHView = [theView retain];
}
// =======================================================================
// function : DoubleBuffer
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::DoubleBuffer() const
{
return Standard_True;
}
// =======================================================================
// function : SetBackground
// purpose :
// =======================================================================
void Cocoa_Window::SetBackground (const Aspect_Background& theBackground)
{
SetBackground (theBackground.Color());
}
// =======================================================================
// function : SetBackground
// purpose :
// =======================================================================
void Cocoa_Window::SetBackground (const Quantity_NameOfColor theBackColor)
{
SetBackground (Quantity_Color (theBackColor));
}
// =======================================================================
// function : SetBackground
// purpose :
// =======================================================================
void Cocoa_Window::SetBackground (const Aspect_Handle theBackPixmap)
{
//
}
// =======================================================================
// function : SetBackground
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::SetBackground (const Standard_CString theFileName,
const Aspect_FillMethod theMethod)
{
return Standard_False;
}
// =======================================================================
// function : SetBackground
// purpose :
// =======================================================================
void Cocoa_Window::SetBackground (const Quantity_Color& theColor)
{
//
}
// =======================================================================
// function : SetBackground
// purpose :
// =======================================================================
void Cocoa_Window::SetBackground (const Aspect_GradientBackground& theGrBackground)
{
Quantity_Color aColor1, aColor2;
theGrBackground.Colors (aColor1, aColor2);
SetBackground (aColor1, aColor2, theGrBackground.BgGradientFillMethod());
}
// =======================================================================
// function : SetBackground
// purpose :
// =======================================================================
void Cocoa_Window::SetBackground (const Quantity_Color& theColor1,
const Quantity_Color& theColor2,
const Aspect_GradientFillMethod theMethod)
{
//
}
// =======================================================================
// function : SetDoubleBuffer
// purpose :
// =======================================================================
void Cocoa_Window::SetDoubleBuffer (const Standard_Boolean )
{
//
}
// =======================================================================
// function : Flush
// purpose :
// =======================================================================
void Cocoa_Window::Flush() const
{
Restore();
}
// =======================================================================
// function : IsMapped
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::IsMapped() const
{
if (IsVirtual())
{
return Standard_True;
}
return (myHView != NULL) && [[myHView window] isVisible];
}
// =======================================================================
// function : Map
// purpose :
// =======================================================================
void Cocoa_Window::Map() const
{
if (IsVirtual())
{
return;
}
if (myHView != NULL)
{
[[myHView window] orderFront: NULL];
}
}
// =======================================================================
// function : Unmap
// purpose :
// =======================================================================
void Cocoa_Window::Unmap() const
{
if (myHView != NULL)
{
[[myHView window] orderOut: NULL];
}
}
// =======================================================================
// function : DoResize
// purpose :
// =======================================================================
Aspect_TypeOfResize Cocoa_Window::DoResize() const
{
if (myHView == NULL)
{
return Aspect_TOR_UNKNOWN;
}
NSRect aBounds = [myHView bounds];
Standard_Integer aMask = 0;
Aspect_TypeOfResize aMode = Aspect_TOR_UNKNOWN;
if (Abs ((Standard_Integer )aBounds.origin.x - myXLeft ) > 2) aMask |= 1;
if (Abs ((Standard_Integer )(aBounds.origin.x + aBounds.size.width) - myXRight ) > 2) aMask |= 2;
if (Abs ((Standard_Integer )aBounds.origin.y - myYTop ) > 2) aMask |= 4;
if (Abs ((Standard_Integer )(aBounds.origin.y + aBounds.size.height) - myYBottom) > 2) aMask |= 8;
switch (aMask)
{
case 0: aMode = Aspect_TOR_NO_BORDER; break;
case 1: aMode = Aspect_TOR_LEFT_BORDER; break;
case 2: aMode = Aspect_TOR_RIGHT_BORDER; break;
case 4: aMode = Aspect_TOR_TOP_BORDER; break;
case 5: aMode = Aspect_TOR_LEFT_AND_TOP_BORDER; break;
case 6: aMode = Aspect_TOR_TOP_AND_RIGHT_BORDER; break;
case 8: aMode = Aspect_TOR_BOTTOM_BORDER; break;
case 9: aMode = Aspect_TOR_BOTTOM_AND_LEFT_BORDER; break;
case 10: aMode = Aspect_TOR_RIGHT_AND_BOTTOM_BORDER; break;
default: break;
}
*((Standard_Integer* )&myXLeft ) = (Standard_Integer )aBounds.origin.x;
*((Standard_Integer* )&myXRight ) = (Standard_Integer )(aBounds.origin.x + aBounds.size.width);
*((Standard_Integer* )&myYTop ) = (Standard_Integer )aBounds.origin.y;
*((Standard_Integer* )&myYBottom ) = (Standard_Integer )(aBounds.origin.y + aBounds.size.height);
return aMode;
}
// =======================================================================
// function : DoMapping
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::DoMapping() const
{
return Standard_True;
}
// =======================================================================
// function : Clear
// purpose :
// =======================================================================
void Cocoa_Window::Clear() const
{
//
}
// =======================================================================
// function : ClearArea
// purpose :
// =======================================================================
void Cocoa_Window::ClearArea (const Standard_Integer Xc,
const Standard_Integer Yc,
const Standard_Integer Width,
const Standard_Integer Height) const
{
//
}
// =======================================================================
// function : Restore
// purpose :
// =======================================================================
void Cocoa_Window::Restore() const
{
//
}
// =======================================================================
// function : RestoreArea
// purpose :
// =======================================================================
void Cocoa_Window::RestoreArea (const Standard_Integer Xc,
const Standard_Integer Yc,
const Standard_Integer Width,
const Standard_Integer Height) const
{
//
}
// =======================================================================
// function : Dump
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::Dump (const Standard_CString theFilename,
const Standard_Real theGammaValue) const
{
/*Image_AlienPixMap anImg;
if (!ToPixMap (anImg) || anImg.IsEmpty())
{
return Standard_False;
}
if (Abs (theGammaValue - 1.0) > 0.001)
{
anImg.AdjustGamma (theGammaValue);
}
return anImg.Save (theFilename);*/
return Standard_False;
}
// =======================================================================
// function : DumpArea
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::DumpArea (const Standard_CString theFilename,
const Standard_Integer theCenterX,
const Standard_Integer theCenterY,
const Standard_Integer theWidth,
const Standard_Integer theHeight,
const Standard_Real theGammaValue) const
{
return Standard_False;
}
// =======================================================================
// function : ToPixMap
// purpose :
// =======================================================================
/*Standard_Boolean Cocoa_Window::ToPixMap (Image_PixMap& thePixMap) const
{
return Standard_False;
}*/
// =======================================================================
// function : Load
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::Load (const Standard_CString theFilename) const
{
return Standard_False;
}
// =======================================================================
// function : LoadArea
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::LoadArea (const Standard_CString theFilename,
const Standard_Integer theCenterX,
const Standard_Integer theCenterY,
const Standard_Integer theWidth,
const Standard_Integer theHeight) const
{
return Standard_False;
}
// =======================================================================
// function : BackingStore
// purpose :
// =======================================================================
Standard_Boolean Cocoa_Window::BackingStore() const
{
return Standard_False;
}
// =======================================================================
// function : Ratio
// purpose :
// =======================================================================
Quantity_Ratio Cocoa_Window::Ratio() const
{
if (myHView == NULL)
{
return 1.0;
}
NSRect aBounds = [myHView bounds];
return Quantity_Ratio (aBounds.size.width / aBounds.size.height);
}
// =======================================================================
// function : Position
// purpose :
// =======================================================================
void Cocoa_Window::Position (Quantity_Parameter& X1, Quantity_Parameter& Y1,
Quantity_Parameter& X2, Quantity_Parameter& Y2) const
{
//
}
// =======================================================================
// function : Position
// purpose :
// =======================================================================
void Cocoa_Window::Position (Standard_Integer& X1, Standard_Integer& Y1,
Standard_Integer& X2, Standard_Integer& Y2) const
{
//
}
// =======================================================================
// function : Size
// purpose :
// =======================================================================
void Cocoa_Window::Size (Quantity_Parameter& theWidth,
Quantity_Parameter& theHeight) const
{
//
}
// =======================================================================
// function : Size
// purpose :
// =======================================================================
void Cocoa_Window::Size (Standard_Integer& theWidth,
Standard_Integer& theHeight) const
{
if (myHView == NULL)
{
return;
}
NSRect aBounds = [myHView bounds];
theWidth = (Standard_Integer )aBounds.size.width;
theHeight = (Standard_Integer )aBounds.size.height;
}
// =======================================================================
// function : MMSize
// purpose :
// =======================================================================
void Cocoa_Window::MMSize (Standard_Real& theWidth,
Standard_Real& theHeight) const
{
//
}
// =======================================================================
// function : Convert
// purpose :
// =======================================================================
Quantity_Parameter Cocoa_Window::Convert (const Standard_Integer PV) const
{
return 0.0; ///
}
// =======================================================================
// function : Convert
// purpose :
// =======================================================================
Standard_Integer Cocoa_Window::Convert (const Quantity_Parameter DV) const
{
return 0; ////
}
// =======================================================================
// function : Convert
// purpose :
// =======================================================================
void Cocoa_Window::Convert (const Standard_Integer PX,
const Standard_Integer PY,
Quantity_Parameter& DX,
Quantity_Parameter& DY) const
{
//
}
// =======================================================================
// function : Convert
// purpose :
// =======================================================================
void Cocoa_Window::Convert (const Quantity_Parameter DX,
const Quantity_Parameter DY,
Standard_Integer& PX,
Standard_Integer& PY) const
{
//
}

3
src/Cocoa/EXTERNLIB Executable file
View File

@ -0,0 +1,3 @@
CSF_objc
CSF_Appkit
CSF_IOKit

4
src/Cocoa/FILES Executable file
View File

@ -0,0 +1,4 @@
Cocoa_LocalPool.hxx
Cocoa_LocalPool.mm
Cocoa_Window.hxx
Cocoa_Window.mm

View File

@ -6,6 +6,7 @@ InterfaceGraphic_Portability.hxx
InterfaceGraphic_Visual3d.hxx InterfaceGraphic_Visual3d.hxx
InterfaceGraphic_WNT.hxx InterfaceGraphic_WNT.hxx
InterfaceGraphic_X11.hxx InterfaceGraphic_X11.hxx
InterfaceGraphic_Cocoa.hxx
InterfaceGraphic_XWD.hxx InterfaceGraphic_XWD.hxx
InterfaceGraphic_wntio.hxx InterfaceGraphic_wntio.hxx
InterfaceGraphic_cPrintf.cxx InterfaceGraphic_cPrintf.cxx

View File

@ -17,12 +17,14 @@
// and conditions governing the rights and limitations under the License. // and conditions governing the rights and limitations under the License.
#ifndef __INTERFACE_GRAPHIC_HXX #ifndef __INTERFACE_GRAPHIC_HXX
# define __INTERFACE_GRAPHIC_HXX #define __INTERFACE_GRAPHIC_HXX
#ifdef WNT #ifdef WNT
# include <InterfaceGraphic_WNT.hxx> #include <InterfaceGraphic_WNT.hxx>
#elif defined(__APPLE__)
#include <InterfaceGraphic_Cocoa.hxx>
#else #else
# include <InterfaceGraphic_X11.hxx> #include <InterfaceGraphic_X11.hxx>
#endif //WNT #endif
#endif /* __INTERFACE_GRAPHIC_HXX */ #endif // __INTERFACE_GRAPHIC_HXX

View File

@ -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 <stdio.h>
#define WINDOW void*
#define DISPLAY void*
#define GLCONTEXT void*
#define GLDRAWABLE void*
#define GET_GL_CONTEXT() NULL
#define GET_GLDEV_CONTEXT() NULL
#define GL_MAKE_CURRENT(a,b,c) {}
#ifndef EXPORT
#define EXPORT
#endif
#endif InterfaceGraphic_CocoaHeader
#endif // __APPLE__

View File

@ -2,6 +2,9 @@ CSF_user32
CSF_gdi32 CSF_gdi32
CSF_opengl32 CSF_opengl32
CSF_glu32 CSF_glu32
CSF_objc
CSF_Appkit
CSF_IOKit
CSF_OpenGlLibs CSF_OpenGlLibs
CSF_AviLibs CSF_AviLibs
CSF_FREETYPE CSF_FREETYPE

View File

@ -77,6 +77,7 @@ OpenGl_Display_2.cxx
Handle_OpenGl_Window.hxx Handle_OpenGl_Window.hxx
OpenGl_Window.hxx OpenGl_Window.hxx
OpenGl_Window.cxx OpenGl_Window.cxx
OpenGl_Window_1.mm
OpenGl_PriorityList.hxx OpenGl_PriorityList.hxx
OpenGl_PriorityList.cxx OpenGl_PriorityList.cxx
OpenGl_AVIWriter.hxx OpenGl_AVIWriter.hxx
@ -100,6 +101,7 @@ OpenGl_tgl_funcs.hxx
Handle_OpenGl_Context.hxx Handle_OpenGl_Context.hxx
OpenGl_Context.hxx OpenGl_Context.hxx
OpenGl_Context.cxx OpenGl_Context.cxx
OpenGl_Context_1.mm
OpenGl_ArbIns.hxx OpenGl_ArbIns.hxx
OpenGl_ArbTBO.hxx OpenGl_ArbTBO.hxx
OpenGl_ArbVBO.hxx OpenGl_ArbVBO.hxx

View File

@ -1,6 +1,6 @@
// Created on: 2012-01-26 // Created on: 2012-01-26
// Created by: Kirill GAVRILOV // 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 // 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 // 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 // purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License. // and conditions governing the rights and limitations under the License.
#if (defined(_WIN32) || defined(__WIN32__)) #if (defined(_WIN32) || defined(__WIN32__))
#include <windows.h> #include <windows.h>
#endif #endif
@ -166,6 +165,8 @@ void OpenGl_Context::Share (const Handle(OpenGl_Context)& theShareCtx)
} }
} }
#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
// ======================================================================= // =======================================================================
// function : IsCurrent // function : IsCurrent
// purpose : // purpose :
@ -265,6 +266,8 @@ void OpenGl_Context::SwapBuffers()
#endif #endif
} }
#endif // __APPLE__
// ======================================================================= // =======================================================================
// function : findProc // function : findProc
// purpose : // purpose :
@ -335,6 +338,8 @@ Standard_Boolean OpenGl_Context::CheckExtension (const char* theExtName) const
return Standard_False; return Standard_False;
} }
#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
// ======================================================================= // =======================================================================
// function : Init // function : Init
// purpose : // purpose :
@ -364,6 +369,8 @@ Standard_Boolean OpenGl_Context::Init()
return Standard_True; return Standard_True;
} }
#endif // __APPLE__
// ======================================================================= // =======================================================================
// function : Init // function : Init
// purpose : // purpose :
@ -372,6 +379,8 @@ Standard_Boolean OpenGl_Context::Init()
Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow, Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow,
const Aspect_Handle theWindowDC, const Aspect_Handle theWindowDC,
const Aspect_RenderingContext theGContext) const Aspect_RenderingContext theGContext)
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
Standard_Boolean OpenGl_Context::Init (const void* theGContext)
#else #else
Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow, Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow,
const Aspect_Display theDisplay, const Aspect_Display theDisplay,
@ -379,12 +388,15 @@ Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theWindow,
#endif #endif
{ {
Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!"); Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!");
#if (defined(_WIN32) || defined(__WIN32__))
myWindow = theWindow; myWindow = theWindow;
myGContext = theGContext; myGContext = theGContext;
#if (defined(_WIN32) || defined(__WIN32__))
myWindowDC = theWindowDC; myWindowDC = theWindowDC;
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
myGContext = (void* )theGContext;
#else #else
myWindow = theWindow;
myGContext = theGContext;
myDisplay = theDisplay; myDisplay = theDisplay;
#endif #endif
if (myGContext == NULL || !MakeCurrent()) if (myGContext == NULL || !MakeCurrent())

View File

@ -100,6 +100,8 @@ public:
Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow, Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow,
const Aspect_Handle theWindowDC, const Aspect_Handle theWindowDC,
const Aspect_RenderingContext theGContext); const Aspect_RenderingContext theGContext);
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
Standard_EXPORT Standard_Boolean Init (const void* theGContext);
#else #else
Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theWindow, Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theWindow,
const Aspect_Display theDisplay, const Aspect_Display theDisplay,
@ -253,6 +255,8 @@ private: // system-dependent fields
Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND
Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC
Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
void* myGContext; //!< Rendering Context handle : NSOpenGLContext
#else #else
Aspect_Drawable myWindow; //!< window handle (owner of GL context) : GLXDrawable Aspect_Drawable myWindow; //!< window handle (owner of GL context) : GLXDrawable
Aspect_Display myDisplay; //!< connection to the X-server : Display* Aspect_Display myDisplay; //!< connection to the X-server : Display*

View File

@ -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 <Cocoa/Cocoa.h>
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_Context.hxx>
#include <Standard_ProgramError.hxx>
// =======================================================================
// function : IsCurrent
// purpose :
// =======================================================================
Standard_Boolean OpenGl_Context::IsCurrent() const
{
return myGContext != NULL
&& [NSOpenGLContext currentContext] == (NSOpenGLContext* )myGContext;
}
// =======================================================================
// function : MakeCurrent
// purpose :
// =======================================================================
Standard_Boolean OpenGl_Context::MakeCurrent()
{
if (myGContext == NULL)
{
Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
return Standard_False;
}
[(NSOpenGLContext* )myGContext makeCurrentContext];
return Standard_True;
}
// =======================================================================
// function : SwapBuffers
// purpose :
// =======================================================================
void OpenGl_Context::SwapBuffers()
{
if (myGContext != NULL)
{
glFinish();
[(NSOpenGLContext* )myGContext flushBuffer];
}
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
Standard_Boolean OpenGl_Context::Init()
{
if (myIsInitialized)
{
return Standard_True;
}
myGContext = [NSOpenGLContext currentContext];
if (myGContext == NULL)
{
return Standard_False;
}
init();
myIsInitialized = Standard_True;
return Standard_True;
}
#endif // __APPLE__

View File

@ -28,7 +28,7 @@
#include <OpenGl_Light.hxx> #include <OpenGl_Light.hxx>
#if (!defined(_WIN32) && !defined(__WIN32__)) #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
#include <X11/Xlib.h> // XOpenDisplay() #include <X11/Xlib.h> // XOpenDisplay()
#endif #endif
@ -39,7 +39,7 @@ Handle(OpenGl_Display) openglDisplay;
namespace namespace
{ {
#if (defined(_WIN32) || defined(__WIN32__)) #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
static char* TheDummyDisplay = "DISPLAY"; static char* TheDummyDisplay = "DISPLAY";
#endif #endif
@ -65,7 +65,7 @@ OpenGl_Display::OpenGl_Display (const Standard_CString theDisplay)
myFont(-1), myFont(-1),
myFontSize(-1) myFontSize(-1)
{ {
#if (defined(_WIN32) || defined(__WIN32__)) #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
myDisplay = TheDummyDisplay; myDisplay = TheDummyDisplay;
#else #else
if (theDisplay != NULL && *theDisplay != '\0') if (theDisplay != NULL && *theDisplay != '\0')
@ -257,7 +257,7 @@ void OpenGl_Display::Init()
{ {
if (myDisplay != NULL) 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); XSynchronize ((Display* )myDisplay, (getenv("CALL_SYNCHRO_X") != NULL) ? 1 : 0);
if (getenv("CSF_GraphicSync") != NULL) if (getenv("CSF_GraphicSync") != NULL)
@ -276,7 +276,7 @@ void OpenGl_Display::Init()
else else
{ {
TCollection_AsciiString msg("OpenGl_Display::Init"); 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 += " : Cannot connect to X server ";
msg += XDisplayName ((char*) NULL); msg += XDisplayName ((char*) NULL);
#endif #endif

View File

@ -17,6 +17,7 @@
// purpose or non-infringement. Please see the License for the specific terms // purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License. // and conditions governing the rights and limitations under the License.
#include <OpenGl_GlCore11.hxx>
#include <InterfaceGraphic.hxx> #include <InterfaceGraphic.hxx>
#include <OpenGl_Display.hxx> #include <OpenGl_Display.hxx>
@ -41,6 +42,48 @@
* Prototypes variables statiques * 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))
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* /*
@ -112,25 +155,51 @@ void OpenGl_Display::getGL2PSFontName (const char *src_font, char *ps_font)
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
Standard_Integer OpenGl_Display::FindFont (Standard_CString theFontName, int OpenGl_Display::FindFont (const char* AFontName, const Font_FontAspect AFontAspect,
const Font_FontAspect theFontAspect, const int ABestSize, const float AXScale, const float AYScale)
const Standard_Integer theBestSize,
const Standard_ShortReal theXScale,
const Standard_ShortReal theYScale)
{ {
if (!theFontName) if (!AFontName)
return -1; return -1;
if (theBestSize != -1) if (ABestSize != -1)
myFontSize = theBestSize; myFontSize = ABestSize;
OpenGl_FontMgr* anOpenGlFontMgr = OpenGl_FontMgr::instance(); OpenGl_FontMgr* mgr = OpenGl_FontMgr::instance();
Handle(TCollection_HAsciiString) aFontName = new TCollection_HAsciiString (theFontName); Handle(TCollection_HAsciiString) family_name = new TCollection_HAsciiString(AFontName);
myFont = anOpenGlFontMgr->request_font (aFontName, theFontAspect, myFontSize); myFont = mgr->request_font( family_name, AFontAspect, myFontSize );
if (myFont != -1) if( myFont == -1 )
anOpenGlFontMgr->setCurrentScale (theXScale, theYScale); {
//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 );
}
// 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 );
}
// 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; return myFont;
} }

View File

@ -38,9 +38,6 @@
#define GLAPI extern #define GLAPI extern
#endif #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 // exclude modern definitions and system-provided glext.h, should be defined before gl.h inclusion
#define GL_GLEXT_LEGACY #define GL_GLEXT_LEGACY

View File

@ -17,7 +17,6 @@
// purpose or non-infringement. Please see the License for the specific terms // purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License. // and conditions governing the rights and limitations under the License.
#include <InterfaceGraphic.hxx> #include <InterfaceGraphic.hxx>
#include <OpenGl_Window.hxx> #include <OpenGl_Window.hxx>
@ -33,6 +32,8 @@
IMPLEMENT_STANDARD_HANDLE(OpenGl_Window,MMgt_TShared) IMPLEMENT_STANDARD_HANDLE(OpenGl_Window,MMgt_TShared)
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Window,MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Window,MMgt_TShared)
#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
namespace namespace
{ {
static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } }; 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
} }
#endif // !__APPLE__
// ======================================================================= // =======================================================================
// function : Activate // function : Activate
// purpose : // purpose :
@ -446,6 +449,8 @@ Standard_Boolean OpenGl_Window::Activate()
return myGlContext->MakeCurrent(); return myGlContext->MakeCurrent();
} }
#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
// ======================================================================= // =======================================================================
// function : Resize // function : Resize
// purpose : call_subr_resize // purpose : call_subr_resize
@ -471,6 +476,8 @@ void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow)
Init(); Init();
} }
#endif // !__APPLE__
// ======================================================================= // =======================================================================
// function : ReadDepths // function : ReadDepths
// purpose : TelReadDepths // purpose : TelReadDepths
@ -507,6 +514,8 @@ void OpenGl_Window::SetBackgroundColor (const Standard_ShortReal theR,
myBgColor.rgb[2] = theB; myBgColor.rgb[2] = theB;
} }
#if !defined(__APPLE__) || defined(MACOSX_USE_GLX)
// ======================================================================= // =======================================================================
// function : Init // function : Init
// purpose : // purpose :
@ -540,6 +549,8 @@ void OpenGl_Window::Init()
glDrawBuffer (GL_BACK); glDrawBuffer (GL_BACK);
} }
#endif // !__APPLE__
// ======================================================================= // =======================================================================
// function : EnablePolygonOffset // function : EnablePolygonOffset
// purpose : call_subr_enable_polygon_offset // purpose : call_subr_enable_polygon_offset

View File

@ -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 <Cocoa/Cocoa.h>
#include <InterfaceGraphic.hxx>
#include <OpenGl_Window.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_Display.hxx>
#include <Aspect_GraphicDeviceDefinitionError.hxx>
#include <Cocoa_LocalPool.hxx>
#include <TCollection_AsciiString.hxx>
namespace
{
static const TEL_COLOUR THE_DEFAULT_BG_COLOR = { { 0.F, 0.F, 0.F, 1.F } };
static const NSOpenGLPixelFormatAttribute THE_DOUBLE_BUFF[] = {
//NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute )32,
NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute )24,
NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute )8,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
0
};
};
// =======================================================================
// function : OpenGl_Window
// purpose :
// =======================================================================
OpenGl_Window::OpenGl_Window (const Handle(OpenGl_Display)& theDisplay,
const CALL_DEF_WINDOW& theCWindow,
Aspect_RenderingContext theGContext,
const Handle(OpenGl_Context)& theShareCtx)
: myDisplay (theDisplay),
myGlContext (new OpenGl_Context()),
myOwnGContext (theGContext == 0),
myWidth ((Standard_Integer )theCWindow.dx),
myHeight ((Standard_Integer )theCWindow.dy),
myBgColor (THE_DEFAULT_BG_COLOR),
myDither (theDisplay->Dither()),
myBackDither (theDisplay->BackDither())
{
myBgColor.rgb[0] = theCWindow.Background.r;
myBgColor.rgb[1] = theCWindow.Background.g;
myBgColor.rgb[2] = theCWindow.Background.b;
Cocoa_LocalPool aLocalPool;
//NSOpenGLContext* aGContext = (NSOpenGLContext* )theGContext;
// all GL context within one OpenGl_GraphicDriver should be shared!
NSOpenGLContext* aGLCtxShare = theShareCtx.IsNull() ? NULL : (NSOpenGLContext* )theShareCtx->myGContext;
NSOpenGLPixelFormat* aGLFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes: THE_DOUBLE_BUFF] autorelease];
NSOpenGLContext* aGLContext = [[NSOpenGLContext alloc] initWithFormat: aGLFormat
shareContext: aGLCtxShare];
if (aGLContext == NULL)
{
TCollection_AsciiString aMsg ("OpenGl_Window::CreateWindow: NSOpenGLContext creation failed");
Aspect_GraphicDeviceDefinitionError::Raise (aMsg.ToCString());
return;
}
NSView* aView = (NSView* )theCWindow.XWindow;
[aGLContext setView: aView];
myGlContext->Init (aGLContext);
myGlContext->Share (theShareCtx);
Init();
}
// =======================================================================
// function : ~OpenGl_Window
// purpose :
// =======================================================================
OpenGl_Window::~OpenGl_Window()
{
NSOpenGLContext* aGLCtx = (NSOpenGLContext* )myGlContext->myGContext;
myGlContext.Nullify();
[NSOpenGLContext clearCurrentContext];
if (myOwnGContext)
{
[aGLCtx clearDrawable];
[aGLCtx release];
}
}
// =======================================================================
// function : Resize
// purpose : call_subr_resize
// =======================================================================
void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow)
{
DISPLAY* aDisp = (DISPLAY* )myDisplay->GetDisplay();
if (aDisp == NULL)
{
return;
}
// If the size is not changed - do nothing
if ((myWidth == theCWindow.dx) && (myHeight == theCWindow.dy))
{
return;
}
myWidth = (Standard_Integer )theCWindow.dx;
myHeight = (Standard_Integer )theCWindow.dy;
Init();
}
// =======================================================================
// function : Init
// purpose :
// =======================================================================
void OpenGl_Window::Init()
{
if (!Activate())
{
return;
}
NSOpenGLContext* aGLCtx = (NSOpenGLContext* )myGlContext->myGContext;
NSRect aBounds = [[aGLCtx view] bounds];
// we should call this method each time when window is resized
[aGLCtx update];
myWidth = Standard_Integer(aBounds.size.width);
myHeight = Standard_Integer(aBounds.size.height);
glMatrixMode (GL_MODELVIEW);
glViewport (0, 0, myWidth, myHeight);
glDisable (GL_SCISSOR_TEST);
glDrawBuffer (GL_BACK);
}
#endif // __APPLE__

View File

@ -28,7 +28,7 @@
# include <config.h> # include <config.h>
#endif #endif
#ifdef HAVE_FREEIMAGE #if (defined(_WIN32) || defined(__WIN32__)) && defined(HAVE_FREEIMAGE)
#include <NCollection_Handle.hxx> #include <NCollection_Handle.hxx>
#include <FreeImagePlus.h> #include <FreeImagePlus.h>
#ifdef _MSC_VER #ifdef _MSC_VER

View File

@ -2,6 +2,9 @@ TKernel
TKService TKService
TKV3d TKV3d
CSF_OpenGlLibs CSF_OpenGlLibs
CSF_objc
CSF_Appkit
CSF_IOKit
CSF_FREETYPE CSF_FREETYPE
CSF_FTGL CSF_FTGL
CSF_GL2PS CSF_GL2PS

View File

@ -3,5 +3,8 @@ TKMath
CSF_XwLibs CSF_XwLibs
CSF_dpsLibs CSF_dpsLibs
CSF_XmuLibs CSF_XmuLibs
CSF_objc
CSF_Appkit
CSF_IOKit
CSF_FreeImagePlus CSF_FreeImagePlus
CSF_FREETYPE CSF_FREETYPE

View File

@ -11,5 +11,7 @@ Image
PlotMgt PlotMgt
ImageUtility ImageUtility
WNT WNT
Cocoa
TColQuantity TColQuantity
Font Font

View File

@ -25,3 +25,6 @@ CSF_TclTkLibs
CSF_user32 CSF_user32
CSF_gdi32 CSF_gdi32
CSF_OpenGlLibs CSF_OpenGlLibs
CSF_objc
CSF_Appkit
CSF_IOKit

3
src/ViewerTest/EXTERNLIB Executable file
View File

@ -0,0 +1,3 @@
CSF_objc
CSF_Appkit
CSF_IOKit

View File

@ -1,3 +1,4 @@
EXTERNLIB
ViewerTest_CMPLRS.edl ViewerTest_CMPLRS.edl
ViewerTest_AviCommands.cxx ViewerTest_AviCommands.cxx
ViewerTest_ViewerCommands.cxx ViewerTest_ViewerCommands.cxx
@ -6,3 +7,4 @@ ViewerTest_ObjectCommands.cxx
ViewerTest_FilletCommands.cxx ViewerTest_FilletCommands.cxx
ViewerTest_VoxelCommands.cxx ViewerTest_VoxelCommands.cxx
ViewerTest_OpenGlCommands.cxx ViewerTest_OpenGlCommands.cxx
ViewerTest_ViewerCommands_1.mm

View File

@ -61,28 +61,29 @@
#include <Visual3d_Layer.hxx> #include <Visual3d_Layer.hxx>
#include <cstdlib> #include <cstdlib>
#ifndef WNT #if defined(_WIN32) || defined(__WIN32__)
#include <Graphic3d_GraphicDevice.hxx> #include <Graphic3d_WNTGraphicDevice.hxx>
#include <Xw_GraphicDevice.hxx> #include <WNT_WClass.hxx>
#include <Xw_WindowQuality.hxx> #include <WNT_Window.hxx>
#include <Xw_Window.hxx>
#include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
#include <X11/Xutil.h>
#include <tk.h>
#if defined(_MSC_VER)
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
#include <Graphic3d_GraphicDevice.hxx>
#include <Cocoa_Window.hxx>
#include <tk.h>
#else #else
#include <Graphic3d_GraphicDevice.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx> #include <Xw_GraphicDevice.hxx>
#include <WNT_WClass.hxx> #include <Xw_WindowQuality.hxx>
#include <WNT_Window.hxx> #include <Xw_Window.hxx>
#include <X11/Xlib.h> /* contains some dangerous #defines such as Status, True etc. */
#define _CRT_SECURE_NO_DEPRECATE #include <X11/Xutil.h>
#pragma warning (disable:4996) #include <tk.h>
#endif #endif
#define OCC120
//============================================================================== //==============================================================================
//============================================================================== //==============================================================================
@ -94,7 +95,7 @@ Standard_IMPORT Standard_Boolean Draw_VirtualWindows;
Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv); Standard_EXPORT int ViewerMainLoop(Standard_Integer , const char** argv);
extern const Handle(NIS_InteractiveContext)& TheNISContext(); extern const Handle(NIS_InteractiveContext)& TheNISContext();
#ifdef WNT #if defined(_WIN32) || defined(__WIN32__)
static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){ static Handle(Graphic3d_WNTGraphicDevice)& GetG3dDevice(){
static Handle(Graphic3d_WNTGraphicDevice) GD; static Handle(Graphic3d_WNTGraphicDevice) GD;
return GD; return GD;
@ -104,7 +105,18 @@ static Handle(WNT_Window)& VT_GetWindow() {
static Handle(WNT_Window) WNTWin; static Handle(WNT_Window) WNTWin;
return 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 #else
static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){ static Handle(Graphic3d_GraphicDevice)& GetG3dDevice(){
static Handle(Graphic3d_GraphicDevice) GD; static Handle(Graphic3d_GraphicDevice) GD;
@ -119,9 +131,7 @@ static Display *display;
static void VProcessEvents(ClientData,int); static void VProcessEvents(ClientData,int);
#endif #endif
#ifdef OCC120
static Standard_Boolean DegenerateMode = Standard_True; static Standard_Boolean DegenerateMode = Standard_True;
#endif
#define ZCLIPWIDTH 1. #define ZCLIPWIDTH 1.
@ -133,9 +143,12 @@ static void OSWindowSetup();
static int Start_Rot = 0; static int Start_Rot = 0;
static int ZClipIsOn = 0; static int ZClipIsOn = 0;
static int X_Motion= 0,Y_Motion=0; // Current cursor position int X_Motion = 0; // Current cursor position
static int X_ButtonPress = 0, Y_ButtonPress = 0; // Last ButtonPress 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() const Handle(MMgt_TShared)& ViewerTest::WClass()
{ {
static Handle(MMgt_TShared) theWClass; static Handle(MMgt_TShared) theWClass;
#ifdef WNT #if defined(_WIN32) || defined(__WIN32__)
if (theWClass.IsNull()) { if (theWClass.IsNull())
{
theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc, theWClass = new WNT_WClass ("GW3D_Class", AdvViewerWindowProc,
CS_VREDRAW | CS_HREDRAW, 0, 0, CS_VREDRAW | CS_HREDRAW, 0, 0,
::LoadCursor (NULL, IDC_ARROW)); ::LoadCursor (NULL, IDC_ARROW));
@ -201,7 +215,7 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I
if (isFirst) if (isFirst)
{ {
// Create the Graphic device // Create the Graphic device
#ifdef WNT #if defined(_WIN32) || defined(__WIN32__)
if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice(); if (GetG3dDevice().IsNull()) GetG3dDevice() = new Graphic3d_WNTGraphicDevice();
if (VT_GetWindow().IsNull()) if (VT_GetWindow().IsNull())
{ {
@ -214,7 +228,18 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I
aPxLeft, aPxTop, aPxLeft, aPxTop,
aPxWidth, aPxHeight, aPxWidth, aPxHeight,
Quantity_NOC_BLACK); 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 #else
if (GetG3dDevice().IsNull()) GetG3dDevice() = if (GetG3dDevice().IsNull()) GetG3dDevice() =
@ -227,9 +252,9 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I
aPxWidth, aPxHeight, aPxWidth, aPxHeight,
Xw_WQ_3DQUALITY, Xw_WQ_3DQUALITY,
Quantity_NOC_BLACK); Quantity_NOC_BLACK);
VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
} }
#endif #endif
VT_GetWindow()->SetVirtual (Draw_VirtualWindows);
Handle(V3d_Viewer) a3DViewer, a3DCollector; Handle(V3d_Viewer) a3DViewer, a3DCollector;
// Viewer and View creation // Viewer and View creation
@ -266,9 +291,7 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I
Handle (V3d_View) V = ViewerTest::CurrentView(); Handle (V3d_View) V = ViewerTest::CurrentView();
V->SetDegenerateModeOn(); V->SetDegenerateModeOn();
#ifdef OCC120
DegenerateMode = V->DegenerateModeIsOn(); DegenerateMode = V->DegenerateModeIsOn();
#endif
// V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL); // V->SetWindow(VT_GetWindow(), NULL, MyViewProc, NULL);
V->SetZClippingDepth(0.5); V->SetZClippingDepth(0.5);
@ -276,19 +299,21 @@ void ViewerTest::ViewerInit (const Standard_Integer thePxLeft, const Standard_I
a3DViewer->SetDefaultLights(); a3DViewer->SetDefaultLights();
a3DViewer->SetLightOn(); a3DViewer->SetLightOn();
#ifndef WNT #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
#if TCL_MAJOR_VERSION < 8 #if TCL_MAJOR_VERSION < 8
Tk_CreateFileHandler((void*)ConnectionNumber(display), Tk_CreateFileHandler((void*)ConnectionNumber(display),
TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
#else #else
Tk_CreateFileHandler(ConnectionNumber(display), Tk_CreateFileHandler(ConnectionNumber(display),
TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() ); TK_READABLE, VProcessEvents, (ClientData) VT_GetWindow()->XWindow() );
#endif #endif
#endif #endif
isFirst = Standard_False; isFirst = Standard_False;
} }
VT_GetWindow()->Map(); 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 //purpose : Handle KeyPress event from a CString
//============================================================================== //==============================================================================
void VT_ProcessKeyPress (const char* buf_ret)
static void ProcessKeyPress( char *buf_ret )
{ {
//cout << "KeyPress" << endl; //cout << "KeyPress" << endl;
const Handle(V3d_View) aView = ViewerTest::CurrentView(); const Handle(V3d_View) aView = ViewerTest::CurrentView();
@ -337,20 +361,15 @@ static void ProcessKeyPress( char *buf_ret )
else if ( !strcasecmp(buf_ret, "H") ) { else if ( !strcasecmp(buf_ret, "H") ) {
// HLR // HLR
cout << "HLR" << endl; cout << "HLR" << endl;
#ifdef OCC120
if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff(); if (aView->DegenerateModeIsOn()) ViewerTest::CurrentView()->SetDegenerateModeOff();
else aView->SetDegenerateModeOn(); else aView->SetDegenerateModeOn();
DegenerateMode = aView->DegenerateModeIsOn(); DegenerateMode = aView->DegenerateModeIsOn();
#else
ViewerTest::CurrentView()->SetDegenerateModeOff();
#endif
} }
else if ( !strcasecmp(buf_ret, "S") ) { else if ( !strcasecmp(buf_ret, "S") ) {
// SHADING // SHADING
cout << "passage en mode 1 (shading pour les shapes)" << endl; cout << "passage en mode 1 (shading pour les shapes)" << endl;
#ifndef OCC120
ViewerTest::CurrentView()->SetDegenerateModeOn();
#endif
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 || if(Ctx->NbCurrents()==0 ||
Ctx->NbSelected()==0) Ctx->NbSelected()==0)
@ -370,9 +389,7 @@ static void ProcessKeyPress( char *buf_ret )
else if ( !strcasecmp(buf_ret, "U") ) { else if ( !strcasecmp(buf_ret, "U") ) {
// Unset display mode // Unset display mode
cout<<"passage au mode par defaut"<<endl; cout<<"passage au mode par defaut"<<endl;
#ifndef OCC120
ViewerTest::CurrentView()->SetDegenerateModeOn();
#endif
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 || if(Ctx->NbCurrents()==0 ||
Ctx->NbSelected()==0) Ctx->NbSelected()==0)
@ -409,13 +426,7 @@ static void ProcessKeyPress( char *buf_ret )
else if ( !strcasecmp(buf_ret, "W") ) { else if ( !strcasecmp(buf_ret, "W") ) {
// WIREFRAME // WIREFRAME
#ifndef OCC120
ViewerTest::CurrentView()->SetDegenerateModeOn();
#endif
cout << "passage en mode 0 (filaire pour les shapes)" << endl; cout << "passage en mode 0 (filaire pour les shapes)" << endl;
#ifndef OCC120
ViewerTest::CurrentView()->SetDegenerateModeOn();
#endif
Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
if(Ctx->NbCurrents()==0 || if(Ctx->NbCurrents()==0 ||
Ctx->NbSelected()==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 //purpose : Redraw the View on an Expose Event
//============================================================================== //==============================================================================
void VT_ProcessExpose()
static void ProcessExpose( ) {
{ //cout << "Expose" << endl; Handle(V3d_View) aView3d = ViewerTest::CurrentView();
ViewerTest::CurrentView()->Redraw(); if (!aView3d.IsNull())
{
aView3d->Redraw();
}
} }
//============================================================================== //==============================================================================
//function : ProcessConfigure //function : VT_ProcessConfigure
//purpose : Resize the View on an Configure Event //purpose : Resize the View on an Configure Event
//============================================================================== //==============================================================================
void VT_ProcessConfigure()
static void ProcessConfigure()
{ {
Handle(V3d_View) V = ViewerTest::CurrentView(); Handle(V3d_View) aView3d = ViewerTest::CurrentView();
V->MustBeResized(); if (aView3d.IsNull())
V->Update(); {
V->Redraw(); return;
}
aView3d->MustBeResized();
aView3d->Update();
aView3d->Redraw();
} }
//============================================================================== //==============================================================================
//function : ProcessButton1Press //function : VT_ProcessButton1Press
//purpose : Picking //purpose : Picking
//============================================================================== //==============================================================================
Standard_Boolean VT_ProcessButton1Press(
static Standard_Boolean ProcessButton1Press(
Standard_Integer , Standard_Integer ,
const char** argv, const char** argv,
Standard_Boolean pick, Standard_Boolean pick,
Standard_Boolean shift ) Standard_Boolean shift)
{ {
Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); Handle(ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager();
if ( pick ) { if ( pick ) {
@ -520,35 +537,50 @@ static Standard_Boolean ProcessButton1Press(
} }
//============================================================================== //==============================================================================
//function : ProcessButton3Press //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));
}
}
}
//==============================================================================
//function : VT_ProcessButton3Press
//purpose : Start Rotation //purpose : Start Rotation
//============================================================================== //==============================================================================
void VT_ProcessButton3Press()
static void ProcessButton3Press() {
{ // Start rotation
Start_Rot = 1; Start_Rot = 1;
ViewerTest::CurrentView()->SetDegenerateModeOn(); ViewerTest::CurrentView()->SetDegenerateModeOn();
ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress ); ViewerTest::CurrentView()->StartRotation( X_ButtonPress, Y_ButtonPress );
} }
//==============================================================================
//function : ProcessButtonRelease
//purpose : Start Rotation
//==============================================================================
static void ProcessButtonRelease() //==============================================================================
//function : VT_ProcessButton3Release
{ // End rotation //purpose : End rotation
#ifdef OCC120 //==============================================================================
if (Start_Rot) { void VT_ProcessButton3Release()
{
if (Start_Rot)
{
Start_Rot = 0; Start_Rot = 0;
if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff(); if (!DegenerateMode) ViewerTest::CurrentView()->SetDegenerateModeOff();
} }
#else
Start_Rot = 0;
ViewerTest::CurrentView()->SetDegenerateModeOff();
#endif
} }
//============================================================================== //==============================================================================
@ -605,11 +637,10 @@ static void ProcessControlButton1Motion()
} }
//============================================================================== //==============================================================================
//function : ProcessControlButton2Motion //function : VT_ProcessControlButton2Motion
//purpose : Pann //purpose : Panning
//============================================================================== //==============================================================================
void VT_ProcessControlButton2Motion()
static void ProcessControlButton2Motion()
{ {
Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress); Quantity_Length dx = ViewerTest::CurrentView()->Convert(X_Motion - X_ButtonPress);
Quantity_Length dy = ViewerTest::CurrentView()->Convert(Y_Motion - Y_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 //purpose : Rotation
//============================================================================== //==============================================================================
void VT_ProcessControlButton3Motion()
static void ProcessControlButton3Motion()
{ {
if ( Start_Rot ) ViewerTest::CurrentView()->Rotation( X_Motion, Y_Motion); if (Start_Rot)
{
ViewerTest::CurrentView()->Rotation (X_Motion, Y_Motion);
}
} }
//============================================================================== //==============================================================================
//function : ProcessPointerMotion //function : VT_ProcessMotion
//purpose : Rotation //purpose :
//============================================================================== //==============================================================================
void VT_ProcessMotion()
static void ProcessMotion()
{ {
//pre-hilights detected objects at mouse position //pre-hilights detected objects at mouse position
@ -790,14 +822,6 @@ static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
return 0; 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 #ifdef WNT
static Standard_Boolean Ppick = 0; static Standard_Boolean Ppick = 0;
@ -824,17 +848,17 @@ static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) ); HGDIOBJ anObj = SelectObject( hdc, GetStockObject( WHITE_PEN ) );
SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) ); SelectObject( hdc, GetStockObject( HOLLOW_BRUSH ) );
SetROP2( hdc, R2_NOT ); SetROP2( hdc, R2_NOT );
Rectangle( hdc, xx1, yy1, xx2, yy2 ); Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
ReleaseDC( hwnd, hdc ); ReleaseDC( hwnd, hdc );
const Handle(ViewerTest_EventManager) EM = const Handle(ViewerTest_EventManager) EM =
ViewerTest::CurrentEventManager(); ViewerTest::CurrentEventManager();
if ( fwKeys & MK_SHIFT ) if ( fwKeys & MK_SHIFT )
EM->ShiftSelect( min( xx1, xx2 ), max( yy1, yy2 ), EM->ShiftSelect( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
max( xx1, xx2 ), min( yy1, yy2 )); max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
else else
EM->Select( min( xx1, xx2 ), max( yy1, yy2 ), EM->Select( min( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
max( xx1, xx2 ), min( yy1, yy2 )); max( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ));
} }
return ViewerWindowProc( hwnd, Msg, wParam, lParam ); return ViewerWindowProc( hwnd, Msg, wParam, lParam );
@ -843,8 +867,8 @@ static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
{ {
IsDragged = Standard_True; IsDragged = Standard_True;
DragFirst = Standard_True; DragFirst = Standard_True;
xx1 = LOWORD(lParam); X_ButtonPress = LOWORD(lParam);
yy1 = HIWORD(lParam); Y_ButtonPress = HIWORD(lParam);
} }
return ViewerWindowProc( hwnd, Msg, wParam, lParam ); return ViewerWindowProc( hwnd, Msg, wParam, lParam );
@ -860,13 +884,13 @@ static LRESULT WINAPI AdvViewerWindowProc( HWND hwnd,
SetROP2( hdc, R2_NOT ); SetROP2( hdc, R2_NOT );
if( !DragFirst ) if( !DragFirst )
Rectangle( hdc, xx1, yy1, xx2, yy2 ); Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
DragFirst = Standard_False; DragFirst = Standard_False;
xx2 = LOWORD(lParam); X_Motion = LOWORD(lParam);
yy2 = HIWORD(lParam); Y_Motion = HIWORD(lParam);
Rectangle( hdc, xx1, yy1, xx2, yy2 ); Rectangle( hdc, X_ButtonPress, Y_ButtonPress, X_Motion, Y_Motion );
SelectObject( hdc, anObj ); SelectObject( hdc, anObj );
@ -905,41 +929,36 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
VT_GetWindow()->Unmap(); VT_GetWindow()->Unmap();
return 0; return 0;
case WM_PAINT: case WM_PAINT:
//cout << "\t WM_PAINT" << endl;
BeginPaint(hwnd, &ps); BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps); EndPaint(hwnd, &ps);
ProcessExpose(); VT_ProcessExpose();
break; break;
case WM_SIZE: case WM_SIZE:
//cout << "\t WM_SIZE" << endl; VT_ProcessConfigure();
ProcessConfigure();
break; break;
case WM_KEYDOWN: 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]; char c[2];
c[0] = (char) wParam; c[0] = (char) wParam;
c[1] = '\0'; c[1] = '\0';
ProcessKeyPress( c); VT_ProcessKeyPress (c);
} }
break; break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
case WM_MBUTTONUP: case WM_MBUTTONUP:
case WM_RBUTTONUP: case WM_RBUTTONUP:
//cout << "\t WM_xBUTTONUP" << endl;
Up = 1; Up = 1;
ProcessButtonRelease(); VT_ProcessButton3Release();
break; break;
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
{ {
//cout << "\t WM_xBUTTONDOWN" << endl;
WPARAM fwKeys = wParam; WPARAM fwKeys = wParam;
Up = 0; Up = 0;
@ -947,15 +966,21 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
X_ButtonPress = LOWORD(lParam); X_ButtonPress = LOWORD(lParam);
Y_ButtonPress = HIWORD(lParam); Y_ButtonPress = HIWORD(lParam);
if ( Msg == WM_LBUTTONDOWN) { if (Msg == WM_LBUTTONDOWN)
if(fwKeys & MK_CONTROL) { {
Ppick = ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) ); if (fwKeys & MK_CONTROL)
} else {
ProcessButton1Press( Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT) ); Ppick = VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
} }
else if ( Msg == WM_RBUTTONDOWN ) { else
{
VT_ProcessButton1Press (Pargc, Pargv, Ppick, (fwKeys & MK_SHIFT));
}
}
else if (Msg == WM_RBUTTONDOWN)
{
// Start rotation // Start rotation
ProcessButton3Press( ); VT_ProcessButton3Press();
} }
} }
break; break;
@ -975,7 +1000,7 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
if ( fwKeys & MK_RBUTTON ) { if ( fwKeys & MK_RBUTTON ) {
// Start rotation // Start rotation
ProcessButton3Press(); VT_ProcessButton3Press();
} }
} }
@ -986,10 +1011,10 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
else if ( fwKeys & MK_MBUTTON || else if ( fwKeys & MK_MBUTTON ||
((fwKeys&MK_LBUTTON) && ((fwKeys&MK_LBUTTON) &&
(fwKeys&MK_RBUTTON) ) ){ (fwKeys&MK_RBUTTON) ) ){
ProcessControlButton2Motion(); VT_ProcessControlButton2Motion();
} }
else if ( fwKeys & MK_RBUTTON ) { else if ( fwKeys & MK_RBUTTON ) {
ProcessControlButton3Motion(); VT_ProcessControlButton3Motion();
} }
} }
#ifdef BUG #ifdef BUG
@ -1003,11 +1028,14 @@ static LRESULT WINAPI ViewerWindowProc( HWND hwnd,
} }
#endif #endif
else else
if (( fwKeys & MK_MBUTTON || ((fwKeys&MK_LBUTTON) && (fwKeys&MK_RBUTTON) ) )){ if ((fwKeys & MK_MBUTTON
|| ((fwKeys & MK_LBUTTON) && (fwKeys & MK_RBUTTON))))
{
ProcessZClipMotion(); ProcessZClipMotion();
} }
else { else
ProcessMotion(); {
VT_ProcessMotion();
} }
} }
break; break;
@ -1051,7 +1079,7 @@ static int ViewerMainLoop(Standard_Integer argc, const char** argv)
//while ( Ppick == -1 ) { //while ( Ppick == -1 ) {
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) ) { if (GetMessage(&msg, NULL, 0, 0) ) {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
@ -1064,8 +1092,7 @@ static int ViewerMainLoop(Standard_Integer argc, const char** argv)
return Ppick; return Ppick;
} }
#elif !defined(__APPLE__) || defined(MACOSX_USE_GLX)
#else
int min( int a, int b ) int min( int a, int b )
{ {
@ -1098,12 +1125,12 @@ XNextEvent( display, &report );
switch ( report.type ) { switch ( report.type ) {
case Expose: case Expose:
{ {
ProcessExpose(); VT_ProcessExpose();
} }
break; break;
case ConfigureNotify: case ConfigureNotify:
{ {
ProcessConfigure(); VT_ProcessConfigure();
} }
break; break;
case KeyPress: case KeyPress:
@ -1121,8 +1148,9 @@ switch ( report.type ) {
buf_ret[ret_len] = '\0' ; buf_ret[ret_len] = '\0' ;
if ( ret_len ) { if (ret_len)
ProcessKeyPress( buf_ret); {
VT_ProcessKeyPress (buf_ret);
} }
} }
break; break;
@ -1132,20 +1160,25 @@ switch ( report.type ) {
X_ButtonPress = report.xbutton.x; X_ButtonPress = report.xbutton.x;
Y_ButtonPress = report.xbutton.y; Y_ButtonPress = report.xbutton.y;
if ( report.xbutton.button == Button1 ) if (report.xbutton.button == Button1)
if( report.xbutton.state & ControlMask ) {
pick = ProcessButton1Press( argc, argv, pick, if (report.xbutton.state & ControlMask)
( report.xbutton.state & ShiftMask) ); {
pick = VT_ProcessButton1Press (argc, argv, pick, (report.xbutton.state & ShiftMask));
}
else else
{ {
IsDragged = Standard_True; IsDragged = Standard_True;
xx1 = X_ButtonPress; X_ButtonPress = X_ButtonPress;
yy1 = Y_ButtonPress; Y_ButtonPress = Y_ButtonPress;
DragFirst = Standard_True; DragFirst = Standard_True;
} }
else if ( report.xbutton.button == Button3 ) }
else if (report.xbutton.button == Button3)
{
// Start rotation // Start rotation
ProcessButton3Press(); VT_ProcessButton3Press();
}
} }
break; break;
case ButtonRelease: case ButtonRelease:
@ -1161,7 +1194,7 @@ switch ( report.type ) {
Aspect_Handle aWindow = VT_GetWindow()->XWindow(); Aspect_Handle aWindow = VT_GetWindow()->XWindow();
GC gc = XCreateGC( display, aWindow, 0, 0 ); GC gc = XCreateGC( display, aWindow, 0, 0 );
// XSetFunction( display, gc, GXinvert ); // 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(); Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
@ -1187,25 +1220,25 @@ switch ( report.type ) {
else else
if( ShiftPressed ) if( ShiftPressed )
{ {
aContext->ShiftSelect( min( xx1, xx2 ), min( yy1, yy2 ), aContext->ShiftSelect( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
max( xx1, xx2 ), max( yy1, yy2 ), max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
ViewerTest::CurrentView()); ViewerTest::CurrentView());
// cout << "shift select" << endl; // cout << "shift select" << endl;
} }
else else
{ {
aContext->Select( min( xx1, xx2 ), min( yy1, yy2 ), aContext->Select( min( X_ButtonPress, X_Motion ), min( Y_ButtonPress, Y_Motion ),
max( xx1, xx2 ), max( yy1, yy2 ), max( X_ButtonPress, X_Motion ), max( Y_ButtonPress, Y_Motion ),
ViewerTest::CurrentView() ); ViewerTest::CurrentView() );
// cout << "select" << endl; // cout << "select" << endl;
} }
else else
ProcessButtonRelease(); VT_ProcessButton3Release();
IsDragged = Standard_False; IsDragged = Standard_False;
} }
else else
ProcessButtonRelease(); VT_ProcessButton3Release();
} }
break; break;
case MotionNotify: case MotionNotify:
@ -1222,14 +1255,14 @@ switch ( report.type ) {
XSetFunction( display, gc, GXinvert ); XSetFunction( display, gc, GXinvert );
if( !DragFirst ) 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; X_Motion = X_Motion;
yy2 = Y_Motion; Y_Motion = Y_Motion;
DragFirst = Standard_False; DragFirst = Standard_False;
//cout << "draw rect : " << xx2 << ", " << yy2 << endl; //cout << "draw rect : " << X_Motion << ", " << Y_Motion << endl;
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 ) );
} }
else else
{ {
@ -1273,14 +1306,15 @@ switch ( report.type ) {
ProcessControlButton1Motion(); ProcessControlButton1Motion();
} }
else if ( report.xmotion.state & Button2Mask ) { else if ( report.xmotion.state & Button2Mask ) {
ProcessControlButton2Motion(); VT_ProcessControlButton2Motion();
} }
else if ( report.xmotion.state & Button3Mask ) { else if ( report.xmotion.state & Button3Mask ) {
ProcessControlButton3Motion(); VT_ProcessControlButton3Motion();
} }
} }
else { else
ProcessMotion(); {
VT_ProcessMotion();
} }
} }
} }
@ -1316,7 +1350,7 @@ static void VProcessEvents(ClientData,int)
static void OSWindowSetup() static void OSWindowSetup()
{ {
#ifndef WNT #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
// X11 // X11
Window window = VT_GetWindow()->XWindow(); Window window = VT_GetWindow()->XWindow();
@ -1424,8 +1458,6 @@ while (ViewerMainLoop( argc, argv)) {
return 0; return 0;
} }
//============================================================================== //==============================================================================
//function : InitViewerTest //function : InitViewerTest
//purpose : initialisation de toutes les variables static de ViewerTest (dp) //purpose : initialisation de toutes les variables static de ViewerTest (dp)
@ -1441,7 +1473,7 @@ void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
ViewerTest::ResetEventManager(); ViewerTest::ResetEventManager();
Handle(Aspect_GraphicDevice) device = viewer->Device(); Handle(Aspect_GraphicDevice) device = viewer->Device();
Handle(Aspect_Window) window = view->Window(); Handle(Aspect_Window) window = view->Window();
#ifndef WNT #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
// X11 // X11
VT_GetWindow() = Handle(Xw_Window)::DownCast(window); VT_GetWindow() = Handle(Xw_Window)::DownCast(window);
GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device); GetG3dDevice() = Handle(Graphic3d_GraphicDevice)::DownCast(device);
@ -1460,7 +1492,6 @@ void ViewerTest_InitViewerTest (const Handle(AIS_InteractiveContext)& context)
#endif #endif
} }
//============================================================================== //==============================================================================
//function : VSetBg //function : VSetBg
//purpose : Load image as background //purpose : Load image as background

View File

@ -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 <Cocoa/Cocoa.h>
#include <Cocoa_Window.hxx>
#include <ViewerTest.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <AIS_InteractiveContext.hxx>
#include <NIS_View.hxx>
//! Custom Cocoa view to handle events
@interface ViewerTest_CocoaEventManagerView : NSView
@end
extern void VT_ProcessExpose();
extern void VT_ProcessConfigure();
extern void VT_ProcessKeyPress (const char* theBuffer);
extern void VT_ProcessMotion();
extern void VT_ProcessButton3Press();
extern void VT_ProcessButton3Release();
extern void VT_ProcessControlButton2Motion();
extern void VT_ProcessControlButton3Motion();
extern Standard_Boolean VT_ProcessButton1Press (Standard_Integer theArgsNb,
const char** theArgsVec,
Standard_Boolean theToPick,
Standard_Boolean theIsShift);
extern void VT_ProcessButton1Release(Standard_Boolean theIsShift);
extern int X_Motion; // Current cursor position
extern int Y_Motion;
extern int X_ButtonPress; // Last ButtonPress position
extern int Y_ButtonPress;
extern Standard_Boolean IsDragged;
// =======================================================================
// function : ViewerMainLoop
// purpose :
// =======================================================================
int ViewerMainLoop (Standard_Integer, const char** )
{
// unused
return 0;
}
// =======================================================================
// function : ViewerTest_SetCocoaEventManagerView
// purpose :
// =======================================================================
void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow)
{
if (theWindow.IsNull())
{
return;
}
NSWindow* aWin = [theWindow->HView() window];
NSRect aBounds = [[aWin contentView] bounds];
ViewerTest_CocoaEventManagerView* aView = [[ViewerTest_CocoaEventManagerView alloc] initWithFrame: aBounds];
// replace content view in the window
theWindow->SetHView (aView);
// make view as first responder in winow to capture all useful events
[aWin makeFirstResponder: aView];
[aWin setAcceptsMouseMovedEvents: YES];
// should be retained by parent NSWindow
[aView release];
}
// =======================================================================
// function : getMouseCoords
// purpose : Retrieve cursor position
// =======================================================================
static void getMouseCoords (NSView* theView,
NSEvent* theEvent,
Standard_Integer& theX,
Standard_Integer& theY)
{
NSPoint aMouseLoc = [theView convertPoint: [theEvent locationInWindow] fromView: nil];
NSRect aBounds = [theView bounds];
theX = Standard_Integer(aMouseLoc.x);
theY = Standard_Integer(aBounds.size.height - aMouseLoc.y);
}
@implementation ViewerTest_CocoaEventManagerView
// =======================================================================
// function : setFrameSize
// purpose :
// =======================================================================
- (void )setFrameSize: (NSSize )theNewSize
{
[super setFrameSize: theNewSize];
VT_ProcessConfigure();
}
// =======================================================================
// function : drawRect
// purpose :
// =======================================================================
- (void )drawRect: (NSRect )theDirtyRect
{
VT_ProcessExpose();
}
// =======================================================================
// function : mouseMoved
// purpose :
// =======================================================================
- (void )mouseMoved: (NSEvent* )theEvent
{
getMouseCoords (self, theEvent, X_Motion, Y_Motion);
VT_ProcessMotion();
}
// =======================================================================
// function : acceptsFirstResponder
// purpose :
// =======================================================================
- (BOOL )acceptsFirstResponder
{
return YES;
}
// =======================================================================
// function : mouseDown
// purpose :
// =======================================================================
- (void )mouseDown: (NSEvent* )theEvent
{
getMouseCoords (self, theEvent, X_ButtonPress, Y_ButtonPress);
VT_ProcessButton1Press (0, NULL, Standard_False, [theEvent modifierFlags] & NSShiftKeyMask);
}
// =======================================================================
// function : mouseUp
// purpose :
// =======================================================================
- (void )mouseUp: (NSEvent* )theEvent
{
getMouseCoords (self, theEvent, X_Motion, Y_Motion);
VT_ProcessButton1Release([theEvent modifierFlags] & NSShiftKeyMask);
}
// =======================================================================
// function : mouseDragged
// purpose :
// =======================================================================
- (void )mouseDragged: (NSEvent* )theEvent
{
IsDragged = Standard_True;
if ([theEvent modifierFlags] & NSControlKeyMask)
{
getMouseCoords (self, theEvent, X_Motion, Y_Motion);
VT_ProcessControlButton2Motion();
}
}
// =======================================================================
// function : rightMouseDown
// purpose :
// =======================================================================
- (void )rightMouseDown: (NSEvent* )theEvent
{
getMouseCoords (self, theEvent, X_ButtonPress, Y_ButtonPress);
VT_ProcessButton3Press(); // Start rotation
}
// =======================================================================
// function : rightMouseUp
// purpose :
// =======================================================================
- (void )rightMouseUp: (NSEvent* )theEvent
{
VT_ProcessButton3Release();
}
// =======================================================================
// function : rightMouseDragged
// purpose :
// =======================================================================
- (void )rightMouseDragged: (NSEvent* )theEvent
{
if ([theEvent modifierFlags] & NSControlKeyMask)
{
getMouseCoords (self, theEvent, X_Motion, Y_Motion);
VT_ProcessControlButton3Motion();
}
}
// =======================================================================
// function : scrollWheel
// purpose :
// =======================================================================
- (void )scrollWheel: (NSEvent* )theEvent
{
float aDelta = [theEvent deltaY];
if (Abs (aDelta) < 0.001)
{
// a lot of values near zero can be generated by touchpad
return;
}
ViewerTest::CurrentView()->Zoom (0, 0, aDelta, aDelta);
}
// =======================================================================
// function : keyDown
// purpose :
// =======================================================================
- (void )keyDown: (NSEvent* )theEvent
{
NSString* aStringNs = [theEvent characters];
if (aStringNs == NULL || [aStringNs length] == 0)
{
return;
}
const Standard_CString aString = [aStringNs UTF8String];
VT_ProcessKeyPress (aString);
}
@end
#endif

View File

@ -165,11 +165,13 @@
#include <TColStd_HArray2OfReal.hxx> #include <TColStd_HArray2OfReal.hxx>
#ifndef WNT #if (defined(_WIN32) || defined(__WIN32__))
# include <Xw_Window.hxx> #include <WNT_Window.hxx>
#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
#include <Cocoa_Window.hxx>
#else #else
# include <WNT_Window.hxx> #include <Xw_Window.hxx>
#endif // WNT #endif
#include <float.h> #include <float.h>
@ -458,36 +460,38 @@ void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow,
} }
// RIC120302 // RIC120302
void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow) { void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
{
if (IsDeleted ()) return; if (IsDeleted ()) return;
if (IsDefined ()) if (IsDefined ())
Visual3d_ViewDefinitionError::Raise ("Window already defined"); Visual3d_ViewDefinitionError::Raise ("Window already defined");
MyWindow = AWindow; MyWindow = theWindow;
MyCView.WsId = MyCView.ViewId; MyCView.WsId = MyCView.ViewId;
MyCView.DefWindow.IsDefined = 1; MyCView.DefWindow.IsDefined = 1;
#ifndef WNT
const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AWindow; #if (defined(_WIN32) || defined(__WIN32__))
MyCView.DefWindow.XWindow = theWindow->XWindow (); const Handle(WNT_Window) aWin = Handle(WNT_Window)::DownCast (theWindow);
#ifdef RIC120302 MyCView.DefWindow.XWindow = (HWND )(aWin->HWindow());
MyCView.DefWindow.XParentWindow = theWindow->XParentWindow (); MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow());
#endif 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 #else
WNT_WindowData* wd; const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow);
const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AWindow; MyCView.DefWindow.XWindow = aWin->XWindow();
MyCView.DefWindow.XWindow = ( HWND )(theWindow->HWindow()); MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
#ifdef RIC120302
MyCView.DefWindow.XParentWindow = ( HWND )(theWindow->HParentWindow());
#endif #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; Standard_Integer Width, Height;
AWindow->Size (Width, Height); theWindow->Size (Width, Height);
MyCView.DefWindow.dx = float( Width ); MyCView.DefWindow.dx = float( Width );
MyCView.DefWindow.dy = float( Height ); MyCView.DefWindow.dy = float( Height );