0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / TopClass / TopClass_SolidClassifier.gxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19//-- TopClass_SolidClassifier.gxx
20
21#ifdef DEB
22Standard_EXPORT Standard_Boolean TopClass_GettraceFC();
23#endif
24
25#include <gp_Lin.hxx>
26
27//extern void DrawSegment(const gp_Pnt& P1,const gp_Lin& L,const Standard_Real par);
28//extern Standard_Boolean DebugDrawSegment;
29
30TopClass_SolidClassifier::TopClass_SolidClassifier()
31{
32}
33
34
35TopClass_SolidClassifier::TopClass_SolidClassifier(TheSolidExplorer& S,
36 const gp_Pnt& P,
37 const Standard_Real Tol) {
38 Perform(S,P,Tol);
39}
40
41
42void TopClass_SolidClassifier::Perform(TheSolidExplorer& SolidExplorer,
43 const gp_Pnt& P,
44 const Standard_Real Tol) {
45#ifdef DEB
46 Standard_Boolean trace = TopClass_GettraceFC();
47#endif
48
49 myState = 0;
50 if(SolidExplorer.Reject(P) == Standard_False) {
51
52 //-- There is no rejection between the Shape loaded in the SolidExplorer
53 //-- and the point P.
54
55 gp_Lin L;
56 Standard_Real Par;
57 //-- We compute the intersection betwwen the line builded in the Solid Explorer
58 //-- and the shape.
59
60 SolidExplorer.Segment(P,L,Par);
61
62 TheIntersection3d Intersector;
63
64 Standard_Real parmin = RealLast();
65
66 for(SolidExplorer.InitShell();
67 SolidExplorer.MoreShell();
68 SolidExplorer.NextShell()) {
69
70 if(SolidExplorer.RejectShell(L) == Standard_False) {
71
72 for(SolidExplorer.InitFace();
73 SolidExplorer.MoreFace();
74 SolidExplorer.NextFace()) {
75
76 if(SolidExplorer.RejectFace(L) == Standard_False) {
77
78 Intersector.Perform(L,Par,Tol,SolidExplorer.CurrentFace());
79
80 if(Intersector.IsDone()) {
81 if(Intersector.HasAPoint()) {
82 if(Intersector.WParameter() < parmin) {
83
84 parmin = Intersector.WParameter();
85 if(Abs(parmin)<=Tol) {
86#ifdef DEB
87 if (trace) {
88 //-- #########################################
89 cout<<" parmin = "<<parmin<< " avec Par = "<<Par;
90 cout<<" ds TopClass_SolidClassifier.gxx "<<endl;
91 //-- #########################################
92 }
93#endif
94 myState = 2;
95 myFace = Intersector.Face();
96 }
97 else if(Intersector.State()==TopAbs_IN) {
98
99 //-- The intersection point between the line and a face F
100 // -- of the solid is in the face F
101
102 if(Intersector.Transition() == IntCurveSurface_Out) {
103 //-- The line is going from inside the solid to outside
104 //-- the solid.
105 myState = 3; //-- IN --
106 }
107 else if(Intersector.Transition() == IntCurveSurface_In) {
108 myState = 4; //-- OUT --
109 }
110 else {
111#ifdef DEB
112 cout<<"*Probleme ds TopClass_SolidClassifier.gxx"<<endl;
113#endif
114 }
115 myFace = Intersector.Face();
116 }
117 else if(Intersector.State()==TopAbs_ON) {
118 //-- The intersection point between the line and a face F
119 //-- of the solid is in the face F
120
121 if(Intersector.Transition() == IntCurveSurface_Out) {
122 //-- The line is going from inside the solid to outside
123 //-- the solid.
124 myState = 3; //-- IN --
125 }
126 else if(Intersector.Transition() == IntCurveSurface_In) {
127 myState = 4; //-- OUT --
128 }
129 else {
130#ifdef DEB
131 cout<<"*Probleme ds TopClass_SolidClassifier.gxx "<<endl;
132#endif
133 }
134#ifdef DEB
135 //-- #########################################
136// cout<<" Intersector.State() == TopAbs_ON";
137// cout<<" ds TopClass_SolidClassifier.gxx "<<endl;
138// cout<<" Transition : ";
139// if(myState==3) { cout<<" IN "; }
140// else if(myState==4) { cout<<" OUT "; }
141// else { cout<<" PB "; }
142// cout<<endl;
143 //-- #########################################
144#endif
145 //-- myState = 2;
146 myFace = Intersector.Face();
147 }
148 }
149 else {
150 //-- No point has been found by the intersector.
151 //-- Or a Point has been found with a greater parameter.
152 }
153 } //-- Intersector Has a point
154 else {
155 //-- The intersector failed.
156 }
157 } //-- Face has not been rejected
158 else {
159 myState = 1;
160 }
161 }
162 } //-- Exploration of the faces
163 } //-- Shell has not been rejected
164 else {
165 myState=1;
166 }
167 } //-- Exploration of the shells
168
169#ifdef DEB
170 //#################################################
171 SolidExplorer.DumpSegment(P,L,parmin,State());
172 //#################################################
173#endif
174
175 } //-- Solid has not been rejected
176 else {
177 myState = 1;
178 }
179}
180
181
182TopAbs_State TopClass_SolidClassifier::State() const {
183 if(myState==2) return(TopAbs_ON);
184 if(myState==4) return(TopAbs_OUT); //--
185 else if(myState==3) return(TopAbs_IN); //--
186 return(TopAbs_OUT);
187}
188
189TopoDS_Face TopClass_SolidClassifier::Face() const {
190 return(myFace);
191}
192
193Standard_Boolean TopClass_SolidClassifier::Rejected() const {
194 return(myState==1);
195}
196
197
198Standard_Boolean TopClass_SolidClassifier::IsOnAFace() const {
199 return(myState==2);
200}