0028599: Replacement of old Boolean operations with new ones in BRepProj_Projection...
[occt.git] / src / BRepTest / BRepTest_ProjectionCommands.cxx
1 // Created on: 1998-03-03
2 // Created by: Didier PIFFAULT
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <GeometryTest.hxx>
18 #include <DrawTrSurf.hxx>
19 #include <Draw_Appli.hxx>
20 #include <TopoDS_Shape.hxx>
21 #include <DBRep.hxx>
22 #include <Draw_Interpretor.hxx>
23 #include <BRepProj_Projection.hxx>
24 #include <TopExp_Explorer.hxx>
25 #include <BRepTest.hxx>
26 #include <TopoDS.hxx>
27 #include <stdio.h>
28
29 //=======================================================================
30 //function : prj
31 //purpose  : Draw command for Conical and Cylindrical projection
32 //=======================================================================
33 static Standard_Integer prj(Draw_Interpretor& di, Standard_Integer n, const char** a)
34 {
35   if (n != 7)
36   {
37     di.PrintHelp(a[0]);
38     return 1;
39   }
40   //
41   TopoDS_Shape anInputWire =  DBRep::Get(a[2]);
42   TopoDS_Shape anInputShape = DBRep::Get(a[3]);
43   if (anInputWire.IsNull() || anInputShape.IsNull())
44   {
45     di << "Null input shapes\n";
46     return 1;
47   }
48   //
49   Standard_Real X = Draw::Atof(a[4]),
50                 Y = Draw::Atof(a[5]),
51                 Z = Draw::Atof(a[6]);
52   //
53   Standard_Boolean bCylProj = !strcmp(a[0], "prj");
54   //
55   BRepProj_Projection aPrj = bCylProj ?
56     BRepProj_Projection(anInputWire, anInputShape, gp_Dir(X, Y, Z)) :
57     BRepProj_Projection(anInputWire, anInputShape, gp_Pnt(X, Y, Z));
58   //
59   if (!aPrj.IsDone())
60   {
61     di << "Not done\n";
62     return 0;
63   }
64   //
65   for (Standard_Integer i = 1; aPrj.More(); aPrj.Next(), ++i)
66   {
67     char name[255];
68     Sprintf(name, "%s_%d", a[1], i);
69     DBRep::Set(name, aPrj.Current());
70     di << name << " ";
71   }
72   //
73   di << "\n";
74   return 0;
75 }
76
77 /*********************************************************************************/
78
79 void BRepTest::ProjectionCommands(Draw_Interpretor& theCommands)
80 {
81   static Standard_Boolean loaded = Standard_False;
82   if (loaded) return;
83   loaded = Standard_True;
84
85   const char* g = "Projection of wire commands";
86
87   theCommands.Add("prj","prj result w s x y z: "
88     "Cylindrical projection of w (wire or edge) on s (faces) along direction.\n",
89     __FILE__, prj, g);
90   //
91   theCommands.Add("cprj","cprj result w s x y z: "
92     "Conical projection of w (wire or edge) on s (faces).\n",
93     __FILE__, prj, g);
94 }