0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / BOPTest / BOPTest_RemoveFeaturesCommands.cxx
1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2018 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <BOPTest.hxx>
16
17 #include <BOPTest_DrawableShape.hxx>
18 #include <BOPTest_Objects.hxx>
19
20 #include <BRep_Builder.hxx>
21
22 #include <BRepAlgoAPI_Defeaturing.hxx>
23
24 #include <BRepTest_Objects.hxx>
25
26 #include <DBRep.hxx>
27 #include <Draw.hxx>
28
29 #include <TopoDS.hxx>
30 #include <TopoDS_Compound.hxx>
31
32 static Standard_Integer RemoveFeatures (Draw_Interpretor&, Standard_Integer, const char**);
33
34 //=======================================================================
35 //function : RemoveFeaturesCommands
36 //purpose  : 
37 //=======================================================================
38 void BOPTest::RemoveFeaturesCommands(Draw_Interpretor& theCommands)
39 {
40   static Standard_Boolean done = Standard_False;
41   if (done) return;
42   done = Standard_True;
43   // Chapter's name
44   const char* group = "BOPTest commands";
45   // Commands
46   theCommands.Add("removefeatures", "removefeatures result shape f1 f2 ... [-parallel]\n"
47                   "\t\tRemoves user-defined features (faces) from the shape.\n"
48                   "\t\tresult   - result of the operation;\n"
49                   "\t\tshape    - the shape to remove the features from;\n"
50                   "\t\tf1, f2   - features to remove from the shape;\n"
51                   "\t\tparallel - enables the parallel processing mode.",
52                   __FILE__, RemoveFeatures, group);
53 }
54
55 //=======================================================================
56 //function : RemoveFeatures
57 //purpose  : 
58 //=======================================================================
59 Standard_Integer RemoveFeatures(Draw_Interpretor& theDI,
60                                 Standard_Integer  theArgc,
61                                 const char ** theArgv)
62 {
63   if (theArgc < 4)
64   {
65     theDI.PrintHelp(theArgv[0]);
66     return 1;
67   }
68
69   // Get the shape to remove the features from
70   TopoDS_Shape aShape = DBRep::Get(theArgv[2]);
71   if (aShape.IsNull())
72   {
73     theDI << "Error: " << theArgv[2] << " is a null shape.\n";
74     return 1;
75   }
76
77   BRepAlgoAPI_Defeaturing aRF;
78   aRF.SetShape(aShape);
79
80   // Add faces to remove
81   for (Standard_Integer i = 3; i < theArgc; ++i)
82   {
83     TopoDS_Shape aF = DBRep::Get(theArgv[i]);
84     if (aF.IsNull())
85     {
86       if (!strcmp(theArgv[i], "-parallel"))
87       {
88         // enable the parallel processing mode
89         aRF.SetRunParallel(Standard_True);
90       }
91       else
92         theDI << "Warning: " << theArgv[i] << " is a null shape. Skip it.\n";
93
94       continue;
95     }
96
97     aRF.AddFaceToRemove(aF);
98   }
99
100   aRF.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
101
102   // Perform the removal
103   aRF.Build();
104
105   // Check for the errors/warnings
106   BOPTest::ReportAlerts(aRF.GetReport());
107
108   if (BRepTest_Objects::IsHistoryNeeded())
109     BRepTest_Objects::SetHistory(aRF.History());
110
111   if (aRF.HasErrors())
112     return 0;
113
114   const TopoDS_Shape& aResult = aRF.Shape();
115   DBRep::Set(theArgv[1], aResult);
116
117   return 0;
118 }