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