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 |
7fd59977 |
428 | { |
429 | myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer); |
430 | return AIS_SOP_OneSelected; |
431 | } |
432 | } |
433 | // AIS_StatusOfPick PS(AIS_SOP_NothingSelected); |
434 | if(myWasLastMain && !myLastinMain.IsNull()){ |
435 | if(myLastinMain->State()!=1){ |
436 | SetCurrentObject(myLastinMain,Standard_False); |
437 | if(updateviewer) |
438 | UpdateCurrentViewer();} |
439 | } |
7fd59977 |
440 | else{ |
441 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
442 | Handle(AIS_Selection) S = AIS_Selection::CurrentSelection(); |
443 | Handle(Standard_Transient) Tr; |
444 | Handle(AIS_InteractiveObject) IO; |
445 | |
446 | for(S->Init();S->More();S->Next()){ |
447 | Tr = S->Value(); |
448 | IO = (*((Handle(AIS_InteractiveObject)*)&Tr)); |
449 | IO->State(0); |
450 | Unhilight(IO,Standard_False); |
451 | if(myObjects.IsBound(IO)){ // anti-plantage-rob |
452 | if(myObjects(IO)->IsSubIntensityOn()) |
453 | HilightWithColor(IO,mySubIntensity,Standard_False); |
454 | } |
455 | } |
456 | |
457 | AIS_Selection::Select(); |
458 | if(updateviewer){ |
459 | if(myWasLastMain) |
eb4320f2 |
460 | UpdateCurrentViewer(); |
7fd59977 |
461 | } |
462 | } |
463 | Standard_Integer NS = NbCurrents(); |
464 | if(NS==0) return AIS_SOP_NothingSelected; |
465 | if(NS==1) return AIS_SOP_OneSelected; |
466 | return AIS_SOP_SeveralSelected; |
467 | } |
468 | |
469 | //======================================================================= |
470 | //function : ShiftSelect |
471 | //purpose : |
472 | //======================================================================= |
473 | |
474 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer) |
475 | { |
476 | if(HasOpenedContext()){ |
477 | if(myWasLastMain) |
478 | return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer); |
479 | else{ |
480 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer); |
481 | Standard_Integer NS =NbSelected(); |
482 | if(NS==0) return AIS_SOP_NothingSelected; |
483 | if(NS==1) return AIS_SOP_OneSelected; |
484 | return AIS_SOP_SeveralSelected; |
485 | } |
486 | } |
487 | if(myWasLastMain && !myLastinMain.IsNull()) |
488 | AddOrRemoveCurrentObject(myLastinMain,updateviewer); |
eb4320f2 |
489 | |
7fd59977 |
490 | Standard_Integer NS = NbCurrents(); |
491 | if(NS==0) return AIS_SOP_NothingSelected; |
492 | if(NS==1) return AIS_SOP_OneSelected; |
493 | return AIS_SOP_SeveralSelected; |
494 | } |
495 | |
496 | |
497 | //======================================================================= |
498 | //function : ShiftSelect |
499 | //purpose : |
500 | //======================================================================= |
501 | |
502 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin, |
503 | const Standard_Integer YPMin, |
504 | const Standard_Integer XPMax, |
505 | const Standard_Integer YPMax, |
506 | const Handle(V3d_View)& aView, |
507 | const Standard_Boolean updateviewer) |
508 | { |
509 | |
510 | if(HasOpenedContext()) |
511 | return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,aView,updateviewer); |
512 | |
513 | UnhilightCurrents(Standard_False); |
514 | // OCC11904 - local variables made non-static - it looks and works better like this |
515 | Handle(StdSelect_ViewerSelector3d) selector; |
516 | |
517 | if(aView->Viewer()== myMainVwr) { |
518 | selector= myMainSel; |
519 | myWasLastMain = Standard_True;} |
7fd59977 |
520 | else |
521 | return AIS_SOP_NothingSelected; |
522 | |
523 | selector->Pick(XPMin,YPMin,XPMax,YPMax,aView); |
524 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
525 | for(selector->Init();selector->More();selector->Next()){ |
526 | const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable(); |
527 | if(!SO.IsNull()){ |
528 | AIS_SelectStatus SelStat = AIS_Selection::Select(SO); |
529 | Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0; |
530 | (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod); |
531 | } |
532 | } |
533 | |
534 | HilightCurrents(updateviewer); |
535 | |
536 | Standard_Integer NS =NbCurrents(); |
537 | if(NS==0) return AIS_SOP_NothingSelected; |
538 | if(NS==1) return AIS_SOP_OneSelected; |
539 | return AIS_SOP_SeveralSelected; |
540 | |
541 | } |
542 | |
543 | //======================================================================= |
544 | //function : ShiftSelect |
545 | //purpose : |
546 | //======================================================================= |
547 | |
548 | AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline, |
549 | const Handle(V3d_View)& aView, |
550 | const Standard_Boolean updateviewer ) |
551 | { |
552 | if( HasOpenedContext() ) |
553 | return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer ); |
554 | |
555 | UnhilightCurrents( Standard_False ); |
556 | // OCC11904 - local variables made non-static - it looks and works better like this |
557 | Handle(StdSelect_ViewerSelector3d) selector; |
558 | |
559 | if( aView->Viewer() == myMainVwr ) { |
560 | selector= myMainSel; |
561 | myWasLastMain = Standard_True; |
562 | } |
7fd59977 |
563 | else |
564 | return AIS_SOP_NothingSelected; |
565 | |
566 | selector->Pick( aPolyline, aView ); |
567 | |
568 | AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() ); |
569 | for( selector->Init(); selector->More(); selector->Next() ) { |
570 | const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable(); |
571 | if( !SO.IsNull() ) { |
572 | AIS_SelectStatus SelStat = AIS_Selection::Select( SO ); |
573 | Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0; |
574 | (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod ); |
575 | } |
576 | } |
577 | |
578 | HilightCurrents( updateviewer ); |
579 | Standard_Integer NS = NbCurrents(); |
580 | if( NS == 0 ) return AIS_SOP_NothingSelected; |
581 | if( NS == 1 ) return AIS_SOP_OneSelected; |
582 | return AIS_SOP_SeveralSelected; |
583 | } |
584 | |
585 | //======================================================================= |
586 | //function : SetCurrentObject |
587 | //purpose : |
588 | //======================================================================= |
589 | |
590 | void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj, |
591 | const Standard_Boolean updateviewer) |
592 | { |
81bba717 |
593 | // single case processing... |
7fd59977 |
594 | if(NbCurrents()==1 && anIObj->State()==1){ |
595 | Quantity_NameOfColor HiCol; |
596 | Standard_Boolean HasHiCol; |
597 | if(IsHilighted(anIObj,HasHiCol,HiCol)){ |
598 | if(HasHiCol && HiCol!= mySelectionColor) { |
599 | #ifdef UKI60826 |
600 | HilightWithColor(anIObj,mySelectionColor,updateviewer); |
601 | #else |
602 | Hilight(anIObj,updateviewer); |
603 | #endif |
604 | } |
605 | } |
606 | return; |
607 | } |
608 | |
609 | |
610 | // |
611 | if(!HasOpenedContext()) { |
612 | if(anIObj.IsNull()) return; |
613 | if(!myObjects.IsBound(anIObj)) |
614 | Display(anIObj,Standard_False); |
615 | |
616 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
617 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
618 | Handle(Standard_Transient) TR; |
619 | Handle(AIS_InteractiveObject) IO; |
620 | sel->Init(); |
621 | while (sel->More()) { |
622 | TR = sel->Value(); |
623 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
624 | Unhilight(IO,Standard_False); |
625 | IO->State(0); |
626 | sel->Next(); |
627 | } |
628 | |
81bba717 |
629 | // added to avoid untimely viewer update... |
7fd59977 |
630 | AIS_Selection::ClearAndSelect(anIObj); |
631 | anIObj->State(1); |
632 | Quantity_NameOfColor HiCol; |
633 | Standard_Boolean HasHiCol; |
634 | if(IsHilighted(anIObj,HasHiCol,HiCol)){ |
635 | if(HasHiCol && HiCol!= mySelectionColor) { |
636 | #ifdef UKI60826 |
637 | HilightWithColor(anIObj,mySelectionColor,Standard_False); |
638 | #else |
639 | Hilight(anIObj,Standard_False); |
640 | #endif |
641 | } |
642 | } |
643 | else{ |
644 | #ifdef UKI60826 |
645 | HilightWithColor(anIObj,mySelectionColor,Standard_False); |
646 | #else |
647 | Hilight(anIObj,Standard_False); |
648 | #endif |
649 | } |
650 | if (updateviewer) |
651 | UpdateCurrentViewer(); |
652 | } |
653 | else{ |
654 | #ifdef DEB |
655 | cout<<"Nothing Done : Opened Local Context"<<endl; |
656 | #endif |
657 | } |
658 | } |
659 | |
660 | //======================================================================= |
661 | //function : AddOrRemoveCurrentObject |
662 | //purpose : |
663 | //======================================================================= |
664 | |
665 | void AIS_InteractiveContext:: |
666 | AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj, |
667 | const Standard_Boolean updateviewer) |
668 | { |
669 | if(anIObj.IsNull()) return; |
670 | //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method) |
671 | if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) { |
672 | |
673 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
674 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
675 | |
676 | AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj); |
677 | |
678 | Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0; |
679 | anIObj->State(mod); |
680 | if(mod==1) |
681 | #ifdef BUC60814 |
682 | HilightWithColor(anIObj,mySelectionColor,Standard_False); |
683 | #else |
684 | Hilight(anIObj,Standard_False); |
685 | #endif |
686 | else |
687 | Unhilight(anIObj,Standard_False); |
688 | |
689 | |
690 | if(updateviewer) |
691 | UpdateCurrentViewer(); |
692 | } |
693 | else{ |
694 | #ifdef DEB |
695 | cout<<"Nothing Done : Opened Local Context"<<endl; |
696 | #endif |
697 | } |
698 | } |
699 | //======================================================================= |
700 | //function : UpdateCurrent |
701 | //purpose : |
702 | //======================================================================= |
703 | |
704 | void AIS_InteractiveContext::UpdateCurrent() |
705 | { |
706 | HilightCurrents(); |
707 | } |
708 | |
709 | //======================================================================= |
710 | //function : IsCurrent |
711 | //purpose : |
712 | //======================================================================= |
713 | |
714 | Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const |
715 | { |
716 | |
717 | if (anIObj.IsNull()) return Standard_False; |
718 | return (anIObj->State()==1); |
719 | |
720 | // Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
721 | // sel->Init(); |
722 | // while (sel->More()) { |
723 | // if (anIObj == sel->Value()) return Standard_True; |
724 | // sel->Next(); |
725 | // } |
726 | // return Standard_False; |
727 | |
728 | } |
729 | |
730 | //======================================================================= |
731 | //function : InitCurrent |
732 | //purpose : |
733 | //======================================================================= |
734 | |
735 | void AIS_InteractiveContext::InitCurrent() |
736 | { |
737 | AIS_Selection::Selection(myCurrentName.ToCString())->Init(); |
738 | } |
739 | |
740 | //======================================================================= |
741 | //function : MoreCurrent |
742 | //purpose : |
743 | //======================================================================= |
744 | |
745 | Standard_Boolean AIS_InteractiveContext::MoreCurrent() const |
746 | { |
747 | return AIS_Selection::Selection(myCurrentName.ToCString())->More(); |
748 | |
749 | } |
750 | |
751 | //======================================================================= |
752 | //function : NextCurrent |
753 | //purpose : |
754 | //======================================================================= |
755 | |
756 | void AIS_InteractiveContext::NextCurrent() |
757 | { |
758 | AIS_Selection::Selection(myCurrentName.ToCString())->Next(); |
759 | } |
760 | |
761 | //======================================================================= |
762 | //function : Current |
763 | //purpose : |
764 | //======================================================================= |
765 | |
766 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const |
767 | { |
768 | Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value(); |
769 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR); |
770 | return IO; |
771 | } |
772 | |
773 | //======================================================================= |
774 | //function : FirstCurrentObject |
775 | //purpose : |
776 | //======================================================================= |
777 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject() |
778 | { |
779 | Handle(AIS_InteractiveObject) IO ; |
780 | InitCurrent(); |
781 | if(MoreCurrent()){ |
782 | return Current(); |
783 | } |
784 | return IO; |
785 | } |
786 | |
787 | //======================================================================= |
788 | //function : NbCurrents |
789 | //purpose : |
790 | //======================================================================= |
791 | Standard_Integer AIS_InteractiveContext::NbCurrents() |
792 | { |
793 | Standard_Integer i(0); |
794 | for(InitCurrent();MoreCurrent();NextCurrent()) |
795 | {i++;} |
796 | return i; |
797 | } |
798 | |
799 | //======================================================================= |
800 | //function : HilightCurrents |
801 | //purpose : |
802 | //======================================================================= |
803 | void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer) |
804 | { |
805 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
806 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
807 | Handle(Standard_Transient) TR; |
808 | Handle(AIS_InteractiveObject) IO; |
809 | sel->Init(); |
810 | while (sel->More()) { |
811 | TR = sel->Value(); |
812 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
813 | #ifdef BUC60814 |
814 | HilightWithColor(IO,mySelectionColor,Standard_False); |
815 | #else |
816 | Hilight(IO,Standard_False); |
817 | #endif |
818 | sel->Next(); |
819 | } |
820 | if(updateviewer) |
821 | UpdateCurrentViewer(); |
822 | } |
823 | |
824 | //======================================================================= |
825 | //function : UnhilightCurrents |
826 | //purpose : |
827 | //======================================================================= |
828 | |
829 | void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer) |
830 | { |
831 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
832 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
833 | Handle(Standard_Transient) TR; |
834 | Handle(AIS_InteractiveObject) IO; |
835 | sel->Init(); |
836 | while (sel->More()) { |
837 | TR = sel->Value(); |
838 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
839 | Unhilight(IO,Standard_False); |
840 | sel->Next(); |
841 | } |
842 | if(updateviewer) |
843 | UpdateCurrentViewer(); |
844 | } |
845 | |
846 | //======================================================================= |
847 | //function : ClearCurrents |
848 | //purpose : |
849 | //======================================================================= |
850 | |
851 | void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer) |
852 | { |
853 | if(NbCurrents()==0) return; |
854 | AIS_Selection::SetCurrentSelection(myCurrentName.ToCString()); |
855 | Handle(AIS_Selection) S = AIS_Selection::CurrentSelection(); |
856 | Handle(Standard_Transient) Tr; |
857 | Handle(AIS_InteractiveObject) IO; |
858 | for(S->Init();S->More();S->Next()){ |
859 | Tr = S->Value(); |
860 | IO = (*((Handle(AIS_InteractiveObject)*)&Tr)); |
861 | IO->State(0); |
862 | Unhilight(IO,Standard_False); |
863 | } |
864 | AIS_Selection::Select(); |
865 | if(updateviewer) |
866 | UpdateCurrentViewer(); |
867 | } |
868 | |
869 | |
870 | //======================================================================= |
871 | //function : HilightSelected |
872 | //purpose : |
873 | //======================================================================= |
874 | |
875 | void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer) |
876 | { |
877 | if(!HasOpenedContext()){ |
878 | AIS_Selection::SetCurrentSelection(mySelectionName.ToCString()); |
879 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
880 | Handle(Standard_Transient) TR; |
881 | Handle(AIS_InteractiveObject) IO; |
882 | sel->Init(); |
883 | while (sel->More()) { |
884 | TR = sel->Value(); |
885 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
886 | #ifdef BUC60814 |
887 | HilightWithColor(IO,mySelectionColor,Standard_False); |
888 | #else |
889 | Hilight(IO,Standard_False); |
890 | #endif |
891 | sel->Next(); |
892 | } |
893 | } |
894 | else |
895 | { |
896 | myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer); |
897 | } |
898 | if(updateviewer) |
899 | UpdateCurrentViewer(); |
900 | } |
901 | |
902 | //======================================================================= |
903 | //function : UnhilightSelected |
904 | //purpose : |
905 | //======================================================================= |
906 | |
907 | void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer) |
908 | { |
909 | if(!HasOpenedContext()){ |
910 | AIS_Selection::SetCurrentSelection(mySelectionName.ToCString()); |
911 | Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString()); |
912 | Handle(Standard_Transient) TR; |
913 | Handle(AIS_InteractiveObject) IO; |
914 | sel->Init(); |
915 | while (sel->More()) { |
916 | TR = sel->Value(); |
917 | IO = *((Handle(AIS_InteractiveObject)*)&TR); |
918 | Unhilight(IO,Standard_False); |
919 | sel->Next(); |
920 | } |
921 | if(updateviewer) |
922 | UpdateCurrentViewer(); |
923 | } |
924 | else |
925 | { |
926 | myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer); |
927 | } |
928 | } |
929 | |
930 | |
931 | //======================================================================= |
932 | //function : ClearSelected |
933 | //purpose : |
934 | //======================================================================= |
935 | |
936 | void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer) |
937 | { |
938 | if(!HasOpenedContext()) |
939 | ClearCurrents(updateviewer); |
940 | else |
941 | myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer); |
942 | |
943 | } |
944 | |
945 | |
946 | //======================================================================= |
947 | //function : SetSelectedCurrent |
948 | //purpose : |
949 | //======================================================================= |
950 | |
951 | void AIS_InteractiveContext::SetSelectedCurrent() |
952 | { |
953 | |
954 | |
955 | #ifdef DEB |
956 | cout<<"Not Yet Implemented"<<endl; |
957 | #endif |
958 | } |
959 | |
960 | //======================================================================= |
961 | //function : UpdateSelection |
962 | //purpose : |
963 | //======================================================================= |
964 | |
965 | void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer) |
966 | { |
967 | if(!HasOpenedContext()) { |
968 | HilightSelected(); |
969 | #ifndef BUG |
970 | return; |
971 | #endif |
972 | } |
973 | myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer); |
974 | } |
975 | |
976 | //======================================================================= |
977 | //function : SetCurrentObject |
978 | //purpose : |
979 | //======================================================================= |
980 | void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer) |
981 | { |
982 | if(!HasOpenedContext()) |
983 | SetCurrentObject(anIObj,updateviewer); |
984 | else |
985 | myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer); |
986 | } |
987 | |
988 | //======================================================================= |
989 | //function : AddOrRemoveSelected |
990 | //purpose : |
991 | //======================================================================= |
992 | |
993 | void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj, |
994 | const Standard_Boolean updateviewer) |
995 | { |
996 | if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this); |
997 | if(!HasOpenedContext()) |
998 | AddOrRemoveCurrentObject(anIObj,updateviewer); |
999 | else |
1000 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer); |
1001 | |
1002 | } |
1003 | //======================================================================= |
1004 | //function : AddOrRemoveSelected |
1005 | //purpose : |
1006 | //======================================================================= |
1007 | |
1008 | void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap, |
1009 | const Standard_Boolean updateviewer) |
1010 | { |
1011 | if(!HasOpenedContext()) { |
1012 | #ifdef DEB |
1013 | cout<<" Attempt to remove a selected shape with no opened local context"<<endl; |
1014 | #endif |
1015 | return; |
1016 | } |
1017 | |
1018 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer); |
1019 | if(updateviewer) UpdateCurrentViewer(); |
1020 | |
1021 | } |
1022 | //======================================================================= |
1023 | //function : AddOrRemoveSelected |
1024 | //purpose : |
1025 | //======================================================================= |
1026 | |
1027 | void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own, |
1028 | const Standard_Boolean updateviewer) |
1029 | { |
1030 | if(!HasOpenedContext()) { |
1031 | #ifdef DEB |
1032 | cout<<" Attempt to remove a selected ownr with no opened local context"<<endl; |
1033 | #endif |
1034 | return; |
1035 | } |
1036 | |
1037 | myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False); |
1038 | if(updateviewer) UpdateCurrentViewer(); |
1039 | |
1040 | } |
1041 | |
1042 | |
1043 | |
1044 | //======================================================================= |
1045 | //function : IsSelected |
1046 | //purpose : |
1047 | //======================================================================= |
1048 | |
1049 | Standard_Boolean AIS_InteractiveContext:: |
1050 | IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const |
1051 | { |
1052 | if (anIObj.IsNull()) return Standard_False; |
1053 | |
1054 | if(!HasOpenedContext()) |
1055 | return (anIObj->State()==1); |
1056 | else |
1057 | return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj); |
1058 | } |
1059 | |
1060 | |
1061 | //======================================================================= |
1062 | //function : InitSelected |
1063 | //purpose : |
1064 | //======================================================================= |
1065 | |
1066 | void AIS_InteractiveContext::InitSelected() |
1067 | { |
1068 | if(!HasOpenedContext()) |
1069 | AIS_Selection::Selection(myCurrentName.ToCString())->Init(); |
1070 | else |
1071 | myLocalContexts(myCurLocalIndex)->InitSelected(); |
1072 | } |
1073 | |
1074 | //======================================================================= |
1075 | //function : MoreSelected |
1076 | //purpose : |
1077 | //======================================================================= |
1078 | |
1079 | Standard_Boolean AIS_InteractiveContext::MoreSelected() const |
1080 | { |
1081 | if(!HasOpenedContext()) |
1082 | return AIS_Selection::Selection(myCurrentName.ToCString())->More(); |
1083 | return myLocalContexts(myCurLocalIndex)->MoreSelected(); |
1084 | } |
1085 | |
1086 | //======================================================================= |
1087 | //function : NextSelected |
1088 | //purpose : |
1089 | //======================================================================= |
1090 | |
1091 | void AIS_InteractiveContext::NextSelected() |
1092 | { |
1093 | if(!HasOpenedContext()) |
1094 | AIS_Selection::Selection(myCurrentName.ToCString())->Next(); |
1095 | else |
1096 | myLocalContexts(myCurLocalIndex)->NextSelected(); |
1097 | } |
1098 | |
1099 | //======================================================================= |
1100 | //function : HasSelectedShape |
1101 | //purpose : |
1102 | //======================================================================= |
1103 | |
1104 | Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const |
1105 | { |
1106 | if(!HasOpenedContext()) { |
1107 | #ifdef IMP280200 |
1108 | Handle(AIS_Shape) shape = |
1109 | Handle(AIS_Shape)::DownCast(SelectedInteractive()); |
1110 | if( !shape.IsNull() ) return Standard_True; |
1111 | #endif |
1112 | return Standard_False; |
1113 | } |
1114 | return myLocalContexts(myCurLocalIndex)->HasShape(); |
1115 | |
1116 | |
1117 | } |
1118 | |
1119 | //======================================================================= |
1120 | //function : SelectedShape |
1121 | //purpose : |
1122 | //======================================================================= |
1123 | |
1124 | TopoDS_Shape AIS_InteractiveContext::SelectedShape() const |
1125 | { |
1126 | |
1127 | if(!HasOpenedContext()){ |
1128 | TopoDS_Shape sh; |
1129 | #ifdef IMP280200 |
1130 | Handle(AIS_Shape) shape = |
1131 | Handle(AIS_Shape)::DownCast(SelectedInteractive()); |
1132 | if( !shape.IsNull() ) sh = shape->Shape(); |
1133 | #endif |
1134 | return sh; |
1135 | } else |
1136 | return myLocalContexts(myCurLocalIndex)->SelectedShape(); |
1137 | } |
1138 | |
1139 | //======================================================================= |
1140 | //function : Interactive |
1141 | //purpose : |
1142 | //======================================================================= |
1143 | |
1144 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const |
1145 | { |
1146 | return SelectedInteractive(); |
1147 | } |
1148 | |
1149 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const |
1150 | { |
1151 | if(!HasOpenedContext()){ |
1152 | Handle(Standard_Transient) TR =AIS_Selection::Selection(myCurrentName.ToCString())->Value(); |
1153 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR); |
1154 | return IO;} |
1155 | |
1156 | return myLocalContexts(myCurLocalIndex)->SelectedInteractive(); |
1157 | |
1158 | } |
1159 | //======================================================================= |
1160 | //function : Interactive |
1161 | //purpose : |
1162 | //======================================================================= |
1163 | |
1164 | Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const |
1165 | { |
1166 | if(!HasOpenedContext()){ |
1167 | Handle(SelectMgr_EntityOwner) Ownr; |
1168 | return Ownr; |
1169 | } |
1170 | return myLocalContexts(myCurLocalIndex)->SelectedOwner(); |
1171 | |
1172 | } |
1173 | |
1174 | //======================================================================= |
1175 | //function : EntityOwners |
1176 | //purpose : |
1177 | //======================================================================= |
1178 | void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners, |
1179 | const Handle(AIS_InteractiveObject)& theIObj, |
1180 | const Standard_Integer theMode) const |
1181 | { |
1182 | if ( theIObj.IsNull() ) |
1183 | return; |
1184 | |
1185 | TColStd_ListOfInteger aModes; |
1186 | if ( theMode == -1 ) |
1187 | ActivatedModes( theIObj, aModes ); |
1188 | else |
1189 | aModes.Append( theMode ); |
1190 | |
1191 | TColStd_ListIteratorOfListOfInteger anItr( aModes ); |
1192 | for (; anItr.More(); anItr.Next() ) |
1193 | { |
1194 | int aMode = anItr.Value(); |
1195 | if ( !theIObj->HasSelection( aMode ) ) |
1196 | continue; |
1197 | |
1198 | Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode ); |
1199 | |
1200 | for ( aSel->Init(); aSel->More(); aSel->Next() ) |
1201 | { |
1202 | Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive(); |
1203 | if ( aEntity.IsNull() ) |
1204 | continue; |
1205 | |
1206 | Handle(SelectMgr_EntityOwner) aOwner = |
1207 | Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId()); |
1208 | if ( !aOwner.IsNull() ) |
1209 | theOwners.Add( aOwner ); |
1210 | } |
1211 | } |
1212 | } |
1213 | |
1214 | Standard_Integer AIS_InteractiveContext::NbSelected() |
1215 | { |
1216 | Standard_Integer i(0); |
1217 | for(InitSelected();MoreSelected();NextSelected()) |
1218 | {i++;} |
1219 | return i; |
1220 | } |
1221 | |
1222 | //======================================================================= |
1223 | //function : HasApplicative |
1224 | //purpose : |
1225 | //======================================================================= |
1226 | |
1227 | Standard_Boolean AIS_InteractiveContext::HasApplicative() const |
1228 | { |
1229 | return Interactive()->HasOwner(); |
1230 | } |
1231 | |
1232 | //======================================================================= |
1233 | //function : Applicative |
1234 | //purpose : |
1235 | //======================================================================= |
1236 | |
1237 | Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const |
1238 | { |
1239 | return Interactive()->GetOwner(); |
1240 | } |
1241 | |
1242 | |
1243 | |
1244 | //================================================== |
1245 | // Function: |
1246 | // Purpose : |
1247 | //================================================== |
1248 | Standard_Boolean AIS_InteractiveContext::HasDetected() const |
1249 | { |
1250 | if(HasOpenedContext()) |
1251 | return myLocalContexts(myCurLocalIndex)->HasDetected(); |
1252 | else |
1253 | return !myLastPicked.IsNull(); |
1254 | } |
1255 | |
1256 | //======================================================================= |
1257 | //function : HasDetectedShape |
1258 | //purpose : |
1259 | //======================================================================= |
1260 | |
1261 | Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const |
1262 | { |
1263 | if(HasOpenedContext()) |
1264 | return myLocalContexts(myCurLocalIndex)->HasDetectedShape(); |
1265 | return Standard_False; |
1266 | } |
1267 | |
1268 | //======================================================================= |
1269 | //function : DetectedShape |
1270 | //purpose : |
1271 | //======================================================================= |
1272 | |
1273 | const TopoDS_Shape& |
1274 | AIS_InteractiveContext::DetectedShape() const |
1275 | { |
1276 | return myLocalContexts(myCurLocalIndex)->DetectedShape(); |
1277 | } |
1278 | |
1279 | //======================================================================= |
1280 | //function : DetectedInteractive |
1281 | //purpose : |
1282 | //======================================================================= |
1283 | |
1284 | Handle(AIS_InteractiveObject) |
1285 | AIS_InteractiveContext::DetectedInteractive() const |
1286 | { |
1287 | if(HasOpenedContext()) |
1288 | return myLocalContexts(myCurLocalIndex)->DetectedInteractive(); |
1289 | return myLastPicked; |
1290 | } |
1291 | |
1292 | |
1293 | Standard_Boolean AIS_InteractiveContext::HasNextDetected() const |
1294 | { |
1295 | if(!HasOpenedContext()) |
1296 | return Standard_False; // temporaire |
1297 | else |
1298 | return myLocalContexts(myCurLocalIndex)->HasNextDetected(); |
1299 | |
1300 | } |
1301 | |
1302 | |
1303 | //======================================================================= |
1304 | //function : DetectedOwner |
1305 | //purpose : |
1306 | //======================================================================= |
1307 | Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const |
1308 | { |
1309 | if(HasOpenedContext()) |
1310 | return myLocalContexts(myCurLocalIndex)->DetectedOwner(); |
1311 | Handle(SelectMgr_EntityOwner) Ownr; |
1312 | return Ownr; |
1313 | } |
1314 | |
1315 | |
1316 | //======================================================================= |
1317 | //function : HilightNextDetected |
1318 | //purpose : |
1319 | //======================================================================= |
1320 | Standard_Integer AIS_InteractiveContext::HilightNextDetected(const Handle(V3d_View)& V) |
1321 | { |
1322 | if(!HasOpenedContext()) |
1323 | return 0; |
1324 | return myLocalContexts(myCurLocalIndex)->HilightNextDetected(V); |
1325 | |
1326 | } |
1327 | |
1328 | //======================================================================= |
1329 | //function : HilightNextDetected |
1330 | //purpose : |
1331 | //======================================================================= |
1332 | Standard_Integer AIS_InteractiveContext::HilightPreviousDetected(const Handle(V3d_View)& V) |
1333 | { |
1334 | if(!HasOpenedContext()) |
1335 | return 0; |
1336 | return myLocalContexts(myCurLocalIndex)->HilightPreviousDetected(V); |
1337 | |
1338 | } |
1339 | |
1340 | #ifdef IMP150501 |
1341 | void AIS_InteractiveContext::Drag( |
1342 | const Handle(V3d_View)& aView, |
1343 | const Handle(AIS_InteractiveObject)& anObject, |
1344 | const Handle(Geom_Transformation)& aTrsf, |
1345 | const Standard_Boolean postConcatenate, |
1346 | const Standard_Boolean update, |
1347 | const Standard_Boolean zBuffer) { |
1348 | |
1349 | if( anObject.IsNull() || aView.IsNull() ) return; |
1350 | |
1351 | if( update ) { |
1352 | anObject->SetTransformation(aTrsf,postConcatenate,Standard_True); |
1353 | aView->Update(); |
1354 | } else if( Visual3d_TransientManager::BeginDraw(aView->View(), |
1355 | zBuffer,Standard_False) ) { |
1356 | Handle(Prs3d_Presentation) P = anObject->Presentation(); |
1357 | if( !P.IsNull() ) { |
1358 | if( postConcatenate ) P->Multiply(aTrsf); |
1359 | else P->Transform(aTrsf); |
1360 | Visual3d_TransientManager::DrawStructure(P); |
1361 | } |
1362 | Visual3d_TransientManager::EndDraw(Standard_True); |
1363 | } |
1364 | } |
1365 | #endif |
1366 | |
1367 | #ifdef IMP160701 |
1368 | //======================================================================= |
1369 | //function : InitDetected |
1370 | //purpose : |
1371 | //======================================================================= |
1372 | void AIS_InteractiveContext::InitDetected() |
1373 | { |
1374 | if(HasOpenedContext()) |
1375 | { |
1376 | myLocalContexts(myCurLocalIndex)->InitDetected(); |
1377 | return; |
1378 | } |
1379 | |
1380 | if(myAISDetectedSeq.Length() != 0) |
1381 | myAISCurDetected = 1; |
1382 | |
1383 | } |
1384 | |
1385 | //======================================================================= |
1386 | //function : MoreDetected |
1387 | //purpose : |
1388 | //======================================================================= |
1389 | Standard_Boolean AIS_InteractiveContext::MoreDetected() const |
1390 | { |
1391 | if(HasOpenedContext()) |
1392 | return myLocalContexts(myCurLocalIndex)->MoreDetected(); |
1393 | |
1394 | return (myAISCurDetected>0 &&myAISCurDetected <= myAISDetectedSeq.Length()) ? |
1395 | Standard_True : Standard_False; |
1396 | } |
1397 | |
1398 | //======================================================================= |
1399 | //function : NextDetected |
1400 | //purpose : |
1401 | //======================================================================= |
1402 | void AIS_InteractiveContext::NextDetected() |
1403 | { |
1404 | if(HasOpenedContext()) |
1405 | { |
1406 | myLocalContexts(myCurLocalIndex)->NextDetected(); |
1407 | return; |
1408 | } |
1409 | |
1410 | myAISCurDetected++; |
1411 | } |
1412 | |
1413 | //======================================================================= |
1414 | //function : DetectedCurrentShape |
1415 | //purpose : |
1416 | //======================================================================= |
1417 | |
1418 | const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const |
1419 | { |
1420 | if(HasOpenedContext()) |
1421 | return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape(); |
1422 | |
1423 | static TopoDS_Shape bidsh; |
1424 | if(myAISCurDetected > 0 && |
1425 | myAISCurDetected <= myAISDetectedSeq.Length()) |
1426 | return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape(); |
1427 | return bidsh; |
1428 | } |
1429 | |
1430 | //======================================================================= |
1431 | //function : DetectedCurrentObject |
1432 | //purpose : |
1433 | //======================================================================= |
1434 | |
1435 | Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const { |
1436 | if(HasOpenedContext()) |
1437 | return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject(); |
1438 | |
1439 | Handle(AIS_InteractiveObject) aBad; |
1440 | |
1441 | if(myAISCurDetected > 0 && |
1442 | myAISCurDetected <= myAISDetectedSeq.Length()) |
1443 | return myAISDetectedSeq(myAISCurDetected); |
1444 | else |
1445 | return aBad; |
1446 | } |
1447 | #endif |