X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_DocumentDataModel.cpp;h=6082e445bb56df332252a752caa11c14477e13dd;hb=4224f4dbe7ceaefe74b5d6b79a5840a9f5df2d7a;hp=b4cc62c0c9f4d5f8bc6a6fba6cd41dffd6301903;hpb=12621bb509825d0eb1fb0847a7f9c8011021ca5a;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index b4cc62c0c..6082e445b 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -7,7 +7,8 @@ #include #include #include -#include +#include +#include #include #include @@ -18,6 +19,7 @@ #include #include +#include #define ACTIVE_COLOR QColor(0,72,140) #define PASSIVE_COLOR Qt::black @@ -26,9 +28,9 @@ XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent) : QAbstractItemModel(theParent), myActivePart(0) { // Register in event loop - Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED)); - Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); - Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED)); + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED)); + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); // Create a top part of data tree model myModel = new XGUI_TopDataModel(this); @@ -47,16 +49,20 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); // Created object event ******************* - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) { - const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); - std::set aFeatures = aUpdMsg->features(); - - std::set::const_iterator aIt; - for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { - FeaturePtr aFeature = (*aIt); - DocumentPtr aDoc = aFeature->document(); + if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) { + const ModelAPI_ObjectUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); + std::set aObjects = aUpdMsg->objects(); + + std::set::const_iterator aIt; + for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) { + ObjectPtr aObject = (*aIt); + FeaturePtr aFeature = boost::dynamic_pointer_cast(aObject); + if (aFeature && (!aFeature->isInHistory())) + continue; + + DocumentPtr aDoc = aObject->document(); if (aDoc == aRootDoc) { // If root objects - if (aFeature->getGroup().compare(PARTS_GROUP) == 0) { // Update only Parts group + if (aObject->groupName() == ModelAPI_ResultPart::group()) { // Update only Parts group // Add a new part int aStart = myPartModels.size(); XGUI_PartDataModel* aModel = new XGUI_PartDataModel(this); @@ -64,8 +70,9 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) myPartModels.append(aModel); insertRow(aStart, partFolderNode()); } else { // Update top groups (other except parts - QModelIndex aIndex = myModel->findParent(aFeature); + QModelIndex aIndex = myModel->findParent(aObject); int aStart = myModel->rowCount(aIndex) - 1; + if (aStart < 0) aStart = 0; aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)); insertRow(aStart, aIndex); } @@ -79,16 +86,16 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) } } if (aPartModel) { - QModelIndex aIndex = aPartModel->findParent(aFeature); - int aStart = aPartModel->rowCount(aIndex) - 1; + QModelIndex aIndex = aPartModel->findParent(aObject); + int aStart = aPartModel->rowCount(aIndex); // check this index aIndex = createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)); insertRow(aStart, aIndex); } } } // Deleted object event *********************** - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) { - const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast(theMessage); + } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) { + const ModelAPI_ObjectDeletedMessage* aUpdMsg = dynamic_cast(theMessage); DocumentPtr aDoc = aUpdMsg->document(); std::set aGroups = aUpdMsg->groups(); @@ -96,7 +103,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) { std::string aGroup = (*aIt); if (aDoc == aRootDoc) { // If root objects - if (aGroup.compare(PARTS_GROUP) == 0) { // Updsate only Parts group + if (aGroup == ModelAPI_ResultPart::group()) { // Update only Parts group int aStart = myPartModels.size() - 1; removeSubModel(aStart); removeRow(aStart, partFolderNode()); @@ -129,9 +136,9 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) } } // Deleted object event *********************** - } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) { - //const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); - //FeaturePtr aFeature = aUpdMsg->feature(); + } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) { + //const ModelAPI_ObjectUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); + //ObjectPtr aFeature = aUpdMsg->feature(); //DocumentPtr aDoc = aFeature->document(); // TODO: Identify the necessary index by the modified feature @@ -151,7 +158,7 @@ void XGUI_DocumentDataModel::rebuildDataTree() beginResetModel(); clearModelIndexes(); - int aNbParts = aRootDoc->size(PARTS_GROUP); + int aNbParts = aRootDoc->size(ModelAPI_ResultPart::group()); if (myPartModels.size() != aNbParts) { // resize internal models while (myPartModels.size() > aNbParts) { delete myPartModels.last(); @@ -192,13 +199,14 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) { int aOffset = historyOffset(); DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - FeaturePtr aFeature = aRootDoc->feature(FEATURES_GROUP, theIndex.row() - aOffset); + ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); + FeaturePtr aFeature = boost::dynamic_pointer_cast(aObj); if (!aFeature) return QVariant(); switch (theRole) { case Qt::DisplayRole: if (aFeature) - return aFeature->data()->getName().c_str(); + return aFeature->data()->name().c_str(); else return QVariant(); case Qt::DecorationRole: @@ -236,10 +244,11 @@ int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const // Size of external models int aVal = historyOffset(); // Plus history size - aVal += aRootDoc->size(FEATURES_GROUP); + aVal += aRootDoc->size(ModelAPI_Feature::group()); return aVal; } if (theParent.internalId() == PartsFolder) { + int aSize = myPartModels.size(); return myPartModels.size(); } if (theParent.internalId() == HistoryNode) { @@ -357,21 +366,21 @@ void XGUI_DocumentDataModel::clearModelIndexes() myIndexes.clear(); } -FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const +ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const { if (theIndex.internalId() == PartsFolder) - return FeaturePtr(); + return ObjectPtr(); if (theIndex.internalId() == HistoryNode) { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); int aOffset = historyOffset(); - return aRootDoc->feature(FEATURES_GROUP, theIndex.row() - aOffset); + return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset); } QModelIndex* aIndex = toSourceModelIndex(theIndex); if (!isSubModel(aIndex->model())) - return FeaturePtr(); + return ObjectPtr(); const XGUI_FeaturesModel* aModel = dynamic_cast(aIndex->model()); - return aModel->feature(*aIndex); + return aModel->object(*aIndex); } bool XGUI_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent) @@ -474,11 +483,11 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) return false; } -FeaturePtr XGUI_DocumentDataModel::activePart() const +ResultPartPtr XGUI_DocumentDataModel::activePart() const { if (myActivePart) return myActivePart->part(); - return FeaturePtr(); + return ResultPartPtr(); } void XGUI_DocumentDataModel::deactivatePart() @@ -493,21 +502,19 @@ void XGUI_DocumentDataModel::deactivatePart() Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const { Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex); - if (feature(theIndex)) { + if (object(theIndex)) { aFlags |= Qt::ItemIsEditable; } return aFlags; } -QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const +QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const { - FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature); - int aRow = -1; XGUI_PartModel* aModel = 0; foreach (XGUI_PartModel* aPartModel, myPartModels) { aRow++; - if (aPartModel->part() == aFeature) { + if (aPartModel->part() == theObject) { aModel = aPartModel; break; } @@ -518,22 +525,25 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) cons return QModelIndex(); } -QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) const +QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const { // Check that this feature belongs to root document DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - DocumentPtr aDoc = theFeature->document(); + DocumentPtr aDoc = theObject->document(); if (aDoc == aRootDoc) { // This feature belongs to histrory or top model - if (theFeature->isInHistory()) { + FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); + if (aFeature) { int aId; - for (aId = 0; aId < aRootDoc->size(FEATURES_GROUP); aId++) { - if (theFeature == aRootDoc->feature(FEATURES_GROUP, aId)) + int aNb = aRootDoc->size(ModelAPI_Feature::group()); + for (aId = 0; aId < aNb; aId++) { + if (theObject == aRootDoc->object(ModelAPI_Feature::group(), aId)) break; } - return index(aId + historyOffset(), 0, QModelIndex()); + if (aId < aNb) + return index(aId + historyOffset(), 0, QModelIndex()); } else { - QModelIndex aIndex = myModel->featureIndex(theFeature); + QModelIndex aIndex = myModel->objectIndex(theObject); return aIndex.isValid()? createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) : QModelIndex(); @@ -547,11 +557,11 @@ QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) co } } if (aPartModel) { - QModelIndex aIndex = aPartModel->featureIndex(theFeature); + QModelIndex aIndex = aPartModel->objectIndex(theObject); return aIndex.isValid()? createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) : QModelIndex(); } } return QModelIndex(); -} \ No newline at end of file +}