summaryrefslogtreecommitdiff
path: root/src/AIS/AIS_ConnectedShape.cxx
blob: 4575599c94a317ec162492471a430ffa6e400bad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// File:	AIS_ConnectedShape.cxx
// Created:	Wed Apr 10 16:40:43 1996
// Author:	Guest Design
//		<g_design>


#include <Standard_NotImplemented.hxx>

#include <AIS_ConnectedShape.ixx>

#include <AIS_InteractiveContext.hxx>
#include <AIS_Drawer.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <StdPrs_WFDeflectionShape.hxx>
#include <StdPrs_HLRPolyShape.hxx>
#include <Prs3d_Drawer.hxx>
#include <Aspect_TypeOfDeflection.hxx>
#include <BRepTools.hxx>
#include <OSD_Timer.hxx>
#include <StdSelect_BRepSelectionTool.hxx>
#include <StdSelect_BRepOwner.hxx>
#include <StdSelect.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <AIS_MultipleConnectedShape.hxx>
#include <Precision.hxx>

//=======================================================================
//function : AIS_ConnectedShape
//purpose  : 
//=======================================================================

AIS_ConnectedShape::AIS_ConnectedShape (const Handle(AIS_Shape)& TheAISShape,
					const PrsMgr_TypeOfPresentation3d TheType): 
AIS_ConnectedInteractive(TheType)
{
  myReference = TheAISShape;
}

AIS_ConnectedShape::AIS_ConnectedShape (const Handle(AIS_ConnectedShape)& TheConnectedShape,
					const PrsMgr_TypeOfPresentation3d TheType): 
AIS_ConnectedInteractive(TheType)
{
  myReference = TheConnectedShape;
}


//=======================================================================
//function : Type
//purpose  : 
//=======================================================================

AIS_KindOfInteractive AIS_ConnectedShape::Type() const
{return AIS_KOI_Shape;}

//=======================================================================
//function : Signature
//purpose  : 
//=======================================================================
Standard_Integer AIS_ConnectedShape::Signature() const
{return 1;}

//=======================================================================
//function : AcceptShapeDecomposition
//purpose  : 
//=======================================================================
Standard_Boolean AIS_ConnectedShape::AcceptShapeDecomposition() const 
{return Standard_True;}

//=======================================================================
//function : Compute Hidden Lines
//purpose  : 
//=======================================================================

void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
				 const Handle(Prs3d_Presentation)& aPresentation)
{
  UpdateShape(Standard_True);
  Compute(aProjector,aPresentation,myOwnSh);
}


//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================
void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
				 const Handle(Geom_Transformation)& TheTrsf,
				 const Handle(Prs3d_Presentation)& aPresentation)
{
  UpdateShape(Standard_False);
  const TopLoc_Location& loc = myOwnSh.Location();
  TopoDS_Shape shbis = myOwnSh.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
  Compute(aProjector,aPresentation,shbis);
}


//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================

void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
				 const Handle(Prs3d_Presentation)& aPresentation,
				 const TopoDS_Shape& SH)
{
//  Standard_Boolean recompute = Standard_False;
//  Standard_Boolean myFirstCompute = Standard_True;
  switch (SH.ShapeType()){
  case TopAbs_VERTEX:
  case TopAbs_EDGE:
  case TopAbs_WIRE:
    {
      aPresentation->SetDisplayPriority(4);
      StdPrs_WFDeflectionShape::Add(aPresentation,SH,myDrawer);
      break;
    }
  default:
    {
      Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
      if (defdrawer->DrawHiddenLine()) 
	{myDrawer->EnableDrawHiddenLine();}
      else {myDrawer->DisableDrawHiddenLine();}
      
      Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
      defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);

      // process HLRAngle and HLRDeviationCoefficient()
      Standard_Real prevangl = myDrawer->HLRAngle();
      Standard_Real newangl = defdrawer->HLRAngle();
      if (Abs(newangl- prevangl) > Precision::Angular()) {
#ifdef DEB
	cout << "AIS_MultipleConnectedShape : compute"<<endl;
	cout << "newangl   : " << newangl << " # de " << "prevangl  : " << prevangl << endl;
#endif	
	BRepTools::Clean(SH);
      }
      myDrawer->SetHLRAngle(newangl);
      myDrawer->SetHLRDeviationCoefficient(defdrawer->HLRDeviationCoefficient());
      StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector);
      defdrawer->SetTypeOfDeflection (prevdef);
    }
  }
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================

void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d& aPresentationManager2d,
                                 const Handle_Graphic2d_GraphicObject& aGraphicObject,
                                 const int anInteger)
{
// Standard_NotImplemented::Raise("AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d&, const Handle_Graphic2d_GraphicObject&, const int)");
 AIS_ConnectedInteractive::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ; 
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================

void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d& /*aPresentationManager3d*/,
                                 const Handle_Prs3d_Presentation& /*aPresentation*/,
                                 const int /*anInteger*/)
{
 Standard_NotImplemented::Raise("AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d&, const Handle_Prs3d_Presentation&, const int)");
// AIS_ConnectedInteractive::Compute( aPresentationManager3d ,aPresentation,anInteger) ;  not accessible
}

//=======================================================================
//function : ComputeSelection 
//purpose  : Attention fragile...
//=======================================================================

void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
					   const Standard_Integer             aMode)
{
  UpdateShape();
  aSelection->Clear();
  // It is checked if there is nothing to do with the reference
  // of type update...
  
  if(!myReference->HasSelection(aMode))
    myReference->UpdateSelection(aMode);
  const Handle(SelectMgr_Selection)& RefSel = myReference->Selection(aMode);
  if(RefSel->IsEmpty())
    myReference->UpdateSelection(aMode);
  if(RefSel->UpdateStatus()==SelectMgr_TOU_Full)
    myReference->UpdateSelection(aMode);

  // depending on the type of decomposition, connected primitives are subtracted
  // it is necessary to follow the order of creation of StdSelect_BRepSelectionTool...
  
  TopAbs_ShapeEnum TheType = AIS_Shape::SelectionType(aMode);
  Handle(StdSelect_BRepOwner) OWNR;
  Handle(Select3D_SensitiveEntity) SE,NiouSE;
  TopLoc_Location BidLoc;

  switch(TheType){
  case TopAbs_VERTEX:
  case TopAbs_EDGE:
  case TopAbs_WIRE:
  case TopAbs_FACE:
  case TopAbs_SHELL:
    {
      TopTools_IndexedMapOfShape subshaps;
      TopExp::MapShapes(myOwnSh,TheType,subshaps);

      RefSel->Init();
      for(Standard_Integer I=1;
	  I<=subshaps.Extent()&& RefSel->More();
	  RefSel->Next(),I++){
	
	SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive()));
	if(!SE.IsNull()){
	  OWNR = new StdSelect_BRepOwner(subshaps(I),this,SE->OwnerId()->Priority());
	  
	  
	  if(myLocation.IsIdentity())
	    NiouSE = SE->GetConnected(BidLoc);
	  else
	    NiouSE = SE->GetConnected(myLocation);
	  NiouSE->Set(OWNR);
	  aSelection->Add(NiouSE);
	}
      }
     break;
    }
    
  case TopAbs_SHAPE:
  default:
    {
      // In case if there is only one owner of the set of
      // sensible primitives...
      OWNR = new StdSelect_BRepOwner(myOwnSh,this);
      Standard_Boolean FirstIncr(Standard_True);
      for(RefSel->Init();RefSel->More();RefSel->Next()){
	SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive()));
	if(FirstIncr){
	  Standard_Integer Prior = SE->OwnerId()->Priority();
	  Handle(SelectBasics_EntityOwner)::DownCast(OWNR)->Set(Prior);
	  FirstIncr = Standard_False;}

	if(myLocation.IsIdentity())
	  NiouSE = SE->GetConnected(BidLoc);
	else
	  NiouSE = SE->GetConnected(myLocation);
	NiouSE->Set(OWNR);
	aSelection->Add(NiouSE);
      }
      break;
    }
  }
  StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
  
}
 

//=======================================================================
//function : Shape
//purpose  : 
//=======================================================================

const TopoDS_Shape& AIS_ConnectedShape::Shape()
{ 
  UpdateShape(); 
  return myOwnSh;
}
AIS_ConnectedShape::AIS_ConnectedShape(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
AIS_ConnectedInteractive(aTypeOfPresentation3d)
{    
  SetHilightMode(0);
}
  
//=======================================================================
//function : UpdateShape
//purpose  : if<WithLocation=False> computes only the deducted shape
//           from reference; does not put "myLocation"
//=======================================================================
void AIS_ConnectedShape::UpdateShape(const Standard_Boolean WithTheLocation)
{
  if(myReference.IsNull()) return;

  // attention great line...
  if(myReference->Type()!=AIS_KOI_Shape) return;

  Standard_Integer Sig = myReference->Signature();
  
  TopoDS_Shape S ;
  switch(Sig){
  case 0:
    S = (*((Handle(AIS_Shape)*) &myReference))->Shape();
    break;
  case 1:
    S = (*((Handle(AIS_ConnectedShape)*) &myReference))->Shape();
    break;
  case 2:
    S=(*((Handle(AIS_MultipleConnectedShape)*) &myReference))->Shape();
    break;
  default:
    S = myOwnSh;
  }
  if(S.IsNull()) return;
  if(myLocation.IsIdentity() || !WithTheLocation) 
    myOwnSh = S;
  else
    myOwnSh = S.Moved(myLocation);
}


//=======================================================================
//function : Connect
//purpose  : 
//=======================================================================
void AIS_ConnectedShape::
Connect(const Handle(AIS_InteractiveObject)& anotherIObj)
{
  if(anotherIObj->Type()== AIS_KOI_Shape){
    Standard_Integer Sig = anotherIObj->Signature();
    if(Sig <=2)
      AIS_ConnectedInteractive::Connect(anotherIObj);
  }
}

//=======================================================================
//function : Connect
//purpose  : 
//=======================================================================
void AIS_ConnectedShape::
Connect(const Handle(AIS_InteractiveObject)& anotherIObj, 
	const TopLoc_Location& aLocation)
{
  if(anotherIObj->Type()== AIS_KOI_Shape){
    Standard_Integer Sig = anotherIObj->Signature();
    if(Sig <=2)
      AIS_ConnectedInteractive::Connect(anotherIObj,aLocation);
  }
}