0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[occt.git] / src / PrsDim / PrsDim_MaxRadiusDimension.cxx
CommitLineData
b311480e 1// Created on: 1998-01-23
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
787ff240 17#include <PrsDim_EllipseRadiusDimension.hxx>
7fd59977 18
787ff240 19#include <PrsDim.hxx>
20#include <PrsDim_MaxRadiusDimension.hxx>
42cf5bc1 21#include <BRepAdaptor_Curve.hxx>
22#include <BRepAdaptor_Surface.hxx>
23#include <DsgPrs_EllipseRadiusPresentation.hxx>
7fd59977 24#include <ElCLib.hxx>
25#include <ElSLib.hxx>
42cf5bc1 26#include <Geom_CylindricalSurface.hxx>
7fd59977 27#include <Geom_Ellipse.hxx>
c04c30b3 28#include <Geom_OffsetCurve.hxx>
7fd59977 29#include <Geom_Plane.hxx>
30#include <Geom_Surface.hxx>
7fd59977 31#include <Geom_SurfaceOfLinearExtrusion.hxx>
42cf5bc1 32#include <Geom_SurfaceOfRevolution.hxx>
42cf5bc1 33#include <Geom_TrimmedCurve.hxx>
7fd59977 34#include <gp_Ax1.hxx>
35#include <gp_Dir.hxx>
42cf5bc1 36#include <gp_Lin.hxx>
37#include <gp_Pln.hxx>
38#include <gp_Pnt.hxx>
7fd59977 39#include <gp_Vec.hxx>
7fd59977 40#include <Precision.hxx>
42cf5bc1 41#include <Prs3d_ArrowAspect.hxx>
42#include <Prs3d_DimensionAspect.hxx>
43#include <Prs3d_Drawer.hxx>
44#include <Prs3d_Presentation.hxx>
42cf5bc1 45#include <Prs3d_Text.hxx>
46#include <Prs3d_TextAspect.hxx>
47#include <Select3D_SensitiveBox.hxx>
48#include <Select3D_SensitiveCurve.hxx>
49#include <Select3D_SensitiveSegment.hxx>
50#include <SelectMgr_EntityOwner.hxx>
51#include <SelectMgr_Selection.hxx>
52#include <Standard_ConstructionError.hxx>
53#include <Standard_NotImplemented.hxx>
42cf5bc1 54#include <TCollection_ExtendedString.hxx>
55#include <TopoDS.hxx>
56#include <TopoDS_Shape.hxx>
7fd59977 57
787ff240 58IMPLEMENT_STANDARD_RTTIEXT(PrsDim_MaxRadiusDimension, PrsDim_EllipseRadiusDimension)
92efcf78 59
7fd59977 60//=======================================================================
787ff240 61//function : PrsDim_MaxRadiusDimension
7fd59977 62//purpose :
63//=======================================================================
787ff240 64PrsDim_MaxRadiusDimension::PrsDim_MaxRadiusDimension(const TopoDS_Shape& aShape,
7fd59977 65 const Standard_Real aVal,
66 const TCollection_ExtendedString& aText)
787ff240 67:PrsDim_EllipseRadiusDimension(aShape, aText)
7fd59977 68{
69 myVal = aVal;
70 mySymbolPrs = DsgPrs_AS_LASTAR;
71 myAutomaticPosition = Standard_True;
72 myArrowSize = myVal / 100.;
73}
74
75//=======================================================================
787ff240 76//function : PrsDim_MaxRadiusDimension
7fd59977 77//purpose :
78//=======================================================================
79
787ff240 80PrsDim_MaxRadiusDimension::PrsDim_MaxRadiusDimension(const TopoDS_Shape& aShape,
7fd59977 81 const Standard_Real aVal,
82 const TCollection_ExtendedString& aText,
83 const gp_Pnt& aPosition,
84 const DsgPrs_ArrowSide aSymbolPrs,
85 const Standard_Real anArrowSize)
787ff240 86:PrsDim_EllipseRadiusDimension(aShape, aText)
7fd59977 87{
88 myVal = aVal;
89 mySymbolPrs = aSymbolPrs;
90 myPosition = aPosition;
91 myAutomaticPosition = Standard_False;
7fd59977 92 SetArrowSize( anArrowSize );
7fd59977 93}
94
95//=======================================================================
96//function : Compute
97//purpose :
98//=======================================================================
99
787ff240 100void PrsDim_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
7fd59977 101 const Handle(Prs3d_Presentation)& aPresentation,
102 const Standard_Integer /*aMode*/)
103{
7fd59977 104// if( myAutomaticPosition )
105 {//ota : recompute in any case
106 ComputeGeometry();
107 myEllipse.SetMajorRadius(myVal);
108 gp_Vec v1(myEllipse.XAxis().Direction());
109 v1 *=myVal;
110 myApexP = myEllipse.Location().Translated(v1);
111 myApexN = myEllipse.Location().Translated(-v1);
112 }
113 if(myIsAnArc) ComputeArcOfEllipse(aPresentation);
114 else
115 ComputeEllipse(aPresentation);
116}
117
118//=======================================================================
7fd59977 119//function : ComputeEllipse
120//purpose :
121//=======================================================================
122
787ff240 123void PrsDim_MaxRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 124{
125
a6eb515f 126 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
127 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 128
129 // size
7fd59977 130 if( !myArrowSizeIsDefined ) {
131 myArrowSize = Min(myArrowSize,myVal / 5.);
132 }
133 arr->SetLength(myArrowSize);
7fd59977 134
135 Standard_Real U;//,V;
136 gp_Pnt curPos, Center;
137 Center = myEllipse.Location();
138 if( myAutomaticPosition )
139 {
140 myPosition = Center;
141 myEndOfArrow = myApexP;
142 myAutomaticPosition = Standard_True;
143
144 if ( myIsSetBndBox )
787ff240 145 myPosition = PrsDim::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
7fd59977 146 myBndBox );
147 curPos = myPosition;
148 }
149 else //!AutomaticPosition
150 {
151 curPos = myPosition;
152 gp_Lin L1(myEllipse.XAxis());
153 U = ElCLib::Parameter ( L1, curPos );
154 curPos = ElCLib::Value (U, L1);
155 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
156 myEndOfArrow = myApexP ;
157 else
158 myEndOfArrow = myApexN ;
159 }
160
161 // Presenatation
162 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
163 myEndOfArrow, Center, Standard_True, mySymbolPrs);
164
165}
166
167//=======================================================================
168//function : ComputeArcOfEllipse
169//purpose :
170//=======================================================================
171
787ff240 172void PrsDim_MaxRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 173{
174
a6eb515f 175 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
176 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 177
178 // size
7fd59977 179 if( !myArrowSizeIsDefined ) {
180 myArrowSize = Min(myArrowSize,myVal / 5.);
181 }
182 arr->SetLength(myArrowSize);
7fd59977 183
184 Standard_Real par;
185 gp_Pnt curPos, Center;
186 Center = myEllipse.Location();
187 Standard_Boolean IsInDomain = Standard_True;
188 if( myAutomaticPosition )
189 {
787ff240 190 myEndOfArrow = PrsDim::NearestApex(myEllipse, myApexP, myApexN,
7fd59977 191 myFirstPar, myLastPar, IsInDomain);
192 myPosition = Center;
193 myAutomaticPosition = Standard_True;
194 if ( myIsSetBndBox )
787ff240 195 myPosition = PrsDim::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
7fd59977 196 myBndBox );
197 curPos = myPosition;
198 }
199 else //!AutomaticPosition
200 {
201 curPos = myPosition;
202// ElSLib::Parameters ( myPlane->Pln(), curPos, U, V );
203// curPos = ElSLib::Value (U, V, myPlane->Pln());
204 gp_Lin L1(myEllipse.XAxis());
205 par = ElCLib::Parameter ( L1, curPos );
206 curPos = ElCLib::Value (par, L1);
207 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
208 myEndOfArrow = myApexP ;
209 else
210 myEndOfArrow = myApexN ;
211 par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
787ff240 212 IsInDomain = PrsDim::InDomain( myFirstPar, myLastPar, par );
7fd59977 213 myPosition = curPos;
214 }
215
216// Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
217 Standard_Real parStart = 0.;
218 if( !IsInDomain )
219 {
787ff240 220 if(PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
221 PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
7fd59977 222 parStart = myFirstPar;
223 else
224 parStart = myLastPar;
225 }
226 if(!myIsOffset)
227 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
228 curPos, myEndOfArrow, Center, parStart, IsInDomain,
229 Standard_True, mySymbolPrs);
230 else
231 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
232 curPos, myEndOfArrow, Center, parStart, IsInDomain,
233 Standard_True, mySymbolPrs);
234}
235
236//=======================================================================
237//function : ComputeSelection
238//purpose :
239//=======================================================================
240
787ff240 241void PrsDim_MaxRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
7fd59977 242 const Standard_Integer /*aMode*/)
243{
244
245 gp_Pnt center = myEllipse.Location();
246 gp_Pnt AttachmentPoint = myPosition;
247 Standard_Real dist = center.Distance(AttachmentPoint);
248 Standard_Real aRadius = myVal;
249 //Standard_Real inside = Standard_False;
250 gp_Pnt pt1;
251 if (dist > aRadius) pt1 = AttachmentPoint;
252 else
253 pt1 = myEndOfArrow;
254 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
255 Handle(Select3D_SensitiveSegment)
256 seg = new Select3D_SensitiveSegment(own, center , pt1);
257 aSelection->Add(seg);
258
259 // Text
260 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
261 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
262 AttachmentPoint.X(),
263 AttachmentPoint.Y(),
264 AttachmentPoint.Z(),
265 AttachmentPoint.X()+size,
266 AttachmentPoint.Y()+size,
267 AttachmentPoint.Z()+size);
268 aSelection->Add(box);
269
270 // Arc of Ellipse
271 if(myIsAnArc)
272 {
273
274 Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
787ff240 275 if(!PrsDim::InDomain(myFirstPar, myLastPar, parEnd))
7fd59977 276 {
277 Standard_Real parStart, par;
787ff240 278 if(PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
279 PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
7fd59977 280 par = myFirstPar;
281 else
282 par = myLastPar;
283 gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
284 gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
285 gp_Dir dir(Vpnt ^ Vapex);
286 if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
287 parStart = parEnd;
288 parEnd = par;
289 }
290 else
291 parStart = par;
292
c04c30b3 293 Handle(Geom_Curve)TrimCurve;
7fd59977 294 if(myIsOffset)
295 {
296 Handle(Geom_Curve) aCurve = myOffsetCurve;
297 TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd );
298 }
299 else
300 {
301 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
302 TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd );
303 }
304 Handle( Select3D_SensitiveCurve ) SensArc;
305 SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
306 aSelection->Add( SensArc );
307 }
308 }
309
310}