Changes between Version 53 and Version 54 of PythonOcc
- Timestamp:
- Nov 3, 2015, 11:35:48 AM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PythonOcc
v53 v54 310 310 {{{ 311 311 #!python 312 ##Copyright 2011 Simon Kulovec (simon.kulovec@lecad.si) 312 ##Copyright 2011 Simon Kulovec (simon.kulovec@lecad.si) 313 ##Uredil in posodobil 2015 Dejan Penko (dejan.penko@lecad.fs.uni-lj.si) 313 314 ##Example: MakeCADBottle 314 315 ##This file is part of pythonOCC. … … 327 328 from OCC.BRepFilletAPI import * 328 329 from OCC.BRepAlgoAPI import * 329 from OCC.Utils.Topology import *330 330 from OCC.Geom import * 331 331 from OCC.Geom2d import * … … 340 340 import math 341 341 342 #Naslednja podprograma "face_is_plane" in "geom_plane_from_face" sta napisana za pomoč v nadaljevanju programa 343 def face_is_plane(face): 344 """ 345 Vrne True če je TopoDS_Shape ravnina, False v nasprotnem primeru 346 """ 347 hs = BRep_Tool_Surface(face) 348 downcast_result = Handle_Geom_Plane.DownCast(hs) 349 # Vrednost je "null", če se izvedba tega podprograma ne izvede pravilo ali je ni mogoče izvesti. Iz tega sledi, da profil ni ravnina 350 if downcast_result.IsNull(): 351 return False 352 else: 353 return True 354 355 def geom_plane_from_face(aFace): 356 """ 357 Vrne subjekt geometrične ravnine iz ravninske površine 358 """ 359 return Handle_Geom_Plane.DownCast(BRep_Tool_Surface(aFace)).GetObject() 360 342 361 def show_bottle(aRes): 343 362 display.EraseAll() 344 print dir(display)363 #print (dir(display)) 345 364 display.DisplayShape(aRes) 346 365 347 def define_ points(myWidth, myThickness, myHeight):348 # Definiranje začetnih točk366 def define_body(myWidth, myThickness, myHeight): 367 ## Definiranje začetnih točk 349 368 aPnt1 = gp_Pnt(-myWidth / 2. , 0 , 0) 350 369 aPnt2 = gp_Pnt(-myWidth / 2. , -myThickness / 4. , 0) … … 353 372 aPnt5 = gp_Pnt(myWidth / 2. , 0 , 0) 354 373 355 # Definiranje geometrije374 ## Definiranje geometrije 356 375 aArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3 ,aPnt4) 357 376 aSegment1 = GC_MakeSegment(aPnt1 , aPnt2) 358 377 aSegment2 = GC_MakeSegment(aPnt4 , aPnt5) 359 378 360 #Definiranje topologije 379 ## Definiranje topologije 380 #Definiranje robov 361 381 aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value()) 362 382 aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value()) 363 383 aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value()) 384 #Definiranje robov iz mreže 364 385 aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge() , aEdge2.Edge() ,aEdge3.Edge()) 365 386 366 #Izdelava celotnega profila - mirror 387 ## Izdelava celotnega profila - mirror 388 #Definiramo os zrcaljenja (os X) 367 389 xAxis = gp_OX() 390 #Nastavimo "zrcalo" 368 391 aTrsf = gp_Trsf() 369 392 aTrsf.SetMirror(xAxis) 393 #Uporabimo zrcalno transformacijo 370 394 aBRepTrsf = BRepBuilderAPI_Transform(aWire.Shape() , aTrsf) 395 #Zrcalno obliko dobimo nazaj iz transformacije in pretvorimo v mrežo 371 396 aMirroredShape = aBRepTrsf.Shape() 372 aMirroredWire = TopoDS_wire(aMirroredShape) 397 aMirroredWire = topods_Wire(aMirroredShape) 398 #Kombiniramo dve konsistentni mreži 373 399 mkWire = BRepBuilderAPI_MakeWire() 374 400 mkWire.Add(aWire.Wire()) … … 376 402 myWireProfile = mkWire.Wire() 377 403 378 # Telo: Iz profila se izdela telo 404 ## Telo: 405 #Iz profila se izdela telo 379 406 myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile) 380 407 aPrismVec = gp_Vec(0 , 0 , myHeight) 381 408 myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face() , aPrismVec) 382 409 383 # Telo: Dodamo zaokrožitve (fillet)410 #Dodamo zaokrožitve (fillet) s pomočjo t. i. Explorerja 384 411 mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape()) 385 topology_traverser = Topo(myBody.Shape()) 386 for aEdge in topology_traverser.edges(): 387 mkFillet.Add(myThickness / 12. , aEdge) 388 myBody = mkFillet.Shape() 389 390 #Dodajanje grla na steklenico 412 413 anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE) 414 415 while anEdgeExplorer.More(): 416 anEdge = topods.Edge(anEdgeExplorer.Current()) 417 mkFillet.Add(myThickness / 12.0, anEdge) 418 419 anEdgeExplorer.Next() 420 421 myBody = mkFillet 422 423 ##Dodajanje grla na steklenico 391 424 neckLocation = gp_Pnt(0, 0, myHeight) 392 425 neckNormal = gp_DZ() … … 396 429 myNeckHeight = myHeight / 10 397 430 398 mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2 , myNeckRadius , \ 399 myNeckHeight) 400 myNeck = mkCylinder.Shape(); 401 402 myBody = BRepAlgoAPI_Fuse(myBody, myNeck) 403 404 # Izdelava votle steklenice 431 mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2 , myNeckRadius , myNeckHeight) 432 433 myNeck = mkCylinder; 434 435 myBody = BRepAlgoAPI_Fuse(myBody.Shape(), myNeck.Shape()) 436 437 ## Izdelava votle steklenice 438 #CILJ: Poiščemo najvišji Z profil in ga odstranimo 405 439 faceToRemove = None 406 440 zMax = -1; 407 t = Topo(myBody.Shape()) 408 k=1 409 for aFace in t.faces(): 410 411 aSurface = BRep_Tool().Surface(aFace) 412 413 if aSurface.GetObject().IsInstance('Geom_Plane'): 414 aPlane = Handle_Geom_Plane().DownCast(aSurface).GetObject() 441 442 #Če želimo najti najvišji Z profil, katerega želimo odstraniti iz lupine, je potrebno iti skozi vse profile 443 aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE) 444 while aFaceExplorer.More(): 445 aFace = topods.Face(aFaceExplorer.Current()) 446 447 if face_is_plane(aFace): 448 aPlane = geom_plane_from_face(aFace) 449 450 # We want the highest Z face, so compare this to the previous faces 415 451 aPnt = aPlane.Location() 416 452 aZ = aPnt.Z() 417 if aZ>zMax: 453 if aZ > zMax: 454 zMax = aZ 418 455 faceToRemove = aFace 419 456 457 aFaceExplorer.Next() 458 420 459 facesToRemove = TopTools_ListOfShape() 421 460 facesToRemove.Append(faceToRemove) … … 423 462 -myThickness/50 , 1.e-3) 424 463 425 # Threading : Create Surfaces 464 ## Navoj na vratu steklenice: 465 #Ustvarjanje površine 426 466 aCyl1 = Geom_CylindricalSurface(gp_Ax3(neckAx2) , myNeckRadius * 0.99) 427 467 aCyl2 = Geom_CylindricalSurface(gp_Ax3(neckAx2) , myNeckRadius * 1.05) 428 468 429 # Threading : Define 2D Curves430 aPnt = gp_Pnt2d(2. * 3.141592, myNeckHeight / 2.)431 aDir = gp_Dir2d(2. * 3.141592, myNeckHeight / 4.)469 #Definiranje 2D krivulje navoja 470 aPnt = gp_Pnt2d(2. * math.pi , myNeckHeight / 2.) 471 aDir = gp_Dir2d(2. * math.pi , myNeckHeight / 4.) 432 472 aAx2d = gp_Ax2d(aPnt , aDir) 433 473 434 aMajor = 2. * 3.141592474 aMajor = 2.0 * math.pi 435 475 aMinor = myNeckHeight / 10. 436 476 437 477 anEllipse1 = Geom2d_Ellipse(aAx2d , aMajor , aMinor) 438 anEllipse2 = Geom2d_Ellipse(aAx2d , aMajor , aMinor / 4 )439 440 a Arc2 = Geom2d_TrimmedCurve(anEllipse1.GetHandle() , 3.141592, 0.)441 a Arc1 = Geom2d_TrimmedCurve(anEllipse2.GetHandle() , 3.141592, 0.)442 478 anEllipse2 = Geom2d_Ellipse(aAx2d , aMajor , aMinor / 4.0) 479 480 anArc1 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse1), 0, math.pi) 481 anArc2 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse2), 0, math.pi) 482 443 483 anEllipsePnt2 = anEllipse1.Value(0.) 444 anEllipsePnt1 = anEllipse1.Value( 3.141592)484 anEllipsePnt1 = anEllipse1.Value(math.pi) 445 485 446 486 aSegment = GCE2d_MakeSegment(anEllipsePnt1 , anEllipsePnt2) 447 487 448 # Threading : Build Edges and Wires449 aEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(a Arc1.GetHandle() , aCyl1.GetHandle())488 #Robovi in mreže 489 aEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1.GetHandle() , aCyl1.GetHandle()) 450 490 aEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value() , aCyl1.GetHandle()) 451 aEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(a Arc2.GetHandle() , aCyl2.GetHandle())491 aEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2.GetHandle() , aCyl2.GetHandle()) 452 492 aEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value() , aCyl2.GetHandle()) 453 print dir(aEdge1OnSurf1)493 #print (dir(aEdge1OnSurf1)) 454 494 threadingWire1 = BRepBuilderAPI_MakeWire(aEdge1OnSurf1.Edge() , aEdge2OnSurf1.Edge()) 455 495 threadingWire2 = BRepBuilderAPI_MakeWire(aEdge1OnSurf2.Edge() , aEdge2OnSurf2.Edge()) 456 496 457 458 BRepLib().BuildCurves3d(threadingWire1.Wire())459 BRepLib().BuildCurves3d(threadingWire2.Wire())460 461 # Create Threading497 #3D predstava robov/mrež 498 breplib.BuildCurves3d(threadingWire1.Shape()) 499 breplib.BuildCurves3d(threadingWire2.Shape()) 500 501 #Površina navoja 462 502 aTool = BRepOffsetAPI_ThruSections(True) 463 464 503 aTool.AddWire(threadingWire1.Wire()) 465 504 aTool.AddWire(threadingWire2.Wire()) 466 505 aTool.CheckCompatibility(False) 467 468 506 myThreading = aTool.Shape() 469 507 470 # Izdelava sestava508 ## Izdelava sestava 471 509 aRes = TopoDS_Compound() 472 510 … … 477 515 aBuilder.Add (aRes, myThreading) 478 516 479 # Izris oblike517 ## Izris oblike 480 518 show_bottle(aRes) 519 520 def draw_bottle(event=None): 521 # Definiranje razdalj: širina, dolžina, višina 522 myWidth = 50.0 523 myThickness = 30.0 524 myHeight = 70.0 525 # Define Points 526 define_body(myWidth, myThickness, myHeight) 527 528 if __name__ == '__main__': 529 # OCC.Display.SimpleGui.init_display() returns multiple 530 # values which are assigned here 531 display, start_display, add_menu, add_function_to_menu = \ 532 init_display() 533 draw_bottle() #kličemo podprogram za izris bottle 534 start_display() 535 481 536 482 537 def draw_bottle(event=None):