From 8f1b7e91736d9a3190850696e2dc7b9120b9c83e Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 13 Nov 2017 16:18:46 +0300 Subject: [PATCH] refs #1405: patch for fit selection on polylines --- src/HYDROGUI/HYDROGUI_Overview.cxx | 116 +++++++++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_Overview.h | 5 ++ 2 files changed, 121 insertions(+) diff --git a/src/HYDROGUI/HYDROGUI_Overview.cxx b/src/HYDROGUI/HYDROGUI_Overview.cxx index 7a6c1897..bc809703 100644 --- a/src/HYDROGUI/HYDROGUI_Overview.cxx +++ b/src/HYDROGUI/HYDROGUI_Overview.cxx @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -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 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 || xxpmax ) + xpmax = x; + if( isFirst || yypmax ) + 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( vm ); + if( viewer ) + return viewer->getAISContext(); + } + return Handle(AIS_InteractiveContext)(); +} + +typedef NCollection_DataMap AIS_MapOfObjectOwners1; + typedef NCollection_DataMap::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; +} diff --git a/src/HYDROGUI/HYDROGUI_Overview.h b/src/HYDROGUI/HYDROGUI_Overview.h index b96afdd8..6ab94a4b 100644 --- a/src/HYDROGUI/HYDROGUI_Overview.h +++ b/src/HYDROGUI/HYDROGUI_Overview.h @@ -22,6 +22,7 @@ #include #include +#include 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 ); -- 2.39.2