1 // Copyright (C) 2007-2022 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 <Basics_OCCTVersion.hxx>
40 #include <QMouseEvent>
42 #include <AIS_InteractiveContext.hxx>
43 #include <AIS_LengthDimension.hxx>
44 #include <AIS_DiameterDimension.hxx>
45 #include <AIS_AngleDimension.hxx>
46 #include <Prs3d_DimensionAspect.hxx>
47 #include <Prs3d_TextAspect.hxx>
50 #include <gce_MakeDir.hxx>
53 #include <Extrema_ExtCC.hxx>
54 #include <Extrema_POnCurv.hxx>
55 #include <GeomAdaptor_Curve.hxx>
56 #include <GeomAPI_IntCS.hxx>
57 #include <Geom_Line.hxx>
58 #include <Geom_Plane.hxx>
59 #include <NCollection_Sequence.hxx>
61 //=================================================================================
62 // function : Constructor
64 //=================================================================================
65 MeasureGUI_DimensionInteractor::MeasureGUI_DimensionInteractor( GeometryGUI* theGUI,
67 : QObject( theParent ),
72 myOperation( Operation_None )
76 //=================================================================================
77 // function : Deactivate
79 //=================================================================================
80 MeasureGUI_DimensionInteractor::~MeasureGUI_DimensionInteractor()
85 //=================================================================================
88 //=================================================================================
89 void MeasureGUI_DimensionInteractor::Enable()
98 // install event filtering on viewer windows
99 SalomeApp_Application* anApp = myGeomGUI->getApp();
105 myVM = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
106 myViewer = (OCCViewer_Viewer*) myVM->getViewModel();
107 if ( !myVM || !myViewer )
112 connect( myVM, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), SLOT( OnViewCreated( SUIT_ViewWindow* ) ) );
113 connect( myVM, SIGNAL( deleteView ( SUIT_ViewWindow* ) ), SLOT( OnViewRemoved( SUIT_ViewWindow* ) ) );
115 QVector<SUIT_ViewWindow*> aViews = myVM->getViews();
116 QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
117 for ( ; aViewIt != aViews.end(); ++aViewIt )
119 ConnectView( *aViewIt );
123 //=================================================================================
124 // function : Disable
126 //=================================================================================
127 void MeasureGUI_DimensionInteractor::Disable()
137 // remove event filtering from viewer windows
138 QVector<SUIT_ViewWindow*> aViews = myVM->getViews();
139 QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
140 for ( ; aViewIt != aViews.end(); ++aViewIt )
142 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 #if OCC_VERSION_LARGE >= 0x070400ff
162 Handle(PrsDim_DimensionOwner) anOwner = Handle(PrsDim_DimensionOwner)::DownCast( theEntity );
164 Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast( theEntity );
166 if ( anOwner.IsNull() )
168 return Operation_None;
171 //Standard_Real anAngTolerance = M_PI / 30.0; // 6 degree tolerance
173 switch ( anOwner->SelectionMode() )
175 #if OCC_VERSION_LARGE >= 0x070400ff
176 case PrsDim_DimensionSelectionMode_Line :
181 if ( ( theKeys & Qt::ControlModifier ) == 0 )
183 return Operation_MoveFlyoutInPlane;
186 // "free moving" is only available for length and diameter
187 if ( !myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
188 && !myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
190 return Operation_None;
193 return Operation_MoveFlyoutFree;
196 #if OCC_VERSION_LARGE >= 0x070400ff
197 case PrsDim_DimensionSelectionMode_Text : return Operation_MoveText;
199 case AIS_DSM_Text : return Operation_MoveText;
201 default : return Operation_None;
205 //=================================================================================
206 // function : StartOperation
208 //=================================================================================
209 bool MeasureGUI_DimensionInteractor::StartOperation( const Operation theOp,
210 const Handle(V3d_View)& theView,
214 Standard_Real anAngTolerance = M_PI / 30.0; // 6 degree tolerance
218 case Operation_MoveFlyoutInPlane :
219 case Operation_MoveText :
221 // operation can be started if the plane in which the flyout
222 // or text moved is not completely orthogonal to the screen
223 gp_Pln aPlane = myInteractedIO->GetPlane();
224 gp_Lin aProj = Projection( theView, theX, theY );
225 Standard_Real aCrossAng = aProj.Direction().Angle( aPlane.Axis().Direction() );
226 return Abs( M_PI * 0.5 - aCrossAng ) > anAngTolerance;
229 case Operation_MoveFlyoutFree :
231 // operation can be started only for linear dimensions
232 if ( !myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
233 && !myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
238 // determine whether the rotation operation is frontal or side
242 // get first and second point from which the flyout line is normally extended
243 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
244 if ( !aLength.IsNull() )
246 aFirstPoint = aLength->FirstPoint();
247 aSecondPoint = aLength->SecondPoint();
250 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
251 if ( !aDiameter.IsNull() )
253 const gp_Pnt& aCenter = aDiameter->Circle().Location();
254 aFirstPoint = aDiameter->AnchorPoint();
255 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
258 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
259 gp_Pln aPlane = myInteractedIO->GetPlane();
260 gp_Dir aPlaneN = aPlane.Axis().Direction();
261 gp_Lin aProj = Projection( theView, theX, theY );
263 const gp_Dir& aProjDir = aProj.Direction();
265 // can turn only if looking from side
266 if ( aProjDir.IsParallel( aPlaneN, anAngTolerance ) ||
267 aProjDir.IsNormal( aBaseDir, anAngTolerance ) )
272 bool isProjected = false;
273 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
279 gp_Vec aPointVector( aFirstPoint, aPointOnPlane );
280 gp_Pnt aPointOnBase = gp_Pnt( aFirstPoint.XYZ() + aBaseDir.XYZ() * aPointVector.Dot( aBaseDir ) );
281 myFreeMovePlane = gp_Pln( aPointOnBase, aBaseDir );
291 //=================================================================================
292 // function : MoveFlyoutFree
294 //=================================================================================
295 void MeasureGUI_DimensionInteractor::MoveFlyoutFree( const Handle(V3d_View)& theView,
299 // project point onto dimension plane
300 bool isProjected = false;
301 gp_Pln aPlane = myFreeMovePlane;
302 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
311 // get first and second point from which the flyout line is normally extended
312 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
313 if ( !aLength.IsNull() )
315 aFirstPoint = aLength->FirstPoint();
316 aSecondPoint = aLength->SecondPoint();
319 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
320 if ( !aDiameter.IsNull() )
322 const gp_Pnt& aCenter = aDiameter->Circle().Location();
323 aFirstPoint = aDiameter->AnchorPoint();
324 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
327 gp_Vec aPointVector( aFirstPoint, aPointOnPlane );
328 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
329 gp_Pnt aPointOnBase = gp_Pnt( aFirstPoint.XYZ() + aBaseDir.XYZ() * aPointVector.Dot( aBaseDir ) );
331 // snapping tolerance
332 Standard_Real aSize[2];
333 theView->Size( aSize[0], aSize[1] );
334 Standard_Real aSnapTolerance = 1e-2 * Max( aSize[0], aSize[1] );
336 gp_Dir aFlyoutDir = gce_MakeDir( aPointOnBase, aPointOnPlane );
338 // snapping to planes
339 NCollection_Sequence<gp_Pln> aSnapPlanes;
341 if ( aPointOnPlane.Distance( aPointOnBase ) > aSnapTolerance )
343 if ( !aBaseDir.IsParallel( gp::DZ(), Precision::Angular() ) )
345 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DZ().Crossed( aBaseDir ) ) );
347 if ( !aBaseDir.IsParallel( gp::DX(), Precision::Angular() ) )
349 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DX().Crossed( aBaseDir ) ) );
351 if ( !aBaseDir.IsParallel( gp::DY(), Precision::Angular() ) )
353 aSnapPlanes.Append( gp_Pln( aFirstPoint, gp::DY().Crossed( aBaseDir ) ) );
357 // snap "drag proj" to Flyout plane, relative XOY, YOZ, ZOX planes
358 NCollection_Sequence<gp_Pln>::Iterator aSnapIt( aSnapPlanes );
360 for ( ; aSnapIt.More(); aSnapIt.Next() )
362 const gp_Pln& aSnapPln = aSnapIt.Value();
364 // project direction into plane
365 gp_Vec aPlaneDir = gp_Vec( aSnapPln.Axis().Direction() );
366 gp_Vec aFlyoutProj = gp_Vec( aFlyoutDir ) - aPlaneDir * gp_Vec( aFlyoutDir ).Dot( aPlaneDir );
368 // snapping is not applicable
369 if ( aSnapPln.Contains( gp_Lin( aFirstPoint, aFlyoutDir ), Precision::Confusion(), Precision::Angular() ) )
373 if ( Abs( gp_Vec( aPointOnBase, aPointOnPlane ).Dot( aPlaneDir ) ) > aSnapTolerance )
377 if ( aFlyoutProj.Magnitude() <= Precision::Confusion() )
382 aFlyoutDir = gp_Dir( aFlyoutProj );
387 Standard_Real aNewFlyout = aPointOnPlane.Distance( aPointOnBase );
389 if ( aNewFlyout <= Precision::Confusion() )
391 myInteractedIO->SetFlyout( 0.0 );
392 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
396 gp_Pln aNewPlane = gp_Pln( aFirstPoint, aBaseDir.Crossed( aFlyoutDir ) );
398 myInteractedIO->SetFlyout( aNewFlyout );
399 myInteractedIO->SetCustomPlane( aNewPlane );
401 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
404 //=================================================================================
405 // function : MoveFlyoutInPlane
407 //=================================================================================
408 void MeasureGUI_DimensionInteractor::MoveFlyoutInPlane( const Handle(V3d_View)& theView,
412 // project point onto dimension plane
413 bool isProjected = false;
414 gp_Pln aPlane = myInteractedIO->GetPlane();
415 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
421 const gp_Dir& aPlaneN = aPlane.Axis().Direction();
424 Standard_Real aFlyout = 0.0;
426 // extend flyout of linear dimension
427 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
428 || myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
433 // get first and second point from which the flyout line is normally extended
434 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
435 if ( !aLength.IsNull() )
437 aFirstPoint = aLength->FirstPoint();
438 aSecondPoint = aLength->SecondPoint();
441 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
442 if ( !aDiameter.IsNull() )
444 const gp_Pnt& aCenter = aDiameter->Circle().Location();
445 aFirstPoint = aDiameter->AnchorPoint();
446 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
449 gp_Lin aBaseLine( aFirstPoint, gce_MakeDir( aFirstPoint, aSecondPoint ) );
451 // check if the negative value is expected
452 gp_Dir aPositiveDir = aPlaneN.Crossed( aBaseLine.Direction() );
453 gp_Dir aPointDir = gce_MakeDir( aBaseLine.Location(), aPointOnPlane );
454 Standard_Boolean isPositive = aPointDir.Dot( aPositiveDir ) > 0;
457 ? aBaseLine.Distance( aPointOnPlane )
458 : -aBaseLine.Distance( aPointOnPlane );
461 // exten flyout of angular dimension
462 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
464 Handle(AIS_AngleDimension) anAngle = Handle(AIS_AngleDimension)::DownCast( myInteractedIO );
466 const gp_Pnt& aCenterPoint = anAngle->CenterPoint();
467 const gp_Pnt& aFirstPoint = anAngle->FirstPoint();
468 const gp_Pnt& aSecondPoint = anAngle->SecondPoint();
470 gp_Dir aFirstDir = gce_MakeDir( aCenterPoint, aFirstPoint );
471 gp_Dir aSecondDir = gce_MakeDir( aCenterPoint, aSecondPoint );
473 Standard_Real aDirAngle = aFirstDir.Angle( aSecondDir );
477 // the direction are: \ | /
482 gp_Dir aCenterDir = aFirstDir.Rotated( gp_Ax1( aCenterPoint, aPlaneN ), -aDirAngle * 0.5 );
484 gp_Dir aPointDir = gce_MakeDir( aCenterPoint, aPointOnPlane );
486 Standard_Boolean isPositive = aPointDir.Dot( aCenterDir ) > 0;
488 Standard_Real aPointAngle = aPointDir.AngleWithRef( aCenterDir, aPlaneN );
491 aPointAngle = ( M_PI - Abs( aPointAngle ) ) * ( -Sign( 1.0, aPointAngle ) );
494 gp_Vec aPointVec = gp_Vec( aCenterPoint, aPointOnPlane );
496 // calculate flyout for each separate case of point location
497 if ( aPointAngle < -aDirAngle * 0.5 ) // outside of second dir
499 aFlyout = aPointVec.Dot( aFirstDir );
501 else if ( aPointAngle > aDirAngle * 0.5 ) // outside of first dir
503 aFlyout = aPointVec.Dot( aSecondDir );
505 else // between first and second direction
508 ? aPointVec.Magnitude()
509 : -aPointVec.Magnitude();
513 myInteractedIO->SetFlyout( aFlyout );
515 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
518 //=================================================================================
519 // function : MoveText
521 //=================================================================================
522 void MeasureGUI_DimensionInteractor::MoveText( const Handle(V3d_View)& theView,
526 // project point onto dimension plane
527 bool isProjected = false;
528 gp_Pln aPlane = myInteractedIO->GetPlane();
529 gp_Pnt aPointOnPlane = ProjectPlane( theView, theX, theY, aPlane, isProjected );
535 const gp_Dir& aPlaneN = aPlane.Axis().Direction();
537 Prs3d_DimensionTextHorizontalPosition aHPos = myInteractedIO->DimensionAspect()->TextHorizontalPosition();
538 Prs3d_DimensionTextVerticalPosition aVPos = myInteractedIO->DimensionAspect()->TextVerticalPosition();
539 Prs3d_DimensionArrowOrientation aArrPos = myInteractedIO->DimensionAspect()->ArrowOrientation();
541 Standard_Real aHeight = myInteractedIO->DimensionAspect()->TextAspect()->Height() * 0.5;
543 // move text of linear dimension
544 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
545 || myInteractedIO->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) ) )
550 // get first and second point from which the flyout line is normally extended
551 Handle(AIS_LengthDimension) aLength = Handle(AIS_LengthDimension)::DownCast( myInteractedIO );
552 if ( !aLength.IsNull() )
554 aFirstPoint = aLength->FirstPoint();
555 aSecondPoint = aLength->SecondPoint();
558 Handle(AIS_DiameterDimension) aDiameter = Handle(AIS_DiameterDimension)::DownCast( myInteractedIO );
559 if ( !aDiameter.IsNull() )
561 const gp_Pnt& aCenter = aDiameter->Circle().Location();
562 aFirstPoint = aDiameter->AnchorPoint();
563 aSecondPoint = gp_Pnt( aFirstPoint.XYZ() + gp_Vec( aFirstPoint, aCenter ).XYZ() * 2.0 );
567 Standard_Real aFlyout = myInteractedIO->GetFlyout();
568 gp_Dir aBaseDir = gce_MakeDir( aFirstPoint, aSecondPoint );
569 gp_Dir aFlyoutDir = aFlyout >= 0.0
570 ? aPlaneN.Crossed( gce_MakeDir( aFirstPoint, aSecondPoint ) )
571 : -aPlaneN.Crossed( gce_MakeDir( aFirstPoint, aSecondPoint ) );
572 gp_Vec aFlyoutTranslate = gp_Vec( aFlyoutDir ) * Abs( myInteractedIO->GetFlyout() );
573 gp_Lin aFlyoutLine = gp_Lin( aFirstPoint, aBaseDir ).Translated( aFlyoutTranslate );
575 // check if positive or negative offset along flyout line
576 gp_Vec aFlyout2Point = gp_Vec( aFlyoutLine.Location(), aPointOnPlane );
578 Standard_Real aPosY = aFlyout2Point.Dot( aFlyoutDir );
579 Standard_Real aPosX = aFlyout2Point.Dot( aFlyoutLine.Direction() );
583 aHPos = Prs3d_DTHP_Left;
584 aArrPos = Prs3d_DAO_External;
586 else if ( aPosX > aFirstPoint.Distance( aSecondPoint ) )
588 aHPos = Prs3d_DTHP_Right;
589 aArrPos = Prs3d_DAO_External;
593 aHPos = Prs3d_DTHP_Center;
594 aArrPos = Prs3d_DAO_Fit;
597 if ( aPosY > aHeight )
599 aVPos = Prs3d_DTVP_Above;
601 else if ( aPosY < -aHeight )
603 aVPos = Prs3d_DTVP_Below;
607 aVPos = Prs3d_DTVP_Center;
611 // move text of angular dimension
612 if ( myInteractedIO->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
614 Handle(AIS_AngleDimension) anAngle = Handle(AIS_AngleDimension)::DownCast( myInteractedIO );
616 const gp_Pnt& aCenterPoint = anAngle->CenterPoint();
617 const gp_Pnt& aFirstPoint = anAngle->FirstPoint();
618 const gp_Pnt& aSecondPoint = anAngle->SecondPoint();
620 //Standard_Boolean isPositive = anAngle->GetFlyout() > 0.0;
622 gp_Dir aFirstDir = gce_MakeDir( aCenterPoint, aFirstPoint );
623 gp_Dir aSecondDir = gce_MakeDir( aCenterPoint, aSecondPoint );
624 if ( anAngle->GetFlyout() < 0.0 )
627 aSecondDir.Reverse();
630 Standard_Real aDirAngle = aFirstDir.Angle( aSecondDir );
634 // the direction are: \ | /
638 gp_Dir aCenterDir = aFirstDir.Rotated( gp_Ax1( aCenterPoint, aPlaneN ), -aDirAngle * 0.5 );
640 gp_Dir aPointDir = gce_MakeDir( aCenterPoint, aPointOnPlane );
642 Standard_Real aPointAngle = aPointDir.AngleWithRef( aCenterDir, aPlaneN );
644 gp_Vec aPointVec = gp_Vec( aCenterPoint, aPointOnPlane );
646 Standard_Real aPosY = 0.0;
648 // calculate flyout for each separate case of point location
649 if ( aPointAngle < -aDirAngle * 0.5 ) // outside of second dir
651 aHPos = Prs3d_DTHP_Left;
652 aArrPos = Prs3d_DAO_External;
653 aPosY = aPointVec.Dot( aFirstDir ) - Abs( anAngle->GetFlyout() );
655 else if ( aPointAngle > aDirAngle * 0.5 ) // outside of first dir
657 aHPos = Prs3d_DTHP_Right;
658 aArrPos = Prs3d_DAO_External;
659 aPosY = aPointVec.Dot( aSecondDir ) - Abs( anAngle->GetFlyout() );
661 else // between first and second direction
663 aHPos = Prs3d_DTHP_Center;
664 aArrPos = Prs3d_DAO_Fit;
665 aPosY = aPointVec.Magnitude() - Abs( anAngle->GetFlyout() );
668 if ( aPosY > aHeight )
670 aVPos = Prs3d_DTVP_Above;
672 else if ( aPosY < -aHeight )
674 aVPos = Prs3d_DTVP_Below;
678 aVPos = Prs3d_DTVP_Center;
682 myInteractedIO->DimensionAspect()->SetTextVerticalPosition( aVPos );
683 myInteractedIO->DimensionAspect()->SetTextHorizontalPosition( aHPos );
684 myInteractedIO->DimensionAspect()->SetArrowOrientation( aArrPos );
685 myInteractedIO->SetToUpdate();
687 myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
690 //=================================================================================
691 // function : eventFilter
693 //=================================================================================
694 bool MeasureGUI_DimensionInteractor::eventFilter( QObject* theObject, QEvent* theEvent )
696 OCCViewer_ViewPort3d* aViewPort = (OCCViewer_ViewPort3d*) theObject;
698 Handle(V3d_View) aView3d = aViewPort->getView();
700 switch ( theEvent->type() )
702 // check whether it is the "dimension modify" operation or not.
703 case QEvent::MouseButtonPress :
705 Handle(AIS_InteractiveContext) anAISContext = myViewer->getAISContext();
707 QMouseEvent* aMouseEv = dynamic_cast<QMouseEvent*>( theEvent );
710 anAISContext->MoveTo( aMouseEv->x(), aMouseEv->y(), aView3d, Standard_True );
711 if ( !anAISContext->HasDetected() )
716 // commented by mpa 18.03.2015: since OCCT version 6.8.0 it's impossible
717 // to change position of the dimensions presentations (flyout, text),
718 // because anAISContext has 2 detected objects.
720 // check that there is only one detected entity
721 //anAISContext->InitDetected();
722 //if ( anAISContext->MoreDetected() )
727 Handle(SelectMgr_EntityOwner) aDetectedOwner = anAISContext->DetectedOwner();
728 if( aDetectedOwner.IsNull() )
733 myInteractedIO = Handle(AIS_Dimension)::DownCast( aDetectedOwner->Selectable() );
735 // try to start operation for the detected entity
736 Operation aStartOp = GetOperation( aDetectedOwner, aMouseEv->buttons(), aMouseEv->modifiers() );
737 if ( aStartOp == Operation_None )
742 if ( !StartOperation( aStartOp, aView3d, aMouseEv->x(), aMouseEv->y() ) )
747 myOperation = aStartOp;
751 for ( anAISContext->InitSelected(); anAISContext->MoreSelected(); anAISContext->NextSelected() )
753 mySelection.Append( anAISContext->SelectedOwner() );
756 anAISContext->ClearSelected( Standard_False );
757 anAISContext->AddOrRemoveSelected( aDetectedOwner, Standard_True );
759 emit InteractionStarted( myInteractedIO );
764 // stop event processing on mouse release
765 case QEvent::MouseButtonRelease :
767 if ( myOperation != Operation_None )
769 Handle(AIS_InteractiveContext) anAISContext = myViewer->getAISContext();
771 anAISContext->ClearSelected( Standard_False );
772 SeqOfOwners::Iterator anIt( mySelection );
773 for( ; anIt.More(); anIt.Next() )
775 anAISContext->AddOrRemoveSelected( anIt.Value(), Standard_False );
778 anAISContext->UpdateCurrentViewer();
782 myOperation = Operation_None;
784 emit InteractionFinished( myInteractedIO );
793 case QEvent::MouseMove :
795 QMouseEvent* aMouseEv = (QMouseEvent*) theEvent;
796 switch( myOperation )
798 case Operation_MoveFlyoutFree : MoveFlyoutFree ( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
799 case Operation_MoveFlyoutInPlane : MoveFlyoutInPlane( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
800 case Operation_MoveText : MoveText ( aView3d, aMouseEv->x(), aMouseEv->y() ); return true;
801 default : return false;
805 default: return false;
809 //=================================================================================
810 // function : ConnectView
812 //=================================================================================
813 void MeasureGUI_DimensionInteractor::ConnectView( SUIT_ViewWindow* theView )
815 ( (OCCViewer_ViewWindow*) theView )->getViewPort()->installEventFilter( this );
818 //=================================================================================
819 // function : DisconnectView
821 //=================================================================================
822 void MeasureGUI_DimensionInteractor::DisconnectView( SUIT_ViewWindow* theView )
824 ( (OCCViewer_ViewWindow*) theView )->getViewPort()->removeEventFilter( this );
827 //=================================================================================
828 // function : Projection
830 //=================================================================================
831 gp_Lin MeasureGUI_DimensionInteractor::Projection( const Handle(V3d_View)& theView,
833 const int theMouseY )
835 Standard_Real P[3], D[3];
836 theView->ConvertWithProj( theMouseX, theMouseY, P[0], P[1], P[2], D[0], D[1], D[2] );
837 return gp_Lin( gp_Pnt( P[0], P[1], P[2] ), gp_Dir( D[0], D[1], D[2] ) );
840 //=================================================================================
841 // function : ProjectPlane
843 //=================================================================================
844 gp_Pnt MeasureGUI_DimensionInteractor::ProjectPlane( const Handle(V3d_View)& theView,
847 const gp_Pln& thePlane,
850 gp_Lin aProjection = Projection( theView, theMouseX, theMouseY );
852 Handle(Geom_Line) aCrossLine = new Geom_Line( aProjection );
853 Handle(Geom_Plane) aCrossPlane = new Geom_Plane( thePlane );
855 GeomAPI_IntCS aFindCross( aCrossLine, aCrossPlane );
856 if ( !aFindCross.IsDone() || aFindCross.NbPoints() == 0 )
863 return aFindCross.Point( 1 );
866 //=================================================================================
867 // function : SensitivityTolerance
869 //=================================================================================
870 Standard_Real MeasureGUI_DimensionInteractor::SensitivityTolerance( const Handle(V3d_View)& theView )
872 // snapping tolerance
873 Standard_Real aSize[2];
874 theView->Size( aSize[0], aSize[1] );
875 return 1e-2 * Max( aSize[0], aSize[1] );
878 //=================================================================================
879 // function : OnViewCreated
881 //=================================================================================
882 void MeasureGUI_DimensionInteractor::OnViewCreated( SUIT_ViewWindow* theView )
884 ConnectView( theView );
887 //=================================================================================
888 // function : OnViewRemoved
890 //=================================================================================
891 void MeasureGUI_DimensionInteractor::OnViewRemoved( SUIT_ViewWindow* theView )
893 DisconnectView( theView );