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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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 //==================================================
36 //==================================================
38 StdSelect_BRepHilighter::
39 StdSelect_BRepHilighter():mylastindex(0)
40 ,myManager(new Visual3d_TransientManager){}
42 //==================================================
45 //==================================================
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),
55 mydrwr(new Prs3d_Drawer()),
58 myManager(new Visual3d_TransientManager)
61 Handle(Prs3d_PointAspect) PA = new Prs3d_PointAspect(Aspect_TOM_O,Quantity_NOC_INDIANRED3,3.);
62 mydrwr->SetPointAspect(PA);
64 //==================================================
67 //==================================================
69 void StdSelect_BRepHilighter::
70 Set(const Handle(StdSelect_ViewerSelector3d)& aSelector)
71 {myselector=aSelector;}
72 //==================================================
75 //==================================================
77 void StdSelect_BRepHilighter::
78 Set(const StdSelect_TypeOfResult aTOR)
81 //==================================================
84 //==================================================
86 void StdSelect_BRepHilighter::
87 Set(const Handle(V3d_Viewer)& aViewer)
89 //==================================================
92 //==================================================
94 void StdSelect_BRepHilighter::
95 Set(const Quantity_NameOfColor aColor)
97 //==================================================
100 //==================================================
101 void StdSelect_BRepHilighter::
107 //==================================================
110 //==================================================
111 void StdSelect_BRepHilighter::
112 Process(const Handle(V3d_View)& aViou,const Standard_Boolean DoubleBuffer)
114 if(aViou->Viewer() == myviewer){
115 Update(aViou,DoubleBuffer);
120 //==================================================
123 //==================================================
125 void StdSelect_BRepHilighter::
131 case StdSelect_TOR_MULTIPLE:{
132 TColStd_MapIteratorOfMapOfInteger aIt;
133 if(!myselector->More())
135 for(aIt.Initialize(myold);aIt.More();aIt.Next())
136 {myhimap.FindFromIndex(aIt.Key())->UnHighlight();
137 myhimap.FindFromIndex(aIt.Key())->SetVisible(Standard_False);
144 for (;myselector->More();myselector->Next())
146 const Handle(SelectBasics_EntityOwner)& OO = myselector->Picked();
147 if (!myhimap.Contains(OO))
149 if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
150 Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs
151 (myviewer->Viewer());
153 StdPrs_WFShape::Add(NiouPrs,
154 Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),
157 myhimap.Add(OO,NiouPrs);
158 mynew.Add(myhimap.FindIndex(OO));
159 if(myold.Contains(myhimap.FindIndex(OO)))
160 myold.Remove(myhimap.FindIndex(OO));
164 for(aIt.Initialize(myold);aIt.More();aIt.Next()){
165 myhimap.FindFromIndex(aIt.Key())->UnHighlight();
166 myhimap.FindFromIndex(aIt.Key())->SetVisible(Standard_False);
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);
180 case StdSelect_TOR_SIMPLE:
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(),
192 myhimap.Add(OO,NiouPrs);
195 if(mylastindex!=myhimap.FindIndex(OO))
199 myhimap.FindFromIndex(mylastindex)->UnHighlight();
200 myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_False);
202 mylastindex = myhimap.FindIndex(OO);
203 myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_True);
204 myhimap.FindFromIndex(mylastindex)->SetDisplayPriority(10);
205 myhimap.FindFromIndex(mylastindex)->Color(mycolor);
211 myhimap.FindFromIndex(mylastindex)->UnHighlight();
212 myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_False);
215 for (it.Initialize(myold);it.More();it.Next()){
216 myhimap.FindFromIndex(it.Key())->UnHighlight();
217 myhimap.FindFromIndex(it.Key())->SetVisible(Standard_False);}
224 void StdSelect_BRepHilighter::
225 Update(const Handle(V3d_View)& aView,const Standard_Boolean DoubleBuffer)
227 if(!ImmediateIsEnableIsDef) {
228 ImmediateIsEnable = aView->TransientManagerBeginDraw();
229 ImmediateIsEnableIsDef = Standard_True;
230 Visual3d_TransientManager::EndDraw();
232 if(!ImmediateIsEnable) {
240 case StdSelect_TOR_MULTIPLE:{
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());
248 StdPrs_WFShape::Add(NiouPrs,Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),mydrwr);
249 NiouPrs->Color(mycolor);
250 myhimap.Add(OO,NiouPrs);
252 mynew.Add(myhimap.FindIndex(OO));
258 case StdSelect_TOR_SIMPLE: {
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);
269 mynew.Add(myhimap.FindIndex(OO));
275 Standard_Boolean First = Standard_True; // to avoid begindraw if there is nothing (expensive)
277 for(it.Initialize(mynew);it.More();it.Next()){
280 aView->TransientManagerBeginDraw(DoubleBuffer);
281 First = Standard_False;
284 Visual3d_TransientManager::DrawStructure(myhimap.FindFromIndex(it.Key()));
288 Visual3d_TransientManager::EndDraw();
292 void StdSelect_BRepHilighter::Clear()
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();
307 const Handle(Prs3d_Drawer)& StdSelect_BRepHilighter::Drawer() const