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.
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>
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>
36 IMPLEMENT_STANDARD_RTTIEXT(AIS_MultipleConnectedInteractive,AIS_InteractiveObject)
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
48 // Copies another SelectMgr_EntityOwner.
49 SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner,
50 SelectMgr_SelectableObject* theAssembly);
52 void SetAssembly (SelectMgr_SelectableObject* theAssembly)
54 myAssembly = theAssembly;
57 //! Selectable() method modified to return myAssembly.
58 virtual Handle(SelectMgr_SelectableObject) Selectable() const;
60 Standard_Boolean IsHilighted (const Handle(PrsMgr_PresentationManager)& PM,const Standard_Integer aMode) const;
62 void Hilight (const Handle(PrsMgr_PresentationManager)& PM,const Standard_Integer aMode);
64 void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& PM,
65 const Quantity_NameOfColor aColor,
66 const Standard_Integer aMode);
68 void Unhilight (const Handle(PrsMgr_PresentationManager)& PM, const Standard_Integer aMode);
72 SelectMgr_SelectableObject* myAssembly;
77 //=======================================================================
78 //function : SelectMgr_AssemblyEntityOwner
80 //=======================================================================
81 SelectMgr_AssemblyEntityOwner::SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner,
82 SelectMgr_SelectableObject* theAssembly)
84 SelectMgr_EntityOwner (theOwner),
85 myAssembly (theAssembly)
89 //=======================================================================
90 //function : Selectable
92 //=======================================================================
93 Handle(SelectMgr_SelectableObject) SelectMgr_AssemblyEntityOwner::Selectable() const
98 //=======================================================================
99 //function : IsHilighted
101 //=======================================================================
102 Standard_Boolean SelectMgr_AssemblyEntityOwner::IsHilighted (const Handle(PrsMgr_PresentationManager)& PM,
103 const Standard_Integer aMode) const
107 return PM->IsHighlighted (myAssembly, aMode);
110 return Standard_False;
113 //=======================================================================
116 //=======================================================================
117 void SelectMgr_AssemblyEntityOwner::Hilight (const Handle(PrsMgr_PresentationManager)& PM,
118 const Standard_Integer aMode)
122 PM->Highlight (myAssembly, aMode);
126 //=======================================================================
127 //function : HilightWithColor
129 //=======================================================================
130 void SelectMgr_AssemblyEntityOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& PM,
131 const Quantity_NameOfColor aColor,
132 const Standard_Integer aMode)
138 PM->Color (myAssembly, aColor, aMode);
142 myAssembly->HilightOwnerWithColor (PM, aColor, this);
147 //=======================================================================
148 //function : Unhilight
150 //=======================================================================
151 void SelectMgr_AssemblyEntityOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& PM,
152 const Standard_Integer aMode)
156 PM->Unhighlight (myAssembly, aMode);
161 //=======================================================================
162 //function : AIS_MultipleConnectedInteractive
164 //=======================================================================
166 AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive()
167 : AIS_InteractiveObject (PrsMgr_TOP_AllView)
169 myHasOwnPresentations = Standard_False;
170 myAssemblyOwner = NULL;
174 //=======================================================================
177 //=======================================================================
178 AIS_KindOfInteractive AIS_MultipleConnectedInteractive::Type() const
180 return AIS_KOI_Object;
183 //=======================================================================
184 //function : Signature
186 //=======================================================================
187 Standard_Integer AIS_MultipleConnectedInteractive::Signature() const
192 //=======================================================================
195 //=======================================================================
196 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
197 const gp_Trsf& theTransformation,
198 const Handle(Graphic3d_TransformPers)& theTrsfPers)
200 if (myAssemblyOwner.IsNull())
201 myAssemblyOwner = new SelectMgr_EntityOwner (this);
203 Handle(AIS_InteractiveObject) anObjectToAdd;
205 Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
206 if (!aMultiConnected.IsNull())
208 Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
209 aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
210 aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformation());
212 // Perform deep copy of instance tree
213 for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
215 Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
216 if (anInteractive.IsNull())
221 aNewMultiConnected->Connect (anInteractive);
224 anObjectToAdd = aNewMultiConnected;
228 Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
229 aNewConnected->Connect (theAnotherObj);
230 aNewConnected->SetLocalTransformation (theAnotherObj->LocalTransformation());
232 anObjectToAdd = aNewConnected;
235 anObjectToAdd->SetLocalTransformation (theTransformation);
236 if (!theTrsfPers.IsNull())
238 anObjectToAdd->SetTransformPersistence (theTrsfPers);
240 AddChild (anObjectToAdd);
241 return anObjectToAdd;
244 //=======================================================================
247 //=======================================================================
248 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj)
250 return Connect (theAnotherObj, theAnotherObj->LocalTransformation(), theAnotherObj->TransformPersistence());
253 //=======================================================================
256 //=======================================================================
257 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
258 const gp_Trsf& theTransformation)
260 return Connect (theAnotherObj, theTransformation, theAnotherObj->TransformPersistence());
263 //=======================================================================
264 //function : HasConnection
266 //=======================================================================
267 Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const
269 return (Children().Size() != 0);
272 //=======================================================================
273 //function : Disconnect
275 //=======================================================================
277 void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
279 RemoveChild (anotherIObj);
282 //=======================================================================
283 //function : DisconnectAll
285 //=======================================================================
287 void AIS_MultipleConnectedInteractive::DisconnectAll()
289 Standard_Integer aNbItemsToRemove = Children().Size();
290 for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
292 RemoveChild (Children().First());
296 //=======================================================================
299 //=======================================================================
300 void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
301 const Handle(Prs3d_Presentation)& /*thePrs*/,
302 const Standard_Integer /*theMode*/)
304 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
306 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
312 if (!aChild->HasInteractiveContext())
314 aChild->SetContext (GetContext());
319 //=======================================================================
322 //=======================================================================
324 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
325 const Handle(Prs3d_Presentation)& aPresentation)
327 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
330 //=======================================================================
333 //=======================================================================
335 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
336 const Handle(Geom_Transformation)& aTransformation,
337 const Handle(Prs3d_Presentation)& aPresentation)
339 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
342 //=======================================================================
343 //function : AcceptShapeDecomposition
345 //=======================================================================
346 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const
348 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
350 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
356 if (aChild->AcceptShapeDecomposition())
358 return Standard_True;
361 return Standard_False;
364 //=======================================================================
365 //function : ComputeSelection
367 //=======================================================================
368 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
369 const Standard_Integer theMode)
373 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
375 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
381 if (!aChild->HasSelection (theMode))
383 aChild->RecomputePrimitives (theMode);
386 Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
387 aChild->ComputeSelection (aSelection, theMode);
392 //=======================================================================
393 //function : GlobalSelOwner
395 //=======================================================================
396 Handle(SelectMgr_EntityOwner) AIS_MultipleConnectedInteractive::GlobalSelOwner() const
398 return myAssemblyOwner;
401 //=======================================================================
402 //function : HasSelection
404 //=======================================================================
405 Standard_Boolean AIS_MultipleConnectedInteractive::HasSelection (const Standard_Integer theMode) const
407 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
409 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
413 if (!aChild->HasSelection (theMode))
414 return Standard_False;
417 return Standard_True;