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