1 // Copyright (C) 2007-2013 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.
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 //=================================================================================
56 // function : Constructor
58 //=================================================================================
59 MeasureGUI_CreateDimensionDlg::MeasureGUI_CreateDimensionDlg( const GEOM::GeomObjPtr& theObj,
62 : GEOMBase_Skeleton( theGUI, theParent ),
63 myParentObj( theObj ),
64 myEditingViewer( NULL )
66 setWindowTitle( tr( "CREATE_DIMENSION_TITLE" ) );
68 // init "dimension type" radio buttons
69 QAbstractButton* aTypeButtonLength = mainFrame()->RadioButton1;
70 QAbstractButton* aTypeButtonDiameter = mainFrame()->RadioButton2;
71 QAbstractButton* aTypeButtonAngle = mainFrame()->RadioButton3;
73 mainFrame()->GroupConstructors->setTitle( tr( "DIMENSIONS" ) );
74 aTypeButtonDiameter->setText( tr( "DIAMETER" ) );
75 aTypeButtonLength->setText( tr( "LENGTH" ) );
76 aTypeButtonAngle->setText( tr( "ANGLE" ) );
78 // construct "arguments" pane
79 QGroupBox* aGroupArgs = new QGroupBox( tr( "ARGUMENTS" ), centralWidget() );
80 QVBoxLayout* aGroupArgsLayout = new QVBoxLayout( aGroupArgs );
82 myLengthArgs = new LengthPane ( centralWidget() );
83 myDiameterArgs = new DiameterPane( centralWidget() );
84 myAngleArgs = new AnglePane ( centralWidget() );
86 // connect selector pane signals
87 connect( myLengthArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
88 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
89 connect( myDiameterArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
90 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
91 connect( myAngleArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
92 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
94 connect( myLengthArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
95 connect( myDiameterArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
96 connect( myAngleArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection( ) ) );
98 connect( myLengthArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
99 connect( myDiameterArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
100 connect( myAngleArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
102 aGroupArgsLayout->addWidget( myLengthArgs );
103 aGroupArgsLayout->addWidget( myDiameterArgs );
104 aGroupArgsLayout->addWidget( myAngleArgs );
106 // construct main layout
107 QVBoxLayout* aCustomWidLayout = new QVBoxLayout( centralWidget() );
108 aCustomWidLayout->setMargin( 0 );
109 aCustomWidLayout->setSpacing( 6 );
110 aCustomWidLayout->addWidget( aGroupArgs );
112 // add visibility rules for structural widgets
113 connect( aTypeButtonLength, SIGNAL( toggled(bool) ), myLengthArgs, SLOT( setVisible(bool) ) );
114 connect( aTypeButtonDiameter, SIGNAL( toggled(bool) ), myDiameterArgs, SLOT( setVisible(bool) ) );
115 connect( aTypeButtonAngle, SIGNAL( toggled(bool) ), myAngleArgs, SLOT( setVisible(bool) ) );
117 // signals and slots connections
118 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
119 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
121 // map functional signals
122 myRBGroup->setId( aTypeButtonLength, TypeButtonID_Length );
123 myRBGroup->setId( aTypeButtonDiameter, TypeButtonID_Diameter );
124 myRBGroup->setId( aTypeButtonAngle, TypeButtonID_Angle );
126 connect( this, SIGNAL( constructorsClicked( int ) ), SLOT( ConstructTypeChanged( int ) ) );
127 connect( myLengthArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
128 connect( myDiameterArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
129 connect( myAngleArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
131 myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent );
133 myDiameterArgs->setVisible( false );
134 myAngleArgs ->setVisible( false );
135 myLengthArgs ->setVisible( true );
139 setHelpFileName("add_dimension_page.html");
142 //=================================================================================
143 // function : Destructor
145 //=================================================================================
146 MeasureGUI_CreateDimensionDlg::~MeasureGUI_CreateDimensionDlg()
150 //=================================================================================
151 // function : ActiveArgs
153 //=================================================================================
154 MeasureGUI_CreateDimensionDlg::BaseSelectorPane* MeasureGUI_CreateDimensionDlg::ActiveArgs()
156 switch ( getConstructorId() )
158 case TypeButtonID_Length : return myLengthArgs;
159 case TypeButtonID_Diameter : return myDiameterArgs;
160 case TypeButtonID_Angle : return myAngleArgs;
166 //=================================================================================
167 // function : GenerateName
169 //=================================================================================
170 QString MeasureGUI_CreateDimensionDlg::GenerateName( const QString& thePrefix )
172 QRegExp anExtractIds( "^" + thePrefix + "_([0-9]+)$" );
174 QSet<int> anOccupiedIds;
176 GEOMGUI_DimensionProperty aProp =
177 getStudy()->getObjectProperty( GEOM::sharedPropertiesId(),
178 myParentObj->GetStudyEntry(),
179 GEOM::propertyName( GEOM::Dimensions ),
181 .value<GEOMGUI_DimensionProperty>();
183 // get names and convert to QStrings to perform index matching
184 for( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
186 if ( anExtractIds.indexIn( aProp.GetName( anIt ) ) == -1 )
191 anOccupiedIds.insert( anExtractIds.cap( 1 ).toInt() );
197 if ( !anOccupiedIds.contains( aSearchId ) )
205 return QString( thePrefix + "_%1" ).arg( aSearchId );
208 //=================================================================================
209 // function : ConstructTypeChanged
211 //=================================================================================
212 void MeasureGUI_CreateDimensionDlg::ConstructTypeChanged( int theType )
214 ActiveArgs()->Reset();
221 case TypeButtonID_Length : aName = GenerateName( tr("NAME_LENGTH") ); break;
222 case TypeButtonID_Diameter : aName = GenerateName( tr("NAME_DIAMETER") ); break;
223 case TypeButtonID_Angle : aName = GenerateName( tr("NAME_ANGLE") ); break;
226 myMainFrame->ResultName->setText( aName );
232 resize( minimumSizeHint() );
235 //=================================================================================
236 // function : OnArgumentTabChanged
238 //=================================================================================
239 void MeasureGUI_CreateDimensionDlg::OnArgumentTabChanged()
245 //=================================================================================
246 // function : OnStartSelection
248 //=================================================================================
249 void MeasureGUI_CreateDimensionDlg::OnStartSelection( const QList<TopAbs_ShapeEnum>& theModes )
255 QList<TopAbs_ShapeEnum>::const_iterator aModeIt = theModes.constBegin();
256 for ( ; aModeIt != theModes.constEnd(); ++aModeIt )
258 localSelection( myParentObj.get(), *aModeIt );
261 mySelectionModes = theModes;
263 connect( myGeomGUI->getApp()->selectionMgr(),
264 SIGNAL( currentSelectionChanged() ),
265 SLOT( SelectionIntoArgument() ) );
268 //=================================================================================
269 // function : OnStopSelection
271 //=================================================================================
272 void MeasureGUI_CreateDimensionDlg::OnStopSelection()
276 disconnect( myGeomGUI->getApp()->selectionMgr(),
277 SIGNAL( currentSelectionChanged() ),
279 SLOT( SelectionIntoArgument() ) );
282 //=================================================================================
283 // function : SelectionIntoArgument
284 // purpose : Handle model selection by active selector pane
285 //=================================================================================
286 void MeasureGUI_CreateDimensionDlg::SelectionIntoArgument()
288 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
289 SALOME_ListIO aSelection;
290 aSelectionMgr->selectedObjects( aSelection );
292 if ( aSelection.Extent() != 1 )
294 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
302 ActiveArgs()->SelectionIntoArguments( getSelected( mySelectionModes ) );
305 //=================================================================================
306 // function : OnSelectionDone
308 //=================================================================================
309 void MeasureGUI_CreateDimensionDlg::OnSelectionDone()
311 // create new dimension presentation
312 myDimension = CreateDimension();
314 if ( myDimension.IsNull() )
316 // can not create preview, repeat selection
317 SUIT_MessageBox::warning( this,
318 tr( "WARNING_TITLE_CANNOT_CREATE_DIMENSION" ),
319 tr( "WARNING_MSG_INVALID_ARGUMENTS" ) );
321 ActiveArgs()->Reset();
326 // show preview of dimension object
327 SUIT_ViewWindow* aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
329 SOCC_Prs* aSalomePrs = dynamic_cast<SOCC_Prs*>( ( (SOCC_Viewer*)( aViewWindow->getViewManager()->getViewModel() ) )->CreatePrs( 0 ) );
331 aSalomePrs->AddObject( myDimension );
333 displayPreview( aSalomePrs );
338 //=================================================================================
339 // function : ClickOnOk
341 //=================================================================================
342 void MeasureGUI_CreateDimensionDlg::ClickOnOk()
344 setIsApplyAndClose( true );
345 if ( ClickOnApply() )
351 //=================================================================================
352 // function : ClickOnApply
354 //=================================================================================
355 bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
359 if ( !AddDimensionToOwner() )
364 redisplay( myParentObj.get() );
366 if ( !isApplyAndClose() )
374 //=================================================================================
375 // function : StartLocalEditing
377 //=================================================================================
378 void MeasureGUI_CreateDimensionDlg::StartLocalEditing()
382 myDimensionInteractor->Enable();
384 if ( myDimension.IsNull() )
389 SalomeApp_Application* anApp = myGeomGUI->getApp();
391 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
393 if ( aViewMgr->getType() != OCCViewer_Viewer::Type() )
398 SOCC_Viewer* anOCCViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
400 myEditingViewer = anOCCViewer;
401 if ( !myEditingViewer )
406 Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
407 Handle(V3d_Viewer) aViewer3d = myEditingViewer->getViewer3d();
409 aViewer3d->AddZLayer( myEditingLayer );
411 anAISContext->OpenLocalContext( Standard_False, Standard_False );
412 anAISContext->Load( myDimension, AIS_DSM_All );
413 anAISContext->SetZLayer( myDimension, myEditingLayer );
414 anAISContext->Activate( myDimension, AIS_DSM_Line );
415 anAISContext->Activate( myDimension, AIS_DSM_Text );
416 anAISContext->Redisplay( myDimension );
419 //=================================================================================
420 // function : StopLocalEditing
422 //=================================================================================
423 void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
425 myDimensionInteractor->Disable();
427 if ( !myEditingViewer )
432 Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
433 Handle(V3d_Viewer) aViewer3d = myEditingViewer->getViewer3d();
435 aViewer3d->RemoveZLayer( myEditingLayer );
436 anAISContext->CloseLocalContext();
438 myEditingViewer = NULL;
441 //=================================================================================
444 //=================================================================================
445 void MeasureGUI_CreateDimensionDlg::Init()
453 myDiameterArgs->Reset();
454 myLengthArgs->Reset();
455 myAngleArgs->Reset();
457 myRBGroup->button( TypeButtonID_Length )->click();
460 //=================================================================================
461 // function : CreateDimensionPrs
463 //=================================================================================
464 Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
466 Handle(AIS_Dimension) aDimensionIO;
468 // prepare dimension styling
469 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
471 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
472 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
473 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
474 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
475 double aDefFlyout = aResMgr->doubleValue ( "Geometry", "dimensions_default_flyout", 20 );
476 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
477 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
478 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
480 OCCViewer_ViewWindow* anActiveView = NULL;
482 SalomeApp_Application* anApp = myGeomGUI->getApp();
486 OCCViewer_ViewManager* aViewMgr = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
489 anActiveView = (OCCViewer_ViewWindow*) aViewMgr->getActiveView();
493 MeasureGUI_DimensionCreateTool aTool;
495 aTool.Settings.DefaultFlyout = aDefFlyout;
496 aTool.Settings.ActiveView = anActiveView ? anActiveView->getViewPort()->getView() : NULL;
498 switch ( getConstructorId() )
500 // create length dimension
501 case TypeButtonID_Length :
503 LengthPane* aLengthPane = qobject_cast<LengthPane*>( ActiveArgs() );
505 switch (aLengthPane->ActiveTab())
507 case LengthPane::TabID_SingleEdge:
509 const GEOM::GeomObjPtr& anEdge = aLengthPane->GetSingleEdge();
511 aDimensionIO = aTool.LengthOnEdge( anEdge );
515 case LengthPane::TabID_TwoPoints:
517 const GEOM::GeomObjPtr& aPoint1 = aLengthPane->GetPoint1();
518 const GEOM::GeomObjPtr& aPoint2 = aLengthPane->GetPoint2();
520 aDimensionIO = aTool.LengthByPoints( aPoint1, aPoint2 );
524 case LengthPane::TabID_ParallelEdges:
526 const GEOM::GeomObjPtr& anEdge1 = aLengthPane->GetEdge1();
527 const GEOM::GeomObjPtr& anEdge2 = aLengthPane->GetEdge2();
529 aDimensionIO = aTool.LengthByParallelEdges( anEdge1, anEdge2 );
536 // create diameter dimension
537 case TypeButtonID_Diameter :
539 DiameterPane* aDiameterPane = qobject_cast<DiameterPane*>( ActiveArgs() );
541 const GEOM::GeomObjPtr& aShape = aDiameterPane->GetShape();
543 aDimensionIO = aTool.Diameter( aShape );
547 // create angle dimension
548 case TypeButtonID_Angle :
550 AnglePane* anAnglePane = qobject_cast<AnglePane*>( ActiveArgs() );
552 switch (ActiveArgs()->ActiveTab())
554 case AnglePane::TabID_TwoEdges:
556 const GEOM::GeomObjPtr& anEdge1 = anAnglePane->GetEdge1();
557 const GEOM::GeomObjPtr& anEdge2 = anAnglePane->GetEdge2();
559 aDimensionIO = aTool.AngleByTwoEdges( anEdge1, anEdge2 );
563 case AnglePane::TabID_ThreePoints:
565 const GEOM::GeomObjPtr& aPoint1 = anAnglePane->GetPoint1();
566 const GEOM::GeomObjPtr& aPoint2 = anAnglePane->GetPoint2();
567 const GEOM::GeomObjPtr& aPoint3 = anAnglePane->GetPoint3();
569 aDimensionIO = aTool.AngleByThreePoints( aPoint1, aPoint2, aPoint3 );
577 if ( aDimensionIO.IsNull() )
582 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
584 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
586 aStyle->SetCommonColor( aColor );
587 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
588 aStyle->MakeText3d( Standard_True );
589 aStyle->MakeTextShaded( Standard_True );
590 aStyle->SetExtensionSize( aFontHeight * 0.5 );
591 aStyle->TextAspect()->SetHeight( aFontHeight );
592 aStyle->ArrowAspect()->SetLength( anArrowLength );
593 aStyle->LineAspect()->SetWidth( aLineWidth );
595 if ( aDimensionIO->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
597 // show degree symbol for dimension instead of label "deg"
598 if ( aUnitsAngle == "deg" )
600 aDimensionIO->SetSpecialSymbol(0xB0);
601 aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
602 aStyle->MakeUnitsDisplayed(Standard_False);
606 aDimensionIO->SetDisplaySpecialSymbol(AIS_DSS_No);
607 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
612 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
615 aDimensionIO->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
616 aDimensionIO->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
617 aDimensionIO->SetDimensionAspect( aStyle );
618 aDimensionIO->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
623 //=================================================================================
624 // class : AddDimensionToOwner
626 //=================================================================================
627 bool MeasureGUI_CreateDimensionDlg::AddDimensionToOwner()
629 if ( myDimension.IsNull() )
635 TopoDS_Shape anParentSh;
636 if ( GEOMBase::GetShape( myParentObj.get(), anParentSh ) )
638 aLCS = GEOMUtils::GetPosition( anParentSh );
641 QString aName = getNewObjectName();
643 SalomeApp_Study* aStudy = getStudy();
645 GEOMGUI_DimensionProperty aProp =
646 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
647 myParentObj->GetStudyEntry(),
648 GEOM::propertyName( GEOM::Dimensions ),
650 .value<GEOMGUI_DimensionProperty>();
652 // append new dimension record to data
653 aProp.AddRecord( myDimension, aLCS );
654 aProp.SetName( aProp.GetNumber() - 1, aName );
655 aProp.SetVisible( aProp.GetNumber() - 1, true );
657 // store modified property data
658 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
659 myParentObj->GetStudyEntry(),
660 GEOM::propertyName( GEOM::Dimensions ),
666 /* ------------------------------------------------------------------------------*
668 * Argument shape selector layout *
670 * ------------------------------------------------------------------------------*/
672 //=================================================================================
673 // class : MeasureGUI_CreateDimensionDlg::LengthPane
674 // purpose : Constructor
675 //=================================================================================
676 MeasureGUI_CreateDimensionDlg::LengthPane::LengthPane( QWidget* theParent )
677 : BaseSelectorPane( theParent )
679 myTabs = new QTabWidget( this );
680 mySingleEdgeSelectors = new MeasureGUI_1Sel_Frame( this );
681 myTwoPointsSelectors = new MeasureGUI_2Sel_Frame( this );
682 myParallelEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
684 myTabs->addTab( mySingleEdgeSelectors, MeasureGUI_CreateDimensionDlg::tr( "EDGE_LENGTH" ) );
685 myTabs->addTab( myTwoPointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "TWO_POINTS" ) );
686 myTabs->addTab( myParallelEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "PARALLEL_EDGES" ) );
688 mySingleEdgeSelectors->PushButton1->setIcon( mySelectorIcon );
689 mySingleEdgeSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE" ) );
690 mySingleEdgeSelectors->LineEdit1->setReadOnly( true );
692 myTwoPointsSelectors->PushButton1->setIcon( mySelectorIcon );
693 myTwoPointsSelectors->PushButton2->setIcon( mySelectorIcon );
694 myTwoPointsSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
695 myTwoPointsSelectors->TextLabel2->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
696 myTwoPointsSelectors->LineEdit1->setReadOnly( true );
697 myTwoPointsSelectors->LineEdit2->setReadOnly( true );
699 myParallelEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
700 myParallelEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
701 myParallelEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
702 myParallelEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
703 myParallelEdgesSelectors->LineEdit1->setReadOnly( true );
704 myParallelEdgesSelectors->LineEdit2->setReadOnly( true );
706 QVBoxLayout* aLayout = new QVBoxLayout( this );
708 aLayout->setMargin( 0 );
709 aLayout->addWidget( myTabs );
711 SelectionModes anEdgeModes;
712 SelectionModes aPointModes;
713 anEdgeModes << TopAbs_EDGE;
714 aPointModes << TopAbs_VERTEX;
716 SetTabWidget( myTabs );
717 RegisterSelector( mySingleEdgeSelectors->LineEdit1, mySingleEdgeSelectors->PushButton1, anEdgeModes, TabID_SingleEdge );
718 RegisterSelector( myTwoPointsSelectors->LineEdit1, myTwoPointsSelectors->PushButton1, aPointModes, TabID_TwoPoints );
719 RegisterSelector( myTwoPointsSelectors->LineEdit2, myTwoPointsSelectors->PushButton2, aPointModes, TabID_TwoPoints );
720 RegisterSelector( myParallelEdgesSelectors->LineEdit1, myParallelEdgesSelectors->PushButton1, anEdgeModes, TabID_ParallelEdges );
721 RegisterSelector( myParallelEdgesSelectors->LineEdit2, myParallelEdgesSelectors->PushButton2, anEdgeModes, TabID_ParallelEdges );
724 //=================================================================================
725 // class : MeasureGUI_CreateDimensionDlg::DiameterPane
726 // purpose : Constructor
727 //=================================================================================
728 MeasureGUI_CreateDimensionDlg::DiameterPane::DiameterPane( QWidget* theParent )
729 : BaseSelectorPane( theParent )
731 myShapeSelector = new MeasureGUI_1Sel_Frame( this );
732 myShapeSelector->PushButton1->setIcon( mySelectorIcon );
733 myShapeSelector->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "OBJECT" ) );
735 QVBoxLayout* aLayout = new QVBoxLayout( this );
737 aLayout->setMargin( 0 );
738 aLayout->addWidget( myShapeSelector );
740 SelectionModes aDiamModes;
741 aDiamModes << TopAbs_SHAPE
745 RegisterSelector( myShapeSelector->LineEdit1, myShapeSelector->PushButton1, aDiamModes );
748 //=================================================================================
749 // class : MeasureGUI_CreateDimensionDlg::AnglePane
750 // purpose : Constructor
751 //=================================================================================
752 MeasureGUI_CreateDimensionDlg::AnglePane::AnglePane( QWidget* theParent )
753 : BaseSelectorPane( theParent )
755 myTabs = new QTabWidget( this );
756 myTwoEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
757 myThreePointsSelectors = new MeasureGUI_3Sel_Frame( this );
759 myTabs->addTab( myTwoEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "TWO_EDGES" ) );
760 myTabs->addTab( myThreePointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "THREE_POINTS" ) );
762 myTwoEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
763 myTwoEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
764 myTwoEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
765 myTwoEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
767 myThreePointsSelectors->PushButton1->setIcon( mySelectorIcon );
768 myThreePointsSelectors->PushButton2->setIcon( mySelectorIcon );
769 myThreePointsSelectors->PushButton3->setIcon( mySelectorIcon );
770 myThreePointsSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
771 myThreePointsSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
772 myThreePointsSelectors->TextLabel3 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_3" ) );
774 QVBoxLayout* aLayout = new QVBoxLayout( this );
776 aLayout->setMargin( 0 );
777 aLayout->addWidget( myTabs );
779 SelectionModes anEdgeModes;
780 SelectionModes aPointModes;
781 anEdgeModes << TopAbs_EDGE;
782 aPointModes << TopAbs_VERTEX;
784 SetTabWidget( myTabs );
785 RegisterSelector( myTwoEdgesSelectors->LineEdit1, myTwoEdgesSelectors->PushButton1, anEdgeModes, TabID_TwoEdges );
786 RegisterSelector( myTwoEdgesSelectors->LineEdit2, myTwoEdgesSelectors->PushButton2, anEdgeModes, TabID_TwoEdges );
787 RegisterSelector( myThreePointsSelectors->LineEdit1, myThreePointsSelectors->PushButton1, aPointModes, TabID_ThreePoints );
788 RegisterSelector( myThreePointsSelectors->LineEdit2, myThreePointsSelectors->PushButton2, aPointModes, TabID_ThreePoints );
789 RegisterSelector( myThreePointsSelectors->LineEdit3, myThreePointsSelectors->PushButton3, aPointModes, TabID_ThreePoints );
792 /* ------------------------------------------------------------------------------*
794 * Argument shape selection logics *
796 * ------------------------------------------------------------------------------*/
798 //=================================================================================
799 // class : MeasureGUI_CreateDimensionDlg::BaseSelectorPane
800 // purpose : Constructor
801 //=================================================================================
802 MeasureGUI_CreateDimensionDlg::BaseSelectorPane::BaseSelectorPane( QWidget* theParent )
803 : QWidget( theParent ),
806 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
807 mySelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
810 //=================================================================================
811 // function : BaseSelectorPane::Reset
812 // purpose : Reset selector line edits and controls
813 //=================================================================================
814 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::Reset( bool theOpenDefaultTab )
816 if ( theOpenDefaultTab && myTabs )
818 myTabs->setCurrentIndex( 0 );
821 QMap< int, QList<QLineEdit*> >::iterator aTabsIt = mySelectors.begin();
822 for ( ; aTabsIt != mySelectors.end(); ++aTabsIt )
824 QList<QLineEdit*>& aSelectors = *aTabsIt;
825 QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
826 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
828 QLineEdit* aSelector = *aSelectorIt;
830 mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
834 QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
836 mySelectionButtons[aFirstSelector]->click();
839 //=================================================================================
840 // function : BaseSelectorPane::ActiveTab
841 // purpose : Returns active tab
842 //=================================================================================
843 int MeasureGUI_CreateDimensionDlg::BaseSelectorPane::ActiveTab() const
845 return myTabs != NULL ? myTabs->currentIndex() : 0;
848 //=================================================================================
849 // function : BaseSelectorPane::SelectionIntoArgument
850 // purpose : Populates current selector
851 //=================================================================================
852 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SelectionIntoArguments( const GEOM::GeomObjPtr& theSelected )
854 if ( theSelected.isNull() )
856 myCurrentSelector->clear();
857 mySelectedShapes[myCurrentSelector] = GEOM::GeomObjPtr();
861 QString aName = GEOMBase::GetName( theSelected.get() );
863 myCurrentSelector->setText( aName );
865 mySelectedShapes[myCurrentSelector] = theSelected;
867 // find next empty selector (iterate to the last)
868 QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
869 int aCurrentPos = aCurrentSelectors.indexOf( myCurrentSelector );
870 int aSelectorIt = aCurrentPos + 1;
871 for ( ; aSelectorIt != aCurrentSelectors.size(); ++aSelectorIt )
873 QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
874 if ( mySelectedShapes[aNextSelector].isNull() )
876 mySelectionButtons[aNextSelector]->click();
881 // find next empty selector (itearte from the first)
883 for ( ; aSelectorIt != aCurrentPos; ++aSelectorIt )
885 QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
886 if ( mySelectedShapes[aNextSelector].isNull() )
888 mySelectionButtons[aNextSelector]->click();
893 // stop selector switching
894 myCurrentSelector->setEnabled( false );
895 mySelectionButtons[myCurrentSelector]->setDown( false );
897 // every selector is populated - construct presentation
898 emit StopSelection();
899 emit SelectionDone();
902 //=================================================================================
903 // function : BaseSelectorPane::GetSelection
905 //=================================================================================
906 GEOM::GeomObjPtr MeasureGUI_CreateDimensionDlg::BaseSelectorPane::GetSelection( QLineEdit* theSelector ) const
908 return mySelectedShapes[theSelector];
911 //=================================================================================
912 // function : BaseSelectorPane::OnSelectorClicked
913 // purpose : Handle activation of selector controls pair {edit, button}
914 //=================================================================================
915 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnSelectorClicked()
917 // clicked "selector" button
918 QAbstractButton* aSender = qobject_cast<QAbstractButton*>( sender() );
924 // get "selector" controls on the active tab
925 QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
927 // iterate over controls on the tab and process them
928 for ( int aSelectorIt = 0; aSelectorIt < aCurrentSelectors.size(); ++aSelectorIt )
930 QLineEdit* aSelector = aCurrentSelectors[aSelectorIt];
931 QPushButton* aButton = mySelectionButtons[aSelector];
933 bool isClickedOnes = (aButton == aSender);
935 aSelector->setEnabled( isClickedOnes );
939 myCurrentSelector = aSelector;
940 myCurrentSelector->setFocus();
943 aButton->setDown( isClickedOnes );
946 emit StartSelection( mySelectionModes[myCurrentSelector] );
949 //=================================================================================
950 // function : BaseSelectorPane::OnTabChanged
952 //=================================================================================
953 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnTabChanged()
955 QList<QLineEdit*>& aSelectors = mySelectors[ ActiveTab() ];
956 QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
957 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
959 QLineEdit* aSelector = *aSelectorIt;
963 mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
966 QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
968 mySelectionButtons[aFirstSelector]->click();
973 //=================================================================================
974 // function : BaseSelectorPane::SetTabWidget
976 //=================================================================================
977 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SetTabWidget( QTabWidget* theTabs )
980 connect( myTabs, SIGNAL( currentChanged( int ) ), this, SLOT( OnTabChanged() ) );
983 //=================================================================================
984 // function : BaseSelectorPane::RegisterSelector
986 //=================================================================================
987 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::RegisterSelector( QLineEdit* theSelectorEdit,
988 QPushButton* theSelectorButton,
989 const SelectionModes& theSelectorModes,
992 if ( !mySelectors.contains( theTab ) )
994 mySelectors.insert( theTab, QList<QLineEdit*>() );
996 mySelectors[theTab].append( theSelectorEdit );
998 mySelectionButtons[theSelectorEdit] = theSelectorButton;
999 mySelectionModes [theSelectorEdit] = theSelectorModes;
1001 connect( theSelectorButton, SIGNAL( clicked() ), this, SLOT( OnSelectorClicked() ) );