c4a0238cff3fa0f13cf057b4092db604cb878746
[occt.git] / src / QANewBRepNaming / QANewBRepNaming_Intersection.cxx
1 // File:        QANewBRepNaming_Intersection.cdl
2 // Created:     Tue Oct 31 15:01:54 2000
3 // Author:      Vladislav ROMASHKO
4 //              <vro@flox.nnov.matra-dtv.fr>
5 // Copyright:   Matra Datavision 2000
6
7 const static char sccsid[] = "@(#) 3.0-00-3, 01/10/01@(#)";
8
9 // Lastly modified by :
10 // +---------------------------------------------------------------------------+
11 // !       szy ! Modified Load                           ! 8-05-2003! 3.0-00-%L%!
12 // +---------------------------------------------------------------------------+
13
14 #include <QANewBRepNaming_Intersection.ixx>
15 #include <TNaming_Builder.hxx>
16 #include <QANewBRepNaming_Loader.hxx>
17 #include <TopTools_ListIteratorOfListOfShape.hxx>
18 #include <TopOpeBRepBuild_HBuilder.hxx>
19 #include <TopoDS_Iterator.hxx>
20
21 #ifdef MDTV_DEB
22 #include <TDataStd_Name.hxx>
23 #include <TNaming_NamedShape.hxx>
24 #endif
25 enum BoolArguments {
26   SOLID_SOLID,
27   SOLID_SHELL,
28   SOLID_WIRE,
29   SHELL_SOLID,
30   SHELL_SHELL,
31   SHELL_WIRE,
32   WIRE_SOLID,
33   WIRE_SHELL,
34   WIRE_WIRE,
35   UNEXPECTED
36 };
37 //=======================================================================
38 //function : QANewBRepNaming_Intersection
39 //purpose  : 
40 //=======================================================================
41
42 QANewBRepNaming_Intersection::QANewBRepNaming_Intersection() {}
43
44 //=======================================================================
45 //function : QANewBRepNaming_Intersection
46 //purpose  : 
47 //=======================================================================
48
49 QANewBRepNaming_Intersection::QANewBRepNaming_Intersection(const TDF_Label& ResultLabel)
50      :QANewBRepNaming_BooleanOperationFeat(ResultLabel) {}
51
52 //=======================================================================
53 //function : Load
54 //purpose  : 
55 //=======================================================================
56
57 void QANewBRepNaming_Intersection::Load(BRepAlgoAPI_BooleanOperation& MS) const {
58   TopoDS_Shape ResSh = MS.Shape();
59   if (ResSh.IsNull()) {
60 #ifdef MDTV_DEB
61     cout<<"QANewBRepNaming_Intersection::Load(): The result of the Intersection is null"<<endl;
62 #endif
63     return;
64   }
65
66   const TopAbs_ShapeEnum& ResType = ShapeType(ResSh);
67   const TopoDS_Shape& ObjSh = MS.Shape1();
68   const TopoDS_Shape& ToolSh = MS.Shape2();
69
70   // If the shapes are the same - select the result and exit:
71   if (IsResultChanged(MS)) {
72 #ifdef MDTV_DEB
73     cout<<"QANewBRepNaming_Intersection::Load(): The object and the result of INTERSECTION operation are the same"<<endl;
74     // Not modified!
75 #endif
76     if (ResType == TopAbs_COMPOUND) {
77       Standard_Integer nbSubResults = 0;
78       TopoDS_Iterator itr(MS.Shape());
79       for (; itr.More(); itr.Next()) nbSubResults++;
80       if (nbSubResults == 1) {
81         itr.Initialize(MS.Shape());
82         if (itr.More()) ResSh = itr.Value();
83       }
84     }    
85     TNaming_Builder aBuilder(ResultLabel());
86     aBuilder.Select(ResSh, ObjSh);
87     return;
88   }
89   
90   const TopAbs_ShapeEnum& anObjType = ShapeType(ObjSh);
91   const TopAbs_ShapeEnum& aToolType = ShapeType(ToolSh);
92   BoolArguments anArg;
93   switch (anObjType) 
94     {
95     case TopAbs_SOLID://1
96       switch (aToolType)
97         {
98         case TopAbs_WIRE:
99         case TopAbs_EDGE:
100           anArg = SOLID_WIRE;
101           break;
102         case TopAbs_SOLID:
103           anArg = SHELL_SHELL;
104           break;
105         default:
106           anArg = UNEXPECTED;
107         }
108       break;
109     case TopAbs_SHELL://2
110     case TopAbs_FACE:
111       switch (aToolType)
112         {
113         case TopAbs_SHELL:
114         case TopAbs_FACE:
115           anArg = SHELL_SHELL;
116           break;
117         case TopAbs_WIRE:
118         case TopAbs_EDGE:
119           anArg = SHELL_WIRE;
120           break;
121         default:
122           anArg = UNEXPECTED;
123         }
124       break;
125     case TopAbs_WIRE://3
126     case TopAbs_EDGE:
127       switch (aToolType)
128         {
129         case TopAbs_SOLID:
130           anArg = WIRE_SOLID;
131           break;
132         case TopAbs_SHELL:
133         case TopAbs_FACE:
134           anArg = WIRE_SHELL;
135           break;  
136         case TopAbs_WIRE:
137         case TopAbs_EDGE:
138           anArg = WIRE_WIRE;
139           break;
140         default:
141           anArg = UNEXPECTED;
142         }
143       break;
144     default:
145       anArg = UNEXPECTED;
146     }
147
148   if(anArg == UNEXPECTED) {
149 #ifdef MDTV_DEB
150       cout <<"QANewBRepNaming_Intersection:: Unexpected Use Case" << endl;
151 #endif
152       return;
153     } else
154       LoadResult(MS);   
155
156   // Naming of modified, deleted and new sub shapes:
157   if (anArg == SHELL_SHELL) { // Result Wire/Edge
158 //Generated Edges and (may be) vertexes
159     if(MS.HasGenerated()) {  
160       TNaming_Builder nBuilder (NewShapes());
161       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ObjSh,  TopAbs_FACE, nBuilder);
162       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ToolSh, TopAbs_FACE, nBuilder);
163       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ObjSh,  TopAbs_EDGE, nBuilder);
164       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ToolSh, TopAbs_EDGE, nBuilder);
165     }
166     if(MS.HasDeleted()){ 
167       TNaming_Builder DelFBuilder(DeletedFaces());
168       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ObjSh,  TopAbs_FACE, DelFBuilder);
169       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ToolSh, TopAbs_FACE, DelFBuilder);
170       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ObjSh,  TopAbs_EDGE, DelFBuilder);
171       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ToolSh, TopAbs_EDGE, DelFBuilder);
172     }
173   }
174   else if (anArg == SOLID_WIRE || anArg == WIRE_SOLID || 
175            anArg == SHELL_WIRE || anArg == WIRE_SHELL) { // Result ==> Vertex
176     
177     if(MS.HasGenerated()) {  
178       TNaming_Builder nBuilder (NewShapes());
179       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ObjSh,  TopAbs_FACE, nBuilder);
180       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ToolSh, TopAbs_FACE, nBuilder);
181       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ObjSh,  TopAbs_EDGE, nBuilder);
182       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ToolSh, TopAbs_EDGE, nBuilder);
183     }
184     if(MS.HasDeleted()){ 
185       TNaming_Builder DelFBuilder(DeletedFaces());
186       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ObjSh,  TopAbs_FACE, DelFBuilder);
187       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ToolSh, TopAbs_FACE, DelFBuilder);
188       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ObjSh,  TopAbs_EDGE, DelFBuilder);
189       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ToolSh, TopAbs_EDGE, DelFBuilder);
190       if(anArg == SOLID_WIRE || anArg == SHELL_WIRE) {
191         QANewBRepNaming_Loader::LoadDeletedShapes(MS, ToolSh, TopAbs_VERTEX, DelFBuilder);
192       } else 
193         QANewBRepNaming_Loader::LoadDeletedShapes(MS, ObjSh, TopAbs_VERTEX, DelFBuilder);
194     }   
195   } else if (anArg == WIRE_WIRE) {
196     if(MS.HasGenerated()) {  
197       TNaming_Builder nBuilder (NewShapes());
198       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ObjSh,  TopAbs_EDGE, nBuilder);
199       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, ToolSh, TopAbs_EDGE, nBuilder);
200     }
201     if(MS.HasDeleted()){ 
202       TNaming_Builder DelFBuilder(DeletedFaces());
203       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ObjSh,  TopAbs_EDGE,   DelFBuilder);
204       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ToolSh, TopAbs_EDGE,   DelFBuilder);
205       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ToolSh, TopAbs_VERTEX, DelFBuilder);
206       QANewBRepNaming_Loader::LoadDeletedShapes(MS, ObjSh,  TopAbs_VERTEX, DelFBuilder);
207     }
208   }
209
210   LoadDegenerated(MS);
211   
212   // Naming of the content:
213 //    if (ShapeType(ResSh) == TopAbs_VERTEX) LoadContent(MS);
214 }
215
216 // @@SDM: begin
217
218 // Lastly modified by : vro                                    Date : 31-10-2000
219
220 // File history synopsis (creation,modification,correction)
221 // +---------------------------------------------------------------------------+
222 // ! Developer !              Comments                   !   Date   ! Version  !
223 // +-----------!-----------------------------------------!----------!----------+
224 // !       vro ! Creation                                !31-10-2000!3.0-00-3!
225 // !       vro ! Redesign                                !13-12-2000! 3.0-00-3!
226 // !       vro ! Result control                          !07-03-2001! 3.0-00-3!
227 // !       vro ! Result may be null                      !19-03-2001! 3.0-00-3!
228 // !       szy ! Modified Load                           ! 8-05-2003! 3.0-00-%L%!
229 // +---------------------------------------------------------------------------+
230 // Lastly modified by : szy                                    Date :  8-05-2003
231
232 // @@SDM: end