b311480e |
1 | // Created on: 1996-02-23 |
2 | // Created by: Jacques GOUSSARD |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | #include <BRepTest.hxx> |
7fd59977 |
18 | #include <BRepAlgo.hxx> |
19 | #include <BRepCheck_Analyzer.hxx> |
20 | #include <BRepCheck_Result.hxx> |
21 | #include <BRepCheck_ListIteratorOfListOfStatus.hxx> |
22 | #include <TopoDS_Iterator.hxx> |
23 | #include <TopExp_Explorer.hxx> |
24 | #include <TopTools_DataMapOfShapeListOfShape.hxx> |
25 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> |
26 | #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx> |
27 | #include <TopTools_ListOfShape.hxx> |
28 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
29 | #include <DBRep_DrawableShape.hxx> |
30 | #include <Draw_SequenceOfDrawable3D.hxx> |
31 | #include <BRepCheck.hxx> |
32 | #include <BRepCheck_Edge.hxx> |
33 | #include <Draw_Interpretor.hxx> |
34 | #include <Draw_Appli.hxx> |
35 | #include <Draw.hxx> |
36 | #include <DBRep.hxx> |
37 | #include <BRepTest.hxx> |
38 | #include <GeometryTest.hxx> |
39 | #include <Precision.hxx> |
40 | #include <LocalAnalysis.hxx> |
41 | #include <LocalAnalysis_SurfaceContinuity.hxx> |
c0a1a35f |
42 | #include <Geom_SphericalSurface.hxx> |
7fd59977 |
43 | #include <Geom_Surface.hxx> |
44 | #include <Geom_Curve.hxx> |
45 | #include <Geom2d_TrimmedCurve.hxx> |
46 | #include <Geom2d_Curve.hxx> |
47 | #include <DrawTrSurf.hxx> |
48 | #include <GeomAbs_Shape.hxx> |
c0a1a35f |
49 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
50 | #include <TopoDS.hxx> |
51 | #include <TopExp.hxx> |
52 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
53 | #include <TopTools_MapOfShape.hxx> |
54 | #include <TopTools_MapIteratorOfMapOfShape.hxx> |
55 | #include <TopoDS_Shape.hxx> |
56 | #include <TopoDS_Edge.hxx> |
57 | #include <TopoDS_Face.hxx> |
58 | #include <BRep_Tool.hxx> |
59 | |
60 | #include <TopOpeBRepTool_PurgeInternalEdges.hxx> |
61 | //#include <TopOpeBRepTool_FuseEdges.hxx> |
c0a1a35f |
62 | #include <BRepLib.hxx> |
7fd59977 |
63 | #include <BRepLib_FuseEdges.hxx> |
64 | |
65 | #include <TopTools_HSequenceOfShape.hxx> |
66 | #include <BRep_Builder.hxx> |
67 | #include <TopoDS_Compound.hxx> |
68 | #include <TColStd_HArray1OfInteger.hxx> |
69 | |
70 | #include <Standard_ErrorHandler.hxx> |
71 | #include <Standard_Failure.hxx> |
72 | |
7fd59977 |
73 | #include <stdio.h> |
7fd59977 |
74 | |
52d45841 |
75 | //Number of BRepCheck_Statuses in BRepCheck_Status.hxx file |
76 | //(BRepCheck_NoError is not considered, i.e. general status |
77 | //is smaller by one specified in file) |
949df2b6 |
78 | static const Standard_Integer NumberOfStatus = 36; |
52d45841 |
79 | |
7fd59977 |
80 | static char* checkfaultyname = NULL; |
81 | Standard_EXPORT void BRepTest_CheckCommands_SetFaultyName(const char* name) |
82 | { |
83 | if (checkfaultyname != NULL) { |
84 | free(checkfaultyname); |
85 | checkfaultyname = NULL; |
86 | } |
87 | if (name == NULL) { |
88 | checkfaultyname = (char*)malloc(strlen("faulty_")+1); |
89 | strcpy(checkfaultyname,"faulty_"); |
90 | } |
91 | else { |
92 | checkfaultyname = (char*)malloc(strlen(name)+1); |
93 | strcpy(checkfaultyname,name); |
94 | } |
95 | } |
96 | |
97 | |
98 | static TopTools_DataMapOfShapeListOfShape theMap; |
99 | static Standard_Integer nbfaulty = 0; |
100 | static Draw_SequenceOfDrawable3D lfaulty; |
101 | |
102 | Standard_IMPORT Standard_Integer BRepCheck_Trace(const Standard_Integer phase); |
103 | |
104 | //======================================================================= |
105 | //function : FindNamed |
106 | //======================================================================= |
107 | static Standard_Boolean FindNamed(const TopoDS_Shape& S, |
108 | char*& Name) |
109 | { |
110 | for (Standard_Integer i = 1 ;i <= lfaulty.Length(); i++) { |
111 | Handle(DBRep_DrawableShape) DS = |
112 | Handle(DBRep_DrawableShape)::DownCast(lfaulty(i)); |
113 | if (DS->Shape().IsSame(S)) { |
114 | Name = (char*)DS->Name(); |
115 | return Standard_True; |
116 | } |
117 | } |
118 | return Standard_False; |
119 | } |
120 | |
121 | |
122 | //======================================================================= |
123 | //function : Contains |
124 | //======================================================================= |
125 | static Standard_Boolean Contains(const TopTools_ListOfShape& L, |
126 | const TopoDS_Shape& S) |
127 | { |
128 | TopTools_ListIteratorOfListOfShape it; |
129 | for (it.Initialize(L); it.More(); it.Next()) { |
130 | if (it.Value().IsSame(S)) { |
131 | return Standard_True; |
132 | } |
133 | } |
134 | return Standard_False; |
135 | } |
136 | |
137 | |
138 | |
139 | //======================================================================= |
140 | //function : PrintSub |
141 | //======================================================================= |
142 | static void PrintSub(Standard_OStream& OS, |
143 | const BRepCheck_Analyzer& Ana, |
144 | const TopoDS_Shape& S, |
145 | const TopAbs_ShapeEnum Subtype) |
146 | |
147 | { |
148 | char* Name; |
149 | BRepCheck_ListIteratorOfListOfStatus itl; |
150 | TopExp_Explorer exp; |
151 | for (exp.Init(S,Subtype); exp.More(); exp.Next()) { |
152 | const Handle(BRepCheck_Result)& res = Ana.Result(exp.Current()); |
153 | const TopoDS_Shape& sub = exp.Current(); |
154 | for (res->InitContextIterator(); |
155 | res->MoreShapeInContext(); |
156 | res->NextShapeInContext()) { |
157 | if (res->ContextualShape().IsSame(S) && |
158 | !Contains(theMap(sub),S)) { |
159 | theMap(sub).Append(S); |
160 | itl.Initialize(res->StatusOnShape()); |
161 | if (itl.Value() != BRepCheck_NoError) { |
162 | if (!FindNamed(sub,Name)) { |
163 | nbfaulty++; |
164 | Name = (char*)malloc(18*sizeof(char)); |
91322f44 |
165 | Sprintf(Name,"%s%d",checkfaultyname,nbfaulty); |
7fd59977 |
166 | DBRep::Set(Name,sub); |
167 | lfaulty.Append(Draw::Get((Standard_CString&)Name)); |
168 | } |
169 | OS << "Shape " << Name << " "; |
170 | if (!FindNamed(S,Name)) { |
171 | nbfaulty++; |
172 | Name = (char*)malloc(18*sizeof(char)); |
91322f44 |
173 | Sprintf(Name,"%s%d",checkfaultyname,nbfaulty); |
7fd59977 |
174 | DBRep::Set(Name,S); |
175 | lfaulty.Append(Draw::Get((Standard_CString&)Name)); |
176 | } |
177 | OS << " on shape " << Name << " :\n"; |
178 | for (;itl.More(); itl.Next()) { |
179 | BRepCheck::Print(itl.Value(),OS); |
180 | } |
181 | } |
182 | break; |
183 | } |
184 | } |
185 | } |
186 | } |
187 | |
188 | |
189 | //======================================================================= |
190 | //function : Print |
191 | //======================================================================= |
192 | static void Print(Standard_OStream& OS, |
193 | const BRepCheck_Analyzer& Ana, |
194 | const TopoDS_Shape& S) |
195 | { |
196 | for (TopoDS_Iterator iter(S); iter.More(); iter.Next()) { |
197 | Print(OS,Ana,iter.Value()); |
198 | } |
199 | |
200 | char* Name; |
201 | TopAbs_ShapeEnum styp = S.ShapeType(); |
202 | BRepCheck_ListIteratorOfListOfStatus itl; |
203 | if (!Ana.Result(S).IsNull() && !theMap.IsBound(S)) { |
204 | itl.Initialize(Ana.Result(S)->Status()); |
205 | if (itl.Value() != BRepCheck_NoError) { |
206 | if (!FindNamed(S,Name)) { |
207 | nbfaulty++; |
208 | Name = (char*)malloc(18*sizeof(char)); |
91322f44 |
209 | Sprintf(Name,"%s%d",checkfaultyname,nbfaulty); |
7fd59977 |
210 | DBRep::Set(Name,S); |
211 | lfaulty.Append(Draw::Get((Standard_CString&)Name)); |
212 | } |
213 | OS << "On Shape " << Name << " :\n"; |
214 | |
215 | for (;itl.More(); itl.Next()) { |
52d45841 |
216 | if (itl.Value() != BRepCheck_NoError) |
7fd59977 |
217 | BRepCheck::Print(itl.Value(),OS); |
218 | } |
219 | } |
220 | } |
221 | if (!theMap.IsBound(S)) { |
222 | TopTools_ListOfShape thelist; |
223 | theMap.Bind(S, thelist); |
224 | } |
225 | |
226 | switch (styp) { |
227 | case TopAbs_EDGE: |
228 | PrintSub(OS,Ana,S,TopAbs_VERTEX); |
229 | break; |
52d45841 |
230 | case TopAbs_WIRE: |
231 | PrintSub(OS,Ana,S,TopAbs_EDGE); |
232 | PrintSub(OS,Ana,S,TopAbs_VERTEX); |
233 | break; |
7fd59977 |
234 | case TopAbs_FACE: |
235 | PrintSub(OS,Ana,S,TopAbs_WIRE); |
236 | PrintSub(OS,Ana,S,TopAbs_EDGE); |
237 | PrintSub(OS,Ana,S,TopAbs_VERTEX); |
238 | break; |
239 | case TopAbs_SHELL: |
240 | // PrintSub(OS,Ana,S,TopAbs_FACE); |
241 | break; |
242 | case TopAbs_SOLID: |
243 | // PrintSub(OS,Ana,S,TopAbs_EDGE); |
244 | PrintSub(OS,Ana,S,TopAbs_SHELL); |
245 | break; |
246 | default: |
247 | break; |
248 | } |
249 | |
250 | } |
251 | |
252 | //======================================================================= |
253 | //function : computetolerance |
254 | //purpose : |
255 | //======================================================================= |
256 | static Standard_Integer computetolerance(Draw_Interpretor& di, |
257 | Standard_Integer narg, const char** a) |
258 | { |
259 | if (narg < 2) { |
260 | //cout << "Usage: computetolerance shape" << endl; |
586db386 |
261 | di << "Usage: computetolerance shape\n"; |
7fd59977 |
262 | return 1; |
263 | } |
264 | TopoDS_Shape S = DBRep::Get(a[1]); |
265 | Standard_Real tol; |
266 | if (S.ShapeType() == TopAbs_EDGE) { |
267 | BRepCheck_Edge bce(TopoDS::Edge(S)); |
268 | tol=bce.Tolerance(); |
269 | //cout<< "Tolerance de " << (void*) &(*S.TShape()) << " : " << tol << endl; |
270 | Standard_SStream aSStream1; |
271 | aSStream1<< "Tolerance de " << (void*) &(*S.TShape()) << " : " << tol << "\n"; |
272 | di << aSStream1; |
273 | } |
274 | else { |
275 | TopTools_MapOfShape theEdges; |
276 | TopExp_Explorer exp; |
277 | for (exp.Init(S, TopAbs_EDGE); exp.More(); exp.Next()) { |
278 | if (theEdges.Add(exp.Current())) { |
279 | BRepCheck_Edge bce(TopoDS::Edge(exp.Current())); |
280 | tol=bce.Tolerance(); |
281 | //cout<< "Tolerance de " << (void*) &(*exp.Current().TShape()) << " : " << tol << "\n"; |
282 | Standard_SStream aSStream2; |
283 | aSStream2<< "Tolerance de " << (void*) &(*exp.Current().TShape()) << " : " << tol << "\n"; |
284 | di << aSStream2; |
285 | } |
286 | } |
287 | //cout << endl; |
288 | di << "\n"; |
289 | } |
290 | return 0; |
291 | } |
292 | |
293 | //======================================================================= |
294 | //function : checksection |
295 | //purpose : Checks the closure of a section line |
296 | //======================================================================= |
297 | static Standard_Integer checksection(Draw_Interpretor& di, |
298 | Standard_Integer narg, const char** a) |
299 | { |
300 | if (narg < 2) { |
3306fdd9 |
301 | di << a[0] << " shape [-r <ref_val>]\n"; |
7fd59977 |
302 | return 1; |
303 | } |
3306fdd9 |
304 | |
305 | Standard_Integer aCompareValue = -1; |
7fd59977 |
306 | TopoDS_Shape S = DBRep::Get(a[1]); |
3306fdd9 |
307 | |
308 | for (Standard_Integer anAI = 2; anAI < narg; anAI++) |
309 | { |
310 | if (!strcmp(a[anAI], "-r")) |
311 | { |
312 | aCompareValue = Draw::Atoi(a[++anAI]); |
313 | } |
314 | else |
315 | { |
316 | di << "Error: Wrong option" << a[anAI] << "\n"; |
317 | } |
318 | } |
319 | |
7fd59977 |
320 | TopTools_MapOfShape theVertices; |
321 | TopExp_Explorer exp; |
322 | for (exp.Init(S, TopAbs_VERTEX); exp.More(); exp.Next()) { |
323 | if (!theVertices.Add(exp.Current())) |
324 | theVertices.Remove(exp.Current()); |
325 | } |
326 | //cout << " nb alone Vertices : " << theVertices.Extent() << endl; |
327 | di << " nb alone Vertices : " << theVertices.Extent() << "\n"; |
3306fdd9 |
328 | |
329 | if (aCompareValue >= 0) |
330 | { |
331 | if (theVertices.Extent() == aCompareValue) |
332 | { |
333 | di << "Section is OK\n"; |
334 | } |
335 | else |
336 | { |
337 | di << "Error: "<< aCompareValue << " vertices are expected but " << |
338 | theVertices.Extent() << " are found.\n"; |
339 | } |
340 | } |
341 | |
7fd59977 |
342 | char Name[32]; |
343 | Standard_Integer ipp=0; |
344 | TopTools_MapIteratorOfMapOfShape itvx; |
345 | for (itvx.Initialize(theVertices); itvx.More(); itvx.Next()) { |
346 | ipp++; |
91322f44 |
347 | Sprintf(Name,"alone_%d",ipp); |
7fd59977 |
348 | DBRep::Set(Name, itvx.Key()); |
349 | //cout << Name << " " ; |
350 | di << Name << " " ; |
351 | } |
352 | //cout << endl; |
353 | di << "\n"; |
354 | return 0; |
355 | } |
356 | //======================================================================= |
357 | |
358 | //======================================================================= |
359 | //function : checkdiff |
360 | //purpose : Checks the differences beetween a result and his arguments |
361 | //======================================================================= |
362 | static Standard_Integer checkdiff(Draw_Interpretor& di, |
363 | Standard_Integer narg, const char** a) |
364 | { |
365 | const char* syntaxe = "checkdiff arg1 [arg2..argn] result [closedSolid (0/1)] [geomCtrl (1/0)]"; |
366 | if (narg < 3) { |
367 | if (narg==2) { |
91322f44 |
368 | Standard_Integer bcrtrace=Draw::Atoi(a[narg-1]); |
7fd59977 |
369 | bcrtrace=BRepCheck_Trace(bcrtrace); |
370 | //cout << "BRepCheck_Trace : " << bcrtrace << endl; |
371 | di << "BRepCheck_Trace : " << bcrtrace << "\n"; |
372 | //cout << syntaxe << endl; |
373 | di << syntaxe << "\n"; |
374 | return 0; |
375 | } |
376 | //cout << syntaxe << endl; |
377 | di << syntaxe << "\n"; |
378 | return 1; |
379 | } |
380 | |
381 | Standard_Integer lastArg=narg-2; |
382 | Standard_Boolean closedSolid = Standard_False; |
383 | Standard_Boolean geomCtrl = Standard_True; |
384 | TopoDS_Shape resu = DBRep::Get(a[narg-1]); |
385 | if (resu.IsNull()) { |
386 | if (narg < 4) { |
387 | //cout << syntaxe << endl; |
388 | di << syntaxe << "\n"; |
389 | return 1; |
390 | } |
dde68833 |
391 | closedSolid = Draw::Atoi(a[narg-1]) != 0; |
7fd59977 |
392 | resu = DBRep::Get(a[narg-2]); |
393 | lastArg=narg-3; |
394 | if (resu.IsNull()) { |
395 | if (narg < 5) { |
396 | //cout << syntaxe << endl; |
397 | di << syntaxe << "\n"; |
398 | return 1; |
399 | } |
400 | geomCtrl=closedSolid; |
dde68833 |
401 | closedSolid = Draw::Atoi(a[narg-2]) != 0; |
7fd59977 |
402 | resu = DBRep::Get(a[narg-3]); |
403 | lastArg=narg-4; |
404 | if (resu.IsNull()) { |
405 | //cout << syntaxe << endl; |
406 | di << syntaxe << "\n"; |
407 | return 1; |
408 | } |
409 | } |
410 | } |
411 | |
412 | TopTools_ListOfShape lesArgs; |
413 | for (Standard_Integer id=1; id <=lastArg; id++) { |
414 | lesArgs.Append(DBRep::Get(a[id])); |
415 | } |
416 | |
417 | if (BRepAlgo::IsValid(lesArgs, resu, closedSolid, geomCtrl)) { |
418 | //cout << "Difference is Valid." << endl; |
586db386 |
419 | di << "Difference is Valid.\n"; |
7fd59977 |
420 | } else { |
421 | //cout << "error : Difference is Not Valid !" << endl; |
586db386 |
422 | di << "error : Difference is Not Valid !\n"; |
7fd59977 |
423 | } |
424 | |
425 | return 0; |
426 | } |
427 | //======================================================================= |
428 | |
429 | // Modified by skv - Tue Apr 27 13:38:44 2004 Begin |
430 | //======================================================================= |
431 | //function : CHK |
432 | //purpose : Checks a shape |
433 | //======================================================================= |
434 | |
435 | // static Standard_Integer CHK(Draw_Interpretor& theCommands, |
436 | // Standard_Integer narg, const char** a) |
437 | // { |
438 | // if (narg < 2) { |
439 | // return 1; |
440 | // } |
441 | |
442 | // Standard_Boolean doprint = Standard_True; |
443 | // if (narg == 3) { if (!strcmp(a[2],"-short")) doprint = Standard_False; } |
444 | |
445 | // TopoDS_Shape S = DBRep::Get(a[1]); |
446 | // if (S.IsNull()) { |
447 | // cout<<"not a topological shape"<<endl; |
448 | // return 1; |
449 | // } |
450 | |
451 | // Standard_Boolean GeomCtrl = Standard_True; |
452 | // if (!strcasecmp(a[0],"CHECKTOPSHAPE")) { |
453 | // GeomCtrl = Standard_False; |
454 | // } |
455 | |
456 | // BRepCheck_Analyzer ana(S,GeomCtrl); |
457 | // if (ana.IsValid()) { |
458 | // theCommands<<"This shape seems to be valid"; |
459 | // } |
460 | // else { |
461 | // theMap.Clear(); |
462 | // nbfaulty = 0; |
463 | // lfaulty.Clear(); |
464 | // theMap.Clear(); |
465 | // if (doprint) { |
466 | // Print(cout,ana,S); |
467 | // cout<<"\n"; |
468 | // theMap.Clear(); |
469 | // if (nbfaulty !=0) |
470 | // cout<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n"; |
471 | // cout<<endl; |
472 | // } |
473 | // else { |
474 | // theCommands<<"This shape has faulty shapes"; |
475 | // } |
476 | // } |
477 | // return 0; |
478 | // } |
479 | |
480 | //======================================================================= |
481 | //function : ContextualDump |
482 | //purpose : Contextual (modeling) style of output. |
483 | //======================================================================= |
484 | |
485 | //void ContextualDump(const BRepCheck_Analyzer &theAna, |
486 | // const TopoDS_Shape &theShape) |
487 | void ContextualDump(Draw_Interpretor& theCommands, |
488 | const BRepCheck_Analyzer &theAna, |
489 | const TopoDS_Shape &theShape) |
490 | { |
491 | theMap.Clear(); |
492 | nbfaulty = 0; |
493 | lfaulty.Clear(); |
494 | |
495 | //Print(cout, theAna, theShape); |
496 | Standard_SStream aSStream; |
497 | Print(aSStream, theAna, theShape); |
498 | theCommands << aSStream; |
499 | //cout<<"\n"; |
500 | theCommands<<"\n"; |
501 | theMap.Clear(); |
502 | |
503 | if (nbfaulty !=0) |
504 | theCommands<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n"; |
505 | //cout<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n"; |
506 | |
507 | //cout<<endl; |
508 | theCommands<<"\n"; |
509 | } |
510 | |
511 | |
512 | //======================================================================= |
513 | //function : FillProblems |
514 | // purpose : auxilary for StructuralDump |
515 | //======================================================================= |
516 | static void FillProblems(const BRepCheck_Status stat, |
517 | Handle(TColStd_HArray1OfInteger)& NbProblems) |
518 | { |
52d45841 |
519 | |
520 | const Standard_Integer anID = static_cast<Standard_Integer> (stat); |
521 | |
522 | if((NbProblems->Upper() < anID) || (NbProblems->Lower() > anID)) |
523 | return; |
524 | |
525 | NbProblems->SetValue(anID, NbProblems->Value(anID)+1); |
526 | |
7fd59977 |
527 | } |
528 | |
529 | |
530 | //======================================================================= |
531 | //function : GetProblemSub |
532 | // purpose : auxilary for StructuralDump |
533 | //======================================================================= |
534 | static void GetProblemSub(const BRepCheck_Analyzer& Ana, |
535 | const TopoDS_Shape& Shape, |
536 | Handle(TopTools_HSequenceOfShape)& sl, |
537 | Handle(TColStd_HArray1OfInteger)& NbProblems, |
538 | const TopAbs_ShapeEnum Subtype) |
539 | { |
540 | BRepCheck_ListIteratorOfListOfStatus itl; |
541 | TopExp_Explorer exp; |
542 | for (exp.Init(Shape,Subtype); exp.More(); exp.Next()) { |
543 | const Handle(BRepCheck_Result)& res = Ana.Result(exp.Current()); |
544 | |
545 | const TopoDS_Shape& sub = exp.Current(); |
546 | for (res->InitContextIterator(); |
547 | res->MoreShapeInContext(); |
548 | res->NextShapeInContext()) { |
549 | if (res->ContextualShape().IsSame(Shape) && |
550 | !Contains(theMap(sub),Shape)) { |
551 | theMap(sub).Append(Shape); |
552 | itl.Initialize(res->StatusOnShape()); |
553 | |
554 | if (itl.Value() != BRepCheck_NoError) { |
555 | Standard_Integer ii = 0; |
556 | |
557 | for(ii=1; ii<=sl->Length(); ii++) |
558 | if(sl->Value(ii).IsSame(sub)) break; |
559 | |
560 | if(ii>sl->Length()) { |
561 | sl->Append(sub); |
562 | FillProblems(itl.Value(),NbProblems); |
563 | } |
564 | for(ii=1; ii<=sl->Length(); ii++) |
565 | if(sl->Value(ii).IsSame(Shape)) break; |
566 | if(ii>sl->Length()) { |
567 | sl->Append(Shape); |
568 | FillProblems(itl.Value(),NbProblems); |
569 | } |
570 | } |
571 | break; |
572 | } |
573 | } |
574 | } |
575 | } |
576 | |
577 | |
578 | //======================================================================= |
579 | //function : GetProblemShapes |
580 | // purpose : auxilary for StructuralDump |
581 | //======================================================================= |
582 | static void GetProblemShapes(const BRepCheck_Analyzer& Ana, |
583 | const TopoDS_Shape& Shape, |
584 | Handle(TopTools_HSequenceOfShape)& sl, |
585 | Handle(TColStd_HArray1OfInteger)& NbProblems) |
586 | { |
587 | for (TopoDS_Iterator iter(Shape); iter.More(); iter.Next()) { |
588 | GetProblemShapes(Ana,iter.Value(),sl, NbProblems); |
589 | } |
590 | TopAbs_ShapeEnum styp = Shape.ShapeType(); |
591 | BRepCheck_ListIteratorOfListOfStatus itl; |
592 | if (!Ana.Result(Shape).IsNull() && !theMap.IsBound(Shape)) { |
593 | itl.Initialize(Ana.Result(Shape)->Status()); |
594 | |
595 | if (itl.Value() != BRepCheck_NoError) { |
596 | sl->Append(Shape); |
597 | FillProblems(itl.Value(),NbProblems); |
598 | } |
599 | } |
600 | if (!theMap.IsBound(Shape)) { |
601 | TopTools_ListOfShape thelist; |
602 | theMap.Bind(Shape, thelist); |
603 | } |
604 | |
605 | switch (styp) { |
606 | case TopAbs_EDGE: |
607 | GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_VERTEX); |
608 | break; |
609 | case TopAbs_FACE: |
610 | GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_WIRE); |
611 | GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_EDGE); |
612 | GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_VERTEX); |
613 | break; |
614 | case TopAbs_SHELL: |
615 | break; |
616 | case TopAbs_SOLID: |
617 | GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_SHELL); |
618 | break; |
619 | default: |
620 | break; |
621 | } |
622 | |
623 | } |
624 | |
625 | //======================================================================= |
626 | //function : StructuralDump |
627 | //purpose : Structural (data exchange) style of output. |
628 | //======================================================================= |
629 | |
630 | //void StructuralDump(const BRepCheck_Analyzer &theAna, |
631 | // const Standard_CString ShName, |
632 | // const Standard_CString Pref, |
633 | // const TopoDS_Shape &theShape) |
634 | void StructuralDump(Draw_Interpretor& theCommands, |
635 | const BRepCheck_Analyzer &theAna, |
636 | const Standard_CString ShName, |
637 | const Standard_CString Pref, |
638 | const TopoDS_Shape &theShape) |
639 | { |
640 | Standard_Integer i; |
641 | //cout << "StructuralDump" << endl; |
642 | //cout << " -- The Shape " << ShName << " has problems :"<<endl; |
643 | //cout<<" Check Count"<<endl; |
644 | //cout<<" ------------------------------------------------"<<endl; |
586db386 |
645 | theCommands << " -- The Shape " << ShName << " has problems :\n"; |
646 | theCommands<<" Check Count\n"; |
647 | theCommands<<" ------------------------------------------------\n"; |
7fd59977 |
648 | |
52d45841 |
649 | Handle(TColStd_HArray1OfInteger) NbProblems = new |
650 | TColStd_HArray1OfInteger(1,NumberOfStatus); |
651 | for(i=1; i<=NumberOfStatus; i++) NbProblems->SetValue(i,0); |
7fd59977 |
652 | Handle(TopTools_HSequenceOfShape) sl,slv,sle,slw,slf,sls,slo; |
653 | sl = new TopTools_HSequenceOfShape(); |
654 | theMap.Clear(); |
655 | GetProblemShapes(theAna, theShape, sl, NbProblems); |
656 | theMap.Clear(); |
657 | |
52d45841 |
658 | Standard_Integer aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidPointOnCurve); |
659 | if(NbProblems->Value(aProblemID) > 0) |
660 | theCommands<<" Invalid Point on Curve ................... "<<NbProblems->Value(aProblemID)<<"\n"; |
661 | |
662 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidPointOnCurveOnSurface); |
663 | if(NbProblems->Value(aProblemID)>0) |
664 | theCommands<<" Invalid Point on CurveOnSurface .......... "<<NbProblems->Value(aProblemID)<<"\n"; |
665 | |
666 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidPointOnSurface); |
667 | if(NbProblems->Value(aProblemID)>0) |
668 | theCommands<<" Invalid Point on Surface ................. "<<NbProblems->Value(aProblemID)<<"\n"; |
669 | |
670 | aProblemID = static_cast<Standard_Integer>(BRepCheck_No3DCurve); |
671 | if(NbProblems->Value(aProblemID)>0) |
672 | theCommands<<" No 3D Curve .............................. "<<NbProblems->Value(aProblemID)<<"\n"; |
673 | |
674 | aProblemID = static_cast<Standard_Integer>(BRepCheck_Multiple3DCurve); |
675 | if(NbProblems->Value(aProblemID)>0) |
676 | theCommands<<" Multiple 3D Curve ........................ "<<NbProblems->Value(aProblemID)<<"\n"; |
677 | |
678 | aProblemID = static_cast<Standard_Integer>(BRepCheck_Invalid3DCurve); |
679 | if(NbProblems->Value(aProblemID)>0) |
680 | theCommands<<" Invalid 3D Curve ......................... "<<NbProblems->Value(aProblemID)<<"\n"; |
681 | |
682 | aProblemID = static_cast<Standard_Integer>(BRepCheck_NoCurveOnSurface); |
683 | if(NbProblems->Value(aProblemID)>0) |
684 | theCommands<<" No Curve on Surface ...................... "<<NbProblems->Value(aProblemID)<<"\n"; |
685 | |
686 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidCurveOnSurface); |
687 | if(NbProblems->Value(aProblemID)>0) |
688 | theCommands<<" Invalid Curve on Surface ................. "<<NbProblems->Value(aProblemID)<<"\n"; |
689 | |
690 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidCurveOnClosedSurface); |
691 | if(NbProblems->Value(aProblemID)>0) |
692 | theCommands<<" Invalid Curve on closed Surface .......... "<<NbProblems->Value(aProblemID)<<"\n"; |
693 | |
694 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidSameRangeFlag); |
695 | if(NbProblems->Value(aProblemID)>0) |
696 | theCommands<<" Invalid SameRange Flag ................... "<<NbProblems->Value(aProblemID)<<"\n"; |
697 | |
698 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidSameParameterFlag); |
699 | if(NbProblems->Value(aProblemID)>0) |
700 | theCommands<<" Invalid SameParameter Flag ............... "<<NbProblems->Value(aProblemID)<<"\n"; |
701 | |
702 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidDegeneratedFlag); |
703 | if(NbProblems->Value(aProblemID)>0) |
704 | theCommands<<" Invalid Degenerated Flag ................. "<<NbProblems->Value(aProblemID)<<"\n"; |
705 | |
706 | aProblemID = static_cast<Standard_Integer>(BRepCheck_FreeEdge); |
707 | if(NbProblems->Value(aProblemID)>0) |
708 | theCommands<<" Free Edge ................................ "<<NbProblems->Value(aProblemID)<<"\n"; |
709 | |
710 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidMultiConnexity); |
711 | if(NbProblems->Value(aProblemID)>0) |
712 | theCommands<<" Invalid MultiConnexity ................... "<<NbProblems->Value(aProblemID)<<"\n"; |
713 | |
714 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidRange); |
715 | if(NbProblems->Value(aProblemID)>0) |
716 | theCommands<<" Invalid Range ............................ "<<NbProblems->Value(aProblemID)<<"\n"; |
717 | |
718 | aProblemID = static_cast<Standard_Integer>(BRepCheck_EmptyWire); |
719 | if(NbProblems->Value(aProblemID)>0) |
720 | theCommands<<" Empty Wire ............................... "<<NbProblems->Value(aProblemID)<<"\n"; |
721 | |
722 | aProblemID = static_cast<Standard_Integer>(BRepCheck_RedundantEdge); |
723 | if(NbProblems->Value(aProblemID)>0) |
724 | theCommands<<" Redundant Edge ........................... "<<NbProblems->Value(aProblemID)<<"\n"; |
725 | |
726 | aProblemID = static_cast<Standard_Integer>(BRepCheck_SelfIntersectingWire); |
727 | if(NbProblems->Value(aProblemID)>0) |
728 | theCommands<<" Self Intersecting Wire ................... "<<NbProblems->Value(aProblemID)<<"\n"; |
729 | |
730 | aProblemID = static_cast<Standard_Integer>(BRepCheck_NoSurface); |
731 | if(NbProblems->Value(aProblemID)>0) |
732 | theCommands<<" No Surface ............................... "<<NbProblems->Value(aProblemID)<<"\n"; |
733 | |
734 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidWire); |
735 | if(NbProblems->Value(aProblemID)>0) |
736 | theCommands<<" Invalid Wire ............................. "<<NbProblems->Value(aProblemID)<<"\n"; |
737 | |
738 | aProblemID = static_cast<Standard_Integer>(BRepCheck_RedundantWire); |
739 | if(NbProblems->Value(aProblemID)>0) |
740 | theCommands<<" Redundant Wire ........................... "<<NbProblems->Value(aProblemID)<<"\n"; |
741 | |
742 | aProblemID = static_cast<Standard_Integer>(BRepCheck_IntersectingWires); |
743 | if(NbProblems->Value(aProblemID)>0) |
744 | theCommands<<" Intersecting Wires ....................... "<<NbProblems->Value(aProblemID)<<"\n"; |
745 | |
746 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidImbricationOfWires); |
747 | if(NbProblems->Value(aProblemID)>0) |
748 | theCommands<<" Invalid Imbrication of Wires ............. "<<NbProblems->Value(aProblemID)<<"\n"; |
749 | |
750 | aProblemID = static_cast<Standard_Integer>(BRepCheck_EmptyShell); |
751 | if(NbProblems->Value(aProblemID)>0) |
752 | theCommands<<" Empty Shell .............................. "<<NbProblems->Value(aProblemID)<<"\n"; |
753 | |
754 | aProblemID = static_cast<Standard_Integer>(BRepCheck_RedundantFace); |
755 | if(NbProblems->Value(aProblemID)>0) |
756 | theCommands<<" Redundant Face ........................... "<<NbProblems->Value(aProblemID)<<"\n"; |
757 | |
758 | aProblemID = static_cast<Standard_Integer>(BRepCheck_UnorientableShape); |
759 | if(NbProblems->Value(aProblemID)>0) |
760 | theCommands<<" Unorientable Shape ....................... "<<NbProblems->Value(aProblemID)<<"\n"; |
761 | |
762 | aProblemID = static_cast<Standard_Integer>(BRepCheck_NotClosed); |
763 | if(NbProblems->Value(aProblemID)>0) |
764 | theCommands<<" Not Closed ............................... "<<NbProblems->Value(aProblemID)<<"\n"; |
765 | |
766 | aProblemID = static_cast<Standard_Integer>(BRepCheck_NotConnected); |
767 | if(NbProblems->Value(aProblemID)>0) |
768 | theCommands<<" Not Connected ............................ "<<NbProblems->Value(aProblemID)<<"\n"; |
769 | |
770 | aProblemID = static_cast<Standard_Integer>(BRepCheck_SubshapeNotInShape); |
771 | if(NbProblems->Value(aProblemID)>0) |
772 | theCommands<<" Subshape not in Shape .................... "<<NbProblems->Value(aProblemID)<<"\n"; |
773 | |
774 | aProblemID = static_cast<Standard_Integer>(BRepCheck_BadOrientation); |
775 | if(NbProblems->Value(aProblemID)>0) |
776 | theCommands<<" Bad Orientation .......................... "<<NbProblems->Value(aProblemID)<<"\n"; |
777 | |
778 | aProblemID = static_cast<Standard_Integer>(BRepCheck_BadOrientationOfSubshape); |
779 | if(NbProblems->Value(aProblemID)>0) |
780 | theCommands<<" Bad Orientation of Subshape .............. "<<NbProblems->Value(aProblemID)<<"\n"; |
781 | |
782 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidToleranceValue); |
783 | if(NbProblems->Value(aProblemID)>0) |
784 | theCommands<<" Invalid tolerance value................... "<<NbProblems->Value(aProblemID)<<"\n"; |
785 | |
786 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidPolygonOnTriangulation); |
787 | if(NbProblems->Value(aProblemID)>0) |
788 | theCommands<<" Invalid polygon on triangulation.......... "<<NbProblems->Value(aProblemID)<<"\n"; |
789 | |
949df2b6 |
790 | aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidImbricationOfShells); |
791 | if(NbProblems->Value(aProblemID)>0) |
792 | theCommands<<" Invalid Imbrication of Shells............. "<<NbProblems->Value(aProblemID)<<"\n"; |
793 | |
794 | aProblemID = static_cast<Standard_Integer>(BRepCheck_EnclosedRegion); |
795 | if(NbProblems->Value(aProblemID)>0) |
796 | theCommands<<" Enclosed Region........................... "<<NbProblems->Value(aProblemID)<<"\n"; |
797 | |
52d45841 |
798 | aProblemID = static_cast<Standard_Integer>(BRepCheck_CheckFail); |
799 | if(NbProblems->Value(aProblemID)>0) |
800 | theCommands<<" checkshape failure........................ "<<NbProblems->Value(aProblemID)<<"\n"; |
7fd59977 |
801 | |
949df2b6 |
802 | |
803 | |
586db386 |
804 | theCommands<<" ------------------------------------------------\n"; |
7fd59977 |
805 | theCommands<<"*** Shapes with problems : "<<sl->Length()<<"\n"; |
806 | |
807 | slv = new TopTools_HSequenceOfShape(); |
808 | sle = new TopTools_HSequenceOfShape(); |
809 | slw = new TopTools_HSequenceOfShape(); |
810 | slf = new TopTools_HSequenceOfShape(); |
811 | sls = new TopTools_HSequenceOfShape(); |
812 | slo = new TopTools_HSequenceOfShape(); |
813 | |
814 | for(i=1; i<=sl->Length(); i++) { |
815 | TopoDS_Shape shi = sl->Value(i); |
816 | TopAbs_ShapeEnum sti = shi.ShapeType(); |
817 | switch (sti) { |
818 | case TopAbs_VERTEX : slv->Append (shi); break; |
819 | case TopAbs_EDGE : sle->Append (shi); break; |
820 | case TopAbs_WIRE : slw->Append (shi); break; |
821 | case TopAbs_FACE : slf->Append (shi); break; |
822 | case TopAbs_SHELL : sls->Append (shi); break; |
823 | case TopAbs_SOLID : slo->Append (shi); break; |
824 | default : break; |
825 | } |
826 | } |
827 | |
828 | BRep_Builder B; |
829 | if(slv->Length()>0) { |
830 | TopoDS_Compound comp; |
831 | B.MakeCompound(comp); |
832 | Standard_Integer nb = slv->Length(); |
833 | for(i=1; i<=nb; i++) |
834 | B.Add(comp,slv->Value(i)); |
835 | char aName[20]; |
91322f44 |
836 | Sprintf(aName,"%s_v",Pref); |
7fd59977 |
837 | DBRep::Set(aName,comp); |
586db386 |
838 | //cout<<"VERTEX : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl; |
7fd59977 |
839 | if (nb > 9) |
586db386 |
840 | theCommands<<"VERTEX : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
841 | else |
586db386 |
842 | theCommands<<"VERTEX : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
843 | } |
844 | if(sle->Length()>0) { |
845 | TopoDS_Compound comp; |
846 | B.MakeCompound(comp); |
847 | Standard_Integer nb = sle->Length(); |
848 | for(i=1; i<=nb; i++) |
849 | B.Add(comp,sle->Value(i)); |
850 | char aName[20]; |
91322f44 |
851 | Sprintf(aName,"%s_e",Pref); |
7fd59977 |
852 | DBRep::Set(aName,comp); |
586db386 |
853 | //cout<<"EDGE : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl; |
7fd59977 |
854 | if (nb > 9) |
586db386 |
855 | theCommands<<"EDGE : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
856 | else |
586db386 |
857 | theCommands<<"EDGE : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
858 | } |
859 | if(slw->Length()>0) { |
860 | TopoDS_Compound comp; |
861 | B.MakeCompound(comp); |
862 | Standard_Integer nb = slw->Length(); |
863 | for(i=1; i<=nb; i++) |
864 | B.Add(comp,slw->Value(i)); |
865 | char aName[20]; |
91322f44 |
866 | Sprintf(aName,"%s_w",Pref); |
7fd59977 |
867 | DBRep::Set(aName,comp); |
586db386 |
868 | //cout<<"WIRE : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl; |
7fd59977 |
869 | if (nb > 9) |
586db386 |
870 | theCommands<<"WIRE : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
871 | else |
586db386 |
872 | theCommands<<"WIRE : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
873 | } |
874 | if(slf->Length()>0) { |
875 | TopoDS_Compound comp; |
876 | B.MakeCompound(comp); |
877 | Standard_Integer nb = slf->Length(); |
878 | for(i=1; i<=nb; i++) |
879 | B.Add(comp,slf->Value(i)); |
880 | char aName[20]; |
91322f44 |
881 | Sprintf(aName,"%s_f",Pref); |
7fd59977 |
882 | DBRep::Set(aName,comp); |
586db386 |
883 | //cout<<"FACE : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl; |
7fd59977 |
884 | if (nb > 9) |
586db386 |
885 | theCommands<<"FACE : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
886 | else |
586db386 |
887 | theCommands<<"FACE : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
888 | } |
889 | if(sls->Length()>0) { |
890 | TopoDS_Compound comp; |
891 | B.MakeCompound(comp); |
892 | Standard_Integer nb = sls->Length(); |
893 | for(i=1; i<=nb; i++) |
894 | B.Add(comp,sls->Value(i)); |
895 | char aName[20]; |
91322f44 |
896 | Sprintf(aName,"%s_s",Pref); |
7fd59977 |
897 | DBRep::Set(aName,comp); |
586db386 |
898 | //cout<<"SHELL : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl; |
7fd59977 |
899 | if (nb > 9) |
586db386 |
900 | theCommands<<"SHELL : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
901 | else |
586db386 |
902 | theCommands<<"SHELL : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
903 | } |
904 | if(slo->Length()>0) { |
905 | TopoDS_Compound comp; |
906 | B.MakeCompound(comp); |
907 | Standard_Integer nb = slo->Length(); |
908 | for(i=1; i<=nb; i++) |
909 | B.Add(comp,slo->Value(i)); |
910 | char aName[20]; |
91322f44 |
911 | Sprintf(aName,"%s_o",Pref); |
7fd59977 |
912 | DBRep::Set(aName,comp); |
586db386 |
913 | //cout<<"SOLID : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl; |
7fd59977 |
914 | if (nb > 9) |
586db386 |
915 | theCommands<<"SOLID : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
916 | else |
586db386 |
917 | theCommands<<"SOLID : "<<nb<<" Items -> compound named "<<aName<<"\n"; |
7fd59977 |
918 | } |
919 | } |
920 | |
921 | //======================================================================= |
922 | //function : checkshape |
923 | //purpose : Checks a shape |
924 | //======================================================================= |
925 | |
926 | static Standard_Integer checkshape(Draw_Interpretor& theCommands, |
927 | Standard_Integer narg, const char** a) |
928 | { |
929 | if (narg == 1) { |
930 | //cout << endl; |
931 | //cout << "Usage : checkshape [-top] shape [result] [-short]" << endl; |
932 | //cout << endl; |
933 | //cout << "Where :" << endl; |
934 | //cout << " -top - check topology only." << endl; |
935 | //cout << " shape - the name of the shape to test." << endl; |
936 | //cout << " result - the prefix of the output shape names. If it is used, structural" << endl; |
937 | //cout << " output style will be used. Otherwise - contextual one." << endl; |
938 | //cout << " -short - short description of check." << endl; |
939 | theCommands << "\n"; |
586db386 |
940 | theCommands << "Usage : checkshape [-top] shape [result] [-short]\n"; |
7fd59977 |
941 | theCommands << "\n"; |
586db386 |
942 | theCommands << "Where :\n"; |
943 | theCommands << " -top - check topology only.\n"; |
944 | theCommands << " shape - the name of the shape to test.\n"; |
945 | theCommands << " result - the prefix of the output shape names. If it is used, structural\n"; |
946 | theCommands << " output style will be used. Otherwise - contextual one.\n"; |
947 | theCommands << " -short - short description of check.\n"; |
7fd59977 |
948 | |
949 | return 0; |
950 | } |
951 | |
952 | if (narg > 5) { |
953 | //cout << "Invalid number of args!!!" << endl; |
954 | //cout << "No args to have help." << endl; |
586db386 |
955 | theCommands << "Invalid number of args!!!\n"; |
956 | theCommands << "No args to have help.\n"; |
7fd59977 |
957 | |
958 | return 1; |
959 | } |
960 | |
961 | Standard_Boolean aGeomCtrl = Standard_True; |
962 | Standard_Integer aCurInd = 1; |
963 | |
964 | if (!strcmp(a[1],"-top")) { |
965 | aGeomCtrl = Standard_False; |
966 | aCurInd++; |
967 | } |
968 | |
969 | if (aCurInd > narg - 1) { |
970 | //cout << "Invalid number of args!!!" << endl; |
971 | //cout << "No args to have help." << endl; |
586db386 |
972 | theCommands << "Invalid number of args!!!\n"; |
973 | theCommands << "No args to have help.\n"; |
7fd59977 |
974 | |
975 | return 1; |
976 | } |
977 | |
978 | Standard_CString aShapeName = a[aCurInd]; |
979 | TopoDS_Shape aShape = DBRep::Get(aShapeName); |
980 | |
981 | if (aShape.IsNull()) { |
982 | //cout << a[aCurInd] << " is not a topological shape!!!" << endl; |
586db386 |
983 | theCommands << a[aCurInd] << " is not a topological shape!!!\n"; |
7fd59977 |
984 | |
985 | return 1; |
986 | } |
987 | |
988 | Standard_Boolean IsShortDump = Standard_False; |
989 | Standard_Boolean IsContextDump = Standard_True; |
990 | Standard_Integer aBackInd = narg - 1; |
991 | |
992 | if (aCurInd < aBackInd) { |
993 | if (!strcmp(a[aBackInd],"-short")) { |
994 | IsShortDump = Standard_True; |
995 | aBackInd--; |
996 | } |
997 | } |
998 | |
999 | if (aCurInd < aBackInd - 1) { |
1000 | //cout << "Invalid number of args!!!" << endl; |
1001 | //cout << "No args to have help." << endl; |
586db386 |
1002 | theCommands << "Invalid number of args!!!\n"; |
1003 | theCommands << "No args to have help.\n"; |
7fd59977 |
1004 | |
1005 | return 1; |
1006 | } else if (aCurInd < aBackInd) { |
1007 | IsContextDump = Standard_False; |
1008 | } |
1009 | |
1010 | try { |
1011 | OCC_CATCH_SIGNALS |
1012 | BRepCheck_Analyzer anAna(aShape,aGeomCtrl); |
1013 | Standard_Boolean isValid = anAna.IsValid(); |
1014 | |
1015 | if (isValid) { |
1016 | if (IsContextDump) { |
1017 | theCommands << "This shape seems to be valid"; |
1018 | } else { |
1019 | theCommands << " -- The Shape " << aShapeName << " looks OK"; |
1020 | } |
1021 | } else { |
1022 | if (IsShortDump) { |
1023 | theCommands<<"This shape has faulty shapes"; |
1024 | } else { |
1025 | if (IsContextDump) { |
1026 | //ContextualDump(anAna, aShape); |
1027 | ContextualDump(theCommands, anAna, aShape); |
1028 | } else { |
1029 | Standard_CString aPref = a[aCurInd+1]; |
1030 | //StructuralDump(anAna, aShapeName, aPref, aShape); |
1031 | StructuralDump(theCommands, anAna, aShapeName, aPref, aShape); |
1032 | } |
1033 | } |
1034 | } |
1035 | } |
9775fa61 |
1036 | catch(Standard_Failure const& anException) { |
7fd59977 |
1037 | theCommands<<"checkshape exception : "; |
9775fa61 |
1038 | theCommands << anException.GetMessageString(); |
7fd59977 |
1039 | theCommands<<"\n"; |
1040 | return 1; |
1041 | } |
1042 | |
1043 | return 0; |
1044 | } |
1045 | // Modified by skv - Tue Apr 27 13:38:24 2004 End |
1046 | /***************************************************************/ |
1047 | static void InitEpsSurf(Standard_Real& epsnl,Standard_Real& epsdis, Standard_Real& epsangk1, |
1048 | Standard_Real& epsangk2, Standard_Real& epsangn1, |
1049 | Standard_Real& perce,Standard_Real& maxlen ) |
1050 | { |
1051 | epsnl = 0.001; |
1052 | epsdis = 0.001; |
1053 | epsangk1 = 0.001 ; |
1054 | epsangk2 = 0.001; |
1055 | epsangn1 = 0.001 ; |
1056 | perce = 0.01; |
1057 | maxlen = 10000 ; |
1058 | } |
1059 | |
1060 | static Standard_Integer shapeG1continuity (Draw_Interpretor& di, Standard_Integer n, const char** a) |
1061 | |
1062 | { Standard_Real epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen; |
1063 | Standard_Integer nbeval; |
1064 | InitEpsSurf(epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen); |
1065 | Standard_Boolean ISG1=Standard_True; |
1066 | if (n<4) return 1; |
1067 | TopoDS_Face face1,face2; |
1068 | Standard_Real f1,f2,l1,l2; |
1069 | TopoDS_Shape shape = DBRep::Get(a[1],TopAbs_SHAPE); |
1070 | if (shape.IsNull()) return 1; |
1071 | TopoDS_Shape edge = DBRep::Get(a[2],TopAbs_EDGE); |
1072 | if (edge.IsNull()) return 1; |
1073 | // calcul des deux faces |
1074 | TopTools_IndexedDataMapOfShapeListOfShape lface; |
1075 | TopExp::MapShapesAndAncestors(shape,TopAbs_EDGE,TopAbs_FACE,lface); |
1076 | const TopTools_ListOfShape& lfac = lface.FindFromKey(edge); |
1077 | |
1078 | Standard_Integer nelem= lfac.Extent(); |
1079 | if(nelem!=2) return 1; |
1080 | TopTools_ListIteratorOfListOfShape It; |
1081 | It.Initialize(lfac); |
1082 | face1=TopoDS::Face(It.Value()); |
1083 | It.Next(); |
1084 | face2=TopoDS::Face(It.Value()); |
1085 | |
1086 | // calcul des deux pcurves |
1087 | const Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface |
1088 | (TopoDS::Edge(edge),face1,f1,l1); |
1089 | if (c1.IsNull()) return 1; |
1090 | const Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface |
1091 | (TopoDS::Edge(edge),face2,f2,l2); |
1092 | if (c2.IsNull()) return 1; |
1093 | |
1094 | Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1); |
1095 | |
1096 | Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2); |
1097 | |
1098 | // calcul dees deux surfaces |
1099 | TopLoc_Location L1,L2; |
1100 | TopoDS_Face aLocalFace = face1; |
1101 | const Handle(Geom_Surface)& s1 = BRep_Tool::Surface(aLocalFace,L1); |
1102 | // const Handle(Geom_Surface)& s1 = |
1103 | // BRep_Tool::Surface(TopoDS::Face(face1),L1); |
1104 | if (s1.IsNull()) return 1; |
1105 | aLocalFace = face2; |
1106 | const Handle(Geom_Surface)& s2 = BRep_Tool::Surface(aLocalFace,L2); |
1107 | // const Handle(Geom_Surface)& s2 = |
1108 | // BRep_Tool::Surface(TopoDS::Face(face2),L2); |
1109 | if (s2.IsNull()) return 1; |
1110 | |
1111 | |
1112 | Handle(Geom_Surface) surf1 = Handle(Geom_Surface):: |
1113 | DownCast(s1->Transformed(L1.Transformation())); |
1114 | if (surf1.IsNull()) return 1; |
1115 | Handle(Geom_Surface) surf2 = Handle(Geom_Surface):: |
1116 | DownCast(s2->Transformed(L2.Transformation())); |
1117 | if (surf2.IsNull()) return 1; |
1118 | |
1119 | |
1120 | |
91322f44 |
1121 | nbeval = (Standard_Integer ) Draw::Atof( a[3]); |
7fd59977 |
1122 | |
1123 | switch(n) |
b1811c1d |
1124 | { |
1125 | case 7 : epsG1 = Draw::Atof(a[6]); |
1126 | Standard_FALLTHROUGH |
1127 | case 6 : epsC0 = Draw::Atof(a[5]); |
1128 | Standard_FALLTHROUGH |
1129 | case 5 : epsnl = Draw::Atof(a[4]); |
1130 | Standard_FALLTHROUGH |
1131 | case 4 : break; |
1132 | default : return 1; |
1133 | } |
7fd59977 |
1134 | |
1135 | |
1136 | Standard_Real pard1, parf1, U, Uf, deltaU, nb = 0; |
1137 | Standard_Boolean isconti = Standard_True; |
1138 | Standard_Boolean isdone = Standard_True; |
1139 | pard1 = curv1->FirstParameter(); |
1140 | parf1 = curv1->LastParameter(); |
1141 | Standard_Real MaxG0Value=0, MaxG1Angle=0; |
1142 | U = Min( pard1,parf1); |
1143 | Uf = Max (pard1,parf1); |
1144 | |
1145 | deltaU = Abs(parf1- pard1)/nbeval; |
1146 | |
1147 | do |
1148 | { if ( nb == nbeval) |
1149 | { LocalAnalysis_SurfaceContinuity res(curv1, curv2, Uf,surf1, surf2, GeomAbs_G1, epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen ); |
1150 | isdone = res.IsDone(); |
1151 | if ( isdone) { isconti = res.IsG1(); |
1152 | if (isconti) |
1153 | {if (res.C0Value()>MaxG0Value) MaxG0Value = res.C0Value(); |
1154 | if (res.G1Angle ()>MaxG1Angle) MaxG1Angle = res.G1Angle();}} |
1155 | else isconti = Standard_False;} |
1156 | |
1157 | else {LocalAnalysis_SurfaceContinuity res (curv1, curv2, (U+nb*deltaU ), surf1,surf2, GeomAbs_G1,epsnl,epsC0, epsC1, epsC2, epsG1, |
1158 | percent,maxlen); |
1159 | isdone = res.IsDone(); |
1160 | if ( isdone) { isconti = res.IsG1(); |
1161 | if ( nb == 0) { MaxG0Value = res.C0Value(); |
1162 | MaxG1Angle = res.G1Angle();} |
1163 | if (res.C0Value()> MaxG0Value) MaxG0Value = res.C0Value(); |
1164 | if (res.G1Angle()> MaxG1Angle) MaxG1Angle= res.G1Angle();;} |
1165 | |
1166 | else isconti = Standard_False;} |
1167 | if (!isconti) ISG1=Standard_False; |
1168 | nb++; |
1169 | |
1170 | } |
1171 | while ((nb<nbeval)&& isdone ); |
1172 | |
1173 | //if (!isdone) { cout<<" Problem in computation "<<endl; return 1;} |
1174 | //if (ISG1) |
1175 | // {cout<<" the continuity is G1 "<<endl;} |
1176 | //else { cout<<" the continuity is not G1 "<<endl;} |
1177 | //cout<<"MaxG0Value :"<< MaxG0Value << endl; |
1178 | //cout<<"MaxG1Angle:"<< MaxG1Angle << endl; |
586db386 |
1179 | if (!isdone) { di<<" Problem in computation \n"; return 1;} |
7fd59977 |
1180 | if (ISG1) |
586db386 |
1181 | {di<<" the continuity is G1 \n";} |
1182 | else { di<<" the continuity is not G1 \n";} |
7fd59977 |
1183 | di<<"MaxG0Value :"<< MaxG0Value << "\n"; |
1184 | di<<"MaxG1Angle:"<< MaxG1Angle << "\n"; |
1185 | return 0; |
1186 | } |
1187 | /*****************************************************************************/ |
1188 | static Standard_Integer shapeG0continuity (Draw_Interpretor& di, Standard_Integer n, const char** a) |
1189 | |
1190 | { Standard_Real epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen; |
1191 | Standard_Integer nbeval; |
1192 | Standard_Boolean ISG0; |
1193 | InitEpsSurf(epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen ); |
1194 | |
1195 | if (n<4) return 1; |
1196 | TopoDS_Face face1,face2; |
1197 | Standard_Real f1,f2,l1,l2; |
1198 | TopoDS_Shape shape = DBRep::Get(a[1],TopAbs_SHAPE); |
1199 | if (shape.IsNull()) return 1; |
1200 | TopoDS_Shape edge = DBRep::Get(a[2],TopAbs_EDGE); |
1201 | if (edge.IsNull()) return 1; |
1202 | // calcul des deux faces |
1203 | TopTools_IndexedDataMapOfShapeListOfShape lface; |
1204 | TopExp::MapShapesAndAncestors(shape,TopAbs_EDGE,TopAbs_FACE,lface); |
1205 | const TopTools_ListOfShape& lfac = lface.FindFromKey(edge); |
1206 | |
1207 | Standard_Integer nelem= lfac.Extent(); |
1208 | if(nelem!=2) return 1; |
1209 | TopTools_ListIteratorOfListOfShape It; |
1210 | It.Initialize(lfac); |
1211 | face1=TopoDS::Face(It.Value()); |
1212 | It.Next(); |
1213 | face2=TopoDS::Face(It.Value()); |
1214 | |
1215 | // calcul des deux pcurves |
1216 | const Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface |
1217 | (TopoDS::Edge(edge),face1,f1,l1); |
1218 | if (c1.IsNull()) return 1; |
1219 | const Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface |
1220 | (TopoDS::Edge(edge),face2,f2,l2); |
1221 | if (c2.IsNull()) return 1; |
1222 | |
1223 | Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1); |
1224 | |
1225 | Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2); |
1226 | |
1227 | // calcul des deux surfaces |
1228 | TopLoc_Location L1,L2; |
1229 | TopoDS_Face aLocalFace = face1; |
1230 | const Handle(Geom_Surface)& s1 = BRep_Tool::Surface(aLocalFace,L1); |
1231 | // const Handle(Geom_Surface)& s1 = |
1232 | // BRep_Tool::Surface(TopoDS::Face(face1),L1); |
1233 | if (s1.IsNull()) return 1; |
1234 | aLocalFace = face2; |
1235 | const Handle(Geom_Surface)& s2 = BRep_Tool::Surface(aLocalFace,L2); |
1236 | // const Handle(Geom_Surface)& s2 = |
1237 | // BRep_Tool::Surface(TopoDS::Face(face2),L2); |
1238 | if (s2.IsNull()) return 1; |
1239 | |
1240 | |
1241 | Handle(Geom_Surface) surf1 = Handle(Geom_Surface):: |
1242 | DownCast(s1->Transformed(L1.Transformation())); |
1243 | if (surf1.IsNull()) return 1; |
1244 | Handle(Geom_Surface) surf2 = Handle(Geom_Surface):: |
1245 | DownCast(s2->Transformed(L2.Transformation())); |
1246 | if (surf2.IsNull()) return 1; |
1247 | |
1248 | |
1249 | |
91322f44 |
1250 | nbeval = (Standard_Integer ) Draw::Atof( a[3]); |
7fd59977 |
1251 | |
1252 | switch(n) |
b1811c1d |
1253 | { |
1254 | case 6 : epsC0 = Draw::Atof(a[5]); |
1255 | Standard_FALLTHROUGH |
1256 | case 5 : epsnl = Draw::Atof(a[4]); |
1257 | Standard_FALLTHROUGH |
1258 | case 4 : break; |
1259 | default : return 1; |
1260 | } |
7fd59977 |
1261 | |
1262 | Standard_Real pard1, parf1, U, Uf, deltaU, nb = 0; |
1263 | Standard_Boolean isconti = Standard_True; |
1264 | Standard_Boolean isdone = Standard_True; |
1265 | pard1 = curv1->FirstParameter(); |
1266 | parf1 = curv1->LastParameter(); |
1267 | Standard_Real MaxG0Value=0; |
1268 | U = Min( pard1,parf1); |
1269 | Uf = Max (pard1,parf1); |
1270 | |
1271 | deltaU = Abs(parf1- pard1)/nbeval; |
1272 | ISG0=Standard_True; |
1273 | do |
1274 | { if ( nb == nbeval) |
1275 | { LocalAnalysis_SurfaceContinuity res (curv1, curv2, Uf,surf1, surf2, GeomAbs_C0,epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen ); |
1276 | isdone = res.IsDone(); |
1277 | if ( isdone) { isconti = res.IsC0( ); |
1278 | if (isconti) |
1279 | if (res.C0Value()>MaxG0Value) MaxG0Value= res.C0Value();} |
1280 | else isconti = Standard_False;} |
1281 | |
1282 | else {LocalAnalysis_SurfaceContinuity res (curv1, curv2, (U+nb*deltaU), surf1, surf2, GeomAbs_C0,epsnl,epsC0, epsC1, epsC2, epsG1, percent,maxlen ); |
1283 | isdone = res.IsDone(); |
1284 | if ( isdone) { isconti = res.IsC0() ; |
1285 | if ( nb == 0) { MaxG0Value = res.C0Value();} |
1286 | if (res.C0Value()> MaxG0Value) MaxG0Value = res.C0Value();} |
1287 | |
1288 | else isconti = Standard_False;} |
1289 | |
1290 | nb++; |
1291 | if (!isconti) ISG0=Standard_False; |
1292 | |
1293 | } |
1294 | while ((nb<nbeval)&& isdone ); |
1295 | |
1296 | //f (!isdone) { cout<<" Problem in computation "<<endl; return 1;} |
1297 | //if (ISG0) |
1298 | // {cout<<" the continuity is G0 "<<endl;} |
1299 | |
1300 | //else { cout<<" the continuity is not G0 "<<endl;} |
1301 | //cout<<"MaxG0Value :"<< MaxG0Value << endl; |
586db386 |
1302 | if (!isdone) { di<<" Problem in computation \n"; return 1;} |
7fd59977 |
1303 | if (ISG0) |
586db386 |
1304 | {di<<" the continuity is G0 \n";} |
7fd59977 |
1305 | |
586db386 |
1306 | else { di<<" the continuity is not G0 \n";} |
7fd59977 |
1307 | di<<"MaxG0Value :"<< MaxG0Value << "\n"; |
1308 | return 0; |
1309 | } |
1310 | /*****************************************************************************************/ |
1311 | static Standard_Integer shapeG2continuity (Draw_Interpretor& di, Standard_Integer n, const char** a) |
1312 | |
1313 | { Standard_Real epsnl,epsC0, epsC1, epsC2, epsG1, percent,maxlen; |
1314 | Standard_Boolean ISG2=Standard_True; |
1315 | Standard_Integer nbeval; |
1316 | Standard_Real MaxG0Value=0,MaxG1Angle=0,MaxG2Curvature=0; |
1317 | InitEpsSurf(epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen ); |
1318 | |
1319 | if (n<4) return 1; |
1320 | TopoDS_Face face1,face2; |
1321 | Standard_Real f1,f2,l1,l2; |
1322 | TopoDS_Shape shape = DBRep::Get(a[1],TopAbs_SHAPE); |
1323 | if (shape.IsNull()) return 1; |
1324 | TopoDS_Shape edge = DBRep::Get(a[2],TopAbs_EDGE); |
1325 | if (edge.IsNull()) return 1; |
1326 | // calcul des deux faces |
1327 | TopTools_IndexedDataMapOfShapeListOfShape lface; |
1328 | TopExp::MapShapesAndAncestors(shape,TopAbs_EDGE,TopAbs_FACE,lface); |
1329 | const TopTools_ListOfShape& lfac = lface.FindFromKey(edge); |
1330 | |
1331 | Standard_Integer nelem= lfac.Extent(); |
1332 | if(nelem!=2) return 1; |
1333 | TopTools_ListIteratorOfListOfShape It; |
1334 | It.Initialize(lfac); |
1335 | face1=TopoDS::Face(It.Value()); |
1336 | It.Next(); |
1337 | face2=TopoDS::Face(It.Value()); |
1338 | // calcul des deux pcurves |
1339 | const Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface |
1340 | (TopoDS::Edge(edge),face1,f1,l1); |
1341 | if (c1.IsNull()) return 1; |
1342 | const Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface |
1343 | (TopoDS::Edge(edge),face2,f2,l2); |
1344 | if (c2.IsNull()) return 1; |
1345 | |
1346 | Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1); |
1347 | |
1348 | Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2); |
1349 | |
1350 | // calcul des deux surfaces |
1351 | TopLoc_Location L1,L2; |
1352 | TopoDS_Face aLocalFace = face1; |
1353 | const Handle(Geom_Surface)& s1 = BRep_Tool::Surface(aLocalFace,L1); |
1354 | // const Handle(Geom_Surface)& s1 = |
1355 | // BRep_Tool::Surface(TopoDS::Face(face1),L1); |
1356 | if (s1.IsNull()) return 1; |
1357 | aLocalFace = face2; |
1358 | const Handle(Geom_Surface)& s2 = BRep_Tool::Surface(aLocalFace,L2); |
1359 | // const Handle(Geom_Surface)& s2 = |
1360 | // BRep_Tool::Surface(TopoDS::Face(face2),L2); |
1361 | if (s2.IsNull()) return 1; |
1362 | |
1363 | |
1364 | Handle(Geom_Surface) surf1 = Handle(Geom_Surface):: |
1365 | DownCast(s1->Transformed(L1.Transformation())); |
1366 | if (surf1.IsNull()) return 1; |
1367 | Handle(Geom_Surface) surf2 = Handle(Geom_Surface):: |
1368 | DownCast(s2->Transformed(L2.Transformation())); |
1369 | if (surf2.IsNull()) return 1; |
1370 | |
1371 | |
1372 | |
91322f44 |
1373 | nbeval = (Standard_Integer ) Draw::Atof( a[3]); |
7fd59977 |
1374 | |
1375 | switch(n) |
b1811c1d |
1376 | { |
1377 | case 9 : maxlen = Draw::Atof(a[8]); |
1378 | Standard_FALLTHROUGH |
1379 | case 8 : percent = Draw::Atof(a[7]); |
1380 | Standard_FALLTHROUGH |
1381 | case 7 : epsG1 = Draw::Atof(a[6]); |
1382 | Standard_FALLTHROUGH |
1383 | case 6 : epsC0 = Draw::Atof(a[5]); |
1384 | Standard_FALLTHROUGH |
1385 | case 5 : epsnl = Draw::Atof(a[4]); |
1386 | Standard_FALLTHROUGH |
1387 | case 4 : break; |
1388 | default : return 1; |
1389 | } |
7fd59977 |
1390 | |
1391 | |
1392 | Standard_Real pard1, parf1, U, Uf, deltaU, nb = 0; |
1393 | Standard_Boolean isconti = Standard_True; |
1394 | Standard_Boolean isdone = Standard_True; |
1395 | pard1 = curv1->FirstParameter(); |
1396 | parf1 = curv1->LastParameter(); |
1397 | U = Min( pard1,parf1); |
1398 | Uf = Max (pard1,parf1); |
1399 | |
1400 | deltaU = Abs(parf1- pard1)/nbeval; |
1401 | |
1402 | do |
1403 | { if ( nb == nbeval) |
1404 | { LocalAnalysis_SurfaceContinuity res (curv1, curv2, Uf,surf1, surf2, GeomAbs_G2,epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen ); |
1405 | isdone = res.IsDone(); |
1406 | if (isdone){isconti = res.IsG2(); |
1407 | if (isconti) |
1408 | {if(res.C0Value()>MaxG0Value) MaxG0Value=res.C0Value(); |
1409 | if(res.G1Angle()>MaxG1Angle) MaxG1Angle=res.G1Angle(); |
1410 | if(res.G2CurvatureGap()>MaxG2Curvature) |
1411 | MaxG2Curvature=res.G2CurvatureGap(); |
1412 | }} |
1413 | else isconti = Standard_False;} |
1414 | |
1415 | else { LocalAnalysis_SurfaceContinuity res (curv1, curv2, (U+nb*deltaU), surf1,surf2, GeomAbs_G2,epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen ); |
1416 | isdone = res.IsDone(); |
1417 | if ( isdone) {isconti = res.IsG2(); |
1418 | if (nb==0){MaxG0Value=res.C0Value(); |
1419 | MaxG1Angle=res.G1Angle(); |
1420 | MaxG2Curvature=res.G2CurvatureGap();} |
1421 | if(res.C0Value()>MaxG0Value) |
1422 | MaxG0Value=res.C0Value(); |
1423 | if(res.G1Angle()>MaxG1Angle) |
1424 | MaxG1Angle=res.G1Angle(); |
1425 | if(res.G2CurvatureGap()>MaxG2Curvature) |
1426 | MaxG2Curvature=res.G2CurvatureGap();} |
1427 | else isconti = Standard_False;} |
1428 | |
1429 | nb++; |
1430 | if (!isconti) ISG2=Standard_False; |
1431 | |
1432 | } |
1433 | while ((nb<nbeval)&& isdone ); |
1434 | |
1435 | //if (!isdone) { cout<<" Problem in computation "<<endl; return 1;} |
1436 | //if (ISG2) |
1437 | //cout<<" the continuity is G2 "<<endl; |
1438 | //else cout<<" the continuity is not G2 "<<endl; |
1439 | //cout<<"MaxG0Value :"<< MaxG0Value << endl; |
1440 | //cout<<"MaxG1Angle:"<< MaxG1Angle << endl; |
1441 | //cout<<"MaxG2Curvature:"<<MaxG2Curvature<<endl; |
586db386 |
1442 | if (!isdone) { di<<" Problem in computation \n"; return 1;} |
7fd59977 |
1443 | if (ISG2) |
586db386 |
1444 | di<<" the continuity is G2 \n"; |
1445 | else di<<" the continuity is not G2 \n"; |
7fd59977 |
1446 | di<<"MaxG0Value :"<< MaxG0Value << "\n"; |
1447 | di<<"MaxG1Angle:"<< MaxG1Angle << "\n"; |
1448 | di<<"MaxG2Curvature:"<<MaxG2Curvature<<"\n"; |
1449 | return 0; |
1450 | } |
1451 | |
1452 | |
1453 | //======================================================================= |
1454 | //function : clintedge |
1455 | //purpose : |
1456 | //======================================================================= |
1457 | static Standard_Integer clintedge(Draw_Interpretor& di, |
1458 | Standard_Integer narg, const char** a) |
1459 | { |
1460 | char newname[255]; |
1461 | |
1462 | if (narg < 2) { |
1463 | //cout << "Usage: clintedge shape" << endl; |
586db386 |
1464 | di << "Usage: clintedge shape\n"; |
7fd59977 |
1465 | return 1; |
1466 | } |
1467 | TopoDS_Shape S = DBRep::Get(a[1]); |
1468 | |
1469 | TopTools_DataMapOfShapeListOfShape mymap; |
1470 | TopOpeBRepTool_PurgeInternalEdges mypurgealgo(S); |
773f53f1 |
1471 | Standard_Integer nbedges = mypurgealgo.NbEdges(); |
1472 | if (nbedges > 0) |
1473 | { |
7fd59977 |
1474 | //cout<<nbedges<<" internal (or external) edges to be removed"<<endl; |
586db386 |
1475 | di<<nbedges<<" internal (or external) edges to be removed\n"; |
7fd59977 |
1476 | |
1477 | Standard_Integer i = 1; |
1478 | char* temp = newname; |
1479 | |
91322f44 |
1480 | Sprintf(newname,"%s_%d",a[1],i); |
7fd59977 |
1481 | DBRep::Set(temp,mypurgealgo.Shape()); |
1482 | //cout<<newname<<" "; |
1483 | di<<newname<<" "; |
1484 | |
1485 | //cout<<endl; |
1486 | di<<"\n"; |
1487 | } |
1488 | else |
586db386 |
1489 | di << "no internal (or external) edges\n"; |
7fd59977 |
1490 | //cout << "no internal (or external) edges"<<endl; |
1491 | |
1492 | return 0; |
1493 | } |
1494 | |
1495 | |
1496 | //======================================================================= |
1497 | //function : facintedge |
1498 | //purpose : |
1499 | //======================================================================= |
1500 | static Standard_Integer facintedge(Draw_Interpretor& di, |
1501 | Standard_Integer narg, const char** a) |
1502 | { |
1503 | char newname[255]; |
1504 | |
1505 | if (narg < 2) { |
1506 | //cout << "Usage: facintedge shape" << endl; |
586db386 |
1507 | di << "Usage: facintedge shape\n"; |
7fd59977 |
1508 | return 1; |
1509 | } |
1510 | TopoDS_Shape S = DBRep::Get(a[1]); |
1511 | |
1512 | TopTools_DataMapOfShapeListOfShape mymap; |
1513 | TopOpeBRepTool_PurgeInternalEdges mypurgealgo(S); |
1514 | mypurgealgo.Faces(mymap); |
1515 | |
1516 | Standard_Integer i = 1; |
1517 | char* temp = newname; |
1518 | |
1519 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itFacEdg; |
1520 | for (itFacEdg.Initialize(mymap); itFacEdg.More(); itFacEdg.Next()) { |
91322f44 |
1521 | Sprintf(newname,"%s_%d",a[1],i); |
7fd59977 |
1522 | DBRep::Set(temp,itFacEdg.Key()); |
1523 | //cout<<newname<<" "; |
1524 | di<<newname<<" "; |
1525 | i++; |
1526 | } |
1527 | |
1528 | //cout<<endl; |
1529 | di<<"\n"; |
1530 | |
1531 | return 0; |
1532 | } |
1533 | |
1534 | //======================================================================= |
1535 | //function : fuseedge |
1536 | //purpose : |
1537 | //======================================================================= |
1538 | static Standard_Integer fuseedge(Draw_Interpretor& di, |
1539 | Standard_Integer narg, const char** a) |
1540 | { |
1541 | char newname[255]; |
1542 | |
1543 | if (narg < 2) { |
1544 | //cout << "Usage: fuseedge shape" << endl; |
586db386 |
1545 | di << "Usage: fuseedge shape\n"; |
7fd59977 |
1546 | return 1; |
1547 | } |
1548 | TopoDS_Shape S = DBRep::Get(a[1]); |
1549 | |
1550 | TopTools_DataMapOfIntegerListOfShape mymap; |
1551 | //TopOpeBRepTool_FuseEdges myfusealgo(S); |
1552 | BRepLib_FuseEdges myfusealgo(S); |
1553 | myfusealgo.SetConcatBSpl(); |
1554 | Standard_Integer nbvertices; |
1555 | nbvertices = myfusealgo.NbVertices(); |
1556 | |
1557 | if (nbvertices > 0) { |
1558 | |
1559 | //cout<<nbvertices<<" vertices to be removed"<<endl; |
586db386 |
1560 | di<<nbvertices<<" vertices to be removed\n"; |
7fd59977 |
1561 | |
1562 | Standard_Integer i = 1; |
1563 | char* temp = newname; |
1564 | |
91322f44 |
1565 | Sprintf(newname,"%s_%d",a[1],i); |
7fd59977 |
1566 | DBRep::Set(temp,myfusealgo.Shape()); |
1567 | //cout<<newname<<" "; |
1568 | di<<newname<<" "; |
1569 | |
1570 | //cout<<endl; |
1571 | di<<"\n"; |
1572 | } |
1573 | else |
586db386 |
1574 | di << "no vertices to remove\n"; |
7fd59977 |
1575 | //cout << "no vertices to remove"<<endl; |
1576 | |
1577 | return 0; |
1578 | } |
1579 | |
1580 | |
1581 | //======================================================================= |
1582 | //function : listfuseedge |
1583 | //purpose : |
1584 | //======================================================================= |
1585 | static Standard_Integer listfuseedge(Draw_Interpretor& di, |
1586 | Standard_Integer narg, const char** a) |
1587 | { |
1588 | char newname[255]; |
1589 | |
1590 | if (narg < 2) { |
1591 | //cout << "Usage: listfuseedge shape" << endl; |
586db386 |
1592 | di << "Usage: listfuseedge shape\n"; |
7fd59977 |
1593 | return 1; |
1594 | } |
1595 | TopoDS_Shape S = DBRep::Get(a[1]); |
1596 | |
1597 | TopTools_DataMapOfIntegerListOfShape mymap; |
1598 | BRepLib_FuseEdges myfusealgo(S); |
1599 | myfusealgo.Edges(mymap); |
1600 | |
1601 | Standard_Integer i; |
1602 | char* temp = newname; |
1603 | |
1604 | TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape itLstEdg; |
1605 | for (itLstEdg.Initialize(mymap); itLstEdg.More(); itLstEdg.Next()) { |
1606 | const Standard_Integer& iLst = itLstEdg.Key(); |
1607 | const TopTools_ListOfShape& LmapEdg = mymap.Find(iLst); |
1608 | TopTools_ListIteratorOfListOfShape itEdg; |
1609 | i = 1; |
1610 | for (itEdg.Initialize(LmapEdg); itEdg.More(); itEdg.Next()) { |
91322f44 |
1611 | Sprintf(newname,"%s_%d_%d",a[1],iLst,i); |
7fd59977 |
1612 | DBRep::Set(temp,itEdg.Value()); |
1613 | //cout<<newname<<" "; |
1614 | di<<newname<<" "; |
1615 | i++; |
1616 | } |
1617 | |
1618 | } |
1619 | |
1620 | //cout<<endl; |
1621 | di<<"\n"; |
1622 | |
1623 | return 0; |
1624 | } |
1625 | |
c0a1a35f |
1626 | //======================================================================= |
1627 | //function : tolsphere |
1628 | //purpose : |
1629 | //======================================================================= |
1630 | static Standard_Integer tolsphere(Draw_Interpretor& di, Standard_Integer n, const char** a) |
1631 | { |
1632 | if (n != 2) |
1633 | { |
1634 | di << "use toolsphere shape\n"; |
1635 | return 1; |
1636 | } |
1637 | |
1638 | TopoDS_Shape aS = DBRep::Get(a[1]); |
1639 | if (aS.IsNull()) |
1640 | { |
1641 | di << "No such shape " << a[1] << "\n"; |
1642 | return 1; |
1643 | } |
1644 | |
1645 | TopTools_IndexedMapOfShape aMapV; |
1646 | TopExp::MapShapes(aS, TopAbs_VERTEX, aMapV); |
1647 | for (Standard_Integer i = 1; i <= aMapV.Extent(); i++) |
1648 | { |
1649 | const TopoDS_Vertex& aV = TopoDS::Vertex(aMapV.FindKey(i)); |
1650 | Standard_Real aRadius = BRep_Tool::Tolerance(aV); |
1651 | gp_Pnt aCenter = BRep_Tool::Pnt(aV); |
1652 | Handle(Geom_Surface) aSph = new Geom_SphericalSurface(gp_Ax2(aCenter,gp::DZ()), aRadius); |
1653 | TCollection_AsciiString aName(a[1]); |
1654 | aName = aName + "_v" + i; |
1655 | DrawTrSurf::Set(aName.ToCString(), aSph); |
1656 | di << aName << " "; |
1657 | } |
1658 | return 0; |
1659 | } |
1660 | |
1661 | //======================================================================= |
1662 | //function : validrange |
1663 | //purpose : |
1664 | //======================================================================= |
1665 | static Standard_Integer validrange(Draw_Interpretor& di, |
1666 | Standard_Integer narg, const char** a) |
1667 | { |
1668 | if (narg < 2) |
1669 | { |
1670 | di << "usage: validrange edge [(out) u1 u2]"; |
1671 | return 1; |
1672 | } |
1673 | |
1674 | TopoDS_Edge aE = TopoDS::Edge(DBRep::Get(a[1],TopAbs_EDGE, true)); |
1675 | if (aE.IsNull()) |
1676 | return 1; |
7fd59977 |
1677 | |
c0a1a35f |
1678 | Standard_Real u1, u2; |
1679 | if (BRepLib::FindValidRange(aE, u1, u2)) |
1680 | { |
1681 | if (narg > 3) |
1682 | { |
1683 | Draw::Set(a[2], u1); |
1684 | Draw::Set(a[3], u2); |
1685 | } |
1686 | else |
1687 | { |
1688 | di << u1 << " " << u2; |
1689 | } |
1690 | } |
1691 | else |
1692 | di << "edge has no valid range"; |
1693 | return 0; |
1694 | } |
7fd59977 |
1695 | |
1696 | //======================================================================= |
1697 | //function : CheckCommands |
1698 | //purpose : |
1699 | //======================================================================= |
1700 | |
1701 | void BRepTest::CheckCommands(Draw_Interpretor& theCommands) |
1702 | { |
1703 | static Standard_Boolean done = Standard_False; |
1704 | if (done) return; |
1705 | done = Standard_True; |
1706 | |
1707 | BRepTest_CheckCommands_SetFaultyName("faulty_"); |
1708 | DBRep::BasicCommands(theCommands); |
1709 | |
1710 | const char* g = "TOPOLOGY Check commands"; |
1711 | |
1712 | // Modified by skv - Tue Apr 27 13:35:35 2004 Begin |
1713 | theCommands.Add("checkshape", |
1714 | "checkshape : no args to have help", |
1715 | __FILE__, |
1716 | checkshape, |
1717 | g); |
1718 | // theCommands.Add("checkshape", |
1719 | // "checks the validity of a shape : checkshape name,\n short description of check : checkshape name -short", |
1720 | // __FILE__, |
1721 | // CHK, |
1722 | // g); |
1723 | // theCommands.Add("checktopshape", |
1724 | // "checks the topological validity of a shape : checktopshape name", |
1725 | // __FILE__, |
1726 | // CHK, |
1727 | // g); |
1728 | // Modified by skv - Tue Apr 27 13:35:39 2004 End |
1729 | |
1730 | theCommands.Add("checksection", |
3306fdd9 |
1731 | "checks the closure of a section : checksection name [-r <RefVal>]\n" |
1732 | "\"-r\" - allowed number of allone vertices.", |
7fd59977 |
1733 | __FILE__, |
1734 | checksection, |
1735 | g); |
1736 | |
1737 | theCommands.Add("checkdiff", |
1738 | "checks the validity of the diff beetween the shapes arg1..argn and result :\n checkdiff arg1 [arg2..argn] result [closedSolid (1/0)] [geomCtrl (1/0)]", |
1739 | __FILE__, |
1740 | checkdiff, |
1741 | g); |
1742 | |
1743 | g = "TOPOLOGY Analysis of shapes "; |
1744 | |
1745 | theCommands.Add("shapeG0continuity", |
1746 | "shapeG0continuity shape edge nbeval [epsnul [epsG0]]", |
1747 | __FILE__, |
1748 | shapeG0continuity, g); |
1749 | |
1750 | theCommands.Add("shapeG1continuity", |
1751 | "shapeG1continuity shape edge nbeval [epsnul [epsG0 [epsG1]]]", |
1752 | __FILE__, |
1753 | shapeG1continuity ,g); |
1754 | theCommands.Add("shapeG2continuity", |
1755 | "shapeG2continuity shape edge nbeval [epsnul [epsG0 [epsG1 [maxlen [perce]]]]]", |
1756 | __FILE__, |
1757 | shapeG2continuity,g); |
1758 | |
1759 | theCommands.Add("computetolerance", |
1760 | "computetolerance shape", |
1761 | __FILE__, |
1762 | computetolerance,g); |
1763 | |
1764 | theCommands.Add("clintedge", |
1765 | "clintedge shape", |
1766 | __FILE__, |
1767 | clintedge,g); |
1768 | |
1769 | theCommands.Add("facintedge", |
1770 | "facintedge shape", |
1771 | __FILE__, |
1772 | facintedge,g); |
1773 | |
1774 | theCommands.Add("fuseedge", |
1775 | "fuseedge shape", |
1776 | __FILE__, |
1777 | fuseedge,g); |
1778 | |
1779 | theCommands.Add("listfuseedge", |
1780 | "listfuseedge shape", |
1781 | __FILE__, |
1782 | listfuseedge,g); |
c0a1a35f |
1783 | theCommands.Add("tolsphere", "toolsphere shape\n" |
1784 | "\t\tshows vertex tolerances by drawing spheres", |
1785 | __FILE__, tolsphere, g); |
1786 | theCommands.Add("validrange", |
1787 | "validrange edge [(out) u1 u2]\n" |
1788 | "\t\tcomputes valid range of the edge, and\n" |
1789 | "\t\tprints first and last values or sets the variables u1 and u2", |
1790 | __FILE__, validrange, g); |
7fd59977 |
1791 | } |
1792 | |