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