X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSHAPERGUI%2FSHAPERGUI_SalomeViewer.cpp;h=cd1759c2349a497c0981de80bcbe82f2c9cc9fc2;hb=cf3d083e537c121658d873ff4225cda6b78abd29;hp=58cb99b4ccb86062964ea8fd29032f541d3de0e7;hpb=8f02d52c15bcdfa1c65323ba33d0d03f9483dd86;p=modules%2Fshaper.git diff --git a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp index 58cb99b4c..cd1759c23 100644 --- a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp +++ b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "SHAPERGUI_SalomeViewer.h" @@ -29,12 +28,18 @@ #include #include +#include #include +#include +#include #include #include +#include -#define SALOME_PATCH_FOR_CTRL_WHEEL +#if OCC_VERSION_HEX < 0x070400 + #define SALOME_PATCH_FOR_CTRL_WHEEL +#endif SHAPERGUI_SalomeView::SHAPERGUI_SalomeView(OCCViewer_Viewer* theViewer) : ModuleBase_IViewWindow(), myCurrentView(0) @@ -120,7 +125,7 @@ Handle(V3d_View) SHAPERGUI_SalomeViewer::activeView() const //********************************************** QWidget* SHAPERGUI_SalomeViewer::activeViewPort() const { - QWidget* aViewPort; + QWidget* aViewPort = 0; if (mySelector) { OCCViewer_Viewer* aViewer = mySelector->viewer(); SUIT_ViewManager* aMgr = aViewer->getViewManager(); @@ -233,13 +238,13 @@ bool SHAPERGUI_SalomeViewer::canDragByMouse() const //********************************************** -void SHAPERGUI_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent) +void SHAPERGUI_SalomeViewer::onKeyPress(SUIT_ViewWindow* /*theView*/, QKeyEvent* theEvent) { emit keyPress(myView, theEvent); } //********************************************** -void SHAPERGUI_SalomeViewer::onKeyRelease(SUIT_ViewWindow* theView, QKeyEvent* theEvent) +void SHAPERGUI_SalomeViewer::onKeyRelease(SUIT_ViewWindow* /*theView*/, QKeyEvent* theEvent) { emit keyRelease(myView, theEvent); } @@ -278,11 +283,19 @@ void SHAPERGUI_SalomeViewer::onViewCreated(SUIT_ViewWindow* theView) myWindowScale.insert(aView->getViewPort()->getView(), aView->getViewPort()->getView()->Camera()->Scale()); - emit viewCreated(myView); + QTimer::singleShot(10, this, SLOT(onAfterViewCreated())); + emit viewCreated(myView); +} +//********************************************** +void SHAPERGUI_SalomeViewer::onAfterViewCreated() +{ + // Update trihedron and dimension arrows + emit onViewTransformed(OCCViewer_ViewWindow::ZOOMVIEW); } + //********************************************** void SHAPERGUI_SalomeViewer::onActivated(SUIT_ViewManager* theMgr) { @@ -406,7 +419,7 @@ void SHAPERGUI_SalomeViewer::setViewProjection(double theX, double theY, aView3d->SetProj(theX, theY, theZ); aView3d->SetTwist( theTwist ); aView3d->FitAll(0.01, false); - aView3d->SetZSize(0.); + //aView3d->SetZSize(0.); if (aView3d->Depth() < 0.1) aView3d->DepthFitAll(); } @@ -508,21 +521,153 @@ void SHAPERGUI_SalomeViewer::activateViewer(bool toActivate) } } -//void SHAPERGUI_SalomeViewer::Zfitall() -//{ -// if (!mySelector || !mySelector->viewer()) -// return; -// SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); -// /// WORKAROUND for issue #1798. SUIT_ViewManager::closeAllViews() should nullify myActiveView -// /// As a result, we need to check views count in manager -// if (aMgr->getViews().size() > 0) { -// OCCViewer_ViewFrame* aView = dynamic_cast(aMgr->getActiveView()); -// if (aView) { -// OCCViewer_ViewWindow* aWnd = aView->getView(OCCViewer_ViewFrame::MAIN_VIEW); -// Handle(V3d_View) aView3d = aWnd->getViewPort()->getView(); -// aView3d->ZFitAll(); -// if (aView3d->Depth() < 0.1) -// aView3d->DepthFitAll(); -// } -// } -//} \ No newline at end of file +bool SHAPERGUI_SalomeViewer::isColorScaleVisible() const +{ + if (mySelector) { + return mySelector->viewer()->isColorScaleVisible(); + } + return false; +} + +void SHAPERGUI_SalomeViewer::setColorScaleShown(bool on) +{ + if (mySelector) { + mySelector->viewer()->setColorScaleShown(on); + } +} + +void SHAPERGUI_SalomeViewer::setColorScalePosition(double theX, double theY) +{ + if (mySelector) { + QWidget* aWindow = activeViewPort(); + mySelector->viewer()->getColorScale()->SetPosition(aWindow->width() * theX, + aWindow->height() * theY); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleSize(double theW, double theH) +{ + if (mySelector) { + QWidget* aWindow = activeViewPort(); + mySelector->viewer()->getColorScale()->SetSize(aWindow->width() * theW, + aWindow->height() * theH); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleRange(double theMin, double theMax) +{ + if (mySelector) { + mySelector->viewer()->getColorScale()->SetRange(theMin, theMax); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleIntervals(int theNb) +{ + if (mySelector) { + mySelector->viewer()->getColorScale()->SetNumberOfIntervals(theNb); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleTextHeigth(int theH) +{ + if (mySelector) { + mySelector->viewer()->getColorScale()->SetTextHeight(theH); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleTextColor(const QColor& theColor) +{ + if (mySelector) { + Quantity_Color aColor(theColor.redF(), theColor.greenF(), theColor.blueF(), Quantity_TOC_RGB); + mySelector->viewer()->getColorScale()->SetColor(aColor); + } +} + +void SHAPERGUI_SalomeViewer::setColorScaleTitle(const QString& theText) +{ + if (mySelector) { + mySelector->viewer()->getColorScale()->SetTitle(theText.toStdString().c_str()); + } +} + +void SHAPERGUI_SalomeViewer::setText( + const ModuleBase_IViewer::TextColor& theText, const int theSize) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + if (aContext.IsNull()) + return; + NCollection_List::Iterator aPrsIter(myText); + if (!theText.empty()) + { + Quantity_Color aTextColor; + std::string aTextFont; + + double anOffset = -theSize - 1; // initial offset from the toolbar of the viewer + ModuleBase_IViewer::TextColor::const_iterator aLine = theText.cbegin(); + for (; aLine != theText.cend(); aLine++) + { + Quantity_Color aColor(aLine->second.at(0) / 255., + aLine->second.at(1) / 255., aLine->second.at(2) / 255., Quantity_TOC_RGB); + if (aLine == theText.cbegin()) + { // the first is the font name and text color + aTextColor = aColor; + aTextFont = std::string(aLine->first.begin(), aLine->first.end()); + continue; + } + + Handle(AIS_TextLabel) aPrs; + if (!aPrsIter.More()) + { // new presentation is added to the list forever + aPrs = new AIS_TextLabel; + aPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD); + aPrs->SetHJustification(Graphic3d_HTA_RIGHT); + aPrs->SetVJustification(Graphic3d_VTA_TOPFIRSTLINE); + aPrs->SetDisplayType(Aspect_TODT_SUBTITLE); + aPrs->SetTransparency(0.2); + static const Graphic3d_Vec2i aZOffset(0); + aPrs->SetTransformPersistence(new Graphic3d_TransformPers( + Graphic3d_TMF_2d, Aspect_TOTP_RIGHT_UPPER, aZOffset)); + } + else + { // update the existing presentation + aPrs = aPrsIter.ChangeValue(); + if (!aContext->IsDisplayed(aPrs)) + aContext->Display(aPrs, Standard_False); + } + // common part of parameters for new and existing prs + aPrs->SetText(aLine->first.c_str()); + aPrs->SetFont(aTextFont.c_str()); + aPrs->SetHeight(theSize); + aPrs->SetPosition(gp_Pnt(0, anOffset, 0)); + anOffset -= int(double(theSize) * 1.2 + 1); // to have a proportional gap between lines + aPrs->SetColor(aTextColor); + aPrs->SetColorSubTitle(aColor); + if (!aPrsIter.More()) + { // for the new presentation + aContext->Display(aPrs, Standard_False); + myText.Append(aPrs); + } + else + { // update existing presentation + aContext->Redisplay(aPrs, Standard_False, Standard_False); + aPrsIter.Next(); + } + } + } + // hide the left presentations, created previously, but unused for now + for (; aPrsIter.More(); aPrsIter.Next()) + aContext->Erase(aPrsIter.ChangeValue(), Standard_False); +} + +void SHAPERGUI_SalomeViewer::setFitter(OCCViewer_Fitter* theFitter) +{ + if (mySelector) + mySelector->viewer()->setFitter(theFitter); +} + +OCCViewer_Fitter* SHAPERGUI_SalomeViewer::fitter() const +{ + if (mySelector) + return mySelector->viewer()->fitter(); + return 0; +}