Changes between Version 38 and Version 39 of PythonOcc/primitives


Ignore:
Timestamp:
Nov 6, 2015, 4:16:13 PM (5 years ago)
Author:
dpenko
Comment:

Uredil kodo za nov PythonOcc 0.16 pri "Izdelava zaokrožitev"

Legend:

Unmodified
Added
Removed
Modified
  • PythonOcc/primitives

    v38 v39  
    453453Knjižnica ukazov za izdelavo zaokrožitev se nahaja v viru BRepFilletAPI in jo je potrebno vključiti v program pred uporabo ukaza:
    454454{{{
    455 #!python
    456 from OCC.TopExp import*       
     455#!python     
    457456from OCC.BRepFilletAPI import *
    458 from OCC.Utils.Topology import *
     457from OCC.TopExp import *
     458from OCC.TopAbs import *
     459from OCC.TopTools import *
     460from OCC.TopoDS import *
     461from OCC.TColgp import *
     462from OCC.Display.OCCViewer import *
    459463}}}
    460464Pri apliciranju vseh vrst zaokrožitev je potrebno imeti podatek o robu oziroma točki kamor hočemo izvesti zaokrožitev ter o parametrih zaokrožitve (radij zaokrožitve).
     
    469473{{{
    470474#!python
    471 topology_traverser = Topo(Oblika)
    472 for aEdge in topology_traverser.edges():
    473     zaokrozitev.Add(Radij , aEdge)
    474 #    zaokrozitev.Add(Radij_1, Radij_2 , aEdge)
     475anEdgeExplorer = TopExp_Explorer(oblika, TopAbs_EDGE)
     476
     477    while anEdgeExplorer.More():
     478        anEdge = topods.Edge(anEdgeExplorer.Current())
     479        zaokrozitev.Add(Radij_1, anEdge)
     480        #zaokrozitev.Add(Radij_1, Radij_2, anEdge)
     481        anEdgeExplorer.Next()
     482
     483    zaokrozitev.Build()
     484    oblika = zaokrozitev.Shape()
    475485}}}
    476486[[BR]][[BR]][[BR]][[BR]][[BR]][[BR]][[BR]][[BR]] [[Image(26.png, 300, right)]]
     
    478488{{{
    479489#!python
    480 for aEdge in topology_traverser.edges():
    481     first, last = TopExp().FirstVertex(aEdge), TopExp().LastVertex(aEdge)
    482     first_vert, last_vert = BRep_Tool().Pnt(first), BRep_Tool().Pnt(last)
    483     if first_vert.Z() != last_vert.Z():
    484         zaokrozitev.Add(Radij, aEdge)
     490topExp = TopExp_Explorer()
     491    topExp.Init(oblika, TopAbs_VERTEX)
     492
     493    # Vzamemo dve točki (two vertices)
     494    vertA = topods_Vertex(topExp.Current())
     495    topExp.Next()
     496    vertB = topods_Vertex(topExp.Current())
     497    anEdgeExplorer = TopExp_Explorer(oblika, TopAbs_EDGE)
     498    while anEdgeExplorer.More():
     499        edge = topods.Edge(anEdgeExplorer.Current())
     500        first, last = topexp_FirstVertex(edge), topexp_LastVertex(edge)
     501        vertex, first_vert, last_vert = BRep_Tool().Pnt(vertA), BRep_Tool().Pnt(first), BRep_Tool().Pnt(last)
     502        if first_vert.Z() != last_vert.Z():
     503            zaokrozitev.Add(Radij_1, edge)
     504        anEdgeExplorer.Next()
     505    afillet.Build()
     506    oblika = afillet.Shape()
    485507}}}
    486508Pri izdelavi zaokrožitev moramo biti pozorni na velikost zaokrožitve. Vrednost zaokrožitve mora biti dovolj majhna da lahko normalno zaokrožimo robove.
     
    523545{{{
    524546#!python
    525 def vertex_fillet(oblika, tocka):
     547def vertex_fillet(oblika, vert):
    526548    afillet = BRepFilletAPI_MakeFillet(oblika)
    527549    cnt = 0
    528     for edg in topo.edges_from_vertex(tocka):
    529         first, last = TopExp().FirstVertex(edg), TopExp().LastVertex(edg)
    530         vertex, first_vert, last_vert = BRep_Tool().Pnt(tocka), BRep_Tool().Pnt(first), BRep_Tool().Pnt(last)
    531         if edg.Orientation():
     550    # Iz točk najdemo robove
     551    _map = TopTools_IndexedDataMapOfShapeListOfShape()
     552    topexp_MapShapesAndAncestors(oblika, TopAbs_VERTEX, TopAbs_EDGE, _map)
     553    results = _map.FindFromKey(vert)
     554    topology_iterator = TopTools_ListIteratorOfListOfShape(results)
     555    while topology_iterator.More():
     556        edge = topods_Edge(topology_iterator.Value())
     557        topology_iterator.Next()
     558        first, last = topexp_FirstVertex(edge), topexp_LastVertex(edge)
     559        vertex, first_vert, last_vert = BRep_Tool().Pnt(vert), BRep_Tool().Pnt(first), BRep_Tool().Pnt(last)
     560        if edge.Orientation():
    532561            if not vertex.IsEqual(first_vert, 0.001):
    533                 afillet.Add(Radij_1, Radij_2, Rob)
     562                afillet.Add(0, 20., edge)
    534563            else:
    535                 afillet.Add(Radij_1, Radij_2, Rob)
    536             cnt+=1
     564                afillet.Add(20, 0, edge)
     565        cnt += 1
    537566    afillet.Build()
    538567    if afillet.IsDone():