summaryrefslogtreecommitdiff
path: root/src/BOPTest/BOPTest_CurveCommands.cxx
blob: 6e25c24239d456e0b2eb06f3843244905d843130 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// File:	BOPTest_CurveCommands.cxx
// Created:	10:45:01 2000
// Author:	Peter KURNEV
//		<pkv@irinox>


#include <BOPTest.ixx>

#include <stdio.h>

#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>

#include <TCollection_AsciiString.hxx>

#include <IntTools_FaceFace.hxx>
#include <IntTools_SequenceOfCurves.hxx>
#include <IntTools_Curve.hxx>

#include <Geom_Curve.hxx>
#include <DrawTrSurf.hxx>
#include <DBRep.hxx>
#include <IntTools_Tools.hxx>


static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char** );
static Standard_Integer bcurtolerance (Draw_Interpretor& di, Standard_Integer n, const char** a);

//=======================================================================
//function : BOPTest::CurveCommands
//purpose  : 
//=======================================================================
  void  BOPTest::CurveCommands(Draw_Interpretor& theCommands)
{
  static Standard_Boolean done = Standard_False;
  if (done) return;
  done = Standard_True;
  // Chapter's name
  const char* g = "CCR commands";

  theCommands.Add("bopcurves"     , "Use  bopcurves> F1 F2", __FILE__, bopcurves, g);
  theCommands.Add("bcurtolerance" , " use >bcurtolerance C3Dtrim, Tol\n", __FILE__, bcurtolerance, g);
}

//=======================================================================
//function : bopcurves
//purpose  : 
//=======================================================================
Standard_Integer bopcurves (Draw_Interpretor& di, 
			    Standard_Integer n, 
			    const char** a)
{
  if (n<3) {
    di << " Use bopcurves> F1 F2\n";
    return 1;
  }

  TopoDS_Shape S1 = DBRep::Get(a[1]);
  TopoDS_Shape S2 = DBRep::Get(a[2]);
  TopAbs_ShapeEnum aType;

  if (S1.IsNull() || S2.IsNull()) {
    di << " Null shapes is not allowed \n";
    return 1;
  }

  aType=S1.ShapeType();
  if (aType != TopAbs_FACE) {
    di << " Type mismatch F1\n";
    return 1;
  }
  aType=S2.ShapeType();
  if (aType != TopAbs_FACE) {
    di << " Type mismatch F2\n";
    return 1;
  }


  const TopoDS_Face& aF1=TopoDS::Face(S1);
  const TopoDS_Face& aF2=TopoDS::Face(S2);

  Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
  Standard_Integer i, aNbCurves;
  Standard_Real anAppTol, aTolR;
  TCollection_AsciiString aNm("c_");

  aToApproxC3d=Standard_True;
  aToApproxC2dOnS1=Standard_False;
  aToApproxC2dOnS2=Standard_False;
  anAppTol=0.0000001;


  IntTools_FaceFace aFF;
  
  aFF.SetParameters (aToApproxC3d,
		     aToApproxC2dOnS1,
		     aToApproxC2dOnS2,
		     anAppTol);
  
  aFF.Perform (aF1, aF2);
  
  anIsDone=aFF.IsDone();
  if (!anIsDone) {
    //printf(" anIsDone=%d\n", anIsDone);
    di << " anIsDone=" << (Standard_Integer) anIsDone << "\n";
    return 1;
  }

  aFF.PrepareLines3D();
  const IntTools_SequenceOfCurves& aSCs=aFF.Lines();

  //
  aTolR=aFF.TolReached3d();
  di << "Tolerance Reached=" << aTolR << "\n";

  aNbCurves=aSCs.Length();
  if (!aNbCurves) {
    di << " has no 3d curve\n";
    return 1;
  }

  for (i=1; i<=aNbCurves; i++) {
    const IntTools_Curve& anIC=aSCs(i);

    Handle (Geom_Curve) aC3D=anIC.Curve();

    if (aC3D.IsNull()) {
      di << " has Null 3d curve# " << i << "%d\n";
      continue;
    }

    TCollection_AsciiString anIndx(i), aNmx;
    aNmx=aNm+anIndx;
    Standard_CString name= aNmx.ToCString();
    DrawTrSurf::Set(name, aC3D);
    di << name << " ";
  }

  di << "\n";
  
  return 0;
}

//=======================================================================
//function : bcurtolerance
//purpose  : 
//=======================================================================
 Standard_Integer bcurtolerance (Draw_Interpretor& di, 
				 Standard_Integer n, 
				 const char** a)
{
  if(n < 2) {
    di << " use >bcurtolerance C3D [Tol=1.e-7]\n";
    return 1;
  }

  Handle(Geom_Curve) aC3D = DrawTrSurf::GetCurve(a[1]);
  if ( aC3D.IsNull()) {
    di << " Null Curve is not allowed here\n";
    return 1;
  }
  //
  Standard_Real  aTolMax, aTol;
  
  aTol=1.e-7;
  if (n>2) {
    aTol=atof(a[2]);
    if (aTol<=0.) {
      aTol=1.e-7;
    }
  }
  //
  aTolMax=IntTools_Tools::CurveTolerance(aC3D, aTol);
  //printf(" aTolMax=%16.11f\n", aTolMax);
  di << " aTolMax=" << aTolMax << "\n";
  
  return 0;
}