Commit | Line | Data |
---|---|---|
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 | #include <StdSelect_BRepOwner.ixx> |
7fd59977 | 18 | |
19 | #include <Graphic3d_StructureManager.hxx> | |
7f917335 | 20 | #include <Prs3d_Drawer.hxx> |
21 | #include <SelectBasics_EntityOwner.hxx> | |
7fd59977 | 22 | |
23 | //================================================== | |
24 | // Function: | |
25 | // Purpose : | |
26 | //================================================== | |
27 | StdSelect_BRepOwner::StdSelect_BRepOwner(const Standard_Integer aPriority): | |
28 | SelectMgr_EntityOwner(aPriority), | |
29 | myFromDecomposition(Standard_False), | |
30 | myCurMode(0) | |
31 | { | |
32 | } | |
33 | ||
34 | StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape, | |
35 | const Standard_Integer aPriority, | |
36 | const Standard_Boolean ComesFromDecomposition): | |
37 | SelectMgr_EntityOwner(aPriority), | |
38 | myFromDecomposition(ComesFromDecomposition), | |
39 | myShape(aShape), | |
40 | myCurMode(0) | |
41 | { | |
42 | } | |
43 | ||
44 | StdSelect_BRepOwner::StdSelect_BRepOwner(const TopoDS_Shape& aShape, | |
45 | const Handle (SelectMgr_SelectableObject)& theOrigin, | |
46 | const Standard_Integer aPriority, | |
47 | const Standard_Boolean ComesFromDecomposition): | |
48 | SelectMgr_EntityOwner(theOrigin,aPriority), | |
49 | myFromDecomposition(ComesFromDecomposition), | |
50 | myShape(aShape), | |
51 | myCurMode(0) | |
52 | { | |
53 | } | |
54 | ||
55 | //======================================================================= | |
56 | //function : IsHilighted | |
57 | //purpose : | |
58 | //======================================================================= | |
59 | Standard_Boolean StdSelect_BRepOwner:: | |
60 | IsHilighted(const Handle(PrsMgr_PresentationManager)& PM, | |
61 | const Standard_Integer aMode) const | |
62 | { | |
7fd59977 | 63 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
7fd59977 | 64 | if(myPrsSh.IsNull()) |
65 | return PM->IsHighlighted(Selectable(),M); | |
66 | return PM->IsHighlighted(myPrsSh,M); | |
67 | } | |
68 | ||
69 | //======================================================================= | |
70 | //function : Hilight/Unhilight Methods... | |
71 | //purpose : | |
72 | //======================================================================= | |
73 | void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM, | |
74 | const Standard_Integer aMode) | |
75 | { | |
76 | ||
7fd59977 | 77 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
a1954302 | 78 | Handle(SelectMgr_SelectableObject) aSel = Selectable(); |
29d43f9c A |
79 | if (myFromDecomposition) |
80 | { | |
81 | // do the update flag check | |
82 | if (!myPrsSh.IsNull()) | |
83 | { | |
84 | TColStd_ListOfInteger aModesList; | |
85 | myPrsSh->ToBeUpdated (aModesList); | |
86 | if (!aModesList.IsEmpty()) | |
87 | myPrsSh.Nullify(); | |
88 | } | |
89 | ||
7f917335 | 90 | Handle(Prs3d_Drawer) aDrawer; |
91 | if (!aSel.IsNull()) | |
92 | { | |
93 | aDrawer = aSel->HilightAttributes(); | |
94 | } | |
95 | else | |
96 | { | |
97 | aDrawer = new Prs3d_Drawer(); | |
98 | SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer); | |
99 | } | |
100 | ||
59f45b7c | 101 | // generate new presentable shape |
a1954302 | 102 | if (myPrsSh.IsNull()) |
103 | { | |
7f917335 | 104 | myPrsSh = new StdSelect_Shape (myShape, aDrawer); |
a1954302 | 105 | } |
59f45b7c | 106 | if (!aSel.IsNull()) |
107 | { | |
a1954302 | 108 | myPrsSh->SetZLayer (aSel->ZLayer()); |
59f45b7c | 109 | } |
a1954302 | 110 | |
111 | // highlight and set layer | |
112 | PM->Highlight (myPrsSh, M); | |
59f45b7c | 113 | } |
7fd59977 | 114 | else |
59f45b7c | 115 | { |
116 | if(myPrsSh.IsNull()) | |
a1954302 | 117 | PM->Highlight(aSel,M); |
59f45b7c | 118 | else |
119 | PM->Highlight(myPrsSh,M); | |
120 | } | |
7fd59977 | 121 | } |
122 | ||
123 | void StdSelect_BRepOwner::Hilight() | |
124 | {} | |
125 | ||
126 | void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManager3d)& PM, | |
127 | const Quantity_NameOfColor aCol, | |
128 | const Standard_Integer aMode) | |
129 | { | |
7fd59977 | 130 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
a1954302 | 131 | Handle(SelectMgr_SelectableObject) aSel = Selectable(); |
29d43f9c A |
132 | if (myFromDecomposition) |
133 | { | |
134 | // do the update flag check | |
135 | if (!myPrsSh.IsNull()) | |
136 | { | |
137 | TColStd_ListOfInteger aModesList; | |
138 | myPrsSh->ToBeUpdated (aModesList); | |
139 | if (!aModesList.IsEmpty()) | |
140 | myPrsSh.Nullify(); | |
141 | } | |
142 | ||
7f917335 | 143 | Handle(Prs3d_Drawer) aDrawer; |
144 | if (!aSel.IsNull()) | |
145 | { | |
146 | aDrawer = aSel->HilightAttributes(); | |
147 | } | |
148 | else | |
149 | { | |
150 | aDrawer = new Prs3d_Drawer(); | |
151 | SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer); | |
152 | } | |
153 | ||
59f45b7c | 154 | // generate new presentable shape |
155 | if(myPrsSh.IsNull()) | |
156 | { | |
157 | if(HasLocation()) | |
158 | { | |
159 | TopLoc_Location lbid = Location() * myShape.Location(); | |
160 | TopoDS_Shape ShBis = myShape.Located(lbid); | |
7f917335 | 161 | myPrsSh = new StdSelect_Shape(ShBis, aDrawer); |
7fd59977 | 162 | } |
163 | else | |
7f917335 | 164 | myPrsSh = new StdSelect_Shape(myShape, aDrawer); |
59f45b7c | 165 | } |
59f45b7c | 166 | if (!aSel.IsNull()) |
167 | { | |
a1954302 | 168 | myPrsSh->SetZLayer (aSel->ZLayer()); |
7fd59977 | 169 | } |
a1954302 | 170 | |
171 | // highlight with color and set layer | |
a272ed94 | 172 | PM->Color (myPrsSh, aCol, M, aSel); |
7fd59977 | 173 | } |
7fd59977 | 174 | else |
59f45b7c | 175 | { |
a272ed94 | 176 | if (!myPrsSh.IsNull()) |
177 | { | |
178 | PM->Color (myPrsSh, aCol, M, aSel); | |
179 | } | |
59f45b7c | 180 | else |
a272ed94 | 181 | { |
182 | PM->Color (aSel, aCol, M); | |
183 | } | |
59f45b7c | 184 | } |
7fd59977 | 185 | } |
186 | ||
187 | void StdSelect_BRepOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& PM, | |
188 | const Standard_Integer aMode) | |
189 | { | |
7fd59977 | 190 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
7fd59977 | 191 | if(myPrsSh.IsNull() || !myFromDecomposition) |
192 | PM->Unhighlight(Selectable(),M); | |
193 | else | |
194 | PM->Unhighlight(myPrsSh,M); | |
195 | } | |
196 | ||
197 | void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM, | |
198 | const Standard_Integer aMode) | |
199 | { | |
7fd59977 | 200 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
6153bb63 | 201 | if (!myPrsSh.IsNull()) |
7fd59977 | 202 | PM->Clear(myPrsSh,M); |
203 | myPrsSh.Nullify(); | |
204 | } | |
205 | ||
206 | void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc) | |
207 | { | |
208 | SelectMgr_EntityOwner::SetLocation(aLoc); | |
29d43f9c A |
209 | // we must not nullify the myPrsSh here, because unhilight method |
210 | // will be working with wrong entity in this case, the best is to | |
211 | // set the update flag and then recompute myPrsSh on hilighting | |
212 | if (!myPrsSh.IsNull()) | |
213 | myPrsSh->SetToUpdate(); | |
7fd59977 | 214 | } |
59f45b7c | 215 | |
7fd59977 | 216 | void StdSelect_BRepOwner::ResetLocation() |
217 | { | |
218 | SelectMgr_EntityOwner::ResetLocation(); | |
29d43f9c A |
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(); | |
59f45b7c | 224 | } |
29d43f9c | 225 | |
59f45b7c | 226 | //======================================================================= |
227 | //function : SetZLayer | |
228 | //purpose : | |
229 | //======================================================================= | |
a1954302 | 230 | void StdSelect_BRepOwner::SetZLayer (const Graphic3d_ZLayerId theLayerId) |
59f45b7c | 231 | { |
232 | if (!myPrsSh.IsNull()) | |
a1954302 | 233 | { |
234 | myPrsSh->SetZLayer (theLayerId); | |
235 | } | |
7fd59977 | 236 | } |