3 #include "GEOMImpl_PartitionDriver.hxx"
4 #include "GEOMImpl_IPartition.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
8 #include <NMTAlgo_Splitter1.hxx>
9 #include <BRep_Tool.hxx>
10 #include <BRepAlgo.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Vertex.hxx>
14 #include <TopoDS_Wire.hxx>
17 #include <TopTools_MapOfShape.hxx>
19 #include <Standard_NullObject.hxx>
20 #include <Precision.hxx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_PartitionDriver::GetID()
29 static Standard_GUID aPartitionDriver("FF1BBB22-5D14-4df2-980B-3A668264EA16");
30 return aPartitionDriver;
34 //=======================================================================
35 //function : GEOMImpl_PartitionDriver
37 //=======================================================================
38 GEOMImpl_PartitionDriver::GEOMImpl_PartitionDriver()
42 //=======================================================================
45 //=======================================================================
46 Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const
48 if (Label().IsNull()) return 0;
49 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 GEOMImpl_IPartition aCI (aFunction);
52 Standard_Integer aType = aFunction->GetType();
56 if (aType == PARTITION_PARTITION) {
57 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
58 Handle(TColStd_HSequenceOfTransient) aTools = aCI.GetTools();
59 Handle(TColStd_HSequenceOfTransient) aKeepIns = aCI.GetKeepIns();
60 Handle(TColStd_HSequenceOfTransient) aRemIns = aCI.GetRemoveIns();
61 Handle(TColStd_HArray1OfInteger) aMaterials = aCI.GetMaterials();
62 Standard_Boolean DoRemoveWebs = !aMaterials.IsNull();
64 unsigned int ind, nbshapes = 0;
65 nbshapes += aShapes->Length() + aTools->Length();
66 nbshapes += aKeepIns->Length() + aRemIns->Length();
69 TopTools_MapOfShape ShapesMap(nbshapes), ToolsMap(nbshapes);
71 // add object shapes that are in ListShapes;
72 for (ind = 1; ind <= aShapes->Length(); ind++) {
73 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aShapes->Value(ind));
74 TopoDS_Shape aShape_i = aRefShape->GetValue();
75 if (aShape_i.IsNull()) {
76 Standard_NullObject::Raise("In Partition a shape is null");
78 if (ShapesMap.Add(aShape_i)) {
79 PS.AddShape(aShape_i);
81 if (aMaterials->Length() >= ind)
82 PS.SetMaterial(aShape_i, aMaterials->Value(ind));
87 // add tool shapes that are in ListTools and not in ListShapes;
88 for (ind = 1; ind <= aTools->Length(); ind++) {
89 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aTools->Value(ind));
90 TopoDS_Shape aShape_i = aRefShape->GetValue();
91 if (aShape_i.IsNull()) {
92 Standard_NullObject::Raise("In Partition a tool shape is null");
94 if (!ShapesMap.Contains(aShape_i) && ToolsMap.Add(aShape_i))
98 // add shapes that are in ListKeepInside, as object shapes;
99 for (ind = 1; ind <= aKeepIns->Length(); ind++) {
100 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aKeepIns->Value(ind));
101 TopoDS_Shape aShape_i = aRefShape->GetValue();
102 if (aShape_i.IsNull()) {
103 Standard_NullObject::Raise("In Partition a Keep Inside shape is null");
105 if (!ToolsMap.Contains(aShape_i) && ShapesMap.Add(aShape_i))
106 PS.AddShape(aShape_i);
109 // add shapes that are in ListRemoveInside, as object shapes;
110 for (ind = 1; ind <= aRemIns->Length(); ind++) {
111 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aRemIns->Value(ind));
112 TopoDS_Shape aShape_i = aRefShape->GetValue();
113 if (aShape_i.IsNull()) {
114 Standard_NullObject::Raise("In Partition a Remove Inside shape is null");
116 if (!ToolsMap.Contains(aShape_i) && ShapesMap.Add(aShape_i))
117 PS.AddShape(aShape_i);
121 PS.SetRemoveWebs(DoRemoveWebs);
122 PS.Build((TopAbs_ShapeEnum) aCI.GetLimit());
124 // suppress result outside of shapes in KInsideMap
125 for (ind = 1; ind <= aKeepIns->Length(); ind++) {
126 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aKeepIns->Value(ind));
127 TopoDS_Shape aShape_i = aRefShape->GetValue();
128 PS.KeepShapesInside(aShape_i);
131 // suppress result inside of shapes in RInsideMap
132 for (ind = 1; ind <= aRemIns->Length(); ind++) {
133 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aRemIns->Value(ind));
134 TopoDS_Shape aShape_i = aRefShape->GetValue();
135 PS.RemoveShapesInside(aShape_i);
140 if (!BRepAlgo::IsValid(aShape)) {
141 Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
143 } else if (aType == PARTITION_HALF) {
144 Handle(GEOM_Function) aRefShape = aCI.GetShape();
145 Handle(GEOM_Function) aRefPlane = aCI.GetPlane();
146 TopoDS_Shape aShapeArg = aRefShape->GetValue();
147 TopoDS_Shape aPlaneArg = aRefPlane->GetValue();
149 if (aShapeArg.IsNull() || aPlaneArg.IsNull()) {
150 Standard_NullObject::Raise("In Half Partition a shape or a plane is null");
153 NMTAlgo_Splitter1 PS;
155 // add object shapes that are in ListShapes;
156 PS.AddShape(aShapeArg);
158 // add tool shapes that are in ListTools and not in ListShapes;
159 PS.AddTool(aPlaneArg);
162 PS.SetRemoveWebs(Standard_False);
163 PS.Build(aShapeArg.ShapeType());
167 if (!BRepAlgo::IsValid(aShape)) {
168 Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
174 if (aShape.IsNull()) return 0;
176 aFunction->SetValue(aShape);
178 log.SetTouched(Label());
184 //=======================================================================
185 //function : GEOMImpl_PartitionDriver_Type_
187 //=======================================================================
188 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PartitionDriver_Type_()
191 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
192 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
193 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
194 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
195 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
196 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
199 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
200 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PartitionDriver",
201 sizeof(GEOMImpl_PartitionDriver),
203 (Standard_Address)_Ancestors,
204 (Standard_Address)NULL);
209 //=======================================================================
210 //function : DownCast
212 //=======================================================================
213 const Handle(GEOMImpl_PartitionDriver) Handle(GEOMImpl_PartitionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
215 Handle(GEOMImpl_PartitionDriver) _anOtherObject;
217 if (!AnObject.IsNull()) {
218 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PartitionDriver))) {
219 _anOtherObject = Handle(GEOMImpl_PartitionDriver)((Handle(GEOMImpl_PartitionDriver)&)AnObject);
223 return _anOtherObject ;