Changes between Version 9 and Version 10 of PythonOcc


Ignore:
Timestamp:
Dec 19, 2011, 3:38:46 PM (13 years ago)
Author:
skulovec
Comment:

Izdelava CAD kocke z predhodno definiranimi točkami (Uporaba for zanke za generiranje točk, površin, mreže)

Legend:

Unmodified
Added
Removed
Modified
  • PythonOcc

    v9 v10  
    603603start_display()
    604604}}}
     605
     606=== Izdelava CAD kocke z predhodno definiranimi točkami (Uporaba for zanke za generiranje točk, površin, mreže) ===
     607{{{
     608#!python
     609import sys
     610from OCC.Display.SimpleGui import *
     611
     612from OCC.gp import gp_Pnt
     613from OCC.GC import GC_MakeSegment
     614from OCC.BRepBuilderAPI import \
     615  BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire,\
     616  BRepBuilderAPI_MakeShell, BRepBuilderAPI_MakeSolid
     617from OCC.BRep import BRep_Builder
     618from OCC.TopoDS import TopoDS_Shell, TopoDS_Solid
     619from OCC import StlAPI
     620
     621mesh = {
     622  "vertices":[[-0.2,-0.2,0.2],[0.2,-0.2,0.2],[0.2,0.2,0.2],[-0.2,0.2,0.2],\
     623                  [-0.2,-0.2,0.6000000000000001],[0.2,-0.2,0.6000000000000001],\
     624                  [0.2,0.2,0.6000000000000001],[-0.2,0.2,0.6000000000000001]],
     625  "faces":[[3,2,1,0],[4,5,6,7],[7,6,2,3],[5,4,0,1],[6,5,1,2],[4,7,3,0]]
     626}
     627
     628def main():
     629
     630  vertices = [ gp_Pnt(p[0],p[1],p[2]) for p in mesh['vertices'] ]
     631  oFaces = []
     632
     633  builder = BRep_Builder()
     634  shell = TopoDS_Shell()
     635  builder.MakeShell(shell)
     636
     637  for face in mesh['faces']:
     638    edges = []
     639    face.reverse()
     640    for i in range(len(face)):
     641      cur = face[i]
     642      nxt = face[(i+1)%len(face)]
     643      segment = GC_MakeSegment(vertices[cur],vertices[nxt])
     644      edges.append(BRepBuilderAPI_MakeEdge(segment.Value()))
     645
     646    wire = BRepBuilderAPI_MakeWire()
     647    for edge in edges:
     648      wire.Add(edge.Edge())
     649
     650    oFace = BRepBuilderAPI_MakeFace(wire.Wire())
     651
     652    builder.Add(shell, oFace.Shape())
     653    display.DisplayShape(shell)
     654
     655if __name__ == '__main__':
     656    display, start_display, add_menu, add_function_to_menu = \
     657        init_display()
     658    main()
     659    start_display()
     660}}}