-// 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
//
// 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<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SHAPERGUI_SalomeViewer.h"
#include <QtxActionToolMgr.h>
#include <SALOME_AISShape.hxx>
+#include <Standard_Version.hxx>
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+#include <AIS_TextLabel.hxx>
+#include <Graphic3d_Vec2.hxx>
#include <QMouseEvent>
#include <QContextMenuEvent>
+#include <QTimer>
-#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)
//**********************************************
QWidget* SHAPERGUI_SalomeViewer::activeViewPort() const
{
- QWidget* aViewPort;
+ QWidget* aViewPort = 0;
if (mySelector) {
OCCViewer_Viewer* aViewer = mySelector->viewer();
SUIT_ViewManager* aMgr = aViewer->getViewManager();
//**********************************************
-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);
}
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)
{
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();
}
}
}
-//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<OCCViewer_ViewFrame*>(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<Handle(AIS_TextLabel)>::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;
+}