0025418: Debug output to be limited to OCC development environment
[occt.git] / src / QANewBRepNaming / QANewBRepNaming_Limitation.cxx
1 // Created on: 2000-12-26
2 // Created by: Vladislav ROMASHKO <vro@nnov.matra-dtv.fr>
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <QANewBRepNaming_Limitation.ixx>
17 #include <TopTools_ListIteratorOfListOfShape.hxx>
18 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
19 #include <TopTools_IndexedMapOfShape.hxx>
20 #include <BRep_Tool.hxx>
21 #include <TopoDS.hxx>
22 #include <TopoDS_Iterator.hxx>
23 #include <TopExp.hxx>
24 #include <TopExp_Explorer.hxx>
25
26 // OCAF
27 #include <TDataStd_Name.hxx>
28 #include <TNaming_Builder.hxx>
29 #include <TNaming_NamedShape.hxx>
30 #include <QANewBRepNaming_Loader.hxx>
31 // Specific
32 #include <QANewModTopOpe_ModeOfLimitation.hxx>
33
34 //=======================================================================
35 //function : QANewBRepNaming_Limitation
36 //purpose  : 
37 //=======================================================================
38
39 QANewBRepNaming_Limitation::QANewBRepNaming_Limitation() {}
40
41 //=======================================================================
42 //function : QANewBRepNaming_Limitation
43 //purpose  : 
44 //=======================================================================
45
46 QANewBRepNaming_Limitation::QANewBRepNaming_Limitation(const TDF_Label& ResultLabel)
47      :QANewBRepNaming_BooleanOperationFeat(ResultLabel) {}
48
49 //=======================================================================
50 //function : Load
51 //purpose  : 
52 //=======================================================================
53
54 void QANewBRepNaming_Limitation::Load(QANewModTopOpe_Limitation& MS) const {
55   TopoDS_Shape ResSh = MS.Shape();
56
57   const TopoDS_Shape& ObjSh = MS.Shape1();
58   const TopAbs_ShapeEnum& ObjType = ShapeType(ObjSh);
59
60   if (ResSh.IsNull()) {
61 #ifdef OCCT_DEBUG
62     cout<<"QANewBRepNaming_Limitation::Load(): The result of the boolean operation is null"<<endl;
63 #endif
64     return;
65   }
66
67   if (MS.Shape().ShapeType() == TopAbs_COMPOUND) {
68     Standard_Integer nbSubResults = 0;
69     TopoDS_Iterator itr(MS.Shape());
70     for (; itr.More(); itr.Next()) nbSubResults++;
71     if (nbSubResults == 1) {
72       itr.Initialize(MS.Shape());
73       if (itr.More()) ResSh = itr.Value();
74     }
75   } 
76   if(MS.Shape1().IsSame(ResSh)) {
77 // If the shapes are the same - select the result and exit:
78 #ifdef OCCT_DEBUG
79     cout<<"QANewBRepNaming_Limitation::Load(): The object and the result of LIMITATION operation are the same"<<endl;
80 #endif
81     TNaming_Builder aBuilder(ResultLabel());
82     aBuilder.Select(ResSh, ObjSh);
83     return;
84   }
85   // Naming of the result:
86   LoadResult(MS);
87      
88   // Naming of the content:
89 //  if (ResSh.ShapeType() == TopAbs_COMPOUND) {
90     
91 //    LoadContent(MS);
92
93 //  }
94   
95   // Naming of modified, deleted and new sub shapes:
96   if (ObjType == TopAbs_WIRE || ObjType == TopAbs_EDGE) {
97 //    LoadWire(MS);
98     TNaming_Builder ModBuilder(ModifiedEdges()); 
99     QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_EDGE, ModBuilder, Standard_False);
100     if(MS.HasGenerated()) {  
101       TNaming_Builder nBuilder (NewShapes());
102 //  generated Vertexes
103       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_EDGE, nBuilder);
104       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder);
105       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_EDGE, nBuilder);  
106     }
107     if(MS.HasDeleted()){ 
108       TNaming_Builder DelEBuilder(DeletedEdges());
109       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_EDGE, DelEBuilder);
110       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_EDGE, DelEBuilder);
111       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_VERTEX, DelEBuilder);
112       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_VERTEX, DelEBuilder);      
113     }
114   }
115   else if (ObjType == TopAbs_SHELL || ObjType == TopAbs_FACE) {
116     //LoadShell(MS);
117     TNaming_Builder ModBuilder(ModifiedFaces()); 
118     QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_FACE, ModBuilder, Standard_False);
119     QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_EDGE, ModBuilder, Standard_False);
120
121     if(MS.HasGenerated()) {  
122       TNaming_Builder nBuilder (NewShapes());
123 //  generated free Edges
124       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_FACE, nBuilder);
125       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder);
126       QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_EDGE, nBuilder);
127     }
128     if(MS.HasDeleted()){ 
129       TNaming_Builder DelEBuilder(DeletedFaces());
130       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelEBuilder);
131       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelEBuilder);
132       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_EDGE, DelEBuilder); //free bound.
133       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_EDGE, DelEBuilder);      
134     }    
135   }
136   else if(ObjType == TopAbs_SOLID) {
137     TNaming_Builder ModBuilder(ModifiedFaces()); 
138     QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_FACE, ModBuilder, Standard_False);
139     QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape2(), TopAbs_FACE, ModBuilder, Standard_False);
140     
141     if(MS.HasDeleted()){ 
142       TNaming_Builder DelEBuilder(DeletedFaces());
143       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelEBuilder);
144       QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelEBuilder);    
145     }        
146   }
147
148   LoadDegenerated(MS);
149
150 }
151
152 //=======================================================================
153 //function : LoadResult
154 //purpose  : 
155 //=======================================================================
156
157 void QANewBRepNaming_Limitation::LoadResult(QANewModTopOpe_Limitation& MS) const {
158   Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel());
159   if (Tagger.IsNull()) return;
160   Tagger->Set(0);
161   TNaming_Builder Builder (ResultLabel());
162   TopoDS_Shape aResult = MS.Shape();
163   if (aResult.ShapeType() == TopAbs_COMPOUND) {
164     Standard_Integer nbSubResults = 0;
165     TopoDS_Iterator itr(aResult);
166     for (; itr.More(); itr.Next()) nbSubResults++;
167     if (nbSubResults == 1) {
168       itr.Initialize(aResult);
169       if (itr.More()) aResult = itr.Value();
170     }
171   }
172   if (MS.Shape1().IsNull()) Builder.Generated(aResult);
173   else Builder.Modify(MS.Shape1(), aResult);  
174 }
175
176 //=======================================================================
177 //function : LoadDegenerated
178 //purpose  : 
179 //=======================================================================
180
181 void QANewBRepNaming_Limitation::LoadDegenerated(QANewModTopOpe_Limitation& MS) const {
182   TopTools_IndexedMapOfShape allEdges;
183   TopExp::MapShapes(MS.Shape1(), TopAbs_EDGE, allEdges);
184   Standard_Integer i = 1;
185   for (; i <= allEdges.Extent(); i++) {
186     if (BRep_Tool::Degenerated(TopoDS::Edge(allEdges.FindKey(i)))) {
187       if (MS.IsDeleted(allEdges.FindKey(i))) {
188         TNaming_Builder DegeneratedBuilder(DeletedDegeneratedEdges()); 
189         DegeneratedBuilder.Generated(allEdges.FindKey(i));
190 #ifdef OCCT_DEBUG
191         TDataStd_Name::Set(DegeneratedBuilder.NamedShape()->Label(), "DeletedDegenerated");
192 #endif
193       }      
194     }
195   }
196 }
197 //=======================================================================
198 //function : LoadContent
199 //purpose  : 
200 //=======================================================================
201
202 void QANewBRepNaming_Limitation::LoadContent(QANewModTopOpe_Limitation& MS) const {
203   if (MS.Shape().ShapeType() == TopAbs_COMPSOLID || MS.Shape().ShapeType() == TopAbs_COMPOUND) {
204     TopoDS_Iterator itr(MS.Shape());
205     Standard_Integer nbShapes = 0;
206     while (itr.More()) {
207       nbShapes++;
208       itr.Next();
209     }
210     if (nbShapes > 1) {
211       for (itr.Initialize(MS.Shape()); itr.More(); itr.Next()) {
212         TNaming_Builder bContent(Content());
213         bContent.Generated(MS.Shape1(),itr.Value());
214         bContent.Generated(MS.Shape2(),itr.Value());
215       }
216     }
217   } 
218