From: vsv Date: Fri, 14 Feb 2020 14:00:38 +0000 (+0300) Subject: Issue #3140: Add show/hide Isos menu item. X-Git-Tag: V9_5_0a1~14^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=918e097c6c3f8e02abf72c74f7a117c3b5adab61;p=modules%2Fshaper.git Issue #3140: Add show/hide Isos menu item. --- diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index ecafd0c20..7995c85fd 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -438,7 +438,7 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr) // trim: need to redisplay or set color in the python script if (myObject && (theAttr->attributeType() == "Point2D" || theAttr->id() == "Color" || theAttr->id() == "Transparency" || theAttr->id() == "Deflection" || - theAttr->id() == "Iso_lines")) { + theAttr->id() == "Iso_lines" || theAttr->id() == "Show_Iso_lines")) { static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent); } diff --git a/src/ModelAPI/ModelAPI_Result.cpp b/src/ModelAPI/ModelAPI_Result.cpp index b3d3dc574..32d04da6b 100644 --- a/src/ModelAPI/ModelAPI_Result.cpp +++ b/src/ModelAPI/ModelAPI_Result.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -38,6 +39,7 @@ void ModelAPI_Result::initAttributes() aData->addAttribute(DEFLECTION_ID(), ModelAPI_AttributeDouble::typeId())->setIsArgument(false); aData->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeDouble::typeId())->setIsArgument(false); aData->addAttribute(ISO_LINES_ID(), ModelAPI_AttributeIntArray::typeId())->setIsArgument(false); + aData->addAttribute(SHOW_ISO_LINES_ID(), ModelAPI_AttributeBoolean::typeId())->setIsArgument(false); } bool ModelAPI_Result::setDisabled(std::shared_ptr theThis, const bool theFlag) diff --git a/src/ModelAPI/ModelAPI_Result.h b/src/ModelAPI/ModelAPI_Result.h index a53c1e04f..f242ce3d3 100644 --- a/src/ModelAPI/ModelAPI_Result.h +++ b/src/ModelAPI/ModelAPI_Result.h @@ -71,6 +71,14 @@ class ModelAPI_Result : public ModelAPI_Object return MY_ISO_LINES_ID; } + /// Reference to the transparency of the result. + /// The double value is used. The value is in [0, 1] range + inline static const std::string& SHOW_ISO_LINES_ID() + { + static const std::string MY_SHOW_ISO_LINES_ID("Show_Iso_lines"); + return MY_SHOW_ISO_LINES_ID; + } + /// Returns true if the result is concealed from the data tree (referenced by other objects) MODELAPI_EXPORT virtual bool isConcealed(); diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 0c312f395..64c477972 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -850,23 +851,31 @@ void getColor(const std::shared_ptr& theResult, std::vector& theResult, std::vector& theNbLines) +void getIsoLines(const std::shared_ptr& theResult, + bool& isVisible, std::vector& theNbLines) { theNbLines.clear(); + isVisible = false; + if (!theResult.get()) + return; if (theResult->groupName() == ModelAPI_ResultConstruction::group()) { theNbLines.push_back(0); theNbLines.push_back(0); } else { // get color from the attribute of the result - if (theResult.get() != NULL && - theResult->data()->attribute(ModelAPI_Result::ISO_LINES_ID()).get() != NULL) { - AttributeIntArrayPtr aAttr = theResult->data()->intArray(ModelAPI_Result::ISO_LINES_ID()); - if (aAttr.get() && aAttr->size()) { + AttributeIntArrayPtr aAttr = theResult->data()->intArray(ModelAPI_Result::ISO_LINES_ID()); + if (aAttr.get()) { + if (aAttr->size()) { theNbLines.push_back(aAttr->value(0)); theNbLines.push_back(aAttr->value(1)); } } + AttributeBooleanPtr aBoolAttr = + theResult->data()->boolean(ModelAPI_Result::SHOW_ISO_LINES_ID()); + if (aBoolAttr.get()) { + isVisible = aBoolAttr->value(); + } } } @@ -886,6 +895,31 @@ void setIsoLines(ResultPtr theResult, const std::vector& theIso) } } +//****************************************************** +void showIsoLines(std::shared_ptr theResult, bool theShow) +{ + if (!theResult.get()) + return; + + AttributeBooleanPtr aAttr = theResult->data()->boolean(ModelAPI_Result::SHOW_ISO_LINES_ID()); + if (aAttr.get() != NULL) { + aAttr->setValue(theShow); + } +} + +//****************************************************** +bool isShownIsoLines(std::shared_ptr theResult) +{ + if (!theResult.get()) + return false; + + AttributeBooleanPtr aAttr = theResult->data()->boolean(ModelAPI_Result::SHOW_ISO_LINES_ID()); + if (aAttr.get() != NULL) { + return aAttr->value(); + } + return false; +} + //************************************************************** void setTransparency(ResultPtr theResult, double theTransparency) { diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index f9502dc82..e34b8aa6c 100644 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -242,7 +242,7 @@ MODELAPI_EXPORT void setColor(std::shared_ptr theResult, * \param[out] theNbLines values of iso-lines */ MODELAPI_EXPORT void getIsoLines(const std::shared_ptr& theResult, - std::vector& theNbLines); + bool& isVisible, std::vector& theNbLines); /*! Set number of iso-lines of the result * \param[in] theResult a result object @@ -251,6 +251,14 @@ MODELAPI_EXPORT void getIsoLines(const std::shared_ptr& theResu MODELAPI_EXPORT void setIsoLines(std::shared_ptr theResult, const std::vector& theIso); +/*! Set visibility of Iso lines +* \param[in] theResult a result object +* \param[in] theShow is a visibility flag +*/ +MODELAPI_EXPORT void showIsoLines(std::shared_ptr theResult, bool theShow); + +MODELAPI_EXPORT bool isShownIsoLines(std::shared_ptr theResult); + /*! Returns current transparency in the given result * \param theResult a result object * \return a transparency value or -1 if it was not defined diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 5fb170087..f94b65780 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -88,10 +88,17 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) Color(aColor); std::vector aIsoValues; - ModelAPI_Tools::getIsoLines(myResult, aIsoValues); - if (aIsoValues.size() == 0) { - aIsoValues.push_back(1); - aIsoValues.push_back(1); + bool isIsoVisible; + ModelAPI_Tools::getIsoLines(myResult, isIsoVisible, aIsoValues); + if (isIsoVisible) { + if (aIsoValues.size() == 0) { + aIsoValues.push_back(1); + aIsoValues.push_back(1); + } + } + else { + aIsoValues.push_back(0); + aIsoValues.push_back(0); } myUIsoAspect = new Prs3d_IsoAspect(aColor, Aspect_TOL_SOLID, 1, aIsoValues[0]); myVIsoAspect = new Prs3d_IsoAspect(aColor, Aspect_TOL_SOLID, 1, aIsoValues[1]); @@ -469,3 +476,30 @@ void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_Presentatio thePM->AddToImmediateList(aHilightPrs); } } + + +//******************************************************************** +void ModuleBase_ResultPrs::updateIsoLines() +{ + std::vector aIsoValues; + bool isIsoVisible; + ModelAPI_Tools::getIsoLines(myResult, isIsoVisible, aIsoValues); + if (isIsoVisible) { + if (aIsoValues.size() == 0) { + aIsoValues.push_back(1); + aIsoValues.push_back(1); + } + } + else { + if (aIsoValues.size() == 0) { + aIsoValues.push_back(0); + aIsoValues.push_back(0); + } + else { + aIsoValues[0] = 0; + aIsoValues[1] = 0; + } + } + myUIsoAspect->SetNumber(aIsoValues[0]); + myVIsoAspect->SetNumber(aIsoValues[1]); +} diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index a93089e98..a1f40f9fe 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -119,22 +119,7 @@ public: /// Returns True if the original shape is substituted by a corresponded shell Standard_EXPORT bool isSubstituted() const { return myIsSubstituted; } - /// Set number of Iso-lines - /// \param theU a number of U Iso-lines - /// \param theV a number of V Iso-lines - Standard_EXPORT void setIsolinesNumber(int theU, int theV) { - myUIsoAspect->SetNumber(theU); myVIsoAspect->SetNumber(theV); - } - - /// Returns number of U Iso-lines - Standard_EXPORT int UIsoLines() const { - return myUIsoAspect->Number(); - } - - /// Returns number of V Iso-lines - Standard_EXPORT int VIsoLines() const { - return myVIsoAspect->Number(); - } + Standard_EXPORT void updateIsoLines(); DEFINE_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape) diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 3c5146ffc..c36f9cef5 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -140,10 +140,14 @@ void XGUI_ContextMenuMgr::createActions() aDesktop); addAction("WIREFRAME_CMD", aAction); - aAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Iso-lines..."), + aAction = ModuleBase_Tools::createAction(QIcon(":pictures/iso_lines.png"), tr("Define Isos..."), aDesktop); addAction("ISOLINES_CMD", aAction); + aAction = ModuleBase_Tools::createAction(QIcon(), tr("Show Isos..."), aDesktop); + aAction->setCheckable(true); + addAction("SHOW_ISOLINES_CMD", aAction); + mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop); mySeparator1->setSeparator(true); @@ -306,22 +310,25 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu() //Process Feature if (aSelected == 1) { // single selection ObjectPtr aObject = aObjects.first(); + ResultPtr aResult; + if (hasResult) + aResult = std::dynamic_pointer_cast(aObject); if (aObject) { if (hasResult && myWorkshop->canBeShaded(aObject)) { XGUI_Displayer::DisplayMode aMode = aDisplayer->displayMode(aObject); if (aMode != XGUI_Displayer::NoMode) { action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading); action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe); - action("ISOLINES_CMD")->setEnabled(true); } else { action("WIREFRAME_CMD")->setEnabled(true); action("SHADING_CMD")->setEnabled(true); - action("ISOLINES_CMD")->setEnabled(true); } + action("SHOW_ISOLINES_CMD")->setEnabled(true); + action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult)); + action("ISOLINES_CMD")->setEnabled(true); } if (!hasFeature) { - bool aHasSubResults = ModelAPI_Tools::hasSubResults( - std::dynamic_pointer_cast(aObject)); + bool aHasSubResults = ModelAPI_Tools::hasSubResults(aResult); if (aHasSubResults) { action("HIDE_CMD")->setEnabled(true); action("SHOW_CMD")->setEnabled(true); @@ -358,6 +365,7 @@ void XGUI_ContextMenuMgr::updateObjectBrowserMenu() action("SHOW_ONLY_CMD")->setEnabled(true); action("SHADING_CMD")->setEnabled(true); action("WIREFRAME_CMD")->setEnabled(true); + action("SHOW_ISOLINES_CMD")->setEnabled(false); action("ISOLINES_CMD")->setEnabled(true); } if (hasFeature && myWorkshop->canMoveFeature()) { @@ -544,11 +552,18 @@ void XGUI_ContextMenuMgr::updateViewerMenu() if (aMode != XGUI_Displayer::NoMode) { action("WIREFRAME_CMD")->setEnabled(aMode == XGUI_Displayer::Shading); action("SHADING_CMD")->setEnabled(aMode == XGUI_Displayer::Wireframe); - action("ISOLINES_CMD")->setEnabled(true); } else { action("WIREFRAME_CMD")->setEnabled(true); action("SHADING_CMD")->setEnabled(true); - action("ISOLINES_CMD")->setEnabled(true); + } + action("ISOLINES_CMD")->setEnabled(true); + + if (aPrsList.size() == 1) { + ResultPtr aResult = std::dynamic_pointer_cast(aObject); + if (aResult.get()) { + action("SHOW_ISOLINES_CMD")->setEnabled(true); + action("SHOW_ISOLINES_CMD")->setChecked(ModelAPI_Tools::isShownIsoLines(aResult)); + } } } action("SHOW_ONLY_CMD")->setEnabled(true); @@ -664,6 +679,7 @@ void XGUI_ContextMenuMgr::buildObjBrowserMenu() aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); aList.append(action("TRANSPARENCY_CMD")); + aList.append(action("SHOW_ISOLINES_CMD")); aList.append(action("ISOLINES_CMD")); aList.append(action("SHOW_FEATURE_CMD")); aList.append(mySeparator3); @@ -740,6 +756,7 @@ void XGUI_ContextMenuMgr::buildViewerMenu() aList.append(action("COLOR_CMD")); aList.append(action("DEFLECTION_CMD")); aList.append(action("TRANSPARENCY_CMD")); + aList.append(action("SHOW_ISOLINES_CMD")); aList.append(action("ISOLINES_CMD")); aList.append(mySeparator3); aList.append(action("SET_VIEW_NORMAL_CMD")); @@ -794,6 +811,7 @@ void XGUI_ContextMenuMgr::addObjBrowserMenu(QMenu* theMenu) const aActions.append(action("COLOR_CMD")); aActions.append(action("DEFLECTION_CMD")); aActions.append(action("TRANSPARENCY_CMD")); + aActions.append(action("SHOW_ISOLINES_CMD")); aActions.append(action("ISOLINES_CMD")); aActions.append(action("CLEAN_HISTORY_CMD")); aActions.append(action("DELETE_CMD")); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index da590b502..00360a96d 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -316,13 +316,9 @@ bool XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) aAISObj->setTransparency(aTransparency); // Set Iso-Lines - std::vector aIsoValues; - ModelAPI_Tools::getIsoLines(aResult, aIsoValues); - if (aIsoValues.size() > 0) { - Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO); - if (!aResPrs.IsNull()) - aResPrs->setIsolinesNumber(aIsoValues[0], aIsoValues[1]); - } + Handle(ModuleBase_ResultPrs) aResPrs = Handle(ModuleBase_ResultPrs)::DownCast(aAISIO); + if (!aResPrs.IsNull()) + aResPrs->updateIsoLines(); } myWorkshop->module()->storeSelection(); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index ac03c11b2..c2d44a802 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1698,6 +1698,15 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) changeColor(aObjects); else if (theId == "ISOLINES_CMD") changeIsoLines(aObjects); + else if (theId == "SHOW_ISOLINES_CMD") { + foreach(ObjectPtr aObj, aObjects) { + ResultPtr aResult = std::dynamic_pointer_cast(aObj); + if (aResult.get()) + ModelAPI_Tools::showIsoLines(aResult, !ModelAPI_Tools::isShownIsoLines(aResult)); + } + mySelector->clearSelection(); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } else if (theId == "DEFLECTION_CMD") changeDeflection(aObjects); else if (theId == "TRANSPARENCY_CMD") @@ -3186,10 +3195,11 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects) return; std::vector aValues; + bool isVisible; if (theObjects.size() == 1) { ResultPtr aRes = std::dynamic_pointer_cast(theObjects.first()); if (aRes.get()) - ModelAPI_Tools::getIsoLines(aRes, aValues); + ModelAPI_Tools::getIsoLines(aRes, isVisible, aValues); else return; } @@ -3233,6 +3243,7 @@ void XGUI_Workshop::changeIsoLines(const QObjectPtrList& theObjects) ModelAPI_Tools::setIsoLines(aRes, aValues); } } + mySelector->clearSelection(); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); aMgr->finishOperation(); updateCommandStatus(); diff --git a/src/XGUI/XGUI_msg_fr.ts b/src/XGUI/XGUI_msg_fr.ts index 666c30458..270adced6 100644 --- a/src/XGUI/XGUI_msg_fr.ts +++ b/src/XGUI/XGUI_msg_fr.ts @@ -206,7 +206,15 @@ Iso-lines... - Iso-lines... + Iso-lines... + + + Define Isos... + Définir l'Isos... + + + Show Isos... + Show Isos...