From: vsv Date: Tue, 28 Nov 2017 12:36:43 +0000 (+0300) Subject: Do not use Parts for folders X-Git-Tag: V_2.10.0RC~123^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=84b552769d2f2ae7ff51a9f7c38bfe7a3d477ce8;p=modules%2Fshaper.git Do not use Parts for folders --- diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 0026ad7e1..be9bf8c16 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -352,86 +352,89 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu() // Check folder management commands state if only features are selected if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) && (!hasResultInHistory) && (!hasFolder)) { - QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes(); - QModelIndex aFirstIdx = aIndexes.first(); - QModelIndex aLastIdx = aIndexes.last(); - QModelIndex aParentIdx = aFirstIdx.parent(); - - // if all selected are from the same level - bool isSameParent = true; - foreach(QModelIndex aIdx, aIndexes) { - if (aIdx.parent() != aParentIdx) { - isSameParent = false; - break; + std::list aFeatures = aSelMgr->getSelectedFeatures(); + if (aFeatures.size() > 0) { // Check that features do not include Parts + QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes(); + QModelIndex aFirstIdx = aIndexes.first(); + QModelIndex aLastIdx = aIndexes.last(); + QModelIndex aParentIdx = aFirstIdx.parent(); + + // if all selected are from the same level + bool isSameParent = true; + foreach(QModelIndex aIdx, aIndexes) { + if (aIdx.parent() != aParentIdx) { + isSameParent = false; + break; + } } - } - if (isSameParent) { - // Check is selection continuous - XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel(); - DocumentPtr aDoc = aMgr->activeDocument(); - std::list aFeatures = aSelMgr->getSelectedFeatures(); - - bool isContinuos = true; - if (aSelected > 1) { - int aId = -1; - foreach(FeaturePtr aF, aFeatures) { - if (aId == -1) - aId = aDoc->index(aF); - else { - aId++; - if (aId != aDoc->index(aF)) { - isContinuos = false; - break; + if (isSameParent) { + // Check is selection continuous + XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel(); + DocumentPtr aDoc = aMgr->activeDocument(); + std::list aFeatures = aSelMgr->getSelectedFeatures(); + + bool isContinuos = true; + if (aSelected > 1) { + int aId = -1; + foreach(FeaturePtr aF, aFeatures) { + if (aId == -1) + aId = aDoc->index(aF); + else { + aId++; + if (aId != aDoc->index(aF)) { + isContinuos = false; + break; + } } } } - } - if (isContinuos) { - ObjectPtr aDataObj = aModel->object(aParentIdx); + if (isContinuos) { + ObjectPtr aDataObj = aModel->object(aParentIdx); - ObjectPtr aPrevObj; - if (aFirstIdx.row() > 0) { - QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0); - aPrevObj = aModel->object(aPrevIdx); - } + ObjectPtr aPrevObj; + if (aFirstIdx.row() > 0) { + QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0); + aPrevObj = aModel->object(aPrevIdx); + } - ObjectPtr aNextObj; - if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) { - QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0); - aNextObj = aModel->object(aNextIdx); - } + ObjectPtr aNextObj; + if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) { + QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0); + aNextObj = aModel->object(aNextIdx); + } - bool isPrevFolder = (aPrevObj.get() && - (aPrevObj->groupName() == ModelAPI_Folder::group())); - bool isNextFolder = (aNextObj.get() && - (aNextObj->groupName() == ModelAPI_Folder::group())); - bool isInFolder = (aDataObj.get() && - (aDataObj->groupName() == ModelAPI_Folder::group())); - bool isOutsideFolder = !isInFolder; - - bool hasFirst = false; - bool hasLast = false; - if (isInFolder) { - FolderPtr aFolder = std::dynamic_pointer_cast(aDataObj); - FeaturePtr aFirstFeatureInFolder; - AttributeReferencePtr aFirstFeatAttr = - aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID()); - if (aFirstFeatAttr) - aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value()); - hasFirst = (aFirstFeatureInFolder == aFeatures.front()); - - FeaturePtr aLastFeatureInFolder; - AttributeReferencePtr aLastFeatAttr = - aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID()); - if (aLastFeatAttr) - aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value()); - hasLast = (aLastFeatureInFolder == aFeatures.back()); + bool isPrevFolder = (aPrevObj.get() && + (aPrevObj->groupName() == ModelAPI_Folder::group())); + bool isNextFolder = (aNextObj.get() && + (aNextObj->groupName() == ModelAPI_Folder::group())); + bool isInFolder = (aDataObj.get() && + (aDataObj->groupName() == ModelAPI_Folder::group())); + bool isOutsideFolder = !isInFolder; + + bool hasFirst = false; + bool hasLast = false; + if (isInFolder) { + FolderPtr aFolder = std::dynamic_pointer_cast(aDataObj); + FeaturePtr aFirstFeatureInFolder; + AttributeReferencePtr aFirstFeatAttr = + aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID()); + if (aFirstFeatAttr) + aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value()); + hasFirst = (aFirstFeatureInFolder == aFeatures.front()); + + FeaturePtr aLastFeatureInFolder; + AttributeReferencePtr aLastFeatAttr = + aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID()); + if (aLastFeatAttr) + aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value()); + hasLast = (aLastFeatureInFolder == aFeatures.back()); + } + action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder); + action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder); + action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder); + action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst); + action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast); } - action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder); - action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder); - action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder); - action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst); - action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast); } } } // end folder management commands diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 38cb1d325..ed7e5e233 100755 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -228,10 +228,15 @@ std::list XGUI_SelectionMgr::getSelectedFeatures() if (aObjects.isEmpty()) return aFeatures; + bool isPart = false; foreach(ObjectPtr aObj, aObjects) { FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); - if (aFeature.get()) - aFeatures.push_back(aFeature); + if (aFeature.get()) { + ResultPtr aRes = aFeature->firstResult(); + isPart = (aRes.get() && (aRes->groupName() == ModelAPI_ResultPart::group())); + if (!isPart) + aFeatures.push_back(aFeature); + } } return aFeatures; } \ No newline at end of file diff --git a/src/XGUI/XGUI_SelectionMgr.h b/src/XGUI/XGUI_SelectionMgr.h index b6829da0a..06e6fe54e 100644 --- a/src/XGUI/XGUI_SelectionMgr.h +++ b/src/XGUI/XGUI_SelectionMgr.h @@ -78,7 +78,7 @@ Q_OBJECT /// \param thePlace a widget where selection has happened. void updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace); - /// Returns list of selected features (ignores other selected objects) + /// Returns list of selected features (ignores other selected objects and parts) std::list getSelectedFeatures(); signals: