From d1e41c70e69a0c6eb8cdbc65f2c78c1104b3f1aa Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 22 Sep 2014 13:04:22 +0400 Subject: [PATCH] Shading/Wireframe commands added --- src/XGUI/XGUI_ContextMenuMgr.cpp | 27 ++++++++++++++++++---- src/XGUI/XGUI_Displayer.cpp | 38 +++++++++++++++++++++++++++++-- src/XGUI/XGUI_Displayer.h | 12 +++++++++- src/XGUI/XGUI_Workshop.cpp | 14 ++++++++++++ src/XGUI/XGUI_Workshop.h | 2 ++ src/XGUI/XGUI_pictures.qrc | 2 ++ src/XGUI/pictures/shading.png | Bin 0 -> 751 bytes src/XGUI/pictures/wireframe.png | Bin 0 -> 568 bytes 8 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 src/XGUI/pictures/shading.png create mode 100644 src/XGUI/pictures/wireframe.png diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 5f69add11..c278646e0 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -51,6 +51,12 @@ void XGUI_ContextMenuMgr::createActions() aAction = new QAction(QIcon(":pictures/eye_pencil_closed.png"), tr("Hide"), this); addAction("HIDE_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/shading.png"), tr("Shading"), this); + addAction("SHADING_CMD", aAction); + + aAction = new QAction(QIcon(":pictures/wireframe.png"), tr("Wireframe"), this); + addAction("WIREFRAME_CMD", aAction); } void XGUI_ContextMenuMgr::addAction(const QString& theId, QAction* theAction) @@ -134,9 +140,13 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const } else if (hasFeature) { aMenu->addAction(action("EDIT_CMD")); } else { - if (aDisplayer->isVisible(aObject)) + if (aDisplayer->isVisible(aObject)) { aMenu->addAction(action("HIDE_CMD")); - else { + if (aDisplayer->displayMode(aObject) == XGUI_Displayer::Shading) + aMenu->addAction(action("WIREFRAME_CMD")); + else + aMenu->addAction(action("SHADING_CMD")); + } else { aMenu->addAction(action("SHOW_CMD")); } aMenu->addAction(action("SHOW_ONLY_CMD")); @@ -150,6 +160,9 @@ QMenu* XGUI_ContextMenuMgr::objectBrowserMenu() const aMenu->addAction(action("SHOW_CMD")); aMenu->addAction(action("HIDE_CMD")); aMenu->addAction(action("SHOW_ONLY_CMD")); + aMenu->addSeparator(); + aMenu->addAction(action("SHADING_CMD")); + aMenu->addAction(action("WIREFRAME_CMD")); } } if (hasFeature) @@ -182,17 +195,23 @@ void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const //if (aObjects.size() == 1) // theMenu->addAction(action("EDIT_CMD")); bool isVisible = false; + bool isShading = false; foreach(ObjectPtr aObject, aObjects) { ResultPtr aRes = boost::dynamic_pointer_cast(aObject); if (aRes && myWorkshop->displayer()->isVisible(aRes)) { isVisible = true; + isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading); break; } } - if (isVisible) + if (isVisible) { theMenu->addAction(action("HIDE_CMD")); - else + if (isShading) + theMenu->addAction(action("WIREFRAME_CMD")); + else + theMenu->addAction(action("SHADING_CMD")); + } else theMenu->addAction(action("SHOW_CMD")); //theMenu->addAction(action("DELETE_CMD")); } diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 7f1627c28..83b2f0eb7 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -35,7 +35,7 @@ XGUI_Displayer::~XGUI_Displayer() { } -bool XGUI_Displayer::isVisible(ObjectPtr theObject) +bool XGUI_Displayer::isVisible(ObjectPtr theObject) const { return myResult2AISObjectMap.find(theObject) != myResult2AISObjectMap.end(); } @@ -441,4 +441,38 @@ void XGUI_Displayer::deactivateObjectsOutOfContext() aContext->RemoveFilters(); aContext->NotUseDisplayedObjects(); -} \ No newline at end of file +} + + +void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate) +{ + if (theMode == NoMode) + return; + + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; + + boost::shared_ptr aAISObj = getAISObject(theObject); + if (!aAISObj) + return; + + Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl(); + aContext->SetDisplayMode(aAISIO, theMode, toUpdate); +} + + +XGUI_Displayer::DisplayMode XGUI_Displayer::displayMode(ObjectPtr theObject) const +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return NoMode; + + boost::shared_ptr aAISObj = getAISObject(theObject); + if (!aAISObj) + return NoMode; + + Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl(); + return (XGUI_Displayer::DisplayMode) aAISIO->DisplayMode(); +} + diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 7d0970659..cf3a76798 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -37,6 +37,8 @@ class XGUI_Workshop; class XGUI_EXPORT XGUI_Displayer { public: + enum DisplayMode { NoMode = -1, Wireframe, Shading }; + /// Constructor /// \param theViewer the viewer XGUI_Displayer(XGUI_Workshop* theWorkshop); @@ -49,7 +51,7 @@ class XGUI_EXPORT XGUI_Displayer /// Returns the feature visibility state. /// \param theFeature a feature instance - bool isVisible(ObjectPtr theObject); + bool isVisible(ObjectPtr theObject) const; /// Display the feature. Obtain the visualized object from the feature. /// \param theFeature a feature instance @@ -132,6 +134,14 @@ class XGUI_EXPORT XGUI_Displayer void deactivateObjectsOutOfContext(); + /// Sets display mode for the given object if this object is displayed + void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true); + + /// Returns current display mode for the given object. + /// If object is not displayed then returns NoMode. + DisplayMode displayMode(ObjectPtr theObject) const; + + protected: /// Deactivate local selection /// \param isUpdateViewer the state wether the viewer should be updated immediatelly diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 51a66d026..bbec2aabf 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1076,6 +1076,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) showObjects(aObjects, false); else if (theId == "SHOW_ONLY_CMD") showOnlyObjects(aObjects); + else if (theId == "SHADING_CMD") + setDisplayMode(aObjects, XGUI_Displayer::Shading); + else if (theId == "WIREFRAME_CMD") + setDisplayMode(aObjects, XGUI_Displayer::Wireframe); } //************************************************************** @@ -1257,3 +1261,13 @@ void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup for (int i = 0; i < theDoc->size(theGroup); i++) myDisplayer->display(theDoc->object(theGroup, i), false); } + +//************************************************************** +void XGUI_Workshop::setDisplayMode(const QList& theList, int theMode) +{ + foreach(ObjectPtr aObj, theList) { + myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false); + } + if (theList.size() > 0) + myDisplayer->updateViewer(); +} diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index dbb6cb60f..5a557db2b 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -157,6 +157,8 @@ Q_OBJECT //! Show the given features in 3d Viewer void showOnlyObjects(const QList& theList); + void setDisplayMode(const QList& theList, int theMode); + ModuleBase_IModule* module() const { return myModule; diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index dd4aa4808..6aaa26762 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -64,5 +64,7 @@ pictures/view_prefs.png pictures/module.png + pictures/shading.png + pictures/wireframe.png diff --git a/src/XGUI/pictures/shading.png b/src/XGUI/pictures/shading.png new file mode 100644 index 0000000000000000000000000000000000000000..909df3d18db75ef00e0791f22d9fbb89e05bad29 GIT binary patch literal 751 zcmVPx#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FZT01FZU(%pXi00007bV*G`2iyb` z5DFRvubRaG00M7GL_t(I%Z=2(i(FL{!13>!*>Mb65F|w!D+38O5vvs2N}81Z4Jr1I z@Q<(%?EC{P6vSFkNF%a>q%xI8Wigt~%zN+N^V8zK*`1kPvbk`IcOUP=Ip>~tyUYZj z>pC{;^KYLfuUW^BKIr!M&Yf*=AM!}lf}z?)6yx-)0PyvvA9wrUY_swBvmdgkqaK(C zYAvcdMf@D=s{t@n<-y}G61cgY#BBTF^ySE3{|;1b&?rU`r{BW*V%&T09X`5qYxCKM z+vveIc=+~$u7ek=veTdCV#ac@^Gf!6?qz zAgl(ZuZGrw*B+B$^Vx0S@X8FUI+2NcV$pgyR%bmL>!O$xybhQQxQxu-x^Za&cEBQz zN8%BPwHS)A8Wk-KaT#$PF)7!BVvc*FegRf>+=S4ATWz62SiN#a&rkWER|St&sz(x2 zcqAD?Wp=kXm`Y9}FQOqqrcaoW?mYkbyX#60%=3J(#R3tX`c`nQxD>*K zaJe$W9dM|ISt90$1!028fR+_j`i4sDW!M{lWA%10ri2QvrGeubt36>A*GjmOrq_d| z3a*v$)oD9bt+Sz|I1CZrp)g9RD!1||RZC$5G0!IJD|bnO~}Ogf;WBRi1ctnFV1 z&gKi!6dhN%wjs7Uv~sl))3|hWbn`jxb_v|R5AWZ7czgn|JiImiUISJe94@WQt;~M^ z>6`C?6X46t{AC|}ANT|~y8H0>(M~H~Jm1M;f&kXQkHA-%`D`D&Io)kXz@7bDWN)pf hE9 literal 0 HcmV?d00001 diff --git a/src/XGUI/pictures/wireframe.png b/src/XGUI/pictures/wireframe.png new file mode 100644 index 0000000000000000000000000000000000000000..e500831bc66a6e3555be8fc49f2ed519ccb7f1a6 GIT binary patch literal 568 zcmV-80>}M{P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FZT01FZU(%pXi00007bV*G`2iyb` z5D)}Uja_{J00Fp3L_t(I%dM2XP8>lHgulHT?#^J013*ZfVCfzJ$$kI==N1t$Z(#8_ zBuE6v??B?*LUQ16B;;TP2yBCo-vxFZP=lJi+dBtLw%V?$?waY!csv=<0y@BSG&^O? z>F4MpbDyK0k5LjK!A_Hv;qWDxex9!a zOCq_H`U6n8N!k*diDtXP9EkWP2;2pTW?!Ye0h~(twno^EW_zyVcM|^#6lvrs5q*}2 z+Y>xo0~Vs$7BC0QCXOK0Otl4Y+t2fL;7;8Sd8qnxhe_RMslznVg$fVlT~~yet1D$g z+hLx34mI^cUL4C8-#w1B0%jbhOh3bjaqfW|y|J>v#+K{wSxsmFRE~Vq3C^Y=r58Of zPS`YZ+U+o=k?em66G=~xb=)oYMon2K>;P|~+0O}^^4{I@vj7QhM55V_0An{Ln(e#q z*CNmS^;dqEwVx;2nxV9*?Q+Lkk>Y3;=tr|}E^Tt)S3}zDt8Nqc1N;CYFnG#CU=dgb zmZI602_AmZ>XpEe&%<9SDmCWjld!R0000