|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +##Copyright 2009-2015 Jelle Ferina ([email protected]) |
| 4 | +## |
| 5 | +##This file is part of pythonOCC. |
| 6 | +## |
| 7 | +##pythonOCC is free software: you can redistribute it and/or modify |
| 8 | +##it under the terms of the GNU Lesser General Public License as published by |
| 9 | +##the Free Software Foundation, either version 3 of the License, or |
| 10 | +##(at your option) any later version. |
| 11 | +## |
| 12 | +##pythonOCC is distributed in the hope that it will be useful, |
| 13 | +##but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +##GNU Lesser General Public License for more details. |
| 16 | +## |
| 17 | +##You should have received a copy of the GNU Lesser General Public License |
| 18 | +##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +from __future__ import print_function |
| 21 | + |
| 22 | +import math |
| 23 | +import time |
| 24 | +import sys |
| 25 | + |
| 26 | +from OCC.gp import gp_Pnt2d, gp_Pln |
| 27 | +from OCC.Geom import Geom_Plane |
| 28 | +from OCC.FairCurve import FairCurve_MinimalVariation |
| 29 | +from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeEdge |
| 30 | +from OCC.Display.SimpleGui import init_display |
| 31 | +display, start_display, add_menu, add_function_to_menu = init_display() |
| 32 | + |
| 33 | + |
| 34 | +def error_code(n): |
| 35 | + errors = {0: "FairCurve_OK", |
| 36 | + 1: "FairCurve_NotConverged", |
| 37 | + 2: "FairCurve_InfiniteSliding", |
| 38 | + 3: "FairCurve_NullHeight", |
| 39 | + } |
| 40 | + return errors[n] |
| 41 | + |
| 42 | + |
| 43 | +def batten_curve(pt1, pt2, height, slope, angle1, angle2): |
| 44 | + fc = FairCurve_MinimalVariation(pt1, pt2, height, slope) |
| 45 | + fc.SetConstraintOrder1(2) |
| 46 | + fc.SetConstraintOrder2(2) |
| 47 | + fc.SetAngle1(angle1) |
| 48 | + fc.SetAngle2(angle2) |
| 49 | + fc.SetHeight(height) |
| 50 | + fc.SetSlope(slope) |
| 51 | + fc.SetFreeSliding(True) |
| 52 | + print(fc.DumpToString()) |
| 53 | + status = fc.Compute() |
| 54 | + print(error_code(status[0]), error_code(status[1])) |
| 55 | + return fc.Curve() |
| 56 | + |
| 57 | + |
| 58 | +def faircurve(event=None): |
| 59 | + pt1 = gp_Pnt2d(0., 0.) |
| 60 | + pt2 = gp_Pnt2d(0., 120.) |
| 61 | + height = 100. |
| 62 | + pl = Geom_Plane(gp_Pln()) |
| 63 | + for i in range(0, 40): |
| 64 | + # TODO: the parameter slope needs to be visualized |
| 65 | + slope = i/100. |
| 66 | + bc = batten_curve(pt1, pt2, height, slope, |
| 67 | + math.radians(i), math.radians(-i)) |
| 68 | + display.EraseAll() |
| 69 | + edge = BRepBuilderAPI_MakeEdge(bc, pl.GetHandle()).Edge() |
| 70 | + display.DisplayShape(edge, update=True) |
| 71 | + time.sleep(0.21) |
| 72 | + |
| 73 | + |
| 74 | +def exit(event=None): |
| 75 | + sys.exit(0) |
| 76 | + |
| 77 | +if __name__ == "__main__": |
| 78 | + add_menu('fair curve') |
| 79 | + add_function_to_menu('fair curve', faircurve) |
| 80 | + add_function_to_menu('fair curve', exit) |
| 81 | + start_display() |
0 commit comments