Replacing french comments by english one
[occt.git] / src / AIS / AIS_ConnectedShape.cxx
1 // File:        AIS_ConnectedShape.cxx
2 // Created:     Wed Apr 10 16:40:43 1996
3 // Author:      Guest Design
4 //              <g_design>
5
6
7 #include <Standard_NotImplemented.hxx>
8
9 #include <AIS_ConnectedShape.ixx>
10
11 #include <AIS_InteractiveContext.hxx>
12 #include <AIS_Drawer.hxx>
13 #include <TopAbs_ShapeEnum.hxx>
14 #include <StdPrs_WFDeflectionShape.hxx>
15 #include <StdPrs_HLRPolyShape.hxx>
16 #include <Prs3d_Drawer.hxx>
17 #include <Aspect_TypeOfDeflection.hxx>
18 #include <BRepTools.hxx>
19 #include <OSD_Timer.hxx>
20 #include <StdSelect_BRepSelectionTool.hxx>
21 #include <StdSelect_BRepOwner.hxx>
22 #include <StdSelect.hxx>
23 #include <TopTools_IndexedMapOfShape.hxx>
24 #include <TopExp.hxx>
25 #include <Select3D_SensitiveEntity.hxx>
26 #include <SelectMgr_EntityOwner.hxx>
27 #include <SelectBasics_EntityOwner.hxx>
28 #include <AIS_MultipleConnectedShape.hxx>
29 #include <Precision.hxx>
30
31 //=======================================================================
32 //function : AIS_ConnectedShape
33 //purpose  : 
34 //=======================================================================
35
36 AIS_ConnectedShape::AIS_ConnectedShape (const Handle(AIS_Shape)& TheAISShape,
37                                         const PrsMgr_TypeOfPresentation3d TheType): 
38 AIS_ConnectedInteractive(TheType)
39 {
40   myReference = TheAISShape;
41 }
42
43 AIS_ConnectedShape::AIS_ConnectedShape (const Handle(AIS_ConnectedShape)& TheConnectedShape,
44                                         const PrsMgr_TypeOfPresentation3d TheType): 
45 AIS_ConnectedInteractive(TheType)
46 {
47   myReference = TheConnectedShape;
48 }
49
50
51 //=======================================================================
52 //function : Type
53 //purpose  : 
54 //=======================================================================
55
56 AIS_KindOfInteractive AIS_ConnectedShape::Type() const
57 {return AIS_KOI_Shape;}
58
59 //=======================================================================
60 //function : Signature
61 //purpose  : 
62 //=======================================================================
63 Standard_Integer AIS_ConnectedShape::Signature() const
64 {return 1;}
65
66 //=======================================================================
67 //function : AcceptShapeDecomposition
68 //purpose  : 
69 //=======================================================================
70 Standard_Boolean AIS_ConnectedShape::AcceptShapeDecomposition() const 
71 {return Standard_True;}
72
73 //=======================================================================
74 //function : Compute Hidden Lines
75 //purpose  : 
76 //=======================================================================
77
78 void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
79                                  const Handle(Prs3d_Presentation)& aPresentation)
80 {
81   UpdateShape(Standard_True);
82   Compute(aProjector,aPresentation,myOwnSh);
83 }
84
85
86 //=======================================================================
87 //function : Compute
88 //purpose  : 
89 //=======================================================================
90 void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
91                                  const Handle(Geom_Transformation)& TheTrsf,
92                                  const Handle(Prs3d_Presentation)& aPresentation)
93 {
94   UpdateShape(Standard_False);
95   const TopLoc_Location& loc = myOwnSh.Location();
96   TopoDS_Shape shbis = myOwnSh.Located(TopLoc_Location(TheTrsf->Trsf())*loc);
97   Compute(aProjector,aPresentation,shbis);
98 }
99
100
101 //=======================================================================
102 //function : Compute
103 //purpose  : 
104 //=======================================================================
105
106 void AIS_ConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
107                                  const Handle(Prs3d_Presentation)& aPresentation,
108                                  const TopoDS_Shape& SH)
109 {
110 //  Standard_Boolean recompute = Standard_False;
111 //  Standard_Boolean myFirstCompute = Standard_True;
112   switch (SH.ShapeType()){
113   case TopAbs_VERTEX:
114   case TopAbs_EDGE:
115   case TopAbs_WIRE:
116     {
117       aPresentation->SetDisplayPriority(4);
118       StdPrs_WFDeflectionShape::Add(aPresentation,SH,myDrawer);
119       break;
120     }
121   default:
122     {
123       Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
124       if (defdrawer->DrawHiddenLine()) 
125         {myDrawer->EnableDrawHiddenLine();}
126       else {myDrawer->DisableDrawHiddenLine();}
127       
128       Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
129       defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
130
131       // process HLRAngle and HLRDeviationCoefficient()
132       Standard_Real prevangl = myDrawer->HLRAngle();
133       Standard_Real newangl = defdrawer->HLRAngle();
134       if (Abs(newangl- prevangl) > Precision::Angular()) {
135 #ifdef DEB
136         cout << "AIS_MultipleConnectedShape : compute"<<endl;
137         cout << "newangl   : " << newangl << " # de " << "prevangl  : " << prevangl << endl;
138 #endif  
139         BRepTools::Clean(SH);
140       }
141       myDrawer->SetHLRAngle(newangl);
142       myDrawer->SetHLRDeviationCoefficient(defdrawer->HLRDeviationCoefficient());
143       StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector);
144       defdrawer->SetTypeOfDeflection (prevdef);
145     }
146   }
147 }
148
149 //=======================================================================
150 //function : Compute
151 //purpose  : 
152 //=======================================================================
153
154 void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d& aPresentationManager2d,
155                                  const Handle_Graphic2d_GraphicObject& aGraphicObject,
156                                  const int anInteger)
157 {
158 // Standard_NotImplemented::Raise("AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d&, const Handle_Graphic2d_GraphicObject&, const int)");
159  AIS_ConnectedInteractive::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ; 
160 }
161
162 //=======================================================================
163 //function : Compute
164 //purpose  : 
165 //=======================================================================
166
167 void AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d& /*aPresentationManager3d*/,
168                                  const Handle_Prs3d_Presentation& /*aPresentation*/,
169                                  const int /*anInteger*/)
170 {
171  Standard_NotImplemented::Raise("AIS_ConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d&, const Handle_Prs3d_Presentation&, const int)");
172 // AIS_ConnectedInteractive::Compute( aPresentationManager3d ,aPresentation,anInteger) ;  not accessible
173 }
174
175 //=======================================================================
176 //function : ComputeSelection 
177 //purpose  : Attention fragile...
178 //=======================================================================
179
180 void AIS_ConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
181                                            const Standard_Integer             aMode)
182 {
183   UpdateShape();
184   aSelection->Clear();
185   // It is checked if there is nothing to do with the reference
186   // of type update...
187   
188   if(!myReference->HasSelection(aMode))
189     myReference->UpdateSelection(aMode);
190   const Handle(SelectMgr_Selection)& RefSel = myReference->Selection(aMode);
191   if(RefSel->IsEmpty())
192     myReference->UpdateSelection(aMode);
193   if(RefSel->UpdateStatus()==SelectMgr_TOU_Full)
194     myReference->UpdateSelection(aMode);
195
196   // depending on the type of decomposition, connected primitives are subtracted
197   // it is necessary to follow the order of creation of StdSelect_BRepSelectionTool...
198   
199   TopAbs_ShapeEnum TheType = AIS_Shape::SelectionType(aMode);
200   Handle(StdSelect_BRepOwner) OWNR;
201   Handle(Select3D_SensitiveEntity) SE,NiouSE;
202   TopLoc_Location BidLoc;
203
204   switch(TheType){
205   case TopAbs_VERTEX:
206   case TopAbs_EDGE:
207   case TopAbs_WIRE:
208   case TopAbs_FACE:
209   case TopAbs_SHELL:
210     {
211       TopTools_IndexedMapOfShape subshaps;
212       TopExp::MapShapes(myOwnSh,TheType,subshaps);
213
214       RefSel->Init();
215       for(Standard_Integer I=1;
216           I<=subshaps.Extent()&& RefSel->More();
217           RefSel->Next(),I++){
218         
219         SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive()));
220         if(!SE.IsNull()){
221           OWNR = new StdSelect_BRepOwner(subshaps(I),this,SE->OwnerId()->Priority());
222           
223           
224           if(myLocation.IsIdentity())
225             NiouSE = SE->GetConnected(BidLoc);
226           else
227             NiouSE = SE->GetConnected(myLocation);
228           NiouSE->Set(OWNR);
229           aSelection->Add(NiouSE);
230         }
231       }
232      break;
233     }
234     
235   case TopAbs_SHAPE:
236   default:
237     {
238       // In case if there is only one owner of the set of
239       // sensible primitives...
240       OWNR = new StdSelect_BRepOwner(myOwnSh,this);
241       Standard_Boolean FirstIncr(Standard_True);
242       for(RefSel->Init();RefSel->More();RefSel->Next()){
243         SE = *((Handle(Select3D_SensitiveEntity)*) &(RefSel->Sensitive()));
244         if(FirstIncr){
245           Standard_Integer Prior = SE->OwnerId()->Priority();
246           Handle(SelectBasics_EntityOwner)::DownCast(OWNR)->Set(Prior);
247           FirstIncr = Standard_False;}
248
249         if(myLocation.IsIdentity())
250           NiouSE = SE->GetConnected(BidLoc);
251         else
252           NiouSE = SE->GetConnected(myLocation);
253         NiouSE->Set(OWNR);
254         aSelection->Add(NiouSE);
255       }
256       break;
257     }
258   }
259   StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
260   
261 }
262  
263
264 //=======================================================================
265 //function : Shape
266 //purpose  : 
267 //=======================================================================
268
269 const TopoDS_Shape& AIS_ConnectedShape::Shape()
270
271   UpdateShape(); 
272   return myOwnSh;
273 }
274 AIS_ConnectedShape::AIS_ConnectedShape(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):
275 AIS_ConnectedInteractive(aTypeOfPresentation3d)
276 {    
277   SetHilightMode(0);
278 }
279   
280 //=======================================================================
281 //function : UpdateShape
282 //purpose  : if<WithLocation=False> computes only the deducted shape
283 //           from reference; does not put "myLocation"
284 //=======================================================================
285 void AIS_ConnectedShape::UpdateShape(const Standard_Boolean WithTheLocation)
286 {
287   if(myReference.IsNull()) return;
288
289   // attention great line...
290   if(myReference->Type()!=AIS_KOI_Shape) return;
291
292   Standard_Integer Sig = myReference->Signature();
293   
294   TopoDS_Shape S ;
295   switch(Sig){
296   case 0:
297     S = (*((Handle(AIS_Shape)*) &myReference))->Shape();
298     break;
299   case 1:
300     S = (*((Handle(AIS_ConnectedShape)*) &myReference))->Shape();
301     break;
302   case 2:
303     S=(*((Handle(AIS_MultipleConnectedShape)*) &myReference))->Shape();
304     break;
305   default:
306     S = myOwnSh;
307   }
308   if(S.IsNull()) return;
309   if(myLocation.IsIdentity() || !WithTheLocation) 
310     myOwnSh = S;
311   else
312     myOwnSh = S.Moved(myLocation);
313 }
314
315
316 //=======================================================================
317 //function : Connect
318 //purpose  : 
319 //=======================================================================
320 void AIS_ConnectedShape::
321 Connect(const Handle(AIS_InteractiveObject)& anotherIObj)
322 {
323   if(anotherIObj->Type()== AIS_KOI_Shape){
324     Standard_Integer Sig = anotherIObj->Signature();
325     if(Sig <=2)
326       AIS_ConnectedInteractive::Connect(anotherIObj);
327   }
328 }
329
330 //=======================================================================
331 //function : Connect
332 //purpose  : 
333 //=======================================================================
334 void AIS_ConnectedShape::
335 Connect(const Handle(AIS_InteractiveObject)& anotherIObj, 
336         const TopLoc_Location& aLocation)
337 {
338   if(anotherIObj->Type()== AIS_KOI_Shape){
339     Standard_Integer Sig = anotherIObj->Signature();
340     if(Sig <=2)
341       AIS_ConnectedInteractive::Connect(anotherIObj,aLocation);
342   }
343 }
344