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