@bitbybit-dev/occt
Version:
Bit By Bit Developers CAD algorithms using OpenCascade Technology kernel. Run in Node and in Browser.
100 lines (99 loc) • 5.06 kB
JavaScript
export class IteratorService {
constructor(occ) {
this.occ = occ;
}
forEachWire(shape, callback) {
let wireIndex = 0;
const anExplorer = new this.occ.TopExp_Explorer(shape, this.occ.TopAbs_ShapeEnum.WIRE, this.occ.TopAbs_ShapeEnum.SHAPE);
for (anExplorer.Init(shape, this.occ.TopAbs_ShapeEnum.WIRE, this.occ.TopAbs_ShapeEnum.SHAPE); anExplorer.More(); anExplorer.Next()) {
callback(wireIndex++, this.occ.CastToWire(anExplorer.Current()));
}
anExplorer.delete();
}
forEachEdge(shape, callback) {
const edgeHashes = {};
let edgeIndex = 0;
const anExplorer = new this.occ.TopExp_Explorer(shape, this.occ.TopAbs_ShapeEnum.EDGE, this.occ.TopAbs_ShapeEnum.SHAPE);
for (anExplorer.Init(shape, this.occ.TopAbs_ShapeEnum.EDGE, this.occ.TopAbs_ShapeEnum.SHAPE); anExplorer.More(); anExplorer.Next()) {
const edge = this.occ.CastToEdge(anExplorer.Current());
const edgeHash = this.occ.TopoDS_Shape_HashCode(edge, 100000000);
if (!Object.prototype.hasOwnProperty.call(edgeHashes, edgeHash)) {
edgeHashes[edgeHash] = edgeIndex;
callback(edgeIndex++, edge);
}
}
anExplorer.delete();
return edgeHashes;
}
forEachEdgeAlongWire(shape, callback) {
const edgeHashes = {};
let edgeIndex = 0;
const anExplorer = new this.occ.BRepTools_WireExplorer(shape);
for ( /* initialized in constructor */; anExplorer.More(); anExplorer.Next()) {
const edge = this.occ.CastToEdge(anExplorer.Current());
const edgeHash = this.occ.TopoDS_Shape_HashCode(edge, 100000000);
if (!Object.prototype.hasOwnProperty.call(edgeHashes, edgeHash)) {
edgeHashes[edgeHash] = edgeIndex;
callback(edgeIndex++, edge);
}
}
anExplorer.delete();
return edgeHashes;
}
forEachFace(shape, callback) {
let faceIndex = 0;
const anExplorer = new this.occ.TopExp_Explorer(shape, this.occ.TopAbs_ShapeEnum.FACE, this.occ.TopAbs_ShapeEnum.SHAPE);
for (anExplorer.Init(shape, this.occ.TopAbs_ShapeEnum.FACE, this.occ.TopAbs_ShapeEnum.SHAPE); anExplorer.More(); anExplorer.Next()) {
callback(faceIndex++, this.occ.CastToFace(anExplorer.Current()));
}
anExplorer.delete();
}
forEachShell(shape, callback) {
let shellIndex = 0;
const anExplorer = new this.occ.TopExp_Explorer(shape, this.occ.TopAbs_ShapeEnum.SHELL, this.occ.TopAbs_ShapeEnum.SHAPE);
for (anExplorer.Init(shape, this.occ.TopAbs_ShapeEnum.SHELL, this.occ.TopAbs_ShapeEnum.SHAPE); anExplorer.More(); anExplorer.Next()) {
callback(shellIndex++, this.occ.CastToShell(anExplorer.Current()));
}
anExplorer.delete();
}
forEachVertex(shape, callback) {
let vertexIndex = 0;
const anExplorer = new this.occ.TopExp_Explorer(shape, this.occ.TopAbs_ShapeEnum.VERTEX, this.occ.TopAbs_ShapeEnum.SHAPE);
for (anExplorer.Init(shape, this.occ.TopAbs_ShapeEnum.VERTEX, this.occ.TopAbs_ShapeEnum.SHAPE); anExplorer.More(); anExplorer.Next()) {
callback(vertexIndex++, this.occ.CastToVertex(anExplorer.Current()));
}
anExplorer.delete();
}
forEachSolid(shape, callback) {
let solidIndex = 0;
const anExplorer = new this.occ.TopExp_Explorer(shape, this.occ.TopAbs_ShapeEnum.SOLID, this.occ.TopAbs_ShapeEnum.SHAPE);
for (anExplorer.Init(shape, this.occ.TopAbs_ShapeEnum.SOLID, this.occ.TopAbs_ShapeEnum.SHAPE); anExplorer.More(); anExplorer.Next()) {
callback(solidIndex++, this.occ.CastToSolid(anExplorer.Current()));
}
anExplorer.delete();
}
forEachCompound(shape, callback) {
let compoundIndex = 0;
const anExplorer = new this.occ.TopExp_Explorer(shape, this.occ.TopAbs_ShapeEnum.COMPOUND, this.occ.TopAbs_ShapeEnum.SHAPE);
for (anExplorer.Init(shape, this.occ.TopAbs_ShapeEnum.COMPOUND, this.occ.TopAbs_ShapeEnum.SHAPE); anExplorer.More(); anExplorer.Next()) {
callback(compoundIndex++, anExplorer.Current());
}
anExplorer.delete();
}
forEachCompSolid(shape, callback) {
let compSolidIndex = 0;
const anExplorer = new this.occ.TopExp_Explorer(shape, this.occ.TopAbs_ShapeEnum.COMPSOLID, this.occ.TopAbs_ShapeEnum.SHAPE);
for (anExplorer.Init(shape, this.occ.TopAbs_ShapeEnum.COMPSOLID, this.occ.TopAbs_ShapeEnum.SHAPE); anExplorer.More(); anExplorer.Next()) {
callback(compSolidIndex++, anExplorer.Current());
}
anExplorer.delete();
}
forEachShapeInCompound(shape, callback) {
let shapeIndex = 0;
const iterator = new this.occ.TopoDS_Iterator(shape);
for ( /* initialized in constructor */; iterator.More(); iterator.Next()) {
callback(shapeIndex++, iterator.Value());
}
iterator.delete();
}
}