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