b0a24b790a270b944973ff6eee5000110e0c5969
[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   AIS_MultipleConnectedInteractive::Compute( aPresentationManager3d , aPresentation , anint ) ;
172 }
173
174 //=======================================================================
175 //function : Compute
176 //purpose  : 
177 //=======================================================================
178
179 void AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d& aPresentationManager2d,
180                                          const Handle_Graphic2d_GraphicObject& aGraphicObject,
181                                          const int anInteger)
182 {
183 // Standard_NotImplemented::Raise("AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager2d&, const Handle_Graphic2d_GraphicObject&, const int)");
184  PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
185 }
186
187 //=======================================================================
188 //function : ComputeSelection 
189 //purpose  : 
190 //=======================================================================
191
192 void AIS_MultipleConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
193                                                    const Standard_Integer             aMode)
194 {
195   //cout<<"AIS_MultipleConnectedShape::ComputeSelection"<<endl;
196
197   Standard_Real aDeviationAngle = myDrawer->DeviationAngle();
198   Standard_Real aDeflection = myDrawer->MaximalChordialDeviation();
199   if (myDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
200   {
201     // On calcule la fleche en fonction des min max globaux de la piece:
202     Bnd_Box aBndBox; //= BoundingBox(); ?
203     BRepBndLib::Add (myShape, aBndBox);
204     if (!aBndBox.IsVoid())
205     {
206       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
207       aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
208       aDeflection = Max (aXmax - aXmin, Max (aYmax - aYmin, aZmax - aZmin)) * myDrawer->DeviationCoefficient();
209     }
210   }
211
212   switch(aMode){
213   case 1:
214     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_VERTEX, aDeflection, aDeviationAngle);
215     break;
216   case 2:
217     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_EDGE, aDeflection, aDeviationAngle);
218       break;
219   case 3:
220     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_WIRE, aDeflection, aDeviationAngle);
221     break;
222   case 4:
223     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_FACE, aDeflection, aDeviationAngle);
224     break;
225   case 5:
226     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHELL, aDeflection, aDeviationAngle);
227     break;
228   case 6:
229     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SOLID, aDeflection, aDeviationAngle);
230     break;
231   case 7:
232     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPOUND, aDeflection, aDeviationAngle);
233     break;
234   case 8:
235     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPSOLID, aDeflection, aDeviationAngle);
236     break;
237   default:
238     StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHAPE, aDeflection, aDeviationAngle);
239     break;
240   }
241   // insert the drawer in the BrepOwners for hilight...
242   StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
243   
244 }
245
246   
247   
248