From 1b2c4e945e9291fe6f9e16229907eeae6fc4b610 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Mon, 25 Apr 2016 17:16:26 +0200 Subject: [PATCH] gmio_support: provide gmio_stl_mesh support of TopoDS_Shape --- src/CMakeLists.txt | 2 + src/gmio_support/stl_occ_brep.cpp | 140 ++++++++ src/gmio_support/stl_occ_brep.h | 116 +++++++ tests/fake_support/CMakeLists.txt | 18 +- tests/fake_support/opencascade/BRep_Tool.hxx | 20 ++ .../opencascade/Handle_MeshVS_DataSource.hxx | 20 -- .../opencascade/Handle_StlMesh_Mesh.hxx | 27 -- .../Handle_StlMesh_MeshTriangle.hxx | 15 - .../opencascade/NCollection_Array1.hxx | 300 ++++++++++++++++++ .../opencascade/NCollection_StlIterator.hxx | 249 +++++++++++++++ .../opencascade/Poly_Array1OfTriangle.hxx | 26 ++ .../opencascade/Poly_Triangle.hxx | 13 + .../opencascade/Poly_Triangulation.hxx | 23 ++ .../opencascade/TColgp_Array1OfPnt.hxx | 26 ++ .../opencascade/TopExp_Explorer.hxx | 26 ++ .../opencascade/TopLoc_Location.hxx | 16 + tests/fake_support/opencascade/TopoDS.hxx | 16 + .../fake_support/opencascade/TopoDS_Face.hxx | 12 + .../fake_support/opencascade/TopoDS_Shape.hxx | 38 +++ .../fake_support/opencascade/generic_handle.h | 22 ++ tests/fake_support/opencascade/gp_Pnt.hxx | 19 ++ tests/fake_support/opencascade/gp_Trsf.hxx | 27 ++ 22 files changed, 1096 insertions(+), 75 deletions(-) create mode 100644 src/gmio_support/stl_occ_brep.cpp create mode 100644 src/gmio_support/stl_occ_brep.h create mode 100644 tests/fake_support/opencascade/BRep_Tool.hxx delete mode 100644 tests/fake_support/opencascade/Handle_MeshVS_DataSource.hxx delete mode 100644 tests/fake_support/opencascade/Handle_StlMesh_Mesh.hxx delete mode 100644 tests/fake_support/opencascade/Handle_StlMesh_MeshTriangle.hxx create mode 100644 tests/fake_support/opencascade/NCollection_Array1.hxx create mode 100644 tests/fake_support/opencascade/NCollection_StlIterator.hxx create mode 100644 tests/fake_support/opencascade/Poly_Array1OfTriangle.hxx create mode 100644 tests/fake_support/opencascade/Poly_Triangle.hxx create mode 100644 tests/fake_support/opencascade/Poly_Triangulation.hxx create mode 100644 tests/fake_support/opencascade/TColgp_Array1OfPnt.hxx create mode 100644 tests/fake_support/opencascade/TopExp_Explorer.hxx create mode 100644 tests/fake_support/opencascade/TopLoc_Location.hxx create mode 100644 tests/fake_support/opencascade/TopoDS.hxx create mode 100644 tests/fake_support/opencascade/TopoDS_Face.hxx create mode 100644 tests/fake_support/opencascade/TopoDS_Shape.hxx create mode 100644 tests/fake_support/opencascade/generic_handle.h create mode 100644 tests/fake_support/opencascade/gp_Pnt.hxx create mode 100644 tests/fake_support/opencascade/gp_Trsf.hxx diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 686b79e..8732cec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,8 +66,10 @@ install(FILES gmio_support/stream_qt.h DESTINATION include/gmio_support) install(FILES gmio_support/stream_qt.cpp DESTINATION src/gmio_support) # OpenCASCADE support +install(FILES gmio_support/stl_occ_brep.h DESTINATION include/gmio_support) install(FILES gmio_support/stl_occ_mesh.h DESTINATION include/gmio_support) install(FILES gmio_support/stl_occ_meshvs.h DESTINATION include/gmio_support) +install(FILES gmio_support/stl_occ_brep.cpp DESTINATION src/gmio_support) install(FILES gmio_support/stl_occ_mesh.cpp DESTINATION src/gmio_support) install(FILES gmio_support/stl_occ_meshvs.cpp DESTINATION src/gmio_support) install(FILES gmio_support/stl_occ_utils.h DESTINATION src/gmio_support) diff --git a/src/gmio_support/stl_occ_brep.cpp b/src/gmio_support/stl_occ_brep.cpp new file mode 100644 index 0000000..68ce791 --- /dev/null +++ b/src/gmio_support/stl_occ_brep.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** gmio +** Copyright Fougue (2 Mar. 2015) +** contact@fougue.pro +** +** This software is a reusable library whose purpose is to provide complete +** I/O support for various CAD file formats (eg. STL) +** +** This software is governed by the CeCILL-B license under French law and +** abiding by the rules of distribution of free software. You can use, +** modify and/ or redistribute the software under the terms of the CeCILL-B +** license as circulated by CEA, CNRS and INRIA at the following URL +** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". +****************************************************************************/ + +#include + +#include "stl_occ_utils.h" + +#include +#include +#include +#include + +namespace internal { + +static void occshape_get_triangle( + const void* cookie, uint32_t /*tri_id*/, gmio_stl_triangle* tri) +{ + void* wcookie = const_cast(cookie); + gmio_stl_occshape_iterator* it = + static_cast(wcookie); + + const bool reversed = it->face_is_reversed(); + const gp_Trsf& trsf = it->face_trsf(); + const TColgp_Array1OfPnt* nodes = it->face_nodes(); + int n1, n2, n3; // Node index + it->face_current_triangle()->Get(n1, n2, n3); + gp_Pnt p1 = nodes->Value(n1); + gp_Pnt p2 = nodes->Value(reversed ? n3 : n2); + gp_Pnt p3 = nodes->Value(reversed ? n2 : n3); + if (trsf.Form() != gp_Identity) { + p1.Transform(trsf); + p2.Transform(trsf); + p3.Transform(trsf); + } + gmio_stl_occ_copy_xyz(&tri->v1, p1.XYZ()); + gmio_stl_occ_copy_xyz(&tri->v2, p2.XYZ()); + gmio_stl_occ_copy_xyz(&tri->v3, p3.XYZ()); + gmio_stl_triangle_compute_normal(tri); + it->move_to_next_tri(); +} + +} // namespace internal + +gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occshape_iterator& it) +{ + gmio_stl_mesh mesh = {}; + mesh.cookie = ⁢ + + if (it.shape() != NULL) { + TopLoc_Location loc; + const TopoDS_Shape& sh = *it.shape(); + for (TopExp_Explorer expl(sh, TopAbs_FACE); expl.More(); expl.Next()) { + const Handle_Poly_Triangulation& poly = + BRep_Tool::Triangulation(TopoDS::Face(expl.Current()), loc); + if (!poly.IsNull()) + mesh.triangle_count += poly->NbTriangles(); + } + } + + mesh.func_get_triangle = internal::occshape_get_triangle; + return mesh; +} + + +gmio_stl_occshape_iterator::gmio_stl_occshape_iterator() + : m_shape(NULL) +{ + this->reset_face(); +} + +gmio_stl_occshape_iterator::gmio_stl_occshape_iterator(const TopoDS_Shape& shape) + : m_shape(&shape), + m_expl(shape, TopAbs_FACE) +{ + if (m_expl.More()) { + this->cache_face(TopoDS::Face(m_expl.Current())); + } + else { + this->reset_face(); + } +} + +bool gmio_stl_occshape_iterator::move_to_next_tri() +{ + ++m_face_tri_id; + if (m_face_tri_id > m_face_last_tri_id) { + m_expl.Next(); + if (m_expl.More()) { + this->cache_face(TopoDS::Face(m_expl.Current())); + return true; + } + return false; + } + return true; +} + +void gmio_stl_occshape_iterator::reset_face() +{ + m_face_poly = NULL; + m_face_nodes = NULL; + m_face_triangles = NULL; + if (m_face_trsf.Form() != gp_Identity) + m_face_trsf = gp_Trsf(); + m_face_is_reversed = false; + m_face_tri_id = 0; + m_face_last_tri_id = 0; +} + +void gmio_stl_occshape_iterator::cache_face(const TopoDS_Face& face) +{ + TopLoc_Location loc; + const Handle_Poly_Triangulation& hnd_face_poly = + BRep_Tool::Triangulation(face, loc); + m_face_trsf = loc.Transformation(); + m_face_poly = + !hnd_face_poly.IsNull() ? hnd_face_poly.operator->() : NULL; + m_face_nodes = + m_face_poly != NULL ? &m_face_poly->Nodes() : NULL; + m_face_triangles = + m_face_poly != NULL ? &m_face_poly->Triangles() : NULL; + m_face_is_reversed = face.Orientation() == TopAbs_REVERSED; + if (m_face_trsf.IsNegative()) + m_face_is_reversed = !m_face_is_reversed; + m_face_tri_id = + m_face_triangles != NULL ? m_face_triangles->Lower() : -1; + m_face_last_tri_id = + m_face_triangles != NULL ? m_face_triangles->Upper() : -1; +} diff --git a/src/gmio_support/stl_occ_brep.h b/src/gmio_support/stl_occ_brep.h new file mode 100644 index 0000000..7f18463 --- /dev/null +++ b/src/gmio_support/stl_occ_brep.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** gmio +** Copyright Fougue (2 Mar. 2015) +** contact@fougue.pro +** +** This software is a reusable library whose purpose is to provide complete +** I/O support for various CAD file formats (eg. STL) +** +** This software is governed by the CeCILL-B license under French law and +** abiding by the rules of distribution of free software. You can use, +** modify and/ or redistribute the software under the terms of the CeCILL-B +** license as circulated by CEA, CNRS and INRIA at the following URL +** "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". +****************************************************************************/ + +/*! \file stl_occ_brep.h + * STL support of OpenCascade's TopoDS_Shape + * + * \addtogroup gmio_support + * @{ + */ + +#ifndef __cplusplus +# error C++ compiler required +#endif + +#ifndef GMIO_SUPPORT_STL_OCC_BREP_H +#define GMIO_SUPPORT_STL_OCC_BREP_H + +#include "support_global.h" +#include "../gmio_stl/stl_mesh.h" + +#include +#include +#include +class TopoDS_Face; + +struct gmio_stl_occshape_iterator; + +/*! Returns a gmio_stl_mesh mapped to the OpenCascade mesh in iterator \p it + * + * The mesh's cookie will point to \c &it so the lifescope of the corresponding + * object must be at least as longer as the returned gmio_stl_mesh. + * + * Example of use: + * \code{.cpp} + * const TopoDS_Shape occshape = ...; + * const gmio_stl_occshape_iterator it(occshape); + * const gmio_stl_mesh mesh = gmio_stl_occmesh(it); + * gmio_stl_write_file(stl_format, filepath, &mesh, &options); + * \endcode + */ +gmio_stl_mesh gmio_stl_occmesh(const gmio_stl_occshape_iterator& it); + + +/*! Forward iterator over the triangles of OpenCascade's TopoDS_Shape + * + * It is used to iterate efficiently over the triangles of all internally + * triangulated sub faces + * + * Don't use API of this class, it's intended to gmio_stl_occmesh() + */ +struct gmio_stl_occshape_iterator +{ + gmio_stl_occshape_iterator(); + explicit gmio_stl_occshape_iterator(const TopoDS_Shape& shape); + + inline const TopoDS_Shape* shape() const; + + bool move_to_next_tri(); + inline bool face_is_reversed() const; + inline const gp_Trsf& face_trsf() const; + inline const TColgp_Array1OfPnt* face_nodes() const; + inline const Poly_Triangle* face_current_triangle() const; + +private: + void reset_face(); + void cache_face(const TopoDS_Face& face); + + const TopoDS_Shape* m_shape; + TopExp_Explorer m_expl; + const Poly_Triangulation* m_face_poly; + const TColgp_Array1OfPnt* m_face_nodes; + const Poly_Array1OfTriangle* m_face_triangles; + gp_Trsf m_face_trsf; + bool m_face_is_reversed; + int m_face_tri_id; + int m_face_last_tri_id; +}; + + +#ifndef DOXYGEN + +/* + * Implementation + */ + +const TopoDS_Shape *gmio_stl_occshape_iterator::shape() const +{ return m_shape; } + +bool gmio_stl_occshape_iterator::face_is_reversed() const +{ return m_face_is_reversed; } + +const gp_Trsf &gmio_stl_occshape_iterator::face_trsf() const +{ return m_face_trsf; } + +const TColgp_Array1OfPnt *gmio_stl_occshape_iterator::face_nodes() const +{ return m_face_nodes; } + +const Poly_Triangle *gmio_stl_occshape_iterator::face_current_triangle() const +{ return &m_face_triangles->Value(m_face_tri_id); } + +#endif /* !DOXYGEN */ + +#endif /* GMIO_SUPPORT_STL_OCC_BREP_H */ +/*! @} */ diff --git a/tests/fake_support/CMakeLists.txt b/tests/fake_support/CMakeLists.txt index 85e009c..2fc6583 100644 --- a/tests/fake_support/CMakeLists.txt +++ b/tests/fake_support/CMakeLists.txt @@ -13,29 +13,21 @@ ## "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html". ############################################################################# +file(GLOB GMIO_FAKEOCC_HEADERS opencascade/*.hxx opencascade/*.h) +set(GMIO_FAKEOCC_HEADERS ${GMIO_FAKEOCC_HEADERS}) + add_executable( fake_support EXCLUDE_FROM_ALL main.cpp - opencascade/gp_XYZ.hxx - opencascade/Handle_MeshVS_DataSource.hxx - opencascade/Handle_StlMesh_Mesh.hxx - opencascade/Handle_StlMesh_MeshTriangle.hxx - opencascade/MeshVS_DataSource.hxx - opencascade/Standard_TypeDef.hxx - opencascade/StlMesh_Mesh.hxx - opencascade/StlMesh_MeshTriangle.hxx - opencascade/StlMesh_SequenceOfMeshTriangle.hxx - opencascade/TColStd_Array1OfReal.hxx - opencascade/TColStd_MapIteratorOfPackedMapOfInteger.hxx - opencascade/TColStd_PackedMapOfInteger.hxx - opencascade/TColgp_SequenceOfXYZ.hxx + ${GMIO_FAKEOCC_HEADERS} qt/QtCore/QFile qt/QtCore/QIODevice qt/QtCore/QString qt/QtCore/QtGlobal ../../src/gmio_support/stl_occ_mesh.cpp ../../src/gmio_support/stl_occ_meshvs.cpp + ../../src/gmio_support/stl_occ_brep.cpp ../../src/gmio_support/stream_qt.cpp) target_link_libraries(fake_support gmio) include_directories( diff --git a/tests/fake_support/opencascade/BRep_Tool.hxx b/tests/fake_support/opencascade/BRep_Tool.hxx new file mode 100644 index 0000000..d528d67 --- /dev/null +++ b/tests/fake_support/opencascade/BRep_Tool.hxx @@ -0,0 +1,20 @@ +#ifndef _BRep_Tool_HeaderFile +#define _BRep_Tool_HeaderFile + +#include +#include +#include +#include + +class BRep_Tool +{ +public: + static const Handle_Poly_Triangulation& Triangulation( + const TopoDS_Face& /*F*/, TopLoc_Location& /*L*/) + { + static Handle_Poly_Triangulation ply; + return ply; + } +}; + +#endif // _BRep_Tool_HeaderFile diff --git a/tests/fake_support/opencascade/Handle_MeshVS_DataSource.hxx b/tests/fake_support/opencascade/Handle_MeshVS_DataSource.hxx deleted file mode 100644 index 773b669..0000000 --- a/tests/fake_support/opencascade/Handle_MeshVS_DataSource.hxx +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _Handle_MeshVS_DataSource_HeaderFile -#define _Handle_MeshVS_DataSource_HeaderFile - -class MeshVS_DataSource; - -class Handle_MeshVS_DataSource -{ -public: - Handle_MeshVS_DataSource() {} - Handle_MeshVS_DataSource(const Handle_MeshVS_DataSource&) {} - Handle_MeshVS_DataSource(const MeshVS_DataSource*) {} - - MeshVS_DataSource* operator->() const - { return 0; } - - Handle_MeshVS_DataSource& operator=(const MeshVS_DataSource*) - { return *this; } -}; - -#endif // _Handle_MeshVS_DataSource_HeaderFile diff --git a/tests/fake_support/opencascade/Handle_StlMesh_Mesh.hxx b/tests/fake_support/opencascade/Handle_StlMesh_Mesh.hxx deleted file mode 100644 index 19bcc3a..0000000 --- a/tests/fake_support/opencascade/Handle_StlMesh_Mesh.hxx +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _Handle_StlMesh_Mesh_HeaderFile -#define _Handle_StlMesh_Mesh_HeaderFile - -#include - -class StlMesh_Mesh; - -class Handle_StlMesh_Mesh -{ -public: - Handle_StlMesh_Mesh() - { } - - Handle_StlMesh_Mesh(const Handle_StlMesh_Mesh&) - { } - - Handle_StlMesh_Mesh(const StlMesh_Mesh*) - { } - - StlMesh_Mesh* operator->() const - { return NULL; } - - Handle_StlMesh_Mesh& operator=(const StlMesh_Mesh*) - { return *this; } -}; - -#endif // _Handle_StlMesh_Mesh_HeaderFile diff --git a/tests/fake_support/opencascade/Handle_StlMesh_MeshTriangle.hxx b/tests/fake_support/opencascade/Handle_StlMesh_MeshTriangle.hxx deleted file mode 100644 index 47eb880..0000000 --- a/tests/fake_support/opencascade/Handle_StlMesh_MeshTriangle.hxx +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _Handle_StlMesh_MeshTriangle_HeaderFile -#define _Handle_StlMesh_MeshTriangle_HeaderFile - -#include - -class StlMesh_MeshTriangle; - -class Handle_StlMesh_MeshTriangle -{ -public: - StlMesh_MeshTriangle* operator->() const - { return NULL; } -}; - -#endif // _Handle_StlMesh_MeshTriangle_HeaderFile diff --git a/tests/fake_support/opencascade/NCollection_Array1.hxx b/tests/fake_support/opencascade/NCollection_Array1.hxx new file mode 100644 index 0000000..1e19f0e --- /dev/null +++ b/tests/fake_support/opencascade/NCollection_Array1.hxx @@ -0,0 +1,300 @@ +// Created on: 2002-04-15 +// Created by: Alexander Kartomin (akm) +// Copyright (c) 2002-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 NCollection_Array1_HeaderFile +#define NCollection_Array1_HeaderFile + +#include +#include +#include + +// *********************************************** Template for Array1 class + +/** +* Purpose: The class Array1 represents unidimensional arrays +* of fixed size known at run time. +* The range of the index is user defined. +* An array1 can be constructed with a "C array". +* This functionality is useful to call methods expecting +* an Array1. It allows to carry the bounds inside the arrays. +* +* Examples: Item tab[100]; // An example with a C array +* Array1OfItem ttab (tab[0],1,100); +* +* Array1OfItem tttab (ttab(10),10,20); // a slice of ttab +* +* If you want to reindex an array from 1 to Length do : +* +* Array1 tab1(tab(tab.Lower()),1,tab.Length()); +* +* Warning: Programs client of such a class must be independant +* of the range of the first element. Then, a C++ for +* loop must be written like this +* +* for (i = A.Lower(); i <= A.Upper(); i++) +* +* Changes: In comparison to TCollection the flag isAllocated was +* renamed into myDeletable (alike in the Array2). For naming +* compatibility the method IsAllocated remained in class along +* with IsDeletable. +*/ +template +class NCollection_Array1 +{ +public: + //! STL-compliant typedef for value type + typedef TheItemType value_type; + +public: + //! Implementation of the Iterator interface. + class Iterator + { + public: + + //! Empty constructor - for later Init + Iterator (void) : + myPtrCur (NULL), + myPtrEnd (NULL) + { + // + } + + //! Constructor with initialization + Iterator (const NCollection_Array1& theArray, Standard_Boolean theToEnd = Standard_False) : + myPtrEnd (const_cast (&theArray.Last() + 1)) + { + myPtrCur = theToEnd ? myPtrEnd : const_cast (&theArray.First()); + } + + //! Initialisation + void Init (const NCollection_Array1& theArray) + { + myPtrCur = const_cast (&theArray.First()); + myPtrEnd = const_cast (&theArray.Last() + 1); + } + + //! Assignment + Iterator& operator= (const Iterator& theOther) + { + myPtrCur = theOther.myPtrCur; + myPtrEnd = theOther.myPtrEnd; + return *this; + } + + //! Check end + Standard_Boolean More (void) const + { return myPtrCur < myPtrEnd; } + + //! Increment operator + void Next (void) + { ++myPtrCur; } + + //! Decrement operator + void Previous() + { --myPtrCur; } + + //! Offset operator. + void Offset (ptrdiff_t theOffset) + { myPtrCur += theOffset; } + + //! Difference operator. + ptrdiff_t Differ (const Iterator& theOther) const + { return myPtrCur - theOther.myPtrCur; } + + //! Constant value access + const TheItemType& Value (void) const + { return *myPtrCur; } + + //! Variable value access + TheItemType& ChangeValue (void) const + { return *myPtrCur; } + + //! Performs comparison of two iterators + Standard_Boolean IsEqual (const Iterator& theOther) const + { return myPtrCur == theOther.myPtrCur; } + + private: + TheItemType* myPtrCur; //!< Pointer to the current element in the array + TheItemType* myPtrEnd; //!< Pointer to the past-the-end element in the array + }; // End of the nested class Iterator + + //! Shorthand for a regular iterator type. + typedef NCollection_StlIterator iterator; + + //! Shorthand for a constant iterator type. + typedef NCollection_StlIterator const_iterator; + + //! Returns an iterator pointing to the first element in the array. + iterator begin() const { return Iterator (*this, false); } + + //! Returns an iterator referring to the past-the-end element in the array. + iterator end() const { return Iterator (*this, true); } + + //! Returns a const iterator pointing to the first element in the array. + const_iterator cbegin() const { return Iterator (*this, false); } + + //! Returns a const iterator referring to the past-the-end element in the array. + const_iterator cend() const { return Iterator (*this, true); } + + public: + // ---------- PUBLIC METHODS ------------ + + //! Constructor + NCollection_Array1(const Standard_Integer theLower, + const Standard_Integer theUpper) : + myLowerBound (theLower), + myUpperBound (theUpper), + myDeletable (Standard_True) + { + TheItemType* pBegin = new TheItemType[Length()]; + + myData = pBegin - theLower; + } + + //! Copy constructor + NCollection_Array1 (const NCollection_Array1& theOther) : + myLowerBound (theOther.Lower()), + myUpperBound (theOther.Upper()), + myDeletable (Standard_True) + { + TheItemType* pBegin = new TheItemType[Length()]; + myData = pBegin - myLowerBound; + + *this = theOther; + } + + //! C array-based constructor + NCollection_Array1 (const TheItemType& theBegin, + const Standard_Integer theLower, + const Standard_Integer theUpper) : + myLowerBound (theLower), + myUpperBound (theUpper), + myDeletable (Standard_False) + { + myData = (TheItemType *) &theBegin - theLower; + } + + //! Initialise the items with theValue + void Init (const TheItemType& theValue) + { + TheItemType *pCur = &myData[myLowerBound], *pEnd=&myData[myUpperBound]; + for(; pCur <= pEnd; pCur++) + *pCur = (TheItemType&) theValue; + } + + //! Size query + Standard_Integer Size (void) const + { return Length(); } + //! Length query (the same) + Standard_Integer Length (void) const + { return (myUpperBound-myLowerBound+1); } + + //! Lower bound + Standard_Integer Lower (void) const + { return myLowerBound; } + //! Upper bound + Standard_Integer Upper (void) const + { return myUpperBound; } + + //! myDeletable flag + Standard_Boolean IsDeletable (void) const + { return myDeletable; } + + //! IsAllocated flag - for naming compatibility + Standard_Boolean IsAllocated (void) const + { return myDeletable; } + + //! Assignment + NCollection_Array1& Assign (const NCollection_Array1& theOther) + { + if (&theOther == this) + return *this; + TheItemType * pMyItem = &myData[myLowerBound]; + TheItemType * const pEndItem = &(theOther.myData)[theOther.myUpperBound]; + TheItemType * pItem = &(theOther.myData)[theOther.myLowerBound]; + while (pItem <= pEndItem) * pMyItem ++ = * pItem ++; + return *this; + } + + //! Assignment operator + NCollection_Array1& operator= (const NCollection_Array1& theOther) + { + return Assign (theOther); + } + + //! @return first element + const TheItemType& First() const + { + return myData[myLowerBound]; + } + + //! @return first element + TheItemType& ChangeFirst() + { + return myData[myLowerBound]; + } + + //! @return last element + const TheItemType& Last() const + { + return myData[myUpperBound]; + } + + //! @return last element + TheItemType& ChangeLast() + { + return myData[myUpperBound]; + } + + //! Constant value access + const TheItemType& Value (const Standard_Integer theIndex) const + { + return myData[theIndex]; + } + + //! operator() - alias to Value + const TheItemType& operator() (const Standard_Integer theIndex) const + { return Value (theIndex); } + + //! Variable value access + TheItemType& ChangeValue (const Standard_Integer theIndex) + { + return myData[theIndex]; + } + + //! operator() - alias to ChangeValue + TheItemType& operator() (const Standard_Integer theIndex) + { return ChangeValue (theIndex); } + + //! Set value + void SetValue (const Standard_Integer theIndex, + const TheItemType& theItem) + { + myData[theIndex] = theItem; + } + + //! Destructor - releases the memory + ~NCollection_Array1 (void) + { if (myDeletable) delete [] &(myData[myLowerBound]); } + + protected: + // ---------- PROTECTED FIELDS ----------- + Standard_Integer myLowerBound; + Standard_Integer myUpperBound; + Standard_Boolean myDeletable; //!< Flag showing who allocated the array + TheItemType* myData; //!< Pointer to '0'th array item +}; + +#endif diff --git a/tests/fake_support/opencascade/NCollection_StlIterator.hxx b/tests/fake_support/opencascade/NCollection_StlIterator.hxx new file mode 100644 index 0000000..abcac2f --- /dev/null +++ b/tests/fake_support/opencascade/NCollection_StlIterator.hxx @@ -0,0 +1,249 @@ +// Created on: 2014-04-15 +// Created by: Denis BOGOLEPOV +// Copyright (c) 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 NCollection_StlIterator_HeaderFile +#define NCollection_StlIterator_HeaderFile + +#include + +// This file uses C++11 utilities like std::is_base<>, which are not +// available in some environments (e.g. MSVC includes them since VS 2008). +// Hence here we define our own implementation of these tools in namespace opencascade. +// When all compilers support this, this namespace can be removed and replaced by std. +namespace opencascade +{ + template + struct enable_if + { + typedef T type; + }; + + template + struct enable_if + { + }; + + template + struct is_same + { + enum { value = 0 }; + }; + + template + struct is_same + { + enum { value = 1 }; + }; + + template + struct conditional + { + typedef TypeTrue type; + }; + + template + struct conditional + { + typedef TypeFalse type; + }; +} + +//! Helper class that allows to use NCollection iterators as STL iterators. +//! NCollection iterator can be extended to STL iterator of any category by +//! adding necessary methods: STL forward iterator requires IsEqual method, +//! STL bidirectional iterator requires Previous method, and STL random access +//! iterator requires Offset and Differ methods. See NCollection_Vector as +//! example of declaring custom STL iterators. +template +class NCollection_StlIterator : + public std::iterator::type, + typename opencascade::conditional::type> +{ +public: + + //! Default constructor + NCollection_StlIterator () {} + + //! Constructor from NCollection iterator + NCollection_StlIterator (const BaseIterator& theIterator) + : myIterator (theIterator) + { } + + //! Cast from non-const variant to const one + NCollection_StlIterator (const NCollection_StlIterator& theIterator) + : myIterator (theIterator.Iterator()) + { } + + //! Assignment of non-const iterator to const one + NCollection_StlIterator& operator= (const NCollection_StlIterator& theIterator) + { + myIterator = theIterator.myIterator; + return *this; + } + + //! Access to NCollection iterator instance + const BaseIterator& Iterator () const + { + return myIterator; + } + +protected: //! @name methods related to forward STL iterator + + // Note: Here we use SFINAE (Substitution failure is not an error) to choose + // an appropriate method based on template arguments (at instantiation time). + + template + typename opencascade::enable_if::type Reference() const + { + return myIterator.ChangeValue(); + } + + template + typename opencascade::enable_if::type Reference() const + { + return myIterator.Value(); + } + +public: //! @name methods related to forward STL iterator + + //! Test for equality + bool operator== (const NCollection_StlIterator& theOther) const + { + return myIterator.More() == theOther.myIterator.More() && + (!myIterator.More() || myIterator.IsEqual (theOther.myIterator)); + } + + //! Test for inequality + bool operator!= (const NCollection_StlIterator& theOther) const + { + return !(*this == theOther); + } + + //! Get reference to current item + typename NCollection_StlIterator::reference operator*() const + { + return Reference(); + } + + //! Dereferencing operator + typename NCollection_StlIterator::pointer operator->() const + { + return &Reference(); + } + + //! Prefix increment + NCollection_StlIterator& operator++() + { + myIterator.Next(); + return *this; + } + + //! Postfix increment + NCollection_StlIterator operator++(int) + { + const NCollection_StlIterator theOld (*this); + ++(*this); + return theOld; + } + +public: //! @name methods related to bidirectional STL iterator + + //! Prefix decrement + NCollection_StlIterator& operator--() + { + myIterator.Previous(); + return *this; + } + + //! Postfix decrement + NCollection_StlIterator operator--(int) + { + NCollection_StlIterator theOld (*this); + --(*this); + return theOld; + } + +public: //! @name methods related to random access STL iterator + + //! Move forward + NCollection_StlIterator& operator+= (typename NCollection_StlIterator::difference_type theOffset) + { + myIterator.Offset (theOffset); + return *this; + } + + //! Addition + NCollection_StlIterator operator+ (typename NCollection_StlIterator::difference_type theOffset) const + { + NCollection_StlIterator aTemp (*this); + return aTemp += theOffset; + } + + //! Move backward + NCollection_StlIterator& operator-= (typename NCollection_StlIterator::difference_type theOffset) + { + return *this += -theOffset; + } + + //! Decrease + NCollection_StlIterator operator- (typename NCollection_StlIterator::difference_type theOffset) const + { + NCollection_StlIterator aTemp (*this); + return aTemp += -theOffset; + } + + //! Difference + typename NCollection_StlIterator::difference_type operator- (const NCollection_StlIterator& theOther) const + { + return myIterator.Differ (theOther.myIterator); + } + + //! Get item at offset from current + typename NCollection_StlIterator::reference operator[] (typename NCollection_StlIterator::difference_type theOffset) const + { + return *(*this + theOffset); + } + + //! Comparison + bool operator< (const NCollection_StlIterator& theOther) const + { + return (*this - theOther) < 0; + } + + //! Comparison + bool operator> (const NCollection_StlIterator& theOther) const + { + return theOther < *this; + } + + //! Comparison + bool operator<= (const NCollection_StlIterator& theOther) const + { + return !(theOther < *this); + } + + //! Comparison + bool operator>= (const NCollection_StlIterator& theOther) const + { + return !(*this < theOther); + } + +private: + //! NCollection iterator + BaseIterator myIterator; +}; + +#endif // NCollection_StlIterator_HeaderFile diff --git a/tests/fake_support/opencascade/Poly_Array1OfTriangle.hxx b/tests/fake_support/opencascade/Poly_Array1OfTriangle.hxx new file mode 100644 index 0000000..4fdcacb --- /dev/null +++ b/tests/fake_support/opencascade/Poly_Array1OfTriangle.hxx @@ -0,0 +1,26 @@ +// Created on: 1995-03-06 +// Created by: Laurent PAINNOT +// Copyright (c) 1995-1999 Matra Datavision +// Copyright (c) 1999-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 Poly_Array1OfTriangle_HeaderFile +#define Poly_Array1OfTriangle_HeaderFile + +#include +#include + +typedef NCollection_Array1 Poly_Array1OfTriangle; + + +#endif diff --git a/tests/fake_support/opencascade/Poly_Triangle.hxx b/tests/fake_support/opencascade/Poly_Triangle.hxx new file mode 100644 index 0000000..3b977f3 --- /dev/null +++ b/tests/fake_support/opencascade/Poly_Triangle.hxx @@ -0,0 +1,13 @@ +#ifndef _Poly_Triangle_HeaderFile +#define _Poly_Triangle_HeaderFile + +#include + +class Poly_Triangle +{ +public: + Poly_Triangle() {} + void Get(Standard_Integer&, Standard_Integer&, Standard_Integer&) const {} +}; + +#endif // _Poly_Triangle_HeaderFile diff --git a/tests/fake_support/opencascade/Poly_Triangulation.hxx b/tests/fake_support/opencascade/Poly_Triangulation.hxx new file mode 100644 index 0000000..970aeb2 --- /dev/null +++ b/tests/fake_support/opencascade/Poly_Triangulation.hxx @@ -0,0 +1,23 @@ +#ifndef _Poly_Triangulation_HeaderFile +#define _Poly_Triangulation_HeaderFile + +#include +#include +#include + +class Poly_Triangulation +{ +public: + const TColgp_Array1OfPnt& Nodes() const { return myNodes; } + const Poly_Array1OfTriangle& Triangles() const { return myTriangles; } + Standard_Integer NbTriangles() const { return 0; } + +private: + TColgp_Array1OfPnt myNodes; + Poly_Array1OfTriangle myTriangles; +}; + +#include "generic_handle.h" +typedef FakeOcc::GenericHandle Handle_Poly_Triangulation; + +#endif // _Poly_Triangulation_HeaderFile diff --git a/tests/fake_support/opencascade/TColgp_Array1OfPnt.hxx b/tests/fake_support/opencascade/TColgp_Array1OfPnt.hxx new file mode 100644 index 0000000..28802d1 --- /dev/null +++ b/tests/fake_support/opencascade/TColgp_Array1OfPnt.hxx @@ -0,0 +1,26 @@ +// Created on: 1993-03-10 +// Created by: Philippe DAUTRY +// Copyright (c) 1993-1999 Matra Datavision +// Copyright (c) 1999-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 TColgp_Array1OfPnt_HeaderFile +#define TColgp_Array1OfPnt_HeaderFile + +#include +#include + +typedef NCollection_Array1 TColgp_Array1OfPnt; + + +#endif diff --git a/tests/fake_support/opencascade/TopExp_Explorer.hxx b/tests/fake_support/opencascade/TopExp_Explorer.hxx new file mode 100644 index 0000000..256da4f --- /dev/null +++ b/tests/fake_support/opencascade/TopExp_Explorer.hxx @@ -0,0 +1,26 @@ +#ifndef _TopExp_Explorer_HeaderFile +#define _TopExp_Explorer_HeaderFile + +#include +#include + +class TopExp_Explorer +{ +public: + TopExp_Explorer() {} + TopExp_Explorer( + const TopoDS_Shape& /*S*/, + const TopAbs_ShapeEnum /*ToFind*/, + const TopAbs_ShapeEnum /*ToAvoid*/ = TopAbs_SHAPE) + {} + + Standard_Boolean More() const { return Standard_False; } + void Next() {} + const TopoDS_Shape& Current() const { return myShape; } + void ReInit() {} + +private: + TopoDS_Shape myShape; +}; + +#endif // _TopExp_Explorer_HeaderFile diff --git a/tests/fake_support/opencascade/TopLoc_Location.hxx b/tests/fake_support/opencascade/TopLoc_Location.hxx new file mode 100644 index 0000000..733adc4 --- /dev/null +++ b/tests/fake_support/opencascade/TopLoc_Location.hxx @@ -0,0 +1,16 @@ +#ifndef _TopLoc_Location_HeaderFile +#define _TopLoc_Location_HeaderFile + +#include + +class TopLoc_Location +{ +public: + TopLoc_Location() {} + const gp_Trsf& Transformation() const { return m_trsf; } + +private: + gp_Trsf m_trsf; +}; + +#endif // _TopLoc_Location_HeaderFile diff --git a/tests/fake_support/opencascade/TopoDS.hxx b/tests/fake_support/opencascade/TopoDS.hxx new file mode 100644 index 0000000..c46b160 --- /dev/null +++ b/tests/fake_support/opencascade/TopoDS.hxx @@ -0,0 +1,16 @@ +#ifndef _TopoDS_HeaderFile +#define _TopoDS_HeaderFile + +#include + +class TopoDS +{ +public: + static const TopoDS_Face& Face(const TopoDS_Shape&) + { + static const TopoDS_Face face; + return face; + } +}; + +#endif // _TopoDS_HeaderFile diff --git a/tests/fake_support/opencascade/TopoDS_Face.hxx b/tests/fake_support/opencascade/TopoDS_Face.hxx new file mode 100644 index 0000000..1dcf817 --- /dev/null +++ b/tests/fake_support/opencascade/TopoDS_Face.hxx @@ -0,0 +1,12 @@ +#ifndef _TopoDS_Face_HeaderFile +#define _TopoDS_Face_HeaderFile + +#include + +class TopoDS_Face : public TopoDS_Shape +{ +public: + TopoDS_Face() {} +}; + +#endif // _TopoDS_Face_HeaderFile diff --git a/tests/fake_support/opencascade/TopoDS_Shape.hxx b/tests/fake_support/opencascade/TopoDS_Shape.hxx new file mode 100644 index 0000000..b17082c --- /dev/null +++ b/tests/fake_support/opencascade/TopoDS_Shape.hxx @@ -0,0 +1,38 @@ +#ifndef _TopoDS_Shape_HeaderFile +#define _TopoDS_Shape_HeaderFile + +#include + +enum TopAbs_Orientation +{ + TopAbs_FORWARD, + TopAbs_REVERSED, + TopAbs_INTERNAL, + TopAbs_EXTERNAL +}; + +enum TopAbs_ShapeEnum +{ + TopAbs_COMPOUND, + TopAbs_COMPSOLID, + TopAbs_SOLID, + TopAbs_SHELL, + TopAbs_FACE, + TopAbs_WIRE, + TopAbs_EDGE, + TopAbs_VERTEX, + TopAbs_SHAPE +}; + +class TopoDS_Shape +{ +public: + TopoDS_Shape() : myOrient(TopAbs_FORWARD) {} + Standard_Boolean IsNull() const { return Standard_True; } + TopAbs_Orientation Orientation() const { return myOrient; } + +private: + TopAbs_Orientation myOrient; +}; + +#endif // _TopoDS_Shape_HeaderFile diff --git a/tests/fake_support/opencascade/generic_handle.h b/tests/fake_support/opencascade/generic_handle.h new file mode 100644 index 0000000..bd317f9 --- /dev/null +++ b/tests/fake_support/opencascade/generic_handle.h @@ -0,0 +1,22 @@ +#ifndef FAKE_OCC_GENERIC_HANDLE +#define FAKE_OCC_GENERIC_HANDLE + +#include + +namespace FakeOcc { + +template +class GenericHandle +{ +public: + GenericHandle() { } + GenericHandle(const GenericHandle&) { } + GenericHandle(const T*) { } + Standard_Boolean IsNull() const { return Standard_True; } + T* operator->() const { return NULL; } + GenericHandle& operator=(const T*) { return *this; } +}; + +} // namespace FakeOcc + +#endif // FAKE_OCC_GENERIC_HANDLE diff --git a/tests/fake_support/opencascade/gp_Pnt.hxx b/tests/fake_support/opencascade/gp_Pnt.hxx new file mode 100644 index 0000000..3360a86 --- /dev/null +++ b/tests/fake_support/opencascade/gp_Pnt.hxx @@ -0,0 +1,19 @@ +#ifndef _gp_Pnt_HeaderFile +#define _gp_Pnt_HeaderFile + +#include +#include +#include + +class gp_Pnt +{ +public: + gp_Pnt() {} + const gp_XYZ& XYZ() const { return coord; } + void Transform(const gp_Trsf&) {} + +private: + gp_XYZ coord; +}; + +#endif // _gp_Pnt_HeaderFile diff --git a/tests/fake_support/opencascade/gp_Trsf.hxx b/tests/fake_support/opencascade/gp_Trsf.hxx new file mode 100644 index 0000000..bc6d3f8 --- /dev/null +++ b/tests/fake_support/opencascade/gp_Trsf.hxx @@ -0,0 +1,27 @@ +#ifndef _gp_Trsf_HeaderFile +#define _gp_Trsf_HeaderFile + +#include + +enum gp_TrsfForm +{ + gp_Identity, + gp_Rotation, + gp_Translation, + gp_PntMirror, + gp_Ax1Mirror, + gp_Ax2Mirror, + gp_Scale, + gp_CompoundTrsf, + gp_Other +}; + +class gp_Trsf +{ +public: + gp_Trsf() {} + Standard_Boolean IsNegative() const { return Standard_False; } + gp_TrsfForm Form() const { return gp_Identity; } +}; + +#endif // _gp_Trsf_HeaderFile