0024624: Lost word in license statement in source files
[occt.git] / src / AIS / AIS_MinRadiusDimension.cxx
CommitLineData
b311480e 1// Created on: 1998-01-27
2// Created by: Sergey ZARITCHNY
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
18// if any in all dimensions.
19
20#include <Standard_NotImplemented.hxx>
21
22#include <AIS_MinRadiusDimension.ixx>
23
24#include <AIS_EllipseRadiusDimension.hxx>
25#include <TCollection_ExtendedString.hxx>
26
a6eb515f 27#include <Prs3d_DimensionAspect.hxx>
7fd59977 28#include <Prs3d_ArrowAspect.hxx>
29#include <Prs3d_Drawer.hxx>
30#include <Prs3d_TextAspect.hxx>
31#include <Prs3d_Text.hxx>
32
33#include <Select3D_SensitiveSegment.hxx>
34#include <Select3D_SensitiveCurve.hxx>
35#include <Select3D_SensitiveBox.hxx>
36#include <SelectMgr_EntityOwner.hxx>
37
38#include <ElCLib.hxx>
39#include <ElSLib.hxx>
40
41#include <TopoDS.hxx>
42
43#include <BRepAdaptor_Surface.hxx>
44#include <BRepAdaptor_Curve.hxx>
45
46#include <Geom_Ellipse.hxx>
47#include <Geom_TrimmedCurve.hxx>
48#include <Geom_Plane.hxx>
49#include <Geom_Surface.hxx>
50#include <Geom_CylindricalSurface.hxx>
51#include <Geom_SurfaceOfRevolution.hxx>
52#include <Geom_CylindricalSurface.hxx>
53#include <Geom_SurfaceOfLinearExtrusion.hxx>
54
55#include <gp_Pln.hxx>
56#include <gp_Pnt.hxx>
57#include <gp_Lin.hxx>
58#include <gp_Ax1.hxx>
59#include <gp_Dir.hxx>
60#include <gp_Vec.hxx>
61
62#include <AIS.hxx>
63#include <AIS_Drawer.hxx>
64
65#include <Precision.hxx>
66#include <DsgPrs_EllipseRadiusPresentation.hxx>
67
68
69//=======================================================================
70//function : AIS_MinRadiusDimension
71//purpose :
72//=======================================================================
73
74AIS_MinRadiusDimension::AIS_MinRadiusDimension(const TopoDS_Shape& aShape,
75 const Standard_Real aVal,
76 const TCollection_ExtendedString& aText)
77:AIS_EllipseRadiusDimension(aShape, aText)
78{
79 myVal = aVal;
80 mySymbolPrs = DsgPrs_AS_LASTAR;
81 myAutomaticPosition = Standard_True;
82 myArrowSize = myVal / 100.;
83}
84
85//=======================================================================
86//function : AIS_MinRadiusDimension
87//purpose :
88//=======================================================================
89
90AIS_MinRadiusDimension::AIS_MinRadiusDimension(const TopoDS_Shape& aShape,
91 const Standard_Real aVal,
92 const TCollection_ExtendedString& aText,
93 const gp_Pnt& aPosition,
94 const DsgPrs_ArrowSide aSymbolPrs,
95 const Standard_Real anArrowSize)
96:AIS_EllipseRadiusDimension(aShape, aText)
97{
98 myVal = aVal;
99 mySymbolPrs = aSymbolPrs;
100 myPosition = aPosition;
101 myAutomaticPosition = Standard_False;
102#ifdef BUC60915
103 SetArrowSize( anArrowSize );
104#else
105 myArrowSize = anArrowSize;
106#endif
107}
108
109//=======================================================================
110//function : Compute
111//purpose :
112//=======================================================================
113
114void AIS_MinRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
115 const Handle(Prs3d_Presentation)& aPresentation,
116 const Standard_Integer /*aMode*/)
117{
118 aPresentation->Clear();
119
120// if( myAutomaticPosition )
121 //{ //ota : recompute ellipse always
122 ComputeGeometry();
123 myEllipse.SetMinorRadius(myVal);
124 gp_Vec v1(myEllipse.YAxis().Direction());
125 v1 *=myVal;
126 myApexP = myEllipse.Location().Translated(v1);
127 myApexN = myEllipse.Location().Translated(-v1);
128// }
129 if(myIsAnArc) ComputeArcOfEllipse(aPresentation);
130 else
131 ComputeEllipse(aPresentation);
132}
133
134//=======================================================================
135//function : Compute
136//purpose : to avoid warning
137//=======================================================================
138
139void AIS_MinRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
140 const Handle(Prs3d_Presentation)& aPresentation)
141{
142// Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)");
143 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
144}
145
146//=======================================================================
147//function : Compute
7fd59977 148//purpose :
149//=======================================================================
150
151void AIS_MinRadiusDimension::Compute(const Handle_Prs3d_Projector& aProjector,
152 const Handle_Geom_Transformation& aTransformation,
153 const Handle_Prs3d_Presentation& aPresentation)
154{
155// Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
156 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
157}
158
159//=======================================================================
160//function : ComputeEllipse
161//purpose :
162//=======================================================================
163
164void AIS_MinRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
165{
166
a6eb515f 167 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
168 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 169
170 // size
171#ifdef BUC60915
172 if( !myArrowSizeIsDefined ) {
173 myArrowSize = Min(myArrowSize,myVal/5.);
174 }
175 arr->SetLength(myArrowSize);
176#else
177 if (myVal/5. > myArrowSize) {
178 arr->SetLength(myArrowSize);
179 }
180 else {
181 arr->SetLength(myVal/5.);
182 }
183#endif
184
185 Standard_Real U;//,V;
186 gp_Pnt curPos, Center;
187 Center = myEllipse.Location();
188 if( myAutomaticPosition )
189 {
190 myPosition = Center;
191 myEndOfArrow = myApexP;
192 myAutomaticPosition = Standard_True;
193
194 if ( myIsSetBndBox )
195 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
196 myBndBox );
197 curPos = myPosition;
198 }
199 else //!AutomaticPosition
200 {
201 curPos = myPosition;
202 gp_Lin L1(myEllipse.YAxis());
203 U = ElCLib::Parameter ( L1, curPos );
204 curPos = ElCLib::Value (U, L1);
205 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
206 myEndOfArrow = myApexP ;
207 else
208 myEndOfArrow = myApexN ;
209 myPosition = curPos;
210 }
211
212 // Presenatation
213 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
214 myEndOfArrow, Center, Standard_False, mySymbolPrs);
215
216}
217
218//=======================================================================
219//function : ComputeArcOfEllipse
220//purpose :
221//=======================================================================
222
223void AIS_MinRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
224{
225
a6eb515f 226 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
227 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 228
229 // size
230#ifdef BUC60915
231 if( !myArrowSizeIsDefined ) {
232 myArrowSize = Min(myArrowSize,myVal/5.);
233 }
234 arr->SetLength(myArrowSize);
235#else
236 if (myVal/5. > myArrowSize) {
237 arr->SetLength(myArrowSize);
238 }
239 else {
240 arr->SetLength(myVal/5.);
241 }
242#endif
243
244 Standard_Real par;
245 gp_Pnt curPos, Center;
246 Center = myEllipse.Location();
247 Standard_Boolean IsInDomain = Standard_True;
248 if( myAutomaticPosition )
249 {
250 myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN,
251 myFirstPar, myLastPar, IsInDomain);
252 myPosition = Center;
253 myAutomaticPosition = Standard_True;
254 if ( myIsSetBndBox )
255 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
256 myBndBox );
257 curPos = myPosition;
258
259 }
260 else //!AutomaticPosition
261 {
262 curPos = myPosition;
263 gp_Lin L1(myEllipse.YAxis());
264 par = ElCLib::Parameter ( L1, curPos );
265 curPos = ElCLib::Value (par, L1);
266 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
267 myEndOfArrow = myApexP ;
268 else
269 myEndOfArrow = myApexN ;
270 par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
271 IsInDomain = AIS::InDomain(myFirstPar, myLastPar, par);
272 myPosition = curPos;
273 }
274
275 Standard_Real parStart =0.;
276 if( !IsInDomain )
277 {
278 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
279 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
280 parStart = myFirstPar;
281 else
282 parStart = myLastPar;
283
284 }
285
286 if(!myIsOffset)
287 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
288 curPos, myEndOfArrow, Center, parStart, IsInDomain,
289 Standard_True, mySymbolPrs);
290 else
291 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
292 curPos, myEndOfArrow, Center, parStart, IsInDomain,
293 Standard_True, mySymbolPrs);
294}
295
296
297//=======================================================================
298//function : ComputeSelection
299//purpose :
300//=======================================================================
301
302void AIS_MinRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
303 const Standard_Integer /*aMode*/)
304{
305
306 gp_Pnt center = myEllipse.Location();
307 gp_Pnt AttachmentPoint = myPosition;
308 Standard_Real dist = center.Distance(AttachmentPoint);
309 Standard_Real aRadius = myVal;
310 //Standard_Real inside = Standard_False;
311 gp_Pnt pt1;
312 if (dist > aRadius) pt1 = AttachmentPoint;
313 else
314 pt1 = myEndOfArrow;
315 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
316 Handle(Select3D_SensitiveSegment)
317 seg = new Select3D_SensitiveSegment(own, center , pt1);
318 aSelection->Add(seg);
319
320 // Text
321 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
322 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
323 AttachmentPoint.X(),
324 AttachmentPoint.Y(),
325 AttachmentPoint.Z(),
326 AttachmentPoint.X()+size,
327 AttachmentPoint.Y()+size,
328 AttachmentPoint.Z()+size);
329 aSelection->Add(box);
330
331 // Arc of Ellipse
332 if(myIsAnArc)
333 {
334
335 Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
336 if(!AIS::InDomain(myFirstPar, myLastPar, parEnd))
337 {
338 Standard_Real parStart, par;
339 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
340 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
341 par = myFirstPar;
342 else
343 par = myLastPar;
344 gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
345 gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
346 gp_Dir dir(Vpnt ^ Vapex);
347 if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
348 parStart = parEnd;
349 parEnd = par;
350 }
351 else
352 parStart = par;
353 Handle(Geom_TrimmedCurve)TrimCurve;
354 if(myIsOffset)
355 {
356 Handle(Geom_Curve) aCurve = myOffsetCurve;
357 TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd );
358 }
359 else
360 {
361 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
362 TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd );
363 }
364 Handle( Select3D_SensitiveCurve ) SensArc;
365 SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
366 aSelection->Add( SensArc );
367 }
368 }
369
370}