b311480e |
1 | // Created on: 1995-03-15 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
f751596e |
17 | #include <StdSelect_ViewerSelector3d.hxx> |
7fd59977 |
18 | #include <StdSelect.hxx> |
19 | #include <SelectBasics_SensitiveEntity.hxx> |
20 | #include <Graphic3d_AspectLine3d.hxx> |
21 | #include <gp_Pnt.hxx> |
22 | #include <gp_Lin.hxx> |
23 | #include <gp_Pnt2d.hxx> |
24 | #include <gp_Dir.hxx> |
25 | #include <gp_Ax3.hxx> |
26 | #include <gp_GTrsf.hxx> |
4269bd1b |
27 | #include <gp_Pln.hxx> |
7fd59977 |
28 | #include <Select3D_SensitiveEntity.hxx> |
b8ddfc2f |
29 | #include <Graphic3d_ArrayOfPolylines.hxx> |
f751596e |
30 | #include <Graphic3d_Group.hxx> |
51b10cd4 |
31 | #include <Graphic3d_SequenceOfHClipPlane.hxx> |
f751596e |
32 | #include <Graphic3d_Structure.hxx> |
4269bd1b |
33 | #include <SelectMgr_SelectableObject.hxx> |
7fd59977 |
34 | #include <TColgp_HArray1OfPnt.hxx> |
35 | #include <TColgp_Array1OfPnt.hxx> |
f751596e |
36 | #include <TColgp_Array1OfPnt2d.hxx> |
7fd59977 |
37 | #include <TColgp_HArray1OfPnt2d.hxx> |
38 | #include <Select3D_SensitiveCurve.hxx> |
39 | #include <Select3D_SensitiveSegment.hxx> |
40 | #include <Select3D_SensitiveFace.hxx> |
41 | #include <Select3D_SensitiveCircle.hxx> |
42 | #include <Select3D_SensitivePoint.hxx> |
43 | #include <Select3D_SensitiveTriangulation.hxx> |
44 | #include <Select3D_SensitiveTriangle.hxx> |
45 | #include <Select3D_SensitiveWire.hxx> |
7fd59977 |
46 | #include <Select3D_SensitiveBox.hxx> |
f751596e |
47 | #include <SelectMgr_Selection.hxx> |
48 | #include <SelectMgr_EntityOwner.hxx> |
7fd59977 |
49 | |
679ecdee |
50 | #include <Aspect_Grid.hxx> |
7fd59977 |
51 | #include <Aspect_TypeOfMarker.hxx> |
f751596e |
52 | #include <Aspect_Window.hxx> |
7fd59977 |
53 | #include <Graphic3d_AspectMarker3d.hxx> |
a577aaab |
54 | #include <Graphic3d_ArrayOfPoints.hxx> |
7fd59977 |
55 | #include <Poly_Connect.hxx> |
56 | #include <TColStd_HArray1OfInteger.hxx> |
57 | |
58 | #include <Poly_Array1OfTriangle.hxx> |
59 | #include <Poly_Triangulation.hxx> |
60 | #include <OSD_Environment.hxx> |
61 | #include <V3d.hxx> |
62 | #include <V3d_View.hxx> |
679ecdee |
63 | #include <V3d_Viewer.hxx> |
b8ddfc2f |
64 | #include <TColgp_SequenceOfPnt.hxx> |
65 | |
f751596e |
66 | #include <OSD_Timer.hxx> |
67 | |
f751596e |
68 | |
92efcf78 |
69 | IMPLEMENT_STANDARD_RTTIEXT(StdSelect_ViewerSelector3d,SelectMgr_ViewerSelector) |
70 | |
7fd59977 |
71 | static Standard_Integer StdSel_NumberOfFreeEdges (const Handle(Poly_Triangulation)& Trg) |
72 | { |
73 | Standard_Integer nFree = 0; |
74 | Poly_Connect pc(Trg); |
75 | Standard_Integer t[3]; |
76 | Standard_Integer i, j; |
77 | for (i = 1; i <= Trg->NbTriangles(); i++) |
78 | { |
79 | pc.Triangles (i, t[0], t[1], t[2]); |
80 | for (j = 0; j < 3; j++) |
81 | if (t[j] == 0) nFree++; |
82 | } |
83 | return nFree; |
84 | } |
85 | |
197ac94e |
86 | //======================================================================= |
87 | // Function : Constructor |
88 | // Purpose : |
89 | //======================================================================= |
f751596e |
90 | StdSelect_ViewerSelector3d::StdSelect_ViewerSelector3d() {} |
3c982548 |
91 | |
197ac94e |
92 | //======================================================================= |
3c982548 |
93 | // Function: SetPixelTolerance |
94 | // Purpose : |
197ac94e |
95 | //======================================================================= |
3bf9a45f |
96 | void StdSelect_ViewerSelector3d::SetPixelTolerance (const Standard_Integer theTolerance) |
3c982548 |
97 | { |
29a4908e |
98 | if (myTolerances.Tolerance() != theTolerance) |
3c982548 |
99 | { |
3bf9a45f |
100 | if (theTolerance < 0) |
28ee613b |
101 | myTolerances.ResetDefaults(); |
102 | else |
103 | myTolerances.SetCustomTolerance (theTolerance); |
197ac94e |
104 | myToUpdateTolerance = Standard_True; |
3c982548 |
105 | } |
7fd59977 |
106 | } |
107 | |
197ac94e |
108 | //======================================================================= |
109 | // Function: Pick |
7fd59977 |
110 | // Purpose : |
197ac94e |
111 | //======================================================================= |
112 | void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPix, |
113 | const Standard_Integer theYPix, |
114 | const Handle(V3d_View)& theView) |
7fd59977 |
115 | { |
1593b4ee |
116 | updateZLayers (theView); |
f751596e |
117 | if(myToUpdateTolerance) |
118 | { |
29a4908e |
119 | mySelectingVolumeMgr.SetPixelTolerance (myTolerances.Tolerance()); |
f751596e |
120 | myToUpdateTolerance = Standard_False; |
121 | } |
122 | |
123 | mySelectingVolumeMgr.SetCamera (theView->Camera()); |
124 | mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Point); |
125 | Standard_Integer aWidth = 0, aHeight = 0; |
126 | theView->Window()->Size (aWidth, aHeight); |
127 | mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight); |
128 | gp_Pnt2d aMousePos (static_cast<Standard_Real> (theXPix), |
129 | static_cast<Standard_Real> (theYPix)); |
130 | mySelectingVolumeMgr.BuildSelectingVolume (aMousePos); |
3202bf1e |
131 | mySelectingVolumeMgr.SetViewClipping (theView->ClipPlanes()); |
7fd59977 |
132 | |
f751596e |
133 | TraverseSensitives(); |
197ac94e |
134 | } |
7fd59977 |
135 | |
197ac94e |
136 | //======================================================================= |
137 | // Function: Pick |
7fd59977 |
138 | // Purpose : |
197ac94e |
139 | //======================================================================= |
140 | void StdSelect_ViewerSelector3d::Pick (const Standard_Integer theXPMin, |
141 | const Standard_Integer theYPMin, |
142 | const Standard_Integer theXPMax, |
143 | const Standard_Integer theYPMax, |
144 | const Handle(V3d_View)& theView) |
7fd59977 |
145 | { |
1593b4ee |
146 | updateZLayers (theView); |
f751596e |
147 | mySelectingVolumeMgr.SetCamera (theView->Camera()); |
148 | mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Box); |
149 | Standard_Integer aWidth = 0, aHeight = 0; |
150 | theView->Window()->Size (aWidth, aHeight); |
151 | mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight); |
152 | gp_Pnt2d aMinMousePos (static_cast<Standard_Real> (theXPMin), |
153 | static_cast<Standard_Real> (theYPMin)); |
154 | gp_Pnt2d aMaxMousePos (static_cast<Standard_Real> (theXPMax), |
155 | static_cast<Standard_Real> (theYPMax)); |
156 | mySelectingVolumeMgr.BuildSelectingVolume (aMinMousePos, |
157 | aMaxMousePos); |
158 | |
159 | TraverseSensitives(); |
7fd59977 |
160 | } |
161 | |
197ac94e |
162 | //======================================================================= |
7fd59977 |
163 | // Function: Pick |
164 | // Purpose : Selection using a polyline |
197ac94e |
165 | //======================================================================= |
166 | void StdSelect_ViewerSelector3d::Pick (const TColgp_Array1OfPnt2d& thePolyline, |
167 | const Handle(V3d_View)& theView) |
7fd59977 |
168 | { |
1593b4ee |
169 | updateZLayers (theView); |
f751596e |
170 | mySelectingVolumeMgr.SetCamera (theView->Camera()); |
171 | mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Polyline); |
172 | Standard_Integer aWidth = 0, aHeight = 0; |
173 | theView->Window()->Size (aWidth, aHeight); |
174 | mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight); |
175 | mySelectingVolumeMgr.BuildSelectingVolume (thePolyline); |
176 | |
177 | TraverseSensitives(); |
7fd59977 |
178 | } |
179 | |
197ac94e |
180 | //======================================================================= |
7fd59977 |
181 | // Function: DisplaySensitive. |
182 | // Purpose : Display active primitives. |
197ac94e |
183 | //======================================================================= |
184 | void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(V3d_View)& theView) |
7fd59977 |
185 | { |
099f3513 |
186 | SelectMgr_SelectableObjectSet::Iterator aSelectableIt (mySelectableObjects); |
197ac94e |
187 | |
099f3513 |
188 | for (; aSelectableIt.More(); aSelectableIt.Next()) |
197ac94e |
189 | { |
099f3513 |
190 | const Handle (SelectMgr_SelectableObject)& anObj = aSelectableIt.Value(); |
7fd59977 |
191 | |
c357e426 |
192 | Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->StructureManager()); |
7fd59977 |
193 | |
825aa485 |
194 | for (anObj->Init(); anObj->More(); anObj->Next()) |
7fd59977 |
195 | { |
825aa485 |
196 | if (anObj->CurrentSelection()->GetSelectionState() == SelectMgr_SOS_Activated) |
f751596e |
197 | { |
778cd667 |
198 | computeSensitivePrs (aStruct, anObj->CurrentSelection(), anObj->Transformation(), Handle(Graphic3d_TransformPers)()); |
f751596e |
199 | } |
7fd59977 |
200 | } |
825aa485 |
201 | |
202 | myStructs.Append (aStruct); |
7fd59977 |
203 | } |
7fd59977 |
204 | |
825aa485 |
205 | for (Standard_Integer aStructIdx = 1; aStructIdx <= myStructs.Length(); ++aStructIdx) |
206 | { |
207 | Handle(Graphic3d_Structure)& aStruct = myStructs.ChangeValue (aStructIdx); |
208 | aStruct->SetDisplayPriority (10); |
209 | aStruct->Display(); |
210 | } |
197ac94e |
211 | |
679ecdee |
212 | theView->Update(); |
7fd59977 |
213 | } |
214 | |
197ac94e |
215 | //======================================================================= |
7fd59977 |
216 | // Function: ClearSensitive |
217 | // Purpose : |
197ac94e |
218 | //======================================================================= |
219 | void StdSelect_ViewerSelector3d::ClearSensitive (const Handle(V3d_View)& theView) |
7fd59977 |
220 | { |
825aa485 |
221 | for (Standard_Integer aStructIdx = 1; aStructIdx <= myStructs.Length(); ++aStructIdx) |
197ac94e |
222 | { |
825aa485 |
223 | myStructs.Value (aStructIdx)->Remove(); |
197ac94e |
224 | } |
225 | |
825aa485 |
226 | myStructs.Clear(); |
7fd59977 |
227 | |
825aa485 |
228 | if (!theView.IsNull()) |
197ac94e |
229 | { |
825aa485 |
230 | theView->Update(); |
197ac94e |
231 | } |
7fd59977 |
232 | } |
233 | |
234 | //======================================================================= |
235 | //function : DisplaySenstive |
236 | //purpose : |
237 | //======================================================================= |
197ac94e |
238 | void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(SelectMgr_Selection)& theSel, |
f751596e |
239 | const gp_Trsf& theTrsf, |
197ac94e |
240 | const Handle(V3d_View)& theView, |
241 | const Standard_Boolean theToClearOthers) |
7fd59977 |
242 | { |
197ac94e |
243 | if (theToClearOthers) |
244 | { |
825aa485 |
245 | ClearSensitive (theView); |
197ac94e |
246 | } |
7fd59977 |
247 | |
c357e426 |
248 | Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->StructureManager()); |
7fd59977 |
249 | |
778cd667 |
250 | computeSensitivePrs (aStruct, theSel, theTrsf, Handle(Graphic3d_TransformPers)()); |
825aa485 |
251 | |
252 | myStructs.Append (aStruct); |
253 | myStructs.Last()->SetDisplayPriority (10); |
254 | myStructs.Last()->Display(); |
7fd59977 |
255 | |
679ecdee |
256 | theView->Update(); |
7fd59977 |
257 | } |
258 | |
259 | //======================================================================= |
1593b4ee |
260 | //function : computeSensitivePrs |
7fd59977 |
261 | //purpose : |
262 | //======================================================================= |
1593b4ee |
263 | void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Structure)& theStructure, |
825aa485 |
264 | const Handle(SelectMgr_Selection)& theSel, |
265 | const gp_Trsf& theLoc, |
778cd667 |
266 | const Handle(Graphic3d_TransformPers)& theTrsfPers) |
7fd59977 |
267 | { |
778cd667 |
268 | theStructure->SetTransformPersistence (theTrsfPers); |
825aa485 |
269 | |
270 | Handle(Graphic3d_Group) aSensGroup = theStructure->NewGroup(); |
271 | |
272 | Quantity_Color aColor (Quantity_NOC_INDIANRED3); |
273 | Handle(Graphic3d_AspectMarker3d) aMarkerAspect = |
274 | new Graphic3d_AspectMarker3d (Aspect_TOM_O_PLUS, aColor, 2.0); |
275 | |
276 | aSensGroup->SetPrimitivesAspect (aMarkerAspect); |
277 | aSensGroup->SetPrimitivesAspect ( |
278 | new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0)); |
279 | |
280 | Handle(Graphic3d_Group) anAreaGroup = theStructure->NewGroup(); |
281 | |
282 | anAreaGroup->SetPrimitivesAspect ( |
283 | new Graphic3d_AspectLine3d (Quantity_NOC_AQUAMARINE1, Aspect_TOL_DASH, 1.0)); |
284 | |
b8ddfc2f |
285 | TColgp_SequenceOfPnt aSeqLines, aSeqFree; |
286 | TColStd_SequenceOfInteger aSeqBnds; |
287 | |
197ac94e |
288 | for (theSel->Init(); theSel->More(); theSel->Next()) |
7fd59977 |
289 | { |
f751596e |
290 | Handle(Select3D_SensitiveEntity) Ent = |
291 | Handle(Select3D_SensitiveEntity)::DownCast(theSel->Sensitive()->BaseSensitive()); |
292 | const Standard_Boolean hasloc = theLoc.Form() != gp_Identity; |
7fd59977 |
293 | |
294 | //============== |
295 | // Box |
296 | //============= |
297 | |
298 | if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveBox)) |
299 | { |
300 | const Bnd_Box& B = Handle(Select3D_SensitiveBox)::DownCast (Ent)->Box(); |
301 | Standard_Real xmin, ymin, zmin, xmax, ymax, zmax; |
302 | B.Get (xmin, ymin, zmin, xmax, ymax, zmax); |
b8ddfc2f |
303 | Standard_Integer i; |
7fd59977 |
304 | gp_Pnt theboxpoint[8] = |
305 | { |
306 | gp_Pnt(xmin,ymin,zmin), |
307 | gp_Pnt(xmax,ymin,zmin), |
308 | gp_Pnt(xmax,ymax,zmin), |
309 | gp_Pnt(xmin,ymax,zmin), |
310 | gp_Pnt(xmin,ymin,zmax), |
311 | gp_Pnt(xmax,ymin,zmax), |
312 | gp_Pnt(xmax,ymax,zmax), |
313 | gp_Pnt(xmin,ymax,zmax) |
314 | }; |
315 | if(hasloc) |
316 | { |
b8ddfc2f |
317 | for (i = 0; i <= 7; i++) |
f751596e |
318 | theboxpoint[i].Transform (theLoc); |
7fd59977 |
319 | } |
7fd59977 |
320 | |
b8ddfc2f |
321 | aSeqBnds.Append(5); |
322 | for (i = 0; i < 4; i++) |
323 | aSeqLines.Append(theboxpoint[i]); |
324 | aSeqLines.Append(theboxpoint[0]); |
325 | |
326 | aSeqBnds.Append(5); |
327 | for (i = 4; i < 8; i++) |
328 | aSeqLines.Append(theboxpoint[i]); |
329 | aSeqLines.Append(theboxpoint[4]); |
7fd59977 |
330 | |
b8ddfc2f |
331 | for (i = 0; i < 4; i++) |
7fd59977 |
332 | { |
b8ddfc2f |
333 | aSeqBnds.Append(2); |
334 | aSeqLines.Append(theboxpoint[i]); |
335 | aSeqLines.Append(theboxpoint[i+4]); |
7fd59977 |
336 | } |
337 | } |
338 | //============== |
339 | // Face |
340 | //============= |
341 | else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveFace)) |
342 | { |
343 | Handle(Select3D_SensitiveFace) aFace = Handle(Select3D_SensitiveFace)::DownCast(Ent); |
344 | Handle(TColgp_HArray1OfPnt) TheHPts; |
f751596e |
345 | aFace->GetPoints(TheHPts); |
7fd59977 |
346 | const TColgp_Array1OfPnt& ThePts = TheHPts->Array1(); |
347 | |
b8ddfc2f |
348 | aSeqBnds.Append(ThePts.Length()); |
7fd59977 |
349 | for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++) |
350 | { |
351 | if (hasloc) |
f751596e |
352 | aSeqLines.Append(ThePts(I).Transformed (theLoc)); |
7fd59977 |
353 | else |
b8ddfc2f |
354 | aSeqLines.Append(ThePts(I)); |
7fd59977 |
355 | } |
7fd59977 |
356 | } |
357 | //============== |
358 | // Curve |
359 | //============= |
360 | else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCurve)) |
361 | { |
362 | Handle(Select3D_SensitiveCurve) aCurve = Handle(Select3D_SensitiveCurve)::DownCast(Ent); |
363 | Handle(TColgp_HArray1OfPnt) TheHPts; |
364 | aCurve->Points3D(TheHPts); |
365 | const TColgp_Array1OfPnt& ThePts = TheHPts->Array1(); |
366 | |
b8ddfc2f |
367 | aSeqBnds.Append(ThePts.Length()); |
7fd59977 |
368 | for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++) |
369 | { |
370 | if (hasloc) |
f751596e |
371 | aSeqLines.Append(ThePts(I).Transformed (theLoc)); |
7fd59977 |
372 | else |
b8ddfc2f |
373 | aSeqLines.Append(ThePts(I)); |
7fd59977 |
374 | } |
7fd59977 |
375 | } |
376 | //============== |
377 | // Wire |
378 | //============= |
379 | else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveWire)) |
380 | { |
b8ddfc2f |
381 | Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast(Ent); |
f751596e |
382 | const NCollection_Vector<Handle(Select3D_SensitiveEntity)>& anEntities = aWire->GetEdges(); |
7fd59977 |
383 | |
f751596e |
384 | for (int i = 0; i < anEntities.Length(); i++) |
7fd59977 |
385 | { |
a9dde4a3 |
386 | Handle(Select3D_SensitiveEntity) SubEnt = anEntities.Value(i); |
7fd59977 |
387 | |
388 | //Segment |
389 | if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveSegment)) |
390 | { |
7fd59977 |
391 | gp_Pnt P1 (Handle(Select3D_SensitiveSegment)::DownCast(SubEnt)->StartPoint().XYZ()); |
392 | gp_Pnt P2 (Handle(Select3D_SensitiveSegment)::DownCast(SubEnt)->EndPoint().XYZ()); |
393 | if (hasloc) |
394 | { |
f751596e |
395 | P1.Transform(theLoc); |
396 | P2.Transform(theLoc); |
7fd59977 |
397 | } |
b8ddfc2f |
398 | aSeqBnds.Append(2); |
399 | aSeqLines.Append(P1); |
400 | aSeqLines.Append(P2); |
7fd59977 |
401 | } |
402 | |
403 | //circle |
404 | if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCircle)) |
405 | { |
d7515f9a |
406 | Handle(Select3D_SensitiveCircle) aCircle = Handle(Select3D_SensitiveCircle)::DownCast(SubEnt); |
407 | Standard_Integer aFrom, aTo; |
408 | aCircle->ArrayBounds (aFrom, aTo); |
409 | aTo -= 2; |
410 | for (Standard_Integer aPntIter = aFrom; aPntIter <= aTo; aPntIter += 2) |
7fd59977 |
411 | { |
d7515f9a |
412 | gp_Pnt aPnts[3] = |
7fd59977 |
413 | { |
d7515f9a |
414 | gp_Pnt (aCircle->GetPoint3d (aPntIter + 0).XYZ()), |
415 | gp_Pnt (aCircle->GetPoint3d (aPntIter + 1).XYZ()), |
416 | gp_Pnt (aCircle->GetPoint3d (aPntIter + 2).XYZ()) |
7fd59977 |
417 | }; |
418 | |
419 | if (hasloc) |
420 | { |
f751596e |
421 | aPnts[0].Transform (theLoc); |
422 | aPnts[1].Transform (theLoc); |
423 | aPnts[2].Transform (theLoc); |
7fd59977 |
424 | } |
425 | |
d7515f9a |
426 | aSeqBnds.Append (4); |
427 | aSeqLines.Append (aPnts[0]); |
428 | aSeqLines.Append (aPnts[1]); |
429 | aSeqLines.Append (aPnts[2]); |
430 | aSeqLines.Append (aPnts[0]); |
7fd59977 |
431 | } |
432 | } |
433 | |
434 | //curve |
435 | if (SubEnt->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCurve)) |
436 | { |
437 | Handle(Select3D_SensitiveCurve) aCurve = Handle(Select3D_SensitiveCurve)::DownCast(SubEnt); |
438 | Handle(TColgp_HArray1OfPnt) TheHPts; |
439 | aCurve->Points3D (TheHPts); |
440 | const TColgp_Array1OfPnt& ThePts = TheHPts->Array1(); |
b8ddfc2f |
441 | |
442 | aSeqBnds.Append(ThePts.Length()); |
7fd59977 |
443 | for (Standard_Integer I = ThePts.Lower(); I <= ThePts.Upper(); I++) |
444 | { |
445 | if (hasloc) |
f751596e |
446 | aSeqLines.Append(ThePts(I).Transformed (theLoc)); |
7fd59977 |
447 | else |
b8ddfc2f |
448 | aSeqLines.Append(ThePts(I)); |
7fd59977 |
449 | } |
7fd59977 |
450 | } |
451 | } |
452 | } |
453 | //============== |
454 | // Segment |
455 | //============= |
456 | else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveSegment)) |
457 | { |
7fd59977 |
458 | gp_Pnt P1 (Handle(Select3D_SensitiveSegment)::DownCast(Ent)->StartPoint().XYZ()); |
459 | gp_Pnt P2 (Handle(Select3D_SensitiveSegment)::DownCast(Ent)->EndPoint().XYZ()); |
460 | if (hasloc) |
461 | { |
f751596e |
462 | P1.Transform (theLoc); |
463 | P2.Transform (theLoc); |
7fd59977 |
464 | } |
b8ddfc2f |
465 | aSeqBnds.Append(2); |
466 | aSeqLines.Append(P1); |
467 | aSeqLines.Append(P2); |
7fd59977 |
468 | } |
469 | //============== |
470 | // Circle |
471 | //============= |
472 | else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveCircle)) |
473 | { |
d7515f9a |
474 | Handle(Select3D_SensitiveCircle) aCircle = Handle(Select3D_SensitiveCircle)::DownCast(Ent); |
475 | Standard_Integer aFrom, aTo; |
476 | aCircle->ArrayBounds (aFrom, aTo); |
477 | aTo -= 2; |
478 | for (Standard_Integer aPntIter = aFrom; aPntIter <= aTo; aPntIter += 2) |
7fd59977 |
479 | { |
d7515f9a |
480 | gp_Pnt aPnts[3] = |
7fd59977 |
481 | { |
d7515f9a |
482 | gp_Pnt (aCircle->GetPoint3d (aPntIter + 0).XYZ()), |
483 | gp_Pnt (aCircle->GetPoint3d (aPntIter + 1).XYZ()), |
484 | gp_Pnt (aCircle->GetPoint3d (aPntIter + 2).XYZ()) |
7fd59977 |
485 | }; |
486 | |
487 | if (hasloc) |
488 | { |
f751596e |
489 | aPnts[0].Transform (theLoc); |
490 | aPnts[1].Transform (theLoc); |
491 | aPnts[2].Transform (theLoc); |
7fd59977 |
492 | } |
493 | |
d7515f9a |
494 | aSeqBnds.Append (4); |
495 | aSeqLines.Append (aPnts[0]); |
496 | aSeqLines.Append (aPnts[1]); |
497 | aSeqLines.Append (aPnts[2]); |
498 | aSeqLines.Append (aPnts[0]); |
7fd59977 |
499 | } |
500 | } |
501 | //============== |
502 | // Point |
503 | //============= |
504 | else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitivePoint)) |
505 | { |
506 | gp_Pnt P = hasloc ? |
507 | Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point() : |
f751596e |
508 | Handle(Select3D_SensitivePoint)::DownCast(Ent)->Point().Transformed (theLoc); |
a577aaab |
509 | Handle(Graphic3d_ArrayOfPoints) anArrayOfPoints = new Graphic3d_ArrayOfPoints (1); |
510 | anArrayOfPoints->AddVertex (P.X(), P.Y(), P.Z()); |
825aa485 |
511 | aSensGroup->AddPrimitiveArray (anArrayOfPoints); |
7fd59977 |
512 | } |
513 | //============================================================ |
514 | // Triangulation : On met un petit offset ves l'interieur... |
515 | //========================================================== |
516 | else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveTriangulation)) |
517 | { |
c5f3a425 |
518 | Handle(Poly_Triangulation) PT (Handle(Select3D_SensitiveTriangulation)::DownCast (Ent)->Triangulation()); |
7fd59977 |
519 | |
520 | const Poly_Array1OfTriangle& triangles = PT->Triangles(); |
521 | const TColgp_Array1OfPnt& Nodes = PT->Nodes(); |
7fd59977 |
522 | Standard_Integer n[3]; |
7fd59977 |
523 | |
524 | TopLoc_Location iloc, bidloc; |
c5f3a425 |
525 | if (Handle(Select3D_SensitiveTriangulation)::DownCast (Ent)->HasInitLocation()) |
526 | bidloc = Handle(Select3D_SensitiveTriangulation)::DownCast (Ent)->GetInitLocation(); |
7fd59977 |
527 | |
528 | if (bidloc.IsIdentity()) |
f751596e |
529 | iloc = theLoc; |
7fd59977 |
530 | else |
f751596e |
531 | iloc = theLoc * bidloc; |
7fd59977 |
532 | |
533 | Standard_Integer i; |
534 | for (i = 1; i <= PT->NbTriangles(); i++) |
535 | { |
536 | triangles (i).Get (n[0], n[1], n[2]); |
537 | gp_Pnt P1 (Nodes (n[0]).Transformed (iloc)); |
538 | gp_Pnt P2 (Nodes (n[1]).Transformed (iloc)); |
539 | gp_Pnt P3 (Nodes (n[2]).Transformed (iloc)); |
540 | gp_XYZ V1 (P1.XYZ()); |
541 | gp_XYZ V2 (P2.XYZ()); |
542 | gp_XYZ V3 (P3.XYZ()); |
543 | gp_XYZ CDG (P1.XYZ()); CDG += (P2.XYZ()); CDG += (P3.XYZ()); CDG /= 3.0; |
7fd59977 |
544 | V1 -= CDG; V2 -= CDG; V3 -= CDG; |
7fd59977 |
545 | V1 *= 0.9; V2 *= 0.9; V3 *= 0.9; |
546 | V1 += CDG; V2 += CDG; V3 += CDG; |
b8ddfc2f |
547 | |
548 | aSeqBnds.Append(4); |
549 | aSeqLines.Append(gp_Pnt(V1)); |
550 | aSeqLines.Append(gp_Pnt(V2)); |
551 | aSeqLines.Append(gp_Pnt(V3)); |
552 | aSeqLines.Append(gp_Pnt(V1)); |
7fd59977 |
553 | } |
554 | |
555 | // recherche des bords libres... |
556 | |
557 | Handle(TColStd_HArray1OfInteger) FreeEdges = new TColStd_HArray1OfInteger (1, 2 * StdSel_NumberOfFreeEdges (PT)); |
558 | TColStd_Array1OfInteger& FreeE = FreeEdges->ChangeArray1(); |
559 | Poly_Connect pc (PT); |
560 | Standard_Integer t[3]; |
561 | Standard_Integer j; |
562 | Standard_Integer fr (1); |
563 | for (i = 1; i <= PT->NbTriangles(); i++) |
564 | { |
565 | pc.Triangles (i, t[0], t[1], t[2]); |
566 | triangles (i).Get (n[0], n[1], n[2]); |
567 | for (j = 0; j < 3; j++) |
568 | { |
569 | Standard_Integer k = (j + 1) % 3; |
570 | if (t[j] == 0) |
571 | { |
572 | FreeE (fr) = n[j]; |
573 | FreeE (fr + 1)= n[k]; |
574 | fr += 2; |
575 | } |
576 | } |
577 | } |
7fd59977 |
578 | for (Standard_Integer ifri = 1; ifri <= FreeE.Length(); ifri += 2) |
579 | { |
b8ddfc2f |
580 | gp_Pnt pe1 (Nodes (FreeE (ifri)).Transformed (iloc)), pe2 (Nodes (FreeE (ifri + 1)).Transformed (iloc)); |
581 | aSeqFree.Append(pe1); |
582 | aSeqFree.Append(pe2); |
7fd59977 |
583 | } |
7fd59977 |
584 | } |
585 | else if (Ent->DynamicType()==STANDARD_TYPE(Select3D_SensitiveTriangle)) |
586 | { |
587 | Handle(Select3D_SensitiveTriangle) Str = Handle(Select3D_SensitiveTriangle)::DownCast(Ent); |
b8ddfc2f |
588 | gp_Pnt P1, P2, P3; |
7fd59977 |
589 | Str->Points3D (P1, P2, P3); |
b8ddfc2f |
590 | gp_Pnt CDG = Str->Center3D(); |
7fd59977 |
591 | |
592 | gp_XYZ V1 (P1.XYZ()); V1 -= (CDG.XYZ()); |
593 | gp_XYZ V2 (P2.XYZ()); V2 -= (CDG.XYZ()); |
594 | gp_XYZ V3 (P3.XYZ()); V3 -= (CDG.XYZ()); |
7fd59977 |
595 | V1 *= 0.9; V2 *= 0.9; V3 *= 0.9; |
596 | V1 += CDG.XYZ(); V2 += CDG.XYZ(); V3 += CDG.XYZ(); |
b8ddfc2f |
597 | |
598 | aSeqBnds.Append(4); |
599 | aSeqLines.Append(gp_Pnt(V1)); |
600 | aSeqLines.Append(gp_Pnt(V2)); |
601 | aSeqLines.Append(gp_Pnt(V3)); |
602 | aSeqLines.Append(gp_Pnt(V1)); |
7fd59977 |
603 | } |
604 | } |
b8ddfc2f |
605 | |
606 | Standard_Integer i; |
607 | |
608 | if (aSeqLines.Length()) |
609 | { |
610 | Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqLines.Length(),aSeqBnds.Length()); |
611 | for (i = 1; i <= aSeqLines.Length(); i++) |
612 | aPrims->AddVertex(aSeqLines(i)); |
613 | for (i = 1; i <= aSeqBnds.Length(); i++) |
614 | aPrims->AddBound(aSeqBnds(i)); |
825aa485 |
615 | anAreaGroup->AddPrimitiveArray(aPrims); |
b8ddfc2f |
616 | } |
617 | |
618 | if (aSeqFree.Length()) |
619 | { |
825aa485 |
620 | aSensGroup->SetPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_GREEN, Aspect_TOL_SOLID, 2.0)); |
b8ddfc2f |
621 | Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqFree.Length(),aSeqFree.Length()/2); |
622 | for (i = 1; i <= aSeqFree.Length(); i++) |
197ac94e |
623 | { |
b8ddfc2f |
624 | aPrims->AddBound(2); |
625 | aPrims->AddVertex(aSeqLines(i++)); |
626 | aPrims->AddVertex(aSeqLines(i)); |
197ac94e |
627 | } |
825aa485 |
628 | aSensGroup->AddPrimitiveArray(aPrims); |
629 | aSensGroup->SetPrimitivesAspect (new Graphic3d_AspectLine3d (Quantity_NOC_GRAY40, Aspect_TOL_SOLID, 2.0)); |
b8ddfc2f |
630 | } |
7fd59977 |
631 | } |
632 | |
4269bd1b |
633 | //======================================================================= |
634 | //function : HasDepthClipping |
635 | //purpose : |
636 | //======================================================================= |
637 | Standard_Boolean StdSelect_ViewerSelector3d::HasDepthClipping (const Handle(SelectMgr_EntityOwner)& theOwner) const |
638 | { |
639 | if (!theOwner->HasSelectable()) |
640 | { |
641 | return Standard_False; |
642 | } |
643 | |
644 | const Handle(SelectMgr_SelectableObject)& aSelectable = theOwner->Selectable(); |
3202bf1e |
645 | return !aSelectable->ClipPlanes().IsNull() |
646 | && !aSelectable->ClipPlanes()->IsEmpty(); |
4269bd1b |
647 | } |
1593b4ee |
648 | |
649 | //======================================================================= |
650 | // Function: updateZLayers |
651 | // Purpose : |
652 | //======================================================================= |
653 | void StdSelect_ViewerSelector3d::updateZLayers (const Handle(V3d_View)& theView) |
654 | { |
655 | myZLayerOrderMap.Clear(); |
656 | TColStd_SequenceOfInteger aZLayers; |
657 | theView->Viewer()->GetAllZLayers (aZLayers); |
658 | Standard_Integer aPos = 0; |
659 | Standard_Boolean isPrevDepthWrite = true; |
660 | for (TColStd_SequenceOfInteger::Iterator aLayerIter (aZLayers); aLayerIter.More(); aLayerIter.Next()) |
661 | { |
662 | Graphic3d_ZLayerSettings aSettings = theView->Viewer()->ZLayerSettings (aLayerIter.Value()); |
663 | if (aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthClear) |
664 | || isPrevDepthWrite != aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite)) |
665 | { |
666 | ++aPos; |
667 | } |
668 | isPrevDepthWrite = aSettings.IsSettingEnabled (Graphic3d_ZLayerDepthWrite); |
669 | myZLayerOrderMap.Bind (aLayerIter.Value(), aPos); |
670 | } |
671 | } |