Part: use of ShapeMapHasher for code simplification
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Mod/Part/App/FeatureCompound.h>
|
||||
#include <Mod/Part/App/ShapeMapHasher.h>
|
||||
|
||||
#include "ImportOCAF.h"
|
||||
|
||||
@@ -151,11 +152,7 @@ void ImportOCAF::loadShapes(const TDF_Label& label,
|
||||
std::vector<App::DocumentObject*> localValue;
|
||||
|
||||
if (aShapeTool->GetShape(label, aShape)) {
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
hash = std::hash<TopoDS_Shape> {}(aShape);
|
||||
#else
|
||||
hash = aShape.HashCode(HashUpper);
|
||||
#endif
|
||||
hash = Part::ShapeMapHasher {}(aShape);
|
||||
}
|
||||
|
||||
Handle(TDataStd_Name) name;
|
||||
@@ -227,11 +224,7 @@ void ImportOCAF::loadShapes(const TDF_Label& label,
|
||||
if (isRef || myRefShapes.find(hash) == myRefShapes.end()) {
|
||||
TopoDS_Shape 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
|
||||
myRefShapes.insert(Part::ShapeMapHasher {}(aShape));
|
||||
}
|
||||
|
||||
if (aShapeTool->IsSimpleShape(label) && (isRef || aShapeTool->IsFree(label))) {
|
||||
@@ -558,11 +551,7 @@ 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
|
||||
jt = myColorMap.find(Part::ShapeMapHasher {}(shape));
|
||||
|
||||
App::Color partColor(0.8f, 0.8f, 0.8f);
|
||||
#if 0 // TODO
|
||||
@@ -583,11 +572,7 @@ 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
|
||||
jt = myNameMap.find(Part::ShapeMapHasher {}(shape));
|
||||
if (jt != myNameMap.end()) {
|
||||
part->Label.setValue(jt->second);
|
||||
}
|
||||
@@ -607,11 +592,7 @@ 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
|
||||
jt = myColorMap.find(Part::ShapeMapHasher {}(xp.Current()));
|
||||
if (jt != myColorMap.end()) {
|
||||
int index = faces.FindIndex(xp.Current());
|
||||
faceColors[index - 1] = convertColor(jt->second);
|
||||
@@ -646,57 +627,29 @@ void ImportXCAF::loadShapes(const TDF_Label& label)
|
||||
// add the shapes
|
||||
TopExp_Explorer xp;
|
||||
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());
|
||||
#endif
|
||||
this->mySolids[Part::ShapeMapHasher {}(xp.Current())] = (xp.Current());
|
||||
}
|
||||
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
|
||||
this->myShells[Part::ShapeMapHasher {}(xp.Current())] = (xp.Current());
|
||||
}
|
||||
// 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++) {
|
||||
#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
|
||||
this->myCompds[Part::ShapeMapHasher {}(xp.Current())] = (xp.Current());
|
||||
}
|
||||
}
|
||||
if (ctComps == 0) {
|
||||
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());
|
||||
#endif
|
||||
this->myShapes[Part::ShapeMapHasher {}(xp.Current())] = (xp.Current());
|
||||
}
|
||||
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());
|
||||
#endif
|
||||
this->myShapes[Part::ShapeMapHasher {}(xp.Current())] = (xp.Current());
|
||||
}
|
||||
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());
|
||||
#endif
|
||||
this->myShapes[Part::ShapeMapHasher {}(xp.Current())] = (xp.Current());
|
||||
}
|
||||
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
|
||||
this->myShapes[Part::ShapeMapHasher {}(xp.Current())] = (xp.Current());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -707,11 +660,7 @@ 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
|
||||
myColorMap[Part::ShapeMapHasher {}(aShape)] = col;
|
||||
}
|
||||
else {
|
||||
// http://www.opencascade.org/org/forum/thread_17107/
|
||||
@@ -721,11 +670,7 @@ 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
|
||||
myColorMap[Part::ShapeMapHasher {}(it.Value())] = col;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,11 +683,7 @@ void ImportXCAF::loadShapes(const TDF_Label& label)
|
||||
extstr.ToUTF8CString(str);
|
||||
std::string labelName(str);
|
||||
if (!labelName.empty()) {
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
myNameMap[std::hash<TopoDS_Shape> {}(aShape)] = labelName;
|
||||
#else
|
||||
myNameMap[aShape.HashCode(INT_MAX)] = labelName;
|
||||
#endif
|
||||
myNameMap[Part::ShapeMapHasher {}(aShape)] = labelName;
|
||||
}
|
||||
delete[] str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user