0023024: Update headers of OCCT files
[occt.git] / src / BOPTest / BOPTest_MTestCommands.cxx
CommitLineData
b311480e 1// Created on: 2000-05-18
2// Created by: Peter KURNEV
3// Copyright (c) 2000-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <BOPTest.ixx>
23
24#include <stdio.h>
25
26#include <Draw_Interpretor.hxx>
27#include <TopoDS_Shape.hxx>
28#include <DBRep.hxx>
29#include <TopoDS_Edge.hxx>
30#include <TopoDS.hxx>
31#include <IntTools_EdgeEdge.hxx>
32#include <IntTools_SequenceOfCommonPrts.hxx>
33#include <IntTools_Range.hxx>
34#include <IntTools_CommonPrt.hxx>
35#include <BRep_Tool.hxx>
36
37//=======================================================================
38//function :bbedge
39//purpose :
40//=======================================================================
41static Standard_Integer bbedge (Draw_Interpretor& di,
42 Standard_Integer n,
43 const char** a)
44{
45 if (n<7) {
46 di << " Use bbedge> Edge1 Edge2 f1 l1 f2 l2\n";
47 return 1;
48 }
49
50 TopoDS_Shape S1 = DBRep::Get(a[1]);
51 TopoDS_Shape S2 = DBRep::Get(a[2]);
52
53 if (S1.IsNull() || S2.IsNull()) {
54 di << " Null shapes is not allowed \n";
55 return 1;
56 }
57
58 if (S1.ShapeType()!=TopAbs_EDGE && S2.ShapeType()!=TopAbs_EDGE) {
59 di << " Shapes must be EDGE type\n";
60 return 1;
61 }
62
63 TopoDS_Edge E1=TopoDS::Edge(S1);
64 TopoDS_Edge E2=TopoDS::Edge(S2);
65
66 Standard_Integer aDiscr=30;
67 Standard_Real aTol=.0000001, aDeflection=.01;
68 Standard_Real f1, l1, f2, l2;
69
70 f1=atof (a[3]);
71 l1=atof (a[4]);
72 f2=atof (a[5]);
73 l2=atof (a[6]);
74
75 IntTools_Range aR1, aR2;
76 aR1.SetFirst(f1); aR1.SetLast(l1);
77 aR2.SetFirst(f2); aR2.SetLast(l2);
78
79 di << " bbedge: ===Begin===\n";
80 di << " bbedge: Discretize=" << aDiscr << "\n";
81 di << " bbedge: Tolerance =" << aTol << "\n";
82 di << " bbedge: Deflection=" << aDeflection << "\n";
83
84 IntTools_EdgeEdge aEE;
85
86
87 aEE.SetEdge1(E1);
88 aEE.SetEdge2(E2);
89 aEE.SetTolerance1(aTol);
90 aEE.SetTolerance2(aTol);
91
92 aEE.SetDiscretize(aDiscr);
93 aEE.SetDeflection(aDeflection);
94
95 aEE.SetRange1(aR1);
96 aEE.SetRange2(aR2);
97
98 aEE.Perform();
99 //
100 // Results treatment
101 Standard_Boolean anIsDone=aEE.IsDone();
102 di << "\n aEE.IsDone()=" << (Standard_Integer) anIsDone << ", aEE.ErrorStatus()=" << aEE.ErrorStatus() << "\n";
103
104 if (anIsDone) {
105 const IntTools_SequenceOfCommonPrts& aSCp=aEE.CommonParts ();
106
107 Standard_Integer i,j, aNbRanges, aNbRanges2;
108 Standard_Real t1, t2;
109
110 aNbRanges=aSCp.Length();
111 for (i=1; i<=aNbRanges; i++) {
112 const IntTools_CommonPrt& aCommonPrt=aSCp(i);
113
114 di << " CommonPrt#" << i << " , Type=" << aCommonPrt.Type() << "\n";
115 const IntTools_Range& aRange1=aCommonPrt.Range1();
116 aRange1.Range(t1, t2);
117 di << "Range 1: [" << t1 << ", " << t2 << "]\n";
118
119 const IntTools_SequenceOfRanges& aSeqOfRanges2=aCommonPrt.Ranges2();
120 aNbRanges2=aSeqOfRanges2.Length();
121 for (j=1; j<=aNbRanges2; j++) {
122 const IntTools_Range& aRange2=aSeqOfRanges2(j);
123 aRange2.Range(t1, t2);
124 di << "Range 2: [" << t1 << ", " << t2 << "] (# " << j << ")\n";
125 }
126 }
127 }
128
129
130 di << " bedge: ===End===\n";
131 return 0;
132}
133
134//=======================================================================
135//function :bedge
136//purpose :
137//=======================================================================
138static Standard_Integer bedge (Draw_Interpretor& di,
139 Standard_Integer n,
140 const char** a)
141{
142 if (n<3) {
143 di << " Use bedge> Edge1 Edge2 Discr[30] Tol[1.e-7] Deflection[0.01]\n";
144 return 1;
145 }
146
147 TopoDS_Shape S1 = DBRep::Get(a[1]);
148 TopoDS_Shape S2 = DBRep::Get(a[2]);
149
150 if (S1.IsNull() || S2.IsNull()) {
151 di << " Null shapes is not allowed \n";
152 return 1;
153 }
154
155 if (S1.ShapeType()!=TopAbs_EDGE && S2.ShapeType()!=TopAbs_EDGE) {
156 di << " Shapes must be EDGE type\n";
157 return 1;
158 }
159
160 TopoDS_Edge E1=TopoDS::Edge(S1);
161 TopoDS_Edge E2=TopoDS::Edge(S2);
162
163 Standard_Integer aDiscr=30;
164 Standard_Real aTol=.0000001, aDeflection=.01;
165 Standard_Real f1, l1, f2, l2;
166
167 BRep_Tool::Range(E1, f1, l1);
168 BRep_Tool::Range(E2, f2, l2);
169
170 IntTools_Range aR1, aR2;
171 aR1.SetFirst(f1); aR1.SetLast(l1);
172 aR2.SetFirst(f2); aR2.SetLast(l2);
173
174 if (n>=4) {
175 aDiscr=atoi (a[3]);
176 }
177
178 if (n>=5) {
179 aTol=atof (a[4]);
180 }
181
182 if (n>=6) {
183 aDeflection=atof (a[5]);
184 }
185
186 di << " bedge: ===Begin===\n";
187 di << " bedge: Discretize=" << aDiscr << "\n";
188 di << " bedge: Tolerance =" << aTol << "\n";
189 di << " bedge: Deflection=" << aDeflection << "\n";
190
191 IntTools_EdgeEdge aEE;
192
193
194 aEE.SetEdge1(E1);
195 aEE.SetEdge2(E2);
196 aEE.SetTolerance1(aTol);
197 aEE.SetTolerance2(aTol);
198
199 aEE.SetDiscretize(aDiscr);
200 aEE.SetDeflection(aDeflection);
201
202 aEE.SetRange1(aR1);
203 aEE.SetRange2(aR2);
204
205 aEE.Perform();
206 //
207 // Results treatment
208 Standard_Boolean anIsDone=aEE.IsDone();
209 di << "\n aEE.IsDone()=" << (Standard_Integer) anIsDone << ", aEE.ErrorStatus()=" << aEE.ErrorStatus() << "\n";
210
211 if (anIsDone) {
212 const IntTools_SequenceOfCommonPrts& aSCp=aEE.CommonParts ();
213
214 Standard_Integer i,j, aNbRanges, aNbRanges2;
215 Standard_Real t1, t2;
216
217 aNbRanges=aSCp.Length();
218 for (i=1; i<=aNbRanges; i++) {
219 const IntTools_CommonPrt& aCommonPrt=aSCp(i);
220
221 di << " CommonPrt#" << i << " , Type=" << aCommonPrt.Type() << "\n";
222 const IntTools_Range& aRange1=aCommonPrt.Range1();
223 aRange1.Range(t1, t2);
224 di << "Range 1: [" << t1 << ", " << t2 << "]\n";
225
226 const IntTools_SequenceOfRanges& aSeqOfRanges2=aCommonPrt.Ranges2();
227 aNbRanges2=aSeqOfRanges2.Length();
228 for (j=1; j<=aNbRanges2; j++) {
229 const IntTools_Range& aRange2=aSeqOfRanges2(j);
230 aRange2.Range(t1, t2);
231 di << "Range 2: [" << t1 << ", " << t2 << "] (# " << j << ")\n";
232 }
233 }
234 }
235
236
237 di << " bedge: ===End===\n";
238 return 0;
239}
240
241//=======================================================================
242//function : MTestCommands
243//purpose :
244//=======================================================================
245 void BOPTest::MTestCommands(Draw_Interpretor& theCommands)
246{
247 static Standard_Boolean done = Standard_False;
248 if (done) return;
249 done = Standard_True;
250 // Chapter's name
251 const char* g = "Mtest commands";
252
253 theCommands.Add("bedge" , "Use bedge> Edge1 Edge2 Discr[30] Tol[1.e-7] Deflection[0.01]", __FILE__, bedge,g);
254 theCommands.Add("bbedge", "Use bbedge> Edge1 Edge2 f1 l1 f2 l2", __FILE__, bbedge,g);
255}