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 <Standard_NotImplemented.hxx>
19 #include <AIS_MultipleConnectedInteractive.ixx>
20 #include <AIS_ConnectedInteractive.hxx>
21 #include <AIS_InteractiveContext.hxx>
23 #include <PrsMgr_ModedPresentation.hxx>
24 #include <PrsMgr_Presentation.hxx>
25 #include <SelectMgr_EntityOwner.hxx>
26 #include <Select3D_SensitiveEntity.hxx>
27 #include <TopLoc_Location.hxx>
28 #include <NCollection_DataMap.hxx>
29 #include <AIS_InteractiveObject.hxx>
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 gp_Trsf& theTransformation,
191 const Graphic3d_TransModeFlags& theTrsfPersFlag,
192 const gp_Pnt& theTrsfPersPoint)
194 if (myAssemblyOwner.IsNull())
195 myAssemblyOwner = new SelectMgr_EntityOwner (this);
197 Handle(AIS_InteractiveObject) anObjectToAdd;
199 Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
200 if (!aMultiConnected.IsNull())
202 Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
203 aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
204 aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformation());
206 // Perform deep copy of instance tree
207 for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
209 Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
210 if (anInteractive.IsNull())
215 aNewMultiConnected->Connect (anInteractive);
218 anObjectToAdd = aNewMultiConnected;
222 Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
223 aNewConnected->Connect (theAnotherObj);
224 aNewConnected->SetLocalTransformation (theAnotherObj->LocalTransformation());
226 anObjectToAdd = aNewConnected;
229 anObjectToAdd->SetLocalTransformation (theTransformation);
230 if (theTrsfPersFlag != Graphic3d_TMF_None)
232 anObjectToAdd->SetTransformPersistence (theTrsfPersFlag, theTrsfPersPoint);
234 AddChild (anObjectToAdd);
235 return anObjectToAdd;
238 //=======================================================================
241 //=======================================================================
242 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj)
244 return Connect (theAnotherObj, theAnotherObj->LocalTransformation(),
245 theAnotherObj->GetTransformPersistenceMode(),
246 theAnotherObj->GetTransformPersistencePoint());
249 //=======================================================================
252 //=======================================================================
253 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
254 const gp_Trsf& theTransformation)
256 return Connect (theAnotherObj, theTransformation,
257 theAnotherObj->GetTransformPersistenceMode(),
258 theAnotherObj->GetTransformPersistencePoint());
261 //=======================================================================
262 //function : HasConnection
264 //=======================================================================
265 Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const
267 return (Children().Size() != 0);
270 //=======================================================================
271 //function : Disconnect
273 //=======================================================================
275 void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
277 RemoveChild (anotherIObj);
280 //=======================================================================
281 //function : DisconnectAll
283 //=======================================================================
285 void AIS_MultipleConnectedInteractive::DisconnectAll()
287 Standard_Integer aNbItemsToRemove = Children().Size();
288 for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
290 RemoveChild (Children().First());
294 //=======================================================================
297 //=======================================================================
298 void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
299 const Handle(Prs3d_Presentation)& /*thePrs*/,
300 const Standard_Integer /*theMode*/)
302 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
304 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
310 if (!aChild->HasInteractiveContext())
312 aChild->SetContext (GetContext());
317 //=======================================================================
320 //=======================================================================
322 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
323 const Handle(Prs3d_Presentation)& aPresentation)
325 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
328 //=======================================================================
331 //=======================================================================
333 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
334 const Handle(Geom_Transformation)& aTransformation,
335 const Handle(Prs3d_Presentation)& aPresentation)
337 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
340 //=======================================================================
341 //function : AcceptShapeDecomposition
343 //=======================================================================
344 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const
346 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
348 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
354 if (aChild->AcceptShapeDecomposition())
356 return Standard_True;
359 return Standard_False;
362 //=======================================================================
363 //function : ComputeSelection
365 //=======================================================================
366 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
367 const Standard_Integer theMode)
371 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
373 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
379 if (!aChild->HasSelection (theMode))
381 aChild->RecomputePrimitives (theMode);
384 Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
385 aChild->ComputeSelection (aSelection, theMode);