Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / mfc / standard / Common / ISession2D / ISession2D_Shape.cpp
CommitLineData
7fd59977 1#include "stdafx.h"
2
3#include "ISession2D_Shape.h"
4#include <TopTools_ListIteratorOfListOfShape.hxx>
5#include <HLRBRep_PolyHLRToShape.hxx>
6#include <HLRBRep_HLRToShape.hxx>
7#include <TopExp.hxx>
8
9IMPLEMENT_STANDARD_HANDLE(ISession2D_Shape,AIS_InteractiveObject)
10IMPLEMENT_STANDARD_RTTIEXT(ISession2D_Shape,AIS_InteractiveObject)
11
12ISession2D_Shape::ISession2D_Shape ()
13 :AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant)
14{}
15
16void ISession2D_Shape::Add(const TopoDS_Shape& aShape)
17{
18 myListOfShape.Append(aShape);
19 myAlgo.Nullify();
20 myPolyAlgo.Nullify();
21 Update(); // protected method used to specify that the presentation are not up to date
22}
23
24void ISession2D_Shape::SetProjector(HLRAlgo_Projector& aProjector)
25{
26 myProjector= aProjector;
27 myAlgo.Nullify();
28 myPolyAlgo.Nullify();
29 Update(); // protected method used to specify that the presentation are not up to date
30};
31
32
33void ISession2D_Shape::SetNbIsos(Standard_Integer& aNbIsos)
34{
35 myNbIsos= aNbIsos;
36 myAlgo.Nullify();
37
38 // declare the mode 100 to 110 as non valid
39 for (int i=100;i<=110;i++)
40 Update(i,Standard_False); // protected method used to specify that the presentation are not up to date
41
42 // declare the mode 1100 to 1110 as non valid
43 for (int i=1100;i<=1110;i++)
44 Update(i,Standard_False); // protected method used to specify that the presentation are not up to date
45
46};
47
48
49/* virtual private */ void ISession2D_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,const Handle(Prs3d_Presentation)& aPresentation,const Standard_Integer aMode)
50{
51}
52/* virtual private */ void ISession2D_Shape::Compute(const Handle(Prs3d_Projector)& aProjector,const Handle(Prs3d_Presentation)& aPresentation)
53{
54}
55
56void ISession2D_Shape::BuildAlgo()
57{
58 myAlgo = new HLRBRep_Algo();
59 TopTools_ListIteratorOfListOfShape anIterator(myListOfShape);
60 for (;anIterator.More();anIterator.Next()) myAlgo->Add(anIterator.Value(),myNbIsos);
61 myAlgo->Projector(myProjector);
62 myAlgo->Update();
63 myAlgo->Hide();
64
65}
66void ISession2D_Shape::BuildPolyAlgo()
67{
68 myPolyAlgo = new HLRBRep_PolyAlgo();
69 TopTools_ListIteratorOfListOfShape anIterator(myListOfShape);
70 for (;anIterator.More();anIterator.Next()) myPolyAlgo->Load(anIterator.Value());
71 myPolyAlgo->Projector(myProjector);
72 myPolyAlgo->Update();
73}
74
75/* virtual private */ void ISession2D_Shape::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager,
76 const Handle(Graphic2d_GraphicObject)& aGrObj,
77 const Standard_Integer aMode)
78{
79 Standard_Integer TheMode = aMode;
80
81 Standard_Boolean DrawHiddenLine= Standard_True;
82 if (TheMode >= 1000)
83 {
84 DrawHiddenLine = Standard_False;
85 TheMode -= 1000;
86 }
87
88 Standard_Boolean UsePolyAlgo= Standard_True;
89 if (TheMode >= 100)
90 {
91 UsePolyAlgo = Standard_False;
92 TheMode -= 100;
93 }
94 TopoDS_Shape VCompound;
95 TopoDS_Shape Rg1LineVCompound;
96 TopoDS_Shape RgNLineVCompound;
97 TopoDS_Shape OutLineVCompound;
98 TopoDS_Shape IsoLineVCompound; // only fro Exact algo
99 TopoDS_Shape HCompound;
100 TopoDS_Shape Rg1LineHCompound;
101 TopoDS_Shape RgNLineHCompound;
102 TopoDS_Shape OutLineHCompound;
103 TopoDS_Shape IsoLineHCompound; // only fro Exact algo
104
105 if (UsePolyAlgo)
106 {
107 if (myPolyAlgo.IsNull()) BuildPolyAlgo();
108 HLRBRep_PolyHLRToShape aPolyHLRToShape;
109 aPolyHLRToShape.Update(myPolyAlgo);
110
111 VCompound = aPolyHLRToShape.VCompound();
112 Rg1LineVCompound = aPolyHLRToShape.Rg1LineVCompound();
113 RgNLineVCompound = aPolyHLRToShape.RgNLineVCompound();
114 OutLineVCompound = aPolyHLRToShape.OutLineVCompound();
115 HCompound = aPolyHLRToShape.HCompound();
116 Rg1LineHCompound = aPolyHLRToShape.Rg1LineHCompound();
117 RgNLineHCompound = aPolyHLRToShape.RgNLineHCompound();
118 OutLineHCompound = aPolyHLRToShape.OutLineHCompound();
119 }
120 else
121 {
122 if (myAlgo.IsNull()) BuildAlgo();
123 HLRBRep_HLRToShape aHLRToShape(myAlgo);
124
125 VCompound = aHLRToShape.VCompound();
126 Rg1LineVCompound = aHLRToShape.Rg1LineVCompound();
127 RgNLineVCompound = aHLRToShape.RgNLineVCompound();
128 OutLineVCompound = aHLRToShape.OutLineVCompound();
129 IsoLineVCompound = aHLRToShape.IsoLineVCompound();
130 HCompound = aHLRToShape.HCompound();
131 Rg1LineHCompound = aHLRToShape.Rg1LineHCompound();
132 RgNLineHCompound = aHLRToShape.RgNLineHCompound();
133 OutLineHCompound = aHLRToShape.OutLineHCompound();
134 IsoLineHCompound = aHLRToShape.IsoLineHCompound();
135 }
136
137 if (UsePolyAlgo)
138 {
139 Handle(Graphic2d_SetOfSegments) aSetOfVSegmentsHighLighted = new Graphic2d_SetOfSegments(aGrObj);
140 Handle(Graphic2d_SetOfSegments) aSetOfVSegments = new Graphic2d_SetOfSegments(aGrObj);
141
142 if (TheMode == 1) DrawCompound(VCompound , aSetOfVSegmentsHighLighted);
143 else DrawCompound(VCompound , aSetOfVSegments);
144 if (TheMode == 2) DrawCompound(Rg1LineVCompound , aSetOfVSegmentsHighLighted);
145 else DrawCompound(Rg1LineVCompound , aSetOfVSegments);
146 if (TheMode == 3) DrawCompound(RgNLineVCompound , aSetOfVSegmentsHighLighted);
147 else DrawCompound(RgNLineVCompound , aSetOfVSegments);
148 if (TheMode == 4) DrawCompound(OutLineVCompound , aSetOfVSegmentsHighLighted);
149 else DrawCompound(OutLineVCompound , aSetOfVSegments);
150
151 aSetOfVSegmentsHighLighted->SetColorIndex (1);
152 aSetOfVSegmentsHighLighted->SetWidthIndex (1);
153 aSetOfVSegmentsHighLighted->SetTypeIndex (1);
154 aSetOfVSegments->SetColorIndex (2);
155 aSetOfVSegments->SetWidthIndex (2);
156 if (DrawHiddenLine)
157 {
158 Handle(Graphic2d_SetOfSegments) aSetOfHSegmentsHighLighted = new Graphic2d_SetOfSegments(aGrObj);
159 Handle(Graphic2d_SetOfSegments) aSetOfHSegments = new Graphic2d_SetOfSegments(aGrObj);
160 if (TheMode == 6) DrawCompound(HCompound , aSetOfHSegmentsHighLighted);
161 else DrawCompound(HCompound , aSetOfHSegments);
162 if (TheMode == 7) DrawCompound(Rg1LineHCompound , aSetOfHSegmentsHighLighted);
163 else DrawCompound(Rg1LineHCompound , aSetOfHSegments);
164 if (TheMode == 8) DrawCompound(RgNLineHCompound , aSetOfHSegmentsHighLighted);
165 else DrawCompound(RgNLineHCompound , aSetOfHSegments);
166 if (TheMode == 9) DrawCompound(OutLineHCompound , aSetOfHSegmentsHighLighted);
167 else DrawCompound(OutLineHCompound , aSetOfHSegments);
168
169 aSetOfVSegments->SetTypeIndex (2);
170 aSetOfHSegmentsHighLighted->SetColorIndex (3);
171 aSetOfHSegmentsHighLighted->SetWidthIndex (3);
172 aSetOfHSegmentsHighLighted->SetTypeIndex (3);
173 aSetOfHSegments->SetColorIndex (4);
174 aSetOfHSegments->SetWidthIndex (4);
175 aSetOfHSegments->SetTypeIndex (4);
176 }
177 }
178 else
179 {
180 Handle(Graphic2d_SetOfCurves) aSetOfVCurvesHighLighted = new Graphic2d_SetOfCurves(aGrObj);
181 Handle(Graphic2d_SetOfCurves) aSetOfVCurves = new Graphic2d_SetOfCurves(aGrObj);
182
183 if (TheMode == 1) DrawCompound(VCompound , aSetOfVCurvesHighLighted);
184 else DrawCompound(VCompound , aSetOfVCurves);
185 if (TheMode == 2) DrawCompound(Rg1LineVCompound , aSetOfVCurvesHighLighted);
186 else DrawCompound(Rg1LineVCompound , aSetOfVCurves);
187 if (TheMode == 3) DrawCompound(RgNLineVCompound , aSetOfVCurvesHighLighted);
188 else DrawCompound(RgNLineVCompound , aSetOfVCurves);
189 if (TheMode == 4) DrawCompound(OutLineVCompound , aSetOfVCurvesHighLighted);
190 else DrawCompound(OutLineVCompound , aSetOfVCurves);
191 if (TheMode == 5) DrawCompound(IsoLineVCompound , aSetOfVCurvesHighLighted);
192 else DrawCompound(IsoLineVCompound , aSetOfVCurves);
193 aSetOfVCurvesHighLighted->SetColorIndex (1);
194 aSetOfVCurvesHighLighted->SetWidthIndex (1);
195 aSetOfVCurvesHighLighted->SetTypeIndex (1);
196 aSetOfVCurves->SetColorIndex (2);
197 aSetOfVCurves->SetWidthIndex (2);
198 aSetOfVCurves->SetTypeIndex (2);
199
200 if (DrawHiddenLine)
201 {
202 Handle(Graphic2d_SetOfCurves) aSetOfHCurvesHighLighted = new Graphic2d_SetOfCurves(aGrObj);
203 Handle(Graphic2d_SetOfCurves) aSetOfHCurves = new Graphic2d_SetOfCurves(aGrObj);
204 if (TheMode == 6) DrawCompound(HCompound , aSetOfHCurvesHighLighted);
205 else DrawCompound(HCompound , aSetOfHCurves);
206 if (TheMode == 7) DrawCompound(Rg1LineHCompound , aSetOfHCurvesHighLighted);
207 else DrawCompound(Rg1LineHCompound , aSetOfHCurves);
208 if (TheMode == 8) DrawCompound(RgNLineHCompound , aSetOfHCurvesHighLighted);
209 else DrawCompound(RgNLineHCompound , aSetOfHCurves);
210 if (TheMode == 9) DrawCompound(OutLineHCompound , aSetOfHCurvesHighLighted);
211 else DrawCompound(OutLineHCompound , aSetOfHCurves);
212 if (TheMode == 10) DrawCompound(IsoLineHCompound , aSetOfHCurvesHighLighted);
213 else DrawCompound(IsoLineHCompound , aSetOfHCurves);
214
215 aSetOfHCurvesHighLighted->SetColorIndex (3);
216 aSetOfHCurvesHighLighted->SetWidthIndex (3);
217 aSetOfHCurvesHighLighted->SetTypeIndex (3);
218 aSetOfHCurves->SetColorIndex (4);
219 aSetOfHCurves->SetWidthIndex (4);
220 aSetOfHCurves->SetTypeIndex (4);
221 }
222 }
223}
224
225
226void ISession2D_Shape::DrawCompound(TopoDS_Shape& aCompound,const Handle(Graphic2d_SetOfSegments)& aSetOfSegments)
227{
228 if (aCompound.IsNull())
229 return;
230
231 TopExp_Explorer ex(aCompound,TopAbs_EDGE);
232 while (ex.More()) {
233 const TopoDS_Edge& CurrentEdge = TopoDS::Edge(ex.Current());
234 const TopoDS_Vertex& FirstVertex=TopExp::FirstVertex(CurrentEdge);
235 const TopoDS_Vertex& LastVertex =TopExp::LastVertex(CurrentEdge);
236 gp_Pnt FirstPoint = BRep_Tool::Pnt(FirstVertex);
237 gp_Pnt LastPoint = BRep_Tool::Pnt(LastVertex);
238 aSetOfSegments->Add(FirstPoint.X(),FirstPoint.Y(),LastPoint.X(),LastPoint.Y());
239 ex.Next();
240 }
241}
242
243void ISession2D_Shape::DrawCompound(TopoDS_Shape& aCompound,const Handle(Graphic2d_SetOfCurves)& aSetOfCurves)
244{
245 if (aCompound.IsNull())
246 return;
247
248 TopExp_Explorer ex(aCompound,TopAbs_EDGE);
249 Handle(Geom2d_Curve) aCurve;
250 Handle(Geom_Surface) aSurface;
251 TopLoc_Location L;
252 Standard_Real f,l;
253 while (ex.More()) {
254 const TopoDS_Edge& CurrentEdge = TopoDS::Edge(ex.Current());
255 ASSERT(CurrentEdge.Location().IsIdentity());
256 BRep_Tool::CurveOnSurface(CurrentEdge,aCurve,aSurface,L,f,l);
257 ASSERT(L.IsIdentity());
258 Handle(Geom2d_TrimmedCurve) c= new Geom2d_TrimmedCurve(aCurve,f,l);
259 ASSERT(!c.IsNull());
260 aSetOfCurves->Add(c);
261 ex.Next();
262 }
263}
264
265void ISession2D_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
266 const Standard_Integer aMode)
267{
268}
269