X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Workshop.cpp;h=8859ef6546a163852b28fd902d1389e201563700;hb=c837befca5d8a28a000ac1b87345f038d87b727f;hp=b78a019bccde374fcd12c43ef7c647f5f00449fa;hpb=b86ed875ca3ab2b1d10a5d4d06a6954820849bed;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b78a019bc..8859ef654 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2020 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -51,7 +51,10 @@ #include #include -#ifndef HAVE_SALOME +#ifdef HAVE_SALOME +#include +#include +#else #include #include #include @@ -87,6 +90,7 @@ #include #include #include +#include #include #include @@ -151,16 +155,16 @@ #include #include +#include #include #ifdef TINSPECTOR -#include -#include +#include +#include #include #include static TInspector_Communicator* MyTCommunicator; static Handle(VInspector_CallBack) MyVCallBack; - #endif #ifdef _DEBUG @@ -170,6 +174,8 @@ static Handle(VInspector_CallBack) MyVCallBack; #ifdef WIN32 #include +#pragma warning(disable : 4456) // for nested foreach +#pragma warning(disable : 4189) // for declaration of unused variables (MAYBE_UNUSED) #else #include #endif @@ -677,8 +683,18 @@ void XGUI_Workshop::showHelpPage(const QString& thePage) const #endif QString aFileName = aDocDir + aSep + thePage; if (QFile::exists(aFileName)) { +#ifdef HAVE_SALOME + SUIT_Application* app = SUIT_Session::session()->activeApplication(); + if (app) + app->onHelpContextModule("SHAPER", aFileName); + else { + QUrl aUrl = QUrl::fromLocalFile(aFileName); + QDesktopServices::openUrl(aUrl); + } +#else QUrl aUrl = QUrl::fromLocalFile(aFileName); QDesktopServices::openUrl(aUrl); +#endif } } } @@ -1047,14 +1063,45 @@ void XGUI_Workshop::openFile(const QString& theDirectory) if (aNewPart) { int aSize = aRootDoc->size(ModelAPI_ResultPart::group()); if (aSize > 0 ) { - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0); - ResultPartPtr aPart = std::dynamic_pointer_cast(aObject); + ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), 0); + ResultPartPtr aPart = std::dynamic_pointer_cast(anObject); if (aPart.get()) aPart->activate(); } } #endif + int anActivationId = + ModuleBase_Preferences::resourceMgr()->integerValue("General", "part_activation_study", -1); + int aSize = aRootDoc->size(ModelAPI_ResultPart::group()); + + if (anActivationId == 0 && aSize > 0) { + ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), aSize - 1); + ResultPartPtr aPart = std::dynamic_pointer_cast(anObject); + if (aPart.get()) { + aPart->activate(); + ModuleBase_Tools::setDisplaying(aPart); + } + } + else if (anActivationId == 1) { + for (int anIndex = 0; anIndex < aSize; ++anIndex) { + ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), anIndex); + ResultPartPtr aPart = std::dynamic_pointer_cast(anObject); + if (aPart.get()) { + aPart->activate(); + ModuleBase_Tools::setDisplaying(aPart); + + if (anIndex < aSize - 1) { + SessionPtr aMgr = ModelAPI_Session::get(); + aMgr->startOperation("Activation"); + aMgr->setActiveDocument(aMgr->moduleDocument()); + aMgr->finishOperation(); + updateCommandStatus(); + viewer()->update(); + } + } + } + } QApplication::restoreOverrideCursor(); } @@ -1115,6 +1162,12 @@ void XGUI_Workshop::onPreferences() } else if (aSection == ModuleBase_Preferences::MENU_SECTION) { myMainWindow->menuObject()->updateFromResources(); } + else if (aSection == ModuleBase_Preferences::GENERAL_SECTION && aPref.second == "create_init_part") { + bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue( + ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true); + Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate); + aCreateMsg.send(); + } } std::vector aColor; try { @@ -1723,19 +1776,23 @@ ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const //************************************************************** void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) { - QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); + QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); if (theId == "DELETE_CMD") deleteObjects(); else if (theId == "CLEAN_HISTORY_CMD") cleanHistory(); else if (theId == "MOVE_CMD" || theId == "MOVE_SPLIT_CMD") moveObjects(theId == "MOVE_SPLIT_CMD"); + else if (theId == "RECOVER_CMD") + recoverFeature(); else if (theId == "COLOR_CMD") - changeColor(aObjects); + changeColor(anObjects); + else if (theId == "AUTOCOLOR_CMD") + changeAutoColor(anObjects); else if (theId == "ISOLINES_CMD") - changeIsoLines(aObjects); + changeIsoLines(anObjects); else if (theId == "SHOW_ISOLINES_CMD") { - foreach(ObjectPtr aObj, aObjects) { + foreach(ObjectPtr aObj, anObjects) { ResultPtr aResult = std::dynamic_pointer_cast(aObj); if (aResult.get()) ModelAPI_Tools::showIsoLines(aResult, !ModelAPI_Tools::isShownIsoLines(aResult)); @@ -1744,27 +1801,29 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } else if (theId == "DEFLECTION_CMD") - changeDeflection(aObjects); + changeDeflection(anObjects); else if (theId == "TRANSPARENCY_CMD") - changeTransparency(aObjects); + changeTransparency(anObjects); else if (theId == "SHOW_CMD") { - showObjects(aObjects, true); + showObjects(anObjects, true); mySelector->updateSelectionBy(ModuleBase_ISelection::Browser); updateCommandStatus(); } else if (theId == "HIDE_CMD") { - showObjects(aObjects, false); + showObjects(anObjects, false); updateCommandStatus(); } else if (theId == "SHOW_ONLY_CMD") { - showOnlyObjects(aObjects); + showOnlyObjects(anObjects); mySelector->updateSelectionBy(ModuleBase_ISelection::Browser); updateCommandStatus(); } else if (theId == "SHADING_CMD") - setDisplayMode(aObjects, XGUI_Displayer::Shading); + setDisplayMode(anObjects, XGUI_Displayer::Shading); else if (theId == "WIREFRAME_CMD") - setDisplayMode(aObjects, XGUI_Displayer::Wireframe); + setDisplayMode(anObjects, XGUI_Displayer::Wireframe); + else if (theId == "SHOW_EDGES_DIRECTION_CMD") + toggleEdgesDirection(anObjects); else if (theId == "HIDEALL_CMD") { QObjectPtrList aList = myDisplayer->displayedObjects(); foreach (ObjectPtr aObj, aList) { @@ -1801,9 +1860,9 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result); setViewerSelectionMode(TopAbs_COMPSOLID); } else if (theId == "SHOW_RESULTS_CMD") { - highlightResults(aObjects); + highlightResults(anObjects); } else if (theId == "SHOW_FEATURE_CMD") { - highlightFeature(aObjects); + highlightFeature(anObjects); } else if (theId == "SET_VIEW_NORMAL_CMD") { setNormalView(); } else if (theId == "SET_VIEW_INVERTEDNORMAL_CMD") { @@ -1811,7 +1870,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) } #ifdef TINSPECTOR else if (theId == "TINSPECTOR_VIEW") { - Handle(CDF_Application) anApplication = CDF_Session::CurrentSession()->CurrentApplication(); + std::shared_ptr aSession = + std::dynamic_pointer_cast(ModelAPI_Session::get()); + + Handle(TDocStd_Application) anApplication = aSession->application(); if (!anApplication.IsNull()) { if (!MyTCommunicator) @@ -2242,6 +2304,15 @@ void XGUI_Workshop::moveObjects(const bool theSplit) myViewerProxy->update(); } +void XGUI_Workshop::recoverFeature() +{ + if (!abortAllOperations()) + return; + + static const QString RECOVER_OP_NAME = "Recover"; + module()->launchOperation(RECOVER_OP_NAME, false); +} + //************************************************************** bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theObjects) { @@ -2305,9 +2376,9 @@ std::list toCurrentFeatures(const ObjectPtr& theObject) DocumentPtr aDocument = theObject->document(); std::list anAllFeatures = allFeatures(aDocument); // find the object iterator - std::list::iterator aObjectIt = + std::list::iterator anObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject); - if (aObjectIt == anAllFeatures.end()) + if (anObjectIt == anAllFeatures.end()) return aResult; // find the current feature iterator std::list::iterator aCurrentIt = @@ -2315,14 +2386,14 @@ std::list toCurrentFeatures(const ObjectPtr& theObject) if (aCurrentIt == anAllFeatures.end()) return aResult; // check the right order - if (std::distance(aObjectIt, anAllFeatures.end()) <= + if (std::distance(anObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end())) return aResult; // exclude the object - std::advance(aObjectIt, 1); + std::advance(anObjectIt, 1); // include the current feature std::advance(aCurrentIt, 1); - return std::list(aObjectIt, aCurrentIt); + return std::list(anObjectIt, aCurrentIt); } //****************************************************** @@ -2330,29 +2401,29 @@ bool XGUI_Workshop::canMoveFeature() { QString anActionId = "MOVE_CMD"; - QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); + QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); QObjectPtrList aValidatedObjects; - foreach (ObjectPtr aObject, aObjects) { - if (!myModule->canApplyAction(aObject, anActionId)) + foreach (ObjectPtr anObject, anObjects) { + if (!myModule->canApplyAction(anObject, anActionId)) continue; // To be moved feature should be in active document - if (aObject->document() != ModelAPI_Session::get()->activeDocument()) + if (anObject->document() != ModelAPI_Session::get()->activeDocument()) continue; - aValidatedObjects.append(aObject); + aValidatedObjects.append(anObject); } - if (aValidatedObjects.size() != aObjects.size()) - aObjects = aValidatedObjects; + if (aValidatedObjects.size() != anObjects.size()) + anObjects = aValidatedObjects; - bool aCanMove = !aObjects.empty(); + bool aCanMove = !anObjects.empty(); - QObjectPtrList::const_iterator anIt = aObjects.begin(), aLast = aObjects.end(); + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); for (; anIt != aLast && aCanMove; anIt++) { - ObjectPtr aObject = *anIt; - if (!aObject.get() || !aObject->data().get() || !aObject->data()->isValid()) { + ObjectPtr anObject = *anIt; + if (!anObject.get() || !anObject->data().get() || !anObject->data()->isValid()) { aCanMove = false; break; } - FeaturePtr aFeat = std::dynamic_pointer_cast(aObject); + FeaturePtr aFeat = std::dynamic_pointer_cast(anObject); // only groups can be moved to the end for now (#2451) if (aFeat.get() && aFeat->getKind() != "Group") { aCanMove = false; @@ -2360,15 +2431,15 @@ bool XGUI_Workshop::canMoveFeature() } // 1. Get features placed between selected and current in the document - std::list aFeaturesBetween = toCurrentFeatures(aObject); - // if aFeaturesBetween is empty it means wrong order or aObject is the current feature + std::list aFeaturesBetween = toCurrentFeatures(anObject); + // if aFeaturesBetween is empty it means wrong order or anObject is the current feature if (aFeaturesBetween.empty()) aCanMove = false; else { std::set aPlacedFeatures(aFeaturesBetween.begin(), aFeaturesBetween.end()); // 2. Get all reference features to the selected object in the document std::set aRefFeatures; - ModuleBase_Tools::refsToFeatureInFeatureDocument(aObject, aRefFeatures); + ModuleBase_Tools::refsToFeatureInFeatureDocument(anObject, aRefFeatures); if (aRefFeatures.empty()) continue; @@ -2411,7 +2482,7 @@ bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const if (theActionName == "COLOR_CMD" || theActionName == "DEFLECTION_CMD" || theActionName == "TRANSPARENCY_CMD") { - QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); + QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); std::set aTypes; aTypes.insert(ModelAPI_ResultGroup::group()); @@ -2419,7 +2490,16 @@ bool XGUI_Workshop::canChangeProperty(const QString& theActionName) const aTypes.insert(ModelAPI_ResultBody::group()); aTypes.insert(ModelAPI_ResultPart::group()); - return hasResults(aObjects, aTypes); + return hasResults(anObjects, aTypes); + } + if (theActionName == "AUTOCOLOR_CMD") { + + QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); + + std::set aTypes; + aTypes.insert(ModelAPI_ResultGroup::group()); + + return hasResults(anObjects, aTypes); } return false; } @@ -2459,22 +2539,17 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { ModelAPI_Tools::getColor(aResult, aColor); - if (aColor.empty()) + if (aColor.empty()) { + AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject); + if (anAISObj.get()) { + aColor.resize(3); + anAISObj->getColor(aColor[0], aColor[1], aColor[2]); + } + } + if (aColor.empty()) { getDefaultColor(aResult, false, aColor); - } - else { - // TODO: remove the obtaining a color from the AIS object - // this does not happen never because: - // 1. The color can be changed only on results - // 2. The result can be not visualized in the viewer(e.g. Origin Construction) - AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject); - if (anAISObj.get()) { - aColor.resize(3); - anAISObj->getColor(aColor[0], aColor[1], aColor[2]); } } - if (!aColor.empty()) - break; } if (aColor.size() != 3) return; @@ -2494,6 +2569,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) // 3. abort the previous operation and start a new one SessionPtr aMgr = ModelAPI_Session::get(); QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text(); + aMgr->startOperation(aDescription.toStdString()); // 4. set the value to all results @@ -2518,6 +2594,56 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) myViewerProxy->update(); } +//************************************************************** +void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects) +{ + if (!abortAllOperations()) + return; + + std::vector aColor; + + // abort the previous operation and start a new one + SessionPtr aMgr = ModelAPI_Session::get(); + QString aDescription = contextMenuMgr()->action("AUTOCOLOR_CMD")->text(); + aMgr->startOperation(aDescription.toStdString()); + + if (Config_PropManager::getAutoColorStatus()) { + contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Auto color")); + Config_PropManager::setAutoColorStatus(false); + ModelAPI_Tools::findRandomColor(aColor, true); + } else { + // set the value to all results + foreach (ObjectPtr anObj, theObjects) { + DocumentPtr aDocument = anObj->document(); + std::list anAllFeatures = allFeatures(aDocument); + // find the object iterator + std::list::iterator anObjectIt = anAllFeatures.begin(); + for (; anObjectIt != anAllFeatures.end(); ++ anObjectIt) { + FeaturePtr aFeature = *anObjectIt; + if (aFeature.get()) { + std::list aResults; + ModelAPI_Tools::allResults(aFeature, aResults); + std::list >::const_iterator aIt; + for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { + ResultPtr aGroupResult = *aIt; + if (aGroupResult.get() && + aGroupResult->groupName() == ModelAPI_ResultGroup::group()) { + ModelAPI_Tools::findRandomColor(aColor); + ModelAPI_Tools::setColor(aGroupResult, aColor); + } + } + } + } + } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + aMgr->finishOperation(); + updateCommandStatus(); + myViewerProxy->update(); + contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Disable auto color")); + Config_PropManager::setAutoColorStatus(true); + } +} + //************************************************************** void setTransparency(double theTransparency, const QObjectPtrList& theObjects) { @@ -2772,11 +2898,11 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) //************************************************************** void XGUI_Workshop::updateColorScaleVisibility() { - QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); - viewer()->setColorScaleShown(false); - if (aObjects.size() == 1) { + QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); + myViewerProxy->setColorScaleShown(false); + if (anObjects.size() == 1) { FieldStepPtr aStep = - std::dynamic_pointer_cast(aObjects.first()); + std::dynamic_pointer_cast(anObjects.first()); if (aStep.get() && myDisplayer->isVisible(aStep)) { AISObjectPtr aAisPtr = myDisplayer->getAISObject(aStep); Handle(AIS_InteractiveObject) aIO = aAisPtr->impl(); @@ -2804,6 +2930,55 @@ void XGUI_Workshop::updateColorScaleVisibility() } } +//************************************************************** +void XGUI_Workshop::updateGroupsText() +{ + ModuleBase_IViewer::TextColor aText; + + int aSize = 10; + SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr(); + if (aResMgr->booleanValue("Viewer", "group_names_display")) { + // the first item in the TextColor list is font name -> text color + QColor aTextColor = aResMgr->colorValue("Viewer", "group_names_color"); + std::vector aTextCV; + aTextCV.push_back(aTextColor.red()); + aTextCV.push_back(aTextColor.green()); + aTextCV.push_back(aTextColor.blue()); + QString aFontName = aResMgr->stringValue("Viewer", "group_names_font"); + aText.push_back(std::pair >(aFontName.toStdWString(), aTextCV)); + aSize = aResMgr->integerValue("Viewer", "group_names_size"); + + DocumentPtr aDoc = ModelAPI_Session::get()->activeDocument(); + int aNbGroups = aDoc->size(ModelAPI_ResultGroup::group()); + for (int aGIndex = 0; aGIndex < aNbGroups; aGIndex++) + { + ResultGroupPtr aGroup = std::dynamic_pointer_cast( + aDoc->object(ModelAPI_ResultGroup::group(), aGIndex)); + if (aGroup.get() && !aGroup->isDisabled() && aGroup->isDisplayed()) + { + std::vector aColor; + ModelAPI_Tools::getColor(aGroup, aColor); + if (aColor.empty()) + { // default groups colors + std::string aSection, aName, aDefault; + aGroup->colorConfigInfo(aSection, aName, aDefault); + if (!aSection.empty() && !aName.empty()) { + aColor = Config_PropManager::color(aSection, aName); + } + } + if (aColor.empty()) + { + aColor.push_back(150.); + aColor.push_back(150.); + aColor.push_back(150.); + } + aText.push_back(std::pair >(aGroup->data()->name(), aColor)); + } + } + } + myViewerProxy->setText(aText, aSize); +} + //************************************************************** void XGUI_Workshop::setNormalView(bool toInvert) @@ -2882,6 +3057,32 @@ void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode) myDisplayer->updateViewer(); } +//************************************************************** +void XGUI_Workshop::toggleEdgesDirection(const QObjectPtrList& theList) +{ + foreach(ObjectPtr anObj, theList) { + ResultPtr aResult = std::dynamic_pointer_cast(anObj); + if (aResult.get() != NULL) + { + bool aToShow = !ModelAPI_Tools::isShowEdgesDirection(aResult); + ResultBodyPtr aBodyResult = std::dynamic_pointer_cast(aResult); + if (aBodyResult.get() != NULL) { // change property for all sub-solids + std::list allRes; + ModelAPI_Tools::allSubs(aBodyResult, allRes); + std::list::iterator aRes; + for (aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + ModelAPI_Tools::showEdgesDirection(*aRes, aToShow); + myDisplayer->redisplay(*aRes, false); + } + } + ModelAPI_Tools::showEdgesDirection(aResult, aToShow); + myDisplayer->redisplay(anObj, false); + } + } + if (theList.size() > 0) + myDisplayer->updateViewer(); +} + //************************************************************** void XGUI_Workshop::closeDocument() { @@ -3090,10 +3291,10 @@ void XGUI_Workshop::highlightFeature(const QObjectPtrList& theObjects) void XGUI_Workshop::insertFeatureFolder() { - QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); - if (aObjects.isEmpty()) + QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); + if (anObjects.isEmpty()) return; - ObjectPtr aObj = aObjects.first(); + ObjectPtr aObj = anObjects.first(); FeaturePtr aFeature = std::dynamic_pointer_cast(aObj); if (aFeature.get() == NULL) return;