|
| 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_Sphere, gp_Ax3, gp_Dir, gp_Circ, gp_Ax2, |
| 21 | + gp_Pnt2d, gp_Dir2d) |
| 22 | +from OCC.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge, |
| 23 | + BRepBuilderAPI_MakeFace, |
| 24 | + BRepBuilderAPI_MakeWire) |
| 25 | +from OCC.TColgp import TColgp_Array2OfPnt |
| 26 | +from OCC.GeomAPI import GeomAPI_PointsToBSplineSurface |
| 27 | +from OCC.GeomAbs import GeomAbs_C2 |
| 28 | +from OCC.Geom2d import Geom2d_Line |
| 29 | +from OCC.BRepLib import breplib_BuildCurves3d |
| 30 | +from OCC.Quantity import Quantity_Color, Quantity_NOC_PINK |
| 31 | + |
| 32 | +from OCC.Display.SimpleGui import init_display |
| 33 | +display, start_display, add_menu, add_function_to_menu = init_display() |
| 34 | + |
| 35 | + |
| 36 | +def face(): |
| 37 | + p1 = gp_Pnt() |
| 38 | + p2 = gp_Pnt() |
| 39 | + p3 = gp_Pnt() |
| 40 | + p4 = gp_Pnt() |
| 41 | + p5 = gp_Pnt() |
| 42 | + p6 = gp_Pnt() |
| 43 | + |
| 44 | + # The white Face |
| 45 | + sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150) |
| 46 | + green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9) |
| 47 | + |
| 48 | + # The red face |
| 49 | + p1.SetCoord(-15, 200, 10) |
| 50 | + p2.SetCoord(5, 204, 0) |
| 51 | + p3.SetCoord(15, 200, 0) |
| 52 | + p4.SetCoord(-15, 20, 15) |
| 53 | + p5.SetCoord(-5, 20, 0) |
| 54 | + p6.SetCoord(15, 20, 35) |
| 55 | + array = TColgp_Array2OfPnt(1, 3, 1, 2) |
| 56 | + array.SetValue(1, 1, p1) |
| 57 | + array.SetValue(2, 1, p2) |
| 58 | + array.SetValue(3, 1, p3) |
| 59 | + array.SetValue(1, 2, p4) |
| 60 | + array.SetValue(2, 2, p5) |
| 61 | + array.SetValue(3, 2, p6) |
| 62 | + curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, |
| 63 | + 0.001).Surface() |
| 64 | + red_face = BRepBuilderAPI_MakeFace(curve, 1e-6) |
| 65 | + |
| 66 | + #The brown face |
| 67 | + circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80) |
| 68 | + Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi) |
| 69 | + Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40)) |
| 70 | + Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80)) |
| 71 | + |
| 72 | + ##TopoDS_Wire YellowWire |
| 73 | + MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge()) |
| 74 | + if MW1.IsDone(): |
| 75 | + yellow_wire = MW1.Wire() |
| 76 | + brown_face = BRepBuilderAPI_MakeFace(yellow_wire) |
| 77 | + |
| 78 | + #The pink face |
| 79 | + p1.SetCoord(35, -200, 40) |
| 80 | + p2.SetCoord(50, -204, 30) |
| 81 | + p3.SetCoord(65, -200, 30) |
| 82 | + p4.SetCoord(35, -20, 45) |
| 83 | + p5.SetCoord(45, -20, 30) |
| 84 | + p6.SetCoord(65, -20, 65) |
| 85 | + array2 = TColgp_Array2OfPnt(1, 3, 1, 2) |
| 86 | + array2.SetValue(1, 1, p1) |
| 87 | + array2.SetValue(2, 1, p2) |
| 88 | + array2.SetValue(3, 1, p3) |
| 89 | + array2.SetValue(1, 2, p4) |
| 90 | + array2.SetValue(2, 2, p5) |
| 91 | + array2.SetValue(3, 2, p6) |
| 92 | + BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2, |
| 93 | + 0.001) |
| 94 | + aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face() |
| 95 | + ## |
| 96 | + ##//2d lines |
| 97 | + P12d = gp_Pnt2d(0.9, 0.1) |
| 98 | + P22d = gp_Pnt2d(0.2, 0.7) |
| 99 | + P32d = gp_Pnt2d(0.02, 0.1) |
| 100 | + ## |
| 101 | + line1 = Geom2d_Line(P12d, gp_Dir2d((0.2-0.9), (0.7-0.1))) |
| 102 | + line2 = Geom2d_Line(P22d, gp_Dir2d((0.02-0.2), (0.1-0.7))) |
| 103 | + line3 = Geom2d_Line(P32d, gp_Dir2d((0.9-0.02), (0.1-0.1))) |
| 104 | + ## |
| 105 | + ##//Edges are on the BSpline surface |
| 106 | + Edge1 = BRepBuilderAPI_MakeEdge(line1.GetHandle(), BSplineSurf.Surface(), |
| 107 | + 0, P12d.Distance(P22d)).Edge() |
| 108 | + Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(), |
| 109 | + 0, P22d.Distance(P32d)).Edge() |
| 110 | + Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), BSplineSurf.Surface(), |
| 111 | + 0, P32d.Distance(P12d)).Edge() |
| 112 | + ## |
| 113 | + Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire() |
| 114 | + Wire1.Reverse() |
| 115 | + pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face() |
| 116 | + breplib_BuildCurves3d(pink_face) |
| 117 | + |
| 118 | + display.DisplayColoredShape(green_face.Face(), 'GREEN') |
| 119 | + display.DisplayColoredShape(red_face.Face(), 'RED') |
| 120 | + display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK)) |
| 121 | + display.DisplayColoredShape(brown_face.Face(), 'BLUE') |
| 122 | + display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True) |
| 123 | + |
| 124 | +if __name__ == '__main__': |
| 125 | + face() |
| 126 | + start_display() |
0 commit comments