0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BRepTest / BRepTest_HistoryCommands.cxx
CommitLineData
4f7d41ea 1// Created on: 2018/03/21
2// Created by: Eugeny MALTCHIKOV
3// Copyright (c) 2018 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 <BRepTest.hxx>
17
18#include <BRep_Builder.hxx>
19
20#include <BRepTest_DrawableHistory.hxx>
21#include <BRepTest_Objects.hxx>
22
23#include <Draw.hxx>
24#include <DBRep.hxx>
25
26#include <TopoDS.hxx>
4f7d41ea 27
948fe6ca 28static Standard_Integer SetFillHistory(Draw_Interpretor&, Standard_Integer, const char**);
29static Standard_Integer SaveHistory (Draw_Interpretor&, Standard_Integer, const char**);
30static Standard_Integer Modified (Draw_Interpretor&, Standard_Integer, const char**);
31static Standard_Integer Generated (Draw_Interpretor&, Standard_Integer, const char**);
32static Standard_Integer IsDeleted (Draw_Interpretor&, Standard_Integer, const char**);
4f7d41ea 33
34//=======================================================================
35//function : HistoryCommands
36//purpose :
37//=======================================================================
38void BRepTest::HistoryCommands(Draw_Interpretor& theCommands)
39{
40 static Standard_Boolean isDone = Standard_False;
41 if (isDone) return;
42 isDone = Standard_True;
43 // Chapter's name
44 const char* group = "History commands";
45
46 // Commands
948fe6ca 47 theCommands.Add("setfillhistory" , "Controls the history collection by the algorithms and its saving into the session after algorithm is done.\n"
48 "\t\tUsage: setfillhistory [flag]\n"
49 "\t\tw/o arguments prints the current state of the option;\n"
50 "\t\tflag == 0 - history will not be collected and saved;\n"
51 "\t\tflag != 0 - history will be collected and saved into the session (default).",
52 __FILE__, SetFillHistory , group);
53
4f7d41ea 54 theCommands.Add("savehistory" , "savehistory name\n"
55 "\t\tSaves the history from the session into a drawable object with the name <name>.",
56 __FILE__, SaveHistory , group);
57
58 theCommands.Add("modified" , "modified modified_shapes history shape\n"
59 "\t\tReturns the shapes Modified from the given shape in the given history",
60 __FILE__, Modified , group);
61
62 theCommands.Add("generated", "generated generated_shapes history shape\n"
63 "\t\tReturns the shapes Generated from the given shape in the given history",
64 __FILE__, Generated, group);
65
66 theCommands.Add("isdeleted", "isdeleted history shape\n"
67 "\t\tChecks if the given shape has been deleted in the given history",
68 __FILE__, IsDeleted, group);
69}
70
948fe6ca 71//=======================================================================
72//function : SetFillHistory
73//purpose :
74//=======================================================================
75Standard_Integer SetFillHistory(Draw_Interpretor& theDI,
76 Standard_Integer theArgc,
77 const char** theArgv)
78{
79 if (theArgc > 2)
80 {
81 theDI.PrintHelp(theArgv[0]);
82 return 1;
83 }
84
85 if (theArgc == 1)
86 {
87 theDI << "Filling of the history is " <<
88 (BRepTest_Objects::IsHistoryNeeded() ? "enabled." : "disabled.");
89 }
90 else
91 {
92 Standard_Integer iHist = Draw::Atoi(theArgv[1]);
93 BRepTest_Objects::SetToFillHistory(iHist != 0);
94 }
95 return 0;
96}
97
4f7d41ea 98//=======================================================================
99//function : SaveHistory
100//purpose :
101//=======================================================================
102Standard_Integer SaveHistory(Draw_Interpretor& theDI,
103 Standard_Integer theArgc,
104 const char** theArgv)
105{
106 if (theArgc != 2)
107 {
108 theDI.PrintHelp(theArgv[0]);
109 return 1;
110 }
111
112 // Get the history from the session
113 Handle(BRepTools_History) aHistory = BRepTest_Objects::History();
114 if (aHistory.IsNull())
115 {
116 theDI << "No history has been prepared yet.";
117 return 1;
118 }
119
120 Handle(BRepTest_DrawableHistory) aDrawHist = new BRepTest_DrawableHistory(aHistory);
121
122 Draw::Set(theArgv[1], aDrawHist);
123
124 return 0;
125}
126
127//=======================================================================
128//function : GetHistory
129//purpose :
130//=======================================================================
131static Handle(BRepTools_History) GetHistory(Draw_Interpretor& theDI,
132 Standard_CString theName)
133{
134 Handle(BRepTest_DrawableHistory) aHistory =
135 Handle(BRepTest_DrawableHistory)::DownCast(Draw::Get(theName));
136
137 if (aHistory.IsNull() || aHistory->History().IsNull())
138 {
139 theDI << "History with the name " << theName << " does not exist.";
140 return NULL;
141 }
142
143 return aHistory->History();
144}
145
146//=======================================================================
147//function : GetShape
148//purpose :
149//=======================================================================
150static TopoDS_Shape GetShape(Draw_Interpretor& theDI,
151 Standard_CString theName)
152{
153 TopoDS_Shape aS = DBRep::Get(theName);
154
155 if (aS.IsNull())
156 {
157 theDI << theName << " is a null shape.";
158 return TopoDS_Shape();
159 }
160
161 if (!BRepTools_History::IsSupportedType(aS))
162 {
163 theDI << "History is not supported for this kind of shape.";
164 return TopoDS_Shape();
165 }
166 return aS;
167}
168
169//=======================================================================
170//function : MakeCompound
171//purpose :
172//=======================================================================
173static TopoDS_Shape MakeCompound(const TopTools_ListOfShape& theLS)
174{
175 TopoDS_Shape aC;
176 if (theLS.Extent() == 1)
177 aC = theLS.First();
178 else
179 {
180 BRep_Builder().MakeCompound(TopoDS::Compound(aC));
181 TopTools_ListIteratorOfListOfShape it(theLS);
182 for (; it.More(); it.Next())
183 BRep_Builder().Add(aC, it.Value());
184 }
185 return aC;
186}
187
188//=======================================================================
189//function : Modified
190//purpose :
191//=======================================================================
192Standard_Integer Modified(Draw_Interpretor& theDI,
193 Standard_Integer theArgc,
194 const char** theArgv)
195{
196 if (theArgc != 4)
197 {
198 theDI.PrintHelp(theArgv[0]);
199 return 1;
200 }
201
202 Handle(BRepTools_History) aHistory = GetHistory(theDI, theArgv[2]);
203 if (aHistory.IsNull())
204 return 1;
205
206 TopoDS_Shape aS = GetShape(theDI, theArgv[3]);
207 if (aS.IsNull())
208 return 1;
209
210 const TopTools_ListOfShape& aModified = aHistory->Modified(aS);
211
212 if (aModified.IsEmpty())
213 {
214 theDI << "The shape has not been modified.";
215 return 0;
216 }
217
218 DBRep::Set(theArgv[1], MakeCompound(aModified));
219
220 return 0;
221}
222
223//=======================================================================
224//function : Generated
225//purpose :
226//=======================================================================
227Standard_Integer Generated(Draw_Interpretor& theDI,
228 Standard_Integer theArgc,
229 const char** theArgv)
230{
231 if (theArgc != 4)
232 {
233 theDI.PrintHelp(theArgv[0]);
234 return 1;
235 }
236
237 Handle(BRepTools_History) aHistory = GetHistory(theDI, theArgv[2]);
238 if (aHistory.IsNull())
239 return 1;
240
241 TopoDS_Shape aS = GetShape(theDI, theArgv[3]);
242 if (aS.IsNull())
243 return 1;
244
245 const TopTools_ListOfShape& aGenerated = aHistory->Generated(aS);
246
247 if (aGenerated.IsEmpty())
248 {
249 theDI << "No shapes were generated from the shape.";
250 return 0;
251 }
252
253 DBRep::Set(theArgv[1], MakeCompound(aGenerated));
254
255 return 0;
256}
257
258//=======================================================================
259//function : IsDeleted
260//purpose :
261//=======================================================================
262Standard_Integer IsDeleted(Draw_Interpretor& theDI,
263 Standard_Integer theArgc,
264 const char** theArgv)
265{
266 if (theArgc != 3)
267 {
268 theDI.PrintHelp(theArgv[0]);
269 return 1;
270 }
271
272 Handle(BRepTools_History) aHistory = GetHistory(theDI, theArgv[1]);
273 if (aHistory.IsNull())
274 return 1;
275
276 TopoDS_Shape aS = GetShape(theDI, theArgv[2]);
277 if (aS.IsNull())
278 return 1;
279
280 theDI << (aHistory->IsRemoved(aS) ? "Deleted." : "Not deleted.");
281
282 return 0;
283}