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 | |
f838dac4 |
17 | #include <StdSelect_BRepOwner.hxx> |
7fd59977 |
18 | |
19 | #include <Graphic3d_StructureManager.hxx> |
7f917335 |
20 | #include <Prs3d_Drawer.hxx> |
42cf5bc1 |
21 | #include <PrsMgr_PresentationManager.hxx> |
0ef04197 |
22 | #include <SelectMgr_EntityOwner.hxx> |
42cf5bc1 |
23 | #include <SelectMgr_SelectableObject.hxx> |
24 | #include <Standard_Type.hxx> |
42cf5bc1 |
25 | #include <StdSelect_Shape.hxx> |
26 | #include <TopLoc_Location.hxx> |
27 | #include <TopoDS_Shape.hxx> |
7fd59977 |
28 | |
92efcf78 |
29 | IMPLEMENT_STANDARD_RTTIEXT(StdSelect_BRepOwner,SelectMgr_EntityOwner) |
30 | |
7fd59977 |
31 | //================================================== |
f838dac4 |
32 | // Function: StdSelect_BRepOwner |
7fd59977 |
33 | // Purpose : |
34 | //================================================== |
f838dac4 |
35 | StdSelect_BRepOwner::StdSelect_BRepOwner (const Standard_Integer thePriority) |
36 | : SelectMgr_EntityOwner (thePriority), |
37 | myCurMode (0) |
7fd59977 |
38 | { |
f838dac4 |
39 | // |
7fd59977 |
40 | } |
41 | |
f838dac4 |
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) |
7fd59977 |
52 | { |
f838dac4 |
53 | myFromDecomposition = theComesFromDecomposition; |
7fd59977 |
54 | } |
55 | |
f838dac4 |
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) |
7fd59977 |
67 | { |
f838dac4 |
68 | myFromDecomposition = theComesFromDecomposition; |
7fd59977 |
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 | { |
7fd59977 |
79 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
7fd59977 |
80 | if(myPrsSh.IsNull()) |
81 | return PM->IsHighlighted(Selectable(),M); |
82 | return PM->IsHighlighted(myPrsSh,M); |
83 | } |
84 | |
85 | //======================================================================= |
8e5fb5ea |
86 | //function : HilightWithColor |
87 | //purpose : |
7fd59977 |
88 | //======================================================================= |
decbff0d |
89 | void StdSelect_BRepOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager)& thePM, |
90 | const Handle(Prs3d_Drawer)& theStyle, |
91 | const Standard_Integer theMode) |
7fd59977 |
92 | { |
f838dac4 |
93 | if (!HasSelectable()) |
29d43f9c |
94 | { |
f838dac4 |
95 | return; |
96 | } |
7f917335 |
97 | |
f838dac4 |
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 | } |
a1954302 |
106 | |
f838dac4 |
107 | // do the update flag check |
226fce20 |
108 | if (!myPrsSh.IsNull() |
109 | && myPrsSh->ToBeUpdated (true)) |
f838dac4 |
110 | { |
226fce20 |
111 | myPrsSh.Nullify(); |
7fd59977 |
112 | } |
f838dac4 |
113 | |
114 | // generate new presentable shape |
115 | if (myPrsSh.IsNull()) |
59f45b7c |
116 | { |
ba590cbf |
117 | myPrsSh = new StdSelect_Shape (myShape, theStyle); |
59f45b7c |
118 | } |
f838dac4 |
119 | |
120 | // initialize presentation attributes of child presentation |
121 | myPrsSh->SetZLayer (aSel->ZLayer()); |
122 | myPrsSh->SetTransformPersistence (aSel->TransformPersistence()); |
ba590cbf |
123 | myPrsSh->SetLocalTransformation (Location()); |
f838dac4 |
124 | myPrsSh->Attributes()->SetLink (theStyle); |
125 | myPrsSh->Attributes()->SetColor (theStyle->Color()); |
126 | myPrsSh->Attributes()->SetTransparency (theStyle->Transparency()); |
127 | myPrsSh->Attributes()->SetBasicFillAreaAspect (theStyle->BasicFillAreaAspect()); |
128 | |
129 | // highlight with color and set layer |
130 | thePM->Color (myPrsSh, theStyle, aDispMode, aSel, aHiLayer); |
7fd59977 |
131 | } |
132 | |
f838dac4 |
133 | void StdSelect_BRepOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& thePrsMgr, const Standard_Integer ) |
7fd59977 |
134 | { |
f838dac4 |
135 | if (myPrsSh.IsNull() || !myFromDecomposition) |
136 | { |
137 | thePrsMgr->Unhighlight (Selectable()); |
138 | } |
7fd59977 |
139 | else |
f838dac4 |
140 | { |
141 | thePrsMgr->Unhighlight (myPrsSh); |
142 | } |
7fd59977 |
143 | } |
144 | |
145 | void StdSelect_BRepOwner::Clear(const Handle(PrsMgr_PresentationManager)& PM, |
146 | const Standard_Integer aMode) |
147 | { |
7fd59977 |
148 | Standard_Integer M = (aMode < 0) ? myCurMode : aMode; |
6153bb63 |
149 | if (!myPrsSh.IsNull()) |
7fd59977 |
150 | PM->Clear(myPrsSh,M); |
151 | myPrsSh.Nullify(); |
152 | } |
153 | |
154 | void StdSelect_BRepOwner::SetLocation(const TopLoc_Location& aLoc) |
155 | { |
156 | SelectMgr_EntityOwner::SetLocation(aLoc); |
29d43f9c |
157 | if (!myPrsSh.IsNull()) |
ba590cbf |
158 | { |
159 | myPrsSh->SetLocalTransformation (Location()); |
160 | } |
7fd59977 |
161 | } |
59f45b7c |
162 | |
5396886c |
163 | //======================================================================= |
164 | //function : UpdateHighlightTrsf |
165 | //purpose : |
166 | //======================================================================= |
167 | void StdSelect_BRepOwner::UpdateHighlightTrsf (const Handle(V3d_Viewer)& theViewer, |
decbff0d |
168 | const Handle(PrsMgr_PresentationManager)& theManager, |
5396886c |
169 | const Standard_Integer theDispMode) |
170 | { |
ba590cbf |
171 | if (!myPrsSh.IsNull() || HasSelectable()) |
172 | { |
173 | theManager->UpdateHighlightTrsf (theViewer, Selectable(), theDispMode, myPrsSh); |
174 | } |
5396886c |
175 | } |
bc73b006 |
176 | |
177 | // ======================================================================= |
178 | // function : DumpJson |
179 | // purpose : |
180 | // ======================================================================= |
181 | void StdSelect_BRepOwner::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
182 | { |
183 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
184 | |
185 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myShape) |
186 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myPrsSh.get()) |
187 | |
188 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurMode) |
189 | } |