b311480e |
1 | // Created on: 1997-01-29 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1997-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | #define UKI60826 //GG_161199 Use the requested selection color instead of default |
23 | |
24 | #define IMP280200 //GG Don't returns a NULL shape in SelectedShape() |
25 | // method when the current selected is a shape ! |
26 | |
27 | #define BUC60814 //GG_300101 Idem UKI60826 |
28 | |
29 | #define IMP150501 //GG_150501 CADPAK_V2 Add Drag() method |
30 | |
31 | #define IMP160701 //ZSV Add InitDetected(),MoreDetected(),NextDetected(), |
32 | // DetectedCurrentShape(),DetectedCurrentObject() |
33 | // methods |
34 | |
7fd59977 |
35 | #define OCC138 //VTN Avoding infinit loop in AddOrRemoveCurrentObject method. |
36 | |
37 | #define OCC9657 |
38 | |
39 | #include <AIS_InteractiveContext.jxx> |
40 | #include <SelectMgr_EntityOwner.hxx> |
41 | #include <AIS_Selection.hxx> |
42 | #include <AIS_StatusOfDetection.hxx> |
43 | #include <AIS_StatusOfPick.hxx> |
44 | |
45 | #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx> |
46 | #include <AIS_LocalContext.hxx> |
47 | #include <AIS_GlobalStatus.hxx> |
48 | #include <AIS_Shape.hxx> |
49 | |
50 | #include <V3d_Light.hxx> |
51 | #include <V3d_PositionalLight.hxx> |
52 | #include <V3d_SpotLight.hxx> |
53 | #include <V3d_DirectionalLight.hxx> |
54 | #include <V3d_AmbientLight.hxx> |
55 | |
56 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
57 | #include <SelectMgr_Selection.hxx> |
58 | #include <SelectBasics_SensitiveEntity.hxx> |
59 | |
60 | #ifdef IMP150501 |
61 | #include <Visual3d_TransientManager.hxx> |
62 | #include <Prs3d_Presentation.hxx> |
63 | #endif |
64 | |
65 | #ifdef OCC9657 |
66 | #include <AIS_MapOfInteractive.hxx> |
67 | #include <AIS_MapIteratorOfMapOfInteractive.hxx> |
68 | #endif |
69 | |
70 | //unused |
71 | /*#ifdef DEB |
72 | static void InfoOnLight(const Handle(V3d_View) aView) |
73 | { |
74 | Standard_Real V1=0.,V2=0.,V3=0.; |
75 | Standard_Integer IndexOfLit(0); |
76 | |
77 | static Standard_Boolean FirstTime (Standard_True); |
78 | if(FirstTime) |
79 | { |
80 | FirstTime = Standard_False; |
81 | for (aView->InitActiveLights();aView->MoreActiveLights();aView->NextActiveLights()){ |
82 | IndexOfLit++; |
83 | cout<<"lumiere no "<<IndexOfLit<<"\n************\n\t"; |
84 | Handle(V3d_Light) Li = aView->ActiveLight(); |
85 | Quantity_NameOfColor Col; |
86 | Li->Color(Col); |
87 | cout<<"Color :"<<Standard_Integer(Col)<<"\n\t"<<endl; |
88 | cout<<"type :"; |
89 | switch(Li->Type()){ |
90 | case V3d_AMBIENT: |
91 | { |
92 | cout<<" AMBIENT\n\t"; |
93 | //POP K4L |
94 | // Handle(V3d_AmbientLight)::DownCast(Li)->DisplayPosition(V1,V2,V3); |
95 | cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl; |
96 | break; |
97 | } |
98 | case V3d_DIRECTIONAL: |
99 | { |
100 | cout<<" DIRECTIONAL\n\t"; |
101 | Handle(V3d_DirectionalLight)::DownCast(Li)->DisplayPosition(V1,V2,V3); |
102 | cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl; |
103 | Handle(V3d_DirectionalLight)::DownCast(Li)->Direction(V1,V2,V3); |
104 | cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl; |
105 | |
106 | break; |
107 | } |
108 | case V3d_POSITIONAL: |
109 | { |
110 | cout<<" POSITIONAL\n\t"; |
111 | Handle(V3d_PositionalLight)::DownCast(Li)->Position(V1,V2,V3); |
112 | cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl; |
113 | Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3); |
114 | cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl; |
115 | break; |
116 | } |
117 | case V3d_SPOT: |
118 | { |
119 | cout<<" SPOT\n\t"; |
120 | cout<<" DIRECTIONAL\n\t"; |
121 | Handle(V3d_SpotLight)::DownCast(Li)->Position(V1,V2,V3); |
122 | cout<<"Position : X1 = "<<V1<<" X2 = "<<V2<<" X3 = "<<V3<<endl; |
123 | Handle(V3d_SpotLight)::DownCast(Li)->Direction(V1,V2,V3); |
124 | cout<<"Direction : V1 = "<<V1<<" V2 = "<<V2<<" V3 = "<<V3<<endl; |
125 | Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3); |
126 | cout<<"Target : x1 = "<<V1<<" x2 = "<<V2<<" x3 = "<<V3<<endl; |
127 | cout<<"\tAngle :"<<Handle(V3d_SpotLight)::DownCast(Li)->Angle()<<endl; |
128 | break; |
129 | } |
130 | } |
131 | } |
132 | } |
133 | } |
134 | #endif |
135 | */ |
136 | //======================================================================= |
137 | //function : MoveTo |
138 | //purpose : |
139 | //======================================================================= |
140 | |
141 | AIS_StatusOfDetection AIS_InteractiveContext::MoveTo(const Standard_Integer XPix, |
142 | const Standard_Integer YPix, |
143 | const Handle(V3d_View)& aView) |
144 | { |
eb4320f2 |
145 | if(HasOpenedContext()){ |
7fd59977 |
146 | myWasLastMain = Standard_True; |
147 | return myLocalContexts(myCurLocalIndex)->MoveTo(XPix,YPix,aView); |
148 | } |
149 | |
150 | #ifdef IMP160701 |
151 | //Nullify class members storing information about detected AIS objects. |
152 | myAISCurDetected = 0; |
153 | myAISDetectedSeq.Clear(); |
154 | #endif |
155 | |
156 | // OCC11904 - local variables made non-static - it looks and works better like this |
157 | Handle (PrsMgr_PresentationManager3d) pmgr ; |
158 | Handle (StdSelect_ViewerSelector3d) selector; |
159 | Standard_Boolean ismain = Standard_True,UpdVwr = Standard_False; |
160 | |
161 | // Preliminaires |
162 | if(aView->Viewer()== myMainVwr) { |
163 | pmgr = myMainPM; |
164 | selector=myMainSel; |
165 | myLastPicked = myLastinMain; |
166 | myWasLastMain = Standard_True; |
167 | } |
7fd59977 |
168 | else |
169 | return AIS_SOD_Error; |
170 | |
171 | AIS_StatusOfDetection TheStat(AIS_SOD_Nothing); |
172 | |
173 | |
174 | // allonzy |
175 | selector->Pick(XPix, YPix, aView); |
176 | |
177 | #ifdef IMP160701 |
178 | //filling of myAISDetectedSeq sequence storing information about detected AIS objects |
179 | // (the objects must be AIS_Shapes). |
180 | Handle(SelectMgr_EntityOwner) anEntityOwner; |
181 | const Standard_Integer NbDetected = selector->NbPicked(); |
182 | for(Standard_Integer i_detect = 1;i_detect<=NbDetected;i_detect++) |
183 | { |
184 | anEntityOwner = selector->Picked(i_detect); |
185 | if(!anEntityOwner.IsNull()) |
186 | if(myFilters->IsOk(anEntityOwner)) |
187 | { |
188 | Handle(AIS_InteractiveObject) anObj = |
189 | Handle(AIS_InteractiveObject)::DownCast(anEntityOwner->Selectable()); |
190 | if(!Handle(AIS_Shape)::DownCast(anObj).IsNull()) |
191 | myAISDetectedSeq.Append(anObj); |
192 | } |
193 | } |
194 | #endif |
195 | |
196 | selector->Init(); |
197 | if ( selector->More() ) |
198 | { |
eafb234b |
199 | if ( HasOpenedContext() ) |
200 | { |
7fd59977 |
201 | if ( !myFilters->IsOk( selector->OnePicked() ) ) |
eafb234b |
202 | return AIS_SOD_AllBad; |
7fd59977 |
203 | else |
204 | if ( !myLocalContexts( myCurLocalIndex )->Filter()->IsOk( selector->OnePicked() ) ) |
205 | return AIS_SOD_AllBad; |
eafb234b |
206 | } |
81bba717 |
207 | |
7fd59977 |
208 | // Does nothing if previously detected object is equal to the current one |
209 | if ( selector->OnePicked()->Selectable() == myLastPicked ) |
210 | return AIS_SOD_OnlyOneDetected; |
81bba717 |
211 | |
7fd59977 |
212 | // Previously detected object is unhilighted if it is not selected or hilighted |
213 | // with selection color if it is selected. Such highlighting with selection color |
214 | // is needed only if myToHilightSelected flag is true. In this case previously detected |
215 | // object has been already highlighted with myHilightColor during previous MoveTo() |
216 | // method call. As result it is necessary to rehighligt it with mySelectionColor. |
be6e564e |
217 | if (!myLastPicked.IsNull()) |
7fd59977 |
218 | { |
be6e564e |
219 | Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0; |
220 | if (myLastPicked->State() != 1) |
7fd59977 |
221 | { |
be6e564e |
222 | pmgr->Unhighlight (myLastPicked, aHiMod); |
7fd59977 |
223 | UpdVwr = Standard_True; |
224 | } |
be6e564e |
225 | else if (myToHilightSelected) |
7fd59977 |
226 | { |
be6e564e |
227 | pmgr->Color (myLastPicked, mySelectionColor, aHiMod); |
7fd59977 |
228 | UpdVwr = Standard_True; |
229 | } |
230 | } |
be6e564e |
231 | |
7fd59977 |
232 | // Initialize myLastPicked field with currently detected object |
be6e564e |
233 | myLastPicked = Handle(AIS_InteractiveObject)::DownCast (selector->OnePicked()->Selectable()); |
234 | |
7fd59977 |
235 | if ( ismain ) |
236 | myLastinMain = myLastPicked; |
be6e564e |
237 | |
7fd59977 |
238 | // Highlight detected object if it is not selected or myToHilightSelected flag is true |
be6e564e |
239 | if (!myLastPicked.IsNull() |
240 | && (myLastPicked->State()!= 1 || myToHilightSelected)) |
7fd59977 |
241 | { |
be6e564e |
242 | Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0; |
243 | pmgr->Color (myLastPicked, myHilightColor, aHiMod); |
7fd59977 |
244 | UpdVwr = Standard_True; |
245 | } |
be6e564e |
246 | |
247 | if (!myLastPicked.IsNull() |
248 | && myLastPicked->State() == 1) |
249 | { |
7fd59977 |
250 | TheStat = AIS_SOD_Selected; |
be6e564e |
251 | } |
7fd59977 |
252 | } |
253 | else |
254 | { |
be6e564e |
255 | // Previously detected object is unhilighted if it is not selected or hilighted |
256 | // with selection color if it is selected. |
7fd59977 |
257 | TheStat = AIS_SOD_Nothing; |
be6e564e |
258 | if (!myLastPicked.IsNull()) |
7fd59977 |
259 | { |
be6e564e |
260 | Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0; |
261 | if (myLastPicked->State() != 1) |
7fd59977 |
262 | { |
be6e564e |
263 | pmgr->Unhighlight (myLastPicked, aHiMod); |
7fd59977 |
264 | UpdVwr = Standard_True; |
265 | } |
be6e564e |
266 | else if (myToHilightSelected) |
7fd59977 |
267 | { |
be6e564e |
268 | pmgr->Color (myLastPicked, mySelectionColor, aHiMod); |
7fd59977 |
269 | UpdVwr = Standard_True; |
270 | } |
271 | } |
be6e564e |
272 | |
7fd59977 |
273 | if ( ismain ) |
274 | myLastinMain.Nullify(); |
7fd59977 |
275 | } |
276 | |
277 | if(UpdVwr) aView->Viewer()->Update(); |
278 | myLastPicked.Nullify(); |
279 | |
280 | mylastmoveview = aView; |
281 | return TheStat; |
282 | } |
283 | |
284 | //======================================================================= |
285 | //function : Select |
286 | //purpose : |
287 | //======================================================================= |
288 | |
289 | AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Integer XPMin, |
290 | const Standard_Integer YPMin, |
291 | const Standard_Integer XPMax, |
292 | const Standard_Integer YPMax, |
293 | const Handle(V3d_View)& aView, |
294 | const Standard_Boolean updateviewer) |
295 | { |
81bba717 |
296 | // all objects detected by the selector are taken, previous current objects are emptied, |
297 | // new objects are put... |
7fd59977 |
298 | |
299 | if(HasOpenedContext()) |
300 | return myLocalContexts(myCurLocalIndex)->Select(XPMin,YPMin,XPMax,YPMax,aView,updateviewer); |
301 | |
302 | ClearCurrents(Standard_False); |
303 | // OCC11904 - local variables made non-static - it looks and works better like this |
304 | Handle(StdSelect_ViewerSelector3d) selector; |
305 | |
306 | if(aView->Viewer()== myMainVwr) { |
307 | selector= myMainSel; |
308 | myWasLastMain = Standard_True;} |
eb4320f2 |
309 | |
7fd59977 |
310 | selector->Pick(XPMin,YPMin,XPMax,YPMax,aView); |
311 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
312 | |
313 | #ifdef OCC9657 |
314 | AIS_MapOfInteractive theSelectedObj; |
315 | for( selector->Init(); selector->More(); selector->Next() ) |
316 | { |
317 | Handle( AIS_InteractiveObject ) anObj = |
318 | Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() ); |
319 | if( !anObj.IsNull() ) |
320 | theSelectedObj.Add( anObj ); |
321 | } |
322 | AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj ); |
323 | for( ; anIt.More(); anIt.Next() ) |
324 | { |
325 | AIS_Selection::Select( anIt.Key() ); |
326 | anIt.Key()->State(1); |
327 | } |
328 | #else |
329 | for(selector->Init();selector->More();selector->Next()){ |
330 | const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable(); |
331 | if(!SO.IsNull()){ |
332 | #ifdef OCC138 |
333 | AIS_Selection::Select(SO); |
334 | (*((Handle(AIS_InteractiveObject)*)&SO))->State(1); |
335 | #else |
336 | (*((Handle(AIS_InteractiveObject)*)&SO))->State(1); |
337 | AIS_Selection::Select(SO); |
338 | #endif //OCC138 |
339 | } |
340 | } |
341 | |
342 | #endif //OCC9657 |
343 | HilightCurrents(updateviewer); |
344 | |
345 | Standard_Integer NS = NbCurrents(); |
346 | if(NS==0) return AIS_SOP_NothingSelected; |
347 | if(NS==1) return AIS_SOP_OneSelected; |
348 | return AIS_SOP_SeveralSelected; |
349 | |
350 | } |
351 | |
352 | //======================================================================= |
353 | //function : Select |
354 | //purpose : Selection by polyline |
355 | //======================================================================= |
356 | |
357 | AIS_StatusOfPick AIS_InteractiveContext::Select(const TColgp_Array1OfPnt2d& aPolyline, |
358 | const Handle(V3d_View)& aView, |
359 | const Standard_Boolean updateviewer) |
360 | { |
81bba717 |
361 | // all objects detected by the selector are taken, previous current objects are emptied, |
362 | // new objects are put... |
7fd59977 |
363 | |
364 | if(HasOpenedContext()) |
365 | return myLocalContexts(myCurLocalIndex)->Select(aPolyline,aView,updateviewer); |
366 | |
367 | ClearCurrents(Standard_False); |
368 | // OCC11904 - local variables made non-static - it looks and works better like this |
369 | Handle(StdSelect_ViewerSelector3d) selector; |
370 | |
371 | if(aView->Viewer()== myMainVwr) { |
372 | selector= myMainSel; |
373 | myWasLastMain = Standard_True;} |
eb4320f2 |
374 | |
7fd59977 |
375 | selector->Pick(aPolyline,aView); |
376 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
377 | |
378 | |
379 | #ifdef OCC9657 |
380 | AIS_MapOfInteractive theSelectedObj; |
381 | for( selector->Init(); selector->More(); selector->Next() ) |
382 | { |
383 | Handle( AIS_InteractiveObject ) anObj = |
384 | Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() ); |
385 | if( !anObj.IsNull() ) |
386 | theSelectedObj.Add( anObj ); |
387 | } |
388 | AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj ); |
389 | for( ; anIt.More(); anIt.Next() ) |
390 | { |
391 | AIS_Selection::Select( anIt.Key() ); |
392 | anIt.Key()->State(1); |
393 | } |
394 | #else |
395 | for(selector->Init();selector->More();selector->Next()){ |
396 | const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable(); |
397 | if(!SO.IsNull()){ |
398 | #ifdef OCC138 |
399 | AIS_Selection::Select(SO); |
400 | (*((Handle(AIS_InteractiveObject)*)&SO))->State(1); |
401 | #else |
402 | (*((Handle(AIS_InteractiveObject)*)&SO))->State(1); |
403 | AIS_Selection::Select(SO); |
404 | #endif //OCC138 |
405 | } |
406 | } |
407 | #endif //OCC9657 |
408 | HilightCurrents(updateviewer); |
409 | |
410 | Standard_Integer NS = NbCurrents(); |
411 | if(NS==0) return AIS_SOP_NothingSelected; |
412 | if(NS==1) return AIS_SOP_OneSelected; |
413 | return AIS_SOP_SeveralSelected; |
414 | |
415 | } |
416 | |
417 | //======================================================================= |
418 | //function : Select |
419 | //purpose : |
420 | //======================================================================= |
421 | |
422 | AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Boolean updateviewer) |
423 | { |
424 | if(HasOpenedContext()){ |
425 | if(myWasLastMain) |
426 | return myLocalContexts(myCurLocalIndex)->Select(updateviewer); |
427 | else |
81bba717 |
428 | // picking was done in the collector, special processing is required... |
7fd59977 |
429 | { |
430 | myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer); |
431 | return AIS_SOP_OneSelected; |
432 | } |
433 | } |
434 | // AIS_StatusOfPick PS(AIS_SOP_NothingSelected); |
435 | if(myWasLastMain && !myLastinMain.IsNull()){ |
436 | if(myLastinMain->State()!=1){ |
437 | SetCurrentObject(myLastinMain,Standard_False); |
438 | if(updateviewer) |
439 | UpdateCurrentViewer();} |
440 | } |
7fd59977 |
441 | else{ |
442 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
443 | Handle(AIS_Selection) S = AIS_Selection::CurrentSelection(); |
444 | Handle(Standard_Transient) Tr; |
445 | Handle(AIS_InteractiveObject) IO; |
446 | |
447 | for(S->Init();S->More();S->Next()){ |
448 | Tr = S->Value(); |
449 | IO = (*((Handle(AIS_InteractiveObject)*)&Tr)); |
450 | IO->State(0); |
451 | Unhilight(IO,Standard_False); |
452 | if(myObjects.IsBound(IO)){ // anti-plantage-rob |
453 | if(myObjects(IO)->IsSubIntensityOn()) |
454 | HilightWithColor(IO,mySubIntensity,Standard_False); |
455 | } |
456 | } |
457 | |
458 | AIS_Selection::Select(); |
459 | if(updateviewer){ |
460 | if(myWasLastMain) |
eb4320f2 |
461 | UpdateCurrentViewer(); |
7fd59977 |
462 | } |
463 | } |
464 | Standard_Integer NS = NbCurrents(); |
465 | if(NS==0) return AIS_SOP_NothingSelected; |
466 | if(NS==1) return AIS_SOP_OneSelected; |
467 | return AIS_SOP_SeveralSelected; |
468 | } |
469 | |
470 | //======================================================================= |
471 | //function : ShiftSelect |
472 | //purpose : |
473 | //======================================================================= |
474 | |
475 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer) |
476 | { |
477 | if(HasOpenedContext()){ |
478 | if(myWasLastMain) |
479 | return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer); |
480 | else{ |
481 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer); |
482 | Standard_Integer NS =NbSelected(); |
483 | if(NS==0) return AIS_SOP_NothingSelected; |
484 | if(NS==1) return AIS_SOP_OneSelected; |
485 | return AIS_SOP_SeveralSelected; |
486 | } |
487 | } |
488 | if(myWasLastMain && !myLastinMain.IsNull()) |
489 | AddOrRemoveCurrentObject(myLastinMain,updateviewer); |
eb4320f2 |
490 | |
7fd59977 |
491 | Standard_Integer NS = NbCurrents(); |
492 | if(NS==0) return AIS_SOP_NothingSelected; |
493 | if(NS==1) return AIS_SOP_OneSelected; |
494 | return AIS_SOP_SeveralSelected; |
495 | } |
496 | |
497 | |
498 | //======================================================================= |
499 | //function : ShiftSelect |
500 | //purpose : |
501 | //======================================================================= |
502 | |
503 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin, |
504 | const Standard_Integer YPMin, |
505 | const Standard_Integer XPMax, |
506 | const Standard_Integer YPMax, |
507 | const Handle(V3d_View)& aView, |
508 | const Standard_Boolean updateviewer) |
509 | { |
510 | |
511 | if(HasOpenedContext()) |
512 | return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,aView,updateviewer); |
513 | |
514 | UnhilightCurrents(Standard_False); |
515 | // OCC11904 - local variables made non-static - it looks and works better like this |
516 | Handle(StdSelect_ViewerSelector3d) selector; |
517 | |
518 | if(aView->Viewer()== myMainVwr) { |
519 | selector= myMainSel; |
520 | myWasLastMain = Standard_True;} |
7fd59977 |
521 | else |
522 | return AIS_SOP_NothingSelected; |
523 | |
524 | selector->Pick(XPMin,YPMin,XPMax,YPMax,aView); |
525 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
526 | for(selector->Init();selector->More();selector->Next()){ |
527 | const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable(); |
528 | if(!SO.IsNull()){ |
529 | AIS_SelectStatus SelStat = AIS_Selection::Select(SO); |
530 | Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0; |
531 | (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod); |
532 | } |
533 | } |
534 | |
535 | HilightCurrents(updateviewer); |
536 | |
537 | Standard_Integer NS =NbCurrents(); |
538 | if(NS==0) return AIS_SOP_NothingSelected; |
539 | if(NS==1) return AIS_SOP_OneSelected; |
540 | return AIS_SOP_SeveralSelected; |
541 | |
542 | } |
543 | |
544 | //======================================================================= |
545 | //function : ShiftSelect |
546 | //purpose : |
547 | //======================================================================= |
548 | |
549 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline, |
550 | const Handle(V3d_View)& aView, |
551 | const Standard_Boolean updateviewer ) |
552 | { |
553 | if( HasOpenedContext() ) |
554 | return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer ); |
555 | |
556 | UnhilightCurrents( Standard_False ); |
557 | // OCC11904 - local variables made non-static - it looks and works better like this |
558 | Handle(StdSelect_ViewerSelector3d) selector; |
559 | |
560 | if( aView->Viewer() == myMainVwr ) { |
561 | selector= myMainSel; |
562 | myWasLastMain = Standard_True; |
563 | } |
7fd59977 |
564 | else |
565 | return AIS_SOP_NothingSelected; |
566 | |
567 | selector->Pick( aPolyline, aView ); |
568 | |
569 | AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() ); |
570 | for( selector->Init(); selector->More(); selector->Next() ) { |
571 | const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable(); |
572 | if( !SO.IsNull() ) { |
573 | AIS_SelectStatus SelStat = AIS_Selection::Select( SO ); |
574 | Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0; |
575 | (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod ); |
576 | } |
577 | } |
578 | |
579 | HilightCurrents( updateviewer ); |
580 | Standard_Integer NS = NbCurrents(); |
581 | if( NS == 0 ) return AIS_SOP_NothingSelected; |
582 | if( NS == 1 ) return AIS_SOP_OneSelected; |
583 | return AIS_SOP_SeveralSelected; |
584 | } |
585 | |
586 | //======================================================================= |
587 | //function : SetCurrentObject |
588 | //purpose : |
589 | //======================================================================= |
590 | |
591 | void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj, |
592 | const Standard_Boolean updateviewer) |
593 | { |
81bba717 |
594 | // single case processing... |
7fd59977 |
595 | if(NbCurrents()==1 && anIObj->State()==1){ |
596 | Quantity_NameOfColor HiCol; |
597 | Standard_Boolean HasHiCol; |
598 | if(IsHilighted(anIObj,HasHiCol,HiCol)){ |
599 | if(HasHiCol && HiCol!= mySelectionColor) { |
600 | #ifdef UKI60826 |
601 | HilightWithColor(anIObj,mySelectionColor,updateviewer); |
602 | #else |
603 | Hilight(anIObj,updateviewer); |
604 | #endif |
605 | } |
606 | } |
607 | return; |
608 | } |
609 | |
610 | |
611 | // |
612 | if(!HasOpenedContext()) { |
613 | if(anIObj.IsNull()) return; |
614 | if(!myObjects.IsBound(anIObj)) |
615 | Display(anIObj,Standard_False); |
616 | |
617 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
618 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
619 | Handle(Standard_Transient) TR; |
620 | Handle(AIS_InteractiveObject) IO; |
621 | sel->Init(); |
622 | while (sel->More()) { |
623 | TR = sel->Value(); |
624 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
625 | Unhilight(IO,Standard_False); |
626 | IO->State(0); |
627 | sel->Next(); |
628 | } |
629 | |
81bba717 |
630 | // added to avoid untimely viewer update... |
7fd59977 |
631 | AIS_Selection::ClearAndSelect(anIObj); |
632 | anIObj->State(1); |
633 | Quantity_NameOfColor HiCol; |
634 | Standard_Boolean HasHiCol; |
635 | if(IsHilighted(anIObj,HasHiCol,HiCol)){ |
636 | if(HasHiCol && HiCol!= mySelectionColor) { |
637 | #ifdef UKI60826 |
638 | HilightWithColor(anIObj,mySelectionColor,Standard_False); |
639 | #else |
640 | Hilight(anIObj,Standard_False); |
641 | #endif |
642 | } |
643 | } |
644 | else{ |
645 | #ifdef UKI60826 |
646 | HilightWithColor(anIObj,mySelectionColor,Standard_False); |
647 | #else |
648 | Hilight(anIObj,Standard_False); |
649 | #endif |
650 | } |
651 | if (updateviewer) |
652 | UpdateCurrentViewer(); |
653 | } |
654 | else{ |
655 | #ifdef DEB |
656 | cout<<"Nothing Done : Opened Local Context"<<endl; |
657 | #endif |
658 | } |
659 | } |
660 | |
661 | //======================================================================= |
662 | //function : AddOrRemoveCurrentObject |
663 | //purpose : |
664 | //======================================================================= |
665 | |
666 | void AIS_InteractiveContext:: |
667 | AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj, |
668 | const Standard_Boolean updateviewer) |
669 | { |
670 | if(anIObj.IsNull()) return; |
671 | //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method) |
672 | if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) { |
673 | |
674 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
675 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
676 | |
677 | AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj); |
678 | |
679 | Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0; |
680 | anIObj->State(mod); |
681 | if(mod==1) |
682 | #ifdef BUC60814 |
683 | HilightWithColor(anIObj,mySelectionColor,Standard_False); |
684 | #else |
685 | Hilight(anIObj,Standard_False); |
686 | #endif |
687 | else |
688 | Unhilight(anIObj,Standard_False); |
689 | |
690 | |
691 | if(updateviewer) |
692 | UpdateCurrentViewer(); |
693 | } |
694 | else{ |
695 | #ifdef DEB |
696 | cout<<"Nothing Done : Opened Local Context"<<endl; |
697 | #endif |
698 | } |
699 | } |
700 | //======================================================================= |
701 | //function : UpdateCurrent |
702 | //purpose : |
703 | //======================================================================= |
704 | |
705 | void AIS_InteractiveContext::UpdateCurrent() |
706 | { |
707 | HilightCurrents(); |
708 | } |
709 | |
710 | //======================================================================= |
711 | //function : IsCurrent |
712 | //purpose : |
713 | //======================================================================= |
714 | |
715 | Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const |
716 | { |
717 | |
718 | if (anIObj.IsNull()) return Standard_False; |
719 | return (anIObj->State()==1); |
720 | |
721 | // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
722 | // sel->Init(); |
723 | // while (sel->More()) { |
724 | // if (anIObj == sel->Value()) return Standard_True; |
725 | // sel->Next(); |
726 | // } |
727 | // return Standard_False; |
728 | |
729 | } |
730 | |
731 | //======================================================================= |
732 | //function : InitCurrent |
733 | //purpose : |
734 | //======================================================================= |
735 | |
736 | void AIS_InteractiveContext::InitCurrent() |
737 | { |
738 | AIS_Selection::Selection(myCurrentName.ToCString())->Init(); |
739 | } |
740 | |
741 | //======================================================================= |
742 | //function : MoreCurrent |
743 | //purpose : |
744 | //======================================================================= |
745 | |
746 | Standard_Boolean AIS_InteractiveContext::MoreCurrent() const |
747 | { |
748 | return AIS_Selection::Selection(myCurrentName.ToCString())->More(); |
749 | |
750 | } |
751 | |
752 | //======================================================================= |
753 | //function : NextCurrent |
754 | //purpose : |
755 | //======================================================================= |
756 | |
757 | void AIS_InteractiveContext::NextCurrent() |
758 | { |
759 | AIS_Selection::Selection(myCurrentName.ToCString())->Next(); |
760 | } |
761 | |
762 | //======================================================================= |
763 | //function : Current |
764 | //purpose : |
765 | //======================================================================= |
766 | |
767 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const |
768 | { |
769 | Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value(); |
770 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR); |
771 | return IO; |
772 | } |
773 | |
774 | //======================================================================= |
775 | //function : FirstCurrentObject |
776 | //purpose : |
777 | //======================================================================= |
778 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject() |
779 | { |
780 | Handle(AIS_InteractiveObject) IO ; |
781 | InitCurrent(); |
782 | if(MoreCurrent()){ |
783 | return Current(); |
784 | } |
785 | return IO; |
786 | } |
787 | |
788 | //======================================================================= |
789 | //function : NbCurrents |
790 | //purpose : |
791 | //======================================================================= |
792 | Standard_Integer AIS_InteractiveContext::NbCurrents() |
793 | { |
794 | Standard_Integer i(0); |
795 | for(InitCurrent();MoreCurrent();NextCurrent()) |
796 | {i++;} |
797 | return i; |
798 | } |
799 | |
800 | //======================================================================= |
801 | //function : HilightCurrents |
802 | //purpose : |
803 | //======================================================================= |
804 | void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer) |
805 | { |
806 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
807 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
808 | Handle(Standard_Transient) TR; |
809 | Handle(AIS_InteractiveObject) IO; |
810 | sel->Init(); |
811 | while (sel->More()) { |
812 | TR = sel->Value(); |
813 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
814 | #ifdef BUC60814 |
815 | HilightWithColor(IO,mySelectionColor,Standard_False); |
816 | #else |
817 | Hilight(IO,Standard_False); |
818 | #endif |
819 | sel->Next(); |
820 | } |
821 | if(updateviewer) |
822 | UpdateCurrentViewer(); |
823 | } |
824 | |
825 | //======================================================================= |
826 | //function : UnhilightCurrents |
827 | //purpose : |
828 | //======================================================================= |
829 | |
830 | void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer) |
831 | { |
832 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
833 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
834 | Handle(Standard_Transient) TR; |
835 | Handle(AIS_InteractiveObject) IO; |
836 | sel->Init(); |
837 | while (sel->More()) { |
838 | TR = sel->Value(); |
839 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
840 | Unhilight(IO,Standard_False); |
841 | sel->Next(); |
842 | } |
843 | if(updateviewer) |
844 | UpdateCurrentViewer(); |
845 | } |
846 | |
847 | //======================================================================= |
848 | //function : ClearCurrents |
849 | //purpose : |
850 | //======================================================================= |
851 | |
852 | void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer) |
853 | { |
854 | if(NbCurrents()==0) return; |
855 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
856 | Handle(AIS_Selection) S = AIS_Selection::CurrentSelection(); |
857 | Handle(Standard_Transient) Tr; |
858 | Handle(AIS_InteractiveObject) IO; |
859 | for(S->Init();S->More();S->Next()){ |
860 | Tr = S->Value(); |
861 | IO = (*((Handle(AIS_InteractiveObject)*)&Tr)); |
862 | IO->State(0); |
863 | Unhilight(IO,Standard_False); |
864 | } |
865 | AIS_Selection::Select(); |
866 | if(updateviewer) |
867 | UpdateCurrentViewer(); |
868 | } |
869 | |
870 | |
871 | //======================================================================= |
872 | //function : HilightSelected |
873 | //purpose : |
874 | //======================================================================= |
875 | |
876 | void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer) |
877 | { |
878 | if(!HasOpenedContext()){ |
879 | AIS_Selection::SetCurrentSelection(mySelectionName.ToCString()); |
880 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
881 | Handle(Standard_Transient) TR; |
882 | Handle(AIS_InteractiveObject) IO; |
883 | sel->Init(); |
884 | while (sel->More()) { |
885 | TR = sel->Value(); |
886 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
887 | #ifdef BUC60814 |
888 | HilightWithColor(IO,mySelectionColor,Standard_False); |
889 | #else |
890 | Hilight(IO,Standard_False); |
891 | #endif |
892 | sel->Next(); |
893 | } |
894 | } |
895 | else |
896 | { |
897 | myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer); |
898 | } |
899 | if(updateviewer) |
900 | UpdateCurrentViewer(); |
901 | } |
902 | |
903 | //======================================================================= |
904 | //function : UnhilightSelected |
905 | //purpose : |
906 | //======================================================================= |
907 | |
908 | void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer) |
909 | { |
910 | if(!HasOpenedContext()){ |
911 | AIS_Selection::SetCurrentSelection(mySelectionName.ToCString()); |
912 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
913 | Handle(Standard_Transient) TR; |
914 | Handle(AIS_InteractiveObject) IO; |
915 | sel->Init(); |
916 | while (sel->More()) { |
917 | TR = sel->Value(); |
918 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
919 | Unhilight(IO,Standard_False); |
920 | sel->Next(); |
921 | } |
922 | if(updateviewer) |
923 | UpdateCurrentViewer(); |
924 | } |
925 | else |
926 | { |
927 | myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer); |
928 | } |
929 | } |
930 | |
931 | |
932 | //======================================================================= |
933 | //function : ClearSelected |
934 | //purpose : |
935 | //======================================================================= |
936 | |
937 | void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer) |
938 | { |
939 | if(!HasOpenedContext()) |
940 | ClearCurrents(updateviewer); |
941 | else |
942 | myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer); |
943 | |
944 | } |
945 | |
946 | |
947 | //======================================================================= |
948 | //function : SetSelectedCurrent |
949 | //purpose : |
950 | //======================================================================= |
951 | |
952 | void AIS_InteractiveContext::SetSelectedCurrent() |
953 | { |
954 | |
955 | |
956 | #ifdef DEB |
957 | cout<<"Not Yet Implemented"<<endl; |
958 | #endif |
959 | } |
960 | |
961 | //======================================================================= |
962 | //function : UpdateSelection |
963 | //purpose : |
964 | //======================================================================= |
965 | |
966 | void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer) |
967 | { |
968 | if(!HasOpenedContext()) { |
969 | HilightSelected(); |
970 | #ifndef BUG |
971 | return; |
972 | #endif |
973 | } |
974 | myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer); |
975 | } |
976 | |
977 | //======================================================================= |
978 | //function : SetCurrentObject |
979 | //purpose : |
980 | //======================================================================= |
981 | void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer) |
982 | { |
983 | if(!HasOpenedContext()) |
984 | SetCurrentObject(anIObj,updateviewer); |
985 | else |
986 | myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer); |
987 | } |
988 | |
989 | //======================================================================= |
990 | //function : AddOrRemoveSelected |
991 | //purpose : |
992 | //======================================================================= |
993 | |
994 | void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj, |
995 | const Standard_Boolean updateviewer) |
996 | { |
997 | if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this); |
998 | if(!HasOpenedContext()) |
999 | AddOrRemoveCurrentObject(anIObj,updateviewer); |
1000 | else |
1001 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer); |
1002 | |
1003 | } |
1004 | //======================================================================= |
1005 | //function : AddOrRemoveSelected |
1006 | //purpose : |
1007 | //======================================================================= |
1008 | |
1009 | void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap, |
1010 | const Standard_Boolean updateviewer) |
1011 | { |
1012 | if(!HasOpenedContext()) { |
1013 | #ifdef DEB |
1014 | cout<<" Attempt to remove a selected shape with no opened local context"<<endl; |
1015 | #endif |
1016 | return; |
1017 | } |
1018 | |
1019 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer); |
1020 | if(updateviewer) UpdateCurrentViewer(); |
1021 | |
1022 | } |
1023 | //======================================================================= |
1024 | //function : AddOrRemoveSelected |
1025 | //purpose : |
1026 | //======================================================================= |
1027 | |
1028 | void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own, |
1029 | const Standard_Boolean updateviewer) |
1030 | { |
1031 | if(!HasOpenedContext()) { |
1032 | #ifdef DEB |
1033 | cout<<" Attempt to remove a selected ownr with no opened local context"<<endl; |
1034 | #endif |
1035 | return; |
1036 | } |
1037 | |
1038 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False); |
1039 | if(updateviewer) UpdateCurrentViewer(); |
1040 | |
1041 | } |
1042 | |
1043 | |
1044 | |
1045 | //======================================================================= |
1046 | //function : IsSelected |
1047 | //purpose : |
1048 | //======================================================================= |
1049 | |
1050 | Standard_Boolean AIS_InteractiveContext:: |
1051 | IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const |
1052 | { |
1053 | if (anIObj.IsNull()) return Standard_False; |
1054 | |
1055 | if(!HasOpenedContext()) |
1056 | return (anIObj->State()==1); |
1057 | else |
1058 | return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj); |
1059 | } |
1060 | |
1061 | |
1062 | //======================================================================= |
1063 | //function : InitSelected |
1064 | //purpose : |
1065 | //======================================================================= |
1066 | |
1067 | void AIS_InteractiveContext::InitSelected() |
1068 | { |
1069 | if(!HasOpenedContext()) |
1070 | AIS_Selection::Selection(myCurrentName.ToCString())->Init(); |
1071 | else |
1072 | myLocalContexts(myCurLocalIndex)->InitSelected(); |
1073 | } |
1074 | |
1075 | //======================================================================= |
1076 | //function : MoreSelected |
1077 | //purpose : |
1078 | //======================================================================= |
1079 | |
1080 | Standard_Boolean AIS_InteractiveContext::MoreSelected() const |
1081 | { |
1082 | if(!HasOpenedContext()) |
1083 | return AIS_Selection::Selection(myCurrentName.ToCString())->More(); |
1084 | return myLocalContexts(myCurLocalIndex)->MoreSelected(); |
1085 | } |
1086 | |
1087 | //======================================================================= |
1088 | //function : NextSelected |
1089 | //purpose : |
1090 | //======================================================================= |
1091 | |
1092 | void AIS_InteractiveContext::NextSelected() |
1093 | { |
1094 | if(!HasOpenedContext()) |
1095 | AIS_Selection::Selection(myCurrentName.ToCString())->Next(); |
1096 | else |
1097 | myLocalContexts(myCurLocalIndex)->NextSelected(); |
1098 | } |
1099 | |
1100 | //======================================================================= |
1101 | //function : HasSelectedShape |
1102 | //purpose : |
1103 | //======================================================================= |
1104 | |
1105 | Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const |
1106 | { |
1107 | if(!HasOpenedContext()) { |
1108 | #ifdef IMP280200 |
1109 | Handle(AIS_Shape) shape = |
1110 | Handle(AIS_Shape)::DownCast(SelectedInteractive()); |
1111 | if( !shape.IsNull() ) return Standard_True; |
1112 | #endif |
1113 | return Standard_False; |
1114 | } |
1115 | return myLocalContexts(myCurLocalIndex)->HasShape(); |
1116 | |
1117 | |
1118 | } |
1119 | |
1120 | //======================================================================= |
1121 | //function : SelectedShape |
1122 | //purpose : |
1123 | //======================================================================= |
1124 | |
1125 | TopoDS_Shape AIS_InteractiveContext::SelectedShape() const |
1126 | { |
1127 | |
1128 | if(!HasOpenedContext()){ |
1129 | TopoDS_Shape sh; |
1130 | #ifdef IMP280200 |
1131 | Handle(AIS_Shape) shape = |
1132 | Handle(AIS_Shape)::DownCast(SelectedInteractive()); |
1133 | if( !shape.IsNull() ) sh = shape->Shape(); |
1134 | #endif |
1135 | return sh; |
1136 | } else |
1137 | return myLocalContexts(myCurLocalIndex)->SelectedShape(); |
1138 | } |
1139 | |
1140 | //======================================================================= |
1141 | //function : Interactive |
1142 | //purpose : |
1143 | //======================================================================= |
1144 | |
1145 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const |
1146 | { |
1147 | return SelectedInteractive(); |
1148 | } |
1149 | |
1150 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const |
1151 | { |
1152 | if(!HasOpenedContext()){ |
1153 | Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value(); |
1154 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR); |
1155 | return IO;} |
1156 | |
1157 | return myLocalContexts(myCurLocalIndex)->SelectedInteractive(); |
1158 | |
1159 | } |
1160 | //======================================================================= |
1161 | //function : Interactive |
1162 | //purpose : |
1163 | //======================================================================= |
1164 | |
1165 | Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const |
1166 | { |
1167 | if(!HasOpenedContext()){ |
1168 | Handle(SelectMgr_EntityOwner) Ownr; |
1169 | return Ownr; |
1170 | } |
1171 | return myLocalContexts(myCurLocalIndex)->SelectedOwner(); |
1172 | |
1173 | } |
1174 | |
1175 | //======================================================================= |
1176 | //function : EntityOwners |
1177 | //purpose : |
1178 | //======================================================================= |
1179 | void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners, |
1180 | const Handle(AIS_InteractiveObject)& theIObj, |
1181 | const Standard_Integer theMode) const |
1182 | { |
1183 | if ( theIObj.IsNull() ) |
1184 | return; |
1185 | |
1186 | TColStd_ListOfInteger aModes; |
1187 | if ( theMode == -1 ) |
1188 | ActivatedModes( theIObj, aModes ); |
1189 | else |
1190 | aModes.Append( theMode ); |
1191 | |
1192 | TColStd_ListIteratorOfListOfInteger anItr( aModes ); |
1193 | for (; anItr.More(); anItr.Next() ) |
1194 | { |
1195 | int aMode = anItr.Value(); |
1196 | if ( !theIObj->HasSelection( aMode ) ) |
1197 | continue; |
1198 | |
1199 | Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode ); |
1200 | |
1201 | for ( aSel->Init(); aSel->More(); aSel->Next() ) |
1202 | { |
1203 | Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive(); |
1204 | if ( aEntity.IsNull() ) |
1205 | continue; |
1206 | |
1207 | Handle(SelectMgr_EntityOwner) aOwner = |
1208 | Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId()); |
1209 | if ( !aOwner.IsNull() ) |
1210 | theOwners.Add( aOwner ); |
1211 | } |
1212 | } |
1213 | } |
1214 | |
1215 | Standard_Integer AIS_InteractiveContext::NbSelected() |
1216 | { |
1217 | Standard_Integer i(0); |
1218 | for(InitSelected();MoreSelected();NextSelected()) |
1219 | {i++;} |
1220 | return i; |
1221 | } |
1222 | |
1223 | //======================================================================= |
1224 | //function : HasApplicative |
1225 | //purpose : |
1226 | //======================================================================= |
1227 | |
1228 | Standard_Boolean AIS_InteractiveContext::HasApplicative() const |
1229 | { |
1230 | return Interactive()->HasOwner(); |
1231 | } |
1232 | |
1233 | //======================================================================= |
1234 | //function : Applicative |
1235 | //purpose : |
1236 | //======================================================================= |
1237 | |
1238 | Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const |
1239 | { |
1240 | return Interactive()->GetOwner(); |
1241 | } |
1242 | |
1243 | |
1244 | |
1245 | //================================================== |
1246 | // Function: |
1247 | // Purpose : |
1248 | //================================================== |
1249 | Standard_Boolean AIS_InteractiveContext::HasDetected() const |
1250 | { |
1251 | if(HasOpenedContext()) |
1252 | return myLocalContexts(myCurLocalIndex)->HasDetected(); |
1253 | else |
1254 | return !myLastPicked.IsNull(); |
1255 | } |
1256 | |
1257 | //======================================================================= |
1258 | //function : HasDetectedShape |
1259 | //purpose : |
1260 | //======================================================================= |
1261 | |
1262 | Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const |
1263 | { |
1264 | if(HasOpenedContext()) |
1265 | return myLocalContexts(myCurLocalIndex)->HasDetectedShape(); |
1266 | return Standard_False; |
1267 | } |
1268 | |
1269 | //======================================================================= |
1270 | //function : DetectedShape |
1271 | //purpose : |
1272 | //======================================================================= |
1273 | |
1274 | const TopoDS_Shape& |
1275 | AIS_InteractiveContext::DetectedShape() const |
1276 | { |
1277 | return myLocalContexts(myCurLocalIndex)->DetectedShape(); |
1278 | } |
1279 | |
1280 | //======================================================================= |
1281 | //function : DetectedInteractive |
1282 | //purpose : |
1283 | //======================================================================= |
1284 | |
1285 | Handle(AIS_InteractiveObject) |
1286 | AIS_InteractiveContext::DetectedInteractive() const |
1287 | { |
1288 | if(HasOpenedContext()) |
1289 | return myLocalContexts(myCurLocalIndex)->DetectedInteractive(); |
1290 | return myLastPicked; |
1291 | } |
1292 | |
1293 | |
1294 | Standard_Boolean AIS_InteractiveContext::HasNextDetected() const |
1295 | { |
1296 | if(!HasOpenedContext()) |
1297 | return Standard_False; // temporaire |
1298 | else |
1299 | return myLocalContexts(myCurLocalIndex)->HasNextDetected(); |
1300 | |
1301 | } |
1302 | |
1303 | |
1304 | //======================================================================= |
1305 | //function : DetectedOwner |
1306 | //purpose : |
1307 | //======================================================================= |
1308 | Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const |
1309 | { |
1310 | if(HasOpenedContext()) |
1311 | return myLocalContexts(myCurLocalIndex)->DetectedOwner(); |
1312 | Handle(SelectMgr_EntityOwner) Ownr; |
1313 | return Ownr; |
1314 | } |
1315 | |
1316 | |
1317 | //======================================================================= |
1318 | //function : HilightNextDetected |
1319 | //purpose : |
1320 | //======================================================================= |
1321 | Standard_Integer AIS_InteractiveContext::HilightNextDetected(const Handle(V3d_View)& V) |
1322 | { |
1323 | if(!HasOpenedContext()) |
1324 | return 0; |
1325 | return myLocalContexts(myCurLocalIndex)->HilightNextDetected(V); |
1326 | |
1327 | } |
1328 | |
1329 | //======================================================================= |
1330 | //function : HilightNextDetected |
1331 | //purpose : |
1332 | //======================================================================= |
1333 | Standard_Integer AIS_InteractiveContext::HilightPreviousDetected(const Handle(V3d_View)& V) |
1334 | { |
1335 | if(!HasOpenedContext()) |
1336 | return 0; |
1337 | return myLocalContexts(myCurLocalIndex)->HilightPreviousDetected(V); |
1338 | |
1339 | } |
1340 | |
1341 | #ifdef IMP150501 |
1342 | void AIS_InteractiveContext::Drag( |
1343 | const Handle(V3d_View)& aView, |
1344 | const Handle(AIS_InteractiveObject)& anObject, |
1345 | const Handle(Geom_Transformation)& aTrsf, |
1346 | const Standard_Boolean postConcatenate, |
1347 | const Standard_Boolean update, |
1348 | const Standard_Boolean zBuffer) { |
1349 | |
1350 | if( anObject.IsNull() || aView.IsNull() ) return; |
1351 | |
1352 | if( update ) { |
1353 | anObject->SetTransformation(aTrsf,postConcatenate,Standard_True); |
1354 | aView->Update(); |
1355 | } else if( Visual3d_TransientManager::BeginDraw(aView->View(), |
1356 | zBuffer,Standard_False) ) { |
1357 | Handle(Prs3d_Presentation) P = anObject->Presentation(); |
1358 | if( !P.IsNull() ) { |
1359 | if( postConcatenate ) P->Multiply(aTrsf); |
1360 | else P->Transform(aTrsf); |
1361 | Visual3d_TransientManager::DrawStructure(P); |
1362 | } |
1363 | Visual3d_TransientManager::EndDraw(Standard_True); |
1364 | } |
1365 | } |
1366 | #endif |
1367 | |
1368 | #ifdef IMP160701 |
1369 | //======================================================================= |
1370 | //function : InitDetected |
1371 | //purpose : |
1372 | //======================================================================= |
1373 | void AIS_InteractiveContext::InitDetected() |
1374 | { |
1375 | if(HasOpenedContext()) |
1376 | { |
1377 | myLocalContexts(myCurLocalIndex)->InitDetected(); |
1378 | return; |
1379 | } |
1380 | |
1381 | if(myAISDetectedSeq.Length() != 0) |
1382 | myAISCurDetected = 1; |
1383 | |
1384 | } |
1385 | |
1386 | //======================================================================= |
1387 | //function : MoreDetected |
1388 | //purpose : |
1389 | //======================================================================= |
1390 | Standard_Boolean AIS_InteractiveContext::MoreDetected() const |
1391 | { |
1392 | if(HasOpenedContext()) |
1393 | return myLocalContexts(myCurLocalIndex)->MoreDetected(); |
1394 | |
1395 | return (myAISCurDetected>0 &&myAISCurDetected <= myAISDetectedSeq.Length()) ? |
1396 | Standard_True : Standard_False; |
1397 | } |
1398 | |
1399 | //======================================================================= |
1400 | //function : NextDetected |
1401 | //purpose : |
1402 | //======================================================================= |
1403 | void AIS_InteractiveContext::NextDetected() |
1404 | { |
1405 | if(HasOpenedContext()) |
1406 | { |
1407 | myLocalContexts(myCurLocalIndex)->NextDetected(); |
1408 | return; |
1409 | } |
1410 | |
1411 | myAISCurDetected++; |
1412 | } |
1413 | |
1414 | //======================================================================= |
1415 | //function : DetectedCurrentShape |
1416 | //purpose : |
1417 | //======================================================================= |
1418 | |
1419 | const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const |
1420 | { |
1421 | if(HasOpenedContext()) |
1422 | return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape(); |
1423 | |
1424 | static TopoDS_Shape bidsh; |
1425 | if(myAISCurDetected > 0 && |
1426 | myAISCurDetected <= myAISDetectedSeq.Length()) |
1427 | return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape(); |
1428 | return bidsh; |
1429 | } |
1430 | |
1431 | //======================================================================= |
1432 | //function : DetectedCurrentObject |
1433 | //purpose : |
1434 | //======================================================================= |
1435 | |
1436 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const { |
1437 | if(HasOpenedContext()) |
1438 | return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject(); |
1439 | |
1440 | Handle(AIS_InteractiveObject) aBad; |
1441 | |
1442 | if(myAISCurDetected > 0 && |
1443 | myAISCurDetected <= myAISDetectedSeq.Length()) |
1444 | return myAISDetectedSeq(myAISCurDetected); |
1445 | else |
1446 | return aBad; |
1447 | } |
1448 | #endif |