0030687: Visualization - remove redundant interfaces SelectBasics_EntityOwner and...
[occt.git] / src / StdSelect / StdSelect_BRepOwner.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <StdSelect_BRepOwner.hxx>
18
19 #include <Graphic3d_StructureManager.hxx>
20 #include <Prs3d_Drawer.hxx>
21 #include <PrsMgr_PresentationManager.hxx>
22 #include <SelectMgr_EntityOwner.hxx>
23 #include <SelectMgr_SelectableObject.hxx>
24 #include <Standard_Type.hxx>
25 #include <StdSelect_Shape.hxx>
26 #include <TopLoc_Location.hxx>
27 #include <TopoDS_Shape.hxx>
28
29 IMPLEMENT_STANDARD_RTTIEXT(StdSelect_BRepOwner,SelectMgr_EntityOwner)
30
31 //==================================================
32 // Function: StdSelect_BRepOwner
33 // Purpose :
34 //==================================================
35 StdSelect_BRepOwner::StdSelect_BRepOwner (const Standard_Integer thePriority)
36 : SelectMgr_EntityOwner (thePriority),
37   myCurMode (0)
38 {
39   //
40 }
41
42 //==================================================
43 // Function: StdSelect_BRepOwner
44 // Purpose :
45 //==================================================
46 StdSelect_BRepOwner::StdSelect_BRepOwner (const TopoDS_Shape& theShape,
47                                           const Standard_Integer thePriority,
48                                           const Standard_Boolean theComesFromDecomposition)
49 : SelectMgr_EntityOwner (thePriority),
50   myShape (theShape),
51   myCurMode (0)
52 {
53   myFromDecomposition = theComesFromDecomposition;
54 }
55
56 //==================================================
57 // Function: StdSelect_BRepOwner
58 // Purpose :
59 //==================================================
60 StdSelect_BRepOwner::StdSelect_BRepOwner (const TopoDS_Shape& theShape,
61                                           const Handle (SelectMgr_SelectableObject)& theOrigin,
62                                           const Standard_Integer thePriority,
63                                           const Standard_Boolean theComesFromDecomposition)
64 : SelectMgr_EntityOwner (theOrigin, thePriority),
65   myShape (theShape),
66   myCurMode (0)
67 {
68   myFromDecomposition = theComesFromDecomposition;
69 }
70
71 //=======================================================================
72 //function : IsHilighted
73 //purpose  : 
74 //=======================================================================
75 Standard_Boolean StdSelect_BRepOwner::
76 IsHilighted(const Handle(PrsMgr_PresentationManager)& PM,
77             const Standard_Integer aMode) const 
78 {
79   Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
80   if(myPrsSh.IsNull())
81     return PM->IsHighlighted(Selectable(),M);
82   return PM->IsHighlighted(myPrsSh,M);
83 }
84
85 //=======================================================================
86 //function : HilightWithColor
87 //purpose  :
88 //=======================================================================
89 void StdSelect_BRepOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
90                                             const Handle(Prs3d_Drawer)&                 theStyle,
91                                             const Standard_Integer                      theMode)
92 {
93   if (!HasSelectable())
94   {
95     return;
96   }
97
98   const Standard_Integer aDispMode = (theMode < 0) ? myCurMode : theMode;
99   Handle(SelectMgr_SelectableObject) aSel = Selectable();
100   const Graphic3d_ZLayerId aHiLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : aSel->ZLayer();
101   if (!myFromDecomposition)
102   {
103     thePM->Color (aSel, theStyle, aDispMode, NULL, aHiLayer);
104     return;
105   }
106
107   // do the update flag check
108   if (!myPrsSh.IsNull()
109    && myPrsSh->ToBeUpdated (true))
110   {
111     myPrsSh.Nullify();
112   }
113
114   // generate new presentable shape
115   if (myPrsSh.IsNull())
116   {
117     if (HasLocation())
118     {
119       TopLoc_Location lbid = Location() * myShape.Location();
120       TopoDS_Shape ShBis = myShape.Located(lbid);
121       myPrsSh = new StdSelect_Shape (ShBis, theStyle);
122     }
123     else
124     {
125       myPrsSh = new StdSelect_Shape (myShape, theStyle);
126     }
127   }
128
129   // initialize presentation attributes of child presentation
130   myPrsSh->SetZLayer               (aSel->ZLayer());
131   myPrsSh->SetTransformPersistence (aSel->TransformPersistence());
132   myPrsSh->Attributes()->SetLink                (theStyle);
133   myPrsSh->Attributes()->SetColor               (theStyle->Color());
134   myPrsSh->Attributes()->SetTransparency        (theStyle->Transparency());
135   myPrsSh->Attributes()->SetBasicFillAreaAspect (theStyle->BasicFillAreaAspect());
136
137   // highlight with color and set layer
138   thePM->Color (myPrsSh, theStyle, aDispMode, aSel, aHiLayer);
139 }
140
141 void StdSelect_BRepOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr, const Standard_Integer )
142 {
143   if (myPrsSh.IsNull() || !myFromDecomposition)
144   {
145     thePrsMgr->Unhighlight (Selectable());
146   }
147   else
148   {
149     thePrsMgr->Unhighlight (myPrsSh);
150   }
151 }
152
153 void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM,
154                                 const Standard_Integer aMode)
155 {
156   Standard_Integer M = (aMode < 0) ? myCurMode : aMode;
157   if (!myPrsSh.IsNull())
158     PM->Clear(myPrsSh,M);
159   myPrsSh.Nullify();
160 }
161
162 void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc)
163 {
164   SelectMgr_EntityOwner::SetLocation(aLoc);
165   // we must not nullify the myPrsSh here, because unhilight method
166   // will be working with wrong entity in this case, the best is to
167   // set the update flag and then recompute myPrsSh on hilighting
168   if (!myPrsSh.IsNull())
169     myPrsSh->SetToUpdate();
170 }
171
172 //=======================================================================
173 //function : UpdateHighlightTrsf
174 //purpose  :
175 //=======================================================================
176 void StdSelect_BRepOwner::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer,
177                                                const Handle(PrsMgr_PresentationManager3d)& theManager,
178                                                const Standard_Integer theDispMode)
179 {
180   if (myPrsSh.IsNull() && Selectable().IsNull())
181     return;
182
183   theManager->UpdateHighlightTrsf (theViewer, Selectable(), theDispMode, myPrsSh);
184 }