Skip to content

Commit

Permalink
Add support for OCCT 7.8.0 (FreeCAD#11909)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgbsww authored and Jordan Richards committed Sep 18, 2024
1 parent 631044a commit e2058f2
Show file tree
Hide file tree
Showing 34 changed files with 237 additions and 75 deletions.
14 changes: 6 additions & 8 deletions cMake/FindOCC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ if(OCC_FOUND)
TKG2d
TKG3d
TKMath
TKIGES
TKSTL
TKShHealing
TKXSBase
TKBool
Expand All @@ -139,10 +137,6 @@ if(OCC_FOUND)
TKGeomBase
TKOffset
TKPrim
TKSTEPBase
TKSTEPAttr
TKSTEP209
TKSTEP
TKHLR
TKFeat
)
Expand All @@ -154,8 +148,6 @@ if(OCC_FOUND)
TKLCAF
TKVCAF
TKCDF
TKXDESTEP
TKXDEIGES
TKMeshVS
TKService
TKV3d
Expand All @@ -165,6 +157,12 @@ if(OCC_FOUND)
elseif(NOT OCC_VERSION_STRING VERSION_LESS 7.5.0)
list(APPEND OCC_OCAF_LIBRARIES TKRWMesh)
endif(OCC_VERSION_STRING VERSION_LESS 6.7.3)
if(OCC_VERSION_STRING VERSION_LESS 7.8.0)
list(APPEND OCC_LIBRARIES TKIGES TKSTL TKSTEPBase TKSTEPAttr TKSTEP209 TKSTEP)
list(APPEND OCC_OCAF_LIBRARIES TKXDESTEP TKXDEIGES)
else(OCC_VERSION_STRING VERSION_LESS 7.8.0)
list(APPEND OCC_LIBRARIES TKDESTEP TKDEIGES TKDEGLTF TKDESTL)
endif(OCC_VERSION_STRING VERSION_LESS 7.8.0)
message(STATUS "-- Found OCE/OpenCASCADE version: ${OCC_VERSION_STRING}")
message(STATUS "-- OCE/OpenCASCADE include directory: ${OCC_INCLUDE_DIR}")
message(STATUS "-- OCE/OpenCASCADE shared libraries directory: ${OCC_LIBRARY_DIR}")
Expand Down
17 changes: 15 additions & 2 deletions src/3rdParty/salomesmesh/inc/SMESHDS_DataMapOfShape.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,26 @@

#include <TopoDS_Shape.hxx>

#include <Standard_Version.hxx>

/*
* This method needed for instance NCollection_DataMap with TopoDS_Shape as key
*/
#if OCC_VERSION_HEX >= 0x070800
struct SMESHDS_Hasher
{
size_t operator()(const TopoDS_Shape& S) const noexcept {
return std::hash<TopoDS_Shape>{}(S);
}
size_t operator()(const TopoDS_Shape& S1, const TopoDS_Shape& S2) const noexcept {
return S1.IsSame(S2);
}
};
#else
struct SMESHDS_Hasher
{
static inline Standard_Boolean IsEqual(const TopoDS_Shape& S1,
const TopoDS_Shape& S2)
const TopoDS_Shape& S2)
{
return S1.IsSame(S2);
}
Expand All @@ -45,6 +58,6 @@ struct SMESHDS_Hasher
return ::HashCode( S, Upper);
}
};

#endif

#endif
3 changes: 0 additions & 3 deletions src/3rdParty/salomesmesh/inc/SMESH_MeshVSLink.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
#ifndef _MeshVS_EntityType_HeaderFile
#include <MeshVS_EntityType.hxx>
#endif
#ifndef _Standard_Address_HeaderFile
#include <Standard_Address.hxx>
#endif
#ifndef _TColStd_HArray1OfInteger_HeaderFile
#include <TColStd_HArray1OfInteger.hxx>
#endif
Expand Down
1 change: 1 addition & 0 deletions src/3rdParty/salomesmesh/inc/SMESH_SMESH.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
#define SMESH_EXPORT
#endif

#include <Standard_Version.hxx>
#endif
3 changes: 2 additions & 1 deletion src/3rdParty/salomesmesh/inc/SMESH_SequenceOfNode.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@

#include "SMESH_SMESH.hxx"

#include <NCollection_DefineSequence.hxx>
#if OCC_VERSION_HEX >= 0x060703
#include <NCollection_IncAllocator.hxx>
#include <NCollection_Sequence.hxx>
#else
#include <NCollection_DefineSequence.hxx>
#endif

typedef const SMDS_MeshNode* SMDS_MeshNodePtr;

Check failure on line 38 in src/3rdParty/salomesmesh/inc/SMESH_SequenceOfNode.hxx

View workflow job for this annotation

GitHub Actions / Lint / Lint

unknown type name 'SMDS_MeshNode'
Expand Down
7 changes: 7 additions & 0 deletions src/3rdParty/salomesmesh/inc/SMESH_TypeDefs.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,18 @@ typedef std::vector< UVPtStruct > UVPtStructVec;

// --------------------------------------------------------------------------------
// class SMESH_SequenceOfElemPtr
#include <Standard_Version.hxx>
#if OCC_VERSION_HEX >= 0x060703
#include <NCollection_Sequence.hxx>
#else
#include <NCollection_DefineSequence.hxx>
#endif

class SMDS_MeshElement;

typedef const SMDS_MeshElement* SMDS_MeshElementPtr;
#define DEFINE_SEQUENCE(_ClassName_, _BaseCollection_, TheItemType) \
typedef NCollection_Sequence<TheItemType > _ClassName_;

DEFINE_SEQUENCE (SMESH_SequenceOfElemPtr, SMESH_BaseCollectionElemPtr, SMDS_MeshElementPtr)

Expand Down
29 changes: 27 additions & 2 deletions src/3rdParty/salomesmesh/src/DriverSTL/DriverSTL_R_SMDS_Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,33 @@
#include "SMDS_MeshNode.hxx"
#include "SMESH_File.hxx"

#include <Standard_Version.hxx>

namespace
{
struct Hasher
{
#if OCC_VERSION_HEX >= 0x070800
size_t operator()(const gp_Pnt& point) const noexcept
{
union
{
Standard_Real R[3];
Standard_Integer I[6];
} U;

point.Coord( U.R[0], U.R[1], U.R[2] );
return std::hash<Standard_Integer>{}(U.I[0]/23+U.I[1]/19+U.I[2]/17+U.I[3]/13+U.I[4]/11+U.I[5]/7);
}

size_t operator()(const gp_Pnt& point1, const gp_Pnt& point2) const noexcept
{
static Standard_Real tab1[3], tab2[3];
point1.Coord(tab1[0],tab1[1],tab1[2]);
point2.Coord(tab2[0],tab2[1],tab2[2]);
return (memcmp(tab1,tab2,sizeof(tab1)) == 0);
}
#else
//=======================================================================
//function : HashCode
//purpose :
Expand All @@ -51,9 +74,9 @@ namespace
} U;

point.Coord( U.R[0], U.R[1], U.R[2] );

return ::HashCode(U.I[0]/23+U.I[1]/19+U.I[2]/17+U.I[3]/13+U.I[4]/11+U.I[5]/7,Upper);
return std::hash<Standard_Integer>{}(U.I[0]/23+U.I[1]/19+U.I[2]/17+U.I[3]/13+U.I[4]/11+U.I[5]/7);
}

Check warning on line 79 in src/3rdParty/salomesmesh/src/DriverSTL/DriverSTL_R_SMDS_Mesh.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

<-- trailing whitespace
//=======================================================================
//function : IsEqual
//purpose :
Expand All @@ -66,7 +89,9 @@ namespace
point2.Coord(tab2[0],tab2[1],tab2[2]);
return (memcmp(tab1,tab2,sizeof(tab1)) == 0);
}
#endif
};

typedef NCollection_DataMap<gp_Pnt,SMDS_MeshNode*,Hasher> TDataMapOfPntNodePtr;

const int HEADER_SIZE = 84;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <Bnd_Box.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <Geom_Surface.hxx>
#include <NCollection_DefineArray2.hxx>
#include <Precision.hxx>
#include <Standard_Real.hxx>
#include <TColStd_SequenceOfInteger.hxx>
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Fem/Gui/PreCompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
// OCC
#include <BRepAdaptor_Surface.hxx>
#include <Precision.hxx>
#include <Standard_math.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>

Expand Down
5 changes: 2 additions & 3 deletions src/Mod/Fem/Gui/TaskCreateNodeSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
# include <Inventor/nodes/SoCamera.h>
# include <Inventor/nodes/SoEventCallback.h>

# include <SMESH_Mesh.hxx>
# include <SMESHDS_Mesh.hxx>
# include <Standard_math.hxx>
#include <SMESHDS_Mesh.hxx>
#include <SMESH_Mesh.hxx>
#endif

#include <Base/Console.h>
Expand Down
91 changes: 80 additions & 11 deletions src/Mod/Import/App/ImportOCAF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc,

std::vector<App::DocumentObject *> localValue;

if (aShapeTool->GetShape(label,aShape)) {
if (aShapeTool->GetShape(label, aShape)) {
#if OCC_VERSION_HEX >= 0x070800
hash = std::hash<TopoDS_Shape> {}(aShape);
#else
hash = aShape.HashCode(HashUpper);
#endif
}

Handle(TDataStd_Name) name;
Expand Down Expand Up @@ -217,8 +221,13 @@ void ImportOCAF::loadShapes(const TDF_Label& label, const TopLoc_Location& loc,

if (isRef || myRefShapes.find(hash) == myRefShapes.end()) {
TopoDS_Shape aShape;
if (isRef && aShapeTool->GetShape(label, aShape))
if (isRef && aShapeTool->GetShape(label, aShape)) {
#if OCC_VERSION_HEX >= 0x070800
myRefShapes.insert(std::hash<TopoDS_Shape> {}(aShape));
#else
myRefShapes.insert(aShape.HashCode(HashUpper));
#endif
}

if (aShapeTool->IsSimpleShape(label) && (isRef || aShapeTool->IsFree(label))) {
if (!asm_name.empty())
Expand Down Expand Up @@ -532,7 +541,11 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna
part->Label.setValue(default_name);
part->Shape.setValue(shape);
std::map<Standard_Integer, Quantity_ColorRGBA>::const_iterator jt;
#if OCC_VERSION_HEX >= 0x070800
jt = myColorMap.find(std::hash<TopoDS_Shape> {}(shape));
#else
jt = myColorMap.find(shape.HashCode(INT_MAX));
#endif

App::Color partColor(0.8f,0.8f,0.8f);
#if 0//TODO
Expand All @@ -553,7 +566,11 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna
// set label name if defined
if (setname && !myNameMap.empty()) {
std::map<Standard_Integer, std::string>::const_iterator jt;
#if OCC_VERSION_HEX >= 0x070800
jt = myNameMap.find(std::hash<TopoDS_Shape> {}(shape));
#else
jt = myNameMap.find(shape.HashCode(INT_MAX));
#endif
if (jt != myNameMap.end()) {
part->Label.setValue(jt->second);
}
Expand All @@ -573,7 +590,11 @@ void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setna
faceColors.resize(faces.Extent(), partColor);
xp.Init(shape,TopAbs_FACE);
while (xp.More()) {
#if OCC_VERSION_HEX >= 0x070800
jt = myColorMap.find(std::hash<TopoDS_Shape> {}(xp.Current()));
#else
jt = myColorMap.find(xp.Current().HashCode(INT_MAX));
#endif
if (jt != myColorMap.end()) {
int index = faces.FindIndex(xp.Current());
faceColors[index-1] = convertColor(jt->second);
Expand Down Expand Up @@ -607,24 +628,59 @@ void ImportXCAF::loadShapes(const TDF_Label& label)
int ctSolids = 0, ctShells = 0, ctComps = 0;
// add the shapes
TopExp_Explorer xp;
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++)
for (xp.Init(aShape, TopAbs_SOLID); xp.More(); xp.Next(), ctSolids++) {
#if OCC_VERSION_HEX >= 0x070800
this->mySolids[std::hash<TopoDS_Shape> {}(xp.Current())] = (xp.Current());
#else
this->mySolids[xp.Current().HashCode(INT_MAX)] = (xp.Current());
for (xp.Init(aShape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next(), ctShells++)
#endif
}
for (xp.Init(aShape, TopAbs_SHELL, TopAbs_SOLID); xp.More(); xp.Next(), ctShells++) {
#if OCC_VERSION_HEX >= 0x070800
this->myShells[std::hash<TopoDS_Shape> {}(xp.Current())] = (xp.Current());
#else
this->myShells[xp.Current().HashCode(INT_MAX)] = (xp.Current());
#endif
}
// if no solids and no shells were found then go for compounds
if (ctSolids == 0 && ctShells == 0) {
for (xp.Init(aShape, TopAbs_COMPOUND); xp.More(); xp.Next(), ctComps++)
for (xp.Init(aShape, TopAbs_COMPOUND); xp.More(); xp.Next(), ctComps++) {
#if OCC_VERSION_HEX >= 0x070800
this->myCompds[std::hash<TopoDS_Shape> {}(xp.Current())] = (xp.Current());
#else
this->myCompds[xp.Current().HashCode(INT_MAX)] = (xp.Current());
#endif
}
}
if (ctComps == 0) {
for (xp.Init(aShape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next())
for (xp.Init(aShape, TopAbs_FACE, TopAbs_SHELL); xp.More(); xp.Next()) {
#if OCC_VERSION_HEX >= 0x070800
this->myShapes[std::hash<TopoDS_Shape> {}(xp.Current())] = (xp.Current());
#else
this->myShapes[xp.Current().HashCode(INT_MAX)] = (xp.Current());
for (xp.Init(aShape, TopAbs_WIRE, TopAbs_FACE); xp.More(); xp.Next())
#endif
}
for (xp.Init(aShape, TopAbs_WIRE, TopAbs_FACE); xp.More(); xp.Next()) {
#if OCC_VERSION_HEX >= 0x070800
this->myShapes[std::hash<TopoDS_Shape> {}(xp.Current())] = (xp.Current());
#else
this->myShapes[xp.Current().HashCode(INT_MAX)] = (xp.Current());
for (xp.Init(aShape, TopAbs_EDGE, TopAbs_WIRE); xp.More(); xp.Next())
#endif
}
for (xp.Init(aShape, TopAbs_EDGE, TopAbs_WIRE); xp.More(); xp.Next()) {
#if OCC_VERSION_HEX >= 0x070800
this->myShapes[std::hash<TopoDS_Shape> {}(xp.Current())] = (xp.Current());
#else
this->myShapes[xp.Current().HashCode(INT_MAX)] = (xp.Current());
for (xp.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); xp.More(); xp.Next())
#endif
}
for (xp.Init(aShape, TopAbs_VERTEX, TopAbs_EDGE); xp.More(); xp.Next()) {
#if OCC_VERSION_HEX >= 0x070800
this->myShapes[std::hash<TopoDS_Shape> {}(xp.Current())] = (xp.Current());
#else
this->myShapes[xp.Current().HashCode(INT_MAX)] = (xp.Current());
#endif
}
}
}

Expand All @@ -634,7 +690,11 @@ void ImportXCAF::loadShapes(const TDF_Label& label)
hColors->GetColor(label, XCAFDoc_ColorSurf, col) ||
hColors->GetColor(label, XCAFDoc_ColorCurv, col)) {
// add defined color
#if OCC_VERSION_HEX >= 0x070800
myColorMap[std::hash<TopoDS_Shape> {}(aShape)] = col;
#else
myColorMap[aShape.HashCode(INT_MAX)] = col;
#endif
}
else {
// http://www.opencascade.org/org/forum/thread_17107/
Expand All @@ -644,7 +704,11 @@ void ImportXCAF::loadShapes(const TDF_Label& label)
hColors->GetColor(it.Value(), XCAFDoc_ColorSurf, col) ||
hColors->GetColor(it.Value(), XCAFDoc_ColorCurv, col)) {
// add defined color
#if OCC_VERSION_HEX >= 0x070800
myColorMap[std::hash<TopoDS_Shape> {}(it.Value())] = col;
#else
myColorMap[it.Value().HashCode(INT_MAX)] = col;
#endif
}
}
}
Expand All @@ -656,9 +720,14 @@ void ImportXCAF::loadShapes(const TDF_Label& label)
char* str = new char[extstr.LengthOfCString()+1];
extstr.ToUTF8CString(str);
std::string labelName(str);
if (!labelName.empty())
if (!labelName.empty()) {
#if OCC_VERSION_HEX >= 0x070800
myNameMap[std::hash<TopoDS_Shape> {}(aShape)] = labelName;
#else
myNameMap[aShape.HashCode(INT_MAX)] = labelName;
delete [] str;
#endif
}
delete[] str;
}

#if 0
Expand Down
Loading

0 comments on commit e2058f2

Please sign in to comment.