1 // Copyright (C) 2007-2020 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 <QButtonGroup>
55 #include <Aspect_PolygonOffsetMode.hxx>
57 #include <Basics_OCCTVersion.hxx>
59 //=================================================================================
60 // function : Constructor
62 //=================================================================================
63 MeasureGUI_CreateDimensionDlg::MeasureGUI_CreateDimensionDlg( const GEOM::GeomObjPtr& theObj,
66 : GEOMBase_Skeleton( theGUI, theParent ),
67 myParentObj( theObj ),
68 myEditingViewer( NULL )
70 setWindowTitle( tr( "CREATE_DIMENSION_TITLE" ) );
72 // init "dimension type" radio buttons
73 QAbstractButton* aTypeButtonLength = mainFrame()->RadioButton1;
74 QAbstractButton* aTypeButtonDiameter = mainFrame()->RadioButton2;
75 QAbstractButton* aTypeButtonAngle = mainFrame()->RadioButton3;
77 mainFrame()->GroupConstructors->setTitle( tr( "DIMENSIONS" ) );
78 aTypeButtonDiameter->setText( tr( "DIAMETER" ) );
79 aTypeButtonLength->setText( tr( "LENGTH" ) );
80 aTypeButtonAngle->setText( tr( "ANGLE" ) );
82 // construct "arguments" pane
83 QGroupBox* aGroupArgs = new QGroupBox( tr( "ARGUMENTS" ), centralWidget() );
84 QVBoxLayout* aGroupArgsLayout = new QVBoxLayout( aGroupArgs );
86 myLengthArgs = new LengthPane ( centralWidget() );
87 myDiameterArgs = new DiameterPane( centralWidget() );
88 myAngleArgs = new AnglePane ( centralWidget() );
90 // connect selector pane signals
91 connect( myLengthArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
92 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
93 connect( myDiameterArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
94 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
95 connect( myAngleArgs, SIGNAL( StartSelection( const QList<TopAbs_ShapeEnum>& ) ),
96 SLOT( OnStartSelection( const QList<TopAbs_ShapeEnum>& ) ) );
98 connect( myLengthArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
99 connect( myDiameterArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
100 connect( myAngleArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection( ) ) );
102 connect( myLengthArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
103 connect( myDiameterArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
104 connect( myAngleArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
106 aGroupArgsLayout->addWidget( myLengthArgs );
107 aGroupArgsLayout->addWidget( myDiameterArgs );
108 aGroupArgsLayout->addWidget( myAngleArgs );
110 // construct main layout
111 QVBoxLayout* aCustomWidLayout = new QVBoxLayout( centralWidget() );
112 aCustomWidLayout->setMargin( 0 );
113 aCustomWidLayout->setSpacing( 6 );
114 aCustomWidLayout->addWidget( aGroupArgs );
116 // add visibility rules for structural widgets
117 connect( aTypeButtonLength, SIGNAL( toggled(bool) ), myLengthArgs, SLOT( setVisible(bool) ) );
118 connect( aTypeButtonDiameter, SIGNAL( toggled(bool) ), myDiameterArgs, SLOT( setVisible(bool) ) );
119 connect( aTypeButtonAngle, SIGNAL( toggled(bool) ), myAngleArgs, SLOT( setVisible(bool) ) );
121 // signals and slots connections
122 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
123 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
125 // map functional signals
126 myRBGroup->setId( aTypeButtonLength, TypeButtonID_Length );
127 myRBGroup->setId( aTypeButtonDiameter, TypeButtonID_Diameter );
128 myRBGroup->setId( aTypeButtonAngle, TypeButtonID_Angle );
130 connect( this, SIGNAL( constructorsClicked( int ) ), SLOT( ConstructTypeChanged( int ) ) );
131 connect( myLengthArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
132 connect( myDiameterArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
133 connect( myAngleArgs, SIGNAL( TabChanged() ), SLOT( OnArgumentTabChanged() ) );
135 myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent );
137 myDiameterArgs->setVisible( false );
138 myAngleArgs ->setVisible( false );
139 myLengthArgs ->setVisible( true );
141 myRBGroup->button( TypeButtonID_Length )->click();
145 setHelpFileName("add_dimension_page.html");
148 //=================================================================================
149 // function : Destructor
151 //=================================================================================
152 MeasureGUI_CreateDimensionDlg::~MeasureGUI_CreateDimensionDlg()
156 //=================================================================================
157 // function : ActiveArgs
159 //=================================================================================
160 MeasureGUI_CreateDimensionDlg::BaseSelectorPane* MeasureGUI_CreateDimensionDlg::ActiveArgs()
162 switch ( getConstructorId() )
164 case TypeButtonID_Length : return myLengthArgs;
165 case TypeButtonID_Diameter : return myDiameterArgs;
166 case TypeButtonID_Angle : return myAngleArgs;
172 //=================================================================================
173 // function : GenerateName
175 //=================================================================================
176 QString MeasureGUI_CreateDimensionDlg::GenerateName( const QString& thePrefix )
178 QRegExp anExtractIds( "^" + thePrefix + "_([0-9]+)$" );
180 QSet<int> anOccupiedIds;
182 GEOMGUI_DimensionProperty aProp =
183 getStudy()->getObjectProperty( GEOM::sharedPropertiesId(),
184 myParentObj->GetStudyEntry(),
185 GEOM::propertyName( GEOM::Dimensions ),
187 .value<GEOMGUI_DimensionProperty>();
189 // get names and convert to QStrings to perform index matching
190 for( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
192 if ( anExtractIds.indexIn( aProp.GetName( anIt ) ) == -1 )
197 anOccupiedIds.insert( anExtractIds.cap( 1 ).toInt() );
203 if ( !anOccupiedIds.contains( aSearchId ) )
211 return QString( thePrefix + "_%1" ).arg( aSearchId );
214 //=================================================================================
215 // function : ConstructTypeChanged
217 //=================================================================================
218 void MeasureGUI_CreateDimensionDlg::ConstructTypeChanged( int theType )
220 ActiveArgs()->Reset();
227 case TypeButtonID_Length : aName = GenerateName( tr("NAME_LENGTH") ); break;
228 case TypeButtonID_Diameter : aName = GenerateName( tr("NAME_DIAMETER") ); break;
229 case TypeButtonID_Angle : aName = GenerateName( tr("NAME_ANGLE") ); break;
232 myMainFrame->ResultName->setText( aName );
238 resize( minimumSizeHint() );
241 //=================================================================================
242 // function : OnArgumentTabChanged
244 //=================================================================================
245 void MeasureGUI_CreateDimensionDlg::OnArgumentTabChanged()
251 //=================================================================================
252 // function : OnStartSelection
254 //=================================================================================
255 void MeasureGUI_CreateDimensionDlg::OnStartSelection( const QList<TopAbs_ShapeEnum>& theModes )
261 QList<TopAbs_ShapeEnum>::const_iterator aModeIt = theModes.constBegin();
262 for ( ; aModeIt != theModes.constEnd(); ++aModeIt )
264 localSelection( myParentObj.get(), *aModeIt );
267 mySelectionModes = theModes;
269 connect( myGeomGUI->getApp()->selectionMgr(),
270 SIGNAL( currentSelectionChanged() ),
271 SLOT( SelectionIntoArgument() ) );
274 //=================================================================================
275 // function : OnStopSelection
277 //=================================================================================
278 void MeasureGUI_CreateDimensionDlg::OnStopSelection()
282 disconnect( myGeomGUI->getApp()->selectionMgr(),
283 SIGNAL( currentSelectionChanged() ),
285 SLOT( SelectionIntoArgument() ) );
288 //=================================================================================
289 // function : SelectionIntoArgument
290 // purpose : Handle model selection by active selector pane
291 //=================================================================================
292 void MeasureGUI_CreateDimensionDlg::SelectionIntoArgument()
294 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
295 SALOME_ListIO aSelection;
296 aSelectionMgr->selectedObjects( aSelection );
298 if ( aSelection.Extent() != 1 )
300 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
304 GEOM::GeomObjPtr aSelected = getSelected( mySelectionModes );
305 if ( aSelected.isNull() )
307 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
311 GEOM::GeomObjPtr aSelectedMain =
312 !aSelected->IsMainShape()
313 ? aSelected->GetMainShape()
314 : GEOM::GeomObjPtr();
316 if ( myParentObj != aSelected && myParentObj != aSelectedMain )
318 ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
326 ActiveArgs()->SelectionIntoArguments( aSelected );
329 //=================================================================================
330 // function : OnSelectionDone
332 //=================================================================================
333 void MeasureGUI_CreateDimensionDlg::OnSelectionDone()
335 // create new dimension presentation
336 myDimension = CreateDimension();
338 if ( myDimension.IsNull() )
340 // can not create preview, repeat selection
341 SUIT_MessageBox::warning( this,
342 tr( "WARNING_TITLE_CANNOT_CREATE_DIMENSION" ),
343 tr( "WARNING_MSG_INVALID_ARGUMENTS" ) );
345 ActiveArgs()->Reset();
350 // show preview of dimension object
351 SUIT_ViewWindow* aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
353 SOCC_Prs* aSalomePrs = dynamic_cast<SOCC_Prs*>( ( (SOCC_Viewer*)( aViewWindow->getViewManager()->getViewModel() ) )->CreatePrs( 0 ) );
355 aSalomePrs->AddObject( myDimension );
357 displayPreview( aSalomePrs );
362 //=================================================================================
363 // function : ClickOnOk
365 //=================================================================================
366 void MeasureGUI_CreateDimensionDlg::ClickOnOk()
368 setIsApplyAndClose( true );
369 if ( ClickOnApply() )
375 //=================================================================================
376 // function : ClickOnApply
378 //=================================================================================
379 bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
383 if ( myDimension.IsNull() )
388 if ( !AddDimensionToOwner() )
393 redisplay( myParentObj.get() );
395 if ( !isApplyAndClose() )
399 ConstructTypeChanged( getConstructorId() );
405 //=================================================================================
406 // function : StartLocalEditing
408 //=================================================================================
409 void MeasureGUI_CreateDimensionDlg::StartLocalEditing()
413 myDimensionInteractor->Enable();
415 if ( myDimension.IsNull() )
420 SalomeApp_Application* anApp = myGeomGUI->getApp();
422 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
424 if ( aViewMgr->getType() != OCCViewer_Viewer::Type() )
429 SOCC_Viewer* anOCCViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
431 myEditingViewer = anOCCViewer;
432 if ( !myEditingViewer )
437 Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
438 Handle(V3d_Viewer) aViewer3d = myEditingViewer->getViewer3d();
440 aViewer3d->AddZLayer( myEditingLayer );
442 #if OCC_VERSION_LARGE >= 0x070400ff
443 anAISContext->Load( myDimension, PrsDim_DimensionSelectionMode_All );
444 anAISContext->SetZLayer( myDimension, myEditingLayer );
445 anAISContext->Activate( myDimension, PrsDim_DimensionSelectionMode_Line );
446 anAISContext->Activate( myDimension, PrsDim_DimensionSelectionMode_Text );
448 anAISContext->Load( myDimension, AIS_DSM_All );
449 anAISContext->SetZLayer( myDimension, myEditingLayer );
450 anAISContext->Activate( myDimension, AIS_DSM_Line );
451 anAISContext->Activate( myDimension, AIS_DSM_Text );
453 anAISContext->Redisplay( myDimension , Standard_True );
456 //=================================================================================
457 // function : StopLocalEditing
459 //=================================================================================
460 void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
462 myDimensionInteractor->Disable();
464 if ( !myEditingViewer )
469 Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
470 Handle(V3d_Viewer) aViewer3d = myEditingViewer->getViewer3d();
472 aViewer3d->RemoveZLayer( myEditingLayer );
473 anAISContext->Deactivate();
474 anAISContext->Activate(0);
476 myEditingViewer = NULL;
479 //=================================================================================
482 //=================================================================================
483 void MeasureGUI_CreateDimensionDlg::Init()
491 myDiameterArgs->Reset();
492 myLengthArgs->Reset();
493 myAngleArgs->Reset();
496 //=================================================================================
497 // function : CreateDimensionPrs
499 //=================================================================================
500 Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
502 Handle(AIS_Dimension) aDimensionIO;
504 // prepare dimension styling
505 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
507 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
508 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
509 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
510 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
511 double aDefFlyout = aResMgr->doubleValue ( "Geometry", "dimensions_default_flyout", 20 );
512 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
513 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
514 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
515 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
517 OCCViewer_ViewWindow* anActiveView = NULL;
519 SalomeApp_Application* anApp = myGeomGUI->getApp();
523 OCCViewer_ViewManager* aViewMgr = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
526 anActiveView = (OCCViewer_ViewWindow*) aViewMgr->getActiveView();
530 MeasureGUI_DimensionCreateTool aTool;
532 aTool.Settings.DefaultFlyout = aDefFlyout;
533 aTool.Settings.ActiveView = anActiveView ? anActiveView->getViewPort()->getView() : NULL;
535 switch ( getConstructorId() )
537 // create length dimension
538 case TypeButtonID_Length :
540 LengthPane* aLengthPane = qobject_cast<LengthPane*>( ActiveArgs() );
542 switch (aLengthPane->ActiveTab())
544 case LengthPane::TabID_SingleEdge:
546 const GEOM::GeomObjPtr& anEdge = aLengthPane->GetSingleEdge();
548 aDimensionIO = aTool.LengthOnEdge( anEdge );
552 case LengthPane::TabID_TwoPoints:
554 const GEOM::GeomObjPtr& aPoint1 = aLengthPane->GetPoint1();
555 const GEOM::GeomObjPtr& aPoint2 = aLengthPane->GetPoint2();
557 aDimensionIO = aTool.LengthByPoints( aPoint1, aPoint2 );
561 case LengthPane::TabID_ParallelEdges:
563 const GEOM::GeomObjPtr& anEdge1 = aLengthPane->GetEdge1();
564 const GEOM::GeomObjPtr& anEdge2 = aLengthPane->GetEdge2();
566 aDimensionIO = aTool.LengthByParallelEdges( anEdge1, anEdge2 );
573 // create diameter dimension
574 case TypeButtonID_Diameter :
576 DiameterPane* aDiameterPane = qobject_cast<DiameterPane*>( ActiveArgs() );
578 const GEOM::GeomObjPtr& aShape = aDiameterPane->GetShape();
580 aDimensionIO = aTool.Diameter( aShape );
584 // create angle dimension
585 case TypeButtonID_Angle :
587 AnglePane* anAnglePane = qobject_cast<AnglePane*>( ActiveArgs() );
589 switch (ActiveArgs()->ActiveTab())
591 case AnglePane::TabID_TwoEdges:
593 const GEOM::GeomObjPtr& anEdge1 = anAnglePane->GetEdge1();
594 const GEOM::GeomObjPtr& anEdge2 = anAnglePane->GetEdge2();
596 aDimensionIO = aTool.AngleByTwoEdges( anEdge1, anEdge2 );
600 case AnglePane::TabID_ThreePoints:
602 const GEOM::GeomObjPtr& aPoint1 = anAnglePane->GetPoint1();
603 const GEOM::GeomObjPtr& aPoint2 = anAnglePane->GetPoint2();
604 const GEOM::GeomObjPtr& aPoint3 = anAnglePane->GetPoint3();
606 aDimensionIO = aTool.AngleByThreePoints( aPoint1, aPoint2, aPoint3 );
614 if ( aDimensionIO.IsNull() )
619 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
621 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
623 aStyle->SetCommonColor( aColor );
624 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
625 aStyle->MakeText3d( aUseText3d );
626 aStyle->MakeTextShaded( Standard_True );
627 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
628 aStyle->SetExtensionSize( fsize * 0.5 );
629 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
630 aStyle->TextAspect()->SetHeight( fsize );
631 aStyle->ArrowAspect()->SetLength( anArrowLength );
632 aStyle->LineAspect()->SetWidth( aLineWidth );
634 if ( aDimensionIO->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
636 // show degree symbol for dimension instead of label "deg"
637 if ( aUnitsAngle == "deg" )
639 aDimensionIO->SetSpecialSymbol(0xB0);
640 #if OCC_VERSION_LARGE >= 0x070400ff
641 aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? PrsDim_DisplaySpecialSymbol_After :
642 PrsDim_DisplaySpecialSymbol_No );
644 aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
646 aStyle->MakeUnitsDisplayed(Standard_False);
650 #if OCC_VERSION_LARGE >= 0x070400ff
651 aDimensionIO->SetDisplaySpecialSymbol(PrsDim_DisplaySpecialSymbol_No);
653 aDimensionIO->SetDisplaySpecialSymbol(AIS_DSS_No);
655 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
660 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
663 aDimensionIO->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
664 aDimensionIO->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
665 aDimensionIO->SetDimensionAspect( aStyle );
666 aDimensionIO->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
671 //=================================================================================
672 // class : AddDimensionToOwner
674 //=================================================================================
675 bool MeasureGUI_CreateDimensionDlg::AddDimensionToOwner()
677 if ( myDimension.IsNull() )
683 TopoDS_Shape anParentSh;
684 if ( GEOMBase::GetShape( myParentObj.get(), anParentSh ) )
686 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
689 QString aName = getNewObjectName();
691 SalomeApp_Study* aStudy = getStudy();
693 GEOMGUI_DimensionProperty aProp =
694 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
695 myParentObj->GetStudyEntry(),
696 GEOM::propertyName( GEOM::Dimensions ),
698 .value<GEOMGUI_DimensionProperty>();
700 // append new dimension record to data
701 aProp.AddRecord( myDimension, aLCS );
702 aProp.SetName( aProp.GetNumber() - 1, aName );
703 aProp.SetVisible( aProp.GetNumber() - 1, true );
705 // store modified property data
706 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
707 myParentObj->GetStudyEntry(),
708 GEOM::propertyName( GEOM::Dimensions ),
714 /* ------------------------------------------------------------------------------*
716 * Argument shape selector layout *
718 * ------------------------------------------------------------------------------*/
720 //=================================================================================
721 // class : MeasureGUI_CreateDimensionDlg::LengthPane
722 // purpose : Constructor
723 //=================================================================================
724 MeasureGUI_CreateDimensionDlg::LengthPane::LengthPane( QWidget* theParent )
725 : BaseSelectorPane( theParent )
727 myTabs = new QTabWidget( this );
728 mySingleEdgeSelectors = new MeasureGUI_1Sel_Frame( this );
729 myTwoPointsSelectors = new MeasureGUI_2Sel_Frame( this );
730 myParallelEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
732 myTabs->addTab( mySingleEdgeSelectors, MeasureGUI_CreateDimensionDlg::tr( "EDGE_LENGTH" ) );
733 myTabs->addTab( myTwoPointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "TWO_POINTS" ) );
734 myTabs->addTab( myParallelEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "PARALLEL_EDGES" ) );
736 mySingleEdgeSelectors->PushButton1->setIcon( mySelectorIcon );
737 mySingleEdgeSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE" ) );
738 mySingleEdgeSelectors->LineEdit1->setReadOnly( true );
740 myTwoPointsSelectors->PushButton1->setIcon( mySelectorIcon );
741 myTwoPointsSelectors->PushButton2->setIcon( mySelectorIcon );
742 myTwoPointsSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
743 myTwoPointsSelectors->TextLabel2->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
744 myTwoPointsSelectors->LineEdit1->setReadOnly( true );
745 myTwoPointsSelectors->LineEdit2->setReadOnly( true );
747 myParallelEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
748 myParallelEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
749 myParallelEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
750 myParallelEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
751 myParallelEdgesSelectors->LineEdit1->setReadOnly( true );
752 myParallelEdgesSelectors->LineEdit2->setReadOnly( true );
754 QVBoxLayout* aLayout = new QVBoxLayout( this );
756 aLayout->setMargin( 0 );
757 aLayout->addWidget( myTabs );
759 SelectionModes anEdgeModes;
760 SelectionModes aPointModes;
761 anEdgeModes << TopAbs_EDGE;
762 aPointModes << TopAbs_VERTEX;
764 SetTabWidget( myTabs );
765 RegisterSelector( mySingleEdgeSelectors->LineEdit1, mySingleEdgeSelectors->PushButton1, anEdgeModes, TabID_SingleEdge );
766 RegisterSelector( myTwoPointsSelectors->LineEdit1, myTwoPointsSelectors->PushButton1, aPointModes, TabID_TwoPoints );
767 RegisterSelector( myTwoPointsSelectors->LineEdit2, myTwoPointsSelectors->PushButton2, aPointModes, TabID_TwoPoints );
768 RegisterSelector( myParallelEdgesSelectors->LineEdit1, myParallelEdgesSelectors->PushButton1, anEdgeModes, TabID_ParallelEdges );
769 RegisterSelector( myParallelEdgesSelectors->LineEdit2, myParallelEdgesSelectors->PushButton2, anEdgeModes, TabID_ParallelEdges );
772 //=================================================================================
773 // class : MeasureGUI_CreateDimensionDlg::DiameterPane
774 // purpose : Constructor
775 //=================================================================================
776 MeasureGUI_CreateDimensionDlg::DiameterPane::DiameterPane( QWidget* theParent )
777 : BaseSelectorPane( theParent )
779 myShapeSelector = new MeasureGUI_1Sel_Frame( this );
780 myShapeSelector->PushButton1->setIcon( mySelectorIcon );
781 myShapeSelector->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "OBJECT" ) );
783 QVBoxLayout* aLayout = new QVBoxLayout( this );
785 aLayout->setMargin( 0 );
786 aLayout->addWidget( myShapeSelector );
788 SelectionModes aDiamModes;
789 aDiamModes << TopAbs_SHAPE
793 RegisterSelector( myShapeSelector->LineEdit1, myShapeSelector->PushButton1, aDiamModes );
796 //=================================================================================
797 // class : MeasureGUI_CreateDimensionDlg::AnglePane
798 // purpose : Constructor
799 //=================================================================================
800 MeasureGUI_CreateDimensionDlg::AnglePane::AnglePane( QWidget* theParent )
801 : BaseSelectorPane( theParent )
803 myTabs = new QTabWidget( this );
804 myTwoEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
805 myThreePointsSelectors = new MeasureGUI_3Sel_Frame( this );
807 myTabs->addTab( myTwoEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "TWO_EDGES" ) );
808 myTabs->addTab( myThreePointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "THREE_POINTS" ) );
810 myTwoEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
811 myTwoEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
812 myTwoEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
813 myTwoEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
815 myThreePointsSelectors->PushButton1->setIcon( mySelectorIcon );
816 myThreePointsSelectors->PushButton2->setIcon( mySelectorIcon );
817 myThreePointsSelectors->PushButton3->setIcon( mySelectorIcon );
818 myThreePointsSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
819 myThreePointsSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
820 myThreePointsSelectors->TextLabel3 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_3" ) );
822 QVBoxLayout* aLayout = new QVBoxLayout( this );
824 aLayout->setMargin( 0 );
825 aLayout->addWidget( myTabs );
827 SelectionModes anEdgeModes;
828 SelectionModes aPointModes;
829 anEdgeModes << TopAbs_EDGE;
830 aPointModes << TopAbs_VERTEX;
832 SetTabWidget( myTabs );
833 RegisterSelector( myTwoEdgesSelectors->LineEdit1, myTwoEdgesSelectors->PushButton1, anEdgeModes, TabID_TwoEdges );
834 RegisterSelector( myTwoEdgesSelectors->LineEdit2, myTwoEdgesSelectors->PushButton2, anEdgeModes, TabID_TwoEdges );
835 RegisterSelector( myThreePointsSelectors->LineEdit1, myThreePointsSelectors->PushButton1, aPointModes, TabID_ThreePoints );
836 RegisterSelector( myThreePointsSelectors->LineEdit2, myThreePointsSelectors->PushButton2, aPointModes, TabID_ThreePoints );
837 RegisterSelector( myThreePointsSelectors->LineEdit3, myThreePointsSelectors->PushButton3, aPointModes, TabID_ThreePoints );
840 /* ------------------------------------------------------------------------------*
842 * Argument shape selection logics *
844 * ------------------------------------------------------------------------------*/
846 //=================================================================================
847 // class : MeasureGUI_CreateDimensionDlg::BaseSelectorPane
848 // purpose : Constructor
849 //=================================================================================
850 MeasureGUI_CreateDimensionDlg::BaseSelectorPane::BaseSelectorPane( QWidget* theParent )
851 : QWidget( theParent ),
854 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
855 mySelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
858 //=================================================================================
859 // function : BaseSelectorPane::Reset
860 // purpose : Reset selector line edits and controls
861 //=================================================================================
862 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::Reset( bool theOpenDefaultTab )
864 if ( theOpenDefaultTab && myTabs )
866 myTabs->setCurrentIndex( 0 );
869 QMap< int, QList<QLineEdit*> >::iterator aTabsIt = mySelectors.begin();
870 for ( ; aTabsIt != mySelectors.end(); ++aTabsIt )
872 QList<QLineEdit*>& aSelectors = *aTabsIt;
873 QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
874 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
876 QLineEdit* aSelector = *aSelectorIt;
878 mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
882 QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
884 mySelectionButtons[aFirstSelector]->click();
887 //=================================================================================
888 // function : BaseSelectorPane::ActiveTab
889 // purpose : Returns active tab
890 //=================================================================================
891 int MeasureGUI_CreateDimensionDlg::BaseSelectorPane::ActiveTab() const
893 return myTabs != NULL ? myTabs->currentIndex() : 0;
896 //=================================================================================
897 // function : BaseSelectorPane::SelectionIntoArgument
898 // purpose : Populates current selector
899 //=================================================================================
900 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SelectionIntoArguments( const GEOM::GeomObjPtr& theSelected )
902 if ( theSelected.isNull() )
904 myCurrentSelector->clear();
905 mySelectedShapes[myCurrentSelector] = GEOM::GeomObjPtr();
909 QString aName = GEOMBase::GetName( theSelected.get() );
911 myCurrentSelector->setText( aName );
913 mySelectedShapes[myCurrentSelector] = theSelected;
915 // find next empty selector (iterate to the last)
916 QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
917 int aCurrentPos = aCurrentSelectors.indexOf( myCurrentSelector );
918 int aSelectorIt = aCurrentPos + 1;
919 for ( ; aSelectorIt != aCurrentSelectors.size(); ++aSelectorIt )
921 QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
922 if ( mySelectedShapes[aNextSelector].isNull() )
924 mySelectionButtons[aNextSelector]->click();
929 // find next empty selector (itearte from the first)
931 for ( ; aSelectorIt != aCurrentPos; ++aSelectorIt )
933 QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
934 if ( mySelectedShapes[aNextSelector].isNull() )
936 mySelectionButtons[aNextSelector]->click();
941 // stop selector switching
942 myCurrentSelector->setEnabled( false );
943 mySelectionButtons[myCurrentSelector]->setDown( false );
945 // every selector is populated - construct presentation
946 emit StopSelection();
947 emit SelectionDone();
950 //=================================================================================
951 // function : BaseSelectorPane::GetSelection
953 //=================================================================================
954 GEOM::GeomObjPtr MeasureGUI_CreateDimensionDlg::BaseSelectorPane::GetSelection( QLineEdit* theSelector ) const
956 return mySelectedShapes[theSelector];
959 //=================================================================================
960 // function : BaseSelectorPane::OnSelectorClicked
961 // purpose : Handle activation of selector controls pair {edit, button}
962 //=================================================================================
963 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnSelectorClicked()
965 // clicked "selector" button
966 QAbstractButton* aSender = qobject_cast<QAbstractButton*>( sender() );
972 // get "selector" controls on the active tab
973 QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
975 // iterate over controls on the tab and process them
976 for ( int aSelectorIt = 0; aSelectorIt < aCurrentSelectors.size(); ++aSelectorIt )
978 QLineEdit* aSelector = aCurrentSelectors[aSelectorIt];
979 QPushButton* aButton = mySelectionButtons[aSelector];
981 bool isClickedOnes = (aButton == aSender);
983 aSelector->setEnabled( isClickedOnes );
987 myCurrentSelector = aSelector;
988 myCurrentSelector->setFocus();
991 aButton->setDown( isClickedOnes );
994 emit StartSelection( mySelectionModes[myCurrentSelector] );
997 //=================================================================================
998 // function : BaseSelectorPane::OnTabChanged
1000 //=================================================================================
1001 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnTabChanged()
1003 QList<QLineEdit*>& aSelectors = mySelectors[ ActiveTab() ];
1004 QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
1005 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
1007 QLineEdit* aSelector = *aSelectorIt;
1011 mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
1014 QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
1016 mySelectionButtons[aFirstSelector]->click();
1021 //=================================================================================
1022 // function : BaseSelectorPane::SetTabWidget
1024 //=================================================================================
1025 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SetTabWidget( QTabWidget* theTabs )
1028 connect( myTabs, SIGNAL( currentChanged( int ) ), this, SLOT( OnTabChanged() ) );
1031 //=================================================================================
1032 // function : BaseSelectorPane::RegisterSelector
1034 //=================================================================================
1035 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::RegisterSelector( QLineEdit* theSelectorEdit,
1036 QPushButton* theSelectorButton,
1037 const SelectionModes& theSelectorModes,
1040 if ( !mySelectors.contains( theTab ) )
1042 mySelectors.insert( theTab, QList<QLineEdit*>() );
1044 mySelectors[theTab].append( theSelectorEdit );
1046 mySelectionButtons[theSelectorEdit] = theSelectorButton;
1047 mySelectionModes [theSelectorEdit] = theSelectorModes;
1049 connect( theSelectorButton, SIGNAL( clicked() ), this, SLOT( OnSelectorClicked() ) );