| 89 | Nan::Persistent<v8::FunctionTemplate> Face::_template; |
| 90 | |
| 91 | bool Face::buildFace(std::vector<Wire*>& wires) |
| 92 | { |
| 93 | if (wires.size()==0) return false; |
| 94 | |
| 95 | // checling that all wires are closed |
| 96 | for (uint32_t i = 0; i < wires.size(); i++) { |
| 97 | if (!wires[i]->isClosed()) { |
| 98 | Nan::ThrowError("Some of the wires are not closed"); |
| 99 | return false; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | try { |
| 104 | const TopoDS_Wire& outerwire = wires[0]->wire(); |
| 105 | |
| 106 | BRepBuilderAPI_MakeFace MF(outerwire); |
| 107 | |
| 108 | // add optional holes |
| 109 | for (unsigned i = 1; i < wires.size(); i++) { |
| 110 | const TopoDS_Wire& wire = wires[i]->wire(); |
| 111 | |
| 112 | if (wire.Orientation() != outerwire.Orientation()) { |
| 113 | MF.Add(TopoDS::Wire(wire.Reversed())); |
| 114 | } else { |
| 115 | MF.Add(wire); |
| 116 | } |
| 117 | } |
| 118 | this->setShape(MF.Shape()); |
| 119 | |
| 120 | // possible fix shape |
| 121 | if (!this->fixShape()) { |
| 122 | StdFail_NotDone::Raise("Shapes not valid"); |
| 123 | } |
| 124 | |
| 125 | } |
| 126 | CATCH_AND_RETHROW_NO_RETURN("Failed to create a face"); |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | NAN_METHOD(Face::NewInstance) { _NewInstance<Face>(info); } |
| 131 | |