1 // Copyright (C) 2007-2015 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 //=================================================================================
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 );
137 myRBGroup->button( TypeButtonID_Length )->click();
141 setHelpFileName("add_dimension_page.html");
144 //=================================================================================
145 // function : Destructor
147 //=================================================================================
148 MeasureGUI_CreateDimensionDlg::~MeasureGUI_CreateDimensionDlg()
152 //=================================================================================
153 // function : ActiveArgs
155 //=================================================================================
156 MeasureGUI_CreateDimensionDlg::BaseSelectorPane* MeasureGUI_CreateDimensionDlg::ActiveArgs()
158 switch ( getConstructorId() )
160 case TypeButtonID_Length : return myLengthArgs;
161 case TypeButtonID_Diameter : return myDiameterArgs;
162 case TypeButtonID_Angle : return myAngleArgs;
168 //=================================================================================
169 // function : GenerateName
171 //=================================================================================
172 QString MeasureGUI_CreateDimensionDlg::GenerateName( const QString& thePrefix )
174 QRegExp anExtractIds( "^" + thePrefix + "_([0-9]+)$" );
176 QSet<int> anOccupiedIds;
178 GEOMGUI_DimensionProperty aProp =
179 getStudy()->getObjectProperty( GEOM::sharedPropertiesId(),
180 myParentObj->GetStudyEntry(),
181 GEOM::propertyName( GEOM::Dimensions ),
183 .value<GEOMGUI_DimensionProperty>();
185 // get names and convert to QStrings to perform index matching
186 for( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
188 if ( anExtractIds.indexIn( aProp.GetName( anIt ) ) == -1 )
193 anOccupiedIds.insert( anExtractIds.cap( 1 ).toInt() );
199 if ( !anOccupiedIds.contains( aSearchId ) )
207 return QString( thePrefix + "_%1" ).arg( aSearchId );
210 //=================================================================================
211 // function : ConstructTypeChanged
213 //=================================================================================
214 void MeasureGUI_CreateDimensionDlg::ConstructTypeChanged( int theType )
216 ActiveArgs()->Reset();
223 case TypeButtonID_Length : aName = GenerateName( tr("NAME_LENGTH") ); break;
224 case TypeButtonID_Diameter : aName = GenerateName( tr("NAME_DIAMETER") ); break;
225 case TypeButtonID_Angle : aName = GenerateName( tr("NAME_ANGLE") ); break;
228 myMainFrame->ResultName->setText( aName );
234 resize( minimumSizeHint() );
237 //=================================================================================
238 // function : OnArgumentTabChanged
240 //=================================================================================
241 void MeasureGUI_CreateDimensionDlg::OnArgumentTabChanged()
247 //=================================================================================
248 // function : OnStartSelection
250 //=================================================================================
251 void MeasureGUI_CreateDimensionDlg::OnStartSelection( const QList<TopAbs_ShapeEnum>& theModes )
257 QList<TopAbs_ShapeEnum>::const_iterator aModeIt = theModes.constBegin();
258 for ( ; aModeIt != theModes.constEnd(); ++aModeIt )
260 localSelection( myParentObj.get(), *aModeIt );
263 mySelectionModes = theModes;
265 connect( myGeomGUI->getApp()->selectionMgr(),
266 SIGNAL( currentSelectionChanged() ),
267 SLOT( SelectionIntoArgument() ) );
270 //=================================================================================
271 // function : OnStopSelection
273 //=================================================================================
274 void MeasureGUI_CreateDimensionDlg::OnStopSelection()
278 disconnect( myGeomGUI->getApp()->selectionMgr(),
279 SIGNAL( currentSelectionChanged() ),
281 SLOT( SelectionIntoArgument() ) );
284 //=================================================================================
285 // function : SelectionIntoArgument
286 // purpose : Handle model selection by active selector pane
287 //=================================================================================
288 void MeasureGUI_CreateDimensionDlg::SelectionIntoArgument()
290 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
291 SALOME_ListIO aSelection;
292 aSelectionMgr->selectedObjects( aSelection );
294 if ( aSelection.Extent() != 1 )
296 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
300 GEOM::GeomObjPtr aSelected = getSelected( mySelectionModes );
301 if ( aSelected.isNull() )
303 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
307 GEOM::GeomObjPtr aSelectedMain =
308 !aSelected->IsMainShape()
309 ? aSelected->GetMainShape()
310 : GEOM::GeomObjPtr();
312 if ( myParentObj != aSelected && myParentObj != aSelectedMain )
314 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
322 ActiveArgs()->SelectionIntoArguments( aSelected );
325 //=================================================================================
326 // function : OnSelectionDone
328 //=================================================================================
329 void MeasureGUI_CreateDimensionDlg::OnSelectionDone()
331 // create new dimension presentation
332 myDimension = CreateDimension();
334 if ( myDimension.IsNull() )
336 // can not create preview, repeat selection
337 SUIT_MessageBox::warning( this,
338 tr( "WARNING_TITLE_CANNOT_CREATE_DIMENSION" ),
339 tr( "WARNING_MSG_INVALID_ARGUMENTS" ) );
341 ActiveArgs()->Reset();
346 // show preview of dimension object
347 SUIT_ViewWindow* aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
349 SOCC_Prs* aSalomePrs = dynamic_cast<SOCC_Prs*>( ( (SOCC_Viewer*)( aViewWindow->getViewManager()->getViewModel() ) )->CreatePrs( 0 ) );
351 aSalomePrs->AddObject( myDimension );
353 displayPreview( aSalomePrs );
358 //=================================================================================
359 // function : ClickOnOk
361 //=================================================================================
362 void MeasureGUI_CreateDimensionDlg::ClickOnOk()
364 setIsApplyAndClose( true );
365 if ( ClickOnApply() )
371 //=================================================================================
372 // function : ClickOnApply
374 //=================================================================================
375 bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
379 if ( myDimension.IsNull() )
384 if ( !AddDimensionToOwner() )
389 redisplay( myParentObj.get() );
391 if ( !isApplyAndClose() )
395 ConstructTypeChanged( getConstructorId() );
401 //=================================================================================
402 // function : StartLocalEditing
404 //=================================================================================
405 void MeasureGUI_CreateDimensionDlg::StartLocalEditing()
409 myDimensionInteractor->Enable();
411 if ( myDimension.IsNull() )
416 SalomeApp_Application* anApp = myGeomGUI->getApp();
418 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
420 if ( aViewMgr->getType() != OCCViewer_Viewer::Type() )
425 SOCC_Viewer* anOCCViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
427 myEditingViewer = anOCCViewer;
428 if ( !myEditingViewer )
433 Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
434 Handle(V3d_Viewer) aViewer3d = myEditingViewer->getViewer3d();
436 aViewer3d->AddZLayer( myEditingLayer );
438 anAISContext->OpenLocalContext( Standard_False, Standard_False );
439 anAISContext->Load( myDimension, AIS_DSM_All );
440 anAISContext->SetZLayer( myDimension, myEditingLayer );
441 anAISContext->Activate( myDimension, AIS_DSM_Line );
442 anAISContext->Activate( myDimension, AIS_DSM_Text );
443 anAISContext->Redisplay( myDimension );
446 //=================================================================================
447 // function : StopLocalEditing
449 //=================================================================================
450 void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
452 myDimensionInteractor->Disable();
454 if ( !myEditingViewer )
459 Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
460 Handle(V3d_Viewer) aViewer3d = myEditingViewer->getViewer3d();
462 aViewer3d->RemoveZLayer( myEditingLayer );
463 anAISContext->CloseLocalContext();
465 myEditingViewer = NULL;
468 //=================================================================================
471 //=================================================================================
472 void MeasureGUI_CreateDimensionDlg::Init()
480 myDiameterArgs->Reset();
481 myLengthArgs->Reset();
482 myAngleArgs->Reset();
485 //=================================================================================
486 // function : CreateDimensionPrs
488 //=================================================================================
489 Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
491 Handle(AIS_Dimension) aDimensionIO;
493 // prepare dimension styling
494 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
496 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
497 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
498 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
499 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
500 double aDefFlyout = aResMgr->doubleValue ( "Geometry", "dimensions_default_flyout", 20 );
501 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
502 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
503 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
505 OCCViewer_ViewWindow* anActiveView = NULL;
507 SalomeApp_Application* anApp = myGeomGUI->getApp();
511 OCCViewer_ViewManager* aViewMgr = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
514 anActiveView = (OCCViewer_ViewWindow*) aViewMgr->getActiveView();
518 MeasureGUI_DimensionCreateTool aTool;
520 aTool.Settings.DefaultFlyout = aDefFlyout;
521 aTool.Settings.ActiveView = anActiveView ? anActiveView->getViewPort()->getView() : NULL;
523 switch ( getConstructorId() )
525 // create length dimension
526 case TypeButtonID_Length :
528 LengthPane* aLengthPane = qobject_cast<LengthPane*>( ActiveArgs() );
530 switch (aLengthPane->ActiveTab())
532 case LengthPane::TabID_SingleEdge:
534 const GEOM::GeomObjPtr& anEdge = aLengthPane->GetSingleEdge();
536 aDimensionIO = aTool.LengthOnEdge( anEdge );
540 case LengthPane::TabID_TwoPoints:
542 const GEOM::GeomObjPtr& aPoint1 = aLengthPane->GetPoint1();
543 const GEOM::GeomObjPtr& aPoint2 = aLengthPane->GetPoint2();
545 aDimensionIO = aTool.LengthByPoints( aPoint1, aPoint2 );
549 case LengthPane::TabID_ParallelEdges:
551 const GEOM::GeomObjPtr& anEdge1 = aLengthPane->GetEdge1();
552 const GEOM::GeomObjPtr& anEdge2 = aLengthPane->GetEdge2();
554 aDimensionIO = aTool.LengthByParallelEdges( anEdge1, anEdge2 );
561 // create diameter dimension
562 case TypeButtonID_Diameter :
564 DiameterPane* aDiameterPane = qobject_cast<DiameterPane*>( ActiveArgs() );
566 const GEOM::GeomObjPtr& aShape = aDiameterPane->GetShape();
568 aDimensionIO = aTool.Diameter( aShape );
572 // create angle dimension
573 case TypeButtonID_Angle :
575 AnglePane* anAnglePane = qobject_cast<AnglePane*>( ActiveArgs() );
577 switch (ActiveArgs()->ActiveTab())
579 case AnglePane::TabID_TwoEdges:
581 const GEOM::GeomObjPtr& anEdge1 = anAnglePane->GetEdge1();
582 const GEOM::GeomObjPtr& anEdge2 = anAnglePane->GetEdge2();
584 aDimensionIO = aTool.AngleByTwoEdges( anEdge1, anEdge2 );
588 case AnglePane::TabID_ThreePoints:
590 const GEOM::GeomObjPtr& aPoint1 = anAnglePane->GetPoint1();
591 const GEOM::GeomObjPtr& aPoint2 = anAnglePane->GetPoint2();
592 const GEOM::GeomObjPtr& aPoint3 = anAnglePane->GetPoint3();
594 aDimensionIO = aTool.AngleByThreePoints( aPoint1, aPoint2, aPoint3 );
602 if ( aDimensionIO.IsNull() )
607 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
609 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
611 aStyle->SetCommonColor( aColor );
612 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
613 aStyle->MakeText3d( Standard_True );
614 aStyle->MakeTextShaded( Standard_True );
615 aStyle->SetExtensionSize( aFontHeight * 0.5 );
616 aStyle->TextAspect()->SetHeight( aFontHeight );
617 aStyle->ArrowAspect()->SetLength( anArrowLength );
618 aStyle->LineAspect()->SetWidth( aLineWidth );
620 if ( aDimensionIO->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
622 // show degree symbol for dimension instead of label "deg"
623 if ( aUnitsAngle == "deg" )
625 aDimensionIO->SetSpecialSymbol(0xB0);
626 aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
627 aStyle->MakeUnitsDisplayed(Standard_False);
631 aDimensionIO->SetDisplaySpecialSymbol(AIS_DSS_No);
632 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
637 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
640 aDimensionIO->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
641 aDimensionIO->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
642 aDimensionIO->SetDimensionAspect( aStyle );
643 aDimensionIO->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
648 //=================================================================================
649 // class : AddDimensionToOwner
651 //=================================================================================
652 bool MeasureGUI_CreateDimensionDlg::AddDimensionToOwner()
654 if ( myDimension.IsNull() )
660 TopoDS_Shape anParentSh;
661 if ( GEOMBase::GetShape( myParentObj.get(), anParentSh ) )
663 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
666 QString aName = getNewObjectName();
668 SalomeApp_Study* aStudy = getStudy();
670 GEOMGUI_DimensionProperty aProp =
671 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
672 myParentObj->GetStudyEntry(),
673 GEOM::propertyName( GEOM::Dimensions ),
675 .value<GEOMGUI_DimensionProperty>();
677 // append new dimension record to data
678 aProp.AddRecord( myDimension, aLCS );
679 aProp.SetName( aProp.GetNumber() - 1, aName );
680 aProp.SetVisible( aProp.GetNumber() - 1, true );
682 // store modified property data
683 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
684 myParentObj->GetStudyEntry(),
685 GEOM::propertyName( GEOM::Dimensions ),
691 /* ------------------------------------------------------------------------------*
693 * Argument shape selector layout *
695 * ------------------------------------------------------------------------------*/
697 //=================================================================================
698 // class : MeasureGUI_CreateDimensionDlg::LengthPane
699 // purpose : Constructor
700 //=================================================================================
701 MeasureGUI_CreateDimensionDlg::LengthPane::LengthPane( QWidget* theParent )
702 : BaseSelectorPane( theParent )
704 myTabs = new QTabWidget( this );
705 mySingleEdgeSelectors = new MeasureGUI_1Sel_Frame( this );
706 myTwoPointsSelectors = new MeasureGUI_2Sel_Frame( this );
707 myParallelEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
709 myTabs->addTab( mySingleEdgeSelectors, MeasureGUI_CreateDimensionDlg::tr( "EDGE_LENGTH" ) );
710 myTabs->addTab( myTwoPointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "TWO_POINTS" ) );
711 myTabs->addTab( myParallelEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "PARALLEL_EDGES" ) );
713 mySingleEdgeSelectors->PushButton1->setIcon( mySelectorIcon );
714 mySingleEdgeSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE" ) );
715 mySingleEdgeSelectors->LineEdit1->setReadOnly( true );
717 myTwoPointsSelectors->PushButton1->setIcon( mySelectorIcon );
718 myTwoPointsSelectors->PushButton2->setIcon( mySelectorIcon );
719 myTwoPointsSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
720 myTwoPointsSelectors->TextLabel2->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
721 myTwoPointsSelectors->LineEdit1->setReadOnly( true );
722 myTwoPointsSelectors->LineEdit2->setReadOnly( true );
724 myParallelEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
725 myParallelEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
726 myParallelEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
727 myParallelEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
728 myParallelEdgesSelectors->LineEdit1->setReadOnly( true );
729 myParallelEdgesSelectors->LineEdit2->setReadOnly( true );
731 QVBoxLayout* aLayout = new QVBoxLayout( this );
733 aLayout->setMargin( 0 );
734 aLayout->addWidget( myTabs );
736 SelectionModes anEdgeModes;
737 SelectionModes aPointModes;
738 anEdgeModes << TopAbs_EDGE;
739 aPointModes << TopAbs_VERTEX;
741 SetTabWidget( myTabs );
742 RegisterSelector( mySingleEdgeSelectors->LineEdit1, mySingleEdgeSelectors->PushButton1, anEdgeModes, TabID_SingleEdge );
743 RegisterSelector( myTwoPointsSelectors->LineEdit1, myTwoPointsSelectors->PushButton1, aPointModes, TabID_TwoPoints );
744 RegisterSelector( myTwoPointsSelectors->LineEdit2, myTwoPointsSelectors->PushButton2, aPointModes, TabID_TwoPoints );
745 RegisterSelector( myParallelEdgesSelectors->LineEdit1, myParallelEdgesSelectors->PushButton1, anEdgeModes, TabID_ParallelEdges );
746 RegisterSelector( myParallelEdgesSelectors->LineEdit2, myParallelEdgesSelectors->PushButton2, anEdgeModes, TabID_ParallelEdges );
749 //=================================================================================
750 // class : MeasureGUI_CreateDimensionDlg::DiameterPane
751 // purpose : Constructor
752 //=================================================================================
753 MeasureGUI_CreateDimensionDlg::DiameterPane::DiameterPane( QWidget* theParent )
754 : BaseSelectorPane( theParent )
756 myShapeSelector = new MeasureGUI_1Sel_Frame( this );
757 myShapeSelector->PushButton1->setIcon( mySelectorIcon );
758 myShapeSelector->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "OBJECT" ) );
760 QVBoxLayout* aLayout = new QVBoxLayout( this );
762 aLayout->setMargin( 0 );
763 aLayout->addWidget( myShapeSelector );
765 SelectionModes aDiamModes;
766 aDiamModes << TopAbs_SHAPE
770 RegisterSelector( myShapeSelector->LineEdit1, myShapeSelector->PushButton1, aDiamModes );
773 //=================================================================================
774 // class : MeasureGUI_CreateDimensionDlg::AnglePane
775 // purpose : Constructor
776 //=================================================================================
777 MeasureGUI_CreateDimensionDlg::AnglePane::AnglePane( QWidget* theParent )
778 : BaseSelectorPane( theParent )
780 myTabs = new QTabWidget( this );
781 myTwoEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
782 myThreePointsSelectors = new MeasureGUI_3Sel_Frame( this );
784 myTabs->addTab( myTwoEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "TWO_EDGES" ) );
785 myTabs->addTab( myThreePointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "THREE_POINTS" ) );
787 myTwoEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
788 myTwoEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
789 myTwoEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
790 myTwoEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
792 myThreePointsSelectors->PushButton1->setIcon( mySelectorIcon );
793 myThreePointsSelectors->PushButton2->setIcon( mySelectorIcon );
794 myThreePointsSelectors->PushButton3->setIcon( mySelectorIcon );
795 myThreePointsSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
796 myThreePointsSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
797 myThreePointsSelectors->TextLabel3 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_3" ) );
799 QVBoxLayout* aLayout = new QVBoxLayout( this );
801 aLayout->setMargin( 0 );
802 aLayout->addWidget( myTabs );
804 SelectionModes anEdgeModes;
805 SelectionModes aPointModes;
806 anEdgeModes << TopAbs_EDGE;
807 aPointModes << TopAbs_VERTEX;
809 SetTabWidget( myTabs );
810 RegisterSelector( myTwoEdgesSelectors->LineEdit1, myTwoEdgesSelectors->PushButton1, anEdgeModes, TabID_TwoEdges );
811 RegisterSelector( myTwoEdgesSelectors->LineEdit2, myTwoEdgesSelectors->PushButton2, anEdgeModes, TabID_TwoEdges );
812 RegisterSelector( myThreePointsSelectors->LineEdit1, myThreePointsSelectors->PushButton1, aPointModes, TabID_ThreePoints );
813 RegisterSelector( myThreePointsSelectors->LineEdit2, myThreePointsSelectors->PushButton2, aPointModes, TabID_ThreePoints );
814 RegisterSelector( myThreePointsSelectors->LineEdit3, myThreePointsSelectors->PushButton3, aPointModes, TabID_ThreePoints );
817 /* ------------------------------------------------------------------------------*
819 * Argument shape selection logics *
821 * ------------------------------------------------------------------------------*/
823 //=================================================================================
824 // class : MeasureGUI_CreateDimensionDlg::BaseSelectorPane
825 // purpose : Constructor
826 //=================================================================================
827 MeasureGUI_CreateDimensionDlg::BaseSelectorPane::BaseSelectorPane( QWidget* theParent )
828 : QWidget( theParent ),
831 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
832 mySelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
835 //=================================================================================
836 // function : BaseSelectorPane::Reset
837 // purpose : Reset selector line edits and controls
838 //=================================================================================
839 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::Reset( bool theOpenDefaultTab )
841 if ( theOpenDefaultTab && myTabs )
843 myTabs->setCurrentIndex( 0 );
846 QMap< int, QList<QLineEdit*> >::iterator aTabsIt = mySelectors.begin();
847 for ( ; aTabsIt != mySelectors.end(); ++aTabsIt )
849 QList<QLineEdit*>& aSelectors = *aTabsIt;
850 QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
851 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
853 QLineEdit* aSelector = *aSelectorIt;
855 mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
859 QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
861 mySelectionButtons[aFirstSelector]->click();
864 //=================================================================================
865 // function : BaseSelectorPane::ActiveTab
866 // purpose : Returns active tab
867 //=================================================================================
868 int MeasureGUI_CreateDimensionDlg::BaseSelectorPane::ActiveTab() const
870 return myTabs != NULL ? myTabs->currentIndex() : 0;
873 //=================================================================================
874 // function : BaseSelectorPane::SelectionIntoArgument
875 // purpose : Populates current selector
876 //=================================================================================
877 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SelectionIntoArguments( const GEOM::GeomObjPtr& theSelected )
879 if ( theSelected.isNull() )
881 myCurrentSelector->clear();
882 mySelectedShapes[myCurrentSelector] = GEOM::GeomObjPtr();
886 QString aName = GEOMBase::GetName( theSelected.get() );
888 myCurrentSelector->setText( aName );
890 mySelectedShapes[myCurrentSelector] = theSelected;
892 // find next empty selector (iterate to the last)
893 QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
894 int aCurrentPos = aCurrentSelectors.indexOf( myCurrentSelector );
895 int aSelectorIt = aCurrentPos + 1;
896 for ( ; aSelectorIt != aCurrentSelectors.size(); ++aSelectorIt )
898 QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
899 if ( mySelectedShapes[aNextSelector].isNull() )
901 mySelectionButtons[aNextSelector]->click();
906 // find next empty selector (itearte from the first)
908 for ( ; aSelectorIt != aCurrentPos; ++aSelectorIt )
910 QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
911 if ( mySelectedShapes[aNextSelector].isNull() )
913 mySelectionButtons[aNextSelector]->click();
918 // stop selector switching
919 myCurrentSelector->setEnabled( false );
920 mySelectionButtons[myCurrentSelector]->setDown( false );
922 // every selector is populated - construct presentation
923 emit StopSelection();
924 emit SelectionDone();
927 //=================================================================================
928 // function : BaseSelectorPane::GetSelection
930 //=================================================================================
931 GEOM::GeomObjPtr MeasureGUI_CreateDimensionDlg::BaseSelectorPane::GetSelection( QLineEdit* theSelector ) const
933 return mySelectedShapes[theSelector];
936 //=================================================================================
937 // function : BaseSelectorPane::OnSelectorClicked
938 // purpose : Handle activation of selector controls pair {edit, button}
939 //=================================================================================
940 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnSelectorClicked()
942 // clicked "selector" button
943 QAbstractButton* aSender = qobject_cast<QAbstractButton*>( sender() );
949 // get "selector" controls on the active tab
950 QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
952 // iterate over controls on the tab and process them
953 for ( int aSelectorIt = 0; aSelectorIt < aCurrentSelectors.size(); ++aSelectorIt )
955 QLineEdit* aSelector = aCurrentSelectors[aSelectorIt];
956 QPushButton* aButton = mySelectionButtons[aSelector];
958 bool isClickedOnes = (aButton == aSender);
960 aSelector->setEnabled( isClickedOnes );
964 myCurrentSelector = aSelector;
965 myCurrentSelector->setFocus();
968 aButton->setDown( isClickedOnes );
971 emit StartSelection( mySelectionModes[myCurrentSelector] );
974 //=================================================================================
975 // function : BaseSelectorPane::OnTabChanged
977 //=================================================================================
978 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnTabChanged()
980 QList<QLineEdit*>& aSelectors = mySelectors[ ActiveTab() ];
981 QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
982 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
984 QLineEdit* aSelector = *aSelectorIt;
988 mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
991 QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
993 mySelectionButtons[aFirstSelector]->click();
998 //=================================================================================
999 // function : BaseSelectorPane::SetTabWidget
1001 //=================================================================================
1002 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SetTabWidget( QTabWidget* theTabs )
1005 connect( myTabs, SIGNAL( currentChanged( int ) ), this, SLOT( OnTabChanged() ) );
1008 //=================================================================================
1009 // function : BaseSelectorPane::RegisterSelector
1011 //=================================================================================
1012 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::RegisterSelector( QLineEdit* theSelectorEdit,
1013 QPushButton* theSelectorButton,
1014 const SelectionModes& theSelectorModes,
1017 if ( !mySelectors.contains( theTab ) )
1019 mySelectors.insert( theTab, QList<QLineEdit*>() );
1021 mySelectors[theTab].append( theSelectorEdit );
1023 mySelectionButtons[theSelectorEdit] = theSelectorButton;
1024 mySelectionModes [theSelectorEdit] = theSelectorModes;
1026 connect( theSelectorButton, SIGNAL( clicked() ), this, SLOT( OnSelectorClicked() ) );