VS 2005 - C# - open cascade and windows forms app example

Hello!
Im a student and i`m trying to create Windows form application in c# which is using open cascade lib. but i can`t handle with that. Have anybody some example of similar application ? Please help me !

Pawel's picture

Hi Kamil,

there is a c# example shipped with the OCC distribution. Have you checked that?

Pawel

klejor's picture

yes i did, but there is a lot of source code and it doesnt work`s correctly. It is compiling but return some exceptions. I`m using VS 2005 and 2008

devast's picture

i've managed to run c# sample, though it was not easy.. first i fused shell project into occ project, then copied all OCC dlls to debug directory and only then it worked... and dont forget to set path to tkopengl.dll

Tatva85's picture

Hi,

I want to user OCC and shell projects that are available in C# sample ...how can I do that.

basically I want to use OCC and shell project in my current C# project, I tried lot but no luck to get it work..please help me...

Thanks

Pawel's picture

Hi Kamil,

I would suggest searching the forum. There have already been some posts dealing with running the sample.

Pawel

marek99's picture

Kamil you can use narocadwrapper. When You are creating project in VS you just need to add dll to referencees of your project. Then you have most of functions of OCC

klejor's picture

yes, i did it and everything works fine :)

berenr's picture

Hi! I'm a student and i'm trying to develop a C# application.
Can someone write a very very little tutorial for embed and use narocad wrapper? [in visual studio or in SharpDevelop]

marek99's picture

If you installed OCC you have folder \OpenCascade\win32\samples\standard\c#\IE. In the folder you have sample project with 3d view written in c# and c++. It contains its own wrapper but narocadwrapper is better. You create new project of dll library with class viewer thats inherits after UserControl class, this is your 3d viewer control. After you finish you are adding your control to Tool Box of VS2005 ("Tool>>Choose Tool Box Items" in .NET Framework components you are clicking Browse then you are choosing location of your dll with control inside). Now last thing is to drag you control on window.

berenr's picture

Thanks!!

mihaizn's picture

Hi,

If you download the NaroCad project there are two simple projects in the trunk\wrappers\tests\. One of them is the MakeBottle sample ported to these wrappers.
Another complete and fully working visual project that you might use for start is located on branches\newtestproject\OpenCascadeResearch\.

Mihai

berenr's picture

ok, I have embed the view user control!
The MakeBottle example is very complex and I need only to draw lines, circles and write some text.
How I can do it? I have only to add simple entities to my draw. Could anyone help me?

berenr's picture

For example:

using System;
using System.Windows.Forms;
using OCNaroWrappers;

namespace test
{
public partial class MainForm : Form
{
private ViewUserControl control;

public MainForm()
{
InitializeComponent();

control = new ViewUserControl();
control.Dock = DockStyle.Fill;
this.Controls.Add(control);

double x1 = 0; double x2 = 10; double y1 = 0; double y2 = 10;

OCgp_Pnt aPnt1 = new OCgp_Pnt(x1,y1,0);
OCgp_Pnt aPnt2 = new OCgp_Pnt(x2,y2,0);

OCGC_MakeSegment makeSegment1 = new OCGC_MakeSegment(aPnt1, aPnt2);

// What I have to write for add this segment??

control.ZoomAll();
}
}
}

ciplogic's picture

Hi,

I think you have two problems here:
- create a window that embeds OCC view
- 2nd: add to context your shape

About the first one, the code that NaroCAD uses for this may be found here: http://narocad.svn.sourceforge.net/viewvc/narocad/trunk/narocad/Source/P...

About adding your shape to OCC context, the code may be the following:
OCTopoDS_Shape shape = makeSegment1.Shape();
OCAIS_Shape interactive = new OCAIS_Shape(shape);
context.Display(interactive, true);

So all you need is to obtain the TopoDS_Shape and to add it to OCC context.

Bests,
Ciprian

berenr's picture

Thanks! I have done! But this command:

OCTopoDS_Shape shape = makeSegment1.Shape();

give to me this error:
'OCNaroWrappers.OCGC_MakeSegment' does not contain a definition for 'Shape' etc. etc...

What's happening?

marek99's picture

OCGC_MakeSegment::Value() returns OCGeom_TrimmedCurve object type.

OCGeom_TrimmedCurve trimCurve = makeSegment1.Value();
OCBRepBuilderAPI_MakeEdge edgeMaker = new OCBRepBuilderAPI_MakeEdge(trimCurve);
OCTopoDS_Shape shape = edgeMaker.Shape();
OCAIS_Shape interactive = new OCAIS_Shape(shape);
context.Display(interactive, true);

berenr's picture

Thanks! It's perfect!

But, where I can found more information about these procedures?
I wouldn't want to ask for every single entity that I have to draw!

Thanks a lot and sorry for my English!

ciplogic's picture

The procedures are documented based on OpenCascade documentations and headers. The NaroCAD project only provide (fairly complete but still partial) wrappers. So if you have an OpenCascade code, you can convert the code mostly by writing: using OCNaroWrappers; and put OC before every OpenCascade class.

So if your code is like this:
gp_Pnt a (10, 20, 10);
the C# code will be:
OCgp_Pnt a = new OCgp_Pnt(10, 20, 10);

In rest the code follows the OpenCascade "look and feel".

berenr's picture

Thanks! I added new shapes and I changed the colors!
I still need help for two things:
Add TEXT and
add a control for the user interaction such as Zoom and Pan: (at least for the Window Zoom).

If anyone can help me, I would be very grateful.

qui's picture

hi, for Pan there is no problem
add to your project the events onMouseDown and onMouseMouve
for the event onMouseDown store the e.X and the e.Y in tow different variables (Lx and Ly)
{
Lx = e.X;
Lx = e.Y;
}

now for the event onMouseMouve use this

{
view.Zoom(Lx,Lx, e.X, e.Y);
Lx = e.X;
Lx = e.Y;
}

It works perfectly, so i have also the problem of displaying text, so if you found the solution please contact me
Futate2001@yahoo.fr

qui's picture

sorry, i was talking of Zoom
For pan use the folowing function onMouseMouve

{
Lx = e.X;
Ly = e.Y;
View.Pan(e.X-Lx, Ly- e.Y,1)
}

sorry for the mistake, So the problem persists for displaying text
good luck