|
| 1 | +##Copyright 2009-2015 Thomas Paviot ([email protected]) |
| 2 | +## |
| 3 | +##This file is part of pythonOCC. |
| 4 | +## |
| 5 | +##pythonOCC is free software: you can redistribute it and/or modify |
| 6 | +##it under the terms of the GNU Lesser General Public License as published by |
| 7 | +##the Free Software Foundation, either version 3 of the License, or |
| 8 | +##(at your option) any later version. |
| 9 | +## |
| 10 | +##pythonOCC is distributed in the hope that it will be useful, |
| 11 | +##but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +##GNU Lesser General Public License for more details. |
| 14 | +## |
| 15 | +##You should have received a copy of the GNU Lesser General Public License |
| 16 | +##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +import math |
| 19 | + |
| 20 | +from OCC.gp import gp_Pnt, gp_Lin, gp_Ax1, gp_Dir, gp_Elips, gp_Ax2 |
| 21 | +from OCC.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge, |
| 22 | + BRepBuilderAPI_MakeVertex) |
| 23 | +from OCC.TColgp import TColgp_Array1OfPnt |
| 24 | +from OCC.Geom import Geom_BezierCurve |
| 25 | + |
| 26 | +from OCC.Display.SimpleGui import init_display |
| 27 | +display, start_display, add_menu, add_function_to_menu = init_display() |
| 28 | + |
| 29 | + |
| 30 | +def edge(event=None): |
| 31 | + # The blud edge |
| 32 | + BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20), |
| 33 | + gp_Pnt(-30, -60, -60)) |
| 34 | + V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30)) |
| 35 | + V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25)) |
| 36 | + YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex()) |
| 37 | + |
| 38 | + #The white edge |
| 39 | + line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0))) |
| 40 | + WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10) |
| 41 | + |
| 42 | + #The red edge |
| 43 | + Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30) |
| 44 | + RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi/2) |
| 45 | + |
| 46 | + # The green edge and the both extreme vertex |
| 47 | + P1 = gp_Pnt(-15, 200, 10) |
| 48 | + P2 = gp_Pnt(5, 204, 0) |
| 49 | + P3 = gp_Pnt(15, 200, 0) |
| 50 | + P4 = gp_Pnt(-15, 20, 15) |
| 51 | + P5 = gp_Pnt(-5, 20, 0) |
| 52 | + P6 = gp_Pnt(15, 20, 0) |
| 53 | + P7 = gp_Pnt(24, 120, 0) |
| 54 | + P8 = gp_Pnt(-24, 120, 12.5) |
| 55 | + array = TColgp_Array1OfPnt(1, 8) |
| 56 | + array.SetValue(1, P1) |
| 57 | + array.SetValue(2, P2) |
| 58 | + array.SetValue(3, P3) |
| 59 | + array.SetValue(4, P4) |
| 60 | + array.SetValue(5, P5) |
| 61 | + array.SetValue(6, P6) |
| 62 | + array.SetValue(7, P7) |
| 63 | + array.SetValue(8, P8) |
| 64 | + curve = Geom_BezierCurve(array) |
| 65 | + ME = BRepBuilderAPI_MakeEdge(curve.GetHandle()) |
| 66 | + GreenEdge = ME |
| 67 | + V3 = ME.Vertex1() |
| 68 | + V4 = ME.Vertex2() |
| 69 | + |
| 70 | + display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE') |
| 71 | + display.DisplayShape(V1.Vertex()) |
| 72 | + display.DisplayShape(V2.Vertex()) |
| 73 | + display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE') |
| 74 | + display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW') |
| 75 | + display.DisplayColoredShape(RedEdge.Edge(), 'RED') |
| 76 | + display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN') |
| 77 | + display.DisplayShape(V3) |
| 78 | + display.DisplayShape(V4, update=True) |
| 79 | + |
| 80 | +if __name__ == '__main__': |
| 81 | + edge() |
| 82 | + start_display() |
0 commit comments