ce08089a1c2db50921ee820f1ac2c2e21f1df348
[occt.git] / src / LocOpe / LocOpe_RevolutionForm.cxx
1 // Created on: 1997-10-20
2 // Created by: Olga KOULECHOVA
3 // Copyright (c) 1997-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 <BRepLib_MakeVertex.hxx>
19 #include <BRepSweep_Revol.hxx>
20 #include <BRepTools_Modifier.hxx>
21 #include <BRepTools_TrsfModification.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Curve.hxx>
24 #include <gp_Ax1.hxx>
25 #include <gp_Circ.hxx>
26 #include <gp_Trsf.hxx>
27 #include <gp_Vec.hxx>
28 #include <LocOpe.hxx>
29 #include <LocOpe_BuildShape.hxx>
30 #include <LocOpe_RevolutionForm.hxx>
31 #include <Precision.hxx>
32 #include <Standard_NoSuchObject.hxx>
33 #include <StdFail_NotDone.hxx>
34 #include <TColgp_SequenceOfPnt.hxx>
35 #include <TopExp.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopoDS.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
41
42 //=======================================================================
43 //function : LocOpe_Revol
44 //purpose  : 
45 //=======================================================================
46 LocOpe_RevolutionForm::LocOpe_RevolutionForm() :  myDone(Standard_False)
47
48 {}
49
50
51 //=======================================================================
52 //function : Perform
53 //purpose  : 
54 //=======================================================================
55
56 void LocOpe_RevolutionForm::Perform(const TopoDS_Shape& Base,
57                                     const gp_Ax1& Axis,
58                                     const Standard_Real Angle)
59 {
60   myMap.Clear();
61   myFirstShape.Nullify();
62   myLastShape.Nullify();
63   myBase.Nullify();
64   myRes.Nullify();
65   myBase = Base;
66   myAngle = Angle;
67   myAxis = Axis;
68   myAngTra = 0.;
69   myIsTrans = Standard_False;
70   IntPerf();
71 }
72
73
74 //=======================================================================
75 //function : IntPerf
76 //purpose  : 
77 //=======================================================================
78
79 void LocOpe_RevolutionForm::IntPerf()
80 {
81   TopoDS_Shape theBase = myBase;
82   BRepTools_Modifier Modif;
83   if (myIsTrans) {
84     gp_Trsf T;
85     T.SetRotation(myAxis,myAngTra);
86     Handle(BRepTools_TrsfModification) modbase = 
87       new BRepTools_TrsfModification(T);
88     Modif.Init(theBase);
89     Modif.Perform(modbase);
90     theBase = Modif.ModifiedShape(theBase);
91   }
92   
93   BRepSweep_Revol theRevol(theBase,myAxis,myAngle);
94
95   myFirstShape = theRevol.FirstShape();
96   myLastShape = theRevol.LastShape();
97
98   TopExp_Explorer exp;
99   if (theBase.ShapeType() == TopAbs_FACE) {
100     for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
101       const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
102       if (!myMap.IsBound(edg)) {
103         TopTools_ListOfShape thelist;
104         myMap.Bind(edg, thelist);
105         TopoDS_Shape desc = theRevol.Shape(edg);
106         if (!desc.IsNull()) {
107           myMap(edg).Append(desc);
108         }
109       }
110     }
111     myRes = theRevol.Shape();
112   }
113
114   else {
115     // Cas base != FACE
116     TopTools_IndexedDataMapOfShapeListOfShape theEFMap;
117     TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap);
118     TopTools_ListOfShape lfaces;
119     Standard_Boolean toremove = Standard_False;
120     for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) {
121       const TopoDS_Shape& edg = theEFMap.FindKey(i);
122       TopTools_ListOfShape thelist1;
123       myMap.Bind(edg, thelist1);
124       TopoDS_Shape desc = theRevol.Shape(edg);
125       if (!desc.IsNull()) {
126         if (theEFMap(i).Extent() >= 2) {
127           toremove = Standard_True;
128         }
129         else {
130           myMap(edg).Append(desc);
131           lfaces.Append(desc);
132         }
133       }
134     }
135     if(toremove) {
136       // Rajouter les faces de FirstShape et LastShape
137       for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) {
138         lfaces.Append(exp.Current());
139       }
140       for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) {
141         lfaces.Append(exp.Current());
142       }
143       
144       LocOpe_BuildShape BS(lfaces);
145       myRes = BS.Shape();
146     }
147     else {
148       for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
149         const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
150         if (!myMap.IsBound(edg)) {
151           TopTools_ListOfShape thelist2;  
152           myMap.Bind(edg, thelist2);
153           TopoDS_Shape desc = theRevol.Shape(edg);
154           if (!desc.IsNull()) {
155             myMap(edg).Append(desc);
156           }
157         }
158       }
159       myRes = theRevol.Shape();
160     }
161   }
162
163   if (myIsTrans) {
164     // m-a-j des descendants
165     TopExp_Explorer anExp;
166     for (anExp.Init(myBase,TopAbs_EDGE); anExp.More(); anExp.Next()) {
167       const TopoDS_Edge& edg = TopoDS::Edge(anExp.Current());
168       const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg));
169       if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) {
170         myMap.Bind(edg,myMap(edgbis));
171         myMap.UnBind(edgbis);
172       }
173     }
174   }
175   myDone = Standard_True;
176 }
177
178 //=======================================================================
179 //function : Shape
180 //purpose  : 
181 //=======================================================================
182
183 const TopoDS_Shape& LocOpe_RevolutionForm::Shape () const
184 {
185   if (!myDone) {
186     throw StdFail_NotDone();
187   }
188   return myRes;
189 }
190
191
192 //=======================================================================
193 //function : FirstShape
194 //purpose  : 
195 //=======================================================================
196
197 const TopoDS_Shape& LocOpe_RevolutionForm::FirstShape () const
198 {
199   return myFirstShape;
200 }
201
202 //=======================================================================
203 //function : LastShape
204 //purpose  : 
205 //=======================================================================
206
207 const TopoDS_Shape& LocOpe_RevolutionForm::LastShape () const
208 {
209   return myLastShape;
210 }
211
212
213 //=======================================================================
214 //function : Shapes
215 //purpose  : 
216 //=======================================================================
217
218 const TopTools_ListOfShape& LocOpe_RevolutionForm::Shapes (const TopoDS_Shape& S) const
219 {
220   return myMap(S);
221 }