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 scriptingSupport =
false;
138 if ( ! scriptingSupport ) {
139 emit
log(
LOGERR ,tr(
"No scripting support available, please check if we load a scripting plugin .. Skipping script execution on startup"));
145 if ( scriptingSupport ) {
148 QDir scriptDir = OpenFlipper::Options::scriptDir();
149 QStringList scriptFiles = scriptDir.entryList(QDir::Files,QDir::Name);
152 for (
int i = 0 ; i < scriptFiles.size(); ++i ) {
153 if ( scriptFiles[i].endsWith(
"ofs",Qt::CaseInsensitive) )
156 if ( scriptFiles[i].endsWith(
"ofp",Qt::CaseInsensitive) )
162 slotCall(
"scripting" ,
"clearEditor()",ok);
165 OpenFlipper::Options::blockSceneGraphUpdates();
172 if ( tmp.endsWith(
".ofs",Qt::CaseInsensitive) || tmp.endsWith(
".ofp",Qt::CaseInsensitive) ) {
185 OpenFlipper::Options::unblockSceneGraphUpdates();
191 if ( scriptingSupport )
204 if ( !OpenFlipper::Options::gui() && !OpenFlipper::Options::remoteControl())
210 if ( OpenFlipper::Options::gui() ) {
215 int id = thread->getObjId(0);
216 QString filename = thread->getFilename(0);
219 coreWidget_->statusMessage( tr(
"Loading %1 ... done").arg(filename), 4000 );
229 if ( OpenFlipper::Options::gui() )
232 emit
log(
LOGERR, tr(
"Unable to add recent as object with id %1 could not be found!").arg(
id) );
236 coreWidget_->statusMessage( tr(
"Loading %1 ... failed!").arg(filename), 4000 );
238 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
252 if (_filename.endsWith(
".ini",Qt::CaseInsensitive)) {
257 if ( OpenFlipper::Options::gui() )
261 }
else if (_filename.endsWith(
".ofs",Qt::CaseInsensitive)) {
262 emit
log(
LOGINFO ,tr(
"Starting script execution of OpenFlipper Script %1.").arg( _filename)) ;
264 }
else if (_filename.endsWith(
".ofp",Qt::CaseInsensitive)) {
265 emit
log(
LOGINFO ,tr(
"Starting script execution of Python script %1.").arg( _filename)) ;
269 QFileInfo fi(_filename);
271 for (
int i=0; i < (int)supportedTypes().size(); i++){
273 QString filters = supportedTypes()[i].loadFilters;
276 filters = filters.section(
"(",1).section(
")",0,0);
279 QStringList separateFilters = filters.split(
" ");
284 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
285 separateFilters[filterId] = separateFilters[filterId].trimmed();
288 if ( separateFilters[filterId].endsWith(
"*." + fi.completeSuffix() , Qt::CaseInsensitive) ) {
293 if ( separateFilters[filterId].endsWith(
"*." + fi.suffix() , Qt::CaseInsensitive) ) {
295 emit
log(
LOGWARN,
"Found supported datatype but only the suffix is matched not the complete suffix!");
305 if ( OpenFlipper::Options::gui() ) {
306 coreWidget_->statusMessage( tr(
"Loading %1 ... ").arg(_filename));
307 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
311 QString jobId = QString(
"Loading_"+_filename);
312 QVector<LoadFromPluginThread::LoadInfos> infos;
316 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
319 if ( OpenFlipper::Options::gui() )
323 slotStartJob(jobId , QString(
"Loading %1").arg(_filename) , 0, 0,
true);
328 while(thread->isRunning())
329 QApplication::processEvents();
331 QApplication::processEvents();
335 thread->loadFromPlugin();
338 int objId = thread->getObjId(0);
344 emit
log(
LOGERR, tr(
"Unable to load object (type unknown). No suitable plugin found!") );
359 QFileInfo fi(_filename);
361 std::vector<int> typeIds;
362 for (
int i=0; i < (int)supportedTypes().size(); i++) {
363 if (supportedTypes()[i].type & _type || supportedTypes()[i].type == _type) {
365 QString filters = supportedTypes()[i].loadFilters;
368 filters = filters.section(
"(",1).section(
")",0,0);
371 QStringList separateFilters = filters.split(
" ");
374 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
375 separateFilters[filterId] = separateFilters[filterId].trimmed();
378 if ( separateFilters[filterId].endsWith(
"*." + fi.completeSuffix() , Qt::CaseInsensitive) ) {
379 typeIds.push_back(i);
383 if ( separateFilters[filterId].endsWith(
"*." + fi.suffix() , Qt::CaseInsensitive) ) {
384 typeIds.push_back(i);
385 emit
log(
LOGWARN,
"Found supported datatype but only the suffix is matched not the complete suffix!");
393 size_t nPlugins = typeIds.size();
401 if ( OpenFlipper::Options::gui() ) {
403 for (
size_t j = 0; j < nPlugins; ++j) {
405 if (items.indexOf(supportedTypes()[typeIds[j]].name) == -1)
406 items << supportedTypes()[typeIds[j]].name;
410 QString item = QInputDialog::getItem(
coreWidget_, tr(
"File Plugins"),
411 tr(
"Please choose a plugin for loading:"), items, 0,
false, &ok);
413 emit
log(
LOGERR, tr(
"Unable to load object. No suitable plugin found!") );
416 i = typeIds[items.indexOf(item)];
425 if ( OpenFlipper::Options::gui() ) {
426 coreWidget_->statusMessage( tr(
"Loading %1 ... ").arg(_filename));
427 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
432 QString jobId = QString(
"Loading_"+_filename);
433 QVector<LoadFromPluginThread::LoadInfos> infos;
435 if (
checkSlot( supportedTypes()[i].
object ,
"loadObject(QString,DataType)" ) )
442 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
445 if ( OpenFlipper::Options::gui() )
449 slotStartJob(jobId , QString(
"Loading %1").arg(_filename) , 0, 0,
true);
454 while(thread->isRunning())
455 QApplication::processEvents();
457 QApplication::processEvents();
461 thread->loadFromPlugin();
464 int objId = thread->getObjId(0);
470 emit
log(
LOGERR, tr(
"Unable to load object. No suitable plugin found!") );
505 if (QThread::currentThread() != QApplication::instance()->thread())
508 QMetaObject::invokeMethod(
this,
"slotAddEmptyObject",Qt::BlockingQueuedConnection, Q_ARG(
DataType, _type), Q_ARG(
int*, &_id));
513 if ( OpenFlipper::Options::doSlotDebugging() ) {
514 if ( sender() != 0 ) {
515 if ( sender()->metaObject() != 0 ) {
516 emit
log(
LOGINFO,
"slotAddEmptyObject( " + _type.
name() +
"," + QString::number(_id) + tr(
" ) called by ") +
517 QString( sender()->metaObject()->className() ) );
520 emit
log(
LOGINFO,
"slotAddEmptyObject( " + _type.
name() +
"," + QString::number(_id) + tr(
" ) called by Core") );
529 if ( _oldId == -1 ) {
530 emit
log(
LOGERR,tr(
"Requested copy for illegal Object id: %1").arg(_oldId) );
539 emit
log(
LOGERR,tr(
"Requested copy for unknown Object id: %1 ").arg(_oldId) );
548 emit
log(
LOGERR,tr(
"Unable to create a copy of the object."));
571 QString filemsg =
"";
572 if (_filenames.size() > 1)
573 filemsg = QString( tr(
"Loading Files ...") );
575 filemsg = QString( tr(
"Loading %1 ...").arg(_filenames[0]) );
577 if ( OpenFlipper::Options::gui() ) {
579 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
584 QString jobId = QString(
"Loading File");
585 if (_filenames.size() > 1)
588 QVector<LoadFromPluginThread::LoadInfos> loadInfos;
589 for (
int i = 0; i < _filenames.size(); ++i)
593 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
594 connect(thread, SIGNAL(state(QString ,
int )),
this, SLOT(
slotSetJobState(QString ,
int)));
596 if ( OpenFlipper::Options::gui() )
603 if (_filenames.size() > 1)
604 slotStartJob(jobId , QString(filemsg), 0, _filenames.size(),
true);
612 while(thread->isRunning())
613 QApplication::processEvents();
615 QApplication::processEvents();
622 thread->loadFromPlugin();
626 QVector<DataType> type = QVector<DataType>(_filenames.size(),
DATA_UNKNOWN);
628 for (
int i = 0; i < _filenames.size(); ++i)
630 int id = thread->getObjId(i);
632 if ( OpenFlipper::Options::gui() ) {
635 coreWidget_->statusMessage( tr(
"Loading %1 done").arg(_filenames[i]), 4000 );
637 coreWidget_->statusMessage( tr(
"Loading %1 failed").arg(_filenames[i]), 4000 );
639 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
665 emit
log(
LOGERR,tr(
"Object id returned but no object with this id has been found! Error in one of the file plugins!"));
672 type[i] =
object->dataType();
677 if ( OpenFlipper::Options::gui() )
678 for (
int i = 0; i < _filenames.size(); ++i)
679 if ( thread->getObjId(i) >= 0 )
691 if ( OpenFlipper::Options::gui() )
698 if (QThread::currentThread() != QApplication::instance()->thread())
700 QMetaObject::invokeMethod(
this,
"slotFileOpened",Qt::QueuedConnection, Q_ARG(
int, _id));
704 if ( OpenFlipper::Options::doSlotDebugging() ) {
705 if ( sender() != 0 ) {
706 if ( sender()->metaObject() != 0 ) {
707 emit
log(
LOGINFO,tr(
"slotObjectOpened( ") + QString::number(_id) + tr(
" ) called by ") +
708 QString( sender()->metaObject()->className() ) );
711 emit
log(
LOGINFO,tr(
"slotObjectOpened( ") + QString::number(_id) + tr(
" ) called by Core") );
749 QString filename =
object->path() + OpenFlipper::Options::dirSeparator() +
object->name();
764 if ( OpenFlipper::Options::doSlotDebugging() ) {
765 if ( sender() != 0 ) {
766 if ( sender()->metaObject() != 0 ) {
767 emit
log(
LOGINFO,tr(
"slotEmptyObjectAdded( ") + QString::number(_id) + tr(
" ) called by ") +
768 QString( sender()->metaObject()->className() ) );
771 emit
log(
LOGINFO,tr(
"slotEmptyObjectAdded( ") + QString::number(_id) + tr(
" ) called by Core") );
800 std::vector< DataType > types;
801 QStringList typeNames;
811 for ( uint i = 0 ; i <
typeCount() - 2 ; ++i) {
822 types.push_back(currentType);
823 typeNames.push_back(
typeName( currentType ) );
831 for ( uint j = 0 ; j < supportedTypes().size(); j++) {
834 if ( supportedTypes()[j].type & currentType ) {
837 bool duplicate =
false;
838 for(std::vector< DataType >::iterator it = types.begin(); it != types.end(); ++it) {
839 if(*it == currentType) {
846 types.push_back(currentType);
847 typeNames.push_back(
typeName( currentType ) );
861 if (supportedTypes().size() != 0) {
867 widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
874 emit
log(
LOGERR,tr(
"Could not show 'add Empty' dialog. Missing file-plugins ?"));
885 if ( OpenFlipper::Options::gui() ){
887 if (supportedTypes().size() != 0){
889 connect(widget,SIGNAL(loadFiles(QStringList,
IdList)),
this,SLOT(
slotLoad(QStringList,
IdList)));
890 connect(widget,SIGNAL(save(
int, QString,
int)),
this,SLOT(
saveObject(
int, QString,
int)));
892 widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
896 widget->disconnect();
900 emit
log(
LOGERR,tr(
"Could not show 'load objects' dialog. Missing file-plugins."));
908 if ( OpenFlipper::Options::gui() ){
910 QString complete_name;
916 tr(
"INI files (*.ini)") );
918 fileDialog.setOption (QFileDialog::DontUseNativeDialog,
true);
919 fileDialog.setAcceptMode ( QFileDialog::AcceptOpen );
920 fileDialog.setFileMode ( QFileDialog::AnyFile );
922 QGridLayout *layout = (QGridLayout*)fileDialog.layout();
924 QGroupBox* optionsBox =
new QGroupBox( &fileDialog ) ;
925 optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
926 optionsBox->setTitle(tr(
"Options"));
927 layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
929 QCheckBox *loadProgramSettings =
new QCheckBox(optionsBox);
930 loadProgramSettings->setText(tr(
"Load program settings"));
931 loadProgramSettings->setToolTip(tr(
"Load all current program settings from the file ( This will include view settings, colors,...) "));
932 loadProgramSettings->setCheckState( Qt::Unchecked );
934 QCheckBox *loadPluginSettings =
new QCheckBox(optionsBox);
935 loadPluginSettings->setText(tr(
"Load per Plugin Settings"));
936 loadPluginSettings->setToolTip(tr(
"Plugins should load their current global settings from the file"));
937 loadPluginSettings->setCheckState( Qt::Checked );
939 QCheckBox *loadObjectInfo =
new QCheckBox(optionsBox);
940 loadObjectInfo->setText(tr(
"Load all objects defined in the file"));
941 loadObjectInfo->setToolTip(tr(
"Load all objects which are defined in the file"));
942 loadObjectInfo->setCheckState( Qt::Checked );
944 QBoxLayout* frameLayout =
new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
945 frameLayout->addWidget( loadProgramSettings , 0 , 0);
946 frameLayout->addWidget( loadPluginSettings , 1 , 0);
947 frameLayout->addWidget( loadObjectInfo , 2 , 0);
948 frameLayout->addStretch();
950 fileDialog.resize(550 ,500);
955 QStringList fileNames;
956 if (fileDialog.exec()) {
957 fileNames = fileDialog.selectedFiles();
962 if ( fileNames.size() > 1 ) {
963 std::cerr <<
"Too many save filenames selected" << std::endl;
967 complete_name = fileNames[0];
970 QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
973 if ( complete_name.endsWith(
"ini",Qt::CaseInsensitive) ) {
975 loadProgramSettings->isChecked(),
976 loadPluginSettings->isChecked(),
977 loadObjectInfo->isChecked());
978 if ( loadProgramSettings->isChecked() )
989 if ( !QFile(_filename).exists() )
992 QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
995 if ( _filename.endsWith(
"obj",Qt::CaseInsensitive) ) {
std::vector< std::pair< QString, bool > > commandLineFileNames_
Vector storing filenames from commandline to be opened after application startup (objects) ...
LoggerWidget * logWidget_
Textedit at the bottom for log messages.
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void slotCopyObject(int _oldId, int &_newId)
Slot copying an object.
void slotEmptyObjectAdded(int _id)
Called when an empty object has been Added.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
void slotAddEmptyObjectMenu()
Open the add Empty dialog.
void openedFile(int _id)
Tell the plugins that a file has been opened ( -> Database)
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
Status is ready (green light)
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
void slotObjectUpdated(int _identifier, const UpdateType &_type=UPDATE_ALL)
Called by the plugins if they changed something in the object list (deleted, added, or other property changes)
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
void slotLoad(QString _filename, DataType _type, int &_id)
A plugin wants to load a given file.
void slotFinishJob(QString _jobId)
A job state has been finished by a plugin.
void unLockUpdate()
Unlock display locked by updateLock().
SeparatorNode * root_node_scenegraph_
Scenegraphs root node.
void signalObjectUpdated(int)
When this Signal is emitted all Plugins are informed that the object list changed.
void openIniFile(QString _filename, bool _coreSettings, bool _perPluginSettings, bool _loadObjects)
Load information from an ini file.
void addRecent(QString _filename, DataType _type)
Add a recent file and update menu.
void executeFileScript(QString _filename)
Core scripting engine.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void executePythonScriptFile(QString _filename)
Open the given file and execute its contents as a python script.
void commandLineOpen(const QString &_filename, bool _asPolyMesh)
Load an object from the commandline on application start.
int showLoad()
show Widget for loading Files
bool dataType(DataType _type) const
int addEmptyObject(DataType _type)
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
DLLEXPORT size_t typeCount()
Get the number of registered types.
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
void loadObjectFinished(QString _filename)
Vector storing filenames from commandline to be opened after application startup (objects) ...
void slotAddEmptyObject(DataType _type, int &_id)
Slot adding empty object of a given type.
void analyzeSceneGraph(ACG::SceneGraph::BaseNode *_root, unsigned int &_maxPasses, ACG::Vec3d &_bbmin, ACG::Vec3d &_bbmax)
Analyze the SceneGraph <ACG/Scenegraph/SceneGraphAnalysis.hh>
void slotFileOpened(int _id)
Called when a file has been opened.
const DataType DATA_UNKNOWN(0)
None of the other Objects.
BaseObject * objectRoot_
Pointer to the data rootNode;.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Status is processing but system will allow interaction (yellow light)
QString name() const
Return the name of this type as text.
void slotStartJob(QString _jobId, QString _description, int _min, int _max, bool _blocking)
A job has been started by a plugin.
void loadObject()
Open Load Widget.
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 updateView()
Called when a plugin requests an update in the viewer.
const DataType DATA_GROUP(1)
Items used for Grouping.
void startProcessing()
start processing
void applyOptions()
after ini-files have been loaded and core is up or if options have been changed -> apply Options ...
void setParent(BaseObject *_parent)
Set the parent pointer.
void emptyObjectAdded(int _id)
Tell the plugins that an empty object has been added.
void viewAll(int _viewer)
View the whole scene.
void commandLineScript(const QString &_filename)
Load a script from the commandline on application start.
void updateInSceneLoggerGeometry()
Set in-scene logger geometry right.
std::vector< dataTypes > supportedDataTypes_
Type-Plugins.
void loadSettings()
Load status from file.
std::vector< glViewer *> examiner_widgets_
Examiner Widget.
virtual BaseObject * copy()
Returns a full copy of the object.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void exitApplication()
exit the current application
void slotGetAllFilters(QStringList &_list)
Called when a plugin requests a list of file-filters.
void slotExecuteAfterStartup()
Executed after loading core completly to load files from commandline.
bool checkSlot(QObject *_plugin, const char *_slotSignature)
Check if a plugin has a slot.
bool saveObject(int _id, QString _filename)
Save an object.
std::vector< QString > commandLineScriptNames_
Vector storing filenames from commandline to be opened after application startup (script files) ...
void slotCall(QString _pluginName, QString _functionName, bool &_success)
DLLEXPORT DataType typeId(QString _name)
Given a dataType Identifier string this function will return the id of the datatype.
void resetScenegraph(bool _resetTrackBall)
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
void slotPluginExists(QString _pluginName, bool &_exists)
Check if a plugin exists.