1 // Created on: 1995-03-08
2 // Created by: Mister rmi
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 under
9 // the terms of the GNU Lesser General Public License 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.
18 #include <Graphic3d_StructureManager.hxx>
19 #include <Prs3d_Drawer.hxx>
20 #include <PrsMgr_PresentationManager.hxx>
21 #include <SelectBasics_EntityOwner.hxx>
22 #include <SelectMgr_SelectableObject.hxx>
23 #include <Standard_Type.hxx>
24 #include <StdSelect_BRepOwner.hxx>
25 #include <StdSelect_Shape.hxx>
26 #include <TopLoc_Location.hxx>
27 #include <TopoDS_Shape.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(StdSelect_BRepOwner,SelectMgr_EntityOwner)
31 //==================================================
34 //==================================================
35 StdSelect_BRepOwner::StdSelect_BRepOwner(const Standard_Integer aPriority):
36 SelectMgr_EntityOwner(aPriority),
37 myFromDecomposition(Standard_False),
42 StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape,
43 const Standard_Integer aPriority,
44 const Standard_Boolean ComesFromDecomposition):
45 SelectMgr_EntityOwner(aPriority),
46 myFromDecomposition(ComesFromDecomposition),
52 StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape,
53 const Handle (SelectMgr_SelectableObject)& theOrigin,
54 const Standard_Integer aPriority,
55 const Standard_Boolean ComesFromDecomposition):
56 SelectMgr_EntityOwner(theOrigin,aPriority),
57 myFromDecomposition(ComesFromDecomposition),
63 //=======================================================================
64 //function : IsHilighted
66 //=======================================================================
67 Standard_Boolean StdSelect_BRepOwner::
68 IsHilighted(const Handle(PrsMgr_PresentationManager)& PM,
69 const Standard_Integer aMode) const
71 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
73 return PM->IsHighlighted(Selectable(),M);
74 return PM->IsHighlighted(myPrsSh,M);
77 //=======================================================================
78 //function : Hilight/Unhilight Methods...
80 //=======================================================================
81 void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM,
82 const Standard_Integer aMode)
85 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
86 Handle(SelectMgr_SelectableObject) aSel = Selectable();
87 if (myFromDecomposition)
89 // do the update flag check
90 if (!myPrsSh.IsNull())
92 TColStd_ListOfInteger aModesList;
93 myPrsSh->ToBeUpdated (aModesList);
94 if (!aModesList.IsEmpty())
98 Handle(Prs3d_Drawer) aDrawer;
101 aDrawer = aSel->HilightAttributes();
105 aDrawer = new Prs3d_Drawer();
106 SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer);
109 // generate new presentable shape
110 if (myPrsSh.IsNull())
112 myPrsSh = new StdSelect_Shape (myShape, aDrawer);
116 myPrsSh->SetZLayer (aSel->ZLayer());
119 // highlight and set layer
120 PM->Highlight (myPrsSh, M);
125 PM->Highlight(aSel,M);
127 PM->Highlight(myPrsSh,M);
131 void StdSelect_BRepOwner::Hilight()
134 void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManager3d)& PM,
135 const Quantity_NameOfColor aCol,
136 const Standard_Integer aMode)
138 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
139 Graphic3d_ZLayerId aHiLayer = this == Selectable()->GlobalSelOwner().get() ?
140 Graphic3d_ZLayerId_Top : Graphic3d_ZLayerId_Topmost;
141 Handle(SelectMgr_SelectableObject) aSel = Selectable();
142 if (myFromDecomposition)
144 // do the update flag check
145 if (!myPrsSh.IsNull())
147 TColStd_ListOfInteger aModesList;
148 myPrsSh->ToBeUpdated (aModesList);
149 if (!aModesList.IsEmpty())
153 Handle(Prs3d_Drawer) aDrawer;
156 aDrawer = aSel->HilightAttributes();
160 aDrawer = new Prs3d_Drawer();
161 SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer);
164 // generate new presentable shape
169 TopLoc_Location lbid = Location() * myShape.Location();
170 TopoDS_Shape ShBis = myShape.Located(lbid);
171 myPrsSh = new StdSelect_Shape(ShBis, aDrawer);
174 myPrsSh = new StdSelect_Shape(myShape, aDrawer);
178 myPrsSh->SetZLayer (aSel->ZLayer());
181 // highlight with color and set layer
182 PM->Color (myPrsSh, aCol, M, aSel, aHiLayer);
186 if (!myPrsSh.IsNull())
188 PM->Color (myPrsSh, aCol, M, aSel, aHiLayer);
192 PM->Color (aSel, aCol, M, NULL, aHiLayer);
197 void StdSelect_BRepOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& PM,
198 const Standard_Integer aMode)
200 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
201 if(myPrsSh.IsNull() || !myFromDecomposition)
202 PM->Unhighlight(Selectable(),M);
204 PM->Unhighlight(myPrsSh,M);
207 void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM,
208 const Standard_Integer aMode)
210 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
211 if (!myPrsSh.IsNull())
212 PM->Clear(myPrsSh,M);
216 void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc)
218 SelectMgr_EntityOwner::SetLocation(aLoc);
219 // we must not nullify the myPrsSh here, because unhilight method
220 // will be working with wrong entity in this case, the best is to
221 // set the update flag and then recompute myPrsSh on hilighting
222 if (!myPrsSh.IsNull())
223 myPrsSh->SetToUpdate();
226 void StdSelect_BRepOwner::ResetLocation()
228 SelectMgr_EntityOwner::ResetLocation();
229 // we must not nullify the myPrsSh here, because unhilight method
230 // will be working with wrong entity in this case, the best is to
231 // set the update flag and then recompute myPrsSh on hilighting
232 if (!myPrsSh.IsNull())
233 myPrsSh->SetToUpdate();
236 //=======================================================================
237 //function : SetZLayer
239 //=======================================================================
240 void StdSelect_BRepOwner::SetZLayer (const Graphic3d_ZLayerId theLayerId)
242 if (!myPrsSh.IsNull())
244 myPrsSh->SetZLayer (theLayerId);
248 //=======================================================================
249 //function : UpdateHighlightTrsf
251 //=======================================================================
252 void StdSelect_BRepOwner::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
253 const Handle(PrsMgr_PresentationManager3d)& theManager,
254 const Standard_Integer theDispMode)
256 if (myPrsSh.IsNull() && Selectable().IsNull())
259 theManager->UpdateHighlightTrsf (theViewer, Selectable(), theDispMode, myPrsSh);