0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / AIS / AIS_MultipleConnectedShape.cxx
CommitLineData
b311480e 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
7fd59977 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
50AIS_MultipleConnectedShape::AIS_MultipleConnectedShape (const TopoDS_Shape& aShape):
51AIS_MultipleConnectedInteractive(PrsMgr_TOP_ProjectorDependant),
52myShape(aShape)
53{
54}
55
56//=======================================================================
57//function : Type
58//purpose :
59//=======================================================================
60AIS_KindOfInteractive AIS_MultipleConnectedShape::Type() const
61{return AIS_KOI_Shape;}
62
63
64//=======================================================================
65//function : Signature
66//purpose :
67//=======================================================================
68Standard_Integer AIS_MultipleConnectedShape::Signature() const
69{return 2;}
70
71
72//=======================================================================
73//function : AcceptShapeDecomposition
74//purpose :
75//=======================================================================
76
77Standard_Boolean AIS_MultipleConnectedShape::AcceptShapeDecomposition() const
78{return Standard_True;}
79
80
81
82
83//=======================================================================
84//function : Compute Hidden Lines
85//purpose :
86//=======================================================================
87
88void 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
100void 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
114void 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
792c785c 167void AIS_MultipleConnectedShape::Compute(const Handle_PrsMgr_PresentationManager3d& aPresentationManager3d,
168 const Handle_Prs3d_Presentation& aPresentation,
169 const int anint)
7fd59977 170{
792c785c 171 AIS_MultipleConnectedInteractive::Compute( aPresentationManager3d , aPresentation , anint ) ;
7fd59977 172}
173
7fd59977 174//=======================================================================
175//function : ComputeSelection
176//purpose :
177//=======================================================================
178
179void AIS_MultipleConnectedShape::ComputeSelection (const Handle(SelectMgr_Selection)& aSelection,
180 const Standard_Integer aMode)
181{
182 //cout<<"AIS_MultipleConnectedShape::ComputeSelection"<<endl;
183
184 Standard_Real aDeviationAngle = myDrawer->DeviationAngle();
185 Standard_Real aDeflection = myDrawer->MaximalChordialDeviation();
186 if (myDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE)
187 {
188 // On calcule la fleche en fonction des min max globaux de la piece:
189 Bnd_Box aBndBox; //= BoundingBox(); ?
190 BRepBndLib::Add (myShape, aBndBox);
191 if (!aBndBox.IsVoid())
192 {
193 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
194 aBndBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
195 aDeflection = Max (aXmax - aXmin, Max (aYmax - aYmin, aZmax - aZmin)) * myDrawer->DeviationCoefficient();
196 }
197 }
198
199 switch(aMode){
200 case 1:
201 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_VERTEX, aDeflection, aDeviationAngle);
202 break;
203 case 2:
204 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_EDGE, aDeflection, aDeviationAngle);
205 break;
206 case 3:
207 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_WIRE, aDeflection, aDeviationAngle);
208 break;
209 case 4:
210 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_FACE, aDeflection, aDeviationAngle);
211 break;
212 case 5:
213 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHELL, aDeflection, aDeviationAngle);
214 break;
215 case 6:
216 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SOLID, aDeflection, aDeviationAngle);
217 break;
218 case 7:
219 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPOUND, aDeflection, aDeviationAngle);
220 break;
221 case 8:
222 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_COMPSOLID, aDeflection, aDeviationAngle);
223 break;
224 default:
225 StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHAPE, aDeflection, aDeviationAngle);
226 break;
227 }
228 // insert the drawer in the BrepOwners for hilight...
229 StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
230
231}
232
233
234
235