@bitbybit-dev/occt
Version:
Bit By Bit Developers CAD algorithms using OpenCascade Technology kernel. Run in Node and in Browser.
88 lines (87 loc) • 3.06 kB
JavaScript
export class ConverterService {
constructor(occ) {
this.occ = occ;
}
getActualTypeOfShape(shape) {
let result = shape;
if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.EDGE) {
result = this.occ.CastToEdge(shape);
}
else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.WIRE) {
result = this.occ.CastToWire(shape);
}
else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.VERTEX) {
result = this.occ.CastToVertex(shape);
}
else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.SOLID) {
result = this.occ.CastToSolid(shape);
}
else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.SHELL) {
result = this.occ.CastToShell(shape);
}
else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.FACE) {
result = this.occ.CastToFace(shape);
}
else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.COMPSOLID) {
result = this.occ.CastToCompSolid(shape);
}
else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.COMPOUND) {
result = this.occ.CastToCompound(shape);
}
else {
result = shape;
}
return result;
}
combineEdgesAndWiresIntoAWire(inputs) {
if (inputs.shapes === undefined) {
throw (Error(("Shapes are not defined")));
}
const makeWire = new this.occ.BRepBuilderAPI_MakeWire();
inputs.shapes.forEach((shape) => {
if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.EDGE) {
makeWire.AddEdge(shape);
}
else if (shape.ShapeType() === this.occ.TopAbs_ShapeEnum.WIRE) {
makeWire.AddWire(shape);
}
});
if (makeWire.IsDone()) {
const wire = makeWire.Wire();
this.occ.BRepLib_BuildCurves3d_Full(wire, 1.0e-7, this.occ.GeomAbs_Shape.C1, 14, 0);
makeWire.delete();
return wire;
}
else {
makeWire.delete();
throw new Error("Wire could not be constructed");
}
}
vertexToPoint(inputs) {
const pt = this.occ.BRep_Tool_Pnt(inputs.shape);
const res = [pt.X(), pt.Y(), pt.Z()];
pt.delete();
return res;
}
makeCompound(inputs) {
const builder = new this.occ.BRep_Builder();
const resCompound = this.occ.BRep_Builder_MakeCompound(builder);
inputs.shapes.forEach(shape => {
const s = this.occ.BRepBuilderAPI_Copy_Shape(shape, true);
builder.Add(resCompound, s);
s.delete();
});
builder.delete();
return resCompound;
}
makeCompoundIfNeeded(shapes, returnCompound) {
if (returnCompound) {
const compound = this.makeCompound({ shapes });
shapes.forEach(w => w.delete());
return compound;
}
else {
return shapes;
}
}
}