Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1996-04-10 |
2 | // Created by: Guest Design | |
3 | // Copyright (c) 1996-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. | |
b311480e | 16 | |
7fd59977 | 17 | // <g_design> |
18 | ||
19 | ||
20 | #include <Standard_NotImplemented.hxx> | |
21 | ||
22 | #include <AIS_ConnectedShape.ixx> | |
23 | ||
24 | #include <AIS_InteractiveContext.hxx> | |
25 | #include <AIS_Drawer.hxx> | |
26 | #include <TopAbs_ShapeEnum.hxx> | |
27 | #include <StdPrs_WFDeflectionShape.hxx> | |
28 | #include <StdPrs_HLRPolyShape.hxx> | |
29 | #include <Prs3d_Drawer.hxx> | |
30 | #include <Aspect_TypeOfDeflection.hxx> | |
31 | #include <BRepTools.hxx> | |
32 | #include <OSD_Timer.hxx> | |
33 | #include <StdSelect_BRepSelectionTool.hxx> | |
34 | #include <StdSelect_BRepOwner.hxx> | |
35 | #include <StdSelect.hxx> | |
36 | #include <TopTools_IndexedMapOfShape.hxx> | |
f3fa1d35 | 37 | #include <TopTools_OrientedShapeMapHasher.hxx> |
7fd59977 | 38 | #include <TopExp.hxx> |
39 | #include <Select3D_SensitiveEntity.hxx> | |
40 | #include <SelectMgr_EntityOwner.hxx> | |
41 | #include <SelectBasics_EntityOwner.hxx> | |
42 | #include <AIS_MultipleConnectedShape.hxx> | |
43 | #include <Precision.hxx> | |
ac04d101 SA |
44 | #include <NCollection_DataMap.hxx> |
45 | #include <NCollection_List.hxx> | |
7fd59977 | 46 | |
47 | //======================================================================= | |
48 | //function : AIS_ConnectedShape | |
49 | //purpose : | |
50 | //======================================================================= | |
51 | ||
52 | AIS_ConnectedShape::AIS_ConnectedShape (const Handle(AIS_Shape)& TheAISShape, | |
53 | const PrsMgr_TypeOfPresentation3d TheType): | |
54 | AIS_ConnectedInteractive(TheType) | |
55 | { | |
56 | myReference = TheAISShape; | |
57 | } | |
58 | ||
59 | AIS_ConnectedShape::AIS_ConnectedShape (const Handle(AIS_ConnectedShape)& TheConnectedShape, | |
60 | const PrsMgr_TypeOfPresentation3d TheType): | |
61 | AIS_ConnectedInteractive(TheType) | |
62 | { | |
63 | myReference = TheConnectedShape; | |
64 | } | |
65 | ||
66 | ||
67 | //======================================================================= | |
68 | //function : Type | |
69 | //purpose : | |
70 | //======================================================================= | |
71 | ||
72 | AIS_KindOfInteractive AIS_ConnectedShape::Type() const | |
73 | {return AIS_KOI_Shape;} | |
74 | ||
75 | //======================================================================= | |
76 | //function : Signature | |
77 | //purpose : | |
78 | //======================================================================= | |
79 | Standard_Integer AIS_ConnectedShape::Signature() const | |
80 | {return 1;} | |
81 | ||
82 | //======================================================================= | |
83 | //function : AcceptShapeDecomposition | |
84 | //purpose : | |
85 | //======================================================================= | |
86 | Standard_Boolean AIS_ConnectedShape::AcceptShapeDecomposition() const | |
87 | {return Standard_True;} | |
88 | ||
89 | //======================================================================= | |
90 | //function : Compute Hidden Lines | |
91 | //purpose : | |
92 | //======================================================================= | |
93 | ||
94 | void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, | |
95 | const Handle(Prs3d_Presentation)& aPresentation) | |
96 | { | |
97 | UpdateShape(Standard_True); | |
98 | Compute(aProjector,aPresentation,myOwnSh); | |
99 | } | |
100 | ||
101 | ||
102 | //======================================================================= | |
103 | //function : Compute | |
104 | //purpose : | |
105 | //======================================================================= | |
106 | void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, | |
107 | const Handle(Geom_Transformation)& TheTrsf, | |
108 | const Handle(Prs3d_Presentation)& aPresentation) | |
109 | { | |
110 | UpdateShape(Standard_False); | |
111 | const TopLoc_Location& loc = myOwnSh.Location(); | |
112 | TopoDS_Shape shbis = myOwnSh.Located(TopLoc_Location(TheTrsf->Trsf())*loc); | |
113 | Compute(aProjector,aPresentation,shbis); | |
114 | } | |
115 | ||
116 | ||
117 | //======================================================================= | |
118 | //function : Compute | |
119 | //purpose : | |
120 | //======================================================================= | |
121 | ||
122 | void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, | |
123 | const Handle(Prs3d_Presentation)& aPresentation, | |
124 | const TopoDS_Shape& SH) | |
125 | { | |
126 | // Standard_Boolean recompute = Standard_False; | |
127 | // Standard_Boolean myFirstCompute = Standard_True; | |
128 | switch (SH.ShapeType()){ | |
129 | case TopAbs_VERTEX: | |
130 | case TopAbs_EDGE: | |
131 | case TopAbs_WIRE: | |
132 | { | |
133 | aPresentation->SetDisplayPriority(4); | |
134 | StdPrs_WFDeflectionShape::Add(aPresentation,SH,myDrawer); | |
135 | break; | |
136 | } | |
137 | default: | |
138 | { | |
139 | Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer(); | |
140 | if (defdrawer->DrawHiddenLine()) | |
141 | {myDrawer->EnableDrawHiddenLine();} | |
142 | else {myDrawer->DisableDrawHiddenLine();} | |
143 | ||
144 | Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection(); | |
145 | defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE); | |
146 | ||
81bba717 | 147 | // process HLRAngle and HLRDeviationCoefficient() |
7fd59977 | 148 | Standard_Real prevangl = myDrawer->HLRAngle(); |
149 | Standard_Real newangl = defdrawer->HLRAngle(); | |
150 | if (Abs(newangl- prevangl) > Precision::Angular()) { | |
151 | #ifdef DEB | |
152 | cout << "AIS_MultipleConnectedShape : compute"<<endl; | |
153 | cout << "newangl : " << newangl << " # de " << "prevangl : " << prevangl << endl; | |
154 | #endif | |
155 | BRepTools::Clean(SH); | |
156 | } | |
157 | myDrawer->SetHLRAngle(newangl); | |
158 | myDrawer->SetHLRDeviationCoefficient(defdrawer->HLRDeviationCoefficient()); | |
159 | StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector); | |
160 | defdrawer->SetTypeOfDeflection (prevdef); | |
161 | } | |
162 | } | |
163 | } | |
164 | ||
7fd59977 | 165 | //======================================================================= |
166 | //function : ComputeSelection | |
167 | //purpose : Attention fragile... | |
168 | //======================================================================= | |
169 | ||
ac04d101 SA |
170 | void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection, |
171 | const Standard_Integer aMode) | |
7fd59977 | 172 | { |
ac04d101 | 173 | typedef NCollection_List<Handle(Select3D_SensitiveEntity)> SensitiveList; |
f3fa1d35 RL |
174 | typedef NCollection_DataMap<TopoDS_Shape, SensitiveList, TopTools_OrientedShapeMapHasher> |
175 | Shapes2EntitiesMap; | |
ac04d101 | 176 | |
7fd59977 | 177 | UpdateShape(); |
178 | aSelection->Clear(); | |
81bba717 | 179 | // It is checked if there is nothing to do with the reference |
180 | // of type update... | |
7fd59977 | 181 | |
182 | if(!myReference->HasSelection(aMode)) | |
183 | myReference->UpdateSelection(aMode); | |
ac04d101 SA |
184 | const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection(aMode); |
185 | if(aRefSel->IsEmpty()) | |
7fd59977 | 186 | myReference->UpdateSelection(aMode); |
187 | ||
ac04d101 SA |
188 | if(aRefSel->UpdateStatus()==SelectMgr_TOU_Full) |
189 | myReference->UpdateSelection(aMode); | |
7fd59977 | 190 | |
ac04d101 SA |
191 | Handle(StdSelect_BRepOwner) anOwner; |
192 | TopLoc_Location aBidLoc; | |
193 | Handle(Select3D_SensitiveEntity) aSE, aNewSE; | |
194 | Shapes2EntitiesMap aShapes2EntitiesMap; | |
195 | SensitiveList aSEList; | |
196 | TopoDS_Shape aSubShape; | |
197 | ||
198 | // Fill in the map of subshapes and corresponding | |
199 | // sensitive entities associated with aMode | |
200 | for(aRefSel->Init(); aRefSel->More(); aRefSel->Next()) | |
201 | { | |
202 | aSE = Handle(Select3D_SensitiveEntity)::DownCast(aRefSel->Sensitive()); | |
203 | if(!aSE.IsNull()) | |
7fd59977 | 204 | { |
ac04d101 SA |
205 | anOwner = Handle(StdSelect_BRepOwner)::DownCast(aSE->OwnerId()); |
206 | if(!anOwner.IsNull()) | |
207 | { | |
208 | aSubShape = anOwner->Shape(); | |
209 | if(!aShapes2EntitiesMap.IsBound(aSubShape)) | |
210 | { | |
211 | aShapes2EntitiesMap.Bind(aSubShape, aSEList); | |
212 | } | |
213 | aShapes2EntitiesMap(aSubShape).Append(aSE); | |
7fd59977 | 214 | } |
7fd59977 | 215 | } |
ac04d101 SA |
216 | } |
217 | ||
218 | // Fill in selection from aShapes2EntitiesMap | |
219 | Shapes2EntitiesMap::Iterator aMapIt(aShapes2EntitiesMap); | |
220 | for(; aMapIt.More(); aMapIt.Next()) | |
221 | { | |
222 | aSEList = aMapIt.Value(); | |
223 | anOwner = new StdSelect_BRepOwner(aMapIt.Key(), | |
224 | this, | |
225 | aSEList.First()->OwnerId()->Priority(), | |
226 | Standard_True); | |
7fd59977 | 227 | |
ac04d101 SA |
228 | SensitiveList::Iterator aListIt(aSEList); |
229 | for(; aListIt.More(); aListIt.Next()) | |
7fd59977 | 230 | { |
ac04d101 SA |
231 | aSE = aListIt.Value(); |
232 | if(myLocation.IsIdentity()) | |
233 | { | |
234 | aNewSE = aSE->GetConnected(aBidLoc); | |
235 | aNewSE->Set(anOwner); | |
236 | // In case if aSE caches some location-dependent data | |
237 | // that must be updated after setting anOwner | |
238 | aNewSE->SetLocation(aBidLoc); | |
7fd59977 | 239 | } |
ac04d101 SA |
240 | else |
241 | { | |
242 | aNewSE = aSE->GetConnected(myLocation); | |
243 | aNewSE->Set(anOwner); | |
244 | // In case if aSE caches some location-dependent data | |
245 | // that must be updated after setting anOwner | |
246 | aNewSE->SetLocation(myLocation); | |
247 | } | |
248 | aSelection->Add(aNewSE); | |
7fd59977 | 249 | } |
250 | } | |
ac04d101 SA |
251 | |
252 | StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer); | |
7fd59977 | 253 | } |
7fd59977 | 254 | |
255 | //======================================================================= | |
256 | //function : Shape | |
257 | //purpose : | |
258 | //======================================================================= | |
259 | ||
260 | const TopoDS_Shape& AIS_ConnectedShape::Shape() | |
261 | { | |
262 | UpdateShape(); | |
263 | return myOwnSh; | |
264 | } | |
265 | AIS_ConnectedShape::AIS_ConnectedShape(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d): | |
266 | AIS_ConnectedInteractive(aTypeOfPresentation3d) | |
267 | { | |
268 | SetHilightMode(0); | |
269 | } | |
270 | ||
271 | //======================================================================= | |
272 | //function : UpdateShape | |
273 | //purpose : if<WithLocation=False> computes only the deducted shape | |
274 | // from reference; does not put "myLocation" | |
275 | //======================================================================= | |
276 | void AIS_ConnectedShape::UpdateShape(const Standard_Boolean WithTheLocation) | |
277 | { | |
278 | if(myReference.IsNull()) return; | |
279 | ||
81bba717 | 280 | // attention great line... |
7fd59977 | 281 | if(myReference->Type()!=AIS_KOI_Shape) return; |
282 | ||
283 | Standard_Integer Sig = myReference->Signature(); | |
284 | ||
285 | TopoDS_Shape S ; | |
286 | switch(Sig){ | |
287 | case 0: | |
288 | S = (*((Handle(AIS_Shape)*) &myReference))->Shape(); | |
289 | break; | |
290 | case 1: | |
291 | S = (*((Handle(AIS_ConnectedShape)*) &myReference))->Shape(); | |
292 | break; | |
293 | case 2: | |
294 | S=(*((Handle(AIS_MultipleConnectedShape)*) &myReference))->Shape(); | |
295 | break; | |
296 | default: | |
297 | S = myOwnSh; | |
298 | } | |
299 | if(S.IsNull()) return; | |
300 | if(myLocation.IsIdentity() || !WithTheLocation) | |
301 | myOwnSh = S; | |
302 | else | |
303 | myOwnSh = S.Moved(myLocation); | |
304 | } | |
305 | ||
306 | ||
307 | //======================================================================= | |
308 | //function : Connect | |
309 | //purpose : | |
310 | //======================================================================= | |
311 | void AIS_ConnectedShape:: | |
312 | Connect(const Handle(AIS_InteractiveObject)& anotherIObj) | |
313 | { | |
314 | if(anotherIObj->Type()== AIS_KOI_Shape){ | |
315 | Standard_Integer Sig = anotherIObj->Signature(); | |
316 | if(Sig <=2) | |
317 | AIS_ConnectedInteractive::Connect(anotherIObj); | |
318 | } | |
319 | } | |
320 | ||
321 | //======================================================================= | |
322 | //function : Connect | |
323 | //purpose : | |
324 | //======================================================================= | |
325 | void AIS_ConnectedShape:: | |
326 | Connect(const Handle(AIS_InteractiveObject)& anotherIObj, | |
327 | const TopLoc_Location& aLocation) | |
328 | { | |
329 | if(anotherIObj->Type()== AIS_KOI_Shape){ | |
330 | Standard_Integer Sig = anotherIObj->Signature(); | |
331 | if(Sig <=2) | |
332 | AIS_ConnectedInteractive::Connect(anotherIObj,aLocation); | |
333 | } | |
334 | } | |
335 |