| 893 | |
| 894 | |
| 895 | static void ShapeFactory_createBoolean(_NAN_METHOD_ARGS, Solid* pSolid1, Solid* pSolid2, BOPAlgo_Operation op) |
| 896 | { |
| 897 | |
| 898 | const TopoDS_Shape& firstObject = pSolid1->shape(); |
| 899 | const TopoDS_Shape& secondObject = pSolid2->shape(); |
| 900 | |
| 901 | std::unique_ptr<BRepAlgoAPI_BooleanOperation> pTool; |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | TopoDS_Shape shape; |
| 907 | try { |
| 908 | switch (op) { |
| 909 | case BOPAlgo_FUSE: |
| 910 | pTool = std::unique_ptr<BRepAlgoAPI_BooleanOperation>(new BRepAlgoAPI_Fuse(firstObject, secondObject)); |
| 911 | break; |
| 912 | case BOPAlgo_CUT: |
| 913 | pTool = std::unique_ptr<BRepAlgoAPI_BooleanOperation>(new BRepAlgoAPI_Cut(firstObject, secondObject)); |
| 914 | break; |
| 915 | case BOPAlgo_COMMON: |
| 916 | pTool = std::unique_ptr<BRepAlgoAPI_BooleanOperation>(new BRepAlgoAPI_Common(firstObject, secondObject)); |
| 917 | break; |
| 918 | default: |
| 919 | Standard_ConstructionError::Raise("unknown operation"); |
| 920 | break; |
| 921 | } |
| 922 | if (!pTool->IsDone()) { |
| 923 | Standard_ConstructionError::Raise("operation failed"); |
| 924 | } |
| 925 | shape = pTool->Shape(); |
| 926 | |
| 927 | v8::Local<v8::Value> result(Solid::NewInstance(shape)); |
| 928 | |
| 929 | Solid* pResult = Nan::ObjectWrap::Unwrap<Solid>(Nan::To<v8::Object>(result).ToLocalChecked()); |
| 930 | |
| 931 | registerShapes(pTool.get(), pResult, pSolid1, pSolid2); |
| 932 | |
| 933 | if (pTool->HasDeleted()) { |
| 934 | // the boolean operation causes some shape from s1 or s2 to be deleted |
| 935 | } |
| 936 | if (pTool->HasGenerated()) { |
| 937 | // the boolean operation causes some shape from s1 or s2 to be created |
| 938 | |
| 939 | } |
| 940 | if (pTool->HasModified()) { |
| 941 | // the boolean operation causes some shape from s1 or s2 to be created |
| 942 | } |
| 943 | // check for empty compound shape |
| 944 | TopoDS_Iterator It(shape, Standard_True, Standard_True); |
| 945 | int found = 0; |
| 946 | for (; It.More(); It.Next()) { |
| 947 | found++; |
| 948 | } |
| 949 | if (found == 0) { |
| 950 | Standard_ConstructionError::Raise("result object is empty compound"); |
| 951 | } |
| 952 |
no test coverage detected