0025584: Wrong result obtained by PerformInfinitePoint Test
[occt.git] / src / BRepAlgoAPI / BRepAlgoAPI.cxx
1 // Created on: 2012-12-25
2 // Created by: KULIKOVA Galina
3 // Copyright (c) 2012-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BRepAlgoAPI.ixx>
17
18 #include <stdio.h>
19 #include <TCollection_AsciiString.hxx>
20 #include <BRepTools.hxx>
21 #include <OSD_File.hxx>
22
23 //=======================================================================
24 //function : dumpOper
25 //purpose  : 
26 //=======================================================================
27 void BRepAlgoAPI::DumpOper(const Standard_CString theFilePath,
28                            const TopoDS_Shape& theShape1,
29                            const TopoDS_Shape& theShape2,
30                            const TopoDS_Shape& theResult,
31                            BOPAlgo_Operation theOperation,
32                            Standard_Boolean isNonValidArgs)
33 {
34   TCollection_AsciiString aPath(theFilePath);
35   aPath += "/";
36   Standard_Integer aNumOper = 1;
37   Standard_Boolean isExist = Standard_True;
38   TCollection_AsciiString aFileName;
39  
40   while(isExist)
41   {
42     aFileName = aPath + "BO_" + TCollection_AsciiString(aNumOper) +".tcl";
43     OSD_File aScript(aFileName);
44     isExist = aScript.Exists();
45     if(isExist)
46       aNumOper++;
47   }
48
49   FILE* afile = fopen(aFileName.ToCString(), "w+");
50   if(!afile)
51     return;
52   if(isNonValidArgs)
53     fprintf(afile,"%s\n","# Arguments are invalid");
54
55   TCollection_AsciiString aName1;
56   TCollection_AsciiString aName2;
57   TCollection_AsciiString aNameRes;
58   if(!theShape1.IsNull())
59   {
60     aName1 = aPath +
61       "Arg1_" + TCollection_AsciiString(aNumOper) + ".brep";
62     BRepTools::Write(theShape1, aName1.ToCString());
63   }
64   else
65     fprintf(afile,"%s\n","# First argument is Null ");
66    
67   if(!theShape2.IsNull())
68   {
69     aName2 =  aPath +
70       "Arg2_"+ TCollection_AsciiString(aNumOper) + ".brep";
71
72     BRepTools::Write(theShape2, aName2.ToCString());
73   }
74   else
75     fprintf(afile,"%s\n","# Second argument is Null ");
76    
77    if(!theResult.IsNull())
78   {
79     aNameRes =  aPath +
80       "Result_"+ TCollection_AsciiString(aNumOper) + ".brep";
81
82     BRepTools::Write(theResult, aNameRes.ToCString());
83   }
84   else
85     fprintf(afile,"%s\n","# Result is Null ");
86   
87   fprintf(afile, "%s %s %s\n","restore",  aName1.ToCString(), "arg1");
88   fprintf(afile, "%s %s %s\n","restore",  aName2.ToCString(), "arg2");;
89   TCollection_AsciiString aBopString;
90   switch (theOperation)
91   {
92     case BOPAlgo_COMMON : aBopString += "bcommon Res "; break;
93     case BOPAlgo_FUSE   : aBopString += "bfuse Res "; break;
94     case BOPAlgo_CUT    : 
95     case BOPAlgo_CUT21  : aBopString += "bcut Res "; break;
96     case BOPAlgo_SECTION : aBopString += "bsection Res "; break;
97     default : break;
98   };
99   aBopString += ("arg1 arg2");
100   if(theOperation == BOPAlgo_CUT21)
101     aBopString += " 1";
102
103   fprintf(afile, "%s\n",aBopString.ToCString());
104   fclose(afile);
105 }