0025991: Cyclic dependency in OCCT detected by WOK compiler
[occt.git] / src / AIS / AIS_ConnectedInteractive.cxx
... / ...
CommitLineData
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 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.
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_Presentation.hxx>
26
27#include <StdSelect_BRepOwner.hxx>
28
29#include <StdSelect.hxx>
30#include <TopTools_IndexedMapOfShape.hxx>
31#include <TopTools_OrientedShapeMapHasher.hxx>
32
33#include <AIS_InteractiveContext.hxx>
34#include <BRepTools.hxx>
35#include <Precision.hxx>
36#include <TopAbs_ShapeEnum.hxx>
37#include <Standard_ProgramError.hxx>
38#include <StdPrs_WFDeflectionShape.hxx>
39#include <StdPrs_HLRPolyShape.hxx>
40#include <Prs3d_Drawer.hxx>
41
42#include <AIS_Shape.hxx>
43
44#include <NCollection_DataMap.hxx>
45
46
47//=======================================================================
48//function : AIS_ConnectedInteractive
49//purpose :
50//=======================================================================
51AIS_ConnectedInteractive::AIS_ConnectedInteractive(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
52AIS_InteractiveObject(aTypeOfPresentation3d)
53{
54 SetHilightMode(0);
55}
56
57//=======================================================================
58//function : Type
59//purpose :
60//=======================================================================
61AIS_KindOfInteractive AIS_ConnectedInteractive::Type() const
62{
63 return AIS_KOI_Object;
64}
65
66Standard_Integer AIS_ConnectedInteractive::Signature() const
67{
68 return 0;
69}
70
71
72//=======================================================================
73//function : Connect
74//purpose :
75//=======================================================================
76void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj)
77{
78 if (myReference == theAnotherObj) return;
79
80 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (theAnotherObj);
81 if (!aConnected.IsNull())
82 {
83 myReference = aConnected->myReference;
84 }
85 else if (theAnotherObj->HasOwnPresentations())
86 {
87 myReference = theAnotherObj;
88 }
89 else
90 {
91 Standard_ProgramError::Raise ("AIS_ConnectedInteractive::Connect() - object without own presentation can not be connected");
92 }
93
94 if (!myReference.IsNull())
95 {
96 myTypeOfPresentation3d = myReference->TypeOfPresentation3d();
97 }
98}
99
100//=======================================================================
101//function : Connect
102//purpose :
103//=======================================================================
104void AIS_ConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
105 const gp_Trsf& theLocation)
106{
107 Connect (theAnotherObj);
108
109 SetLocalTransformation (theLocation);
110}
111
112
113//=======================================================================
114//function : Disconnect
115//purpose :
116//=======================================================================
117
118void AIS_ConnectedInteractive::Disconnect()
119{
120 for(Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
121 {
122 const Handle(PrsMgr_Presentation)& aPrs = myPresentations (aPrsIter).Presentation();
123 if (!aPrs.IsNull())
124 {
125 aPrs->Presentation()->DisconnectAll (Graphic3d_TOC_DESCENDANT);
126 }
127 }
128}
129//=======================================================================
130//function : Compute
131//purpose :
132//=======================================================================
133void AIS_ConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
134 const Handle(Prs3d_Presentation)& thePrs,
135 const Standard_Integer theMode)
136{
137 if (HasConnection())
138 {
139 thePrs->Clear (Standard_False);
140 thePrs->RemoveAll();
141
142 if (!myReference->HasInteractiveContext())
143 {
144 myReference->SetContext (GetContext());
145 }
146 thePrsMgr->Connect (this, myReference, theMode, theMode);
147 if (thePrsMgr->Presentation (myReference, theMode)->MustBeUpdated())
148 {
149 thePrsMgr->Update (myReference, theMode);
150 }
151 }
152
153 if (!thePrs.IsNull())
154 {
155 thePrs->ReCompute();
156 }
157}
158
159//=======================================================================
160//function : Compute
161//purpose :
162//=======================================================================
163void AIS_ConnectedInteractive::Compute (const Handle(Prs3d_Projector)& theProjector,
164 const Handle(Geom_Transformation)& theTransformation,
165 const Handle(Prs3d_Presentation)& thePresentation)
166{
167 updateShape (Standard_False);
168 if (myShape.IsNull())
169 {
170 return;
171 }
172 const TopLoc_Location& aLocation = myShape.Location();
173 TopoDS_Shape aShape = myShape.Located (TopLoc_Location (theTransformation->Trsf()) * aLocation);
174 Compute (theProjector, thePresentation, aShape);
175}
176
177//=======================================================================
178//function : Compute
179//purpose :
180//=======================================================================
181void AIS_ConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)
182{
183 updateShape (Standard_True);
184 Compute (aProjector, aPresentation, myShape);
185}
186
187//=======================================================================
188//function : Compute
189//purpose :
190//=======================================================================
191void AIS_ConnectedInteractive::Compute (const Handle(Prs3d_Projector)& theProjector,
192 const Handle(Prs3d_Presentation)& thePresentation,
193 const TopoDS_Shape& theShape)
194{
195 if (myShape.IsNull())
196 {
197 return;
198 }
199
200 switch (theShape.ShapeType())
201 {
202 case TopAbs_VERTEX:
203 case TopAbs_EDGE:
204 case TopAbs_WIRE:
205 {
206 thePresentation->SetDisplayPriority (4);
207 StdPrs_WFDeflectionShape::Add (thePresentation, theShape, myDrawer);
208 break;
209 }
210 default:
211 {
212 Handle(Prs3d_Drawer) aDefaultDrawer = GetContext()->DefaultDrawer();
213 if (aDefaultDrawer->DrawHiddenLine())
214 {
215 myDrawer->EnableDrawHiddenLine();
216 }
217 else
218 {
219 myDrawer->DisableDrawHiddenLine();
220 }
221
222 Aspect_TypeOfDeflection aPrevDeflection = aDefaultDrawer->TypeOfDeflection();
223 aDefaultDrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
224
225 // process HLRAngle and HLRDeviationCoefficient()
226 Standard_Real aPrevAngle = myDrawer->HLRAngle();
227 Standard_Real aNewAngle = aDefaultDrawer->HLRAngle();
228 if (myDrawer->IsAutoTriangulation() &&
229 Abs (aNewAngle - aPrevAngle) > Precision::Angular())
230 {
231 BRepTools::Clean (theShape);
232 }
233
234 myDrawer->SetHLRAngle (aNewAngle);
235 myDrawer->SetHLRDeviationCoefficient (aDefaultDrawer->HLRDeviationCoefficient());
236 StdPrs_HLRPolyShape::Add (thePresentation, theShape, myDrawer, theProjector);
237 aDefaultDrawer->SetTypeOfDeflection (aPrevDeflection);
238 }
239 }
240}
241
242//=======================================================================
243//function : updateShape
244//purpose :
245//=======================================================================
246void AIS_ConnectedInteractive::updateShape (const Standard_Boolean isWithLocation)
247{
248 Handle(AIS_Shape) anAisShape = Handle(AIS_Shape)::DownCast (myReference);
249 if (anAisShape.IsNull())
250 {
251 return;
252 }
253
254 TopoDS_Shape aShape = anAisShape->Shape();
255 if (aShape.IsNull())
256 {
257 return;
258 }
259
260 if(!isWithLocation)
261 {
262 myShape = aShape;
263 }
264 else
265 {
266 myShape = aShape.Moved (TopLoc_Location (Transformation()));
267 }
268}
269
270//=======================================================================
271//function : ComputeSelection
272//purpose :
273//=======================================================================
274void AIS_ConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
275 const Standard_Integer theMode)
276{
277 if (!HasConnection())
278 {
279 return;
280 }
281
282 if (theMode != 0 && myReference->AcceptShapeDecomposition())
283 {
284 computeSubShapeSelection (theSelection, theMode);
285 return;
286 }
287
288 if (!myReference->HasSelection (theMode))
289 {
290 myReference->UpdateSelection (theMode);
291 }
292
293 const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection (theMode);
294 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
295 Handle(Select3D_SensitiveEntity) aSensitive, aNewSensitive;
296
297 if (TheRefSel->IsEmpty())
298 {
299 myReference->UpdateSelection (theMode);
300 }
301
302 for (TheRefSel->Init(); TheRefSel->More(); TheRefSel->Next())
303 {
304 aSensitive = Handle(Select3D_SensitiveEntity)::DownCast (TheRefSel->Sensitive());
305 if (!aSensitive.IsNull())
306 {
307 TopLoc_Location aLocation (Transformation());
308 // Get the copy of SE3D
309 aNewSensitive = aSensitive->GetConnected (aLocation);
310
311 aNewSensitive->Set(anOwner);
312 // In case if SE3D caches some location-dependent data
313 // that must be updated after setting OWN
314 aNewSensitive->SetLocation (aLocation);
315
316 theSelection->Add (aNewSensitive);
317 }
318 }
319}
320
321//=======================================================================
322//function : ComputeSubShapeSelection
323//purpose :
324//=======================================================================
325void AIS_ConnectedInteractive::computeSubShapeSelection (const Handle(SelectMgr_Selection)& theSelection,
326 const Standard_Integer theMode)
327{
328 typedef NCollection_List<Handle(Select3D_SensitiveEntity)> SensitiveList;
329 typedef NCollection_DataMap<TopoDS_Shape, SensitiveList, TopTools_OrientedShapeMapHasher>
330 Shapes2EntitiesMap;
331
332 if (!myReference->HasSelection (theMode))
333 myReference->UpdateSelection (theMode);
334
335 const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection (theMode);
336
337 if (aRefSel->IsEmpty() || aRefSel->UpdateStatus() == SelectMgr_TOU_Full)
338 {
339 myReference->UpdateSelection (theMode);
340 }
341
342 Handle(StdSelect_BRepOwner) anOwner;
343 TopLoc_Location aDummyLoc;
344
345 Handle(Select3D_SensitiveEntity) aSE, aNewSE;
346 Shapes2EntitiesMap aShapes2EntitiesMap;
347
348 SensitiveList aSEList;
349 TopoDS_Shape aSubShape;
350
351 // Fill in the map of subshapes and corresponding
352 // sensitive entities associated with aMode
353 for (aRefSel->Init(); aRefSel->More(); aRefSel->Next())
354 {
355 aSE = Handle(Select3D_SensitiveEntity)::DownCast (aRefSel->Sensitive());
356 if(!aSE.IsNull())
357 {
358 anOwner = Handle(StdSelect_BRepOwner)::DownCast (aSE->OwnerId());
359 if(!anOwner.IsNull())
360 {
361 aSubShape = anOwner->Shape();
362 if(!aShapes2EntitiesMap.IsBound (aSubShape))
363 {
364 aShapes2EntitiesMap.Bind (aSubShape, aSEList);
365 }
366 aShapes2EntitiesMap (aSubShape).Append (aSE);
367 }
368 }
369 }
370
371 // Fill in selection from aShapes2EntitiesMap
372 for (Shapes2EntitiesMap::Iterator aMapIt (aShapes2EntitiesMap); aMapIt.More(); aMapIt.Next())
373 {
374 aSEList = aMapIt.Value();
375 anOwner = new StdSelect_BRepOwner (aMapIt.Key(),
376 this,
377 aSEList.First()->OwnerId()->Priority(),
378 Standard_True);
379
380 for (SensitiveList::Iterator aListIt (aSEList); aListIt.More(); aListIt.Next())
381 {
382 aSE = aListIt.Value();
383
384 TopLoc_Location aLocation (Transformation());
385 aNewSE = aSE->GetConnected (aDummyLoc);
386 aNewSE->Set (anOwner);
387 // In case if aSE caches some location-dependent data
388 // that must be updated after setting anOwner
389 aNewSE->SetLocation (aLocation);
390
391 theSelection->Add (aNewSE);
392 }
393 }
394
395 StdSelect::SetDrawerForBRepOwner (theSelection, myDrawer);
396}