56 #include <ACG/QtWidgets/QtFileDialog.hh>
59 #include <OpenFlipper/common/RecentFiles.hh>
61 #include "OpenFlipper/widgets/loadWidget/loadWidget.hh"
62 #include "OpenFlipper/widgets/addEmptyWidget/addEmptyWidget.hh"
66 #include "OpenFunctionThread.hh"
70 if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::sceneGraphUpdatesBlocked() ) {
72 unsigned int maxPases = 1;
76 for (
unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
97 for (
int i=0; i < (int)supportedTypes().size(); i++){
98 QString f = supportedTypes()[i].plugin->getLoadFilters();
99 f = f.section(
")",0,0).section(
"(",1,1).trimmed();
106 QString file(_filename);
109 if ( !file.startsWith(
"/") && !file.contains(
":") ) {
110 file = QDir::currentPath();
111 file += OpenFlipper::Options::dirSeparator();
121 QString file(_filename);
124 if ( !file.startsWith(
"/") && !file.contains(
":") ) {
125 file = QDir::currentPath();
126 file += OpenFlipper::Options::dirSeparator();
138 if ( OpenFlipper::Options::gui())
142 bool scriptingSupport =
false;
144 if ( ! scriptingSupport ) {
145 emit
log(
LOGERR ,tr(
"No scripting support available, please check if we load a scripting plugin .. Skipping script execution on startup"));
151 if ( scriptingSupport ) {
154 QDir scriptDir = OpenFlipper::Options::scriptDir();
155 QStringList scriptFiles = scriptDir.entryList(QDir::Files,QDir::Name);
158 for (
int i = 0 ; i < scriptFiles.size(); ++i )
159 if ( scriptFiles[i].endsWith(
"ofs",Qt::CaseInsensitive) )
164 slotCall(
"scripting" ,
"clearEditor()",ok);
167 OpenFlipper::Options::blockSceneGraphUpdates();
174 if ( tmp.endsWith(
"ofs",Qt::CaseInsensitive) ) {
187 OpenFlipper::Options::unblockSceneGraphUpdates();
193 if ( scriptingSupport )
200 if ( !OpenFlipper::Options::gui() && !OpenFlipper::Options::remoteControl())
206 if ( OpenFlipper::Options::gui() ) {
211 int id = thread->getObjId(0);
212 QString filename = thread->getFilename(0);
215 coreWidget_->statusMessage( tr(
"Loading %1 ... done").arg(filename), 4000 );
225 if ( OpenFlipper::Options::gui() )
228 emit
log(
LOGERR, tr(
"Unable to add recent as object with id %1 could not be found!").arg(
id) );
232 coreWidget_->statusMessage( tr(
"Loading %1 ... failed!").arg(filename), 4000 );
234 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
248 if (_filename.endsWith(
".ini",Qt::CaseInsensitive)) {
253 if ( OpenFlipper::Options::gui() )
257 }
else if (_filename.endsWith(
".ofs",Qt::CaseInsensitive)) {
258 emit
log(
LOGINFO ,tr(
"Starting script execution of %1.").arg( _filename)) ;
262 QFileInfo fi(_filename);
264 for (
int i=0; i < (int)supportedTypes().size(); i++){
266 QString filters = supportedTypes()[i].loadFilters;
269 filters = filters.section(
"(",1).section(
")",0,0);
272 QStringList separateFilters = filters.split(
" ");
277 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
278 separateFilters[filterId] = separateFilters[filterId].trimmed();
281 if ( separateFilters[filterId].endsWith(
"*." + fi.completeSuffix() , Qt::CaseInsensitive) ) {
286 if ( separateFilters[filterId].endsWith(
"*." + fi.suffix() , Qt::CaseInsensitive) ) {
288 emit
log(
LOGWARN,
"Found supported datatype but only the suffix is matched not the complete suffix!");
298 if ( OpenFlipper::Options::gui() ) {
299 coreWidget_->statusMessage( tr(
"Loading %1 ... ").arg(_filename));
300 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
304 QString jobId = QString(
"Loading_"+_filename);
305 QVector<LoadFromPluginThread::LoadInfos> infos;
309 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
312 if ( OpenFlipper::Options::gui() )
316 slotStartJob(jobId , QString(
"Loading %1").arg(_filename) , 0, 0,
true);
321 while(thread->isRunning())
322 QApplication::processEvents();
324 QApplication::processEvents();
328 thread->loadFromPlugin();
331 int objId = thread->getObjId(0);
337 emit
log(
LOGERR, tr(
"Unable to load object (type unknown). No suitable plugin found!") );
352 QFileInfo fi(_filename);
354 std::vector<int> typeIds;
355 for (
int i=0; i < (int)supportedTypes().size(); i++) {
356 if (supportedTypes()[i].type & _type || supportedTypes()[i].type == _type) {
358 QString filters = supportedTypes()[i].loadFilters;
361 filters = filters.section(
"(",1).section(
")",0,0);
364 QStringList separateFilters = filters.split(
" ");
367 for (
int filterId = 0 ; filterId < separateFilters.size(); ++filterId ) {
368 separateFilters[filterId] = separateFilters[filterId].trimmed();
371 if ( separateFilters[filterId].endsWith(
"*." + fi.completeSuffix() , Qt::CaseInsensitive) ) {
372 typeIds.push_back(i);
376 if ( separateFilters[filterId].endsWith(
"*." + fi.suffix() , Qt::CaseInsensitive) ) {
377 typeIds.push_back(i);
378 emit
log(
LOGWARN,
"Found supported datatype but only the suffix is matched not the complete suffix!");
386 size_t nPlugins = typeIds.size();
394 if ( OpenFlipper::Options::gui() ) {
396 for (
size_t j = 0; j < nPlugins; ++j) {
398 if (items.indexOf(supportedTypes()[typeIds[j]].name) == -1)
399 items << supportedTypes()[typeIds[j]].name;
403 QString item = QInputDialog::getItem(
coreWidget_, tr(
"File Plugins"),
404 tr(
"Please choose a plugin for loading:"), items, 0,
false, &ok);
406 emit
log(
LOGERR, tr(
"Unable to load object. No suitable plugin found!") );
409 i = typeIds[items.indexOf(item)];
418 if ( OpenFlipper::Options::gui() ) {
419 coreWidget_->statusMessage( tr(
"Loading %1 ... ").arg(_filename));
420 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
425 QString jobId = QString(
"Loading_"+_filename);
426 QVector<LoadFromPluginThread::LoadInfos> infos;
428 if (
checkSlot( supportedTypes()[i].
object ,
"loadObject(QString,DataType)" ) )
435 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
438 if ( OpenFlipper::Options::gui() )
442 slotStartJob(jobId , QString(
"Loading %1").arg(_filename) , 0, 0,
true);
447 while(thread->isRunning())
448 QApplication::processEvents();
450 QApplication::processEvents();
454 thread->loadFromPlugin();
457 int objId = thread->getObjId(0);
463 emit
log(
LOGERR, tr(
"Unable to load object. No suitable plugin found!") );
498 if (QThread::currentThread() != QApplication::instance()->thread())
501 QMetaObject::invokeMethod(
this,
"slotAddEmptyObject",Qt::BlockingQueuedConnection, Q_ARG(
DataType, _type), Q_ARG(
int*, &_id));
506 if ( OpenFlipper::Options::doSlotDebugging() ) {
507 if ( sender() != 0 ) {
508 if ( sender()->metaObject() != 0 ) {
509 emit
log(
LOGINFO,
"slotAddEmptyObject( " + _type.
name() +
"," + QString::number(_id) + tr(
" ) called by ") +
510 QString( sender()->metaObject()->className() ) );
513 emit
log(
LOGINFO,
"slotAddEmptyObject( " + _type.
name() +
"," + QString::number(_id) + tr(
" ) called by Core") );
522 if ( _oldId == -1 ) {
523 emit
log(
LOGERR,tr(
"Requested copy for illegal Object id: %1").arg(_oldId) );
532 emit
log(
LOGERR,tr(
"Requested copy for unknown Object id: %1 ").arg(_oldId) );
541 emit
log(
LOGERR,tr(
"Unable to create a copy of the object."));
564 QString filemsg =
"";
565 if (_filenames.size() > 1)
566 filemsg = QString( tr(
"Loading Files ...") );
568 filemsg = QString( tr(
"Loading %1 ...").arg(_filenames[0]) );
570 if ( OpenFlipper::Options::gui() ) {
572 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
577 QString jobId = QString(
"Loading File");
578 if (_filenames.size() > 1)
581 QVector<LoadFromPluginThread::LoadInfos> loadInfos;
582 for (
int i = 0; i < _filenames.size(); ++i)
586 connect(thread, SIGNAL(finished(QString)),
this, SLOT(
slotFinishJob(QString)));
587 connect(thread, SIGNAL(state(QString ,
int )),
this, SLOT(
slotSetJobState(QString ,
int)));
589 if ( OpenFlipper::Options::gui() )
596 if (_filenames.size() > 1)
597 slotStartJob(jobId , QString(filemsg), 0, _filenames.size(),
true);
605 while(thread->isRunning())
606 QApplication::processEvents();
608 QApplication::processEvents();
615 thread->loadFromPlugin();
619 QVector<DataType> type = QVector<DataType>(_filenames.size(),
DATA_UNKNOWN);
621 for (
int i = 0; i < _filenames.size(); ++i)
623 int id = thread->getObjId(i);
625 if ( OpenFlipper::Options::gui() ) {
628 coreWidget_->statusMessage( tr(
"Loading %1 done").arg(_filenames[i]), 4000 );
630 coreWidget_->statusMessage( tr(
"Loading %1 failed").arg(_filenames[i]), 4000 );
632 if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() )
658 emit
log(
LOGERR,tr(
"Object id returned but no object with this id has been found! Error in one of the file plugins!"));
665 type[i] =
object->dataType();
670 if ( OpenFlipper::Options::gui() )
671 for (
int i = 0; i < _filenames.size(); ++i)
672 if ( thread->getObjId(i) >= 0 )
684 if ( OpenFlipper::Options::gui() )
691 if (QThread::currentThread() != QApplication::instance()->thread())
693 QMetaObject::invokeMethod(
this,
"slotFileOpened",Qt::QueuedConnection, Q_ARG(
int, _id));
697 if ( OpenFlipper::Options::doSlotDebugging() ) {
698 if ( sender() != 0 ) {
699 if ( sender()->metaObject() != 0 ) {
700 emit
log(
LOGINFO,tr(
"slotObjectOpened( ") + QString::number(_id) + tr(
" ) called by ") +
701 QString( sender()->metaObject()->className() ) );
704 emit
log(
LOGINFO,tr(
"slotObjectOpened( ") + QString::number(_id) + tr(
" ) called by Core") );
742 QString filename =
object->path() + OpenFlipper::Options::dirSeparator() +
object->name();
757 if ( OpenFlipper::Options::doSlotDebugging() ) {
758 if ( sender() != 0 ) {
759 if ( sender()->metaObject() != 0 ) {
760 emit
log(
LOGINFO,tr(
"slotEmptyObjectAdded( ") + QString::number(_id) + tr(
" ) called by ") +
761 QString( sender()->metaObject()->className() ) );
764 emit
log(
LOGINFO,tr(
"slotEmptyObjectAdded( ") + QString::number(_id) + tr(
" ) called by Core") );
793 std::vector< DataType > types;
794 QStringList typeNames;
804 for ( uint i = 0 ; i <
typeCount() - 2 ; ++i) {
815 types.push_back(currentType);
816 typeNames.push_back(
typeName( currentType ) );
824 for ( uint j = 0 ; j < supportedTypes().size(); j++) {
827 if ( supportedTypes()[j].type & currentType ) {
830 bool duplicate =
false;
831 for(std::vector< DataType >::iterator it = types.begin(); it != types.end(); ++it) {
832 if(*it == currentType) {
839 types.push_back(currentType);
840 typeNames.push_back(
typeName( currentType ) );
854 if (supportedTypes().size() != 0) {
860 widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
867 emit
log(
LOGERR,tr(
"Could not show 'add Empty' dialog. Missing file-plugins ?"));
878 if ( OpenFlipper::Options::gui() ){
880 if (supportedTypes().size() != 0){
882 connect(widget,SIGNAL(loadFiles(QStringList,
IdList)),
this,SLOT(
slotLoad(QStringList,
IdList)));
883 connect(widget,SIGNAL(save(
int, QString,
int)),
this,SLOT(
saveObject(
int, QString,
int)));
885 widget->setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
889 widget->disconnect();
893 emit
log(
LOGERR,tr(
"Could not show 'load objects' dialog. Missing file-plugins."));
901 if ( OpenFlipper::Options::gui() ){
903 QString complete_name;
909 tr(
"INI files (*.ini)") );
911 fileDialog.setOption (QFileDialog::DontUseNativeDialog,
true);
912 fileDialog.setAcceptMode ( QFileDialog::AcceptOpen );
913 fileDialog.setFileMode ( QFileDialog::AnyFile );
915 QGridLayout *layout = (QGridLayout*)fileDialog.layout();
917 QGroupBox* optionsBox =
new QGroupBox( &fileDialog ) ;
918 optionsBox->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding , QSizePolicy::Preferred ) );
919 optionsBox->setTitle(tr(
"Options"));
920 layout->addWidget( optionsBox, layout->rowCount() , 0 , 1,layout->columnCount() );
922 QCheckBox *loadProgramSettings =
new QCheckBox(optionsBox);
923 loadProgramSettings->setText(tr(
"Load program settings"));
924 loadProgramSettings->setToolTip(tr(
"Load all current program settings from the file ( This will include view settings, colors,...) "));
925 loadProgramSettings->setCheckState( Qt::Unchecked );
927 QCheckBox *loadPluginSettings =
new QCheckBox(optionsBox);
928 loadPluginSettings->setText(tr(
"Load per Plugin Settings"));
929 loadPluginSettings->setToolTip(tr(
"Plugins should load their current global settings from the file"));
930 loadPluginSettings->setCheckState( Qt::Checked );
932 QCheckBox *loadObjectInfo =
new QCheckBox(optionsBox);
933 loadObjectInfo->setText(tr(
"Load all objects defined in the file"));
934 loadObjectInfo->setToolTip(tr(
"Load all objects which are defined in the file"));
935 loadObjectInfo->setCheckState( Qt::Checked );
937 QBoxLayout* frameLayout =
new QBoxLayout(QBoxLayout::TopToBottom,optionsBox);
938 frameLayout->addWidget( loadProgramSettings , 0 , 0);
939 frameLayout->addWidget( loadPluginSettings , 1 , 0);
940 frameLayout->addWidget( loadObjectInfo , 2 , 0);
941 frameLayout->addStretch();
943 fileDialog.resize(550 ,500);
948 QStringList fileNames;
949 if (fileDialog.exec()) {
950 fileNames = fileDialog.selectedFiles();
955 if ( fileNames.size() > 1 ) {
956 std::cerr <<
"Too many save filenames selected" << std::endl;
960 complete_name = fileNames[0];
963 QString newpath = complete_name.section(OpenFlipper::Options::dirSeparator(),0,-2);
966 if ( complete_name.endsWith(
"ini",Qt::CaseInsensitive) ) {
968 loadProgramSettings->isChecked(),
969 loadPluginSettings->isChecked(),
970 loadObjectInfo->isChecked());
971 if ( loadProgramSettings->isChecked() )
982 if ( !QFile(_filename).exists() )
985 QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
988 if ( _filename.endsWith(
"obj",Qt::CaseInsensitive) ) {
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
bool saveObject(int _id, QString _filename)
Save an object.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void signalObjectUpdated(int)
When this Signal is emitted all Plugins are informed that the object list changed.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void slotCopyObject(int _oldId, int &_newId)
Slot copying an object.
std::vector< std::pair< std::string, bool > > commandLineFileNames_
Vector storing filenames from commandline to be opened after application startup (objects) ...
void slotFileOpened(int _id)
Called when a file has been opened.
void slotAddEmptyObject(DataType _type, int &_id)
Slot adding empty object of a given type.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
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)
int addEmptyObject(DataType _type)
const DataType DATA_UNKNOWN(0)
None of the other Objects.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
const DataType DATA_GROUP(1)
Items used for Grouping.
void commandLineOpen(const char *_filename, bool _asPolyMesh)
Load an object from the commandline on application start.
BaseObject * objectRoot_
Pointer to the data rootNode;.
void slotExecuteAfterStartup()
Executed after loading core completly to load files from commandline.
void slotFinishJob(QString _jobId)
A job state has been finished by a plugin.
DLLEXPORT size_t typeCount()
Get the number of registered types.
void slotAddEmptyObjectMenu()
Open the add Empty dialog.
LoggerWidget * logWidget_
Textedit at the bottom for log messages.
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
bool dataType(DataType _type) const
void loadObject()
Open Load Widget.
int showLoad()
show Widget for loading Files
void resetScenegraph(bool _resetTrackBall)
void slotGetAllFilters(QStringList &_list)
Called when a plugin requests a list of file-filters.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
void slotStartJob(QString _jobId, QString _description, int _min, int _max, bool _blocking)
A job has been started by a plugin.
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
void setParent(BaseObject *_parent)
Set the parent pointer.
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
Status is processing but system will allow interaction (yellow light)
void openedFile(int _id)
Tell the plugins that a file has been opened ( -> Database)
void analyzeSceneGraph(ACG::SceneGraph::BaseNode *_root, unsigned int &_maxPasses, ACG::Vec3d &_bbmin, ACG::Vec3d &_bbmax)
std::vector< std::string > commandLineScriptNames_
Vector storing filenames from commandline to be opened after application startup (script files) ...
void addRecent(QString _filename, DataType _type)
Add a recent file and update menu.
void executeFileScript(QString _filename)
Core scripting engine.
void applyOptions()
after ini-files have been loaded and core is up or if options have been changed -> apply Options ...
void emptyObjectAdded(int _id)
Tell the plugins that an empty object has been added.
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
void commandLineScript(const char *_filename)
Load a script from the commandline on application start.
void loadObjectFinished(QString _filename)
Vector storing filenames from commandline to be opened after application startup (objects) ...
void exitApplication()
exit the current application
void updateInSceneLoggerGeometry()
Set in-scene logger geometry right.
virtual BaseObject * copy()
Returns a full copy of the object.
Status is ready (green light)
std::vector< dataTypes > supportedDataTypes_
Type-Plugins.
void unLockUpdate()
Unlock display locked by updateLock().
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void slotSetJobState(QString _jobId, int _value)
A job state has been updated by a plugin.
void startProcessing()
start processing
void slotLoad(QString _filename, DataType _type, int &_id)
A plugin wants to load a given file.
bool checkSlot(QObject *_plugin, const char *_slotSignature)
Check if a plugin has a slot.
QString name() const
Return the name of this type as text.
void loadSettings()
Load status from file.
void updateView()
Called when a plugin requests an update in the viewer.
SeparatorNode * root_node_scenegraph_
Scenegraphs root node.
void slotPluginExists(QString _pluginName, bool &_exists)
Check if a plugin exists.
void viewAll(int _viewer)
View the whole scene.
void openIniFile(QString _filename, bool _coreSettings, bool _perPluginSettings, bool _loadObjects)
Load information from an ini file.
void createBackup(int _objectid, QString _name, UpdateType _type=UPDATE_ALL)
Tell backup-plugin to create a backup.
void slotEmptyObjectAdded(int _id)
Called when an empty object has been Added.
std::vector< glViewer * > examiner_widgets_
Examiner Widget.
void slotCall(QString _pluginName, QString _functionName, bool &_success)