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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_MultipleConnectedInteractive.hxx>
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>
29 IMPLEMENT_STANDARD_RTTIEXT(AIS_MultipleConnectedInteractive,AIS_InteractiveObject)
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
41 // Copies another SelectMgr_EntityOwner.
42 SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner,
43 SelectMgr_SelectableObject* theAssembly);
45 void SetAssembly (SelectMgr_SelectableObject* theAssembly)
47 myAssembly = theAssembly;
50 //! Selectable() method modified to return myAssembly.
51 virtual Handle(SelectMgr_SelectableObject) Selectable() const;
53 Standard_Boolean IsHilighted (const Handle(PrsMgr_PresentationManager)& PM,const Standard_Integer aMode) const;
55 void Hilight (const Handle(PrsMgr_PresentationManager)& PM,const Standard_Integer aMode);
57 void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& PM,
58 const Quantity_NameOfColor aColor,
59 const Standard_Integer aMode);
61 void Unhilight (const Handle(PrsMgr_PresentationManager)& PM, const Standard_Integer aMode);
65 SelectMgr_SelectableObject* myAssembly;
70 //=======================================================================
71 //function : SelectMgr_AssemblyEntityOwner
73 //=======================================================================
74 SelectMgr_AssemblyEntityOwner::SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner,
75 SelectMgr_SelectableObject* theAssembly)
77 SelectMgr_EntityOwner (theOwner),
78 myAssembly (theAssembly)
82 //=======================================================================
83 //function : Selectable
85 //=======================================================================
86 Handle(SelectMgr_SelectableObject) SelectMgr_AssemblyEntityOwner::Selectable() const
91 //=======================================================================
92 //function : IsHilighted
94 //=======================================================================
95 Standard_Boolean SelectMgr_AssemblyEntityOwner::IsHilighted (const Handle(PrsMgr_PresentationManager)& PM,
96 const Standard_Integer aMode) const
100 return PM->IsHighlighted (myAssembly, aMode);
103 return Standard_False;
106 //=======================================================================
109 //=======================================================================
110 void SelectMgr_AssemblyEntityOwner::Hilight (const Handle(PrsMgr_PresentationManager)& PM,
111 const Standard_Integer aMode)
115 PM->Highlight (myAssembly, aMode);
119 //=======================================================================
120 //function : HilightWithColor
122 //=======================================================================
123 void SelectMgr_AssemblyEntityOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& PM,
124 const Quantity_NameOfColor aColor,
125 const Standard_Integer aMode)
131 PM->Color (myAssembly, aColor, aMode);
135 myAssembly->HilightOwnerWithColor (PM, aColor, this);
140 //=======================================================================
141 //function : Unhilight
143 //=======================================================================
144 void SelectMgr_AssemblyEntityOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& PM,
145 const Standard_Integer aMode)
149 PM->Unhighlight (myAssembly, aMode);
154 //=======================================================================
155 //function : AIS_MultipleConnectedInteractive
157 //=======================================================================
159 AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive()
160 : AIS_InteractiveObject (PrsMgr_TOP_AllView)
162 myHasOwnPresentations = Standard_False;
163 myAssemblyOwner = NULL;
167 //=======================================================================
170 //=======================================================================
171 AIS_KindOfInteractive AIS_MultipleConnectedInteractive::Type() const
173 return AIS_KOI_Object;
176 //=======================================================================
177 //function : Signature
179 //=======================================================================
180 Standard_Integer AIS_MultipleConnectedInteractive::Signature() const
185 //=======================================================================
188 //=======================================================================
189 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
190 const Handle(Geom_Transformation)& theTrsf,
191 const Handle(Graphic3d_TransformPers)& theTrsfPers)
193 if (myAssemblyOwner.IsNull())
194 myAssemblyOwner = new SelectMgr_EntityOwner (this);
196 Handle(AIS_InteractiveObject) anObjectToAdd;
198 Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
199 if (!aMultiConnected.IsNull())
201 Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
202 aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
203 aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformationGeom());
205 // Perform deep copy of instance tree
206 for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
208 Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
209 if (anInteractive.IsNull())
214 aNewMultiConnected->Connect (anInteractive);
217 anObjectToAdd = aNewMultiConnected;
221 Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
222 aNewConnected->Connect (theAnotherObj, theAnotherObj->LocalTransformationGeom());
224 anObjectToAdd = aNewConnected;
227 anObjectToAdd->SetLocalTransformation (theTrsf);
228 if (!theTrsfPers.IsNull())
230 anObjectToAdd->SetTransformPersistence (theTrsfPers);
232 AddChild (anObjectToAdd);
233 return anObjectToAdd;
236 //=======================================================================
237 //function : HasConnection
239 //=======================================================================
240 Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const
242 return (Children().Size() != 0);
245 //=======================================================================
246 //function : Disconnect
248 //=======================================================================
250 void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
252 RemoveChild (anotherIObj);
255 //=======================================================================
256 //function : DisconnectAll
258 //=======================================================================
260 void AIS_MultipleConnectedInteractive::DisconnectAll()
262 Standard_Integer aNbItemsToRemove = Children().Size();
263 for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
265 RemoveChild (Children().First());
269 //=======================================================================
272 //=======================================================================
273 void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
274 const Handle(Prs3d_Presentation)& /*thePrs*/,
275 const Standard_Integer /*theMode*/)
277 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
279 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
285 if (!aChild->HasInteractiveContext())
287 aChild->SetContext (GetContext());
292 //=======================================================================
295 //=======================================================================
297 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
298 const Handle(Prs3d_Presentation)& aPresentation)
300 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
303 //=======================================================================
306 //=======================================================================
308 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
309 const Handle(Geom_Transformation)& aTransformation,
310 const Handle(Prs3d_Presentation)& aPresentation)
312 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
315 //=======================================================================
316 //function : AcceptShapeDecomposition
318 //=======================================================================
319 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const
321 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
323 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
329 if (aChild->AcceptShapeDecomposition())
331 return Standard_True;
334 return Standard_False;
337 //=======================================================================
338 //function : ComputeSelection
340 //=======================================================================
341 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
342 const Standard_Integer theMode)
346 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
348 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
354 if (!aChild->HasSelection (theMode))
356 aChild->RecomputePrimitives (theMode);
359 Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
360 aChild->ComputeSelection (aSelection, theMode);
365 //=======================================================================
366 //function : GlobalSelOwner
368 //=======================================================================
369 Handle(SelectMgr_EntityOwner) AIS_MultipleConnectedInteractive::GlobalSelOwner() const
371 return myAssemblyOwner;
374 //=======================================================================
375 //function : HasSelection
377 //=======================================================================
378 Standard_Boolean AIS_MultipleConnectedInteractive::HasSelection (const Standard_Integer theMode) const
380 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
382 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
386 if (!aChild->HasSelection (theMode))
387 return Standard_False;
390 return Standard_True;