@bitbybit-dev/occt-worker
Version:
Bit By Bit Developers CAD algorithms using OpenCascade Technology kernel adapted for WebWorker
144 lines (143 loc) • 5.52 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
export class OCCTIO {
constructor(occWorkerManager) {
this.occWorkerManager = occWorkerManager;
}
/**
* Saves the step file
* @param inputs STEP filename and shape to be saved
* @group io
* @shortname save step
* @drawable false
*/
saveShapeSTEP(inputs) {
return __awaiter(this, void 0, void 0, function* () {
this.saveSTEP(inputs);
});
}
/**
* Saves the step file and returns the text value
* @param inputs STEP filename and shape to be saved
* @group io
* @shortname save step and return
* @drawable false
*/
saveShapeSTEPAndReturn(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.saveSTEP(inputs);
});
}
/**
* Saves the stl file
* @param inputs STL filename and shape to be saved
* @group io
* @shortname save stl
* @drawable false
*/
saveShapeStl(inputs) {
return __awaiter(this, void 0, void 0, function* () {
this.saveStl(inputs);
});
}
/**
* Saves the stl file and returns
* @param inputs STL filename and shape to be saved
* @group io
* @shortname save stl return
* @drawable false
*/
saveShapeStlAndReturn(inputs) {
return __awaiter(this, void 0, void 0, function* () {
return this.saveStl(inputs);
});
}
saveSTEP(inputs) {
return this.occWorkerManager.genericCallToWorkerPromise("io.saveShapeSTEP", inputs).then(s => {
if (inputs.tryDownload && document) {
const blob = new Blob([s], { type: "text/plain" });
const blobUrl = URL.createObjectURL(blob);
let fileName = inputs.fileName ? inputs.fileName : "bitbybit-dev.step";
if (!fileName.toLowerCase().includes(".step")) {
fileName += ".step";
}
const fileLink = document.createElement("a");
fileLink.href = blobUrl;
fileLink.target = "_self";
fileLink.download = fileName;
fileLink.click();
fileLink.remove();
}
return s;
});
}
saveStl(inputs) {
return this.occWorkerManager.genericCallToWorkerPromise("io.saveShapeStl", inputs).then(s => {
if (inputs.tryDownload && document) {
const blob = new Blob([s], { type: "application/stl" });
const blobUrl = URL.createObjectURL(blob);
const fileName = inputs.fileName ? inputs.fileName : "bitbybit-dev.stl";
const fileLink = document.createElement("a");
fileLink.href = blobUrl;
fileLink.target = "_self";
fileLink.download = fileName;
fileLink.click();
fileLink.remove();
}
return s;
});
}
/**
* Creates DXF paths from an OCCT shape
* Important - shapes containing wires must lie on XZ plane (Y=0) for correct 2D DXF export.
* @param inputs Shape to convert to DXF paths
* @group dxf
* @shortname shape to dxf paths
* @drawable false
*/
shapeToDxfPaths(inputs) {
return this.occWorkerManager.genericCallToWorkerPromise("io.shapeToDxfPaths", inputs);
}
/**
* Adds layer and color information to DXF paths
* Important - shapes containing wires must lie on XZ plane (Y=0) for correct 2D DXF export.
* @param inputs DXF paths, layer name, and color
* @group dxf
* @shortname dxf paths with layer
* @drawable false
*/
dxfPathsWithLayer(inputs) {
return this.occWorkerManager.genericCallToWorkerPromise("io.dxfPathsWithLayer", inputs);
}
/**
* Assembles multiple path parts into a complete DXF file.
* Important - shapes containing wires must lie on XZ plane (Y=0) for correct 2D DXF export.
* @param inputs Multiple DXF paths parts
* @group dxf
* @shortname dxf create
* @drawable false
*/
dxfCreate(inputs) {
return this.occWorkerManager.genericCallToWorkerPromise("io.dxfCreate", inputs).then(s => {
if (inputs.tryDownload && document) {
const blob = new Blob([s], { type: "application/stl" });
const blobUrl = URL.createObjectURL(blob);
const fileName = inputs.fileName ? inputs.fileName : "bitbybit-dev.dxf";
const fileLink = document.createElement("a");
fileLink.href = blobUrl;
fileLink.target = "_self";
fileLink.download = fileName;
fileLink.click();
fileLink.remove();
}
return s;
});
}
}