0021762: Integration of new Boolean Operation algorithm to OCCT.
[occt.git] / src / BOPTest / BOPTest_LowCommands.cxx
1 // Created on: 2001-03-28
2 // Created by: Peter KURNEV
3 // Copyright (c) 2001-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 #include <BOPTest.ixx>
22
23 #include <stdio.h>
24
25 #include <gp_Pnt2d.hxx>
26 #include <gp_Pnt.hxx>
27
28 #include <TopoDS.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopAbs_State.hxx>
31
32 #include <TCollection_AsciiString.hxx>
33
34 #include <BRepClass3d_SolidClassifier.hxx>
35 #include <BRepClass_FaceClassifier.hxx>
36 #include <BRep_Tool.hxx>
37
38 #include <Draw.hxx>
39 #include <DBRep.hxx>
40 #include <DrawTrSurf.hxx>
41
42 static
43   void PrintState (Draw_Interpretor& aDI,
44                    const TopAbs_State& aState);
45
46 static  Standard_Integer bclassify   (Draw_Interpretor& , Standard_Integer , const char** );
47 static  Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** );
48
49 //=======================================================================
50 //function : LowCommands
51 //purpose  : 
52 //=======================================================================
53   void  BOPTest::LowCommands(Draw_Interpretor& theCommands)
54 {
55   static Standard_Boolean done = Standard_False;
56   if (done) return;
57   done = Standard_True;
58   // Chapter's name
59   const char* g = "CCR commands";
60   theCommands.Add("bclassify"    , "Use >bclassify Solid Point [Tolerance=1.e-7]",
61                   __FILE__, bclassify   , g);
62   theCommands.Add("b2dclassify"  , "Use >bclassify Face Point2d [Tol2D=Tol(Face)] ",
63                   __FILE__, b2dclassify , g);
64 }
65
66
67 //=======================================================================
68 //function : bclassify
69 //purpose  : 
70 //=======================================================================
71 Standard_Integer bclassify (Draw_Interpretor& aDI,
72                             Standard_Integer n, 
73                             const char** a)
74 {
75   char sbf[512];        
76   
77   if (n < 3) {
78     Sprintf(sbf, " Use >bclassify Solid Point [Tolerance=1.e-7]\n");
79     aDI<<sbf;
80     return 1;
81   }
82   
83   TopoDS_Shape aS = DBRep::Get(a[1]);
84   if (aS.IsNull()) {
85     Sprintf(sbf, " Null Shape is not allowed here\n");
86     aDI<<sbf;
87     return 1;
88   }
89   
90   if (aS.ShapeType()!=TopAbs_SOLID) {
91     Sprintf(sbf, " Shape type must be SOLID\n");
92     aDI<<sbf;
93     return 1;
94   }
95   //
96   Standard_Real aTol=1.e-7;
97   TopAbs_State aState = TopAbs_UNKNOWN;
98   gp_Pnt aP(8., 9., 10.);
99   
100   DrawTrSurf::GetPoint(a[2], aP);
101   
102   aTol=1.e-7; 
103   if (n==4) {
104     aTol=Draw::Atof(a[3]);
105   }
106   //
107   BRepClass3d_SolidClassifier aSC(aS);
108   aSC.Perform(aP,aTol);
109   //
110   aState = aSC.State();
111   //
112   PrintState (aDI, aState);
113   //
114   return 0;
115 }
116 //
117 //=======================================================================
118 //function : b2dclassify
119 //purpose  : 
120 //=======================================================================
121 Standard_Integer b2dclassify (Draw_Interpretor& aDI,
122                               Standard_Integer n, 
123                               const char** a)
124 {
125   char sbf[512];        
126   
127   if (n < 3) {
128     Sprintf(sbf, " Use >bclassify Face Point2d [Tol2D=Tol(Face)]\n");
129     aDI<<sbf;
130     return 1;
131   }
132   
133   TopoDS_Shape aS = DBRep::Get(a[1]);
134   if (aS.IsNull()) {
135     Sprintf(sbf, " Null Shape is not allowed here\n");
136     aDI<<sbf;
137     return 1;
138   }
139   
140   if (aS.ShapeType()!=TopAbs_FACE) {
141     Sprintf(sbf, " Shape type must be FACE\n");
142     aDI<<sbf;
143     return 1;
144   }
145   //
146   Standard_Real aTol;
147   TopAbs_State aState = TopAbs_UNKNOWN;
148   gp_Pnt2d aP(8., 9.);
149   
150   DrawTrSurf::GetPoint2d(a[2], aP);
151   
152   const TopoDS_Face& aF=TopoDS::Face(aS);
153   aTol=BRep_Tool::Tolerance(aF); 
154   if (n==4) {
155     aTol=Draw::Atof(a[3]);
156   }
157   //
158   BRepClass_FaceClassifier aClassifier;
159   aClassifier.Perform(aF, aP, aTol);
160   //
161   aState = aClassifier.State();
162   //
163   PrintState (aDI, aState);
164   //
165   return 0;
166 }
167
168 //=======================================================================
169 //function : PrintState
170 //purpose  : 
171 //=======================================================================
172 void PrintState (Draw_Interpretor& aDI,
173                  const TopAbs_State& aState)
174 {
175   char sbf[512];        
176   TCollection_AsciiString sIN("IN"), sOUT("OUT of"), sON("ON"), sUNKNOWN("UNKNOWN"); 
177   //
178   Sprintf(sbf, "The point is "); aDI<<sbf;
179   //
180   switch (aState) {
181   case TopAbs_IN:
182     Sprintf(sbf, sIN.ToCString());
183     break;
184   case TopAbs_OUT:
185     Sprintf(sbf, sOUT.ToCString());
186     break;
187   case TopAbs_ON:
188     Sprintf(sbf, sON.ToCString());
189     break;
190   case TopAbs_UNKNOWN:
191     Sprintf(sbf, sUNKNOWN.ToCString());
192     break;
193   default:
194     Sprintf(sbf, sUNKNOWN.ToCString()); 
195     break;
196   }
197   aDI<<sbf; 
198   //
199   Sprintf(sbf, " shape\n");
200   aDI<<sbf;
201   
202 }