Skip to content

Commit ec416c7

Browse files
committed
Added core_geometry_line_properties thanks Emad
1 parent e6e78f6 commit ec416c7

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
3+
##Copyright 2017 Emad Dlala (emad.dlala@gmail.com)
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 sys
23+
24+
from OCC.gp import gp_Pnt, gp_Dir
25+
from OCC.Geom import Geom_Line
26+
from OCC.AIS import AIS_Line, AIS_Drawer
27+
from OCC.Quantity import Quantity_NOC_RED
28+
from OCC.Prs3d import (Prs3d_LineAspect)
29+
from OCC.Aspect import Aspect_TOL_DASH
30+
31+
from OCC.Display.SimpleGui import init_display
32+
display, start_display, add_menu, add_function_to_menu = init_display()
33+
34+
35+
def line():
36+
# create a line
37+
p1 = gp_Pnt(2., 3., 4.)
38+
d1 = gp_Dir(4., 5., 6.)
39+
line1 = Geom_Line(p1, d1)
40+
41+
ais_line1 = AIS_Line(line1.GetHandle())
42+
43+
# if we need to edit color, we can simply use SetColor
44+
# ais_line1.SetColor(Quantity_NOC_RED)
45+
46+
# but actually we need to edit more, not just color. Line width and style as well
47+
# To do that, we need to do use AIS_Drawer and apply it to ais_line1
48+
width = 1.0
49+
drawer = AIS_Drawer()
50+
asp = Prs3d_LineAspect(Quantity_NOC_RED, Aspect_TOL_DASH, width)
51+
drawer.SetLineAspect(asp.GetHandle())
52+
ais_line1.SetAttributes(drawer.GetHandle())
53+
54+
display.Context.Display(ais_line1.GetHandle(), False)
55+
# we can apply the same rule for other lines by just doing a for loop
56+
for i in range(1, 5):
57+
p2 = gp_Pnt(i, 2., 5.)
58+
d2 = gp_Dir(4*i, 6., 9.)
59+
line2 = Geom_Line(p2, d2)
60+
61+
ais_line2 = AIS_Line(line2.GetHandle())
62+
# ais_line2.SetColor(Quantity_NOC_RED)
63+
64+
width = float(i)
65+
drawer = AIS_Drawer()
66+
asp = Prs3d_LineAspect(9*i, i, width)
67+
drawer.SetLineAspect(asp.GetHandle())
68+
ais_line2.SetAttributes(drawer.GetHandle())
69+
70+
display.Context.Display(ais_line2.GetHandle(), False)
71+
start_display()
72+
73+
74+
def exit(event=None):
75+
sys.exit()
76+
77+
if __name__ == '__main__':
78+
line()

0 commit comments

Comments
 (0)