Salome HOME
2a30656d42ea2c9766a5239445442787d9971975
[modules/shaper.git] / src / XGUI / XGUI_DataModel.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        ModuleBase_IDocumentDataModel.cpp
4 // Created:     28 Apr 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "XGUI_DataModel.h"
8
9 #include <ModuleBase_IconFactory.h>
10
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_Events.h>
13 #include <ModelAPI_ResultParameter.h>
14 #include <ModelAPI_AttributeDouble.h>
15 #include <ModelAPI_ResultPart.h>
16
17 #include <Config_FeatureMessage.h>
18
19 #include <Events_Loop.h>
20 #include <Events_Error.h>
21
22 #include <QIcon>
23 #include <QBrush>
24
25 #define ACTIVE_COLOR QColor(0,72,140)
26 #define PASSIVE_COLOR Qt::black
27
28 /// Returns ResultPart object if the given object is a Part feature
29 /// Otherwise returns NULL
30 ResultPartPtr getPartResult(ModelAPI_Object* theObj)
31 {
32   ModelAPI_Feature* aFeature = dynamic_cast<ModelAPI_Feature*>(theObj);
33   if (aFeature) {
34     ResultPtr aRes = aFeature->firstResult();
35     if (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())) {
36       return std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRes);
37     }
38   }
39   return ResultPartPtr();
40 }
41
42 /// Returns pointer on document if the given object is document object
43 ModelAPI_Document* getSubDocument(void* theObj)
44 {
45   ModelAPI_Document* aDoc = dynamic_cast<ModelAPI_Document*>((ModelAPI_Entity*)theObj);
46   return aDoc;
47 }
48
49
50
51
52 // Constructor *************************************************
53 XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent)
54 {
55   myXMLReader.readAll();
56
57   Events_Loop* aLoop = Events_Loop::loop();
58   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
59   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
60 }
61
62 //******************************************************
63 void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMessage)
64 {
65   DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
66   std::string aRootType = myXMLReader.rootType();
67   std::string aSubType = myXMLReader.subType();
68   int aNbFolders = foldersCount();
69
70   // Created object event *******************
71   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
72     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
73         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
74     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
75
76     std::set<ObjectPtr>::const_iterator aIt;
77     std::string aObjType;
78     for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
79       ObjectPtr aObject = (*aIt);
80       aObjType = aObject->groupName();
81       DocumentPtr aDoc = aObject->document();
82       if (aDoc == aRootDoc) {
83         // Check that new folders could appear
84         QStringList aNotEmptyFolders = listOfShowNotEmptyFolders();
85         foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
86           if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) == 1))
87             // Appears first object in folder which can not be shown empty
88             insertRow(myXMLReader.rootFolderId(aObjType));
89         }
90         // Insert new object
91         int aRow = aRootDoc->size(aObjType) - 1;
92         if (aObjType == aRootType) {
93           insertRow(aRow + aNbFolders + 1);
94         } else {
95           int aFolderId = myXMLReader.rootFolderId(aObjType);
96           if (aFolderId != -1) {
97             insertRow(aRow, createIndex(aFolderId, 0, -1));
98           }
99         } 
100       } else {
101         // Object created in sub-document
102         QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get());
103         if (aDocRoot.isValid()) {
104           // Check that new folders could appear
105           QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false);
106           foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
107             if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) == 1))
108               // Appears first object in folder which can not be shown empty
109               insertRow(myXMLReader.subFolderId(aObjType), aDocRoot);
110           }
111           int aRow = aDoc->size(aObjType) - 1;
112           int aNbSubFolders = foldersCount(aDoc.get());
113           if (aObjType == aSubType) {
114             // List of objects under document root
115             insertRow(aRow + aNbSubFolders, aDocRoot);
116           } else {
117             // List of objects under a folder
118             int aFolderId = myXMLReader.subFolderId(aObjType);
119             if (aFolderId != -1) {
120               insertRow(aRow, createIndex(aFolderId, 0, aDoc.get()));
121             }
122           }
123         } 
124 #ifdef _DEBUG
125         else {
126           Events_Error::send("Problem with Data Model definition of sub-document");
127         }
128 #endif
129       }
130     }
131     // Deleted object event ***********************
132   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
133     std::shared_ptr<ModelAPI_ObjectDeletedMessage> aUpdMsg =
134         std::dynamic_pointer_cast<ModelAPI_ObjectDeletedMessage>(theMessage);
135     DocumentPtr aDoc = aUpdMsg->document();
136     std::set<std::string> aGroups = aUpdMsg->groups();
137     std::set<std::string>::const_iterator aIt;
138     for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) {
139       std::string aGroup = (*aIt);
140       if (aDoc == aRootDoc) {  // If root objects
141         int aRow = aRootDoc->size(aGroup);
142         if (aGroup == aRootType) {
143           removeRow(aRow + aNbFolders);
144         } else {
145           int aFolderId = myXMLReader.rootFolderId(aGroup);
146           if (aFolderId != -1) {
147             QModelIndex aFolderIndex = createIndex(aFolderId, 0, -1);
148             removeRow(aRow, aFolderIndex);
149           }
150         }
151         // Check that some folders could erased
152         QStringList aNotEmptyFolders = listOfShowNotEmptyFolders();
153         foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
154           if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup) == 0))
155             // Appears first object in folder which can not be shown empty
156             removeRow(myXMLReader.rootFolderId(aGroup));
157         }
158       } else {
159         // Remove row for sub-document
160         QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get());
161         if (aDocRoot.isValid()) {
162           int aRow = aDoc->size(aGroup);
163           int aNbSubFolders = foldersCount(aDoc.get());
164           if (aGroup == aSubType) {
165             // List of objects under document root
166             removeRow(aRow + aNbSubFolders, aDocRoot);
167           } else {
168             // List of objects under a folder
169             int aFolderId = myXMLReader.subFolderId(aGroup);
170             if (aFolderId != -1) {
171               removeRow(aRow, createIndex(aFolderId, 0, aDoc.get()));
172             }
173           }
174           // Check that some folders could disappear
175           QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false);
176           foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
177             if ((aNotEmptyFolder.toStdString() == aGroup) && (aDoc->size(aGroup) == 1))
178               // Appears first object in folder which can not be shown empty
179               removeRow(myXMLReader.subFolderId(aGroup), aDocRoot);
180           }
181         } 
182 #ifdef _DEBUG
183         else {
184           Events_Error::send("Problem with Data Model definition of sub-document");
185         }
186 #endif
187       }
188     }
189   } 
190 }
191
192 //******************************************************
193 void XGUI_DataModel::clear()
194 {
195
196 }
197
198 //******************************************************
199 void XGUI_DataModel::rebuildDataTree()
200 {
201
202 }
203
204 //******************************************************
205 ObjectPtr XGUI_DataModel::object(const QModelIndex& theIndex) const
206 {
207   if (theIndex.internalId() < 0) // this is a folder
208     return ObjectPtr();
209   ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
210   if (getSubDocument(aObj)) // the selected index is a folder of sub-document
211     return ObjectPtr();
212
213   // We can not create the ObjectPtr directly because the pointer will be deleted 
214   // with deletion of the ObjectPtr because its counter become to 0.
215   DocumentPtr aDoc = aObj->document();
216   std::string aType = aObj->groupName();
217
218   ObjectPtr aObjPtr;
219   for (int i = 0; i < aDoc->size(aType); i++) {
220     aObjPtr = aDoc->object(aType, i);
221     if (aObjPtr.get() == aObj)
222       return aObjPtr;
223   }
224   return ObjectPtr();
225 }
226
227 //******************************************************
228 QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject) const
229 {
230   std::string aType = theObject->groupName();
231   DocumentPtr aDoc = theObject->document();
232   int aRow = aDoc->index(theObject);
233   if (aRow == -1)
234     return QModelIndex();
235
236   SessionPtr aSession = ModelAPI_Session::get();
237   DocumentPtr aRootDoc = aSession->moduleDocument();
238   if (aDoc == aRootDoc && myXMLReader.rootType() == aType) { 
239     // The object from root document
240     aRow += foldersCount();
241   } else if (myXMLReader.subType() == aType) { 
242     // The object from sub document
243     aRow += foldersCount(aDoc.get());
244   }
245   return createIndex(aRow, 0, theObject.get());
246 }
247
248 //******************************************************
249 QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
250 {
251   SessionPtr aSession = ModelAPI_Session::get();
252   DocumentPtr aRootDoc = aSession->moduleDocument();
253   int aNbFolders = foldersCount();
254   int theIndexRow = theIndex.row();
255
256   if ((theIndex.column() == 1) ) {
257     //if (theIndexRow >= aNbFolders) {
258     //  if (theRole == Qt::DecorationRole) {
259     //    return QIcon(":pictures/arrow.png");
260     //  }
261     //}
262     return QVariant();
263   }
264
265   int aParentId = theIndex.internalId();
266   if (aParentId == -1) { // root folders
267     switch (theRole) {
268       case Qt::DisplayRole:
269         return QString(myXMLReader.rootFolderName(theIndexRow).c_str()) + 
270           QString(" (%1)").arg(rowCount(theIndex));
271       case Qt::DecorationRole:
272         return QIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str());
273       case Qt::ForegroundRole:
274         if (aRootDoc->isActive())
275           return QBrush(ACTIVE_COLOR);
276         else
277           return QBrush(PASSIVE_COLOR);
278     }
279   } else {
280     ModelAPI_Document* aSubDoc = getSubDocument(theIndex.internalPointer());
281
282     if (theRole == Qt::ForegroundRole) {
283       bool aIsActive = false;
284       if (aSubDoc)
285         aIsActive = aSubDoc->isActive();
286       else {
287         ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
288         aIsActive = aObj->document()->isActive();
289       }
290       if (aIsActive)
291         return QBrush(ACTIVE_COLOR);
292       else
293         return QBrush(PASSIVE_COLOR);
294     }
295
296     if (aSubDoc) { // this is a folder of sub document
297       switch (theRole) {
298         case Qt::DisplayRole:
299           return QString(myXMLReader.subFolderName(theIndexRow).c_str()) + 
300             QString(" (%1)").arg(rowCount(theIndex));
301         case Qt::DecorationRole:
302           return QIcon(myXMLReader.subFolderIcon(theIndexRow).c_str());
303       }
304     } else {
305       ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
306       switch (theRole) {
307       case Qt::DisplayRole:
308         if (aObj->groupName() == ModelAPI_ResultParameter::group()) {
309           ModelAPI_ResultParameter* aParam = dynamic_cast<ModelAPI_ResultParameter*>(aObj);
310           AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
311           QString aVal = QString::number(aValueAttribute->value());
312           QString aTitle = QString(aObj->data()->name().c_str());
313           return aTitle + " = " + aVal;
314         }
315         return aObj->data()->name().c_str();
316       case Qt::DecorationRole:
317         return ModuleBase_IconFactory::get()->getIcon(object(theIndex));
318       }
319     }
320   }
321   return QVariant();
322 }
323
324 //******************************************************
325 QVariant XGUI_DataModel::headerData(int theSection, Qt::Orientation theOrient, int theRole) const
326 {
327   return QVariant();
328 }
329
330 //******************************************************
331 int XGUI_DataModel::rowCount(const QModelIndex& theParent) const
332 {
333   SessionPtr aSession = ModelAPI_Session::get();
334   if (!aSession->hasModuleDocument())
335     return 0;
336   DocumentPtr aRootDoc = aSession->moduleDocument();
337
338   if (!theParent.isValid()) {
339     // Return number of items in root
340     int aNbFolders = foldersCount();
341     int aNbItems = 0;
342     std::string aType = myXMLReader.rootType();
343     if (!aType.empty())
344       aNbItems = aRootDoc->size(aType);
345     return aNbFolders + aNbItems;
346   }
347
348   int aId = theParent.internalId();
349   if (aId == -1) { 
350     // this is a folder under root
351     int aParentPos = theParent.row();
352     std::string aType = myXMLReader.rootFolderType(aParentPos);
353     //qDebug("### %s = %i\n", aType.c_str(), aRootDoc->size(aType));
354     return aRootDoc->size(aType);
355   } else {
356     // It is an object which could have children
357     ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
358     if (aDoc) { 
359       // a folder of sub-document
360       std::string aType = myXMLReader.subFolderType(theParent.row());
361       return aDoc->size(aType);
362     } else {
363       // Check for Part feature
364       ModelAPI_Object* aObj = (ModelAPI_Object*)theParent.internalPointer();
365       ResultPartPtr aPartRes = getPartResult(aObj);
366       if (aPartRes.get()) {
367         DocumentPtr aSubDoc = aPartRes->partDoc();
368         int aNbSubFolders = foldersCount(aSubDoc.get());
369         int aNbSubItems = 0;
370         std::string aSubType = myXMLReader.subType();
371         if (!aSubType.empty())
372           aNbSubItems = aSubDoc->size(aSubType);
373         return aNbSubItems + aNbSubFolders;
374       }
375     }
376   }
377   return 0;
378 }
379
380 //******************************************************
381 int XGUI_DataModel::columnCount(const QModelIndex& theParent) const
382 {
383   return 2;
384 }
385
386 //******************************************************
387 QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
388 {
389   SessionPtr aSession = ModelAPI_Session::get();
390   DocumentPtr aRootDoc = aSession->moduleDocument();
391   int aNbFolders = foldersCount();
392
393   if (!theParent.isValid()) {
394     if (theRow < aNbFolders) // Return first level folder index
395       return createIndex(theRow, theColumn, -1);
396     else { // return object under root index
397       std::string aType = myXMLReader.rootType();
398       int aObjId = theRow - aNbFolders;
399       if (aObjId < aRootDoc->size(aType)) {
400         ObjectPtr aObj = aRootDoc->object(aType, aObjId);
401         QModelIndex aIndex = objectIndex(aObj);
402         if (theColumn != 0)
403           return createIndex(aIndex.row(), theColumn, aIndex.internalPointer());
404         return aIndex;
405       }
406       return QModelIndex();
407     }
408   }
409   int aId = theParent.internalId();
410   int aParentPos = theParent.row();
411   if (aId == -1) { // return object index inside of first level of folders
412     std::string aType = myXMLReader.rootFolderType(aParentPos);
413     if (theRow < aRootDoc->size(aType)) {
414       ObjectPtr aObj = aRootDoc->object(aType, theRow);
415       QModelIndex aIndex = objectIndex(aObj);
416       if (theColumn != 0)
417         return createIndex(aIndex.row(), theColumn, aIndex.internalPointer());
418       return aIndex;
419     }
420   } else {
421     // It is an object which could have children
422     ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
423     if (aDoc) { 
424       // It is a folder of sub-document
425       std::string aType = myXMLReader.subFolderType(aParentPos);
426       if (theRow < aDoc->size(aType)) {
427         ObjectPtr aObj = aDoc->object(aType, theRow);
428         QModelIndex aIndex = objectIndex(aObj);
429         if (theColumn != 0)
430           return createIndex(aIndex.row(), theColumn, aIndex.internalPointer());
431         return aIndex;
432       }
433     } else {
434       ModelAPI_Object* aParentObj = (ModelAPI_Object*)theParent.internalPointer();
435
436       // Check for Part feature
437       ResultPartPtr aPartRes = getPartResult(aParentObj);
438       if (aPartRes.get()) {
439         DocumentPtr aSubDoc = aPartRes->partDoc();
440         int aNbSubFolders = foldersCount(aSubDoc.get());
441         if (theRow < aNbSubFolders) { // Create a Folder of sub-document
442           return createIndex(theRow, theColumn, aSubDoc.get());
443         } else {
444           // this is an object under sub document root
445           std::string aType = myXMLReader.subType();
446           ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders);
447           QModelIndex aIndex = objectIndex(aObj);
448           if (theColumn != 0)
449             return createIndex(aIndex.row(), theColumn, aIndex.internalPointer());
450           return aIndex;
451         }
452       }
453     }
454   }
455   return QModelIndex();
456 }
457
458 //******************************************************
459 QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const
460 {
461   int aId = theIndex.internalId();
462   if (aId != -1) { // The object is not a root folder
463     ModelAPI_Document* aDoc = getSubDocument(theIndex.internalPointer());
464     if (aDoc) { 
465       // It is a folder of sub-document
466       return findDocumentRootIndex(aDoc);
467     }
468     ModelAPI_Object* aObj = (ModelAPI_Object*) theIndex.internalPointer();
469     std::string aType = aObj->groupName();
470     SessionPtr aSession = ModelAPI_Session::get();
471     DocumentPtr aRootDoc = aSession->moduleDocument();
472     DocumentPtr aSubDoc = aObj->document();
473     if (aSubDoc == aRootDoc) {
474       if (aType == myXMLReader.rootType())
475         return QModelIndex();
476       else {
477         // return first level of folder index
478         int aFolderId = myXMLReader.rootFolderId(aType);
479         // Items in a one row must have the same parent
480         return createIndex(aFolderId, 0, -1);
481       }
482     } else {
483       if (aType == myXMLReader.subType())
484         return findDocumentRootIndex(aSubDoc.get());
485       else {
486         // return first level of folder index
487         int aFolderId = myXMLReader.subFolderId(aType);
488         // Items in a one row must have the same parent
489         return createIndex(aFolderId, 0, aSubDoc.get());
490       }
491     }
492   } 
493   return QModelIndex();
494 }
495
496 //******************************************************
497 bool XGUI_DataModel::hasChildren(const QModelIndex& theParent) const
498 {
499   if (!theParent.isValid()) {
500     int aNbFolders = foldersCount();
501     if (aNbFolders > 0)
502       return true;
503     SessionPtr aSession = ModelAPI_Session::get();
504     DocumentPtr aRootDoc = aSession->moduleDocument();
505     return aRootDoc->size(myXMLReader.rootType()) > 0;
506   }
507   if (theParent.internalId() == -1) {
508     std::string aType = myXMLReader.rootFolderType(theParent.row());
509     if (!aType.empty()) {
510       SessionPtr aSession = ModelAPI_Session::get();
511       DocumentPtr aRootDoc = aSession->moduleDocument();
512       return aRootDoc->size(aType) > 0;
513     }
514   } else {
515     ModelAPI_Document* aDoc = getSubDocument(theParent.internalPointer());
516     if (aDoc) { 
517       // a folder of sub-document
518       std::string aType = myXMLReader.subFolderType(theParent.row());
519       return aDoc->size(aType) > 0;
520     } else {
521       // Check that it could be an object with children
522       ModelAPI_Object* aObj = (ModelAPI_Object*)theParent.internalPointer();
523
524       // Check for Part feature
525       ResultPartPtr aPartRes = getPartResult(aObj);
526       if (aPartRes.get())
527         return true;
528     }
529   }
530   return false;
531 }
532
533 //******************************************************
534 bool XGUI_DataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
535 {
536   beginInsertRows(theParent, theRow, theRow + theCount - 1);
537   endInsertRows();
538
539   return true;
540 }
541
542 //******************************************************
543 bool XGUI_DataModel::removeRows(int theRow, int theCount, const QModelIndex& theParent)
544 {
545   beginRemoveRows(theParent, theRow, theRow + theCount - 1);
546   endRemoveRows();
547   return true;
548 }
549
550 //******************************************************
551 Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const
552 {
553   Qt::ItemFlags aFlags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
554   if (theIndex.internalId() > -1) {
555     aFlags |= Qt::ItemIsEditable;
556   }
557   return aFlags;
558 }
559
560 //******************************************************
561 QModelIndex XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc) const
562 {
563   SessionPtr aSession = ModelAPI_Session::get();
564   DocumentPtr aRootDoc = aSession->moduleDocument();
565   if (myXMLReader.isAttachToResult()) { // If document is attached to result
566     int aNb = aRootDoc->size(ModelAPI_ResultPart::group());
567     ObjectPtr aObj;
568     ResultPartPtr aPartRes;
569     for (int i = 0; i < aNb; i++) {
570       aObj = aRootDoc->object(ModelAPI_ResultPart::group(), i);
571       aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
572       if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
573         int aRow = i;
574         if (myXMLReader.rootType() == ModelAPI_Feature::group())
575           aRow += foldersCount();
576         return createIndex(aRow, 0, aObj.get());
577       }
578     }
579   } else { // If document is attached to feature
580     int aNb = aRootDoc->size(ModelAPI_Feature::group());
581     ObjectPtr aObj;
582     ResultPartPtr aPartRes;
583     for (int i = 0; i < aNb; i++) {
584       aObj = aRootDoc->object(ModelAPI_Feature::group(), i);
585       aPartRes = getPartResult(aObj.get());
586       if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
587         int aRow = i;
588         if (myXMLReader.rootType() == ModelAPI_Feature::group())
589           aRow += foldersCount();
590         return createIndex(aRow, 0, aObj.get());
591       }
592     }
593   }
594   return QModelIndex();
595 }
596
597 //******************************************************
598 QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc) const
599 {
600   SessionPtr aSession = ModelAPI_Session::get();
601   DocumentPtr aRootDoc = aSession->moduleDocument();
602   if (theDoc == aRootDoc)
603     return QModelIndex();
604   else 
605     return findDocumentRootIndex(theDoc.get());
606 }
607
608 //******************************************************
609 int XGUI_DataModel::foldersCount(ModelAPI_Document* theDoc) const
610 {
611   int aNb = 0;
612   SessionPtr aSession = ModelAPI_Session::get();
613   DocumentPtr aRootDoc = aSession->moduleDocument();
614   if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
615     for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
616       if (myXMLReader.rootShowEmpty(i))
617         aNb++;
618       else {
619         if (aRootDoc->size(myXMLReader.rootFolderType(i)) > 0)
620           aNb++;
621       }
622     }
623   } else {
624     for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
625       if (myXMLReader.subShowEmpty(i))
626         aNb++;
627       else {
628         if (theDoc->size(myXMLReader.subFolderType(i)) > 0)
629           aNb++;
630       }
631     }
632   }
633   return aNb;
634 }
635
636 //******************************************************
637 QStringList XGUI_DataModel::listOfShowNotEmptyFolders(bool fromRoot) const
638 {
639   QStringList aResult;
640   if (fromRoot) {
641     for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
642       if (!myXMLReader.rootShowEmpty(i))
643         aResult << myXMLReader.rootFolderType(i).c_str();
644     }
645   } else {
646     for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
647       if (!myXMLReader.subShowEmpty(i))
648         aResult << myXMLReader.subFolderType(i).c_str();
649     }
650   }
651   return aResult;
652 }