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 Graphic3d_TransModeFlags& theTrsfPersFlag,
199 const gp_Pnt& theTrsfPersPoint)
201 if (myAssemblyOwner.IsNull())
202 myAssemblyOwner = new SelectMgr_EntityOwner (this);
204 Handle(AIS_InteractiveObject) anObjectToAdd;
206 Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
207 if (!aMultiConnected.IsNull())
209 Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
210 aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
211 aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformation());
213 // Perform deep copy of instance tree
214 for (PrsMgr_ListOfPresentableObjectsIter anIter (aMultiConnected->Children()); anIter.More(); anIter.Next())
216 Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
217 if (anInteractive.IsNull())
222 aNewMultiConnected->Connect (anInteractive);
225 anObjectToAdd = aNewMultiConnected;
229 Handle(AIS_ConnectedInteractive) aNewConnected = new AIS_ConnectedInteractive();
230 aNewConnected->Connect (theAnotherObj);
231 aNewConnected->SetLocalTransformation (theAnotherObj->LocalTransformation());
233 anObjectToAdd = aNewConnected;
236 anObjectToAdd->SetLocalTransformation (theTransformation);
237 if (theTrsfPersFlag != Graphic3d_TMF_None)
239 anObjectToAdd->SetTransformPersistence (theTrsfPersFlag, theTrsfPersPoint);
241 AddChild (anObjectToAdd);
242 return anObjectToAdd;
245 //=======================================================================
248 //=======================================================================
249 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj)
251 return Connect (theAnotherObj, theAnotherObj->LocalTransformation(),
252 theAnotherObj->GetTransformPersistenceMode(),
253 theAnotherObj->GetTransformPersistencePoint());
256 //=======================================================================
259 //=======================================================================
260 Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
261 const gp_Trsf& theTransformation)
263 return Connect (theAnotherObj, theTransformation,
264 theAnotherObj->GetTransformPersistenceMode(),
265 theAnotherObj->GetTransformPersistencePoint());
268 //=======================================================================
269 //function : HasConnection
271 //=======================================================================
272 Standard_Boolean AIS_MultipleConnectedInteractive::HasConnection() const
274 return (Children().Size() != 0);
277 //=======================================================================
278 //function : Disconnect
280 //=======================================================================
282 void AIS_MultipleConnectedInteractive::Disconnect(const Handle(AIS_InteractiveObject)& anotherIObj)
284 RemoveChild (anotherIObj);
287 //=======================================================================
288 //function : DisconnectAll
290 //=======================================================================
292 void AIS_MultipleConnectedInteractive::DisconnectAll()
294 Standard_Integer aNbItemsToRemove = Children().Size();
295 for (Standard_Integer anIter = 0; anIter < aNbItemsToRemove; ++anIter)
297 RemoveChild (Children().First());
301 //=======================================================================
304 //=======================================================================
305 void AIS_MultipleConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
306 const Handle(Prs3d_Presentation)& /*thePrs*/,
307 const Standard_Integer /*theMode*/)
309 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
311 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
317 if (!aChild->HasInteractiveContext())
319 aChild->SetContext (GetContext());
324 //=======================================================================
327 //=======================================================================
329 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
330 const Handle(Prs3d_Presentation)& aPresentation)
332 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
335 //=======================================================================
338 //=======================================================================
340 void AIS_MultipleConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector,
341 const Handle(Geom_Transformation)& aTransformation,
342 const Handle(Prs3d_Presentation)& aPresentation)
344 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
347 //=======================================================================
348 //function : AcceptShapeDecomposition
350 //=======================================================================
351 Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() const
353 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
355 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
361 if (aChild->AcceptShapeDecomposition())
363 return Standard_True;
366 return Standard_False;
369 //=======================================================================
370 //function : ComputeSelection
372 //=======================================================================
373 void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
374 const Standard_Integer theMode)
378 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
380 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
386 if (!aChild->HasSelection (theMode))
388 aChild->RecomputePrimitives (theMode);
391 Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
392 aChild->ComputeSelection (aSelection, theMode);
397 //=======================================================================
398 //function : GlobalSelOwner
400 //=======================================================================
401 Handle(SelectMgr_EntityOwner) AIS_MultipleConnectedInteractive::GlobalSelOwner() const
403 return myAssemblyOwner;
406 //=======================================================================
407 //function : HasSelection
409 //=======================================================================
410 Standard_Boolean AIS_MultipleConnectedInteractive::HasSelection (const Standard_Integer theMode) const
412 for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
414 Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
418 if (!aChild->HasSelection (theMode))
419 return Standard_False;
422 return Standard_True;