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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
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>
29 #include <TColStd_ListOfInteger.hxx>
30 #include <BRep_Tool.hxx>
31 #include <TNaming_NamedShape.hxx>
34 #include <TDataStd_Name.hxx>
38 //=======================================================================
39 //function : QANewBRepNaming_Sphere
41 //=======================================================================
43 QANewBRepNaming_Sphere::QANewBRepNaming_Sphere() {}
45 //=======================================================================
46 //function : QANewBRepNaming_Sphere
48 //=======================================================================
50 QANewBRepNaming_Sphere::QANewBRepNaming_Sphere(const TDF_Label& ResultLabel):QANewBRepNaming_TopNaming(ResultLabel) {}
52 //=======================================================================
55 //=======================================================================
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;
63 //=======================================================================
66 //=======================================================================
68 TDF_Label QANewBRepNaming_Sphere::Bottom() const {
69 const TDF_Label& BottomL = ResultLabel().NewChild();
71 TDataStd_Name::Set(BottomL, "Bottom");
76 //=======================================================================
79 //=======================================================================
81 TDF_Label QANewBRepNaming_Sphere::Top() const {
82 const TDF_Label& TopL = ResultLabel().NewChild();
84 TDataStd_Name::Set(TopL, "Top");
89 //=======================================================================
92 //=======================================================================
94 TDF_Label QANewBRepNaming_Sphere::Lateral() const {
95 const TDF_Label& LateralL = ResultLabel().NewChild();
97 TDataStd_Name::Set(LateralL, "Lateral");
102 //=======================================================================
103 //function : StartSide
105 //=======================================================================
107 TDF_Label QANewBRepNaming_Sphere::StartSide() const {
108 const TDF_Label& StartSideL = ResultLabel().NewChild();
110 TDataStd_Name::Set(StartSideL, "StartSide");
115 //=======================================================================
118 //=======================================================================
120 TDF_Label QANewBRepNaming_Sphere::EndSide() const {
121 const TDF_Label& EndSideL = ResultLabel().NewChild();
123 TDataStd_Name::Set(EndSideL, "EndSide");
128 //=======================================================================
129 //function : Meridian
131 //=======================================================================
133 TDF_Label QANewBRepNaming_Sphere::Meridian() const {
134 const TDF_Label& MeridianL = ResultLabel().NewChild();
136 TDataStd_Name::Set(MeridianL, "Meridian");
141 //=======================================================================
142 //function : Degenerated
144 //=======================================================================
146 TDF_Label QANewBRepNaming_Sphere::Degenerated() const {
147 const TDF_Label& DegeneratedL = ResultLabel().NewChild();
149 TDataStd_Name::Set(DegeneratedL, "Degenerated");
154 //=======================================================================
155 //function : Load (Sphere)
157 //=======================================================================
159 void QANewBRepNaming_Sphere::Load (BRepPrimAPI_MakeSphere& mkSphere,
160 const QANewBRepNaming_TypeOfPrimitive3D Type) const
162 BRepPrim_Sphere& S = mkSphere.Sphere();
164 Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel());
165 if (Tagger.IsNull()) return;
168 TNaming_Builder Builder (ResultLabel());
169 if (Type == QANewBRepNaming_SOLID) Builder.Generated (mkSphere.Solid());
170 else if (Type == QANewBRepNaming_SHELL) Builder.Generated (mkSphere.Shell());
173 cout<<"QANewBRepNaming_Sphere::Load(): Unexpected type of result"<<endl;
174 Builder.Generated (mkSphere.Shape());
179 TopoDS_Face BottomFace = S.BottomFace();
180 TNaming_Builder BottomFaceIns(Bottom());
181 BottomFaceIns.Generated(BottomFace);
185 TopoDS_Face TopFace = S.TopFace();
186 TNaming_Builder TopFaceIns(Top());
187 TopFaceIns.Generated (TopFace);
190 TopoDS_Face LateralFace = S.LateralFace();
191 TNaming_Builder LateralFaceIns(Lateral());
192 LateralFaceIns.Generated(LateralFace);
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);
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);
210 TNaming_Builder DegeneratedBuilder(Degenerated());
211 DegeneratedBuilder.Generated(LateralEdges.FindKey(i));
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);