OCC using java

Hi !

I just wanted to check if there would be any interest in a java version of OCC ? with that I mean a 100% java version, no JNI calls involved.

I am working on translating OCC to Java, and before you start complaining why...

With java you get rid of all C++ problems, porting to other compilers and so on, you also get rid of all the "smart pointers" that exists today, with java the garbage collector takes care of that, and finally, I prefer java to C++ and using OCC from java using JNI is a mess if you ask me.

It isn't as difficult as you might think, operator overloading is not used that much and there is some messing with pointers in gp_Trsf for example but nothing that cannot be handled, I have made a java application that translates most of the C++ code into java source code, it takes care of about 75-80% of the work, a little hands on is required to make it work but most of the time this is for performance reasons, you cannot convert the C++ code strait to java because it will would be pretty slow and use to much memory.

The biggest problem if of course the AIS stuff, but one possibility would be to retrofit it to use JOGL for example.

Anyway, as I said, I do this first and most for myself, but if there is any interest in it let me know, it is far from finished but I expect to have most of the gp and Geom code complete pretty soon.


nicholas_yue's picture

Hi Mikael,

That would be a very useful contribution to a lot of Java developer out there.

The JNI is a nightmare when it comes to debugging.

OCC does not use more recent technologies like Boost and other C++ standards e.g. std::string. It still have a big baggage of legacy code dating back to the early 1990s.

This makes it very time consuming to debug and step through code. There are many layers of indirection and smart-pointering shim.

It is also slow to build because it uses it's own build technology 'wok' and code generation technologies 'CDL' instead of standard Makefile or CMake.

Even though it is open source, there is no SVN repository where external developer can contribute code easily back to the main project when serious bugs are encountered.

Using JOGL is way ahead of the game, it's what I am using to prototype more advance visualization.

Will you be publishing your converter? via SVN? Does it have Junit test?

Once again, your contribution will be greatly appreciated and it is way cool.


m-aronsson's picture

Hi !

If there is any interest for it I will of course publish it, and when doing that som kind of revision support would be likley.

As I said there is lots of work to do, and all classes does not have JUnit tests at the moment, but the idea is to put that in there also, there are JUnit tests for gp_XY,gp_XYZ,gp_Vec2,gp_Vec,gp_Pnt2d,gp_Pnt,gp_Dir2d and gp_Dir at the moment and more will be added.

The JUnit tetsts are needed anyway as a lot of the code is "machine" converted so there is a big need to test that the code works as intended.

PG's picture

Hello Michael,
We are extensively using OCC with Java/Swing with JNI calls.

We are very much interested in a Java version of OCC and see
whether we can join hands in this development and how we can
help in the development process.

Please respond and best wishes.


- PG

W. M.'s picture

This would be invaluable for people that program primarily in Java. OCC in java using JNI can be painful quite and has made me abandon twice in the past.

Having a Java version would certainly bring a larger number of users onboard.

AIS in my opinion is less critical as being natively in Java. Since JOGL uses JNI calls, AIS might as well be JNI based. This might just a be my bias since my current interest lies in the Modeling Algorithms.

I would definitely be interested in working to make this conversion particularly since I will be working on this modules anyway. Could you share with us/me more specifically your development process? And what do you think about the possibility of moving the development efforts onto public domain.

m-aronsson's picture

At the moment I am working with the gp and Geom packages, I have created a small java application that converts the original C++ code into java code, it did not work out as good as I hoped, there is a little bit to much post processing needed so I have changed that into using a real C++ parser (using JavaCC) that parse the C++ code and translate it to Java code and I think this will work out much better.

Once I get the translator to work as I want it to I will give OCC (except AIS) a stab, but it will take some time until we are there.

As this is just a conversion of the orginal OCC code I guess it will have to use the same license to avoid any problems.

I have tried it on gp_XY,gp_XYZ,gp_Pnt,gp_Pnt2d,gp_Vec,gp_Vec2d,gp_Dir,gp_Dir2d,gp_Trsf2d,gp_Trsf,gp_Mat and a few other classes and so far to post processing has been minimal so it does look good.

The things that does not work to 100% at the moment is removal of & and * (should work much better with the new parser) and inserting "new" in a lot of plaaces where it is needed, there are not many places where operators are used but I think I have that covered also.

I will put it up on a website as soon as possible when I have made the new parser work as I want it to.