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
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 <BRepLib_MakeVertex.hxx>
19 #include <BRepSweep_Prism.hxx>
20 #include <BRepTools_Modifier.hxx>
21 #include <BRepTools_TrsfModification.hxx>
22 #include <Geom_Curve.hxx>
23 #include <Geom_Line.hxx>
24 #include <Geom_TrimmedCurve.hxx>
26 #include <gp_Trsf.hxx>
29 #include <LocOpe_BuildShape.hxx>
30 #include <LocOpe_Prism.hxx>
31 #include <StdFail_NotDone.hxx>
32 #include <TColgp_SequenceOfPnt.hxx>
34 #include <TopExp_Explorer.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Shape.hxx>
38 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
40 //=======================================================================
41 //function : LocOpe_Prism
43 //=======================================================================
44 LocOpe_Prism::LocOpe_Prism()
45 : myIsTrans(Standard_False),
46 myDone(Standard_False)
50 //=======================================================================
51 //function : LocOpe_Prism
53 //=======================================================================
55 LocOpe_Prism::LocOpe_Prism(const TopoDS_Shape& Base,
57 myBase(Base), myVec(V), myIsTrans(Standard_False)
63 //=======================================================================
64 //function : LocOpe_Prism
66 //=======================================================================
68 LocOpe_Prism::LocOpe_Prism(const TopoDS_Shape& Base,
71 myBase(Base), myVec(V), myTra(Vtra), myIsTrans(Standard_True)
78 //=======================================================================
81 //=======================================================================
83 void LocOpe_Prism::Perform(const TopoDS_Shape& Base,
87 myFirstShape.Nullify();
88 myLastShape.Nullify();
94 myIsTrans = Standard_False;
98 //=======================================================================
101 //=======================================================================
103 void LocOpe_Prism::Perform(const TopoDS_Shape& Base,
108 myFirstShape.Nullify();
109 myLastShape.Nullify();
116 myIsTrans = Standard_True;
121 //=======================================================================
124 //=======================================================================
126 void LocOpe_Prism::IntPerf()
128 TopoDS_Shape theBase = myBase;
129 BRepTools_Modifier Modif;
132 T.SetTranslation(myTra);
133 Handle(BRepTools_TrsfModification) modbase =
134 new BRepTools_TrsfModification(T);
136 Modif.Perform(modbase);
137 theBase = Modif.ModifiedShape(theBase);
140 BRepSweep_Prism thePrism(theBase,myVec);
142 myFirstShape = thePrism.FirstShape();
143 myLastShape = thePrism.LastShape();
146 if (theBase.ShapeType() == TopAbs_FACE) {
147 for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
148 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
149 if (!myMap.IsBound(edg)) {
150 TopTools_ListOfShape thelist;
151 myMap.Bind(edg, thelist);
152 TopoDS_Shape desc = thePrism.Shape(edg);
153 if (!desc.IsNull()) {
154 myMap(edg).Append(desc);
158 myRes = thePrism.Shape();
163 TopTools_IndexedDataMapOfShapeListOfShape theEFMap;
164 TopExp::MapShapesAndAncestors(theBase,TopAbs_EDGE,TopAbs_FACE,theEFMap);
165 TopTools_ListOfShape lfaces;
166 Standard_Boolean toremove = Standard_False;
167 for (Standard_Integer i=1; i<=theEFMap.Extent(); i++) {
168 const TopoDS_Shape& edg = theEFMap.FindKey(i);
169 TopTools_ListOfShape thelist1;
170 myMap.Bind(edg, thelist1);
171 TopoDS_Shape desc = thePrism.Shape(edg);
172 if (!desc.IsNull()) {
173 if (theEFMap(i).Extent() >= 2) {
174 toremove = Standard_True;
177 myMap(edg).Append(desc);
183 // Rajouter les faces de FirstShape et LastShape
184 for (exp.Init(myFirstShape,TopAbs_FACE);exp.More();exp.Next()) {
185 lfaces.Append(exp.Current());
187 for (exp.Init(myLastShape,TopAbs_FACE);exp.More();exp.Next()) {
188 lfaces.Append(exp.Current());
191 LocOpe_BuildShape BS(lfaces);
195 for (exp.Init(theBase,TopAbs_EDGE);exp.More();exp.Next()) {
196 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
197 if (!myMap.IsBound(edg)) {
198 TopTools_ListOfShape thelist2;
199 myMap.Bind(edg, thelist2);
200 TopoDS_Shape desc = thePrism.Shape(edg);
201 if (!desc.IsNull()) {
202 myMap(edg).Append(desc);
206 myRes = thePrism.Shape();
211 // m-a-j des descendants
212 TopExp_Explorer anExp;
213 for (anExp.Init(myBase,TopAbs_EDGE); anExp.More(); anExp.Next()) {
214 const TopoDS_Edge& edg = TopoDS::Edge(anExp.Current());
215 const TopoDS_Edge& edgbis = TopoDS::Edge(Modif.ModifiedShape(edg));
216 if (!edgbis.IsSame(edg) && myMap.IsBound(edgbis)) {
217 myMap.Bind(edg,myMap(edgbis));
218 myMap.UnBind(edgbis);
222 myDone = Standard_True;
225 //=======================================================================
228 //=======================================================================
230 const TopoDS_Shape& LocOpe_Prism::Shape () const
233 throw StdFail_NotDone();
239 //=======================================================================
240 //function : FirstShape
242 //=======================================================================
244 const TopoDS_Shape& LocOpe_Prism::FirstShape () const
249 //=======================================================================
250 //function : LastShape
252 //=======================================================================
254 const TopoDS_Shape& LocOpe_Prism::LastShape () const
260 //=======================================================================
263 //=======================================================================
265 const TopTools_ListOfShape& LocOpe_Prism::Shapes (const TopoDS_Shape& S) const
271 //=======================================================================
274 //=======================================================================
276 void LocOpe_Prism::Curves(TColGeom_SequenceOfCurve& Scurves) const
279 TColgp_SequenceOfPnt spt;
280 LocOpe::SampleEdges(myFirstShape,spt);
281 Standard_Real height =
282 Sqrt(myVec.X()*myVec.X()+myVec.Y()*myVec.Y()+myVec.Z()*myVec.Z());
283 Standard_Real u1 = -2*height;
284 Standard_Real u2 = 2*height;
286 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
287 gp_Ax1 theAx(spt(jj),myVec);
288 Handle(Geom_Line) theLin = new Geom_Line(theAx);
289 Handle(Geom_TrimmedCurve) trlin =
290 new Geom_TrimmedCurve(theLin, u1, u2, Standard_True);
291 Scurves.Append(trlin);
295 //=======================================================================
296 //function : BarycCurve
298 //=======================================================================
300 Handle(Geom_Curve) LocOpe_Prism::BarycCurve() const
302 gp_Pnt bar(0., 0., 0.);
303 TColgp_SequenceOfPnt spt;
304 LocOpe::SampleEdges(myFirstShape,spt);
305 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
306 const gp_Pnt& pvt = spt(jj);
307 bar.ChangeCoord() += pvt.XYZ();
309 bar.ChangeCoord().Divide(spt.Length());
310 gp_Ax1 newAx(bar,myVec);
311 Handle(Geom_Line) theLin = new Geom_Line(newAx);