0031909: Visualization, AIS_Trihedron - replace maps with arrays
[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>
0717ddc1 22#include <Select3D_SensitiveEntity.hxx>
42cf5bc1 23#include <SelectMgr_EntityOwner.hxx>
24#include <Standard_NotImplemented.hxx>
0717ddc1 25#include <TopLoc_Location.hxx>
0717ddc1 26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(AIS_MultipleConnectedInteractive,AIS_InteractiveObject)
28
7fd59977 29//=======================================================================
30//function : AIS_MultipleConnectedInteractive
b5cce1ab 31//purpose :
7fd59977 32//=======================================================================
33
0717ddc1 34AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive()
b5cce1ab 35: AIS_InteractiveObject (PrsMgr_TOP_AllView)
0717ddc1 36{
37 myHasOwnPresentations = Standard_False;
7fd59977 38}
39
40//=======================================================================
41//function : Type
42//purpose :
43//=======================================================================
44AIS_KindOfInteractive AIS_MultipleConnectedInteractive::Type() const
0717ddc1 45{
46 return AIS_KOI_Object;
47}
7fd59977 48
49//=======================================================================
50//function : Signature
51//purpose :
52//=======================================================================
53Standard_Integer AIS_MultipleConnectedInteractive::Signature() const
0717ddc1 54{
55 return 1;
56}
7fd59977 57
58//=======================================================================
1f7f5a90 59//function : connect
ba9e14df 60//purpose :
7fd59977 61//=======================================================================
1f7f5a90 62Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
7f24b768 63 const Handle(TopLoc_Datum3D)& theTrsf,
778cd667 64 const Handle(Graphic3d_TransformPers)& theTrsfPers)
7fd59977 65{
f751596e 66 if (myAssemblyOwner.IsNull())
67 myAssemblyOwner = new SelectMgr_EntityOwner (this);
68
0717ddc1 69 Handle(AIS_InteractiveObject) anObjectToAdd;
70
71 Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
72 if (!aMultiConnected.IsNull())
73 {
74 Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
f751596e 75 aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
1f7f5a90 76 aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformationGeom());
0717ddc1 77
78 // Perform deep copy of instance tree
79 for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
80 {
81 Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
82 if (anInteractive.IsNull())
83 {
84 continue;
85 }
86
87 aNewMultiConnected->Connect (anInteractive);
88 }
7fd59977 89
0717ddc1 90 anObjectToAdd = aNewMultiConnected;
7fd59977 91 }
0717ddc1 92 else
93 {
94 Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
1f7f5a90 95 aNewConnected->Connect (theAnotherObj, theAnotherObj->LocalTransformationGeom());
0717ddc1 96
97 anObjectToAdd = aNewConnected;
98 }
99
1f7f5a90 100 anObjectToAdd->SetLocalTransformation (theTrsf);
778cd667 101 if (!theTrsfPers.IsNull())
ba9e14df 102 {
778cd667 103 anObjectToAdd->SetTransformPersistence (theTrsfPers);
ba9e14df 104 }
0717ddc1 105 AddChild (anObjectToAdd);
ba9e14df 106 return anObjectToAdd;
0717ddc1 107}
108
7fd59977 109//=======================================================================
110//function : HasConnection
111//purpose :
112//=======================================================================
113Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const
114{
0717ddc1 115 return (Children().Size() != 0);
7fd59977 116}
117
118//=======================================================================
119//function : Disconnect
120//purpose :
121//=======================================================================
122
123void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
124{
0717ddc1 125 RemoveChild (anotherIObj);
7fd59977 126}
127
128//=======================================================================
129//function : DisconnectAll
130//purpose :
131//=======================================================================
132
0717ddc1 133void AIS_MultipleConnectedInteractive::DisconnectAll()
7fd59977 134{
0717ddc1 135 Standard_Integer aNbItemsToRemove = Children().Size();
136 for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
137 {
138 RemoveChild (Children().First());
139 }
7fd59977 140}
141
142//=======================================================================
143//function : Compute
792c785c 144//purpose :
7fd59977 145//=======================================================================
0717ddc1 146void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
147 const Handle(Prs3d_Presentation)& /*thePrs*/,
148 const Standard_Integer /*theMode*/)
7fd59977 149{
2ec85268 150 Handle(AIS_InteractiveContext) aCtx = GetContext();
0717ddc1 151 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
792c785c 152 {
0717ddc1 153 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
2ec85268 154 if (!aChild.IsNull())
0717ddc1 155 {
2ec85268 156 aChild->SetContext (aCtx);
7fd59977 157 }
158 }
7fd59977 159}
792c785c 160
0717ddc1 161//=======================================================================
162//function : AcceptShapeDecomposition
163//purpose :
164//=======================================================================
165Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const
166{
167 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
168 {
169 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
170 if (aChild.IsNull())
171 {
172 continue;
173 }
174
175 if (aChild->AcceptShapeDecomposition())
176 {
177 return Standard_True;
178 }
179 }
180 return Standard_False;
7fd59977 181}
182
183//=======================================================================
184//function : ComputeSelection
185//purpose :
186//=======================================================================
f751596e 187void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
0717ddc1 188 const Standard_Integer theMode)
7fd59977 189{
b5cce1ab 190 if (theMode == 0)
0717ddc1 191 {
b5cce1ab 192 return;
0717ddc1 193 }
7411850a 194
7411850a 195 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
196 {
197 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
198 if (aChild.IsNull())
b5cce1ab 199 {
7411850a 200 continue;
b5cce1ab 201 }
7411850a 202
203 if (!aChild->HasSelection (theMode))
b5cce1ab 204 {
205 aChild->RecomputePrimitives (theMode);
206 }
7411850a 207
b5cce1ab 208 Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
209 aChild->ComputeSelection (aSelection, theMode);
210 }
7411850a 211}
2ec85268 212
213//=======================================================================
214//function : SetContext
215//purpose :
216//=======================================================================
217void AIS_MultipleConnectedInteractive::SetContext (const Handle(AIS_InteractiveContext)& theCtx)
218{
219 AIS_InteractiveObject::SetContext (theCtx);
220 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
221 {
222 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
223 if (!aChild.IsNull())
224 {
225 aChild->SetContext (theCtx);
226 }
227 }
228}