1 // Copyright (C) 2007-2019 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_CreateDimensionDlg.cxx
25 // Author : Anton POLETAEV, Open CASCADE S.A.S.
27 #include "MeasureGUI_CreateDimensionDlg.h"
28 #include "MeasureGUI_DimensionCreateTool.h"
30 #include <GEOM_Constants.h>
31 #include <GeometryGUI.h>
34 #include <GEOMUtils.hxx>
35 #include <GEOMGUI_DimensionProperty.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewWindow.h>
39 #include <OCCViewer_ViewPort3d.h>
40 #include <LightApp_SelectionMgr.h>
41 #include <SalomeApp_Application.h>
42 #include <SalomeApp_DataObject.h>
43 #include <SalomeApp_Study.h>
44 #include <SOCC_ViewModel.h>
46 #include <SUIT_ViewWindow.h>
47 #include <SUIT_ViewManager.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_Desktop.h>
53 #include <Aspect_PolygonOffsetMode.hxx>
55 #include <Basics_OCCTVersion.hxx>
57 //=================================================================================
58 // function : Constructor
60 //=================================================================================
61 MeasureGUI_CreateDimensionDlg::MeasureGUI_CreateDimensionDlg( const GEOM::GeomObjPtr& theObj,
64 : GEOMBase_Skeleton( theGUI, theParent ),
65 myParentObj( theObj ),
66 myEditingViewer( NULL )
68 setWindowTitle( tr( "CREATE_DIMENSION_TITLE" ) );
70 // init "dimension type" radio buttons
71 QAbstractButton* aTypeButtonLength = mainFrame()->RadioButton1;
72 QAbstractButton* aTypeButtonDiameter = mainFrame()->RadioButton2;
73 QAbstractButton* aTypeButtonAngle = mainFrame()->RadioButton3;
75 mainFrame()->GroupConstructors->setTitle( tr( "DIMENSIONS" ) );
76 aTypeButtonDiameter->setText( tr( "DIAMETER" ) );
77 aTypeButtonLength->setText( tr( "LENGTH" ) );
78 aTypeButtonAngle->setText( tr( "ANGLE" ) );
80 // construct "arguments" pane
81 QGroupBox* aGroupArgs = new QGroupBox( tr( "ARGUMENTS" ), centralWidget() );
82 QVBoxLayout* aGroupArgsLayout = new QVBoxLayout( aGroupArgs );
84 myLengthArgs = new LengthPane ( centralWidget() );
85 myDiameterArgs = new DiameterPane( centralWidget() );
86 myAngleArgs = new AnglePane ( centralWidget() );
88 // connect selector pane signals
89 connect( myLengthArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
90 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
91 connect( myDiameterArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
92 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
93 connect( myAngleArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
94 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
96 connect( myLengthArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
97 connect( myDiameterArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
98 connect( myAngleArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection( ) ) );
100 connect( myLengthArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
101 connect( myDiameterArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
102 connect( myAngleArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
104 aGroupArgsLayout->addWidget( myLengthArgs );
105 aGroupArgsLayout->addWidget( myDiameterArgs );
106 aGroupArgsLayout->addWidget( myAngleArgs );
108 // construct main layout
109 QVBoxLayout* aCustomWidLayout = new QVBoxLayout( centralWidget() );
110 aCustomWidLayout->setMargin( 0 );
111 aCustomWidLayout->setSpacing( 6 );
112 aCustomWidLayout->addWidget( aGroupArgs );
114 // add visibility rules for structural widgets
115 connect( aTypeButtonLength, SIGNAL( toggled(bool) ), myLengthArgs, SLOT( setVisible(bool) ) );
116 connect( aTypeButtonDiameter, SIGNAL( toggled(bool) ), myDiameterArgs, SLOT( setVisible(bool) ) );
117 connect( aTypeButtonAngle, SIGNAL( toggled(bool) ), myAngleArgs, SLOT( setVisible(bool) ) );
119 // signals and slots connections
120 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
121 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
123 // map functional signals
124 myRBGroup->setId( aTypeButtonLength, TypeButtonID_Length );
125 myRBGroup->setId( aTypeButtonDiameter, TypeButtonID_Diameter );
126 myRBGroup->setId( aTypeButtonAngle, TypeButtonID_Angle );
128 connect( this, SIGNAL( constructorsClicked( int ) ), SLOT( ConstructTypeChanged( int ) ) );
129 connect( myLengthArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
130 connect( myDiameterArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
131 connect( myAngleArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
133 myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent );
135 myDiameterArgs->setVisible( false );
136 myAngleArgs ->setVisible( false );
137 myLengthArgs ->setVisible( true );
139 myRBGroup->button( TypeButtonID_Length )->click();
143 setHelpFileName("add_dimension_page.html");
146 //=================================================================================
147 // function : Destructor
149 //=================================================================================
150 MeasureGUI_CreateDimensionDlg::~MeasureGUI_CreateDimensionDlg()
154 //=================================================================================
155 // function : ActiveArgs
157 //=================================================================================
158 MeasureGUI_CreateDimensionDlg::BaseSelectorPane* MeasureGUI_CreateDimensionDlg::ActiveArgs()
160 switch ( getConstructorId() )
162 case TypeButtonID_Length : return myLengthArgs;
163 case TypeButtonID_Diameter : return myDiameterArgs;
164 case TypeButtonID_Angle : return myAngleArgs;
170 //=================================================================================
171 // function : GenerateName
173 //=================================================================================
174 QString MeasureGUI_CreateDimensionDlg::GenerateName( const QString& thePrefix )
176 QRegExp anExtractIds( "^" + thePrefix + "_([0-9]+)$" );
178 QSet<int> anOccupiedIds;
180 GEOMGUI_DimensionProperty aProp =
181 getStudy()->getObjectProperty( GEOM::sharedPropertiesId(),
182 myParentObj->GetStudyEntry(),
183 GEOM::propertyName( GEOM::Dimensions ),
185 .value<GEOMGUI_DimensionProperty>();
187 // get names and convert to QStrings to perform index matching
188 for( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
190 if ( anExtractIds.indexIn( aProp.GetName( anIt ) ) == -1 )
195 anOccupiedIds.insert( anExtractIds.cap( 1 ).toInt() );
201 if ( !anOccupiedIds.contains( aSearchId ) )
209 return QString( thePrefix + "_%1" ).arg( aSearchId );
212 //=================================================================================
213 // function : ConstructTypeChanged
215 //=================================================================================
216 void MeasureGUI_CreateDimensionDlg::ConstructTypeChanged( int theType )
218 ActiveArgs()->Reset();
225 case TypeButtonID_Length : aName = GenerateName( tr("NAME_LENGTH") ); break;
226 case TypeButtonID_Diameter : aName = GenerateName( tr("NAME_DIAMETER") ); break;
227 case TypeButtonID_Angle : aName = GenerateName( tr("NAME_ANGLE") ); break;
230 myMainFrame->ResultName->setText( aName );
236 resize( minimumSizeHint() );
239 //=================================================================================
240 // function : OnArgumentTabChanged
242 //=================================================================================
243 void MeasureGUI_CreateDimensionDlg::OnArgumentTabChanged()
249 //=================================================================================
250 // function : OnStartSelection
252 //=================================================================================
253 void MeasureGUI_CreateDimensionDlg::OnStartSelection( const QList<TopAbs_ShapeEnum>& theModes )
259 QList<TopAbs_ShapeEnum>::const_iterator aModeIt = theModes.constBegin();
260 for ( ; aModeIt != theModes.constEnd(); ++aModeIt )
262 localSelection( myParentObj.get(), *aModeIt );
265 mySelectionModes = theModes;
267 connect( myGeomGUI->getApp()->selectionMgr(),
268 SIGNAL( currentSelectionChanged() ),
269 SLOT( SelectionIntoArgument() ) );
272 //=================================================================================
273 // function : OnStopSelection
275 //=================================================================================
276 void MeasureGUI_CreateDimensionDlg::OnStopSelection()
280 disconnect( myGeomGUI->getApp()->selectionMgr(),
281 SIGNAL( currentSelectionChanged() ),
283 SLOT( SelectionIntoArgument() ) );
286 //=================================================================================
287 // function : SelectionIntoArgument
288 // purpose : Handle model selection by active selector pane
289 //=================================================================================
290 void MeasureGUI_CreateDimensionDlg::SelectionIntoArgument()
292 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
293 SALOME_ListIO aSelection;
294 aSelectionMgr->selectedObjects( aSelection );
296 if ( aSelection.Extent() != 1 )
298 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
302 GEOM::GeomObjPtr aSelected = getSelected( mySelectionModes );
303 if ( aSelected.isNull() )
305 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
309 GEOM::GeomObjPtr aSelectedMain =
310 !aSelected->IsMainShape()
311 ? aSelected->GetMainShape()
312 : GEOM::GeomObjPtr();
314 if ( myParentObj != aSelected && myParentObj != aSelectedMain )
316 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
324 ActiveArgs()->SelectionIntoArguments( aSelected );
327 //=================================================================================
328 // function : OnSelectionDone
330 //=================================================================================
331 void MeasureGUI_CreateDimensionDlg::OnSelectionDone()
333 // create new dimension presentation
334 myDimension = CreateDimension();
336 if ( myDimension.IsNull() )
338 // can not create preview, repeat selection
339 SUIT_MessageBox::warning( this,
340 tr( "WARNING_TITLE_CANNOT_CREATE_DIMENSION" ),
341 tr( "WARNING_MSG_INVALID_ARGUMENTS" ) );
343 ActiveArgs()->Reset();
348 // show preview of dimension object
349 SUIT_ViewWindow* aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
351 SOCC_Prs* aSalomePrs = dynamic_cast<SOCC_Prs*>( ( (SOCC_Viewer*)( aViewWindow->getViewManager()->getViewModel() ) )->CreatePrs( 0 ) );
353 aSalomePrs->AddObject( myDimension );
355 displayPreview( aSalomePrs );
360 //=================================================================================
361 // function : ClickOnOk
363 //=================================================================================
364 void MeasureGUI_CreateDimensionDlg::ClickOnOk()
366 setIsApplyAndClose( true );
367 if ( ClickOnApply() )
373 //=================================================================================
374 // function : ClickOnApply
376 //=================================================================================
377 bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
381 if ( myDimension.IsNull() )
386 if ( !AddDimensionToOwner() )
391 redisplay( myParentObj.get() );
393 if ( !isApplyAndClose() )
397 ConstructTypeChanged( getConstructorId() );
403 //=================================================================================
404 // function : StartLocalEditing
406 //=================================================================================
407 void MeasureGUI_CreateDimensionDlg::StartLocalEditing()
411 myDimensionInteractor->Enable();
413 if ( myDimension.IsNull() )
418 SalomeApp_Application* anApp = myGeomGUI->getApp();
420 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
422 if ( aViewMgr->getType() != OCCViewer_Viewer::Type() )
427 SOCC_Viewer* anOCCViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
429 myEditingViewer = anOCCViewer;
430 if ( !myEditingViewer )
435 Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
436 Handle(V3d_Viewer) aViewer3d = myEditingViewer->getViewer3d();
438 aViewer3d->AddZLayer( myEditingLayer );
439 #if OCC_VERSION_LARGE <= 0x07030000
440 anAISContext->OpenLocalContext( Standard_False, Standard_False );
442 anAISContext->Load( myDimension, AIS_DSM_All );
443 anAISContext->SetZLayer( myDimension, myEditingLayer );
444 anAISContext->Activate( myDimension, AIS_DSM_Line );
445 anAISContext->Activate( myDimension, AIS_DSM_Text );
446 anAISContext->Redisplay( myDimension , Standard_True );
449 //=================================================================================
450 // function : StopLocalEditing
452 //=================================================================================
453 void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
455 myDimensionInteractor->Disable();
457 if ( !myEditingViewer )
462 Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
463 Handle(V3d_Viewer) aViewer3d = myEditingViewer->getViewer3d();
465 aViewer3d->RemoveZLayer( myEditingLayer );
466 #if OCC_VERSION_LARGE <= 0x07030000
467 anAISContext->CloseLocalContext( Standard_True );
469 anAISContext->Deactivate();
470 anAISContext->Activate(0);
473 myEditingViewer = NULL;
476 //=================================================================================
479 //=================================================================================
480 void MeasureGUI_CreateDimensionDlg::Init()
488 myDiameterArgs->Reset();
489 myLengthArgs->Reset();
490 myAngleArgs->Reset();
493 //=================================================================================
494 // function : CreateDimensionPrs
496 //=================================================================================
497 Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
499 Handle(AIS_Dimension) aDimensionIO;
501 // prepare dimension styling
502 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
504 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
505 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
506 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
507 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
508 double aDefFlyout = aResMgr->doubleValue ( "Geometry", "dimensions_default_flyout", 20 );
509 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
510 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
511 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
512 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
514 OCCViewer_ViewWindow* anActiveView = NULL;
516 SalomeApp_Application* anApp = myGeomGUI->getApp();
520 OCCViewer_ViewManager* aViewMgr = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
523 anActiveView = (OCCViewer_ViewWindow*) aViewMgr->getActiveView();
527 MeasureGUI_DimensionCreateTool aTool;
529 aTool.Settings.DefaultFlyout = aDefFlyout;
530 aTool.Settings.ActiveView = anActiveView ? anActiveView->getViewPort()->getView() : NULL;
532 switch ( getConstructorId() )
534 // create length dimension
535 case TypeButtonID_Length :
537 LengthPane* aLengthPane = qobject_cast<LengthPane*>( ActiveArgs() );
539 switch (aLengthPane->ActiveTab())
541 case LengthPane::TabID_SingleEdge:
543 const GEOM::GeomObjPtr& anEdge = aLengthPane->GetSingleEdge();
545 aDimensionIO = aTool.LengthOnEdge( anEdge );
549 case LengthPane::TabID_TwoPoints:
551 const GEOM::GeomObjPtr& aPoint1 = aLengthPane->GetPoint1();
552 const GEOM::GeomObjPtr& aPoint2 = aLengthPane->GetPoint2();
554 aDimensionIO = aTool.LengthByPoints( aPoint1, aPoint2 );
558 case LengthPane::TabID_ParallelEdges:
560 const GEOM::GeomObjPtr& anEdge1 = aLengthPane->GetEdge1();
561 const GEOM::GeomObjPtr& anEdge2 = aLengthPane->GetEdge2();
563 aDimensionIO = aTool.LengthByParallelEdges( anEdge1, anEdge2 );
570 // create diameter dimension
571 case TypeButtonID_Diameter :
573 DiameterPane* aDiameterPane = qobject_cast<DiameterPane*>( ActiveArgs() );
575 const GEOM::GeomObjPtr& aShape = aDiameterPane->GetShape();
577 aDimensionIO = aTool.Diameter( aShape );
581 // create angle dimension
582 case TypeButtonID_Angle :
584 AnglePane* anAnglePane = qobject_cast<AnglePane*>( ActiveArgs() );
586 switch (ActiveArgs()->ActiveTab())
588 case AnglePane::TabID_TwoEdges:
590 const GEOM::GeomObjPtr& anEdge1 = anAnglePane->GetEdge1();
591 const GEOM::GeomObjPtr& anEdge2 = anAnglePane->GetEdge2();
593 aDimensionIO = aTool.AngleByTwoEdges( anEdge1, anEdge2 );
597 case AnglePane::TabID_ThreePoints:
599 const GEOM::GeomObjPtr& aPoint1 = anAnglePane->GetPoint1();
600 const GEOM::GeomObjPtr& aPoint2 = anAnglePane->GetPoint2();
601 const GEOM::GeomObjPtr& aPoint3 = anAnglePane->GetPoint3();
603 aDimensionIO = aTool.AngleByThreePoints( aPoint1, aPoint2, aPoint3 );
611 if ( aDimensionIO.IsNull() )
616 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
618 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
620 aStyle->SetCommonColor( aColor );
621 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
622 aStyle->MakeText3d( aUseText3d );
623 aStyle->MakeTextShaded( Standard_True );
624 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
625 aStyle->SetExtensionSize( fsize * 0.5 );
626 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
627 aStyle->TextAspect()->SetHeight( fsize );
628 aStyle->ArrowAspect()->SetLength( anArrowLength );
629 aStyle->LineAspect()->SetWidth( aLineWidth );
631 if ( aDimensionIO->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
633 // show degree symbol for dimension instead of label "deg"
634 if ( aUnitsAngle == "deg" )
636 aDimensionIO->SetSpecialSymbol(0xB0);
637 aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
638 aStyle->MakeUnitsDisplayed(Standard_False);
642 aDimensionIO->SetDisplaySpecialSymbol(AIS_DSS_No);
643 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
648 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
651 aDimensionIO->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
652 aDimensionIO->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
653 aDimensionIO->SetDimensionAspect( aStyle );
654 aDimensionIO->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
659 //=================================================================================
660 // class : AddDimensionToOwner
662 //=================================================================================
663 bool MeasureGUI_CreateDimensionDlg::AddDimensionToOwner()
665 if ( myDimension.IsNull() )
671 TopoDS_Shape anParentSh;
672 if ( GEOMBase::GetShape( myParentObj.get(), anParentSh ) )
674 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
677 QString aName = getNewObjectName();
679 SalomeApp_Study* aStudy = getStudy();
681 GEOMGUI_DimensionProperty aProp =
682 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
683 myParentObj->GetStudyEntry(),
684 GEOM::propertyName( GEOM::Dimensions ),
686 .value<GEOMGUI_DimensionProperty>();
688 // append new dimension record to data
689 aProp.AddRecord( myDimension, aLCS );
690 aProp.SetName( aProp.GetNumber() - 1, aName );
691 aProp.SetVisible( aProp.GetNumber() - 1, true );
693 // store modified property data
694 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
695 myParentObj->GetStudyEntry(),
696 GEOM::propertyName( GEOM::Dimensions ),
702 /* ------------------------------------------------------------------------------*
704 * Argument shape selector layout *
706 * ------------------------------------------------------------------------------*/
708 //=================================================================================
709 // class : MeasureGUI_CreateDimensionDlg::LengthPane
710 // purpose : Constructor
711 //=================================================================================
712 MeasureGUI_CreateDimensionDlg::LengthPane::LengthPane( QWidget* theParent )
713 : BaseSelectorPane( theParent )
715 myTabs = new QTabWidget( this );
716 mySingleEdgeSelectors = new MeasureGUI_1Sel_Frame( this );
717 myTwoPointsSelectors = new MeasureGUI_2Sel_Frame( this );
718 myParallelEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
720 myTabs->addTab( mySingleEdgeSelectors, MeasureGUI_CreateDimensionDlg::tr( "EDGE_LENGTH" ) );
721 myTabs->addTab( myTwoPointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "TWO_POINTS" ) );
722 myTabs->addTab( myParallelEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "PARALLEL_EDGES" ) );
724 mySingleEdgeSelectors->PushButton1->setIcon( mySelectorIcon );
725 mySingleEdgeSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE" ) );
726 mySingleEdgeSelectors->LineEdit1->setReadOnly( true );
728 myTwoPointsSelectors->PushButton1->setIcon( mySelectorIcon );
729 myTwoPointsSelectors->PushButton2->setIcon( mySelectorIcon );
730 myTwoPointsSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
731 myTwoPointsSelectors->TextLabel2->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
732 myTwoPointsSelectors->LineEdit1->setReadOnly( true );
733 myTwoPointsSelectors->LineEdit2->setReadOnly( true );
735 myParallelEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
736 myParallelEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
737 myParallelEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
738 myParallelEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
739 myParallelEdgesSelectors->LineEdit1->setReadOnly( true );
740 myParallelEdgesSelectors->LineEdit2->setReadOnly( true );
742 QVBoxLayout* aLayout = new QVBoxLayout( this );
744 aLayout->setMargin( 0 );
745 aLayout->addWidget( myTabs );
747 SelectionModes anEdgeModes;
748 SelectionModes aPointModes;
749 anEdgeModes << TopAbs_EDGE;
750 aPointModes << TopAbs_VERTEX;
752 SetTabWidget( myTabs );
753 RegisterSelector( mySingleEdgeSelectors->LineEdit1, mySingleEdgeSelectors->PushButton1, anEdgeModes, TabID_SingleEdge );
754 RegisterSelector( myTwoPointsSelectors->LineEdit1, myTwoPointsSelectors->PushButton1, aPointModes, TabID_TwoPoints );
755 RegisterSelector( myTwoPointsSelectors->LineEdit2, myTwoPointsSelectors->PushButton2, aPointModes, TabID_TwoPoints );
756 RegisterSelector( myParallelEdgesSelectors->LineEdit1, myParallelEdgesSelectors->PushButton1, anEdgeModes, TabID_ParallelEdges );
757 RegisterSelector( myParallelEdgesSelectors->LineEdit2, myParallelEdgesSelectors->PushButton2, anEdgeModes, TabID_ParallelEdges );
760 //=================================================================================
761 // class : MeasureGUI_CreateDimensionDlg::DiameterPane
762 // purpose : Constructor
763 //=================================================================================
764 MeasureGUI_CreateDimensionDlg::DiameterPane::DiameterPane( QWidget* theParent )
765 : BaseSelectorPane( theParent )
767 myShapeSelector = new MeasureGUI_1Sel_Frame( this );
768 myShapeSelector->PushButton1->setIcon( mySelectorIcon );
769 myShapeSelector->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "OBJECT" ) );
771 QVBoxLayout* aLayout = new QVBoxLayout( this );
773 aLayout->setMargin( 0 );
774 aLayout->addWidget( myShapeSelector );
776 SelectionModes aDiamModes;
777 aDiamModes << TopAbs_SHAPE
781 RegisterSelector( myShapeSelector->LineEdit1, myShapeSelector->PushButton1, aDiamModes );
784 //=================================================================================
785 // class : MeasureGUI_CreateDimensionDlg::AnglePane
786 // purpose : Constructor
787 //=================================================================================
788 MeasureGUI_CreateDimensionDlg::AnglePane::AnglePane( QWidget* theParent )
789 : BaseSelectorPane( theParent )
791 myTabs = new QTabWidget( this );
792 myTwoEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
793 myThreePointsSelectors = new MeasureGUI_3Sel_Frame( this );
795 myTabs->addTab( myTwoEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "TWO_EDGES" ) );
796 myTabs->addTab( myThreePointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "THREE_POINTS" ) );
798 myTwoEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
799 myTwoEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
800 myTwoEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
801 myTwoEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
803 myThreePointsSelectors->PushButton1->setIcon( mySelectorIcon );
804 myThreePointsSelectors->PushButton2->setIcon( mySelectorIcon );
805 myThreePointsSelectors->PushButton3->setIcon( mySelectorIcon );
806 myThreePointsSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
807 myThreePointsSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
808 myThreePointsSelectors->TextLabel3 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_3" ) );
810 QVBoxLayout* aLayout = new QVBoxLayout( this );
812 aLayout->setMargin( 0 );
813 aLayout->addWidget( myTabs );
815 SelectionModes anEdgeModes;
816 SelectionModes aPointModes;
817 anEdgeModes << TopAbs_EDGE;
818 aPointModes << TopAbs_VERTEX;
820 SetTabWidget( myTabs );
821 RegisterSelector( myTwoEdgesSelectors->LineEdit1, myTwoEdgesSelectors->PushButton1, anEdgeModes, TabID_TwoEdges );
822 RegisterSelector( myTwoEdgesSelectors->LineEdit2, myTwoEdgesSelectors->PushButton2, anEdgeModes, TabID_TwoEdges );
823 RegisterSelector( myThreePointsSelectors->LineEdit1, myThreePointsSelectors->PushButton1, aPointModes, TabID_ThreePoints );
824 RegisterSelector( myThreePointsSelectors->LineEdit2, myThreePointsSelectors->PushButton2, aPointModes, TabID_ThreePoints );
825 RegisterSelector( myThreePointsSelectors->LineEdit3, myThreePointsSelectors->PushButton3, aPointModes, TabID_ThreePoints );
828 /* ------------------------------------------------------------------------------*
830 * Argument shape selection logics *
832 * ------------------------------------------------------------------------------*/
834 //=================================================================================
835 // class : MeasureGUI_CreateDimensionDlg::BaseSelectorPane
836 // purpose : Constructor
837 //=================================================================================
838 MeasureGUI_CreateDimensionDlg::BaseSelectorPane::BaseSelectorPane( QWidget* theParent )
839 : QWidget( theParent ),
842 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
843 mySelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
846 //=================================================================================
847 // function : BaseSelectorPane::Reset
848 // purpose : Reset selector line edits and controls
849 //=================================================================================
850 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::Reset( bool theOpenDefaultTab )
852 if ( theOpenDefaultTab && myTabs )
854 myTabs->setCurrentIndex( 0 );
857 QMap< int, QList<QLineEdit*> >::iterator aTabsIt = mySelectors.begin();
858 for ( ; aTabsIt != mySelectors.end(); ++aTabsIt )
860 QList<QLineEdit*>& aSelectors = *aTabsIt;
861 QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
862 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
864 QLineEdit* aSelector = *aSelectorIt;
866 mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
870 QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
872 mySelectionButtons[aFirstSelector]->click();
875 //=================================================================================
876 // function : BaseSelectorPane::ActiveTab
877 // purpose : Returns active tab
878 //=================================================================================
879 int MeasureGUI_CreateDimensionDlg::BaseSelectorPane::ActiveTab() const
881 return myTabs != NULL ? myTabs->currentIndex() : 0;
884 //=================================================================================
885 // function : BaseSelectorPane::SelectionIntoArgument
886 // purpose : Populates current selector
887 //=================================================================================
888 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SelectionIntoArguments( const GEOM::GeomObjPtr& theSelected )
890 if ( theSelected.isNull() )
892 myCurrentSelector->clear();
893 mySelectedShapes[myCurrentSelector] = GEOM::GeomObjPtr();
897 QString aName = GEOMBase::GetName( theSelected.get() );
899 myCurrentSelector->setText( aName );
901 mySelectedShapes[myCurrentSelector] = theSelected;
903 // find next empty selector (iterate to the last)
904 QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
905 int aCurrentPos = aCurrentSelectors.indexOf( myCurrentSelector );
906 int aSelectorIt = aCurrentPos + 1;
907 for ( ; aSelectorIt != aCurrentSelectors.size(); ++aSelectorIt )
909 QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
910 if ( mySelectedShapes[aNextSelector].isNull() )
912 mySelectionButtons[aNextSelector]->click();
917 // find next empty selector (itearte from the first)
919 for ( ; aSelectorIt != aCurrentPos; ++aSelectorIt )
921 QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
922 if ( mySelectedShapes[aNextSelector].isNull() )
924 mySelectionButtons[aNextSelector]->click();
929 // stop selector switching
930 myCurrentSelector->setEnabled( false );
931 mySelectionButtons[myCurrentSelector]->setDown( false );
933 // every selector is populated - construct presentation
934 emit StopSelection();
935 emit SelectionDone();
938 //=================================================================================
939 // function : BaseSelectorPane::GetSelection
941 //=================================================================================
942 GEOM::GeomObjPtr MeasureGUI_CreateDimensionDlg::BaseSelectorPane::GetSelection( QLineEdit* theSelector ) const
944 return mySelectedShapes[theSelector];
947 //=================================================================================
948 // function : BaseSelectorPane::OnSelectorClicked
949 // purpose : Handle activation of selector controls pair {edit, button}
950 //=================================================================================
951 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnSelectorClicked()
953 // clicked "selector" button
954 QAbstractButton* aSender = qobject_cast<QAbstractButton*>( sender() );
960 // get "selector" controls on the active tab
961 QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
963 // iterate over controls on the tab and process them
964 for ( int aSelectorIt = 0; aSelectorIt < aCurrentSelectors.size(); ++aSelectorIt )
966 QLineEdit* aSelector = aCurrentSelectors[aSelectorIt];
967 QPushButton* aButton = mySelectionButtons[aSelector];
969 bool isClickedOnes = (aButton == aSender);
971 aSelector->setEnabled( isClickedOnes );
975 myCurrentSelector = aSelector;
976 myCurrentSelector->setFocus();
979 aButton->setDown( isClickedOnes );
982 emit StartSelection( mySelectionModes[myCurrentSelector] );
985 //=================================================================================
986 // function : BaseSelectorPane::OnTabChanged
988 //=================================================================================
989 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnTabChanged()
991 QList<QLineEdit*>& aSelectors = mySelectors[ ActiveTab() ];
992 QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
993 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
995 QLineEdit* aSelector = *aSelectorIt;
999 mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
1002 QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
1004 mySelectionButtons[aFirstSelector]->click();
1009 //=================================================================================
1010 // function : BaseSelectorPane::SetTabWidget
1012 //=================================================================================
1013 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SetTabWidget( QTabWidget* theTabs )
1016 connect( myTabs, SIGNAL( currentChanged( int ) ), this, SLOT( OnTabChanged() ) );
1019 //=================================================================================
1020 // function : BaseSelectorPane::RegisterSelector
1022 //=================================================================================
1023 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::RegisterSelector( QLineEdit* theSelectorEdit,
1024 QPushButton* theSelectorButton,
1025 const SelectionModes& theSelectorModes,
1028 if ( !mySelectors.contains( theTab ) )
1030 mySelectors.insert( theTab, QList<QLineEdit*>() );
1032 mySelectors[theTab].append( theSelectorEdit );
1034 mySelectionButtons[theSelectorEdit] = theSelectorButton;
1035 mySelectionModes [theSelectorEdit] = theSelectorModes;
1037 connect( theSelectorButton, SIGNAL( clicked() ), this, SLOT( OnSelectorClicked() ) );