]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Features editing commands
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 22 May 2014 15:53:26 +0000 (19:53 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 22 May 2014 15:53:26 +0000 (19:53 +0400)
src/Model/Model_Object.cpp
src/Model/Model_Object.h
src/ModelAPI/ModelAPI_Feature.h
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_PartDataModel.cpp

index c8a852b511c0eb5e2edefbd9811b426d2b4cda35..269c547cf90b641ceeaa1ee7c912ac69d460520a 100644 (file)
@@ -21,9 +21,11 @@ void Model_Object::setName(std::string theName)
 {
   if (myName->Get() != theName.c_str()) {
     myName->Set(theName.c_str());
+    /*
     static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
     Model_FeatureUpdatedMessage aMsg(boost::shared_ptr<ModelAPI_Object>(this), anEvent);
     Events_Loop::loop()->send(aMsg, false);
+    */
   }
 }
 
index 18314c04d6fd4e0c8bc337172d2547b0ecc4f612..8179d701d6d70c7032fdad2deba769ae3d72db08 100644 (file)
@@ -36,6 +36,17 @@ public:
   /// Returns to which group in the document must be added feature
   MODEL_EXPORT virtual const std::string& getGroup() {return myRef->getGroup();}
 
+  /// Returns document this feature belongs to
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
+  {return myRef->document();}
+
+  /// Returns true if feature refers to the same model data instance
+  MODEL_EXPORT virtual bool isSame(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+  {
+    boost::shared_ptr<Model_Object> anObj = boost::dynamic_pointer_cast<Model_Object>(theFeature);
+    return anObj && myRef == anObj->myRef;
+  }
+
   /// It is just a reference: don't init attributes
   MODEL_EXPORT virtual void initAttributes() {}
 
@@ -47,7 +58,7 @@ private:
   /// Constructor fully defines this object
   Model_Object(boost::shared_ptr<ModelAPI_Feature> theRef, Handle_TDataStd_Name theName);
 
-  friend class Model_Document;
+  friend class Model_Document;  
 };
 
 #endif
index dd98c597a02c7f466f9caa61a01ec77d804e5c38..bd726461ff4194ecec2da0f35d4c5d65e63e80aa 100644 (file)
@@ -56,6 +56,10 @@ public:
   MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
   {return myDoc;}
 
+  /// Returns true if feature refers to the same model data instance
+  MODELAPI_EXPORT virtual bool isSame(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+  {return true;}
+
   /// To virtually destroy the fields of successors
   virtual ~ModelAPI_Feature() {}
 
index a74824431b559a7be3066491d82b2b33fa344597..38e74834ba85a9a57f655e02172a0a6e0240d6bb 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_Object.h>
 
 #include <QAction>
 #include <QContextMenuEvent>
@@ -90,7 +91,8 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const
     //Process Feature
     if (aFeature) {
       if (aFeature->getKind() == "Part") {
-        boost::shared_ptr<ModelAPI_Document> aFeaDoc = aFeature->data()->docRef("PartDocument")->value();
+        ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
+        DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
         if (aMgr->currentDocument() == aFeaDoc)
           aActions.append(action("DEACTIVATE_PART_CMD"));
         else 
index 352fa4ba8dd1fdf9f0da2b0fdec87c83a2cd8e37..702c44fef8cd696cfcff8fb55c68b14ca98dfec1 100644 (file)
@@ -4,6 +4,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_Object.h>
 
 #include <QLayout>
 #include <QLabel>
@@ -82,7 +83,12 @@ void XGUI_DataTree::commitData(QWidget* theEditor)
   if (aEditor) {
     QString aRes = aEditor->text();
     FeaturePtr aFeature = mySelectedData.first();
-    aFeature->data()->setName(qPrintable(aRes));
+    aFeature->document()->startOperation();
+    if (aFeature->data())
+      aFeature->data()->setName(qPrintable(aRes));
+    else
+      boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->setName(qPrintable(aRes));
+    aFeature->document()->finishOperation();
   }
 }
 
@@ -289,7 +295,8 @@ void XGUI_ObjectsBrowser::onEditItem()
       // Find index which corresponds the feature
       QModelIndex aIndex;
       foreach(QModelIndex aIdx, selectedIndexes()) {
-        if (dataModel()->feature(aIdx) == aFeature) {
+        FeaturePtr aFea = dataModel()->feature(aIdx);
+        if (dataModel()->feature(aIdx)->isSame(aFeature)) {
           aIndex = aIdx;
           break;
         }
index 6610b64c58ff15dcbbe5b5268c7224188ad021c9..dc09185cc52be72def60de75adb7ccdb4e99c953 100644 (file)
@@ -41,17 +41,17 @@ 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(), true);
+        FeaturePtr aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       } 
     case ConstructFolder:
         return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
     case ConstructObject:
       {
-        FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+        FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     }
     break;
@@ -65,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(), true);
+        FeaturePtr aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
         if (aFeature)
           return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       }
@@ -152,9 +152,9 @@ FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
   case ConstructFolder:
     return FeaturePtr();
   case ParamObject:
-    return myDocument->feature(PARAMETERS_GROUP, theIndex.row(), true);
+    return myDocument->feature(PARAMETERS_GROUP, theIndex.row());
   case ConstructObject:
-    return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+    return myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
   }
   return FeaturePtr();
 }
@@ -182,7 +182,7 @@ QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& theFeature) const
     int aNb = myDocument->size(aGroup);
     int aRow = -1;
     for (int i = 0; i < aNb; i++) {
-      if (myDocument->feature(aGroup, i, true) == theFeature) {
+      if (myDocument->feature(aGroup, i) == theFeature) {
         aRow = i;
         break;
       }
@@ -220,9 +220,9 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
     switch (theIndex.internalId()) {
     case MyRoot:
       {
-        FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId, true);
+        FeaturePtr aFeature = myDocument->feature(PARTS_GROUP, myId);
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     case ParamsFolder:
       return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
@@ -232,19 +232,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(), true);
+        FeaturePtr aFeature = featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     case ConstructObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+        FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
         if (aFeature)
-          return aFeature->data()->getName().c_str();
+          return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
       }
     case HistoryObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3, true);
+        FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3);
         if (aFeature)
           return aFeature->data()->getName().c_str();
       }
@@ -262,13 +262,13 @@ 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(), true);
+        FeaturePtr aFeature = featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
         if (aFeature)
           return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       }
     case HistoryObject:
       {
-        FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3, true);
+        FeaturePtr aFeature = featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3);
         if (aFeature)
           return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
       }
@@ -292,7 +292,7 @@ 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, true))
+    if (myDocument->feature(PARTS_GROUP, myId))
       return 1;
     else 
       return 0;
@@ -376,20 +376,19 @@ FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
 {
   switch (theIndex.internalId()) {
   case MyRoot:
-    if (theIndex.row() < 3) {
-      return myDocument->feature(PARTS_GROUP, myId, true);
-    } else 
-      return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3, true);
+    return myDocument->feature(PARTS_GROUP, myId);
   case ParamsFolder:
   case ConstructFolder:
   case BodiesFolder:
     return FeaturePtr();
   case ParamObject:
-    return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row(), true);
+    return featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
   case ConstructObject:
-    return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+    return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
   //case BodiesObject:
-  //  return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row(), true);
+  //  return featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+  case HistoryObject:
+    return featureDocument()->feature(FEATURES_GROUP, theIndex.row() - 3); 
   }
   return FeaturePtr();
 }
@@ -430,7 +429,7 @@ QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
     int aNb = myDocument->size(aGroup);
     int aRow = -1;
     for (int i = 0; i < aNb; i++) {
-      if (myDocument->feature(aGroup, i, true) == theFeature) {
+      if (myDocument->feature(aGroup, i) == theFeature) {
         aRow = i;
         break;
       }