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