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