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