1 // Created on: 2018/03/21
2 // Created by: Eugeny MALTCHIKOV
3 // Copyright (c) 2018 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BRepTest.hxx>
18 #include <BRep_Builder.hxx>
20 #include <BRepTest_DrawableHistory.hxx>
21 #include <BRepTest_Objects.hxx>
27 #include <TopoDS_Compound.hxx>
29 static Standard_Integer SetFillHistory(Draw_Interpretor&, Standard_Integer, const char**);
30 static Standard_Integer SaveHistory (Draw_Interpretor&, Standard_Integer, const char**);
31 static Standard_Integer Modified (Draw_Interpretor&, Standard_Integer, const char**);
32 static Standard_Integer Generated (Draw_Interpretor&, Standard_Integer, const char**);
33 static Standard_Integer IsDeleted (Draw_Interpretor&, Standard_Integer, const char**);
35 //=======================================================================
36 //function : HistoryCommands
38 //=======================================================================
39 void BRepTest::HistoryCommands(Draw_Interpretor& theCommands)
41 static Standard_Boolean isDone = Standard_False;
43 isDone = Standard_True;
45 const char* group = "History commands";
48 theCommands.Add("setfillhistory" , "Controls the history collection by the algorithms and its saving into the session after algorithm is done.\n"
49 "\t\tUsage: setfillhistory [flag]\n"
50 "\t\tw/o arguments prints the current state of the option;\n"
51 "\t\tflag == 0 - history will not be collected and saved;\n"
52 "\t\tflag != 0 - history will be collected and saved into the session (default).",
53 __FILE__, SetFillHistory , group);
55 theCommands.Add("savehistory" , "savehistory name\n"
56 "\t\tSaves the history from the session into a drawable object with the name <name>.",
57 __FILE__, SaveHistory , group);
59 theCommands.Add("modified" , "modified modified_shapes history shape\n"
60 "\t\tReturns the shapes Modified from the given shape in the given history",
61 __FILE__, Modified , group);
63 theCommands.Add("generated", "generated generated_shapes history shape\n"
64 "\t\tReturns the shapes Generated from the given shape in the given history",
65 __FILE__, Generated, group);
67 theCommands.Add("isdeleted", "isdeleted history shape\n"
68 "\t\tChecks if the given shape has been deleted in the given history",
69 __FILE__, IsDeleted, group);
72 //=======================================================================
73 //function : SetFillHistory
75 //=======================================================================
76 Standard_Integer SetFillHistory(Draw_Interpretor& theDI,
77 Standard_Integer theArgc,
82 theDI.PrintHelp(theArgv[0]);
88 theDI << "Filling of the history is " <<
89 (BRepTest_Objects::IsHistoryNeeded() ? "enabled." : "disabled.");
93 Standard_Integer iHist = Draw::Atoi(theArgv[1]);
94 BRepTest_Objects::SetToFillHistory(iHist != 0);
99 //=======================================================================
100 //function : SaveHistory
102 //=======================================================================
103 Standard_Integer SaveHistory(Draw_Interpretor& theDI,
104 Standard_Integer theArgc,
105 const char** theArgv)
109 theDI.PrintHelp(theArgv[0]);
113 // Get the history from the session
114 Handle(BRepTools_History) aHistory = BRepTest_Objects::History();
115 if (aHistory.IsNull())
117 theDI << "No history has been prepared yet.";
121 Handle(BRepTest_DrawableHistory) aDrawHist = new BRepTest_DrawableHistory(aHistory);
123 Draw::Set(theArgv[1], aDrawHist);
128 //=======================================================================
129 //function : GetHistory
131 //=======================================================================
132 static Handle(BRepTools_History) GetHistory(Draw_Interpretor& theDI,
133 Standard_CString theName)
135 Handle(BRepTest_DrawableHistory) aHistory =
136 Handle(BRepTest_DrawableHistory)::DownCast(Draw::Get(theName));
138 if (aHistory.IsNull() || aHistory->History().IsNull())
140 theDI << "History with the name " << theName << " does not exist.";
144 return aHistory->History();
147 //=======================================================================
148 //function : GetShape
150 //=======================================================================
151 static TopoDS_Shape GetShape(Draw_Interpretor& theDI,
152 Standard_CString theName)
154 TopoDS_Shape aS = DBRep::Get(theName);
158 theDI << theName << " is a null shape.";
159 return TopoDS_Shape();
162 if (!BRepTools_History::IsSupportedType(aS))
164 theDI << "History is not supported for this kind of shape.";
165 return TopoDS_Shape();
170 //=======================================================================
171 //function : MakeCompound
173 //=======================================================================
174 static TopoDS_Shape MakeCompound(const TopTools_ListOfShape& theLS)
177 if (theLS.Extent() == 1)
181 BRep_Builder().MakeCompound(TopoDS::Compound(aC));
182 TopTools_ListIteratorOfListOfShape it(theLS);
183 for (; it.More(); it.Next())
184 BRep_Builder().Add(aC, it.Value());
189 //=======================================================================
190 //function : Modified
192 //=======================================================================
193 Standard_Integer Modified(Draw_Interpretor& theDI,
194 Standard_Integer theArgc,
195 const char** theArgv)
199 theDI.PrintHelp(theArgv[0]);
203 Handle(BRepTools_History) aHistory = GetHistory(theDI, theArgv[2]);
204 if (aHistory.IsNull())
207 TopoDS_Shape aS = GetShape(theDI, theArgv[3]);
211 const TopTools_ListOfShape& aModified = aHistory->Modified(aS);
213 if (aModified.IsEmpty())
215 theDI << "The shape has not been modified.";
219 DBRep::Set(theArgv[1], MakeCompound(aModified));
224 //=======================================================================
225 //function : Generated
227 //=======================================================================
228 Standard_Integer Generated(Draw_Interpretor& theDI,
229 Standard_Integer theArgc,
230 const char** theArgv)
234 theDI.PrintHelp(theArgv[0]);
238 Handle(BRepTools_History) aHistory = GetHistory(theDI, theArgv[2]);
239 if (aHistory.IsNull())
242 TopoDS_Shape aS = GetShape(theDI, theArgv[3]);
246 const TopTools_ListOfShape& aGenerated = aHistory->Generated(aS);
248 if (aGenerated.IsEmpty())
250 theDI << "No shapes were generated from the shape.";
254 DBRep::Set(theArgv[1], MakeCompound(aGenerated));
259 //=======================================================================
260 //function : IsDeleted
262 //=======================================================================
263 Standard_Integer IsDeleted(Draw_Interpretor& theDI,
264 Standard_Integer theArgc,
265 const char** theArgv)
269 theDI.PrintHelp(theArgv[0]);
273 Handle(BRepTools_History) aHistory = GetHistory(theDI, theArgv[1]);
274 if (aHistory.IsNull())
277 TopoDS_Shape aS = GetShape(theDI, theArgv[2]);
281 theDI << (aHistory->IsRemoved(aS) ? "Deleted." : "Not deleted.");