0027818: Visualization - provide an interface to define highlight presentation properties
[occt.git] / src / StdSelect / StdSelect_BRepOwner.cxx
CommitLineData
b311480e 1// Created on: 1995-03-08
2// Created by: Mister rmi
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
18#include <Graphic3d_StructureManager.hxx>
7f917335 19#include <Prs3d_Drawer.hxx>
42cf5bc1 20#include <PrsMgr_PresentationManager.hxx>
7f917335 21#include <SelectBasics_EntityOwner.hxx>
42cf5bc1 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>
7fd59977 28
92efcf78 29IMPLEMENT_STANDARD_RTTIEXT(StdSelect_BRepOwner,SelectMgr_EntityOwner)
30
7fd59977 31//==================================================
32// Function:
33// Purpose :
34//==================================================
35StdSelect_BRepOwner::StdSelect_BRepOwner(const Standard_Integer aPriority):
36SelectMgr_EntityOwner(aPriority),
37myFromDecomposition(Standard_False),
38myCurMode(0)
39{
40}
41
42StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape,
43 const Standard_Integer aPriority,
44 const Standard_Boolean ComesFromDecomposition):
45SelectMgr_EntityOwner(aPriority),
46myFromDecomposition(ComesFromDecomposition),
47myShape(aShape),
48myCurMode(0)
49{
50}
51
52StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape,
53 const Handle (SelectMgr_SelectableObject)& theOrigin,
54 const Standard_Integer aPriority,
55 const Standard_Boolean ComesFromDecomposition):
56SelectMgr_EntityOwner(theOrigin,aPriority),
57myFromDecomposition(ComesFromDecomposition),
58myShape(aShape),
59myCurMode(0)
60{
61}
62
63//=======================================================================
64//function : IsHilighted
65//purpose :
66//=======================================================================
67Standard_Boolean StdSelect_BRepOwner::
68IsHilighted(const Handle(PrsMgr_PresentationManager)& PM,
69 const Standard_Integer aMode) const
70{
7fd59977 71 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
7fd59977 72 if(myPrsSh.IsNull())
73 return PM->IsHighlighted(Selectable(),M);
74 return PM->IsHighlighted(myPrsSh,M);
75}
76
77//=======================================================================
8e5fb5ea 78//function : HilightWithColor
79//purpose :
7fd59977 80//=======================================================================
8e5fb5ea 81void StdSelect_BRepOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
82 const Handle(Graphic3d_HighlightStyle)& theStyle,
83 const Standard_Integer theMode)
7fd59977 84{
8e5fb5ea 85 Standard_Integer M = (theMode < 0) ? myCurMode : theMode;
c3282ec1 86 Graphic3d_ZLayerId aHiLayer = this == Selectable()->GlobalSelOwner().get() ?
87 Graphic3d_ZLayerId_Top : Graphic3d_ZLayerId_Topmost;
a1954302 88 Handle(SelectMgr_SelectableObject) aSel = Selectable();
8e5fb5ea 89
29d43f9c
A
90 if (myFromDecomposition)
91 {
92 // do the update flag check
93 if (!myPrsSh.IsNull())
94 {
95 TColStd_ListOfInteger aModesList;
96 myPrsSh->ToBeUpdated (aModesList);
97 if (!aModesList.IsEmpty())
98 myPrsSh.Nullify();
99 }
100
7f917335 101 Handle(Prs3d_Drawer) aDrawer;
102 if (!aSel.IsNull())
103 {
104 aDrawer = aSel->HilightAttributes();
105 }
106 else
107 {
108 aDrawer = new Prs3d_Drawer();
109 SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer);
110 }
111
59f45b7c 112 // generate new presentable shape
113 if(myPrsSh.IsNull())
114 {
115 if(HasLocation())
116 {
117 TopLoc_Location lbid = Location() * myShape.Location();
118 TopoDS_Shape ShBis = myShape.Located(lbid);
7f917335 119 myPrsSh = new StdSelect_Shape(ShBis, aDrawer);
7fd59977 120 }
121 else
7f917335 122 myPrsSh = new StdSelect_Shape(myShape, aDrawer);
59f45b7c 123 }
59f45b7c 124 if (!aSel.IsNull())
125 {
a1954302 126 myPrsSh->SetZLayer (aSel->ZLayer());
778cd667 127 myPrsSh->SetTransformPersistence (aSel->TransformPersistence());
7fd59977 128 }
a1954302 129
130 // highlight with color and set layer
8e5fb5ea 131 thePM->Color (myPrsSh, theStyle, M, aSel, aHiLayer);
7fd59977 132 }
7fd59977 133 else
59f45b7c 134 {
a272ed94 135 if (!myPrsSh.IsNull())
136 {
8e5fb5ea 137 thePM->Color (myPrsSh, theStyle, M, aSel, aHiLayer);
a272ed94 138 }
59f45b7c 139 else
a272ed94 140 {
8e5fb5ea 141 thePM->Color (aSel, theStyle, M, NULL, aHiLayer);
a272ed94 142 }
59f45b7c 143 }
7fd59977 144}
145
146void StdSelect_BRepOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& PM,
147 const Standard_Integer aMode)
148{
7fd59977 149 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
7fd59977 150 if(myPrsSh.IsNull() || !myFromDecomposition)
151 PM->Unhighlight(Selectable(),M);
152 else
153 PM->Unhighlight(myPrsSh,M);
154}
155
156void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM,
157 const Standard_Integer aMode)
158{
7fd59977 159 Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
6153bb63 160 if (!myPrsSh.IsNull())
7fd59977 161 PM->Clear(myPrsSh,M);
162 myPrsSh.Nullify();
163}
164
165void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc)
166{
167 SelectMgr_EntityOwner::SetLocation(aLoc);
29d43f9c
A
168 // we must not nullify the myPrsSh here, because unhilight method
169 // will be working with wrong entity in this case, the best is to
170 // set the update flag and then recompute myPrsSh on hilighting
171 if (!myPrsSh.IsNull())
172 myPrsSh->SetToUpdate();
7fd59977 173}
59f45b7c 174
7fd59977 175void StdSelect_BRepOwner::ResetLocation()
176{
177 SelectMgr_EntityOwner::ResetLocation();
29d43f9c
A
178 // we must not nullify the myPrsSh here, because unhilight method
179 // will be working with wrong entity in this case, the best is to
180 // set the update flag and then recompute myPrsSh on hilighting
181 if (!myPrsSh.IsNull())
182 myPrsSh->SetToUpdate();
59f45b7c 183}
29d43f9c 184
59f45b7c 185//=======================================================================
186//function : SetZLayer
187//purpose :
188//=======================================================================
a1954302 189void StdSelect_BRepOwner::SetZLayer (const Graphic3d_ZLayerId theLayerId)
59f45b7c 190{
191 if (!myPrsSh.IsNull())
a1954302 192 {
193 myPrsSh->SetZLayer (theLayerId);
194 }
7fd59977 195}
5396886c 196
197//=======================================================================
198//function : UpdateHighlightTrsf
199//purpose :
200//=======================================================================
201void StdSelect_BRepOwner::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
202 const Handle(PrsMgr_PresentationManager3d)& theManager,
203 const Standard_Integer theDispMode)
204{
205 if (myPrsSh.IsNull() && Selectable().IsNull())
206 return;
207
208 theManager->UpdateHighlightTrsf (theViewer, Selectable(), theDispMode, myPrsSh);
209}