Has FreeCAD implemented all of interfaces of OCCT?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Has FreeCAD implemented all of interfaces of OCCT?
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?
- wandererfan
- Veteran
- Posts: 6321
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Has FreeCAD implemented all of interfaces of OCCT?
Function makeBox() in Part module file App/AppPartPy.cpp implements the Python function Part.makeBox().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?
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.
Re: Has FreeCAD implemented all of interfaces of OCCT?
wandererfan wrote: ↑Sat Jan 12, 2019 1:49 pmFunction makeBox() in Part module file App/AppPartPy.cpp implements the Python function Part.makeBox().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?
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" is not the member of "Part::Moudle"
Thanks for your help.
- wandererfan
- Veteran
- Posts: 6321
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Has FreeCAD implemented all of interfaces of OCCT?
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
...
You have: add_varargs_method("makeMyBox", &Module::makeMyShape,
but it should be: add_varargs_method("makeMyShape", &Module::makeMyShape,
Re: Has FreeCAD implemented all of interfaces of OCCT?
wandererfan wrote: ↑Mon Jan 14, 2019 2:08 pmUsually 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 ...
You have: add_varargs_method("makeMyBox", &Module::makeMyShape,
but it should be: add_varargs_method("makeMyShape", &Module::makeMyShape,
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");
}
...
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
- wandererfan
- Veteran
- Posts: 6321
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Has FreeCAD implemented all of interfaces of OCCT?
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
>>>
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?
Re: Has FreeCAD implemented all of interfaces of OCCT?
wandererfan wrote: ↑Tue Jan 15, 2019 1:14 pmAre 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 runsin this environment: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 >>>
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.