]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_PartitionDriver.cxx
Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PartitionDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_PartitionDriver.hxx"
4 #include "GEOMImpl_IPartition.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <NMTAlgo_Splitter1.hxx>
9 #include <BRep_Tool.hxx>
10 #include <BRepAlgo.hxx>
11 #include <TopoDS.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Vertex.hxx>
14 #include <TopoDS_Wire.hxx>
15 #include <TopAbs.hxx>
16 #include <TopExp.hxx>
17 #include <TopTools_MapOfShape.hxx>
18
19 #include <Standard_NullObject.hxx>
20 #include <Precision.hxx>
21 #include <gp_Pnt.hxx>
22
23 //=======================================================================
24 //function : GetID
25 //purpose  :
26 //======================================================================= 
27 const Standard_GUID& GEOMImpl_PartitionDriver::GetID()
28 {
29   static Standard_GUID aPartitionDriver("FF1BBB22-5D14-4df2-980B-3A668264EA16");
30   return aPartitionDriver; 
31 }
32
33
34 //=======================================================================
35 //function : GEOMImpl_PartitionDriver
36 //purpose  : 
37 //=======================================================================
38 GEOMImpl_PartitionDriver::GEOMImpl_PartitionDriver() 
39 {
40 }
41
42 //=======================================================================
43 //function : Execute
44 //purpose  :
45 //======================================================================= 
46 Standard_Integer GEOMImpl_PartitionDriver::Execute(TFunction_Logbook& log) const
47 {
48   if (Label().IsNull()) return 0;    
49   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
50
51   GEOMImpl_IPartition aCI (aFunction);
52   Standard_Integer aType = aFunction->GetType();
53
54   TopoDS_Shape aShape;
55
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();
63
64     unsigned int ind, nbshapes = 0;
65     nbshapes += aShapes->Length() + aTools->Length();
66     nbshapes += aKeepIns->Length() + aRemIns->Length();
67
68     NMTAlgo_Splitter1 PS;
69     TopTools_MapOfShape ShapesMap(nbshapes), ToolsMap(nbshapes);
70
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");
77       }
78       if (ShapesMap.Add(aShape_i)) {
79         PS.AddShape(aShape_i);
80         if (DoRemoveWebs) {
81           if (aMaterials->Length() >= ind)
82             PS.SetMaterial(aShape_i, aMaterials->Value(ind));
83         }
84       }
85     }
86
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");
93       }
94       if (!ShapesMap.Contains(aShape_i) && ToolsMap.Add(aShape_i))
95         PS.AddTool(aShape_i);
96     }
97
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");
104       }
105       if (!ToolsMap.Contains(aShape_i) && ShapesMap.Add(aShape_i))
106         PS.AddShape(aShape_i);
107     }
108
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");
115       }
116       if (!ToolsMap.Contains(aShape_i) && ShapesMap.Add(aShape_i))
117         PS.AddShape(aShape_i);
118     }
119
120     PS.Compute();
121     PS.SetRemoveWebs(DoRemoveWebs);
122     PS.Build((TopAbs_ShapeEnum) aCI.GetLimit());
123
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);
129     }
130
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);
136     }
137
138     aShape = PS.Shape();
139
140     if (!BRepAlgo::IsValid(aShape)) {
141       Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
142     }
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();
148
149     if (aShapeArg.IsNull() || aPlaneArg.IsNull()) {
150       Standard_NullObject::Raise("In Half Partition a shape or a plane is null");
151     }
152
153     NMTAlgo_Splitter1 PS;
154
155     // add object shapes that are in ListShapes;
156     PS.AddShape(aShapeArg);
157
158     // add tool shapes that are in ListTools and not in ListShapes;
159     PS.AddTool(aPlaneArg);
160
161     PS.Compute();
162     PS.SetRemoveWebs(Standard_False);
163     PS.Build(aShapeArg.ShapeType());
164
165     aShape = PS.Shape();
166
167     if (!BRepAlgo::IsValid(aShape)) {
168       Standard_ConstructionError::Raise("Partition aborted : non valid shape result");
169     }
170   }
171   else {
172   }
173
174   if (aShape.IsNull()) return 0;
175
176   aFunction->SetValue(aShape);
177
178   log.SetTouched(Label());
179
180   return 1;
181 }
182
183
184 //=======================================================================
185 //function :  GEOMImpl_PartitionDriver_Type_
186 //purpose  :
187 //======================================================================= 
188 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PartitionDriver_Type_()
189 {
190
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);
197  
198
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),
202                                                          1,
203                                                          (Standard_Address)_Ancestors,
204                                                          (Standard_Address)NULL);
205
206   return _aType;
207 }
208
209 //=======================================================================
210 //function : DownCast
211 //purpose  :
212 //======================================================================= 
213 const Handle(GEOMImpl_PartitionDriver) Handle(GEOMImpl_PartitionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
214 {
215   Handle(GEOMImpl_PartitionDriver) _anOtherObject;
216
217   if (!AnObject.IsNull()) {
218      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PartitionDriver))) {
219        _anOtherObject = Handle(GEOMImpl_PartitionDriver)((Handle(GEOMImpl_PartitionDriver)&)AnObject);
220      }
221   }
222
223   return _anOtherObject ;
224 }