#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>
{
myViewPort->fitAll();
}
+ if( theOp==OCCViewer_ViewWindow::FITSELECTION )
+ {
+ CustomFitSelection();
+ }
OnTransformation();
}
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;
+}