X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Workshop.cpp;h=8f01c2d620ad63878bb7891df7f0ffad5aba016d;hb=176403004ff97696f3c0b5f8bdf48692177fb34a;hp=d7f38883ae936c3c8119f71402b5da68859a3f7f;hpb=69ed966e5a75e545b5e9ae71499fd08790819484;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d7f38883a..8f01c2d62 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -6,6 +6,7 @@ #include "XGUI_ActionsMgr.h" #include "XGUI_MenuMgr.h" #include "XGUI_ColorDialog.h" +#include "XGUI_DeflectionDialog.h" #include "XGUI_ContextMenuMgr.h" #include "XGUI_Displayer.h" #include "XGUI_ErrorDialog.h" @@ -36,6 +37,7 @@ #include #include +#include #include #include #include @@ -70,6 +72,7 @@ #include #include #include +#include #include #include @@ -146,6 +149,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) QString aPath = Config_XMLReader::pluginConfigFile().c_str(); QDir aDir(aPath); + // Load translations QStringList aFilters; aFilters << "*_en.ts"; QStringList aTsFiles = aDir.entryList(aFilters, QDir::Files); @@ -175,8 +179,6 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) myErrorMgr = new XGUI_ErrorMgr(this, aWorkshop); - connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)), - SLOT(onOperationStarted(ModuleBase_Operation*))); connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)), SLOT(onOperationResumed(ModuleBase_Operation*))); connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), @@ -197,21 +199,36 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color", // Config_Prop::Color, "225,225,225"); - Config_PropManager::registerProp("Visualization", "result_body_color", "Body color", + Config_PropManager::registerProp("Visualization", "result_body_color", "Result color", Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR()); Config_PropManager::registerProp("Visualization", "result_group_color", "Group color", Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR()); - Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color", - Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR()); + Config_PropManager::registerProp("Visualization", "result_construction_color", + "Construction color", + Config_Prop::Color, + ModelAPI_ResultConstruction::DEFAULT_COLOR()); Config_PropManager::registerProp("Visualization", "result_part_color", "Part color", Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR()); - + + Config_PropManager::registerProp("Visualization", "body_deflection", + "Body deflection coefficient", + Config_Prop::Double, + ModelAPI_ResultBody::DEFAULT_DEFLECTION());//"0.001"); + + Config_PropManager::registerProp("Visualization", "construction_deflection", + "Construction deflection coefficient", + Config_Prop::Double, + ModelAPI_ResultConstruction::DEFAULT_DEFLECTION());//"0.0001"); + if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true)) myViewerSelMode.append(TopAbs_FACE); if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "edge-selection", true)) myViewerSelMode.append(TopAbs_EDGE); if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "vertex-selection", true)) myViewerSelMode.append(TopAbs_VERTEX); + //IMP: an attempt to use result selection with other selection modes + myViewerSelMode.append(ModuleBase_ResultPrs::Sel_Result);//TopAbs_VERTEX); + myViewerSelMode.append(TopAbs_COMPSOLID); } //****************************************************** @@ -309,7 +326,8 @@ void XGUI_Workshop::initMenu() QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"), tr("Undo last command"), QIcon(":pictures/undo.png"), - QKeySequence::Undo, false, "MEN_DESK_EDIT"); + QKeySequence::Undo, false, + "MEN_DESK_EDIT"); QString aToolBarTitle = tr( "INF_DESK_TOOLBAR_STANDARD" ); salomeConnector()->addActionInToolbar( aAction,aToolBarTitle ); @@ -325,7 +343,8 @@ void XGUI_Workshop::initMenu() addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList&)), SLOT(onRedo(int))); salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT"); - //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"), + //aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), + // tr("Rebuild data objects"), // QIcon(":pictures/rebuild.png"), QKeySequence(), // false, "MEN_DESK_EDIT"); //salomeConnector()->addActionInToolbar( aAction, aToolBarTitle ); @@ -333,12 +352,14 @@ void XGUI_Workshop::initMenu() //connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild())); //salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT"); - aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."), tr("Export the current document into a native file"), + aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export native..."), + tr("Export the current document into a native file"), QIcon(), QKeySequence(), false, "MEN_DESK_FILE"); connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs())); - aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."), tr("Import native file"), + aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import native..."), + tr("Import native file"), QIcon(), QKeySequence(), false, "MEN_DESK_FILE"); connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen())); @@ -483,9 +504,10 @@ bool XGUI_Workshop::isFeatureOfNested(const FeaturePtr& theFeature) return aHasNested; } -void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) +void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation) { - ModuleBase_OperationFeature* aFOperation = dynamic_cast(theOperation); + ModuleBase_OperationFeature* aFOperation = + dynamic_cast(theOperation); if (!aFOperation) return; @@ -507,7 +529,8 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) if (!aWidget->attributeID().empty() && !aFeature->attribute(aWidget->attributeID()).get()) { std::string anErrorMsg = "The feature '%1' has no attribute '%2' used by widget '%3'."; Events_InfoMessage("XGUI_Workshop", anErrorMsg) - .arg(aFeatureKind).arg(aWidget->attributeID()).arg(aWidget->metaObject()->className()).send(); + .arg(aFeatureKind).arg(aWidget->attributeID()) + .arg(aWidget->metaObject()->className()).send(); myPropertyPanel->cleanContent(); return; } @@ -527,7 +550,8 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) // update visible state of Preview button #ifdef HAVE_SALOME - bool anIsAutoPreview = mySalomeConnector->featureInfo(aFeatureKind.c_str())->isAutoPreview(); + bool anIsAutoPreview = + mySalomeConnector->featureInfo(aFeatureKind.c_str())->isAutoPreview(); #else AppElements_MainMenu* aMenuBar = mainWindow()->menuObject(); AppElements_Command* aCommand = aMenuBar->feature(aFeatureKind.c_str()); @@ -550,8 +574,9 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation) myPropertyPanel->setWindowTitle(theOperation->getDescription()->description()); #else std::string aFeatureName = aFeature->name(); - myPropertyPanel->setWindowTitle(QString("%1: %2").arg(theOperation->getDescription()->description()) - .arg(aFeatureName.c_str())); + myPropertyPanel->setWindowTitle(QString("%1: %2") + .arg(theOperation->getDescription()->description()) + .arg(aFeatureName.c_str())); #endif myErrorMgr->setPropertyPanel(myPropertyPanel); @@ -578,20 +603,13 @@ void XGUI_Workshop::connectToPropertyPanel(const bool isToConnect) } } -//****************************************************** -void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation) -{ - setGrantedFeatures(theOperation); - myModule->operationStarted(theOperation); -} - //****************************************************** void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation) { setGrantedFeatures(theOperation); if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel - setPropertyPanel(theOperation); + fillPropertyPanel(theOperation); connectToPropertyPanel(true); } updateCommandStatus(); @@ -626,7 +644,8 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) if (aFeature.get()) { // feature may be not created (plugin load fail) if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature)) anObjects.append(aFeature); - std::list aResults = aFeature->results(); + std::list aResults; + ModelAPI_Tools::allResults(aFeature, aResults); std::list::const_iterator aIt; for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { ResultPtr anObject = *aIt; @@ -651,7 +670,8 @@ void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation) void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation) { - ModuleBase_OperationFeature* aFOperation = dynamic_cast(theOperation); + ModuleBase_OperationFeature* aFOperation = + dynamic_cast(theOperation); if (!aFOperation) return; @@ -673,10 +693,7 @@ void XGUI_Workshop::setGrantedFeatures(ModuleBase_Operation* theOperation) aFOperation->setGrantedOperationIds(aGrantedIds); } - -/* - * Saves document with given name. - */ +//****************************************************** void XGUI_Workshop::saveDocument(const QString& theName, std::list& theFileNames) { QApplication::restoreOverrideCursor(); @@ -685,11 +702,24 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list& QApplication::restoreOverrideCursor(); } +//****************************************************** bool XGUI_Workshop::abortAllOperations() { return myOperationMgr->abortAllOperations(); } +//****************************************************** +void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation) +{ + setGrantedFeatures(theOperation); + if (!theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel + updateCommandStatus(); + } + else { + myModule->operationStarted(theOperation); + } +} + //****************************************************** void XGUI_Workshop::onOpen() { @@ -712,20 +742,33 @@ void XGUI_Workshop::onOpen() } //show file dialog, check if readable and open - myCurrentDir = QFileDialog::getExistingDirectory(desktop(), tr("Select directory")); + QString aDirectory = QFileDialog::getExistingDirectory(desktop(), tr("Select directory")); + openDirectory(aDirectory); +} + +//****************************************************** +void XGUI_Workshop::openDirectory(const QString& theDirectory) +{ + myCurrentDir = theDirectory; if (myCurrentDir.isEmpty()) return; + QFileInfo aFileInfo(myCurrentDir); if (!aFileInfo.exists() || !aFileInfo.isReadable()) { QMessageBox::critical(desktop(), tr("Warning"), tr("Unable to open the file.")); myCurrentDir = ""; return; } + QApplication::setOverrideCursor(Qt::WaitCursor); + SessionPtr aSession = ModelAPI_Session::get(); aSession->closeAll(); aSession->load(myCurrentDir.toLatin1().constData()); myObjectBrowser->rebuildDataTree(); updateCommandStatus(); +#ifndef HAVE_SALOME + myMainWindow->setCurrentDir(myCurrentDir, true); +#endif QApplication::restoreOverrideCursor(); } @@ -837,7 +880,8 @@ bool XGUI_Workshop::onSaveAs() if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) { int answer = QMessageBox::question( desktop(), - //: Title of the dialog which asks user if he wants to save study in existing non-empty folder + // Title of the dialog which asks user if he wants to save study + // in existing non-empty folder tr("Save"), tr("The directory already contains some files, save anyway?"), QMessageBox::Save | QMessageBox::Cancel); @@ -881,8 +925,8 @@ void XGUI_Workshop::onRedo(int theTimes) { // the viewer update should be blocked in order to avoid the features blinking. For the created // feature a results are created, the flush of the created signal caused the viewer redisplay for - // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until - // redo of all possible objects happens + // each created result. After a redisplay signal is flushed. So, the viewer update is blocked + // until redo of all possible objects happens bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false); objectBrowser()->treeView()->setCurrentIndex(QModelIndex()); @@ -1102,7 +1146,9 @@ void XGUI_Workshop::updateHistory() QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent) { QDockWidget* aObjDock = new QDockWidget(theParent); - aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea); + aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | + Qt::RightDockWidgetArea | + Qt::BottomDockWidgetArea); aObjDock->setWindowTitle(tr("Object browser")); aObjDock->setStyleSheet( "::title { position: relative; padding-left: 5px; text-align: left center }"); @@ -1127,7 +1173,9 @@ void XGUI_Workshop::createDockWidgets() aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock); myPropertyPanel = new XGUI_PropertyPanel(aDesktop, myOperationMgr); myPropertyPanel->setupActions(myActionsMgr); - myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea); + myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | + Qt::RightDockWidgetArea | + Qt::BottomDockWidgetArea); aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel); hidePropertyPanel(); ///updateSelectionBy(ModuleBase_ISelection::Browser); @@ -1252,7 +1302,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) } else if (theId == "SELECT_FACE_CMD") { setViewerSelectionMode(TopAbs_FACE); } else if (theId == "SELECT_RESULT_CMD") { - setViewerSelectionMode(-1); + //setViewerSelectionMode(-1); + //IMP: an attempt to use result selection with other selection modes + setViewerSelectionMode(ModuleBase_ResultPrs::Sel_Result); + setViewerSelectionMode(TopAbs_COMPSOLID); } else if (theId == "SHOW_RESULTS_CMD") { highlightResults(aObjects); } else if (theId == "SHOW_FEATURE_CMD") { @@ -1297,9 +1350,6 @@ void XGUI_Workshop::deleteObjects() QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); if (!abortAllOperations()) return; - // check whether the object can be deleted. There should not be parts which are not loaded - if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects)) - return; bool hasResult = false; bool hasFeature = false; @@ -1378,13 +1428,14 @@ void XGUI_Workshop::cleanHistory() anInfo.append(aFeature->name().c_str()); } QString anInfoStr = anInfo.join(";\t"); - qDebug(QString("cleanHistory for: [%1] - %2").arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str()); + qDebug(QString("cleanHistory for: [%1] - %2"). + arg(aFeatures.size()).arg(anInfoStr).toStdString().c_str()); #endif std::map > aReferences; ModelAPI_Tools::findAllReferences(aFeatures, aReferences, true, false); - // find for each object whether all reference values are in the map as key, that means that there is - // no other reference in the model to this object, so it might be removed by cleaning history + // find for each object whether all reference values are in the map as key, that means that there + // is no other reference in the model to this object, so it might be removed by cleaning history // sk_1(ext_1, vertex_1) + (sk_3, bool_1) - cann't be deleted, dependency to bool_1 // ext_1(bool_1, sk_3) - cann't be deleted, dependency to bool_1 // vertex_1() @@ -1398,7 +1449,8 @@ void XGUI_Workshop::cleanHistory() for (; aMainIt != aMainLast; aMainIt++) { FeaturePtr aMainListFeature = aMainIt->first; std::set aMainRefList = aMainIt->second; - std::set::const_iterator aRefIt = aMainRefList.begin(), aRefLast = aMainRefList.end(); + std::set::const_iterator aRefIt = aMainRefList.begin(), + aRefLast = aMainRefList.end(); bool aFeatureOutOfTheList = false; for (; aRefIt != aRefLast && !aFeatureOutOfTheList; aRefIt++) { FeaturePtr aRefFeature = *aRefIt; @@ -1414,7 +1466,8 @@ void XGUI_Workshop::cleanHistory() FeaturePtr aFeature = *aFIt; anInfo.append(aFeature->name().c_str()); } - qDebug(QString("unused objects: [%1] - %2").arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str()); + qDebug(QString("unused objects: [%1] - %2"). + arg(anInfo.size()).arg(anInfo.join(";\t")).toStdString().c_str()); #endif // warn about the references remove, break the delete operation if the user chose it @@ -1435,14 +1488,15 @@ void XGUI_Workshop::cleanHistory() aMessageBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes); aMessageBox.setDefaultButton(QMessageBox::No); - QString aText = QString(tr("Unused features are the following: %1.\nThese features will be deleted.\nWould you like to continue?") - .arg(anUnusedNames)); + QString aText = QString(tr("Unused features are the following: \ +%1.\nThese features will be deleted.\nWould you like to continue?").arg(anUnusedNames)); aMessageBox.setText(aText); if (aMessageBox.exec() == QMessageBox::No) return; // 1. start operation - aDescription += "by deleting of " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", ")); + aDescription += "by deleting of " + + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", ")); ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module()); operationMgr()->startOperation(anOpAction); @@ -1498,20 +1552,21 @@ void XGUI_Workshop::moveObjects() // moving and negative consequences connected with processing of already moved items mySelector->clearSelection(); // check whether the object can be moved. There should not be parts which are not loaded - if (!XGUI_Tools::canRemoveOrRename(desktop(), anObjects)) + std::set aFeatures; + ModuleBase_Tools::convertToFeatures(anObjects, aFeatures); + if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures)) return; DocumentPtr anActiveDocument = aMgr->activeDocument(); FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true); - foreach (ObjectPtr aObject, anObjects) { - if (!myModule->canApplyAction(aObject, anActionId)) + std::set::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); + for (; anIt != aLast; anIt++) { + FeaturePtr aFeature = *anIt; + if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId)) continue; - FeaturePtr aFeature = std::dynamic_pointer_cast(aObject); - if (aFeature.get()) { - anActiveDocument->moveFeature(aFeature, aCurrentFeature); - aCurrentFeature = anActiveDocument->currentFeature(true); - } + anActiveDocument->moveFeature(aFeature, aCurrentFeature); + aCurrentFeature = anActiveDocument->currentFeature(true); } aMgr->finishOperation(); } @@ -1553,7 +1608,9 @@ std::list allFeatures(const DocumentPtr& theDocument) // The order of appending features of the part and the part itself is important // Append features from a part feature - foreach (const ResultPtr& aResult, aFeature->results()) { + std::list aResults; + ModelAPI_Tools::allResults(aFeature, aResults); + foreach (const ResultPtr& aResult, aResults) { ResultPartPtr aResultPart = std::dynamic_pointer_cast(aResult); if (aResultPart.get() && aResultPart->partDoc().get()) { @@ -1577,15 +1634,18 @@ std::list toCurrentFeatures(const ObjectPtr& theObject) DocumentPtr aDocument = theObject->document(); std::list anAllFeatures = allFeatures(aDocument); // find the object iterator - std::list::iterator aObjectIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject); + std::list::iterator aObjectIt = + std::find(anAllFeatures.begin(), anAllFeatures.end(), theObject); if (aObjectIt == anAllFeatures.end()) return aResult; // find the current feature iterator - std::list::iterator aCurrentIt = std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true)); + std::list::iterator aCurrentIt = + std::find(anAllFeatures.begin(), anAllFeatures.end(), aDocument->currentFeature(true)); if (aCurrentIt == anAllFeatures.end()) return aResult; // check the right order - if (std::distance(aObjectIt, anAllFeatures.end()) <= std::distance(aCurrentIt, anAllFeatures.end())) + if (std::distance(aObjectIt, anAllFeatures.end()) <= + std::distance(aCurrentIt, anAllFeatures.end())) return aResult; // exclude the object std::advance(aObjectIt, 1); @@ -1741,10 +1801,12 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) foreach(ObjectPtr anObj, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObj); if (aResult.get() != NULL) { - ResultCompSolidPtr aCompsolidResult = std::dynamic_pointer_cast(aResult); + ResultCompSolidPtr aCompsolidResult = + std::dynamic_pointer_cast(aResult); if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) { - setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult : aDlg->getRandomColor()); + setColor(aCompsolidResult->subResult(i), !isRandomColor ? aColorResult : + aDlg->getRandomColor()); } } setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor()); @@ -1754,6 +1816,93 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) updateCommandStatus(); } +//************************************************************** +bool XGUI_Workshop::canChangeDeflection() const +{ + QObjectPtrList aObjects = mySelector->selection()->selectedObjects(); + + std::set aTypes; + aTypes.insert(ModelAPI_ResultGroup::group()); + aTypes.insert(ModelAPI_ResultConstruction::group()); + aTypes.insert(ModelAPI_ResultBody::group()); + aTypes.insert(ModelAPI_ResultPart::group()); + + return hasResults(aObjects, aTypes); +} + +void setDeflection(ResultPtr theResult, const double theDeflection) +{ + if (!theResult.get()) + return; + + AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID()); + if (aDeflectionAttr.get() != NULL) + aDeflectionAttr->setValue(theDeflection); +} + + +//************************************************************** +void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects) +{ + AttributeDoublePtr aDoubleAttr; + // 1. find the current color of the object. This is a color of AIS presentation + // The objects are iterated until a first valid color is found + double aDeflection = -1; + foreach(ObjectPtr anObject, theObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get()) { + aDeflection = XGUI_CustomPrs::getResultDeflection(aResult); + } + 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()) { + aDeflection = anAISObj->getDeflection(); + } + } + if (aDeflection > 0) + break; + } + if (aDeflection < 0) + return; + + if (!abortAllOperations()) + return; + // 2. show the dialog to change the value + XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop()); + aDlg->setDeflection(aDeflection); + aDlg->move(QCursor::pos()); + bool isDone = aDlg->exec() == QDialog::Accepted; + if (!isDone) + return; + + // 3. abort the previous operation and start a new one + SessionPtr aMgr = ModelAPI_Session::get(); + QString aDescription = contextMenuMgr()->action("DEFLECTION_CMD")->text(); + aMgr->startOperation(aDescription.toStdString()); + + // 4. set the value to all results + aDeflection = aDlg->getDeflection(); + foreach(ObjectPtr anObj, theObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(anObj); + if (aResult.get() != NULL) { + ResultCompSolidPtr aCompsolidResult = + std::dynamic_pointer_cast(aResult); + if (aCompsolidResult.get() != NULL) { // change colors for all sub-solids + for(int i = 0; i < aCompsolidResult->numberOfSubs(); i++) { + setDeflection(aCompsolidResult->subResult(i), aDeflection); + } + } + setDeflection(aResult, aDeflection); + } + } + aMgr->finishOperation(); + updateCommandStatus(); +} + //************************************************************** #define SET_DISPLAY_GROUP(aGroupName, aDisplay) \ for (int i = 0; i < aDoc->size(aGroupName); i++) { \ @@ -1953,14 +2102,14 @@ void XGUI_Workshop::highlightResults(const QObjectPtrList& theObjects) { FeaturePtr aFeature; QObjectPtrList aSelList = theObjects; - std::list aResList; bool aHasHidden = false; foreach(ObjectPtr aObj, theObjects) { aFeature = std::dynamic_pointer_cast(aObj); if (aFeature.get()) { - aResList = aFeature->results(); + std::list aResults; + ModelAPI_Tools::allResults(aFeature, aResults); std::list >::const_iterator aIt; - for(aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) { + for(aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { aHasHidden |= (*aIt)->isConcealed(); aSelList.append(*aIt); }