Bug Summary

File:OMOptim/OMOptim/build/../Core/Project.cpp
Warning:line 796, column 5
Called C++ object pointer is null

Annotated Source Code

[?] Use j/k keys for keyboard navigation

1// $Id$
2/**
3 * This file is part of OpenModelica.
4 *
5 * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
6 * c/o Linköpings universitet, Department of Computer and Information Science,
7 * SE-58183 Linköping, Sweden.
8 *
9 * All rights reserved.
10 *
11 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
12 * THIS OSMC PUBLIC LICENSE (OSMC-PL).
13 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
14 * OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the Open Source Modelica
17 * Consortium (OSMC) Public License (OSMC-PL) are obtained
18 * from OSMC, either from the above address,
19 * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20 * http://www.openmodelica.org, and in the OpenModelica distribution.
21 * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22 *
23 * This program is distributed WITHOUT ANY WARRANTY; without
24 * even the implied warranty of MERCHANTABILITY or FITNESS
25 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27 *
28 * See the full OSMC Public License conditions for more details.
29 *
30 * Main contributor 2010, Hubert Thierot, CEP - ARMINES (France)
31 * Main contributor 2010, Hubert Thierot, CEP - ARMINES (France)
32
33 @file Project.cpp
34 @brief Comments for file documentation.
35 @author Hubert Thieriot, hubert.thieriot@mines-paristech.fr
36 Company : CEP - ARMINES (France)
37 http://www-cep.ensmp.fr/english/
38 @version
39
40 */
41#include "Project.h"
42#include "onesimulationinterface.h"
43#include "optimizationinterface.h"
44#include "Save.h"
45
46#include "ModModelPlus.h"
47#include "MOItem.h"
48#include "OMCases.h"
49#include "Problems.h"
50#include "Results.h"
51#include "ModLoader.h"
52#include "InfoSender.h"
53#include "MOVector.h"
54#include "SleeperThread.h"
55#include "Info.h"
56#include "OneSimResult.h"
57#include "OneSimulation.h"
58#include "Optimization.h"
59#include "LowTools.h"
60#include "HighTools.h"
61#include "SaveOMOptim.h"
62#include "LoadOMOptim.h"
63#include "MOThreads.h"
64#include "ModItemsTree.h"
65#include "ProblemInterface.h"
66#include "ProblemInterfaces.h"
67#include "ModExePlus.h"
68#include "scriptparseromoptim.h"
69
70Project::Project(bool useOMC)
71{
72 _isdefined = false;
73 _useOmc = useOMC;
74 // _curProblem = -1;
75
76
77 _problems = new Problems("Problems");
78 _results = new Results("Results");
79 // _curLaunchedProblem = NULL;
80 setCurModItem(NULL__null);
81
82 _moomc = new MOomc("OMOptim",_useOmc);
83 _modLoader = new ModLoader(_moomc);
84 _modItemsTree = new ModItemsTree(this,_modLoader,_moomc);
85
86 // add interfaces for OneSimulation and Optimization
87 addProblemInterface(new OneSimulationInterface());
88 addProblemInterface(new OptimizationInterface());
89
90 emit projectChanged();
91}
92
93Project::~Project()
94{
95 if(_useOmc)
1
Assuming the condition is true
2
Taking true branch
96 terminateOms();
3
Calling 'Project::terminateOms'
97 terminateProblemsThreads(); // should be done before deleting modelPlus
98
99 if(_useOmc)
100 _moomc->stopServer();
101
102 if(_modItemsTree)
103 delete _modItemsTree;
104
105 delete _moomc;
106 delete _modLoader;
107
108 for(int i=0;i<_problemsInterfaces.uniqueInterfaces().size();i++)
109 {
110 delete _problemsInterfaces.uniqueInterfaces().at(i);
111 }
112
113 QList<ModelPlus*> allModelPlus = _mapModelPlus.values();
114 for(int i=0;i<allModelPlus.size();i++)
115 delete allModelPlus.at(i);
116
117 _problemsInterfaces.clear();
118
119}
120
121bool Project::launchScript(QFileInfo scriptFile)
122{
123 // parse file
124 QStringList scriptCommands;
125 QMap<QString,QString> definitions;
126
127 bool scriptResult = ScriptParser::parseFile(scriptFile,scriptCommands,definitions);
128 if(!scriptResult)
129 {
130 InfoSender::instance()->sendWarning("Failed to read script file.");
131 return false;
132 }
133
134 ScriptParserOMOptim* scriptParser = new ScriptParserOMOptim(this);
135 bool scriptOk = scriptParser->executeCommands(scriptCommands);
136 return scriptOk;
137}
138
139
140bool Project::launchScript(const QString & text)
141{
142 if(!_scriptParser)
143 return false;
144
145 // parse file
146 QStringList scriptCommands;
147 QMap<QString,QString> definitions;
148
149 bool scriptResult = ScriptParser::parseFile(text,scriptCommands,definitions);
150 if(!scriptResult)
151 {
152 InfoSender::instance()->sendWarning("Failed to read script file.");
153 return false;
154 }
155
156 bool scriptOk = _scriptParser->executeCommands(scriptCommands);
157 return scriptOk;
158}
159
160QString Project::getFieldName(int iField, int role) const
161{
162 return "name";
163}
164
165unsigned Project::getNbFields() const
166{
167 return 1;
168}
169
170/**
171* \brief
172* Clear project (Modelica hierarchy, _problems, Solved _problems, _moFiles...)
173*/
174void Project::clear()
175{
176 // delete GUI tabs...
177 emit projectAboutToBeReset();
178
179
180 _modItemsTree->clear();
181 _mapModelPlus.clear();
182
183 // OMC
184 _moomc->clear();
185
186
187 _problems->clear();
188 _results->clear();
189
190 _isdefined=false;
191 _filePath.clear();
192 _name.clear();
193 setCurModItem(NULL__null);
194
195 _moFiles.clear();
196 _mofilesWatcher.removePaths(_mofilesWatcher.files());
197 _mmoFiles.clear();
198
199 unloadPlugins();
200
201 emit projectChanged();
202}
203
204
205/**
206* \brief
207* Load a modelica file
208* \param moFilePath full file path of .mo
209* \param storePath yes/no should path be stored in project file
210* (as to be reloaded when loading project)
211* \param forceLoad yes/no should mo file be reloaded in OMC when already loaded in OMC
212*/
213void Project::loadMoFile(QString moFilePath, bool storePath, bool forceLoad)
214{
215 // unwatch mo file (avoid recursive call)
216 bool wasThere = _mofilesWatcher.files().contains(moFilePath);
217 _mofilesWatcher.removePath(moFilePath);
218
219 // clear modelplus of this file
220 // since if model has changed, compiled version may not be correct anymore.
221 QList<ModModelPlus*> modModelsConcerned = modModelPlusOfFile(moFilePath);
222 for(int i=0;i<modModelsConcerned.size();i++)
223 {
224 modModelsConcerned.at(i)->uncompile();
225 modModelsConcerned.at(i)->clear();
226 }
227
228 // add to mofileloadedlist
229 if(storePath && !_moFiles.contains(moFilePath))
230 _moFiles.push_back(QFileInfo(moFilePath));
231
232 // load moFile ...
233 QString msg;
234 bool loadOk = _modLoader->loadMoFile(modItemsTree(),moFilePath,msg,forceLoad);
235
236 // watch mo file
237 if(storePath || wasThere)
238 _mofilesWatcher.addPath(moFilePath);
239
240 if(loadOk)
241 {
242 _modItemsTree->emitDataChanged();
243 emit projectChanged();
244 }
245}
246
247/**
248* \brief Load several moFiles
249* \param moFilePaths list of full file paths of .mo
250* \param storePath yes/no should paths be stored in project file
251* (as to be reloaded when loading project)
252* \param forceLoad yes/no should mo file be reloaded in OMC when already loaded in OMC
253*/
254void Project::loadMoFiles(QStringList moFilePaths, bool storePath, bool forceLoad)
255{
256 QString moFilePath;
257 for(int i=0;i<moFilePaths.size();i++)
258 {
259 moFilePath = moFilePaths.at(i);
260 if(storePath && !_moFiles.contains(moFilePath))
261 _moFiles.push_back(moFilePath);
262 }
263
264 // load _moFiles and read them
265 _modLoader->loadMoFiles(modItemsTree(),moFilePaths,forceLoad);
266
267 // watch mo files
268 _mofilesWatcher.addPaths(moFilePaths);
269
270 _modItemsTree->emitDataChanged();
271
272 emit projectChanged();
273}
274
275
276void Project::loadExeFiles(QStringList exeModelNames, QStringList exeFilePaths, QStringList inputFilePaths, bool forceLoad)
277{
278 for(int i = 0; i<exeFilePaths.size(); i++)
279 {
280 // QString name = QFileInfo(exeFilePaths.at(i)).dir().dirName();
281 loadExecutableModel(exeModelNames.at(i),QFileInfo(exeFilePaths.at(i)), QFileInfo(inputFilePaths.at(i)));
282 }
283
284}
285
286
287/**
288* \brief Unload a modelica file
289* \param moFilePath full file path of .mo
290* \param storePath yes/no should path be removed from project
291*/
292void Project::unloadMoFile(QString moFilePath, bool removePath)
293{
294 // unwatch mo file (avoid recursive call)
295 bool wasThere = _mofilesWatcher.files().contains(moFilePath);
296 _mofilesWatcher.removePath(moFilePath);
297
298
299 // remove from mofileloadedlist
300 if(removePath)
301 _moFiles.removeAll(moFilePath);
302
303 // unload moFile ...
304 _modLoader->unloadMoFile(modItemsTree(),moFilePath);
305
306 _modItemsTree->emitDataChanged();
307
308
309 emit projectChanged();
310}
311
312/**
313* \brief Load Modelica library (calls OpenModelica load library function
314* \param storePath yes/no should path be stored in project file
315* (as to be reloaded when loading project)
316* \param forceLoad yes/no should mo file be reloaded in OMC when already loaded in OMC
317*/
318bool Project::loadModelicaLibrary(bool storePath, bool forceLoad)
319{
320
321 QFileInfo previousLoadedModelica = _moomc->getFileOfClass("Modelica");
322 QString libPath = MOSettings::value("modelicaLibrary").toString();
323 _moomc->loadStandardLibrary(libPath);
324 QFileInfo libPathInfo = _moomc->getFileOfClass("Modelica");
325 if(storePath)
326 {
327 _moFiles.removeAll(previousLoadedModelica); // only one loaded Modelica
328 _moFiles.push_back(libPathInfo);
329 }
330
331 refreshAllMod();
332
333 emit projectChanged();
334
335 return true;
336}
337
338bool Project::loadExecutableModel(QString name,QFileInfo exeFileInfo, QFileInfo inputFileInfo)
339{
340 QString exeFile = exeFileInfo.absoluteFilePath();
341 QString inputFile = inputFileInfo.absoluteFilePath();
342 // QString modelFolderName = modModelPlusFolder()+ QDir::separator() + name;
343
344 // if(!QDir(modelFolderName).exists())
345 // QDir(modelFolderName).mkpath(modelFolderName);
346 // bool copyExeFileOk = QFile::copy(exeFileInfo.absoluteFilePath(), exeFile );
347 // bool copyInputFileOk = QFile::copy(inputFileInfo.absoluteFilePath(), inputFile);
348
349 _modItemsTree->addExeModel(_modItemsTree->rootElement(),name, inputFile, exeFile);
350 _modItemsTree->emitDataChanged();
351
352 // add modelplus
353 addModelPlus(newModelPlus(name));
354
355 //Store the model
356 // QDir modPlusdir(modModelPlusFolder()+QDir::separator()+name);
357 // LowTools::mkpath(modPlusdir.absolutePath(),true);
358 // QFile::copy(exeFileInfo.absoluteFilePath(), modPlusdir.absoluteFilePath(exeFileInfo.fileName()) );
359 // QFile::copy(inputFileInfo.absoluteFilePath(), modPlusdir.absoluteFilePath(inputFileInfo.fileName()) );
360
361 return true;
362}
363
364bool Project::loadExecutableModel(QString name, QFileInfo exeFileInfo, QFileInfo inputFileInfo, ModExePlus* modExePlus)
365{
366
367
368 _modItemsTree->addExeModel(_modItemsTree->rootElement(),name, inputFileInfo, exeFileInfo);
369 _modItemsTree->emitDataChanged();
370
371 // add modelplus
372 addModelPlus(modExePlus);
373
374 //Store the model
375 // QDir modPlusdir(modModelPlusFolder()+QDir::separator()+name);
376 // LowTools::mkpath(modPlusdir.absolutePath(),true);
377 // QFile::copy(exeFileInfo.absoluteFilePath(), modPlusdir.absoluteFilePath(exeFileInfo.fileName()) );
378 // QFile::copy(inputFileInfo.absoluteFilePath(), modPlusdir.absoluteFilePath(inputFileInfo.fileName()) );
379
380 return true;
381}
382
383/**
384* \brief load a ModModelPlus defined by a filePath. It will be loaded only if refers to an existing model in current workspace.
385* \param mmoFilePath full file path of .mmo
386* \param uncompile : delete compiled version or not.
387*/
388void Project::loadModelPlus(QString mmoFilePath, bool uncompile)
389{
390 QString modelName = LoadOMOptim::loadModelPlus(this,mmoFilePath);
391 storeMmoFilePath(mmoFilePath);
392
393 if(uncompile)
394 {
395 ModModelPlus* modelPlus = dynamic_cast<ModModelPlus*>(this->modelPlus(modelName));
396 if(modelPlus)
397 modelPlus->uncompile();
398 }
399
400 emit projectChanged();
401}
402
403/**
404* \brief store mmoFilePath in project file. It will therefore be loaded when reloading project file.
405*/
406void Project::storeMmoFilePath(QString mmoFilePath)
407{
408 QString path = this->folder().relativeFilePath(mmoFilePath);
409
410 if(!_mmoFiles.contains(path))
411 {
412 _mmoFiles.push_back(path);
413 }
414
415 emit projectChanged();
416}
417
418//void Project::storeExeFilePath(QString exeFilePath)
419//{
420// // QString path = QFileInfo(exeFilePath).absoluteFilePath();
421
422// if(!_exeFileInfoList.contains(QFileInfo(exeFilePath)))
423// {
424// _exeFileInfoList.push_back(exeFilePath);
425// }
426
427// emit projectChanged();
428//}
429/**
430* \brief Reload the mo file of model
431*/
432void Project::reloadModModel(QString modModelName)
433{
434 ModModel* model = dynamic_cast<ModModel*>(modItemsTree()->findItem(modModelName));
435 if(model)
436 {
437 QString moFile = model->filePath();
438 this->loadMoFile(moFile,true,true);
439 }
440
441 emit projectChanged();
442}
443
444
445/**
446* \brief Refresh modelica tree in GUI. Do not reload in OpenModelica ! Just reread hierarchy.
447*/
448void Project::refreshAllMod()
449{
450 _modItemsTree->clear();
451 _modItemsTree->readFromOMCWThread(_modItemsTree->rootElement(),2);
452 _modItemsTree->emitDataChanged();
453}
454
455/**
456* \brief Return selected ModModel. Return NULL if no ModModel selected.
457*/
458ModModel* Project::curModModel()
459{
460 if(_curModItem && (_curModItem->getClassRestr()==Modelica::MODEL))
461 return (ModModel*)_curModItem;
462 else
463 return NULL__null;
464}
465/**
466* \brief Find a ModModel within _modItemsTree
467* \arg modelName name of the model looked for
468*/
469//ModModel* Project::findModModel(QString modelName)
470//{
471// ModItem* modModel = _modItemsTree->findInDescendants(modelName);
472
473// if(!modModel || modModel->getClassRestr()!=Modelica::MODEL)
474// return NULL;
475// else
476// return (ModModel*)modModel;
477//}
478
479ModItem* Project::findModItem(QString modelName)
480{
481 ModItem* modModel = _modItemsTree->findInDescendants(modelName);
482
483 if(!modModel)
484 return NULL__null;
485 else
486 return modModel;
487}
488/**
489* \brief Returns all ModModelPlus contained in project
490*/
491QList<ModelPlus*> Project::allModelPlus()
492{
493 return _mapModelPlus.values();
494}
495
496/**
497* \brief Adds modModelPlus in project
498*/
499void Project::addModelPlus(ModelPlus* modelPlus)
500{
501 if(modelPlus)
502 _mapModelPlus.insert(modelPlus->modelName(),modelPlus);
503}
504
505/**
506 * @brief Returns selected modModelPlus
507 */
508ModelPlus* Project::curModelPlus()
509{
510 ModModel* curMM = curModModel();
511 if(curMM)
512 return modelPlus(curMM->name());
513 else
514 return NULL__null;
515}
516
517void Project::setCurModItem(ModItem* modClass)
518{
519 if(_curModItem != modClass)
520 {
521 _curModItem = modClass;
522 emit curModItemChanged(_curModItem);
523
524 if(_curModItem && _curModItem->getClassRestr()==Modelica::MODEL)
525 emit curModModelChanged((ModModel*)_curModItem);
526 }
527}
528
529/**
530 * @brief Returns modModelPlus of modModelName.
531 * If it does not exist, this function creates a new ModModelPlus, adds it to the project,
532 * and returns it.
533 */
534ModelPlus* Project::modelPlus(QString modelName)
535{
536 ModelPlus* corrModelPlus = _mapModelPlus.value(modelName,NULL__null);
537
538 if(corrModelPlus)
539 return corrModelPlus;
540 else
541 {
542 corrModelPlus = newModelPlus(modelName);
543 if(corrModelPlus)
544 addModelPlus(corrModelPlus);
545 return corrModelPlus;
546 }
547}
548
549/**
550 * @brief Returns all modModelPlus related to a moFile.
551 */
552QList<ModModelPlus*> Project::modModelPlusOfFile(QString moFile)
553{
554 QList<ModModelPlus*> result;
555 QList<ModelPlus*> allModels = allModelPlus();
556 ModModelPlus* curModel;
557 for(int i=0;i<allModels.size();i++)
558 {
559 curModel = dynamic_cast<ModModelPlus*>(allModels.at(i));
560 if(curModel && QFileInfo(curModel->moFilePath())==QFileInfo(moFile))
561 result.push_back(curModel);
562 }
563 return result;
564}
565
566
567/**
568 * @brief Creates a new modelPlus for a model.
569 * New modModelPlus is automatically added to project.
570 */
571ModelPlus* Project::newModelPlus(QString modelName)
572{
573 // Create ModModelFile or ExeModelFile
574 ModItem* item = _modItemsTree->findItem(modelName);
575
576 ModelPlus* modelPlus=NULL__null;
577 ModModel* modModel = dynamic_cast<ModModel*> (item);
578 ExeModel* exeModel = dynamic_cast<ExeModel*> (item);
579
580 if(modModel)
581 modelPlus = new ModModelPlus(this,modelName);
582
583 if(exeModel)
584 modelPlus = new ModExePlus(this, modelName);
585
586 if(!modelPlus)
587 return NULL__null;
588
589 // Add to map
590 _mapModelPlus.insert(modelName,modelPlus);
591
592 // Store it
593 // create folder
594 QDir allModPlusdir(modelPlusFolder());
595 LowTools::mkpath(allModPlusdir.absolutePath(),false);
596 QDir modPlusdir(allModPlusdir.absolutePath()+QDir::separator()+modelName);
597 LowTools::mkpath(modPlusdir.absolutePath(),true);
598
599 // update modelplus with its path
600 QString newMmoFilePath = modPlusdir.absolutePath() + QDir::separator() + modelName + ".mmo";
601 storeMmoFilePath(newMmoFilePath);
602
603 // set mmoFilePath in ModelPlus
604 modelPlus->setMmoFilePath(newMmoFilePath);
605
606 // save it
607 SaveOMOptim::saveModelPlus(this,modelPlus);
608
609 emit projectChanged();
610 return modelPlus;
611}
612
613
614/** @brief Save project.
615 * @param saveAllOMCases Should we save all problems and results.
616 */
617void Project::save(bool saveAllOMCases)
618{
619 if(_saveLoadMutex.tryLock())
620 {
621 InfoSender::instance()->sendCurrentTask("Saving project...");
622 SaveOMOptim::saveProject(this,saveAllOMCases);
623
624 setSaved(true);
625 emit projectChanged();
626 InfoSender::instance()->eraseCurrentTask();
627 if (_saveLoadMutex.tryLock())
628 _saveLoadMutex.unlock();
629 }
630}
631
632void Project::exportProjectFolder(QDir externalFolder,bool includeMSL)
633{
634 // only if folder is empty
635 if(externalFolder.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs).isEmpty())
636 {
637 QFileInfoList orgMoFiles = this->moFiles();
638
639 QFileInfo orgPathInfo(this->filePath());
640
641 this->setFilePath(externalFolder.absoluteFilePath(orgPathInfo.fileName()));
642
643 // // copy mo files
644 // QFileInfoList orgMoFiles = this->moFiles();
645 // QFileInfoList newMoFiles;
646 // QFileInfo orgMoFile;
647 // QString newMoFileName;
648 // for(int i=0;i<orgMoFiles.size();i++)
649 // {
650 // orgMoFile = orgMoFiles.at(i);
651 // newMoFileName = orgMoFile.fileName();
652 // if(newMoFileName != "package.mo")
653 // {
654 // // get new paths
655 // int i=2;
656 // while(externalFolder.entryList().contains(newMoFileName))
657 // {
658
659 // newMoFileName = orgMoFile.baseName()+
660 // QString::number(i)+"."+orgMoFile.completeSuffix();
661 // i++;
662 // }
663 // QFile::copy(orgMoFile.absoluteFilePath(),externalFolder.absoluteFilePath(newMoFileName));
664 // newMoFiles.push_back(QFileInfo(externalFolder,newMoFileName));
665 // }
666 // }
667
668 // // change mo filepaths
669 // this->setMoFiles(newMoFiles);
670 // this->save(true);
671
672 // create mo file with all content (without Modelica)
673 QString moTxt = _moomc->getWholeText(includeMSL);
674
675 QString moFilePath = externalFolder.absoluteFilePath("Models.mo");
676 QFile file(moFilePath);
677 QFileInfo moFileInfo(moFilePath);
678
679 file.open(QIODevice::WriteOnly);
680
681 moTxt.remove(QRegExp("^\""));
682 moTxt.remove(QRegExp("\"$"));
683 QTextStream ts( &file );
684 ts << moTxt.toLocal8Bit();
685 file.close();
686
687 // change mo filepaths
688 QFileInfoList newMoFiles;
689 newMoFiles << moFileInfo;
690 this->setMoFiles(newMoFiles);
691 this->save(true);
692 // restore
693 this->setMoFiles(orgMoFiles);
694 this->setFilePath(orgPathInfo.absoluteFilePath());
695 }
696}
697
698/** @brief Save project and result given as parameter.
699 */
700void Project::save(Result* result)
701{
702 // save project but not all omcases
703 SaveOMOptim::saveProject(this,false);
704
705 // save result
706 Save::saveResult(this,result);
707
708 emit projectChanged();
709}
710
711/** @brief Save project and problem given as parameter.
712 */
713void Project::save(Problem* problem)
714{
715 // save project but not all omcases
716 SaveOMOptim::saveProject(this,false);
717
718 // save problem
719 Save::saveProblem(this,problem);
720
721 emit projectChanged();
722 if (_saveLoadMutex.tryLock())
723 _saveLoadMutex.unlock();
724}
725
726/** @brief Load project from file given as parameter.
727 */
728bool Project::load(QString loadPath)
729{
730 if(_saveLoadMutex.tryLock())
731 {
732 bool configOk = checkConfiguration();
733 bool loaded = false;
734
735 if(configOk)
736 loaded = LoadOMOptim::loadProject(loadPath,this);
737
738 if (loaded)
739 {
740 emit InfoSender::instance()->send( Info(ListInfo::PROJECTLOADSUCCESSFULL,filePath()));
741 emit projectChanged();
742 }
743 else
744 {
745 emit InfoSender::instance()->send( Info(ListInfo::PROJECTLOADFAILED,filePath()));
746 clear();
747 emit projectChanged();
748 }
749 setSaved(true);
750 emit projectChanged();
751 if (_saveLoadMutex.tryLock())
752 _saveLoadMutex.unlock();
753 return loaded;
754 }
755 else
756 return false;
757}
758
759
760/** @brief Return folder containting modelPlus saving files
761 */
762QString Project::modelPlusFolder()
763{
764 return folder().absoluteFilePath("Models");
765}
766
767
768/**
769 * @brief Check configuration. e.g. : checks omc is started.
770 */
771bool Project::checkConfiguration()
772{
773 bool ok = true;
774
775 if(!_moomc->isStarted() && _useOmc)
776 ok = ok && _moomc->startServer();
777
778 return ok;
779}
780
781/**
782 * @brief All threads using OMC are terminated.
783 */
784void Project::terminateOms()
785{
786 if(_moomc!=NULL__null)
4
Assuming pointer value is null
5
Taking false branch
787 {
788 // terminating current threads using omc
789 for(int i=0;i<_moomc->getThreads().size();i++)
790 {
791 QString msg ="Stopping "+_moomc->getThreadsNames().at(i);
792 InfoSender::instance()->send(Info(msg,ListInfo::NORMAL2));
793 _moomc->getThreads().at(i)->terminate();
794 }
795 }
796 _moomc->stopServer();
6
Called C++ object pointer is null
797}
798
799
800QFileInfoList Project::moFiles()
801{
802 return _moFiles;
803}
804
805QFileInfoList Project::mmoFiles()
806{
807 return _mmoFiles;
808}
809
810/**
811 * Careful : does not load moFiles, neither changed paths of loaded modelPlus.
812 * So far, only used to export project folder
813 */
814void Project::setMoFiles(QFileInfoList moFiles)
815{
816 _moFiles = moFiles;
817}
818
819ModItem *Project::rootModItem()
820{
821 return _modItemsTree->rootElement();
822}
823
824
825void Project::onModItemSelectionChanged(QList<ModItem*> &classes)
826{
827 if(classes.size()==1)
828 {
829 emit curModItemChanged(classes.at(0));
830
831 if(classes.at(0)->getClassRestr()==Modelica::MODEL)
832 emit curModModelChanged((ModModel*)classes.at(0));
833 else
834 emit curModModelChanged(NULL__null);
835 }
836 else
837 {
838 curModItemChanged(NULL__null);
839 curModModelChanged(NULL__null);
840 }
841}
842
843void Project::onReloadMOFileAsked()
844{
845 QAction* button = dynamic_cast<QAction*>(sender());
846 if(button)
847 {
848 QString moFile = button->data().toString();
849 this->loadMoFile(moFile,true,true);
850 _modItemsTree->readFromOMCWThread(_modItemsTree->rootElement(),2);
851 }
852}
853
854void Project::onUnloadMOFileAsked()
855{
856 QAction* button = dynamic_cast<QAction*>(sender());
857 if(button)
858 {
859 QString moFile = button->data().toString();
860 this->unloadMoFile(moFile,true);
861 _modItemsTree->readFromOMCWThread(_modItemsTree->rootElement(),2);
862 }
863}