1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_DimensionInteractor.cxx
25 // Author : Anton POLETAEV, Open CASCADE S.A.S.
27 #include "MeasureGUI_DimensionInteractor.h"
29 #include <GEOM_Displayer.h>
30 #include <SalomeApp_Application.h>
31 #include <OCCViewer_ViewManager.h>
32 #include <OCCViewer_ViewWindow.h>
33 #include <OCCViewer_ViewPort3d.h>
34 #include <SUIT_ViewManager.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_Desktop.h>
38 #include <QMouseEvent>
40 #include <AIS_InteractiveContext.hxx>
41 #include <AIS_LengthDimension.hxx>
42 #include <AIS_DiameterDimension.hxx>
43 #include <AIS_AngleDimension.hxx>
44 #include <Prs3d_DimensionAspect.hxx>
45 #include <Prs3d_TextAspect.hxx>
48 #include <gce_MakeDir.hxx>
51 #include <Extrema_ExtCC.hxx>
52 #include <Extrema_POnCurv.hxx>
53 #include <GeomAdaptor_Curve.hxx>
54 #include <GeomAPI_IntCS.hxx>
55 #include <Geom_Line.hxx>
56 #include <Geom_Plane.hxx>
57 #include <NCollection_Sequence.hxx>
59 #if OCC_VERSION_LARGE >= 0x07010000
60 #include <Quantity_Length.hxx>
63 //=================================================================================
64 // function : Constructor
66 //=================================================================================
67 MeasureGUI_DimensionInteractor::MeasureGUI_DimensionInteractor( GeometryGUI* theGUI,
69 : QObject( theParent ),
74 myOperation( Operation_None )
78 //=================================================================================
79 // function : Deactivate
81 //=================================================================================
82 MeasureGUI_DimensionInteractor::~MeasureGUI_DimensionInteractor()
87 //=================================================================================
90 //=================================================================================
91 void MeasureGUI_DimensionInteractor::Enable()
100 // install event filtering on viewer windows
101 SalomeApp_Application* anApp = myGeomGUI->getApp();
107 myVM = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
108 myViewer = (OCCViewer_Viewer*) myVM->getViewModel();
109 if ( !myVM || !myViewer )
114 connect( myVM, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), SLOT( OnViewCreated( SUIT_ViewWindow* ) ) );
115 connect( myVM, SIGNAL( deleteView ( SUIT_ViewWindow* ) ), SLOT( OnViewRemoved( SUIT_ViewWindow* ) ) );
117 QVector<SUIT_ViewWindow*> aViews = myVM->getViews();
118 QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
119 for ( ; aViewIt != aViews.end(); ++aViewIt )
121 ConnectView( *aViewIt );
125 //=================================================================================
126 // function : Disable
128 //=================================================================================
129 void MeasureGUI_DimensionInteractor::Disable()
138 // remove event filtering from viewer windows
139 QVector<SUIT_ViewWindow*> aViews = myVM->getViews();
140 QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
141 for ( ; aViewIt != aViews.end(); ++aViewIt )
143 DisconnectView( *aViewIt );
147 //=================================================================================
148 // function : GetOperation
150 //=================================================================================
151 MeasureGUI_DimensionInteractor::Operation
152 MeasureGUI_DimensionInteractor::GetOperation( const Handle(SelectMgr_EntityOwner)& theEntity,
153 const Qt::MouseButtons theButtons,
154 const Qt::KeyboardModifiers theKeys )
156 if ( ( theButtons & Qt::LeftButton ) == 0 )
158 return Operation_None;
161 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast( theEntity );
162 if ( anOwner.IsNull() )
164 return Operation_None;
167 Standard_Real anAngTolerance = M_PI / 30.0; // 6 degree tolerance
169 switch ( anOwner->SelectionMode() )
173 if ( ( theKeys & Qt::ControlModifier ) == 0 )
175 return Operation_MoveFlyoutInPlane;
178 // "free moving" is only available for length and diameter
179 if ( !myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
180 && !myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
182 return Operation_None;
185 return Operation_MoveFlyoutFree;
188 case AIS_DSM_Text : return Operation_MoveText;
189 default : return Operation_None;
193 //=================================================================================
194 // function : StartOperation
196 //=================================================================================
197 bool MeasureGUI_DimensionInteractor::StartOperation( const Operation theOp,
198 const Handle(V3d_View)& theView,
202 Standard_Real anAngTolerance = M_PI / 30.0; // 6 degree tolerance
206 case Operation_MoveFlyoutInPlane :
207 case Operation_MoveText :
209 // operation can be started if the plane in which the flyout
210 // or text moved is not completely orthogonal to the screen
211 gp_Pln aPlane = myInteractedIO->GetPlane();
212 gp_Lin aProj = Projection( theView, theX, theY );
213 Standard_Real aCrossAng = aProj.Direction().Angle( aPlane.Axis().Direction() );
214 return Abs( M_PI * 0.5 - aCrossAng ) > anAngTolerance;
217 case Operation_MoveFlyoutFree :
219 // operation can be started only for linear dimensions
220 if ( !myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
221 && !myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
226 // determine whether the rotation operation is frontal or side
230 // get first and second point from which the flyout line is normally extended
231 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
232 if ( !aLength.IsNull() )
234 aFirstPoint = aLength->FirstPoint();
235 aSecondPoint = aLength->SecondPoint();
238 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
239 if ( !aDiameter.IsNull() )
241 const gp_Pnt& aCenter = aDiameter->Circle().Location();
242 aFirstPoint = aDiameter->AnchorPoint();
243 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
246 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
247 gp_Pln aPlane = myInteractedIO->GetPlane();
248 gp_Dir aPlaneN = aPlane.Axis().Direction();
249 gp_Lin aProj = Projection( theView, theX, theY );
251 const gp_Dir& aProjDir = aProj.Direction();
253 // can turn only if looking from side
254 if ( aProjDir.IsParallel( aPlaneN, anAngTolerance ) ||
255 aProjDir.IsNormal( aBaseDir, anAngTolerance ) )
260 bool isProjected = false;
261 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
267 gp_Vec aPointVector( aFirstPoint, aPointOnPlane );
268 gp_Pnt aPointOnBase = gp_Pnt( aFirstPoint.XYZ() + aBaseDir.XYZ() * aPointVector.Dot( aBaseDir ) );
269 myFreeMovePlane = gp_Pln( aPointOnBase, aBaseDir );
279 //=================================================================================
280 // function : MoveFlyoutFree
282 //=================================================================================
283 void MeasureGUI_DimensionInteractor::MoveFlyoutFree( const Handle(V3d_View)& theView,
287 // project point onto dimension plane
288 bool isProjected = false;
289 gp_Pln aPlane = myFreeMovePlane;
290 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
299 // get first and second point from which the flyout line is normally extended
300 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
301 if ( !aLength.IsNull() )
303 aFirstPoint = aLength->FirstPoint();
304 aSecondPoint = aLength->SecondPoint();
307 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
308 if ( !aDiameter.IsNull() )
310 const gp_Pnt& aCenter = aDiameter->Circle().Location();
311 aFirstPoint = aDiameter->AnchorPoint();
312 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
315 gp_Vec aPointVector( aFirstPoint, aPointOnPlane );
316 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
317 gp_Pnt aPointOnBase = gp_Pnt( aFirstPoint.XYZ() + aBaseDir.XYZ() * aPointVector.Dot( aBaseDir ) );
319 // snapping tolerance
320 Quantity_Length aSize[2];
321 theView->Size( aSize[0], aSize[1] );
322 Standard_Real aSnapTolerance = 1e-2 * Max( aSize[0], aSize[1] );
324 gp_Dir aFlyoutDir = gce_MakeDir( aPointOnBase, aPointOnPlane );
326 // snapping to planes
327 NCollection_Sequence<gp_Pln> aSnapPlanes;
329 if ( aPointOnPlane.Distance( aPointOnBase ) > aSnapTolerance )
331 if ( !aBaseDir.IsParallel( gp::DZ(), Precision::Angular() ) )
333 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DZ().Crossed( aBaseDir ) ) );
335 if ( !aBaseDir.IsParallel( gp::DX(), Precision::Angular() ) )
337 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DX().Crossed( aBaseDir ) ) );
339 if ( !aBaseDir.IsParallel( gp::DY(), Precision::Angular() ) )
341 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DY().Crossed( aBaseDir ) ) );
345 // snap "drag proj" to Flyout plane, relative XOY, YOZ, ZOX planes
346 NCollection_Sequence<gp_Pln>::Iterator aSnapIt( aSnapPlanes );
348 for ( ; aSnapIt.More(); aSnapIt.Next() )
350 const gp_Pln& aSnapPln = aSnapIt.Value();
352 // project direction into plane
353 gp_Vec aPlaneDir = gp_Vec( aSnapPln.Axis().Direction() );
354 gp_Vec aFlyoutProj = gp_Vec( aFlyoutDir ) - aPlaneDir * gp_Vec( aFlyoutDir ).Dot( aPlaneDir );
356 // snapping is not applicable
357 if ( aSnapPln.Contains( gp_Lin( aFirstPoint, aFlyoutDir ), Precision::Confusion(), Precision::Angular() ) )
361 if ( Abs( gp_Vec( aPointOnBase, aPointOnPlane ).Dot( aPlaneDir ) ) > aSnapTolerance )
365 if ( aFlyoutProj.Magnitude() <= Precision::Confusion() )
370 aFlyoutDir = gp_Dir( aFlyoutProj );
375 Standard_Real aNewFlyout = aPointOnPlane.Distance( aPointOnBase );
377 if ( aNewFlyout <= Precision::Confusion() )
379 myInteractedIO->SetFlyout( 0.0 );
380 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
384 gp_Pln aNewPlane = gp_Pln( aFirstPoint, aBaseDir.Crossed( aFlyoutDir ) );
386 myInteractedIO->SetFlyout( aNewFlyout );
387 myInteractedIO->SetCustomPlane( aNewPlane );
389 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
392 //=================================================================================
393 // function : MoveFlyoutInPlane
395 //=================================================================================
396 void MeasureGUI_DimensionInteractor::MoveFlyoutInPlane( const Handle(V3d_View)& theView,
400 // project point onto dimension plane
401 bool isProjected = false;
402 gp_Pln aPlane = myInteractedIO->GetPlane();
403 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
409 const gp_Dir& aPlaneN = aPlane.Axis().Direction();
412 Standard_Real aFlyout = 0.0;
414 // extend flyout of linear dimension
415 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
416 || myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
421 // get first and second point from which the flyout line is normally extended
422 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
423 if ( !aLength.IsNull() )
425 aFirstPoint = aLength->FirstPoint();
426 aSecondPoint = aLength->SecondPoint();
429 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
430 if ( !aDiameter.IsNull() )
432 const gp_Pnt& aCenter = aDiameter->Circle().Location();
433 aFirstPoint = aDiameter->AnchorPoint();
434 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
437 gp_Lin aBaseLine( aFirstPoint, gce_MakeDir( aFirstPoint, aSecondPoint ) );
439 // check if the negative value is expected
440 gp_Dir aPositiveDir = aPlaneN.Crossed( aBaseLine.Direction() );
441 gp_Dir aPointDir = gce_MakeDir( aBaseLine.Location(), aPointOnPlane );
442 Standard_Boolean isPositive = aPointDir.Dot( aPositiveDir ) > 0;
445 ? aBaseLine.Distance( aPointOnPlane )
446 : -aBaseLine.Distance( aPointOnPlane );
449 // exten flyout of angular dimension
450 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
452 Handle(AIS_AngleDimension) anAngle = Handle(AIS_AngleDimension)::DownCast( myInteractedIO );
454 const gp_Pnt& aCenterPoint = anAngle->CenterPoint();
455 const gp_Pnt& aFirstPoint = anAngle->FirstPoint();
456 const gp_Pnt& aSecondPoint = anAngle->SecondPoint();
458 gp_Dir aFirstDir = gce_MakeDir( aCenterPoint, aFirstPoint );
459 gp_Dir aSecondDir = gce_MakeDir( aCenterPoint, aSecondPoint );
461 Standard_Real aDirAngle = aFirstDir.Angle( aSecondDir );
465 // the direction are: \ | /
470 gp_Dir aCenterDir = aFirstDir.Rotated( gp_Ax1( aCenterPoint, aPlaneN ), -aDirAngle * 0.5 );
472 gp_Dir aPointDir = gce_MakeDir( aCenterPoint, aPointOnPlane );
474 Standard_Boolean isPositive = aPointDir.Dot( aCenterDir ) > 0;
476 Standard_Real aPointAngle = aPointDir.AngleWithRef( aCenterDir, aPlaneN );
479 aPointAngle = ( M_PI - Abs( aPointAngle ) ) * ( -Sign( 1.0, aPointAngle ) );
482 gp_Vec aPointVec = gp_Vec( aCenterPoint, aPointOnPlane );
484 // calculate flyout for each separate case of point location
485 if ( aPointAngle < -aDirAngle * 0.5 ) // outside of second dir
487 aFlyout = aPointVec.Dot( aFirstDir );
489 else if ( aPointAngle > aDirAngle * 0.5 ) // outside of first dir
491 aFlyout = aPointVec.Dot( aSecondDir );
493 else // between first and second direction
496 ? aPointVec.Magnitude()
497 : -aPointVec.Magnitude();
501 myInteractedIO->SetFlyout( aFlyout );
503 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
506 //=================================================================================
507 // function : MoveText
509 //=================================================================================
510 void MeasureGUI_DimensionInteractor::MoveText( const Handle(V3d_View)& theView,
514 // project point onto dimension plane
515 bool isProjected = false;
516 gp_Pln aPlane = myInteractedIO->GetPlane();
517 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
523 const gp_Dir& aPlaneN = aPlane.Axis().Direction();
525 Prs3d_DimensionTextHorizontalPosition aHPos = myInteractedIO->DimensionAspect()->TextHorizontalPosition();
526 Prs3d_DimensionTextVerticalPosition aVPos = myInteractedIO->DimensionAspect()->TextVerticalPosition();
527 Prs3d_DimensionArrowOrientation aArrPos = myInteractedIO->DimensionAspect()->ArrowOrientation();
529 Standard_Real aHeight = myInteractedIO->DimensionAspect()->TextAspect()->Height() * 0.5;
531 // move text of linear dimension
532 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
533 || myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
538 // get first and second point from which the flyout line is normally extended
539 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
540 if ( !aLength.IsNull() )
542 aFirstPoint = aLength->FirstPoint();
543 aSecondPoint = aLength->SecondPoint();
546 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
547 if ( !aDiameter.IsNull() )
549 const gp_Pnt& aCenter = aDiameter->Circle().Location();
550 aFirstPoint = aDiameter->AnchorPoint();
551 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
555 Standard_Real aFlyout = myInteractedIO->GetFlyout();
556 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
557 gp_Dir aFlyoutDir = aFlyout >= 0.0
558 ? aPlaneN.Crossed( gce_MakeDir( aFirstPoint, aSecondPoint ) )
559 : -aPlaneN.Crossed( gce_MakeDir( aFirstPoint, aSecondPoint ) );
560 gp_Vec aFlyoutTranslate = gp_Vec( aFlyoutDir ) * Abs( myInteractedIO->GetFlyout() );
561 gp_Lin aFlyoutLine = gp_Lin( aFirstPoint, aBaseDir ).Translated( aFlyoutTranslate );
563 // check if positive or negative offset along flyout line
564 gp_Vec aFlyout2Point = gp_Vec( aFlyoutLine.Location(), aPointOnPlane );
566 Standard_Real aPosY = aFlyout2Point.Dot( aFlyoutDir );
567 Standard_Real aPosX = aFlyout2Point.Dot( aFlyoutLine.Direction() );
571 aHPos = Prs3d_DTHP_Left;
572 aArrPos = Prs3d_DAO_External;
574 else if ( aPosX > aFirstPoint.Distance( aSecondPoint ) )
576 aHPos = Prs3d_DTHP_Right;
577 aArrPos = Prs3d_DAO_External;
581 aHPos = Prs3d_DTHP_Center;
582 aArrPos = Prs3d_DAO_Fit;
585 if ( aPosY > aHeight )
587 aVPos = Prs3d_DTVP_Above;
589 else if ( aPosY < -aHeight )
591 aVPos = Prs3d_DTVP_Below;
595 aVPos = Prs3d_DTVP_Center;
599 // move text of angular dimension
600 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
602 Handle(AIS_AngleDimension) anAngle = Handle(AIS_AngleDimension)::DownCast( myInteractedIO );
604 const gp_Pnt& aCenterPoint = anAngle->CenterPoint();
605 const gp_Pnt& aFirstPoint = anAngle->FirstPoint();
606 const gp_Pnt& aSecondPoint = anAngle->SecondPoint();
608 Standard_Boolean isPositive = anAngle->GetFlyout() > 0.0;
610 gp_Dir aFirstDir = gce_MakeDir( aCenterPoint, aFirstPoint );
611 gp_Dir aSecondDir = gce_MakeDir( aCenterPoint, aSecondPoint );
612 if ( anAngle->GetFlyout() < 0.0 )
615 aSecondDir.Reverse();
618 Standard_Real aDirAngle = aFirstDir.Angle( aSecondDir );
622 // the direction are: \ | /
626 gp_Dir aCenterDir = aFirstDir.Rotated( gp_Ax1( aCenterPoint, aPlaneN ), -aDirAngle * 0.5 );
628 gp_Dir aPointDir = gce_MakeDir( aCenterPoint, aPointOnPlane );
630 Standard_Real aPointAngle = aPointDir.AngleWithRef( aCenterDir, aPlaneN );
632 gp_Vec aPointVec = gp_Vec( aCenterPoint, aPointOnPlane );
634 Standard_Real aPosY = 0.0;
636 // calculate flyout for each separate case of point location
637 if ( aPointAngle < -aDirAngle * 0.5 ) // outside of second dir
639 aHPos = Prs3d_DTHP_Left;
640 aArrPos = Prs3d_DAO_External;
641 aPosY = aPointVec.Dot( aFirstDir ) - Abs( anAngle->GetFlyout() );
643 else if ( aPointAngle > aDirAngle * 0.5 ) // outside of first dir
645 aHPos = Prs3d_DTHP_Right;
646 aArrPos = Prs3d_DAO_External;
647 aPosY = aPointVec.Dot( aSecondDir ) - Abs( anAngle->GetFlyout() );
649 else // between first and second direction
651 aHPos = Prs3d_DTHP_Center;
652 aArrPos = Prs3d_DAO_Fit;
653 aPosY = aPointVec.Magnitude() - Abs( anAngle->GetFlyout() );
656 if ( aPosY > aHeight )
658 aVPos = Prs3d_DTVP_Above;
660 else if ( aPosY < -aHeight )
662 aVPos = Prs3d_DTVP_Below;
666 aVPos = Prs3d_DTVP_Center;
670 myInteractedIO->DimensionAspect()->SetTextVerticalPosition( aVPos );
671 myInteractedIO->DimensionAspect()->SetTextHorizontalPosition( aHPos );
672 myInteractedIO->DimensionAspect()->SetArrowOrientation( aArrPos );
673 myInteractedIO->SetToUpdate();
675 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
678 //=================================================================================
679 // function : eventFilter
681 //=================================================================================
682 bool MeasureGUI_DimensionInteractor::eventFilter( QObject* theObject, QEvent* theEvent )
684 OCCViewer_ViewPort3d* aViewPort = (OCCViewer_ViewPort3d*) theObject;
686 Handle(V3d_View) aView3d = aViewPort->getView();
688 switch ( theEvent->type() )
690 // check whether it is the "dimension modify" operation or not.
691 case QEvent::MouseButtonPress :
693 Handle(AIS_InteractiveContext) anAISContext = myViewer->getAISContext();
695 QMouseEvent* aMouseEv = dynamic_cast<QMouseEvent*>( theEvent );
698 anAISContext->MoveTo( aMouseEv->x(), aMouseEv->y(), aView3d, Standard_True );
699 if ( !anAISContext->HasDetected() )
704 // commented by mpa 18.03.2015: since OCCT version 6.8.0 it's impossible
705 // to change position of the dimensions presentations (flyout, text),
706 // because anAISContext has 2 detected objects.
708 // check that there is only one detected entity
709 //anAISContext->InitDetected();
710 //if ( anAISContext->MoreDetected() )
715 Handle(SelectMgr_EntityOwner) aDetectedOwner = anAISContext->DetectedOwner();
716 if( aDetectedOwner.IsNull() )
721 myInteractedIO = Handle(AIS_Dimension)::DownCast( aDetectedOwner->Selectable() );
723 // try to start operation for the detected entity
724 Operation aStartOp = GetOperation( aDetectedOwner, aMouseEv->buttons(), aMouseEv->modifiers() );
725 if ( aStartOp == Operation_None )
730 if ( !StartOperation( aStartOp, aView3d, aMouseEv->x(), aMouseEv->y() ) )
735 myOperation = aStartOp;
739 for ( anAISContext->InitSelected(); anAISContext->MoreSelected(); anAISContext->NextSelected() )
741 mySelection.Append( anAISContext->SelectedOwner() );
744 anAISContext->ClearSelected( Standard_False );
745 anAISContext->AddOrRemoveSelected( aDetectedOwner, Standard_True );
747 emit InteractionStarted( myInteractedIO );
752 // stop event processing on mouse release
753 case QEvent::MouseButtonRelease :
755 if ( myOperation != Operation_None )
757 Handle(AIS_InteractiveContext) anAISContext = myViewer->getAISContext();
759 anAISContext->ClearSelected( Standard_False );
760 SeqOfOwners::Iterator anIt( mySelection );
761 for( ; anIt.More(); anIt.Next() )
763 anAISContext->AddOrRemoveSelected( anIt.Value(), Standard_False );
766 anAISContext->UpdateCurrentViewer();
770 myOperation = Operation_None;
772 emit InteractionFinished( myInteractedIO );
781 case QEvent::MouseMove :
783 QMouseEvent* aMouseEv = (QMouseEvent*) theEvent;
784 switch( myOperation )
786 case Operation_MoveFlyoutFree : MoveFlyoutFree ( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
787 case Operation_MoveFlyoutInPlane : MoveFlyoutInPlane( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
788 case Operation_MoveText : MoveText ( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
789 default : return false;
793 default: return false;
797 //=================================================================================
798 // function : ConnectView
800 //=================================================================================
801 void MeasureGUI_DimensionInteractor::ConnectView( SUIT_ViewWindow* theView )
803 ( (OCCViewer_ViewWindow*) theView )->getViewPort()->installEventFilter( this );
806 //=================================================================================
807 // function : DisconnectView
809 //=================================================================================
810 void MeasureGUI_DimensionInteractor::DisconnectView( SUIT_ViewWindow* theView )
812 ( (OCCViewer_ViewWindow*) theView )->getViewPort()->removeEventFilter( this );
815 //=================================================================================
816 // function : Projection
818 //=================================================================================
819 gp_Lin MeasureGUI_DimensionInteractor::Projection( const Handle(V3d_View)& theView,
821 const int theMouseY )
823 Standard_Real P[3], D[3];
824 theView->ConvertWithProj( theMouseX, theMouseY, P[0], P[1], P[2], D[0], D[1], D[2] );
825 return gp_Lin( gp_Pnt( P[0], P[1], P[2] ), gp_Dir( D[0], D[1], D[2] ) );
828 //=================================================================================
829 // function : ProjectPlane
831 //=================================================================================
832 gp_Pnt MeasureGUI_DimensionInteractor::ProjectPlane( const Handle(V3d_View)& theView,
835 const gp_Pln& thePlane,
838 gp_Lin aProjection = Projection( theView, theMouseX, theMouseY );
840 Handle(Geom_Line) aCrossLine = new Geom_Line( aProjection );
841 Handle(Geom_Plane) aCrossPlane = new Geom_Plane( thePlane );
843 GeomAPI_IntCS aFindCross( aCrossLine, aCrossPlane );
844 if ( !aFindCross.IsDone() || aFindCross.NbPoints() == 0 )
851 return aFindCross.Point( 1 );
854 //=================================================================================
855 // function : SensitivityTolerance
857 //=================================================================================
858 Standard_Real MeasureGUI_DimensionInteractor::SensitivityTolerance( const Handle(V3d_View)& theView )
860 // snapping tolerance
861 Quantity_Length aSize[2];
862 theView->Size( aSize[0], aSize[1] );
863 return 1e-2 * Max( aSize[0], aSize[1] );
866 //=================================================================================
867 // function : OnViewCreated
869 //=================================================================================
870 void MeasureGUI_DimensionInteractor::OnViewCreated( SUIT_ViewWindow* theView )
872 ConnectView( theView );
875 //=================================================================================
876 // function : OnViewRemoved
878 //=================================================================================
879 void MeasureGUI_DimensionInteractor::OnViewRemoved( SUIT_ViewWindow* theView )
881 DisconnectView( theView );