Friday, February 20, 2009

NaroCAD to have support for IronPython 2.0!

There was one attempt to work with IronPython in code under the path: branches/CipTests/IronPythonTests. You may find here a mini text editor that can execute simple IronPython code.

As there was a need for a command line interpreter, the code was integrated using the latest IronPython code. The C# code that integrates with IronPython seems to not be so compatible with the versions, as IPy 2.0 is based on DLR (Dynamic Language Runtime). This allows the API of IronPython 2.0 to be more generic and expose the DLR interface to work with. This means that with minimal change right now NaroCad will support in the same way any DLR capable language (like IronRuby).

What can you do right now with the IronPython integration?
- you may execute IronPython commands like this "Hello world" program:
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import *
MessageBox.Show("hello from NaroCad")
- you may: execute the lines you write, load a file from disk, or save onto a disk your hard worked program
- pressing "Enter" to any line will execute your line of program, and in case the program will misbehave the exception will be shown to the user
- you can change all the properties of the command line editor like this: panel.CommandLineEditor.ShowLineNumbers = 1; or anything that reflects the CommandLineView public members (so you can hide/show the items in real time). The way to react with NaroCad internal API is a subject of change but this is a fully working concept
- the editor use the file: commandLineHistory.py (or create a blank one if none exists), as the editor default text.

Here is the picture that values 1000 words.

7 comments:

ytjun said...

HI~~

Thanks~

I want to use "Get" Method of OCBnd_Box.
The Method receive "double *" argument

I want to update this problem
because I don't know how to.

Thank You~

Ciprian Khlud said...

Hi ytjun,

The wrappers are generated based on WOK + C++.NET code and is done automatically. For having a better interface, please submit patches. There is an attempt to rewrite the wrappers code to be C# only and is in: branches/CipTests/FastBuildWrappers SVN code.

Anyway, for now, considering that you have one project and you want to use OCWrappers in actual stage, you may do the following:
- create one project that have reference to OCWrappers
- set the UNSAFE flag (/unsafe in CSC command line, or look for unsafe in your project options)
- write the code as following:
unsafe
{
OCBnd_Box box = new OCBnd_Box();
double minx, miny, minz, maxx, maxy, maxz;
box.Get(&minx, &miny, &minz, &maxx, &maxy, &maxz);
}

In future we may use a completely managed code for that parts of code, but for now is not the first priority.

ytjun said...

thank you for your answer.

But I wonder

unsafe
{
OCBnd_Box box = new OCBnd_Box();
double minx, miny, minz, maxx, maxy, maxz;
double* a = &minx; -> success
box.Get(&minx, &miny, &minz, &maxx, &maxy, &maxz); -> Fail
}

Do you know how to do?
Help me~ Please

Ciprian Khlud said...

Hi ytjun,

I hope you have OpenCascade installed in your machine.
If NaroCad starts, it means that both OpenCascade and wrappers works. If yes, you should have in your OpenCascade folder a directory named: ros (which points your environment variable: $CASROOT).

In ros/src/Bnd/Bnd_Box.cdl (open it with notepad) you should find how Bnd_Box class works: you will start creating one and you add geometry and the bounding box it will enlarge).

Some useful functions are: Update(double x, double y, double z),
a lot of Add methods: Add(OCBnd_Box other), Add(OCgp_Pnt P, OCgp_Dir D), etc.

The most probably reason that your call to get it fails is that your bounding box is infinite (as is not bounded to any geometry!) and you have functions to check it's validity like bool IsWhole() - returns true if bounding box is infinite, and IsVoid: returns true if bounding box is empty.

I'm not sure how much it answer your question, but for me it not seem an issue on wrappers, is about Bnd_Box specifics.

Regards,
Ciprian

Ciprian Khlud said...

Based on my last comment, I've wrote one code that do seems what you are looking for.

If you comment the box.Update line, the code will not enter in the code that crash (inside opencascade as the Bnd_Box is not initialized!).

I hope it covers what you need from it:

unsafe {
OCBnd_Box box = new OCBnd_Box();
box.Update(2,2,2,4,4,4);
double minx, miny, minz, maxx, maxy, maxz;
if(!box.IsVoid())
{
box.Get(&minx, &miny, &minz, &maxx, &maxy, &maxz);
} //if
} //unsafe

ytjun said...

Thank You~~

I don't initialize OCBnd_Box object.
Thank you for your kindness.


I have another problem.
I use many times "OCBRepAlgoAPI_Common".
so I want to use "using"
using (OCBRepAlgoAPI_Common tAlgoAPICommon = new OCBRepAlgoAPI_Common(tTopoBndBox, tPartTopoShape))
{ OCTopoDS_Shape tCommonTopoShape = tAlgoAPICommon.Shape();
}
-> """ERROR"""

Do you know how to do?

Ciprian Khlud said...

Hi ytjun,

You wasn't so clear about your error. I used to work full time in my daily life so I cannot reproduce any problem. The same is about Mihai.

Anyway I may say how we do it in NaroCad source-code about long constructions. We use the "var" keyword that is possible to be used in C# 3.0.
Your code may become:
var tAlgoAPICommon = new OCBRepAlgoAPI_Common(tTopoBndBox, tPartTopoShape);
var tCommonTopoShape = tAlgoAPICommon.Shape();

And it will make both a clean code and the compiler will detect your right type.

Hope it helps,
Ciprian