0028207: Unexpected result of the unify same domain algorithm
[occt.git] / src / QANewBRepNaming / QANewBRepNaming_Sphere.cxx
1 // Created on: 1999-11-05
2 // Created by: Vladislav ROMASHKO
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRep_Tool.hxx>
19 #include <BRepPrimAPI_MakeSphere.hxx>
20 #include <QANewBRepNaming_Loader.hxx>
21 #include <QANewBRepNaming_Sphere.hxx>
22 #include <Standard_NullObject.hxx>
23 #include <TColStd_ListOfInteger.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDF_TagSource.hxx>
26 #include <TNaming_Builder.hxx>
27 #include <TNaming_NamedShape.hxx>
28 #include <TopExp.hxx>
29 #include <TopoDS.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Shell.hxx>
32 #include <TopoDS_Solid.hxx>
33 #include <TopTools_IndexedMapOfShape.hxx>
34
35 #ifdef OCCT_DEBUG
36 #include <TDataStd_Name.hxx>
37 #endif
38
39
40 //=======================================================================
41 //function : QANewBRepNaming_Sphere
42 //purpose  : 
43 //=======================================================================
44
45 QANewBRepNaming_Sphere::QANewBRepNaming_Sphere() {}
46
47 //=======================================================================
48 //function : QANewBRepNaming_Sphere
49 //purpose  : 
50 //=======================================================================
51
52 QANewBRepNaming_Sphere::QANewBRepNaming_Sphere(const TDF_Label& ResultLabel):QANewBRepNaming_TopNaming(ResultLabel) {}
53
54 //=======================================================================
55 //function : Init
56 //purpose  : 
57 //=======================================================================
58
59 void QANewBRepNaming_Sphere::Init(const TDF_Label& ResultLabel) {
60   if(ResultLabel.IsNull())
61     throw Standard_NullObject("QANewBRepNaming_Sphere::Init The Result label is Null ...");
62   myResultLabel = ResultLabel;
63 }   
64
65 //=======================================================================
66 //function : Bottom
67 //purpose  : 
68 //=======================================================================
69
70 TDF_Label QANewBRepNaming_Sphere::Bottom() const {
71   const TDF_Label& BottomL = ResultLabel().NewChild();
72 #ifdef OCCT_DEBUG
73   TDataStd_Name::Set(BottomL, "Bottom");
74 #endif
75   return BottomL;
76 }
77
78 //=======================================================================
79 //function : Top
80 //purpose  : 
81 //=======================================================================
82
83 TDF_Label QANewBRepNaming_Sphere::Top() const {
84   const TDF_Label& TopL = ResultLabel().NewChild();
85 #ifdef OCCT_DEBUG
86   TDataStd_Name::Set(TopL, "Top");
87 #endif
88   return TopL;
89 }
90
91 //=======================================================================
92 //function : Lateral
93 //purpose  : 
94 //=======================================================================
95
96 TDF_Label QANewBRepNaming_Sphere::Lateral() const {
97   const TDF_Label& LateralL = ResultLabel().NewChild();
98 #ifdef OCCT_DEBUG
99   TDataStd_Name::Set(LateralL, "Lateral");
100 #endif
101   return LateralL;
102 }
103
104 //=======================================================================
105 //function : StartSide
106 //purpose  : 
107 //=======================================================================
108
109 TDF_Label QANewBRepNaming_Sphere::StartSide() const {
110   const TDF_Label& StartSideL = ResultLabel().NewChild();
111 #ifdef OCCT_DEBUG
112   TDataStd_Name::Set(StartSideL, "StartSide");
113 #endif
114   return StartSideL;
115 }
116
117 //=======================================================================
118 //function : EndSide
119 //purpose  : 
120 //=======================================================================
121
122 TDF_Label QANewBRepNaming_Sphere::EndSide() const {
123   const TDF_Label& EndSideL = ResultLabel().NewChild();
124 #ifdef OCCT_DEBUG
125   TDataStd_Name::Set(EndSideL, "EndSide");
126 #endif
127   return EndSideL;
128 }
129
130 //=======================================================================
131 //function : Meridian
132 //purpose  : 
133 //=======================================================================
134
135 TDF_Label QANewBRepNaming_Sphere::Meridian() const {
136   const TDF_Label& MeridianL = ResultLabel().NewChild();
137 #ifdef OCCT_DEBUG
138   TDataStd_Name::Set(MeridianL, "Meridian");
139 #endif
140   return MeridianL;
141 }
142
143 //=======================================================================
144 //function : Degenerated
145 //purpose  : 
146 //=======================================================================
147
148 TDF_Label QANewBRepNaming_Sphere::Degenerated() const {
149   const TDF_Label& DegeneratedL = ResultLabel().NewChild();
150 #ifdef OCCT_DEBUG
151   TDataStd_Name::Set(DegeneratedL, "Degenerated");
152 #endif
153   return DegeneratedL;
154 }
155
156 //=======================================================================
157 //function : Load (Sphere)
158 //purpose  : 
159 //=======================================================================
160
161 void QANewBRepNaming_Sphere::Load (BRepPrimAPI_MakeSphere& mkSphere, 
162                               const QANewBRepNaming_TypeOfPrimitive3D Type) const
163 {
164   BRepPrim_Sphere& S = mkSphere.Sphere();
165
166   Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel());
167   if (Tagger.IsNull()) return;
168   Tagger->Set(0);
169
170   TNaming_Builder Builder (ResultLabel());
171   if (Type == QANewBRepNaming_SOLID) Builder.Generated (mkSphere.Solid());
172   else if (Type == QANewBRepNaming_SHELL) Builder.Generated (mkSphere.Shell());
173   else {
174 #ifdef OCCT_DEBUG
175     cout<<"QANewBRepNaming_Sphere::Load(): Unexpected type of result"<<endl;
176     Builder.Generated (mkSphere.Shape());
177 #endif
178   }
179
180   if (S.HasBottom()) {
181     TopoDS_Face BottomFace = S.BottomFace();
182     TNaming_Builder BottomFaceIns(Bottom()); 
183     BottomFaceIns.Generated(BottomFace); 
184   }
185
186   if (S.HasTop()) {
187     TopoDS_Face TopFace = S.TopFace();
188     TNaming_Builder TopFaceIns(Top()); 
189     TopFaceIns.Generated (TopFace); 
190   }
191
192   TopoDS_Face LateralFace = S.LateralFace();
193   TNaming_Builder LateralFaceIns(Lateral()); 
194   LateralFaceIns.Generated(LateralFace); 
195
196   if (S.HasSides()) {
197     TopoDS_Face StartFace = S.StartFace();
198     TNaming_Builder StartFaceIns(StartSide()); 
199     StartFaceIns.Generated(StartFace); 
200     TopoDS_Face EndFace = S.EndFace();
201     TNaming_Builder EndFaceIns(EndSide()); 
202     EndFaceIns.Generated(EndFace); 
203   }
204
205   TopTools_IndexedMapOfShape LateralEdges;
206   TopExp::MapShapes(LateralFace, TopAbs_EDGE, LateralEdges);
207   Standard_Integer i = 1;
208   TColStd_ListOfInteger goodEdges;
209   for (; i <= LateralEdges.Extent(); i++) {
210     if (!BRep_Tool::Degenerated(TopoDS::Edge(LateralEdges.FindKey(i)))) goodEdges.Append(i);
211     else {
212       TNaming_Builder DegeneratedBuilder(Degenerated()); 
213       DegeneratedBuilder.Generated(LateralEdges.FindKey(i));
214     }      
215   }
216   if (goodEdges.Extent() == 1) {
217     const TopoDS_Edge& aLateralEdge = TopoDS::Edge(LateralEdges.FindKey(goodEdges.First()));
218     TNaming_Builder MeridianBuilder(Meridian());
219     MeridianBuilder.Generated(LateralFace, aLateralEdge);
220   }
221
222 }
223