Using MeshFeature in C++
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Using MeshFeature in C++
Hello,
When I include "Mod\Mesh\Gui\PreCompiled.h" and "Mod/Mesh/App/MeshFeature.h" to my project to use MeshFeature class, the objects in my document disappear. (C++)
Any ideas?
When I include "Mod\Mesh\Gui\PreCompiled.h" and "Mod/Mesh/App/MeshFeature.h" to my project to use MeshFeature class, the objects in my document disappear. (C++)
Any ideas?
Re: Using MeshFeature in C++
const MeshCore::MeshFacetArray& facets = mf->Mesh.getValuePtr()->getKernel().GetFacets();
when i comment out this line from my function, everything works fine. This function is not even called when the problem happens.
Any help will be appreciated.
when i comment out this line from my function, everything works fine. This function is not even called when the problem happens.
Any help will be appreciated.
Re: Using MeshFeature in C++
This is already wrong. A pre-compiled header must be included only from .cpp files of the same module. And it must not be included inside header files because it usually contains some module-specific defines and thus might break dependent modules (like yours).When I include "Mod\Mesh\Gui\PreCompiled.h" and
Without a single word about how you use the Mesh stuff or some code snippets it's impossible to say why things don't work as expected.const MeshCore::MeshFacetArray& facets = mf->Mesh.getValuePtr()->getKernel().GetFacets();
when i comment out this line from my function, everything works fine. This function is not even called when the problem happens.
Re: Using MeshFeature in C++
Thank you for your answer,
I was talking about my cpp file. SceneController.cpp in this case. I did not include anything related with FreeCAD in my header file. I only forward declared MDIView for;
I only include PreCompiled.h for MeshExport dll import definition. When I define it as;
I still encounter the same problem.
So this is my only function that I use MeshFeature;
I just want to test it to get Mesh vertices from FreeCAD mesh objects. Again, when I comment out this line everything works fine. But when I try to get facets I only see the background in my document. This function is not even called, so I thought including MeshFeature.h cause this.
Sorry for any mistakes. Thank you again.
EDIT:
Basically, how can i use MeshFeature correctly in my class? (I already add additional include directories, linked Mesh_d.lib and using Mesh_d.pyd and tried to include <Mod/Mesh/App/MeshFeature.h> in my class)
Note: I am using QT5.6.0 and PySide2
I was talking about my cpp file. SceneController.cpp in this case. I did not include anything related with FreeCAD in my header file. I only forward declared MDIView for;
Code: Select all
void onWindowStateChanged(MDIView*);
I only include PreCompiled.h for MeshExport dll import definition. When I define it as;
Code: Select all
define MeshExport __declspec(dllimport)
So this is my only function that I use MeshFeature;
Code: Select all
void SceneController::getVal()
{
App::DocumentObject* obj = App::GetApplication().getActiveDocument()->getObject("myimportedmesh");
Mesh::Feature* mf = static_cast<Mesh::Feature*>(obj);
const MeshCore::MeshFacetArray& facets = mf->Mesh.getValuePtr()->getKernel().GetFacets();
}
Code: Select all
const MeshCore::MeshFacetArray& facets = mf->Mesh.getValuePtr()->getKernel().GetFacets();
Sorry for any mistakes. Thank you again.
EDIT:
Basically, how can i use MeshFeature correctly in my class? (I already add additional include directories, linked Mesh_d.lib and using Mesh_d.pyd and tried to include <Mod/Mesh/App/MeshFeature.h> in my class)
Note: I am using QT5.6.0 and PySide2
Re: Using MeshFeature in C++
In case SceneController.cpp is part of your own module and not MeshGui you should not use the PreCompiled.h of MeshGui (in case you do this) but write your own PreCompiled.h.I only include PreCompiled.h for MeshExport dll import definition. When I define it as;
Here you have to add some security checks so that a static_cast is safe as otherwise the behaviour is undefined. When you get back the object by "getObject" you have to make sure that it's not null and that it's really of the expected type. Alternatively you can use a dynamic_cast and check if "mf" is null or not.void SceneController::getVal()
{
App::DocumentObject* obj = App::GetApplication().getActiveDocument()->getObject("myimportedmesh");
Mesh::Feature* mf = static_cast<Mesh::Feature*>(obj);
const MeshCore::MeshFacetArray& facets = mf->Mesh.getValuePtr()->getKernel().GetFacets();
}
As long as it's guaranteed that "mf" is Mesh::Feature this line is harmless and it doesn't modify the mesh data.const MeshCore::MeshFacetArray& facets = mf->Mesh.getValuePtr()->getKernel().GetFacets();
Re: Using MeshFeature in C++
Assuming your module is called "MyModule" then check the following points:EDIT:
Basically, how can i use MeshFeature correctly in my class? (I already add additional include directories, linked Mesh_d.lib and using Mesh_d.pyd and tried to include <Mod/Mesh/App/MeshFeature.h> in my class)
- Inside the CMake write something like
Code: Select all
set(MyModule_LIBS Mesh ### just write Mesh without any prefix or suffix. CMake will handle debug/release names automatically. ) ... add_library(MyModule SHARED ${MyModule_SRCS}) target_link_libraries(MyModule ${MyModule_LIBS})
- Create your own PreCompiled.h with at least this content:
and use it as very first statement in your .cpp files
Code: Select all
#ifndef __PRECOMPILED__ #define __PRECOMPILED__ #include <FCConfig.h> #ifdef FC_OS_WIN32 # define MeshExport __declspec(dllimport) #else // for Linux # define MeshExport #endif #endif
- After you can write
Code: Select all
#include <PreCompiled.h>
Code: Select all
#include <Mod/Mesh/App/MeshFeature.h>
- When accessing an object of the document make sure the object exists and that it's of the expected type.
- wandererfan
- Veteran
- Posts: 6326
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Using MeshFeature in C++
This code should be in your module's PreCompiled.h rather than including ...Mod/Mesh/App/PreCompiled.h in your cpp files.toral wrote: ↑Tue Aug 07, 2018 7:08 am I only include PreCompiled.h for MeshExport dll import definition. When I define it as;
Code: Select all
define MeshExport __declspec(dllimport)
From PartDesign/App/PreCompiled.h
Code: Select all
// Exporting of App classes
#ifdef FC_OS_WIN32
# define PartDesignExport __declspec(dllexport)
# define PartExport __declspec(dllimport)
# define MeshExport __declspec(dllimport)
#else // for Linux
# define PartDesignExport
# define PartExport
# define MeshExport
#endif
Re: Using MeshFeature in C++
Now I did exactly how you explained. Problem still occurs when I even use;
in my function. Scene dissapears even I do not call the function. When I delete this line and Clean Solution and rebuild again everything works fine.
Again, this line is not even called when problem occurs. I have no idea why this is happening. But somehow when the compiler sees this line something in FreeCAD document fails.
EDIT: Now when I try to import Part::Box to my scene it is rendered successfully. Only the meshes are failed to render.
Code: Select all
const Mesh::MeshObject* a = mf->Mesh.getValuePtr();
Again, this line is not even called when problem occurs. I have no idea why this is happening. But somehow when the compiler sees this line something in FreeCAD document fails.
EDIT: Now when I try to import Part::Box to my scene it is rendered successfully. Only the meshes are failed to render.
Re: Using MeshFeature in C++
Probably when I link Mesh_d.lib and solution use it the problem happens.
Thank you for your time.
Thank you for your time.
Re: Using MeshFeature in C++
is it possible to upload your code or if not offer a stripped down version that shows this behaviour?