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 //==================================================
32 //==================================================
33 StdSelect_BRepOwner::StdSelect_BRepOwner(const Standard_Integer aPriority):
34 SelectMgr_EntityOwner(aPriority),
35 myFromDecomposition(Standard_False),
40 StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape,
41 const Standard_Integer aPriority,
42 const Standard_Boolean ComesFromDecomposition):
43 SelectMgr_EntityOwner(aPriority),
44 myFromDecomposition(ComesFromDecomposition),
50 StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape,
51 const Handle (SelectMgr_SelectableObject)& theOrigin,
52 const Standard_Integer aPriority,
53 const Standard_Boolean ComesFromDecomposition):
54 SelectMgr_EntityOwner(theOrigin,aPriority),
55 myFromDecomposition(ComesFromDecomposition),
61 //=======================================================================
62 //function : IsHilighted
64 //=======================================================================
65 Standard_Boolean StdSelect_BRepOwner::
66 IsHilighted(const Handle(PrsMgr_PresentationManager)& PM,
67 const Standard_Integer aMode) const
69 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
71 return PM->IsHighlighted(Selectable(),M);
72 return PM->IsHighlighted(myPrsSh,M);
75 //=======================================================================
76 //function : Hilight/Unhilight Methods...
78 //=======================================================================
79 void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM,
80 const Standard_Integer aMode)
83 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
84 Handle(SelectMgr_SelectableObject) aSel = Selectable();
85 if (myFromDecomposition)
87 // do the update flag check
88 if (!myPrsSh.IsNull())
90 TColStd_ListOfInteger aModesList;
91 myPrsSh->ToBeUpdated (aModesList);
92 if (!aModesList.IsEmpty())
96 Handle(Prs3d_Drawer) aDrawer;
99 aDrawer = aSel->HilightAttributes();
103 aDrawer = new Prs3d_Drawer();
104 SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer);
107 // generate new presentable shape
108 if (myPrsSh.IsNull())
110 myPrsSh = new StdSelect_Shape (myShape, aDrawer);
114 myPrsSh->SetZLayer (aSel->ZLayer());
117 // highlight and set layer
118 PM->Highlight (myPrsSh, M);
123 PM->Highlight(aSel,M);
125 PM->Highlight(myPrsSh,M);
129 void StdSelect_BRepOwner::Hilight()
132 void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManager3d)& PM,
133 const Quantity_NameOfColor aCol,
134 const Standard_Integer aMode)
136 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
137 Graphic3d_ZLayerId aHiLayer = this == Selectable()->GlobalSelOwner().get() ?
138 Graphic3d_ZLayerId_Top : Graphic3d_ZLayerId_Topmost;
139 Handle(SelectMgr_SelectableObject) aSel = Selectable();
140 if (myFromDecomposition)
142 // do the update flag check
143 if (!myPrsSh.IsNull())
145 TColStd_ListOfInteger aModesList;
146 myPrsSh->ToBeUpdated (aModesList);
147 if (!aModesList.IsEmpty())
151 Handle(Prs3d_Drawer) aDrawer;
154 aDrawer = aSel->HilightAttributes();
158 aDrawer = new Prs3d_Drawer();
159 SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer);
162 // generate new presentable shape
167 TopLoc_Location lbid = Location() * myShape.Location();
168 TopoDS_Shape ShBis = myShape.Located(lbid);
169 myPrsSh = new StdSelect_Shape(ShBis, aDrawer);
172 myPrsSh = new StdSelect_Shape(myShape, aDrawer);
176 myPrsSh->SetZLayer (aSel->ZLayer());
179 // highlight with color and set layer
180 PM->Color (myPrsSh, aCol, M, aSel, aHiLayer);
184 if (!myPrsSh.IsNull())
186 PM->Color (myPrsSh, aCol, M, aSel, aHiLayer);
190 PM->Color (aSel, aCol, M, NULL, aHiLayer);
195 void StdSelect_BRepOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& PM,
196 const Standard_Integer aMode)
198 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
199 if(myPrsSh.IsNull() || !myFromDecomposition)
200 PM->Unhighlight(Selectable(),M);
202 PM->Unhighlight(myPrsSh,M);
205 void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM,
206 const Standard_Integer aMode)
208 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
209 if (!myPrsSh.IsNull())
210 PM->Clear(myPrsSh,M);
214 void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc)
216 SelectMgr_EntityOwner::SetLocation(aLoc);
217 // we must not nullify the myPrsSh here, because unhilight method
218 // will be working with wrong entity in this case, the best is to
219 // set the update flag and then recompute myPrsSh on hilighting
220 if (!myPrsSh.IsNull())
221 myPrsSh->SetToUpdate();
224 void StdSelect_BRepOwner::ResetLocation()
226 SelectMgr_EntityOwner::ResetLocation();
227 // we must not nullify the myPrsSh here, because unhilight method
228 // will be working with wrong entity in this case, the best is to
229 // set the update flag and then recompute myPrsSh on hilighting
230 if (!myPrsSh.IsNull())
231 myPrsSh->SetToUpdate();
234 //=======================================================================
235 //function : SetZLayer
237 //=======================================================================
238 void StdSelect_BRepOwner::SetZLayer (const Graphic3d_ZLayerId theLayerId)
240 if (!myPrsSh.IsNull())
242 myPrsSh->SetZLayer (theLayerId);