50#include <ACG/QtWidgets/QtFileDialog.hh>
53#include <OpenFlipper/common/RecentFiles.hh>
55#include "OpenFlipper/widgets/loadWidget/loadWidget.hh"
56#include "OpenFlipper/widgets/addEmptyWidget/addEmptyWidget.hh"
58#include "OpenFunctionThread.hh"
60#include <ACG/Scenegraph/SeparatorNode.hh>
64 if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::sceneGraphUpdatesBlocked() ) {
66 unsigned int maxPases = 1;
70 for (
unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
91 for (
int i=0; i < (int)supportedTypes().size(); i++){
92 QString f = supportedTypes()[i].plugin->getLoadFilters();
93 f = f.section(
")",0,0).section(
"(",1,1).trimmed();
100 QString file = _filename;
103 if ( !file.startsWith(
"/") && !file.contains(
":") ) {
104 file = QDir::currentPath();
105 file += OpenFlipper::Options::dirSeparator();
115 QString file = _filename;
118 if ( !file.startsWith(
"/") && !file.contains(
":") ) {
119 file = QDir::currentPath();
120 file += OpenFlipper::Options::dirSeparator();
132 if ( OpenFlipper::Options::gui())
136 bool qtScriptSupport =
false;
139 #ifdef PYTHON_ENABLED
140 bool pythonScriptSupport =
true;
142 bool pythonScriptSupport =
false;
151 QDir scriptDir = OpenFlipper::Options::scriptDir();
152 QStringList scriptFiles = scriptDir.entryList(QDir::Files,QDir::Name);
155 for (
int i = 0 ; i < scriptFiles.size(); ++i ) {
156 if ( scriptFiles[i].endsWith(
"ofs",Qt::CaseInsensitive) ) {
157 if ( qtScriptSupport ) {
160 emit
log(
LOGERR,
"No Qt Script support. Unable to execute: " + scriptDir.path() +
"/" + scriptFiles[i] );
164 if ( scriptFiles[i].endsWith(
"ofp",Qt::CaseInsensitive) ) {
165 #ifdef PYTHON_ENABLED
168 emit
log(
LOGERR,
"No Python Script support. Unable to execute: " + scriptDir.path() +
"/" + scriptFiles[i] );
175 #if QT_VERSION_MAJOR < 6
177 if ( qtScriptSupport ) {
179 slotCall(
"scripting" ,
"clearEditor()",ok);
183 OpenFlipper::Options::blockSceneGraphUpdates();
190 if ( tmp.endsWith(
".ofs",Qt::CaseInsensitive) || tmp.endsWith(
".ofp",Qt::CaseInsensitive) ) {
203 OpenFlipper::Options::unblockSceneGraphUpdates();
213 if ( qtScriptSupport ) {
221 #ifdef PYTHON_ENABLED
224 if ( !OpenFlipper::Options::nogui() ) {
240 if ( !OpenFlipper::Options::gui() && !OpenFlipper::Options::remoteControl())
246 if ( OpenFlipper::Options::gui() ) {
251 int id = thread->getObjId(0);
252 QString filename = thread->getFilename(0);
255 coreWidget_->statusMessage( tr(
"Loading %1 ... done").arg(filename), 4000 );
265 if ( OpenFlipper::Options::gui() )
268 emit
log(
LOGERR, tr(
"Unable to add recent as object with id %1 could not be found!").arg(
id) );
272 coreWidget_->statusMessage( tr(
"Loading %1 ... failed!").arg(filename), 4000 );
274 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
288 if (_filename.endsWith(
".ini",Qt::CaseInsensitive)) {
293 if ( OpenFlipper::Options::gui() )
297 }
else if (_filename.endsWith(
".ofs",Qt::CaseInsensitive)) {
298 emit
log(
LOGINFO ,tr(
"Starting script execution of OpenFlipper Script %1.").arg( _filename)) ;
300 }
else if (_filename.endsWith(
".ofp",Qt::CaseInsensitive)) {
301 emit
log(
LOGINFO ,tr(
"Starting script execution of Python script %1.").arg( _filename)) ;
305 QFileInfo fi(_filename);
307 for (
int i=0; i < (int)supportedTypes().size(); i++){
309 QString filters = supportedTypes()[i].loadFilters;
312 filters = filters.section(
"(",1).section(
")",0,0);
315 QStringList separateFilters = filters.split(
" ");
320 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
321 separateFilters[filterId] = separateFilters[filterId].trimmed();
324 if ( separateFilters[filterId].endsWith(
"*." + fi.completeSuffix() , Qt::CaseInsensitive) ) {
329 if ( separateFilters[filterId].endsWith(
"*." + fi.suffix() , Qt::CaseInsensitive) ) {
331 emit
log(
LOGWARN,
"Found supported datatype but only the suffix is matched not the complete suffix!");
341 if ( OpenFlipper::Options::gui() ) {
342 coreWidget_->statusMessage( tr(
"Loading %1 ... ").arg(_filename));
343 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
347 QString jobId = QString(
"Loading_"+_filename);
348 QVector<LoadFromPluginThread::LoadInfos> infos;
352 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
355 if ( OpenFlipper::Options::gui() )
359 slotStartJob(jobId , QString(
"Loading %1").arg(_filename) , 0, 0,
true);
364 while(thread->isRunning())
365 QApplication::processEvents();
367 QApplication::processEvents();
371 thread->loadFromPlugin();
374 int objId = thread->getObjId(0);
380 emit
log(
LOGERR, tr(
"Unable to load object (type unknown). No suitable plugin found!") );
395 QFileInfo fi(_filename);
397 std::vector<int> typeIds;
398 for (
int i=0; i < (int)supportedTypes().size(); i++) {
399 if (supportedTypes()[i].type & _type || supportedTypes()[i].type == _type) {
401 QString filters = supportedTypes()[i].loadFilters;
404 filters = filters.section(
"(",1).section(
")",0,0);
407 QStringList separateFilters = filters.split(
" ");
410 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
411 separateFilters[filterId] = separateFilters[filterId].trimmed();
414 if ( separateFilters[filterId].endsWith(
"*." + fi.completeSuffix() , Qt::CaseInsensitive) ) {
415 typeIds.push_back(i);
419 if ( separateFilters[filterId].endsWith(
"*." + fi.suffix() , Qt::CaseInsensitive) ) {
420 typeIds.push_back(i);
421 emit
log(
LOGWARN,
"Found supported datatype but only the suffix is matched not the complete suffix!");
429 size_t nPlugins = typeIds.size();
437 if ( OpenFlipper::Options::gui() ) {
439 for (
size_t j = 0; j < nPlugins; ++j) {
441 if (items.indexOf(supportedTypes()[typeIds[j]].name) == -1)
442 items << supportedTypes()[typeIds[j]].name;
446 QString item = QInputDialog::getItem(
coreWidget_, tr(
"File Plugins"),
447 tr(
"Please choose a plugin for loading:"), items, 0,
false, &ok);
449 emit
log(
LOGERR, tr(
"Unable to load object. No suitable plugin found!") );
452 i = typeIds[items.indexOf(item)];
461 if ( OpenFlipper::Options::gui() ) {
462 coreWidget_->statusMessage( tr(
"Loading %1 ... ").arg(_filename));
463 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
468 QString jobId = QString(
"Loading_"+_filename);
469 QVector<LoadFromPluginThread::LoadInfos> infos;
471 if (
checkSlot( supportedTypes()[i].
object ,
"loadObject(QString,DataType)" ) )
478 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
481 if ( OpenFlipper::Options::gui() )
485 slotStartJob(jobId , QString(
"Loading %1").arg(_filename) , 0, 0,
true);
490 while(thread->isRunning())
491 QApplication::processEvents();
493 QApplication::processEvents();
497 thread->loadFromPlugin();
500 int objId = thread->getObjId(0);
506 emit
log(
LOGERR, tr(
"Unable to load object. No suitable plugin found!") );
541 if (QThread::currentThread() != QApplication::instance()->thread())
544 QMetaObject::invokeMethod(
this,
"slotAddEmptyObject",Qt::BlockingQueuedConnection, Q_ARG(
DataType, _type), Q_ARG(
int*, &_id));
549 if ( OpenFlipper::Options::doSlotDebugging() ) {
550 if ( sender() != 0 ) {
551 if ( sender()->metaObject() != 0 ) {
552 emit
log(
LOGINFO,
"slotAddEmptyObject( " + _type.
name() +
"," + QString::number(_id) + tr(
" ) called by ") +
553 QString( sender()->metaObject()->className() ) );
556 emit
log(
LOGINFO,
"slotAddEmptyObject( " + _type.
name() +
"," + QString::number(_id) + tr(
" ) called by Core") );
565 if ( _oldId == -1 ) {
566 emit
log(
LOGERR,tr(
"Requested copy for illegal Object id: %1").arg(_oldId) );
575 emit
log(
LOGERR,tr(
"Requested copy for unknown Object id: %1 ").arg(_oldId) );
584 emit
log(
LOGERR,tr(
"Unable to create a copy of the object."));
607 QString filemsg =
"";
608 if (_filenames.size() > 1)
609 filemsg = QString( tr(
"Loading Files ...") );
611 filemsg = QString( tr(
"Loading %1 ...").arg(_filenames[0]) );
613 if ( OpenFlipper::Options::gui() ) {
615 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
620 QString jobId = QString(
"Loading File");
621 if (_filenames.size() > 1)
624 QVector<LoadFromPluginThread::LoadInfos> loadInfos;
625 for (
int i = 0; i < _filenames.size(); ++i)
629 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
630 connect(thread, SIGNAL(state(QString ,
int )),
this, SLOT(
slotSetJobState(QString ,
int)));
632 if ( OpenFlipper::Options::gui() )
639 if (_filenames.size() > 1)
640 slotStartJob(jobId , QString(filemsg), 0, _filenames.size(),
true);
648 while(thread->isRunning())
649 QApplication::processEvents();
651 QApplication::processEvents();
658 thread->loadFromPlugin();
662 QVector<DataType> type = QVector<DataType>(_filenames.size(),
DATA_UNKNOWN);
664 for (
int i = 0; i < _filenames.size(); ++i)
666 int id = thread->getObjId(i);
668 if ( OpenFlipper::Options::gui() ) {
671 coreWidget_->statusMessage( tr(
"Loading %1 done").arg(_filenames[i]), 4000 );
673 coreWidget_->statusMessage( tr(
"Loading %1 failed").arg(_filenames[i]), 4000 );
675 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
701 emit
log(
LOGERR,tr(
"Object id returned but no object with this id has been found! Error in one of the file plugins!"));
708 type[i] =
object->dataType();
713 if ( OpenFlipper::Options::gui() )
714 for (
int i = 0; i < _filenames.size(); ++i)
715 if ( thread->getObjId(i) >= 0 )
727 if ( OpenFlipper::Options::gui() )
734 if (QThread::currentThread() != QApplication::instance()->thread())
736 QMetaObject::invokeMethod(
this,
"slotFileOpened",Qt::QueuedConnection, Q_ARG(
int, _id));
740 if ( OpenFlipper::Options::doSlotDebugging() ) {
741 if ( sender() != 0 ) {
742 if ( sender()->metaObject() != 0 ) {
743 emit
log(
LOGINFO,tr(
"slotObjectOpened( ") + QString::number(_id) + tr(
" ) called by ") +
744 QString( sender()->metaObject()->className() ) );
747 emit
log(
LOGINFO,tr(
"slotObjectOpened( ") + QString::number(_id) + tr(
" ) called by Core") );
785 QString filename =
object->path() + OpenFlipper::Options::dirSeparator() +
object->name();
800 if ( OpenFlipper::Options::doSlotDebugging() ) {
801 if ( sender() != 0 ) {
802 if ( sender()->metaObject() != 0 ) {
803 emit
log(
LOGINFO,tr(
"slotEmptyObjectAdded( ") + QString::number(_id) + tr(
" ) called by ") +
804 QString( sender()->metaObject()->className() ) );
807 emit
log(
LOGINFO,tr(
"slotEmptyObjectAdded( ") + QString::number(_id) + tr(
" ) called by Core") );
836 std::vector< DataType > types;
837 QStringList typeNames;
847 for ( uint i = 0 ; i <
typeCount() - 2 ; ++i) {
858 types.push_back(currentType);
859 typeNames.push_back(
typeName( currentType ) );
867 for ( uint j = 0 ; j < supportedTypes().size(); j++) {
870 if ( supportedTypes()[j].type & currentType ) {
873 bool duplicate =
false;
874 for(std::vector< DataType >::iterator it = types.begin(); it != types.end(); ++it) {
875 if(*it == currentType) {
882 types.push_back(currentType);
883 typeNames.push_back(
typeName( currentType ) );
897 if (supportedTypes().size() != 0) {
903 widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
910 emit
log(
LOGERR,tr(
"Could not show 'add Empty' dialog. Missing file-plugins ?"));
921 if ( OpenFlipper::Options::gui() ){
923 if (supportedTypes().size() != 0){
925 connect(widget,SIGNAL(loadFiles(QStringList,
IdList)),
this,SLOT(
slotLoad(QStringList,
IdList)));
926 connect(widget,SIGNAL(save(
int, QString,
int)),
this,SLOT(
saveObject(
int, QString,
int)));
928 widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
932 widget->disconnect();
936 emit
log(
LOGERR,tr(
"Could not show 'load objects' dialog. Missing file-plugins."));
944 if ( OpenFlipper::Options::gui() ){
946 QString complete_name;
952 tr(
"INI files (*.ini)") );
954 fileDialog.setOption (QFileDialog::DontUseNativeDialog,
true);
955 fileDialog.setAcceptMode ( QFileDialog::AcceptOpen );
956 fileDialog.setFileMode ( QFileDialog::AnyFile );
958 QGridLayout *layout = (QGridLayout*)fileDialog.layout();
960 QGroupBox* optionsBox =
new QGroupBox( &fileDialog ) ;
961 optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
962 optionsBox->setTitle(tr(
"Options"));
963 layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
965 QCheckBox *loadProgramSettings =
new QCheckBox(optionsBox);
966 loadProgramSettings->setText(tr(
"Load program settings"));
967 loadProgramSettings->setToolTip(tr(
"Load all current program settings from the file ( This will include view settings, colors,...) "));
968 loadProgramSettings->setCheckState( Qt::Unchecked );
970 QCheckBox *loadPluginSettings =
new QCheckBox(optionsBox);
971 loadPluginSettings->setText(tr(
"Load per Plugin Settings"));
972 loadPluginSettings->setToolTip(tr(
"Plugins should load their current global settings from the file"));
973 loadPluginSettings->setCheckState( Qt::Checked );
975 QCheckBox *loadObjectInfo =
new QCheckBox(optionsBox);
976 loadObjectInfo->setText(tr(
"Load all objects defined in the file"));
977 loadObjectInfo->setToolTip(tr(
"Load all objects which are defined in the file"));
978 loadObjectInfo->setCheckState( Qt::Checked );
980 QBoxLayout* frameLayout =
new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
982 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
983 frameLayout->addWidget( loadProgramSettings , 0 , 0);
984 frameLayout->addWidget( loadPluginSettings , 1 , 0);
985 frameLayout->addWidget( loadObjectInfo , 2 , 0);
987 frameLayout->addWidget( loadProgramSettings , 0 , Qt::Alignment() );
988 frameLayout->addWidget( loadPluginSettings , 1 , Qt::Alignment() );
989 frameLayout->addWidget( loadObjectInfo , 2 , Qt::Alignment() );
991 frameLayout->addStretch();
993 fileDialog.resize(550 ,500);
998 QStringList fileNames;
999 if (fileDialog.exec()) {
1000 fileNames = fileDialog.selectedFiles();
1005 if ( fileNames.size() > 1 ) {
1006 std::cerr <<
"Too many save filenames selected" << std::endl;
1010 complete_name = fileNames[0];
1013 QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
1016 if ( complete_name.endsWith(
"ini",Qt::CaseInsensitive) ) {
1018 loadProgramSettings->isChecked(),
1019 loadPluginSettings->isChecked(),
1020 loadObjectInfo->isChecked());
1021 if ( loadProgramSettings->isChecked() )
1032 if ( !QFile(_filename).exists() )
1035 QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
1038 if ( _filename.endsWith(
"obj",Qt::CaseInsensitive) ) {
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
const DataType DATA_UNKNOWN(0)
None of the other Objects.
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
DLLEXPORT size_t typeCount()
Get the number of registered types.
const DataType DATA_GROUP(1)
Items used for Grouping.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void setParent(BaseObject *_parent)
Set the parent pointer.
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
bool dataType(DataType _type) const
virtual BaseObject * copy()
Returns a full copy of the object.
void slotGetAllFilters(QStringList &_list)
Called when a plugin requests a list of file-filters.
void executeFileScript(QString _filename)
Core scripting engine.
void commandLineOpen(const QString &_filename, bool _asPolyMesh)
Load an object from the commandline on application start.
void applyOptions()
after ini-files have been loaded and core is up or if options have been changed -> apply Options
BaseObject * objectRoot_
Pointer to the data rootNode;.
void slotCall(const QString &_pluginName, const QString &_functionName, bool &_success)
void emptyObjectAdded(int _id)
Tell the plugins that an empty object has been added.
void commandLineScript(const QString &_filename)
Load a script from the commandline on application start.
void slotAddEmptyObjectMenu()
Open the add Empty dialog.
std::vector< dataTypes > supportedDataTypes_
Type-Plugins.
void openedFile(int _id)
Tell the plugins that a file has been opened ( -> Database)
void slotCopyObject(int _oldId, int &_newId)
Slot copying an object.
void slotEmptyObjectAdded(int _id)
Called when an empty object has been Added.
void slotFinishJob(QString _jobId)
A job state has been finished by a plugin.
void loadObject()
Open Load Widget.
std::vector< std::pair< QString, bool > > commandLineFileNames_
Vector storing filenames from commandline to be opened after application startup (objects)
bool checkSlot(QObject *_plugin, const char *_slotSignature)
Check if a plugin has a slot.
void createBackup(int _objectid, QString _name, UpdateType _type=UPDATE_ALL)
Tell backup-plugin to create a backup.
void slotSetJobState(QString _jobId, int _value)
A job state has been updated by a plugin.
void executePythonScriptFile(QString _filename)
Open the given file and execute its contents as a python script.
void loadObjectFinished(const QString &_filename)
Vector storing filenames from commandline to be opened after application startup (objects)
void slotLoad(QString _filename, DataType _type, int &_id)
A plugin wants to load a given file.
void resetScenegraph(bool _resetTrackBall)
void slotStartJob(QString _jobId, QString _description, int _min, int _max, bool _blocking)
A job has been started by a plugin.
void slotPluginExists(const QString &_pluginName, bool &_exists)
Check if a plugin exists.
void slotExecuteAfterStartup()
Executed after loading core completly to load files from commandline.
void slotAddEmptyObject(DataType _type, int &_id)
Slot adding empty object of a given type.
SeparatorNode * root_node_scenegraph_
Scenegraphs root node.
void slotObjectUpdated(int _identifier, const UpdateType &_type=UPDATE_ALL)
Called by the plugins if they changed something in the object list (deleted, added,...
void updateView()
Called when a plugin requests an update in the viewer.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
void exitApplication()
exit the current application
void slotFileOpened(int _id)
Called when a file has been opened.
void loadSettings()
Load status from file.
bool saveObject(int _id, QString _filename)
Save an object.
void signalObjectUpdated(int)
When this Signal is emitted all Plugins are informed that the object list changed.
int addEmptyObject(DataType _type)
std::vector< QString > commandLineScriptNames_
Vector storing filenames from commandline to be opened after application startup (script files)
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
void openIniFile(QString _filename, bool _coreSettings, bool _perPluginSettings, bool _loadObjects)
Load information from an ini file.
QString name() const
Return the name of this type as text.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void startProcessing()
start processing
void unLockUpdate()
Unlock display locked by updateLock().
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void analyzeSceneGraph(ACG::SceneGraph::BaseNode *_root, unsigned int &_maxPasses, ACG::Vec3d &_bbmin, ACG::Vec3d &_bbmax)
Analyze the SceneGraph <ACG/Scenegraph/SceneGraphAnalysis.hh>
@ READY
Status is ready (green light)
@ PROCESSING
Status is processing but system will allow interaction (yellow light)
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
void viewAll(int _viewer)
View the whole scene.
Struct containing all relevant information about a load operation.