From 057e426145a26c02a1c5d6e1c220f92a17d8e53d Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 30 May 2014 18:26:48 +0400 Subject: [PATCH] =?utf8?q?#refs=2076=20-=20reported=20by=20Herv=C3=A9=20Le?= =?utf8?q?grand:=20Edit=20Sketch=20as=20Constructions=20child=20-=20crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In additional isModelObject() method is added. The bug functionality is in Module::edit(). The feature is obtained from the model object if it is. --- src/ModuleBase/ModuleBase_WidgetPoint2D.cpp | 8 -- src/PartSet/PartSet_Module.cpp | 14 +++- src/PartSet/PartSet_OperationSketchBase.cpp | 7 -- src/XGUI/XGUI_DocumentDataModel.cpp | 3 +- src/XGUI/XGUI_ObjectsBrowser.cpp | 3 +- src/XGUI/XGUI_Tools.cpp | 9 +++ src/XGUI/XGUI_Tools.h | 82 ++++++++++++--------- src/XGUI/XGUI_ViewWindow.cpp | 6 +- src/XGUI/XGUI_Workshop.cpp | 9 ++- 9 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp index 623eaae63..0f397b101 100644 --- a/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPoint2D.cpp @@ -71,10 +71,6 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D() bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr theFeature) { boost::shared_ptr aData = theFeature->data(); - if (!aData) { - ObjectPtr anObj = boost::dynamic_pointer_cast(theFeature); - if (anObj) aData = anObj->featureRef()->data(); - } boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); @@ -89,10 +85,6 @@ bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr th bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr theFeature) { boost::shared_ptr aData = theFeature->data(); - if (!aData) { - ObjectPtr anObj = boost::dynamic_pointer_cast(theFeature); - if (anObj) aData = anObj->featureRef()->data(); - } boost::shared_ptr aPoint = boost::dynamic_pointer_cast(aData->attribute(myFeatureAttributeID)); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 374b1d503..3d9303402 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include @@ -441,7 +443,15 @@ void PartSet_Module::editFeature(FeaturePtr theFeature) return; if (theFeature->getKind() == "Sketch") { - onLaunchOperation(theFeature->getKind(), theFeature); - updateCurrentPreview(theFeature->getKind()); + FeaturePtr aFeature = theFeature; + if (XGUI_Tools::isModelObject(aFeature)) { + ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); + aFeature = aObject->featureRef(); + } + + if (aFeature) { + onLaunchOperation(aFeature->getKind(), aFeature); + updateCurrentPreview(aFeature->getKind()); + } } } diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index c14ab9189..ae751b269 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -5,7 +5,6 @@ #include #include -#include #include @@ -32,12 +31,6 @@ boost::shared_ptr PartSet_OperationSketchBase::preview( { boost::shared_ptr aFeature = boost::dynamic_pointer_cast(theFeature); - if (!aFeature) { // if it is reference to a object feature - boost::shared_ptr anObj = - boost::dynamic_pointer_cast(theFeature); - if (anObj) - aFeature = boost::dynamic_pointer_cast(anObj->featureRef()); - } if (!aFeature) return boost::shared_ptr(); return aFeature->preview(); diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index 37c78f82a..066ebdcae 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -1,6 +1,7 @@ #include "XGUI_DocumentDataModel.h" #include "XGUI_PartDataModel.h" #include "XGUI_Workshop.h" +#include "XGUI_Tools.h" #include #include @@ -492,7 +493,7 @@ Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const { FeaturePtr aFeature = theFeature; - if (!aFeature->data()) { + if (XGUI_Tools::isModelObject(aFeature)) { ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); aFeature = aObject->featureRef(); } diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 258a59f80..125e1aaf4 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -1,5 +1,6 @@ #include "XGUI_ObjectsBrowser.h" #include "XGUI_DocumentDataModel.h" +#include "XGUI_Tools.h" #include #include @@ -85,7 +86,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor) FeaturePtr aFeature = mySelectedData.first(); PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); aMgr->rootDocument()->startOperation(); - if (aFeature->data()) + if (!XGUI_Tools::isModelObject(aFeature)) aFeature->data()->setName(qPrintable(aRes)); else boost::dynamic_pointer_cast(aFeature)->setName(qPrintable(aRes)); diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 8ce0a36ac..339d08369 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -8,6 +8,8 @@ #include #include +namespace XGUI_Tools +{ //****************************************************************** QString dir(const QString& path, bool isAbs) { @@ -53,6 +55,12 @@ QRect makeRect(const int x1, const int y1, const int x2, const int y2) return QRect(qMin(x1, x2), qMin(y1, y2), qAbs(x2 - x1), qAbs(y2 - y1)); } +//****************************************************************** +bool isModelObject(boost::shared_ptr theFeature) +{ + return theFeature && !theFeature->data(); +} + //****************************************************************** std::string featureInfo(boost::shared_ptr theFeature) { @@ -62,3 +70,4 @@ std::string featureInfo(boost::shared_ptr theFeature) return QString(aStream.str().c_str()).toStdString(); } +} \ No newline at end of file diff --git a/src/XGUI/XGUI_Tools.h b/src/XGUI/XGUI_Tools.h index 5c8be08e8..d20260f8e 100644 --- a/src/XGUI/XGUI_Tools.h +++ b/src/XGUI/XGUI_Tools.h @@ -19,46 +19,58 @@ class ModelAPI_Feature; \param abs if true (default) \a path parameter is treated as absolute file path \return directory part of the file path */ -QString XGUI_EXPORT dir(const QString& path, bool isAbs = true); +namespace XGUI_Tools +{ + QString XGUI_EXPORT dir(const QString& path, bool isAbs = true); -/*! - \brief Return file name part of the file path. + /*! + \brief Return file name part of the file path. - \param path file path - \param withExt if true (default) complete file name (with all - extension except the last) is returned, otherwise only base name - is returned - \return file name part of the file path - */ -QString XGUI_EXPORT file(const QString& path, bool withExt = true); + \param path file path + \param withExt if true (default) complete file name (with all + extension except the last) is returned, otherwise only base name + is returned + \return file name part of the file path + */ + QString XGUI_EXPORT file(const QString& path, bool withExt = true); -/*! - \brief Return extension part of the file path. + /*! + \brief Return extension part of the file path. - \param path file path - \param full if true complete extension (all extensions, dot separated) - is returned, otherwise (default) only last extension is returned - \return extension part of the file path - */ -QString XGUI_EXPORT extension(const QString& path, bool full = false); + \param path file path + \param full if true complete extension (all extensions, dot separated) + is returned, otherwise (default) only last extension is returned + \return extension part of the file path + */ + QString XGUI_EXPORT extension(const QString& path, bool full = false); -/*! - \brief Add a slash (platform-specific) to the end of \a path - if it is not already there. - \param path directory path - \return modified path (with slash added to the end) - */ -QString XGUI_EXPORT addSlash(const QString& path); + /*! + \brief Add a slash (platform-specific) to the end of \a path + if it is not already there. + \param path directory path + \return modified path (with slash added to the end) + */ + QString XGUI_EXPORT addSlash(const QString& path); -/*! - Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) ) - and BottomRight = ( TopLeft + (x2-x1)(y2-y1) ) - */ -QRect XGUI_EXPORT makeRect(const int x1, const int y1, const int x2, const int y2); + /*! + Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) ) + and BottomRight = ( TopLeft + (x2-x1)(y2-y1) ) + */ + QRect XGUI_EXPORT makeRect(const int x1, const int y1, const int x2, const int y2); + + /// The model concerning tools + + /*! + Returns true if the feature is a model object + \param theFeature a feature + */ + bool XGUI_EXPORT isModelObject(boost::shared_ptr theFeature); + + /*! + Returns the string presentation of the given feature + \param theFeature a feature + */ + std::string XGUI_EXPORT featureInfo(boost::shared_ptr theFeature); +} -/*! - Returns the string presentation of the given feature - \param theFeature a feature -*/ -std::string XGUI_EXPORT featureInfo(boost::shared_ptr theFeature); #endif diff --git a/src/XGUI/XGUI_ViewWindow.cpp b/src/XGUI/XGUI_ViewWindow.cpp index 5a1a9ba40..7c0bc5d9a 100644 --- a/src/XGUI/XGUI_ViewWindow.cpp +++ b/src/XGUI/XGUI_ViewWindow.cpp @@ -727,7 +727,7 @@ void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent) myCurrX = theEvent->x(); myCurrY = theEvent->y(); drawRect(); - QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY); + QRect rect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY); if (!rect.isEmpty()) myViewPort->fitRect(rect); endDrawRect(); @@ -859,7 +859,7 @@ void XGUI_ViewWindow::drawRect() } myRectBand->setUpdatesEnabled(false); - QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY); + QRect aRect = XGUI_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY); myRectBand->initGeometry(aRect); if (!myRectBand->isVisible()) @@ -1039,7 +1039,7 @@ void XGUI_ViewWindow::dumpView() QApplication::setOverrideCursor( Qt::WaitCursor ); QImage aPicture = myViewPort->dumpView(); - QString aFmt = extension(aFileName).toUpper(); + QString aFmt = XGUI_Tools::extension(aFileName).toUpper(); if( aFmt.isEmpty() ) aFmt = QString( "BMP" ); // default format else if( aFmt == "JPG" ) diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 50eee3179..6ec130cc7 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -737,7 +737,8 @@ void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart) PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); if (thePart) { DocumentPtr aFeaDoc; - if (thePart->data()) { + if (!XGUI_Tools::isModelObject(thePart)) { + //if (thePart->data()) { aFeaDoc = thePart->data()->docRef("PartDocument")->value(); } else { ObjectPtr aObject = boost::dynamic_pointer_cast(thePart); @@ -804,7 +805,8 @@ void XGUI_Workshop::deleteFeatures(QFeatureList theList) foreach (FeaturePtr aFeature, theList) { if (aFeature->getKind() == "Part") { DocumentPtr aDoc; - if (aFeature->data()) { + if (!XGUI_Tools::isModelObject(aFeature)) { + //if (aFeature->data()) { aDoc = aFeature->data()->docRef("PartDocument")->value(); } else { ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); @@ -815,7 +817,8 @@ void XGUI_Workshop::deleteFeatures(QFeatureList theList) aDoc->close(); } } else { - if (!aFeature->data()) { + if (XGUI_Tools::isModelObject(aFeature)) { + //if (!aFeature->data()) { ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); aFeature = aObject->featureRef(); } -- 2.39.2