Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / mfc / standard / 01_Geometry / src / ISession2D / ISession2D_InteractiveContext.cpp
1 #include "stdafx.h"
2
3 #include <ISession2D_InteractiveContext.h>
4
5 IMPLEMENT_STANDARD_HANDLE(ISession2D_InteractiveContext,MMgt_TShared)
6 IMPLEMENT_STANDARD_RTTIEXT(ISession2D_InteractiveContext,MMgt_TShared)
7
8 #include <Aspect_Window.hxx>
9 #include <Aspect_Background.hxx>
10 #include <SelectMgr_EntityOwner.hxx>
11 #include <SelectMgr_SelectionManager.hxx>
12 #include <V2d_Viewer.hxx>
13 #include <V2d_View.hxx>
14 #include <PrsMgr_PresentationManager2d.hxx>
15 #include <StdSelect_ViewerSelector2d.hxx>
16 #include <SelectMgr_SelectableObject.hxx>
17 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
18
19  ISession2D_InteractiveContext::ISession2D_InteractiveContext()
20 {
21 }
22
23  ISession2D_InteractiveContext::ISession2D_InteractiveContext(const Handle(V2d_Viewer)& aViewer)
24 {
25   Initialize(aViewer);
26 }
27
28 void ISession2D_InteractiveContext::Initialize(const Handle(V2d_Viewer)& aViewer) 
29 {
30   myViewer = aViewer;
31   myPrsmgr           = new PrsMgr_PresentationManager2d(myViewer->View());
32   mySelectionManager = new SelectMgr_SelectionManager();
33   mySelector         = new StdSelect_ViewerSelector2d();
34
35   mySelector->Set(3); 
36   // set Sensitivity very very important for SensitiveCurve !!
37   mySelector->SetSensitivity (0.5);   // en mm
38   mySelectionManager->Add(mySelector);
39
40 }
41
42 void ISession2D_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anObject,
43                                                        const Standard_Boolean Redraw) 
44 {
45    myMapOfObject.Add(anObject);
46    myPrsmgr->Display(anObject);//,anObject->DisplayMode()); 
47     
48    mySelectionManager->Load(anObject,mySelector);
49    mySelectionManager->Activate(anObject,0,mySelector);
50
51   if (Redraw) myViewer->Update();
52 }
53
54 void ISession2D_InteractiveContext::Erase(const Handle(AIS_InteractiveObject)& anObject,
55                                                  const Standard_Boolean Redraw) 
56 {
57   if (!anObject.IsNull())
58   {
59     myPrsmgr->Erase(anObject);//,anObject->DisplayMode());
60     mySelectionManager
61       ->Deactivate(anObject,mySelector);
62     if (Redraw) myViewer->Update();
63   }
64 }
65
66 void ISession2D_InteractiveContext::Move(const Handle(V2d_View)& aView,
67                                     const Standard_Integer x1,
68                                     const Standard_Integer y1) 
69 {
70   if (!aBuffer.IsNull())
71   {
72     aBuffer->UnPost(); 
73     aBuffer->Clear();
74   }
75
76   if (myViewer->IsActive())  // A propos de la grille !!!
77     {      
78       aView->ShowHit(x1,y1);
79     }
80
81   aBuffer =new Graphic2d_Buffer(aView->View(),0,0,3,5);
82   mySelector->Pick(x1,y1,aView);  
83   
84   Handle(SelectMgr_SelectableObject) aSelectableObject; 
85
86   mySelector->Init();
87
88   while (mySelector->More())
89   {
90       aSelectableObject = Handle(SelectMgr_SelectableObject)::DownCast(mySelector->Picked()->Selectable());
91
92       myPrsmgr->Dump(aBuffer,aSelectableObject) ;
93       aBuffer->Post();
94
95     mySelector->Next();
96   }
97 }
98
99 void ISession2D_InteractiveContext::Pick(const Handle(V2d_View)& aView,
100                                     const Standard_Integer x1,
101                                     const Standard_Integer y1) 
102 {
103
104   if (myViewer->IsActive())  // A propos de la grille !!!
105     {      
106       aView->ShowHit(x1,y1);
107     }
108
109   mySelector->Pick(x1,y1,aView);  
110  
111   Handle(SelectMgr_SelectableObject) aSelectableObject; 
112   mySelector->Init();
113   while (mySelector->More())
114   {      
115     Handle(SelectMgr_EntityOwner) aOwn= mySelector->Picked();
116     aSelectableObject = Handle(SelectMgr_SelectableObject)::DownCast(aOwn->Selectable());
117     myPrsmgr->ColorHighlight(aSelectableObject,5,0) ;
118     mySelector->Next();
119   }
120
121   if (myViewer->IsActive())  // A propos de la grille !!!
122     {
123       aView->ShowHit(x1,y1);
124     }
125 }
126
127
128 void ISession2D_InteractiveContext::DisplayAreas() 
129 {
130   myViewer->InitActiveViews();
131   while(myViewer->MoreActiveViews())
132     {
133       Handle(V2d_View)  aView  = myViewer->ActiveView();
134       mySelector->DisplayAreas(aView);    
135       myViewer->NextActiveViews();
136     }
137  myViewer->Update();
138 }
139
140 void ISession2D_InteractiveContext::ClearAreas() 
141 {
142    mySelector->ClearAreas();    
143    myViewer->Update();
144 }
145
146 void ISession2D_InteractiveContext::EraseAll()
147 {
148     TColStd_MapIteratorOfMapOfTransient anIterator(myMapOfObject);
149     for (;anIterator.More();anIterator.Next())
150     {
151         Handle(Standard_Transient) aTransient = anIterator.Key();
152         Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast(aTransient);
153
154         if (!anObject.IsNull())
155         {
156             myPrsmgr->Erase(anObject);
157             mySelectionManager
158             ->Deactivate(Handle(AIS_InteractiveObject)::DownCast(anObject),mySelector);
159         }
160         else
161         {
162             Standard_CString ObjectTypeName = aTransient->DynamicType()->Name();
163         }
164     }
165     myViewer->Update();
166 }