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