For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Draw the rectangle in normal direction to screen

yeon cheol Kang's picture
Forums: 

HI. todays i make a rectangle object in my code. In OCC, they don't offer function which users draw the rectangle using by. So i use the Geom_Curve, I draw the rectangle. downside, it's my code.

void GeomSources::DrawRectangle(C****Doc * aDoc, CPoint FirstMousePoint, CPoint LastMousePoint)
{
gp_Pnt ConvertFirstCornerPoint;
ConvertFirstCornerPoint = ((CASCENTView*)((((CMainFrame*)AfxGetMainWnd())->GetActiveFrame())->GetActiveView()))->Convert(FirstMousePoint);
gp_Pnt ConvertLastCornerPoint;
ConvertLastCornerPoint = ((CASCENTView*)((((CMainFrame*)AfxGetMainWnd())->GetActiveFrame())->GetActiveView()))->Convert(LastMousePoint);
if(ConvertFirstCornerPoint.X() == ConvertLastCornerPoint.X() &&
ConvertFirstCornerPoint.Y() == ConvertLastCornerPoint.Y() &&
ConvertFirstCornerPoint.Z() == ConvertLastCornerPoint.Z())
{
AfxMessageBox(_T("You must select difference point"));
}
else
{
gp_Dir NormalToPlaneDirection;
NormalToPlaneDirection = ((CASCENTView*)((((CMainFrame*)AfxGetMainWnd())->GetActiveFrame())->GetActiveView()))->NormalToScreen();

gp_Pln PointLocatedPlane(ConvertFirstCornerPoint, NormalToPlaneDirection);

gp_Pnt CornerPoint1;
gp_Pnt CornerPoint2;

if(PointLocatedPlane.Contains(ConvertLastCornerPoint,0))
{
if(ConvertFirstCornerPoint.Z() == ConvertLastCornerPoint.Z())
{
if(ConvertFirstCornerPoint.Y() {
CornerPoint1.SetX(ConvertFirstCornerPoint.X());
CornerPoint1.SetY(ConvertLastCornerPoint.Y());
CornerPoint1.SetZ(ConvertFirstCornerPoint.Z());

CornerPoint2.SetX(ConvertLastCornerPoint.X());
CornerPoint2.SetY(ConvertFirstCornerPoint.Y());
CornerPoint2.SetZ(ConvertLastCornerPoint.Z());
}
else
{
CornerPoint1.SetX(ConvertLastCornerPoint.X());
CornerPoint1.SetY(ConvertFirstCornerPoint.Y());
CornerPoint1.SetZ(ConvertLastCornerPoint.Z());

CornerPoint2.SetX(ConvertFirstCornerPoint.X());
CornerPoint2.SetY(ConvertLastCornerPoint.Y());
CornerPoint2.SetZ(ConvertFirstCornerPoint.Z());
}
}
else if(ConvertFirstCornerPoint.Y() == ConvertLastCornerPoint.Y())
{
if(ConvertFirstCornerPoint.Z() {
CornerPoint1.SetX(ConvertFirstCornerPoint.X());
CornerPoint1.SetY(ConvertFirstCornerPoint.Y());
CornerPoint1.SetZ(ConvertLastCornerPoint.Z());

CornerPoint2.SetX(ConvertLastCornerPoint.X());
CornerPoint2.SetY(ConvertLastCornerPoint.Y());
CornerPoint2.SetZ(ConvertFirstCornerPoint.Z());
}
else
{
CornerPoint1.SetX(ConvertLastCornerPoint.X());
CornerPoint1.SetY(ConvertLastCornerPoint.Y());
CornerPoint1.SetZ(ConvertFirstCornerPoint.Z());

CornerPoint2.SetX(ConvertFirstCornerPoint.X());
CornerPoint2.SetY(ConvertFirstCornerPoint.Y());
CornerPoint2.SetZ(ConvertLastCornerPoint.Z());
}
}
else
{
if(ConvertFirstCornerPoint.Z() {
CornerPoint1.SetX(ConvertFirstCornerPoint.X());
CornerPoint1.SetY(ConvertFirstCornerPoint.Y());
CornerPoint1.SetZ(ConvertLastCornerPoint.Z());

CornerPoint2.SetX(ConvertLastCornerPoint.X());
CornerPoint2.SetY(ConvertLastCornerPoint.Y());
CornerPoint2.SetZ(ConvertFirstCornerPoint.Z());
}
else
{
CornerPoint1.SetX(ConvertFirstCornerPoint.X());
CornerPoint1.SetY(ConvertFirstCornerPoint.Y());
CornerPoint1.SetZ(ConvertLastCornerPoint.Z());

CornerPoint2.SetX(ConvertLastCornerPoint.X());
CornerPoint2.SetY(ConvertLastCornerPoint.Y());
CornerPoint2.SetZ(ConvertFirstCornerPoint.Z());
}
}

}

Handle(Geom_Curve) Curve1 = GC_MakeSegment(ConvertFirstCornerPoint,CornerPoint1).Value();
DisplayCurve(aDoc, Curve1, Quantity_NOC_GREEN, true);

Handle(Geom_Curve) Curve2 = GC_MakeSegment(CornerPoint1,ConvertLastCornerPoint).Value();
DisplayCurve(aDoc, Curve2, Quantity_NOC_GREEN, true);

Handle(Geom_Curve) Curve3 = GC_MakeSegment(ConvertLastCornerPoint,CornerPoint2).Value();
DisplayCurve(aDoc, Curve3, Quantity_NOC_GREEN, true);

Handle(Geom_Curve) Curve4 = GC_MakeSegment(CornerPoint2,ConvertFirstCornerPoint).Value();
DisplayCurve(aDoc, Curve4, Quantity_NOC_GREEN, true);

PostProcess(aDoc,ID_GEOMETRY_RECTANGLE,TheDisplayType/*0.02*/);
}
}

as you know, It only operate in XYZ Global Coordinate. that's mean it can draw the rectangle in xy plane or yz plane or zx plane. But i want to make a rectangle in general plane which location is normal to screen. Of course, It's not efficient i think. But I hope to make!!

NormalToPlaneDirection = ((CASCENTView*)((((CMainFrame*)AfxGetMainWnd())->GetActiveFrame())->GetActiveView()))->NormalToScreen();

upper code is to get the normal direction to screen. In principal, I use EYE() and AT() function.

Would you help me please?

Venugopal Gudimetla's picture

Hi yeon cheol,
pl see:
http://www.opencascade.org/org/forum/thread_16206/

and kindly post your findings of me and others if it works.

Thanks,
V

yeon cheol Kang's picture

thanks to reply !!!

Although I don't work it yet, very thanks!!. Maybe i can solve this problem, Practically, it's very important to make a plane.

thanks you!!

PS) Today, I find another problem, Could you help me? My problem is ZBufferTriedronSetup.

It's work fine whether i don't use Pan function, But If i Pan the workspace, Trihedron orientation is Moving!!..

why does it happen??

Yeon cheol

Venugopal Gudimetla's picture

This is what I did:

say I have a arbitrary plane and I want to draw on it. I first made it as a privileged plane and then I set View project on to it, then I get a plane pointing in a direction normal to the screen for example:
gp_Pnt P(gp::Origin());
gp_Pnt P2(1.0,0.0,0.0);
gp_Vec V(P, P2);
gp_Dir aDir(V);
gp_Pln aPlane(P, aDir);
gp_Ax3 ax3(gp::Origin(), aDir);
controller->getViewer()->SetPrivilegedPlane(ax3);
controller->getView()->SetProj(aDir.X(), aDir.Y(), aDir.Z());

Venu

Venugopal Gudimetla's picture

Regarding your ZBuffer Trihedron see this:
http://www.opencascade.org/org/forum/thread_17021/

yeon cheol Kang's picture

Hi Venu!!

Always, thanks you!!. I download the linked file in opensources. Roman says, "see the fix235". So i try to find it. But there is not in there. There are other folders like fix 225, 230,.... etc.

I have a worry about resetting the OCC, Because It's really hard work to me. So if you solve this problem, Plz explain more details?? I'm sorry that always i recived your help.

Have a nice day~

Venugopal Gudimetla's picture

I guess you will just need ros/src/OpenGl/OpenGl_triedron.c which you can get from the patch directory mentioned by Roman or Dolbey. What you can do is get the tar ball, untar it in some tmp directory then :
i. back up your old OpenGl_triedron.c
ii. copy the file from the tar ball you got from sourceforge
iii. build
iv. install

There won't have a problem as many are using that patch, but in case you want to be careful, you can always revert back to your back up OpenGl_triedron.c.
Hope it helps.

V

yeon cheol Kang's picture

Hi venu~

I'm sorry i can't understand a install meaning;

i get the OpenGl_Triedron.c and copy to ros/scr/OpenGl/ . Of course i back up original file. and then i go to ros\adm\win43\vc8 and recompile Visualization project.

But Same as before. I'm really sorry.

what can i do to solve this?

Yeon cheol

Venugopal Gudimetla's picture

Hi Yeon Cheol,

I use Linux so I use make install to copy the built libraries back in lib directory. I am not well versed with Windows, but you need to do something similar to copy the linked visualization library to library folder, till then you won't see a change. Also diff the source file against your old source file to make sure you indeed have an modified file. And also please check the time stamp of the library after it is built to make sure your library indeed is the latest one before you copy to the library folder.

V

yeon cheol Kang's picture

HI venu!

always, i thanks your kinds. As your mention, I try to catch the bug. First, I check the date which TKOpenGl.lib is renew. it's no problem. date is today. In windows system, OCC offer the directories of library. So I don't need to change the folder of library. just In Visual studio, I linked and add it.

But It doesn't work for me. maybe I have a mistake somewhere. But i can't find it because of my shallow knowledge about Computing. somedays, i sure that find it.

Venu! may i have a question? How do you study OCC? many peoples say " i just reference the forum" or " i read the document offered in OCC" . Of course, Before the question, I try to find solution in forum and document. But sometimes It's very difficult to interpret the document. These days, I work making the source for selecting object. In document, there are many roots about selecting concept, like owner SensitiveEntity.

I read this.

if you have plenty of time, please explain about methodology more detail for me?
if you do it, like example, I pleasure and thank you

have a nice day~

YC

Venugopal Gudimetla's picture

Hi yeon cheol,

OCC is very vast, you cant read it or master it in a day. I too am learning and have many miles go and I am not good at it myself. But drops make an ocean. I am writing a CAD application, so the only way is to try writing code the hard way, when things don't work look for examples, most of the examples are already done in mfc. Sometimes those examples are not enough when you want to customize functionality, other times, you extrapolate from an example for your needs. It's very difficult to learn by one self. If you are working for an organization which uses OCC, then perhaps the better way is to register for e-learning which is costly if you want to do it yourself so ask your organization to sponsor you. Else the other way is to write code yourself and learn the hard way, there is no other way unfortunately because as you said, there is no documentation or theory available to explain. mfc examples serve the job mostly.
Good Luck.
Venu

yeon cheol Kang's picture

hi Venu!!

thanks to reply. It's too fast :-)

if you hate to be my friend, i hope to be your friend. If You use a messenger, would you tell me ? i hope to enroll your ID.

have a nice day

yeon cheol Kang's picture

if you hate -> if you don't hate

it's my mistake sorry.

yeon cheol