Salome HOME
Updated copyright comment
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PartitionDriver.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <GEOMImpl_PartitionDriver.hxx>
24 #include <GEOMImpl_IPartition.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMUtils.hxx>
27 #include <GEOM_Object.hxx>
28 #include <GEOM_Function.hxx>
29 #include <GEOMAlgo_Splitter.hxx>
30
31 #include <TDataStd_IntegerArray.hxx>
32 #include <TNaming_CopyShape.hxx>
33
34 #include <TopAbs.hxx>
35 #include <TopExp.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Iterator.hxx>
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <TopTools_DataMapOfShapeShape.hxx>
42
43 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
44 #include <Standard_NullObject.hxx>
45 #include <StdFail_NotDone.hxx>
46 #include <BOPAlgo_CheckerSI.hxx>
47 #include <BOPAlgo_Alerts.hxx>
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <BOPDS_DS.hxx>
51 #include <BRepTools_History.hxx>
52
53 // Depth of self-intersection check (see BOPAlgo_CheckerSI::SetLevelOfCheck() for more details)
54 // Default value for BOPAlgo_CheckerSI gives very long computation when checking face-to-face intersections;
55 // here check level is decreased to more appropriate value to avoid problems with performance).
56 #define BOP_SELF_INTERSECTIONS_LEVEL 4
57
58 //=======================================================================
59 //function : GetID
60 //purpose  :
61 //=======================================================================
62 const Standard_GUID& GEOMImpl_PartitionDriver::GetID()
63 {
64   static Standard_GUID aPartitionDriver("FF1BBB22-5D14-4df2-980B-3A668264EA16");
65   return aPartitionDriver;
66 }
67
68
69 //=======================================================================
70 //function : GEOMImpl_PartitionDriver
71 //purpose  :
72 //=======================================================================
73 GEOMImpl_PartitionDriver::GEOMImpl_PartitionDriver()
74 {
75 }
76
77 //=======================================================================
78 //function : SimplifyCompound
79 //purpose  :
80 //=======================================================================
81 static void PrepareShapes (const TopoDS_Shape&   theShape,
82                            Standard_Integer      theType,
83                            TopTools_ListOfShape& theSimpleList)
84 {
85   if (theType == PARTITION_NO_SELF_INTERSECTIONS ||
86       theShape.ShapeType() != TopAbs_COMPOUND) {
87     theSimpleList.Append(theShape);
88     return;
89   }
90
91   // explode compound on simple shapes to allow their intersections
92   TopoDS_Iterator It (theShape, Standard_True, Standard_True);
93   TopTools_MapOfShape mapShape;
94   for (; It.More(); It.Next()) {
95     if (mapShape.Add(It.Value())) {
96       TopoDS_Shape curSh = It.Value();
97       PrepareShapes(curSh, theType, theSimpleList);
98     }
99   }
100 }
101
102 static void CheckSelfIntersection(const TopoDS_Shape &theShape)
103 {
104   BOPAlgo_CheckerSI aCSI;  // checker of self-interferences
105   TopTools_ListOfShape aList;
106
107   aList.Append(theShape);
108   aCSI.SetLevelOfCheck(BOP_SELF_INTERSECTIONS_LEVEL);
109   aCSI.SetArguments(aList);
110   aCSI.Perform();
111   if (aCSI.HasErrors() || aCSI.DS().Interferences().Extent() > 0) {
112     StdFail_NotDone::Raise("Partition operation will not be performed, because argument shape is self-intersected");
113   }
114 }
115
116 //=======================================================================
117 //function : Execute
118 //purpose  :
119 //=======================================================================
120 Standard_Integer GEOMImpl_PartitionDriver::Execute(Handle(TFunction_Logbook)& log) const
121 {
122   if (Label().IsNull()) return 0;
123   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
124
125   GEOMImpl_IPartition aCI (aFunction);
126   Standard_Integer aType = aFunction->GetType();
127   const Standard_Boolean isCheckSelfInte = aCI.GetCheckSelfIntersection();
128
129   TopoDS_Shape aShape;
130   GEOMAlgo_Splitter PS;
131
132   TopTools_DataMapOfShapeShape aCopyMap;
133   TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
134
135   if (aType == PARTITION_PARTITION || aType == PARTITION_NO_SELF_INTERSECTIONS)
136   {
137     Handle(TColStd_HSequenceOfTransient) aShapes  = aCI.GetShapes();
138     Handle(TColStd_HSequenceOfTransient) aTools   = aCI.GetTools();
139     Handle(TColStd_HSequenceOfTransient) aKeepIns = aCI.GetKeepIns();
140     Handle(TColStd_HSequenceOfTransient) aRemIns  = aCI.GetRemoveIns();
141     Handle(TColStd_HArray1OfInteger) aMaterials   = aCI.GetMaterials();
142     //skl Standard_Boolean DoRemoveWebs = !aMaterials.IsNull();
143
144     int ind;
145     //unsigned int ind, nbshapes = 0;
146     //nbshapes += aShapes->Length() + aTools->Length();
147     //nbshapes += aKeepIns->Length() + aRemIns->Length();
148     //TopTools_MapOfShape ShapesMap(nbshapes), ToolsMap(nbshapes);
149     TopTools_MapOfShape ShapesMap, ToolsMap;
150
151     // add object shapes that are in ListShapes;
152     for (ind = 1; ind <= aShapes->Length(); ind++) {
153       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
154       TopoDS_Shape aShape_i = aRefShape->GetValue();
155       if (aShape_i.IsNull()) {
156         Standard_NullObject::Raise("In Partition a shape is null");
157       }
158
159       // Check self-intersection.
160       if (isCheckSelfInte && aType == PARTITION_NO_SELF_INTERSECTIONS) {
161         CheckSelfIntersection(aShape_i);
162       }
163
164       TopoDS_Shape aShape_i_copy;
165       TNaming_CopyShape::CopyTool(aShape_i, aMapTShapes, aShape_i_copy);
166
167       // fill aCopyMap for history
168       TopTools_IndexedMapOfShape aShape_i_inds;
169       TopTools_IndexedMapOfShape aShape_i_copy_inds;
170       TopExp::MapShapes(aShape_i, aShape_i_inds);
171       TopExp::MapShapes(aShape_i_copy, aShape_i_copy_inds);
172       Standard_Integer nbInds = aShape_i_inds.Extent();
173       for (Standard_Integer ie = 1; ie <= nbInds; ie++) {
174         aCopyMap.Bind(aShape_i_inds.FindKey(ie), aShape_i_copy_inds.FindKey(ie));
175       }
176       //
177       TopTools_ListOfShape aSimpleShapes;
178       //PrepareShapes(aShape_i, aType, aSimpleShapes);
179       PrepareShapes(aShape_i_copy, aType, aSimpleShapes);
180       TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes);
181       for (; aSimpleIter.More(); aSimpleIter.Next()) {
182         const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
183         if (ShapesMap.Add(aSimpleSh)) {
184           PS.AddArgument(aSimpleSh);
185           //skl if (DoRemoveWebs) {
186           //skl if (aMaterials->Length() >= ind)
187           //skl PS.SetMaterial(aSimpleSh, aMaterials->Value(ind));
188           //skl }
189         }
190       }
191     }
192
193     // add tool shapes that are in ListTools and not in ListShapes;
194     for (ind = 1; ind <= aTools->Length(); ind++) {
195       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aTools->Value(ind));
196       TopoDS_Shape aShape_i = aRefShape->GetValue();
197       if (aShape_i.IsNull()) {
198         Standard_NullObject::Raise("In Partition a tool shape is null");
199       }
200
201       // Check self-intersection.
202       if (isCheckSelfInte && aType == PARTITION_NO_SELF_INTERSECTIONS) {
203         CheckSelfIntersection(aShape_i);
204       }
205
206       //
207       //BRepBuilderAPI_Copy aCopyTool (aShape_i);
208       TopoDS_Shape aShape_i_copy;
209       TNaming_CopyShape::CopyTool(aShape_i, aMapTShapes, aShape_i_copy);
210       //if (aCopyTool.IsDone())
211       //  aShape_i_copy = aCopyTool.Shape();
212       //else
213       //  Standard_NullObject::Raise("Bad shape detected");
214       //
215       // fill aCopyMap for history
216       TopTools_IndexedMapOfShape aShape_i_inds;
217       TopTools_IndexedMapOfShape aShape_i_copy_inds;
218       TopExp::MapShapes(aShape_i, aShape_i_inds);
219       TopExp::MapShapes(aShape_i_copy, aShape_i_copy_inds);
220       Standard_Integer nbInds = aShape_i_inds.Extent();
221       for (Standard_Integer ie = 1; ie <= nbInds; ie++) {
222         aCopyMap.Bind(aShape_i_inds.FindKey(ie), aShape_i_copy_inds.FindKey(ie));
223       }
224       //
225       TopTools_ListOfShape aSimpleShapes;
226       //PrepareShapes(aShape_i, aType, aSimpleShapes);
227       PrepareShapes(aShape_i_copy, aType, aSimpleShapes);
228       TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes);
229       for (; aSimpleIter.More(); aSimpleIter.Next()) {
230         const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
231         if (!ShapesMap.Contains(aSimpleSh) && ToolsMap.Add(aSimpleSh)) {
232           PS.AddTool(aSimpleSh);
233         }
234       }
235     }
236
237     // add shapes that are in ListKeepInside, as object shapes;
238     for (ind = 1; ind <= aKeepIns->Length(); ind++) {
239       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aKeepIns->Value(ind));
240       TopoDS_Shape aShape_i = aRefShape->GetValue();
241       if (aShape_i.IsNull()) {
242         Standard_NullObject::Raise("In Partition a Keep Inside shape is null");
243       }
244       //
245       //BRepBuilderAPI_Copy aCopyTool (aShape_i);
246       TopoDS_Shape aShape_i_copy;
247       TNaming_CopyShape::CopyTool(aShape_i, aMapTShapes, aShape_i_copy);
248       //if (aCopyTool.IsDone())
249       //  aShape_i_copy = aCopyTool.Shape();
250       //else
251       //  Standard_NullObject::Raise("Bad shape detected");
252       //
253       // fill aCopyMap for history
254       TopTools_IndexedMapOfShape aShape_i_inds;
255       TopTools_IndexedMapOfShape aShape_i_copy_inds;
256       TopExp::MapShapes(aShape_i, aShape_i_inds);
257       TopExp::MapShapes(aShape_i_copy, aShape_i_copy_inds);
258       Standard_Integer nbInds = aShape_i_inds.Extent();
259       for (Standard_Integer ie = 1; ie <= nbInds; ie++) {
260         aCopyMap.Bind(aShape_i_inds.FindKey(ie), aShape_i_copy_inds.FindKey(ie));
261       }
262       //
263       TopTools_ListOfShape aSimpleShapes;
264       //PrepareShapes(aShape_i, aType, aSimpleShapes);
265       PrepareShapes(aShape_i_copy, aType, aSimpleShapes);
266       TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes);
267       for (; aSimpleIter.More(); aSimpleIter.Next()) {
268         const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
269         if (!ToolsMap.Contains(aSimpleSh) && ShapesMap.Add(aSimpleSh))
270           PS.AddArgument(aSimpleSh);
271       }
272     }
273
274     // add shapes that are in ListRemoveInside, as object shapes;
275     for (ind = 1; ind <= aRemIns->Length(); ind++) {
276       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aRemIns->Value(ind));
277       TopoDS_Shape aShape_i = aRefShape->GetValue();
278       if (aShape_i.IsNull()) {
279         Standard_NullObject::Raise("In Partition a Remove Inside shape is null");
280       }
281       //
282       //BRepBuilderAPI_Copy aCopyTool (aShape_i);
283       TopoDS_Shape aShape_i_copy;
284       TNaming_CopyShape::CopyTool(aShape_i, aMapTShapes, aShape_i_copy);
285       //if (aCopyTool.IsDone())
286       //  aShape_i_copy = aCopyTool.Shape();
287       //else
288       //  Standard_NullObject::Raise("Bad shape detected");
289       //
290       // fill aCopyMap for history
291       TopTools_IndexedMapOfShape aShape_i_inds;
292       TopTools_IndexedMapOfShape aShape_i_copy_inds;
293       TopExp::MapShapes(aShape_i, aShape_i_inds);
294       TopExp::MapShapes(aShape_i_copy, aShape_i_copy_inds);
295       Standard_Integer nbInds = aShape_i_inds.Extent();
296       for (Standard_Integer ie = 1; ie <= nbInds; ie++) {
297         aCopyMap.Bind(aShape_i_inds.FindKey(ie), aShape_i_copy_inds.FindKey(ie));
298       }
299       //
300       TopTools_ListOfShape aSimpleShapes;
301       //PrepareShapes(aShape_i, aType, aSimpleShapes);
302       PrepareShapes(aShape_i_copy, aType, aSimpleShapes);
303       TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes);
304       for (; aSimpleIter.More(); aSimpleIter.Next()) {
305         const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
306         if (!ToolsMap.Contains(aSimpleSh) && ShapesMap.Add(aSimpleSh))
307           PS.AddArgument(aSimpleSh);
308       }
309     }
310
311     PS.SetLimitMode(aCI.GetKeepNonlimitShapes());
312     PS.SetLimit((TopAbs_ShapeEnum)aCI.GetLimit());
313
314     // Set parallel processing mode (default is false)
315     Standard_Boolean bRunParallel = Standard_True;
316     PS.SetRunParallel(bRunParallel);
317
318     PS.Perform();
319
320     //skl PS.Compute();
321     //skl PS.SetRemoveWebs(!DoRemoveWebs);
322     //skl PS.Build((TopAbs_ShapeEnum) aCI.GetLimit());
323     /*skl
324     // suppress result outside of shapes in KInsideMap
325     for (ind = 1; ind <= aKeepIns->Length(); ind++) {
326       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aKeepIns->Value(ind));
327       TopoDS_Shape aShape_i = aRefShape->GetValue();
328       PS.KeepShapesInside(aShape_i);
329     }
330
331     // suppress result inside of shapes in RInsideMap
332     for (ind = 1; ind <= aRemIns->Length(); ind++) {
333       Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aRemIns->Value(ind));
334       TopoDS_Shape aShape_i = aRefShape->GetValue();
335       PS.RemoveShapesInside(aShape_i);
336     }
337     */
338   }
339   else if (aType == PARTITION_HALF)
340   {
341     Handle(GEOM_Function) aRefShape = aCI.GetShape();
342     Handle(GEOM_Function) aRefPlane = aCI.GetPlane();
343     TopoDS_Shape aShapeArg = aRefShape->GetValue();
344     TopoDS_Shape aPlaneArg = aRefPlane->GetValue();
345
346     if (aShapeArg.IsNull() || aPlaneArg.IsNull()) {
347       Standard_NullObject::Raise("In Half Partition a shape or a plane is null");
348     }
349
350     TopoDS_Shape aShapeArg_copy;
351     TopoDS_Shape aPlaneArg_copy;
352     {
353       TNaming_CopyShape::CopyTool(aShapeArg, aMapTShapes, aShapeArg_copy);
354       //BRepBuilderAPI_Copy aCopyTool (aShapeArg);
355       //if (aCopyTool.IsDone())
356       //  aShapeArg_copy = aCopyTool.Shape();
357       //else
358       //  Standard_NullObject::Raise("Bad shape detected");
359       //
360       // fill aCopyMap for history
361       TopTools_IndexedMapOfShape aShapeArg_inds;
362       TopTools_IndexedMapOfShape aShapeArg_copy_inds;
363       TopExp::MapShapes(aShapeArg, aShapeArg_inds);
364       TopExp::MapShapes(aShapeArg_copy, aShapeArg_copy_inds);
365       Standard_Integer nbInds = aShapeArg_inds.Extent();
366       for (Standard_Integer ie = 1; ie <= nbInds; ie++) {
367         aCopyMap.Bind(aShapeArg_inds.FindKey(ie), aShapeArg_copy_inds.FindKey(ie));
368       }
369     }
370     {
371       TNaming_CopyShape::CopyTool(aPlaneArg, aMapTShapes, aPlaneArg_copy);
372       //BRepBuilderAPI_Copy aCopyTool (aPlaneArg);
373       //if (aCopyTool.IsDone())
374       //  aPlaneArg_copy = aCopyTool.Shape();
375       //else
376       //  Standard_NullObject::Raise("Bad shape detected");
377       //
378       // fill aCopyMap for history
379       TopTools_IndexedMapOfShape aPlaneArg_inds;
380       TopTools_IndexedMapOfShape aPlaneArg_copy_inds;
381       TopExp::MapShapes(aPlaneArg, aPlaneArg_inds);
382       TopExp::MapShapes(aPlaneArg_copy, aPlaneArg_copy_inds);
383       Standard_Integer nbInds = aPlaneArg_inds.Extent();
384       for (Standard_Integer ie = 1; ie <= nbInds; ie++) {
385         aCopyMap.Bind(aPlaneArg_inds.FindKey(ie), aPlaneArg_copy_inds.FindKey(ie));
386       }
387     }
388
389     // add object shapes that are in ListShapes;
390     TopTools_ListOfShape aSimpleShapes;
391     TopTools_MapOfShape aShapesMap;
392
393     PrepareShapes(aShapeArg_copy, aType, aSimpleShapes);
394
395     TopTools_ListIteratorOfListOfShape aSimpleIter (aSimpleShapes);
396
397     for (; aSimpleIter.More(); aSimpleIter.Next()) {
398       const TopoDS_Shape& aSimpleSh = aSimpleIter.Value();
399
400       if (aShapesMap.Add(aSimpleSh)) {
401         PS.AddArgument(aSimpleSh);
402       }
403     }
404
405     // add tool shapes that are in ListTools and not in ListShapes;
406     PS.AddTool(aPlaneArg_copy);
407     //PS.AddTool(aPlaneArg);
408
409     //skl PS.Compute();
410     PS.Perform();
411     //PS.SetRemoveWebs(Standard_False);
412     //PS.Build(aShapeArg.ShapeType());
413
414   } else {
415   }
416
417   aShape = PS.Shape();
418   if (aShape.IsNull()) {
419     // Mantis issue 22009
420     if (PS.HasError(STANDARD_TYPE(BOPAlgo_AlertTooFewArguments)) && PS.Tools().Extent() == 0 && PS.Arguments().Extent() == 1)
421       aShape = PS.Arguments().First();
422     else
423       return 0;
424   }
425
426   if (aShape.ShapeType() != TopAbs_VERTEX) {
427     //Alternative case to check not valid partition IPAL21418
428     TopoDS_Iterator It (aShape, Standard_True, Standard_True);
429     int nbSubshapes = 0;
430     for (; It.More(); It.Next())
431       nbSubshapes++;
432     if (!nbSubshapes)
433       Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
434     //end of IPAL21418
435   }
436
437   if ( !GEOMUtils::CheckShape(aShape, true) && !GEOMUtils::FixShapeTolerance(aShape) )
438     Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
439
440   aFunction->SetValue(aShape);
441
442   // Fill history to be used by GetInPlace functionality
443   TopTools_IndexedMapOfShape aResIndices;
444   TopExp::MapShapes(aShape, aResIndices);
445
446   // history for all argument shapes
447   // be sure to use aCopyMap
448   TDF_LabelSequence aLabelSeq;
449   aFunction->GetDependency(aLabelSeq);
450   Standard_Integer nbArg = aLabelSeq.Length();
451
452   for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
453
454     TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
455
456     Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
457     TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
458
459     TopTools_IndexedMapOfShape anArgumentIndices;
460     TopExp::MapShapes(anArgumentShape, anArgumentIndices);
461     Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
462
463     // Find corresponding label in history
464     TDF_Label anArgumentHistoryLabel =
465       aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
466
467     for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
468       TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
469       if (!BRepTools_History::IsSupportedType(anEntity))
470         continue;
471
472       // be sure to use aCopyMap here
473       if (aCopyMap.IsBound(anEntity))
474         anEntity = aCopyMap.Find(anEntity);
475       //
476       if (PS.IsDeleted(anEntity))
477         // The shape has been deleted
478         continue;
479
480       // Check if the shape has been modified during the operation.
481       // If it was - use its splits, otherwise use the shape itself
482       const TopTools_ListOfShape *pModified;
483       TopTools_ListOfShape aLItself;
484       const TopTools_ListOfShape& aPSModified = PS.Modified(anEntity);
485       if (!aPSModified.IsEmpty())
486         pModified = &aPSModified;
487       else
488       {
489         aLItself.Append(anEntity);
490         pModified = &aLItself;
491       }
492         
493       TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
494       Handle(TDataStd_IntegerArray) anAttr =
495         TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, pModified->Extent());
496
497       int ih = 1;
498       TopTools_ListIteratorOfListOfShape itM (*pModified);
499       for (; itM.More(); itM.Next(), ++ih) {
500         int id = aResIndices.FindIndex(itM.Value());
501         anAttr->SetValue(ih, id);
502       }
503     }
504   }
505
506   log->SetTouched(Label());
507
508   return 1;
509 }
510
511 //================================================================================
512 /*!
513  * \brief Returns a name of creation operation and names and values of creation parameters
514  */
515 //================================================================================
516
517 bool GEOMImpl_PartitionDriver::
518 GetCreationInformation(std::string&             theOperationName,
519                        std::vector<GEOM_Param>& theParams)
520 {
521   if (Label().IsNull()) return 0;
522   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
523
524   GEOMImpl_IPartition aCI( function );
525   Standard_Integer aType = function->GetType();
526
527   theOperationName = "PARTITION";
528
529   switch ( aType ) {
530   case PARTITION_PARTITION:
531   case PARTITION_NO_SELF_INTERSECTIONS:
532     AddParam( theParams, "Objects", aCI.GetShapes() );
533     AddParam( theParams, "Tool objects", aCI.GetTools() );
534     {
535       Handle(TColStd_HSequenceOfTransient) objSeq = aCI.GetKeepIns();
536       if ( !objSeq.IsNull() && objSeq->Length() > 0 )
537         AddParam( theParams, "Objects to keep inside", objSeq );
538       objSeq = aCI.GetRemoveIns();
539       if ( !objSeq.IsNull() && objSeq->Length() > 0 )
540         AddParam( theParams, "Objects to remove inside", objSeq );
541       Handle(TColStd_HArray1OfInteger) intSeq = aCI.GetMaterials();
542       if ( !intSeq.IsNull() && intSeq->Length() > 0 )
543         AddParam( theParams, "Materials", aCI.GetMaterials() );
544     }
545     AddParam( theParams, "Resulting type", (TopAbs_ShapeEnum) aCI.GetLimit());
546     AddParam( theParams, "Keep shapes of lower type", aCI.GetKeepNonlimitShapes());
547     AddParam( theParams, "No object intersections", ( aType == PARTITION_NO_SELF_INTERSECTIONS ));
548
549     if (aType == PARTITION_NO_SELF_INTERSECTIONS) {
550       AddParam( theParams, "Check self-intersections", aCI.GetCheckSelfIntersection());
551     }
552     break;
553   case PARTITION_HALF:
554     AddParam( theParams, "Object", aCI.GetShape() );
555     AddParam( theParams, "Plane", aCI.GetPlane() );
556     break;
557   default:
558     return false;
559   }
560   
561   return true;
562 }
563
564 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_PartitionDriver,GEOM_BaseDriver)