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>
58 #include <Quantity_Length.hxx>
60 //=================================================================================
61 // function : Constructor
63 //=================================================================================
64 MeasureGUI_DimensionInteractor::MeasureGUI_DimensionInteractor( GeometryGUI* theGUI,
66 : QObject( theParent ),
71 myOperation( Operation_None )
75 //=================================================================================
76 // function : Deactivate
78 //=================================================================================
79 MeasureGUI_DimensionInteractor::~MeasureGUI_DimensionInteractor()
84 //=================================================================================
87 //=================================================================================
88 void MeasureGUI_DimensionInteractor::Enable()
97 // install event filtering on viewer windows
98 SalomeApp_Application* anApp = myGeomGUI->getApp();
104 myVM = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
105 myViewer = (OCCViewer_Viewer*) myVM->getViewModel();
106 if ( !myVM || !myViewer )
111 connect( myVM, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), SLOT( OnViewCreated( SUIT_ViewWindow* ) ) );
112 connect( myVM, SIGNAL( deleteView ( SUIT_ViewWindow* ) ), SLOT( OnViewRemoved( SUIT_ViewWindow* ) ) );
114 QVector<SUIT_ViewWindow*> aViews = myVM->getViews();
115 QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
116 for ( ; aViewIt != aViews.end(); ++aViewIt )
118 ConnectView( *aViewIt );
122 //=================================================================================
123 // function : Disable
125 //=================================================================================
126 void MeasureGUI_DimensionInteractor::Disable()
135 // remove event filtering from viewer windows
136 QVector<SUIT_ViewWindow*> aViews = myVM->getViews();
137 QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
138 for ( ; aViewIt != aViews.end(); ++aViewIt )
140 DisconnectView( *aViewIt );
144 //=================================================================================
145 // function : GetOperation
147 //=================================================================================
148 MeasureGUI_DimensionInteractor::Operation
149 MeasureGUI_DimensionInteractor::GetOperation( const Handle(SelectMgr_EntityOwner)& theEntity,
150 const Qt::MouseButtons theButtons,
151 const Qt::KeyboardModifiers theKeys )
153 if ( ( theButtons & Qt::LeftButton ) == 0 )
155 return Operation_None;
158 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast( theEntity );
159 if ( anOwner.IsNull() )
161 return Operation_None;
164 Standard_Real anAngTolerance = M_PI / 30.0; // 6 degree tolerance
166 switch ( anOwner->SelectionMode() )
170 if ( ( theKeys & Qt::ControlModifier ) == 0 )
172 return Operation_MoveFlyoutInPlane;
175 // "free moving" is only available for length and diameter
176 if ( !myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
177 && !myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
179 return Operation_None;
182 return Operation_MoveFlyoutFree;
185 case AIS_DSM_Text : return Operation_MoveText;
186 default : return Operation_None;
190 //=================================================================================
191 // function : StartOperation
193 //=================================================================================
194 bool MeasureGUI_DimensionInteractor::StartOperation( const Operation theOp,
195 const Handle(V3d_View)& theView,
199 Standard_Real anAngTolerance = M_PI / 30.0; // 6 degree tolerance
203 case Operation_MoveFlyoutInPlane :
204 case Operation_MoveText :
206 // operation can be started if the plane in which the flyout
207 // or text moved is not completely orthogonal to the screen
208 gp_Pln aPlane = myInteractedIO->GetPlane();
209 gp_Lin aProj = Projection( theView, theX, theY );
210 Standard_Real aCrossAng = aProj.Direction().Angle( aPlane.Axis().Direction() );
211 return Abs( M_PI * 0.5 - aCrossAng ) > anAngTolerance;
214 case Operation_MoveFlyoutFree :
216 // operation can be started only for linear dimensions
217 if ( !myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
218 && !myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
223 // determine whether the rotation operation is frontal or side
227 // get first and second point from which the flyout line is normally extended
228 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
229 if ( !aLength.IsNull() )
231 aFirstPoint = aLength->FirstPoint();
232 aSecondPoint = aLength->SecondPoint();
235 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
236 if ( !aDiameter.IsNull() )
238 const gp_Pnt& aCenter = aDiameter->Circle().Location();
239 aFirstPoint = aDiameter->AnchorPoint();
240 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
243 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
244 gp_Pln aPlane = myInteractedIO->GetPlane();
245 gp_Dir aPlaneN = aPlane.Axis().Direction();
246 gp_Lin aProj = Projection( theView, theX, theY );
248 const gp_Dir& aProjDir = aProj.Direction();
250 // can turn only if looking from side
251 if ( aProjDir.IsParallel( aPlaneN, anAngTolerance ) ||
252 aProjDir.IsNormal( aBaseDir, anAngTolerance ) )
257 bool isProjected = false;
258 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
264 gp_Vec aPointVector( aFirstPoint, aPointOnPlane );
265 gp_Pnt aPointOnBase = gp_Pnt( aFirstPoint.XYZ() + aBaseDir.XYZ() * aPointVector.Dot( aBaseDir ) );
266 myFreeMovePlane = gp_Pln( aPointOnBase, aBaseDir );
276 //=================================================================================
277 // function : MoveFlyoutFree
279 //=================================================================================
280 void MeasureGUI_DimensionInteractor::MoveFlyoutFree( const Handle(V3d_View)& theView,
284 // project point onto dimension plane
285 bool isProjected = false;
286 gp_Pln aPlane = myFreeMovePlane;
287 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
296 // get first and second point from which the flyout line is normally extended
297 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
298 if ( !aLength.IsNull() )
300 aFirstPoint = aLength->FirstPoint();
301 aSecondPoint = aLength->SecondPoint();
304 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
305 if ( !aDiameter.IsNull() )
307 const gp_Pnt& aCenter = aDiameter->Circle().Location();
308 aFirstPoint = aDiameter->AnchorPoint();
309 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
312 gp_Vec aPointVector( aFirstPoint, aPointOnPlane );
313 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
314 gp_Pnt aPointOnBase = gp_Pnt( aFirstPoint.XYZ() + aBaseDir.XYZ() * aPointVector.Dot( aBaseDir ) );
316 // snapping tolerance
317 Quantity_Length aSize[2];
318 theView->Size( aSize[0], aSize[1] );
319 Standard_Real aSnapTolerance = 1e-2 * Max( aSize[0], aSize[1] );
321 gp_Dir aFlyoutDir = gce_MakeDir( aPointOnBase, aPointOnPlane );
323 // snapping to planes
324 NCollection_Sequence<gp_Pln> aSnapPlanes;
326 if ( aPointOnPlane.Distance( aPointOnBase ) > aSnapTolerance )
328 if ( !aBaseDir.IsParallel( gp::DZ(), Precision::Angular() ) )
330 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DZ().Crossed( aBaseDir ) ) );
332 if ( !aBaseDir.IsParallel( gp::DX(), Precision::Angular() ) )
334 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DX().Crossed( aBaseDir ) ) );
336 if ( !aBaseDir.IsParallel( gp::DY(), Precision::Angular() ) )
338 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DY().Crossed( aBaseDir ) ) );
342 // snap "drag proj" to Flyout plane, relative XOY, YOZ, ZOX planes
343 NCollection_Sequence<gp_Pln>::Iterator aSnapIt( aSnapPlanes );
345 for ( ; aSnapIt.More(); aSnapIt.Next() )
347 const gp_Pln& aSnapPln = aSnapIt.Value();
349 // project direction into plane
350 gp_Vec aPlaneDir = gp_Vec( aSnapPln.Axis().Direction() );
351 gp_Vec aFlyoutProj = gp_Vec( aFlyoutDir ) - aPlaneDir * gp_Vec( aFlyoutDir ).Dot( aPlaneDir );
353 // snapping is not applicable
354 if ( aSnapPln.Contains( gp_Lin( aFirstPoint, aFlyoutDir ), Precision::Confusion(), Precision::Angular() ) )
358 if ( Abs( gp_Vec( aPointOnBase, aPointOnPlane ).Dot( aPlaneDir ) ) > aSnapTolerance )
362 if ( aFlyoutProj.Magnitude() <= Precision::Confusion() )
367 aFlyoutDir = gp_Dir( aFlyoutProj );
372 Standard_Real aNewFlyout = aPointOnPlane.Distance( aPointOnBase );
374 if ( aNewFlyout <= Precision::Confusion() )
376 myInteractedIO->SetFlyout( 0.0 );
377 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
381 gp_Pln aNewPlane = gp_Pln( aFirstPoint, aBaseDir.Crossed( aFlyoutDir ) );
383 myInteractedIO->SetFlyout( aNewFlyout );
384 myInteractedIO->SetCustomPlane( aNewPlane );
386 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
389 //=================================================================================
390 // function : MoveFlyoutInPlane
392 //=================================================================================
393 void MeasureGUI_DimensionInteractor::MoveFlyoutInPlane( const Handle(V3d_View)& theView,
397 // project point onto dimension plane
398 bool isProjected = false;
399 gp_Pln aPlane = myInteractedIO->GetPlane();
400 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
406 const gp_Dir& aPlaneN = aPlane.Axis().Direction();
409 Standard_Real aFlyout = 0.0;
411 // extend flyout of linear dimension
412 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
413 || myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
418 // get first and second point from which the flyout line is normally extended
419 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
420 if ( !aLength.IsNull() )
422 aFirstPoint = aLength->FirstPoint();
423 aSecondPoint = aLength->SecondPoint();
426 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
427 if ( !aDiameter.IsNull() )
429 const gp_Pnt& aCenter = aDiameter->Circle().Location();
430 aFirstPoint = aDiameter->AnchorPoint();
431 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
434 gp_Lin aBaseLine( aFirstPoint, gce_MakeDir( aFirstPoint, aSecondPoint ) );
436 // check if the negative value is expected
437 gp_Dir aPositiveDir = aPlaneN.Crossed( aBaseLine.Direction() );
438 gp_Dir aPointDir = gce_MakeDir( aBaseLine.Location(), aPointOnPlane );
439 Standard_Boolean isPositive = aPointDir.Dot( aPositiveDir ) > 0;
442 ? aBaseLine.Distance( aPointOnPlane )
443 : -aBaseLine.Distance( aPointOnPlane );
446 // exten flyout of angular dimension
447 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
449 Handle(AIS_AngleDimension) anAngle = Handle(AIS_AngleDimension)::DownCast( myInteractedIO );
451 const gp_Pnt& aCenterPoint = anAngle->CenterPoint();
452 const gp_Pnt& aFirstPoint = anAngle->FirstPoint();
453 const gp_Pnt& aSecondPoint = anAngle->SecondPoint();
455 gp_Dir aFirstDir = gce_MakeDir( aCenterPoint, aFirstPoint );
456 gp_Dir aSecondDir = gce_MakeDir( aCenterPoint, aSecondPoint );
458 Standard_Real aDirAngle = aFirstDir.Angle( aSecondDir );
462 // the direction are: \ | /
467 gp_Dir aCenterDir = aFirstDir.Rotated( gp_Ax1( aCenterPoint, aPlaneN ), -aDirAngle * 0.5 );
469 gp_Dir aPointDir = gce_MakeDir( aCenterPoint, aPointOnPlane );
471 Standard_Boolean isPositive = aPointDir.Dot( aCenterDir ) > 0;
473 Standard_Real aPointAngle = aPointDir.AngleWithRef( aCenterDir, aPlaneN );
476 aPointAngle = ( M_PI - Abs( aPointAngle ) ) * ( -Sign( 1.0, aPointAngle ) );
479 gp_Vec aPointVec = gp_Vec( aCenterPoint, aPointOnPlane );
481 // calculate flyout for each separate case of point location
482 if ( aPointAngle < -aDirAngle * 0.5 ) // outside of second dir
484 aFlyout = aPointVec.Dot( aFirstDir );
486 else if ( aPointAngle > aDirAngle * 0.5 ) // outside of first dir
488 aFlyout = aPointVec.Dot( aSecondDir );
490 else // between first and second direction
493 ? aPointVec.Magnitude()
494 : -aPointVec.Magnitude();
498 myInteractedIO->SetFlyout( aFlyout );
500 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
503 //=================================================================================
504 // function : MoveText
506 //=================================================================================
507 void MeasureGUI_DimensionInteractor::MoveText( const Handle(V3d_View)& theView,
511 // project point onto dimension plane
512 bool isProjected = false;
513 gp_Pln aPlane = myInteractedIO->GetPlane();
514 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
520 const gp_Dir& aPlaneN = aPlane.Axis().Direction();
522 Prs3d_DimensionTextHorizontalPosition aHPos = myInteractedIO->DimensionAspect()->TextHorizontalPosition();
523 Prs3d_DimensionTextVerticalPosition aVPos = myInteractedIO->DimensionAspect()->TextVerticalPosition();
524 Prs3d_DimensionArrowOrientation aArrPos = myInteractedIO->DimensionAspect()->ArrowOrientation();
526 Standard_Real aHeight = myInteractedIO->DimensionAspect()->TextAspect()->Height() * 0.5;
528 // move text of linear dimension
529 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
530 || myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
535 // get first and second point from which the flyout line is normally extended
536 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
537 if ( !aLength.IsNull() )
539 aFirstPoint = aLength->FirstPoint();
540 aSecondPoint = aLength->SecondPoint();
543 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
544 if ( !aDiameter.IsNull() )
546 const gp_Pnt& aCenter = aDiameter->Circle().Location();
547 aFirstPoint = aDiameter->AnchorPoint();
548 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
552 Standard_Real aFlyout = myInteractedIO->GetFlyout();
553 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
554 gp_Dir aFlyoutDir = aFlyout >= 0.0
555 ? aPlaneN.Crossed( gce_MakeDir( aFirstPoint, aSecondPoint ) )
556 : -aPlaneN.Crossed( gce_MakeDir( aFirstPoint, aSecondPoint ) );
557 gp_Vec aFlyoutTranslate = gp_Vec( aFlyoutDir ) * Abs( myInteractedIO->GetFlyout() );
558 gp_Lin aFlyoutLine = gp_Lin( aFirstPoint, aBaseDir ).Translated( aFlyoutTranslate );
560 // check if positive or negative offset along flyout line
561 gp_Vec aFlyout2Point = gp_Vec( aFlyoutLine.Location(), aPointOnPlane );
563 Standard_Real aPosY = aFlyout2Point.Dot( aFlyoutDir );
564 Standard_Real aPosX = aFlyout2Point.Dot( aFlyoutLine.Direction() );
568 aHPos = Prs3d_DTHP_Left;
569 aArrPos = Prs3d_DAO_External;
571 else if ( aPosX > aFirstPoint.Distance( aSecondPoint ) )
573 aHPos = Prs3d_DTHP_Right;
574 aArrPos = Prs3d_DAO_External;
578 aHPos = Prs3d_DTHP_Center;
579 aArrPos = Prs3d_DAO_Fit;
582 if ( aPosY > aHeight )
584 aVPos = Prs3d_DTVP_Above;
586 else if ( aPosY < -aHeight )
588 aVPos = Prs3d_DTVP_Below;
592 aVPos = Prs3d_DTVP_Center;
596 // move text of angular dimension
597 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
599 Handle(AIS_AngleDimension) anAngle = Handle(AIS_AngleDimension)::DownCast( myInteractedIO );
601 const gp_Pnt& aCenterPoint = anAngle->CenterPoint();
602 const gp_Pnt& aFirstPoint = anAngle->FirstPoint();
603 const gp_Pnt& aSecondPoint = anAngle->SecondPoint();
605 Standard_Boolean isPositive = anAngle->GetFlyout() > 0.0;
607 gp_Dir aFirstDir = gce_MakeDir( aCenterPoint, aFirstPoint );
608 gp_Dir aSecondDir = gce_MakeDir( aCenterPoint, aSecondPoint );
609 if ( anAngle->GetFlyout() < 0.0 )
612 aSecondDir.Reverse();
615 Standard_Real aDirAngle = aFirstDir.Angle( aSecondDir );
619 // the direction are: \ | /
623 gp_Dir aCenterDir = aFirstDir.Rotated( gp_Ax1( aCenterPoint, aPlaneN ), -aDirAngle * 0.5 );
625 gp_Dir aPointDir = gce_MakeDir( aCenterPoint, aPointOnPlane );
627 Standard_Real aPointAngle = aPointDir.AngleWithRef( aCenterDir, aPlaneN );
629 gp_Vec aPointVec = gp_Vec( aCenterPoint, aPointOnPlane );
631 Standard_Real aPosY = 0.0;
633 // calculate flyout for each separate case of point location
634 if ( aPointAngle < -aDirAngle * 0.5 ) // outside of second dir
636 aHPos = Prs3d_DTHP_Left;
637 aArrPos = Prs3d_DAO_External;
638 aPosY = aPointVec.Dot( aFirstDir ) - Abs( anAngle->GetFlyout() );
640 else if ( aPointAngle > aDirAngle * 0.5 ) // outside of first dir
642 aHPos = Prs3d_DTHP_Right;
643 aArrPos = Prs3d_DAO_External;
644 aPosY = aPointVec.Dot( aSecondDir ) - Abs( anAngle->GetFlyout() );
646 else // between first and second direction
648 aHPos = Prs3d_DTHP_Center;
649 aArrPos = Prs3d_DAO_Fit;
650 aPosY = aPointVec.Magnitude() - Abs( anAngle->GetFlyout() );
653 if ( aPosY > aHeight )
655 aVPos = Prs3d_DTVP_Above;
657 else if ( aPosY < -aHeight )
659 aVPos = Prs3d_DTVP_Below;
663 aVPos = Prs3d_DTVP_Center;
667 myInteractedIO->DimensionAspect()->SetTextVerticalPosition( aVPos );
668 myInteractedIO->DimensionAspect()->SetTextHorizontalPosition( aHPos );
669 myInteractedIO->DimensionAspect()->SetArrowOrientation( aArrPos );
670 myInteractedIO->SetToUpdate();
672 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
675 //=================================================================================
676 // function : eventFilter
678 //=================================================================================
679 bool MeasureGUI_DimensionInteractor::eventFilter( QObject* theObject, QEvent* theEvent )
681 OCCViewer_ViewPort3d* aViewPort = (OCCViewer_ViewPort3d*) theObject;
683 Handle(V3d_View) aView3d = aViewPort->getView();
685 switch ( theEvent->type() )
687 // check whether it is the "dimension modify" operation or not.
688 case QEvent::MouseButtonPress :
690 Handle(AIS_InteractiveContext) anAISContext = myViewer->getAISContext();
692 QMouseEvent* aMouseEv = dynamic_cast<QMouseEvent*>( theEvent );
695 anAISContext->MoveTo( aMouseEv->x(), aMouseEv->y(), aView3d, Standard_True );
696 if ( !anAISContext->HasDetected() )
701 // commented by mpa 18.03.2015: since OCCT version 6.8.0 it's impossible
702 // to change position of the dimensions presentations (flyout, text),
703 // because anAISContext has 2 detected objects.
705 // check that there is only one detected entity
706 //anAISContext->InitDetected();
707 //if ( anAISContext->MoreDetected() )
712 Handle(SelectMgr_EntityOwner) aDetectedOwner = anAISContext->DetectedOwner();
713 if( aDetectedOwner.IsNull() )
718 myInteractedIO = Handle(AIS_Dimension)::DownCast( aDetectedOwner->Selectable() );
720 // try to start operation for the detected entity
721 Operation aStartOp = GetOperation( aDetectedOwner, aMouseEv->buttons(), aMouseEv->modifiers() );
722 if ( aStartOp == Operation_None )
727 if ( !StartOperation( aStartOp, aView3d, aMouseEv->x(), aMouseEv->y() ) )
732 myOperation = aStartOp;
736 for ( anAISContext->InitSelected(); anAISContext->MoreSelected(); anAISContext->NextSelected() )
738 mySelection.Append( anAISContext->SelectedOwner() );
741 anAISContext->ClearSelected( Standard_False );
742 anAISContext->AddOrRemoveSelected( aDetectedOwner, Standard_True );
744 emit InteractionStarted( myInteractedIO );
749 // stop event processing on mouse release
750 case QEvent::MouseButtonRelease :
752 if ( myOperation != Operation_None )
754 Handle(AIS_InteractiveContext) anAISContext = myViewer->getAISContext();
756 anAISContext->ClearSelected( Standard_False );
757 SeqOfOwners::Iterator anIt( mySelection );
758 for( ; anIt.More(); anIt.Next() )
760 anAISContext->AddOrRemoveSelected( anIt.Value(), Standard_False );
763 anAISContext->UpdateCurrentViewer();
767 myOperation = Operation_None;
769 emit InteractionFinished( myInteractedIO );
778 case QEvent::MouseMove :
780 QMouseEvent* aMouseEv = (QMouseEvent*) theEvent;
781 switch( myOperation )
783 case Operation_MoveFlyoutFree : MoveFlyoutFree ( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
784 case Operation_MoveFlyoutInPlane : MoveFlyoutInPlane( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
785 case Operation_MoveText : MoveText ( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
786 default : return false;
790 default: return false;
794 //=================================================================================
795 // function : ConnectView
797 //=================================================================================
798 void MeasureGUI_DimensionInteractor::ConnectView( SUIT_ViewWindow* theView )
800 ( (OCCViewer_ViewWindow*) theView )->getViewPort()->installEventFilter( this );
803 //=================================================================================
804 // function : DisconnectView
806 //=================================================================================
807 void MeasureGUI_DimensionInteractor::DisconnectView( SUIT_ViewWindow* theView )
809 ( (OCCViewer_ViewWindow*) theView )->getViewPort()->removeEventFilter( this );
812 //=================================================================================
813 // function : Projection
815 //=================================================================================
816 gp_Lin MeasureGUI_DimensionInteractor::Projection( const Handle(V3d_View)& theView,
818 const int theMouseY )
820 Standard_Real P[3], D[3];
821 theView->ConvertWithProj( theMouseX, theMouseY, P[0], P[1], P[2], D[0], D[1], D[2] );
822 return gp_Lin( gp_Pnt( P[0], P[1], P[2] ), gp_Dir( D[0], D[1], D[2] ) );
825 //=================================================================================
826 // function : ProjectPlane
828 //=================================================================================
829 gp_Pnt MeasureGUI_DimensionInteractor::ProjectPlane( const Handle(V3d_View)& theView,
832 const gp_Pln& thePlane,
835 gp_Lin aProjection = Projection( theView, theMouseX, theMouseY );
837 Handle(Geom_Line) aCrossLine = new Geom_Line( aProjection );
838 Handle(Geom_Plane) aCrossPlane = new Geom_Plane( thePlane );
840 GeomAPI_IntCS aFindCross( aCrossLine, aCrossPlane );
841 if ( !aFindCross.IsDone() || aFindCross.NbPoints() == 0 )
848 return aFindCross.Point( 1 );
851 //=================================================================================
852 // function : SensitivityTolerance
854 //=================================================================================
855 Standard_Real MeasureGUI_DimensionInteractor::SensitivityTolerance( const Handle(V3d_View)& theView )
857 // snapping tolerance
858 Quantity_Length aSize[2];
859 theView->Size( aSize[0], aSize[1] );
860 return 1e-2 * Max( aSize[0], aSize[1] );
863 //=================================================================================
864 // function : OnViewCreated
866 //=================================================================================
867 void MeasureGUI_DimensionInteractor::OnViewCreated( SUIT_ViewWindow* theView )
869 ConnectView( theView );
872 //=================================================================================
873 // function : OnViewRemoved
875 //=================================================================================
876 void MeasureGUI_DimensionInteractor::OnViewRemoved( SUIT_ViewWindow* theView )
878 DisconnectView( theView );