From a13f2dc486c70146dab53b435805d8939e5c0743 Mon Sep 17 00:00:00 2001 From: kgv Date: Thu, 16 Jun 2016 14:06:53 +0300 Subject: [PATCH] 0027566: Configuration - define Handle_ as non-template class for compatibility with C++/CLI For MSVC compiler (version 12 and above), Handle_Class types are defined as true classes (inheriting corresponding opencascade::handle) to allow using them in "public" statement of C++/CLI language, to make these classes recognizable by other C++/CLI libraries. Code to test operations with Handle_ class is added to QAHandleOps test command --- src/AIS/AIS_TexturedShape.hxx | 2 +- src/Graphic3d/Graphic3d_AspectMarker3d.hxx | 4 +- src/Graphic3d/Graphic3d_Texture1D.hxx | 4 +- src/Graphic3d/Graphic3d_Texture1Dmanual.hxx | 3 +- src/Graphic3d/Graphic3d_Texture1Dsegment.hxx | 3 +- src/Graphic3d/Graphic3d_Texture2D.hxx | 4 +- src/Graphic3d/Graphic3d_Texture2Dmanual.hxx | 3 +- src/Graphic3d/Graphic3d_Texture2Dplane.hxx | 3 +- src/Graphic3d/Graphic3d_TextureEnv.hxx | 3 +- src/Graphic3d/Graphic3d_TextureMap.hxx | 3 +- src/Graphic3d/Graphic3d_TextureRoot.hxx | 11 ++-- src/Image/FILES | 1 - src/Image/Image_PixMap.hxx | 3 +- src/Image/Image_PixMap_Handle.hxx | 24 -------- src/QANCollection/QANCollection_Handle.cxx | 55 ++++++++++++++++--- src/Standard/Standard_Handle.hxx | 19 ++++++- ...olAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx | 3 +- 17 files changed, 86 insertions(+), 62 deletions(-) delete mode 100644 src/Image/Image_PixMap_Handle.hxx diff --git a/src/AIS/AIS_TexturedShape.hxx b/src/AIS/AIS_TexturedShape.hxx index 5f82dfea69..65b1502ae1 100644 --- a/src/AIS/AIS_TexturedShape.hxx +++ b/src/AIS/AIS_TexturedShape.hxx @@ -63,7 +63,7 @@ public: //! @name main methods //! Sets the texture source. specifies image data. //! Please note that the data should be in Bottom-Up order, the flag of Image_PixMap::IsTopDown() will be ignored by graphic driver. //! Setting texture source using this method resets the source by filename (if was set previously). - Standard_EXPORT virtual void SetTexturePixMap (const Image_PixMap_Handle& theTexturePixMap); + Standard_EXPORT virtual void SetTexturePixMap (const Handle(Image_PixMap)& theTexturePixMap); //! @return flag to control texture mapping (for presentation mode 3) Standard_Boolean TextureMapState() const { return myToMapTexture; } diff --git a/src/Graphic3d/Graphic3d_AspectMarker3d.hxx b/src/Graphic3d/Graphic3d_AspectMarker3d.hxx index a28eca10b8..5945001a89 100644 --- a/src/Graphic3d/Graphic3d_AspectMarker3d.hxx +++ b/src/Graphic3d/Graphic3d_AspectMarker3d.hxx @@ -26,7 +26,7 @@ #include #include #include -#include +#include class Quantity_Color; @@ -58,7 +58,7 @@ public: //! Creates a context table for marker primitives //! defined with the specified values. - Standard_EXPORT Graphic3d_AspectMarker3d(const Image_PixMap_Handle& theTextureImage); + Standard_EXPORT Graphic3d_AspectMarker3d(const Handle(Image_PixMap)& theTextureImage); //! Returns marker's texture size. Standard_EXPORT void GetTextureSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const; diff --git a/src/Graphic3d/Graphic3d_Texture1D.hxx b/src/Graphic3d/Graphic3d_Texture1D.hxx index cf65ca67ba..344be9384c 100644 --- a/src/Graphic3d/Graphic3d_Texture1D.hxx +++ b/src/Graphic3d/Graphic3d_Texture1D.hxx @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include class Standard_OutOfRange; class TCollection_AsciiString; @@ -64,7 +64,7 @@ protected: Standard_EXPORT Graphic3d_Texture1D(const Graphic3d_NameOfTexture1D theName, const Graphic3d_TypeOfTexture theType); - Standard_EXPORT Graphic3d_Texture1D(const Image_PixMap_Handle& thePixMap, const Graphic3d_TypeOfTexture theType); + Standard_EXPORT Graphic3d_Texture1D(const Handle(Image_PixMap)& thePixMap, const Graphic3d_TypeOfTexture theType); diff --git a/src/Graphic3d/Graphic3d_Texture1Dmanual.hxx b/src/Graphic3d/Graphic3d_Texture1Dmanual.hxx index a13c8f5655..dacc01948e 100644 --- a/src/Graphic3d/Graphic3d_Texture1Dmanual.hxx +++ b/src/Graphic3d/Graphic3d_Texture1Dmanual.hxx @@ -22,7 +22,6 @@ #include #include -#include class TCollection_AsciiString; @@ -44,7 +43,7 @@ public: Standard_EXPORT Graphic3d_Texture1Dmanual(const Graphic3d_NameOfTexture1D theNOT); //! Creates a texture from the pixmap. - Standard_EXPORT Graphic3d_Texture1Dmanual(const Image_PixMap_Handle& thePixMap); + Standard_EXPORT Graphic3d_Texture1Dmanual(const Handle(Image_PixMap)& thePixMap); diff --git a/src/Graphic3d/Graphic3d_Texture1Dsegment.hxx b/src/Graphic3d/Graphic3d_Texture1Dsegment.hxx index 274f3902c6..02dc8db815 100644 --- a/src/Graphic3d/Graphic3d_Texture1Dsegment.hxx +++ b/src/Graphic3d/Graphic3d_Texture1Dsegment.hxx @@ -23,7 +23,6 @@ #include #include #include -#include class TCollection_AsciiString; @@ -47,7 +46,7 @@ public: Standard_EXPORT Graphic3d_Texture1Dsegment(const Graphic3d_NameOfTexture1D theNOT); //! Creates a texture from the pixmap. - Standard_EXPORT Graphic3d_Texture1Dsegment(const Image_PixMap_Handle& thePixMap); + Standard_EXPORT Graphic3d_Texture1Dsegment(const Handle(Image_PixMap)& thePixMap); //! Sets the texture application bounds. Defines the way //! the texture is stretched across facets. diff --git a/src/Graphic3d/Graphic3d_Texture2D.hxx b/src/Graphic3d/Graphic3d_Texture2D.hxx index 773dcd9e7c..bf8f990de6 100644 --- a/src/Graphic3d/Graphic3d_Texture2D.hxx +++ b/src/Graphic3d/Graphic3d_Texture2D.hxx @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include class Standard_OutOfRange; class TCollection_AsciiString; @@ -64,7 +64,7 @@ protected: Standard_EXPORT Graphic3d_Texture2D(const Graphic3d_NameOfTexture2D theName, const Graphic3d_TypeOfTexture theType); - Standard_EXPORT Graphic3d_Texture2D(const Image_PixMap_Handle& thePixMap, const Graphic3d_TypeOfTexture theType); + Standard_EXPORT Graphic3d_Texture2D(const Handle(Image_PixMap)& thePixMap, const Graphic3d_TypeOfTexture theType); diff --git a/src/Graphic3d/Graphic3d_Texture2Dmanual.hxx b/src/Graphic3d/Graphic3d_Texture2Dmanual.hxx index a7917e842f..d3a82c1610 100644 --- a/src/Graphic3d/Graphic3d_Texture2Dmanual.hxx +++ b/src/Graphic3d/Graphic3d_Texture2Dmanual.hxx @@ -22,7 +22,6 @@ #include #include -#include class TCollection_AsciiString; @@ -45,7 +44,7 @@ public: Standard_EXPORT Graphic3d_Texture2Dmanual(const Graphic3d_NameOfTexture2D theNOT); //! Creates a texture from the pixmap. - Standard_EXPORT Graphic3d_Texture2Dmanual(const Image_PixMap_Handle& thePixMap); + Standard_EXPORT Graphic3d_Texture2Dmanual(const Handle(Image_PixMap)& thePixMap); diff --git a/src/Graphic3d/Graphic3d_Texture2Dplane.hxx b/src/Graphic3d/Graphic3d_Texture2Dplane.hxx index aec405fa60..bef96ac7a3 100644 --- a/src/Graphic3d/Graphic3d_Texture2Dplane.hxx +++ b/src/Graphic3d/Graphic3d_Texture2Dplane.hxx @@ -23,7 +23,6 @@ #include #include #include -#include #include class TCollection_AsciiString; @@ -46,7 +45,7 @@ public: Standard_EXPORT Graphic3d_Texture2Dplane(const Graphic3d_NameOfTexture2D theNOT); //! Creates a texture from the pixmap. - Standard_EXPORT Graphic3d_Texture2Dplane(const Image_PixMap_Handle& thePixMap); + Standard_EXPORT Graphic3d_Texture2Dplane(const Handle(Image_PixMap)& thePixMap); //! Defines the texture projection plane for texture coordinate S //! default is <1.0, 0.0, 0.0, 0.0> diff --git a/src/Graphic3d/Graphic3d_TextureEnv.hxx b/src/Graphic3d/Graphic3d_TextureEnv.hxx index 76ef1f0825..bd8f902ecd 100644 --- a/src/Graphic3d/Graphic3d_TextureEnv.hxx +++ b/src/Graphic3d/Graphic3d_TextureEnv.hxx @@ -22,7 +22,6 @@ #include #include -#include #include class Standard_OutOfRange; class TCollection_AsciiString; @@ -45,7 +44,7 @@ public: Standard_EXPORT Graphic3d_TextureEnv(const Graphic3d_NameOfTextureEnv theName); //! Creates an environment texture from the pixmap. - Standard_EXPORT Graphic3d_TextureEnv(const Image_PixMap_Handle& thePixMap); + Standard_EXPORT Graphic3d_TextureEnv(const Handle(Image_PixMap)& thePixMap); //! Returns the name of the predefined textures or NOT_ENV_UNKNOWN diff --git a/src/Graphic3d/Graphic3d_TextureMap.hxx b/src/Graphic3d/Graphic3d_TextureMap.hxx index b394f77300..10eeb403fe 100644 --- a/src/Graphic3d/Graphic3d_TextureMap.hxx +++ b/src/Graphic3d/Graphic3d_TextureMap.hxx @@ -22,7 +22,6 @@ #include #include -#include #include #include class TCollection_AsciiString; @@ -95,7 +94,7 @@ protected: Standard_EXPORT Graphic3d_TextureMap(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType); - Standard_EXPORT Graphic3d_TextureMap(const Image_PixMap_Handle& thePixMap, const Graphic3d_TypeOfTexture theType); + Standard_EXPORT Graphic3d_TextureMap(const Handle(Image_PixMap)& thePixMap, const Graphic3d_TypeOfTexture theType); diff --git a/src/Graphic3d/Graphic3d_TextureRoot.hxx b/src/Graphic3d/Graphic3d_TextureRoot.hxx index 1d62390549..c4e63e756a 100644 --- a/src/Graphic3d/Graphic3d_TextureRoot.hxx +++ b/src/Graphic3d/Graphic3d_TextureRoot.hxx @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include @@ -75,7 +75,6 @@ public: //! //! @return texture identifier. Standard_EXPORT const TCollection_AsciiString& GetId() const; - //! This method will be called by graphic driver each time when texture resource should be created. //! Default constructors allow defining the texture source as path to texture image or directly as pixmap. @@ -84,8 +83,8 @@ public: //! Inheritors may dynamically generate the image. //! Notice, image data should be in Bottom-Up order (see Image_PixMap::IsTopDown())! //! @return the image for texture. - Standard_EXPORT virtual Image_PixMap_Handle GetImage() const; - + Standard_EXPORT virtual Handle(Image_PixMap) GetImage() const; + //! @return low-level texture parameters Standard_EXPORT const Handle(Graphic3d_TextureParams)& GetParams() const; @@ -109,11 +108,11 @@ protected: //! Creates a texture from pixmap. //! Please note that the implementation expects the image data //! to be in Bottom-Up order (see Image_PixMap::IsTopDown()). - Standard_EXPORT Graphic3d_TextureRoot(const Image_PixMap_Handle& thePixmap, const Graphic3d_TypeOfTexture theType); + Standard_EXPORT Graphic3d_TextureRoot(const Handle(Image_PixMap)& thePixmap, const Graphic3d_TypeOfTexture theType); Handle(Graphic3d_TextureParams) myParams; TCollection_AsciiString myTexId; - Image_PixMap_Handle myPixMap; + Handle(Image_PixMap) myPixMap; OSD_Path myPath; diff --git a/src/Image/FILES b/src/Image/FILES index 6e8b75cd52..cd4babf505 100755 --- a/src/Image/FILES +++ b/src/Image/FILES @@ -5,5 +5,4 @@ Image_Diff.cxx Image_Diff.hxx Image_PixMap.cxx Image_PixMap.hxx -Image_PixMap_Handle.hxx Image_PixMapData.hxx diff --git a/src/Image/Image_PixMap.hxx b/src/Image/Image_PixMap.hxx index 73ce92bca1..6cfb505771 100644 --- a/src/Image/Image_PixMap.hxx +++ b/src/Image/Image_PixMap.hxx @@ -17,7 +17,6 @@ #define _Image_PixMap_H__ #include -#include #include #include @@ -283,4 +282,6 @@ public: }; +DEFINE_STANDARD_HANDLE(Image_PixMap, Standard_Transient) + #endif // _Image_PixMap_H__ diff --git a/src/Image/Image_PixMap_Handle.hxx b/src/Image/Image_PixMap_Handle.hxx deleted file mode 100644 index d62fedcecc..0000000000 --- a/src/Image/Image_PixMap_Handle.hxx +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2013-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Image_PixMap_Handle_H__ -#define _Image_PixMap_Handle_H__ - -#include -#include - -class Image_PixMap; -DEFINE_STANDARD_HANDLE(Image_PixMap, Standard_Transient) -typedef Handle(Image_PixMap) Image_PixMap_Handle; - -#endif // _Image_PixMap_Handle_H__ diff --git a/src/QANCollection/QANCollection_Handle.cxx b/src/QANCollection/QANCollection_Handle.cxx index 4711261562..252ccc4a6b 100644 --- a/src/QANCollection/QANCollection_Handle.cxx +++ b/src/QANCollection/QANCollection_Handle.cxx @@ -124,6 +124,45 @@ static Standard_Integer QAHandleOps (Draw_Interpretor& theDI, const Handle(Geom_Curve)& aTmpRef (Handle(Geom_Line)::DownCast (aCurve2)); CHECK(theDI, ! aTmpRef.IsNull(), "local reference of handle to base type to temporary handle object"); + // check operations with Handle_* classes + Handle(Geom_Line) hLine = aLine; + CHECK(theDI, ! hLine.IsNull(), "hhandle for non-null"); + + const Handle_Geom_Line& chLine = aLine; // cast to self const ref + const Handle_Geom_Curve& chCurve = aLine; // cast to base const ref + const Handle_Geom_Line& hhLine = hLine; // cast to self const ref + const Handle_Geom_Curve& hhCurve = hLine; // cast to base const ref + Handle_Geom_Curve hCurve = aLine; // copy from handle to derived type + Handle_Geom_Line phLine (aLine.get()); // construct from pointer + + hLine = Handle_Geom_Line::DownCast (cCurve); // inheritance of downcast + CHECK(theDI, ! hLine.IsNull(), "down cast"); + + // comparison operators + CHECK(theDI, hLine == hLine, "equality of hhandle to itself"); + CHECK(theDI, hLine == aLine, "equality of hhandle to handle"); + CHECK(theDI, hhLine == hLine, "equality of hhandle to const"); + CHECK(theDI, chLine == hLine, "equality of hhandle to const"); + CHECK(theDI, hhCurve == hLine, "equality of hhandle to const"); + CHECK(theDI, chCurve == hLine, "equality of hhandle to const"); + CHECK(theDI, hLine, "cast to bool"); + + // passing hhandle as reference to base class + f (hLine); + + // passing handle to overloaded function accepting handle to another type + // will fail on VC below 12 and GCC below 4.3 due to ambiguity of overloads +#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) || (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3) + func (hLine); + func (chLine); +#endif + + Handle_Geom_Line qhLine = cpLine; // constructor from const pointer -- could be made explicit... + + // check whether compiler will destroy reference to temporary handle + const Handle_Geom_Curve& hTmpRef (Handle(Geom_Line)::DownCast (aCurve2)); + CHECK(theDI, ! hTmpRef.IsNull(), "local reference of handle to base type to temporary handle object"); + Handle(Geom_Surface) aSurf; (void)aSurf; @@ -134,21 +173,21 @@ static Standard_Integer QAHandleOps (Draw_Interpretor& theDI, Handle(Geom_Line) xLine = cCurve; // copy from handle to base type Handle(Geom_BSplineCurve) aBSpl (new Geom_Line (gp::Origin(), gp::DX())); // construction from pointer to incompatible type - CHECK(theDI, aLine == aSurf, "equality of handles of incompatible types"); - CHECK(theDI, aSurf == cLine, "equality of const and non-const handle"); + CHECK(theDI, aLine == aSurf, "equality of handles of incompatible types"); + CHECK(theDI, aSurf == cLine, "equality of const and non-const handle"); CHECK(theDI, aSurf == cCurve, "equality of handle and base handle"); CHECK(theDI, aSurf == pLine, "equality of handle and pointer"); CHECK(theDI, pLine == aSurf, "equality of pointer and handle"); - CHECK(theDI, aSurf == cpLine, "equality of handle and const pointer"); - CHECK(theDI, cpLine != aSurf, "equality of const pointer and handle"); + CHECK(theDI, aSurf == cpLine, "equality of handle and const pointer"); + CHECK(theDI, cpLine != aSurf, "equality of const pointer and handle"); - CHECK(theDI, aLine != aSurf, "inequality of handles of incompatible types"); - CHECK(theDI, aSurf != cLine, "inequality of const and non-const handle"); + CHECK(theDI, aLine != aSurf, "inequality of handles of incompatible types"); + CHECK(theDI, aSurf != cLine, "inequality of const and non-const handle"); CHECK(theDI, aSurf != cCurve, "inequality of handle and base handle"); CHECK(theDI, aSurf != pLine, "inequality of handle and pointer"); CHECK(theDI, pLine != aSurf, "inequality of pointer and handle"); - CHECK(theDI, aSurf != cpLine, "inequality of handle and const pointer"); - CHECK(theDI, cpLine != aSurf, "inequality of const pointer and handle"); + CHECK(theDI, aSurf != cpLine, "inequality of handle and const pointer"); + CHECK(theDI, cpLine != aSurf, "inequality of const pointer and handle"); #endif // =============================================================== diff --git a/src/Standard/Standard_Handle.hxx b/src/Standard/Standard_Handle.hxx index 0eed97c9da..35b1ff49ca 100644 --- a/src/Standard/Standard_Handle.hxx +++ b/src/Standard/Standard_Handle.hxx @@ -409,8 +409,25 @@ inline Standard_Integer HashCode (const Handle(T)& theHandle, const Standard_Int return ::HashCode (const_cast(static_cast(theHandle.get())), theUpper); } -//! For compatibility with previous versions of OCCT, defines typedef opencascade::handle Handle(Class) +//! For compatibility with previous versions of OCCT, define Handle_Class alias for opencascade::handle. +#if (defined(_MSC_VER) && _MSC_VER >= 1800) +//! For Visual Studio 2013+, define Handle_Class as non-template class to allow exporting this type in C++/CLI. +#define DEFINE_STANDARD_HANDLECLASS(C1,C2,BC) class C1; class Handle_##C1 : public Handle(C1) \ +{ \ +public: \ + Handle_##C1() {} \ + Handle_##C1(Handle(C1)&& theHandle) : Handle(C1)(theHandle) {} \ + template ::value>::type> \ + inline Handle_##C1(const opencascade::handle& theOther) : Handle(C1)(theOther) {} \ + template ::value>::type> \ + inline Handle_##C1(const T2* theOther) : Handle(C1)(theOther) {} \ + template inline Handle_##C1& operator=(T theOther) { Handle(C1)::operator=(theOther); return *this; } \ +}; +#else +//! For other compilers, use simple typedef #define DEFINE_STANDARD_HANDLECLASS(C1,C2,BC) class C1; typedef Handle(C1) Handle_##C1; +#endif + #define DEFINE_STANDARD_HANDLE(C1,C2) DEFINE_STANDARD_HANDLECLASS(C1,C2,Standard_Transient) #define DEFINE_STANDARD_PHANDLE(C1,C2) DEFINE_STANDARD_HANDLECLASS(C1,C2,Standard_Persistent) diff --git a/src/StepDimTol/StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx b/src/StepDimTol/StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx index 96fe2be374..566434b8a4 100644 --- a/src/StepDimTol/StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx +++ b/src/StepDimTol/StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol.hxx @@ -30,8 +30,7 @@ class StepBasic_MeasureWithUnit; class StepRepr_ShapeAspect; -class StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol; -DEFINE_STANDARD_HANDLE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod, StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) +DEFINE_STANDARD_HANDLE(StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol, StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod) class StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMaxTol : public StepDimTol_GeoTolAndGeoTolWthDatRefAndGeoTolWthMod {