0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / AIS / AIS_MultipleConnectedInteractive.cxx
1 // Created on: 1997-04-22
2 // Created by: Guest Design
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <AIS_MultipleConnectedInteractive.hxx>
18
19 #include <AIS_ConnectedInteractive.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <Prs3d_Projector.hxx>
23 #include <PrsMgr_ModedPresentation.hxx>
24 #include <Select3D_SensitiveEntity.hxx>
25 #include <SelectMgr_EntityOwner.hxx>
26 #include <Standard_NotImplemented.hxx>
27 #include <TopLoc_Location.hxx>
28
29 IMPLEMENT_STANDARD_RTTIEXT(AIS_MultipleConnectedInteractive,AIS_InteractiveObject)
30
31 //=======================================================================
32 //function : AIS_MultipleConnectedInteractive
33 //purpose  : 
34 //=======================================================================
35
36 AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive()
37   : AIS_InteractiveObject (PrsMgr_TOP_AllView)
38 {
39   myHasOwnPresentations = Standard_False;
40   myAssemblyOwner = NULL;
41 }
42
43 //=======================================================================
44 //function : Type
45 //purpose  : 
46 //=======================================================================
47 AIS_KindOfInteractive AIS_MultipleConnectedInteractive::Type() const
48 {
49   return AIS_KOI_Object;
50 }
51
52 //=======================================================================
53 //function : Signature
54 //purpose  : 
55 //=======================================================================
56 Standard_Integer AIS_MultipleConnectedInteractive::Signature() const
57 {
58   return 1;
59 }
60
61 //=======================================================================
62 //function : connect
63 //purpose  :
64 //=======================================================================
65 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
66                                                                          const Handle(Geom_Transformation)& theTrsf,
67                                                                          const Handle(Graphic3d_TransformPers)& theTrsfPers)
68 {
69   if (myAssemblyOwner.IsNull())
70     myAssemblyOwner = new SelectMgr_EntityOwner (this);
71
72   Handle(AIS_InteractiveObject) anObjectToAdd;
73
74   Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
75   if (!aMultiConnected.IsNull())
76   { 
77     Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
78     aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
79     aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformationGeom());
80
81     // Perform deep copy of instance tree
82     for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
83     {
84       Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
85       if (anInteractive.IsNull())
86       {
87         continue;
88       }
89
90       aNewMultiConnected->Connect (anInteractive);     
91     }
92
93     anObjectToAdd = aNewMultiConnected;
94   }
95   else
96   {
97     Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
98     aNewConnected->Connect (theAnotherObj, theAnotherObj->LocalTransformationGeom());
99
100     anObjectToAdd = aNewConnected;
101   }
102
103   anObjectToAdd->SetLocalTransformation (theTrsf);
104   if (!theTrsfPers.IsNull())
105   {
106     anObjectToAdd->SetTransformPersistence (theTrsfPers);
107   }
108   AddChild (anObjectToAdd);
109   return anObjectToAdd;
110 }
111
112 //=======================================================================
113 //function : HasConnection
114 //purpose  : 
115 //=======================================================================
116 Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const 
117 {
118   return (Children().Size() != 0);
119 }
120
121 //=======================================================================
122 //function : Disconnect
123 //purpose  : 
124 //=======================================================================
125
126 void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
127 {
128   RemoveChild (anotherIObj);
129 }
130
131 //=======================================================================
132 //function : DisconnectAll
133 //purpose  : 
134 //=======================================================================
135
136 void AIS_MultipleConnectedInteractive::DisconnectAll()
137 {
138   Standard_Integer aNbItemsToRemove = Children().Size();
139   for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
140   {
141     RemoveChild (Children().First());
142   }
143 }
144
145 //=======================================================================
146 //function : Compute
147 //purpose  :
148 //=======================================================================
149 void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
150                                                 const Handle(Prs3d_Presentation)&           /*thePrs*/,
151                                                 const Standard_Integer                      /*theMode*/)
152 {
153   Handle(AIS_InteractiveContext) aCtx = GetContext();
154   for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
155   {
156     Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
157     if (!aChild.IsNull())
158     {
159       aChild->SetContext (aCtx);
160     }
161   }
162 }
163
164 //=======================================================================
165 //function : Compute
166 //purpose  : 
167 //=======================================================================
168
169 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
170                                                const Handle(Prs3d_Presentation)& aPresentation)
171 {
172   PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
173 }
174
175 //=======================================================================
176 //function : Compute
177 //purpose  : 
178 //=======================================================================
179
180 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
181                                                const Handle(Geom_Transformation)& aTransformation,
182                                                const Handle(Prs3d_Presentation)& aPresentation)
183 {
184   PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
185 }
186
187 //=======================================================================
188 //function : AcceptShapeDecomposition
189 //purpose  : 
190 //=======================================================================
191 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const 
192 {
193   for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
194   {
195     Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
196     if (aChild.IsNull())
197     {
198       continue;
199     }
200
201     if (aChild->AcceptShapeDecomposition())
202     {
203       return Standard_True;
204     }
205   }
206   return Standard_False;
207 }
208
209 //=======================================================================
210 //function : ComputeSelection
211 //purpose  : 
212 //=======================================================================
213 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
214                                                          const Standard_Integer             theMode)
215 {
216   if (theMode != 0)
217   {
218     for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
219     {
220       Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
221       if (aChild.IsNull())
222       {
223         continue;
224       }
225
226       if (!aChild->HasSelection (theMode))
227       {
228         aChild->RecomputePrimitives (theMode);
229       }
230
231       Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
232       aChild->ComputeSelection (aSelection, theMode);
233     }
234   }
235 }
236
237 //=======================================================================
238 //function : GlobalSelOwner
239 //purpose  :
240 //=======================================================================
241 Handle(SelectMgr_EntityOwner) AIS_MultipleConnectedInteractive::GlobalSelOwner() const
242 {
243   return myAssemblyOwner;
244 }
245
246 //=======================================================================
247 //function : HasSelection
248 //purpose  :
249 //=======================================================================
250 Standard_Boolean AIS_MultipleConnectedInteractive::HasSelection (const Standard_Integer theMode) const
251 {
252   for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
253   {
254     Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
255     if (aChild.IsNull())
256       continue;
257
258     if (!aChild->HasSelection (theMode))
259       return Standard_False;
260   }
261
262   return Standard_True;
263 }
264
265 //=======================================================================
266 //function : SetContext
267 //purpose  :
268 //=======================================================================
269 void AIS_MultipleConnectedInteractive::SetContext (const Handle(AIS_InteractiveContext)& theCtx)
270 {
271   AIS_InteractiveObject::SetContext (theCtx);
272   for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
273   {
274     Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
275     if (!aChild.IsNull())
276     {
277       aChild->SetContext (theCtx);
278     }
279   }
280 }