b311480e |
1 | // Created on: 1997-04-22 |
2 | // Created by: Guest Design |
3 | // Copyright (c) 1997-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. |
b311480e |
16 | |
7fd59977 |
17 | |
0717ddc1 |
18 | #include <AIS_ConnectedInteractive.hxx> |
19 | #include <AIS_InteractiveContext.hxx> |
42cf5bc1 |
20 | #include <AIS_InteractiveObject.hxx> |
21 | #include <AIS_MultipleConnectedInteractive.hxx> |
22 | #include <Geom_Transformation.hxx> |
23 | #include <gp_Pnt.hxx> |
24 | #include <gp_Trsf.hxx> |
25 | #include <NCollection_DataMap.hxx> |
26 | #include <Prs3d_Presentation.hxx> |
27 | #include <Prs3d_Projector.hxx> |
7fd59977 |
28 | #include <PrsMgr_ModedPresentation.hxx> |
af324faa |
29 | #include <PrsMgr_Presentation.hxx> |
0717ddc1 |
30 | #include <Select3D_SensitiveEntity.hxx> |
42cf5bc1 |
31 | #include <SelectMgr_EntityOwner.hxx> |
32 | #include <Standard_NotImplemented.hxx> |
33 | #include <Standard_Type.hxx> |
0717ddc1 |
34 | #include <TopLoc_Location.hxx> |
0717ddc1 |
35 | |
36 | namespace |
37 | { |
38 | //! SelectMgr_AssemblyEntityOwner replaces original owners in sensitive entities |
39 | //! copied from reference objects to AIS_MultipleConnectedInteractive in order to |
40 | //! redirect all selection queries to multiply connected (assembly). |
41 | class SelectMgr_AssemblyEntityOwner : public SelectMgr_EntityOwner |
42 | { |
43 | |
44 | public: |
45 | |
46 | // Copies another SelectMgr_EntityOwner. |
47 | SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner, |
48 | SelectMgr_SelectableObject* theAssembly); |
49 | |
50 | void SetAssembly (SelectMgr_SelectableObject* theAssembly) |
51 | { |
52 | myAssembly = theAssembly; |
53 | } |
54 | |
55 | //! Selectable() method modified to return myAssembly. |
35c0599a |
56 | virtual Handle(SelectMgr_SelectableObject) Selectable() const; |
0717ddc1 |
57 | |
58 | Standard_Boolean IsHilighted (const Handle(PrsMgr_PresentationManager)& PM,const Standard_Integer aMode) const; |
59 | |
60 | void Hilight (const Handle(PrsMgr_PresentationManager)& PM,const Standard_Integer aMode); |
61 | |
62 | void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& PM, |
63 | const Quantity_NameOfColor aColor, |
64 | const Standard_Integer aMode); |
65 | |
66 | void Unhilight (const Handle(PrsMgr_PresentationManager)& PM, const Standard_Integer aMode); |
67 | |
68 | private: |
69 | |
70 | SelectMgr_SelectableObject* myAssembly; |
71 | }; |
72 | |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : SelectMgr_AssemblyEntityOwner |
77 | //purpose : |
78 | //======================================================================= |
79 | SelectMgr_AssemblyEntityOwner::SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner, |
80 | SelectMgr_SelectableObject* theAssembly) |
81 | : |
82 | SelectMgr_EntityOwner (theOwner), |
83 | myAssembly (theAssembly) |
84 | { |
85 | } |
86 | |
87 | //======================================================================= |
88 | //function : Selectable |
89 | //purpose : |
90 | //======================================================================= |
91 | Handle(SelectMgr_SelectableObject) SelectMgr_AssemblyEntityOwner::Selectable() const |
92 | { |
93 | return myAssembly; |
94 | } |
7fd59977 |
95 | |
0717ddc1 |
96 | //======================================================================= |
97 | //function : IsHilighted |
98 | //purpose : |
99 | //======================================================================= |
100 | Standard_Boolean SelectMgr_AssemblyEntityOwner::IsHilighted (const Handle(PrsMgr_PresentationManager)& PM, |
101 | const Standard_Integer aMode) const |
7fd59977 |
102 | { |
0717ddc1 |
103 | if (HasSelectable()) |
104 | { |
105 | return PM->IsHighlighted (myAssembly, aMode); |
7fd59977 |
106 | } |
0717ddc1 |
107 | |
108 | return Standard_False; |
7fd59977 |
109 | } |
110 | |
0717ddc1 |
111 | //======================================================================= |
112 | //function : Hilight |
113 | //purpose : |
114 | //======================================================================= |
115 | void SelectMgr_AssemblyEntityOwner::Hilight (const Handle(PrsMgr_PresentationManager)& PM, |
116 | const Standard_Integer aMode) |
7fd59977 |
117 | { |
0717ddc1 |
118 | if (HasSelectable()) |
119 | { |
120 | PM->Highlight (myAssembly, aMode); |
121 | } |
122 | } |
123 | |
124 | //======================================================================= |
125 | //function : HilightWithColor |
126 | //purpose : |
127 | //======================================================================= |
128 | void SelectMgr_AssemblyEntityOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& PM, |
129 | const Quantity_NameOfColor aColor, |
130 | const Standard_Integer aMode) |
131 | { |
132 | if (HasSelectable()) |
133 | { |
134 | if (IsAutoHilight()) |
135 | { |
136 | PM->Color (myAssembly, aColor, aMode); |
137 | } |
138 | else |
139 | { |
140 | myAssembly->HilightOwnerWithColor (PM, aColor, this); |
141 | } |
142 | } |
143 | } |
144 | |
145 | //======================================================================= |
146 | //function : Unhilight |
147 | //purpose : |
148 | //======================================================================= |
149 | void SelectMgr_AssemblyEntityOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& PM, |
150 | const Standard_Integer aMode) |
151 | { |
152 | if (HasSelectable()) |
153 | { |
154 | PM->Unhighlight (myAssembly, aMode); |
7fd59977 |
155 | } |
7fd59977 |
156 | } |
157 | |
158 | |
159 | //======================================================================= |
160 | //function : AIS_MultipleConnectedInteractive |
161 | //purpose : |
162 | //======================================================================= |
163 | |
0717ddc1 |
164 | AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive() |
165 | : AIS_InteractiveObject (PrsMgr_TOP_AllView) |
166 | { |
167 | myHasOwnPresentations = Standard_False; |
f751596e |
168 | myAssemblyOwner = NULL; |
0717ddc1 |
169 | SetHilightMode (0); |
7fd59977 |
170 | } |
171 | |
172 | //======================================================================= |
173 | //function : Type |
174 | //purpose : |
175 | //======================================================================= |
176 | AIS_KindOfInteractive AIS_MultipleConnectedInteractive::Type() const |
0717ddc1 |
177 | { |
178 | return AIS_KOI_Object; |
179 | } |
7fd59977 |
180 | |
181 | //======================================================================= |
182 | //function : Signature |
183 | //purpose : |
184 | //======================================================================= |
185 | Standard_Integer AIS_MultipleConnectedInteractive::Signature() const |
0717ddc1 |
186 | { |
187 | return 1; |
188 | } |
7fd59977 |
189 | |
190 | //======================================================================= |
191 | //function : Connect |
ba9e14df |
192 | //purpose : |
7fd59977 |
193 | //======================================================================= |
ba9e14df |
194 | Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, |
195 | const gp_Trsf& theTransformation, |
196 | const Graphic3d_TransModeFlags& theTrsfPersFlag, |
197 | const gp_Pnt& theTrsfPersPoint) |
7fd59977 |
198 | { |
f751596e |
199 | if (myAssemblyOwner.IsNull()) |
200 | myAssemblyOwner = new SelectMgr_EntityOwner (this); |
201 | |
0717ddc1 |
202 | Handle(AIS_InteractiveObject) anObjectToAdd; |
203 | |
204 | Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj); |
205 | if (!aMultiConnected.IsNull()) |
206 | { |
207 | Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive(); |
f751596e |
208 | aNewMultiConnected->myAssemblyOwner = myAssemblyOwner; |
0717ddc1 |
209 | aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformation()); |
210 | |
211 | // Perform deep copy of instance tree |
212 | for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next()) |
213 | { |
214 | Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); |
215 | if (anInteractive.IsNull()) |
216 | { |
217 | continue; |
218 | } |
219 | |
220 | aNewMultiConnected->Connect (anInteractive); |
221 | } |
7fd59977 |
222 | |
0717ddc1 |
223 | anObjectToAdd = aNewMultiConnected; |
7fd59977 |
224 | } |
0717ddc1 |
225 | else |
226 | { |
227 | Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive(); |
228 | aNewConnected->Connect (theAnotherObj); |
229 | aNewConnected->SetLocalTransformation (theAnotherObj->LocalTransformation()); |
230 | |
231 | anObjectToAdd = aNewConnected; |
232 | } |
233 | |
234 | anObjectToAdd->SetLocalTransformation (theTransformation); |
ba9e14df |
235 | if (theTrsfPersFlag != Graphic3d_TMF_None) |
236 | { |
237 | anObjectToAdd->SetTransformPersistence (theTrsfPersFlag, theTrsfPersPoint); |
238 | } |
0717ddc1 |
239 | AddChild (anObjectToAdd); |
ba9e14df |
240 | return anObjectToAdd; |
0717ddc1 |
241 | } |
242 | |
243 | //======================================================================= |
244 | //function : Connect |
ba9e14df |
245 | //purpose : |
246 | //======================================================================= |
247 | Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj) |
248 | { |
249 | return Connect (theAnotherObj, theAnotherObj->LocalTransformation(), |
250 | theAnotherObj->GetTransformPersistenceMode(), |
251 | theAnotherObj->GetTransformPersistencePoint()); |
252 | } |
253 | |
254 | //======================================================================= |
255 | //function : Connect |
256 | //purpose : |
0717ddc1 |
257 | //======================================================================= |
ba9e14df |
258 | Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, |
259 | const gp_Trsf& theTransformation) |
0717ddc1 |
260 | { |
ba9e14df |
261 | return Connect (theAnotherObj, theTransformation, |
262 | theAnotherObj->GetTransformPersistenceMode(), |
263 | theAnotherObj->GetTransformPersistencePoint()); |
7fd59977 |
264 | } |
265 | |
266 | //======================================================================= |
267 | //function : HasConnection |
268 | //purpose : |
269 | //======================================================================= |
270 | Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const |
271 | { |
0717ddc1 |
272 | return (Children().Size() != 0); |
7fd59977 |
273 | } |
274 | |
275 | //======================================================================= |
276 | //function : Disconnect |
277 | //purpose : |
278 | //======================================================================= |
279 | |
280 | void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj) |
281 | { |
0717ddc1 |
282 | RemoveChild (anotherIObj); |
7fd59977 |
283 | } |
284 | |
285 | //======================================================================= |
286 | //function : DisconnectAll |
287 | //purpose : |
288 | //======================================================================= |
289 | |
0717ddc1 |
290 | void AIS_MultipleConnectedInteractive::DisconnectAll() |
7fd59977 |
291 | { |
0717ddc1 |
292 | Standard_Integer aNbItemsToRemove = Children().Size(); |
293 | for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter) |
294 | { |
295 | RemoveChild (Children().First()); |
296 | } |
7fd59977 |
297 | } |
298 | |
299 | //======================================================================= |
300 | //function : Compute |
792c785c |
301 | //purpose : |
7fd59977 |
302 | //======================================================================= |
0717ddc1 |
303 | void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/, |
304 | const Handle(Prs3d_Presentation)& /*thePrs*/, |
305 | const Standard_Integer /*theMode*/) |
7fd59977 |
306 | { |
0717ddc1 |
307 | for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next()) |
792c785c |
308 | { |
0717ddc1 |
309 | Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); |
310 | if (aChild.IsNull()) |
792c785c |
311 | { |
0717ddc1 |
312 | continue; |
313 | } |
792c785c |
314 | |
0717ddc1 |
315 | if (!aChild->HasInteractiveContext()) |
316 | { |
317 | aChild->SetContext (GetContext()); |
7fd59977 |
318 | } |
319 | } |
7fd59977 |
320 | } |
792c785c |
321 | |
7fd59977 |
322 | //======================================================================= |
323 | //function : Compute |
324 | //purpose : |
325 | //======================================================================= |
326 | |
857ffd5e |
327 | void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector, |
328 | const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 |
329 | { |
0717ddc1 |
330 | PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; |
7fd59977 |
331 | } |
332 | |
333 | //======================================================================= |
334 | //function : Compute |
335 | //purpose : |
7fd59977 |
336 | //======================================================================= |
337 | |
857ffd5e |
338 | void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector, |
339 | const Handle(Geom_Transformation)& aTransformation, |
340 | const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 |
341 | { |
0717ddc1 |
342 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
343 | } |
344 | |
345 | //======================================================================= |
346 | //function : AcceptShapeDecomposition |
347 | //purpose : |
348 | //======================================================================= |
349 | Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const |
350 | { |
351 | for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next()) |
352 | { |
353 | Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); |
354 | if (aChild.IsNull()) |
355 | { |
356 | continue; |
357 | } |
358 | |
359 | if (aChild->AcceptShapeDecomposition()) |
360 | { |
361 | return Standard_True; |
362 | } |
363 | } |
364 | return Standard_False; |
7fd59977 |
365 | } |
366 | |
367 | //======================================================================= |
368 | //function : ComputeSelection |
369 | //purpose : |
370 | //======================================================================= |
f751596e |
371 | void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/, |
0717ddc1 |
372 | const Standard_Integer theMode) |
7fd59977 |
373 | { |
0717ddc1 |
374 | if (theMode != 0) |
375 | { |
376 | for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next()) |
377 | { |
378 | Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); |
379 | if (aChild.IsNull()) |
380 | { |
381 | continue; |
382 | } |
383 | |
f751596e |
384 | if (!aChild->HasSelection (theMode)) |
0717ddc1 |
385 | { |
f751596e |
386 | aChild->RecomputePrimitives (theMode); |
0717ddc1 |
387 | } |
388 | |
f751596e |
389 | Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode); |
390 | aChild->ComputeSelection (aSelection, theMode); |
0717ddc1 |
391 | } |
392 | } |
7fd59977 |
393 | } |