3737#include " BRepAlgoAPI_Cut.hxx"
3838#include " BRepAlgoAPI_Common.hxx"
3939
40+ #include " XCAFDoc_DocumentTool.hxx"
41+ #include " TDocStd_Document.hxx"
42+ #include " XCAFDoc_ShapeTool.hxx"
43+ #include " XCAFDoc_ShapeMapTool.hxx"
44+ #include " TDataStd_Name.hxx"
45+
4046// =====================================================================
4147// boolean operations
4248// op=0 (fuse), 1 (cut), 2 (common)
@@ -51,11 +57,9 @@ PyObject* K_OCC::boolean(PyObject* self, PyObject* args)
5157 GETPACKET;
5258 GETSHAPE;
5359 GETMAPSURFACES;
54-
55- E_Int nfaces1 = PyList_Size (listFaces1);
56- E_Int nfaces2 = PyList_Size (listFaces2);
5760
5861 // Get compound1
62+ E_Int nfaces1 = PyList_Size (listFaces1);
5963 BRep_Builder builder1;
6064 TopoDS_Compound compound1;
6165 builder1.MakeCompound (compound1);
@@ -76,6 +80,7 @@ PyObject* K_OCC::boolean(PyObject* self, PyObject* args)
7680 if (rev1 == 1 ) solid1 = TopoDS::Solid (solid1.Reversed ());
7781
7882 // Get compound2
83+ E_Int nfaces2 = PyList_Size (listFaces2);
7984 BRep_Builder builder2;
8085 TopoDS_Compound compound2;
8186 builder2.MakeCompound (compound2);
@@ -104,15 +109,60 @@ PyObject* K_OCC::boolean(PyObject* self, PyObject* args)
104109 // unify.Build();
105110 // TopoDS_Shape unified = unify.Shape();
106111
112+ #ifdef USEXCAF
113+
114+ GETDOC;
115+ GETSHAPETOOL;
116+
117+ // suppress somes faces
118+ std::map< E_Int, std::vector<E_Int> > label2Faces;
119+ std::map< E_Int, std::vector<E_Int> > label2Edges;
120+ getLabel2Edges (*doc, label2Edges);
121+ getLabel2Faces (*doc, label2Faces);
122+
123+ for (E_Int i = 0 ; i < PyList_Size (listFaces1); i++)
124+ {
125+ PyObject* noFaceO = PyList_GetItem (listFaces1, i);
126+ E_Int noFace = PyInt_AsLong (noFaceO);
127+ for (size_t j = 0 ; j < label2Faces.size (); j++)
128+ {
129+ std::vector< E_Int >& f = label2Faces[j];
130+ f.erase (std::remove (f.begin (), f.end (), noFace), f.end ());
131+ }
132+ }
133+ for (E_Int i = 0 ; i < PyList_Size (listFaces2); i++)
134+ {
135+ PyObject* noFaceO = PyList_GetItem (listFaces2, i);
136+ E_Int noFace = PyInt_AsLong (noFaceO);
137+ for (size_t j = 0 ; j < label2Faces.size (); j++)
138+ {
139+ std::vector< E_Int >& f = label2Faces[j];
140+ f.erase (std::remove (f.begin (), f.end (), noFace), f.end ());
141+ }
142+ }
143+ copyTopShape2OCAF (*shape, label2Edges, label2Faces, *doc);
144+
145+ // Add compound3 as a new shape
146+ TDF_Label label = shapeTool->AddShape (result);
147+ TDataStd_Name::Set (label, " boolean" );
148+
149+ // back copy
150+ TopoDS_Shape* newshp = copyOCAF2TopShape (*doc);
151+ delete shape;
152+ SETSHAPE (newshp);
153+ Py_INCREF (Py_None);
154+ return Py_None;
155+
156+ #else
157+
107158 TopoDS_Shape* newshp = new TopoDS_Shape (result);
108-
109- // Rebuild the hook
110159 delete shape;
111160 SETSHAPE (newshp);
112161
113- printf (" INFO: after boolUnion : Nb edges=%d\n " , se->Extent ());
114- printf (" INFO: after boolUnion : Nb faces=%d\n " , sf->Extent ());
162+ printf (" INFO: after boolean : Nb edges=%d\n " , se->Extent ());
163+ printf (" INFO: after boolean : Nb faces=%d\n " , sf->Extent ());
115164
116165 Py_INCREF (Py_None);
117166 return Py_None;
167+ #endif
118168}
0 commit comments