-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File: ModuleBase_IDocumentDataModel.cpp
-// Created: 28 Apr 2015
-// Author: Vitaly SMETANNIKOV
+// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
#include "XGUI_DataModel.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_ObjectsBrowser.h"
+#include "XGUI_Displayer.h"
#include <ModuleBase_IconFactory.h>
XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent)//,
//myIsEventsProcessingBlocked(false)
{
+ XGUI_ObjectsBrowser* aOB = qobject_cast<XGUI_ObjectsBrowser*>(theParent);
+ myWorkshop = aOB->workshop();
+
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
// Check that new folders could appear
QStringList aNotEmptyFolders = listOfShowNotEmptyFolders();
foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
- if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) == 1))
+ if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) > 0)) {
// Appears first object in folder which can not be shown empty
- insertRow(myXMLReader->rootFolderId(aObjType));
+ if (!hasShownFolder(aRootDoc, aNotEmptyFolder)) {
+ insertRow(myXMLReader->rootFolderId(aObjType));
+ addShownFolder(aRootDoc, aNotEmptyFolder);
+ }
+ }
}
// Insert new object
int aRow = aRootDoc->size(aObjType) - 1;
}
} else {
// Object created in sub-document
- QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get());
+ QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0);
if (aDocRoot.isValid()) {
// Check that new folders could appear
QStringList aNotEmptyFolders = listOfShowNotEmptyFolders(false);
foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
- if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) == 1))
+ if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) > 0)) {
// Appears first object in folder which can not be shown empty
- insertRow(myXMLReader->subFolderId(aObjType), aDocRoot);
- }
+ if (!hasShownFolder(aDoc, aNotEmptyFolder)) {
+ insertRow(myXMLReader->subFolderId(aObjType), aDocRoot);
+ addShownFolder(aDoc, aNotEmptyFolder);
+ }
+ }
+ }
int aRow = aDoc->index(aObject);
if (aRow != -1) {
int aNbSubFolders = foldersCount(aDoc.get());
if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup) == 0)) {
// Appears first object in folder which can not be shown empty
removeRow(myXMLReader->rootFolderId(aGroup));
+ removeShownFolder(aRootDoc, aNotEmptyFolder);
//rebuildBranch(0, aNbFolders + aDoc->size(myXMLReader->rootType()));
break;
}
}
} else {
// Remove row for sub-document
- QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get());
+ QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0);
if (aDocRoot.isValid()) {
int aRow = aDoc->size(aGroup);
int aNbSubFolders = foldersCount(aDoc.get());
if ((aNotEmptyFolder.toStdString() == aGroup) && (aSize == 0)) {
// Appears first object in folder which can not be shown empty
removeRow(myXMLReader->subFolderId(aGroup), aDocRoot);
+ removeShownFolder(aDoc, aNotEmptyFolder);
//rebuildBranch(0, aNbSubFolders + aDoc->size(myXMLReader->subType()), aDocRoot);
break;
}
&& (aFeature->firstResult()->groupName() == ModelAPI_ResultField::group())) {
ResultFieldPtr aResult =
std::dynamic_pointer_cast<ModelAPI_ResultField>(aFeature->firstResult());
- QModelIndex aIndex = objectIndex(aResult);
+ QModelIndex aIndex = objectIndex(aResult, 0);
removeRows(0, aResult->stepsSize(), aIndex);
} else {
- QModelIndex aIndex = objectIndex(aObject);
+ QModelIndex aIndex = objectIndex(aObject, 0);
if (aIndex.isValid()) {
emit dataChanged(aIndex, aIndex);
}
// Update a sub-document
if (aGroup == myXMLReader->subType()) {
// Update sub-document root
- aParent = findDocumentRootIndex(aDoc.get());
+ aParent = findDocumentRootIndex(aDoc.get(), 0);
aStartId = foldersCount(aDoc.get());
} else
// update folder in sub-document
} else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOCUMENT_CHANGED)) {
DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument();
if (aDoc != aRootDoc) {
- QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get());
+ QModelIndex aDocRoot = findDocumentRootIndex(aDoc.get(), 0);
if (aDocRoot.isValid())
emit dataChanged(aDocRoot, aDocRoot);
else
}
//******************************************************
-QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject) const
+QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn) const
{
std::string aType = theObject->groupName();
DocumentPtr aDoc = theObject->document();
if (aResult.get()) {
ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult);
if (aCompRes.get()) {
- for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
- if (aCompRes->subResult(i, true) == theObject) {
- aRow = i;
- break;
- }
- }
+ aRow = ModelAPI_Tools::compSolidIndex(aResult);
}
}
}
if (aRow == -1)
return QModelIndex();
else
- return createIndex(aRow, 0, theObject.get());
+ return createIndex(aRow, theColumn, theObject.get());
}
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
// The object from sub document
aRow += foldersCount(aDoc.get());
}
- return createIndex(aRow, 0, theObject.get());
+ return createIndex(aRow, theColumn, theObject.get());
}
//******************************************************
int aNbFolders = foldersCount();
int theIndexRow = theIndex.row();
- if ((theRole == Qt::DecorationRole) && (theIndex == lastHistoryIndex()))
- return QIcon(":pictures/arrow.png");
+ if (theRole == Qt::DecorationRole) {
+ if (theIndex == lastHistoryIndex())
+ return QIcon(":pictures/arrow.png");
+ else if (theIndex.column() == 0) {
+ VisibilityState aState = getVisibilityState(theIndex);
+ switch (aState) {
+ case NoneState:
+ return QIcon();
+ case Visible:
+ return QIcon(":pictures/eyeopen.png");
+ case SemiVisible:
+ return QIcon(":pictures/eyemiclosed.png");
+ case Hidden:
+ return QIcon(":pictures/eyeclosed.png");
+ }
+ }
+ }
- if (theIndex.column() == 1)
+ //if (theIndex.column() == 1)
+ if (theIndex.column() != 1)
return QVariant();
quintptr aParentId = theIndex.internalId();
//******************************************************
int XGUI_DataModel::columnCount(const QModelIndex& theParent) const
{
- return 2;
+ return 3;
}
//******************************************************
int aObjId = theRow - aNbFolders;
if (aObjId < aRootDoc->size(aType)) {
ObjectPtr aObj = aRootDoc->object(aType, aObjId);
- aIndex = objectIndex(aObj);
+ aIndex = objectIndex(aObj, theColumn);
}
}
} else {
std::string aType = myXMLReader->rootFolderType(aParentPos);
if (theRow < aRootDoc->size(aType)) {
ObjectPtr aObj = aRootDoc->object(aType, theRow);
- aIndex = objectIndex(aObj);
+ aIndex = objectIndex(aObj, theColumn);
}
} else {
// It is an object which could have children
std::string aType = myXMLReader->subFolderType(aParentRow);
if (theRow < aDoc->size(aType)) {
ObjectPtr aObj = aDoc->object(aType, theRow);
- aIndex = objectIndex(aObj);
+ aIndex = objectIndex(aObj, theColumn);
}
}
} else {
// this is an object under sub document root
std::string aType = myXMLReader->subType();
ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders);
- aIndex = objectIndex(aObj);
+ aIndex = objectIndex(aObj, theColumn);
}
} else {
// Check for composite object
ModelAPI_CompositeFeature* aCompFeature =
dynamic_cast<ModelAPI_CompositeFeature*>(aParentObj);
if (aCompFeature) {
- aIndex = objectIndex(aCompFeature->subFeature(theRow));
+ aIndex = objectIndex(aCompFeature->subFeature(theRow), theColumn);
} else {
ModelAPI_ResultCompSolid* aCompRes =
dynamic_cast<ModelAPI_ResultCompSolid*>(aParentObj);
if (aCompRes)
- aIndex = objectIndex(aCompRes->subResult(theRow));
+ aIndex = objectIndex(aCompRes->subResult(theRow), theColumn);
else {
ModelAPI_ResultField* aFieldRes =
dynamic_cast<ModelAPI_ResultField*>(aParentObj);
if (aFieldRes) {
- aIndex = createIndex(theRow, 0, aFieldRes->step(theRow));
+ aIndex = createIndex(theRow, theColumn, aFieldRes->step(theRow));
}
}
}
}
}
}
- if (theColumn != 0)
- return createIndex(aIndex.row(), theColumn, aIndex.internalPointer());
return aIndex;
}
// return first level of folder index
int aFolderId = myXMLReader->rootFolderId(aType);
// Items in a one row must have the same parent
- return createIndex(aFolderId, 0, (void*)Q_NULLPTR);
+ return createIndex(aFolderId, 1, (void*)Q_NULLPTR);
}
} else {
if (aType == myXMLReader->subType())
// return first level of folder index
int aFolderId = folderId(aType, aSubDoc.get());
// Items in a one row must have the same parent
- return createIndex(aFolderId, 0, aSubDoc.get());
+ return createIndex(aFolderId, 1, aSubDoc.get());
}
}
}
if (aObj) {
// An object
if (aObj->isDisabled())
- return theIndex.column() == 1? Qt::ItemIsSelectable : aNullFlag;
+ return theIndex.column() == 2? Qt::ItemIsSelectable : aNullFlag;
if (aSession->moduleDocument() != aObj->document())
if (aActiveDoc != aObj->document())
- return theIndex.column() == 1? Qt::ItemIsSelectable : aNullFlag;
+ return theIndex.column() == 2? Qt::ItemIsSelectable : aNullFlag;
bool isCompositeSub = false;
- // An object which is sub-object of a composite object can not be accessible in column 1
- if (theIndex.column() == 1) {
+ // An object which is sub-object of a composite object can not be accessible in column 2
+ if (theIndex.column() == 2) {
ObjectPtr aObjPtr = aObj->data()->owner();
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObjPtr);
if (aFeature.get()) {
}
//******************************************************
-QModelIndex XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc) const
+QModelIndex
+ XGUI_DataModel::findDocumentRootIndex(const ModelAPI_Document* theDoc, int aColumn) const
{
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
if (myXMLReader->rootType() == ModelAPI_Feature::group()) {
aRow += foldersCount();
}
- return createIndex(aRow, 0, aObj.get());
+ return createIndex(aRow, aColumn, aObj.get());
}
}
} else { // If document is attached to feature
int aRow = i;
if (myXMLReader->rootType() == ModelAPI_Feature::group())
aRow += foldersCount();
- return createIndex(aRow, 0, aObj.get());
+ return createIndex(aRow, aColumn, aObj.get());
}
}
}
}
//******************************************************
-QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc) const
+QModelIndex XGUI_DataModel::documentRootIndex(DocumentPtr theDoc, int theColumn) const
{
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
if (theDoc == aRootDoc)
return QModelIndex();
else
- return findDocumentRootIndex(theDoc.get());
+ return findDocumentRootIndex(theDoc.get(), theColumn);
}
//******************************************************
FeaturePtr aFeature = aCurDoc->currentFeature(true);
if (aFeature.get()) {
QModelIndex aInd = objectIndex(aFeature);
- return createIndex(aInd.row(), 1, aInd.internalPointer());
+ return createIndex(aInd.row(), 2, aInd.internalPointer());
} else {
if (aCurDoc == aSession->moduleDocument())
- return createIndex(foldersCount() - 1, 1, -1);
+ return createIndex(foldersCount() - 1, 2, -1);
else
- return createIndex(foldersCount(aCurDoc.get()) - 1, 1, aCurDoc.get());
+ return createIndex(foldersCount(aCurDoc.get()) - 1, 2, aCurDoc.get());
}
}
// myIsEventsProcessingBlocked = theState;
// return aPreviousState;
//}
+
+//******************************************************
+XGUI_DataModel::VisibilityState
+ XGUI_DataModel::getVisibilityState(const QModelIndex& theIndex) const
+{
+ Qt::ItemFlags aFlags = theIndex.flags();
+ if (aFlags == Qt::ItemFlags())
+ return NoneState;
+
+ ObjectPtr aObj = object(theIndex);
+ if (aObj.get()) {
+ ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ if (aResObj.get()) {
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResObj);
+ if (aCompRes.get()) {
+ VisibilityState aState = aCompRes->numberOfSubs(true) == 0 ?
+ (aDisplayer->isVisible(aCompRes)? Visible : Hidden) : NoneState;
+ for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
+ ResultPtr aSubRes = aCompRes->subResult(i, true);
+ VisibilityState aS = aDisplayer->isVisible(aSubRes)? Visible : Hidden;
+ if (aState == NoneState)
+ aState = aS;
+ else if (aState != aS) {
+ aState = SemiVisible;
+ break;
+ }
+ }
+ return aState;
+ } else {
+ if (aDisplayer->isVisible(aResObj))
+ return Visible;
+ else
+ return Hidden;
+ }
+ }
+ }
+ return NoneState;
+}