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