| 1 | // Created on: 1998-01-23 |
| 2 | // Created by: Sergey ZARITCHNY |
| 3 | // Copyright (c) 1998-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 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 |
| 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. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | #include <PrsDim_EllipseRadiusDimension.hxx> |
| 18 | |
| 19 | #include <PrsDim.hxx> |
| 20 | #include <PrsDim_MaxRadiusDimension.hxx> |
| 21 | #include <BRepAdaptor_Curve.hxx> |
| 22 | #include <BRepAdaptor_Surface.hxx> |
| 23 | #include <DsgPrs_EllipseRadiusPresentation.hxx> |
| 24 | #include <ElCLib.hxx> |
| 25 | #include <ElSLib.hxx> |
| 26 | #include <Geom_CylindricalSurface.hxx> |
| 27 | #include <Geom_Ellipse.hxx> |
| 28 | #include <Geom_OffsetCurve.hxx> |
| 29 | #include <Geom_Plane.hxx> |
| 30 | #include <Geom_Surface.hxx> |
| 31 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
| 32 | #include <Geom_SurfaceOfRevolution.hxx> |
| 33 | #include <Geom_TrimmedCurve.hxx> |
| 34 | #include <gp_Ax1.hxx> |
| 35 | #include <gp_Dir.hxx> |
| 36 | #include <gp_Lin.hxx> |
| 37 | #include <gp_Pln.hxx> |
| 38 | #include <gp_Pnt.hxx> |
| 39 | #include <gp_Vec.hxx> |
| 40 | #include <Precision.hxx> |
| 41 | #include <Prs3d_ArrowAspect.hxx> |
| 42 | #include <Prs3d_DimensionAspect.hxx> |
| 43 | #include <Prs3d_Drawer.hxx> |
| 44 | #include <Prs3d_Presentation.hxx> |
| 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> |
| 54 | #include <TCollection_ExtendedString.hxx> |
| 55 | #include <TopoDS.hxx> |
| 56 | #include <TopoDS_Shape.hxx> |
| 57 | |
| 58 | IMPLEMENT_STANDARD_RTTIEXT(PrsDim_MaxRadiusDimension, PrsDim_EllipseRadiusDimension) |
| 59 | |
| 60 | //======================================================================= |
| 61 | //function : PrsDim_MaxRadiusDimension |
| 62 | //purpose : |
| 63 | //======================================================================= |
| 64 | PrsDim_MaxRadiusDimension::PrsDim_MaxRadiusDimension(const TopoDS_Shape& aShape, |
| 65 | const Standard_Real aVal, |
| 66 | const TCollection_ExtendedString& aText) |
| 67 | :PrsDim_EllipseRadiusDimension(aShape, aText) |
| 68 | { |
| 69 | myVal = aVal; |
| 70 | mySymbolPrs = DsgPrs_AS_LASTAR; |
| 71 | myAutomaticPosition = Standard_True; |
| 72 | myArrowSize = myVal / 100.; |
| 73 | } |
| 74 | |
| 75 | //======================================================================= |
| 76 | //function : PrsDim_MaxRadiusDimension |
| 77 | //purpose : |
| 78 | //======================================================================= |
| 79 | |
| 80 | PrsDim_MaxRadiusDimension::PrsDim_MaxRadiusDimension(const TopoDS_Shape& aShape, |
| 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) |
| 86 | :PrsDim_EllipseRadiusDimension(aShape, aText) |
| 87 | { |
| 88 | myVal = aVal; |
| 89 | mySymbolPrs = aSymbolPrs; |
| 90 | myPosition = aPosition; |
| 91 | myAutomaticPosition = Standard_False; |
| 92 | SetArrowSize( anArrowSize ); |
| 93 | } |
| 94 | |
| 95 | //======================================================================= |
| 96 | //function : Compute |
| 97 | //purpose : |
| 98 | //======================================================================= |
| 99 | |
| 100 | void PrsDim_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
| 101 | const Handle(Prs3d_Presentation)& aPresentation, |
| 102 | const Standard_Integer /*aMode*/) |
| 103 | { |
| 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 | //======================================================================= |
| 119 | //function : ComputeEllipse |
| 120 | //purpose : |
| 121 | //======================================================================= |
| 122 | |
| 123 | void PrsDim_MaxRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation) |
| 124 | { |
| 125 | |
| 126 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
| 127 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
| 128 | |
| 129 | // size |
| 130 | if( !myArrowSizeIsDefined ) { |
| 131 | myArrowSize = Min(myArrowSize,myVal / 5.); |
| 132 | } |
| 133 | arr->SetLength(myArrowSize); |
| 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 ) |
| 145 | myPosition = PrsDim::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )), |
| 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 | |
| 172 | void PrsDim_MaxRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation) |
| 173 | { |
| 174 | |
| 175 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
| 176 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
| 177 | |
| 178 | // size |
| 179 | if( !myArrowSizeIsDefined ) { |
| 180 | myArrowSize = Min(myArrowSize,myVal / 5.); |
| 181 | } |
| 182 | arr->SetLength(myArrowSize); |
| 183 | |
| 184 | Standard_Real par; |
| 185 | gp_Pnt curPos, Center; |
| 186 | Center = myEllipse.Location(); |
| 187 | Standard_Boolean IsInDomain = Standard_True; |
| 188 | if( myAutomaticPosition ) |
| 189 | { |
| 190 | myEndOfArrow = PrsDim::NearestApex(myEllipse, myApexP, myApexN, |
| 191 | myFirstPar, myLastPar, IsInDomain); |
| 192 | myPosition = Center; |
| 193 | myAutomaticPosition = Standard_True; |
| 194 | if ( myIsSetBndBox ) |
| 195 | myPosition = PrsDim::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )), |
| 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 ); |
| 212 | IsInDomain = PrsDim::InDomain( myFirstPar, myLastPar, par ); |
| 213 | myPosition = curPos; |
| 214 | } |
| 215 | |
| 216 | // Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow ); |
| 217 | Standard_Real parStart = 0.; |
| 218 | if( !IsInDomain ) |
| 219 | { |
| 220 | if(PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) < |
| 221 | PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar)) |
| 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 | |
| 241 | void PrsDim_MaxRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
| 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 ); |
| 275 | if(!PrsDim::InDomain(myFirstPar, myLastPar, parEnd)) |
| 276 | { |
| 277 | Standard_Real parStart, par; |
| 278 | if(PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) < |
| 279 | PrsDim::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar)) |
| 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 | |
| 293 | Handle(Geom_Curve)TrimCurve; |
| 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 | } |