]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Profile object realization. OCC Viewer embeded into the profile dialog box.
authornds <nds@opencascade.com>
Mon, 25 Nov 2013 14:10:42 +0000 (14:10 +0000)
committernds <nds@opencascade.com>
Mon, 25 Nov 2013 14:10:42 +0000 (14:10 +0000)
src/HYDROCurveCreator/CMakeLists.txt
src/HYDROCurveCreator/OCCViewer_ViewWidget.cxx [new file with mode: 0644]
src/HYDROCurveCreator/OCCViewer_ViewWidget.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ProfileDlg.cxx
src/HYDROGUI/HYDROGUI_ProfileDlg.h

index 24bf5f5601680debfa6c933a343b6e89d729aaf1..6913762d1a6d8b8083f5b475f051121cc12994d1 100644 (file)
@@ -62,6 +62,7 @@ IF(SALOME_BUILD_GUI)
     CurveCreator_TreeView.h
 #    CurveCreator_UndoOptsDlg.h
     CurveCreator_Widget.h
+    OCCViewer_ViewWidget.h
   )
 ENDIF(SALOME_BUILD_GUI)
 
@@ -104,6 +105,7 @@ IF(SALOME_BUILD_GUI)
     CurveCreator_TreeView.cxx
 #    CurveCreator_UndoOptsDlg.cxx
     CurveCreator_Widget.cxx
+    OCCViewer_ViewWidget.cxx
   )
 ENDIF(SALOME_BUILD_GUI)
 
diff --git a/src/HYDROCurveCreator/OCCViewer_ViewWidget.cxx b/src/HYDROCurveCreator/OCCViewer_ViewWidget.cxx
new file mode 100644 (file)
index 0000000..3f9aff1
--- /dev/null
@@ -0,0 +1,816 @@
+// File:        OCCViewer_ViewWidget.h
+// Created:     26 Jul 2012
+// Author:      Natalia ERMOLAEVA
+// Copyright:   CEA 2011
+
+//#include <MCGUIBase_Defs.h>
+#include "OCCViewer_ViewWidget.h"
+
+#include <Basics_OCCTVersion.hxx>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_Session.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_MessageBox.h>
+#include <OCCViewer_ViewPort3d.h>
+#include <OCCViewer_VService.h>
+#include <SUIT_ViewModel.h>
+#include <SUIT_Tools.h>
+
+#include <QtxAction.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_ListOfInteractive.hxx>
+#include <V3d_Viewer.hxx>
+#include <AIS_Shape.hxx>
+#include <Prs3d_LineAspect.hxx>
+
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <Geom_Axis2Placement.hxx>
+#include <AIS_Drawer.hxx>
+#include <Prs3d_DatumAspect.hxx>
+
+#include <QLayout>
+#include <QCursor>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QPainter>
+#include <QLabel>
+#include <QWheelEvent>
+#include <QMouseEvent>
+#include <QToolBar>
+
+const int SPACING_SIZE = 5;
+const int Z_FIT_ALL_SIZE = 1000;
+
+const char* imageZoomCursor[] = { 
+"32 32 3 1",
+". c None",
+"a c #000000",
+"# c #ffffff",
+"................................",
+"................................",
+".#######........................",
+"..aaaaaaa.......................",
+"................................",
+".............#####..............",
+"...........##.aaaa##............",
+"..........#.aa.....a#...........",
+".........#.a.........#..........",
+".........#a..........#a.........",
+"........#.a...........#.........",
+"........#a............#a........",
+"........#a............#a........",
+"........#a............#a........",
+"........#a............#a........",
+".........#...........#.a........",
+".........#a..........#a.........",
+".........##.........#.a.........",
+"........#####.....##.a..........",
+".......###aaa#####.aa...........",
+"......###aa...aaaaa.......#.....",
+".....###aa................#a....",
+"....###aa.................#a....",
+"...###aa...............#######..",
+"....#aa.................aa#aaaa.",
+".....a....................#a....",
+"..........................#a....",
+"...........................a....",
+"................................",
+"................................",
+"................................",
+"................................"};
+
+const char* imageRotateCursor[] = { 
+"32 32 3 1",
+". c None",
+"a c #000000",
+"# c #ffffff",
+"................................",
+"................................",
+"................................",
+"................................",
+"........#.......................",
+".......#.a......................",
+"......#######...................",
+".......#aaaaa#####..............",
+"........#..##.a#aa##........##..",
+".........a#.aa..#..a#.....##.aa.",
+".........#.a.....#...#..##.aa...",
+".........#a.......#..###.aa.....",
+"........#.a.......#a..#aa.......",
+"........#a.........#..#a........",
+"........#a.........#a.#a........",
+"........#a.........#a.#a........",
+"........#a.........#a.#a........",
+".........#.........#a#.a........",
+"........##a........#a#a.........",
+"......##.a#.......#.#.a.........",
+"....##.aa..##.....##.a..........",
+"..##.aa.....a#####.aa...........",
+"...aa.........aaa#a.............",
+"................#.a.............",
+"...............#.a..............",
+"..............#.a...............",
+"...............a................",
+"................................",
+"................................",
+"................................",
+"................................",
+"................................"};
+
+const char* imageCrossCursor[] = { 
+  "32 32 3 1",
+  ". c None",
+  "a c #000000",
+  "# c #ffffff",
+  "................................",
+  "................................",
+  "................................",
+  "................................",
+  "................................",
+  "................................",
+  "................................",
+  "...............#................",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  ".......#################........",
+  "........aaaaaaa#aaaaaaaaa.......",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "...............#a...............",
+  "................a...............",
+  "................................",
+  "................................",
+  "................................",
+  "................................",
+  "................................",
+  "................................",
+  "................................"};
+
+// ---------------- OCC view widget --------
+OCCViewer_ViewWidget::OCCViewer_ViewWidget(QWidget* parent)
+  : QFrame(parent), myShowTrihedron(true)
+{
+  setObjectName("OCC_view_widget");
+  mySelectedPoint = gp_Pnt(0.,0.,0.);
+  setFrameStyle(QFrame::NoFrame);
+
+  QGridLayout* anAnalLay = new QGridLayout(this);
+  anAnalLay->setMargin(0);
+  anAnalLay->setSpacing(SPACING_SIZE);
+
+  QWidget* aBtnBox = new QWidget(this);
+  QHBoxLayout* aBtnLay = new QHBoxLayout(aBtnBox);
+  aBtnLay->setMargin(0);
+  aBtnLay->setSpacing(SPACING_SIZE);
+
+  myToolBar = new QToolBar(aBtnBox);
+  aBtnLay->addWidget(myToolBar);
+  myZoomBtns = new QtxMultiAction(aBtnBox);
+  myZoomBtns->setObjectName("zoomBtn");
+  myToolBar->addAction(myZoomBtns);
+  myPanBtns = new QtxMultiAction(aBtnBox);
+  myPanBtns->setObjectName("panBtn");
+  myToolBar->addAction(myPanBtns);
+  myProjBtns = new QtxMultiAction(aBtnBox);
+  myProjBtns->setObjectName("projectionBtn");
+  myToolBar->addAction(myProjBtns);
+
+  // Rotation
+  aBtnLay->addStretch(1);
+  anAnalLay->addWidget(aBtnBox, 0, 0, 1, 2);
+
+  myV3dViewer = OCCViewer_VService::CreateViewer((short*) "Viewer3d", "", "", 1000., V3d_XposYnegZpos, true, true);
+  myV3dViewer->Init();
+
+#if OCC_VERSION_LARGE <= 0x06060000 // Porting to OCCT higher 6.6.0 version
+  myV3dCollector = OCCViewer_VService::CreateViewer((short*) "Collector3d", "", "", 1000., V3d_XposYnegZpos, true, true);
+  myV3dCollector->Init();
+#endif
+
+  // init selector
+#if OCC_VERSION_LARGE <= 0x06060000 
+  myAISContext = new AIS_InteractiveContext( myV3dViewer, myV3dCollector );
+#else
+  myAISContext = new AIS_InteractiveContext( myV3dViewer );
+#endif
+  myAISContext->SelectionColor(Quantity_NOC_WHITE);
+  myAISContext->IsoOnPlane(true);
+
+  myViewPort = new OCCViewer_ViewPort3d(this, myV3dViewer, V3d_ORTHOGRAPHIC);
+  myViewPort->setBackgroundColor(Qt::black);
+  myViewPort->setMinimumHeight(300);
+  myViewPort->installEventFilter(this);
+  anAnalLay->addWidget(myViewPort, 1, 0, 1, 2);
+
+  Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(gp::XOY());
+  myTrihedron = new AIS_Trihedron(anAxis);
+  myTrihedron->SetInfiniteState(Standard_True);
+
+  Quantity_Color Col(193/255., 205/255., 193/255., Quantity_TOC_RGB);
+  myTrihedron->SetArrowColor(Col.Name());
+  myTrihedron->SetSize(100);
+  Handle(AIS_Drawer) drawer = myTrihedron->Attributes();
+  if (drawer->HasDatumAspect()) {
+      Handle(Prs3d_DatumAspect) daspect = drawer->DatumAspect();
+      daspect->FirstAxisAspect()->SetColor(Quantity_Color(1.0, 0.0, 0.0, Quantity_TOC_RGB));
+      daspect->SecondAxisAspect()->SetColor(Quantity_Color(0.0, 1.0, 0.0, Quantity_TOC_RGB));
+      daspect->ThirdAxisAspect()->SetColor(Quantity_Color(0.0, 0.0, 1.0, Quantity_TOC_RGB));
+  }
+  myAISContext->Display(myTrihedron);
+  myAISContext->Deactivate(myTrihedron);
+  
+  myTrihedron->SetTransformPersistence(Graphic3d_TMF_TriedronPers, gp_Pnt(-1, -1, 200));
+  myTrihedron->SetSize(100);
+
+  createActions();
+  myButsMap[TrihId]->setChecked(false);
+  onTrihChanged();
+}
+
+OCCViewer_ViewWidget::~OCCViewer_ViewWidget()
+{
+  #if OCC_VERSION_LARGE <= 0x06060000
+    myV3dCollector.Nullify();
+  #endif
+}
+
+void OCCViewer_ViewWidget::reset()
+{
+  clearViewer();
+  myOperation = NOTHING;
+  myCurrPointType = OCCViewer_ViewWindow::GRAVITY;
+}
+
+void OCCViewer_ViewWidget::Display(const TopoDS_Shape shape, const bool theShaded,
+                                   const QColor& shapeColor)
+{
+  clearViewer(false);
+  if (shape.IsNull()) {
+    myAISContext->UpdateCurrentViewer();
+    return;
+  }
+
+  Handle(AIS_InteractiveObject) io = new AIS_Shape(shape);
+  io->UnsetSelectionMode();
+  io->UnsetHilightMode();
+
+  Quantity_Color aColor(shapeColor.red()/255., shapeColor.green()/255.,
+                        shapeColor.blue()/255., Quantity_TOC_RGB);
+  io->SetColor(aColor);
+
+  myAISContext->Display(io, false);
+  if (theShaded) {
+    myAISContext->SetDisplayMode(io, AIS_Shaded, false);
+    myAISContext->SetMaterial(io, Graphic3d_NOM_PLASTIC, false);
+  }
+  else
+    myAISContext->SetDisplayMode(io, AIS_WireFrame, false);
+  viewerFitAll(false);
+  myAISContext->UpdateCurrentViewer();
+}
+
+void OCCViewer_ViewWidget::createActions()
+{
+  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+  QtxAction* aAction;
+
+  // FitAll
+  aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITALL")),
+                           tr("MNU_FITALL"), 0, this);
+  aAction->setStatusTip(tr("DSC_FITALL"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
+  myButsMap[ FitAllId ] = aAction;
+
+  // FitRect
+  aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FITAREA")),
+                           tr("MNU_FITRECT"), 0, this);
+  aAction->setStatusTip(tr("DSC_FITRECT"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
+  myButsMap[ FitRectId ] = aAction;
+
+  // Zoom
+  aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ZOOM")),
+                           tr("MNU_ZOOM_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
+  myButsMap[ ZoomId ] = aAction;
+
+  // Panning
+  aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_PAN")),
+                           tr("MNU_PAN_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_PAN_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
+  myButsMap[ PanId ] = aAction;
+
+  // Global Panning
+  aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_GLOBALPAN")),
+                           tr("MNU_GLOBALPAN_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onActivated()));
+  myButsMap[ GlobalPanId ] = aAction;
+
+  // Projections
+  aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_FRONT")),
+                           tr("MNU_FRONT_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
+  myButsMap[ FrontId ] = aAction;
+
+  aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BACK")),
+                           tr("MNU_BACK_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_BACK_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
+  myButsMap[ BackId ] = aAction;
+
+  aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TOP")),
+                           tr("MNU_TOP_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_TOP_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
+  myButsMap[ TopId ] = aAction;
+
+  aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_BOTTOM")),
+                           tr("MNU_BOTTOM_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
+  myButsMap[ BottomId ] = aAction;
+
+  aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_LEFT")),
+                           tr("MNU_LEFT_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
+  myButsMap[ LeftId ] = aAction;
+
+  aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_RIGHT")),
+                           tr("MNU_RIGHT_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
+  connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
+  myButsMap[ RightId ] = aAction;
+
+  aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_ROTATE")),
+                          tr("MNU_ROTATE_VIEW"), 0, this);
+  aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onActivated()));
+  myToolBar->addAction(aAction);
+  myButsMap[ RotationId ] = aAction;
+
+  aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRE"), aResMgr->loadPixmap("OCCViewer", tr("ICON_OCCVIEWER_VIEW_TRIHEDRON")),
+                          tr("MNU_SHOW_TRIHEDRE"), 0, this);
+  aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRE"));
+  aAction->setCheckable(true);
+  connect(aAction, SIGNAL(triggered()), this, SLOT(onTrihChanged()));
+  myToolBar->addAction(aAction);
+  myButsMap[ TrihId ] = aAction;
+
+  myZoomBtns->insertAction(myButsMap[ FitAllId ]);
+  myZoomBtns->insertAction(myButsMap[ FitRectId ]);
+  myZoomBtns->insertAction(myButsMap[ ZoomId ]);
+
+  myPanBtns->insertAction(myButsMap[ PanId ]);
+  myPanBtns->insertAction(myButsMap[ GlobalPanId ]);
+
+  myProjBtns->insertAction(myButsMap[ FrontId ]);
+  myProjBtns->insertAction(myButsMap[ BackId ]);
+  myProjBtns->insertAction(myButsMap[ TopId ]);
+  myProjBtns->insertAction(myButsMap[ BottomId ]);
+  myProjBtns->insertAction(myButsMap[ LeftId ]);
+  myProjBtns->insertAction(myButsMap[ RightId ]);
+}
+
+/*!
+  Custom event handler
+*/
+bool OCCViewer_ViewWidget::eventFilter(QObject* watched, QEvent* e)
+{
+  if (e->type() == QEvent::ContextMenu)
+    return true;
+
+  bool aRes = false;
+  int aReturn = -1;
+  if (watched == myViewPort) {
+    int aType = e->type();
+    switch(aType) {
+    case QEvent::MouseButtonPress:
+      vpMousePressEvent((QMouseEvent*) e);
+      aRes = true;
+      aReturn = 1;
+      break;
+    case QEvent::MouseButtonRelease:
+      vpMouseReleaseEvent((QMouseEvent*) e);
+      aRes = true;
+      aReturn = 1;
+      break;
+    case QEvent::MouseMove:
+      vpMouseMoveEvent((QMouseEvent*) e);
+      aRes = true;
+      aReturn = 1;
+      break;
+    case QEvent::Wheel:
+      {
+        QWheelEvent* aEvent = (QWheelEvent*) e;
+        double aDelta = aEvent->delta();
+        double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.; 
+        myViewPort->getView()->SetZoom(aScale);
+      }
+      aRes = true;
+      aReturn = 1;
+      break;
+    default:
+      break;
+    }
+  }
+  if (aReturn == -1)
+    aRes = QFrame::eventFilter(watched, e);
+
+  if (watched == myViewPort && !myViewPort->getView().IsNull()) {
+    if (e->type() == QEvent::MouseButtonRelease)
+      viewZFitAll();
+  }
+
+  return aRes;
+}
+
+void OCCViewer_ViewWidget::onActivated()
+{
+  if(!sender() || !sender()->inherits("QtxAction"))
+    return;
+  QtxAction* anAction = (QtxAction*)sender();
+  ActionsMap::const_iterator anIt = myButsMap.begin(), last = myButsMap.end();
+  int aCurAction = -1;
+  for (; anIt != last && aCurAction == -1; anIt++) {
+    if (anIt.value() != anAction)
+      continue;
+    aCurAction = anIt.key();
+  }
+  switch(aCurAction) {
+    case RotationId:  activateRotation(); return;
+    case FitAllId:    viewerFitAll();  break;
+    case FitRectId:   activateWindowFit();   break;
+    case ZoomId:      activateZoom();        break;
+    case PanId:       activatePanning();     break;
+    case GlobalPanId: activateGlPanning();   break;
+  }
+  viewZFitAll();
+}
+
+void OCCViewer_ViewWidget::viewerFitAll(const bool theUpdate)
+{
+  myViewPort->fitAll(false, true, theUpdate);
+  viewZFitAll();
+}
+
+void OCCViewer_ViewWidget::onTrihChanged()
+{
+  QtxAction* anAction = myButsMap[TrihId];
+  myShowTrihedron = anAction->isChecked();
+  if (myShowTrihedron) {
+    myAISContext->Display(myTrihedron);
+    myAISContext->Deactivate(myTrihedron);
+  }
+  else 
+    myAISContext->Erase(myTrihedron);
+}
+/*!
+  Processes transformation "front view"
+*/
+void OCCViewer_ViewWidget::onFrontView()
+{
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xpos);
+  viewerFitAll();
+}
+
+/*!
+  Processes transformation "back view"
+*/
+void OCCViewer_ViewWidget::onBackView()
+{
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if (!aView3d.IsNull()) aView3d->SetProj (V3d_Xneg);
+  viewerFitAll();
+}
+
+/*!
+  Processes transformation "top view"
+*/
+void OCCViewer_ViewWidget::onTopView()
+{
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zpos);
+  viewerFitAll();
+}
+
+/*!
+  Processes transformation "bottom view"
+*/
+void OCCViewer_ViewWidget::onBottomView()
+{
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if (!aView3d.IsNull()) aView3d->SetProj (V3d_Zneg);
+  viewerFitAll();
+}
+
+/*!
+  Processes transformation "left view"
+*/
+void OCCViewer_ViewWidget::onLeftView()
+{
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if (!aView3d.IsNull()) aView3d->SetProj (V3d_Yneg);
+  viewerFitAll();
+}
+
+/*!
+  Processes transformation "right view"
+*/
+void OCCViewer_ViewWidget::onRightView()
+{
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if (!aView3d.IsNull()) aView3d->SetProj (V3d_Ypos);
+  viewerFitAll();
+}
+
+
+void OCCViewer_ViewWidget::viewZFitAll()
+{
+   myViewPort->getView()->ZFitAll(Z_FIT_ALL_SIZE);
+}
+
+void OCCViewer_ViewWidget::activateZoom()
+{
+  if (!transformRequested() && !myCursorIsHand)
+    myCursor = cursor();          /* save old cursor */
+  
+  if (myOperation != ZOOMVIEW) {
+    QPixmap zoomPixmap (imageZoomCursor);
+    QCursor zoomCursor (zoomPixmap);
+    if(setTransformRequested (ZOOMVIEW))
+      setCursor(zoomCursor);
+  }
+}
+
+void OCCViewer_ViewWidget::activateWindowFit()
+{
+  if (!transformRequested() && !myCursorIsHand)
+    myCursor = cursor();          /* save old cursor */
+
+  if (myOperation != WINDOWFIT) {
+    QCursor handCursor (Qt::PointingHandCursor);
+    if(setTransformRequested (WINDOWFIT))
+      setCursor (handCursor);
+    myCursorIsHand = true;
+  }
+}
+
+void OCCViewer_ViewWidget::activateRotation()
+{
+  if (!transformRequested() && !myCursorIsHand)
+    myCursor = cursor();        // save old cursor 
+  
+  if (myOperation != ROTATE) {
+    QPixmap rotatePixmap (imageRotateCursor);
+    QCursor rotCursor (rotatePixmap);
+    if(setTransformRequested (ROTATE))
+      setCursor(rotCursor);
+  }
+}
+
+void OCCViewer_ViewWidget::activatePanning()
+{
+  if (!transformRequested() && !myCursorIsHand)
+    myCursor = cursor();        // save old cursor 
+  
+  if (myOperation != PANVIEW) {
+    QCursor panCursor (Qt::SizeAllCursor);
+    if(setTransformRequested (PANVIEW))
+      setCursor(panCursor);
+  }
+}
+
+void OCCViewer_ViewWidget::activateGlPanning()
+{
+  Handle(V3d_View) aView3d = myViewPort->getView();
+  if (!aView3d.IsNull()) {
+    QPixmap globalPanPixmap (imageCrossCursor);
+    QCursor glPanCursor (globalPanPixmap);
+    myCurScale = aView3d->Scale();
+    aView3d->FitAll(0.01, false);
+    myCursor = cursor();        // save old cursor 
+    myViewPort->fitAll(); // fits view before selecting a new scene center 
+    if(setTransformRequested(PANGLOBAL))
+      setCursor(glPanCursor);
+  }
+}
+
+void OCCViewer_ViewWidget::vpMousePressEvent(QMouseEvent* theEvent)
+{
+  myStartX = theEvent->x();
+  myStartY = theEvent->y();
+  switch (myOperation) {
+    case WINDOWFIT:
+    case PANGLOBAL:
+    case ZOOMVIEW:
+    case PANVIEW:
+    break;
+    case ROTATE:
+    if (theEvent->button() == Qt::LeftButton) {
+           myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
+         }
+    break;
+    default:
+  /*  Try to activate a transformation */
+    switch (getButtonState(theEvent)) {
+      case ZOOMVIEW:
+        activateZoom();
+        break;
+      case PANVIEW:
+        activatePanning();
+        break;
+      case ROTATE:
+        activateRotation();
+        //myViewPort->startRotation(myStartX, myStartY);//, 0, mySelectedPoint);
+        break;
+      default:
+        break;
+    }
+  }
+}
+OCCViewer_ViewWidget::OperationType OCCViewer_ViewWidget::getButtonState(QMouseEvent* theEvent)
+{
+  OperationType aOp = NOTHING;
+  if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]) &&
+      (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ZOOM]))
+    aOp = ZOOMVIEW;
+  else if((theEvent->modifiers() == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]) && 
+           (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::PAN]))
+    aOp = PANVIEW;
+  else if((theEvent->modifiers()  == SUIT_ViewModel::myStateMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]) &&
+           (theEvent->button() == SUIT_ViewModel::myButtonMap[SUIT_ViewModel::STANDARD][SUIT_ViewModel::ROTATE]))
+    aOp = ROTATE;
+
+  return aOp;
+}
+
+void OCCViewer_ViewWidget::vpMouseReleaseEvent(QMouseEvent* theEvent)
+{
+  switch (myOperation) {
+  case NOTHING:
+    break;
+  case ROTATE:
+    myViewPort->endRotation();
+    resetState();
+    break;
+  case PANVIEW:
+  case ZOOMVIEW:
+    resetState();
+    break;
+    
+  case PANGLOBAL:
+    if (theEvent->button() == Qt::LeftButton) {
+      myViewPort->setCenter(theEvent->x(), theEvent->y());
+      myViewPort->getView()->SetScale(myCurScale);
+      resetState();
+    }
+    break;
+      
+  case WINDOWFIT:
+    if (theEvent->modifiers() == Qt::LeftButton) {
+      myCurrX = theEvent->x();
+      myCurrY = theEvent->y();
+      QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
+      if (!rect.isEmpty()) myViewPort->fitRect(rect);
+        resetState();
+    }
+    break;
+  }
+  
+  // NOTE: viewer 3D detects a rectangle of selection using this event
+  // so we must emit it BEFORE resetting the selection rectangle
+
+  if (theEvent->button() == Qt::LeftButton && myDrawRect) {
+    myDrawRect = false;
+    drawRect();
+    resetState(); 
+    myViewPort->update();
+  }
+}
+
+void OCCViewer_ViewWidget::vpMouseMoveEvent(QMouseEvent* theEvent)
+{
+  myCurrX = theEvent->x();
+  myCurrY = theEvent->y();
+  switch (myOperation) {
+  case ROTATE:
+    myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
+    break;
+  case ZOOMVIEW:
+    myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
+    myStartX = myCurrX;
+    myStartY = myCurrY;
+    break;
+    
+  case PANVIEW:
+    myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
+    myStartX = myCurrX;
+    myStartY = myCurrY;
+    break;
+    
+  case PANGLOBAL:
+    break;
+
+  default: {
+    int aState = theEvent->modifiers();
+    if (aState == Qt::LeftButton ||
+      aState == ((int) Qt::LeftButton | (int) Qt::ShiftModifier)) {
+        myDrawRect = true;
+        if (myDrawRect) {
+          drawRect();
+          if (!myCursorIsHand) {   // we are going to sketch a rectangle
+            QCursor handCursor (Qt::PointingHandCursor);
+            myCursorIsHand = true;
+            myCursor = cursor();
+            setCursor(handCursor);
+          }
+        }
+      }
+    }
+  }
+}
+
+/*!
+  Sets the viewport to its initial state
+  (no transformations in process etc.)
+*/
+void OCCViewer_ViewWidget::resetState()
+{
+  myDrawRect = false;
+  myRect.setLeft(2);
+  myRect.setRight(0);
+
+  /* make rectangle empty (left > right) */
+  if (transformRequested() || myCursorIsHand)
+    setCursor(myCursor);
+  myCursorIsHand = false;
+
+  setTransformRequested(NOTHING);
+}
+
+void OCCViewer_ViewWidget::drawRect()
+{
+  QPainter aPainter(myViewPort);
+  aPainter.setCompositionMode(QPainter::CompositionMode_Xor);
+  aPainter.setPen(Qt::white);
+  QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY);
+  if (!myRect.isEmpty())
+    aPainter.drawRect(myRect);
+  aPainter.drawRect(aRect);
+  myRect = aRect;
+}
+
+bool OCCViewer_ViewWidget::setTransformRequested (OperationType op)
+{
+  myOperation = op;
+  myViewPort->setMouseTracking(myOperation == NOTHING);
+  return true;
+}
+
+void OCCViewer_ViewWidget::clearViewer(const bool theUpdate)
+{
+  // check if trihedron is displayed
+  Standard_Boolean isTrihedronDisplayed = myAISContext->IsDisplayed(myTrihedron);
+
+  // get objects to be erased (all currently displayed objects)
+  AIS_ListOfInteractive aList;
+  myAISContext->DisplayedObjects(aList);
+  AIS_ListIteratorOfListOfInteractive anIter(aList);
+  for (; anIter.More(); anIter.Next()) {
+    if (isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE(AIS_Trihedron))
+      continue;
+    // erase an object
+    Handle(AIS_InteractiveObject) anIO = anIter.Value();
+#if OCC_VERSION_LARGE <= 0x06060000 
+    myAISContext->Erase(anIO, false, false);
+#else
+    myAISContext->Erase(anIO, false);
+#endif
+  }
+
+  // display trihedron if necessary
+  if (isTrihedronDisplayed)
+    myAISContext->Display(myTrihedron, theUpdate);
+  else if (theUpdate)
+    myV3dViewer->Update();
+  if (theUpdate)
+    myAISContext->UpdateCurrentViewer();
+}
diff --git a/src/HYDROCurveCreator/OCCViewer_ViewWidget.h b/src/HYDROCurveCreator/OCCViewer_ViewWidget.h
new file mode 100644 (file)
index 0000000..c4d0279
--- /dev/null
@@ -0,0 +1,116 @@
+// File:        OCCViewer_ViewWidget.h
+// Created:     26 Jul 2012
+// Author:      Natalia ERMOLAEVA
+// Copyright:   CEA 2011
+
+#ifndef OCCVIEWER_VIEWWIDGET_H
+#define OCCVIEWER_VIEWWIDGET_H
+
+#include "CurveCreator_Macro.hxx"
+
+#include <QCursor>
+#include <QFrame>
+#include <QColor>
+
+#include <QtxAction.h>
+#include <QtxMultiAction.h>
+
+#include <OCCViewer_ViewWindow.h>
+#include <V3d_Viewer.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_Trihedron.hxx>
+#include <TopoDS_Shape.hxx>
+
+class OCCViewer_ViewPort3d;
+class QPushButton;
+class QToolBar;
+
+class Handle(V3d_Viewer);
+
+#ifdef WIN32
+#pragma warning ( disable:4251 )
+#endif
+
+// ---------------- OCC view widget --------
+class CURVECREATOR_EXPORT OCCViewer_ViewWidget : public QFrame
+{
+  Q_OBJECT
+
+public:
+  OCCViewer_ViewWidget(QWidget* parent);
+  ~OCCViewer_ViewWidget();
+
+  bool      eventFilter(QObject* watched, QEvent* e);
+
+  void      reset();
+  void      Display(const TopoDS_Shape shape, const bool theShaded,
+                    const QColor& shapeColor);
+
+private slots:
+  void      onActivated();
+  void      onTrihChanged();
+  void      onFrontView();
+  void      onBackView();
+  void      onTopView();
+  void      onBottomView();
+  void      onLeftView();
+  void      onRightView();
+
+private:
+  enum OperationType{ NOTHING, FITALLVIEW, WINDOWFIT, ZOOMVIEW, PANVIEW, PANGLOBAL,
+                      ROTATE };
+
+  void      createActions();
+  void      viewZFitAll();
+  void      activateZoom();
+  void      activateWindowFit();
+  void      activateRotation();
+  void      activatePanning();
+  void      activateGlPanning();
+  OperationType getButtonState(QMouseEvent* theEvent);
+  void      viewerFitAll(const bool theUpdate = true);
+
+  void vpMousePressEvent  (QMouseEvent* theEvent);
+  void vpMouseReleaseEvent(QMouseEvent* theEvent);
+  void vpMouseMoveEvent   (QMouseEvent* theEvent);
+
+  void drawRect();
+  void resetState();
+  bool transformRequested() { return myOperation != NOTHING; }
+  bool setTransformRequested (OperationType op);
+  void clearViewer(const bool theUpdate = true);
+
+  typedef enum { FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, TrihId,
+                 FrontId, BackId, TopId, BottomId, LeftId, RightId, None } ButtonsType;
+  typedef QMap<ButtonsType, QtxAction*> ActionsMap;
+
+private:
+  OCCViewer_ViewPort3d*          myViewPort;
+  Handle(V3d_Viewer)             myV3dViewer;
+#if OCC_VERSION_LARGE <= 0x06060000 
+  Handle(V3d_Viewer)             myV3dCollector;
+#endif
+  Handle(AIS_InteractiveContext) myAISContext;
+  Handle(AIS_Trihedron)          myTrihedron;
+
+  QtxMultiAction       *myZoomBtns, *myPanBtns, *myProjBtns;
+  QToolBar*            myToolBar;
+  OperationType        myOperation;
+
+  ActionsMap           myButsMap;
+  QCursor              myCursor;
+  QRect                myRect;
+
+  double                myCurScale;
+  bool                  myCursorIsHand;
+  bool                  myDrawRect;
+  int                   myStartX;
+  int                   myStartY;
+  int                   myCurrX;
+  int                   myCurrY;
+  OCCViewer_ViewWindow::RotationPointType myCurrPointType;
+  gp_Pnt                mySelectedPoint;
+  bool                  myShowTrihedron;
+};
+
+#endif
index 25c2deaa39fb51ed745782cdba6730d181aae4c7..a1ae6afd4b19857d1c4e55f2da35008f58bcb661 100644 (file)
@@ -27,6 +27,7 @@
 #include <CurveCreator_ICurve.hxx>
 
 #include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewWidget.h>
 
 #include <QGroupBox>
 #include <QHBoxLayout>
@@ -47,18 +48,22 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr
   myEditorWidget = new CurveCreator_Widget( this, NULL );
   addWidget( myEditorWidget, 3 );
 
-  myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
-  addWidget( myAddElementBox, 2 );
+  //OCCViewer_ViewWindow* aPreview = new OCCViewer_ViewWindow(
+  OCCViewer_ViewWidget* aViewWidget = new OCCViewer_ViewWidget( this );
+  addWidget( aViewWidget, 4 );
 
-  QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
-  anAddElementLayout->setMargin( 0 );
-  anAddElementLayout->setSpacing( 5 );
+  //myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this );
+  //addWidget( myAddElementBox, 2 );
+
+  //QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
+  //anAddElementLayout->setMargin( 0 );
+  //anAddElementLayout->setSpacing( 5 );
 
   connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
   connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*) ), this, SLOT( processStartedSubOperation(QWidget*) ) );
   connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
 
-  myAddElementBox->hide();
+  //myAddElementBox->hide();
 }
 
 HYDROGUI_ProfileDlg::~HYDROGUI_ProfileDlg()
@@ -72,24 +77,24 @@ void HYDROGUI_ProfileDlg::setOCCViewer( OCCViewer_Viewer* theViewer )
 
 void HYDROGUI_ProfileDlg::processStartedSubOperation( QWidget* theWidget )
 {
-  myEditorWidget->setEnabled( false );
+  //myEditorWidget->setEnabled( false );
 
-  QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
-  anAddElementLayout->addWidget( theWidget );
+  //QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
+  //anAddElementLayout->addWidget( theWidget );
 
-  theWidget->show();
-  myAddElementBox->show();
+  //theWidget->show();
+  //myAddElementBox->show();
 }
 
 void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
 {
-  myEditorWidget->setEnabled( true );
+  /*myEditorWidget->setEnabled( true );
 
   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
   anAddElementLayout->removeWidget( theWidget );
 
   theWidget->hide();
-  myAddElementBox->hide();
+  myAddElementBox->hide();*/
 }
 
 void HYDROGUI_ProfileDlg::reset()
index 589eb1d88e1d3d7ccd30cc9ffd44e9bcd95e8f91..266599303d8940e5cd06a5ee802063d37db31288 100644 (file)
@@ -66,7 +66,7 @@ signals:
 private:
   QLineEdit*            myName;
   CurveCreator_Widget*  myEditorWidget;
-  QGroupBox*            myAddElementBox;
+  //QGroupBox*            myAddElementBox;
 };
 
 #endif