Very simple line displaying example in MFC C++

Dear sirs/mam,
I am starting opencascade. I couldnot understand the big projects on sample and found on the net. I just want to start from displaying line or point. For this please help me proper header and simple settings and codes needed.
thank you.

Thomas Paviot's picture

Hi,

I agree that it's quite hard to get started with OpenCASCADE. Here is the smallest sample I can provide to draw a vertex (python code):

# Simple Vertex program
from OCC.Display.SimpleGui import display, start_display
from OCC.gp import *
from OCC.BRepBuilderAPI import *
V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20,10,-30))
display.DisplayShape(V1.Vertex())
start_display()

And, for an edge:
# Simple Edge draw
from OCC.Display.SimpleGui import display, start_display
from OCC.gp import *
from OCC.BRepBuilderAPI import *
line = gp_Lin(gp_Ax1(gp_Pnt(10,10,10),gp_Dir(1,0,0)))
edge = BRepBuilderAPI_MakeEdge(line,-20,10)
display.DisplayShape(edge.Edge())
start_display()

Code extracted from the topology_building pythonOCC sample: http://svn.gna.org/viewcvs/pythonocc/trunk/src/samples/Level1/TopologyBu...

Best Regards,

Thomas

samscore's picture

firstly, you have to set up Visual Studio so that you could compile the mfc samples. I think you need the mfcsample.lib to compile the other examples... if you have problems with this, post it here.

then you should read the tutorial.pdf file in the "doc" folder.

you can take for example the topologyPrimitives project an try something. Here an example which display a vertex and a line if you click the "Box" button. there a interesting things coded in the examples.

but the best:
http://opencascade.blogspot.com/2009/02/topology-and-geometry-in-open-ca...

good luck

Regards
Simon

The example:

void CTopologyPrimitivesDoc::OnBox()
{
//remove old items
AIS_ListOfInteractive aList;
myAISContext->DisplayedObjects(aList);
AIS_ListIteratorOfListOfInteractive aListIterator;
for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
myAISContext->Remove(aListIterator.Value());
}

//make a point
gp_Pnt point1(100,50,10);

//make a vertex from the point
TopoDS_Vertex vertex1 = BRepBuilderAPI_MakeVertex(point1);

//make one more point
gp_Pnt point2(200,150,0);

//make an edge from the two points
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(point1,point2);

//display the vertex
Handle(AIS_Shape) aisBody1 = new AIS_Shape(vertex1);
myAISContext->SetColor(aisBody1,Quantity_NOC_LAVENDER,Standard_False);
myAISContext->SetMaterial(aisBody1,Graphic3d_NOM_PLASTIC,Standard_False);
myAISContext->Display(aisBody1,Standard_False);

//display the edge
Handle(AIS_Shape) aisBody2 = new AIS_Shape(edge1);
myAISContext->SetColor(aisBody2,Quantity_NOC_BLUE4,Standard_False);
myAISContext->SetMaterial(aisBody2,Graphic3d_NOM_PLASTIC,Standard_False);
myAISContext->Display(aisBody2,Standard_False);

//Zoom to the extend
Fit();
}

Rajendra's picture

Thank you for the replies.
Now I am proceding with the box tutorial.
I am trying hard. I will inform on success.
Thank you.

Rajendra's picture

Respected Simon,
I got problem in this code:
Handle(AIS_Shape) aisBody1 = new AIS_Shape(vertex1);
I got error as 'Standard_Transient::operator new': There is no function loaded over with three arguments.
I have defined myAISContext as in the sample project.
I would be happy if you say guide me how to display only.
Thank you very much.

samscore's picture

Hello
are you sure, that the error belongs to "Handle(AIS_Shape) aisBody1 = new AIS_Shape(vertex1);"? I think you using a construction function "new" with three arguments, but there is no such function???

Regards
Simon

Rajendra's picture

hello Respected Simon,

I knew the cause. There was
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

So now I am able to display the items.
Thank you very much for the co-operation.
have good time there!!

samscore's picture

You're welcome!
Good luck with Open Cascade.

Regards
Simon