Cant display 2d spline

Technical discussions
Vaslav_19
Posts: 3
Joined: Thu Apr 11, 2019 5:34 am

Cant display 2d spline

Postby Vaslav_19 » Sun Feb 09, 2020 2:08 am

Hello gents
I am having problem displaying a 2d spline. A simplified snipped is this:

Code: Select all

      I2DPointArray_DG iArrPnt = myGenerator.Create("2DPointArray_DG") as I2DPointArray_DG;

            iArrPnt.SetCount(3);
            iArrPnt.SetPoint(0, 0, 0);
            iArrPnt.SetPoint(1, 1., 2.);
            iArrPnt.SetPoint(2, 2., 1.5);

            IBSplineCurve2d_DG iCurveBS = myGenerator.Create("BSplineCurve2d_DG") as IBSplineCurve2d_DG;
            iCurveBS.InitFromPoints(iArrPnt, 3, 8, Continuity_DG.eCont_C2, 1e-3);

            IBRepShape_DG iShape = m_myGenerator.Create1("BRepEdge_DG", iCurveBS) as IBRepShape_DG;
            IEntity_DG entity = m_iModel.AddBRepShape(iShape);
             var view = myDgkControl.GetView() as IView_DG;
            view.Reset(true, true);

I do not get any errors. Just an empty screen. The same code works if I do everything in 3D using IBSplineCurve_DG
I would appreciate any ideas
Thank you

Prashant Kande
Posts: 51
Joined: Mon Apr 04, 2016 4:55 am

Re: Cant display 2d spline

Postby Prashant Kande » Mon Feb 10, 2020 5:36 am

Hi Vaslav
The problem is that the edge needs a 3D curve to be attached.
There are several ways to show a 2d spline:
1. Convert a clone of the spline to 3D for the presentation purpose:

Code: Select all

       IBSplineCurve_DG iCurveBs3D = m_myGenerator.Create("BSplineCurve_DG") as IBSplineCurve_DG;  // Empty 3d spline
   // Copy its attributes
            IObject_DG iObj3Dcurve = iCurveBs3D as IObject_DG;
            IObject_DG iObj2d = iCurveBS as IObject_DG;
            iObj3Dcurve.Copy(iObj2d, null);            // Copies 2D staff and sets z=0 everywhere
            IBRepShape_DG iShape = m_myGenerator.Create1("BRepEdge_DG", iCurveBs3D);
            .....

The key here that IObject_DG.Copy() does conversion whenever possible (and implemented) if the other object has a different type.
IObject_DG.Copy() works always for the same type. Other conversions similar to the above (2D is considered as part of z=0 plane whenever possible) are not done consistently. So if you need something else like that, just let us know. You might get it in few days at no charge.

2. This method is easy and nothing added to the model (unless specified)

Code: Select all

           IView_DG iView = m_myDgkControl.GetView() as IView_DG;
            IScene_DG iScene = iView as IScene_DG;
            iScene.CreatePresentationEntity(iCurveBS as IObject_DG, false, null);

Pass true above if the presentation entity it needs to be added to the model for persistence, etc.
Many objects (vaguely related to geometry) can, but not all, be presented this way. Again, give us a yell.

3. The dumbest, but always available:
Create a sampling of the spline with something like 50 points and

Code: Select all

IEntity_DG iStripEntity = m_iModel.AddNewEntity1("SegmentStrip");
IGeometry_DG iGeom = iStripEntity.GetGeometry();
ISectionLineStrip  iStrip = iGeom as ISectionLineStrip;   //.. Copy the points into iStrip

Cheers


Return to “General Issues”

Who is online

Users browsing this forum: No registered users and 1 guest