Has FreeCAD implemented all of interfaces of OCCT?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
JOE_FU
Posts: 79
Joined: Fri Jan 11, 2019 8:41 am

Has FreeCAD implemented all of interfaces of OCCT?

Post by JOE_FU »

I ever seen that FreeCAD can build a box withBRepPrimAPI_makebox(length,width,height,[pnt,dir]).However, In the API of OCCT, there are so many other methods to create a box,for example create a box with BRepPrimAPI_MakeBox (const gp_Pnt &P1, const gp_Pnt &P2). How can I extend this function in FreeCAD?
User avatar
wandererfan
Veteran
Posts: 6317
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Has FreeCAD implemented all of interfaces of OCCT?

Post by wandererfan »

JOE_FU wrote: Sat Jan 12, 2019 7:25 am I ever seen that FreeCAD can build a box withBRepPrimAPI_makebox(length,width,height,[pnt,dir]).However, In the API of OCCT, there are so many other methods to create a box,for example create a box with BRepPrimAPI_MakeBox (const gp_Pnt &P1, const gp_Pnt &P2). How can I extend this function in FreeCAD?
Function makeBox() in Part module file App/AppPartPy.cpp implements the Python function Part.makeBox().

You could add support for different signatures by adding adding new "PyArg_ParseTuple" tests and logic. See makeRevolution() in the same file for an example of using multiple signatures.
JOE_FU
Posts: 79
Joined: Fri Jan 11, 2019 8:41 am

Re: Has FreeCAD implemented all of interfaces of OCCT?

Post by JOE_FU »

wandererfan wrote: Sat Jan 12, 2019 1:49 pm
JOE_FU wrote: Sat Jan 12, 2019 7:25 am I ever seen that FreeCAD can build a box withBRepPrimAPI_makebox(length,width,height,[pnt,dir]).However, In the API of OCCT, there are so many other methods to create a box,for example create a box with BRepPrimAPI_MakeBox (const gp_Pnt &P1, const gp_Pnt &P2). How can I extend this function in FreeCAD?
Function makeBox() in Part module file App/AppPartPy.cpp implements the Python function Part.makeBox().

You could add support for different signatures by adding adding new "PyArg_ParseTuple" tests and logic. See makeRevolution() in the same file for an example of using multiple signatures.

First, Thanks for your reply. Second, there are also two questions I want to pose:
If I want to use a variety of methods of a function, do I need to first determine the parameter type in the makeBox function? and then perform different methods according to different parameter types. Another problem is that when I customize a new make method in AppPartPy.cpp, such as makeMyShape, and add a new method in the add_varargs_mothod method above, but after compiling, there is an error message, suggesting that I have no definition.

Code: Select all

	add_varargs_method("makeMyBox", &Module::makeMyShape,
			"makeMyBox(length,width,height,[pnt,dir]) -- Make a My define box located\n"
			"in pnt with the dimensions (length,width,height)\n"
			"By default pnt=Vector(0,0,0) and dir=Vector(0,0,1)"
			);
			
			
	Py::Object makeMyBox(const Py::Tuple& args)
	
error: "makeMyShape" Undefined identifier
error: "makeMyShape" is not the member of "Part::Moudle"



Thanks for your help.
User avatar
wandererfan
Veteran
Posts: 6317
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Has FreeCAD implemented all of interfaces of OCCT?

Post by wandererfan »

JOE_FU wrote: Mon Jan 14, 2019 7:27 am If I want to use a variety of methods of a function, do I need to first determine the parameter type in the makeBox function? and then perform different methods according to different parameter types.
Usually it is done like this:

Code: Select all

    Py::Object makeMyShape(const Py::Tuple& args)
    {
        ...
        if (PyArg_ParseTuple(args.ptr(), "O!|dddO!O!O!", &(GeometryPy::Type), &pCrv,
                                                   &vmin, &vmax, &angle,
                                                   &(Base::VectorPy::Type), &pPnt,
                                                   &(Base::VectorPy::Type), &pDir,
                                                   &(PyType_Type), &type)) {
            //do stuff unique to this signature
            ...
        } else if (PyArg_ParseTuple(args.ptr(), "O!O!", &(GeometryPy::Type), &myParm1,
                                                   &myParm2) {
            //do stuff unique to this signature
            ...
        } else {
            // error, unsupported signature
        }
        //do stuff common to all signatures
        ...
JOE_FU wrote: Mon Jan 14, 2019 7:27 am Another problem is that when I customize a new make method in AppPartPy.cpp, such as makeMyShape, and add a new method in the add_varargs_mothod method above, but after compiling, there is an error message, suggesting that I have no definition.
You have: add_varargs_method("makeMyBox", &Module::makeMyShape,
but it should be: add_varargs_method("makeMyShape", &Module::makeMyShape,
JOE_FU
Posts: 79
Joined: Fri Jan 11, 2019 8:41 am

Re: Has FreeCAD implemented all of interfaces of OCCT?

Post by JOE_FU »

wandererfan wrote: Mon Jan 14, 2019 2:08 pm
JOE_FU wrote: Mon Jan 14, 2019 7:27 am If I want to use a variety of methods of a function, do I need to first determine the parameter type in the makeBox function? and then perform different methods according to different parameter types.
Usually it is done like this:

Code: Select all

    Py::Object makeMyShape(const Py::Tuple& args)
    {
        ...
        if (PyArg_ParseTuple(args.ptr(), "O!|dddO!O!O!", &(GeometryPy::Type), &pCrv,
                                                   &vmin, &vmax, &angle,
                                                   &(Base::VectorPy::Type), &pPnt,
                                                   &(Base::VectorPy::Type), &pDir,
                                                   &(PyType_Type), &type)) {
            //do stuff unique to this signature
            ...
        } else if (PyArg_ParseTuple(args.ptr(), "O!O!", &(GeometryPy::Type), &myParm1,
                                                   &myParm2) {
            //do stuff unique to this signature
            ...
        } else {
            // error, unsupported signature
        }
        //do stuff common to all signatures
        ...
JOE_FU wrote: Mon Jan 14, 2019 7:27 am Another problem is that when I customize a new make method in AppPartPy.cpp, such as makeMyShape, and add a new method in the add_varargs_mothod method above, but after compiling, there is an error message, suggesting that I have no definition.
You have: add_varargs_method("makeMyBox", &Module::makeMyShape,
but it should be: add_varargs_method("makeMyShape", &Module::makeMyShape,
Image


Thanks for your reply.
I am so sorry that I wrote the code wrongly.
My code is as follows:

Code: Select all

	//AppPartPy.cpp
	/*test*/
	...
	add_varargs_method("makeMyShape", &Module::makeMyShape,
			"makeMyBox(length,width,height,[pnt,dir]) -- Make a My define box located\n"
			"in pnt with the dimensions (length,width,height)\n"
			"By default pnt=Vector(0,0,0) and dir=Vector(0,0,1)"
			);
	...
	...
	Py::Object makeMyShape(const Py::Tuple& args)
	{
		throw Py::ValueError("delta x2 of wedge is negative");
	}
	...
I have written it like above,but it is wrong when I compiled it with Visual Studio 2013.
The error was the same as that I mentioned earlier.

Code: Select all

	Error 48 error C2065: "makeMyShape": Undeclared identifier D:\FreeCAD0.16\FreeCAD-0.16\src\Mod\Part\App\AppPartPy.cpp
	Error 47 error C2039: "makeMyShape": Not a member of "Part::Module" D:\FreeCAD0.16\FreeCAD-0.16\src\Mod\Part\App\AppPartPy.cpp
I didn't know how to solve this problem. I hope you can help me . I am looking forward for your reply.
User avatar
wandererfan
Veteran
Posts: 6317
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Has FreeCAD implemented all of interfaces of OCCT?

Post by wandererfan »

JOE_FU wrote: Tue Jan 15, 2019 11:02 am I have written it like above,but it is wrong when I compiled it with Visual Studio 2013.
The error was the same as that I mentioned earlier.
Are you trying to compile v0.16? That is a very old version, there are people developing v0.19 now.

I don't use Windows, but your code compiles and runs

Code: Select all

>>> import Part
>>> Part.makeMyShape()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: delta x2 of wedge is negative
>>> 
in this environment:
OS: Linux Mint 19 Tara
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15611 +1 (Git)
Build type: debug
Branch: dToolsv2
Hash: bc6a299ef9587cdec37e375143d91f54df9bfe9c
Python version: 2.7.15rc1
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/Canada (en_CA)

Maybe one of the Windows developers has a clue?
JOE_FU
Posts: 79
Joined: Fri Jan 11, 2019 8:41 am

Re: Has FreeCAD implemented all of interfaces of OCCT?

Post by JOE_FU »

wandererfan wrote: Tue Jan 15, 2019 1:14 pm
JOE_FU wrote: Tue Jan 15, 2019 11:02 am I have written it like above,but it is wrong when I compiled it with Visual Studio 2013.
The error was the same as that I mentioned earlier.
Are you trying to compile v0.16? That is a very old version, there are people developing v0.19 now.

I don't use Windows, but your code compiles and runs

Code: Select all

>>> import Part
>>> Part.makeMyShape()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ValueError: delta x2 of wedge is negative
>>> 
in this environment:
OS: Linux Mint 19 Tara
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15611 +1 (Git)
Build type: debug
Branch: dToolsv2
Hash: bc6a299ef9587cdec37e375143d91f54df9bfe9c
Python version: 2.7.15rc1
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: English/Canada (en_CA)

Maybe one of the Windows developers has a clue?

OK,Thank you very much. Maybe this is a version issue or a operating system issue.
I am going to try other more advanced versions.
Post Reply