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