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 | |
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 | |
29 | //================================================== | |
30 | // Function: | |
31 | // Purpose : | |
32 | //================================================== | |
33 | StdSelect_BRepOwner::StdSelect_BRepOwner(const Standard_Integer aPriority): | |
34 | SelectMgr_EntityOwner(aPriority), | |
35 | myFromDecomposition(Standard_False), | |
36 | myCurMode(0) | |
37 | { | |
38 | } | |
39 | ||
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), | |
45 | myShape(aShape), | |
46 | myCurMode(0) | |
47 | { | |
48 | } | |
49 | ||
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), | |
56 | myShape(aShape), | |
57 | myCurMode(0) | |
58 | { | |
59 | } | |
60 | ||
61 | //======================================================================= | |
62 | //function : IsHilighted | |
63 | //purpose : | |
64 | //======================================================================= | |
65 | Standard_Boolean StdSelect_BRepOwner:: | |
66 | IsHilighted(const Handle(PrsMgr_PresentationManager)& PM, | |
67 | const Standard_Integer aMode) const | |
68 | { | |
7fd59977 | 69 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
7fd59977 | 70 | if(myPrsSh.IsNull()) |
71 | return PM->IsHighlighted(Selectable(),M); | |
72 | return PM->IsHighlighted(myPrsSh,M); | |
73 | } | |
74 | ||
75 | //======================================================================= | |
76 | //function : Hilight/Unhilight Methods... | |
77 | //purpose : | |
78 | //======================================================================= | |
79 | void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM, | |
80 | const Standard_Integer aMode) | |
81 | { | |
82 | ||
7fd59977 | 83 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
a1954302 | 84 | Handle(SelectMgr_SelectableObject) aSel = Selectable(); |
29d43f9c A |
85 | if (myFromDecomposition) |
86 | { | |
87 | // do the update flag check | |
88 | if (!myPrsSh.IsNull()) | |
89 | { | |
90 | TColStd_ListOfInteger aModesList; | |
91 | myPrsSh->ToBeUpdated (aModesList); | |
92 | if (!aModesList.IsEmpty()) | |
93 | myPrsSh.Nullify(); | |
94 | } | |
95 | ||
7f917335 | 96 | Handle(Prs3d_Drawer) aDrawer; |
97 | if (!aSel.IsNull()) | |
98 | { | |
99 | aDrawer = aSel->HilightAttributes(); | |
100 | } | |
101 | else | |
102 | { | |
103 | aDrawer = new Prs3d_Drawer(); | |
104 | SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer); | |
105 | } | |
106 | ||
59f45b7c | 107 | // generate new presentable shape |
a1954302 | 108 | if (myPrsSh.IsNull()) |
109 | { | |
7f917335 | 110 | myPrsSh = new StdSelect_Shape (myShape, aDrawer); |
a1954302 | 111 | } |
59f45b7c | 112 | if (!aSel.IsNull()) |
113 | { | |
a1954302 | 114 | myPrsSh->SetZLayer (aSel->ZLayer()); |
59f45b7c | 115 | } |
a1954302 | 116 | |
117 | // highlight and set layer | |
118 | PM->Highlight (myPrsSh, M); | |
59f45b7c | 119 | } |
7fd59977 | 120 | else |
59f45b7c | 121 | { |
122 | if(myPrsSh.IsNull()) | |
a1954302 | 123 | PM->Highlight(aSel,M); |
59f45b7c | 124 | else |
125 | PM->Highlight(myPrsSh,M); | |
126 | } | |
7fd59977 | 127 | } |
128 | ||
129 | void StdSelect_BRepOwner::Hilight() | |
130 | {} | |
131 | ||
132 | void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManager3d)& PM, | |
133 | const Quantity_NameOfColor aCol, | |
134 | const Standard_Integer aMode) | |
135 | { | |
7fd59977 | 136 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
c3282ec1 | 137 | Graphic3d_ZLayerId aHiLayer = this == Selectable()->GlobalSelOwner().get() ? |
138 | Graphic3d_ZLayerId_Top : Graphic3d_ZLayerId_Topmost; | |
a1954302 | 139 | Handle(SelectMgr_SelectableObject) aSel = Selectable(); |
29d43f9c A |
140 | if (myFromDecomposition) |
141 | { | |
142 | // do the update flag check | |
143 | if (!myPrsSh.IsNull()) | |
144 | { | |
145 | TColStd_ListOfInteger aModesList; | |
146 | myPrsSh->ToBeUpdated (aModesList); | |
147 | if (!aModesList.IsEmpty()) | |
148 | myPrsSh.Nullify(); | |
149 | } | |
150 | ||
7f917335 | 151 | Handle(Prs3d_Drawer) aDrawer; |
152 | if (!aSel.IsNull()) | |
153 | { | |
154 | aDrawer = aSel->HilightAttributes(); | |
155 | } | |
156 | else | |
157 | { | |
158 | aDrawer = new Prs3d_Drawer(); | |
159 | SelectMgr_SelectableObject::InitDefaultHilightAttributes (aDrawer); | |
160 | } | |
161 | ||
59f45b7c | 162 | // generate new presentable shape |
163 | if(myPrsSh.IsNull()) | |
164 | { | |
165 | if(HasLocation()) | |
166 | { | |
167 | TopLoc_Location lbid = Location() * myShape.Location(); | |
168 | TopoDS_Shape ShBis = myShape.Located(lbid); | |
7f917335 | 169 | myPrsSh = new StdSelect_Shape(ShBis, aDrawer); |
7fd59977 | 170 | } |
171 | else | |
7f917335 | 172 | myPrsSh = new StdSelect_Shape(myShape, aDrawer); |
59f45b7c | 173 | } |
59f45b7c | 174 | if (!aSel.IsNull()) |
175 | { | |
a1954302 | 176 | myPrsSh->SetZLayer (aSel->ZLayer()); |
7fd59977 | 177 | } |
a1954302 | 178 | |
179 | // highlight with color and set layer | |
c3282ec1 | 180 | PM->Color (myPrsSh, aCol, M, aSel, aHiLayer); |
7fd59977 | 181 | } |
7fd59977 | 182 | else |
59f45b7c | 183 | { |
a272ed94 | 184 | if (!myPrsSh.IsNull()) |
185 | { | |
c3282ec1 | 186 | PM->Color (myPrsSh, aCol, M, aSel, aHiLayer); |
a272ed94 | 187 | } |
59f45b7c | 188 | else |
a272ed94 | 189 | { |
c3282ec1 | 190 | PM->Color (aSel, aCol, M, NULL, aHiLayer); |
a272ed94 | 191 | } |
59f45b7c | 192 | } |
7fd59977 | 193 | } |
194 | ||
195 | void StdSelect_BRepOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& PM, | |
196 | const Standard_Integer aMode) | |
197 | { | |
7fd59977 | 198 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
7fd59977 | 199 | if(myPrsSh.IsNull() || !myFromDecomposition) |
200 | PM->Unhighlight(Selectable(),M); | |
201 | else | |
202 | PM->Unhighlight(myPrsSh,M); | |
203 | } | |
204 | ||
205 | void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM, | |
206 | const Standard_Integer aMode) | |
207 | { | |
7fd59977 | 208 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
6153bb63 | 209 | if (!myPrsSh.IsNull()) |
7fd59977 | 210 | PM->Clear(myPrsSh,M); |
211 | myPrsSh.Nullify(); | |
212 | } | |
213 | ||
214 | void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc) | |
215 | { | |
216 | SelectMgr_EntityOwner::SetLocation(aLoc); | |
29d43f9c A |
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(); | |
7fd59977 | 222 | } |
59f45b7c | 223 | |
7fd59977 | 224 | void StdSelect_BRepOwner::ResetLocation() |
225 | { | |
226 | SelectMgr_EntityOwner::ResetLocation(); | |
29d43f9c A |
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(); | |
59f45b7c | 232 | } |
29d43f9c | 233 | |
59f45b7c | 234 | //======================================================================= |
235 | //function : SetZLayer | |
236 | //purpose : | |
237 | //======================================================================= | |
a1954302 | 238 | void StdSelect_BRepOwner::SetZLayer (const Graphic3d_ZLayerId theLayerId) |
59f45b7c | 239 | { |
240 | if (!myPrsSh.IsNull()) | |
a1954302 | 241 | { |
242 | myPrsSh->SetZLayer (theLayerId); | |
243 | } | |
7fd59977 | 244 | } |