Adding of testing cases from subgroups 937 940 and 941 of CHL group
[occt.git] / src / BOPTest / BOPTest_CurveCommands.cxx
1 // Created on: 2000-03-16
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
20
21
22 #include <BOPTest.ixx>
23
24 #include <stdio.h>
25
26 #include <TopoDS.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <TopoDS_Face.hxx>
29
30 #include <TCollection_AsciiString.hxx>
31
32 #include <IntTools_FaceFace.hxx>
33 #include <IntTools_SequenceOfCurves.hxx>
34 #include <IntTools_Curve.hxx>
35
36 #include <Geom_Curve.hxx>
37 #include <DrawTrSurf.hxx>
38 #include <Draw.hxx>
39 #include <DBRep.hxx>
40 #include <IntTools_Tools.hxx>
41
42
43 static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char** );
44 static Standard_Integer bcurtolerance (Draw_Interpretor& di, Standard_Integer n, const char** a);
45
46 //=======================================================================
47 //function : BOPTest::CurveCommands
48 //purpose  : 
49 //=======================================================================
50   void  BOPTest::CurveCommands(Draw_Interpretor& theCommands)
51 {
52   static Standard_Boolean done = Standard_False;
53   if (done) return;
54   done = Standard_True;
55   // Chapter's name
56   const char* g = "CCR commands";
57
58   theCommands.Add("bopcurves"     , "Use  bopcurves> F1 F2", __FILE__, bopcurves, g);
59   theCommands.Add("bcurtolerance" , " use >bcurtolerance C3Dtrim, Tol\n", __FILE__, bcurtolerance, g);
60 }
61
62 //=======================================================================
63 //function : bopcurves
64 //purpose  : 
65 //=======================================================================
66 Standard_Integer bopcurves (Draw_Interpretor& di, 
67                             Standard_Integer n, 
68                             const char** a)
69 {
70   if (n<3) {
71     di << " Use bopcurves> F1 F2\n";
72     return 1;
73   }
74
75   TopoDS_Shape S1 = DBRep::Get(a[1]);
76   TopoDS_Shape S2 = DBRep::Get(a[2]);
77   TopAbs_ShapeEnum aType;
78
79   if (S1.IsNull() || S2.IsNull()) {
80     di << " Null shapes is not allowed \n";
81     return 1;
82   }
83
84   aType=S1.ShapeType();
85   if (aType != TopAbs_FACE) {
86     di << " Type mismatch F1\n";
87     return 1;
88   }
89   aType=S2.ShapeType();
90   if (aType != TopAbs_FACE) {
91     di << " Type mismatch F2\n";
92     return 1;
93   }
94
95
96   const TopoDS_Face& aF1=TopoDS::Face(S1);
97   const TopoDS_Face& aF2=TopoDS::Face(S2);
98
99   Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
100   Standard_Boolean bToSplit;
101   Standard_Integer i, aNbCurves;
102   Standard_Real anAppTol, aTolR;
103   TCollection_AsciiString aNm("c_");
104   //
105   bToSplit=Standard_False;
106   aToApproxC3d=Standard_True;
107   aToApproxC2dOnS1=Standard_False;
108   aToApproxC2dOnS2=Standard_False;
109   anAppTol=0.0000001;
110
111
112   IntTools_FaceFace aFF;
113   
114   aFF.SetParameters (aToApproxC3d,
115                      aToApproxC2dOnS1,
116                      aToApproxC2dOnS2,
117                      anAppTol);
118   
119   aFF.Perform (aF1, aF2);
120   
121   anIsDone=aFF.IsDone();
122   if (!anIsDone) {
123     //printf(" anIsDone=%d\n", anIsDone);
124     di << " anIsDone=" << (Standard_Integer) anIsDone << "\n";
125     return 1;
126   }
127
128   aFF.PrepareLines3D(bToSplit);
129   const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
130
131   //
132   aTolR=aFF.TolReached3d();
133   di << "Tolerance Reached=" << aTolR << "\n";
134
135   aNbCurves=aSCs.Length();
136   if (!aNbCurves) {
137     di << " has no 3d curve\n";
138     return 1;
139   }
140
141   for (i=1; i<=aNbCurves; i++) {
142     const IntTools_Curve& anIC=aSCs(i);
143
144     Handle (Geom_Curve) aC3D=anIC.Curve();
145
146     if (aC3D.IsNull()) {
147       di << " has Null 3d curve# " << i << "%d\n";
148       continue;
149     }
150
151     TCollection_AsciiString anIndx(i), aNmx;
152     aNmx=aNm+anIndx;
153     Standard_CString name= aNmx.ToCString();
154     DrawTrSurf::Set(name, aC3D);
155     di << name << " ";
156   }
157
158   di << "\n";
159   
160   return 0;
161 }
162
163 //=======================================================================
164 //function : bcurtolerance
165 //purpose  : 
166 //=======================================================================
167  Standard_Integer bcurtolerance (Draw_Interpretor& di, 
168                                  Standard_Integer n, 
169                                  const char** a)
170 {
171   if(n < 2) {
172     di << " use >bcurtolerance C3D [Tol=1.e-7]\n";
173     return 1;
174   }
175
176   Handle(Geom_Curve) aC3D = DrawTrSurf::GetCurve(a[1]);
177   if ( aC3D.IsNull()) {
178     di << " Null Curve is not allowed here\n";
179     return 1;
180   }
181   //
182   Standard_Real  aTolMax, aTol;
183   
184   aTol=1.e-7;
185   if (n>2) {
186     aTol=Draw::Atof(a[2]);
187     if (aTol<=0.) {
188       aTol=1.e-7;
189     }
190   }
191   //
192   aTolMax=IntTools_Tools::CurveTolerance(aC3D, aTol);
193   //printf(" aTolMax=%16.11f\n", aTolMax);
194   di << " aTolMax=" << aTolMax << "\n";
195   
196   return 0;
197 }