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