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 SaveHistory(Draw_Interpretor&, Standard_Integer, const char**);
30 static Standard_Integer Modified (Draw_Interpretor&, Standard_Integer, const char**);
31 static Standard_Integer Generated (Draw_Interpretor&, Standard_Integer, const char**);
32 static Standard_Integer IsDeleted (Draw_Interpretor&, Standard_Integer, const char**);
34 //=======================================================================
35 //function : HistoryCommands
37 //=======================================================================
38 void BRepTest::HistoryCommands(Draw_Interpretor& theCommands)
40 static Standard_Boolean isDone = Standard_False;
42 isDone = Standard_True;
44 const char* group = "History commands";
47 theCommands.Add("savehistory" , "savehistory name\n"
48 "\t\tSaves the history from the session into a drawable object with the name <name>.",
49 __FILE__, SaveHistory , group);
51 theCommands.Add("modified" , "modified modified_shapes history shape\n"
52 "\t\tReturns the shapes Modified from the given shape in the given history",
53 __FILE__, Modified , group);
55 theCommands.Add("generated", "generated generated_shapes history shape\n"
56 "\t\tReturns the shapes Generated from the given shape in the given history",
57 __FILE__, Generated, group);
59 theCommands.Add("isdeleted", "isdeleted history shape\n"
60 "\t\tChecks if the given shape has been deleted in the given history",
61 __FILE__, IsDeleted, group);
64 //=======================================================================
65 //function : SaveHistory
67 //=======================================================================
68 Standard_Integer SaveHistory(Draw_Interpretor& theDI,
69 Standard_Integer theArgc,
74 theDI.PrintHelp(theArgv[0]);
78 // Get the history from the session
79 Handle(BRepTools_History) aHistory = BRepTest_Objects::History();
80 if (aHistory.IsNull())
82 theDI << "No history has been prepared yet.";
86 Handle(BRepTest_DrawableHistory) aDrawHist = new BRepTest_DrawableHistory(aHistory);
88 Draw::Set(theArgv[1], aDrawHist);
93 //=======================================================================
94 //function : GetHistory
96 //=======================================================================
97 static Handle(BRepTools_History) GetHistory(Draw_Interpretor& theDI,
98 Standard_CString theName)
100 Handle(BRepTest_DrawableHistory) aHistory =
101 Handle(BRepTest_DrawableHistory)::DownCast(Draw::Get(theName));
103 if (aHistory.IsNull() || aHistory->History().IsNull())
105 theDI << "History with the name " << theName << " does not exist.";
109 return aHistory->History();
112 //=======================================================================
113 //function : GetShape
115 //=======================================================================
116 static TopoDS_Shape GetShape(Draw_Interpretor& theDI,
117 Standard_CString theName)
119 TopoDS_Shape aS = DBRep::Get(theName);
123 theDI << theName << " is a null shape.";
124 return TopoDS_Shape();
127 if (!BRepTools_History::IsSupportedType(aS))
129 theDI << "History is not supported for this kind of shape.";
130 return TopoDS_Shape();
135 //=======================================================================
136 //function : MakeCompound
138 //=======================================================================
139 static TopoDS_Shape MakeCompound(const TopTools_ListOfShape& theLS)
142 if (theLS.Extent() == 1)
146 BRep_Builder().MakeCompound(TopoDS::Compound(aC));
147 TopTools_ListIteratorOfListOfShape it(theLS);
148 for (; it.More(); it.Next())
149 BRep_Builder().Add(aC, it.Value());
154 //=======================================================================
155 //function : Modified
157 //=======================================================================
158 Standard_Integer Modified(Draw_Interpretor& theDI,
159 Standard_Integer theArgc,
160 const char** theArgv)
164 theDI.PrintHelp(theArgv[0]);
168 Handle(BRepTools_History) aHistory = GetHistory(theDI, theArgv[2]);
169 if (aHistory.IsNull())
172 TopoDS_Shape aS = GetShape(theDI, theArgv[3]);
176 const TopTools_ListOfShape& aModified = aHistory->Modified(aS);
178 if (aModified.IsEmpty())
180 theDI << "The shape has not been modified.";
184 DBRep::Set(theArgv[1], MakeCompound(aModified));
189 //=======================================================================
190 //function : Generated
192 //=======================================================================
193 Standard_Integer Generated(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& aGenerated = aHistory->Generated(aS);
213 if (aGenerated.IsEmpty())
215 theDI << "No shapes were generated from the shape.";
219 DBRep::Set(theArgv[1], MakeCompound(aGenerated));
224 //=======================================================================
225 //function : IsDeleted
227 //=======================================================================
228 Standard_Integer IsDeleted(Draw_Interpretor& theDI,
229 Standard_Integer theArgc,
230 const char** theArgv)
234 theDI.PrintHelp(theArgv[0]);
238 Handle(BRepTools_History) aHistory = GetHistory(theDI, theArgv[1]);
239 if (aHistory.IsNull())
242 TopoDS_Shape aS = GetShape(theDI, theArgv[2]);
246 theDI << (aHistory->IsRemoved(aS) ? "Deleted." : "Not deleted.");