From 9a9c265e7d0eb452ef287121a04a7de0b8ca2325 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 14 Jul 2014 18:09:45 +0400 Subject: [PATCH] XGUI package is adapted to new Model architecture --- src/XGUI/XGUI_DocumentDataModel.cpp | 17 ++-- src/XGUI/XGUI_ObjectsBrowser.cpp | 17 ++-- src/XGUI/XGUI_ObjectsBrowser.h | 3 +- src/XGUI/XGUI_PartDataModel.cpp | 36 +++++---- src/XGUI/XGUI_Workshop.cpp | 119 +++++++++++++--------------- src/XGUI/XGUI_Workshop.h | 9 ++- src/XGUI/XGUI_pictures.qrc | 1 + src/XGUI/pictures/constr_object.png | Bin 0 -> 425 bytes 8 files changed, 100 insertions(+), 102 deletions(-) create mode 100644 src/XGUI/pictures/constr_object.png diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 429012470..24b422421 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -193,7 +193,8 @@ QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) { int aOffset = historyOffset(); DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - ObjectPtr aFeature = aRootDoc->object(ModelAPI_Feature::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) { @@ -372,7 +373,7 @@ ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const 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) @@ -475,11 +476,11 @@ bool XGUI_DocumentDataModel::activatedIndex(const QModelIndex& theIndex) return false; } -ObjectPtr XGUI_DocumentDataModel::activePart() const +ResultPartPtr XGUI_DocumentDataModel::activePart() const { if (myActivePart) return myActivePart->part(); - return ObjectPtr(); + return ResultPartPtr(); } void XGUI_DocumentDataModel::deactivatePart() @@ -500,7 +501,7 @@ Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const return aFlags; } -QModelIndex XGUI_DocumentDataModel::partIndex(const ObjectPtr& theObject) const +QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const { int aRow = -1; XGUI_PartModel* aModel = 0; @@ -517,7 +518,7 @@ QModelIndex XGUI_DocumentDataModel::partIndex(const ObjectPtr& theObject) const return QModelIndex(); } -QModelIndex XGUI_DocumentDataModel::featureIndex(const ObjectPtr theObject) const +QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const { // Check that this feature belongs to root document DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); @@ -532,7 +533,7 @@ QModelIndex XGUI_DocumentDataModel::featureIndex(const ObjectPtr theObject) cons } return index(aId + historyOffset(), 0, QModelIndex()); } else { - QModelIndex aIndex = myModel->featureIndex(theObject); + QModelIndex aIndex = myModel->objectIndex(theObject); return aIndex.isValid()? createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) : QModelIndex(); @@ -546,7 +547,7 @@ QModelIndex XGUI_DocumentDataModel::featureIndex(const ObjectPtr theObject) cons } } if (aPartModel) { - QModelIndex aIndex = aPartModel->featureIndex(theObject); + QModelIndex aIndex = aPartModel->objectIndex(theObject); return aIndex.isValid()? createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) : QModelIndex(); diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 5d9d000e3..6e61fef19 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -46,9 +46,9 @@ void XGUI_DataTree::onSelectionChanged(const QItemSelection& theSelected, XGUI_DocumentDataModel* aModel = dataModel(); QModelIndexList::const_iterator aIt; for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { - ObjectPtr aFeature = aModel->feature(*aIt); - if (aFeature) - mySelectedData.append(aFeature); + ObjectPtr aObject = aModel->object(*aIt); + if (aObject) + mySelectedData.append(aObject); } emit selectionChanged(); } @@ -86,10 +86,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor) ObjectPtr aFeature = mySelectedData.first(); PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); aMgr->rootDocument()->startOperation(); - if (!XGUI_Tools::isModelObject(aFeature)) - aFeature->data()->setName(qPrintable(aRes)); - else - boost::dynamic_pointer_cast(aFeature)->setName(qPrintable(aRes)); + aFeature->data()->setName(qPrintable(aRes)); aMgr->rootDocument()->finishOperation(); } } @@ -235,7 +232,7 @@ void XGUI_ObjectsBrowser::closeDocNameEditing(bool toSave) } //*************************************************** -void XGUI_ObjectsBrowser::activatePart(const ObjectPtr& thePart) +void XGUI_ObjectsBrowser::activatePart(const ResultPartPtr& thePart) { if (thePart) { QModelIndex aIndex = myDocModel->partIndex(thePart); @@ -248,7 +245,7 @@ void XGUI_ObjectsBrowser::activatePart(const ObjectPtr& thePart) if (myDocModel->activePartIndex().isValid()) { myTreeView->setExpanded(aIndex.parent(), true); myTreeView->setExpanded(aIndex, true); - onActivePartChanged(myDocModel->feature(aIndex)); + onActivePartChanged(myDocModel->object(aIndex)); } else { onActivePartChanged(ObjectPtr()); } @@ -266,7 +263,7 @@ void XGUI_ObjectsBrowser::activatePart(const ObjectPtr& thePart) //*************************************************** void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent) { - myObjectsList = myTreeView->selectedFeatures(); + myObjectsList = myTreeView->selectedObjects(); bool toEnable = myObjectsList.size() > 0; foreach(QAction* aCmd, actions()) { aCmd->setEnabled(toEnable); diff --git a/src/XGUI/XGUI_ObjectsBrowser.h b/src/XGUI/XGUI_ObjectsBrowser.h index edcddc628..05a539566 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.h +++ b/src/XGUI/XGUI_ObjectsBrowser.h @@ -5,6 +5,7 @@ #include "XGUI.h" #include #include +#include #include #include @@ -76,7 +77,7 @@ public: XGUI_DataTree* treeView() const { return myTreeView; } //! Activates currently selected part. Signal activePartChanged will not be sent - void activatePart(const ObjectPtr& thePart); + void activatePart(const ResultPartPtr& thePart); void rebuildDataTree(); diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index c9e98b5d4..b77297f54 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -70,12 +70,13 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const case ConstructFolder: return QIcon(":pictures/constr_folder.png"); case ConstructObject: - { - DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); - if (aObject) - return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); - } + return QIcon(":pictures/constr_object.png"); + //{ + // DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); + // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + // if (aObject) + // return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); + //} } break; @@ -238,7 +239,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId); if (aObject) - return boost::dynamic_pointer_cast(aObject)->getName().c_str(); + return boost::dynamic_pointer_cast(aObject)->data()->name().c_str(); } case ParamsFolder: return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); @@ -277,16 +278,18 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons case BodiesFolder: return QIcon(":pictures/constr_folder.png"); case ConstructObject: - { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); - if (aObject) - return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); - } + return QIcon(":pictures/constr_object.png"); + //{ + // ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); + // if (aObject) + // return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); + //} case HistoryObject: { ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3); - if (aObject) - return QIcon(XGUI_Workshop::featureIcon(aObject->getKind())); + FeaturePtr aFeature = boost::dynamic_pointer_cast(aObject); + if (aFeature) + return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); } } break; @@ -435,10 +438,11 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const return QModelIndex(); } -ObjectPtr XGUI_PartDataModel::part() const +ResultPartPtr XGUI_PartDataModel::part() const { DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument(); - return aRootDoc->object(ModelAPI_ResultPart::group(), myId); + ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId); + return boost::dynamic_pointer_cast(aObj); } QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 78c7cc717..dddd97fb6 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -273,13 +274,13 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) //****************************************************** void XGUI_Workshop::onFeatureUpdatedMsg(const Model_ObjectUpdatedMessage* theMsg) { - std::set aFeatures = theMsg->features(); + std::set aFeatures = theMsg->features(); if (myOperationMgr->hasOperation()) { FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature(); - std::set::const_iterator aIt; + std::set::const_iterator aIt; for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { - FeaturePtr aNewFeature = (*aIt); + ObjectPtr aNewFeature = (*aIt); if(aNewFeature == aCurrentFeature) { myPropertyPanel->updateContentWidget(aCurrentFeature); break; @@ -291,13 +292,13 @@ void XGUI_Workshop::onFeatureUpdatedMsg(const Model_ObjectUpdatedMessage* theMsg //****************************************************** void XGUI_Workshop::onFeatureRedisplayMsg(const Model_ObjectUpdatedMessage* theMsg) { - std::set aFeatures = theMsg->features(); - std::set::const_iterator aIt; + std::set aFeatures = theMsg->features(); + std::set::const_iterator aIt; bool isDisplayed = false; for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { - FeaturePtr aFeature = (*aIt); - if (aFeature->getKind() != PARTSET_PART_KIND) { - isDisplayed = myDisplayer->redisplay(aFeature, false); + ResultPtr aRes = boost::dynamic_pointer_cast(*aIt); + if (aRes) { + isDisplayed = myDisplayer->redisplay(aRes, false); } } if (isDisplayed) @@ -307,18 +308,20 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const Model_ObjectUpdatedMessage* theM //****************************************************** void XGUI_Workshop::onFeatureCreatedMsg(const Model_ObjectUpdatedMessage* theMsg) { - std::set aFeatures = theMsg->features(); + std::set aFeatures = theMsg->features(); - std::set::const_iterator aIt; + std::set::const_iterator aIt; bool aHasPart = false; bool isDisplayed = false; for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) { - FeaturePtr aFeature = (*aIt); - if (aFeature->getKind() == PARTSET_PART_KIND) { + ResultPartPtr aPart = boost::dynamic_pointer_cast(*aIt); + if (aPart) { aHasPart = true; //break; } else { - isDisplayed = myDisplayer->display(aFeature, false); + ResultPtr aRes = boost::dynamic_pointer_cast(*aIt); + if (aRes) + isDisplayed = myDisplayer->display(aRes, false); } } if (isDisplayed) @@ -824,19 +827,13 @@ void XGUI_Workshop::onFeatureTriggered() } //****************************************************** -void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart) +void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj) { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - if (thePart) { - DocumentPtr aFeaDoc; - if (!XGUI_Tools::isModelObject(thePart)) { - aFeaDoc = thePart->data()->docRef("PartDocument")->value(); - } else { - ObjectPtr aObject = boost::dynamic_pointer_cast(thePart); - aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value(); - } - if (aFeaDoc) - aMgr->setCurrentDocument(aFeaDoc); + if (theObj) { + DocumentPtr aPartDoc = theObj->document(); + if (aPartDoc) + aMgr->setCurrentDocument(aPartDoc); } else { aMgr->setCurrentDocument(aMgr->rootDocument()); } @@ -858,17 +855,19 @@ XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const //************************************************************** void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) { - QFeatureList aFeatures = mySelector->selection()->selectedFeatures(); - if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0)) - activatePart(aFeatures.first()); - else if (theId == "DEACTIVATE_PART_CMD") - activatePart(FeaturePtr()); + QList aObjects = mySelector->selection()->selectedObjects(); + if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) { + ResultPartPtr aPart = boost::dynamic_pointer_cast(aObjects.first()); + if (aPart) + activatePart(aPart); + } else if (theId == "DEACTIVATE_PART_CMD") + activatePart(ResultPartPtr()); else if (theId == "DELETE_CMD") - deleteFeatures(aFeatures); + deleteObjects(aObjects); else if (theId == "SHOW_CMD") - showFeatures(aFeatures, true); + showObjects(aObjects, true); else if (theId == "HIDE_CMD") - showFeatures(aFeatures, false); + showObjects(aObjects, false); } //************************************************************** @@ -892,7 +891,7 @@ void XGUI_Workshop::onWidgetValuesChanged() } //************************************************************** -void XGUI_Workshop::activatePart(FeaturePtr theFeature) +void XGUI_Workshop::activatePart(ResultPartPtr theFeature) { changeCurrentDocument(theFeature); myObjectBrowser->activatePart(theFeature); @@ -903,58 +902,52 @@ void XGUI_Workshop::activateLastPart() { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); DocumentPtr aDoc = aMgr->rootDocument(); - FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true); - activatePart(aLastPart); + std::string aGrpName = ModelAPI_ResultPart::group(); + ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1); + ResultPartPtr aPart = boost::dynamic_pointer_cast(aLastPart); + if (aPart) + activatePart(aPart); } //************************************************************** -void XGUI_Workshop::deleteFeatures(QFeatureList theList) +void XGUI_Workshop::deleteObjects(const QList& theList) { QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : myMainWindow; QMessageBox::StandardButton aRes = QMessageBox::warning(aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"), QMessageBox::No | QMessageBox::Yes, QMessageBox::No); - if (aRes == QMessageBox::Yes) { + // ToDo: definbe deleting method + /* if (aRes == QMessageBox::Yes) { PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); aMgr->rootDocument()->startOperation(); - foreach (FeaturePtr aFeature, theList) { - if (aFeature->getKind() == PARTSET_PART_KIND) { - DocumentPtr aDoc; - if (!XGUI_Tools::isModelObject(aFeature)) { - aDoc = aFeature->data()->docRef("PartDocument")->value(); - } else { - ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); - aDoc = aObject->featureRef()->data()->docRef("PartDocument")->value(); - aFeature = aObject->featureRef(); - } + foreach (ObjectPtr aObj, theList) { + ResultPartPtr aPart = boost::dynamic_pointer_cast(aObj); + if (aPart) { + DocumentPtr aDoc = aPart->document(); if (aDoc == aMgr->currentDocument()) { aDoc->close(); } + aMgr->rootDocument()->removeFeature(aPart->owner()); } else { - if (XGUI_Tools::isModelObject(aFeature)) { - ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); - aFeature = aObject->featureRef(); - } + aObj->document()->removeFeature(aObj); } - if (myDisplayer->isVisible(aFeature)) - myDisplayer->erase(aFeature, false); - aFeature->document()->removeFeature(aFeature); } myDisplayer->updateViewer(); aMgr->rootDocument()->finishOperation(); - } + }*/ } //************************************************************** -void XGUI_Workshop::showFeatures(QFeatureList theList, bool isVisible) +void XGUI_Workshop::showObjects(const QList& theList, bool isVisible) { - if (isVisible) { - foreach (FeaturePtr aFeature, theList) { - myDisplayer->display(aFeature, false); - } - } else { - foreach (FeaturePtr aFeature, theList) { - myDisplayer->erase(aFeature, false); + foreach (ObjectPtr aObj, theList) { + ResultPtr aRes = boost::dynamic_pointer_cast(aObj); + if (aRes) { + if (isVisible) { + myDisplayer->display(aRes, false); + } else { + myDisplayer->erase(aRes, false); + } } } myDisplayer->updateViewer(); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 870e23f19..1b85fbc0c 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -5,6 +5,7 @@ #include "XGUI_Constants.h" #include #include +#include #include #include @@ -110,13 +111,13 @@ public: //! Activates or deactivates a part //! If PartPtr is Null pointer then PartSet will be activated - void activatePart(FeaturePtr theFeature); + void activatePart(ResultPartPtr theFeature); //! Delete features - void deleteFeatures(QFeatureList theList); + void deleteObjects(const QList& theList); //! Show the given features in 3d Viewer - void showFeatures(QFeatureList theList, bool isVisible); + void showObjects(const QList& theList, bool isVisible); ModuleBase_IModule* module() const { return myModule; } @@ -142,7 +143,7 @@ public slots: void hideObjectBrowser(); void onFeatureTriggered(); - void changeCurrentDocument(FeaturePtr thePart); + void changeCurrentDocument(ObjectPtr theObj); void activateLastPart(); diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 065663ecf..efd946fcb 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -32,6 +32,7 @@ pictures/params_folder.png pictures/constr_folder.png + pictures/constr_object.png pictures/part_ico.png pictures/properties.png pictures/features.png diff --git a/src/XGUI/pictures/constr_object.png b/src/XGUI/pictures/constr_object.png new file mode 100644 index 0000000000000000000000000000000000000000..dd6dc98512fec7057f560779fc6f852efbb99c47 GIT binary patch literal 425 zcmV;a0apHrP)OANV7!vS9y!&+ z4;pp%xUTP-HHd3r@;?}K4)>y%Su}5u2|}C>6qWY26C#WW=y;*wA55%*67EpLglJvM)*A}nu_rT-RYc^ Tp(!Qb00000NkvXXu0mjf(^$7) literal 0 HcmV?d00001 -- 2.39.2