2009/7/10 Nathan Lauener <lauener.nat...@gmx.ch>

> >> Hi,
> >>
> >> I'm pretty new to pythonocc and am impressed by it. Thanks for your
> work!
> >>
> >> After I ran across splines the other day I am now trying to use
> >> opencascade and pythonocc for curve definitions and anaylsis. But I
> >> could not figure out how to concat two splines into one. The mailing
> >> list and searching the internet only showed examples on how to do it in
> >> C++, and I can not adopt it to python! The function I'd like to use is
> >> GeomConvert().ConcatG1(), but I can't figure out how to declare the
> >> third parameter of type Handle_TColGeom_HArray1OfBSplineCurve. I always
> >> get a constructor or type error. See the listing of my little sample
> >> programm.
> >>
> >>    #Line
> >>    L2 = GC_MakeSegment(L1.Lin(),0,8)
> >>    L3 = Geom_TrimmedCurve(L1.GetHandle(),0,8)
> >>    L3_S =
> >>
> >>
> GeomConvert().CurveToBSplineCurve(L3.GetHandle(),Convert.Convert_TgtThetaOver2
> >> )
> >>
> >>    #Circle
> >>    P2 = gp_Pnt(2,8,0)
> >>    N = gp_Dir(0,0,-1)
> >>    C1 = Geom_Circle(gp.gp_Ax2(P2,N),2)
> >>    C3 = Geom_TrimmedCurve(C1.GetHandle(),0,math.pi/2)
> >>    C3_S =
> >>
> >>
> GeomConvert().CurveToBSplineCurve(C3.GetHandle(),Convert.Convert_TgtThetaOver2
> >> )
> >>
> >>    #concat
> >>    curves = TColGeom_Array1OfBSplineCurve(0,1)
> >>    curves.SetValue(0,L3_S)
> >>    curves.SetValue(1,C3_S)
> >>    print curves.Length()
> >>    tol = TColStd_Array1OfReal(0,0)
> >>    tol.SetValue(0,0.0)
> >>
> >>    newCurve = Handle_TColGeom_HArray1OfBSplineCurve()
> >>    GeomConvert().ConcatG1(curves, tol, newCurve, False, 0.0)
> >>
> >> Regards,
> >> Nathan
> >>
>
> > Hi Nathan,
> >
> > I don't see any error in your code. Can you provide the traceback
> > and/or a sample script so that we can help you to figure out what's
> > wrong?
> >
> > Regards,
> >
> > Thomas
>
> Hi Thomas
>
> Thanks for the quick answer. The following traceback is printed
>
> Traceback (most recent call last):
>  File "example.py", line 35, in <module>
>     GeomConvert().ConcatG1(curves, tol, newCurve, False, 0.0)
>   File "/usr/lib/python2.5/site-packages/OCC/GeomConvert.py", line 266, in
> ConcatG1
>    return _GeomConvert.GeomConvert_ConcatG1(*args)
> RuntimeError: Standard_ConstructionError
>
> And here the sample program:
>
> #!/usr/bin/env python
>
> from OCC.gp import *
> from OCC.Geom import *
> from OCC.GeomConvert import *
> from OCC.TColStd import *
> from OCC.TColGeom import *
> from OCC.GC import *
>
> import math
>
> #Line
> P1 = gp_Pnt(0,0,0)
> D = gp_Dir(0,1,0)
> L1 = Geom_Line(P1,D)
> L2 = GC_MakeSegment(L1.Lin(),0,8)
> L3 = Geom_TrimmedCurve(L1.GetHandle(),0,8)
> L3_S =
> GeomConvert().CurveToBSplineCurve(L3.GetHandle(),Convert.Convert_TgtThetaOver2)
>
> #Circle
> P2 = gp_Pnt(2,8,0)
> N = gp_Dir(0,0,-1)
> C1 = Geom_Circle(gp.gp_Ax2(P2,N),2)
> C3 = Geom_TrimmedCurve(C1.GetHandle(),0,math.pi/2)
> C3_S
> =GeomConvert().CurveToBSplineCurve(C3.GetHandle(),Convert.Convert_TgtThetaOver2)
>
> #concat
> curves = TColGeom_Array1OfBSplineCurve(0,1)
> curves.SetValue(0,L3_S)
> curves.SetValue(1,C3_S)
> tol = TColStd_Array1OfReal(0,0)
> tol.SetValue(0,0.0)
>
> newCurve = Handle_TColGeom_HArray1OfBSplineCurve()
> GeomConvert().ConcatG1(curves, tol, newCurve, False, 0.0)
>
>
> Regards,
> Nathan
>

Hi Nathan,

You use the API properly. The 'Standard_ConstructionError' exception is
raised by OpenCASCADE and catched by pythonOCC. It means it's a geometric
(or topological) issue. I tested your script and the problem come from the
tolerance you set: you should not set 0 (tol.SetValue(0,0.0)) but rather a
positive float number (for instance 0.1: tol.SetValue(0,0.1)).

Attached the screenshot and your modified script.

Enjoy,

Thomas

#!/usr/bin/env python

from OCC.gp import *
from OCC.Geom import *
from OCC.GeomConvert import *
from OCC.TColStd import *
from OCC.TColGeom import *
from OCC.GC import *
from OCC.BRepBuilderAPI import *

import math
from OCC.Display.wxSamplesGui import display,start_display

def make_edge(shape):
    spline = BRepBuilderAPI_MakeEdge(shape)
    spline.Build()
    return spline.Shape()

#Line
P1 = gp_Pnt(0,0,0)
D = gp_Dir(0,1,0)
L1 = Geom_Line(P1,D)
L2 = GC_MakeSegment(L1.Lin(),0,8)
L3 = Geom_TrimmedCurve(L1.GetHandle(),0,8)
L3_S =
GeomConvert().CurveToBSplineCurve(L3.GetHandle(),Convert.Convert_TgtThetaOver2)
#Circle
P2 = gp_Pnt(2,8,0)
N = gp_Dir(0,0,-1)
C1 = Geom_Circle(gp.gp_Ax2(P2,N),2)
C3 = Geom_TrimmedCurve(C1.GetHandle(),0,math.pi/2)
C3_S
=GeomConvert().CurveToBSplineCurve(C3.GetHandle(),Convert.Convert_TgtThetaOver2)
#concat
curves = TColGeom_Array1OfBSplineCurve(0,1)
curves.SetValue(0,L3_S)
curves.SetValue(1,C3_S)
tol = TColStd_Array1OfReal(0,0)
tol.SetValue(0,0.1)

newCurve = Handle_TColGeom_HArray1OfBSplineCurve()
GeomConvert().ConcatG1(curves, tol, newCurve, False, 0.0)

# Display curve
display.DisplayShape(make_edge(newCurve.GetObject().Value(0)))
start_display()

<<attachment: scr_test_nathan.JPG>>

_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to