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 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
264 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
270 if (!aChild->HasInteractiveContext())
272 aChild->SetContext (GetContext());
277 //=======================================================================
280 //=======================================================================
282 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
283 const Handle(Prs3d_Presentation)& aPresentation)
285 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
288 //=======================================================================
291 //=======================================================================
293 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
294 const Handle(Geom_Transformation)& aTransformation,
295 const Handle(Prs3d_Presentation)& aPresentation)
297 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
300 //=======================================================================
301 //function : AcceptShapeDecomposition
303 //=======================================================================
304 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const
306 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
308 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
314 if (aChild->AcceptShapeDecomposition())
316 return Standard_True;
319 return Standard_False;
322 //=======================================================================
323 //function : ComputeSelection
325 //=======================================================================
326 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
327 const Standard_Integer theMode)
331 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
333 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
339 if (!aChild->HasSelection (theMode))
341 aChild->RecomputePrimitives (theMode);
344 Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
345 aChild->ComputeSelection (aSelection, theMode);
350 //=======================================================================
351 //function : GlobalSelOwner
353 //=======================================================================
354 Handle(SelectMgr_EntityOwner) AIS_MultipleConnectedInteractive::GlobalSelOwner() const
356 return myAssemblyOwner;
359 //=======================================================================
360 //function : HasSelection
362 //=======================================================================
363 Standard_Boolean AIS_MultipleConnectedInteractive::HasSelection (const Standard_Integer theMode) const
365 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
367 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
371 if (!aChild->HasSelection (theMode))
372 return Standard_False;
375 return Standard_True;