b311480e |
1 | // Created on: 1997-01-08 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <AIS_ConnectedInteractive.hxx> |
1f7f5a90 |
18 | |
42cf5bc1 |
19 | #include <AIS_InteractiveContext.hxx> |
42cf5bc1 |
20 | #include <AIS_Shape.hxx> |
21 | #include <BRepTools.hxx> |
42cf5bc1 |
22 | #include <NCollection_DataMap.hxx> |
23 | #include <Precision.hxx> |
24 | #include <Prs3d_Drawer.hxx> |
b5163d2f |
25 | #include <Prs3d_Presentation.hxx> |
42cf5bc1 |
26 | #include <Select3D_SensitiveEntity.hxx> |
27 | #include <SelectMgr_EntityOwner.hxx> |
28 | #include <SelectMgr_Selection.hxx> |
29 | #include <Standard_NotImplemented.hxx> |
30 | #include <Standard_ProgramError.hxx> |
31 | #include <Standard_Type.hxx> |
32 | #include <StdPrs_HLRPolyShape.hxx> |
5ad8c033 |
33 | #include <StdPrs_WFShape.hxx> |
0717ddc1 |
34 | #include <StdSelect.hxx> |
42cf5bc1 |
35 | #include <StdSelect_BRepOwner.hxx> |
36 | #include <TopAbs_ShapeEnum.hxx> |
37 | #include <TopoDS_Shape.hxx> |
0717ddc1 |
38 | #include <TopTools_IndexedMapOfShape.hxx> |
39 | #include <TopTools_OrientedShapeMapHasher.hxx> |
40 | |
92efcf78 |
41 | IMPLEMENT_STANDARD_RTTIEXT(AIS_ConnectedInteractive,AIS_InteractiveObject) |
42 | |
7fd59977 |
43 | //======================================================================= |
44 | //function : AIS_ConnectedInteractive |
45 | //purpose : |
46 | //======================================================================= |
47 | AIS_ConnectedInteractive::AIS_ConnectedInteractive(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d): |
48 | AIS_InteractiveObject(aTypeOfPresentation3d) |
0717ddc1 |
49 | { |
f838dac4 |
50 | // |
7fd59977 |
51 | } |
52 | |
7fd59977 |
53 | //======================================================================= |
1f7f5a90 |
54 | //function : connect |
55 | //purpose : |
7fd59977 |
56 | //======================================================================= |
1f7f5a90 |
57 | void AIS_ConnectedInteractive::connect (const Handle(AIS_InteractiveObject)& theAnotherObj, |
7f24b768 |
58 | const Handle(TopLoc_Datum3D)& theLocation) |
7fd59977 |
59 | { |
1f7f5a90 |
60 | if (myReference == theAnotherObj) |
61 | { |
62 | setLocalTransformation (theLocation); |
63 | return; |
64 | } |
0717ddc1 |
65 | |
66 | Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (theAnotherObj); |
67 | if (!aConnected.IsNull()) |
68 | { |
69 | myReference = aConnected->myReference; |
70 | } |
71 | else if (theAnotherObj->HasOwnPresentations()) |
72 | { |
73 | myReference = theAnotherObj; |
74 | } |
40f70ac9 |
75 | else |
76 | { |
9775fa61 |
77 | throw Standard_ProgramError("AIS_ConnectedInteractive::Connect() - object without own presentation can not be connected"); |
40f70ac9 |
78 | } |
0717ddc1 |
79 | |
80 | if (!myReference.IsNull()) |
81 | { |
cc99be36 |
82 | if (myReference->HasInteractiveContext() |
83 | && myReference->GetContext()->DisplayStatus (myReference) != AIS_DS_None) |
84 | { |
85 | myReference.Nullify(); |
86 | throw Standard_ProgramError("AIS_ConnectedInteractive::Connect() - connected object should NOT be displayed in context"); |
87 | } |
0717ddc1 |
88 | myTypeOfPresentation3d = myReference->TypeOfPresentation3d(); |
89 | } |
1f7f5a90 |
90 | setLocalTransformation (theLocation); |
7fd59977 |
91 | } |
92 | |
7fd59977 |
93 | //======================================================================= |
94 | //function : Disconnect |
af324faa |
95 | //purpose : |
7fd59977 |
96 | //======================================================================= |
97 | |
98 | void AIS_ConnectedInteractive::Disconnect() |
99 | { |
7dd7c146 |
100 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentations); aPrsIter.More(); aPrsIter.Next()) |
af324faa |
101 | { |
7dd7c146 |
102 | const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value(); |
af324faa |
103 | if (!aPrs.IsNull()) |
7fd59977 |
104 | { |
7dd7c146 |
105 | aPrs->DisconnectAll (Graphic3d_TOC_DESCENDANT); |
7fd59977 |
106 | } |
af324faa |
107 | } |
7fd59977 |
108 | } |
109 | //======================================================================= |
110 | //function : Compute |
792c785c |
111 | //purpose : |
7fd59977 |
112 | //======================================================================= |
792c785c |
113 | void AIS_ConnectedInteractive::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
114 | const Handle(Prs3d_Presentation)& thePrs, |
115 | const Standard_Integer theMode) |
7fd59977 |
116 | { |
792c785c |
117 | if (HasConnection()) |
118 | { |
119 | thePrs->Clear (Standard_False); |
7dd7c146 |
120 | thePrs->DisconnectAll (Graphic3d_TOC_DESCENDANT); |
792c785c |
121 | |
122 | if (!myReference->HasInteractiveContext()) |
123 | { |
124 | myReference->SetContext (GetContext()); |
125 | } |
126 | thePrsMgr->Connect (this, myReference, theMode, theMode); |
127 | if (thePrsMgr->Presentation (myReference, theMode)->MustBeUpdated()) |
128 | { |
129 | thePrsMgr->Update (myReference, theMode); |
130 | } |
131 | } |
132 | |
0717ddc1 |
133 | if (!thePrs.IsNull()) |
792c785c |
134 | { |
0717ddc1 |
135 | thePrs->ReCompute(); |
7fd59977 |
136 | } |
7fd59977 |
137 | } |
138 | |
0717ddc1 |
139 | //======================================================================= |
b5163d2f |
140 | //function : computeHLR |
0717ddc1 |
141 | //purpose : |
142 | //======================================================================= |
b5163d2f |
143 | void AIS_ConnectedInteractive::computeHLR (const Handle(Graphic3d_Camera)& theProjector, |
7f24b768 |
144 | const Handle(TopLoc_Datum3D)& theTransformation, |
b5163d2f |
145 | const Handle(Prs3d_Presentation)& thePresentation) |
7fd59977 |
146 | { |
b5163d2f |
147 | const bool hasTrsf = !theTransformation.IsNull() |
148 | && theTransformation->Form() != gp_Identity; |
149 | updateShape (!hasTrsf); |
0717ddc1 |
150 | if (myShape.IsNull()) |
151 | { |
152 | return; |
153 | } |
b5163d2f |
154 | if (hasTrsf) |
155 | { |
156 | const TopLoc_Location& aLocation = myShape.Location(); |
157 | TopoDS_Shape aShape = myShape.Located (TopLoc_Location (theTransformation->Trsf()) * aLocation); |
158 | AIS_Shape::computeHlrPresentation (theProjector, thePresentation, aShape, myDrawer); |
159 | } |
160 | else |
161 | { |
162 | AIS_Shape::computeHlrPresentation (theProjector, thePresentation, myShape, myDrawer); |
163 | } |
7fd59977 |
164 | } |
165 | |
0717ddc1 |
166 | //======================================================================= |
167 | //function : updateShape |
168 | //purpose : |
169 | //======================================================================= |
170 | void AIS_ConnectedInteractive::updateShape (const Standard_Boolean isWithLocation) |
7fd59977 |
171 | { |
0717ddc1 |
172 | Handle(AIS_Shape) anAisShape = Handle(AIS_Shape)::DownCast (myReference); |
173 | if (anAisShape.IsNull()) |
174 | { |
175 | return; |
176 | } |
177 | |
178 | TopoDS_Shape aShape = anAisShape->Shape(); |
179 | if (aShape.IsNull()) |
180 | { |
181 | return; |
182 | } |
183 | |
184 | if(!isWithLocation) |
185 | { |
186 | myShape = aShape; |
187 | } |
188 | else |
189 | { |
190 | myShape = aShape.Moved (TopLoc_Location (Transformation())); |
191 | } |
7fd59977 |
192 | } |
0717ddc1 |
193 | |
194 | //======================================================================= |
195 | //function : ComputeSelection |
196 | //purpose : |
197 | //======================================================================= |
198 | void AIS_ConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
199 | const Standard_Integer theMode) |
7fd59977 |
200 | { |
0717ddc1 |
201 | if (!HasConnection()) |
202 | { |
203 | return; |
204 | } |
205 | |
206 | if (theMode != 0 && myReference->AcceptShapeDecomposition()) |
207 | { |
208 | computeSubShapeSelection (theSelection, theMode); |
209 | return; |
210 | } |
211 | |
212 | if (!myReference->HasSelection (theMode)) |
213 | { |
f751596e |
214 | myReference->RecomputePrimitives (theMode); |
0717ddc1 |
215 | } |
216 | |
217 | const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection (theMode); |
218 | Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this); |
f751596e |
219 | |
220 | TopLoc_Location aLocation (Transformation()); |
221 | anOwner->SetLocation (aLocation); |
222 | |
0717ddc1 |
223 | if (TheRefSel->IsEmpty()) |
224 | { |
f751596e |
225 | myReference->RecomputePrimitives (theMode); |
0717ddc1 |
226 | } |
227 | |
b5cce1ab |
228 | for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (TheRefSel->Entities()); aSelEntIter.More(); aSelEntIter.Next()) |
0717ddc1 |
229 | { |
0ef04197 |
230 | if (const Handle(Select3D_SensitiveEntity)& aSensitive = aSelEntIter.Value()->BaseSensitive()) |
0717ddc1 |
231 | { |
0717ddc1 |
232 | // Get the copy of SE3D |
834f2897 |
233 | if (Handle(Select3D_SensitiveEntity) aNewSensitive = aSensitive->GetConnected()) |
234 | { |
235 | aNewSensitive->Set(anOwner); |
236 | theSelection->Add (aNewSensitive); |
237 | } |
0717ddc1 |
238 | } |
239 | } |
7fd59977 |
240 | } |
0717ddc1 |
241 | |
242 | //======================================================================= |
243 | //function : ComputeSubShapeSelection |
244 | //purpose : |
245 | //======================================================================= |
246 | void AIS_ConnectedInteractive::computeSubShapeSelection (const Handle(SelectMgr_Selection)& theSelection, |
247 | const Standard_Integer theMode) |
7fd59977 |
248 | { |
0717ddc1 |
249 | typedef NCollection_List<Handle(Select3D_SensitiveEntity)> SensitiveList; |
250 | typedef NCollection_DataMap<TopoDS_Shape, SensitiveList, TopTools_OrientedShapeMapHasher> |
251 | Shapes2EntitiesMap; |
252 | |
253 | if (!myReference->HasSelection (theMode)) |
b5cce1ab |
254 | { |
f751596e |
255 | myReference->RecomputePrimitives (theMode); |
b5cce1ab |
256 | } |
0717ddc1 |
257 | |
b5cce1ab |
258 | const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection (theMode); |
0717ddc1 |
259 | if (aRefSel->IsEmpty() || aRefSel->UpdateStatus() == SelectMgr_TOU_Full) |
260 | { |
f751596e |
261 | myReference->RecomputePrimitives (theMode); |
0717ddc1 |
262 | } |
0717ddc1 |
263 | |
b5cce1ab |
264 | // Fill in the map of subshapes and corresponding sensitive entities associated with aMode |
0717ddc1 |
265 | Shapes2EntitiesMap aShapes2EntitiesMap; |
b5cce1ab |
266 | for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aRefSel->Entities()); aSelEntIter.More(); aSelEntIter.Next()) |
0717ddc1 |
267 | { |
0ef04197 |
268 | if (const Handle(Select3D_SensitiveEntity)& aSE = aSelEntIter.Value()->BaseSensitive()) |
0717ddc1 |
269 | { |
b5cce1ab |
270 | if (Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (aSE->OwnerId())) |
0717ddc1 |
271 | { |
b5cce1ab |
272 | const TopoDS_Shape& aSubShape = anOwner->Shape(); |
0717ddc1 |
273 | if(!aShapes2EntitiesMap.IsBound (aSubShape)) |
274 | { |
b5cce1ab |
275 | aShapes2EntitiesMap.Bind (aSubShape, SensitiveList()); |
0717ddc1 |
276 | } |
277 | aShapes2EntitiesMap (aSubShape).Append (aSE); |
278 | } |
279 | } |
280 | } |
281 | |
282 | // Fill in selection from aShapes2EntitiesMap |
283 | for (Shapes2EntitiesMap::Iterator aMapIt (aShapes2EntitiesMap); aMapIt.More(); aMapIt.Next()) |
284 | { |
b5cce1ab |
285 | const SensitiveList& aSEList = aMapIt.Value(); |
286 | Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner (aMapIt.Key(), this, aSEList.First()->OwnerId()->Priority(), Standard_True); |
f751596e |
287 | anOwner->SetLocation (Transformation()); |
0717ddc1 |
288 | for (SensitiveList::Iterator aListIt (aSEList); aListIt.More(); aListIt.Next()) |
f751596e |
289 | { |
834f2897 |
290 | if (Handle(Select3D_SensitiveEntity) aNewSE = aListIt.Value()->GetConnected()) |
291 | { |
292 | aNewSE->Set (anOwner); |
293 | theSelection->Add (aNewSE); |
294 | } |
0717ddc1 |
295 | } |
296 | } |
297 | |
298 | StdSelect::SetDrawerForBRepOwner (theSelection, myDrawer); |
299 | } |