X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_Workshop.cpp;h=e7dcbfc72ac92d1569dc4fe0c05490a0456a615f;hb=f6a18cc1152654d56b94ab0a28c09eef5b1fbba6;hp=d10ccc61278a39e8c73840d8c2e5ddcfcf1d578a;hpb=95375993f1f35e4716475c0b0c8e265c082c875d;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d10ccc612..e7dcbfc72 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -45,7 +45,6 @@ #include "XGUI_Tools.h" #include "XGUI_ViewerProxy.h" #include "XGUI_WorkshopListener.h" -#include #include #include #include @@ -67,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +80,7 @@ #include #include #include +#include //#include @@ -87,7 +88,12 @@ #include #include +#include +#include +#include + #include +#include #include #include @@ -99,7 +105,6 @@ #include #include #include -#include #include #include #include @@ -168,21 +173,24 @@ static Handle(VInspector_CallBack) MyVCallBack; //#define DEBUG_WITH_MESSAGE_REPORT QString XGUI_Workshop::MOVE_TO_END_COMMAND = QObject::tr("Move to the end"); +QString XGUI_Workshop::MOVE_TO_END_SPLIT_COMMAND = QObject::tr("Move to the end and split"); //#define DEBUG_DELETE //#define DEBUG_FEATURE_NAME //#define DEBUG_CLEAN_HISTORY #ifdef HAVE_SALOME -static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.opp)")); +static QString MyFilter(QObject::tr("SHAPER files (*.shaper *.cadbld)")); static QString MyFilter2(QObject::tr("SHAPER files (*.shaper)")); static QString MyExtension(".shaper"); #else -static QString MyFilter(QObject::tr("CAD Builder files (*.opp);;All files (*.*)")); -static QString MyFilter2(QObject::tr("CAD Builder files (*.opp)")); -static QString MyExtension(".opp"); +static QString MyFilter(QObject::tr("CAD Builder files (*.cadbld);;All files (*.*)")); +static QString MyFilter2(QObject::tr("CAD Builder files (*.cadbld)")); +static QString MyExtension(".cadbld"); #endif +static QString MyImportPartFilter(QObject::tr("Part files (*.shaperpart);;All files (*.*)")); + //****************************************************** XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) @@ -220,7 +228,15 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) // Load translations QStringList aLangs; aLangs << "*_en.ts"; // load by default eng translations + + /// If version of OCCT is 7.4.0 or more then it means that + /// this is version of SALOME older then 9.4.0 +#if OCC_VERSION_HEX >= 0x070400 + QString aCurrLang = aResMgr->language(); +#else QString aCurrLang = aResMgr->stringValue("language", "language", "en"); +#endif + if(aCurrLang != "en") { aLangs << "*_" + aCurrLang + ".ts"; // then replace with translated files } @@ -268,27 +284,14 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) #ifndef HAVE_SALOME connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit())); - onTrihedronVisibilityChanged(true); + myDisplayer->displayTrihedron(true); #endif connect(myEventsListener, SIGNAL(errorOccurred(std::shared_ptr)), myErrorDlg, SLOT(addError(std::shared_ptr))); - //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color", - // Config_Prop::Color, "225,225,225"); - - 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_part_color", "Part color", - Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR()); - Config_PropManager::registerProp("Visualization", "result_field_color", "Field color", - Config_Prop::Color, ModelAPI_ResultField::DEFAULT_COLOR()); + Config_PropManager::registerProp("Visualization", "selection_color", "Selection color", + Config_Prop::Color, "255,255,255"); if (ModuleBase_Preferences::resourceMgr()->booleanValue("Viewer", "face-selection", true)) myViewerSelMode.append(TopAbs_FACE); @@ -346,6 +349,15 @@ void XGUI_Workshop::startApplication() // Calling of loadCustomProps before activating module is required // by Config_PropManger to restore user-defined path to plugins ModuleBase_Preferences::loadCustomProps(); + std::vector aColor; + try { + aColor = Config_PropManager::color("Visualization", "selection_color"); + } + catch (...) { + } + if (aColor.size() == 3) + myDisplayer->setSelectionColor(aColor); + createModule(); #ifndef HAVE_SALOME @@ -470,6 +482,26 @@ void XGUI_Workshop::initMenu() connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen())); salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE"); + aAction = salomeConnector()->addDesktopCommand("EXPORT_PART_CMD", tr("Export part..."), + tr("Export a part of the current document into a file"), + QIcon(), QKeySequence(), + false, "MEN_DESK_FILE"); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onExportPart())); + + aAction = salomeConnector()->addDesktopCommand("IMPORT_PART_CMD", tr("Import part..."), + tr("Import structure of a part"), + QIcon(), QKeySequence(), + false, "MEN_DESK_FILE"); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportPart())); + + aAction = salomeConnector()->addDesktopCommand("IMPORT_SHAPE_CMD", tr("Import shape..."), + tr("Import shape from a file"), + ModuleBase_IconFactory::loadIcon("icons/Exchange/import.png"), + QKeySequence(), false, "MEN_DESK_FILE"); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportShape())); + + salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE"); + #else // File commands group AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage(); @@ -676,12 +708,11 @@ void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation) if (!aFOperation) return; - showPanel(myPropertyPanel); myPropertyPanel->cleanContent(); QList aWidgets; - if (!module()->createWidgets(theOperation, aWidgets)) { - QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation(); + QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation(); + if (!module()->createWidgets(aFOperation->feature(), aXmlRepr, aWidgets)) { ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myModuleConnector); aFactory.createWidget(myPropertyPanel->contentWidget()); aWidgets = aFactory.getModelWidgets(); @@ -752,15 +783,22 @@ void XGUI_Workshop::fillPropertyPanel(ModuleBase_Operation* theOperation) myModule->propertyPanelDefined(theOperation); #ifndef DEBUG_FEATURE_NAME - myPropertyPanel->setWindowTitle(theOperation->getDescription()->description()); + myPropertyPanel->setWindowTitle(ModuleBase_Tools::translate("workshop", + theOperation->getDescription()->description().toStdString())); #else std::string aFeatureName = aFeature->name(); myPropertyPanel->setWindowTitle(QString("%1: %2") - .arg(theOperation->getDescription()->description()) - .arg(aFeatureName.c_str())); + .arg(translate(theOperation->getDescription()->description())) + .arg(translate(aFeatureName.c_str()))); #endif myErrorMgr->setPropertyPanel(myPropertyPanel); + if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) { + theOperation->setHideFacesVisible(myFacesPanel->isVisible()); + if (aFeatureInfo.get() && aFeatureInfo->isHideFacesPanel() && !myFacesPanel->isVisible()) + myFacesPanel->show(); + } + showPanel(myPropertyPanel); } //****************************************************** @@ -842,6 +880,11 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) } } activateObjectsSelection(anObjects); + + if (Config_PropManager::boolean("Windows", "use_hide_faces_panel")) { + if (!theOperation->isHideFacesVisible()) + myFacesPanel->close(); + } } //****************************************************** @@ -939,7 +982,11 @@ void XGUI_Workshop::onOpen() } //show file dialog, check if readable and open - QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter); + qreal aRatio = ModuleBase_Tools::currentPixelRatio(); + // If the ratio is > 1 (HD screen) then QT has a bug in + // displaying of system open file dialog (too small) + QString aFile = QFileDialog::getOpenFileName(desktop(), tr("Open file"), QString(), MyFilter, + Q_NULLPTR, ((aRatio > 1)? QFileDialog::DontUseNativeDialog : QFileDialog::Options())); if (!aFile.isNull()) openFile(aFile); } @@ -1014,6 +1061,8 @@ void XGUI_Workshop::onNew() QMdiSubWindow* aWnd = myMainWindow->viewer()->createView(); aWnd->showMaximized(); updateCommandStatus(); + PyConsole_Console* aConsole = myMainWindow->pythonConsole(); + connect(aConsole, SIGNAL(scriptLoaded()), SLOT(updateCommandStatus())); #endif myContextMenuMgr->connectViewer(); QApplication::restoreOverrideCursor(); @@ -1047,8 +1096,7 @@ void XGUI_Workshop::onPreferences() ModuleBase_Preferences::editPreferences(aModif); if (aModif.size() > 0) { QString aSection; - foreach (ModuleBase_Pref aPref, aModif) - { + foreach (ModuleBase_Pref aPref, aModif) { aSection = aPref.first; if (aSection == ModuleBase_Preferences::VIEWER_SECTION) { myMainWindow->viewer()->updateFromResources(); @@ -1056,6 +1104,15 @@ void XGUI_Workshop::onPreferences() myMainWindow->menuObject()->updateFromResources(); } } + std::vector aColor; + try { + aColor = Config_PropManager::color("Visualization", "selection_color"); + } + catch (...) { + } + if (aColor.size() == 3) + displayer()->setSelectionColor(aColor); + displayer()->redisplayObjects(); } } @@ -1065,8 +1122,10 @@ void XGUI_Workshop::onPreferences() void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState) { XGUI_Displayer* aDisplayer = displayer(); - if (aDisplayer) + if (aDisplayer) { aDisplayer->displayTrihedron(theState); + aDisplayer->updateViewer(); + } } //****************************************************** @@ -1106,8 +1165,10 @@ bool XGUI_Workshop::onSaveAs() { if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) return false; + qreal aRatio = ModuleBase_Tools::currentPixelRatio(); myCurrentFile = QFileDialog::getSaveFileName(desktop(), tr("Select name to save file..."), - QString(), MyFilter2); + QString(), MyFilter2, + Q_NULLPTR, ((aRatio > 1) ? QFileDialog::DontUseNativeDialog : QFileDialog::Options())); if (!myCurrentFile.isNull()) { if (!myCurrentFile.endsWith(MyExtension)) { myCurrentFile += MyExtension; @@ -1175,7 +1236,8 @@ void XGUI_Workshop::processUndoRedo(const ModuleBase_ActionType theActionType, i else aMgr->redo(); - if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND) + if (QString((*aIt).c_str()) == MOVE_TO_END_COMMAND || + QString((*aIt).c_str()) == MOVE_TO_END_SPLIT_COMMAND) myObjectBrowser->rebuildDataTree(); } operationMgr()->updateApplyOfOperations(); @@ -1231,6 +1293,37 @@ void XGUI_Workshop::onValuesChanged() void XGUI_Workshop::onWidgetObjectUpdated() { operationMgr()->onValidateOperation(); + myDisplayer->updateViewer(); +} + +//****************************************************** +void XGUI_Workshop::onImportPart() +{ + if (abortAllOperations()) { + ModuleBase_OperationFeature* anImportPartOp = dynamic_cast( + module()->createOperation(ExchangePlugin_ImportPart::ID())); + operationMgr()->startOperation(anImportPartOp); + } +} + +//****************************************************** +void XGUI_Workshop::onImportShape() +{ + if (abortAllOperations()) { + ModuleBase_OperationFeature* anImportOp = dynamic_cast( + module()->createOperation(ExchangePlugin_Import::ID())); + operationMgr()->startOperation(anImportOp); + } +} + +//****************************************************** +void XGUI_Workshop::onExportPart() +{ + if (abortAllOperations()) { + ModuleBase_OperationFeature* anExportPartOp = dynamic_cast( + module()->createOperation(ExchangePlugin_ExportPart::ID())); + operationMgr()->startOperation(anExportPartOp); + } } //****************************************************** @@ -1406,6 +1499,7 @@ QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent) myObjectBrowser->initialize(myModule->rootNode()); myModule->customizeObjectBrowser(myObjectBrowser); aObjDock->setWidget(myObjectBrowser); + aObjDock->setObjectName("Object browser"); connect(myObjectBrowser, SIGNAL(sizeChanged()), SLOT(onDockSizeChanged())); @@ -1433,14 +1527,14 @@ void XGUI_Workshop::createDockWidgets() hidePanel(myPropertyPanel); ///addSelector(new XGUI_FacesPanelSelector(myFacesPanel)); myFacesPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea); connect(myFacesPanel, SIGNAL(closed()), myFacesPanel, SLOT(onClosed())); - myInspectionPanel = new XGUI_InspectionPanel(aDesktop, mySelector); + myInspectionPanel = new XGUI_InspectionPanel(aDesktop, this); myInspectionPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); aDesktop->addDockWidget(Qt::RightDockWidgetArea, myInspectionPanel); @@ -1516,7 +1610,7 @@ void XGUI_Workshop::showPanel(QDockWidget* theDockWidget) // in order to operation manager could process key events of the panel. // otherwise they are ignored. It happens only if the same(activateWindow) is // not happened by property panel activation(e.g. resume operation of Sketch) - ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()"); + //ModuleBase_Tools::setFocus(theDockWidget, "XGUI_Workshop::showPanel()"); } //****************************************************** @@ -1575,8 +1669,8 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) deleteObjects(); else if (theId == "CLEAN_HISTORY_CMD") cleanHistory(); - else if (theId == "MOVE_CMD") - moveObjects(); + else if (theId == "MOVE_CMD" || theId == "MOVE_SPLIT_CMD") + moveObjects(theId == "MOVE_SPLIT_CMD"); else if (theId == "COLOR_CMD") changeColor(aObjects); else if (theId == "DEFLECTION_CMD") @@ -1788,10 +1882,14 @@ void XGUI_Workshop::deleteObjects() // allow the module to delete objects, do nothing if it has succeed if (aModule->deleteObjects()) { updateCommandStatus(); + myDisplayer->updateViewer(); return; } QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); + if (anObjects.isEmpty()) + return; + if (!abortAllOperations()) return; @@ -1806,6 +1904,21 @@ void XGUI_Workshop::deleteObjects() if (!(hasResult || hasFeature || hasParameter || hasFolder)) return; + // Remove from the list non-deletable objects: infinite constructions which are not in history + bool notDelete = true; + QObjectPtrList::iterator aIt; + for (aIt = anObjects.begin(); aIt != anObjects.end(); aIt++) { + ObjectPtr aObj = (*aIt); + ResultConstructionPtr aConstr = std::dynamic_pointer_cast(aObj); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature) { + notDelete = (!aFeature->isInHistory()) && aConstr->isInfinite(); + if (notDelete) { + anObjects.removeAll(aObj); + aIt--; + } + } + } // delete objects std::map > aReferences; std::set aFeatures; @@ -1818,7 +1931,7 @@ void XGUI_Workshop::deleteObjects() bool aDone = false; QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text() + " %1"; aDescription = aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", ")); - ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module()); + ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, module()); operationMgr()->startOperation(anOpAction); @@ -1861,6 +1974,8 @@ void XGUI_Workshop::deleteObjects() operationMgr()->commitOperation(); else operationMgr()->abortOperation(operationMgr()->currentOperation()); + + myDisplayer->updateViewer(); } //************************************************************** @@ -1954,7 +2069,8 @@ void XGUI_Workshop::cleanHistory() QString anUnusedNames = aNames.join(", "); QString anActionId = "CLEAN_HISTORY_CMD"; - QString aDescription = contextMenuMgr()->action(anActionId)->text(); + QString aDescription = ModuleBase_Tools::translate("workshop", + contextMenuMgr()->action(anActionId)->text().toStdString()); QMessageBox aMessageBox(desktop()); aMessageBox.setWindowTitle(aDescription); @@ -1972,7 +2088,7 @@ void XGUI_Workshop::cleanHistory() // 1. start operation aDescription += "by deleting of " + aDescription.arg(XGUI_Tools::unionOfObjectNames(anObjects, ", ")); - ModuleBase_OperationAction* anOpAction = new ModuleBase_OperationAction(aDescription, module()); + ModuleBase_Operation* anOpAction = new ModuleBase_Operation(aDescription, module()); operationMgr()->startOperation(anOpAction); // WORKAROUND, should be done before each object remove, if it presents in XGUI_DataModel tree @@ -2011,17 +2127,17 @@ void XGUI_Workshop::cleanHistory() } //************************************************************** -void XGUI_Workshop::moveObjects() +bool compareFeature(const FeaturePtr& theF1, const FeaturePtr& theF2) { + DocumentPtr aDoc = theF1->document(); + return aDoc->index(theF1) < aDoc->index(theF2); +} +void XGUI_Workshop::moveObjects(const bool theSplit) { if (!abortAllOperations()) return; SessionPtr aMgr = ModelAPI_Session::get(); - QString anActionId = "MOVE_CMD"; - QString aDescription = contextMenuMgr()->action(anActionId)->text(); - aMgr->startOperation(aDescription.toStdString()); - QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); // It is necessary to clear selection in order to avoid selection changed event during // moving and negative consequences connected with processing of already moved items @@ -2032,18 +2148,28 @@ void XGUI_Workshop::moveObjects() if (!XGUI_Tools::canRemoveOrRename(desktop(), aFeatures)) return; + QString anActionId = theSplit ? "MOVE_CMD" : "MOVE_SPLIT_CMD"; + QString aDescription = contextMenuMgr()->action(anActionId)->text(); + aMgr->startOperation(aDescription.toStdString()); + + // Sort features by index in document + std::list aFList(aFeatures.begin(), aFeatures.end()); + aFList.sort(compareFeature); + DocumentPtr anActiveDocument = aMgr->activeDocument(); FeaturePtr aCurrentFeature = anActiveDocument->currentFeature(true); - std::set::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end(); + std::list::const_iterator anIt = aFList.begin(), aLast = aFList.end(); for (; anIt != aLast; anIt++) { FeaturePtr aFeature = *anIt; if (!aFeature.get() || !myModule->canApplyAction(aFeature, anActionId)) continue; - anActiveDocument->moveFeature(aFeature, aCurrentFeature); + anActiveDocument->moveFeature(aFeature, aCurrentFeature, theSplit); aCurrentFeature = anActiveDocument->currentFeature(true); } aMgr->finishOperation(); + updateCommandStatus(); + myViewerProxy->update(); } //************************************************************** @@ -2243,9 +2369,28 @@ void setColor(ResultPtr theResult, const std::vector& theColor) aColorAttr->setValue(1, theColor[1]); aColorAttr->setValue(2, theColor[2]); } - static const Events_ID kRedisplayEvent = - Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); - ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent); +} + +//************************************************************** +void getDefaultColor(ObjectPtr theObject, const bool isEmptyColorValid, + std::vector& theColor) +{ + theColor.clear(); + // get default color from the preferences manager for the given result + if (theColor.empty()) { + std::string aSection, aName, aDefault; + theObject->colorConfigInfo(aSection, aName, aDefault); + if (!aSection.empty() && !aName.empty()) { + theColor = Config_PropManager::color(aSection, aName); + } + } + if (!isEmptyColorValid && theColor.empty()) { + // all AIS objects, where the color is not set, are in black. + // The color should be defined in XML or set in the attribute + theColor = Config_PropManager::color("Visualization", "object_default_color"); + Events_InfoMessage("XGUI_CustomPrs", + "A default color is not defined in the preferences for this kind of result").send(); + } } //************************************************************** @@ -2259,7 +2404,9 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) foreach(ObjectPtr anObject, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { - XGUI_CustomPrs::getResultColor(aResult, aColor); + ModelAPI_Tools::getColor(aResult, aColor); + if (aColor.empty()) + getDefaultColor(aResult, false, aColor); } else { // TODO: remove the obtaining a color from the AIS object @@ -2311,8 +2458,10 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor()); } } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); aMgr->finishOperation(); updateCommandStatus(); + myViewerProxy->update(); } //************************************************************** @@ -2322,11 +2471,9 @@ void setDeflection(ResultPtr theResult, const double theDeflection) return; AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID()); - if (aDeflectionAttr.get() != NULL) + if (aDeflectionAttr.get() != NULL) { aDeflectionAttr->setValue(theDeflection); - static const Events_ID kRedisplayEvent = - Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); - ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent); + } } //************************************************************** @@ -2336,11 +2483,9 @@ void setTransparency(ResultPtr theResult, double theTransparency) return; AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID()); - if (anAttribute.get() != NULL) + if (anAttribute.get() != NULL) { anAttribute->setValue(theTransparency); - static const Events_ID kRedisplayEvent = - Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); - ModelAPI_EventCreator::get()->sendUpdated(theResult, kRedisplayEvent); + } } //************************************************************** @@ -2353,7 +2498,8 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects) if (aBodyResult.get() != NULL) { // change property for all sub-solids std::list allRes; ModelAPI_Tools::allSubs(aBodyResult, allRes); - for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + std::list::iterator aRes; + for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) { setTransparency(*aRes, theTransparency); } } @@ -2362,6 +2508,34 @@ void setTransparency(double theTransparency, const QObjectPtrList& theObjects) } } +//************************************************************** +double getDefaultDeflection(const ObjectPtr& theObject) +{ + double aDeflection = -1; + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + bool isConstruction = false; + + std::string aResultGroup = aResult->groupName(); + if (aResultGroup == ModelAPI_ResultConstruction::group()) + isConstruction = true; + else if (aResultGroup == ModelAPI_ResultBody::group()) { + GeomShapePtr aGeomShape = aResult->shape(); + if (aGeomShape.get()) { + // if the shape could not be exploded on faces, it contains only wires, edges, and vertices + // correction of deviation for them should not influence to the application performance + GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE); + isConstruction = !anExp.more(); + } + } + if (isConstruction) + aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); + else + aDeflection = Config_PropManager::real("Visualization", "body_deflection"); + } + return aDeflection; +} + //************************************************************** void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects) { @@ -2372,7 +2546,9 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects) foreach(ObjectPtr anObject, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { - aDeflection = XGUI_CustomPrs::getResultDeflection(aResult); + aDeflection = ModelAPI_Tools::getDeflection(aResult); + if (aDeflection < 0) + aDeflection = getDefaultDeflection(aResult); } else { // TODO: remove the obtaining a property from the AIS object @@ -2421,10 +2597,17 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects) setDeflection(aResult, aDeflection); } } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); aMgr->finishOperation(); updateCommandStatus(); } +//************************************************************** +double getDefaultTransparency(const ResultPtr& theResult) +{ + return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.; +} + //************************************************************** void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects) { @@ -2435,7 +2618,9 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects) foreach(ObjectPtr anObject, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { - aCurrentValue = XGUI_CustomPrs::getResultTransparency(aResult); + aCurrentValue = ModelAPI_Tools::getTransparency(aResult); + if (aCurrentValue < 0) + aCurrentValue = getDefaultTransparency(aResult); } if (aCurrentValue > 0) break; @@ -2448,7 +2633,7 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects) // 2. show the dialog to change the value XGUI_PropertyDialog* aDlg = new XGUI_PropertyDialog(desktop()); - aDlg->setWindowTitle("Transparency"); + aDlg->setWindowTitle(tr("Transparency")); XGUI_TransparencyWidget* aTransparencyWidget = new XGUI_TransparencyWidget(aDlg); connect(aTransparencyWidget, SIGNAL(transparencyValueChanged()), this, SLOT(onTransparencyValueChanged())); @@ -2460,14 +2645,16 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects) QString aDescription = contextMenuMgr()->action("TRANSPARENCY_CMD")->text(); aMgr->startOperation(aDescription.toStdString()); - if (aDlg->exec() != QDialog::Accepted) - return; - - // 4. set the value to all results - aCurrentValue = aTransparencyWidget->getValue(); - setTransparency(aCurrentValue, theObjects); + if (aDlg->exec() == QDialog::Accepted) { + // 4. set the value to all results + aCurrentValue = aTransparencyWidget->getValue(); + setTransparency(aCurrentValue, theObjects); + aMgr->finishOperation(); + } else { + aMgr->abortOperation(); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } - aMgr->finishOperation(); updateCommandStatus(); } @@ -2480,7 +2667,11 @@ void XGUI_Workshop::onTransparencyValueChanged() QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); setTransparency(aTransparencyWidget->getValue(), anObjects); - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + static const Events_ID kRedisplayEvent = + Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + Events_Loop::loop()->flush(kRedisplayEvent); + + myViewerProxy->update(); } @@ -2503,6 +2694,7 @@ void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible) myObjectBrowser->updateAllIndexes(); updateColorScaleVisibility(); + displayer()->updateViewer(); } //************************************************************** @@ -2543,6 +2735,7 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) // Necessary for update icons in ObjectBrowser on Linux myObjectBrowser->updateAllIndexes(); updateColorScaleVisibility(); + displayer()->updateViewer(); } @@ -2750,33 +2943,45 @@ void XGUI_Workshop::synchronizeViewer() aDocs.append(aMgr->moduleDocument()); foreach(DocumentPtr aDoc, aDocs) { - synchronizeGroupInViewer(aDoc, ModelAPI_ResultConstruction::group(), false); - synchronizeGroupInViewer(aDoc, ModelAPI_ResultBody::group(), false); - synchronizeGroupInViewer(aDoc, ModelAPI_ResultPart::group(), false); - synchronizeGroupInViewer(aDoc, ModelAPI_ResultGroup::group(), false); + synchronizeGroupInViewer(aDoc, false); } } //****************************************************** void XGUI_Workshop::synchronizeGroupInViewer(const DocumentPtr& theDoc, - const std::string& theGroup, bool theUpdateViewer) { - ObjectPtr aObj; - int aSize = theDoc->size(theGroup); + FeaturePtr aFeature; + ResultPtr aRes; + int aSize = theDoc->numInternalFeatures(); for (int i = 0; i < aSize; i++) { - aObj = theDoc->object(theGroup, i); - if (aObj->isDisplayed()) { - // Hide the presentation with an empty shape. But isDisplayed state of the object should not - // be changed to the object becomes visible when the shape becomes not empty - ResultPtr aRes = std::dynamic_pointer_cast(aObj); - if (aRes.get() && (!aRes->shape().get() || aRes->shape()->isNull())) - continue; - ResultBodyPtr aResBody = std::dynamic_pointer_cast(aObj); - if (aResBody.get()) - synchronizeResultTree(aResBody, false); - else - myDisplayer->display(aObj, false); + aFeature = theDoc->internalFeature(i); + if (!aFeature.get()) + continue; + const std::list& aResults = aFeature->results(); + std::list::const_iterator aIt; + aFeature->setDisplayed(false); + for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { + aRes = (*aIt); + if (aRes->isDisplayed() && !aRes->isConcealed()) { + // Hide the presentation with an empty shape. But isDisplayed state of the object should not + // be changed to the object becomes visible when the shape becomes not empty + if (!aRes->shape().get() || aRes->shape()->isNull()) + continue; + ResultBodyPtr aResBody = std::dynamic_pointer_cast(aRes); + if (aResBody.get()) + synchronizeResultTree(aResBody, false); + else { + if (aRes->isInHistory()) { + if (aRes->isDisplayed()) + myDisplayer->display(aRes, false); + else + myDisplayer->erase(aRes, false); + } + else + aRes->setDisplayed(false); + } + } } } if (theUpdateViewer) @@ -2791,8 +2996,12 @@ void XGUI_Workshop::synchronizeResultTree(const ResultBodyPtr& theRes, bool theU if (aRes.get()) synchronizeResultTree(aRes, theUpdateViewer); } - else - myDisplayer->display(theRes, theUpdateViewer); + else { + if (theRes->isDisplayed()) + myDisplayer->display(theRes, theUpdateViewer); + else + myDisplayer->erase(theRes, theUpdateViewer); + } } #endif