0024483: Visualization - drop unused class StdSelect_BRepHilighter
[occt.git] / src / StdSelect / StdSelect_BRepHilighter.cxx
1 // Created on: 1995-03-22
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <StdSelect_BRepHilighter.ixx>
18 #include <StdSelect_BRepOwner.hxx>
19 #include <StdSelect_Prs.hxx>
20 #include <Graphic3d_StructureManager.hxx>
21 #include <Graphic3d_Structure.hxx>
22 #include <Aspect_TypeOfMarker.hxx>
23 #include <Prs3d_PointAspect.hxx>
24 #include <V3d_Viewer.hxx>
25 #include <V3d_View.hxx>
26 #include <Prs3d_Presentation.hxx>
27 #include <StdPrs_WFShape.hxx>
28 #include <OSD_Chronometer.hxx>
29 #include <Visual3d_TransientManager.hxx>
30 static TColStd_MapIteratorOfMapOfInteger it;
31 static Standard_Boolean ImmediateIsEnable;
32 static  Standard_Boolean ImmediateIsEnableIsDef= Standard_False;
33 //==================================================
34 // Function: 
35 // Purpose :
36 //==================================================
37
38 StdSelect_BRepHilighter::
39 StdSelect_BRepHilighter():mylastindex(0)
40 ,myManager(new Visual3d_TransientManager){}
41
42 //==================================================
43 // Function: 
44 // Purpose :
45 //==================================================
46
47 StdSelect_BRepHilighter::
48 StdSelect_BRepHilighter(const Handle(StdSelect_ViewerSelector3d)& aSelector,
49                         const Handle(V3d_Viewer)& aViewer,
50                         const Quantity_NameOfColor aColor,
51                         const StdSelect_TypeOfResult aTOR):
52 myselector(aSelector),
53 myviewer(aViewer),
54 mycolor(aColor),
55 mydrwr(new Prs3d_Drawer()),
56 mytype(aTOR),
57 mylastindex(0),
58 myManager(new Visual3d_TransientManager)
59
60 {
61   Handle(Prs3d_PointAspect) PA = new Prs3d_PointAspect(Aspect_TOM_O,Quantity_NOC_INDIANRED3,3.);
62   mydrwr->SetPointAspect(PA);
63 }
64 //==================================================
65 // Function: 
66 // Purpose :
67 //==================================================
68
69 void StdSelect_BRepHilighter::
70 Set(const Handle(StdSelect_ViewerSelector3d)& aSelector)
71 {myselector=aSelector;}
72 //==================================================
73 // Function: 
74 // Purpose :
75 //==================================================
76
77 void StdSelect_BRepHilighter::
78 Set(const StdSelect_TypeOfResult aTOR)
79 {mytype =aTOR;}
80
81 //==================================================
82 // Function: Set
83 // Purpose :
84 //==================================================
85
86 void StdSelect_BRepHilighter::
87 Set(const Handle(V3d_Viewer)& aViewer)
88 {myviewer=aViewer;}
89 //==================================================
90 // Function: 
91 // Purpose :
92 //==================================================
93
94 void StdSelect_BRepHilighter::
95 Set(const Quantity_NameOfColor aColor)
96 {mycolor=aColor;} 
97 //==================================================
98 // Function: 
99 // Purpose :
100 //==================================================
101 void StdSelect_BRepHilighter::
102 Process()
103 {
104   Update();
105   myviewer->Update();
106 }
107 //==================================================
108 // Function: 
109 // Purpose :
110 //==================================================
111 void StdSelect_BRepHilighter::
112 Process(const Handle(V3d_View)& aViou,const Standard_Boolean DoubleBuffer)
113 {
114   if(aViou->Viewer() == myviewer){
115     Update(aViou,DoubleBuffer);
116 //    aViou->Update();
117   }
118 }
119
120 //==================================================
121 // Function: 
122 // Purpose :
123 //==================================================
124
125 void StdSelect_BRepHilighter::
126 Update()
127 {
128   myselector->Init();
129   
130   switch(mytype){
131   case StdSelect_TOR_MULTIPLE:{
132     TColStd_MapIteratorOfMapOfInteger aIt;
133     if(!myselector->More())
134       {
135         for(aIt.Initialize(myold);aIt.More();aIt.Next())
136           {myhimap.FindFromIndex(aIt.Key())->UnHighlight();
137            myhimap.FindFromIndex(aIt.Key())->SetVisible(Standard_False);
138          }
139         myold.Clear();
140         mynew.Clear();
141       }
142     else{
143
144       for (;myselector->More();myselector->Next())
145         {
146           const Handle(SelectBasics_EntityOwner)& OO = myselector->Picked();
147           if (!myhimap.Contains(OO))
148             {
149               if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
150                 Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs
151                   (myviewer->Viewer());
152                 
153                 StdPrs_WFShape::Add(NiouPrs,
154                                     Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),
155                                     mydrwr);
156                 NiouPrs->Display();
157                 myhimap.Add(OO,NiouPrs);
158               mynew.Add(myhimap.FindIndex(OO));
159               if(myold.Contains(myhimap.FindIndex(OO))) 
160                 myold.Remove(myhimap.FindIndex(OO));
161               }
162             }
163         }
164       for(aIt.Initialize(myold);aIt.More();aIt.Next()){
165         myhimap.FindFromIndex(aIt.Key())->UnHighlight();
166         myhimap.FindFromIndex(aIt.Key())->SetVisible(Standard_False);
167       }
168       
169       myold = mynew;
170       mynew.Clear();
171       for(aIt.Initialize(myold);aIt.More();aIt.Next()){
172         myhimap.FindFromIndex(aIt.Key())->SetVisible(Standard_True);
173         myhimap.FindFromIndex(aIt.Key())->SetDisplayPriority(10);
174         myhimap.FindFromIndex(aIt.Key())->Color(mycolor);
175       }
176     }
177     break;
178   }
179     
180   case StdSelect_TOR_SIMPLE:
181     {
182       if(myselector->More()){
183         const Handle(SelectBasics_EntityOwner)& OO = myselector->OnePicked();    
184         if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
185           if (!myhimap.Contains(OO)){    
186             Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs
187               (myviewer->Viewer());
188             StdPrs_WFShape::Add(NiouPrs,
189                                 Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),
190                                 mydrwr);
191             NiouPrs->Display();
192             myhimap.Add(OO,NiouPrs);
193           } 
194         }
195         if(mylastindex!=myhimap.FindIndex(OO))
196           {
197             if(mylastindex!=0) 
198               {
199                 myhimap.FindFromIndex(mylastindex)->UnHighlight();
200                 myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_False);
201               }
202             mylastindex = myhimap.FindIndex(OO);
203             myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_True);
204             myhimap.FindFromIndex(mylastindex)->SetDisplayPriority(10);
205             myhimap.FindFromIndex(mylastindex)->Color(mycolor);
206           }
207       }
208       else {   
209         if(mylastindex!=0) 
210               {
211                 myhimap.FindFromIndex(mylastindex)->UnHighlight();
212                 myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_False);
213                 mylastindex=0;
214               }
215         for (it.Initialize(myold);it.More();it.Next()){
216           myhimap.FindFromIndex(it.Key())->UnHighlight();
217           myhimap.FindFromIndex(it.Key())->SetVisible(Standard_False);}
218         myold.Clear();
219       }
220     }
221   }
222 }
223
224 void StdSelect_BRepHilighter::
225 Update(const Handle(V3d_View)& aView,const Standard_Boolean DoubleBuffer)
226 {
227   if(!ImmediateIsEnableIsDef) {
228     ImmediateIsEnable = aView->TransientManagerBeginDraw();
229     ImmediateIsEnableIsDef = Standard_True;
230     Visual3d_TransientManager::EndDraw();
231   }
232   if(!ImmediateIsEnable) {
233     Update();
234   }
235   else {
236     myselector->Init();
237     mynew.Clear();
238   
239     switch(mytype){
240     case StdSelect_TOR_MULTIPLE:{
241       
242       for (;myselector->More();myselector->Next()) {
243         const Handle(SelectBasics_EntityOwner)& OO = myselector->Picked();
244         if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
245           if (!myhimap.Contains(OO)) {
246             Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs(myviewer->Viewer());
247             
248             StdPrs_WFShape::Add(NiouPrs,Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),mydrwr);
249             NiouPrs->Color(mycolor);
250             myhimap.Add(OO,NiouPrs);
251           }
252           mynew.Add(myhimap.FindIndex(OO));
253         }
254       }
255       break;
256     }
257       
258     case StdSelect_TOR_SIMPLE: {
259       
260       if(myselector->More()){
261         const Handle(SelectBasics_EntityOwner)& OO = myselector->OnePicked();    
262         if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
263           if (!myhimap.Contains(OO)){    
264             Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs(myviewer->Viewer());
265             StdPrs_WFShape::Add(NiouPrs,Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),mydrwr);
266             NiouPrs->Color(mycolor);
267             myhimap.Add(OO,NiouPrs);
268           }
269           mynew.Add(myhimap.FindIndex(OO));
270         }
271       }
272     }
273       break;
274     } 
275     Standard_Boolean First = Standard_True; // to avoid begindraw if there is nothing (expensive)
276     
277     for(it.Initialize(mynew);it.More();it.Next()){
278       
279       if(First) {
280         aView->TransientManagerBeginDraw(DoubleBuffer);
281         First = Standard_False;
282       }
283       
284       Visual3d_TransientManager::DrawStructure(myhimap.FindFromIndex(it.Key()));
285     }
286     
287     if(!First) 
288       Visual3d_TransientManager::EndDraw();
289   }
290 }
291
292 void StdSelect_BRepHilighter::Clear()
293 {
294   if(!myhimap.IsEmpty()){
295     for (Standard_Integer i=1;i<=myhimap.Extent();i++){
296       myhimap.FindFromIndex(i)->UnHighlight();
297       myhimap.FindFromIndex(i)->Erase();
298       myhimap.FindFromIndex(i)->Clear();
299     }
300     myold.Clear();
301     mynew.Clear();
302     mylastindex=0;   
303   }
304   myhimap.Clear();
305 }
306
307 const Handle(Prs3d_Drawer)& StdSelect_BRepHilighter::Drawer() const 
308 {
309   return mydrwr;
310 }
311