0023432: Connected Interactive Objects computed without Interactive Context
[occt.git] / src / AIS / AIS_ConnectedInteractive.cxx
CommitLineData
b311480e 1// Created on: 1997-01-08
2// Created by: Robert COUBLANC
3// Copyright (c) 1997-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <Standard_NotImplemented.hxx>
24
25#include <AIS_ConnectedInteractive.ixx>
26#include <SelectMgr_EntityOwner.hxx>
27#include <Select3D_SensitiveEntity.hxx>
28#include <Geom_Transformation.hxx>
29
30#include <PrsMgr_ModedPresentation.hxx>
31#include <PrsMgr_Presentation3d.hxx>
32#include <OSD_Timer.hxx>
33
34
35//=======================================================================
36//function : AIS_ConnectedInteractive
37//purpose :
38//=======================================================================
39AIS_ConnectedInteractive::AIS_ConnectedInteractive(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
40AIS_InteractiveObject(aTypeOfPresentation3d)
41{
42 SetHilightMode(0);
43}
44
45//=======================================================================
46//function : Type
47//purpose :
48//=======================================================================
49AIS_KindOfInteractive AIS_ConnectedInteractive::Type() const
50{return AIS_KOI_Object;}
51
52Standard_Integer AIS_ConnectedInteractive::Signature() const
53{return 0; }
54
55
56
57
58//=======================================================================
59//function : Connect
60//purpose :
61//=======================================================================
62void AIS_ConnectedInteractive::
63Connect(const Handle(AIS_InteractiveObject)& anotherIObj)
64{
81bba717 65 // To have the time to Disconnect below,
66 // the old is kept for a while.
7fd59977 67 if(myReference==anotherIObj) return;
68 myOldReference = myReference;
69//Disconnect();
70 myReference = anotherIObj ;
71}
72
73//=======================================================================
74//function : Connect
75//purpose :
76//=======================================================================
77void AIS_ConnectedInteractive::
78Connect(const Handle(AIS_InteractiveObject)& anotherIobj,
79 const TopLoc_Location& aLocation)
80{
81 if(myLocation!=aLocation)
82 myLocation = aLocation;
83 if(myReference!=anotherIobj) {
81bba717 84 myOldReference = myReference; // necessary to disconnect below..
7fd59977 85// Disconnect();
86 myReference = anotherIobj;}
87
88}
89
90
91//=======================================================================
92//function : Disconnect
93//purpose :
94//=======================================================================
95
96void AIS_ConnectedInteractive::Disconnect()
97{
98 for(Standard_Integer i =1;i<=myPresentations.Length();i++)
99 {
100 Handle(PrsMgr_Presentation3d) P = Handle(PrsMgr_Presentation3d)::DownCast(myPresentations(i).Presentation());
101 if(!P.IsNull()) {
102 P->Presentation()->DisconnectAll(Graphic3d_TOC_DESCENDANT);
103 }
104 }
105}
106//=======================================================================
107//function : Compute
792c785c 108//purpose :
7fd59977 109//=======================================================================
792c785c 110void AIS_ConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
111 const Handle(Prs3d_Presentation)& thePrs,
112 const Standard_Integer theMode)
7fd59977 113{
792c785c 114 if (!(HasLocation() || HasConnection()))
115 {
116 return;
117 }
7fd59977 118
792c785c 119 if (HasConnection())
120 {
121 thePrs->Clear (Standard_False);
122 thePrs->RemoveAll();
123
124 if (!myReference->HasInteractiveContext())
125 {
126 myReference->SetContext (GetContext());
127 }
128 thePrsMgr->Connect (this, myReference, theMode, theMode);
129 if (thePrsMgr->Presentation (myReference, theMode)->MustBeUpdated())
130 {
131 thePrsMgr->Update (myReference, theMode);
132 }
133 }
134
135 if (HasLocation())
136 {
137 Handle(Geom_Transformation) aPrsTrans = new Geom_Transformation (myLocation.Transformation());
138 thePrsMgr->Transform (this, aPrsTrans, theMode);
7fd59977 139 }
792c785c 140 thePrs->ReCompute();
7fd59977 141}
142
143void AIS_ConnectedInteractive::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
144{
145// Standard_NotImplemented::Raise("AIS_ConnectedInteractive::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
146 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
147}
148
149void AIS_ConnectedInteractive::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Prs3d_Presentation& aPresentation)
150{
151// Standard_NotImplemented::Raise("AIS_ConnectedInteractive::Compute(const Handle_Prs3d_Projector&, const Handle_Prs3d_Presentation&)");
152 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
153}
154
155void AIS_ConnectedInteractive::Compute(const Handle_PrsMgr_PresentationManager2d& aPresentationManager2d, const Handle_Graphic2d_GraphicObject& aGraphicObject, const int anInteger)
156{
157// Standard_NotImplemented::Raise("AIS_ConnectedInteractive::Compute(const Handle_PrsMgr_PresentationManager2d&, const Handle_Graphic2d_GraphicObject&, const int)");
158 PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
159}
160
161//=======================================================================
162//function : ComputeSelection
163//purpose :
164//=======================================================================
ac04d101
SA
165
166void AIS_ConnectedInteractive::ComputeSelection(const Handle(SelectMgr_Selection)& aSel,
167 const Standard_Integer aMode)
7fd59977 168{
169 if(!(HasLocation() ||HasConnection())) return;
170
171 aSel->Clear();
172 if(!myReference->HasSelection(aMode))
173 myReference->UpdateSelection(aMode);
ac04d101 174
7fd59977 175 const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection(aMode);
176 Handle(SelectMgr_EntityOwner) OWN = new SelectMgr_EntityOwner(this);
ac04d101 177 Handle(Select3D_SensitiveEntity) SE3D, SNew;
7fd59977 178
179 if(TheRefSel->IsEmpty())
180 myReference->UpdateSelection(aMode);
ac04d101
SA
181 for(TheRefSel->Init();TheRefSel->More();TheRefSel->Next())
182 {
183 SE3D = Handle(Select3D_SensitiveEntity)::DownCast(TheRefSel->Sensitive());
184 if(!SE3D.IsNull())
185 {
186 // Get the copy of SE3D
7fd59977 187 SNew = SE3D->GetConnected(myLocation);
188 if(aMode==0)
ac04d101
SA
189 {
190 SNew->Set(OWN);
191 // In case if SE3D caches some location-dependent data
192 // that must be updated after setting OWN
193 SNew->SetLocation(myLocation);
194 }
7fd59977 195 aSel->Add(SNew);
196 }
197 }
7fd59977 198}
199
200void AIS_ConnectedInteractive::UpdateLocation()
201{
202// Standard_NotImplemented::Raise("AIS_ConnectedInteractive::UpdateLocation()");
203 SelectMgr_SelectableObject::UpdateLocation() ;
204}
205void AIS_ConnectedInteractive::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)
206{
207// Standard_NotImplemented::Raise("AIS_ConnectedInteractive::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)");
208 SelectMgr_SelectableObject::UpdateLocation(Sel) ;
209}
210/*void AIS_ConnectedInteractive::UpdateLocation(const Handle_Prs3d_Presentation& aPresentation)
211{
212// Standard_NotImplemented::Raise("AIS_ConnectedInteractive::UpdateLocation(const Handle_Prs3d_Presentation&)");
213 SelectMgr_SelectableObject::UpdateLocation(aPresentation) ;
214}*/