0031671: Coding Rules - eliminate warnings issued by clang 11
[occt.git] / src / SelectMgr / SelectMgr_ViewClipRange.cxx
CommitLineData
d7fa57a7 1// Copyright (c) 2019 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <SelectMgr_ViewClipRange.hxx>
15
16#include <gp_Ax1.hxx>
17#include <Graphic3d_SequenceOfHClipPlane.hxx>
18
19// =======================================================================
20// function : AddClippingPlanes
21// purpose :
22// =======================================================================
23void SelectMgr_ViewClipRange::AddClippingPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes,
24 const gp_Ax1& thePickRay)
25{
26 const gp_Dir& aViewRayDir = thePickRay.Direction();
27 const gp_Pnt& aNearPnt = thePickRay.Location();
28
29 Graphic3d_Vec4d aPlaneABCD;
30 for (Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (thePlanes); aPlaneIt.More(); aPlaneIt.Next())
31 {
32 const Handle(Graphic3d_ClipPlane)& aClipPlane = aPlaneIt.Value();
33 if (!aClipPlane->IsOn())
34 {
35 continue;
36 }
37
38 Bnd_Range aSubRange (RealFirst(), RealLast());
39 for (const Graphic3d_ClipPlane* aSubPlaneIter = aClipPlane.get(); aSubPlaneIter != NULL; aSubPlaneIter = aSubPlaneIter->ChainNextPlane().get())
40 {
41 const gp_Pln aGeomPlane = aSubPlaneIter->ToPlane();
42 aGeomPlane.Coefficients (aPlaneABCD[0], aPlaneABCD[1], aPlaneABCD[2], aPlaneABCD[3]);
43
44 const gp_XYZ& aPlaneDirXYZ = aGeomPlane.Axis().Direction().XYZ();
45 Standard_Real aDotProduct = aViewRayDir.XYZ().Dot (aPlaneDirXYZ);
46 Standard_Real aDistance = -aNearPnt.XYZ().Dot (aPlaneDirXYZ) - aPlaneABCD[3];
47 Standard_Real aDistToPln = 0.0;
48
49 // check whether the pick line is parallel to clip plane
50 if (Abs (aDotProduct) < Precision::Angular())
51 {
52 if (aDistance < 0.0)
53 {
54 continue;
55 }
56 aDistToPln = RealLast();
57 aDotProduct = 1.0;
58 }
59 else
60 {
61 // compute distance to point of pick line intersection with the plane
62 const Standard_Real aParam = aDistance / aDotProduct;
63
64 const gp_Pnt anIntersectionPnt = aNearPnt.XYZ() + aViewRayDir.XYZ() * aParam;
65 aDistToPln = anIntersectionPnt.Distance (aNearPnt);
66 if (aParam < 0.0)
67 {
68 // the plane is "behind" the ray
69 aDistToPln = -aDistToPln;
70 }
71 }
72
73 // change depth limits for case of opposite and directed planes
74 if (!aClipPlane->IsChain())
75 {
76 if (aDotProduct < 0.0)
77 {
78 ChangeUnclipRange().TrimTo (aDistToPln);
79 }
80 else
81 {
82 ChangeUnclipRange().TrimFrom (aDistToPln);
83 }
84 }
85 else
86 {
87 if (aDotProduct < 0.0)
88 {
89 aSubRange.TrimFrom (aDistToPln);
90 }
91 else
92 {
93 aSubRange.TrimTo (aDistToPln);
94 }
95 }
96 }
97
98 if (!aSubRange.IsVoid()
99 && aClipPlane->IsChain())
100 {
101 AddClipSubRange (aSubRange);
102 }
103 }
104}
0904aa63 105
106// =======================================================================
107// function : DumpJson
108// purpose :
109// =======================================================================
bc73b006 110void SelectMgr_ViewClipRange::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
0904aa63 111{
bc73b006 112 OCCT_DUMP_CLASS_BEGIN (theOStream, SelectMgr_ViewClipRange)
0904aa63 113
0904aa63 114 for (size_t aRangeIter = 0; aRangeIter < myClipRanges.size(); ++aRangeIter)
115 {
bc73b006 116 Bnd_Range aClipRange = myClipRanges[aRangeIter];
117 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &aClipRange)
0904aa63 118 }
bc73b006 119 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myUnclipRange)
0904aa63 120}