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
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.
17 #include <AIS_ConnectedInteractive.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_Shape.hxx>
21 #include <BRepTools.hxx>
22 #include <NCollection_DataMap.hxx>
23 #include <Precision.hxx>
24 #include <Prs3d_Drawer.hxx>
25 #include <Prs3d_Projector.hxx>
26 #include <PrsMgr_ModedPresentation.hxx>
27 #include <Select3D_SensitiveEntity.hxx>
28 #include <SelectMgr_EntityOwner.hxx>
29 #include <SelectMgr_Selection.hxx>
30 #include <Standard_NotImplemented.hxx>
31 #include <Standard_ProgramError.hxx>
32 #include <Standard_Type.hxx>
33 #include <StdPrs_HLRPolyShape.hxx>
34 #include <StdPrs_WFShape.hxx>
35 #include <StdSelect.hxx>
36 #include <StdSelect_BRepOwner.hxx>
37 #include <TopAbs_ShapeEnum.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopTools_OrientedShapeMapHasher.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(AIS_ConnectedInteractive,AIS_InteractiveObject)
44 //=======================================================================
45 //function : AIS_ConnectedInteractive
47 //=======================================================================
48 AIS_ConnectedInteractive::AIS_ConnectedInteractive(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
49 AIS_InteractiveObject(aTypeOfPresentation3d)
54 //=======================================================================
57 //=======================================================================
58 void AIS_ConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj,
59 const Handle(Geom_Transformation)& theLocation)
61 if (myReference == theAnotherObj)
63 setLocalTransformation (theLocation);
67 Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (theAnotherObj);
68 if (!aConnected.IsNull())
70 myReference = aConnected->myReference;
72 else if (theAnotherObj->HasOwnPresentations())
74 myReference = theAnotherObj;
78 Standard_ProgramError::Raise ("AIS_ConnectedInteractive::Connect() - object without own presentation can not be connected");
81 if (!myReference.IsNull())
83 myTypeOfPresentation3d = myReference->TypeOfPresentation3d();
85 setLocalTransformation (theLocation);
88 //=======================================================================
89 //function : Disconnect
91 //=======================================================================
93 void AIS_ConnectedInteractive::Disconnect()
95 for(Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
97 const Handle(PrsMgr_Presentation)& aPrs = myPresentations (aPrsIter).Presentation();
100 aPrs->Presentation()->DisconnectAll (Graphic3d_TOC_DESCENDANT);
104 //=======================================================================
107 //=======================================================================
108 void AIS_ConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
109 const Handle(Prs3d_Presentation)& thePrs,
110 const Standard_Integer theMode)
114 thePrs->Clear (Standard_False);
117 if (!myReference->HasInteractiveContext())
119 myReference->SetContext (GetContext());
121 thePrsMgr->Connect (this, myReference, theMode, theMode);
122 if (thePrsMgr->Presentation (myReference, theMode)->MustBeUpdated())
124 thePrsMgr->Update (myReference, theMode);
128 if (!thePrs.IsNull())
134 //=======================================================================
137 //=======================================================================
138 void AIS_ConnectedInteractive::Compute (const Handle(Prs3d_Projector)& theProjector,
139 const Handle(Geom_Transformation)& theTransformation,
140 const Handle(Prs3d_Presentation)& thePresentation)
142 updateShape (Standard_False);
143 if (myShape.IsNull())
147 const TopLoc_Location& aLocation = myShape.Location();
148 TopoDS_Shape aShape = myShape.Located (TopLoc_Location (theTransformation->Trsf()) * aLocation);
149 Compute (theProjector, thePresentation, aShape);
152 //=======================================================================
155 //=======================================================================
156 void AIS_ConnectedInteractive::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)
158 updateShape (Standard_True);
159 Compute (aProjector, aPresentation, myShape);
162 //=======================================================================
165 //=======================================================================
166 void AIS_ConnectedInteractive::Compute (const Handle(Prs3d_Projector)& theProjector,
167 const Handle(Prs3d_Presentation)& thePresentation,
168 const TopoDS_Shape& theShape)
170 if (myShape.IsNull())
175 switch (theShape.ShapeType())
181 thePresentation->SetDisplayPriority (4);
182 StdPrs_WFShape::Add (thePresentation, theShape, myDrawer);
187 Handle(Prs3d_Drawer) aDefaultDrawer = GetContext()->DefaultDrawer();
188 if (aDefaultDrawer->DrawHiddenLine())
190 myDrawer->EnableDrawHiddenLine();
194 myDrawer->DisableDrawHiddenLine();
197 Aspect_TypeOfDeflection aPrevDeflection = aDefaultDrawer->TypeOfDeflection();
198 aDefaultDrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
200 // process HLRAngle and HLRDeviationCoefficient()
201 Standard_Real aPrevAngle = myDrawer->HLRAngle();
202 Standard_Real aNewAngle = aDefaultDrawer->HLRAngle();
203 if (myDrawer->IsAutoTriangulation() &&
204 Abs (aNewAngle - aPrevAngle) > Precision::Angular())
206 BRepTools::Clean (theShape);
209 myDrawer->SetHLRAngle (aNewAngle);
210 myDrawer->SetHLRDeviationCoefficient (aDefaultDrawer->HLRDeviationCoefficient());
211 StdPrs_HLRPolyShape::Add (thePresentation, theShape, myDrawer, theProjector);
212 aDefaultDrawer->SetTypeOfDeflection (aPrevDeflection);
217 //=======================================================================
218 //function : updateShape
220 //=======================================================================
221 void AIS_ConnectedInteractive::updateShape (const Standard_Boolean isWithLocation)
223 Handle(AIS_Shape) anAisShape = Handle(AIS_Shape)::DownCast (myReference);
224 if (anAisShape.IsNull())
229 TopoDS_Shape aShape = anAisShape->Shape();
241 myShape = aShape.Moved (TopLoc_Location (Transformation()));
245 //=======================================================================
246 //function : ComputeSelection
248 //=======================================================================
249 void AIS_ConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
250 const Standard_Integer theMode)
252 if (!HasConnection())
257 if (theMode != 0 && myReference->AcceptShapeDecomposition())
259 computeSubShapeSelection (theSelection, theMode);
263 if (!myReference->HasSelection (theMode))
265 myReference->RecomputePrimitives (theMode);
268 const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection (theMode);
269 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
270 Handle(Select3D_SensitiveEntity) aSensitive, aNewSensitive;
272 TopLoc_Location aLocation (Transformation());
273 anOwner->SetLocation (aLocation);
275 if (TheRefSel->IsEmpty())
277 myReference->RecomputePrimitives (theMode);
280 for (TheRefSel->Init(); TheRefSel->More(); TheRefSel->Next())
282 aSensitive = Handle(Select3D_SensitiveEntity)::DownCast (TheRefSel->Sensitive()->BaseSensitive());
283 if (!aSensitive.IsNull())
285 // Get the copy of SE3D
286 aNewSensitive = aSensitive->GetConnected();
288 aNewSensitive->Set(anOwner);
290 theSelection->Add (aNewSensitive);
295 //=======================================================================
296 //function : ComputeSubShapeSelection
298 //=======================================================================
299 void AIS_ConnectedInteractive::computeSubShapeSelection (const Handle(SelectMgr_Selection)& theSelection,
300 const Standard_Integer theMode)
302 typedef NCollection_List<Handle(Select3D_SensitiveEntity)> SensitiveList;
303 typedef NCollection_DataMap<TopoDS_Shape, SensitiveList, TopTools_OrientedShapeMapHasher>
306 if (!myReference->HasSelection (theMode))
307 myReference->RecomputePrimitives (theMode);
309 const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection (theMode);
311 if (aRefSel->IsEmpty() || aRefSel->UpdateStatus() == SelectMgr_TOU_Full)
313 myReference->RecomputePrimitives (theMode);
316 Handle(StdSelect_BRepOwner) anOwner;
317 TopLoc_Location aDummyLoc;
319 Handle(Select3D_SensitiveEntity) aSE, aNewSE;
320 Shapes2EntitiesMap aShapes2EntitiesMap;
322 SensitiveList aSEList;
323 TopoDS_Shape aSubShape;
325 // Fill in the map of subshapes and corresponding
326 // sensitive entities associated with aMode
327 for (aRefSel->Init(); aRefSel->More(); aRefSel->Next())
329 aSE = Handle(Select3D_SensitiveEntity)::DownCast (aRefSel->Sensitive()->BaseSensitive());
332 anOwner = Handle(StdSelect_BRepOwner)::DownCast (aSE->OwnerId());
333 if(!anOwner.IsNull())
335 aSubShape = anOwner->Shape();
336 if(!aShapes2EntitiesMap.IsBound (aSubShape))
338 aShapes2EntitiesMap.Bind (aSubShape, aSEList);
340 aShapes2EntitiesMap (aSubShape).Append (aSE);
345 // Fill in selection from aShapes2EntitiesMap
346 for (Shapes2EntitiesMap::Iterator aMapIt (aShapes2EntitiesMap); aMapIt.More(); aMapIt.Next())
348 aSEList = aMapIt.Value();
349 anOwner = new StdSelect_BRepOwner (aMapIt.Key(),
351 aSEList.First()->OwnerId()->Priority(),
353 anOwner->SetLocation (Transformation());
355 for (SensitiveList::Iterator aListIt (aSEList); aListIt.More(); aListIt.Next())
357 aSE = aListIt.Value();
359 aNewSE = aSE->GetConnected();
360 aNewSE->Set (anOwner);
362 theSelection->Add (aNewSE);
366 StdSelect::SetDrawerForBRepOwner (theSelection, myDrawer);