3 #include "GEOMImpl_IBooleanOperations.hxx"
5 #include "GEOM_Function.hxx"
6 #include "GEOMImpl_Types.hxx"
8 #include "GEOMImpl_BooleanDriver.hxx"
9 #include "GEOMImpl_IBoolean.hxx"
11 #include "GEOMImpl_PartitionDriver.hxx"
12 #include "GEOMImpl_IPartition.hxx"
14 #include <TDF_Tool.hxx>
16 #include "utilities.h"
18 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
20 //=============================================================================
24 //=============================================================================
25 GEOMImpl_IBooleanOperations::GEOMImpl_IBooleanOperations (GEOM_Engine* theEngine, int theDocID)
26 : GEOM_IOperations(theEngine, theDocID)
28 MESSAGE("GEOMImpl_IBooleanOperations::GEOMImpl_IBooleanOperations");
31 //=============================================================================
35 //=============================================================================
36 GEOMImpl_IBooleanOperations::~GEOMImpl_IBooleanOperations()
38 MESSAGE("GEOMImpl_IBooleanOperations::~GEOMImpl_IBooleanOperations");
42 //=============================================================================
46 //=============================================================================
47 Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeBoolean (Handle(GEOM_Object) theShape1,
48 Handle(GEOM_Object) theShape2,
49 Standard_Integer theOp)
53 if (theShape1.IsNull() || theShape2.IsNull()) return NULL;
55 //Add a new Boolean object
56 Handle(GEOM_Object) aBool = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN);
58 //Add a new Boolean function
59 Handle(GEOM_Function) aFunction;
61 aFunction = aBool->AddFunction(GEOMImpl_BooleanDriver::GetID(), BOOLEAN_COMMON);
62 } else if (theOp == 2) {
63 aFunction = aBool->AddFunction(GEOMImpl_BooleanDriver::GetID(), BOOLEAN_CUT);
64 } else if (theOp == 3) {
65 aFunction = aBool->AddFunction(GEOMImpl_BooleanDriver::GetID(), BOOLEAN_FUSE);
66 } else if (theOp == 4) {
67 aFunction = aBool->AddFunction(GEOMImpl_BooleanDriver::GetID(), BOOLEAN_SECTION);
70 if (aFunction.IsNull()) return NULL;
72 //Check if the function is set correctly
73 if (aFunction->GetDriverGUID() != GEOMImpl_BooleanDriver::GetID()) return NULL;
75 GEOMImpl_IBoolean aCI (aFunction);
77 Handle(GEOM_Function) aRef1 = theShape1->GetLastFunction();
78 Handle(GEOM_Function) aRef2 = theShape2->GetLastFunction();
80 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
85 //Compute the Boolean value
87 if (!GetSolver()->ComputeFunction(aFunction)) {
88 SetErrorCode("Boolean driver failed");
92 catch (Standard_Failure) {
93 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
94 SetErrorCode(aFail->GetMessageString());
98 //Make a Python command
99 TCollection_AsciiString anEntry, aDescr("");
100 TDF_Tool::Entry(aBool->GetEntry(), anEntry);
102 aDescr += " = IBooleanOperations.MakeBoolean(";
103 TDF_Tool::Entry(theShape1->GetEntry(), anEntry);
104 aDescr += (anEntry+", ");
105 TDF_Tool::Entry(theShape2->GetEntry(), anEntry);
106 aDescr += (anEntry+", ");
107 aDescr += (TCollection_AsciiString(theOp)+")");
109 aFunction->SetDescription(aDescr);
115 //=============================================================================
119 //=============================================================================
120 Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakePartition
121 (const Handle(TColStd_HSequenceOfTransient)& theShapes,
122 const Handle(TColStd_HSequenceOfTransient)& theTools,
123 const Handle(TColStd_HSequenceOfTransient)& theKeepIns,
124 const Handle(TColStd_HSequenceOfTransient)& theRemoveIns,
125 const Standard_Integer theLimit,
126 const Standard_Boolean theRemoveWebs,
127 const Handle(TColStd_HArray1OfInteger)& theMaterials)
131 //Add a new Partition object
132 Handle(GEOM_Object) aPartition = GetEngine()->AddObject(GetDocID(), GEOM_PARTITION);
134 //Add a new Partition function
135 Handle(GEOM_Function) aFunction =
136 aPartition->AddFunction(GEOMImpl_PartitionDriver::GetID(), PARTITION_PARTITION);
137 if (aFunction.IsNull()) return NULL;
139 //Check if the function is set correctly
140 if (aFunction->GetDriverGUID() != GEOMImpl_PartitionDriver::GetID()) return NULL;
142 GEOMImpl_IPartition aCI (aFunction);
144 // int aLen = theShapes.size();
145 // aCI.SetLength(aLen);
147 Handle(TColStd_HSequenceOfTransient) aShapesSeq = new TColStd_HSequenceOfTransient;
148 Handle(TColStd_HSequenceOfTransient) aToolsSeq = new TColStd_HSequenceOfTransient;
149 Handle(TColStd_HSequenceOfTransient) aKeepInsSeq = new TColStd_HSequenceOfTransient;
150 Handle(TColStd_HSequenceOfTransient) aRemInsSeq = new TColStd_HSequenceOfTransient;
152 Standard_Integer ind, aLen;
153 TCollection_AsciiString anEntry;
154 TCollection_AsciiString aShapesDescr, aToolsDescr, aKeepInsDescr, aRemoveInsDescr;
157 aLen = theShapes->Length();
158 for (ind = 1; ind <= aLen; ind++) {
159 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theShapes->Value(ind));
160 Handle(GEOM_Function) aRefSh = anObj->GetLastFunction();
161 if (aRefSh.IsNull()) {
162 SetErrorCode("NULL shape for Partition");
165 aShapesSeq->Append(aRefSh);
167 // For Python command
168 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
169 if (ind > 1) aShapesDescr += ", ";
170 aShapesDescr += anEntry;
172 aCI.SetShapes(aShapesSeq);
175 aLen = theTools->Length();
176 for (ind = 1; ind <= aLen; ind++) {
177 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theTools->Value(ind));
178 Handle(GEOM_Function) aRefSh = anObj->GetLastFunction();
179 if (aRefSh.IsNull()) {
180 SetErrorCode("NULL tool shape for Partition");
183 aToolsSeq->Append(aRefSh);
185 // For Python command
186 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
187 if (ind > 1) aToolsDescr += ", ";
188 aToolsDescr += anEntry;
190 aCI.SetTools(aToolsSeq);
193 aLen = theKeepIns->Length();
194 for (ind = 1; ind <= aLen; ind++) {
195 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theKeepIns->Value(ind));
196 Handle(GEOM_Function) aRefSh = anObj->GetLastFunction();
197 if (aRefSh.IsNull()) {
198 SetErrorCode("NULL <keep inside> shape for Partition");
201 aKeepInsSeq->Append(aRefSh);
203 // For Python command
204 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
205 if (ind > 1) aKeepInsDescr += ", ";
206 aKeepInsDescr += anEntry;
208 aCI.SetKeepIns(aKeepInsSeq);
211 aLen = theRemoveIns->Length();
212 for (ind = 1; ind <= aLen; ind++) {
213 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theRemoveIns->Value(ind));
214 Handle(GEOM_Function) aRefSh = anObj->GetLastFunction();
215 if (aRefSh.IsNull()) {
216 SetErrorCode("NULL <remove inside> shape for Partition");
219 aRemInsSeq->Append(aRefSh);
221 // For Python command
222 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
223 if (ind > 1) aRemoveInsDescr += ", ";
224 aRemoveInsDescr += anEntry;
226 aCI.SetRemoveIns(aRemInsSeq);
229 aCI.SetLimit(theLimit);
233 if (theMaterials.IsNull()) {
234 Handle(TColStd_HArray1OfInteger) aMaterials =
235 new TColStd_HArray1OfInteger (1, aShapesSeq->Length());
236 aCI.SetMaterials(aMaterials);
238 aCI.SetMaterials(theMaterials);
242 //Compute the Partition
244 if (!GetSolver()->ComputeFunction(aFunction)) {
245 SetErrorCode("Partition driver failed");
249 catch (Standard_Failure) {
250 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
251 SetErrorCode(aFail->GetMessageString());
255 //Make a Python command
256 TCollection_AsciiString aDescr;
257 TDF_Tool::Entry(aPartition->GetEntry(), anEntry);
259 aDescr += " = IBooleanOperations.MakePartition([";
261 aDescr += aShapesDescr + "], [";
263 aDescr += aToolsDescr + "], [";
265 aDescr += aKeepInsDescr + "], [";
267 aDescr += aRemoveInsDescr + "], ";
269 aDescr += TCollection_AsciiString(theLimit) + ", ";
271 if (theRemoveWebs) aDescr += "1, [";
272 else aDescr += "0, [";
274 if (theMaterials->Length() > 0) {
275 int i = theMaterials->Lower();
276 aDescr += TCollection_AsciiString(theMaterials->Value(i));
278 for (; i <= theMaterials->Upper(); i++) {
280 aDescr += TCollection_AsciiString(theMaterials->Value(i));
285 aFunction->SetDescription(aDescr);
291 //=============================================================================
295 //=============================================================================
296 Handle(GEOM_Object) GEOMImpl_IBooleanOperations::MakeHalfPartition
297 (Handle(GEOM_Object) theShape, Handle(GEOM_Object) thePlane)
301 if (theShape.IsNull() || thePlane.IsNull()) return NULL;
303 //Add a new Boolean object
304 Handle(GEOM_Object) aPart = GetEngine()->AddObject(GetDocID(), GEOM_BOOLEAN);
306 //Add a new Partition function
307 Handle(GEOM_Function) aFunction =
308 aPart->AddFunction(GEOMImpl_PartitionDriver::GetID(), PARTITION_HALF);
309 if (aFunction.IsNull()) return NULL;
311 //Check if the function is set correctly
312 if (aFunction->GetDriverGUID() != GEOMImpl_PartitionDriver::GetID()) return NULL;
314 GEOMImpl_IPartition aCI (aFunction);
316 Handle(GEOM_Function) aRef1 = theShape->GetLastFunction();
317 Handle(GEOM_Function) aRef2 = thePlane->GetLastFunction();
319 if (aRef1.IsNull() || aRef2.IsNull()) return NULL;
324 //Compute the Partition value
326 if (!GetSolver()->ComputeFunction(aFunction)) {
327 SetErrorCode("Partition driver failed");
331 catch (Standard_Failure) {
332 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
333 SetErrorCode(aFail->GetMessageString());
337 //Make a Python command
338 TCollection_AsciiString anEntry, aDescr;
339 TDF_Tool::Entry(aPart->GetEntry(), anEntry);
341 aDescr += " = IBooleanOperations.MakePartition(";
342 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
343 aDescr += (anEntry+", ");
344 TDF_Tool::Entry(thePlane->GetEntry(), anEntry);
345 aDescr += (anEntry+")");
347 aFunction->SetDescription(aDescr);