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 HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
56 const Handle(Graphic3d_HighlightStyle)& theStyle,
57 const Standard_Integer theMode);
59 void Unhilight (const Handle(PrsMgr_PresentationManager)& PM, const Standard_Integer aMode);
63 SelectMgr_SelectableObject* myAssembly;
68 //=======================================================================
69 //function : SelectMgr_AssemblyEntityOwner
71 //=======================================================================
72 SelectMgr_AssemblyEntityOwner::SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner,
73 SelectMgr_SelectableObject* theAssembly)
75 SelectMgr_EntityOwner (theOwner),
76 myAssembly (theAssembly)
80 //=======================================================================
81 //function : Selectable
83 //=======================================================================
84 Handle(SelectMgr_SelectableObject) SelectMgr_AssemblyEntityOwner::Selectable() const
89 //=======================================================================
90 //function : IsHilighted
92 //=======================================================================
93 Standard_Boolean SelectMgr_AssemblyEntityOwner::IsHilighted (const Handle(PrsMgr_PresentationManager)& PM,
94 const Standard_Integer aMode) const
98 return PM->IsHighlighted (myAssembly, aMode);
101 return Standard_False;
104 //=======================================================================
105 //function : HilightWithColor
107 //=======================================================================
108 void SelectMgr_AssemblyEntityOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
109 const Handle(Graphic3d_HighlightStyle)& theStyle,
110 const Standard_Integer theMode)
116 thePM->Color (myAssembly, theStyle, theMode);
120 myAssembly->HilightOwnerWithColor (thePM, theStyle, this);
125 //=======================================================================
126 //function : Unhilight
128 //=======================================================================
129 void SelectMgr_AssemblyEntityOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& PM,
130 const Standard_Integer aMode)
134 PM->Unhighlight (myAssembly, aMode);
139 //=======================================================================
140 //function : AIS_MultipleConnectedInteractive
142 //=======================================================================
144 AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive()
145 : AIS_InteractiveObject (PrsMgr_TOP_AllView)
147 myHasOwnPresentations = Standard_False;
148 myAssemblyOwner = NULL;
152 //=======================================================================
155 //=======================================================================
156 AIS_KindOfInteractive AIS_MultipleConnectedInteractive::Type() const
158 return AIS_KOI_Object;
161 //=======================================================================
162 //function : Signature
164 //=======================================================================
165 Standard_Integer AIS_MultipleConnectedInteractive::Signature() const
170 //=======================================================================
173 //=======================================================================
174 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
175 const Handle(Geom_Transformation)& theTrsf,
176 const Handle(Graphic3d_TransformPers)& theTrsfPers)
178 if (myAssemblyOwner.IsNull())
179 myAssemblyOwner = new SelectMgr_EntityOwner (this);
181 Handle(AIS_InteractiveObject) anObjectToAdd;
183 Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
184 if (!aMultiConnected.IsNull())
186 Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
187 aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
188 aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformationGeom());
190 // Perform deep copy of instance tree
191 for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
193 Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
194 if (anInteractive.IsNull())
199 aNewMultiConnected->Connect (anInteractive);
202 anObjectToAdd = aNewMultiConnected;
206 Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
207 aNewConnected->Connect (theAnotherObj, theAnotherObj->LocalTransformationGeom());
209 anObjectToAdd = aNewConnected;
212 anObjectToAdd->SetLocalTransformation (theTrsf);
213 if (!theTrsfPers.IsNull())
215 anObjectToAdd->SetTransformPersistence (theTrsfPers);
217 AddChild (anObjectToAdd);
218 return anObjectToAdd;
221 //=======================================================================
222 //function : HasConnection
224 //=======================================================================
225 Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const
227 return (Children().Size() != 0);
230 //=======================================================================
231 //function : Disconnect
233 //=======================================================================
235 void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
237 RemoveChild (anotherIObj);
240 //=======================================================================
241 //function : DisconnectAll
243 //=======================================================================
245 void AIS_MultipleConnectedInteractive::DisconnectAll()
247 Standard_Integer aNbItemsToRemove = Children().Size();
248 for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
250 RemoveChild (Children().First());
254 //=======================================================================
257 //=======================================================================
258 void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
259 const Handle(Prs3d_Presentation)& /*thePrs*/,
260 const Standard_Integer /*theMode*/)
262 Handle(AIS_InteractiveContext) aCtx = GetContext();
263 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
265 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
266 if (!aChild.IsNull())
268 aChild->SetContext (aCtx);
273 //=======================================================================
276 //=======================================================================
278 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
279 const Handle(Prs3d_Presentation)& aPresentation)
281 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
284 //=======================================================================
287 //=======================================================================
289 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
290 const Handle(Geom_Transformation)& aTransformation,
291 const Handle(Prs3d_Presentation)& aPresentation)
293 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
296 //=======================================================================
297 //function : AcceptShapeDecomposition
299 //=======================================================================
300 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const
302 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
304 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
310 if (aChild->AcceptShapeDecomposition())
312 return Standard_True;
315 return Standard_False;
318 //=======================================================================
319 //function : ComputeSelection
321 //=======================================================================
322 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
323 const Standard_Integer theMode)
327 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
329 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
335 if (!aChild->HasSelection (theMode))
337 aChild->RecomputePrimitives (theMode);
340 Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
341 aChild->ComputeSelection (aSelection, theMode);
346 //=======================================================================
347 //function : GlobalSelOwner
349 //=======================================================================
350 Handle(SelectMgr_EntityOwner) AIS_MultipleConnectedInteractive::GlobalSelOwner() const
352 return myAssemblyOwner;
355 //=======================================================================
356 //function : HasSelection
358 //=======================================================================
359 Standard_Boolean AIS_MultipleConnectedInteractive::HasSelection (const Standard_Integer theMode) const
361 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
363 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
367 if (!aChild->HasSelection (theMode))
368 return Standard_False;
371 return Standard_True;
374 //=======================================================================
375 //function : SetContext
377 //=======================================================================
378 void AIS_MultipleConnectedInteractive::SetContext (const Handle(AIS_InteractiveContext)& theCtx)
380 AIS_InteractiveObject::SetContext (theCtx);
381 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
383 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
384 if (!aChild.IsNull())
386 aChild->SetContext (theCtx);