Cannot display PrsDim_LengthDimension

I am trying to create a length dim in the 3dViewer.
I thought that is helpful to see my attachments file first.
That attachment file shows the result about these codes.

// Code Starts //
Handle(Geom_Point) handle_PointA = new Geom_CartesianPoint(messuare_PointA);
Handle(Geom_Point) handle_PointB = new Geom_CartesianPoint(messuare_PointB);

// -vvvv- Display SupportLine -vvvv- //
// Create A supportLine .This Line starts from PointA and PointB;
Handle(AIS_Line) ais_supportLine = new AIS_Line(handle_PointA, handle_PointB);
// Set the supprotLine color and width more clear
Quantity_Color c = Quantity_Color();
c.SetValues(Quantity_NOC_GREEN);
ais_supportLine->SetColor(c);
ais_supportLine->SetWidth(7);

myContext->Display(ais_supportLine, true);
// -^^^^- Display SupportLine -^^^^- //
// Code Ends //

Because I can actually see the green supportLine in my viewer.
So I can know that the PointA and PointB is actually the point that I wanted to select,and the way I display an InteractiveObject is also right.

So the way that I am trying to display a interactive object should be right.Beacuse I actually see the green line.

Now I am trying to show the lengthDim on my screen.
I noticed that class "PrsDim_LengthDimension" inherts from the class "AIS_InteractiveObject".After showing my support line correctly,It should be similar to show another InteractiveObject.

// Code Starts //
Handle(Geom_Point) handle_PointA = new Geom_CartesianPoint(messuare_PointA);
Handle(Geom_Point) handle_PointB = new Geom_CartesianPoint(messuare_PointB);
// -vvvv- Display PrsDIM -vvvv- //
// Get the Camera plane from camera data
gp_Pnt cameraCenter = myV3dView->Camera()->Center();
gp_Dir camera_Dir = myV3dView->Camera()->Direction();
gp_Pln cameraPlane = gp_Pln(cameraCenter, camera_Dir);
// Create our interactiveObject that display lengthDim
Handle(PrsDim_LengthDimension) dimAtCameraPlane = new PrsDim_LengthDimension(messuare_PointA, messuare_PointB, cameraPlane);
myContext->Display(dimAtCameraPlane, true);
// -^^^^- Display PrsDIM -^^^^- //
// Code Ends //

But I can not see the lengthDim on my screen.So I thought maybe the way I construct the PrsDim_LengthDimension is wrong.
so,I thought maybe i get trouble in meaning of the third the third argument in the constructor function:
PrsDim_LengthDimension::PrsDim_LengthDimension (
const gp_Pnt & theFirstPoint,
const gp_Pnt & theSecondPoint,
const gp_Pln & thePlane
).

The document said that " thePlane ------[in] the plane to orient dimension."

So ,I tried to use the ZNear plane and the ZFar plane like the code below

// Code Starts //
// Dim At ZNear Plane
Standard_Real zNear = myV3dView->Camera()->ZNear();
Standard_Real nearPointX = cameraCenter.X() + camera_Dir.X() * zNear;
Standard_Real nearPointY = cameraCenter.Y() + camera_Dir.Y() * zNear;
Standard_Real nearPointZ = cameraCenter.Z() + camera_Dir.Z() * zNear;
gp_Pnt pointAtNearPlane = gp_Pnt(nearPointX, nearPointY, nearPointZ);
gp_Pln nearPlane = gp_Pln(pointAtNearPlane, camera_Dir);
Handle(PrsDim_LengthDimension) dimAtNearPlane = new PrsDim_LengthDimension(messuare_PointA, messuare_PointB, nearPlane);
myContext->Display(dimAtNearPlane, true);
// Dim At ZFar Plane
Standard_Real zFar = myV3dView->Camera()->ZFar();
Standard_Real farPointX = cameraCenter.X() + camera_Dir.X() * zFar;
Standard_Real farPointY = cameraCenter.Y() + camera_Dir.Y() * zFar;
Standard_Real farPointZ = cameraCenter.Z() + camera_Dir.Z() * zFar;
gp_Pnt pointAtFarPlane = gp_Pnt(farPointX, farPointY, farPointZ);
gp_Pln farPlane = gp_Pln(pointAtFarPlane, camera_Dir);
Handle(PrsDim_LengthDimension) dimAtFarPlane = new PrsDim_LengthDimension(messuare_PointA, messuare_PointB, farPlane);
myContext->Display(dimAtFarPlane, true);
// Code Ends //

But I still can not see my dim on the screen.

Now I thought it's time to post my trouble at the fourm and seeking for your helps.
Any words from you guys can help me.
Thank you

gkv311 n's picture

thePlane parameter you are trying to pass cannot be computed like this:

gp_Pnt cameraCenter = myV3dView->Camera()->Center();

gp_Dir camera_Dir = myV3dView->Camera()->Direction();

gp_Pln cameraPlane = gp_Pln(cameraCenter, camera_Dir);

Handle(PrsDim_LengthDimension) dimAtCameraPlane = new PrsDim_LengthDimension(messuare_PointA, messuare_PointB, cameraPlane);

The main requirement for this plane is that 2 end point of length dimension (e.g. messuare_PointA and messuare_PointB) should lie on this plane. So that basically you need to construct gp_Pln from these 2 points plus 1 point defining to the which side this dimension should be drawn.

Or take any of these two points and define normal to the plane (but make sure that normal doesn't pass through the 2nd point).