Bug Summary

File:OMOptim/OMOptim/build/../Core/Modelica/ModItem.cpp
Warning:line 473, column 10
Value stored to 'ok' during its initialization is never read

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 ModItem.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 "ModItem.h"
42#include "MOomc.h"
43#include "LowTools.h"
44
45ModItem::ModItem(MOomc* moomc)
46{
47 _moomc = moomc;
48 _childrenReaden = false;
49 _parent = NULL__null;
50}
51
52
53ModItem::ModItem(MOomc* moomc,ModItem* parent,QString fullname,QFileInfo file)
54{
55 _moomc = moomc;
56 _parent = parent;
57 _name = fullname;
58 _file = file;
59 _childrenReaden = false;
60}
61
62ModItem* ModItem::clone() const
63{
64 ModItem* newModItem = new ModItem(_moomc,_parent,_name,_file);
65 newModItem->_childrenReaden = _childrenReaden;
66
67 for(int i=0;i<_children.size();i++)
68 {
69 newModItem->addChild(_children.at(i)->clone());
70 }
71 return newModItem;
72}
73
74ModItem::~ModItem(void)
75{
76 clearDescendants();
77}
78
79QVariant ModItem::getFieldValue(int iField, int role) const
80{
81 switch(iField)
82 {
83 case NAME:
84 return _name;
85 break;
86 case FILEPATH:
87 return _file.absoluteFilePath();
88 break;
89 default :
90 return QVariant();
91 break;
92 }
93}
94
95bool ModItem::setFieldValue(int iField, QVariant value)
96{
97 try{
98 switch(iField)
99 {
100 case NAME:
101 _name = value.toString();
102 break;
103 case FILEPATH:
104 _file.setFile(value.toString());
105 break;
106 }
107 emit modified();
108 return true;
109 }
110 catch(std::exception )
111 {
112 return false;
113 }
114}
115
116QString ModItem::sFieldName(int iField, int role)
117{
118 switch(iField)
119 {
120 case NAME:
121 return "Name";
122 case FILEPATH:
123 return "FilePath";
124 default :
125 return "-";
126 }
127}
128
129ModItem* ModItem::parentItem()
130{
131 return _parent;
132}
133
134int ModItem::childCount() const
135{
136 return _children.size();
137}
138
139QStringList ModItem::getChildrenNames()
140{
141 QStringList result;
142 for(int i=0;i<this->childCount();i++)
143 {
144 result.push_back(this->child(i)->name());
145 }
146 return result;
147}
148
149bool ModItem::childrenReaden()
150{
151 return _childrenReaden;
152}
153
154void ModItem::setChildrenReaden(bool childrenReaden)
155{
156 _childrenReaden = childrenReaden;
157}
158
159int ModItem::compChildCount()
160{
161 int nbComp=0;
162 for(int i=0;i<_children.size();i++)
163 if(_children.at(i)->getClassRestr()==Modelica::COMPONENT)
164 nbComp++;
165
166 return nbComp;
167}
168
169int ModItem::modelChildCount()
170{
171 int nbModel=0;
172 for(int i=0;i<_children.size();i++)
173 if(_children.at(i)->getClassRestr()==Modelica::MODEL)
174 nbModel++;
175
176 return nbModel;
177}
178
179int ModItem::packageChildCount()
180{
181 int nbPackage=0;
182 for(int i=0;i<_children.size();i++)
183 if(_children.at(i)->getClassRestr()==Modelica::PACKAGE)
184 nbPackage++;
185
186 return nbPackage;
187}
188
189int ModItem::recordChildCount()
190{
191 int nbRecords=0;
192 for(int i=0;i<_children.size();i++)
193 if(_children.at(i)->getClassRestr()==Modelica::RECORD)
194 nbRecords++;
195
196 return nbRecords;
197}
198
199ModItem* ModItem::child(int nRow) const
200{
201 if((nRow>-1)&&(nRow<_children.count()))
202 return _children.at(nRow);
203 else
204 return NULL__null;
205}
206
207ModItem* ModItem::compChild(int nRow) const
208{
209 int iCurComp=-1;
210 int curIndex=0;
211 while((curIndex<_children.size())&&(iCurComp<nRow))
212 {
213 if(_children.at(curIndex)->getClassRestr()==Modelica::COMPONENT)
214 iCurComp++;
215
216 curIndex++;
217 }
218
219 if(iCurComp==nRow)
220 return _children.at(curIndex-1);
221 else
222 return NULL__null;
223}
224
225ModItem* ModItem::packageChild(int nRow) const
226{
227 int iCurPackage=-1;
228 int curIndex=0;
229 while((curIndex<_children.size())&&(iCurPackage<nRow))
230 {
231 if(_children.at(curIndex)->getClassRestr()==Modelica::PACKAGE)
232 iCurPackage++;
233
234 curIndex++;
235 }
236
237 if(iCurPackage==nRow)
238 return _children.at(curIndex-1);
239 else
240 return NULL__null;
241}
242
243ModItem* ModItem::recordChild(int nRow) const
244{
245 int iCurRecord=-1;
246 int curIndex=0;
247 while((curIndex<_children.size())&&(iCurRecord<nRow))
248 {
249 if(_children.at(curIndex)->getClassRestr()==Modelica::PACKAGE)
250 iCurRecord++;
251
252 curIndex++;
253 }
254
255 if(iCurRecord==nRow)
256 return _children.at(curIndex-1);
257 else
258 return NULL__null;
259}
260
261ModItem *ModItem::child(QString childName) const
262{
263 for(int i=0;i<childCount();i++)
264 {
265 if((child(i)->name(ModItem::FULL)==childName)
266 ||(child(i)->name(ModItem::SHORT)==childName))
267 return child(i);
268 }
269 return NULL__null;
270}
271
272
273ModItem* ModItem::modelChild(int nRow) const
274{
275 int iCurModel=-1;
276 int curIndex=0;
277 while((curIndex<_children.size())&&(iCurModel<nRow))
278 {
279 if(_children.at(curIndex)->getClassRestr()==Modelica::MODEL)
280 iCurModel++;
281
282 curIndex++;
283 }
284
285 if(iCurModel==nRow)
286 return _children.at(curIndex-1);
287 else
288 return NULL__null;
289}
290
291int ModItem::indexInParent()
292{
293 if(parent()==NULL__null)
294 return -1;
295
296
297 //looking for row number of child in parent
298 int nbBrothers = parentItem()->childCount();
299 bool found = false;
300 int iC=0;
301
302 while(!found && iC<nbBrothers)
303 {
304 found = (parentItem()->child(iC)==this);
305 if(!found)
306 iC++;
307 }
308 if(!found)
309 return -1;
310 else
311 return iC;
312}
313
314bool ModItem::containsItemOfClass(QString className) const
315{
316 if(this->getClassName()==className)
317 return true;
318
319 bool found = false;
320 int i=0;
321 while(!found && i<childCount())
322 {
323 found = child(i)->containsItemOfClass(className);
324 i++;
325 }
326 return found;
327}
328
329
330QString ModItem::filePath()
331{
332 ModItem* parent = _parent;
333 QFileInfo file = _file;
334 while(file.fileName().isEmpty()&&(parent!=NULL__null))
335 {
336 file = parent->_file;
337 parent = parent->parentItem();
338 }
339
340 if(file.fileName().isEmpty() && _moomc)
341 {
342 file = _moomc->getFileOfClass(name());
343 }
344 return file.absoluteFilePath();
345}
346
347QString ModItem::name(ModItem::NameFormat type)
348{
349 if(type == ModItem::SHORT)
350 return _name.section(".",-1,-1);
351 else
352 {
353 QString fullName = _name;
354 // ModItem *curParent = parent();
355
356 // while((curParent!=NULL)&&(curParent->name(Modelica::SHORT)!=""))
357 // {
358 // fullName.insert(0,curParent->name(Modelica::SHORT)+".");
359 // curParent = curParent->parent();
360 // }
361
362 QString middleName;
363 switch(type)
364 {
365 case ModItem::WITHOUTROOT:
366 middleName = fullName.section(".",1,fullName.count(".")+1);
367 return middleName;
368 case ModItem::FULL:
369 return fullName;
370 default:
371 return _name;
372 }
373 }
374}
375
376QString ModItem::getModClassName()
377{
378 return name(ModItem::FULL);
379}
380
381void ModItem::emitModified()
382{
383 emit modified();
384}
385
386int ModItem::depth()
387{
388 QString fullName=_name;
389 ModItem *curParent = parentItem();
390
391 if(curParent==NULL__null)
392 return 0;
393 else
394 return curParent->depth()+1;
395}
396
397QList<ModItem *> ModItem::children() const
398{
399 return _children;
400}
401
402
403void ModItem::clear()
404{
405 clearDescendants();
406 emit modified();
407
408 _parent = NULL__null;
409 _name = QString();
410 _file = QString();
411 _childrenReaden = false;
412
413 emit cleared();
414}
415
416void ModItem::clearDescendants()
417{
418 while(_children.size()>0)
419 {
420 delete _children.at(0);
421 _children.removeAt(0);
422 }
423 _childrenReaden = false;
424 emit modified();
425}
426
427bool ModItem::addChild(ModItem *child)
428{
429 bool ok=false;
430 if(child)
431 {
432 child->setParentItem(this);
433 _children.push_back(child);
434 ok = true;
435 emit addedChild(child);
436 connect(child,SIGNAL(modified())"2""modified()",this,SIGNAL(modified())"2""modified()");
437 }
438 if(ok)
439 emit modified();
440
441 return ok;
442}
443
444
445void ModItem::setParentItem(ModItem *parent)
446{
447 if(_parent != parent)
448 {
449 _parent = parent;
450 emit modified();
451 }
452}
453
454
455
456QString ModItem::getStrToolTip()
457{
458 QString toolTip;
459 toolTip += ("Generic Modelica Class : " + _name + "\n");
460 toolTip += ("File : " + filePath() + "\n");
461 return toolTip;
462}
463
464void ModItem::openMoFolder()
465{
466 QFileInfo fileInfo(filePath());
467 LowTools::openFolder(fileInfo.absolutePath());
468}
469
470void ModItem::openInEditor()
471{
472 QUrl fileUrl(QString("file:///").append(filePath()));
473 bool ok = QDesktopServices::openUrl(fileUrl);
Value stored to 'ok' during its initialization is never read
474}