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