Salome HOME
#refs 76 - reported by Hervé Legrand: Edit Sketch as Constructions child - crash
authornds <natalia.donis@opencascade.com>
Fri, 30 May 2014 14:26:48 +0000 (18:26 +0400)
committernds <natalia.donis@opencascade.com>
Fri, 30 May 2014 14:26:48 +0000 (18:26 +0400)
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
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationSketchBase.cpp
src/XGUI/XGUI_DocumentDataModel.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_Tools.cpp
src/XGUI/XGUI_Tools.h
src/XGUI/XGUI_ViewWindow.cpp
src/XGUI/XGUI_Workshop.cpp

index 623eaae6392f1c774103ac809ef28750d29cdce3..0f397b1017bf3f2eb55cb24a2383c947962d8c78 100644 (file)
@@ -71,10 +71,6 @@ ModuleBase_WidgetPoint2D::~ModuleBase_WidgetPoint2D()
 bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
 {
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  if (!aData) {
-     ObjectPtr anObj = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
-     if (anObj) aData = anObj->featureRef()->data();
-  }
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
 
@@ -89,10 +85,6 @@ bool ModuleBase_WidgetPoint2D::storeValue(boost::shared_ptr<ModelAPI_Feature> th
 bool ModuleBase_WidgetPoint2D::restoreValue(boost::shared_ptr<ModelAPI_Feature> theFeature)
 {
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  if (!aData) {
-     ObjectPtr anObj = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
-     if (anObj) aData = anObj->featureRef()->data();
-  }
   boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myFeatureAttributeID));
 
index 374b1d503bb2607c30e30610eeaeb09e4395df78..3d93034020fd5ae115d03761f5ee5d1f0174a6c2 100644 (file)
@@ -8,6 +8,7 @@
 #include <PartSet_TestOCC.h>
 
 #include <ModuleBase_Operation.h>
+#include <ModelAPI_Object.h>
 
 #include <XGUI_MainWindow.h>
 #include <XGUI_Displayer.h>
@@ -20,6 +21,7 @@
 #include <XGUI_ViewerProxy.h>
 #include <XGUI_ContextMenuMgr.h>
 #include <XGUI_PropertyPanel.h>
+#include <XGUI_Tools.h>
 
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
@@ -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<ModelAPI_Object>(aFeature);
+      aFeature = aObject->featureRef();
+    }
+
+    if (aFeature) {
+      onLaunchOperation(aFeature->getKind(), aFeature);
+      updateCurrentPreview(aFeature->getKind());
+    }
   }
 }
index c14ab91896c46f2fc195459b27dbcba8ed299cdc..ae751b269ec8f14ce686d059e24a9f4c5f6128c0 100644 (file)
@@ -5,7 +5,6 @@
 #include <PartSet_OperationSketchBase.h>
 
 #include <SketchPlugin_Feature.h>
-#include <ModelAPI_Object.h>
 
 #include <V3d_View.hxx>
 
@@ -32,12 +31,6 @@ boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
 {
   boost::shared_ptr<SketchPlugin_Feature> aFeature = 
                               boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
-  if (!aFeature) { // if it is reference to a object feature
-    boost::shared_ptr<ModelAPI_Object> anObj = 
-      boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
-    if (anObj) 
-      aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(anObj->featureRef());
-  }
   if (!aFeature)
     return boost::shared_ptr<GeomAPI_Shape>();
   return aFeature->preview();
index 37c78f82a4aec5b3f23d24765e9a8a83bd4b6756..066ebdcae6985bf5c7d038401f4f726f173f98fe 100644 (file)
@@ -1,6 +1,7 @@
 #include "XGUI_DocumentDataModel.h"
 #include "XGUI_PartDataModel.h"
 #include "XGUI_Workshop.h"
+#include "XGUI_Tools.h"
 
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
@@ -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<ModelAPI_Object>(aFeature);
     aFeature = aObject->featureRef();
   }
index 258a59f8021fe2b6663f57dbac02b351f4151dad..125e1aaf4bc17cd6d52adda9f90296f88e671bb0 100644 (file)
@@ -1,5 +1,6 @@
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_DocumentDataModel.h"
+#include "XGUI_Tools.h"
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_PluginManager.h>
@@ -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<ModelAPI_Object>(aFeature)->setName(qPrintable(aRes));
index 8ce0a36ac0bcb25349a31bd518513a43d995496f..339d08369551b6128bcff4b93083563a4150848e 100644 (file)
@@ -8,6 +8,8 @@
 #include <iostream>
 #include <sstream>
 
+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<ModelAPI_Feature> theFeature)
+{
+  return theFeature && !theFeature->data();
+}
+
 //******************************************************************
 std::string featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature)
 {
@@ -62,3 +70,4 @@ std::string featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature)
   return QString(aStream.str().c_str()).toStdString();
 }
 
+}
\ No newline at end of file
index 5c8be08e85065d082c519e782efa1056285032ac..d20260f8e3046847cc6d0b53c51f0f1e021e2190 100644 (file)
@@ -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<ModelAPI_Feature> theFeature);
+
+  /*!
+   Returns the string presentation of the given feature
+   \param theFeature a feature
+  */
+  std::string XGUI_EXPORT featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature);
+}
 
-/*!
- Returns the string presentation of the given feature
- \param theFeature a feature
-*/
-std::string XGUI_EXPORT featureInfo(boost::shared_ptr<ModelAPI_Feature> theFeature);
 #endif
index 5a1a9ba4097ed64aeef7c13082fce24c09e0f8ae..7c0bc5d9ac14c8c9e225178db90b52ae4344bf63 100644 (file)
@@ -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" )
index 50eee3179e292eb2ae277d64af2a40a5a261aa2e..6ec130cc75971b348bbfa602a03530f4de1e8a34 100644 (file)
@@ -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<ModelAPI_Object>(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<ModelAPI_Object>(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<ModelAPI_Object>(aFeature);
           aFeature = aObject->featureRef();
         }