| 1 | // Created on: 1999-03-09 |
| 2 | // Created by: data exchange team |
| 3 | // Copyright (c) 1999-1999 Matra Datavision |
| 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 8 | // This library is free software; you can redistribute it and / or modify it |
| 9 | // under the terms of the GNU Lesser General Public version 2.1 as published |
| 10 | // by the Free Software Foundation, with special exception defined in the file |
| 11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 12 | // distribution for complete text of the license and disclaimer of any warranty. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | //gka,rln 30.04.99 S4137: new commands for testing ShapeDivide added, some removed |
| 18 | //abv,pdn 05.05.99 S4174: new commands for testing ShapeDivide added, some removed |
| 19 | //pdn,gka 10.06.99 S4189: command DT_ShapeConvertRev added |
| 20 | |
| 21 | #include <SWDRAW_ShapeUpgrade.ixx> |
| 22 | //#include <SWDRAW_ShapeUpgrade.hxx> |
| 23 | |
| 24 | #include <Draw.hxx> |
| 25 | #include <DBRep.hxx> |
| 26 | #include <ShapeUpgrade.hxx> |
| 27 | #include <ShapeUpgrade_SplitCurve3dContinuity.hxx> |
| 28 | #include <ShapeUpgrade_SplitCurve2dContinuity.hxx> |
| 29 | #include <ShapeUpgrade_SplitSurfaceContinuity.hxx> |
| 30 | //#include <ShapeUpgrade_SupportModification.hxx> |
| 31 | #include <Draw_Interpretor.hxx> |
| 32 | #include <DrawTrSurf.hxx> |
| 33 | #include <Geom_Curve.hxx> |
| 34 | #include <Geom_Plane.hxx> |
| 35 | #include <Geom_Surface.hxx> |
| 36 | #include <Geom2d_Curve.hxx> |
| 37 | #include <TColGeom_HArray1OfCurve.hxx> |
| 38 | #include <TColGeom_HArray2OfSurface.hxx> |
| 39 | #include <TColStd_Array1OfReal.hxx> |
| 40 | #include <TColStd_HArray1OfReal.hxx> |
| 41 | #include <TColStd_HSequenceOfReal.hxx> |
| 42 | #include <TopoDS.hxx> |
| 43 | #include <TopoDS_Edge.hxx> |
| 44 | #include <TopoDS_Face.hxx> |
| 45 | #include <TopoDS_Shape.hxx> |
| 46 | #include <TopoDS_Shell.hxx> |
| 47 | #include <TopoDS_Wire.hxx> |
| 48 | #include <TopoDS_Compound.hxx> |
| 49 | #include <TopExp_Explorer.hxx> |
| 50 | #include <TColGeom_HArray2OfSurface.hxx> |
| 51 | #include <TColGeom2d_HArray1OfCurve.hxx> |
| 52 | #include <BRepBuilderAPI.hxx> |
| 53 | #include <SWDRAW.hxx> |
| 54 | #include <ShapeUpgrade_ShapeDivideArea.hxx> |
| 55 | |
| 56 | #include <stdio.h> |
| 57 | //#include <ShapeExtend_WireData.hxx> |
| 58 | //#include <ShapeAnalysis_Shell.hxx> |
| 59 | //#include <ShapeAnalysis_WireOrder.hxx> |
| 60 | //#include <ShapeAnalysis_Wire.hxx> |
| 61 | //#include <ShapeUpgrade_ShellSewing.hxx> |
| 62 | #include <Geom2d_Curve.hxx> |
| 63 | #include <Geom2d_OffsetCurve.hxx> |
| 64 | #include <Geom_OffsetCurve.hxx> |
| 65 | #include <ShapeUpgrade_SplitCurve3dContinuity.hxx> |
| 66 | #include <TopoDS_Iterator.hxx> |
| 67 | #include <BRep_Tool.hxx> |
| 68 | #include <ShapeExtend_CompositeSurface.hxx> |
| 69 | #include <Geom_RectangularTrimmedSurface.hxx> |
| 70 | #include <TColGeom_HArray2OfSurface.hxx> |
| 71 | #include <ShapeFix_ComposeShell.hxx> |
| 72 | #include <Precision.hxx> |
| 73 | #include <ShapeBuild_ReShape.hxx> |
| 74 | #include <BRepTools.hxx> |
| 75 | #include <ShapeFix.hxx> |
| 76 | #include <ShapeUpgrade_ShapeDivideContinuity.hxx> |
| 77 | #include <ShapeUpgrade_ShapeDivideAngle.hxx> |
| 78 | #include <ShapeUpgrade_ShapeConvertToBezier.hxx> |
| 79 | #include <ShapeCustom.hxx> |
| 80 | #include <ShapeUpgrade_ShapeDivideClosed.hxx> |
| 81 | #include <ShapeUpgrade_RemoveInternalWires.hxx> |
| 82 | #include <ShapeUpgrade_RemoveLocations.hxx> |
| 83 | #include <ShapeUpgrade_UnifySameDomain.hxx> |
| 84 | #include <BRepBuilderAPI_Transform.hxx> |
| 85 | |
| 86 | // the plane (equation z=0) shared by PlaneDividedFaceContinuity and PlaneGridShell |
| 87 | //static Handle(Geom_Plane) ThePlane= new Geom_Plane(0,0,1,0); |
| 88 | |
| 89 | |
| 90 | //======================================================================= |
| 91 | //function : DT_ShapeDivide |
| 92 | //purpose : |
| 93 | //======================================================================= |
| 94 | |
| 95 | static Standard_Integer DT_ShapeDivide (Draw_Interpretor& di, |
| 96 | Standard_Integer n, const char** a) |
| 97 | { |
| 98 | // DT_ShapeDivide result Shape Tol |
| 99 | // a[1]= result |
| 100 | // a[2]= input Face/Surface |
| 101 | // a[3] si n>3= Wire/Face |
| 102 | // a[n-1]= Tolerance |
| 103 | |
| 104 | if (n<3) { |
| 105 | di << "bad number of arguments" <<"\n"; |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | // try to read a shape: |
| 110 | TopoDS_Shape inputShape=DBRep::Get(a[2]); |
| 111 | if (inputShape.IsNull()) { |
| 112 | di << "Unknown shape"<< "\n"; |
| 113 | return 1; |
| 114 | } |
| 115 | // a[2] is a shape. managing: |
| 116 | // DT_ShapeDivide result Face Tol |
| 117 | |
| 118 | // giving a face is available only in the constructor: |
| 119 | // we make the whole and quit. |
| 120 | ShapeUpgrade_ShapeDivideContinuity tool(inputShape); |
| 121 | |
| 122 | // tolerance is optional |
| 123 | if (n==4) { |
| 124 | Standard_Real Tol=Draw::Atof(a[3]); |
| 125 | tool.SetTolerance(Tol); |
| 126 | } |
| 127 | |
| 128 | // theTool.SetGlobalCriterion(GeomAbs_C1); |
| 129 | tool.Perform(); |
| 130 | TopoDS_Shape res = tool.Result(); |
| 131 | |
| 132 | if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n"; |
| 133 | if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n"; |
| 134 | if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n"; |
| 135 | if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n"; |
| 136 | if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n"; |
| 137 | if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n"; |
| 138 | if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n"; |
| 139 | if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n"; |
| 140 | if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n"; |
| 141 | if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n"; |
| 142 | if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n"; |
| 143 | if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n"; |
| 144 | if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n"; |
| 145 | if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n"; |
| 146 | if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n"; |
| 147 | if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n"; |
| 148 | if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n"; |
| 149 | |
| 150 | // fixes |
| 151 | |
| 152 | ShapeFix::SameParameter ( res, Standard_False ); |
| 153 | |
| 154 | DBRep::Set(a[1],res); |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static Standard_Integer DT_ShapeConvertRev (Draw_Interpretor& di, |
| 159 | Standard_Integer n, const char** a) |
| 160 | { |
| 161 | if (n<5) { |
| 162 | di << "bad number of arguments" <<"\n"; |
| 163 | return 1; |
| 164 | } |
| 165 | |
| 166 | // try to read a shape: |
| 167 | TopoDS_Shape inputShape=DBRep::Get(a[2]); |
| 168 | if (inputShape.IsNull()) { |
| 169 | di << "Unknown shape"<< "\n"; |
| 170 | return 1; |
| 171 | } |
| 172 | |
| 173 | Standard_Integer c2d = Draw::Atoi(a[3]); |
| 174 | Standard_Integer c3d = Draw::Atoi(a[4]); |
| 175 | TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape); |
| 176 | if (revsh.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; } |
| 177 | else if (revsh == inputShape) { di<<"No modif"<<"\n";} |
| 178 | else di<<"ConvertToRevolution -> Result : "<<"\n"; |
| 179 | |
| 180 | ShapeUpgrade_ShapeConvertToBezier tool(revsh); |
| 181 | tool.SetSurfaceConversion(Standard_True); |
| 182 | if(c2d) |
| 183 | tool.Set2dConversion(Standard_True); |
| 184 | if(c3d) { |
| 185 | tool.Set3dConversion(Standard_True); |
| 186 | if(n > 5) |
| 187 | tool.Set3dLineConversion(Standard_False); |
| 188 | if(n > 6) |
| 189 | tool.Set3dCircleConversion(Standard_False); |
| 190 | if(n > 7) |
| 191 | tool.Set3dConicConversion(Standard_False); |
| 192 | } |
| 193 | tool.Perform(); |
| 194 | TopoDS_Shape res = tool.Result(); |
| 195 | |
| 196 | if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n"; |
| 197 | if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n"; |
| 198 | if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n"; |
| 199 | if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n"; |
| 200 | if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n"; |
| 201 | if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n"; |
| 202 | if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n"; |
| 203 | if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n"; |
| 204 | if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n"; |
| 205 | if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n"; |
| 206 | if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n"; |
| 207 | if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n"; |
| 208 | if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n"; |
| 209 | if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n"; |
| 210 | if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n"; |
| 211 | if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n"; |
| 212 | if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n"; |
| 213 | |
| 214 | // fixes |
| 215 | |
| 216 | ShapeFix::SameParameter ( res, Standard_False ); |
| 217 | |
| 218 | DBRep::Set(a[1],res); |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /* |
| 224 | if (!inputShape.IsNull()) { |
| 225 | // a[2] is a shape. managing: |
| 226 | // DT_ShapeDivide result Face Tol |
| 227 | |
| 228 | TopoDS_Face inputFace = TopoDS::Face(inputShape); |
| 229 | if (inputFace.IsNull()) { |
| 230 | di << a[2] << " is not a face" << "\n"; |
| 231 | return 1; |
| 232 | } |
| 233 | |
| 234 | // giving a face is available only in the constructor: |
| 235 | // we make the whole and quit. |
| 236 | ShapeUpgrade_ShapeDivideContinuity theTool(inputFace); |
| 237 | |
| 238 | // tolerance is optional |
| 239 | if (n==4) { |
| 240 | Standard_Real Tol=Draw::Atof(a[n-1]); |
| 241 | theTool.SetTolerance(Tol); |
| 242 | } |
| 243 | |
| 244 | theTool.SetGlobalCriterion(GeomAbs_C1); |
| 245 | theTool.Build(); |
| 246 | if (!theTool.IsDone()) { |
| 247 | ShapeUpgrade_Error theError=theTool.Error(); |
| 248 | di << "Not done: error="; |
| 249 | if (theError==ShapeUpgrade_Done) |
| 250 | di << "Done"<<"\n"; |
| 251 | else if (theError==ShapeUpgrade_NotDone) |
| 252 | di << "NotDone"<<"\n"; |
| 253 | else if (theError==ShapeUpgrade_EmptyShell) |
| 254 | di << "EmptyShell"<<"\n"; |
| 255 | else if (theError==ShapeUpgrade_InvalidCriterion) |
| 256 | di << "InvalidCriterion"<<"\n"; |
| 257 | else if (theError==ShapeUpgrade_InvalidGridSurface) |
| 258 | di << "InvalidGridSurface"<<"\n"; |
| 259 | else if (theError==ShapeUpgrade_DegeneratedEdge) |
| 260 | di << "DegeneratedEdge"<<"\n"; |
| 261 | else if (theError==ShapeUpgrade_NoSurface) |
| 262 | di << "NoSurface"<<"\n"; |
| 263 | else if (theError==ShapeUpgrade_NoTolerance) |
| 264 | di << "NoTolerance"<<"\n"; |
| 265 | return 1; |
| 266 | } |
| 267 | TopoDS_Shell res = theTool.Shell(); |
| 268 | DBRep::Set(a[1],res); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | else { |
| 273 | // not a face: we can use the empty consturctor. |
| 274 | ShapeUpgrade_ShapeDivideContinuity theTool; |
| 275 | Standard_Real Tol=Draw::Atof(a[n-1]); |
| 276 | theTool.SetTolerance(Tol); |
| 277 | theTool.SetGlobalCriterion(GeomAbs_C1); |
| 278 | |
| 279 | // try to read a surface: |
| 280 | Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]); |
| 281 | if (! GS.IsNull()) { |
| 282 | // a[2] is a surface. managing the configurations: |
| 283 | // DT_ShapeDivide result Surface Tol |
| 284 | // DT_ShapeDivide result Surface Face Tol |
| 285 | // DT_ShapeDivide result Surface Wire Surf Tol |
| 286 | |
| 287 | theTool.SetSupport(GS); |
| 288 | |
| 289 | // try to read a Wire or a Face: |
| 290 | if (n>=5) { |
| 291 | TopoDS_Shape inputBoundary=DBRep::Get(a[3]); |
| 292 | if (inputBoundary.IsNull()) { |
| 293 | di << "Invalid Boundary" << "\n"; |
| 294 | return 1; |
| 295 | } |
| 296 | TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary); |
| 297 | if (!WireBoundary.IsNull()) { |
| 298 | // DT_ShapeDivide result Surface Wire Surf Tol |
| 299 | Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4]); |
| 300 | if (WireSupport.IsNull()) { |
| 301 | di << "Invalid Surface supporting the Wire" << "\n"; |
| 302 | return 1; |
| 303 | } |
| 304 | theTool.SetBoundary(WireBoundary, WireSupport); |
| 305 | } |
| 306 | else { |
| 307 | TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary); |
| 308 | // DT_ShapeDivide result Surface Face Tol |
| 309 | theTool.SetBoundary(FaceBoundary); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | else { |
| 314 | // it must be a grid: managing the configurations: |
| 315 | // DT_ShapeDivide result NbU NbV {Surf_u_v...} Tol |
| 316 | // DT_ShapeDivide result NbU NbV {Surf_u_v...} Face Tol |
| 317 | // DT_ShapeDivide result NbU NbV {Surf_u_v...} Wire Surf Tol |
| 318 | if (n<6) { |
| 319 | di << "bad number of arguments for grid input" <<"\n"; |
| 320 | return 1; |
| 321 | } |
| 322 | // number of surf: |
| 323 | Standard_Integer NbU=Draw::Atoi(a[2]); |
| 324 | Standard_Integer NbV=Draw::Atoi(a[3]); |
| 325 | if (n < 4+NbU*NbV+1) { |
| 326 | di << "bad number of arguments" <<"\n"; |
| 327 | return 1; |
| 328 | } |
| 329 | |
| 330 | Handle(TColGeom_HArray2OfSurface) |
| 331 | TheGridSurf= new TColGeom_HArray2OfSurface(1,NbU,1,NbV); |
| 332 | |
| 333 | for (Standard_Integer iu=1; iu<=NbU; iu++) { |
| 334 | for (Standard_Integer jv=1; jv<=NbV; jv++) { |
| 335 | Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[4+(iu-1)*NbV+jv-1]); |
| 336 | TheGridSurf->SetValue(iu,jv,GS); |
| 337 | } |
| 338 | } |
| 339 | theTool.SetSupport(TheGridSurf,Tol); |
| 340 | |
| 341 | // try to read a Wire or a Face: |
| 342 | if (n>=6+NbU*NbV) { |
| 343 | TopoDS_Shape inputBoundary=DBRep::Get(a[4+NbU*NbV]); |
| 344 | if (inputBoundary.IsNull()) { |
| 345 | di << "Invalid Boundary" << "\n"; |
| 346 | return 1; |
| 347 | } |
| 348 | TopoDS_Wire WireBoundary = TopoDS::Wire(inputBoundary); |
| 349 | if (!WireBoundary.IsNull()) { |
| 350 | // DT_ShapeDivide result Surface Wire Surf Tol |
| 351 | Handle(Geom_Surface) WireSupport = DrawTrSurf::GetSurface(a[4+NbU*NbV+1]); |
| 352 | if (WireSupport.IsNull()) { |
| 353 | di << "Invalid Surface supporting the Wire" << "\n"; |
| 354 | return 1; |
| 355 | } |
| 356 | theTool.SetBoundary(WireBoundary, WireSupport); |
| 357 | } |
| 358 | else { |
| 359 | TopoDS_Face FaceBoundary = TopoDS::Face(inputBoundary); |
| 360 | // DT_ShapeDivide result Surface Face Tol |
| 361 | theTool.SetBoundary(FaceBoundary); |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | theTool.Build(); |
| 367 | if (!theTool.IsDone()) { |
| 368 | ShapeUpgrade_Error theError=theTool.Error(); |
| 369 | di << "Not done: error="; |
| 370 | if (theError==ShapeUpgrade_Done) |
| 371 | di << "Done"<<"\n"; |
| 372 | else if (theError==ShapeUpgrade_NotDone) |
| 373 | di << "NotDone"<<"\n"; |
| 374 | else if (theError==ShapeUpgrade_EmptyShell) |
| 375 | di << "EmptyShell"<<"\n"; |
| 376 | else if (theError==ShapeUpgrade_InvalidCriterion) |
| 377 | di << "InvalidCriterion"<<"\n"; |
| 378 | else if (theError==ShapeUpgrade_InvalidGridSurface) |
| 379 | di << "InvalidGridSurface"<<"\n"; |
| 380 | else if (theError==ShapeUpgrade_DegeneratedEdge) |
| 381 | di << "DegeneratedEdge"<<"\n"; |
| 382 | else if (theError==ShapeUpgrade_NoSurface) |
| 383 | di << "NoSurface"<<"\n"; |
| 384 | else if (theError==ShapeUpgrade_NoTolerance) |
| 385 | di << "NoTolerance"<<"\n"; |
| 386 | return 1; |
| 387 | } |
| 388 | |
| 389 | TopoDS_Shell res = theTool.Shell(); |
| 390 | DBRep::Set(a[1],res); |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | } |
| 395 | */ |
| 396 | static Standard_Integer DT_ShapeConvert (Draw_Interpretor& di, |
| 397 | Standard_Integer n, const char** a) |
| 398 | { |
| 399 | if (n<5) { |
| 400 | di << "bad number of arguments" <<"\n"; |
| 401 | return 1; |
| 402 | } |
| 403 | |
| 404 | // try to read a shape: |
| 405 | TopoDS_Shape inputShape=DBRep::Get(a[2]); |
| 406 | if (inputShape.IsNull()) { |
| 407 | di << "Unknown shape"<< "\n"; |
| 408 | return 1; |
| 409 | } |
| 410 | |
| 411 | Standard_Integer c2d = Draw::Atoi(a[3]); |
| 412 | Standard_Integer c3d = Draw::Atoi(a[4]); |
| 413 | |
| 414 | ShapeUpgrade_ShapeConvertToBezier tool(inputShape); |
| 415 | tool.SetSurfaceConversion(Standard_True); |
| 416 | if(c2d) |
| 417 | tool.Set2dConversion(Standard_True); |
| 418 | if(c3d) |
| 419 | tool.Set3dConversion(Standard_True); |
| 420 | tool.Perform(); |
| 421 | TopoDS_Shape res = tool.Result(); |
| 422 | |
| 423 | if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n"; |
| 424 | if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n"; |
| 425 | if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n"; |
| 426 | if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n"; |
| 427 | if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n"; |
| 428 | if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n"; |
| 429 | if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n"; |
| 430 | if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n"; |
| 431 | if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n"; |
| 432 | if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n"; |
| 433 | if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n"; |
| 434 | if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n"; |
| 435 | if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n"; |
| 436 | if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n"; |
| 437 | if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n"; |
| 438 | if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n"; |
| 439 | if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n"; |
| 440 | |
| 441 | // fixes |
| 442 | |
| 443 | ShapeFix::SameParameter ( res, Standard_False ); |
| 444 | |
| 445 | DBRep::Set(a[1],res); |
| 446 | return 0; |
| 447 | } |
| 448 | static Standard_Integer DT_SplitAngle(Draw_Interpretor& di, |
| 449 | Standard_Integer n, const char** a) |
| 450 | { |
| 451 | if (n<3) { |
| 452 | di << "bad number of arguments" <<"\n"; |
| 453 | return 1; |
| 454 | } |
| 455 | |
| 456 | TopoDS_Shape inputShape=DBRep::Get(a[2]); |
| 457 | if (inputShape.IsNull()) { |
| 458 | di << "Unknown shape"<< "\n"; |
| 459 | return 1; |
| 460 | } |
| 461 | |
| 462 | Standard_Real maxangle = 95; |
| 463 | if ( n >3 ) { |
| 464 | maxangle = Draw::Atof ( a[3] ); |
| 465 | if ( maxangle <1 ) maxangle = 1; |
| 466 | } |
| 467 | |
| 468 | ShapeUpgrade_ShapeDivideAngle tool(maxangle * M_PI/180,inputShape); |
| 469 | tool.Perform(); |
| 470 | TopoDS_Shape res = tool.Result(); |
| 471 | |
| 472 | if ( tool.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n"; |
| 473 | if ( tool.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n"; |
| 474 | if ( tool.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n"; |
| 475 | if ( tool.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n"; |
| 476 | if ( tool.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n"; |
| 477 | if ( tool.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n"; |
| 478 | if ( tool.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n"; |
| 479 | if ( tool.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n"; |
| 480 | if ( tool.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n"; |
| 481 | if ( tool.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n"; |
| 482 | if ( tool.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n"; |
| 483 | if ( tool.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n"; |
| 484 | if ( tool.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n"; |
| 485 | if ( tool.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n"; |
| 486 | if ( tool.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n"; |
| 487 | if ( tool.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n"; |
| 488 | if ( tool.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n"; |
| 489 | |
| 490 | // fixes |
| 491 | |
| 492 | ShapeFix::SameParameter ( res, Standard_False ); |
| 493 | |
| 494 | DBRep::Set(a[1],res); |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | //======================================================================= |
| 500 | //function : DT_PlaneDividedFace |
| 501 | //purpose : Transfer into a plane with boundary divided |
| 502 | // |
| 503 | // |
| 504 | //======================================================================= |
| 505 | static Standard_Integer DT_PlaneDividedFace (Draw_Interpretor& di, |
| 506 | Standard_Integer n, const char** a) |
| 507 | |
| 508 | { |
| 509 | // a[1]= result |
| 510 | // a[2]= input Face |
| 511 | // a[3]= Tolerance |
| 512 | |
| 513 | if (n !=4) { |
| 514 | di << "bad number of arguments" <<"\n"; |
| 515 | return 1; |
| 516 | } |
| 517 | |
| 518 | Standard_Real Tol=Draw::Atof(a[3]); |
| 519 | TopoDS_Shape inputShape=DBRep::Get(a[2]); |
| 520 | TopoDS_Face inputFace = TopoDS::Face(inputShape); |
| 521 | if (inputFace.IsNull()) { |
| 522 | di << a[2] << " is not a face" << "\n"; |
| 523 | return 1; |
| 524 | } |
| 525 | |
| 526 | ShapeUpgrade_PlaneDividedFace theTool(ThePlane); |
| 527 | theTool.Init(inputFace); |
| 528 | //theTool.SetBoundaryCriterion(GeomAbs_C1); |
| 529 | //theTool.SetTolerance(Tol); |
| 530 | theTool.Build(); |
| 531 | if (!theTool.IsDone()) { |
| 532 | di << "Not done" << "\n"; |
| 533 | return 1; |
| 534 | } |
| 535 | |
| 536 | TopoDS_Face res = theTool.Face(); |
| 537 | DBRep::Set(a[1],res); |
| 538 | |
| 539 | Standard_Real the2d3dFactor=theTool.Get2d3dFactor(); |
| 540 | di << "2d3dFactor="<<the2d3dFactor<< "\n"; |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | //======================================================================= |
| 545 | //function : DT_PlaneGridShell |
| 546 | //purpose : Create a Plane Grid Shell from U and V knots |
| 547 | // |
| 548 | // |
| 549 | //======================================================================= |
| 550 | static Standard_Integer DT_PlaneGridShell (Draw_Interpretor& di, |
| 551 | Standard_Integer n, const char** a) |
| 552 | |
| 553 | { |
| 554 | |
| 555 | if (n < 4) return 1; |
| 556 | // a[1]= result |
| 557 | // a[2]= NbU >=2 |
| 558 | // a[3]= NbV >=2 |
| 559 | // a[4..]= {UKnots} |
| 560 | // a[4+NbU...] = {VKnots} |
| 561 | // a[4+NbU+NbV+1] = Tol |
| 562 | |
| 563 | // number of knots: |
| 564 | Standard_Integer NbU=Draw::Atoi(a[2]); |
| 565 | Standard_Integer NbV=Draw::Atoi(a[3]); |
| 566 | if (n != 4+NbU+NbV+1) { |
| 567 | di << "bad number of arguments" <<"\n"; |
| 568 | return 1; |
| 569 | } |
| 570 | |
| 571 | TColStd_Array1OfReal TheUKnots(1,NbU); |
| 572 | TColStd_Array1OfReal TheVKnots(1,NbV); |
| 573 | |
| 574 | for (Standard_Integer ii=1; ii<=NbU; ii++) { |
| 575 | TheUKnots(ii)=Draw::Atof(a[4+ii-1]); |
| 576 | } |
| 577 | for (ii=1; ii<=NbV; ii++) { |
| 578 | TheVKnots(ii)=Draw::Atof(a[4+NbU+ii-1]); |
| 579 | } |
| 580 | |
| 581 | Standard_Real Tol=Draw::Atof(a[4+NbU+NbV]); |
| 582 | |
| 583 | ShapeUpgrade_PlaneGridShell TheGrid(ThePlane,TheUKnots,TheVKnots,Tol); |
| 584 | |
| 585 | TopoDS_Shell res = TheGrid.Shell(); |
| 586 | DBRep::Set(a[1],res); |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | //======================================================================= |
| 592 | //function : DT_PlaneFaceCommon |
| 593 | //purpose : Common between a plane Face and a Shell whose all Faces are |
| 594 | // laying in the same plane |
| 595 | // |
| 596 | // |
| 597 | //======================================================================= |
| 598 | static Standard_Integer DT_PlaneFaceCommon (Draw_Interpretor& di, |
| 599 | Standard_Integer n, const char** a) |
| 600 | |
| 601 | { |
| 602 | // a[1]= result |
| 603 | // a[2]= input Face |
| 604 | // a[3]= input Shell |
| 605 | |
| 606 | if (n !=4) { |
| 607 | di << "bad number of arguments" <<"\n"; |
| 608 | return 1; |
| 609 | } |
| 610 | |
| 611 | TopoDS_Shape inputShape= DBRep::Get(a[2]); |
| 612 | TopoDS_Face inputFace = TopoDS::Face(inputShape); |
| 613 | if (inputFace.IsNull()) { |
| 614 | di << a[2] << " is not a face" << "\n"; |
| 615 | return 1; |
| 616 | } |
| 617 | |
| 618 | inputShape = DBRep::Get(a[3]); |
| 619 | TopoDS_Shell inputShell = TopoDS::Shell(inputShape); |
| 620 | if (inputShell.IsNull()) { |
| 621 | di << a[3] << " is not a shell" << "\n"; |
| 622 | return 1; |
| 623 | } |
| 624 | |
| 625 | ShapeUpgrade_PlaneFaceCommon theTool; |
| 626 | theTool.Init(inputFace,inputShell); |
| 627 | |
| 628 | TopoDS_Shell res = theTool.Shell(); |
| 629 | DBRep::Set(a[1],res); |
| 630 | |
| 631 | return 0; |
| 632 | }*/ |
| 633 | |
| 634 | //======================================================================= |
| 635 | //function : DT_SplitCurve |
| 636 | //purpose : Splits the curve with C1 criterion |
| 637 | // |
| 638 | // |
| 639 | //======================================================================= |
| 640 | static Standard_Integer DT_SplitCurve (Draw_Interpretor& di, |
| 641 | Standard_Integer n, const char** a) |
| 642 | |
| 643 | { |
| 644 | // a[1]= input curve. This name is used with a suffix to name the output curves |
| 645 | // a[2]= Tolerance |
| 646 | |
| 647 | if (n < 3) { |
| 648 | di << "bad number of arguments" <<"\n"; |
| 649 | return 1; |
| 650 | } |
| 651 | |
| 652 | Standard_Real Tol=Draw::Atof(a[2]); |
| 653 | Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]); |
| 654 | if ( GC.IsNull()) return 1; |
| 655 | Standard_Integer Split = Draw::Atoi(a[3]); |
| 656 | Handle(ShapeUpgrade_SplitCurve3dContinuity) theTool = new ShapeUpgrade_SplitCurve3dContinuity; |
| 657 | theTool->Init(GC); |
| 658 | theTool->SetTolerance (Tol); |
| 659 | theTool->SetCriterion (GeomAbs_C1); |
| 660 | if(Split == 1) { |
| 661 | Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal; |
| 662 | for(Standard_Integer i = 1; i<=5; i++) spval->Append(i); |
| 663 | theTool->SetSplitValues(spval); |
| 664 | } |
| 665 | theTool->Perform (Standard_True); |
| 666 | Handle(TColGeom_HArray1OfCurve) theCurves= theTool->GetCurves(); |
| 667 | Standard_Integer NbC=theCurves->Length(); |
| 668 | for (Standard_Integer icurv=1; icurv<=NbC; icurv++) { |
| 669 | char name[100]; |
| 670 | Sprintf(name,"%s%s%d",a[1],"_",icurv); |
| 671 | char* newname = name; |
| 672 | DrawTrSurf::Set(newname, theCurves->Value(icurv)); |
| 673 | di.AppendElement(newname); |
| 674 | } |
| 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | |
| 679 | //======================================================================= |
| 680 | //function : DT_SplitCurve2d |
| 681 | //purpose : Splits the curve with C1 criterion |
| 682 | // |
| 683 | // |
| 684 | //======================================================================= |
| 685 | static Standard_Integer DT_SplitCurve2d (Draw_Interpretor& di, |
| 686 | Standard_Integer n, const char** a) |
| 687 | |
| 688 | { |
| 689 | // a[1]= input 2d curve. This name is used with a suffix to name the output curves |
| 690 | // a[2]= Tolerance |
| 691 | |
| 692 | if (n < 3) { |
| 693 | di << "bad number of arguments" <<"\n"; |
| 694 | return 1; |
| 695 | } |
| 696 | |
| 697 | Standard_Real Tol=Draw::Atof(a[2]); |
| 698 | Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]); |
| 699 | if ( GC.IsNull()) return 1; |
| 700 | Standard_Integer Split = Draw::Atoi(a[3]); |
| 701 | Handle(ShapeUpgrade_SplitCurve2dContinuity) theTool = new ShapeUpgrade_SplitCurve2dContinuity; |
| 702 | theTool->Init(GC); |
| 703 | theTool->SetTolerance (Tol); |
| 704 | theTool->SetCriterion (GeomAbs_C1); |
| 705 | if(Split == 1) { |
| 706 | Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal; |
| 707 | for(Standard_Integer i = 1; i<=5; i++) spval->Append(i); |
| 708 | theTool->SetSplitValues(spval); |
| 709 | } |
| 710 | theTool->Perform (Standard_True); |
| 711 | Handle(TColGeom2d_HArray1OfCurve) theCurves= theTool->GetCurves(); |
| 712 | Standard_Integer NbC=theCurves->Length(); |
| 713 | for (Standard_Integer icurv=1; icurv<=NbC; icurv++) { |
| 714 | char name[100]; |
| 715 | Sprintf(name,"%s%s%d",a[1],"_",icurv); |
| 716 | char* newname = name; |
| 717 | DrawTrSurf::Set(newname, theCurves->Value(icurv)); |
| 718 | di.AppendElement(newname); |
| 719 | } |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | |
| 724 | //======================================================================= |
| 725 | //function : DT_SplitSurface |
| 726 | //purpose : Splits the surface with C1 criterion |
| 727 | // |
| 728 | // |
| 729 | //======================================================================= |
| 730 | /* |
| 731 | static Standard_Integer DT_SplitWire (Draw_Interpretor& di, |
| 732 | Standard_Integer n, const char** a) |
| 733 | { |
| 734 | |
| 735 | if (n <3) { |
| 736 | di << "bad number of arguments" <<"\n"; |
| 737 | return 1; |
| 738 | } |
| 739 | |
| 740 | TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2])); |
| 741 | if(source.IsNull()) { |
| 742 | di <<"Shape is not face"<<"\n"; |
| 743 | return 1; |
| 744 | } |
| 745 | TopoDS_Iterator wi(source); |
| 746 | if(!wi.More()) { |
| 747 | di <<"Shape is face without wire"<<"\n"; |
| 748 | return 1; |
| 749 | } |
| 750 | |
| 751 | TopoDS_Wire wire = TopoDS::Wire(wi.Value()); |
| 752 | Handle(ShapeUpgrade_WireDivideContinuity) tool = new ShapeUpgrade_WireDivideContinuity; |
| 753 | tool->Init(wire,source); |
| 754 | if(n >=4 ) { |
| 755 | Standard_Real Tol=Draw::Atof(a[3]); |
| 756 | } |
| 757 | Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape; |
| 758 | tool->Perform(context); |
| 759 | TopoDS_Wire result = tool->Wire(); |
| 760 | DBRep::Set(a[1],result); |
| 761 | return 0; |
| 762 | } |
| 763 | */ |
| 764 | /* |
| 765 | static Standard_Integer DT_SplitFace (Draw_Interpretor& di, |
| 766 | Standard_Integer n, const char** a) |
| 767 | { |
| 768 | |
| 769 | if (n <3) { |
| 770 | di << "bad number of arguments" <<"\n"; |
| 771 | return 1; |
| 772 | } |
| 773 | |
| 774 | TopoDS_Face source = TopoDS::Face(DBRep::Get(a[2])); |
| 775 | if(source.IsNull()) { |
| 776 | di <<"Shape is not face"<<"\n"; |
| 777 | return 1; |
| 778 | } |
| 779 | Handle(ShapeUpgrade_ShapeDivideContinuity) tool = new ShapeUpgrade_FaceDivideContinuity; |
| 780 | tool->Init(source); |
| 781 | if(n >=4 ) { |
| 782 | Standard_Real Tol=Draw::Atof(a[3]); |
| 783 | tool->SetPrecision(Tol); |
| 784 | } |
| 785 | |
| 786 | Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape; |
| 787 | tool->Perform(context); |
| 788 | TopoDS_Shape result = tool->Result(); |
| 789 | |
| 790 | |
| 791 | if ( tool->Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n"; |
| 792 | if ( tool->Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n"; |
| 793 | if ( tool->Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n"; |
| 794 | if ( tool->Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n"; |
| 795 | if ( tool->Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n"; |
| 796 | if ( tool->Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n"; |
| 797 | if ( tool->Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n"; |
| 798 | if ( tool->Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n"; |
| 799 | if ( tool->Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n"; |
| 800 | if ( tool->Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n"; |
| 801 | if ( tool->Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n"; |
| 802 | if ( tool->Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n"; |
| 803 | if ( tool->Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n"; |
| 804 | if ( tool->Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n"; |
| 805 | if ( tool->Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n"; |
| 806 | if ( tool->Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n"; |
| 807 | if ( tool->Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n"; |
| 808 | |
| 809 | // fixes |
| 810 | |
| 811 | ShapeFix::SameParameter ( result, Standard_False ); |
| 812 | |
| 813 | DBRep::Set(a[1],result); |
| 814 | return 0; |
| 815 | } |
| 816 | */ |
| 817 | |
| 818 | static Standard_Integer DT_SplitSurface (Draw_Interpretor& di, |
| 819 | Standard_Integer n, const char** a) |
| 820 | |
| 821 | { |
| 822 | // a[1]= result (used with a suffix to name the output surfaces) |
| 823 | // a[2]= input surface. |
| 824 | // a[3]= Tolerance |
| 825 | |
| 826 | // a[1]= result |
| 827 | // a[2]= nbU |
| 828 | // a[3]= nbV |
| 829 | // a[3+1]..a[3+nbU*nbV] = Input Surfaces |
| 830 | // a[4+nbU*nbV]= Tolerance |
| 831 | |
| 832 | if (n <4) { |
| 833 | di << "bad number of arguments" <<"\n"; |
| 834 | return 1; |
| 835 | } |
| 836 | |
| 837 | Handle(ShapeUpgrade_SplitSurfaceContinuity) theTool = new ShapeUpgrade_SplitSurfaceContinuity;//S4137 |
| 838 | |
| 839 | Standard_Real Tol=Draw::Atof(a[3]); |
| 840 | Standard_Integer Split = Draw::Atoi(a[4]); |
| 841 | theTool->SetTolerance(Tol); |
| 842 | theTool->SetCriterion(GeomAbs_C1); |
| 843 | Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]); |
| 844 | /* |
| 845 | if ( GS.IsNull()) { |
| 846 | // Case of composite grid surface |
| 847 | di << "composite surf" << "\n"; |
| 848 | Standard_Integer nbU=Draw::Atoi(a[2]); |
| 849 | Standard_Integer nbV=Draw::Atoi(a[3]); |
| 850 | if (nbU==0 || nbV==0) return 1; |
| 851 | Handle(TColGeom_HArray2OfSurface) |
| 852 | theGrid= new TColGeom_HArray2OfSurface(1,nbU,1,nbV); |
| 853 | for (Standard_Integer iu=1; iu<=nbU; iu++) { |
| 854 | for (Standard_Integer iv=1; iv<=nbV; iv++) { |
| 855 | Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3+(iu-1)*nbV+iv]); |
| 856 | theGrid->SetValue(iu,iv,GS); |
| 857 | } |
| 858 | } |
| 859 | di << "appel a SplitSurface::Init" << "\n"; |
| 860 | theTool->Init(theGrid); |
| 861 | } |
| 862 | else {*/ |
| 863 | // Case of single surface |
| 864 | di << "single surf" << "\n"; |
| 865 | |
| 866 | di << "appel a SplitSurface::Init" << "\n"; |
| 867 | theTool->Init(GS); |
| 868 | if(Split ==1) { |
| 869 | Handle(TColStd_HSequenceOfReal) spval = new TColStd_HSequenceOfReal; |
| 870 | for(Standard_Integer i = 1; i<=5; i++) spval->Append(i); |
| 871 | theTool->SetUSplitValues(spval); |
| 872 | theTool->SetVSplitValues(spval); |
| 873 | } |
| 874 | |
| 875 | di << "appel a SplitSurface::Build" << "\n"; |
| 876 | theTool->Build(Standard_True); |
| 877 | |
| 878 | di << "appel a SplitSurface::GlobalU/VKnots" << "\n"; |
| 879 | Handle(ShapeExtend_CompositeSurface) Grid = theTool->ResSurfaces(); |
| 880 | Handle(TColStd_HArray1OfReal) GlobalU=Grid->UJointValues(); |
| 881 | Handle(TColStd_HArray1OfReal) GlobalV=Grid->VJointValues(); |
| 882 | Standard_Integer nbGlU=GlobalU->Length(); |
| 883 | Standard_Integer nbGlV=GlobalV->Length(); |
| 884 | di << "nb GlobalU ; nb GlobalV="<<nbGlU<<" "<<nbGlV; |
| 885 | for (Standard_Integer iu=1; iu<=nbGlU; iu++) |
| 886 | di <<" "<< GlobalU->Value(iu); |
| 887 | // di <<"\n"; |
| 888 | // di << "nb GlobalV="<<nbGlV; |
| 889 | for (Standard_Integer iv=1; iv<=nbGlV; iv++) |
| 890 | di <<" "<< GlobalV->Value(iv); |
| 891 | di <<"\n"; |
| 892 | |
| 893 | di << "appel a Surfaces" << "\n"; |
| 894 | Handle(TColGeom_HArray2OfSurface) theSurfaces= Grid->Patches(); |
| 895 | |
| 896 | di << "transfert resultat" << "\n"; |
| 897 | Standard_Integer NbRow=theSurfaces->ColLength(); |
| 898 | Standard_Integer NbCol=theSurfaces->RowLength(); |
| 899 | for (Standard_Integer irow=1; irow<=NbRow; irow++) { |
| 900 | for (Standard_Integer icol=1; icol<=NbCol; icol++) { |
| 901 | char name[100]; |
| 902 | Sprintf(name,"%s%s%d%s%d",a[1],"_",irow,"_",icol); |
| 903 | char* newname = name; |
| 904 | DrawTrSurf::Set(newname, theSurfaces->Value(irow, icol)); |
| 905 | di.AppendElement(newname); |
| 906 | } |
| 907 | } |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | |
| 912 | |
| 913 | //======================================================================= |
| 914 | //function : DT_SupportModification |
| 915 | //purpose : Changes the supports of a Shell |
| 916 | // The given surface wil support all the faces of the new shell. |
| 917 | // with the PCurves of the old ones. |
| 918 | // |
| 919 | //======================================================================= |
| 920 | /*static Standard_Integer DT_SupportModification (Draw_Interpretor& di, |
| 921 | Standard_Integer n, const char** a) |
| 922 | |
| 923 | { |
| 924 | // a[1]= result |
| 925 | // a[2]= input Shell |
| 926 | // a[3]= new Surface |
| 927 | // a[4]= 2d3d Scale Factor |
| 928 | |
| 929 | if (n !=5) { |
| 930 | di << "bad number of arguments" <<"\n"; |
| 931 | return 1; |
| 932 | } |
| 933 | |
| 934 | TopoDS_Shape inputShape= DBRep::Get(a[2]); |
| 935 | TopoDS_Shell inputShell = TopoDS::Shell(inputShape); |
| 936 | if (inputShell.IsNull()) { |
| 937 | di << a[2] << " is not a shell" << "\n"; |
| 938 | return 1; |
| 939 | } |
| 940 | |
| 941 | Handle(Geom_Surface) theSurf = DrawTrSurf::GetSurface(a[3]); |
| 942 | if ( theSurf.IsNull()) { |
| 943 | di << a[3] << " is not a surface" << "\n"; |
| 944 | return 1; |
| 945 | } |
| 946 | |
| 947 | ShapeUpgrade_DataMapOfShapeSurface theMap; |
| 948 | // Associates thesurf to each face of inputShell. |
| 949 | TopExp_Explorer ExpSh; |
| 950 | for (ExpSh.Init(inputShell,TopAbs_FACE); ExpSh.More(); ExpSh.Next()){ |
| 951 | TopoDS_Face theFace= TopoDS::Face(ExpSh.Current()); |
| 952 | theMap.Bind(theFace,theSurf); |
| 953 | } |
| 954 | |
| 955 | Standard_Real the2d3dFactor=Draw::Atof(a[4]); |
| 956 | ShapeUpgrade_SupportModification theTool(inputShell,theMap,the2d3dFactor); |
| 957 | |
| 958 | TopoDS_Shell res = theTool.Shell(); |
| 959 | DBRep::Set(a[1],res); |
| 960 | |
| 961 | return 0; |
| 962 | }*/ |
| 963 | |
| 964 | //======================================================================= |
| 965 | //function : DT_Debug |
| 966 | //purpose : activation of the debug mode |
| 967 | // |
| 968 | //======================================================================= |
| 969 | /* |
| 970 | static Standard_Integer DT_Debug (Draw_Interpretor& di, |
| 971 | Standard_Integer n, const char** a) |
| 972 | |
| 973 | { |
| 974 | // a[1]= 0/1 |
| 975 | |
| 976 | if (n !=2) { |
| 977 | di << "bad number of arguments" <<"\n"; |
| 978 | return 1; |
| 979 | } |
| 980 | |
| 981 | if (Draw::Atoi(a[1])==1) { |
| 982 | di << "Activation of debug messages"<<"\n"; |
| 983 | ShapeUpgrade::SetDebug(Standard_True); |
| 984 | } |
| 985 | else { |
| 986 | di << "Desactivation of debug messages"<<"\n"; |
| 987 | ShapeUpgrade::SetDebug(Standard_False); |
| 988 | } |
| 989 | return 0; |
| 990 | } |
| 991 | */ |
| 992 | |
| 993 | /*static Standard_Integer shellsolid |
| 994 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 995 | { |
| 996 | if (argc < 4) { |
| 997 | di<<"Donner option + nom de SHAPE + nom de RESULTAT"<<"\n"; |
| 998 | di<<"Options : a all (sewing sur tous les shells\n" |
| 999 | << " c check (sewing sur shells avec bad edges\n" |
| 1000 | <<" b bad edges\n f free edges"<<"\n"; |
| 1001 | return 1 ; |
| 1002 | } |
| 1003 | Standard_CString arg1 = argv[1]; |
| 1004 | Standard_CString arg2 = argv[2]; |
| 1005 | Standard_CString arg3 = argv[3]; |
| 1006 | |
| 1007 | TopoDS_Shape Shape = DBRep::Get(arg2); |
| 1008 | if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1 ; } |
| 1009 | |
| 1010 | ShapeAnalysis_Shell STS; |
| 1011 | char opt = arg1[0]; |
| 1012 | if (opt == 'a') STS.LoadShells (Shape); |
| 1013 | else if (opt == 'f') STS.CheckOrientedShells (Shape,Standard_True); |
| 1014 | else if (opt == 'b' || opt == 'c') STS.CheckOrientedShells (Shape,Standard_False); |
| 1015 | |
| 1016 | else if (opt == 'o') { |
| 1017 | |
| 1018 | // Test WireOrder |
| 1019 | Handle(ShapeExtend_WireData) Frees = new ShapeExtend_WireData;//:sw Frees.SetPrecision (BRepBuilderAPI::Precision()); |
| 1020 | Standard_Integer nbe = 0; |
| 1021 | for (TopExp_Explorer edges(Shape,TopAbs_EDGE); edges.More(); edges.Next()) { |
| 1022 | Frees->Add (TopoDS::Edge(edges.Current())); nbe ++; |
| 1023 | } |
| 1024 | ShapeAnalysis_WireOrder WO (Standard_True,BRepBuilderAPI::Precision()); |
| 1025 | ShapeAnalysis_Wire saw; |
| 1026 | saw.Load ( Frees ); |
| 1027 | saw.SetPrecision ( BRepBuilderAPI::Precision() ); |
| 1028 | saw.CheckOrder ( WO ); |
| 1029 | |
| 1030 | Standard_Integer stat = WO.Status(); |
| 1031 | di<<"Wire Order Status = "<<stat<<" on "<<nbe<<" Edges"<<"\n"; |
| 1032 | nbe = WO.NbEdges(); |
| 1033 | for (Standard_Integer ie = 1; ie <= nbe; ie ++) { |
| 1034 | Standard_Integer io = WO.Ordered (ie); |
| 1035 | gp_XYZ st3d,en3d; |
| 1036 | WO.XYZ (io,st3d,en3d); |
| 1037 | di<<ie<<": Edge."<<io<<" Start:"<<st3d.X()<<" "<<st3d.Y()<<" "<<st3d.Z() |
| 1038 | <<" End:"<<en3d.X()<<" "<<en3d.Y()<<" "<<en3d.Z()<<"\n"; |
| 1039 | } |
| 1040 | // Chainage ? |
| 1041 | Standard_Real gap = BRepBuilderAPI::Precision(); |
| 1042 | WO.SetChains (gap); |
| 1043 | Standard_Integer n1,n2,ic, nc = WO.NbChains(); |
| 1044 | for (ic = 1; ic <= nc; ic ++) { |
| 1045 | WO.Chain(ic,n1,n2); |
| 1046 | di<<"Chain."<<ic<<" From "<<n1<<" To "<<n2<<"\n"; |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | else { di<<"Option non reconnue : "<<arg1<<"\n"; return 1; } |
| 1051 | |
| 1052 | TopoDS_Shape res; |
| 1053 | if (opt == 'a' || opt == 'c') { |
| 1054 | ShapeUpgrade_ShellSewing sew; |
| 1055 | res = sew.ApplySewing (Shape); |
| 1056 | if (res.IsEqual(Shape)) { |
| 1057 | res.Nullify(); |
| 1058 | di<<"ShellSolid : no sewing done"<<"\n"; |
| 1059 | } |
| 1060 | } else if (opt == 'b') { |
| 1061 | if (STS.HasBadEdges()) res = STS.BadEdges(); |
| 1062 | else di<<"ShellSolid : no bad edge"<<"\n"; |
| 1063 | } else if (opt == 'f') { |
| 1064 | if (STS.HasFreeEdges()) res = STS.FreeEdges(); |
| 1065 | else di<<"ShellSolid : no free edge"<<"\n"; |
| 1066 | if (STS.HasConnectedEdges()) di<<"ShellSolid : connected edges"<<"\n"; |
| 1067 | else di<<"ShellSolid : NO connected edges"<<"\n"; |
| 1068 | } |
| 1069 | |
| 1070 | if (!res.IsNull()) DBRep::Set (arg3,res); |
| 1071 | |
| 1072 | return 0; // Done |
| 1073 | }*/ |
| 1074 | //---------------gka |
| 1075 | //======================================================================= |
| 1076 | //function : offset2dcurve |
| 1077 | //purpose : |
| 1078 | // |
| 1079 | //======================================================================= |
| 1080 | static Standard_Integer offset2dcurve |
| 1081 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 1082 | { |
| 1083 | if (argc < 4) { |
| 1084 | di<<"result + curve + offset"<<"\n"; |
| 1085 | |
| 1086 | return 1 /* Error */; |
| 1087 | } |
| 1088 | // Standard_CString arg1 = argv[1]; |
| 1089 | // Standard_CString arg2 = argv[2]; |
| 1090 | Standard_Real Offset = Draw::Atof(argv[3]); |
| 1091 | Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(argv[2]); |
| 1092 | if ( GC.IsNull()) return 1; |
| 1093 | Handle(Geom2d_OffsetCurve) offcrv = new Geom2d_OffsetCurve(GC,Offset); |
| 1094 | DrawTrSurf::Set(argv[1], offcrv); |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
| 1098 | //======================================================================= |
| 1099 | //function : offsetcurve |
| 1100 | //purpose : |
| 1101 | // |
| 1102 | //======================================================================= |
| 1103 | static Standard_Integer offsetcurve |
| 1104 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 1105 | { |
| 1106 | if (argc < 5) { |
| 1107 | di<<"result + curve + offset + Dir"<<"\n"; |
| 1108 | |
| 1109 | return 1 /* Error */; |
| 1110 | } |
| 1111 | // Standard_CString arg1 = argv[1]; |
| 1112 | // Standard_CString arg2 = argv[2]; |
| 1113 | Standard_Real Offset = Draw::Atof(argv[3]); |
| 1114 | Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(argv[2]); |
| 1115 | if ( GC.IsNull()) return 1; |
| 1116 | gp_Pnt point; |
| 1117 | DrawTrSurf::GetPoint(argv[4],point); |
| 1118 | gp_Dir dir(point.XYZ()); |
| 1119 | Handle(Geom_OffsetCurve) offcrv = new Geom_OffsetCurve(GC,Offset,dir); |
| 1120 | DrawTrSurf::Set(argv[1], offcrv); |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | //======================================================================= |
| 1125 | //function : compose shell |
| 1126 | //purpose : |
| 1127 | //======================================================================= |
| 1128 | static Standard_Integer splitface |
| 1129 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 1130 | { |
| 1131 | if (argc < 5) { |
| 1132 | di << "Split face: splitface result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]" << "\n"; |
| 1133 | return 1; |
| 1134 | } |
| 1135 | |
| 1136 | TopoDS_Shape aLocalShape = DBRep::Get(argv[2]) ; |
| 1137 | TopoDS_Face face = TopoDS::Face ( aLocalShape ); |
| 1138 | if ( face.IsNull() ) { |
| 1139 | di << argv[2] << " is not Face" << "\n"; |
| 1140 | return 1; |
| 1141 | } |
| 1142 | |
| 1143 | Handle(Geom_Surface) S = BRep_Tool::Surface ( face ); |
| 1144 | Standard_Real Uf, Ul, Vf, Vl; |
| 1145 | BRepTools::UVBounds ( face, Uf, Ul, Vf, Vl ); |
| 1146 | Standard_Real Umin, Umax, Vmin, Vmax; |
| 1147 | S->Bounds ( Umin, Umax, Vmin, Vmax ); |
| 1148 | if ( Uf < Umin && ! S->IsUPeriodic() ) Uf = Umin; |
| 1149 | else if ( Uf > Umin ) { |
| 1150 | if ( Precision::IsInfinite(Umin) ) Uf -= 100; |
| 1151 | else Uf = Umin; |
| 1152 | } |
| 1153 | if ( Vf < Vmin && ! S->IsVPeriodic() ) Vf = Vmin; |
| 1154 | else if ( Vf > Vmin ) { |
| 1155 | if ( Precision::IsInfinite(Vmin) ) Vf -= 100; |
| 1156 | else Vf = Vmin; |
| 1157 | } |
| 1158 | if ( Ul > Umax && ! S->IsUPeriodic() ) Ul = Umax; |
| 1159 | else if ( Ul < Umax ) { |
| 1160 | if ( Precision::IsInfinite(Umax) ) Ul += 100; |
| 1161 | else Ul = Umax; |
| 1162 | } |
| 1163 | if ( Vl > Vmax && ! S->IsVPeriodic() ) Vl = Vmax; |
| 1164 | else if ( Vl < Vmax ) { |
| 1165 | if ( Precision::IsInfinite(Vmax) ) Vl += 100; |
| 1166 | else Vl = Vmax; |
| 1167 | } |
| 1168 | |
| 1169 | TColStd_SequenceOfReal uval; |
| 1170 | TColStd_SequenceOfReal vval; |
| 1171 | |
| 1172 | Standard_Boolean byV = Standard_False; |
| 1173 | Standard_Integer i; // svv Jan11 2000 : porting on DEC |
| 1174 | for ( i=3; i < argc; i++ ) { |
| 1175 | if ( argv[i][0] == 'u' ) byV = Standard_False; |
| 1176 | else if ( argv[i][0] == 'v' ) byV = Standard_True; |
| 1177 | else { |
| 1178 | Standard_Real val = Draw::Atof ( argv[i] ); |
| 1179 | TColStd_SequenceOfReal &vals = ( byV ? vval : uval ); |
| 1180 | if ( vals.Length() >0 && val - vals.Last() < Precision::PConfusion() ) { |
| 1181 | di << "Values should be sorted in increasing order; skipped" << "\n"; |
| 1182 | continue; |
| 1183 | } |
| 1184 | if ( ( byV && ( val < Vf+Precision::PConfusion() || |
| 1185 | val > Vl-Precision::PConfusion() ) ) || |
| 1186 | (!byV && ( val < Uf+Precision::PConfusion() || |
| 1187 | val > Ul-Precision::PConfusion() ) ) ) { |
| 1188 | di << "Values should be inside range of surface; skipped" << "\n"; |
| 1189 | continue; |
| 1190 | } |
| 1191 | vals.Append ( val ); |
| 1192 | } |
| 1193 | } |
| 1194 | if ( uval.Length() <1 && vval.Length() <1 ) { |
| 1195 | di << "No splitting defined" << "\n"; |
| 1196 | return 1; |
| 1197 | } |
| 1198 | if ( uval.Length() >0 ) { |
| 1199 | di << "Splitting by U: "; |
| 1200 | for ( Standard_Integer j=1; j <= uval.Length(); j++ ) { |
| 1201 | //cout << ( i >j ? ", " : "" ) << uval(j); |
| 1202 | if (i >j) { |
| 1203 | di << ", "; |
| 1204 | } else { |
| 1205 | di << ""; |
| 1206 | } |
| 1207 | di << uval(j); |
| 1208 | } |
| 1209 | di << "\n"; |
| 1210 | } |
| 1211 | if ( vval.Length() >0 ) { |
| 1212 | di << "Splitting by V: "; |
| 1213 | for ( Standard_Integer j=1; j <= vval.Length(); j++ ) { |
| 1214 | //cout << ( j >1 ? ", " : "" ) << vval(j); |
| 1215 | if (j >1) { |
| 1216 | di << ", "; |
| 1217 | } else { |
| 1218 | di << ""; |
| 1219 | } |
| 1220 | di << vval(j); |
| 1221 | } |
| 1222 | di << "\n"; |
| 1223 | } |
| 1224 | |
| 1225 | Handle(TColGeom_HArray2OfSurface) AS = new TColGeom_HArray2OfSurface ( 1, uval.Length()+1, |
| 1226 | 1, vval.Length()+1 ); |
| 1227 | for ( i=0; i <= uval.Length(); i++ ) { |
| 1228 | Standard_Real umin = ( i ? uval(i) : Uf ); |
| 1229 | Standard_Real umax = ( i < uval.Length() ? uval(i+1) : Ul ); |
| 1230 | for ( Standard_Integer j=0; j <= vval.Length(); j++ ) { |
| 1231 | Standard_Real vmin = ( j ? vval(j) : Vf ); |
| 1232 | Standard_Real vmax = ( j < vval.Length() ? vval(j+1) : Vl ); |
| 1233 | Handle(Geom_RectangularTrimmedSurface) rect = |
| 1234 | new Geom_RectangularTrimmedSurface ( S, umin, umax, vmin, vmax ); |
| 1235 | AS->SetValue ( i+1, j+1, rect ); |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | Handle(ShapeExtend_CompositeSurface) Grid = new ShapeExtend_CompositeSurface; |
| 1240 | if ( ! Grid->Init ( AS ) ) di << "Grid badly connected!" << "\n"; |
| 1241 | |
| 1242 | ShapeFix_ComposeShell SUCS; |
| 1243 | TopLoc_Location l; |
| 1244 | SUCS.Init ( Grid, l, face, Precision::Confusion() ); |
| 1245 | Handle(ShapeBuild_ReShape) RS = new ShapeBuild_ReShape; |
| 1246 | SUCS.SetContext( RS ); |
| 1247 | SUCS.Perform (); |
| 1248 | |
| 1249 | if ( SUCS.Status ( ShapeExtend_OK ) ) di << "Status: OK" << "\n"; |
| 1250 | if ( SUCS.Status ( ShapeExtend_DONE1 ) ) di << "Status: DONE1" << "\n"; |
| 1251 | if ( SUCS.Status ( ShapeExtend_DONE2 ) ) di << "Status: DONE2" << "\n"; |
| 1252 | if ( SUCS.Status ( ShapeExtend_DONE3 ) ) di << "Status: DONE3" << "\n"; |
| 1253 | if ( SUCS.Status ( ShapeExtend_DONE4 ) ) di << "Status: DONE4" << "\n"; |
| 1254 | if ( SUCS.Status ( ShapeExtend_DONE5 ) ) di << "Status: DONE5" << "\n"; |
| 1255 | if ( SUCS.Status ( ShapeExtend_DONE6 ) ) di << "Status: DONE6" << "\n"; |
| 1256 | if ( SUCS.Status ( ShapeExtend_DONE7 ) ) di << "Status: DONE7" << "\n"; |
| 1257 | if ( SUCS.Status ( ShapeExtend_DONE8 ) ) di << "Status: DONE8" << "\n"; |
| 1258 | if ( SUCS.Status ( ShapeExtend_FAIL1 ) ) di << "Status: FAIL1" << "\n"; |
| 1259 | if ( SUCS.Status ( ShapeExtend_FAIL2 ) ) di << "Status: FAIL2" << "\n"; |
| 1260 | if ( SUCS.Status ( ShapeExtend_FAIL3 ) ) di << "Status: FAIL3" << "\n"; |
| 1261 | if ( SUCS.Status ( ShapeExtend_FAIL4 ) ) di << "Status: FAIL4" << "\n"; |
| 1262 | if ( SUCS.Status ( ShapeExtend_FAIL5 ) ) di << "Status: FAIL5" << "\n"; |
| 1263 | if ( SUCS.Status ( ShapeExtend_FAIL6 ) ) di << "Status: FAIL6" << "\n"; |
| 1264 | if ( SUCS.Status ( ShapeExtend_FAIL7 ) ) di << "Status: FAIL7" << "\n"; |
| 1265 | if ( SUCS.Status ( ShapeExtend_FAIL8 ) ) di << "Status: FAIL8" << "\n"; |
| 1266 | |
| 1267 | TopoDS_Shape sh = SUCS.Result(); |
| 1268 | ShapeFix::SameParameter ( sh, Standard_False ); |
| 1269 | DBRep::Set ( argv[1], sh ); |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | static Standard_Integer converttobspline |
| 1274 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 1275 | { |
| 1276 | if (argc<3) { |
| 1277 | di << "Use: " << argv[0] << " result shape [options=ero]\n"; |
| 1278 | di << "where options is combination of letters indicating kinds of\n"; |
| 1279 | di << "surfaces to be converted:\n"; |
| 1280 | di << "e - extrusion\n"; |
| 1281 | di << "r - revolution\n"; |
| 1282 | di << "o - offset\n"; |
| 1283 | di << "p - plane"; |
| 1284 | return 1; |
| 1285 | } |
| 1286 | const char *options = ( argc > 3 ? argv[3] : "ero" ); |
| 1287 | |
| 1288 | TopoDS_Shape inputShape=DBRep::Get(argv[2]); |
| 1289 | if (inputShape.IsNull()) { |
| 1290 | di << "Unknown shape"<< "\n"; |
| 1291 | return 1; |
| 1292 | } |
| 1293 | TopoDS_Shape revsh = ShapeCustom::ConvertToRevolution (inputShape); |
| 1294 | TopoDS_Shape res = |
| 1295 | ShapeCustom::ConvertToBSpline (revsh, strchr (options, 'e') != 0, |
| 1296 | strchr (options, 'r') != 0, |
| 1297 | strchr (options, 'o') != 0, |
| 1298 | strchr (options, 'p') != 0); |
| 1299 | ShapeFix::SameParameter ( res, Standard_False ); |
| 1300 | DBRep::Set ( argv[1], res ); |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
| 1304 | |
| 1305 | static Standard_Integer splitclosed (Draw_Interpretor& di, |
| 1306 | Standard_Integer argc, |
| 1307 | const char** argv) |
| 1308 | { |
| 1309 | if (argc<3) { |
| 1310 | di << "bad number of arguments" <<"\n"; |
| 1311 | return 1; |
| 1312 | } |
| 1313 | |
| 1314 | TopoDS_Shape inputShape=DBRep::Get(argv[2]); |
| 1315 | if (inputShape.IsNull()) { |
| 1316 | di << "Unknown shape"<< "\n"; |
| 1317 | return 1; |
| 1318 | } |
| 1319 | |
| 1320 | ShapeUpgrade_ShapeDivideClosed tool (inputShape); |
| 1321 | tool.Perform(); |
| 1322 | TopoDS_Shape res = tool.Result(); |
| 1323 | |
| 1324 | ShapeFix::SameParameter ( res, Standard_False ); |
| 1325 | DBRep::Set ( argv[1], res ); |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
| 1329 | static Standard_Integer splitarea (Draw_Interpretor& di, |
| 1330 | Standard_Integer argc, |
| 1331 | const char** argv) |
| 1332 | { |
| 1333 | if (argc<4) { |
| 1334 | di << "bad number of arguments" <<"\n"; |
| 1335 | return 1; |
| 1336 | } |
| 1337 | |
| 1338 | TopoDS_Shape inputShape=DBRep::Get(argv[2]); |
| 1339 | if (inputShape.IsNull()) { |
| 1340 | di << "Unknown shape"<< "\n"; |
| 1341 | return 1; |
| 1342 | } |
| 1343 | Standard_Real aMaxArea = Draw::Atof(argv[3]); |
| 1344 | |
| 1345 | |
| 1346 | ShapeUpgrade_ShapeDivideArea tool (inputShape); |
| 1347 | if(argc >4) { |
| 1348 | Standard_Real prec = Draw::Atof(argv[4]); |
| 1349 | tool.SetPrecision(prec); |
| 1350 | } |
| 1351 | tool.MaxArea() = aMaxArea; |
| 1352 | tool.Perform(); |
| 1353 | TopoDS_Shape res = tool.Result(); |
| 1354 | |
| 1355 | ShapeFix::SameParameter ( res, Standard_False ); |
| 1356 | DBRep::Set ( argv[1], res ); |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
| 1360 | static Standard_Integer removeinternalwires (Draw_Interpretor& di, |
| 1361 | Standard_Integer argc, |
| 1362 | const char** argv) |
| 1363 | { |
| 1364 | if (argc<4) { |
| 1365 | di << "bad number of arguments" <<"\n"; |
| 1366 | return 1; |
| 1367 | } |
| 1368 | Standard_Real aMinArea = Draw::Atof(argv[2]); |
| 1369 | TopoDS_Shape inputShape=DBRep::Get(argv[3]); |
| 1370 | if (inputShape.IsNull()) { |
| 1371 | di << "Unknown shape"<< "\n"; |
| 1372 | return 1; |
| 1373 | } |
| 1374 | Handle(ShapeUpgrade_RemoveInternalWires) aTool; |
| 1375 | TopTools_SequenceOfShape aSeqShapes; |
| 1376 | if(inputShape.ShapeType() < TopAbs_WIRE) |
| 1377 | aTool = new ShapeUpgrade_RemoveInternalWires(inputShape); |
| 1378 | else { |
| 1379 | di<<"Invalid type of first shape: should be FACE,SHELL,SOLID or COMPOUND"<<"\n"; |
| 1380 | return 1; |
| 1381 | } |
| 1382 | |
| 1383 | Standard_Integer k = 4; |
| 1384 | Standard_Boolean isShape = Standard_True; |
| 1385 | Standard_Boolean aModeRemoveFaces =Standard_True; |
| 1386 | |
| 1387 | |
| 1388 | for( ; k < argc; k++) { |
| 1389 | if(isShape) { |
| 1390 | TopoDS_Shape aShape=DBRep::Get(argv[k]); |
| 1391 | isShape = !aShape.IsNull(); |
| 1392 | if(isShape) { |
| 1393 | if(aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_WIRE) |
| 1394 | aSeqShapes.Append(aShape); |
| 1395 | } |
| 1396 | } |
| 1397 | if(!isShape) |
| 1398 | aModeRemoveFaces = (Draw::Atoi(argv[k]) == 1); |
| 1399 | } |
| 1400 | |
| 1401 | aTool->MinArea() = aMinArea; |
| 1402 | aTool->RemoveFaceMode() = aModeRemoveFaces; |
| 1403 | if(aSeqShapes.Length()) |
| 1404 | aTool->Perform(aSeqShapes); |
| 1405 | else |
| 1406 | aTool->Perform(); |
| 1407 | if(aTool->Status(ShapeExtend_FAIL1)) |
| 1408 | di<<"Initial shape has invalid type"<<"\n"; |
| 1409 | else if(aTool->Status(ShapeExtend_FAIL2)) |
| 1410 | di<<"Specified sub-shape is not belonged to whole shape"<<"\n"; |
| 1411 | if(aTool->Status(ShapeExtend_DONE1)) { |
| 1412 | const TopTools_SequenceOfShape& aRemovedWires =aTool->RemovedWires(); |
| 1413 | di<<aRemovedWires.Length()<<" internal wires were removed"<<"\n"; |
| 1414 | |
| 1415 | } |
| 1416 | if(aTool->Status(ShapeExtend_DONE2)) { |
| 1417 | const TopTools_SequenceOfShape& aRemovedFaces =aTool->RemovedFaces(); |
| 1418 | di<<aRemovedFaces.Length()<<" small faces were removed"<<"\n"; |
| 1419 | |
| 1420 | } |
| 1421 | TopoDS_Shape res = aTool->GetResult(); |
| 1422 | |
| 1423 | |
| 1424 | DBRep::Set ( argv[1], res ); |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
| 1428 | static Standard_Integer removeloc (Draw_Interpretor& di, |
| 1429 | Standard_Integer argc, |
| 1430 | const char** argv) |
| 1431 | { |
| 1432 | if (argc<3) { |
| 1433 | di << "bad number of arguments. Should be: removeloc res shape" <<"\n"; |
| 1434 | return 1; |
| 1435 | } |
| 1436 | |
| 1437 | TopoDS_Shape aShape = DBRep::Get(argv[2]); |
| 1438 | if(aShape.IsNull()) |
| 1439 | return 1; |
| 1440 | ShapeUpgrade_RemoveLocations aRemLoc; |
| 1441 | aRemLoc.Remove(aShape); |
| 1442 | TopoDS_Shape aNewShape = aRemLoc.GetResult(); |
| 1443 | |
| 1444 | DBRep::Set(argv[1],aNewShape); |
| 1445 | return 0; |
| 1446 | } |
| 1447 | |
| 1448 | //======================================================================= |
| 1449 | // unifysamedom |
| 1450 | //======================================================================= |
| 1451 | static Standard_Integer unifysamedom(Draw_Interpretor& , Standard_Integer n, const char** a) |
| 1452 | { |
| 1453 | if (n < 3) |
| 1454 | return 1; |
| 1455 | |
| 1456 | TopoDS_Shape aShape = DBRep::Get(a[2]); |
| 1457 | if (aShape.IsNull()) |
| 1458 | return 1; |
| 1459 | |
| 1460 | ShapeUpgrade_UnifySameDomain Unifier(aShape); |
| 1461 | Unifier.Build(); |
| 1462 | TopoDS_Shape Result = Unifier.Shape(); |
| 1463 | |
| 1464 | DBRep::Set(a[1], Result); |
| 1465 | return 0; |
| 1466 | } |
| 1467 | |
| 1468 | static Standard_Integer copytranslate(Draw_Interpretor& di, |
| 1469 | Standard_Integer argc, |
| 1470 | const char** argv) |
| 1471 | { |
| 1472 | if (argc<6) { |
| 1473 | di << "bad number of arguments. Should be: removeloc res shape dx dyy dz" <<"\n"; |
| 1474 | return 1; |
| 1475 | } |
| 1476 | TopoDS_Shape aShape = DBRep::Get(argv[2]); |
| 1477 | if(aShape.IsNull()) |
| 1478 | return 1; |
| 1479 | Standard_Real aDx = Draw::Atof(argv[3]); |
| 1480 | Standard_Real aDy = Draw::Atof(argv[4]); |
| 1481 | Standard_Real aDz = Draw::Atof(argv[5]); |
| 1482 | gp_Trsf aTrsf; |
| 1483 | aTrsf.SetTranslation(gp_Vec(aDx, aDy, aDz)); |
| 1484 | BRepBuilderAPI_Transform builderTransform(aTrsf); |
| 1485 | builderTransform.Perform (aShape, true); |
| 1486 | TopoDS_Shape aNewShape = builderTransform.Shape(); |
| 1487 | DBRep::Set(argv[1],aNewShape); |
| 1488 | return 0; |
| 1489 | |
| 1490 | } |
| 1491 | |
| 1492 | //======================================================================= |
| 1493 | //function : InitCommands |
| 1494 | //purpose : |
| 1495 | //======================================================================= |
| 1496 | |
| 1497 | void SWDRAW_ShapeUpgrade::InitCommands(Draw_Interpretor& theCommands) |
| 1498 | { |
| 1499 | static Standard_Integer initactor = 0; |
| 1500 | if (initactor) return; initactor = 1; |
| 1501 | |
| 1502 | Standard_CString g = SWDRAW::GroupName(); // "Tests of DivideTool"; |
| 1503 | |
| 1504 | theCommands.Add("DT_ShapeDivide", |
| 1505 | "DT_ShapeDivide Result Shape Tol: Divides shape with C1 Criterion", |
| 1506 | __FILE__, |
| 1507 | DT_ShapeDivide,g); |
| 1508 | |
| 1509 | theCommands.Add("DT_SplitAngle", |
| 1510 | "DT_SplitAngle Result Shape [MaxAngle=95]: Divides revolved surfaces on segments less MaxAngle deg", |
| 1511 | __FILE__, |
| 1512 | DT_SplitAngle,g); |
| 1513 | |
| 1514 | theCommands.Add("DT_ShapeConvert", |
| 1515 | "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers", |
| 1516 | __FILE__, |
| 1517 | DT_ShapeConvert,g); |
| 1518 | |
| 1519 | theCommands.Add("DT_ShapeConvertRev", |
| 1520 | "DT_ShapeConvert Result Shape convert2d convert3d: Converts curves to beziers", |
| 1521 | __FILE__, |
| 1522 | DT_ShapeConvertRev,g); |
| 1523 | /* theCommands.Add("DT_PlaneDividedFace", |
| 1524 | "DT_PlaneDividedFace Result Face Tol: Transfer into a plane with boundary divided", |
| 1525 | __FILE__, |
| 1526 | DT_PlaneDividedFace,g); |
| 1527 | |
| 1528 | theCommands.Add("DT_PlaneGridShell", |
| 1529 | "DT_PlaneGridShell Result NbU NbV {UKnots} {VKnots} Tol : Create a plane grid Shell", |
| 1530 | __FILE__, |
| 1531 | DT_PlaneGridShell,g); |
| 1532 | |
| 1533 | theCommands.Add("DT_PlaneFaceCommon", |
| 1534 | "DT_PlaneFaceCommon Result Face Shell: Common between a plane Face and a Shell", |
| 1535 | __FILE__, |
| 1536 | DT_PlaneFaceCommon,g);*/ |
| 1537 | |
| 1538 | theCommands.Add("DT_SplitCurve2d", |
| 1539 | "DT_SplitCurve2d Curve Tol: Splits the curve with C1 criterion", |
| 1540 | __FILE__, |
| 1541 | DT_SplitCurve2d,g); |
| 1542 | |
| 1543 | theCommands.Add("DT_SplitCurve", |
| 1544 | "DT_SplitCurve Curve Tol: Splits the curve with C1 criterion", |
| 1545 | __FILE__, |
| 1546 | DT_SplitCurve,g); |
| 1547 | |
| 1548 | theCommands.Add("DT_SplitSurface", |
| 1549 | "DT_SplitSurface Result Surface/GridSurf Tol: Splits the surface with C1 criterion", |
| 1550 | __FILE__, |
| 1551 | DT_SplitSurface,g); |
| 1552 | |
| 1553 | /*theCommands.Add("DT_SupportModification", |
| 1554 | "DT_SupportModification Result Shell Surface 2d3dFactor: Surface will support all the faces", |
| 1555 | __FILE__, |
| 1556 | DT_SupportModification,g);*/ |
| 1557 | |
| 1558 | // theCommands.Add("DT_SpltWire","DT_SpltWire Result Wire Tol", |
| 1559 | // __FILE__,DT_SplitWire,g); |
| 1560 | |
| 1561 | // theCommands.Add("DT_SplitFace", "DT_SplitFace Result Face Tol", |
| 1562 | // __FILE__, DT_SplitFace,g); |
| 1563 | |
| 1564 | // theCommands.Add("DT_Debug", "DT_Debug 0/1 : activation/desactivation of the debug messages", |
| 1565 | // __FILE__, DT_Debug,g); |
| 1566 | // theCommands.Add ("shellsolid","option[a-b-c-f] shape result", |
| 1567 | // __FILE__,shellsolid,g); |
| 1568 | theCommands.Add ("offset2dcurve","result curve offset", |
| 1569 | __FILE__,offset2dcurve,g); |
| 1570 | |
| 1571 | theCommands.Add ("offsetcurve","result curve offset dir", |
| 1572 | __FILE__,offsetcurve,g); |
| 1573 | |
| 1574 | theCommands.Add ("splitface","result face [u usplit1 usplit2...] [v vsplit1 vsplit2 ...]", |
| 1575 | __FILE__,splitface,g); |
| 1576 | |
| 1577 | theCommands.Add ("DT_ToBspl","result shape [options=erop]", |
| 1578 | __FILE__,converttobspline,g); |
| 1579 | theCommands.Add ("DT_ClosedSplit","result shape", |
| 1580 | __FILE__,splitclosed,g); |
| 1581 | theCommands.Add ("DT_SplitByArea","result shape maxarea [preci]", |
| 1582 | __FILE__,splitarea,g); |
| 1583 | |
| 1584 | theCommands.Add ("RemoveIntWires","result minarea wholeshape [faces or wires] [moderemoveface ]", |
| 1585 | __FILE__,removeinternalwires,g); |
| 1586 | |
| 1587 | theCommands.Add ("removeloc","result shape",__FILE__,removeloc,g); |
| 1588 | |
| 1589 | theCommands.Add ("unifysamedom", |
| 1590 | "unifysamedom result shape",__FILE__,unifysamedom,g); |
| 1591 | |
| 1592 | theCommands.Add ("copytranslate","result shape dx dy dz",__FILE__,copytranslate,g); |
| 1593 | } |