|
| 1 | +"use strict"; |
| 2 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 3 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 4 | +}; |
| 5 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 6 | +const should_1 = __importDefault(require("should")); |
| 7 | +const __1 = require(".."); |
| 8 | +const __2 = require(".."); |
| 9 | +const helpers_1 = require("./helpers"); |
| 10 | +const assert_1 = __importDefault(require("assert")); |
| 11 | +describe("testing BREP input output ", function () { |
| 12 | + let b1_brep; |
| 13 | + let b2_brep; |
| 14 | + let b3_brep; |
| 15 | + let b1_volume = 0; |
| 16 | + let b1_area = 0; |
| 17 | + before(() => { |
| 18 | + b1_brep = (0, helpers_1.getTemporaryFilePath)({ prefix: "b1_", suffix: ".brep" }); |
| 19 | + b2_brep = (0, helpers_1.getTemporaryFilePath)({ prefix: "b2_", suffix: ".brep" }); |
| 20 | + b3_brep = (0, helpers_1.getTemporaryFilePath)({ prefix: "b3_", suffix: ".brep" }); |
| 21 | + create_shapes(); |
| 22 | + }); |
| 23 | + after((done) => { |
| 24 | + (0, helpers_1.removeFile)(b1_brep); |
| 25 | + (0, helpers_1.removeFile)(b2_brep); |
| 26 | + (0, helpers_1.removeFile)(b3_brep); |
| 27 | + done(); |
| 28 | + }); |
| 29 | + function create_shapes() { |
| 30 | + let box = __2.occ.makeBox([0, 0, 0], [100, 200, 300]); |
| 31 | + let b1_result = __2.occ.writeBREP(b1_brep, box); |
| 32 | + b1_volume = box.volume; |
| 33 | + b1_area = box.area; |
| 34 | + let cyl = __2.occ.makeCylinder([0, 0, 0], [0, 0, 10], 5); |
| 35 | + let b2_result = __2.occ.writeBREP(b2_brep, cyl); |
| 36 | + let b3_result = __2.occ.writeBREP(b3_brep, [box, cyl]); |
| 37 | + b1_result.should.eql(true); |
| 38 | + b2_result.should.eql(true); |
| 39 | + b3_result.should.eql(true); |
| 40 | + } |
| 41 | + it("should write a simple shape", function () { |
| 42 | + create_shapes(); |
| 43 | + }); |
| 44 | + describe(" readBREP ", function () { |
| 45 | + it("ZZ1 - should throw an error if used with no argument", function () { |
| 46 | + (0, should_1.default)(function () { |
| 47 | + __2.occ.readBREP(null, (err) => { |
| 48 | + err.message.should.match(/expecting a filename/); |
| 49 | + }); |
| 50 | + }).throwError(); |
| 51 | + }); |
| 52 | + it("ZZ2 - should call the callback method with an error if used with an invalid arguments", (done) => { |
| 53 | + __2.occ.readBREP("||this is a invalid filename||", (err, _shapes) => { |
| 54 | + err.message.should.match(/cannot read/); |
| 55 | + done(); |
| 56 | + }); |
| 57 | + }); |
| 58 | + it("ZZ3 - should call the callback with an error if the file doesn't exist", (done) => { |
| 59 | + __2.occ.readBREP("invalid file name", (err, _shapes) => { |
| 60 | + console.log(" intercepting error ", err); |
| 61 | + (0, assert_1.default)(err !== undefined); |
| 62 | + done(); |
| 63 | + }); |
| 64 | + }); |
| 65 | + it("ZZ4 - should read the shape back", (done) => { |
| 66 | + __2.occ.readBREP(b1_brep, (err, shapes) => { |
| 67 | + (0, should_1.default)(err).eql(null); |
| 68 | + if (!err) { |
| 69 | + shapes.length.should.equal(1); |
| 70 | + shapes[0].numFaces.should.equal(6); |
| 71 | + shapes[0].volume.should.equal(b1_volume); |
| 72 | + shapes[0].area.should.equal(b1_area); |
| 73 | + } |
| 74 | + done(err); |
| 75 | + }); |
| 76 | + }); |
| 77 | + it("ZZ5 - should read the shape back", (done) => { |
| 78 | + __2.occ.readBREP(b2_brep, (err, shapes) => { |
| 79 | + if (!err) { |
| 80 | + shapes.length.should.equal(1); |
| 81 | + shapes[0].numFaces.should.equal(3); |
| 82 | + } |
| 83 | + done(err); |
| 84 | + }); |
| 85 | + }); |
| 86 | + it("ZZ6 - should read the shape back", (done) => { |
| 87 | + __2.occ.readBREP(b3_brep, function (err, shapes) { |
| 88 | + if (!err) { |
| 89 | + shapes.length.should.equal(2); |
| 90 | + shapes[0].numFaces.should.equal(6); |
| 91 | + shapes[1].numFaces.should.equal(3); |
| 92 | + } |
| 93 | + done(); |
| 94 | + }); |
| 95 | + }); |
| 96 | + }); |
| 97 | +}); |
| 98 | +function build_large_part() { |
| 99 | + let lego_filename = (0, helpers_1.getTemporaryFilePath)({ prefix: "legoPlate3x2_2x2", suffix: "" }); |
| 100 | + let legoPlate = (0, __1.makeLegoBrick)(__2.occ, 3, 2, "thin"); |
| 101 | + let solids = []; |
| 102 | + for (let x = 0; x < 100; x += 50) { |
| 103 | + for (let y = 0; y < 100; y += 50) { |
| 104 | + solids.push(legoPlate.translate([x, y, 0])); |
| 105 | + } |
| 106 | + } |
| 107 | + __2.occ.writeBREP(lego_filename + ".brep", solids); |
| 108 | + /* |
| 109 | + occ.writeSTL(lego_filename + ".stl", solids); |
| 110 | +
|
| 111 | + let obj = {solids: []}; |
| 112 | + let counter = 0; |
| 113 | + solids.forEach(function (solid) { |
| 114 | + solid.name = "S" + counter; |
| 115 | + counter++; |
| 116 | + obj.solids.push(occ.buildSolidMesh(solid)); |
| 117 | + }); |
| 118 | + fs.writeFile(lego_filename + ".3js", JSON.stringify(obj, null, ""), function (err) { |
| 119 | + console.log("OK"); |
| 120 | + }); |
| 121 | +
|
| 122 | + */ |
| 123 | + return lego_filename; |
| 124 | +} |
| 125 | +describe("it should write and read a large brep file", function () { |
| 126 | + this.timeout(15000); |
| 127 | + let filename = build_large_part(); |
| 128 | + it("should read a large BREP file quickly", (done) => { |
| 129 | + console.log(" lego file ", filename); |
| 130 | + __2.occ.readBREP(filename + ".brep", (err, solids) => { |
| 131 | + console.log(" read !!!"); |
| 132 | + if (!err) { |
| 133 | + console.log(" num Faces = ", solids[0].numFaces); |
| 134 | + } |
| 135 | + done(err); |
| 136 | + }); |
| 137 | + }); |
| 138 | +}); |
0 commit comments