72a3a31fcf3c722941dcb6b2b1544a5808027671
[occt.git] / src / AIS / AIS_ConnectedInteractive.cxx
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
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 //=======================================================================
39 AIS_ConnectedInteractive::AIS_ConnectedInteractive(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
40 AIS_InteractiveObject(aTypeOfPresentation3d)
41 {    
42   SetHilightMode(0);
43 }
44
45 //=======================================================================
46 //function : Type
47 //purpose  : 
48 //=======================================================================
49 AIS_KindOfInteractive AIS_ConnectedInteractive::Type() const
50 {return AIS_KOI_Object;}
51
52 Standard_Integer AIS_ConnectedInteractive::Signature() const
53 {return 0; }
54
55
56
57
58 //=======================================================================
59 //function : Connect
60 //purpose  : 
61 //=======================================================================
62 void AIS_ConnectedInteractive::
63 Connect(const Handle(AIS_InteractiveObject)& anotherIObj)
64 {
65   // To have the time to Disconnect below, 
66   // the old is kept for a while. 
67   if(myReference==anotherIObj) return;
68   myOldReference = myReference;
69 //Disconnect();
70   myReference = anotherIObj ;
71 }
72
73 //=======================================================================
74 //function : Connect
75 //purpose  : 
76 //=======================================================================
77 void AIS_ConnectedInteractive::
78 Connect(const Handle(AIS_InteractiveObject)& anotherIobj, 
79         const TopLoc_Location& aLocation)
80 {
81   if(myLocation!=aLocation)
82     myLocation = aLocation;
83   if(myReference!=anotherIobj) {
84     myOldReference = myReference; // necessary to disconnect below..
85 //  Disconnect();
86     myReference = anotherIobj;}
87   
88 }
89
90
91 //=======================================================================
92 //function : Disconnect
93 //purpose  : 
94 //=======================================================================
95
96 void 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
108 //purpose  :
109 //=======================================================================
110 void AIS_ConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
111                                         const Handle(Prs3d_Presentation)&           thePrs,
112                                         const Standard_Integer                      theMode)
113 {
114   if (!(HasLocation() || HasConnection()))
115   {
116     return;
117   }
118
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);
139   }
140   thePrs->ReCompute();
141 }
142
143 void 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
149 void 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
155 void 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 //=======================================================================
165
166 void AIS_ConnectedInteractive::ComputeSelection(const Handle(SelectMgr_Selection)& aSel, 
167                                                 const Standard_Integer aMode)
168 {
169   if(!(HasLocation() ||HasConnection())) return;
170   
171   aSel->Clear();
172   if(!myReference->HasSelection(aMode))
173     myReference->UpdateSelection(aMode);
174
175   const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection(aMode);
176   Handle(SelectMgr_EntityOwner) OWN = new SelectMgr_EntityOwner(this);
177   Handle(Select3D_SensitiveEntity) SE3D, SNew;
178   
179   if(TheRefSel->IsEmpty())
180     myReference->UpdateSelection(aMode);
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
187       SNew = SE3D->GetConnected(myLocation);
188       if(aMode==0)
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       }
195       aSel->Add(SNew);
196     }
197   }
198 }
199
200 void AIS_ConnectedInteractive::UpdateLocation()
201 {
202 // Standard_NotImplemented::Raise("AIS_ConnectedInteractive::UpdateLocation()");
203  SelectMgr_SelectableObject::UpdateLocation() ;
204 }
205 void 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 }*/