0025418: Debug output to be limited to OCC development environment
[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 #include <QANewBRepNaming_Sphere.ixx>
18 #include <QANewBRepNaming_Loader.hxx>
19 #include <TNaming_Builder.hxx>
20 #include <TDF_Label.hxx>
21 #include <TDF_TagSource.hxx>
22 #include <TopoDS.hxx>
23 #include <TopoDS_Solid.hxx>
24 #include <TopoDS_Shell.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <Standard_NullObject.hxx>
27 #include <TopTools_IndexedMapOfShape.hxx>
28 #include <TopExp.hxx>
29 #include <TColStd_ListOfInteger.hxx>
30 #include <BRep_Tool.hxx>
31 #include <TNaming_NamedShape.hxx>
32
33 #ifdef OCCT_DEBUG
34 #include <TDataStd_Name.hxx>
35 #endif
36
37
38 //=======================================================================
39 //function : QANewBRepNaming_Sphere
40 //purpose  : 
41 //=======================================================================
42
43 QANewBRepNaming_Sphere::QANewBRepNaming_Sphere() {}
44
45 //=======================================================================
46 //function : QANewBRepNaming_Sphere
47 //purpose  : 
48 //=======================================================================
49
50 QANewBRepNaming_Sphere::QANewBRepNaming_Sphere(const TDF_Label& ResultLabel):QANewBRepNaming_TopNaming(ResultLabel) {}
51
52 //=======================================================================
53 //function : Init
54 //purpose  : 
55 //=======================================================================
56
57 void QANewBRepNaming_Sphere::Init(const TDF_Label& ResultLabel) {
58   if(ResultLabel.IsNull())
59     Standard_NullObject::Raise("QANewBRepNaming_Sphere::Init The Result label is Null ..."); 
60   myResultLabel = ResultLabel;
61 }   
62
63 //=======================================================================
64 //function : Bottom
65 //purpose  : 
66 //=======================================================================
67
68 TDF_Label QANewBRepNaming_Sphere::Bottom() const {
69   const TDF_Label& BottomL = ResultLabel().NewChild();
70 #ifdef OCCT_DEBUG
71   TDataStd_Name::Set(BottomL, "Bottom");
72 #endif
73   return BottomL;
74 }
75
76 //=======================================================================
77 //function : Top
78 //purpose  : 
79 //=======================================================================
80
81 TDF_Label QANewBRepNaming_Sphere::Top() const {
82   const TDF_Label& TopL = ResultLabel().NewChild();
83 #ifdef OCCT_DEBUG
84   TDataStd_Name::Set(TopL, "Top");
85 #endif
86   return TopL;
87 }
88
89 //=======================================================================
90 //function : Lateral
91 //purpose  : 
92 //=======================================================================
93
94 TDF_Label QANewBRepNaming_Sphere::Lateral() const {
95   const TDF_Label& LateralL = ResultLabel().NewChild();
96 #ifdef OCCT_DEBUG
97   TDataStd_Name::Set(LateralL, "Lateral");
98 #endif
99   return LateralL;
100 }
101
102 //=======================================================================
103 //function : StartSide
104 //purpose  : 
105 //=======================================================================
106
107 TDF_Label QANewBRepNaming_Sphere::StartSide() const {
108   const TDF_Label& StartSideL = ResultLabel().NewChild();
109 #ifdef OCCT_DEBUG
110   TDataStd_Name::Set(StartSideL, "StartSide");
111 #endif
112   return StartSideL;
113 }
114
115 //=======================================================================
116 //function : EndSide
117 //purpose  : 
118 //=======================================================================
119
120 TDF_Label QANewBRepNaming_Sphere::EndSide() const {
121   const TDF_Label& EndSideL = ResultLabel().NewChild();
122 #ifdef OCCT_DEBUG
123   TDataStd_Name::Set(EndSideL, "EndSide");
124 #endif
125   return EndSideL;
126 }
127
128 //=======================================================================
129 //function : Meridian
130 //purpose  : 
131 //=======================================================================
132
133 TDF_Label QANewBRepNaming_Sphere::Meridian() const {
134   const TDF_Label& MeridianL = ResultLabel().NewChild();
135 #ifdef OCCT_DEBUG
136   TDataStd_Name::Set(MeridianL, "Meridian");
137 #endif
138   return MeridianL;
139 }
140
141 //=======================================================================
142 //function : Degenerated
143 //purpose  : 
144 //=======================================================================
145
146 TDF_Label QANewBRepNaming_Sphere::Degenerated() const {
147   const TDF_Label& DegeneratedL = ResultLabel().NewChild();
148 #ifdef OCCT_DEBUG
149   TDataStd_Name::Set(DegeneratedL, "Degenerated");
150 #endif
151   return DegeneratedL;
152 }
153
154 //=======================================================================
155 //function : Load (Sphere)
156 //purpose  : 
157 //=======================================================================
158
159 void QANewBRepNaming_Sphere::Load (BRepPrimAPI_MakeSphere& mkSphere, 
160                               const QANewBRepNaming_TypeOfPrimitive3D Type) const
161 {
162   BRepPrim_Sphere& S = mkSphere.Sphere();
163
164   Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel());
165   if (Tagger.IsNull()) return;
166   Tagger->Set(0);
167
168   TNaming_Builder Builder (ResultLabel());
169   if (Type == QANewBRepNaming_SOLID) Builder.Generated (mkSphere.Solid());
170   else if (Type == QANewBRepNaming_SHELL) Builder.Generated (mkSphere.Shell());
171   else {
172 #ifdef OCCT_DEBUG
173     cout<<"QANewBRepNaming_Sphere::Load(): Unexpected type of result"<<endl;
174     Builder.Generated (mkSphere.Shape());
175 #endif
176   }
177
178   if (S.HasBottom()) {
179     TopoDS_Face BottomFace = S.BottomFace();
180     TNaming_Builder BottomFaceIns(Bottom()); 
181     BottomFaceIns.Generated(BottomFace); 
182   }
183
184   if (S.HasTop()) {
185     TopoDS_Face TopFace = S.TopFace();
186     TNaming_Builder TopFaceIns(Top()); 
187     TopFaceIns.Generated (TopFace); 
188   }
189
190   TopoDS_Face LateralFace = S.LateralFace();
191   TNaming_Builder LateralFaceIns(Lateral()); 
192   LateralFaceIns.Generated(LateralFace); 
193
194   if (S.HasSides()) {
195     TopoDS_Face StartFace = S.StartFace();
196     TNaming_Builder StartFaceIns(StartSide()); 
197     StartFaceIns.Generated(StartFace); 
198     TopoDS_Face EndFace = S.EndFace();
199     TNaming_Builder EndFaceIns(EndSide()); 
200     EndFaceIns.Generated(EndFace); 
201   }
202
203   TopTools_IndexedMapOfShape LateralEdges;
204   TopExp::MapShapes(LateralFace, TopAbs_EDGE, LateralEdges);
205   Standard_Integer i = 1;
206   TColStd_ListOfInteger goodEdges;
207   for (; i <= LateralEdges.Extent(); i++) {
208     if (!BRep_Tool::Degenerated(TopoDS::Edge(LateralEdges.FindKey(i)))) goodEdges.Append(i);
209     else {
210       TNaming_Builder DegeneratedBuilder(Degenerated()); 
211       DegeneratedBuilder.Generated(LateralEdges.FindKey(i));
212     }      
213   }
214   if (goodEdges.Extent() == 1) {
215     const TopoDS_Edge& aLateralEdge = TopoDS::Edge(LateralEdges.FindKey(goodEdges.First()));
216     TNaming_Builder MeridianBuilder(Meridian());
217     MeridianBuilder.Generated(LateralFace, aLateralEdge);
218   }
219
220 }
221