From: vsv Date: Thu, 22 May 2014 15:53:26 +0000 (+0400) Subject: Features editing commands X-Git-Tag: V_0.2~26^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d8291d7b5e3d98cd32d7cdf27f936421d430affa;p=modules%2Fshaper.git Features editing commands --- diff --git a/src/Model/Model_Object.cpp b/src/Model/Model_Object.cpp index c8a852b51..269c547cf 100644 --- a/src/Model/Model_Object.cpp +++ b/src/Model/Model_Object.cpp @@ -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(this), anEvent); Events_Loop::loop()->send(aMsg, false); + */ } } diff --git a/src/Model/Model_Object.h b/src/Model/Model_Object.h index 18314c04d..8179d701d 100644 --- a/src/Model/Model_Object.h +++ b/src/Model/Model_Object.h @@ -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 document() + {return myRef->document();} + + /// Returns true if feature refers to the same model data instance + MODEL_EXPORT virtual bool isSame(const boost::shared_ptr& theFeature) + { + boost::shared_ptr anObj = boost::dynamic_pointer_cast(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 theRef, Handle_TDataStd_Name theName); - friend class Model_Document; + friend class Model_Document; }; #endif diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index dd98c597a..bd726461f 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -56,6 +56,10 @@ public: MODELAPI_EXPORT virtual boost::shared_ptr document() {return myDoc;} + /// Returns true if feature refers to the same model data instance + MODELAPI_EXPORT virtual bool isSame(const boost::shared_ptr& theFeature) + {return true;} + /// To virtually destroy the fields of successors virtual ~ModelAPI_Feature() {} diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index a74824431..38e74834b 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -90,7 +91,8 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const //Process Feature if (aFeature) { if (aFeature->getKind() == "Part") { - boost::shared_ptr aFeaDoc = aFeature->data()->docRef("PartDocument")->value(); + ObjectPtr aObject = boost::dynamic_pointer_cast(aFeature); + DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value(); if (aMgr->currentDocument() == aFeaDoc) aActions.append(action("DEACTIVATE_PART_CMD")); else diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 352fa4ba8..702c44fef 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -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(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; } diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 6610b64c5..dc09185cc 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -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(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(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(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(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(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; }