0022627: Change OCCT memory management defaults
[occt.git] / src / BOPTest / BOPTest_MTestCommands.cxx
1 // File:        BOPTest_ProjectionCommands.cxx
2 // Created:     Thu May 18 10:45:01 2000
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6
7 #include <BOPTest.ixx>
8
9 #include <stdio.h>
10
11 #include <Draw_Interpretor.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <DBRep.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS.hxx>
16 #include <IntTools_EdgeEdge.hxx>
17 #include <IntTools_SequenceOfCommonPrts.hxx>
18 #include <IntTools_Range.hxx>
19 #include <IntTools_CommonPrt.hxx>
20 #include <BRep_Tool.hxx>
21
22 //=======================================================================
23 //function :bbedge
24 //purpose  : 
25 //=======================================================================
26 static Standard_Integer bbedge (Draw_Interpretor& di,
27                                 Standard_Integer n, 
28                                 const char** a)
29 {
30   if (n<7) {
31     di << " Use bbedge> Edge1 Edge2 f1 l1 f2 l2\n";
32     return 1;
33   }
34
35   TopoDS_Shape S1 = DBRep::Get(a[1]);
36   TopoDS_Shape S2 = DBRep::Get(a[2]);
37   
38   if (S1.IsNull() || S2.IsNull()) {
39     di << " Null shapes is not allowed \n";
40     return 1;
41   }
42
43   if (S1.ShapeType()!=TopAbs_EDGE && S2.ShapeType()!=TopAbs_EDGE) {
44     di << " Shapes must be EDGE type\n";
45     return 1;
46   }
47
48   TopoDS_Edge E1=TopoDS::Edge(S1);
49   TopoDS_Edge E2=TopoDS::Edge(S2);
50
51   Standard_Integer aDiscr=30;
52   Standard_Real aTol=.0000001, aDeflection=.01;
53   Standard_Real f1, l1, f2, l2;
54
55   f1=atof (a[3]);
56   l1=atof (a[4]);
57   f2=atof (a[5]);
58   l2=atof (a[6]);
59
60   IntTools_Range aR1, aR2;
61   aR1.SetFirst(f1);  aR1.SetLast(l1);
62   aR2.SetFirst(f2);  aR2.SetLast(l2);
63   
64   di << " bbedge: ===Begin===\n";
65   di << " bbedge: Discretize=" << aDiscr << "\n";
66   di << " bbedge: Tolerance =" << aTol << "\n";
67   di << " bbedge: Deflection=" << aDeflection << "\n";
68
69   IntTools_EdgeEdge aEE;
70   
71   
72   aEE.SetEdge1(E1); 
73   aEE.SetEdge2(E2); 
74   aEE.SetTolerance1(aTol);
75   aEE.SetTolerance2(aTol);
76
77   aEE.SetDiscretize(aDiscr);
78   aEE.SetDeflection(aDeflection);
79
80   aEE.SetRange1(aR1);
81   aEE.SetRange2(aR2);
82
83   aEE.Perform();
84   //
85   // Results treatment
86   Standard_Boolean anIsDone=aEE.IsDone();
87   di << "\n aEE.IsDone()=" << (Standard_Integer) anIsDone << ", aEE.ErrorStatus()=" << aEE.ErrorStatus() << "\n";
88   
89   if (anIsDone) {
90     const IntTools_SequenceOfCommonPrts& aSCp=aEE.CommonParts ();
91
92     Standard_Integer i,j, aNbRanges, aNbRanges2;
93     Standard_Real    t1, t2;
94
95     aNbRanges=aSCp.Length();
96     for (i=1; i<=aNbRanges; i++) {
97       const IntTools_CommonPrt& aCommonPrt=aSCp(i);
98       
99       di << " CommonPrt#" << i << " , Type=" << aCommonPrt.Type() << "\n";
100       const IntTools_Range& aRange1=aCommonPrt.Range1();
101       aRange1.Range(t1, t2);
102       di << "Range 1: [" << t1 << ", " << t2 << "]\n"; 
103
104       const IntTools_SequenceOfRanges& aSeqOfRanges2=aCommonPrt.Ranges2();
105       aNbRanges2=aSeqOfRanges2.Length();
106       for (j=1; j<=aNbRanges2; j++) {
107         const IntTools_Range& aRange2=aSeqOfRanges2(j);
108         aRange2.Range(t1, t2);
109         di << "Range 2: [" << t1 << ", " << t2 << "] (# " << j << ")\n"; 
110       }
111     } 
112   }
113   
114
115   di << " bedge: ===End===\n";
116   return 0;
117 }
118
119 //=======================================================================
120 //function :bedge
121 //purpose  : 
122 //=======================================================================
123 static Standard_Integer bedge (Draw_Interpretor& di, 
124                                Standard_Integer n, 
125                                const char** a)
126 {
127   if (n<3) {
128     di << " Use bedge> Edge1 Edge2 Discr[30] Tol[1.e-7] Deflection[0.01]\n";
129     return 1;
130   }
131
132   TopoDS_Shape S1 = DBRep::Get(a[1]);
133   TopoDS_Shape S2 = DBRep::Get(a[2]);
134   
135   if (S1.IsNull() || S2.IsNull()) {
136     di << " Null shapes is not allowed \n";
137     return 1;
138   }
139
140   if (S1.ShapeType()!=TopAbs_EDGE && S2.ShapeType()!=TopAbs_EDGE) {
141     di << " Shapes must be EDGE type\n";
142     return 1;
143   }
144
145   TopoDS_Edge E1=TopoDS::Edge(S1);
146   TopoDS_Edge E2=TopoDS::Edge(S2);
147
148   Standard_Integer aDiscr=30;
149   Standard_Real aTol=.0000001, aDeflection=.01;
150   Standard_Real f1, l1, f2, l2;
151
152   BRep_Tool::Range(E1, f1, l1);
153   BRep_Tool::Range(E2, f2, l2);
154
155   IntTools_Range aR1, aR2;
156   aR1.SetFirst(f1);  aR1.SetLast(l1);
157   aR2.SetFirst(f2);  aR2.SetLast(l2);
158
159   if (n>=4) {  
160     aDiscr=atoi (a[3]);
161   }
162
163   if (n>=5) {  
164     aTol=atof (a[4]);
165   }
166
167   if (n>=6) {  
168     aDeflection=atof (a[5]);
169   }
170
171   di << " bedge: ===Begin===\n";
172   di << " bedge: Discretize=" << aDiscr << "\n";
173   di << " bedge: Tolerance =" << aTol << "\n";
174   di << " bedge: Deflection=" << aDeflection << "\n";
175
176   IntTools_EdgeEdge aEE;
177   
178   
179   aEE.SetEdge1(E1); 
180   aEE.SetEdge2(E2); 
181   aEE.SetTolerance1(aTol);
182   aEE.SetTolerance2(aTol);
183
184   aEE.SetDiscretize(aDiscr);
185   aEE.SetDeflection(aDeflection);
186
187   aEE.SetRange1(aR1);
188   aEE.SetRange2(aR2);
189
190   aEE.Perform();
191   //
192   // Results treatment
193   Standard_Boolean anIsDone=aEE.IsDone();
194   di << "\n aEE.IsDone()=" << (Standard_Integer) anIsDone << ", aEE.ErrorStatus()=" << aEE.ErrorStatus() << "\n";
195   
196   if (anIsDone) {
197     const IntTools_SequenceOfCommonPrts& aSCp=aEE.CommonParts ();
198
199     Standard_Integer i,j, aNbRanges, aNbRanges2;
200     Standard_Real    t1, t2;
201
202     aNbRanges=aSCp.Length();
203     for (i=1; i<=aNbRanges; i++) {
204       const IntTools_CommonPrt& aCommonPrt=aSCp(i);
205       
206       di << " CommonPrt#" << i << " , Type=" << aCommonPrt.Type() << "\n";
207       const IntTools_Range& aRange1=aCommonPrt.Range1();
208       aRange1.Range(t1, t2);
209       di << "Range 1: [" << t1 << ", " << t2 << "]\n"; 
210
211       const IntTools_SequenceOfRanges& aSeqOfRanges2=aCommonPrt.Ranges2();
212       aNbRanges2=aSeqOfRanges2.Length();
213       for (j=1; j<=aNbRanges2; j++) {
214         const IntTools_Range& aRange2=aSeqOfRanges2(j);
215         aRange2.Range(t1, t2);
216         di << "Range 2: [" << t1 << ", " << t2 << "] (# " << j << ")\n"; 
217       }
218     } 
219   }
220   
221
222   di << " bedge: ===End===\n";
223   return 0;
224 }
225
226 //=======================================================================
227 //function : MTestCommands
228 //purpose  : 
229 //=======================================================================
230   void  BOPTest::MTestCommands(Draw_Interpretor& theCommands)
231 {
232   static Standard_Boolean done = Standard_False;
233   if (done) return;
234   done = Standard_True;
235   // Chapter's name
236   const char* g = "Mtest commands";
237
238   theCommands.Add("bedge" , "Use bedge> Edge1 Edge2 Discr[30] Tol[1.e-7] Deflection[0.01]", __FILE__, bedge,g);
239   theCommands.Add("bbedge", "Use bbedge> Edge1 Edge2 f1 l1 f2 l2", __FILE__, bbedge,g);
240 }