3 #include "GEOMImpl_PartitionDriver.hxx"
4 #include "GEOMImpl_IPartition.hxx"
5 #include "GEOMImpl_Types.hxx"
7 #include "GEOM_Object.hxx"
8 #include "GEOM_Function.hxx"
10 #include <NMTAlgo_Splitter1.hxx>
12 #include <TDataStd_IntegerArray.hxx>
14 #include <BRep_Tool.hxx>
15 #include <BRepAlgo.hxx>
18 #include <TopoDS_Shape.hxx>
19 #include <TopoDS_Vertex.hxx>
20 #include <TopoDS_Wire.hxx>
23 #include <TopTools_MapOfShape.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
26 #include <TColStd_ListIteratorOfListOfInteger.hxx>
27 #include <TColStd_ListOfInteger.hxx>
28 #include <Standard_NullObject.hxx>
29 #include <Precision.hxx>
32 //=======================================================================
35 //=======================================================================
36 const Standard_GUID& GEOMImpl_PartitionDriver::GetID()
38 static Standard_GUID aPartitionDriver("FF1BBB22-5D14-4df2-980B-3A668264EA16");
39 return aPartitionDriver;
43 //=======================================================================
44 //function : GEOMImpl_PartitionDriver
46 //=======================================================================
47 GEOMImpl_PartitionDriver::GEOMImpl_PartitionDriver()
51 //=======================================================================
54 //=======================================================================
55 Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const
57 if (Label().IsNull()) return 0;
58 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
60 GEOMImpl_IPartition aCI (aFunction);
61 Standard_Integer aType = aFunction->GetType();
66 if (aType == PARTITION_PARTITION) {
67 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
68 Handle(TColStd_HSequenceOfTransient) aTools = aCI.GetTools();
69 Handle(TColStd_HSequenceOfTransient) aKeepIns = aCI.GetKeepIns();
70 Handle(TColStd_HSequenceOfTransient) aRemIns = aCI.GetRemoveIns();
71 Handle(TColStd_HArray1OfInteger) aMaterials = aCI.GetMaterials();
72 Standard_Boolean DoRemoveWebs = !aMaterials.IsNull();
74 unsigned int ind, nbshapes = 0;
75 nbshapes += aShapes->Length() + aTools->Length();
76 nbshapes += aKeepIns->Length() + aRemIns->Length();
78 TopTools_MapOfShape ShapesMap(nbshapes), ToolsMap(nbshapes);
80 // add object shapes that are in ListShapes;
81 for (ind = 1; ind <= aShapes->Length(); ind++) {
82 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
83 TopoDS_Shape aShape_i = aRefShape->GetValue();
84 if (aShape_i.IsNull()) {
85 Standard_NullObject::Raise("In Partition a shape is null");
87 if (ShapesMap.Add(aShape_i)) {
88 PS.AddShape(aShape_i);
90 if (aMaterials->Length() >= ind)
91 PS.SetMaterial(aShape_i, aMaterials->Value(ind));
96 // add tool shapes that are in ListTools and not in ListShapes;
97 for (ind = 1; ind <= aTools->Length(); ind++) {
98 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aTools->Value(ind));
99 TopoDS_Shape aShape_i = aRefShape->GetValue();
100 if (aShape_i.IsNull()) {
101 Standard_NullObject::Raise("In Partition a tool shape is null");
103 if (!ShapesMap.Contains(aShape_i) && ToolsMap.Add(aShape_i))
104 PS.AddTool(aShape_i);
107 // add shapes that are in ListKeepInside, as object shapes;
108 for (ind = 1; ind <= aKeepIns->Length(); ind++) {
109 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aKeepIns->Value(ind));
110 TopoDS_Shape aShape_i = aRefShape->GetValue();
111 if (aShape_i.IsNull()) {
112 Standard_NullObject::Raise("In Partition a Keep Inside shape is null");
114 if (!ToolsMap.Contains(aShape_i) && ShapesMap.Add(aShape_i))
115 PS.AddShape(aShape_i);
118 // add shapes that are in ListRemoveInside, as object shapes;
119 for (ind = 1; ind <= aRemIns->Length(); ind++) {
120 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aRemIns->Value(ind));
121 TopoDS_Shape aShape_i = aRefShape->GetValue();
122 if (aShape_i.IsNull()) {
123 Standard_NullObject::Raise("In Partition a Remove Inside shape is null");
125 if (!ToolsMap.Contains(aShape_i) && ShapesMap.Add(aShape_i))
126 PS.AddShape(aShape_i);
130 PS.SetRemoveWebs(DoRemoveWebs);
131 PS.Build((TopAbs_ShapeEnum) aCI.GetLimit());
133 // suppress result outside of shapes in KInsideMap
134 for (ind = 1; ind <= aKeepIns->Length(); ind++) {
135 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aKeepIns->Value(ind));
136 TopoDS_Shape aShape_i = aRefShape->GetValue();
137 PS.KeepShapesInside(aShape_i);
140 // suppress result inside of shapes in RInsideMap
141 for (ind = 1; ind <= aRemIns->Length(); ind++) {
142 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aRemIns->Value(ind));
143 TopoDS_Shape aShape_i = aRefShape->GetValue();
144 PS.RemoveShapesInside(aShape_i);
147 } else if (aType == PARTITION_HALF) {
148 Handle(GEOM_Function) aRefShape = aCI.GetShape();
149 Handle(GEOM_Function) aRefPlane = aCI.GetPlane();
150 TopoDS_Shape aShapeArg = aRefShape->GetValue();
151 TopoDS_Shape aPlaneArg = aRefPlane->GetValue();
153 if (aShapeArg.IsNull() || aPlaneArg.IsNull()) {
154 Standard_NullObject::Raise("In Half Partition a shape or a plane is null");
157 // add object shapes that are in ListShapes;
158 PS.AddShape(aShapeArg);
160 // add tool shapes that are in ListTools and not in ListShapes;
161 PS.AddTool(aPlaneArg);
164 PS.SetRemoveWebs(Standard_False);
165 PS.Build(aShapeArg.ShapeType());
171 if (aShape.IsNull()) return 0;
173 if (!BRepAlgo::IsValid(aShape)) {
174 Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
177 aFunction->SetValue(aShape);
179 // Fill history to be used by GetInPlace functionality
180 TopTools_IndexedMapOfShape aResIndices;
181 TopExp::MapShapes(aShape, aResIndices);
183 // history for all argument shapes
184 TDF_LabelSequence aLabelSeq;
185 aFunction->GetDependency(aLabelSeq);
186 Standard_Integer nbArg = aLabelSeq.Length();
188 for (Standard_Integer iarg = 1; iarg <= nbArg; iarg++) {
190 TDF_Label anArgumentRefLabel = aLabelSeq.Value(iarg);
192 Handle(GEOM_Object) anArgumentObject = GEOM_Object::GetReferencedObject(anArgumentRefLabel);
193 TopoDS_Shape anArgumentShape = anArgumentObject->GetValue();
195 TopTools_IndexedMapOfShape anArgumentIndices;
196 TopExp::MapShapes(anArgumentShape, anArgumentIndices);
197 Standard_Integer nbArgumentEntities = anArgumentIndices.Extent();
199 // Find corresponding label in history
200 TDF_Label anArgumentHistoryLabel =
201 aFunction->GetArgumentHistoryEntry(anArgumentRefLabel, Standard_True);
203 for (Standard_Integer ie = 1; ie <= nbArgumentEntities; ie++) {
204 TopoDS_Shape anEntity = anArgumentIndices.FindKey(ie);
205 const TopTools_ListOfShape& aModified = PS.Modified(anEntity);
206 Standard_Integer nbModified = aModified.Extent();
208 if (nbModified > 0) {
209 TDF_Label aWhatHistoryLabel = anArgumentHistoryLabel.FindChild(ie, Standard_True);
210 Handle(TDataStd_IntegerArray) anAttr =
211 TDataStd_IntegerArray::Set(aWhatHistoryLabel, 1, nbModified);
213 TopTools_ListIteratorOfListOfShape itM (aModified);
214 for (int im = 1; itM.More(); itM.Next(), ++im) {
215 int id = aResIndices.FindIndex(itM.Value());
216 anAttr->SetValue(im, id);
222 log.SetTouched(Label());
228 //=======================================================================
229 //function : GEOMImpl_PartitionDriver_Type_
231 //=======================================================================
232 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PartitionDriver_Type_()
235 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
236 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
237 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
238 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
239 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
240 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
243 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
244 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PartitionDriver",
245 sizeof(GEOMImpl_PartitionDriver),
247 (Standard_Address)_Ancestors,
248 (Standard_Address)NULL);
253 //=======================================================================
254 //function : DownCast
256 //=======================================================================
257 const Handle(GEOMImpl_PartitionDriver) Handle(GEOMImpl_PartitionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
259 Handle(GEOMImpl_PartitionDriver) _anOtherObject;
261 if (!AnObject.IsNull()) {
262 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PartitionDriver))) {
263 _anOtherObject = Handle(GEOMImpl_PartitionDriver)((Handle(GEOMImpl_PartitionDriver)&)AnObject);
267 return _anOtherObject ;