| 1 | // Created on: 1996-12-05 |
| 2 | // Created by: Jean-Pierre COMBE/Odile Olivier |
| 3 | // Copyright (c) 1996-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 |
| 9 | // under the terms of the GNU Lesser General Public 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 | #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size |
| 18 | // if any in all dimensions. |
| 19 | |
| 20 | #include <AIS_ParallelRelation.ixx> |
| 21 | |
| 22 | #include <Standard_NotImplemented.hxx> |
| 23 | #include <Standard_DomainError.hxx> |
| 24 | |
| 25 | #include <Precision.hxx> |
| 26 | |
| 27 | #include <TCollection_AsciiString.hxx> |
| 28 | #include <TCollection_ExtendedString.hxx> |
| 29 | |
| 30 | #include <DsgPrs_LengthPresentation.hxx> |
| 31 | |
| 32 | #include <Prs3d_Drawer.hxx> |
| 33 | #include <Prs3d_ArrowAspect.hxx> |
| 34 | #include <Prs3d_DimensionAspect.hxx> |
| 35 | |
| 36 | #include <AIS.hxx> |
| 37 | #include <AIS_Drawer.hxx> |
| 38 | |
| 39 | #include <SelectMgr_EntityOwner.hxx> |
| 40 | #include <Select3D_SensitiveSegment.hxx> |
| 41 | #include <Select3D_SensitiveBox.hxx> |
| 42 | |
| 43 | #include <TopoDS.hxx> |
| 44 | #include <TopExp_Explorer.hxx> |
| 45 | #include <BRep_Tool.hxx> |
| 46 | #include <BRepAdaptor_Surface.hxx> |
| 47 | #include <BRepAdaptor_Curve.hxx> |
| 48 | |
| 49 | #include <gp_Lin.hxx> |
| 50 | #include <gp_Pnt.hxx> |
| 51 | #include <ElCLib.hxx> |
| 52 | #include <gp_Pln.hxx> |
| 53 | #include <gp_Dir.hxx> |
| 54 | #include <gp_Ax1.hxx> |
| 55 | #include <gp_Ax2.hxx> |
| 56 | |
| 57 | #include <gce_MakeLin.hxx> |
| 58 | |
| 59 | #include <Geom_Plane.hxx> |
| 60 | #include <Geom_Line.hxx> |
| 61 | #include <Geom_Ellipse.hxx> |
| 62 | |
| 63 | //======================================================================= |
| 64 | //function : Constructor |
| 65 | //purpose : |
| 66 | //======================================================================= |
| 67 | AIS_ParallelRelation::AIS_ParallelRelation(const TopoDS_Shape& aFShape, |
| 68 | const TopoDS_Shape& aSShape, |
| 69 | const Handle(Geom_Plane)& aPlane) |
| 70 | { |
| 71 | myFShape = aFShape; |
| 72 | mySShape = aSShape; |
| 73 | myPlane = aPlane; |
| 74 | myAutomaticPosition = Standard_True; |
| 75 | myArrowSize = 0.01; |
| 76 | mySymbolPrs = DsgPrs_AS_BOTHAR; |
| 77 | } |
| 78 | |
| 79 | //======================================================================= |
| 80 | //function : Constructor |
| 81 | //purpose : |
| 82 | //======================================================================= |
| 83 | AIS_ParallelRelation::AIS_ParallelRelation(const TopoDS_Shape& aFShape, |
| 84 | const TopoDS_Shape& aSShape, |
| 85 | const Handle(Geom_Plane)& aPlane, |
| 86 | const gp_Pnt& aPosition, |
| 87 | const DsgPrs_ArrowSide aSymbolPrs, |
| 88 | const Standard_Real anArrowSize) |
| 89 | { |
| 90 | myFShape = aFShape; |
| 91 | mySShape = aSShape; |
| 92 | myPlane = aPlane; |
| 93 | myAutomaticPosition = Standard_False; |
| 94 | #ifdef BUC60915 |
| 95 | SetArrowSize( anArrowSize ); |
| 96 | #else |
| 97 | myArrowSize = anArrowSize; |
| 98 | #endif |
| 99 | myPosition = aPosition; |
| 100 | mySymbolPrs = aSymbolPrs; |
| 101 | } |
| 102 | |
| 103 | //======================================================================= |
| 104 | //function : Compute |
| 105 | //purpose : |
| 106 | //======================================================================= |
| 107 | void AIS_ParallelRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&, |
| 108 | const Handle(Prs3d_Presentation)& aPresentation, |
| 109 | const Standard_Integer) |
| 110 | { |
| 111 | aPresentation->Clear(); |
| 112 | |
| 113 | switch (myFShape.ShapeType()) |
| 114 | { |
| 115 | case TopAbs_FACE : |
| 116 | { |
| 117 | // cas longueur entre deux faces |
| 118 | ComputeTwoFacesParallel(aPresentation); |
| 119 | } |
| 120 | break; |
| 121 | case TopAbs_EDGE : |
| 122 | { |
| 123 | // cas longueur entre deux edges |
| 124 | ComputeTwoEdgesParallel(aPresentation); |
| 125 | } |
| 126 | break; |
| 127 | default: |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | //======================================================================= |
| 133 | //function : Compute |
| 134 | //purpose : to avoid warning |
| 135 | //======================================================================= |
| 136 | void AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)& aProjector, |
| 137 | const Handle(Prs3d_Presentation)& aPresentation) |
| 138 | { |
| 139 | // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)"); |
| 140 | PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; |
| 141 | } |
| 142 | |
| 143 | void AIS_ParallelRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation) |
| 144 | { |
| 145 | // Standard_NotImplemented::Raise("AIS_ParallelRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)"); |
| 146 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
| 147 | } |
| 148 | |
| 149 | //======================================================================= |
| 150 | //function : ComputeSelection |
| 151 | //purpose : |
| 152 | //======================================================================= |
| 153 | void AIS_ParallelRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
| 154 | const Standard_Integer) |
| 155 | { |
| 156 | gp_Lin L1 (myFAttach,myDirAttach); |
| 157 | gp_Lin L2 (mySAttach,myDirAttach); |
| 158 | gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,myPosition),L1); |
| 159 | gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,myPosition),L2); |
| 160 | |
| 161 | gp_Lin L3; |
| 162 | Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7); |
| 163 | |
| 164 | if (!Proj1.IsEqual(Proj2,Precision::Confusion())) |
| 165 | { |
| 166 | L3 = gce_MakeLin(Proj1,Proj2); |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | L3 = gce_MakeLin(Proj1,myDirAttach); |
| 171 | Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6)); |
| 172 | Handle(Select3D_SensitiveBox) box = |
| 173 | new Select3D_SensitiveBox(own, |
| 174 | myPosition.X(), |
| 175 | myPosition.Y(), |
| 176 | myPosition.Z(), |
| 177 | myPosition.X()+size, |
| 178 | myPosition.Y()+size, |
| 179 | myPosition.Z()+size); |
| 180 | aSelection->Add(box); |
| 181 | } |
| 182 | Standard_Real parmin,parmax,parcur; |
| 183 | parmin = ElCLib::Parameter(L3,Proj1); |
| 184 | parmax = parmin; |
| 185 | |
| 186 | parcur = ElCLib::Parameter(L3,Proj2); |
| 187 | parmin = Min(parmin,parcur); |
| 188 | parmax = Max(parmax,parcur); |
| 189 | |
| 190 | parcur = ElCLib::Parameter(L3,myPosition); |
| 191 | parmin = Min(parmin,parcur); |
| 192 | parmax = Max(parmax,parcur); |
| 193 | |
| 194 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
| 195 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
| 196 | |
| 197 | Handle(Select3D_SensitiveSegment) seg; |
| 198 | |
| 199 | if (!PointMin.IsEqual(PointMax,Precision::Confusion())) |
| 200 | { |
| 201 | seg = new Select3D_SensitiveSegment(own, |
| 202 | PointMin, |
| 203 | PointMax); |
| 204 | aSelection->Add(seg); |
| 205 | } |
| 206 | if (!myFAttach.IsEqual(Proj1,Precision::Confusion())) |
| 207 | { |
| 208 | seg = new Select3D_SensitiveSegment(own, myFAttach, Proj1); |
| 209 | aSelection->Add(seg); |
| 210 | } |
| 211 | if (!mySAttach.IsEqual(Proj2,Precision::Confusion())) |
| 212 | { |
| 213 | seg = new Select3D_SensitiveSegment(own, mySAttach, Proj2); |
| 214 | aSelection->Add(seg); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | //======================================================================= |
| 219 | //function : ComputeTwoFacesParallel |
| 220 | //purpose : |
| 221 | //======================================================================= |
| 222 | void AIS_ParallelRelation::ComputeTwoFacesParallel(const Handle(Prs3d_Presentation)&) |
| 223 | { |
| 224 | Standard_NotImplemented::Raise("AIS_ParallelRelation::ComputeTwoFacesParallel not implemented"); |
| 225 | } |
| 226 | |
| 227 | //======================================================================= |
| 228 | //function : ComputeTwoEdgesParallel |
| 229 | //purpose : |
| 230 | //======================================================================= |
| 231 | void AIS_ParallelRelation::ComputeTwoEdgesParallel(const Handle(Prs3d_Presentation)& aPresentation) |
| 232 | { |
| 233 | TopoDS_Edge E1 = TopoDS::Edge(myFShape); |
| 234 | TopoDS_Edge E2 = TopoDS::Edge(mySShape); |
| 235 | |
| 236 | gp_Pnt ptat11,ptat12,ptat21,ptat22;//,pint3d; |
| 237 | Handle(Geom_Curve) geom1,geom2; |
| 238 | Standard_Boolean isInfinite1,isInfinite2; |
| 239 | Handle(Geom_Curve) extCurv; |
| 240 | if (!AIS::ComputeGeometry(E1,E2,myExtShape, |
| 241 | geom1,geom2, |
| 242 | ptat11,ptat12,ptat21,ptat22, |
| 243 | extCurv, |
| 244 | isInfinite1,isInfinite2, |
| 245 | myPlane)) |
| 246 | { |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | aPresentation->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape != 0)); |
| 251 | |
| 252 | gp_Lin l1; |
| 253 | gp_Lin l2; |
| 254 | Standard_Boolean isEl1 = Standard_False, isEl2 = Standard_False; |
| 255 | |
| 256 | if (geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse))) |
| 257 | { |
| 258 | const Handle(Geom_Ellipse)& geom_el1 = (Handle(Geom_Ellipse)&) geom1; |
| 259 | // construct lines through focuses |
| 260 | gp_Ax1 elAx = geom_el1->XAxis(); |
| 261 | l1 = gp_Lin(elAx); |
| 262 | Standard_Real focex = geom_el1->MajorRadius() - geom_el1->Focal()/2.0; |
| 263 | gp_Vec transvec = gp_Vec(elAx.Direction())*focex; |
| 264 | ptat11 = geom_el1->Focus1().Translated(transvec); |
| 265 | ptat12 = geom_el1->Focus2().Translated(-transvec); |
| 266 | isEl1 = Standard_True; |
| 267 | } |
| 268 | else if (geom1->IsInstance(STANDARD_TYPE(Geom_Line))) |
| 269 | { |
| 270 | const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1; |
| 271 | l1 = geom_lin1->Lin(); |
| 272 | } |
| 273 | else return; |
| 274 | |
| 275 | if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse))) |
| 276 | { |
| 277 | const Handle(Geom_Ellipse)& geom_el2 = (Handle(Geom_Ellipse)&) geom2; |
| 278 | // construct lines through focuses |
| 279 | gp_Ax1 elAx = geom_el2->XAxis(); |
| 280 | l2 = gp_Lin(elAx); |
| 281 | Standard_Real focex = geom_el2->MajorRadius() - geom_el2->Focal()/2.0; |
| 282 | gp_Vec transvec = gp_Vec(elAx.Direction())*focex; |
| 283 | ptat21 = geom_el2->Focus1().Translated(transvec); |
| 284 | ptat22 = geom_el2->Focus2().Translated(-transvec); |
| 285 | isEl2 = Standard_True; |
| 286 | } |
| 287 | else if (geom2->IsInstance(STANDARD_TYPE(Geom_Line))) |
| 288 | { |
| 289 | const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2; |
| 290 | l2 = geom_lin2->Lin(); |
| 291 | } |
| 292 | else return; |
| 293 | |
| 294 | const Handle(Geom_Line)& geom_lin1 = new Geom_Line(l1); |
| 295 | const Handle(Geom_Line)& geom_lin2 = new Geom_Line(l2); |
| 296 | |
| 297 | myDirAttach = l1.Direction(); |
| 298 | // size |
| 299 | #ifdef BUC60915 |
| 300 | if( !myArrowSizeIsDefined ) { |
| 301 | #endif |
| 302 | Standard_Real arrSize1 (myArrowSize), arrSize2 (myArrowSize); |
| 303 | if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/50.; |
| 304 | if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/50.; |
| 305 | myArrowSize = Max(myArrowSize,Max(arrSize1,arrSize2)); |
| 306 | // myArrowSize = Min(myArrowSize,Min(arrSize1,arrSize2)); |
| 307 | #ifdef BUC60915 |
| 308 | } |
| 309 | #endif |
| 310 | |
| 311 | if ( myAutomaticPosition ) |
| 312 | { |
| 313 | gp_Pnt curpos; |
| 314 | if ( !isInfinite1 ) |
| 315 | { |
| 316 | gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l2,ptat11),l2); |
| 317 | curpos.SetXYZ((ptat11.XYZ() + p2.XYZ())/2.); |
| 318 | } |
| 319 | else if ( !isInfinite2 ) |
| 320 | { |
| 321 | gp_Pnt p2 = ElCLib::Value(ElCLib::Parameter(l1,ptat21),l1); |
| 322 | curpos.SetXYZ((ptat21.XYZ()+p2.XYZ())/2.); |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | curpos.SetXYZ((l1.Location().XYZ()+l2.Location().XYZ())/2.); |
| 327 | } |
| 328 | // offset pour eviter confusion Edge et Dimension |
| 329 | gp_Vec offset (myDirAttach); |
| 330 | offset = offset*myArrowSize*(-10.); |
| 331 | curpos.Translate(offset); |
| 332 | myPosition = curpos; |
| 333 | } |
| 334 | |
| 335 | // recherche points attache |
| 336 | if (!isInfinite1) |
| 337 | { |
| 338 | if ( isEl1 ) |
| 339 | { |
| 340 | if (myPosition.Distance(ptat11) < myPosition.Distance(ptat12)) myFAttach = ptat12; |
| 341 | else myFAttach = ptat11; |
| 342 | } |
| 343 | else |
| 344 | { |
| 345 | if (myPosition.Distance(ptat11) > myPosition.Distance(ptat12)) myFAttach = ptat12; |
| 346 | else myFAttach = ptat11; |
| 347 | } |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | myFAttach = ElCLib::Value(ElCLib::Parameter(l1,myPosition),l1); |
| 352 | } |
| 353 | |
| 354 | if (!isInfinite2) |
| 355 | { |
| 356 | if ( isEl2 ) |
| 357 | { |
| 358 | if (myPosition.Distance(ptat21) < myPosition.Distance(ptat22)) mySAttach = ptat22; |
| 359 | else mySAttach = ptat21; |
| 360 | } |
| 361 | else |
| 362 | { |
| 363 | if (myPosition.Distance(ptat21) > myPosition.Distance(ptat22)) mySAttach = ptat22; |
| 364 | else mySAttach = ptat21; |
| 365 | } |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | mySAttach = ElCLib::Value(ElCLib::Parameter(l2,myPosition),l2); |
| 370 | } |
| 371 | TCollection_ExtendedString aText (" //"); |
| 372 | |
| 373 | if (l1.Distance(l2) <= Precision::Confusion()) |
| 374 | { |
| 375 | myArrowSize = 0.; |
| 376 | } |
| 377 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
| 378 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
| 379 | arr->SetLength(myArrowSize); |
| 380 | arr = la->ArrowAspect(); |
| 381 | arr->SetLength(myArrowSize); |
| 382 | if ( myExtShape == 1) |
| 383 | mySymbolPrs = DsgPrs_AS_FIRSTPT_LASTAR; |
| 384 | else if ( myExtShape == 2) |
| 385 | mySymbolPrs = DsgPrs_AS_FIRSTAR_LASTPT; |
| 386 | |
| 387 | DsgPrs_LengthPresentation::Add(aPresentation, |
| 388 | myDrawer, |
| 389 | aText, |
| 390 | myFAttach, |
| 391 | mySAttach, |
| 392 | myDirAttach, |
| 393 | myPosition, |
| 394 | mySymbolPrs); |
| 395 | if ( (myExtShape != 0) && !extCurv.IsNull()) |
| 396 | { |
| 397 | gp_Pnt pf, pl; |
| 398 | if ( myExtShape == 1 ) |
| 399 | { |
| 400 | if (!isInfinite1) |
| 401 | { |
| 402 | pf = ptat11; |
| 403 | pl = ptat12; |
| 404 | } |
| 405 | ComputeProjEdgePresentation(aPresentation,E1,geom_lin1,pf,pl); |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | if (!isInfinite2) |
| 410 | { |
| 411 | pf = ptat21; |
| 412 | pl = ptat22; |
| 413 | } |
| 414 | ComputeProjEdgePresentation(aPresentation,E2,geom_lin2,pf,pl); |
| 415 | } |
| 416 | } |
| 417 | } |