0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / BRepSweep / BRepSweep_Trsf.cxx
1 // Created on: 1993-06-10
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1993-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 <BRepAdaptor_Curve.hxx>
21 #include <BRepLProp.hxx>
22 #include <BRepSweep_Iterator.hxx>
23 #include <BRepSweep_Trsf.hxx>
24 #include <GeomAbs_Shape.hxx>
25 #include <Precision.hxx>
26 #include <Sweep_NumShape.hxx>
27 #include <Sweep_NumShapeIterator.hxx>
28 #include <TopExp.hxx>
29 #include <TopLoc_Location.hxx>
30 #include <TopoDS.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
36
37 BRepSweep_Trsf::BRepSweep_Trsf(const BRep_Builder& aBuilder,
38                                const TopoDS_Shape& aGenShape,
39                                const Sweep_NumShape& aDirWire,
40                                const TopLoc_Location& aLocation,
41                                const Standard_Boolean aCopy):
42        BRepSweep_NumLinearRegularSweep(aBuilder,aGenShape,aDirWire),
43        myLocation(aLocation),
44        myCopy(aCopy)
45 {
46 }
47
48 void BRepSweep_Trsf::Init()
49 {
50   if(!myCopy){
51     Sweep_NumShapeIterator It;
52     for(It.Init(myDirWire);It.More();It.Next()){
53       Process(myGenShape,It.Value());
54     }
55   }
56 }
57
58 Standard_Boolean BRepSweep_Trsf::Process(const TopoDS_Shape& aGenS,
59                                          const Sweep_NumShape& aDirV)
60 {
61   Standard_Boolean dotrsf = (aDirV.Index()==2 && !myDirWire.Closed());
62   Standard_Integer iD = myDirShapeTool.Index(aDirV);
63   Standard_Integer iG = myGenShapeTool.Index(aGenS);
64   if(IsInvariant(aGenS)){ 
65     myShapes(iG,iD) = aGenS;
66     myBuiltShapes(iG,iD) = Standard_True;
67     return Standard_True;
68   }
69   else{
70     BRepSweep_Iterator Jt;
71     Standard_Boolean touch = Standard_False;
72     for(Jt.Init(aGenS);Jt.More();Jt.Next()){
73       if(Process(Jt.Value(),aDirV)) touch = Standard_True;
74     }
75     if(!touch || !dotrsf){
76       TopoDS_Shape newShape = aGenS;
77       if(dotrsf) newShape.Move(myLocation);
78       myShapes(iG,iD) = newShape;
79       myBuiltShapes(iG,iD) = Standard_True;
80     }   
81     return touch;
82   }
83 }
84
85 //=======================================================================
86 //function : SetContinuity
87 //purpose  : 
88 //=======================================================================
89
90 void BRepSweep_Trsf::SetContinuity(const TopoDS_Shape& aGenS, 
91                                    const Sweep_NumShape& aDirS)
92 {
93   Standard_Real tl = Precision::Confusion(), tol3d;
94   //angular etant un peu severe pour les contours sketches.
95   Standard_Real ta = 0.00175;//environ 0.1 degre
96   GeomAbs_Shape cont;
97   BRep_Builder B = myBuilder.Builder();
98   if(aGenS.ShapeType() == TopAbs_EDGE){
99     if (HasShape(aGenS,aDirS)){
100       TopoDS_Edge E = TopoDS::Edge(aGenS);
101       BRepAdaptor_Curve e;
102       Standard_Real ud,uf;
103       TopoDS_Vertex d,f;
104       TopExp::Vertices(E,d,f);
105       if(d.IsSame(f)){
106 //      tol3d = Max(tl,BRep_Tool::Tolerance(d));
107         tol3d = Max(tl,2.*BRep_Tool::Tolerance(d));//IFV 24.05.00 buc60684
108         e.Initialize(E);
109         ud = BRep_Tool::Parameter(d,TopoDS::Edge(aGenS));
110         uf = BRep_Tool::Parameter(f,TopoDS::Edge(aGenS));
111         cont = BRepLProp::Continuity(e,e,ud,uf,tol3d,ta);
112         if(cont >= 1){
113           TopoDS_Shape s_wnt = Shape(d,aDirS);
114           TopoDS_Edge e_wnt = TopoDS::Edge(s_wnt);
115           s_wnt = Shape(aGenS,aDirS);
116           TopoDS_Face f_wnt = TopoDS::Face(s_wnt);
117           B.Continuity(e_wnt,f_wnt,f_wnt,cont);
118         }
119       }
120       if(aDirS.Closed()){
121         Sweep_NumShape dirv = myDirShapeTool.Shape(2);
122         if(GDDShapeIsToAdd(Shape(aGenS,aDirS),
123                            Shape(aGenS,dirv),
124                            aGenS,aDirS,dirv)){
125           TopLoc_Location Lo;
126           Standard_Real fi,la;
127           cont = BRep_Tool::Curve(E,Lo,fi,la)->Continuity();
128           if(cont >= 1){
129             TopoDS_Shape s_wnt = Shape(aGenS,dirv);
130             TopoDS_Edge e_wnt = TopoDS::Edge(s_wnt);
131             s_wnt = Shape(aGenS,aDirS);
132             TopoDS_Face f_wnt = TopoDS::Face(s_wnt);
133             B.Continuity(e_wnt,f_wnt,f_wnt,cont);
134           }
135         }       
136       }
137     }
138   }
139   else if(aGenS.ShapeType() == TopAbs_WIRE){
140     TopoDS_Edge E1,E2;
141     BRepAdaptor_Curve e1,e2;
142     Standard_Real u1,u2;
143     TopTools_IndexedDataMapOfShapeListOfShape M;
144     TopExp::MapShapesAndAncestors(aGenS,TopAbs_VERTEX,TopAbs_EDGE,M);
145     TopTools_ListIteratorOfListOfShape It,Jt;    
146     for(Standard_Integer i = 1; i <= M.Extent(); i++){
147       TopoDS_Vertex V = TopoDS::Vertex(M.FindKey(i));
148       Standard_Integer j = 1;
149       for(It.Initialize(M.FindFromIndex(i));It.More();It.Next(),j++){
150         Jt.Initialize(M.FindFromIndex(i));
151         for(Standard_Integer k=1; k <= j; k++) { Jt.Next(); }
152         for(;Jt.More();Jt.Next()){
153           E1 = TopoDS::Edge(It.Value());
154           E2 = TopoDS::Edge(Jt.Value());
155           if (!E1.IsSame(E2) && HasShape(E1,aDirS) && HasShape(E2,aDirS)){
156             u1 = BRep_Tool::Parameter(V,E1);
157             u2 = BRep_Tool::Parameter(V,E2);
158 //          tol3d = Max(tl,BRep_Tool::Tolerance(V));
159             tol3d = Max(tl,2.*BRep_Tool::Tolerance(V)); //IFV 24.05.00 buc60684
160             e1.Initialize(E1);
161             e2.Initialize(E2);
162             cont = BRepLProp::Continuity(e1,e2,u1,u2,tol3d,ta);
163             if(cont >= 1){
164               TopoDS_Shape s_wnt = Shape(V,aDirS);
165               TopoDS_Edge e_wnt = TopoDS::Edge(s_wnt);
166               s_wnt = Shape(E1,aDirS);
167               TopoDS_Face f1_wnt = TopoDS::Face(s_wnt);
168               s_wnt = Shape(E2,aDirS);
169               TopoDS_Face f2_wnt = TopoDS::Face(s_wnt);
170               B.Continuity(e_wnt,f1_wnt,f2_wnt,cont);
171             }
172           }
173         }
174       }
175     }
176   }
177 }