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>
38 //! SelectMgr_AssemblyEntityOwner replaces original owners in sensitive entities
39 //! copied from reference objects to AIS_MultipleConnectedInteractive in order to
40 //! redirect all selection queries to multiply connected (assembly).
41 class SelectMgr_AssemblyEntityOwner : public SelectMgr_EntityOwner
46 // Copies another SelectMgr_EntityOwner.
47 SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner,
48 SelectMgr_SelectableObject* theAssembly);
50 void SetAssembly (SelectMgr_SelectableObject* theAssembly)
52 myAssembly = theAssembly;
55 //! Selectable() method modified to return myAssembly.
56 virtual Handle(SelectMgr_SelectableObject) Selectable() const;
58 Standard_Boolean IsHilighted (const Handle(PrsMgr_PresentationManager)& PM,const Standard_Integer aMode) const;
60 void Hilight (const Handle(PrsMgr_PresentationManager)& PM,const Standard_Integer aMode);
62 void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& PM,
63 const Quantity_NameOfColor aColor,
64 const Standard_Integer aMode);
66 void Unhilight (const Handle(PrsMgr_PresentationManager)& PM, const Standard_Integer aMode);
70 SelectMgr_SelectableObject* myAssembly;
75 //=======================================================================
76 //function : SelectMgr_AssemblyEntityOwner
78 //=======================================================================
79 SelectMgr_AssemblyEntityOwner::SelectMgr_AssemblyEntityOwner (const Handle(SelectMgr_EntityOwner) theOwner,
80 SelectMgr_SelectableObject* theAssembly)
82 SelectMgr_EntityOwner (theOwner),
83 myAssembly (theAssembly)
87 //=======================================================================
88 //function : Selectable
90 //=======================================================================
91 Handle(SelectMgr_SelectableObject) SelectMgr_AssemblyEntityOwner::Selectable() const
96 //=======================================================================
97 //function : IsHilighted
99 //=======================================================================
100 Standard_Boolean SelectMgr_AssemblyEntityOwner::IsHilighted (const Handle(PrsMgr_PresentationManager)& PM,
101 const Standard_Integer aMode) const
105 return PM->IsHighlighted (myAssembly, aMode);
108 return Standard_False;
111 //=======================================================================
114 //=======================================================================
115 void SelectMgr_AssemblyEntityOwner::Hilight (const Handle(PrsMgr_PresentationManager)& PM,
116 const Standard_Integer aMode)
120 PM->Highlight (myAssembly, aMode);
124 //=======================================================================
125 //function : HilightWithColor
127 //=======================================================================
128 void SelectMgr_AssemblyEntityOwner::HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& PM,
129 const Quantity_NameOfColor aColor,
130 const Standard_Integer aMode)
136 PM->Color (myAssembly, aColor, aMode);
140 myAssembly->HilightOwnerWithColor (PM, aColor, this);
145 //=======================================================================
146 //function : Unhilight
148 //=======================================================================
149 void SelectMgr_AssemblyEntityOwner::Unhilight (const Handle(PrsMgr_PresentationManager)& PM,
150 const Standard_Integer aMode)
154 PM->Unhighlight (myAssembly, aMode);
159 //=======================================================================
160 //function : AIS_MultipleConnectedInteractive
162 //=======================================================================
164 AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive()
165 : AIS_InteractiveObject (PrsMgr_TOP_AllView)
167 myHasOwnPresentations = Standard_False;
168 myAssemblyOwner = NULL;
172 //=======================================================================
175 //=======================================================================
176 AIS_KindOfInteractive AIS_MultipleConnectedInteractive::Type() const
178 return AIS_KOI_Object;
181 //=======================================================================
182 //function : Signature
184 //=======================================================================
185 Standard_Integer AIS_MultipleConnectedInteractive::Signature() const
190 //=======================================================================
193 //=======================================================================
194 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
195 const gp_Trsf& theTransformation,
196 const Graphic3d_TransModeFlags& theTrsfPersFlag,
197 const gp_Pnt& theTrsfPersPoint)
199 if (myAssemblyOwner.IsNull())
200 myAssemblyOwner = new SelectMgr_EntityOwner (this);
202 Handle(AIS_InteractiveObject) anObjectToAdd;
204 Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
205 if (!aMultiConnected.IsNull())
207 Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
208 aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
209 aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformation());
211 // Perform deep copy of instance tree
212 for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
214 Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
215 if (anInteractive.IsNull())
220 aNewMultiConnected->Connect (anInteractive);
223 anObjectToAdd = aNewMultiConnected;
227 Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
228 aNewConnected->Connect (theAnotherObj);
229 aNewConnected->SetLocalTransformation (theAnotherObj->LocalTransformation());
231 anObjectToAdd = aNewConnected;
234 anObjectToAdd->SetLocalTransformation (theTransformation);
235 if (theTrsfPersFlag != Graphic3d_TMF_None)
237 anObjectToAdd->SetTransformPersistence (theTrsfPersFlag, theTrsfPersPoint);
239 AddChild (anObjectToAdd);
240 return anObjectToAdd;
243 //=======================================================================
246 //=======================================================================
247 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj)
249 return Connect (theAnotherObj, theAnotherObj->LocalTransformation(),
250 theAnotherObj->GetTransformPersistenceMode(),
251 theAnotherObj->GetTransformPersistencePoint());
254 //=======================================================================
257 //=======================================================================
258 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
259 const gp_Trsf& theTransformation)
261 return Connect (theAnotherObj, theTransformation,
262 theAnotherObj->GetTransformPersistenceMode(),
263 theAnotherObj->GetTransformPersistencePoint());
266 //=======================================================================
267 //function : HasConnection
269 //=======================================================================
270 Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const
272 return (Children().Size() != 0);
275 //=======================================================================
276 //function : Disconnect
278 //=======================================================================
280 void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
282 RemoveChild (anotherIObj);
285 //=======================================================================
286 //function : DisconnectAll
288 //=======================================================================
290 void AIS_MultipleConnectedInteractive::DisconnectAll()
292 Standard_Integer aNbItemsToRemove = Children().Size();
293 for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
295 RemoveChild (Children().First());
299 //=======================================================================
302 //=======================================================================
303 void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
304 const Handle(Prs3d_Presentation)& /*thePrs*/,
305 const Standard_Integer /*theMode*/)
307 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
309 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
315 if (!aChild->HasInteractiveContext())
317 aChild->SetContext (GetContext());
322 //=======================================================================
325 //=======================================================================
327 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
328 const Handle(Prs3d_Presentation)& aPresentation)
330 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
333 //=======================================================================
336 //=======================================================================
338 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
339 const Handle(Geom_Transformation)& aTransformation,
340 const Handle(Prs3d_Presentation)& aPresentation)
342 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
345 //=======================================================================
346 //function : AcceptShapeDecomposition
348 //=======================================================================
349 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const
351 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
353 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
359 if (aChild->AcceptShapeDecomposition())
361 return Standard_True;
364 return Standard_False;
367 //=======================================================================
368 //function : ComputeSelection
370 //=======================================================================
371 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
372 const Standard_Integer theMode)
376 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
378 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
384 if (!aChild->HasSelection (theMode))
386 aChild->RecomputePrimitives (theMode);
389 Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
390 aChild->ComputeSelection (aSelection, theMode);