Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // | |
3 | // The content of this file is subject to the Open CASCADE Technology Public | |
4 | // License Version 6.5 (the "License"). You may not use the content of this file | |
5 | // except in compliance with the License. Please obtain a copy of the License | |
6 | // at http://www.opencascade.org and read it completely before using this file. | |
7 | // | |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
10 | // | |
11 | // The Original Code and all software distributed under the License is | |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
13 | // Initial Developer hereby disclaims all such warranties, including without | |
14 | // limitation, any warranties of merchantability, fitness for a particular | |
15 | // purpose or non-infringement. Please see the License for the specific terms | |
16 | // and conditions governing the rights and limitations under the License. | |
17 | ||
7fd59977 | 18 | #include <AIS2D_ProjShape.ixx> |
19 | #include <TopExp_Explorer.hxx> | |
20 | #include <TopoDS.hxx> | |
21 | #include <TopExp.hxx> | |
22 | #include <Geom2d_TrimmedCurve.hxx> | |
23 | #include <Geom2d_Curve.hxx> | |
24 | #include <Geom_Surface.hxx> | |
25 | #include <BRep_Tool.hxx> | |
26 | #include <gp_Pnt.hxx> | |
27 | #include <TopoDS_Vertex.hxx> | |
28 | #include <TopTools_ListOfShape.hxx> | |
29 | #include <HLRBRep_PolyAlgo.hxx> | |
30 | #include <HLRAlgo_Projector.hxx> | |
31 | #include <HLRBRep_PolyHLRToShape.hxx> | |
32 | #include <HLRBRep_HLRToShape.hxx> | |
33 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
34 | #include <TopLoc_Location.hxx> | |
91a16bc7 | 35 | #include <Standard_Assert.hxx> |
7fd59977 | 36 | |
37 | #include <V2d_Viewer.hxx> | |
38 | ||
39 | #include <AIS2D_InteractiveContext.hxx> | |
40 | ||
41 | ||
42 | AIS2D_ProjShape::AIS2D_ProjShape( ) | |
43 | : | |
44 | AIS2D_InteractiveObject(), | |
45 | ||
46 | myProjector( HLRAlgo_Projector() ), | |
47 | myNbIsos( 3 ), | |
48 | myIsPolyAlgo( Standard_False ), | |
49 | myIsHiddenLine( Standard_True ), | |
50 | myESharp( Standard_True ), | |
51 | myESmooth( Standard_True ), | |
52 | myESewn( Standard_True ), | |
53 | myEOutline( Standard_True ), | |
54 | myEIsoline( Standard_True ) | |
55 | ||
56 | { | |
57 | } | |
58 | ||
59 | AIS2D_ProjShape::AIS2D_ProjShape( const HLRAlgo_Projector& aProjector, | |
60 | const Standard_Integer nbIsos, | |
61 | const Standard_Boolean isPolyAlgo, | |
62 | const Standard_Boolean visHL ) | |
63 | : | |
64 | AIS2D_InteractiveObject(), | |
65 | myProjector( aProjector ), | |
66 | myNbIsos( nbIsos ), | |
67 | myIsPolyAlgo( isPolyAlgo ), | |
68 | myIsHiddenLine( visHL ), | |
69 | myESharp( Standard_True ), | |
70 | myESmooth( Standard_True ), | |
71 | myESewn( Standard_True ), | |
72 | myEOutline( Standard_True ), | |
73 | myEIsoline( Standard_True ) | |
74 | ||
75 | { | |
76 | } | |
77 | ||
78 | ||
79 | void AIS2D_ProjShape::Add( const TopoDS_Shape& aShape ) { | |
80 | ||
81 | myListOfShape.Append( aShape ); | |
82 | myAlgo.Nullify(); | |
83 | myPolyAlgo.Nullify(); | |
84 | ComputeShape(); | |
85 | } | |
86 | ||
87 | void AIS2D_ProjShape::ComputeShape() { | |
88 | ||
89 | TopoDS_Shape VCompound, Rg1LineVCompound, RgNLineVCompound, | |
90 | OutLineVCompound, IsoLineVCompound, | |
91 | HCompound, Rg1LineHCompound, RgNLineHCompound, | |
92 | OutLineHCompound, IsoLineHCompound; | |
93 | ||
94 | if ( myIsPolyAlgo ) { | |
95 | ||
96 | if ( myPolyAlgo.IsNull() ) CreatePolyAlgo(); | |
97 | ||
98 | HLRBRep_PolyHLRToShape aPolyHLRToShape; | |
99 | aPolyHLRToShape.Update( myPolyAlgo ); | |
100 | ||
101 | mySetOfSegments = new Graphic2d_SetOfSegments( this ); | |
102 | myHSetOfSegments = new Graphic2d_SetOfSegments( this ); | |
103 | ||
104 | if ( myESharp ) { | |
105 | VCompound = aPolyHLRToShape.VCompound(); | |
106 | DrawSegments( Rg1LineVCompound, mySetOfSegments ); | |
107 | } | |
108 | if ( myESmooth ) { | |
109 | Rg1LineVCompound = aPolyHLRToShape.Rg1LineVCompound(); | |
110 | DrawSegments( RgNLineVCompound, mySetOfSegments ); | |
111 | } | |
112 | if ( myESewn ) { | |
113 | RgNLineVCompound = aPolyHLRToShape.RgNLineVCompound(); | |
114 | DrawSegments( OutLineVCompound, mySetOfSegments ); | |
115 | } | |
116 | if ( myEOutline ) { | |
117 | OutLineVCompound = aPolyHLRToShape.OutLineVCompound(); | |
118 | DrawSegments( VCompound, mySetOfSegments ); | |
119 | } | |
120 | ||
121 | if ( myIsHiddenLine ) { | |
122 | if ( myESharp ) { | |
123 | HCompound = aPolyHLRToShape.HCompound(); | |
124 | DrawSegments( Rg1LineHCompound, myHSetOfSegments ); | |
125 | } | |
126 | if ( myESmooth ) { | |
127 | Rg1LineHCompound = aPolyHLRToShape.Rg1LineHCompound(); | |
128 | DrawSegments( RgNLineHCompound, myHSetOfSegments ); | |
129 | } | |
130 | if ( myESewn ) { | |
131 | RgNLineHCompound = aPolyHLRToShape.RgNLineHCompound(); | |
132 | DrawSegments( OutLineHCompound, myHSetOfSegments ); | |
133 | } | |
134 | if ( myEOutline ) { | |
135 | OutLineHCompound = aPolyHLRToShape.OutLineHCompound(); | |
136 | DrawSegments( HCompound, myHSetOfSegments ); | |
137 | } | |
138 | } // end if is HiddenLine | |
139 | } else { | |
140 | ||
141 | if ( myAlgo.IsNull() ) CreateAlgo(); | |
142 | ||
143 | HLRBRep_HLRToShape aHLRToShape( myAlgo ); | |
144 | ||
145 | mySetOfCurves = new GGraphic2d_SetOfCurves( this ); | |
146 | myHSetOfCurves = new GGraphic2d_SetOfCurves( this ); | |
147 | ||
148 | if ( myESharp ) { | |
149 | VCompound = aHLRToShape.VCompound(); | |
150 | DrawCurves( VCompound, mySetOfCurves ); | |
151 | } | |
152 | if ( myESmooth ) { | |
153 | Rg1LineVCompound = aHLRToShape.Rg1LineVCompound(); | |
154 | DrawCurves( Rg1LineVCompound, mySetOfCurves ); | |
155 | } | |
156 | if ( myESewn ) { | |
157 | RgNLineVCompound = aHLRToShape.RgNLineVCompound(); | |
158 | DrawCurves( RgNLineVCompound, mySetOfCurves ); | |
159 | } | |
160 | if ( myEOutline ) { | |
161 | OutLineVCompound = aHLRToShape.OutLineVCompound(); | |
162 | DrawCurves( OutLineVCompound, mySetOfCurves ); | |
163 | } | |
164 | if ( myEIsoline ) { | |
165 | IsoLineVCompound = aHLRToShape.IsoLineVCompound(); | |
166 | DrawCurves( IsoLineVCompound, mySetOfCurves ); | |
167 | } | |
168 | ||
169 | if ( myIsHiddenLine ) { | |
170 | if ( myESharp ) { | |
171 | HCompound = aHLRToShape.HCompound(); | |
172 | DrawCurves( HCompound, myHSetOfCurves ); | |
173 | } | |
174 | if ( myESmooth ) { | |
175 | Rg1LineHCompound = aHLRToShape.Rg1LineHCompound(); | |
176 | DrawCurves( Rg1LineHCompound, myHSetOfCurves ); | |
177 | } | |
178 | if ( myESewn ) { | |
179 | RgNLineHCompound = aHLRToShape.RgNLineHCompound(); | |
180 | DrawCurves( RgNLineHCompound, myHSetOfCurves ); | |
181 | } | |
182 | if ( myEOutline ) { | |
183 | OutLineHCompound = aHLRToShape.OutLineHCompound(); | |
184 | DrawCurves( OutLineHCompound, myHSetOfCurves ); | |
185 | } | |
186 | if ( myEIsoline ) { | |
187 | IsoLineHCompound = aHLRToShape.IsoLineHCompound(); | |
188 | DrawCurves( IsoLineHCompound, myHSetOfCurves ); | |
189 | } | |
190 | } //end if is HiddenLine | |
191 | ||
192 | } // end if is PolyAlgo | |
193 | ||
194 | } | |
195 | ||
196 | inline HLRAlgo_Projector AIS2D_ProjShape::Projector() const { | |
197 | return myProjector; | |
198 | } | |
199 | ||
200 | void AIS2D_ProjShape::SetProjector(const HLRAlgo_Projector& aProjector) { | |
201 | ||
202 | myProjector = aProjector; | |
203 | myAlgo.Nullify(); | |
204 | myPolyAlgo.Nullify(); | |
205 | if ( Length() ) { | |
206 | RemovePrimitives(); | |
207 | ComputeShape(); | |
208 | } | |
209 | } | |
210 | ||
211 | void AIS2D_ProjShape::SetNbIsos( const Standard_Integer aNbIsos ) { | |
212 | ||
213 | myNbIsos = aNbIsos; | |
214 | myAlgo.Nullify(); | |
215 | if ( Length() ) { | |
216 | RemovePrimitives(); | |
217 | ComputeShape(); | |
218 | } | |
219 | } | |
220 | ||
221 | void AIS2D_ProjShape::SetPolyAlgo( const Standard_Boolean aIsPoly ) { | |
222 | ||
223 | myIsPolyAlgo = aIsPoly; | |
224 | if ( Length() ) { | |
225 | RemovePrimitives(); | |
226 | ComputeShape(); | |
227 | } | |
228 | } | |
229 | ||
230 | void AIS2D_ProjShape::SetHLMode( const Standard_Boolean aIsHLM ) { | |
231 | ||
232 | myIsHiddenLine = aIsHLM; | |
233 | if ( Length() ) { | |
234 | RemovePrimitives(); | |
235 | ComputeShape(); | |
236 | } | |
237 | } | |
238 | ||
239 | Standard_Boolean AIS2D_ProjShape::IsHLMode() const { | |
240 | return myIsHiddenLine; | |
241 | } | |
242 | ||
243 | Standard_Integer AIS2D_ProjShape::GetNbIsos() const { | |
244 | return myNbIsos; | |
245 | } | |
246 | ||
247 | Standard_Boolean AIS2D_ProjShape::GetIsPoly() const { | |
248 | return myIsPolyAlgo; | |
249 | } | |
250 | ||
251 | Handle(Graphic2d_Line) AIS2D_ProjShape::GetPrimitives() const { | |
252 | if ( myIsPolyAlgo ) | |
253 | return mySetOfSegments; | |
254 | else | |
255 | return mySetOfCurves; | |
256 | } | |
257 | ||
258 | Handle(Graphic2d_Line) AIS2D_ProjShape::GetHLPrimitives() const { | |
259 | if ( myIsPolyAlgo ) | |
260 | return myHSetOfSegments; | |
261 | else | |
262 | return myHSetOfCurves; | |
263 | } | |
264 | ||
265 | void AIS2D_ProjShape::CreateAlgo() { | |
266 | ||
267 | myAlgo = new HLRBRep_Algo(); | |
268 | TopTools_ListIteratorOfListOfShape anIterator( myListOfShape ); | |
269 | for ( ; anIterator.More(); anIterator.Next() ) | |
270 | myAlgo->Add( anIterator.Value(), myNbIsos ); | |
271 | myAlgo->Projector( myProjector ); | |
272 | myAlgo->Update(); | |
273 | myAlgo->Hide(); | |
274 | ||
275 | } | |
276 | ||
277 | void AIS2D_ProjShape::CreatePolyAlgo() { | |
278 | ||
279 | myPolyAlgo = new HLRBRep_PolyAlgo(); | |
280 | TopTools_ListIteratorOfListOfShape anIterator(myListOfShape); | |
281 | for ( ; anIterator.More(); anIterator.Next() ) | |
282 | myPolyAlgo->Load( anIterator.Value() ); | |
283 | myPolyAlgo->Projector( myProjector ); | |
284 | myPolyAlgo->Update(); | |
285 | } | |
286 | ||
287 | void AIS2D_ProjShape::DrawSegments( const TopoDS_Shape& aShape, | |
288 | Handle(Graphic2d_SetOfSegments)& aSofS ) { | |
289 | ||
290 | if ( aShape.IsNull() ) return; | |
291 | ||
292 | TopExp_Explorer theExp( aShape, TopAbs_EDGE ); | |
293 | while ( theExp.More() ) { | |
294 | const TopoDS_Edge& CurrentEdge = TopoDS::Edge( theExp.Current() ); | |
295 | const TopoDS_Vertex& FirstVertex = TopExp::FirstVertex(CurrentEdge); | |
296 | const TopoDS_Vertex& LastVertex = TopExp::LastVertex(CurrentEdge); | |
297 | gp_Pnt FirstPoint = BRep_Tool::Pnt(FirstVertex); | |
298 | gp_Pnt LastPoint = BRep_Tool::Pnt(LastVertex); | |
299 | aSofS->Add( FirstPoint.X(), FirstPoint.Y(), LastPoint.X(), LastPoint.Y() ); | |
300 | theExp.Next(); | |
301 | } | |
302 | } | |
303 | ||
304 | void AIS2D_ProjShape::DrawCurves( const TopoDS_Shape& aShape, | |
305 | Handle(GGraphic2d_SetOfCurves)& aSofC) { | |
306 | ||
307 | if ( aShape.IsNull() ) return; | |
308 | ||
309 | TopExp_Explorer theExp( aShape, TopAbs_EDGE ); | |
310 | Handle(Geom2d_Curve) aCurve; | |
311 | Handle(Geom_Surface) aSurface; | |
312 | TopLoc_Location theLoc; | |
313 | Standard_Real f, l; | |
314 | while ( theExp.More() ) { | |
315 | ||
316 | const TopoDS_Edge& CurrentEdge = TopoDS::Edge( theExp.Current() ); | |
7fd59977 | 317 | BRep_Tool::CurveOnSurface( CurrentEdge, aCurve, aSurface, theLoc, f, l ); |
91a16bc7 K |
318 | Standard_ASSERT (theLoc.IsIdentity(), "Unexpected edge with non-identity location", continue); |
319 | Standard_ASSERT (! aCurve.IsNull(), "Null PCurve", continue); | |
7fd59977 | 320 | Handle(Geom2d_TrimmedCurve) theCurve = new Geom2d_TrimmedCurve(aCurve,f,l); |
91a16bc7 | 321 | aSofC->Add(theCurve); |
7fd59977 | 322 | theExp.Next(); |
7fd59977 | 323 | } |
324 | } | |
325 | ||
326 | void AIS2D_ProjShape::ShowEdges( const Standard_Boolean aSharp, | |
327 | const Standard_Boolean aSmooth, | |
328 | const Standard_Boolean aSewn, | |
329 | const Standard_Boolean anOutline, | |
330 | const Standard_Boolean anIsoline ) { | |
331 | myESharp = aSharp; | |
332 | myESmooth = aSmooth; | |
333 | myESewn = aSewn; | |
334 | myEOutline = anOutline; | |
335 | myEIsoline = anIsoline; | |
336 | ||
337 | if ( Length() ) { | |
338 | RemovePrimitives(); | |
339 | ComputeShape(); | |
340 | } | |
341 | } |