From: vsv Date: Fri, 24 Nov 2017 08:13:26 +0000 (+0300) Subject: Menu "Insert folder before" is added X-Git-Tag: V_2.10.0RC~123^2~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=767fef5f36265c72503b4ee389c3bd3190c7b4e0;p=modules%2Fshaper.git Menu "Insert folder before" is added --- diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index dbf0f252b..42a5381b5 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -372,20 +373,24 @@ int shapeType(const QString& theType) } void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, - bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory) + bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory, + bool& hasFolder) { hasResult = false; hasFeature = false; hasParameter = false; hasCompositeOwner = false; hasResultInHistory = false; + hasFolder = false; foreach(ObjectPtr aObj, theObjects) { FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); ResultPtr aResult = std::dynamic_pointer_cast(aObj); + FolderPtr aFolder = std::dynamic_pointer_cast(aObj); ResultParameterPtr aConstruction = std::dynamic_pointer_cast(aResult); hasResult |= (aResult.get() != NULL); hasFeature |= (aFeature.get() != NULL); + hasFolder |= (aFolder.get() != NULL); hasParameter |= (aConstruction.get() != NULL); if (hasFeature) hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL); @@ -395,7 +400,7 @@ void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFe hasResultInHistory = aFeature.get() && aFeature->isInHistory(); } - if (hasFeature && hasResult && hasParameter && hasCompositeOwner) + if (hasFeature && hasResult && hasParameter && hasCompositeOwner && hasFeature) break; } } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 0c46f52dc..7bdaab757 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -176,9 +176,10 @@ MODULEBASE_EXPORT bool isSubResult(ObjectPtr theObject); /// \param hasParameter will be set to true if list contains Parameter objects /// \param hasCompositeOwner will be set to true if list contains Sub-Feature objects /// \param hasResultInHistory will be set to true if one of result is in history +/// \param hasFolder will be set to true if one of folder is in the list MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature, bool& hasParameter, bool& hasCompositeOwner, - bool& hasResultInHistory); + bool& hasResultInHistory, bool& hasFolder); /// Sets the default coeffient into the driver calculated accordingly the shape type. /// It provides 1.e-4 for results of construction type diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 57d9fc6b7..3ec2c8552 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1201,8 +1201,9 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const bool hasParameter = false; bool hasCompositeOwner = false; bool hasResultInHistory = false; + bool hasFolder = false; ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, - hasCompositeOwner, hasResultInHistory); + hasCompositeOwner, hasResultInHistory, hasFolder); ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation(); if (aSelected == 1) { diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 1a986b377..9b7b99dcf 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -47,6 +47,7 @@ #include #include #include +#include "ModelAPI_Folder.h" #include @@ -66,7 +67,7 @@ XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent) : QObject(theParent), myWorkshop(theParent), - mySeparator(0) + mySeparator1(0), mySeparator2(0) { } @@ -135,8 +136,11 @@ void XGUI_ContextMenuMgr::createActions() aDesktop); addAction("WIREFRAME_CMD", aAction); - mySeparator = ModuleBase_Tools::createAction(QIcon(), "", aDesktop); - mySeparator->setSeparator(true); + mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop); + mySeparator1->setSeparator(true); + + mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop); + mySeparator2->setSeparator(true); //mySelectActions = new QActionGroup(this); //mySelectActions->setExclusive(true); @@ -180,6 +184,12 @@ void XGUI_ContextMenuMgr::createActions() addAction("TINSPECTOR_VIEW", aAction); #endif + // Features folders actions + aAction = ModuleBase_Tools::createAction(QIcon(), + tr("Insert a folder before"), aDesktop); + addAction("INSERT_FOLDER_CMD", aAction); + + buildObjBrowserMenu(); buildViewerMenu(); } @@ -263,8 +273,9 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu() bool hasParameter = false; bool hasCompositeOwner = false; bool hasResultInHistory = false; + bool hasFolder = false; ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter, - hasCompositeOwner, hasResultInHistory); + hasCompositeOwner, hasResultInHistory, hasFolder); //Process Feature if (aSelected == 1) { ObjectPtr aObject = aObjects.first(); @@ -331,6 +342,7 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu() action("CLEAN_HISTORY_CMD")->setEnabled(true); action("SHOW_RESULTS_CMD")->setEnabled(hasFeature); + action("INSERT_FOLDER_CMD")->setEnabled(hasFeature); action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory); } @@ -492,7 +504,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.append(action("SHOW_CMD")); aList.append(action("HIDE_CMD")); aList.append(action("SHOW_ONLY_CMD")); - aList.append(mySeparator); + aList.append(mySeparator1); aList.append(action("RENAME_CMD")); aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); @@ -507,12 +519,12 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.clear(); aList.append(action("WIREFRAME_CMD")); aList.append(action("SHADING_CMD")); - aList.append(mySeparator); // this separator is not shown as this action is added after show only + aList.append(mySeparator1); // this separator is not shown as this action is added after show only // qt list container contains only one instance of the same action aList.append(action("SHOW_CMD")); aList.append(action("HIDE_CMD")); aList.append(action("SHOW_ONLY_CMD")); - aList.append(mySeparator); + aList.append(mySeparator2); aList.append(action("RENAME_CMD")); aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); @@ -532,18 +544,25 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.append(action("RENAME_CMD")); aList.append(action("SHOW_RESULTS_CMD")); aList.append(action("MOVE_CMD")); - aList.append(mySeparator); + aList.append(mySeparator1); + aList.append(action("INSERT_FOLDER_CMD")); + aList.append(mySeparator2); aList.append(action("CLEAN_HISTORY_CMD")); aList.append(action("DELETE_CMD")); myObjBrowserMenus[ModelAPI_Feature::group()] = aList; aList.clear(); aList.append(action("RENAME_CMD")); - aList.append(mySeparator); + aList.append(mySeparator1); aList.append(action("CLEAN_HISTORY_CMD")); aList.append(action("DELETE_CMD")); myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList; //------------------------------------- + + aList.clear(); + aList.append(action("DELETE_CMD")); + myObjBrowserMenus[ModelAPI_Folder::group()] = aList; + } void XGUI_ContextMenuMgr::buildViewerMenu() @@ -552,7 +571,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu() // Result construction menu aList.append(action("HIDE_CMD")); aList.append(action("SHOW_ONLY_CMD")); - aList.append(mySeparator); + aList.append(mySeparator1); aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); #ifdef USE_TRANSPARENCY @@ -566,10 +585,10 @@ void XGUI_ContextMenuMgr::buildViewerMenu() aList.clear(); aList.append(action("WIREFRAME_CMD")); aList.append(action("SHADING_CMD")); - aList.append(mySeparator); + aList.append(mySeparator1); aList.append(action("HIDE_CMD")); aList.append(action("SHOW_ONLY_CMD")); - aList.append(mySeparator); + aList.append(mySeparator2); aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); #ifdef USE_TRANSPARENCY @@ -603,11 +622,11 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const } else if (aSelected > 1) { aActions.append(action("WIREFRAME_CMD")); aActions.append(action("SHADING_CMD")); - aActions.append(mySeparator); + aActions.append(mySeparator1); aActions.append(action("SHOW_CMD")); aActions.append(action("HIDE_CMD")); aActions.append(action("SHOW_ONLY_CMD")); - aActions.append(mySeparator); + aActions.append(mySeparator2); //aActions.append(action("MOVE_CMD")); aActions.append(action("COLOR_CMD")); aActions.append(action("DEFLECTION_CMD")); diff --git a/src/XGUI/XGUI_ContextMenuMgr.h b/src/XGUI/XGUI_ContextMenuMgr.h index 7513d5e25..280792cdd 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.h +++ b/src/XGUI/XGUI_ContextMenuMgr.h @@ -142,7 +142,8 @@ signals: //QActionGroup* mySelectActions; - QAction* mySeparator; + QAction* mySeparator1; + QAction* mySeparator2; }; #endif diff --git a/src/XGUI/XGUI_DataModel.cpp b/src/XGUI/XGUI_DataModel.cpp index 746b33e03..9a78e665b 100644 --- a/src/XGUI/XGUI_DataModel.cpp +++ b/src/XGUI/XGUI_DataModel.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -141,7 +142,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess // Insert new object int aRow = aRootDoc->size(aObjType) - 1; if (aRow != -1) { - if (aObjType == aRootType) { + if ((aObjType == aRootType) || (aObjType == ModelAPI_Folder::group())) { insertRow(aRow + aNbFolders + 1); } else { int aFolderId = myXMLReader->rootFolderId(aObjType); @@ -165,10 +166,10 @@ void XGUI_DataModel::processEvent(const std::shared_ptr& theMess } } } - int aRow = aDoc->index(aObject); + int aRow = aDoc->index(aObject, true); if (aRow != -1) { int aNbSubFolders = foldersCount(aDoc.get()); - if (aObjType == aSubType) { + if ((aObjType == aSubType) || (aObjType == ModelAPI_Folder::group())) { // List of objects under document root insertRow(aRow + aNbSubFolders, aDocRoot); } else { @@ -383,7 +384,7 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn { std::string aType = theObject->groupName(); DocumentPtr aDoc = theObject->document(); - int aRow = aDoc->index(theObject); + int aRow = aDoc->index(theObject, true); if (aRow == -1) { // it could be a part of complex object FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); @@ -413,10 +414,11 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject, int theColumn } SessionPtr aSession = ModelAPI_Session::get(); DocumentPtr aRootDoc = aSession->moduleDocument(); - if (aDoc == aRootDoc && myXMLReader->rootType() == aType) { + if (aDoc == aRootDoc && + ((myXMLReader->rootType() == aType) || (aType == ModelAPI_Folder::group()))) { // The object from root document aRow += foldersCount(); - } else if (myXMLReader->subType() == aType) { + } else if ((myXMLReader->subType() == aType) || (aType == ModelAPI_Folder::group())) { // The object from sub document aRow += foldersCount(aDoc.get()); } @@ -497,14 +499,13 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const } } } else { - ModelAPI_Object* aObj = - dynamic_cast((ModelAPI_Entity*)theIndex.internalPointer()); + ObjectPtr aObj = object(theIndex); if (aObj) { switch (theRole) { case Qt::DisplayRole: { if (aObj->groupName() == ModelAPI_ResultParameter::group()) { - ModelAPI_ResultParameter* aParam = dynamic_cast(aObj); + ResultParameterPtr aParam = std::dynamic_pointer_cast(aObj); AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE()); QString aVal = QString::number(aValueAttribute->value()); @@ -513,7 +514,7 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const } QString aSuffix; if (aObj->groupName() == myXMLReader->subType()) { - ResultPartPtr aPartRes = getPartResult(aObj); + ResultPartPtr aPartRes = getPartResult(aObj.get()); if (aPartRes.get()) { if (aPartRes->partDoc().get() == NULL) aSuffix = " (Not loaded)"; @@ -522,7 +523,12 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const return aObj->data()->name().c_str() + aSuffix; } case Qt::DecorationRole: - return ModuleBase_IconFactory::get()->getIcon(object(theIndex)); + { + if (aObj->groupName() == ModelAPI_Folder::group()) + return QIcon(":pictures/features_folder.png"); + else + return ModuleBase_IconFactory::get()->getIcon(aObj); + } } } else { switch (theRole) { @@ -564,7 +570,7 @@ int XGUI_DataModel::rowCount(const QModelIndex& theParent) const int aNbItems = 0; std::string aType = myXMLReader->rootType(); if (!aType.empty()) - aNbItems = aRootDoc->size(aType); + aNbItems = aRootDoc->size(aType, true); return aNbFolders + aNbItems; } @@ -601,7 +607,7 @@ int XGUI_DataModel::rowCount(const QModelIndex& theParent) const int aNbSubItems = 0; std::string aSubType = myXMLReader->subType(); if (!aSubType.empty()) - aNbSubItems = aSubDoc->size(aSubType); + aNbSubItems = aSubDoc->size(aSubType, true); return aNbSubItems + aNbSubFolders; } else { // Check for composite object @@ -641,8 +647,8 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & else { // return object under root index std::string aType = myXMLReader->rootType(); int aObjId = theRow - aNbFolders; - if (aObjId < aRootDoc->size(aType)) { - ObjectPtr aObj = aRootDoc->object(aType, aObjId); + if (aObjId < aRootDoc->size(aType, true)) { + ObjectPtr aObj = aRootDoc->object(aType, aObjId, true); aIndex = objectIndex(aObj, theColumn); } } @@ -652,7 +658,7 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & if (aId == 0) { // return object index inside of first level of folders std::string aType = myXMLReader->rootFolderType(aParentPos); if (theRow < aRootDoc->size(aType)) { - ObjectPtr aObj = aRootDoc->object(aType, theRow); + ObjectPtr aObj = aRootDoc->object(aType, theRow, true); aIndex = objectIndex(aObj, theColumn); } } else { @@ -685,7 +691,7 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex & } else { // this is an object under sub document root std::string aType = myXMLReader->subType(); - ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders); + ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders, true); aIndex = objectIndex(aObj, theColumn); } } else { @@ -773,7 +779,7 @@ QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const DocumentPtr aRootDoc = aSession->moduleDocument(); DocumentPtr aSubDoc = aObj->document(); if (aSubDoc == aRootDoc) { - if (aType == myXMLReader->rootType()) + if ((aType == myXMLReader->rootType()) || (aType == ModelAPI_Folder::group())) return QModelIndex(); else { // return first level of folder index @@ -782,7 +788,7 @@ QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const return createIndex(aFolderId, 1, (void*)Q_NULLPTR); } } else { - if (aType == myXMLReader->subType()) + if ((aType == myXMLReader->subType()) || (aType == ModelAPI_Folder::group())) return findDocumentRootIndex(aSubDoc.get()); else { // return first level of folder index @@ -916,7 +922,7 @@ QModelIndex ObjectPtr aObj; ResultPartPtr aPartRes; for (int i = 0; i < aNb; i++) { - aObj = aRootDoc->object(ModelAPI_Feature::group(), i); + aObj = aRootDoc->object(ModelAPI_Feature::group(), i, true); aPartRes = getPartResult(aObj.get()); if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) { int aRow = i; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d6791ab65..cb5ca1d17 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1413,6 +1413,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) setViewerSelectionMode(TopAbs_EDGE); } else if (theId == "SELECT_FACE_CMD") { setViewerSelectionMode(TopAbs_FACE); + } else if (theId == "INSERT_FOLDER_CMD") { + insertFeatureFolder(); } else if (theId == "SELECT_RESULT_CMD") { //setViewerSelectionMode(-1); //IMP: an attempt to use result selection with other selection modes @@ -1507,9 +1509,10 @@ void XGUI_Workshop::deleteObjects() bool hasParameter = false; bool hasCompositeOwner = false; bool hasResultInHistory = false; + bool hasFolder = false; ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner, - hasResultInHistory); - if (!(hasFeature || hasParameter)) + hasResultInHistory, hasFolder); + if (!(hasFeature || hasParameter || hasFolder)) return; // delete objects @@ -2408,3 +2411,22 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects) objectBrowser()->blockSignals(aBlocked); } } + +void XGUI_Workshop::insertFeatureFolder() +{ + QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); + if (aObjects.isEmpty()) + return; + ObjectPtr aObj = aObjects.first(); + FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); + if (aFeature.get() == NULL) + return; + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aDoc = aMgr->activeDocument(); + + aMgr->startOperation(); + aDoc->addFolder(aFeature); + aMgr->finishOperation(); + + //myObjectBrowser->rebuildDataTree(); +} diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 871e2df12..53ce3b98a 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -448,6 +448,9 @@ private: /// Display results from a group void displayGroupResults(DocumentPtr theDoc, std::string theGroup); + /// Insert folder object before currently selected feature + void insertFeatureFolder(); + private slots: /// SLOT, that is called after the operation is started. Update workshop state according to /// the started operation, e.g. visualizes the property panel and connect to it. diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index d2f9f767e..35a345fe0 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -62,5 +62,6 @@ pictures/eyeopen.png pictures/transparency.png + pictures/features_folder.png diff --git a/src/XGUI/pictures/features_folder.png b/src/XGUI/pictures/features_folder.png new file mode 100644 index 000000000..055992b5c Binary files /dev/null and b/src/XGUI/pictures/features_folder.png differ