Open file in plugin

Questions related to plugins development
Post Reply
mlaszkow
Posts: 1
Joined: Wed Jan 18, 2017 11:16 am

Open file in plugin

Post by mlaszkow »

Hi,
I want write my first CloudCompare plugin.
How to open .fls file in plugin?
daniel
Site Admin
Posts: 7717
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Open file in plugin

Post by daniel »

If the FARO file is loaded as well as your plugin, you should be able to load the file with the static 'FileIOFilter::LoadFromFile' method (by default all plugins should have access to 'FileIOFilter.h').

Based on the extension, the 'LoadFromFile' method should use the FARO I/O filter to load the file. However, I'm not sure if the plugin (DLL) will share the same context as the application. Therefore we may need to add an accessor to the file I/O filter in ccMainAppInterface (the 'm_app' member of the plugin). I'll let you test the first solution and wait for your feedback.
Daniel, CloudCompare admin
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

Re: Open file in plugin

Post by CCNewbieL6 »

Hello everyone!
I want to open .txt files in my plugin , I try to write these codes:

AsciiFilter* loadf = new AsciiFilter();
AsciiFilter::LoadParameters loadp;
AsciiFilter::SaveParameters savep;
loadp.alwaysDisplayLoadDialog = true;
loadp.shiftHandlingMode = ccGlobalShiftManager::NO_DIALOG_AUTO_SHIFT;
loadp.autoComputeNormals = false;
loadp.parentWidget = this;
loadp.sessionStart = true;
savep.alwaysDisplaySaveDialog = false;
CC_FILE_ERROR err = CC_FERR_NO_ERROR;
QString txtfile="D:\HJ\test\airplane_0001.txt";
QString txt ="";
ccHObject* ent = loadf->LoadFromFile(txtfile, loadp, err, txt);

The plugin works correctly, but when run the code "ccHObject* ent = loadf->LoadFromFile(txtfile, loadp, err, txt);" , the plugin enter no response state.
And the whole Cloudcompare application terminated.

I think there is sonthing wrong in the loadParameters or CC_FILE_ERROR , but I could not find it.
What should I do ?
Thanks!
daniel
Site Admin
Posts: 7717
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Open file in plugin

Post by daniel »

Actually, you don't need to allocate the filter dynamically (you can keep it on the stack). And you shouldn't call the static 'LoadFile' method (which is actually a method of 'FileIOFilter', relying on registered filters). You should call AsciiFilter::loadFile directly.

Code: Select all


AsciiFilter::LoadParameters loadp;
loadp.alwaysDisplayLoadDialog = true;
loadp.shiftHandlingMode = ccGlobalShiftManager::NO_DIALOG_AUTO_SHIFT;
loadp.autoComputeNormals = false;
loadp.parentWidget = this;
loadp.sessionStart = true;

AsciiFilter filter;
ccHObject container;
CC_FILE_ERROR error = filter.loadFile(filename, container, loadp);

if (error == CC_FILE_NO_ERROR)
{
    //'container' should contain one cloud normally
    //...
}
Daniel, CloudCompare admin
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

Re: Open file in plugin

Post by CCNewbieL6 »

I have edited my code:

Code: Select all

        QString txtfile = "D:/HJ/test/airplane_0001.txt"; //file_path
	//Parameters:
	AsciiFilter::SaveParameters savep;
	savep.alwaysDisplaySaveDialog = false;
	AsciiFilter::LoadParameters loadp;
	loadp.alwaysDisplayLoadDialog = true;
	loadp.shiftHandlingMode = ccGlobalShiftManager::NO_DIALOG_AUTO_SHIFT;
	loadp.autoComputeNormals = false;
	loadp.parentWidget = m_app->getMainWindow();
	loadp.sessionStart = true;
	
	AsciiFilter loadf;
	ccHObject ent;

	m_app->dispToConsole("loadf start", ccMainAppInterface::STD_CONSOLE_MESSAGE);
	CC_FILE_ERROR err = loadf.loadFile(txtfile, ent, loadp);//load the cloud, always crash here
	m_app->dispToConsole("loadf over", ccMainAppInterface::STD_CONSOLE_MESSAGE);

	if (err == CC_FILE_ERROR::CC_FERR_NO_ERROR) {
		......
	}
	
The error still exist.
These are screenshoot:
this is the plugin:
Image
Then I click it. It will load a.txt file directly.
Image
Click apply:
Image
Then I Debug it via VS2017:
Image
Debug shows that error occured in CCCorelib.dll (maybe where function loadFile() located in).
I think when executing the function loadFile(), memory leaked.

I cannot figure it out.
WargodHernandez
Posts: 187
Joined: Tue Mar 05, 2019 3:59 pm

Re: Open file in plugin

Post by WargodHernandez »

Can you please try this version

Code: Select all

FileIOFilter::LoadParameters loadp;
loadp.alwaysDisplayLoadDialog = true;
loadp.shiftHandlingMode = ccGlobalShiftManager::NO_DIALOG_AUTO_SHIFT;
loadp.autoComputeNormals = false;
loadp.parentWidget = m_app->getMainWindow();
loadp.sessionStart = true;
CC_FILE_ERROR res;


ccHObject *loadedObj = FileIOFilter::LoadFromFile(fullPathToObject, loadp, res, AsciiFilter::GetFileFilter());
		if (res == CC_FERR_NO_ERROR) 
		{
			m_app->addToDB(loadedObj);
		}
		else
		{
			ccLog::Error(QString("Failed to load file: %1, Error # = %2").arg(fullPathToObject).arg(res));
		}
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

Re: Open file in plugin

Post by CCNewbieL6 »

Thank you very much! You solved my poroblem!
Post Reply