Integration of OCCT 6.5.0 from SVN
[occt.git] / src / AIS / AIS_MultipleConnectedShape.cxx
1 // File:        AIS_MultipleConnectedShape.cxx
2 // Created:     Tue Apr 22 17:43:42 1997
3 // Author:      Guest Design
4 //              <g_design>
5
6
7 #include <Standard_NotImplemented.hxx>
8
9 #include <AIS_MultipleConnectedShape.ixx>
10
11
12
13 #include <AIS_InteractiveContext.hxx>
14 #include <AIS_Drawer.hxx>
15 #include <TopAbs_ShapeEnum.hxx>
16 #include <StdPrs_WFDeflectionShape.hxx>
17 #include <StdPrs_HLRPolyShape.hxx>
18 #include <Prs3d_Drawer.hxx>
19 #include <Aspect_TypeOfDeflection.hxx>
20 #include <Bnd_Box.hxx>
21 #include <BRepTools.hxx>
22 #include <BRepBndLib.hxx>
23 #include <OSD_Timer.hxx>
24 #include <StdSelect_BRepSelectionTool.hxx>
25 #include <StdSelect.hxx>
26 #include <Precision.hxx>
27
28 //=======================================================================
29 //function : AIS_ConnectedShape
30 //purpose  : 
31 //=======================================================================
32
33 AIS_MultipleConnectedShape::AIS_MultipleConnectedShape (const TopoDS_Shape& aShape):
34 AIS_MultipleConnectedInteractive(PrsMgr_TOP_ProjectorDependant),
35 myShape(aShape)
36 {
37 }
38
39 //=======================================================================
40 //function : Type
41 //purpose  : 
42 //=======================================================================
43 AIS_KindOfInteractive AIS_MultipleConnectedShape::Type() const
44 {return AIS_KOI_Shape;}
45
46
47 //=======================================================================
48 //function : Signature
49 //purpose  : 
50 //=======================================================================
51 Standard_Integer AIS_MultipleConnectedShape::Signature() const
52 {return 2;}
53
54
55 //=======================================================================
56 //function : AcceptShapeDecomposition
57 //purpose  : 
58 //=======================================================================
59
60 Standard_Boolean AIS_MultipleConnectedShape::AcceptShapeDecomposition() const 
61 {return Standard_True;}
62
63
64
65
66 //=======================================================================
67 //function : Compute Hidden Lines
68 //purpose  : 
69 //=======================================================================
70
71 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
72                                          const Handle(Prs3d_Presentation)& aPresentation)
73 {
74   Compute(aProjector,aPresentation,myShape);
75   
76 }
77
78 //=======================================================================
79 //function : Compute
80 //purpose  : 
81 //=======================================================================
82
83 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
84                                          const Handle(Geom_Transformation)& aTrsf,
85                                          const Handle(Prs3d_Presentation)& aPresentation)
86 {
87   aPresentation->Clear();
88
89   const TopLoc_Location& loc = myShape.Location();
90   TopoDS_Shape shbis = myShape.Located(TopLoc_Location(aTrsf->Trsf())*loc);
91   Compute(aProjector,aPresentation,shbis);
92 }
93
94
95
96   
97 void AIS_MultipleConnectedShape::Compute(const Handle(Prs3d_Projector)& aProjector, 
98                                          const Handle(Prs3d_Presentation)& aPresentation,
99                                          const TopoDS_Shape& SH)
100 {
101   //Standard_Boolean recompute = Standard_False;
102   //Standard_Boolean myFirstCompute = Standard_True;
103   switch (SH.ShapeType()){
104   case TopAbs_VERTEX:
105   case TopAbs_EDGE:
106   case TopAbs_WIRE:
107     {
108       aPresentation->SetDisplayPriority(4);
109       StdPrs_WFDeflectionShape::Add(aPresentation,SH,myDrawer);
110       break;
111     }
112   default:
113     {
114       
115       Handle (Prs3d_Drawer) defdrawer = GetContext()->DefaultDrawer();
116       if (defdrawer->DrawHiddenLine()) 
117         {myDrawer->EnableDrawHiddenLine();}
118       else {myDrawer->DisableDrawHiddenLine();}
119       
120       Aspect_TypeOfDeflection prevdef = defdrawer->TypeOfDeflection();
121       defdrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
122
123       // traitement HLRAngle et HLRDeviationCoefficient()
124       Standard_Real prevangl = myDrawer->HLRAngle();
125       Standard_Real newangl = defdrawer->HLRAngle();
126       if (Abs(newangl- prevangl) > Precision::Angular()) {
127 #ifdef DEB
128         cout << "AIS_MultipleConnectedShape : compute"<<endl;
129         cout << "newangl   : " << newangl << " # de " << "prevangl  : " << prevangl << endl;
130 #endif  
131         BRepTools::Clean(SH);
132       }
133       myDrawer->SetHLRAngle(newangl);
134       myDrawer->SetHLRDeviationCoefficient(defdrawer->HLRDeviationCoefficient());
135       
136       StdPrs_HLRPolyShape::Add(aPresentation,SH,myDrawer,aProjector);
137       
138       
139       defdrawer->SetTypeOfDeflection (prevdef);
140       
141     }
142   }
143 }
144   
145 //=======================================================================
146 //function : Compute
147 //purpose  : 
148 //=======================================================================
149
150 void AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d& /*aPresentationManager3d*/,
151                                          const Handle_Prs3d_Presentation& /*aPresentation*/,
152                                          const int /*anint*/)
153 {
154  Standard_NotImplemented::Raise("AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d&, const Handle_Prs3d_Presentation&, const int)");
155 // AIS_MultipleConnectedInteractive::Compute( aPresentationManager3d , aPresentation , anint ) ; Not accessible
156 }
157
158 //=======================================================================
159 //function : Compute
160 //purpose  : 
161 //=======================================================================
162
163 void AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d& aPresentationManager2d,
164                                          const Handle_Graphic2d_GraphicObject& aGraphicObject,
165                                          const int anInteger)
166 {
167 // Standard_NotImplemented::Raise("AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d&, const Handle_Graphic2d_GraphicObject&, const int)");
168  PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
169 }
170
171 //=======================================================================
172 //function : ComputeSelection 
173 //purpose  : 
174 //=======================================================================
175
176 void AIS_MultipleConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
177                                                    const Standard_Integer             aMode)
178 {
179   //cout<<"AIS_MultipleConnectedShape::ComputeSelection"<<endl;
180
181   Standard_Real aDeviationAngle = myDrawer->DeviationAngle();
182   Standard_Real aDeflection = myDrawer->MaximalChordialDeviation();
183   if (myDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
184   {
185     // On calcule la fleche en fonction des min max globaux de la piece:
186     Bnd_Box aBndBox; //= BoundingBox(); ?
187     BRepBndLib::Add (myShape, aBndBox);
188     if (!aBndBox.IsVoid())
189     {
190       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
191       aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
192       aDeflection = Max (aXmax - aXmin, Max (aYmax - aYmin, aZmax - aZmin)) * myDrawer->DeviationCoefficient();
193     }
194   }
195
196   switch(aMode){
197   case 1:
198     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_VERTEX, aDeflection, aDeviationAngle);
199     break;
200   case 2:
201     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_EDGE, aDeflection, aDeviationAngle);
202       break;
203   case 3:
204     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_WIRE, aDeflection, aDeviationAngle);
205     break;
206   case 4:
207     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_FACE, aDeflection, aDeviationAngle);
208     break;
209   case 5:
210     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHELL, aDeflection, aDeviationAngle);
211     break;
212   case 6:
213     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SOLID, aDeflection, aDeviationAngle);
214     break;
215   case 7:
216     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPOUND, aDeflection, aDeviationAngle);
217     break;
218   case 8:
219     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPSOLID, aDeflection, aDeviationAngle);
220     break;
221   default:
222     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHAPE, aDeflection, aDeviationAngle);
223     break;
224   }
225   // insert the drawer in the BrepOwners for hilight...
226   StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
227   
228 }
229
230   
231   
232