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