From: vsv Date: Wed, 4 Dec 2019 08:59:03 +0000 (+0300) Subject: Issue #18398(Tuleap): Restore visual properties change functionality X-Git-Tag: V9_5_0a1~129 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c942db5a30da5f57a89e6d4835187d64a74f89ca;p=modules%2Fshaper.git Issue #18398(Tuleap): Restore visual properties change functionality --- diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 45798a12f..e5641930e 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -431,7 +431,8 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr) } } else { // trim: need to redisplay or set color in the python script - if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color")) { + if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color" || + theAttr->id() == "Transparency" || theAttr->id() == "Deflection")) { static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent); } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index fd4fae9d7..d793a0501 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -293,45 +293,30 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) } if (!aAISIO.IsNull()) { - // Check that the visualized shape is the same and the redisplay is not necessary - // Redisplay of AIS object leads to this object selection compute and the selection - // in the browser is lost - // this check is not necessary anymore because the selection store/restore is realized - // before and after the values modification. - // Moreother, this check avoids customize and redisplay presentation if the presentable - // parameter is changed. - //bool isEqualShapes = false; - //ResultPtr aResult = std::dynamic_pointer_cast(theObject); - //if (aResult.get() != NULL) { - // Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO); - // if (!aShapePrs.IsNull()) { - // std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); - // if (aShapePtr.get()) { - // const TopoDS_Shape& aOldShape = aShapePrs->Shape(); - // if (!aOldShape.IsNull()) - // isEqualShapes = aOldShape.IsEqual(aShapePtr->impl()); - // } - // } - //} - // Customization of presentation - //bool isCustomized = customizeObject(theObject); - #ifdef DEBUG_FEATURE_REDISPLAY - qDebug(QString("Redisplay: %1, isEqualShapes=%2"). - arg(!isEqualShapes/* || isCustomized*/).arg(isEqualShapes) - .toStdString().c_str()); - #endif - //if (!isEqualShapes/* || isCustomized*/) { - // /// if shapes are equal and presentation are customized, selection should be restored - // bool aNeedToRestoreSelection = isEqualShapes/* && isCustomized*/; - // if (aNeedToRestoreSelection) - if (aAISObj.get() && myWorkshop->facesPanel()) - myWorkshop->facesPanel()->customizeObject(theObject, aAISObj); - + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + // Set color + std::vector aColor; + ModelAPI_Tools::getColor(aResult, aColor); + if (aColor.size() > 0) { + aAISIO->SetColor(Quantity_Color(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB)); + } + // Set deflection + double aDeflection = ModelAPI_Tools::getDeflection(aResult); + if ((aDeflection >= 0) && (aDeflection != aAISObj->getDeflection())) + aAISObj->setDeflection(aDeflection); + + // Set transparency + double aTransparency = ModelAPI_Tools::getTransparency(aResult); + if ((aTransparency >= 0) && (aTransparency != aAISObj->getTransparency())) + aAISObj->setTransparency(aTransparency); + } myWorkshop->module()->storeSelection(); #ifdef CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY myWorkshop->selector()->deselectPresentation(aAISIO); #endif + if (aContext->IsDisplayed(aAISIO)) aContext->Redisplay(aAISIO, false); else { diff --git a/src/XGUI/XGUI_FacesPanel.cpp b/src/XGUI/XGUI_FacesPanel.cpp index 28a35884c..f79eb6dba 100644 --- a/src/XGUI/XGUI_FacesPanel.cpp +++ b/src/XGUI/XGUI_FacesPanel.cpp @@ -529,13 +529,6 @@ void XGUI_FacesPanel::closeEvent(QCloseEvent* theEvent) emit closed(); } -//******************************************************************** -bool XGUI_FacesPanel::customizeObject(const ObjectPtr& theObject, - const AISObjectPtr& thePresentation) -{ - return myItems.size() > 0; -} - //******************************************************************** void XGUI_FacesPanel::onDeleteItem() { diff --git a/src/XGUI/XGUI_FacesPanel.h b/src/XGUI/XGUI_FacesPanel.h index 68a3ce53b..d442ee6b8 100644 --- a/src/XGUI/XGUI_FacesPanel.h +++ b/src/XGUI/XGUI_FacesPanel.h @@ -122,18 +122,6 @@ public: /// \param theEvent an event virtual bool eventFilter(QObject* theObject, QEvent *theEvent); - /// Hide/show faces of the object if: - /// - face selector is active - /// - object is mentioned in the list of selected elements - /// If the object is displayed, all panel faces selected on it will be moved into presentation - /// or, if redisplayed, fuction return if the object should be redisplayed or not - /// \param theObject a customized object - /// \param thePresentation visualized presentation of the object - /// \return true if the presentation is customized - bool customizeObject(const std::shared_ptr& theObject, - const std::shared_ptr& thePresentation); - - XGUI_Workshop* workshop() const { return myWorkshop; } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index fcee5e38a..75c1a932f 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -91,6 +91,7 @@ #include #include +#include #include #include @@ -2334,9 +2335,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(); + } } //************************************************************** @@ -2351,6 +2371,8 @@ 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()) + getDefaultColor(aResult, false, aColor); } else { // TODO: remove the obtaining a color from the AIS object @@ -2402,8 +2424,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(); } //************************************************************** @@ -2413,11 +2437,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); + } } //************************************************************** @@ -2427,11 +2449,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); + } } //************************************************************** @@ -2444,7 +2464,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); } } @@ -2453,6 +2474,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) { @@ -2464,6 +2513,8 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects) ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { aDeflection = ModelAPI_Tools::getDeflection(aResult); + if (aDeflection < 0) + aDeflection = getDefaultDeflection(aResult); } else { // TODO: remove the obtaining a property from the AIS object @@ -2512,10 +2563,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) { @@ -2527,6 +2585,8 @@ void XGUI_Workshop::changeTransparency(const QObjectPtrList& theObjects) ResultPtr aResult = std::dynamic_pointer_cast(anObject); if (aResult.get()) { aCurrentValue = ModelAPI_Tools::getTransparency(aResult); + if (aCurrentValue < 0) + aCurrentValue = getDefaultTransparency(aResult); } if (aCurrentValue > 0) break; @@ -2573,7 +2633,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(); }