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;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,6 @@ private:
|
||||
bool merge {true};
|
||||
std::string default_name;
|
||||
std::set<int> myRefShapes;
|
||||
static const int HashUpper = INT_MAX;
|
||||
};
|
||||
|
||||
class ImportExport ImportOCAFCmd: public ImportOCAF
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Part/App/ShapeMapHasher.h>
|
||||
|
||||
#include "ImportOCAFAssembly.h"
|
||||
|
||||
@@ -109,7 +110,7 @@ void ImportOCAFAssembly::loadShapes(const TDF_Label& label,
|
||||
int hash = 0;
|
||||
TopoDS_Shape aShape;
|
||||
if (aShapeTool->GetShape(label, aShape)) {
|
||||
hash = aShape.HashCode(HashUpper);
|
||||
hash = Part::ShapeMapHasher {}(aShape);
|
||||
}
|
||||
|
||||
Handle(TDataStd_Name) name;
|
||||
@@ -192,7 +193,7 @@ void ImportOCAFAssembly::loadShapes(const TDF_Label& label,
|
||||
if (isRef || myRefShapes.find(hash) == myRefShapes.end()) {
|
||||
TopoDS_Shape aShape;
|
||||
if (isRef && aShapeTool->GetShape(label, aShape)) {
|
||||
myRefShapes.insert(aShape.HashCode(HashUpper));
|
||||
myRefShapes.insert(Part::ShapeMapHasher {}(aShape));
|
||||
}
|
||||
|
||||
if (aShapeTool->IsSimpleShape(label) && (isRef || aShapeTool->IsFree(label))) {
|
||||
|
||||
@@ -86,7 +86,6 @@ private:
|
||||
Handle(XCAFDoc_ColorTool) aColorTool;
|
||||
std::string default_name;
|
||||
std::set<int> myRefShapes;
|
||||
static const int HashUpper = INT_MAX;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
|
||||
#include "ImportStep.h"
|
||||
#include "encodeFilename.h"
|
||||
#include "ShapeMapHasher.h"
|
||||
#include "PartFeature.h"
|
||||
#include "ProgressIndicator.h"
|
||||
|
||||
@@ -137,12 +138,7 @@ int Part::ImportStepParts(App::Document *pcDoc, const char* Name)
|
||||
// This is a trick to access the GUI via Python and set the color property
|
||||
// of the associated view provider. If no GUI is up an exception is thrown
|
||||
// and cleared immediately
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
std::hash<TopoDS_Solid> hasher;
|
||||
std::map<int, Quantity_Color>::iterator it = hash_col.find(hasher(aSolid));
|
||||
#else
|
||||
std::map<int, Quantity_Color>::iterator it = hash_col.find(aSolid.HashCode(INT_MAX));
|
||||
#endif
|
||||
std::map<int, Quantity_Color>::iterator it = hash_col.find(ShapeMapHasher{}(aSolid));
|
||||
if (it != hash_col.end()) {
|
||||
try {
|
||||
Py::Object obj(pcFeature->getPyObject(), true);
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
|
||||
#include "OCCError.h"
|
||||
#include "PartPyCXX.h"
|
||||
#include "ShapeMapHasher.h"
|
||||
|
||||
|
||||
using namespace Part;
|
||||
@@ -1306,11 +1307,7 @@ PyObject* TopoShapePy::ancestorsOfType(PyObject *args)
|
||||
TopTools_ListIteratorOfListOfShape it(ancestors);
|
||||
for (; it.More(); it.Next()) {
|
||||
// make sure to avoid duplicates
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
const size_t code = std::hash<TopoDS_Shape>{}(static_cast<TopoDS_Shape>(it.Value()));
|
||||
#else
|
||||
Standard_Integer code = it.Value().HashCode(INT_MAX);
|
||||
#endif
|
||||
Standard_Integer code = ShapeMapHasher{}(it.Value());
|
||||
if (hashes.find(code) == hashes.end()) {
|
||||
list.append(shape2pyshape(it.Value()));
|
||||
hashes.insert(code);
|
||||
@@ -1932,11 +1929,7 @@ PyObject* TopoShapePy::hashCode(PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "|i",&upper))
|
||||
return nullptr;
|
||||
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
int hc = std::hash<TopoDS_Shape>{}(getTopoShapePtr()->getShape());
|
||||
#else
|
||||
int hc = getTopoShapePtr()->getShape().HashCode(upper);
|
||||
#endif
|
||||
int hc = ShapeMapHasher{}(getTopoShapePtr()->getShape());
|
||||
return Py_BuildValue("i", hc);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
#include <Gui/SoFCSelectionAction.h>
|
||||
#include <Gui/SoFCUnifiedSelection.h>
|
||||
#include <Gui/ViewParams.h>
|
||||
#include <Mod/Part/App/ShapeMapHasher.h>
|
||||
#include <Mod/Part/App/Tools.h>
|
||||
|
||||
#include "ViewProviderExt.h"
|
||||
@@ -981,12 +982,9 @@ void ViewProviderPartExt::updateVisual()
|
||||
}
|
||||
|
||||
TopExp_Explorer xp;
|
||||
for (xp.Init(faceMap(i),TopAbs_EDGE);xp.More();xp.Next())
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
faceEdges.insert(std::hash<TopoDS_Shape>{}(xp.Current()));
|
||||
#else
|
||||
faceEdges.insert(xp.Current().HashCode(INT_MAX));
|
||||
#endif
|
||||
for (xp.Init(faceMap(i),TopAbs_EDGE);xp.More();xp.Next()) {
|
||||
faceEdges.insert(Part::ShapeMapHasher{}(xp.Current()));
|
||||
}
|
||||
numFaces++;
|
||||
}
|
||||
|
||||
@@ -1014,11 +1012,7 @@ void ViewProviderPartExt::updateVisual()
|
||||
// So, we have to store the hashes of the edges associated to a face.
|
||||
// If the hash of a given edge is not in this list we know it's really
|
||||
// a free edge.
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
int hash = std::hash<TopoDS_Shape>{}(aEdge);
|
||||
#else
|
||||
int hash = aEdge.HashCode(INT_MAX);
|
||||
#endif
|
||||
int hash = Part::ShapeMapHasher{}(aEdge);
|
||||
if (faceEdges.find(hash) == faceEdges.end()) {
|
||||
Handle(Poly_Polygon3D) aPoly = Part::Tools::polygonOfEdge(aEdge, aLoc);
|
||||
if (!aPoly.IsNull()) {
|
||||
@@ -1217,11 +1211,7 @@ void ViewProviderPartExt::updateVisual()
|
||||
TopLoc_Location aLoc;
|
||||
|
||||
// handling of the free edge that are not associated to a face
|
||||
#if OCC_VERSION_HEX >= 0x070800
|
||||
int hash = std::hash<TopoDS_Shape>{}(aEdge);
|
||||
#else
|
||||
int hash = aEdge.HashCode(INT_MAX);
|
||||
#endif
|
||||
int hash = Part::ShapeMapHasher{}(aEdge);
|
||||
if (faceEdges.find(hash) == faceEdges.end()) {
|
||||
Handle(Poly_Polygon3D) aPoly = Part::Tools::polygonOfEdge(aEdge, aLoc);
|
||||
if (!aPoly.IsNull()) {
|
||||
|
||||
Reference in New Issue
Block a user