]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1405: patch for fit selection on polylines
authorasl <asl@opencascade.com>
Mon, 13 Nov 2017 13:18:46 +0000 (16:18 +0300)
committerasl <asl@opencascade.com>
Mon, 13 Nov 2017 13:18:46 +0000 (16:18 +0300)
src/HYDROGUI/HYDROGUI_Overview.cxx
src/HYDROGUI/HYDROGUI_Overview.h

index 7a6c18976b5204579269d04823784ddec152f60c..bc809703f433f68c82e3be656123c6c455761bbd 100644 (file)
@@ -19,6 +19,8 @@
 #include <HYDROGUI_Overview.h>
 #include <OCCViewer_ViewPort3d.h>
 #include <OCCViewer_ViewFrame.h>
+#include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewManager.h>
 #include <QtxRubberBand.h>
 #include <QApplication>
 #include <QPainter>
@@ -372,6 +374,10 @@ void HYDROGUI_Overview::OnTransformationAfterOp( OCCViewer_ViewWindow::Operation
   {
     myViewPort->fitAll();
   }
+  if( theOp==OCCViewer_ViewWindow::FITSELECTION )
+  {
+    CustomFitSelection();
+  }
   OnTransformation();
 }
 
@@ -458,3 +464,113 @@ void HYDROGUI_Overview::OnResizeEvent( QResizeEvent* )
   if( myBand )
     myBand->update( true );
 }
+
+void HYDROGUI_Overview::CustomFitSelection() const
+{
+  OCCViewer_ViewPort3d* main = getViewPort( true );
+  if( !main )
+    return;
+
+  int w = main->width();
+  int h = main->height();
+
+  Bnd_Box bounding = BoundingForSelection();
+  if( bounding.IsVoid() )
+    return;
+
+  Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
+  bounding.Get( xmin, ymin, zmin, xmax, ymax, zmax );
+
+  QList<QPoint> points;
+  Standard_Integer xp, yp;
+  main->getView()->Convert( xmin, ymin, zmin, xp, yp ); points.append( QPoint( xp, yp ) );
+  main->getView()->Convert( xmax, ymin, zmin, xp, yp ); points.append( QPoint( xp, yp ) );
+  main->getView()->Convert( xmin, ymax, zmin, xp, yp ); points.append( QPoint( xp, yp ) );
+  main->getView()->Convert( xmax, ymax, zmin, xp, yp ); points.append( QPoint( xp, yp ) );
+  main->getView()->Convert( xmin, ymin, zmax, xp, yp ); points.append( QPoint( xp, yp ) );
+  main->getView()->Convert( xmax, ymin, zmax, xp, yp ); points.append( QPoint( xp, yp ) );
+  main->getView()->Convert( xmin, ymax, zmax, xp, yp ); points.append( QPoint( xp, yp ) );
+  main->getView()->Convert( xmax, ymax, zmax, xp, yp ); points.append( QPoint( xp, yp ) );
+
+  int xpmin, ypmin, xpmax, ypmax;
+  bool isFirst = true;
+  foreach( QPoint p, points )
+  {
+    int x = p.x(), y = p.y();
+    if( isFirst || x<xpmin )
+      xpmin = x;
+    if( isFirst || x>xpmax )
+      xpmax = x;
+    if( isFirst || y<ypmin )
+      ypmin = y;
+    if( isFirst || y>ypmax )
+      ypmax = y;
+
+    isFirst = false;
+  }
+
+  const int margin = 5;
+  QRect r( xpmin-margin, ypmin-margin, xpmax-xpmin+2*margin, ypmax-ypmin+2*margin );
+  main->fitRect( r );
+}
+
+Handle(AIS_InteractiveContext) HYDROGUI_Overview::context() const
+{
+  if( myMainView )
+  {
+    SUIT_ViewModel* vm = myMainView->getViewManager()->getViewModel();
+    OCCViewer_Viewer* viewer = dynamic_cast<OCCViewer_Viewer*>( vm );
+    if( viewer )
+      return viewer->getAISContext();
+  }
+  return Handle(AIS_InteractiveContext)();
+}
+
+typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners1;
+  typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners1;
+Bnd_Box HYDROGUI_Overview::BoundingForSelection() const
+{
+  Handle(AIS_InteractiveContext) c = context();
+
+  Bnd_Box aBndSelected;
+
+  AIS_MapOfObjectOwners1 anObjectOwnerMap;
+  for (c->InitSelected(); c->MoreSelected(); c->NextSelected())
+  {
+    const Handle(SelectMgr_EntityOwner)& anOwner = c->SelectedOwner();
+    Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
+    if (anObj->IsInfinite())
+    {
+      continue;
+    }
+
+    if (anOwner == anObj->GlobalSelOwner())
+    {
+      Bnd_Box aTmpBnd;
+      anObj->BoundingBox (aTmpBnd);
+      aBndSelected.Add (aTmpBnd);
+    }
+    else
+    {
+      Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
+      if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
+      {
+        anOwnerMap = new SelectMgr_IndexedMapOfOwner();
+        anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
+      }
+
+      anOwnerMap->Add (anOwner);
+    }
+  }
+
+  for (AIS_MapIteratorOfMapOfObjectOwners1 anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
+  {
+    const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
+    Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
+    aBndSelected.Add (aTmpBox);
+  }
+
+  anObjectOwnerMap.Clear();
+
+  return aBndSelected;
+}
index b96afdd81a4f50bf3866cb72665dd423d41e6117..6ab94a4b231260712735e01bb5be7e8642603aa5 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <QFrame>
 #include <OCCViewer_ViewWindow.h>
+#include <AIS_InteractiveContext.hxx>
 
 class OCCViewer_ViewPort3d;
 class OCCViewer_ViewFrame;
@@ -44,8 +45,12 @@ public:
 
   QImage dump() const;
 
+  Handle(AIS_InteractiveContext) context() const;
+
 protected:
   virtual bool eventFilter( QObject*, QEvent* );
+  void CustomFitSelection() const;
+  Bnd_Box BoundingForSelection() const;
 
 private slots:
   void OnTransformationAfterOp( OCCViewer_ViewWindow::OperationType );