0024428: Implementation of LGPL license
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public 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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Standard_NotImplemented.hxx>
18
19 #include <AIS_ConnectedInteractive.ixx>
20 #include <SelectMgr_EntityOwner.hxx>
21 #include <Select3D_SensitiveEntity.hxx>
22 #include <Geom_Transformation.hxx>
23
24 #include <PrsMgr_ModedPresentation.hxx>
25 #include <PrsMgr_Presentation3d.hxx>
26 #include <OSD_Timer.hxx>
27
28
29 //=======================================================================
30 //function : AIS_ConnectedInteractive
31 //purpose  : 
32 //=======================================================================
33 AIS_ConnectedInteractive::AIS_ConnectedInteractive(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
34 AIS_InteractiveObject(aTypeOfPresentation3d)
35 {    
36   SetHilightMode(0);
37 }
38
39 //=======================================================================
40 //function : Type
41 //purpose  : 
42 //=======================================================================
43 AIS_KindOfInteractive AIS_ConnectedInteractive::Type() const
44 {return AIS_KOI_Object;}
45
46 Standard_Integer AIS_ConnectedInteractive::Signature() const
47 {return 0; }
48
49
50
51
52 //=======================================================================
53 //function : Connect
54 //purpose  : 
55 //=======================================================================
56 void AIS_ConnectedInteractive::
57 Connect(const Handle(AIS_InteractiveObject)& anotherIObj)
58 {
59   // To have the time to Disconnect below, 
60   // the old is kept for a while. 
61   if(myReference==anotherIObj) return;
62   myOldReference = myReference;
63 //Disconnect();
64   myReference = anotherIObj ;
65 }
66
67 //=======================================================================
68 //function : Connect
69 //purpose  : 
70 //=======================================================================
71 void AIS_ConnectedInteractive::
72 Connect(const Handle(AIS_InteractiveObject)& anotherIobj, 
73         const TopLoc_Location& aLocation)
74 {
75   if(myLocation!=aLocation)
76     myLocation = aLocation;
77   if(myReference!=anotherIobj) {
78     myOldReference = myReference; // necessary to disconnect below..
79 //  Disconnect();
80     myReference = anotherIobj;}
81   
82 }
83
84
85 //=======================================================================
86 //function : Disconnect
87 //purpose  : 
88 //=======================================================================
89
90 void AIS_ConnectedInteractive::Disconnect()
91 {
92   for(Standard_Integer i =1;i<=myPresentations.Length();i++)
93     {
94       Handle(PrsMgr_Presentation3d) P = Handle(PrsMgr_Presentation3d)::DownCast(myPresentations(i).Presentation());
95       if(!P.IsNull()) {
96         P->Presentation()->DisconnectAll(Graphic3d_TOC_DESCENDANT);
97       }
98     }
99 }
100 //=======================================================================
101 //function : Compute
102 //purpose  :
103 //=======================================================================
104 void AIS_ConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
105                                         const Handle(Prs3d_Presentation)&           thePrs,
106                                         const Standard_Integer                      theMode)
107 {
108   if (!(HasLocation() || HasConnection()))
109   {
110     return;
111   }
112
113   if (HasConnection())
114   {
115     thePrs->Clear (Standard_False);
116     thePrs->RemoveAll();
117
118     if (!myReference->HasInteractiveContext())
119     {
120       myReference->SetContext (GetContext());
121     }
122     thePrsMgr->Connect (this, myReference, theMode, theMode);
123     if (thePrsMgr->Presentation (myReference, theMode)->MustBeUpdated())
124     {
125       thePrsMgr->Update (myReference, theMode);
126     }
127   }
128
129   if (HasLocation())
130   {
131     Handle(Geom_Transformation) aPrsTrans = new Geom_Transformation (myLocation.Transformation());
132     thePrsMgr->Transform (this, aPrsTrans, theMode);
133   }
134   thePrs->ReCompute();
135 }
136
137 void AIS_ConnectedInteractive::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
138 {
139 // Standard_NotImplemented::Raise("AIS_ConnectedInteractive::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
140   PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
141 }
142
143 void AIS_ConnectedInteractive::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Prs3d_Presentation& aPresentation)
144 {
145 // Standard_NotImplemented::Raise("AIS_ConnectedInteractive::Compute(const Handle_Prs3d_Projector&, const Handle_Prs3d_Presentation&)");
146  PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
147 }
148
149 //=======================================================================
150 //function : ComputeSelection
151 //purpose  : 
152 //=======================================================================
153
154 void AIS_ConnectedInteractive::ComputeSelection(const Handle(SelectMgr_Selection)& aSel, 
155                                                 const Standard_Integer aMode)
156 {
157   if(!(HasLocation() ||HasConnection())) return;
158   
159   aSel->Clear();
160   if(!myReference->HasSelection(aMode))
161     myReference->UpdateSelection(aMode);
162
163   const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection(aMode);
164   Handle(SelectMgr_EntityOwner) OWN = new SelectMgr_EntityOwner(this);
165   Handle(Select3D_SensitiveEntity) SE3D, SNew;
166   
167   if(TheRefSel->IsEmpty())
168     myReference->UpdateSelection(aMode);
169   for(TheRefSel->Init();TheRefSel->More();TheRefSel->Next())
170   {
171     SE3D = Handle(Select3D_SensitiveEntity)::DownCast(TheRefSel->Sensitive());
172     if(!SE3D.IsNull())
173     {
174       // Get the copy of SE3D
175       SNew = SE3D->GetConnected(myLocation);
176       if(aMode==0)
177       {
178         SNew->Set(OWN);
179         // In case if SE3D caches some location-dependent data
180         // that must be updated after setting OWN
181         SNew->SetLocation(myLocation);
182       }
183       aSel->Add(SNew);
184     }
185   }
186 }
187
188 void AIS_ConnectedInteractive::UpdateLocation()
189 {
190 // Standard_NotImplemented::Raise("AIS_ConnectedInteractive::UpdateLocation()");
191  SelectMgr_SelectableObject::UpdateLocation() ;
192 }
193 void AIS_ConnectedInteractive::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)
194 {
195 // Standard_NotImplemented::Raise("AIS_ConnectedInteractive::UpdateLocation(const Handle(SelectMgr_Selection)& Sel)");
196  SelectMgr_SelectableObject::UpdateLocation(Sel) ;
197 }
198 /*void AIS_ConnectedInteractive::UpdateLocation(const Handle_Prs3d_Presentation& aPresentation)
199 {
200 // Standard_NotImplemented::Raise("AIS_ConnectedInteractive::UpdateLocation(const Handle_Prs3d_Presentation&)");
201  SelectMgr_SelectableObject::UpdateLocation(aPresentation) ;
202 }*/