From 11dd9b35687e94024e785879fd5753ab4751b0b8 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 19 May 2014 15:30:38 +0400 Subject: [PATCH] Fixed crash in Object Browser on creation of feature Object --- src/XGUI/XGUI_PartDataModel.cpp | 47 +++++++++++++++++++-------------- src/XGUI/XGUI_Workshop.cpp | 31 +++++++++++----------- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 2ce2c5a26..532d88d78 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -11,6 +11,16 @@ #include #include + +FeaturePtr featureObj(const FeaturePtr& theFeature) +{ + ObjectPtr aObject = boost::dynamic_pointer_cast(theFeature); + if (aObject) + return aObject->featureRef(); + return theFeature; +} + + XGUI_TopDataModel::XGUI_TopDataModel(const DocumentPtr& theDocument, QObject* theParent) : XGUI_FeaturesModel(theDocument, theParent) { @@ -31,7 +41,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - FeaturePtr aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureObj(myDocument->feature(PARAMETERS_GROUP, theIndex.row())); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -39,7 +49,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex)); case ConstructObject: { - FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureObj(myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row())); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -55,7 +65,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const return QIcon(":pictures/constr_folder.png"); case ConstructObject: { - FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureObj(myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row())); if (aFeature) return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); } @@ -142,9 +152,9 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const case ConstructFolder: return FeaturePtr(); case ParamObject: - return myDocument->feature(PARAMETERS_GROUP, theIndex.row()); + return featureObj(myDocument->feature(PARAMETERS_GROUP, theIndex.row())); case ConstructObject: - return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + return featureObj(myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row())); } return FeaturePtr(); } @@ -192,7 +202,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons switch (theIndex.internalId()) { case MyRoot: { - FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId); + FeaturePtr aFeature = featureObj(myDocument->feature(PARTS_GROUP, myId)); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -204,19 +214,19 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - FeaturePtr aFeature = featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureObj(featureDocument()->feature(PARAMETERS_GROUP, theIndex.row())); if (aFeature) return aFeature->data()->getName().c_str(); } case ConstructObject: { - FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureObj(featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row())); if (aFeature) return aFeature->data()->getName().c_str(); } case HistoryObject: { - FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); + FeaturePtr aFeature = featureObj(featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3)); if (aFeature) return aFeature->data()->getName().c_str(); } @@ -234,7 +244,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons return QIcon(":pictures/constr_folder.png"); case ConstructObject: { - FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + FeaturePtr aFeature = featureObj(featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row())); if (aFeature) return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind())); } @@ -340,10 +350,7 @@ bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const DocumentPtr XGUI_PartDataModel::featureDocument() const { - FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId); - ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); - if (aObject) - return aObject->featureRef()->data()->docRef("PartDocument")->value(); + FeaturePtr aFeature = featureObj(myDocument->feature(PARTS_GROUP, myId)); return aFeature->data()->docRef("PartDocument")->value(); } @@ -351,17 +358,17 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const { switch (theIndex.internalId()) { case MyRoot: - if (theIndex.row() < 3) - return myDocument->feature(PARTS_GROUP, myId); - else + if (theIndex.row() < 3) { + return featureObj(myDocument->feature(PARTS_GROUP, myId)); + } else return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); case ParamsFolder: case ConstructFolder: return FeaturePtr(); case ParamObject: - return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row()); + return featureObj(featureDocument()->feature(PARAMETERS_GROUP, theIndex.row())); case ConstructObject: - return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row()); + return featureObj(featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row())); } return FeaturePtr(); } @@ -394,5 +401,5 @@ QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const FeaturePtr XGUI_PartDataModel::part() const { - return myDocument->feature(PARTS_GROUP, myId); + return featureObj(myDocument->feature(PARTS_GROUP, myId)); } \ No newline at end of file diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index a2cd536ec..1a11dca83 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -208,8 +209,8 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) { const Model_FeatureUpdatedMessage* anUpdateMsg = dynamic_cast(theMessage); - boost::shared_ptr aNewFeature = anUpdateMsg->feature(); - boost::shared_ptr aCurrentFeature = myOperationMgr->currentOperation()->feature(); + FeaturePtr aNewFeature = anUpdateMsg->feature(); + FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature(); if(aNewFeature == aCurrentFeature) { myPropertyPanel->updateContentWidget(aCurrentFeature); } @@ -355,8 +356,8 @@ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation) void XGUI_Workshop::saveDocument(QString theName) { QApplication::restoreOverrideCursor(); - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); - boost::shared_ptr aDoc = aMgr->rootDocument(); + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + DocumentPtr aDoc = aMgr->rootDocument(); aDoc->save(theName.toLatin1().constData()); QApplication::restoreOverrideCursor(); } @@ -364,8 +365,8 @@ void XGUI_Workshop::saveDocument(QString theName) //****************************************************** void XGUI_Workshop::onExit() { - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); - boost::shared_ptr aDoc = aMgr->rootDocument(); + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + DocumentPtr aDoc = aMgr->rootDocument(); if(aDoc->isModified()) { int anAnswer = QMessageBox::question( myMainWindow, tr("Save current file"), @@ -403,8 +404,8 @@ void XGUI_Workshop::onNew() void XGUI_Workshop::onOpen() { //save current file before close if modified - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); - boost::shared_ptr aDoc = aMgr->rootDocument(); + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + DocumentPtr aDoc = aMgr->rootDocument(); if(aDoc->isModified()) { //TODO(sbh): re-launch the app? int anAnswer = QMessageBox::question( @@ -468,8 +469,8 @@ void XGUI_Workshop::onSaveAs() void XGUI_Workshop::onUndo() { objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); - boost::shared_ptr aDoc = aMgr->rootDocument(); + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + DocumentPtr aDoc = aMgr->rootDocument(); if (aDoc->isOperation()) operationMgr()->abortOperation(); aDoc->undo(); @@ -480,8 +481,8 @@ void XGUI_Workshop::onUndo() void XGUI_Workshop::onRedo() { objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); - boost::shared_ptr aDoc = aMgr->rootDocument(); + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + DocumentPtr aDoc = aMgr->rootDocument(); aDoc->redo(); updateCommandStatus(); } @@ -569,7 +570,7 @@ void XGUI_Workshop::updateCommandStatus() QList aCommands = aMenuBar->features(); QList::const_iterator aIt; - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); if (aMgr->hasRootDocument()) { XGUI_Command* aUndoCmd; XGUI_Command* aRedoCmd; @@ -581,7 +582,7 @@ void XGUI_Workshop::updateCommandStatus() else // Enable all commands aCmd->enable(); } - boost::shared_ptr aDoc = aMgr->rootDocument(); + DocumentPtr aDoc = aMgr->rootDocument(); aUndoCmd->setEnabled(aDoc->canUndo()); aRedoCmd->setEnabled(aDoc->canRedo()); } else { @@ -678,7 +679,7 @@ void XGUI_Workshop::onFeatureTriggered() //****************************************************** void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart) { - boost::shared_ptr aMgr = ModelAPI_PluginManager::get(); + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); if (thePart) { boost::shared_ptr aDocRef = thePart->data()->docRef("PartDocument"); if (aDocRef) -- 2.39.2