summaryrefslogtreecommitdiff
path: root/src/BOPTest/BOPTest_EFCommands.cxx
blob: 816f05a7e8dc85fef592a89aa28bae90688c1246 (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
// File:	BOPTest_EFCommands.cxx
// Created:	Mon Feb 26 10:44:30 2001
// Author:	Peter KURNEV
//		<pkv@irinox>


#include <BOPTest.ixx>

#include <stdio.h>

#include <Draw_Interpretor.hxx>

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

#include <DBRep.hxx>

#include <IntTools_EdgeFace.hxx>
#include <BRep_Tool.hxx>
#include <IntTools_SequenceOfCommonPrts.hxx>
#include <IntTools_CommonPrt.hxx>

//=======================================================================
//function :bedge
//purpose  : 
//=======================================================================
static Standard_Integer bef   (Draw_Interpretor& di, 
			       Standard_Integer n, 
			       const char** a)
{
  if (n<3) {
    di << " Use bef> Edge Face Discr[33] Tol[1.e-7] Deflection[0.01]\n";
    return 1;
  }

  TopoDS_Shape S1 = DBRep::Get(a[1]);
  TopoDS_Shape S2 = DBRep::Get(a[2]);
  
  if (S1.IsNull() || S2.IsNull()) {
    di << " Null shapes is not allowed \n";
    return 1;
  }

  if (S1.ShapeType()!=TopAbs_EDGE && S2.ShapeType()!=TopAbs_FACE) {
    di << " Shapes must be EDGE and  FACE type\n";
    return 1;
  }

  TopoDS_Edge E=TopoDS::Edge(S1);
  TopoDS_Face F=TopoDS::Face(S2);

  Standard_Integer aDiscr=33;
  Standard_Real aTol=.0000001, aDeflection=.01, aFrom, aTo;
  
  if (n>=4) {  
    aDiscr=atoi (a[3]);
  }

  if (n>=5) {  
    aTol=atof (a[4]);
  }

  if (n>=6) {  
    aDeflection=atof (a[5]);
  }

  di << " bef: ===Begin===\n";
  di << " bef: Discretize=" << aDiscr << "%d\n";
  di << " bef: Tolerance =" << aTol << "\n";
  di << " bef: Deflection=" << aDeflection << "\n";
  
  IntTools_EdgeFace aEF;
  
  aEF.SetEdge(E); 
  aEF.SetFace(F); 
  aEF.SetTolE(aTol);
  aEF.SetTolF(aTol);

  aEF.SetDiscretize(aDiscr);
  aEF.SetDeflection(aDeflection);

  BRep_Tool::Range(E, aFrom, aTo);
  aEF.SetRange (aFrom, aTo);

  aEF.Perform();
  //
  // Results treatment
  Standard_Boolean anIsDone=aEF.IsDone();
  
  di << "\n aEF.IsDone()=" << (Standard_Integer) anIsDone << ", aEF.ErrorStatus()=" << aEF.ErrorStatus() << "\n";
  
  if (anIsDone) {
    Standard_Integer i, aNb;
    Standard_Real tF, tL;

    const IntTools_SequenceOfCommonPrts& aCPs=aEF.CommonParts();
    aNb=aCPs.Length();
    di << " aNb Common Parts=" << aNb << "\n";
    for (i=1; i<=aNb; i++) {
      const IntTools_CommonPrt& aCP=aCPs(i);
      TopAbs_ShapeEnum aType=aCP.Type();
      if (aType==TopAbs_VERTEX)
	di << " aCP => Type=Vertex\n";
      else if (aType==TopAbs_EDGE)
	di << " aCP => Type=Edge\n";
      else 
	di << " aCP => Type=Unknown\n";

      aCP.Range1(tF, tL);
      di << " Part " << i << " Edge#1 (" << tF << ", " << tL << ")\n";
    }
  }

  di << " bef: ===End===\n";
  return 0;
}

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

  theCommands.Add("bef", "Use bef> Edge Face Discr[33] Tol[1.e-7] Deflection[0.01]", __FILE__, bef, g);
}