:NET wrapper for open cascade

Hello,
wouldn't it be nice to have .NET wrapper classes for all open cascade classes which are type safe and throw exceptions, so you could use open cascade from your native .NET application without caring how to access open cascade methods.
We have it! We wrote an automatic class wrapper, that analyses the cdl files and generates wrapper classes that use PInvoke to call to the open cascade dlls.
If you are interested let us know
development@sofa.de

Gerhard

Gerhard Hofmann's picture

Hello,

quite a few people asked me about a sample source code. So I put a link here to the MakeBottle sample from the tutorial "May First Application". http://www.sofa.de/OCasDotNet/Bottle.htm
Feel free to ask more or discuss this approach here in the Forum.
Thank You
Gerhard

Stephen Leary's picture

How do you cast from a Shape to a specific type with your wrapper?

In C++ i would cast when iterating like

TopoDS_Wire newWire = TopoDS::Wire(shapeIterator.Value());

but i cant find an equivalent in the c# wrapper.. A straight cast fails.

Cheers,

Stephen

Gerhard Hofmann's picture

sorry, I didn't get notified on this message

use TopoDS.General.Wire(shapeIterator.Value());

The problem with .NET here was, that a namespace (like TopoDS) cannot have static methods. You always need a class for static methods, so we introduced the class "General" to contain the static methods of a namespace.

best regards
Gerhard

Rene's picture

Hi Gerhard!

I have some questions regarding your approach:

1. Why do you use the cdl files and not the headers? Which information do you gain from the cdl files that the headers do not contain? Using the header files would be a more general solution cause not only opencascade but also other c++-libraries could be wrapped.

2. How do you handle const correctness? Many opencascade methods return const references. Having the same wrapper for const and non-const references would fail because changing a const reference (e.g. by a const cast) is error-prone.

3. Do you regard the inheritance hierarchy? So, can one use a TopoDS.Face where a TopoDS.Shape is expected, e.g.?

Thanks in advance
Rene

Gerhard Hofmann's picture

Hi Rene,
1. maybe it would have been better to use the header files, but cdl files seemed to be more easy to parse. And they contain a little more information:
- the "out" parameters avoid instantiating an object to pass as a parameter which would be overridden anyhow.
- the "like me" attribute tells more about the returned type
- we would like to add the comments in the cdl files as "intellisense" comments to .NET (but didn't implement it yet)
To me it looks like the header files are generated from the cdl files...

2. There is no const in CSharp (and in .NET?) Do you have an example (package, class, method), I would like to check it.

3. Yes, we use the "IsKind" Method or where not appropriate dynamic_cast to create the correct type of object. The .NET objects have the same class hierarchy as the OpenCascade objects. Since TopoDS.Face is derived from TopoDS.Shape, you can pass a TopoDS.Face where a TopoDS.Shape is expected. If a method returns a TopoDS.Shape, you can use the CSharp operator "is" or "as" to perform a type check or a type converion.

Gerhard

Roman Lygin's picture

Gerhard,

This is a great project, imho. So, why don't you post it among Open Source projects (unless it's open source and/or freely available) - http://www.opencascade.org/org/community/ ?

Roman

Gerhard Hofmann's picture

Hi Roman,

yes, we think about it, but first we wanted to see, wether anybody is interested in it.

BUT, it is not finished yet, a few problems have to be solved:
- right now, we only import about 20% of the packages, the DLL would become to big, so we will have to split it.
- the performance in respect to speed has to be improved.

AND, because it was a lot of work and there is still some work ahead to be done, we would like to take some money, if it is used commercially.

best regadrs
Gerhard

Jonathan Hill's picture

Hi,

I have a set of C# wrapper classes (but not using P/Invoke) which would allow to load in IGES or STEP file and add shapes etc. in .NET using VS 2005.

Jonathan

Paola's picture

Hi,
I'm trying to load step file and convert it into another format. I'm using VS 2005.
Can you show me your c# wrapper?
Thanks,
Paola

Gerhard Hofmann's picture

Hello Paola,

we have a wrapper for csharp. Just go ahead to our homepage http://www.sofa.de select CADabilitydotNET in the bottom line and the click "Demo Version". You will have to enter a name and email address and the you will get a Windows installation file.
Just install it although you only need two dlls. The installation also updates the environment variables and expands the "Path" variable to point to the directory where you installed the software.
Now there are two dlls that you need:
"opencascade.dll" is a .NET dll that you should reference from your project. In the object browser you will see hundreds of classes that are imported from this dll and that will look familiar to you when you are familiar with open cascade.
"OCasToCSharp.dll" is a C dll, that makes the connection to the original open cascade dlls. i.e. "opencascade.dll" calls into"OCasToCSharp.dll" via platform invoke, and "OCasToCSharp.dll" calls the original open cascade dlls.
The installation also includes the original open cascade dlls (Version 5.2!).

There is also a little demo myCADapp.exe which has the possibility to import step files (Bearbeiten -> Importieren -> STEP) which is implemented with the open cascade wrapper.

If you have any questions, feel free to ask.

best regards
Gerhard

Jonathan Hill's picture

Hi Paola,

I don’t release the source code; this is because it becomes a nightmare supporting all different uncontrolled versions and all questions which get fired up.

I can add any new functionally that you require to support your own development.

Regards
Jonathan Hill

Hesham Nasif's picture

Hi Jonathan
The new wrapper for opencascade 6.1 not ready yet. Good luck and it seems that you are doing great job

Hesham Nasif's picture

Dear Gerhard
I have one problem when i am writing the gc classes. The problem is as follows, I can not define two classes to each other, it gives me error 2460
I am trying as follows
in the Trsf.h file writing that
Trsf(Trsf2d* T)
{
}
and in Trsf2d.h file i am writing
Trsf2d(Trsf* T)
{
}

so this is give recursive class error
Please if you have a suggestion i would appriciate that

Hesham Nasif's picture

Dear Jonathan
I have wrote a net wrapper i use very nice on the machine where OCC had been installed, i would like to deployed to other machine without OCC, can you tell me the best way to do that
Thanks
Hesham

Hesham Nasif's picture

Dear Jonthan
would you please offer the source code for the wrapper even a sample of it.
Would be great from you
Thanks

Hesham Nasif's picture

Dear Jonthan
would you please offer the source code for the wrapper even a sample of it.
Would be great from you
Thanks