7fd59977 |
1 | #include "stdafx.h" |
2 | |
3 | #include "Sample2D_Face.h" |
4 | |
5c1f974e |
5 | IMPLEMENT_STANDARD_RTTIEXT(Sample2D_Face,AIS_InteractiveObject) |
7fd59977 |
6 | |
5c1f974e |
7 | Sample2D_Face::Sample2D_Face (const TopoDS_Shape& theFace) |
8 | :AIS_InteractiveObject() |
7fd59977 |
9 | { |
5c1f974e |
10 | myshape = theFace; |
11 | myFORWARDColor = Quantity_NOC_BLUE1; |
12 | myREVERSEDColor = Quantity_NOC_YELLOW; |
13 | myINTERNALColor = Quantity_NOC_RED1; |
14 | myEXTERNALColor = Quantity_NOC_MAGENTA1; |
15 | myWidthIndex = 1; |
16 | myTypeIndex = 1; |
17 | |
18 | myForwardNum=0; |
19 | myReversedNum=0; |
20 | myInternalNum=0; |
21 | myExternalNum=0; |
22 | |
23 | SetAutoHilight(Standard_False); |
24 | |
25 | FillData(Standard_True); |
7fd59977 |
26 | } |
27 | |
5c1f974e |
28 | void Sample2D_Face::DrawMarker(const Handle(Geom2d_TrimmedCurve)& theCurve, const Handle(Prs3d_Presentation)& thePresentation) |
7fd59977 |
29 | { |
5c1f974e |
30 | Standard_Real aCenterParam = (theCurve->FirstParameter()+theCurve->LastParameter())/2; |
31 | gp_Pnt2d p; |
32 | gp_Vec2d v; |
33 | theCurve->D1(aCenterParam,p,v); |
34 | if (v.Magnitude() > gp::Resolution()) |
35 | { |
36 | gp_Vec aDir(v.X(),v.Y(),0.); |
37 | gp_Pnt aPoint(p.X(),p.Y(),0.); |
38 | aDir.Normalize(); |
39 | aDir.Reverse(); |
40 | gp_Dir aZ(0,0,1); |
41 | gp_Pnt aLeft(aPoint.Translated(aDir.Rotated(gp_Ax1(aPoint,aZ), M_PI/6)*5)) ; |
42 | gp_Pnt aRight(aPoint.Translated(aDir.Rotated(gp_Ax1(aPoint,aZ), M_PI*11/6)*5)); |
43 | |
44 | Handle(Graphic3d_ArrayOfPolylines) anArrow = new Graphic3d_ArrayOfPolylines(3); |
45 | anArrow->AddVertex(aLeft); |
46 | anArrow->AddVertex(aPoint); |
47 | anArrow->AddVertex(aRight); |
48 | |
d6c48921 |
49 | thePresentation->CurrentGroup()->AddPrimitiveArray(anArrow); |
5c1f974e |
50 | } |
51 | } |
7fd59977 |
52 | |
5c1f974e |
53 | void Sample2D_Face::FillData(Standard_Boolean isSizesRecompute) |
54 | { |
55 | if(myshape.IsNull() || myshape.ShapeType()!=TopAbs_FACE) return; |
56 | |
57 | Standard_Real f,l; |
58 | TopExp_Explorer ex; |
59 | TopoDS_Face aFace = TopoDS::Face(myshape); |
60 | |
61 | //count number of verteces and bounds in primitive arrays |
62 | if(isSizesRecompute) |
63 | { |
64 | mySeq_FORWARD.Clear(); |
65 | mySeq_REVERSED.Clear(); |
66 | mySeq_INTERNAL.Clear(); |
67 | mySeq_EXTERNAL.Clear(); |
68 | |
69 | myshape.Orientation(TopAbs_FORWARD); |
70 | ex.Init(myshape,TopAbs_EDGE); |
71 | while (ex.More()) |
72 | { |
73 | BRepAdaptor_Curve2d aCurveOnEdge(TopoDS::Edge(ex.Current()),aFace); |
74 | GCPnts_QuasiUniformDeflection anEdgeDistrib(aCurveOnEdge,1.e-2); |
75 | if(anEdgeDistrib.IsDone()) |
76 | switch (ex.Current().Orientation()) |
77 | { |
78 | case TopAbs_FORWARD: { |
79 | myForwardNum+=anEdgeDistrib.NbPoints(); |
80 | myForwardBounds++; |
81 | break; |
82 | } |
83 | case TopAbs_REVERSED: { |
84 | myReversedNum+=anEdgeDistrib.NbPoints(); |
85 | myReversedBounds++; |
86 | break; |
87 | } |
88 | case TopAbs_INTERNAL: { |
89 | myInternalNum+=anEdgeDistrib.NbPoints(); |
90 | myInternalBounds++; |
91 | break; |
92 | } |
93 | case TopAbs_EXTERNAL: { |
94 | myExternalNum+=anEdgeDistrib.NbPoints(); |
95 | myExternalBounds++; |
96 | break; |
97 | } |
98 | default : break; |
99 | }//end switch |
100 | ex.Next(); |
101 | } |
102 | } |
103 | |
104 | myForwardArray = new Graphic3d_ArrayOfPolylines(myForwardNum,myForwardBounds); |
105 | myReversedArray = new Graphic3d_ArrayOfPolylines(myReversedNum, myReversedBounds); |
106 | myInternalArray = new Graphic3d_ArrayOfPolylines(myInternalNum, myInternalBounds); |
107 | myExternalArray = new Graphic3d_ArrayOfPolylines(myExternalNum, myExternalBounds); |
108 | |
109 | //fill primitive arrays |
110 | ex.Init(myshape,TopAbs_EDGE); |
111 | while (ex.More()) { |
112 | const Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface |
113 | (TopoDS::Edge(ex.Current()),aFace,f,l); |
114 | |
115 | Handle(Geom2d_TrimmedCurve) aTrimmedCurve = new Geom2d_TrimmedCurve(aCurve,f,l); |
116 | TopoDS_Edge CurrentEdge= TopoDS::Edge(ex.Current()); |
117 | if(!aTrimmedCurve.IsNull()) |
118 | { |
119 | Handle(Geom_Curve) aCurve3d = GeomLib::To3d(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,0,1)),aTrimmedCurve); |
120 | BRepAdaptor_Curve2d aCurveOnEdge(CurrentEdge,aFace); |
121 | GCPnts_QuasiUniformDeflection anEdgeDistrib(aCurveOnEdge,1.e-2); |
122 | if(anEdgeDistrib.IsDone()) |
123 | { |
124 | switch (ex.Current().Orientation()) |
125 | { |
126 | case TopAbs_FORWARD: { |
127 | myForwardArray->AddBound(anEdgeDistrib.NbPoints()); |
128 | for(Standard_Integer i=1;i<=anEdgeDistrib.NbPoints();++i) |
129 | { |
130 | myForwardArray->AddVertex(anEdgeDistrib.Value(i)); |
131 | } |
132 | if(isSizesRecompute) |
133 | mySeq_FORWARD.Append(aCurve3d); |
134 | break; |
135 | } |
136 | case TopAbs_REVERSED: { |
137 | myReversedArray->AddBound(anEdgeDistrib.NbPoints()); |
138 | for(Standard_Integer i=1;i<=anEdgeDistrib.NbPoints();++i) |
139 | { |
140 | myReversedArray->AddVertex(anEdgeDistrib.Value(i)); |
141 | } |
142 | if(isSizesRecompute) |
143 | mySeq_REVERSED.Append(aCurve3d); |
144 | break; |
145 | } |
146 | case TopAbs_INTERNAL: { |
147 | myInternalArray->AddBound(anEdgeDistrib.NbPoints()); |
148 | for(Standard_Integer i=1;i<=anEdgeDistrib.NbPoints();++i) |
149 | { |
150 | myInternalArray->AddVertex(anEdgeDistrib.Value(i)); |
151 | } |
152 | if(isSizesRecompute) |
153 | mySeq_INTERNAL.Append(aCurve3d); |
154 | break; |
155 | } |
156 | case TopAbs_EXTERNAL: { |
157 | myExternalArray->AddBound(anEdgeDistrib.NbPoints()); |
158 | for(Standard_Integer i=1;i<=anEdgeDistrib.NbPoints();++i) |
159 | { |
160 | myExternalArray->AddVertex(anEdgeDistrib.Value(i)); |
161 | } |
162 | if(isSizesRecompute) |
163 | mySeq_EXTERNAL.Append(aCurve3d); |
164 | break; |
165 | } |
166 | default : break; |
167 | }//end switch |
168 | } |
169 | }//end else |
170 | ex.Next(); |
171 | } |
172 | } |
7fd59977 |
173 | |
decbff0d |
174 | void Sample2D_Face::Compute (const Handle(PrsMgr_PresentationManager)& /*thePresentationManager*/, |
5c1f974e |
175 | const Handle(Prs3d_Presentation)& thePresentation, |
5c573e69 |
176 | const Standard_Integer /*theMode*/) |
5c1f974e |
177 | { |
178 | thePresentation->Clear(); |
179 | myDrawer->SetWireDraw(1); |
180 | |
181 | if(myshape.IsNull() || myshape.ShapeType()!=TopAbs_FACE) return; |
182 | |
183 | Handle(Graphic3d_AspectLine3d) aLineAspect_FORWARD = |
184 | new Graphic3d_AspectLine3d(myFORWARDColor, Aspect_TOL_SOLID,1); |
185 | Handle(Graphic3d_AspectLine3d) aLineAspect_REVERSED = |
186 | new Graphic3d_AspectLine3d(myREVERSEDColor, Aspect_TOL_SOLID,1); |
187 | Handle(Graphic3d_AspectLine3d) aLineAspect_INTERNAL = |
188 | new Graphic3d_AspectLine3d(myINTERNALColor, Aspect_TOL_SOLID,1); |
189 | Handle(Graphic3d_AspectLine3d) aLineAspect_EXTERNAL = |
190 | new Graphic3d_AspectLine3d(myEXTERNALColor, Aspect_TOL_SOLID,1); |
191 | |
192 | Standard_Real f,l; |
193 | TopoDS_Face aFace = TopoDS::Face(myshape); |
194 | //estimating number of verteces in primitive arrays |
195 | TopExp_Explorer ex(myshape,TopAbs_EDGE); |
196 | ex.Init(myshape,TopAbs_EDGE); |
197 | while (ex.More()) |
198 | { |
199 | const Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface |
200 | (TopoDS::Edge(ex.Current()),aFace,f,l); |
201 | |
202 | Handle(Geom2d_TrimmedCurve) aTrimmedCurve = new Geom2d_TrimmedCurve(aCurve,f,l); |
203 | TopoDS_Edge aCurrentEdge= TopoDS::Edge(ex.Current()); |
204 | //make a 3D curve from 2D trimmed curve to display it |
205 | Handle(Geom_Curve) aCurve3d = GeomLib::To3d(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,0,1)),aTrimmedCurve); |
206 | //make distribution of points |
207 | BRepAdaptor_Curve2d aCurveOnEdge(aCurrentEdge,aFace); |
208 | GCPnts_QuasiUniformDeflection anEdgeDistrib(aCurveOnEdge,1.e-2); |
209 | if(anEdgeDistrib.IsDone()) |
210 | { |
211 | switch (ex.Current().Orientation()) |
212 | { |
213 | case TopAbs_FORWARD: { |
214 | |
d6c48921 |
215 | thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_FORWARD); |
5c1f974e |
216 | DrawMarker(aTrimmedCurve, thePresentation); |
217 | break; |
218 | } |
219 | case TopAbs_REVERSED: { |
220 | |
d6c48921 |
221 | thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_REVERSED); |
5c1f974e |
222 | DrawMarker(aTrimmedCurve, thePresentation); |
223 | break; |
224 | } |
225 | case TopAbs_INTERNAL: { |
226 | |
d6c48921 |
227 | thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_INTERNAL); |
5c1f974e |
228 | DrawMarker(aTrimmedCurve, thePresentation); |
229 | |
230 | mySeq_INTERNAL.Append(aCurve3d); |
231 | break; |
232 | } |
233 | case TopAbs_EXTERNAL: { |
234 | |
d6c48921 |
235 | thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_EXTERNAL); |
5c1f974e |
236 | DrawMarker(aTrimmedCurve, thePresentation); |
237 | break; |
238 | } |
239 | default : break; |
240 | }//end switch |
241 | } |
242 | ex.Next(); |
243 | } |
244 | //add all primitives to the presentation |
d6c48921 |
245 | thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_FORWARD); |
246 | thePresentation->CurrentGroup()->AddPrimitiveArray(myForwardArray); |
7fd59977 |
247 | |
d6c48921 |
248 | thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_REVERSED); |
249 | thePresentation->CurrentGroup()->AddPrimitiveArray(myReversedArray); |
7fd59977 |
250 | |
d6c48921 |
251 | thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_INTERNAL); |
252 | thePresentation->CurrentGroup()->AddPrimitiveArray(myInternalArray); |
7fd59977 |
253 | |
d6c48921 |
254 | thePresentation->CurrentGroup()->SetPrimitivesAspect(aLineAspect_EXTERNAL); |
255 | thePresentation->CurrentGroup()->AddPrimitiveArray(myExternalArray); |
5c1f974e |
256 | } |
7fd59977 |
257 | |
5c1f974e |
258 | //Method for advanced customizable selection of picked object |
259 | void Sample2D_Face::HilightSelected |
decbff0d |
260 | ( const Handle(PrsMgr_PresentationManager)& thePM, |
5c1f974e |
261 | const SelectMgr_SequenceOfOwner& theOwners) |
262 | { |
263 | Handle( Prs3d_Presentation ) aSelectionPrs; |
7fd59977 |
264 | |
5c1f974e |
265 | aSelectionPrs = GetSelectPresentation( thePM ); |
7fd59977 |
266 | |
5c1f974e |
267 | Handle(Graphic3d_AspectLine3d) aLineAspect = |
268 | new Graphic3d_AspectLine3d(Quantity_NOC_ANTIQUEWHITE, Aspect_TOL_SOLID,2); |
269 | if( HasPresentation() ) |
778cd667 |
270 | aSelectionPrs->SetTransformPersistence (Presentation()->TransformPersistence()); |
7fd59977 |
271 | |
5c1f974e |
272 | Standard_Integer aLength = theOwners.Length(); |
273 | Handle (SelectMgr_EntityOwner) anOwner; |
7fd59977 |
274 | |
5c1f974e |
275 | aSelectionPrs->Clear(); |
276 | FillData(); |
7fd59977 |
277 | |
d6c48921 |
278 | Handle (Graphic3d_Group) aSelectGroup = aSelectionPrs->NewGroup(); |
7fd59977 |
279 | |
5c1f974e |
280 | for(Standard_Integer i=1; i<=aLength; ++i) |
281 | { |
282 | anOwner = theOwners.Value(i); |
283 | //check priority of owner to add primitives in one of array |
284 | //containing primitives with certain type of orientation |
285 | switch(anOwner->Priority()) |
286 | { |
287 | case 7: |
288 | { |
289 | //add to objects with forward orientation |
290 | aSelectGroup->SetGroupPrimitivesAspect(aLineAspect); |
291 | aSelectGroup->AddPrimitiveArray(myForwardArray); |
292 | break; |
293 | } |
294 | case 6: |
295 | { |
296 | //add to objects with reversed orientation |
297 | aSelectGroup->SetGroupPrimitivesAspect(aLineAspect); |
298 | aSelectGroup->AddPrimitiveArray(myReversedArray); |
299 | break; |
300 | } |
301 | case 5: |
7fd59977 |
302 | { |
5c1f974e |
303 | //add to objects with internal orientation |
304 | aSelectGroup->SetGroupPrimitivesAspect(aLineAspect); |
305 | aSelectGroup->AddPrimitiveArray(myInternalArray); |
306 | break; |
307 | } |
308 | case 4: |
309 | { |
310 | //add to objects with external orientation |
311 | aSelectGroup->SetGroupPrimitivesAspect(aLineAspect); |
312 | aSelectGroup->AddPrimitiveArray(myExternalArray); |
313 | break; |
314 | } |
315 | } |
7fd59977 |
316 | |
5c1f974e |
317 | } |
318 | aSelectionPrs->Display(); |
7fd59977 |
319 | |
5c1f974e |
320 | } |
7fd59977 |
321 | |
5c1f974e |
322 | void Sample2D_Face::ClearSelected () |
323 | { |
324 | Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( NULL ); |
325 | if( !aSelectionPrs.IsNull() ) |
326 | aSelectionPrs->Clear(); |
327 | } |
7fd59977 |
328 | |
329 | |
7fd59977 |
330 | |
5c1f974e |
331 | //Method for advanced customizable highlighting of picked object |
decbff0d |
332 | void Sample2D_Face::HilightOwnerWithColor ( const Handle(PrsMgr_PresentationManager)& thePM, |
f838dac4 |
333 | const Handle(Prs3d_Drawer)& theStyle, |
5c1f974e |
334 | const Handle(SelectMgr_EntityOwner)& theOwner) |
335 | { |
336 | Handle( Prs3d_Presentation ) aHighlightPrs; |
337 | aHighlightPrs = GetHilightPresentation( thePM ); |
338 | if( HasPresentation() ) |
778cd667 |
339 | aHighlightPrs->SetTransformPersistence (Presentation()->TransformPersistence()); |
5c1f974e |
340 | if(theOwner.IsNull()) |
341 | return; |
342 | aHighlightPrs->Clear(); |
343 | FillData(); |
344 | |
345 | //Direct highlighting |
d6c48921 |
346 | Handle (Graphic3d_Group) aHilightGroup = aHighlightPrs->NewGroup(); |
5c1f974e |
347 | Handle(Graphic3d_AspectLine3d) aLineAspect = |
8e5fb5ea |
348 | new Graphic3d_AspectLine3d(theStyle->Color(), Aspect_TOL_SOLID,2); |
5c1f974e |
349 | switch(theOwner->Priority()) |
350 | { |
351 | case 7: |
352 | { |
353 | aHilightGroup->SetGroupPrimitivesAspect(aLineAspect); |
354 | aHilightGroup->AddPrimitiveArray(myForwardArray); |
355 | break; |
7fd59977 |
356 | } |
5c1f974e |
357 | case 6: |
358 | { |
359 | aHilightGroup->SetGroupPrimitivesAspect(aLineAspect); |
360 | aHilightGroup->AddPrimitiveArray(myReversedArray); |
361 | break; |
362 | } |
363 | case 5: |
364 | { |
365 | aHilightGroup->SetGroupPrimitivesAspect(aLineAspect); |
366 | aHilightGroup->AddPrimitiveArray(myInternalArray); |
367 | break; |
368 | } |
369 | case 4: |
370 | { |
371 | aHilightGroup->SetGroupPrimitivesAspect(aLineAspect); |
372 | aHilightGroup->AddPrimitiveArray(myExternalArray); |
373 | break; |
374 | } |
375 | } |
376 | if( thePM->IsImmediateModeOn() ) |
377 | thePM->AddToImmediateList( aHighlightPrs ); |
7fd59977 |
378 | |
7fd59977 |
379 | } |
380 | |
381 | |
382 | |
5c1f974e |
383 | //for auto select |
384 | void Sample2D_Face::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
5c573e69 |
385 | const Standard_Integer /*theMode*/) |
5c1f974e |
386 | { |
387 | if(myshape.IsNull()) |
388 | return; |
389 | |
390 | if(mySeq_FORWARD.Length()==0 && |
391 | mySeq_REVERSED.Length()==0 && |
392 | mySeq_INTERNAL.Length()==0 && |
393 | mySeq_EXTERNAL.Length()==0) return; |
394 | |
395 | //create entity owner for every part of the face |
396 | //set different priorities for primitives of different orientation |
397 | Handle(SelectMgr_EntityOwner) anOwner_Forward = new SelectMgr_EntityOwner(this,7); |
398 | Handle(SelectMgr_EntityOwner) anOwner_Reversed = new SelectMgr_EntityOwner(this,6); |
399 | Handle(SelectMgr_EntityOwner) anOwner_Internal = new SelectMgr_EntityOwner(this,5); |
400 | Handle(SelectMgr_EntityOwner) anOwner_External = new SelectMgr_EntityOwner(this,4); |
401 | |
402 | //create a sensitive for every part |
403 | Handle(Select3D_SensitiveGroup) aForwardGroup = new Select3D_SensitiveGroup(anOwner_Forward); |
404 | Handle(Select3D_SensitiveGroup) aReversedGroup = new Select3D_SensitiveGroup(anOwner_Reversed); |
405 | Handle(Select3D_SensitiveGroup) aInternalGroup = new Select3D_SensitiveGroup(anOwner_Internal); |
406 | Handle(Select3D_SensitiveGroup) aExternalGroup = new Select3D_SensitiveGroup(anOwner_External); |
407 | |
408 | Standard_Integer aLength = mySeq_FORWARD.Length(); |
409 | for(Standard_Integer i=1;i<=aLength;++i) |
410 | { |
411 | Handle(Select3D_SensitiveCurve) aSensitveCurve = new Select3D_SensitiveCurve(anOwner_Forward,mySeq_FORWARD(i)); |
412 | aForwardGroup->Add(aSensitveCurve); |
413 | } |
414 | theSelection->Add(aForwardGroup); |
415 | |
416 | aLength = mySeq_REVERSED.Length(); |
417 | for(Standard_Integer i=1;i<=aLength;++i) |
418 | { |
419 | Handle(Select3D_SensitiveCurve) aSensitveCurve = new Select3D_SensitiveCurve(anOwner_Reversed,mySeq_REVERSED(i)); |
420 | aReversedGroup->Add(aSensitveCurve); |
421 | } |
422 | theSelection->Add(aReversedGroup); |
423 | |
424 | aLength = mySeq_INTERNAL.Length(); |
425 | for(Standard_Integer i=1;i<=aLength;++i) |
426 | { |
427 | Handle(Select3D_SensitiveCurve) aSensitveCurve = new Select3D_SensitiveCurve(anOwner_Internal,mySeq_INTERNAL(i)); |
428 | aInternalGroup->Add(aSensitveCurve); |
429 | } |
430 | theSelection->Add(aInternalGroup); |
431 | |
432 | aLength = mySeq_EXTERNAL.Length(); |
433 | for(Standard_Integer i=1;i<=aLength;++i) |
434 | { |
435 | Handle(Select3D_SensitiveCurve) aSensitveCurve = new Select3D_SensitiveCurve(anOwner_External,mySeq_EXTERNAL(i)); |
436 | aExternalGroup->Add(aSensitveCurve); |
437 | } |
438 | theSelection->Add(aExternalGroup); |
439 | } |
7fd59977 |
440 | |