1 // Created on: 1996-02-23
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // modified by mps (dec 96) ajout des commandes pour l'analyse de continuite
23 #include <BRepTest.hxx>
28 #include <BRepAlgo.hxx>
29 #include <BRepCheck_Analyzer.hxx>
30 #include <BRepCheck_Result.hxx>
31 #include <BRepCheck_ListIteratorOfListOfStatus.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <TopTools_DataMapOfShapeListOfShape.hxx>
35 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
36 #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
37 #include <TopTools_ListOfShape.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
39 #include <DBRep_DrawableShape.hxx>
40 #include <Draw_SequenceOfDrawable3D.hxx>
41 #include <BRepCheck.hxx>
42 #include <BRepCheck_Edge.hxx>
43 #include <Draw_Interpretor.hxx>
44 #include <Draw_Appli.hxx>
47 #include <BRepTest.hxx>
48 #include <GeometryTest.hxx>
49 #include <Precision.hxx>
50 #include <LocalAnalysis.hxx>
51 #include <LocalAnalysis_SurfaceContinuity.hxx>
52 #include <Geom_Surface.hxx>
53 #include <Geom_Curve.hxx>
54 #include <Geom2d_TrimmedCurve.hxx>
55 #include <Geom2d_Curve.hxx>
56 #include <DrawTrSurf.hxx>
57 #include <GeomAbs_Shape.hxx>
60 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
61 #include <TopTools_MapOfShape.hxx>
62 #include <TopTools_MapIteratorOfMapOfShape.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <TopoDS_Edge.hxx>
65 #include <TopoDS_Face.hxx>
66 #include <BRep_Tool.hxx>
68 #include <TopOpeBRepTool_PurgeInternalEdges.hxx>
69 //#include <TopOpeBRepTool_FuseEdges.hxx>
70 #include <BRepLib_FuseEdges.hxx>
72 #include <TopTools_HSequenceOfShape.hxx>
73 #include <BRep_Builder.hxx>
74 #include <TopoDS_Compound.hxx>
75 #include <TColStd_HArray1OfInteger.hxx>
77 #include <Standard_ErrorHandler.hxx>
78 #include <Standard_Failure.hxx>
83 //#define strcasecmp strcmp Already defined
89 static char* checkfaultyname = NULL;
90 Standard_EXPORT void BRepTest_CheckCommands_SetFaultyName(const char* name)
92 if (checkfaultyname != NULL) {
93 free(checkfaultyname);
94 checkfaultyname = NULL;
97 checkfaultyname = (char*)malloc(strlen("faulty_")+1);
98 strcpy(checkfaultyname,"faulty_");
101 checkfaultyname = (char*)malloc(strlen(name)+1);
102 strcpy(checkfaultyname,name);
107 static TopTools_DataMapOfShapeListOfShape theMap;
108 static Standard_Integer nbfaulty = 0;
109 static Draw_SequenceOfDrawable3D lfaulty;
111 Standard_IMPORT Standard_Integer BRepCheck_Trace(const Standard_Integer phase);
113 //=======================================================================
114 //function : FindNamed
115 //=======================================================================
116 static Standard_Boolean FindNamed(const TopoDS_Shape& S,
119 for (Standard_Integer i = 1 ;i <= lfaulty.Length(); i++) {
120 Handle(DBRep_DrawableShape) DS =
121 Handle(DBRep_DrawableShape)::DownCast(lfaulty(i));
122 if (DS->Shape().IsSame(S)) {
123 Name = (char*)DS->Name();
124 return Standard_True;
127 return Standard_False;
131 //=======================================================================
132 //function : Contains
133 //=======================================================================
134 static Standard_Boolean Contains(const TopTools_ListOfShape& L,
135 const TopoDS_Shape& S)
137 TopTools_ListIteratorOfListOfShape it;
138 for (it.Initialize(L); it.More(); it.Next()) {
139 if (it.Value().IsSame(S)) {
140 return Standard_True;
143 return Standard_False;
148 //=======================================================================
149 //function : PrintSub
150 //=======================================================================
151 static void PrintSub(Standard_OStream& OS,
152 const BRepCheck_Analyzer& Ana,
153 const TopoDS_Shape& S,
154 const TopAbs_ShapeEnum Subtype)
158 BRepCheck_ListIteratorOfListOfStatus itl;
160 for (exp.Init(S,Subtype); exp.More(); exp.Next()) {
161 const Handle(BRepCheck_Result)& res = Ana.Result(exp.Current());
162 const TopoDS_Shape& sub = exp.Current();
163 for (res->InitContextIterator();
164 res->MoreShapeInContext();
165 res->NextShapeInContext()) {
166 if (res->ContextualShape().IsSame(S) &&
167 !Contains(theMap(sub),S)) {
168 theMap(sub).Append(S);
169 itl.Initialize(res->StatusOnShape());
170 if (itl.Value() != BRepCheck_NoError) {
171 if (!FindNamed(sub,Name)) {
173 Name = (char*)malloc(18*sizeof(char));
174 Sprintf(Name,"%s%d",checkfaultyname,nbfaulty);
175 DBRep::Set(Name,sub);
176 lfaulty.Append(Draw::Get((Standard_CString&)Name));
178 OS << "Shape " << Name << " ";
179 if (!FindNamed(S,Name)) {
181 Name = (char*)malloc(18*sizeof(char));
182 Sprintf(Name,"%s%d",checkfaultyname,nbfaulty);
184 lfaulty.Append(Draw::Get((Standard_CString&)Name));
186 OS << " on shape " << Name << " :\n";
187 for (;itl.More(); itl.Next()) {
188 BRepCheck::Print(itl.Value(),OS);
198 //=======================================================================
200 //=======================================================================
201 static void Print(Standard_OStream& OS,
202 const BRepCheck_Analyzer& Ana,
203 const TopoDS_Shape& S)
205 for (TopoDS_Iterator iter(S); iter.More(); iter.Next()) {
206 Print(OS,Ana,iter.Value());
210 TopAbs_ShapeEnum styp = S.ShapeType();
211 BRepCheck_ListIteratorOfListOfStatus itl;
212 if (!Ana.Result(S).IsNull() && !theMap.IsBound(S)) {
213 itl.Initialize(Ana.Result(S)->Status());
214 if (itl.Value() != BRepCheck_NoError) {
215 if (!FindNamed(S,Name)) {
217 Name = (char*)malloc(18*sizeof(char));
218 Sprintf(Name,"%s%d",checkfaultyname,nbfaulty);
220 lfaulty.Append(Draw::Get((Standard_CString&)Name));
222 OS << "On Shape " << Name << " :\n";
224 for (;itl.More(); itl.Next()) {
225 BRepCheck::Print(itl.Value(),OS);
229 if (!theMap.IsBound(S)) {
230 TopTools_ListOfShape thelist;
231 theMap.Bind(S, thelist);
236 PrintSub(OS,Ana,S,TopAbs_VERTEX);
239 PrintSub(OS,Ana,S,TopAbs_WIRE);
240 PrintSub(OS,Ana,S,TopAbs_EDGE);
241 PrintSub(OS,Ana,S,TopAbs_VERTEX);
244 // PrintSub(OS,Ana,S,TopAbs_FACE);
247 // PrintSub(OS,Ana,S,TopAbs_EDGE);
248 PrintSub(OS,Ana,S,TopAbs_SHELL);
256 //=======================================================================
257 //function : computetolerance
259 //=======================================================================
260 static Standard_Integer computetolerance(Draw_Interpretor& di,
261 Standard_Integer narg, const char** a)
264 //cout << "Usage: computetolerance shape" << endl;
265 di << "Usage: computetolerance shape" << "\n";
268 TopoDS_Shape S = DBRep::Get(a[1]);
270 if (S.ShapeType() == TopAbs_EDGE) {
271 BRepCheck_Edge bce(TopoDS::Edge(S));
273 //cout<< "Tolerance de " << (void*) &(*S.TShape()) << " : " << tol << endl;
274 Standard_SStream aSStream1;
275 aSStream1<< "Tolerance de " << (void*) &(*S.TShape()) << " : " << tol << "\n";
279 TopTools_MapOfShape theEdges;
281 for (exp.Init(S, TopAbs_EDGE); exp.More(); exp.Next()) {
282 if (theEdges.Add(exp.Current())) {
283 BRepCheck_Edge bce(TopoDS::Edge(exp.Current()));
285 //cout<< "Tolerance de " << (void*) &(*exp.Current().TShape()) << " : " << tol << "\n";
286 Standard_SStream aSStream2;
287 aSStream2<< "Tolerance de " << (void*) &(*exp.Current().TShape()) << " : " << tol << "\n";
297 //=======================================================================
298 //function : checksection
299 //purpose : Checks the closure of a section line
300 //=======================================================================
301 static Standard_Integer checksection(Draw_Interpretor& di,
302 Standard_Integer narg, const char** a)
307 TopoDS_Shape S = DBRep::Get(a[1]);
308 TopTools_MapOfShape theVertices;
310 for (exp.Init(S, TopAbs_VERTEX); exp.More(); exp.Next()) {
311 if (!theVertices.Add(exp.Current()))
312 theVertices.Remove(exp.Current());
314 //cout << " nb alone Vertices : " << theVertices.Extent() << endl;
315 di << " nb alone Vertices : " << theVertices.Extent() << "\n";
317 Standard_Integer ipp=0;
318 TopTools_MapIteratorOfMapOfShape itvx;
319 for (itvx.Initialize(theVertices); itvx.More(); itvx.Next()) {
321 Sprintf(Name,"alone_%d",ipp);
322 DBRep::Set(Name, itvx.Key());
323 //cout << Name << " " ;
330 //=======================================================================
332 //=======================================================================
333 //function : checkdiff
334 //purpose : Checks the differences beetween a result and his arguments
335 //=======================================================================
336 static Standard_Integer checkdiff(Draw_Interpretor& di,
337 Standard_Integer narg, const char** a)
339 const char* syntaxe = "checkdiff arg1 [arg2..argn] result [closedSolid (0/1)] [geomCtrl (1/0)]";
342 Standard_Integer bcrtrace=Draw::Atoi(a[narg-1]);
343 bcrtrace=BRepCheck_Trace(bcrtrace);
344 //cout << "BRepCheck_Trace : " << bcrtrace << endl;
345 di << "BRepCheck_Trace : " << bcrtrace << "\n";
346 //cout << syntaxe << endl;
347 di << syntaxe << "\n";
350 //cout << syntaxe << endl;
351 di << syntaxe << "\n";
355 Standard_Integer lastArg=narg-2;
356 Standard_Boolean closedSolid = Standard_False;
357 Standard_Boolean geomCtrl = Standard_True;
358 TopoDS_Shape resu = DBRep::Get(a[narg-1]);
361 //cout << syntaxe << endl;
362 di << syntaxe << "\n";
365 closedSolid=Draw::Atoi(a[narg-1]);
366 resu = DBRep::Get(a[narg-2]);
370 //cout << syntaxe << endl;
371 di << syntaxe << "\n";
374 geomCtrl=closedSolid;
375 closedSolid=Draw::Atoi(a[narg-2]);
376 resu = DBRep::Get(a[narg-3]);
379 //cout << syntaxe << endl;
380 di << syntaxe << "\n";
386 TopTools_ListOfShape lesArgs;
387 for (Standard_Integer id=1; id <=lastArg; id++) {
388 lesArgs.Append(DBRep::Get(a[id]));
391 if (BRepAlgo::IsValid(lesArgs, resu, closedSolid, geomCtrl)) {
392 //cout << "Difference is Valid." << endl;
393 di << "Difference is Valid." << "\n";
395 //cout << "error : Difference is Not Valid !" << endl;
396 di << "error : Difference is Not Valid !" << "\n";
401 //=======================================================================
403 // Modified by skv - Tue Apr 27 13:38:44 2004 Begin
404 //=======================================================================
406 //purpose : Checks a shape
407 //=======================================================================
409 // static Standard_Integer CHK(Draw_Interpretor& theCommands,
410 // Standard_Integer narg, const char** a)
416 // Standard_Boolean doprint = Standard_True;
417 // if (narg == 3) { if (!strcmp(a[2],"-short")) doprint = Standard_False; }
419 // TopoDS_Shape S = DBRep::Get(a[1]);
421 // cout<<"not a topological shape"<<endl;
425 // Standard_Boolean GeomCtrl = Standard_True;
426 // if (!strcasecmp(a[0],"CHECKTOPSHAPE")) {
427 // GeomCtrl = Standard_False;
430 // BRepCheck_Analyzer ana(S,GeomCtrl);
431 // if (ana.IsValid()) {
432 // theCommands<<"This shape seems to be valid";
440 // Print(cout,ana,S);
444 // cout<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n";
448 // theCommands<<"This shape has faulty shapes";
454 //=======================================================================
455 //function : ContextualDump
456 //purpose : Contextual (modeling) style of output.
457 //=======================================================================
459 //void ContextualDump(const BRepCheck_Analyzer &theAna,
460 // const TopoDS_Shape &theShape)
461 void ContextualDump(Draw_Interpretor& theCommands,
462 const BRepCheck_Analyzer &theAna,
463 const TopoDS_Shape &theShape)
469 //Print(cout, theAna, theShape);
470 Standard_SStream aSStream;
471 Print(aSStream, theAna, theShape);
472 theCommands << aSStream;
478 theCommands<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n";
479 //cout<<"Faulty shapes in variables "<<checkfaultyname<<"1 to "<<checkfaultyname<<nbfaulty<<" \n";
486 //=======================================================================
487 //function : FillProblems
488 // purpose : auxilary for StructuralDump
489 //=======================================================================
490 static void FillProblems(const BRepCheck_Status stat,
491 Handle(TColStd_HArray1OfInteger)& NbProblems)
494 case BRepCheck_InvalidPointOnCurve:
495 NbProblems->SetValue(1,NbProblems->Value(1)+1); break;
496 case BRepCheck_InvalidPointOnCurveOnSurface:
497 NbProblems->SetValue(2,NbProblems->Value(2)+1); break;
498 case BRepCheck_InvalidPointOnSurface:
499 NbProblems->SetValue(3,NbProblems->Value(3)+1); break;
500 case BRepCheck_No3DCurve:
501 NbProblems->SetValue(4,NbProblems->Value(4)+1); break;
502 case BRepCheck_Multiple3DCurve:
503 NbProblems->SetValue(5,NbProblems->Value(5)+1); break;
504 case BRepCheck_Invalid3DCurve:
505 NbProblems->SetValue(6,NbProblems->Value(6)+1); break;
506 case BRepCheck_NoCurveOnSurface:
507 NbProblems->SetValue(7,NbProblems->Value(7)+1); break;
508 case BRepCheck_InvalidCurveOnSurface:
509 NbProblems->SetValue(8,NbProblems->Value(8)+1); break;
510 case BRepCheck_InvalidCurveOnClosedSurface:
511 NbProblems->SetValue(9,NbProblems->Value(9)+1); break;
512 case BRepCheck_InvalidSameRangeFlag:
513 NbProblems->SetValue(10,NbProblems->Value(10)+1); break;
514 case BRepCheck_InvalidSameParameterFlag:
515 NbProblems->SetValue(11,NbProblems->Value(11)+1); break;
516 case BRepCheck_InvalidDegeneratedFlag:
517 NbProblems->SetValue(12,NbProblems->Value(12)+1); break;
518 case BRepCheck_FreeEdge:
519 NbProblems->SetValue(13,NbProblems->Value(13)+1); break;
520 case BRepCheck_InvalidMultiConnexity:
521 NbProblems->SetValue(14,NbProblems->Value(14)+1); break;
522 case BRepCheck_InvalidRange:
523 NbProblems->SetValue(15,NbProblems->Value(15)+1); break;
524 case BRepCheck_EmptyWire:
525 NbProblems->SetValue(16,NbProblems->Value(16)+1); break;
526 case BRepCheck_RedundantEdge:
527 NbProblems->SetValue(17,NbProblems->Value(17)+1); break;
528 case BRepCheck_SelfIntersectingWire:
529 NbProblems->SetValue(18,NbProblems->Value(18)+1); break;
530 case BRepCheck_NoSurface:
531 NbProblems->SetValue(19,NbProblems->Value(19)+1); break;
532 case BRepCheck_InvalidWire:
533 NbProblems->SetValue(20,NbProblems->Value(20)+1); break;
534 case BRepCheck_RedundantWire:
535 NbProblems->SetValue(21,NbProblems->Value(21)+1); break;
536 case BRepCheck_IntersectingWires:
537 NbProblems->SetValue(22,NbProblems->Value(22)+1); break;
538 case BRepCheck_InvalidImbricationOfWires:
539 NbProblems->SetValue(23,NbProblems->Value(23)+1); break;
540 case BRepCheck_EmptyShell:
541 NbProblems->SetValue(24,NbProblems->Value(24)+1); break;
542 case BRepCheck_RedundantFace:
543 NbProblems->SetValue(25,NbProblems->Value(25)+1); break;
544 case BRepCheck_UnorientableShape:
545 NbProblems->SetValue(26,NbProblems->Value(26)+1); break;
546 case BRepCheck_NotClosed:
547 NbProblems->SetValue(27,NbProblems->Value(27)+1); break;
548 case BRepCheck_NotConnected:
549 NbProblems->SetValue(28,NbProblems->Value(28)+1); break;
550 case BRepCheck_SubshapeNotInShape:
551 NbProblems->SetValue(29,NbProblems->Value(29)+1); break;
552 case BRepCheck_BadOrientation:
553 NbProblems->SetValue(30,NbProblems->Value(30)+1); break;
554 case BRepCheck_BadOrientationOfSubshape:
555 NbProblems->SetValue(31,NbProblems->Value(31)+1); break;
556 case BRepCheck_CheckFail:
557 NbProblems->SetValue(32,NbProblems->Value(32)+1); break;
564 //=======================================================================
565 //function : GetProblemSub
566 // purpose : auxilary for StructuralDump
567 //=======================================================================
568 static void GetProblemSub(const BRepCheck_Analyzer& Ana,
569 const TopoDS_Shape& Shape,
570 Handle(TopTools_HSequenceOfShape)& sl,
571 Handle(TColStd_HArray1OfInteger)& NbProblems,
572 const TopAbs_ShapeEnum Subtype)
574 BRepCheck_ListIteratorOfListOfStatus itl;
576 for (exp.Init(Shape,Subtype); exp.More(); exp.Next()) {
577 const Handle(BRepCheck_Result)& res = Ana.Result(exp.Current());
579 const TopoDS_Shape& sub = exp.Current();
580 for (res->InitContextIterator();
581 res->MoreShapeInContext();
582 res->NextShapeInContext()) {
583 if (res->ContextualShape().IsSame(Shape) &&
584 !Contains(theMap(sub),Shape)) {
585 theMap(sub).Append(Shape);
586 itl.Initialize(res->StatusOnShape());
588 if (itl.Value() != BRepCheck_NoError) {
589 Standard_Integer ii = 0;
591 for(ii=1; ii<=sl->Length(); ii++)
592 if(sl->Value(ii).IsSame(sub)) break;
594 if(ii>sl->Length()) {
596 FillProblems(itl.Value(),NbProblems);
598 for(ii=1; ii<=sl->Length(); ii++)
599 if(sl->Value(ii).IsSame(Shape)) break;
600 if(ii>sl->Length()) {
602 FillProblems(itl.Value(),NbProblems);
612 //=======================================================================
613 //function : GetProblemShapes
614 // purpose : auxilary for StructuralDump
615 //=======================================================================
616 static void GetProblemShapes(const BRepCheck_Analyzer& Ana,
617 const TopoDS_Shape& Shape,
618 Handle(TopTools_HSequenceOfShape)& sl,
619 Handle(TColStd_HArray1OfInteger)& NbProblems)
621 for (TopoDS_Iterator iter(Shape); iter.More(); iter.Next()) {
622 GetProblemShapes(Ana,iter.Value(),sl, NbProblems);
624 TopAbs_ShapeEnum styp = Shape.ShapeType();
625 BRepCheck_ListIteratorOfListOfStatus itl;
626 if (!Ana.Result(Shape).IsNull() && !theMap.IsBound(Shape)) {
627 itl.Initialize(Ana.Result(Shape)->Status());
629 if (itl.Value() != BRepCheck_NoError) {
631 FillProblems(itl.Value(),NbProblems);
634 if (!theMap.IsBound(Shape)) {
635 TopTools_ListOfShape thelist;
636 theMap.Bind(Shape, thelist);
641 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_VERTEX);
644 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_WIRE);
645 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_EDGE);
646 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_VERTEX);
651 GetProblemSub(Ana, Shape, sl, NbProblems, TopAbs_SHELL);
659 //=======================================================================
660 //function : StructuralDump
661 //purpose : Structural (data exchange) style of output.
662 //=======================================================================
664 //void StructuralDump(const BRepCheck_Analyzer &theAna,
665 // const Standard_CString ShName,
666 // const Standard_CString Pref,
667 // const TopoDS_Shape &theShape)
668 void StructuralDump(Draw_Interpretor& theCommands,
669 const BRepCheck_Analyzer &theAna,
670 const Standard_CString ShName,
671 const Standard_CString Pref,
672 const TopoDS_Shape &theShape)
675 //cout << "StructuralDump" << endl;
676 //cout << " -- The Shape " << ShName << " has problems :"<<endl;
677 //cout<<" Check Count"<<endl;
678 //cout<<" ------------------------------------------------"<<endl;
679 theCommands << " -- The Shape " << ShName << " has problems :"<<"\n";
680 theCommands<<" Check Count"<<"\n";
681 theCommands<<" ------------------------------------------------"<<"\n";
683 Handle(TColStd_HArray1OfInteger) NbProblems = new TColStd_HArray1OfInteger(1,32);
684 for(i=1; i<=32; i++) NbProblems->SetValue(i,0);
685 Handle(TopTools_HSequenceOfShape) sl,slv,sle,slw,slf,sls,slo;
686 sl = new TopTools_HSequenceOfShape();
688 GetProblemShapes(theAna, theShape, sl, NbProblems);
691 if(NbProblems->Value(1)>0)
692 theCommands<<" Invalid Point on Curve ................... "<<NbProblems->Value(1)<<"\n";
693 //cout<<" Invalid Point on Curve ................... "<<NbProblems->Value(1)<<endl;
694 if(NbProblems->Value(2)>0)
695 theCommands<<" Invalid Point on CurveOnSurface .......... "<<NbProblems->Value(2)<<"\n";
696 //cout<<" Invalid Point on CurveOnSurface .......... "<<NbProblems->Value(2)<<endl;
697 if(NbProblems->Value(3)>0)
698 theCommands<<" Invalid Point on Surface ................. "<<NbProblems->Value(3)<<"\n";
699 //cout<<" Invalid Point on Surface ................. "<<NbProblems->Value(3)<<endl;
700 if(NbProblems->Value(4)>0)
701 theCommands<<" No 3D Curve .............................. "<<NbProblems->Value(4)<<"\n";
702 //cout<<" No 3D Curve .............................. "<<NbProblems->Value(4)<<endl;
703 if(NbProblems->Value(5)>0)
704 theCommands<<" Multiple 3D Curve ........................ "<<NbProblems->Value(5)<<"\n";
705 //cout<<" Multiple 3D Curve ........................ "<<NbProblems->Value(5)<<endl;
706 if(NbProblems->Value(6)>0)
707 theCommands<<" Invalid 3D Curve ......................... "<<NbProblems->Value(6)<<"\n";
708 //cout<<" Invalid 3D Curve ......................... "<<NbProblems->Value(6)<<endl;
709 if(NbProblems->Value(7)>0)
710 theCommands<<" No Curve on Surface ...................... "<<NbProblems->Value(7)<<"\n";
711 //cout<<" No Curve on Surface ...................... "<<NbProblems->Value(7)<<endl;
712 if(NbProblems->Value(8)>0)
713 theCommands<<" Invalid Curve on Surface ................. "<<NbProblems->Value(8)<<"\n";
714 //cout<<" Invalid Curve on Surface ................. "<<NbProblems->Value(8)<<endl;
715 if(NbProblems->Value(9)>0)
716 theCommands<<" Invalid Curve on closed Surface .......... "<<NbProblems->Value(9)<<"\n";
717 //cout<<" Invalid Curve on closed Surface .......... "<<NbProblems->Value(9)<<endl;
718 if(NbProblems->Value(10)>0)
719 theCommands<<" Invalid SameRange Flag ................... "<<NbProblems->Value(10)<<"\n";
720 //cout<<" Invalid SameRange Flag ................... "<<NbProblems->Value(10)<<endl;
721 if(NbProblems->Value(11)>0)
722 theCommands<<" Invalid SameParameter Flag ............... "<<NbProblems->Value(11)<<"\n";
723 //cout<<" Invalid SameParameter Flag ............... "<<NbProblems->Value(11)<<endl;
724 if(NbProblems->Value(12)>0)
725 theCommands<<" Invalid Degenerated Flag ................. "<<NbProblems->Value(12)<<"\n";
726 //cout<<" Invalid Degenerated Flag ................. "<<NbProblems->Value(12)<<endl;
727 if(NbProblems->Value(13)>0)
728 theCommands<<" Free Edge ................................ "<<NbProblems->Value(13)<<"\n";
729 //cout<<" Free Edge ................................ "<<NbProblems->Value(13)<<endl;
730 if(NbProblems->Value(14)>0)
731 theCommands<<" Invalid MultiConnexity ................... "<<NbProblems->Value(14)<<"\n";
732 //cout<<" Invalid MultiConnexity ................... "<<NbProblems->Value(14)<<endl;
733 if(NbProblems->Value(15)>0)
734 theCommands<<" Invalid Range ............................ "<<NbProblems->Value(15)<<"\n";
735 //cout<<" Invalid Range ............................ "<<NbProblems->Value(15)<<endl;
736 if(NbProblems->Value(16)>0)
737 theCommands<<" Empty Wire ............................... "<<NbProblems->Value(16)<<"\n";
738 //cout<<" Empty Wire ............................... "<<NbProblems->Value(16)<<endl;
739 if(NbProblems->Value(17)>0)
740 theCommands<<" Redundant Edge ........................... "<<NbProblems->Value(17)<<"\n";
741 //cout<<" Redundant Edge ........................... "<<NbProblems->Value(17)<<endl;
742 if(NbProblems->Value(18)>0)
743 theCommands<<" Self Intersecting Wire ................... "<<NbProblems->Value(18)<<"\n";
744 //cout<<" Self Intersecting Wire ................... "<<NbProblems->Value(18)<<endl;
745 if(NbProblems->Value(19)>0)
746 theCommands<<" No Surface ............................... "<<NbProblems->Value(19)<<"\n";
747 //cout<<" No Surface ............................... "<<NbProblems->Value(19)<<endl;
748 if(NbProblems->Value(20)>0)
749 theCommands<<" Invalid Wire ............................. "<<NbProblems->Value(20)<<"\n";
750 //cout<<" Invalid Wire ............................. "<<NbProblems->Value(20)<<endl;
751 if(NbProblems->Value(21)>0)
752 theCommands<<" Redundant Wire ........................... "<<NbProblems->Value(21)<<"\n";
753 //cout<<" Redundant Wire ........................... "<<NbProblems->Value(21)<<endl;
754 if(NbProblems->Value(22)>0)
755 theCommands<<" Intersecting Wires ....................... "<<NbProblems->Value(22)<<"\n";
756 //cout<<" Intersecting Wires ....................... "<<NbProblems->Value(22)<<endl;
757 if(NbProblems->Value(23)>0)
758 theCommands<<" Invalid Imbrication of Wires ............. "<<NbProblems->Value(23)<<"\n";
759 //cout<<" Invalid Imbrication of Wires ............. "<<NbProblems->Value(23)<<endl;
760 if(NbProblems->Value(24)>0)
761 theCommands<<" Empty Shell .............................. "<<NbProblems->Value(24)<<"\n";
762 //cout<<" Empty Shell .............................. "<<NbProblems->Value(24)<<endl;
763 if(NbProblems->Value(25)>0)
764 theCommands<<" Redundant Face ........................... "<<NbProblems->Value(25)<<"\n";
765 //cout<<" Redundant Face ........................... "<<NbProblems->Value(25)<<endl;
766 if(NbProblems->Value(26)>0)
767 theCommands<<" Unorientable Shape ....................... "<<NbProblems->Value(26)<<"\n";
768 //cout<<" Unorientable Shape ....................... "<<NbProblems->Value(26)<<endl;
769 if(NbProblems->Value(27)>0)
770 theCommands<<" Not Closed ............................... "<<NbProblems->Value(27)<<"\n";
771 //cout<<" Not Closed ............................... "<<NbProblems->Value(27)<<endl;
772 if(NbProblems->Value(28)>0)
773 theCommands<<" Not Connected ............................ "<<NbProblems->Value(28)<<"\n";
774 //cout<<" Not Connected ............................ "<<NbProblems->Value(28)<<endl;
775 if(NbProblems->Value(29)>0)
776 theCommands<<" Subshape not in Shape .................... "<<NbProblems->Value(29)<<"\n";
777 //cout<<" Subshape not in Shape .................... "<<NbProblems->Value(29)<<endl;
778 if(NbProblems->Value(30)>0)
779 theCommands<<" Bad Orientation .......................... "<<NbProblems->Value(30)<<"\n";
780 //cout<<" Bad Orientation .......................... "<<NbProblems->Value(30)<<endl;
781 if(NbProblems->Value(31)>0)
782 theCommands<<" Bad Orientation of Subshape .............. "<<NbProblems->Value(31)<<"\n";
783 //cout<<" Bad Orientation of Subshape .............. "<<NbProblems->Value(31)<<endl;
784 if(NbProblems->Value(32)>0)
785 theCommands<<" checkshape failure......... .............. "<<NbProblems->Value(32)<<"\n";
786 //cout<<" checkshape failure......... .............. "<<NbProblems->Value(32)<<endl;
788 //cout<<" ------------------------------------------------"<<endl;
789 //cout<<"*** Shapes with problems : "<<sl->Length()<<endl;
791 theCommands<<" ------------------------------------------------"<<"\n";
792 theCommands<<"*** Shapes with problems : "<<sl->Length()<<"\n";
794 slv = new TopTools_HSequenceOfShape();
795 sle = new TopTools_HSequenceOfShape();
796 slw = new TopTools_HSequenceOfShape();
797 slf = new TopTools_HSequenceOfShape();
798 sls = new TopTools_HSequenceOfShape();
799 slo = new TopTools_HSequenceOfShape();
801 for(i=1; i<=sl->Length(); i++) {
802 TopoDS_Shape shi = sl->Value(i);
803 TopAbs_ShapeEnum sti = shi.ShapeType();
805 case TopAbs_VERTEX : slv->Append (shi); break;
806 case TopAbs_EDGE : sle->Append (shi); break;
807 case TopAbs_WIRE : slw->Append (shi); break;
808 case TopAbs_FACE : slf->Append (shi); break;
809 case TopAbs_SHELL : sls->Append (shi); break;
810 case TopAbs_SOLID : slo->Append (shi); break;
816 if(slv->Length()>0) {
817 TopoDS_Compound comp;
818 B.MakeCompound(comp);
819 Standard_Integer nb = slv->Length();
821 B.Add(comp,slv->Value(i));
823 Sprintf(aName,"%s_v",Pref);
824 DBRep::Set(aName,comp);
825 //cout<<"VERTEX"<<" : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
827 theCommands<<"VERTEX"<<" : "<<""<<nb<<" Items -> compound named "<<aName<<"\n";
829 theCommands<<"VERTEX"<<" : "<<" "<<nb<<" Items -> compound named "<<aName<<"\n";
831 if(sle->Length()>0) {
832 TopoDS_Compound comp;
833 B.MakeCompound(comp);
834 Standard_Integer nb = sle->Length();
836 B.Add(comp,sle->Value(i));
838 Sprintf(aName,"%s_e",Pref);
839 DBRep::Set(aName,comp);
840 //cout<<"EDGE"<<" : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
842 theCommands<<"EDGE"<<" : "<<""<<nb<<" Items -> compound named "<<aName<<"\n";
844 theCommands<<"EDGE"<<" : "<<" "<<nb<<" Items -> compound named "<<aName<<"\n";
846 if(slw->Length()>0) {
847 TopoDS_Compound comp;
848 B.MakeCompound(comp);
849 Standard_Integer nb = slw->Length();
851 B.Add(comp,slw->Value(i));
853 Sprintf(aName,"%s_w",Pref);
854 DBRep::Set(aName,comp);
855 //cout<<"WIRE"<<" : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
857 theCommands<<"WIRE"<<" : "<<""<<nb<<" Items -> compound named "<<aName<<"\n";
859 theCommands<<"WIRE"<<" : "<<" "<<nb<<" Items -> compound named "<<aName<<"\n";
861 if(slf->Length()>0) {
862 TopoDS_Compound comp;
863 B.MakeCompound(comp);
864 Standard_Integer nb = slf->Length();
866 B.Add(comp,slf->Value(i));
868 Sprintf(aName,"%s_f",Pref);
869 DBRep::Set(aName,comp);
870 //cout<<"FACE"<<" : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
872 theCommands<<"FACE"<<" : "<<""<<nb<<" Items -> compound named "<<aName<<"\n";
874 theCommands<<"FACE"<<" : "<<" "<<nb<<" Items -> compound named "<<aName<<"\n";
876 if(sls->Length()>0) {
877 TopoDS_Compound comp;
878 B.MakeCompound(comp);
879 Standard_Integer nb = sls->Length();
881 B.Add(comp,sls->Value(i));
883 Sprintf(aName,"%s_s",Pref);
884 DBRep::Set(aName,comp);
885 //cout<<"SHELL"<<" : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
887 theCommands<<"SHELL"<<" : "<<""<<nb<<" Items -> compound named "<<aName<<"\n";
889 theCommands<<"SHELL"<<" : "<<" "<<nb<<" Items -> compound named "<<aName<<"\n";
891 if(slo->Length()>0) {
892 TopoDS_Compound comp;
893 B.MakeCompound(comp);
894 Standard_Integer nb = slo->Length();
896 B.Add(comp,slo->Value(i));
898 Sprintf(aName,"%s_o",Pref);
899 DBRep::Set(aName,comp);
900 //cout<<"SOLID"<<" : "<<(nb > 9 ? "" : " ")<<nb<<" Items -> compound named "<<aName<<endl;
902 theCommands<<"SOLID"<<" : "<<""<<nb<<" Items -> compound named "<<aName<<"\n";
904 theCommands<<"SOLID"<<" : "<<" "<<nb<<" Items -> compound named "<<aName<<"\n";
908 //=======================================================================
909 //function : checkshape
910 //purpose : Checks a shape
911 //=======================================================================
913 static Standard_Integer checkshape(Draw_Interpretor& theCommands,
914 Standard_Integer narg, const char** a)
918 //cout << "Usage : checkshape [-top] shape [result] [-short]" << endl;
920 //cout << "Where :" << endl;
921 //cout << " -top - check topology only." << endl;
922 //cout << " shape - the name of the shape to test." << endl;
923 //cout << " result - the prefix of the output shape names. If it is used, structural" << endl;
924 //cout << " output style will be used. Otherwise - contextual one." << endl;
925 //cout << " -short - short description of check." << endl;
927 theCommands << "Usage : checkshape [-top] shape [result] [-short]" << "\n";
929 theCommands << "Where :" << "\n";
930 theCommands << " -top - check topology only." << "\n";
931 theCommands << " shape - the name of the shape to test." << "\n";
932 theCommands << " result - the prefix of the output shape names. If it is used, structural" << "\n";
933 theCommands << " output style will be used. Otherwise - contextual one." << "\n";
934 theCommands << " -short - short description of check." << "\n";
940 //cout << "Invalid number of args!!!" << endl;
941 //cout << "No args to have help." << endl;
942 theCommands << "Invalid number of args!!!" << "\n";
943 theCommands << "No args to have help." << "\n";
948 Standard_Boolean aGeomCtrl = Standard_True;
949 Standard_Integer aCurInd = 1;
951 if (!strcmp(a[1],"-top")) {
952 aGeomCtrl = Standard_False;
956 if (aCurInd > narg - 1) {
957 //cout << "Invalid number of args!!!" << endl;
958 //cout << "No args to have help." << endl;
959 theCommands << "Invalid number of args!!!" << "\n";
960 theCommands << "No args to have help." << "\n";
965 Standard_CString aShapeName = a[aCurInd];
966 TopoDS_Shape aShape = DBRep::Get(aShapeName);
968 if (aShape.IsNull()) {
969 //cout << a[aCurInd] << " is not a topological shape!!!" << endl;
970 theCommands << a[aCurInd] << " is not a topological shape!!!" << "\n";
975 Standard_Boolean IsShortDump = Standard_False;
976 Standard_Boolean IsContextDump = Standard_True;
977 Standard_Integer aBackInd = narg - 1;
979 if (aCurInd < aBackInd) {
980 if (!strcmp(a[aBackInd],"-short")) {
981 IsShortDump = Standard_True;
986 if (aCurInd < aBackInd - 1) {
987 //cout << "Invalid number of args!!!" << endl;
988 //cout << "No args to have help." << endl;
989 theCommands << "Invalid number of args!!!" << "\n";
990 theCommands << "No args to have help." << "\n";
993 } else if (aCurInd < aBackInd) {
994 IsContextDump = Standard_False;
999 BRepCheck_Analyzer anAna(aShape,aGeomCtrl);
1000 Standard_Boolean isValid = anAna.IsValid();
1003 if (IsContextDump) {
1004 theCommands << "This shape seems to be valid";
1006 theCommands << " -- The Shape " << aShapeName << " looks OK";
1010 theCommands<<"This shape has faulty shapes";
1012 if (IsContextDump) {
1013 //ContextualDump(anAna, aShape);
1014 ContextualDump(theCommands, anAna, aShape);
1016 Standard_CString aPref = a[aCurInd+1];
1017 //StructuralDump(anAna, aShapeName, aPref, aShape);
1018 StructuralDump(theCommands, anAna, aShapeName, aPref, aShape);
1023 catch(Standard_Failure) {
1024 theCommands<<"checkshape exception : ";
1025 theCommands << Standard_Failure::Caught()->GetMessageString();
1032 // Modified by skv - Tue Apr 27 13:38:24 2004 End
1033 /***************************************************************/
1034 static void InitEpsSurf(Standard_Real& epsnl,Standard_Real& epsdis, Standard_Real& epsangk1,
1035 Standard_Real& epsangk2, Standard_Real& epsangn1,
1036 Standard_Real& perce,Standard_Real& maxlen )
1047 static Standard_Integer shapeG1continuity (Draw_Interpretor& di, Standard_Integer n, const char** a)
1049 { Standard_Real epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen;
1050 Standard_Integer nbeval;
1051 InitEpsSurf(epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen);
1052 Standard_Boolean ISG1=Standard_True;
1054 TopoDS_Face face1,face2;
1055 Standard_Real f1,f2,l1,l2;
1056 TopoDS_Shape shape = DBRep::Get(a[1],TopAbs_SHAPE);
1057 if (shape.IsNull()) return 1;
1058 TopoDS_Shape edge = DBRep::Get(a[2],TopAbs_EDGE);
1059 if (edge.IsNull()) return 1;
1060 // calcul des deux faces
1061 TopTools_IndexedDataMapOfShapeListOfShape lface;
1062 TopExp::MapShapesAndAncestors(shape,TopAbs_EDGE,TopAbs_FACE,lface);
1063 const TopTools_ListOfShape& lfac = lface.FindFromKey(edge);
1065 Standard_Integer nelem= lfac.Extent();
1066 if(nelem!=2) return 1;
1067 TopTools_ListIteratorOfListOfShape It;
1068 It.Initialize(lfac);
1069 face1=TopoDS::Face(It.Value());
1071 face2=TopoDS::Face(It.Value());
1073 // calcul des deux pcurves
1074 const Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface
1075 (TopoDS::Edge(edge),face1,f1,l1);
1076 if (c1.IsNull()) return 1;
1077 const Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface
1078 (TopoDS::Edge(edge),face2,f2,l2);
1079 if (c2.IsNull()) return 1;
1081 Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1);
1083 Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2);
1085 // calcul dees deux surfaces
1086 TopLoc_Location L1,L2;
1087 TopoDS_Face aLocalFace = face1;
1088 const Handle(Geom_Surface)& s1 = BRep_Tool::Surface(aLocalFace,L1);
1089 // const Handle(Geom_Surface)& s1 =
1090 // BRep_Tool::Surface(TopoDS::Face(face1),L1);
1091 if (s1.IsNull()) return 1;
1093 const Handle(Geom_Surface)& s2 = BRep_Tool::Surface(aLocalFace,L2);
1094 // const Handle(Geom_Surface)& s2 =
1095 // BRep_Tool::Surface(TopoDS::Face(face2),L2);
1096 if (s2.IsNull()) return 1;
1099 Handle(Geom_Surface) surf1 = Handle(Geom_Surface)::
1100 DownCast(s1->Transformed(L1.Transformation()));
1101 if (surf1.IsNull()) return 1;
1102 Handle(Geom_Surface) surf2 = Handle(Geom_Surface)::
1103 DownCast(s2->Transformed(L2.Transformation()));
1104 if (surf2.IsNull()) return 1;
1108 nbeval = (Standard_Integer ) Draw::Atof( a[3]);
1111 { case 7 : epsG1 = Draw::Atof(a[6]);
1112 case 6 : epsC0 = Draw::Atof(a[5]);
1113 case 5 : epsnl = Draw::Atof(a[4]);
1119 Standard_Real pard1, parf1, U, Uf, deltaU, nb = 0;
1120 Standard_Boolean isconti = Standard_True;
1121 Standard_Boolean isdone = Standard_True;
1122 pard1 = curv1->FirstParameter();
1123 parf1 = curv1->LastParameter();
1124 Standard_Real MaxG0Value=0, MaxG1Angle=0;
1125 U = Min( pard1,parf1);
1126 Uf = Max (pard1,parf1);
1128 deltaU = Abs(parf1- pard1)/nbeval;
1131 { if ( nb == nbeval)
1132 { LocalAnalysis_SurfaceContinuity res(curv1, curv2, Uf,surf1, surf2, GeomAbs_G1, epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen );
1133 isdone = res.IsDone();
1134 if ( isdone) { isconti = res.IsG1();
1136 {if (res.C0Value()>MaxG0Value) MaxG0Value = res.C0Value();
1137 if (res.G1Angle ()>MaxG1Angle) MaxG1Angle = res.G1Angle();}}
1138 else isconti = Standard_False;}
1140 else {LocalAnalysis_SurfaceContinuity res (curv1, curv2, (U+nb*deltaU ), surf1,surf2, GeomAbs_G1,epsnl,epsC0, epsC1, epsC2, epsG1,
1142 isdone = res.IsDone();
1143 if ( isdone) { isconti = res.IsG1();
1144 if ( nb == 0) { MaxG0Value = res.C0Value();
1145 MaxG1Angle = res.G1Angle();}
1146 if (res.C0Value()> MaxG0Value) MaxG0Value = res.C0Value();
1147 if (res.G1Angle()> MaxG1Angle) MaxG1Angle= res.G1Angle();;}
1149 else isconti = Standard_False;}
1150 if (!isconti) ISG1=Standard_False;
1154 while ((nb<nbeval)&& isdone );
1156 //if (!isdone) { cout<<" Problem in computation "<<endl; return 1;}
1158 // {cout<<" the continuity is G1 "<<endl;}
1159 //else { cout<<" the continuity is not G1 "<<endl;}
1160 //cout<<"MaxG0Value :"<< MaxG0Value << endl;
1161 //cout<<"MaxG1Angle:"<< MaxG1Angle << endl;
1162 if (!isdone) { di<<" Problem in computation "<<"\n"; return 1;}
1164 {di<<" the continuity is G1 "<<"\n";}
1165 else { di<<" the continuity is not G1 "<<"\n";}
1166 di<<"MaxG0Value :"<< MaxG0Value << "\n";
1167 di<<"MaxG1Angle:"<< MaxG1Angle << "\n";
1170 /*****************************************************************************/
1171 static Standard_Integer shapeG0continuity (Draw_Interpretor& di, Standard_Integer n, const char** a)
1173 { Standard_Real epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen;
1174 Standard_Integer nbeval;
1175 Standard_Boolean ISG0;
1176 InitEpsSurf(epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen );
1179 TopoDS_Face face1,face2;
1180 Standard_Real f1,f2,l1,l2;
1181 TopoDS_Shape shape = DBRep::Get(a[1],TopAbs_SHAPE);
1182 if (shape.IsNull()) return 1;
1183 TopoDS_Shape edge = DBRep::Get(a[2],TopAbs_EDGE);
1184 if (edge.IsNull()) return 1;
1185 // calcul des deux faces
1186 TopTools_IndexedDataMapOfShapeListOfShape lface;
1187 TopExp::MapShapesAndAncestors(shape,TopAbs_EDGE,TopAbs_FACE,lface);
1188 const TopTools_ListOfShape& lfac = lface.FindFromKey(edge);
1190 Standard_Integer nelem= lfac.Extent();
1191 if(nelem!=2) return 1;
1192 TopTools_ListIteratorOfListOfShape It;
1193 It.Initialize(lfac);
1194 face1=TopoDS::Face(It.Value());
1196 face2=TopoDS::Face(It.Value());
1198 // calcul des deux pcurves
1199 const Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface
1200 (TopoDS::Edge(edge),face1,f1,l1);
1201 if (c1.IsNull()) return 1;
1202 const Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface
1203 (TopoDS::Edge(edge),face2,f2,l2);
1204 if (c2.IsNull()) return 1;
1206 Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1);
1208 Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2);
1210 // calcul des deux surfaces
1211 TopLoc_Location L1,L2;
1212 TopoDS_Face aLocalFace = face1;
1213 const Handle(Geom_Surface)& s1 = BRep_Tool::Surface(aLocalFace,L1);
1214 // const Handle(Geom_Surface)& s1 =
1215 // BRep_Tool::Surface(TopoDS::Face(face1),L1);
1216 if (s1.IsNull()) return 1;
1218 const Handle(Geom_Surface)& s2 = BRep_Tool::Surface(aLocalFace,L2);
1219 // const Handle(Geom_Surface)& s2 =
1220 // BRep_Tool::Surface(TopoDS::Face(face2),L2);
1221 if (s2.IsNull()) return 1;
1224 Handle(Geom_Surface) surf1 = Handle(Geom_Surface)::
1225 DownCast(s1->Transformed(L1.Transformation()));
1226 if (surf1.IsNull()) return 1;
1227 Handle(Geom_Surface) surf2 = Handle(Geom_Surface)::
1228 DownCast(s2->Transformed(L2.Transformation()));
1229 if (surf2.IsNull()) return 1;
1233 nbeval = (Standard_Integer ) Draw::Atof( a[3]);
1236 { case 6 : epsC0 = Draw::Atof(a[5]);
1237 case 5 : epsnl = Draw::Atof(a[4]);
1243 Standard_Real pard1, parf1, U, Uf, deltaU, nb = 0;
1244 Standard_Boolean isconti = Standard_True;
1245 Standard_Boolean isdone = Standard_True;
1246 pard1 = curv1->FirstParameter();
1247 parf1 = curv1->LastParameter();
1248 Standard_Real MaxG0Value=0;
1249 U = Min( pard1,parf1);
1250 Uf = Max (pard1,parf1);
1252 deltaU = Abs(parf1- pard1)/nbeval;
1255 { if ( nb == nbeval)
1256 { LocalAnalysis_SurfaceContinuity res (curv1, curv2, Uf,surf1, surf2, GeomAbs_C0,epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen );
1257 isdone = res.IsDone();
1258 if ( isdone) { isconti = res.IsC0( );
1260 if (res.C0Value()>MaxG0Value) MaxG0Value= res.C0Value();}
1261 else isconti = Standard_False;}
1263 else {LocalAnalysis_SurfaceContinuity res (curv1, curv2, (U+nb*deltaU), surf1, surf2, GeomAbs_C0,epsnl,epsC0, epsC1, epsC2, epsG1, percent,maxlen );
1264 isdone = res.IsDone();
1265 if ( isdone) { isconti = res.IsC0() ;
1266 if ( nb == 0) { MaxG0Value = res.C0Value();}
1267 if (res.C0Value()> MaxG0Value) MaxG0Value = res.C0Value();}
1269 else isconti = Standard_False;}
1272 if (!isconti) ISG0=Standard_False;
1275 while ((nb<nbeval)&& isdone );
1277 //f (!isdone) { cout<<" Problem in computation "<<endl; return 1;}
1279 // {cout<<" the continuity is G0 "<<endl;}
1281 //else { cout<<" the continuity is not G0 "<<endl;}
1282 //cout<<"MaxG0Value :"<< MaxG0Value << endl;
1283 if (!isdone) { di<<" Problem in computation "<<"\n"; return 1;}
1285 {di<<" the continuity is G0 "<<"\n";}
1287 else { di<<" the continuity is not G0 "<<"\n";}
1288 di<<"MaxG0Value :"<< MaxG0Value << "\n";
1291 /*****************************************************************************************/
1292 static Standard_Integer shapeG2continuity (Draw_Interpretor& di, Standard_Integer n, const char** a)
1294 { Standard_Real epsnl,epsC0, epsC1, epsC2, epsG1, percent,maxlen;
1295 Standard_Boolean ISG2=Standard_True;
1296 Standard_Integer nbeval;
1297 Standard_Real MaxG0Value=0,MaxG1Angle=0,MaxG2Curvature=0;
1298 InitEpsSurf(epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen );
1301 TopoDS_Face face1,face2;
1302 Standard_Real f1,f2,l1,l2;
1303 TopoDS_Shape shape = DBRep::Get(a[1],TopAbs_SHAPE);
1304 if (shape.IsNull()) return 1;
1305 TopoDS_Shape edge = DBRep::Get(a[2],TopAbs_EDGE);
1306 if (edge.IsNull()) return 1;
1307 // calcul des deux faces
1308 TopTools_IndexedDataMapOfShapeListOfShape lface;
1309 TopExp::MapShapesAndAncestors(shape,TopAbs_EDGE,TopAbs_FACE,lface);
1310 const TopTools_ListOfShape& lfac = lface.FindFromKey(edge);
1312 Standard_Integer nelem= lfac.Extent();
1313 if(nelem!=2) return 1;
1314 TopTools_ListIteratorOfListOfShape It;
1315 It.Initialize(lfac);
1316 face1=TopoDS::Face(It.Value());
1318 face2=TopoDS::Face(It.Value());
1319 // calcul des deux pcurves
1320 const Handle(Geom2d_Curve) c1 = BRep_Tool::CurveOnSurface
1321 (TopoDS::Edge(edge),face1,f1,l1);
1322 if (c1.IsNull()) return 1;
1323 const Handle(Geom2d_Curve) c2 = BRep_Tool::CurveOnSurface
1324 (TopoDS::Edge(edge),face2,f2,l2);
1325 if (c2.IsNull()) return 1;
1327 Handle(Geom2d_Curve) curv1= new Geom2d_TrimmedCurve(c1,f1,l1);
1329 Handle(Geom2d_Curve) curv2= new Geom2d_TrimmedCurve(c2,f2,l2);
1331 // calcul des deux surfaces
1332 TopLoc_Location L1,L2;
1333 TopoDS_Face aLocalFace = face1;
1334 const Handle(Geom_Surface)& s1 = BRep_Tool::Surface(aLocalFace,L1);
1335 // const Handle(Geom_Surface)& s1 =
1336 // BRep_Tool::Surface(TopoDS::Face(face1),L1);
1337 if (s1.IsNull()) return 1;
1339 const Handle(Geom_Surface)& s2 = BRep_Tool::Surface(aLocalFace,L2);
1340 // const Handle(Geom_Surface)& s2 =
1341 // BRep_Tool::Surface(TopoDS::Face(face2),L2);
1342 if (s2.IsNull()) return 1;
1345 Handle(Geom_Surface) surf1 = Handle(Geom_Surface)::
1346 DownCast(s1->Transformed(L1.Transformation()));
1347 if (surf1.IsNull()) return 1;
1348 Handle(Geom_Surface) surf2 = Handle(Geom_Surface)::
1349 DownCast(s2->Transformed(L2.Transformation()));
1350 if (surf2.IsNull()) return 1;
1354 nbeval = (Standard_Integer ) Draw::Atof( a[3]);
1358 case 9 : maxlen = Draw::Atof(a[8]);
1359 case 8 : percent = Draw::Atof(a[7]);
1360 case 7 : epsG1 = Draw::Atof(a[6]);
1361 case 6 : epsC0 = Draw::Atof(a[5]);
1362 case 5 : epsnl = Draw::Atof(a[4]);
1368 Standard_Real pard1, parf1, U, Uf, deltaU, nb = 0;
1369 Standard_Boolean isconti = Standard_True;
1370 Standard_Boolean isdone = Standard_True;
1371 pard1 = curv1->FirstParameter();
1372 parf1 = curv1->LastParameter();
1373 U = Min( pard1,parf1);
1374 Uf = Max (pard1,parf1);
1376 deltaU = Abs(parf1- pard1)/nbeval;
1379 { if ( nb == nbeval)
1380 { LocalAnalysis_SurfaceContinuity res (curv1, curv2, Uf,surf1, surf2, GeomAbs_G2,epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen );
1381 isdone = res.IsDone();
1382 if (isdone){isconti = res.IsG2();
1384 {if(res.C0Value()>MaxG0Value) MaxG0Value=res.C0Value();
1385 if(res.G1Angle()>MaxG1Angle) MaxG1Angle=res.G1Angle();
1386 if(res.G2CurvatureGap()>MaxG2Curvature)
1387 MaxG2Curvature=res.G2CurvatureGap();
1389 else isconti = Standard_False;}
1391 else { LocalAnalysis_SurfaceContinuity res (curv1, curv2, (U+nb*deltaU), surf1,surf2, GeomAbs_G2,epsnl,epsC0, epsC1, epsC2, epsG1,percent,maxlen );
1392 isdone = res.IsDone();
1393 if ( isdone) {isconti = res.IsG2();
1394 if (nb==0){MaxG0Value=res.C0Value();
1395 MaxG1Angle=res.G1Angle();
1396 MaxG2Curvature=res.G2CurvatureGap();}
1397 if(res.C0Value()>MaxG0Value)
1398 MaxG0Value=res.C0Value();
1399 if(res.G1Angle()>MaxG1Angle)
1400 MaxG1Angle=res.G1Angle();
1401 if(res.G2CurvatureGap()>MaxG2Curvature)
1402 MaxG2Curvature=res.G2CurvatureGap();}
1403 else isconti = Standard_False;}
1406 if (!isconti) ISG2=Standard_False;
1409 while ((nb<nbeval)&& isdone );
1411 //if (!isdone) { cout<<" Problem in computation "<<endl; return 1;}
1413 //cout<<" the continuity is G2 "<<endl;
1414 //else cout<<" the continuity is not G2 "<<endl;
1415 //cout<<"MaxG0Value :"<< MaxG0Value << endl;
1416 //cout<<"MaxG1Angle:"<< MaxG1Angle << endl;
1417 //cout<<"MaxG2Curvature:"<<MaxG2Curvature<<endl;
1418 if (!isdone) { di<<" Problem in computation "<<"\n"; return 1;}
1420 di<<" the continuity is G2 "<<"\n";
1421 else di<<" the continuity is not G2 "<<"\n";
1422 di<<"MaxG0Value :"<< MaxG0Value << "\n";
1423 di<<"MaxG1Angle:"<< MaxG1Angle << "\n";
1424 di<<"MaxG2Curvature:"<<MaxG2Curvature<<"\n";
1429 //=======================================================================
1430 //function : clintedge
1432 //=======================================================================
1433 static Standard_Integer clintedge(Draw_Interpretor& di,
1434 Standard_Integer narg, const char** a)
1439 //cout << "Usage: clintedge shape" << endl;
1440 di << "Usage: clintedge shape" << "\n";
1443 TopoDS_Shape S = DBRep::Get(a[1]);
1445 TopTools_DataMapOfShapeListOfShape mymap;
1446 TopOpeBRepTool_PurgeInternalEdges mypurgealgo(S);
1447 Standard_Integer nbedges;
1449 if ((nbedges = mypurgealgo.NbEdges())) {
1451 //cout<<nbedges<<" internal (or external) edges to be removed"<<endl;
1452 di<<nbedges<<" internal (or external) edges to be removed"<<"\n";
1454 Standard_Integer i = 1;
1455 char* temp = newname;
1457 Sprintf(newname,"%s_%d",a[1],i);
1458 DBRep::Set(temp,mypurgealgo.Shape());
1459 //cout<<newname<<" ";
1466 di << "no internal (or external) edges"<<"\n";
1467 //cout << "no internal (or external) edges"<<endl;
1473 //=======================================================================
1474 //function : facintedge
1476 //=======================================================================
1477 static Standard_Integer facintedge(Draw_Interpretor& di,
1478 Standard_Integer narg, const char** a)
1483 //cout << "Usage: facintedge shape" << endl;
1484 di << "Usage: facintedge shape" << "\n";
1487 TopoDS_Shape S = DBRep::Get(a[1]);
1489 TopTools_DataMapOfShapeListOfShape mymap;
1490 TopOpeBRepTool_PurgeInternalEdges mypurgealgo(S);
1491 mypurgealgo.Faces(mymap);
1493 Standard_Integer i = 1;
1494 char* temp = newname;
1496 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itFacEdg;
1497 for (itFacEdg.Initialize(mymap); itFacEdg.More(); itFacEdg.Next()) {
1498 Sprintf(newname,"%s_%d",a[1],i);
1499 DBRep::Set(temp,itFacEdg.Key());
1500 //cout<<newname<<" ";
1511 //=======================================================================
1512 //function : fuseedge
1514 //=======================================================================
1515 static Standard_Integer fuseedge(Draw_Interpretor& di,
1516 Standard_Integer narg, const char** a)
1521 //cout << "Usage: fuseedge shape" << endl;
1522 di << "Usage: fuseedge shape" << "\n";
1525 TopoDS_Shape S = DBRep::Get(a[1]);
1527 TopTools_DataMapOfIntegerListOfShape mymap;
1528 //TopOpeBRepTool_FuseEdges myfusealgo(S);
1529 BRepLib_FuseEdges myfusealgo(S);
1530 myfusealgo.SetConcatBSpl();
1531 Standard_Integer nbvertices;
1532 nbvertices = myfusealgo.NbVertices();
1534 if (nbvertices > 0) {
1536 //cout<<nbvertices<<" vertices to be removed"<<endl;
1537 di<<nbvertices<<" vertices to be removed"<<"\n";
1539 Standard_Integer i = 1;
1540 char* temp = newname;
1542 Sprintf(newname,"%s_%d",a[1],i);
1543 DBRep::Set(temp,myfusealgo.Shape());
1544 //cout<<newname<<" ";
1551 di << "no vertices to remove"<<"\n";
1552 //cout << "no vertices to remove"<<endl;
1558 //=======================================================================
1559 //function : listfuseedge
1561 //=======================================================================
1562 static Standard_Integer listfuseedge(Draw_Interpretor& di,
1563 Standard_Integer narg, const char** a)
1568 //cout << "Usage: listfuseedge shape" << endl;
1569 di << "Usage: listfuseedge shape" << "\n";
1572 TopoDS_Shape S = DBRep::Get(a[1]);
1574 TopTools_DataMapOfIntegerListOfShape mymap;
1575 BRepLib_FuseEdges myfusealgo(S);
1576 myfusealgo.Edges(mymap);
1579 char* temp = newname;
1581 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape itLstEdg;
1582 for (itLstEdg.Initialize(mymap); itLstEdg.More(); itLstEdg.Next()) {
1583 const Standard_Integer& iLst = itLstEdg.Key();
1584 const TopTools_ListOfShape& LmapEdg = mymap.Find(iLst);
1585 TopTools_ListIteratorOfListOfShape itEdg;
1587 for (itEdg.Initialize(LmapEdg); itEdg.More(); itEdg.Next()) {
1588 Sprintf(newname,"%s_%d_%d",a[1],iLst,i);
1589 DBRep::Set(temp,itEdg.Value());
1590 //cout<<newname<<" ";
1605 //=======================================================================
1606 //function : CheckCommands
1608 //=======================================================================
1610 void BRepTest::CheckCommands(Draw_Interpretor& theCommands)
1612 static Standard_Boolean done = Standard_False;
1614 done = Standard_True;
1616 BRepTest_CheckCommands_SetFaultyName("faulty_");
1617 DBRep::BasicCommands(theCommands);
1619 const char* g = "TOPOLOGY Check commands";
1621 // Modified by skv - Tue Apr 27 13:35:35 2004 Begin
1622 theCommands.Add("checkshape",
1623 "checkshape : no args to have help",
1627 // theCommands.Add("checkshape",
1628 // "checks the validity of a shape : checkshape name,\n short description of check : checkshape name -short",
1632 // theCommands.Add("checktopshape",
1633 // "checks the topological validity of a shape : checktopshape name",
1637 // Modified by skv - Tue Apr 27 13:35:39 2004 End
1639 theCommands.Add("checksection",
1640 "checks the closure of a section : checksection name",
1645 theCommands.Add("checkdiff",
1646 "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)]",
1651 g = "TOPOLOGY Analysis of shapes ";
1653 theCommands.Add("shapeG0continuity",
1654 "shapeG0continuity shape edge nbeval [epsnul [epsG0]]",
1656 shapeG0continuity, g);
1658 theCommands.Add("shapeG1continuity",
1659 "shapeG1continuity shape edge nbeval [epsnul [epsG0 [epsG1]]]",
1661 shapeG1continuity ,g);
1662 theCommands.Add("shapeG2continuity",
1663 "shapeG2continuity shape edge nbeval [epsnul [epsG0 [epsG1 [maxlen [perce]]]]]",
1665 shapeG2continuity,g);
1667 theCommands.Add("computetolerance",
1668 "computetolerance shape",
1670 computetolerance,g);
1672 theCommands.Add("clintedge",
1677 theCommands.Add("facintedge",
1682 theCommands.Add("fuseedge",
1687 theCommands.Add("listfuseedge",
1688 "listfuseedge shape",