+
+//******************************************************
+QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc) const
+{
+ SessionPtr aSession = ModelAPI_Session::get();
+ DocumentPtr aRootDoc = aSession->moduleDocument();
+ if (theDoc == aRootDoc)
+ return QModelIndex();
+ else
+ return findDocumentRootIndex(theDoc.get());
+}
+
+//******************************************************
+int XGUI_DataModel::foldersCount(ModelAPI_Document* theDoc) const
+{
+ int aNb = 0;
+ SessionPtr aSession = ModelAPI_Session::get();
+ DocumentPtr aRootDoc = aSession->moduleDocument();
+ if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
+ for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
+ if (myXMLReader.rootShowEmpty(i))
+ aNb++;
+ else {
+ if (aRootDoc->size(myXMLReader.rootFolderType(i)) > 0)
+ aNb++;
+ }
+ }
+ } else {
+ for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
+ if (myXMLReader.subShowEmpty(i))
+ aNb++;
+ else {
+ if (theDoc->size(myXMLReader.subFolderType(i)) > 0)
+ aNb++;
+ }
+ }
+ }
+ return aNb;
+}
+
+
+//******************************************************
+QIntList XGUI_DataModel::missedFolderIndexes(ModelAPI_Document* theDoc) const
+{
+ QIntList aList;
+ SessionPtr aSession = ModelAPI_Session::get();
+ DocumentPtr aRootDoc = aSession->moduleDocument();
+ if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
+ for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
+ if (!myXMLReader.rootShowEmpty(i)) {
+ if (aRootDoc->size(myXMLReader.rootFolderType(i)) == 0)
+ aList.append(i);
+ }
+ }
+ } else {
+ for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
+ if (!myXMLReader.subShowEmpty(i)) {
+ if (theDoc->size(myXMLReader.subFolderType(i)) == 0)
+ aList.append(i);
+ }
+ }
+ }
+ return aList;
+}
+
+
+//******************************************************
+QStringList XGUI_DataModel::listOfShowNotEmptyFolders(bool fromRoot) const
+{
+ QStringList aResult;
+ if (fromRoot) {
+ for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
+ if (!myXMLReader.rootShowEmpty(i))
+ aResult << myXMLReader.rootFolderType(i).c_str();
+ }
+ } else {
+ for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
+ if (!myXMLReader.subShowEmpty(i))
+ aResult << myXMLReader.subFolderType(i).c_str();
+ }
+ }
+ return aResult;
+}
+
+//******************************************************
+QModelIndex XGUI_DataModel::lastHistoryIndex() const
+{
+ SessionPtr aSession = ModelAPI_Session::get();
+ DocumentPtr aCurDoc = aSession->activeDocument();
+ FeaturePtr aFeature = aCurDoc->currentFeature(true);
+ if (aFeature.get()) {
+ QModelIndex aInd = objectIndex(aFeature);
+ return createIndex(aInd.row(), 1, aInd.internalPointer());
+ } else {
+ if (aCurDoc == aSession->moduleDocument())
+ return createIndex(foldersCount() - 1, 1, -1);
+ else
+ return createIndex(foldersCount(aCurDoc.get()) - 1, 1, aCurDoc.get());
+ }
+}
+
+//******************************************************
+int XGUI_DataModel::folderId(std::string theType, ModelAPI_Document* theDoc)
+{
+ SessionPtr aSession = ModelAPI_Session::get();
+ ModelAPI_Document* aDoc = theDoc;
+ if (aDoc == 0)
+ aDoc = aSession->moduleDocument().get();
+
+ bool aUseSubDoc = (aDoc != aSession->moduleDocument().get());
+
+ int aRes = -1;
+ if (aUseSubDoc) {
+ int aId = myXMLReader.subFolderId(theType);
+ aRes = aId;
+ for (int i = 0; i < aId; i++) {
+ if (!myXMLReader.subShowEmpty(i)) {
+ if (aDoc->size(myXMLReader.subFolderType(i)) == 0)
+ aRes--;
+ }
+ }
+ } else {
+ int aId = myXMLReader.rootFolderId(theType);
+ aRes = aId;
+ for (int i = 0; i < aId; i++) {
+ if (!myXMLReader.rootShowEmpty(i)) {
+ if (aDoc->size(myXMLReader.rootFolderType(i)) == 0)
+ aRes--;
+ }
+ }
+ }
+ return aRes;
+}