X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_PartDataModel.cpp;h=d67c2ec4fc27861b06324b3a0489dfec000ee27f;hb=4224f4dbe7ceaefe74b5d6b79a5840a9f5df2d7a;hp=44b74b3207eeb7af3b1b69ac16b41011d7e11e1c;hpb=009748938269b60a5195a288513092b25b09e8d9;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 44b74b320..d67c2ec4f 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -4,13 +4,30 @@ #include #include #include +#include #include #include +#include +#include +#include +#include +#include #include +#include -XGUI_TopDataModel::XGUI_TopDataModel(const boost::shared_ptr& theDocument, QObject* theParent) - : XGUI_FeaturesModel(theDocument, theParent) + +//ObjectPtr featureObj(const ObjectPtr& theFeature) +//{ +// ObjectPtr aObject = boost::dynamic_pointer_cast(theFeature); +// if (aObject) +// return aObject->featureRef(); +// return theFeature; +//} + + +XGUI_TopDataModel::XGUI_TopDataModel(QObject* theParent) + : XGUI_FeaturesModel(theParent) { } @@ -29,17 +46,30 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - boost::shared_ptr aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row()); - if (aFeature) - return aFeature->data()->getName().c_str(); + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); + if (aObject) + return aObject->data()->name().c_str(); } + break; case ConstructFolder: return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); case ConstructObject: { - boost::shared_ptr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); - if (aFeature) - return aFeature->data()->getName().c_str(); + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + if (aObject) + return aObject->data()->name().c_str(); + } + break; + case BodiesFolder: + return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); + case BodiesObject: + { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row()); + if (aObject) + return aObject->data()->name().c_str(); } } break; @@ -49,20 +79,21 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const switch (theIndex.internalId()) { case ParamsFolder: return QIcon(":pictures/params_folder.png"); + case BodiesFolder: case ConstructFolder: return QIcon(":pictures/constr_folder.png"); case ConstructObject: - { - FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); - if (aFeature) - return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); - } + case BodiesObject: + return QIcon(":pictures/constr_object.png"); } break; case Qt::ToolTipRole: // return Tooltip break; + case Qt::ForegroundRole: + return QBrush(myItemsColor); + break; } return QVariant(); } @@ -75,14 +106,17 @@ QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation, int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const { if (!theParent.isValid()) - return 2; + return 3; + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); if (theParent.internalId() == ParamsFolder) - return myDocument->size(PARAMETERS_GROUP); + return aRootDoc->size(ModelAPI_ResultParameters::group()); if (theParent.internalId() == ConstructFolder) - return myDocument->size(CONSTRUCTIONS_GROUP); + return aRootDoc->size(ModelAPI_ResultConstruction::group()); + if (theParent.internalId() == BodiesFolder) + return aRootDoc->size(ModelAPI_ResultBody::group()); return 0; } @@ -99,6 +133,8 @@ QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelInde return createIndex(theRow, theColumn, (qint32) ParamsFolder); case 1: return createIndex(theRow, theColumn, (qint32) ConstructFolder); + case 2: + return createIndex(theRow, theColumn, (qint32) BodiesFolder); } } else { if (theParent.internalId() == ParamsFolder) @@ -106,6 +142,9 @@ QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelInde if (theParent.internalId() == ConstructFolder) return createIndex(theRow, theColumn, (qint32) ConstructObject); + + if (theParent.internalId() == BodiesFolder) + return createIndex(theRow, theColumn, (qint32) BodiesObject); } return QModelIndex(); } @@ -116,11 +155,14 @@ QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const switch (aId) { case ParamsFolder: case ConstructFolder: + case BodiesFolder: return QModelIndex(); case ParamObject: return createIndex(0, 0, (qint32) ParamsFolder); case ConstructObject: return createIndex(1, 0, (qint32) ConstructFolder); + case BodiesObject: + return createIndex(2, 0, (qint32) BodiesFolder); } return QModelIndex(); } @@ -130,47 +172,82 @@ bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const return rowCount(theParent) > 0; } -FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const +ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case ParamsFolder: case ConstructFolder: - return FeaturePtr(); + case BodiesFolder: + return ObjectPtr(); case ParamObject: - return myDocument->feature(PARAMETERS_GROUP, theIndex.row()); + { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + return aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); + } case ConstructObject: - return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + } + case BodiesObject: + { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + return aRootDoc->object(ModelAPI_ResultBody::group(), theIndex.row()); + } } - return FeaturePtr(); + return ObjectPtr(); } -QModelIndex XGUI_TopDataModel::findParent(const boost::shared_ptr& theFeature) const +QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theObject) const { - QString aGroup(theFeature->getGroup().c_str()); - - if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0) - return createIndex(0, 0, (qint32) ParamsFolder); - if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0) - return createIndex(1, 0, (qint32) ConstructFolder); - return QModelIndex(); + return findGroup(theObject->groupName().c_str()); } QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const { - if (theGroup.compare(PARAMETERS_GROUP) == 0) + if (theGroup == ModelAPI_ResultParameters::group()) return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (theGroup == ModelAPI_ResultConstruction::group()) return createIndex(1, 0, (qint32) ConstructFolder); + if (theGroup == ModelAPI_ResultBody::group()) + return createIndex(2, 0, (qint32) BodiesFolder); return QModelIndex(); } +QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const +{ + QModelIndex aIndex; + if (theObject) { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + std::string aGroup = theObject->groupName(); + int aNb = aRootDoc->size(aGroup); + int aRow = -1; + for (int i = 0; i < aNb; i++) { + if (aRootDoc->object(aGroup, i) == theObject) { + aRow = i; + break; + } + } + if (aRow != -1) { + if (aGroup == ModelAPI_ResultParameters::group()) + return createIndex(aRow, 0, (qint32) ParamObject); + if (aGroup == ModelAPI_ResultConstruction::group()) + return createIndex(aRow, 0, (qint32) ConstructObject); + if (aGroup == ModelAPI_ResultBody::group()) + return createIndex(aRow, 0, (qint32) BodiesObject); + } + } + return aIndex; +} + + //****************************************************************** //****************************************************************** //****************************************************************** -XGUI_PartDataModel::XGUI_PartDataModel(const boost::shared_ptr& theDocument, QObject* theParent) - : XGUI_PartModel(theDocument, theParent) +XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent) + : XGUI_PartModel(theParent) { } @@ -187,9 +264,10 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons switch (theIndex.internalId()) { case MyRoot: { - boost::shared_ptr aFeature = myDocument->feature(PARTS_GROUP, myId); - if (aFeature) - return aFeature->data()->getName().c_str(); + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); + if (aObject) + return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); } case ParamsFolder: return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); @@ -199,24 +277,27 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - boost::shared_ptr aFeature = - featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); - if (aFeature) - return aFeature->data()->getName().c_str(); + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row()); + if (aObject) + return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); } case ConstructObject: { - boost::shared_ptr aFeature = - featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); - if (aFeature) - return aFeature->data()->getName().c_str(); + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + if (aObject) + return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); + } + case BodiesObject: + { + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row()); + if (aObject) + return aObject->data()->name().c_str(); } case HistoryObject: { - boost::shared_ptr aFeature = - featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); - if (aFeature) - return aFeature->data()->getName().c_str(); + ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3); + if (aObject) + return aObject->data()->name().c_str(); } } break; @@ -231,15 +312,12 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons case BodiesFolder: return QIcon(":pictures/constr_folder.png"); case ConstructObject: - { - FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); - if (aFeature) - return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); - } + case BodiesObject: + return QIcon(":pictures/constr_object.png"); case HistoryObject: { - boost::shared_ptr aFeature = - featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3); + FeaturePtr aFeature = boost::dynamic_pointer_cast(aObject); if (aFeature) return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); } @@ -248,6 +326,9 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons case Qt::ToolTipRole: // return Tooltip break; + case Qt::ForegroundRole: + return QBrush(myItemsColor); + break; } return QVariant(); } @@ -259,20 +340,22 @@ QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const { - if (!parent.isValid()) - if (myDocument->feature(PARTS_GROUP, myId)) + if (!parent.isValid()) { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + if (aRootDoc->object(ModelAPI_ResultPart::group(), myId)) return 1; else return 0; + } switch (parent.internalId()) { case MyRoot: - return 3 + featureDocument()->size(FEATURES_GROUP); + return 3 + partDocument()->size(ModelAPI_Feature::group()); case ParamsFolder: - return featureDocument()->size(PARAMETERS_GROUP); + return partDocument()->size(ModelAPI_ResultParameters::group()); case ConstructFolder: - return featureDocument()->size(CONSTRUCTIONS_GROUP); + return partDocument()->size(ModelAPI_ResultConstruction::group()); case BodiesFolder: - return 0; + return partDocument()->size(ModelAPI_ResultBody::group()); } return 0; } @@ -305,7 +388,7 @@ QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelInd case ConstructFolder: return createIndex(theRow, 0, (qint32) ConstructObject); case BodiesFolder: - return createIndex(theRow, 0, (qint32) BodieswObject); + return createIndex(theRow, 0, (qint32) BodiesObject); } return QModelIndex(); } @@ -324,6 +407,8 @@ QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const return createIndex(0, 0, (qint32) ParamsFolder); case ConstructObject: return createIndex(1, 0, (qint32) ConstructFolder); + case BodiesObject: + return createIndex(2, 0, (qint32) BodiesFolder); } return QModelIndex(); } @@ -334,58 +419,94 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const } -boost::shared_ptr XGUI_PartDataModel::featureDocument() const +DocumentPtr XGUI_PartDataModel::partDocument() const { - boost::shared_ptr aFeature = myDocument->feature(PARTS_GROUP, myId); - return aFeature->data()->docRef("PartDocument")->value(); + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); + ResultPartPtr aPart = boost::dynamic_pointer_cast(aObject); + return aPart->partDoc(); } - -FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const + +ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case MyRoot: - if (theIndex.row() < 3) - return myDocument->feature(PARTS_GROUP, myId); - else - return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + { + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + return aRootDoc->object(ModelAPI_ResultPart::group(), myId); + } case ParamsFolder: case ConstructFolder: - return FeaturePtr(); + case BodiesFolder: + return ObjectPtr(); case ParamObject: - return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); + return partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row()); case ConstructObject: - return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + case BodiesObject: + return partDocument()->object(ModelAPI_ResultBody::group(), theIndex.row()); + case HistoryObject: + return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3); } - return FeaturePtr(); + return ObjectPtr(); } -bool XGUI_PartDataModel::hasDocument(const boost::shared_ptr& theDoc) const +bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const { - return (featureDocument() == theDoc); + return (partDocument() == theDoc); } -QModelIndex XGUI_PartDataModel::findParent(const boost::shared_ptr& theFeature) const +QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const { - QString aGroup(theFeature->getGroup().c_str()); - - if (theFeature->getGroup().compare(PARAMETERS_GROUP) == 0) - return createIndex(0, 0, (qint32) ParamsFolder); - if (theFeature->getGroup().compare(CONSTRUCTIONS_GROUP) == 0) - return createIndex(1, 0, (qint32) ConstructFolder); - return QModelIndex(); + return findGroup(theObject->groupName().c_str()); } QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const { - if (theGroup.compare(PARAMETERS_GROUP) == 0) + if (theGroup.compare(ModelAPI_ResultParameters::group()) == 0) return createIndex(0, 0, (qint32) ParamsFolder); - if (theGroup.compare(CONSTRUCTIONS_GROUP) == 0) + if (theGroup.compare(ModelAPI_ResultConstruction::group()) == 0) return createIndex(1, 0, (qint32) ConstructFolder); + if (theGroup.compare(ModelAPI_ResultBody::group()) == 0) + return createIndex(2, 0, (qint32) BodiesFolder); return QModelIndex(); } -FeaturePtr XGUI_PartDataModel::part() const +ResultPartPtr XGUI_PartDataModel::part() const { - return myDocument->feature(PARTS_GROUP, myId); -} \ No newline at end of file + DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId); + return boost::dynamic_pointer_cast(aObj); +} + +QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const +{ + QModelIndex aIndex; + if (theObject) { + if (part() == theObject) + return aIndex; + + std::string aGroup = theObject->groupName(); + DocumentPtr aDoc = theObject->document(); + int aNb = aDoc->size(aGroup); + int aRow = -1; + for (int i = 0; i < aNb; i++) { + if (aDoc->object(aGroup, i) == theObject) { + aRow = i; + break; + } + } + if (aRow == -1) + return aIndex; + if (aGroup == ModelAPI_ResultParameters::group()) + return createIndex(aRow, 0, (qint32) ParamObject); + else if (aGroup == ModelAPI_ResultConstruction::group()) + return createIndex(aRow, 0, (qint32) ConstructObject); + else if (aGroup == ModelAPI_ResultBody::group()) + return createIndex(aRow, 0, (qint32) BodiesObject); + else + return createIndex(aRow + 3, 0, (qint32) HistoryObject); + } + return aIndex; +}