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