0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / LocOpe / LocOpe_LinearForm.cxx
1 // Created on: 1996-09-04
2 // Created by: Olga PILLOT
3 // Copyright (c) 1996-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 <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepLib_MakeEdge.hxx>
21 #include <BRepLib_MakeVertex.hxx>
22 #include <BRepSweep_Prism.hxx>
23 #include <BRepTools_Modifier.hxx>
24 #include <BRepTools_TrsfModification.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_TrimmedCurve.hxx>
28 #include <gp_Ax1.hxx>
29 #include <gp_Pnt.hxx>
30 #include <gp_Trsf.hxx>
31 #include <gp_Vec.hxx>
32 #include <LocOpe.hxx>
33 #include <LocOpe_BuildShape.hxx>
34 #include <LocOpe_LinearForm.hxx>
35 #include <Standard_NoSuchObject.hxx>
36 #include <StdFail_NotDone.hxx>
37 #include <TColgp_SequenceOfPnt.hxx>
38 #include <TopExp.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <TopoDS.hxx>
41 #include <TopoDS_Compound.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
46 #include <TopTools_ListIteratorOfListOfShape.hxx>
47
48 //=======================================================================
49 //function : Perform
50 //purpose  : 
51 //=======================================================================
52 void LocOpe_LinearForm::Perform(const TopoDS_Shape& Base,
53                                 const gp_Vec& V,
54                                 const gp_Pnt& Pnt1,
55                                 const gp_Pnt& Pnt2)
56                                 
57 {
58   myIsTrans = Standard_False;
59   myMap.Clear();
60   myFirstShape.Nullify();
61   myLastShape.Nullify();
62   myBase.Nullify();
63   myRes.Nullify();
64
65   myBase = Base;
66   myVec = V;
67   
68 //myEdge = E;
69   myPnt1 = Pnt1;
70   myPnt2 = Pnt2;
71
72   IntPerf();
73 }
74
75
76 //=======================================================================
77 //function : Perform
78 //purpose  : 
79 //=======================================================================
80
81 void LocOpe_LinearForm::Perform(const TopoDS_Shape& Base,
82                                 const gp_Vec& V,
83                                 const gp_Vec& Vectra,
84                                 const gp_Pnt& Pnt1,
85                                 const gp_Pnt& Pnt2)
86                                 
87 {
88   myIsTrans = Standard_True;
89   myTra = Vectra;
90   myMap.Clear();
91   myFirstShape.Nullify();
92   myLastShape.Nullify();
93   myBase.Nullify();
94   myRes.Nullify();
95
96   myBase = Base;
97   myVec = V;
98   
99 //myEdge = E;
100   myPnt1 = Pnt1;
101   myPnt2 = Pnt2;
102
103
104   IntPerf();
105 }
106
107 //=======================================================================
108 //function : IntPerf
109 //purpose  : 
110 //=======================================================================
111
112 void LocOpe_LinearForm::IntPerf()
113 {
114   TopoDS_Shape theBase = myBase;
115   BRepTools_Modifier Modif;
116
117   if (myIsTrans) {
118     gp_Trsf T;
119     T.SetTranslation(myTra);
120     Handle(BRepTools_TrsfModification) modbase = 
121       new BRepTools_TrsfModification(T);
122     Modif.Init(theBase);
123     Modif.Perform(modbase);
124     theBase = Modif.ModifiedShape(theBase);
125   }
126
127   BRepSweep_Prism myPrism(theBase, myVec);
128
129   myFirstShape = myPrism.FirstShape();
130   myLastShape = myPrism.LastShape();
131
132   TopExp_Explorer exp;
133   if (theBase.ShapeType() == TopAbs_FACE) {
134     for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
135       const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
136       if (!myMap.IsBound(edg)) {
137         TopTools_ListOfShape thelist;
138         myMap.Bind(edg, thelist);
139         TopoDS_Shape desc = myPrism.Shape(edg);
140         if (!desc.IsNull()) {
141           myMap(edg).Append(desc);
142         }
143       }
144     }
145     myRes = myPrism.Shape();
146   }
147
148   else {
149     // Cas base != FACE
150     TopTools_IndexedDataMapOfShapeListOfShape theEFMap;
151     TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap);
152     TopTools_ListOfShape lfaces;
153     Standard_Boolean toremove = Standard_False;
154     for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) {
155       const TopoDS_Shape& edg = theEFMap.FindKey(i);
156       TopTools_ListOfShape thelist1;
157       myMap.Bind(edg, thelist1);
158       TopoDS_Shape desc = myPrism.Shape(edg);
159       if (!desc.IsNull()) {
160         if (theEFMap(i).Extent() >= 2) {
161           toremove = Standard_True;
162         }
163         else {
164           myMap(edg).Append(desc);
165           lfaces.Append(desc);
166         }
167       }
168     }
169     if(toremove) {  
170       // Rajouter les faces de FirstShape et LastShape
171       for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) {
172         lfaces.Append(exp.Current());
173       }
174       for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) {
175         lfaces.Append(exp.Current());
176       }
177       
178       LocOpe_BuildShape BS(lfaces);
179       myRes = BS.Shape();
180     }
181     else {
182       for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
183         const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
184         if (!myMap.IsBound(edg)) {
185           TopTools_ListOfShape thelist2;
186           myMap.Bind(edg, thelist2);
187           TopoDS_Shape desc = myPrism.Shape(edg);
188           if (!desc.IsNull()) {
189             myMap(edg).Append(desc);
190           }
191         }
192       }
193       myRes = myPrism.Shape();
194     }
195   }
196
197   if (myIsTrans) {
198     // m-a-j des descendants
199     TopExp_Explorer anExp;
200     for (anExp.Init(myBase,TopAbs_EDGE); anExp.More(); anExp.Next()) {
201       const TopoDS_Edge& edg = TopoDS::Edge(anExp.Current());
202       const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg));
203       if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) {
204         myMap.Bind(edg,myMap(edgbis));
205         myMap.UnBind(edgbis);
206       }
207     }
208   }
209
210   myDone = Standard_True;
211 }
212
213 //=======================================================================
214 //function : Shape
215 //purpose  : 
216 //=======================================================================
217
218 const TopoDS_Shape& LocOpe_LinearForm::Shape () const
219 {
220   if (!myDone) {
221     throw StdFail_NotDone();
222   }
223   return myRes;
224 }
225
226
227 //=======================================================================
228 //function : FirstShape
229 //purpose  : 
230 //=======================================================================
231
232 const TopoDS_Shape& LocOpe_LinearForm::FirstShape () const
233 {
234   return myFirstShape;
235 }
236
237 //=======================================================================
238 //function : LastShape
239 //purpose  : 
240 //=======================================================================
241
242 const TopoDS_Shape& LocOpe_LinearForm::LastShape () const
243 {
244   return myLastShape;
245 }
246
247
248 //=======================================================================
249 //function : Shapes
250 //purpose  : 
251 //=======================================================================
252
253 const TopTools_ListOfShape& LocOpe_LinearForm::Shapes (const TopoDS_Shape& S) const
254 {
255   return myMap(S);
256 }
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302