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.
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>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Shell.hxx>
32 #include <TopoDS_Solid.hxx>
33 #include <TopTools_IndexedMapOfShape.hxx>
36 #include <TDataStd_Name.hxx>
40 //=======================================================================
41 //function : QANewBRepNaming_Sphere
43 //=======================================================================
45 QANewBRepNaming_Sphere::QANewBRepNaming_Sphere() {}
47 //=======================================================================
48 //function : QANewBRepNaming_Sphere
50 //=======================================================================
52 QANewBRepNaming_Sphere::QANewBRepNaming_Sphere(const TDF_Label& ResultLabel):QANewBRepNaming_TopNaming(ResultLabel) {}
54 //=======================================================================
57 //=======================================================================
59 void QANewBRepNaming_Sphere::Init(const TDF_Label& ResultLabel) {
60 if(ResultLabel.IsNull())
61 Standard_NullObject::Raise("QANewBRepNaming_Sphere::Init The Result label is Null ...");
62 myResultLabel = ResultLabel;
65 //=======================================================================
68 //=======================================================================
70 TDF_Label QANewBRepNaming_Sphere::Bottom() const {
71 const TDF_Label& BottomL = ResultLabel().NewChild();
73 TDataStd_Name::Set(BottomL, "Bottom");
78 //=======================================================================
81 //=======================================================================
83 TDF_Label QANewBRepNaming_Sphere::Top() const {
84 const TDF_Label& TopL = ResultLabel().NewChild();
86 TDataStd_Name::Set(TopL, "Top");
91 //=======================================================================
94 //=======================================================================
96 TDF_Label QANewBRepNaming_Sphere::Lateral() const {
97 const TDF_Label& LateralL = ResultLabel().NewChild();
99 TDataStd_Name::Set(LateralL, "Lateral");
104 //=======================================================================
105 //function : StartSide
107 //=======================================================================
109 TDF_Label QANewBRepNaming_Sphere::StartSide() const {
110 const TDF_Label& StartSideL = ResultLabel().NewChild();
112 TDataStd_Name::Set(StartSideL, "StartSide");
117 //=======================================================================
120 //=======================================================================
122 TDF_Label QANewBRepNaming_Sphere::EndSide() const {
123 const TDF_Label& EndSideL = ResultLabel().NewChild();
125 TDataStd_Name::Set(EndSideL, "EndSide");
130 //=======================================================================
131 //function : Meridian
133 //=======================================================================
135 TDF_Label QANewBRepNaming_Sphere::Meridian() const {
136 const TDF_Label& MeridianL = ResultLabel().NewChild();
138 TDataStd_Name::Set(MeridianL, "Meridian");
143 //=======================================================================
144 //function : Degenerated
146 //=======================================================================
148 TDF_Label QANewBRepNaming_Sphere::Degenerated() const {
149 const TDF_Label& DegeneratedL = ResultLabel().NewChild();
151 TDataStd_Name::Set(DegeneratedL, "Degenerated");
156 //=======================================================================
157 //function : Load (Sphere)
159 //=======================================================================
161 void QANewBRepNaming_Sphere::Load (BRepPrimAPI_MakeSphere& mkSphere,
162 const QANewBRepNaming_TypeOfPrimitive3D Type) const
164 BRepPrim_Sphere& S = mkSphere.Sphere();
166 Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel());
167 if (Tagger.IsNull()) return;
170 TNaming_Builder Builder (ResultLabel());
171 if (Type == QANewBRepNaming_SOLID) Builder.Generated (mkSphere.Solid());
172 else if (Type == QANewBRepNaming_SHELL) Builder.Generated (mkSphere.Shell());
175 cout<<"QANewBRepNaming_Sphere::Load(): Unexpected type of result"<<endl;
176 Builder.Generated (mkSphere.Shape());
181 TopoDS_Face BottomFace = S.BottomFace();
182 TNaming_Builder BottomFaceIns(Bottom());
183 BottomFaceIns.Generated(BottomFace);
187 TopoDS_Face TopFace = S.TopFace();
188 TNaming_Builder TopFaceIns(Top());
189 TopFaceIns.Generated (TopFace);
192 TopoDS_Face LateralFace = S.LateralFace();
193 TNaming_Builder LateralFaceIns(Lateral());
194 LateralFaceIns.Generated(LateralFace);
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);
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);
212 TNaming_Builder DegeneratedBuilder(Degenerated());
213 DegeneratedBuilder.Generated(LateralEdges.FindKey(i));
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);