1 // Created on: 1995-03-22
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
24 #include <StdSelect_BRepHilighter.ixx>
25 #include <StdSelect_BRepOwner.hxx>
26 #include <StdSelect_Prs.hxx>
27 #include <Graphic3d_StructureManager.hxx>
28 #include <Graphic3d_Structure.hxx>
29 #include <Aspect_TypeOfMarker.hxx>
30 #include <Prs3d_PointAspect.hxx>
31 #include <V3d_Viewer.hxx>
32 #include <V3d_View.hxx>
33 #include <Prs3d_Presentation.hxx>
34 #include <StdPrs_WFShape.hxx>
35 #include <OSD_Chronometer.hxx>
36 #include <Visual3d_TransientManager.hxx>
37 static TColStd_MapIteratorOfMapOfInteger it;
38 static Standard_Boolean ImmediateIsEnable;
39 static Standard_Boolean ImmediateIsEnableIsDef= Standard_False;
40 //==================================================
43 //==================================================
45 StdSelect_BRepHilighter::
46 StdSelect_BRepHilighter():mylastindex(0)
47 ,myManager(new Visual3d_TransientManager){}
49 //==================================================
52 //==================================================
54 StdSelect_BRepHilighter::
55 StdSelect_BRepHilighter(const Handle(StdSelect_ViewerSelector3d)& aSelector,
56 const Handle(V3d_Viewer)& aViewer,
57 const Quantity_NameOfColor aColor,
58 const StdSelect_TypeOfResult aTOR):
59 myselector(aSelector),
62 mydrwr(new Prs3d_Drawer()),
65 myManager(new Visual3d_TransientManager)
68 Handle(Prs3d_PointAspect) PA = new Prs3d_PointAspect(Aspect_TOM_O,Quantity_NOC_INDIANRED3,3.);
69 mydrwr->SetPointAspect(PA);
71 //==================================================
74 //==================================================
76 void StdSelect_BRepHilighter::
77 Set(const Handle(StdSelect_ViewerSelector3d)& aSelector)
78 {myselector=aSelector;}
79 //==================================================
82 //==================================================
84 void StdSelect_BRepHilighter::
85 Set(const StdSelect_TypeOfResult aTOR)
88 //==================================================
91 //==================================================
93 void StdSelect_BRepHilighter::
94 Set(const Handle(V3d_Viewer)& aViewer)
96 //==================================================
99 //==================================================
101 void StdSelect_BRepHilighter::
102 Set(const Quantity_NameOfColor aColor)
104 //==================================================
107 //==================================================
108 void StdSelect_BRepHilighter::
114 //==================================================
117 //==================================================
118 void StdSelect_BRepHilighter::
119 Process(const Handle(V3d_View)& aViou,const Standard_Boolean DoubleBuffer)
121 if(aViou->Viewer() == myviewer){
122 Update(aViou,DoubleBuffer);
127 //==================================================
130 //==================================================
132 void StdSelect_BRepHilighter::
138 case StdSelect_TOR_MULTIPLE:{
139 TColStd_MapIteratorOfMapOfInteger it;
140 if(!myselector->More())
142 for(it.Initialize(myold);it.More();it.Next())
143 {myhimap.FindFromIndex(it.Key())->UnHighlight();
144 myhimap.FindFromIndex(it.Key())->SetVisible(Standard_False);
151 for (;myselector->More();myselector->Next())
153 const Handle(SelectBasics_EntityOwner)& OO = myselector->Picked();
154 if (!myhimap.Contains(OO))
156 if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
157 Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs
158 (myviewer->Viewer());
160 StdPrs_WFShape::Add(NiouPrs,
161 Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),
164 myhimap.Add(OO,NiouPrs);
165 mynew.Add(myhimap.FindIndex(OO));
166 if(myold.Contains(myhimap.FindIndex(OO)))
167 myold.Remove(myhimap.FindIndex(OO));
171 for(it.Initialize(myold);it.More();it.Next()){
172 myhimap.FindFromIndex(it.Key())->UnHighlight();
173 myhimap.FindFromIndex(it.Key())->SetVisible(Standard_False);
178 for(it.Initialize(myold);it.More();it.Next()){
179 myhimap.FindFromIndex(it.Key())->SetVisible(Standard_True);
180 myhimap.FindFromIndex(it.Key())->SetDisplayPriority(10);
181 myhimap.FindFromIndex(it.Key())->Color(mycolor);
187 case StdSelect_TOR_SIMPLE:
189 if(myselector->More()){
190 const Handle(SelectBasics_EntityOwner)& OO = myselector->OnePicked();
191 if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
192 if (!myhimap.Contains(OO)){
193 Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs
194 (myviewer->Viewer());
195 StdPrs_WFShape::Add(NiouPrs,
196 Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),
199 myhimap.Add(OO,NiouPrs);
202 if(mylastindex!=myhimap.FindIndex(OO))
206 myhimap.FindFromIndex(mylastindex)->UnHighlight();
207 myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_False);
209 mylastindex = myhimap.FindIndex(OO);
210 myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_True);
211 myhimap.FindFromIndex(mylastindex)->SetDisplayPriority(10);
212 myhimap.FindFromIndex(mylastindex)->Color(mycolor);
218 myhimap.FindFromIndex(mylastindex)->UnHighlight();
219 myhimap.FindFromIndex(mylastindex)->SetVisible(Standard_False);
222 for (it.Initialize(myold);it.More();it.Next()){
223 myhimap.FindFromIndex(it.Key())->UnHighlight();
224 myhimap.FindFromIndex(it.Key())->SetVisible(Standard_False);}
231 void StdSelect_BRepHilighter::
232 Update(const Handle(V3d_View)& aView,const Standard_Boolean DoubleBuffer)
234 if(!ImmediateIsEnableIsDef) {
235 ImmediateIsEnable = aView->TransientManagerBeginDraw();
236 ImmediateIsEnableIsDef = Standard_True;
237 Visual3d_TransientManager::EndDraw();
239 if(!ImmediateIsEnable) {
247 case StdSelect_TOR_MULTIPLE:{
249 for (;myselector->More();myselector->Next()) {
250 const Handle(SelectBasics_EntityOwner)& OO = myselector->Picked();
251 if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
252 if (!myhimap.Contains(OO)) {
253 Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs(myviewer->Viewer());
255 StdPrs_WFShape::Add(NiouPrs,Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),mydrwr);
256 NiouPrs->Color(mycolor);
257 myhimap.Add(OO,NiouPrs);
259 mynew.Add(myhimap.FindIndex(OO));
265 case StdSelect_TOR_SIMPLE: {
267 if(myselector->More()){
268 const Handle(SelectBasics_EntityOwner)& OO = myselector->OnePicked();
269 if(!Handle(StdSelect_BRepOwner)::DownCast(OO).IsNull()){
270 if (!myhimap.Contains(OO)){
271 Handle(StdSelect_Prs) NiouPrs = new StdSelect_Prs(myviewer->Viewer());
272 StdPrs_WFShape::Add(NiouPrs,Handle(StdSelect_BRepOwner)::DownCast(OO)->Shape(),mydrwr);
273 NiouPrs->Color(mycolor);
274 myhimap.Add(OO,NiouPrs);
276 mynew.Add(myhimap.FindIndex(OO));
282 Standard_Boolean First = Standard_True; // to avoid begindraw if there is nothing (expensive)
284 for(it.Initialize(mynew);it.More();it.Next()){
287 aView->TransientManagerBeginDraw(DoubleBuffer);
288 First = Standard_False;
291 Visual3d_TransientManager::DrawStructure(myhimap.FindFromIndex(it.Key()));
295 Visual3d_TransientManager::EndDraw();
299 void StdSelect_BRepHilighter::Clear()
301 if(!myhimap.IsEmpty()){
302 for (Standard_Integer i=1;i<=myhimap.Extent();i++){
303 myhimap.FindFromIndex(i)->UnHighlight();
304 myhimap.FindFromIndex(i)->Erase();
305 myhimap.FindFromIndex(i)->Clear();
314 const Handle(Prs3d_Drawer)& StdSelect_BRepHilighter::Drawer() const