1 // Created on: 1996-02-23
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRepTest.hxx>
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>
37 #include <BRepTest.hxx>
38 #include <GeometryTest.hxx>
39 #include <Precision.hxx>
40 #include <LocalAnalysis.hxx>
41 #include <LocalAnalysis_SurfaceContinuity.hxx>
42 #include <Geom_SphericalSurface.hxx>
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>
49 #include <TCollection_AsciiString.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>
60 #include <TopOpeBRepTool_PurgeInternalEdges.hxx>
61 //#include <TopOpeBRepTool_FuseEdges.hxx>
62 #include <BRepLib.hxx>
63 #include <BRepLib_FuseEdges.hxx>
65 #include <TopTools_HSequenceOfShape.hxx>
66 #include <BRep_Builder.hxx>
67 #include <TopoDS_Compound.hxx>
68 #include <TColStd_HArray1OfInteger.hxx>
70 #include <Standard_ErrorHandler.hxx>
71 #include <Standard_Failure.hxx>
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)
78 static const Standard_Integer NumberOfStatus = 36;
80 static char* checkfaultyname = NULL;
81 Standard_EXPORT void BRepTest_CheckCommands_SetFaultyName(const char* name)
83 if (checkfaultyname != NULL) {
84 free(checkfaultyname);
85 checkfaultyname = NULL;
88 checkfaultyname = (char*)malloc(strlen("faulty_")+1);
89 strcpy(checkfaultyname,"faulty_");
92 checkfaultyname = (char*)malloc(strlen(name)+1);
93 strcpy(checkfaultyname,name);
98 static TopTools_DataMapOfShapeListOfShape theMap;
99 static Standard_Integer nbfaulty = 0;
100 static Draw_SequenceOfDrawable3D lfaulty;
102 Standard_IMPORT Standard_Integer BRepCheck_Trace(const Standard_Integer phase);
104 //=======================================================================
105 //function : FindNamed
106 //=======================================================================
107 static Standard_Boolean FindNamed(const TopoDS_Shape& S,
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;
118 return Standard_False;
122 //=======================================================================
123 //function : Contains
124 //=======================================================================
125 static Standard_Boolean Contains(const TopTools_ListOfShape& L,
126 const TopoDS_Shape& S)
128 TopTools_ListIteratorOfListOfShape it;
129 for (it.Initialize(L); it.More(); it.Next()) {
130 if (it.Value().IsSame(S)) {
131 return Standard_True;
134 return Standard_False;
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)
149 BRepCheck_ListIteratorOfListOfStatus itl;
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)) {
164 Name = (char*)malloc(18*sizeof(char));
165 Sprintf(Name,"%s%d",checkfaultyname,nbfaulty);
166 DBRep::Set(Name,sub);
167 lfaulty.Append(Draw::Get((Standard_CString&)Name));
169 OS << "Shape " << Name << " ";
170 if (!FindNamed(S,Name)) {
172 Name = (char*)malloc(18*sizeof(char));
173 Sprintf(Name,"%s%d",checkfaultyname,nbfaulty);
175 lfaulty.Append(Draw::Get((Standard_CString&)Name));
177 OS << " on shape " << Name << " :\n";
178 for (;itl.More(); itl.Next()) {
179 BRepCheck::Print(itl.Value(),OS);
189 //=======================================================================
191 //=======================================================================
192 static void Print(Standard_OStream& OS,
193 const BRepCheck_Analyzer& Ana,
194 const TopoDS_Shape& S)
196 for (TopoDS_Iterator iter(S); iter.More(); iter.Next()) {
197 Print(OS,Ana,iter.Value());
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)) {
208 Name = (char*)malloc(18*sizeof(char));
209 Sprintf(Name,"%s%d",checkfaultyname,nbfaulty);
211 lfaulty.Append(Draw::Get((Standard_CString&)Name));
213 OS << "On Shape " << Name << " :\n";
215 for (;itl.More(); itl.Next()) {
216 if (itl.Value() != BRepCheck_NoError)
217 BRepCheck::Print(itl.Value(),OS);
221 if (!theMap.IsBound(S)) {
222 TopTools_ListOfShape thelist;
223 theMap.Bind(S, thelist);
228 PrintSub(OS,Ana,S,TopAbs_VERTEX);
231 PrintSub(OS,Ana,S,TopAbs_EDGE);
232 PrintSub(OS,Ana,S,TopAbs_VERTEX);
235 PrintSub(OS,Ana,S,TopAbs_WIRE);
236 PrintSub(OS,Ana,S,TopAbs_EDGE);
237 PrintSub(OS,Ana,S,TopAbs_VERTEX);
240 // PrintSub(OS,Ana,S,TopAbs_FACE);
243 // PrintSub(OS,Ana,S,TopAbs_EDGE);
244 PrintSub(OS,Ana,S,TopAbs_SHELL);
252 //=======================================================================
253 //function : computetolerance
255 //=======================================================================
256 static Standard_Integer computetolerance(Draw_Interpretor& di,
257 Standard_Integer narg, const char** a)
260 //cout << "Usage: computetolerance shape" << endl;
261 di << "Usage: computetolerance shape\n";
264 TopoDS_Shape S = DBRep::Get(a[1]);
266 if (S.ShapeType() == TopAbs_EDGE) {
267 BRepCheck_Edge bce(TopoDS::Edge(S));
269 //cout<< "Tolerance de " << (void*) &(*S.TShape()) << " : " << tol << endl;
270 Standard_SStream aSStream1;
271 aSStream1<< "Tolerance de " << (void*) &(*S.TShape()) << " : " << tol << "\n";
275 TopTools_MapOfShape theEdges;
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()));
281 //cout<< "Tolerance de " << (void*) &(*exp.Current().TShape()) << " : " << tol << "\n";
282 Standard_SStream aSStream2;
283 aSStream2<< "Tolerance de " << (void*) &(*exp.Current().TShape()) << " : " << tol << "\n";
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)
301 di << a[0] << " shape [-r <ref_val>]\n";
305 Standard_Integer aCompareValue = -1;
306 TopoDS_Shape S = DBRep::Get(a[1]);
308 for (Standard_Integer anAI = 2; anAI < narg; anAI++)
310 if (!strcmp(a[anAI], "-r"))
312 aCompareValue = Draw::Atoi(a[++anAI]);
316 di << "Error: Wrong option" << a[anAI] << "\n";
320 TopTools_MapOfShape theVertices;
322 for (exp.Init(S, TopAbs_VERTEX); exp.More(); exp.Next()) {
323 if (!theVertices.Add(exp.Current()))
324 theVertices.Remove(exp.Current());
326 //cout << " nb alone Vertices : " << theVertices.Extent() << endl;
327 di << " nb alone Vertices : " << theVertices.Extent() << "\n";
329 if (aCompareValue >= 0)
331 if (theVertices.Extent() == aCompareValue)
333 di << "Section is OK\n";
337 di << "Error: "<< aCompareValue << " vertices are expected but " <<
338 theVertices.Extent() << " are found.\n";
343 Standard_Integer ipp=0;
344 TopTools_MapIteratorOfMapOfShape itvx;
345 for (itvx.Initialize(theVertices); itvx.More(); itvx.Next()) {
347 Sprintf(Name,"alone_%d",ipp);
348 DBRep::Set(Name, itvx.Key());
349 //cout << Name << " " ;
356 //=======================================================================
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)
365 const char* syntaxe = "checkdiff arg1 [arg2..argn] result [closedSolid (0/1)] [geomCtrl (1/0)]";
368 Standard_Integer bcrtrace=Draw::Atoi(a[narg-1]);
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";
376 //cout << syntaxe << endl;
377 di << syntaxe << "\n";
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]);
387 //cout << syntaxe << endl;
388 di << syntaxe << "\n";
391 closedSolid = Draw::Atoi(a[narg-1]) != 0;
392 resu = DBRep::Get(a[narg-2]);
396 //cout << syntaxe << endl;
397 di << syntaxe << "\n";
400 geomCtrl=closedSolid;
401 closedSolid = Draw::Atoi(a[narg-2]) != 0;
402 resu = DBRep::Get(a[narg-3]);
405 //cout << syntaxe << endl;
406 di << syntaxe << "\n";
412 TopTools_ListOfShape lesArgs;
413 for (Standard_Integer id=1; id <=lastArg; id++) {
414 lesArgs.Append(DBRep::Get(a[id]));
417 if (BRepAlgo::IsValid(lesArgs, resu, closedSolid, geomCtrl)) {
418 //cout << "Difference is Valid." << endl;
419 di << "Difference is Valid.\n";
421 //cout << "error : Difference is Not Valid !" << endl;
422 di << "error : Difference is Not Valid !\n";
427 //=======================================================================
429 // Modified by skv - Tue Apr 27 13:38:44 2004 Begin
430 //=======================================================================
432 //purpose : Checks a shape
433 //=======================================================================
435 // static Standard_Integer CHK(Draw_Interpretor& theCommands,
436 // Standard_Integer narg, const char** a)
442 // Standard_Boolean doprint = Standard_True;
443 // if (narg == 3) { if (!strcmp(a[2],"-short")) doprint = Standard_False; }
445 // TopoDS_Shape S = DBRep::Get(a[1]);
447 // cout<<"not a topological shape"<<endl;
451 // Standard_Boolean GeomCtrl = Standard_True;
452 // if (!strcasecmp(a[0],"CHECKTOPSHAPE")) {
453 // GeomCtrl = Standard_False;
456 // BRepCheck_Analyzer ana(S,GeomCtrl);
457 // if (ana.IsValid()) {
458 // theCommands<<"This shape seems to be valid";
466 // Print(cout,ana,S);
470 // cout<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n";
474 // theCommands<<"This shape has faulty shapes";
480 //=======================================================================
481 //function : ContextualDump
482 //purpose : Contextual (modeling) style of output.
483 //=======================================================================
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)
495 //Print(cout, theAna, theShape);
496 Standard_SStream aSStream;
497 Print(aSStream, theAna, theShape);
498 theCommands << aSStream;
504 theCommands<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n";
505 //cout<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n";
512 //=======================================================================
513 //function : FillProblems
514 // purpose : auxilary for StructuralDump
515 //=======================================================================
516 static void FillProblems(const BRepCheck_Status stat,
517 Handle(TColStd_HArray1OfInteger)& NbProblems)
520 const Standard_Integer anID = static_cast<Standard_Integer> (stat);
522 if((NbProblems->Upper() < anID) || (NbProblems->Lower() > anID))
525 NbProblems->SetValue(anID, NbProblems->Value(anID)+1);
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)
540 BRepCheck_ListIteratorOfListOfStatus itl;
542 for (exp.Init(Shape,Subtype); exp.More(); exp.Next()) {
543 const Handle(BRepCheck_Result)& res = Ana.Result(exp.Current());
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());
554 if (itl.Value() != BRepCheck_NoError) {
555 Standard_Integer ii = 0;
557 for(ii=1; ii<=sl->Length(); ii++)
558 if(sl->Value(ii).IsSame(sub)) break;
560 if(ii>sl->Length()) {
562 FillProblems(itl.Value(),NbProblems);
564 for(ii=1; ii<=sl->Length(); ii++)
565 if(sl->Value(ii).IsSame(Shape)) break;
566 if(ii>sl->Length()) {
568 FillProblems(itl.Value(),NbProblems);
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)
587 for (TopoDS_Iterator iter(Shape); iter.More(); iter.Next()) {
588 GetProblemShapes(Ana,iter.Value(),sl, NbProblems);
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());
595 if (itl.Value() != BRepCheck_NoError) {
597 FillProblems(itl.Value(),NbProblems);
600 if (!theMap.IsBound(Shape)) {
601 TopTools_ListOfShape thelist;
602 theMap.Bind(Shape, thelist);
607 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_VERTEX);
610 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_WIRE);
611 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_EDGE);
612 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_VERTEX);
617 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_SHELL);
625 //=======================================================================
626 //function : StructuralDump
627 //purpose : Structural (data exchange) style of output.
628 //=======================================================================
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)
641 //cout << "StructuralDump" << endl;
642 //cout << " -- The Shape " << ShName << " has problems :"<<endl;
643 //cout<<" Check Count"<<endl;
644 //cout<<" ------------------------------------------------"<<endl;
645 theCommands << " -- The Shape " << ShName << " has problems :\n";
646 theCommands<<" Check Count\n";
647 theCommands<<" ------------------------------------------------\n";
649 Handle(TColStd_HArray1OfInteger) NbProblems = new
650 TColStd_HArray1OfInteger(1,NumberOfStatus);
651 for(i=1; i<=NumberOfStatus; i++) NbProblems->SetValue(i,0);
652 Handle(TopTools_HSequenceOfShape) sl,slv,sle,slw,slf,sls,slo;
653 sl = new TopTools_HSequenceOfShape();
655 GetProblemShapes(theAna, theShape, sl, NbProblems);
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";
662 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidPointOnCurveOnSurface);
663 if(NbProblems->Value(aProblemID)>0)
664 theCommands<<" Invalid Point on CurveOnSurface .......... "<<NbProblems->Value(aProblemID)<<"\n";
666 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidPointOnSurface);
667 if(NbProblems->Value(aProblemID)>0)
668 theCommands<<" Invalid Point on Surface ................. "<<NbProblems->Value(aProblemID)<<"\n";
670 aProblemID = static_cast<Standard_Integer>(BRepCheck_No3DCurve);
671 if(NbProblems->Value(aProblemID)>0)
672 theCommands<<" No 3D Curve .............................. "<<NbProblems->Value(aProblemID)<<"\n";
674 aProblemID = static_cast<Standard_Integer>(BRepCheck_Multiple3DCurve);
675 if(NbProblems->Value(aProblemID)>0)
676 theCommands<<" Multiple 3D Curve ........................ "<<NbProblems->Value(aProblemID)<<"\n";
678 aProblemID = static_cast<Standard_Integer>(BRepCheck_Invalid3DCurve);
679 if(NbProblems->Value(aProblemID)>0)
680 theCommands<<" Invalid 3D Curve ......................... "<<NbProblems->Value(aProblemID)<<"\n";
682 aProblemID = static_cast<Standard_Integer>(BRepCheck_NoCurveOnSurface);
683 if(NbProblems->Value(aProblemID)>0)
684 theCommands<<" No Curve on Surface ...................... "<<NbProblems->Value(aProblemID)<<"\n";
686 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidCurveOnSurface);
687 if(NbProblems->Value(aProblemID)>0)
688 theCommands<<" Invalid Curve on Surface ................. "<<NbProblems->Value(aProblemID)<<"\n";
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";
694 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidSameRangeFlag);
695 if(NbProblems->Value(aProblemID)>0)
696 theCommands<<" Invalid SameRange Flag ................... "<<NbProblems->Value(aProblemID)<<"\n";
698 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidSameParameterFlag);
699 if(NbProblems->Value(aProblemID)>0)
700 theCommands<<" Invalid SameParameter Flag ............... "<<NbProblems->Value(aProblemID)<<"\n";
702 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidDegeneratedFlag);
703 if(NbProblems->Value(aProblemID)>0)
704 theCommands<<" Invalid Degenerated Flag ................. "<<NbProblems->Value(aProblemID)<<"\n";
706 aProblemID = static_cast<Standard_Integer>(BRepCheck_FreeEdge);
707 if(NbProblems->Value(aProblemID)>0)
708 theCommands<<" Free Edge ................................ "<<NbProblems->Value(aProblemID)<<"\n";
710 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidMultiConnexity);
711 if(NbProblems->Value(aProblemID)>0)
712 theCommands<<" Invalid MultiConnexity ................... "<<NbProblems->Value(aProblemID)<<"\n";
714 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidRange);
715 if(NbProblems->Value(aProblemID)>0)
716 theCommands<<" Invalid Range ............................ "<<NbProblems->Value(aProblemID)<<"\n";
718 aProblemID = static_cast<Standard_Integer>(BRepCheck_EmptyWire);
719 if(NbProblems->Value(aProblemID)>0)
720 theCommands<<" Empty Wire ............................... "<<NbProblems->Value(aProblemID)<<"\n";
722 aProblemID = static_cast<Standard_Integer>(BRepCheck_RedundantEdge);
723 if(NbProblems->Value(aProblemID)>0)
724 theCommands<<" Redundant Edge ........................... "<<NbProblems->Value(aProblemID)<<"\n";
726 aProblemID = static_cast<Standard_Integer>(BRepCheck_SelfIntersectingWire);
727 if(NbProblems->Value(aProblemID)>0)
728 theCommands<<" Self Intersecting Wire ................... "<<NbProblems->Value(aProblemID)<<"\n";
730 aProblemID = static_cast<Standard_Integer>(BRepCheck_NoSurface);
731 if(NbProblems->Value(aProblemID)>0)
732 theCommands<<" No Surface ............................... "<<NbProblems->Value(aProblemID)<<"\n";
734 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidWire);
735 if(NbProblems->Value(aProblemID)>0)
736 theCommands<<" Invalid Wire ............................. "<<NbProblems->Value(aProblemID)<<"\n";
738 aProblemID = static_cast<Standard_Integer>(BRepCheck_RedundantWire);
739 if(NbProblems->Value(aProblemID)>0)
740 theCommands<<" Redundant Wire ........................... "<<NbProblems->Value(aProblemID)<<"\n";
742 aProblemID = static_cast<Standard_Integer>(BRepCheck_IntersectingWires);
743 if(NbProblems->Value(aProblemID)>0)
744 theCommands<<" Intersecting Wires ....................... "<<NbProblems->Value(aProblemID)<<"\n";
746 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidImbricationOfWires);
747 if(NbProblems->Value(aProblemID)>0)
748 theCommands<<" Invalid Imbrication of Wires ............. "<<NbProblems->Value(aProblemID)<<"\n";
750 aProblemID = static_cast<Standard_Integer>(BRepCheck_EmptyShell);
751 if(NbProblems->Value(aProblemID)>0)
752 theCommands<<" Empty Shell .............................. "<<NbProblems->Value(aProblemID)<<"\n";
754 aProblemID = static_cast<Standard_Integer>(BRepCheck_RedundantFace);
755 if(NbProblems->Value(aProblemID)>0)
756 theCommands<<" Redundant Face ........................... "<<NbProblems->Value(aProblemID)<<"\n";
758 aProblemID = static_cast<Standard_Integer>(BRepCheck_UnorientableShape);
759 if(NbProblems->Value(aProblemID)>0)
760 theCommands<<" Unorientable Shape ....................... "<<NbProblems->Value(aProblemID)<<"\n";
762 aProblemID = static_cast<Standard_Integer>(BRepCheck_NotClosed);
763 if(NbProblems->Value(aProblemID)>0)
764 theCommands<<" Not Closed ............................... "<<NbProblems->Value(aProblemID)<<"\n";
766 aProblemID = static_cast<Standard_Integer>(BRepCheck_NotConnected);
767 if(NbProblems->Value(aProblemID)>0)
768 theCommands<<" Not Connected ............................ "<<NbProblems->Value(aProblemID)<<"\n";
770 aProblemID = static_cast<Standard_Integer>(BRepCheck_SubshapeNotInShape);
771 if(NbProblems->Value(aProblemID)>0)
772 theCommands<<" Subshape not in Shape .................... "<<NbProblems->Value(aProblemID)<<"\n";
774 aProblemID = static_cast<Standard_Integer>(BRepCheck_BadOrientation);
775 if(NbProblems->Value(aProblemID)>0)
776 theCommands<<" Bad Orientation .......................... "<<NbProblems->Value(aProblemID)<<"\n";
778 aProblemID = static_cast<Standard_Integer>(BRepCheck_BadOrientationOfSubshape);
779 if(NbProblems->Value(aProblemID)>0)
780 theCommands<<" Bad Orientation of Subshape .............. "<<NbProblems->Value(aProblemID)<<"\n";
782 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidToleranceValue);
783 if(NbProblems->Value(aProblemID)>0)
784 theCommands<<" Invalid tolerance value................... "<<NbProblems->Value(aProblemID)<<"\n";
786 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidPolygonOnTriangulation);
787 if(NbProblems->Value(aProblemID)>0)
788 theCommands<<" Invalid polygon on triangulation.......... "<<NbProblems->Value(aProblemID)<<"\n";
790 aProblemID = static_cast<Standard_Integer>(BRepCheck_InvalidImbricationOfShells);
791 if(NbProblems->Value(aProblemID)>0)
792 theCommands<<" Invalid Imbrication of Shells............. "<<NbProblems->Value(aProblemID)<<"\n";
794 aProblemID = static_cast<Standard_Integer>(BRepCheck_EnclosedRegion);
795 if(NbProblems->Value(aProblemID)>0)
796 theCommands<<" Enclosed Region........................... "<<NbProblems->Value(aProblemID)<<"\n";
798 aProblemID = static_cast<Standard_Integer>(BRepCheck_CheckFail);
799 if(NbProblems->Value(aProblemID)>0)
800 theCommands<<" checkshape failure........................ "<<NbProblems->Value(aProblemID)<<"\n";
804 theCommands<<" ------------------------------------------------\n";
805 theCommands<<"*** Shapes with problems : "<<sl->Length()<<"\n";
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();
814 for(i=1; i<=sl->Length(); i++) {
815 TopoDS_Shape shi = sl->Value(i);
816 TopAbs_ShapeEnum sti = shi.ShapeType();
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;
829 if(slv->Length()>0) {
830 TopoDS_Compound comp;
831 B.MakeCompound(comp);
832 Standard_Integer nb = slv->Length();
834 B.Add(comp,slv->Value(i));
836 Sprintf(aName,"%s_v",Pref);
837 DBRep::Set(aName,comp);
838 //cout<<"VERTEX : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
840 theCommands<<"VERTEX : "<<nb<<" Items -> compound named "<<aName<<"\n";
842 theCommands<<"VERTEX : "<<nb<<" Items -> compound named "<<aName<<"\n";
844 if(sle->Length()>0) {
845 TopoDS_Compound comp;
846 B.MakeCompound(comp);
847 Standard_Integer nb = sle->Length();
849 B.Add(comp,sle->Value(i));
851 Sprintf(aName,"%s_e",Pref);
852 DBRep::Set(aName,comp);
853 //cout<<"EDGE : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
855 theCommands<<"EDGE : "<<nb<<" Items -> compound named "<<aName<<"\n";
857 theCommands<<"EDGE : "<<nb<<" Items -> compound named "<<aName<<"\n";
859 if(slw->Length()>0) {
860 TopoDS_Compound comp;
861 B.MakeCompound(comp);
862 Standard_Integer nb = slw->Length();
864 B.Add(comp,slw->Value(i));
866 Sprintf(aName,"%s_w",Pref);
867 DBRep::Set(aName,comp);
868 //cout<<"WIRE : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
870 theCommands<<"WIRE : "<<nb<<" Items -> compound named "<<aName<<"\n";
872 theCommands<<"WIRE : "<<nb<<" Items -> compound named "<<aName<<"\n";
874 if(slf->Length()>0) {
875 TopoDS_Compound comp;
876 B.MakeCompound(comp);
877 Standard_Integer nb = slf->Length();
879 B.Add(comp,slf->Value(i));
881 Sprintf(aName,"%s_f",Pref);
882 DBRep::Set(aName,comp);
883 //cout<<"FACE : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
885 theCommands<<"FACE : "<<nb<<" Items -> compound named "<<aName<<"\n";
887 theCommands<<"FACE : "<<nb<<" Items -> compound named "<<aName<<"\n";
889 if(sls->Length()>0) {
890 TopoDS_Compound comp;
891 B.MakeCompound(comp);
892 Standard_Integer nb = sls->Length();
894 B.Add(comp,sls->Value(i));
896 Sprintf(aName,"%s_s",Pref);
897 DBRep::Set(aName,comp);
898 //cout<<"SHELL : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
900 theCommands<<"SHELL : "<<nb<<" Items -> compound named "<<aName<<"\n";
902 theCommands<<"SHELL : "<<nb<<" Items -> compound named "<<aName<<"\n";
904 if(slo->Length()>0) {
905 TopoDS_Compound comp;
906 B.MakeCompound(comp);
907 Standard_Integer nb = slo->Length();
909 B.Add(comp,slo->Value(i));
911 Sprintf(aName,"%s_o",Pref);
912 DBRep::Set(aName,comp);
913 //cout<<"SOLID : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
915 theCommands<<"SOLID : "<<nb<<" Items -> compound named "<<aName<<"\n";
917 theCommands<<"SOLID : "<<nb<<" Items -> compound named "<<aName<<"\n";
921 //=======================================================================
922 //function : checkshape
923 //purpose : Checks a shape
924 //=======================================================================
926 static Standard_Integer checkshape(Draw_Interpretor& theCommands,
927 Standard_Integer narg, const char** a)
931 //cout << "Usage : checkshape [-top] shape [result] [-short]" << 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;
940 theCommands << "Usage : checkshape [-top] shape [result] [-short]\n";
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";
953 //cout << "Invalid number of args!!!" << endl;
954 //cout << "No args to have help." << endl;
955 theCommands << "Invalid number of args!!!\n";
956 theCommands << "No args to have help.\n";
961 Standard_Boolean aGeomCtrl = Standard_True;
962 Standard_Integer aCurInd = 1;
964 if (!strcmp(a[1],"-top")) {
965 aGeomCtrl = Standard_False;
969 if (aCurInd > narg - 1) {
970 //cout << "Invalid number of args!!!" << endl;
971 //cout << "No args to have help." << endl;
972 theCommands << "Invalid number of args!!!\n";
973 theCommands << "No args to have help.\n";
978 Standard_CString aShapeName = a[aCurInd];
979 TopoDS_Shape aShape = DBRep::Get(aShapeName);
981 if (aShape.IsNull()) {
982 //cout << a[aCurInd] << " is not a topological shape!!!" << endl;
983 theCommands << a[aCurInd] << " is not a topological shape!!!\n";
988 Standard_Boolean IsShortDump = Standard_False;
989 Standard_Boolean IsContextDump = Standard_True;
990 Standard_Integer aBackInd = narg - 1;
992 if (aCurInd < aBackInd) {
993 if (!strcmp(a[aBackInd],"-short")) {
994 IsShortDump = Standard_True;
999 if (aCurInd < aBackInd - 1) {
1000 //cout << "Invalid number of args!!!" << endl;
1001 //cout << "No args to have help." << endl;
1002 theCommands << "Invalid number of args!!!\n";
1003 theCommands << "No args to have help.\n";
1006 } else if (aCurInd < aBackInd) {
1007 IsContextDump = Standard_False;
1012 BRepCheck_Analyzer anAna(aShape,aGeomCtrl);
1013 Standard_Boolean isValid = anAna.IsValid();
1016 if (IsContextDump) {
1017 theCommands << "This shape seems to be valid";
1019 theCommands << " -- The Shape " << aShapeName << " looks OK";
1023 theCommands<<"This shape has faulty shapes";
1025 if (IsContextDump) {
1026 //ContextualDump(anAna, aShape);
1027 ContextualDump(theCommands, anAna, aShape);
1029 Standard_CString aPref = a[aCurInd+1];
1030 //StructuralDump(anAna, aShapeName, aPref, aShape);
1031 StructuralDump(theCommands, anAna, aShapeName, aPref, aShape);
1036 catch(Standard_Failure const& anException) {
1037 theCommands<<"checkshape exception : ";
1038 theCommands << anException.GetMessageString();
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 )
1060 static Standard_Integer shapeG1continuity (Draw_Interpretor& di, Standard_Integer n, const char** a)
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;
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);
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());
1084 face2=TopoDS::Face(It.Value());
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;
1094 Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1);
1096 Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2);
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;
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;
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;
1121 nbeval = (Standard_Integer ) Draw::Atof( a[3]);
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
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);
1145 deltaU = Abs(parf1- pard1)/nbeval;
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();
1153 {if (res.C0Value()>MaxG0Value) MaxG0Value = res.C0Value();
1154 if (res.G1Angle ()>MaxG1Angle) MaxG1Angle = res.G1Angle();}}
1155 else isconti = Standard_False;}
1157 else {LocalAnalysis_SurfaceContinuity res (curv1, curv2, (U+nb*deltaU ), surf1,surf2, GeomAbs_G1,epsnl,epsC0, epsC1, epsC2, epsG1,
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();;}
1166 else isconti = Standard_False;}
1167 if (!isconti) ISG1=Standard_False;
1171 while ((nb<nbeval)&& isdone );
1173 //if (!isdone) { cout<<" Problem in computation "<<endl; return 1;}
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;
1179 if (!isdone) { di<<" Problem in computation \n"; return 1;}
1181 {di<<" the continuity is G1 \n";}
1182 else { di<<" the continuity is not G1 \n";}
1183 di<<"MaxG0Value :"<< MaxG0Value << "\n";
1184 di<<"MaxG1Angle:"<< MaxG1Angle << "\n";
1187 /*****************************************************************************/
1188 static Standard_Integer shapeG0continuity (Draw_Interpretor& di, Standard_Integer n, const char** a)
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 );
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);
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());
1213 face2=TopoDS::Face(It.Value());
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;
1223 Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1);
1225 Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2);
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;
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;
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;
1250 nbeval = (Standard_Integer ) Draw::Atof( a[3]);
1254 case 6 : epsC0 = Draw::Atof(a[5]);
1255 Standard_FALLTHROUGH
1256 case 5 : epsnl = Draw::Atof(a[4]);
1257 Standard_FALLTHROUGH
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);
1271 deltaU = Abs(parf1- pard1)/nbeval;
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( );
1279 if (res.C0Value()>MaxG0Value) MaxG0Value= res.C0Value();}
1280 else isconti = Standard_False;}
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();}
1288 else isconti = Standard_False;}
1291 if (!isconti) ISG0=Standard_False;
1294 while ((nb<nbeval)&& isdone );
1296 //f (!isdone) { cout<<" Problem in computation "<<endl; return 1;}
1298 // {cout<<" the continuity is G0 "<<endl;}
1300 //else { cout<<" the continuity is not G0 "<<endl;}
1301 //cout<<"MaxG0Value :"<< MaxG0Value << endl;
1302 if (!isdone) { di<<" Problem in computation \n"; return 1;}
1304 {di<<" the continuity is G0 \n";}
1306 else { di<<" the continuity is not G0 \n";}
1307 di<<"MaxG0Value :"<< MaxG0Value << "\n";
1310 /*****************************************************************************************/
1311 static Standard_Integer shapeG2continuity (Draw_Interpretor& di, Standard_Integer n, const char** a)
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 );
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);
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());
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;
1346 Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1);
1348 Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2);
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;
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;
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;
1373 nbeval = (Standard_Integer ) Draw::Atof( a[3]);
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
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);
1400 deltaU = Abs(parf1- pard1)/nbeval;
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();
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();
1413 else isconti = Standard_False;}
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;}
1430 if (!isconti) ISG2=Standard_False;
1433 while ((nb<nbeval)&& isdone );
1435 //if (!isdone) { cout<<" Problem in computation "<<endl; return 1;}
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;
1442 if (!isdone) { di<<" Problem in computation \n"; return 1;}
1444 di<<" the continuity is G2 \n";
1445 else di<<" the continuity is not G2 \n";
1446 di<<"MaxG0Value :"<< MaxG0Value << "\n";
1447 di<<"MaxG1Angle:"<< MaxG1Angle << "\n";
1448 di<<"MaxG2Curvature:"<<MaxG2Curvature<<"\n";
1453 //=======================================================================
1454 //function : clintedge
1456 //=======================================================================
1457 static Standard_Integer clintedge(Draw_Interpretor& di,
1458 Standard_Integer narg, const char** a)
1463 //cout << "Usage: clintedge shape" << endl;
1464 di << "Usage: clintedge shape\n";
1467 TopoDS_Shape S = DBRep::Get(a[1]);
1469 TopTools_DataMapOfShapeListOfShape mymap;
1470 TopOpeBRepTool_PurgeInternalEdges mypurgealgo(S);
1471 Standard_Integer nbedges = mypurgealgo.NbEdges();
1474 //cout<<nbedges<<" internal (or external) edges to be removed"<<endl;
1475 di<<nbedges<<" internal (or external) edges to be removed\n";
1477 Standard_Integer i = 1;
1478 char* temp = newname;
1480 Sprintf(newname,"%s_%d",a[1],i);
1481 DBRep::Set(temp,mypurgealgo.Shape());
1482 //cout<<newname<<" ";
1489 di << "no internal (or external) edges\n";
1490 //cout << "no internal (or external) edges"<<endl;
1496 //=======================================================================
1497 //function : facintedge
1499 //=======================================================================
1500 static Standard_Integer facintedge(Draw_Interpretor& di,
1501 Standard_Integer narg, const char** a)
1506 //cout << "Usage: facintedge shape" << endl;
1507 di << "Usage: facintedge shape\n";
1510 TopoDS_Shape S = DBRep::Get(a[1]);
1512 TopTools_DataMapOfShapeListOfShape mymap;
1513 TopOpeBRepTool_PurgeInternalEdges mypurgealgo(S);
1514 mypurgealgo.Faces(mymap);
1516 Standard_Integer i = 1;
1517 char* temp = newname;
1519 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itFacEdg;
1520 for (itFacEdg.Initialize(mymap); itFacEdg.More(); itFacEdg.Next()) {
1521 Sprintf(newname,"%s_%d",a[1],i);
1522 DBRep::Set(temp,itFacEdg.Key());
1523 //cout<<newname<<" ";
1534 //=======================================================================
1535 //function : fuseedge
1537 //=======================================================================
1538 static Standard_Integer fuseedge(Draw_Interpretor& di,
1539 Standard_Integer narg, const char** a)
1544 //cout << "Usage: fuseedge shape" << endl;
1545 di << "Usage: fuseedge shape\n";
1548 TopoDS_Shape S = DBRep::Get(a[1]);
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();
1557 if (nbvertices > 0) {
1559 //cout<<nbvertices<<" vertices to be removed"<<endl;
1560 di<<nbvertices<<" vertices to be removed\n";
1562 Standard_Integer i = 1;
1563 char* temp = newname;
1565 Sprintf(newname,"%s_%d",a[1],i);
1566 DBRep::Set(temp,myfusealgo.Shape());
1567 //cout<<newname<<" ";
1574 di << "no vertices to remove\n";
1575 //cout << "no vertices to remove"<<endl;
1581 //=======================================================================
1582 //function : listfuseedge
1584 //=======================================================================
1585 static Standard_Integer listfuseedge(Draw_Interpretor& di,
1586 Standard_Integer narg, const char** a)
1591 //cout << "Usage: listfuseedge shape" << endl;
1592 di << "Usage: listfuseedge shape\n";
1595 TopoDS_Shape S = DBRep::Get(a[1]);
1597 TopTools_DataMapOfIntegerListOfShape mymap;
1598 BRepLib_FuseEdges myfusealgo(S);
1599 myfusealgo.Edges(mymap);
1602 char* temp = newname;
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;
1610 for (itEdg.Initialize(LmapEdg); itEdg.More(); itEdg.Next()) {
1611 Sprintf(newname,"%s_%d_%d",a[1],iLst,i);
1612 DBRep::Set(temp,itEdg.Value());
1613 //cout<<newname<<" ";
1626 //=======================================================================
1627 //function : tolsphere
1629 //=======================================================================
1630 static Standard_Integer tolsphere(Draw_Interpretor& di, Standard_Integer n, const char** a)
1634 di << "use toolsphere shape\n";
1638 TopoDS_Shape aS = DBRep::Get(a[1]);
1641 di << "No such shape " << a[1] << "\n";
1645 TopTools_IndexedMapOfShape aMapV;
1646 TopExp::MapShapes(aS, TopAbs_VERTEX, aMapV);
1647 for (Standard_Integer i = 1; i <= aMapV.Extent(); i++)
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);
1661 //=======================================================================
1662 //function : validrange
1664 //=======================================================================
1665 static Standard_Integer validrange(Draw_Interpretor& di,
1666 Standard_Integer narg, const char** a)
1670 di << "usage: validrange edge [(out) u1 u2]";
1674 TopoDS_Edge aE = TopoDS::Edge(DBRep::Get(a[1],TopAbs_EDGE, true));
1678 Standard_Real u1, u2;
1679 if (BRepLib::FindValidRange(aE, u1, u2))
1683 Draw::Set(a[2], u1);
1684 Draw::Set(a[3], u2);
1688 di << u1 << " " << u2;
1692 di << "edge has no valid range";
1696 //=======================================================================
1697 //function : CheckCommands
1699 //=======================================================================
1701 void BRepTest::CheckCommands(Draw_Interpretor& theCommands)
1703 static Standard_Boolean done = Standard_False;
1705 done = Standard_True;
1707 BRepTest_CheckCommands_SetFaultyName("faulty_");
1708 DBRep::BasicCommands(theCommands);
1710 const char* g = "TOPOLOGY Check commands";
1712 // Modified by skv - Tue Apr 27 13:35:35 2004 Begin
1713 theCommands.Add("checkshape",
1714 "checkshape : no args to have help",
1718 // theCommands.Add("checkshape",
1719 // "checks the validity of a shape : checkshape name,\n short description of check : checkshape name -short",
1723 // theCommands.Add("checktopshape",
1724 // "checks the topological validity of a shape : checktopshape name",
1728 // Modified by skv - Tue Apr 27 13:35:39 2004 End
1730 theCommands.Add("checksection",
1731 "checks the closure of a section : checksection name [-r <RefVal>]\n"
1732 "\"-r\" - allowed number of allone vertices.",
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)]",
1743 g = "TOPOLOGY Analysis of shapes ";
1745 theCommands.Add("shapeG0continuity",
1746 "shapeG0continuity shape edge nbeval [epsnul [epsG0]]",
1748 shapeG0continuity, g);
1750 theCommands.Add("shapeG1continuity",
1751 "shapeG1continuity shape edge nbeval [epsnul [epsG0 [epsG1]]]",
1753 shapeG1continuity ,g);
1754 theCommands.Add("shapeG2continuity",
1755 "shapeG2continuity shape edge nbeval [epsnul [epsG0 [epsG1 [maxlen [perce]]]]]",
1757 shapeG2continuity,g);
1759 theCommands.Add("computetolerance",
1760 "computetolerance shape",
1762 computetolerance,g);
1764 theCommands.Add("clintedge",
1769 theCommands.Add("facintedge",
1774 theCommands.Add("fuseedge",
1779 theCommands.Add("listfuseedge",
1780 "listfuseedge shape",
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);