]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_CreateDimensionDlg.cxx
Salome HOME
21854: Add persistent dimensions
[modules/geom.git] / src / MeasureGUI / MeasureGUI_CreateDimensionDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : MeasureGUI_CreateDimensionDlg.cxx
25 // Author : Anton POLETAEV, Open CASCADE S.A.S.
26
27 #include "MeasureGUI_CreateDimensionDlg.h"
28 #include "MeasureGUI_DimensionCreateTool.h"
29
30 #include <GEOM_Constants.h>
31 #include <GeometryGUI.h>
32 #include <GEOMBase.h>
33 #include <DlgRef.h>
34 #include <GEOMUtils.hxx>
35 #include <GEOMGUI_DimensionProperty.h>
36
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>
45 #include <SOCC_Prs.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>
52
53 #include <Aspect_PolygonOffsetMode.hxx>
54
55 //=================================================================================
56 // function : Constructor
57 // purpose  :
58 //=================================================================================
59 MeasureGUI_CreateDimensionDlg::MeasureGUI_CreateDimensionDlg( const GEOM::GeomObjPtr& theObj,
60                                                               GeometryGUI* theGUI,
61                                                               QWidget* theParent )
62 : GEOMBase_Skeleton( theGUI, theParent ),
63   myParentObj( theObj ),
64   myEditingViewer( NULL )
65 {
66   setWindowTitle( tr( "CREATE_DIMENSION_TITLE" ) );
67
68   // init "dimension type" radio buttons
69   QAbstractButton* aTypeButtonLength   = mainFrame()->RadioButton1;
70   QAbstractButton* aTypeButtonDiameter = mainFrame()->RadioButton2;
71   QAbstractButton* aTypeButtonAngle    = mainFrame()->RadioButton3;
72
73   mainFrame()->GroupConstructors->setTitle( tr( "DIMENSIONS" ) );
74   aTypeButtonDiameter->setText( tr( "DIAMETER" ) );
75   aTypeButtonLength->setText( tr( "LENGTH" ) );
76   aTypeButtonAngle->setText( tr( "ANGLE" ) );
77
78   // construct "arguments" pane
79   QGroupBox*   aGroupArgs       = new QGroupBox( tr( "ARGUMENTS" ), centralWidget() );
80   QVBoxLayout* aGroupArgsLayout = new QVBoxLayout( aGroupArgs );
81
82   myLengthArgs   = new LengthPane  ( centralWidget() );
83   myDiameterArgs = new DiameterPane( centralWidget() );
84   myAngleArgs    = new AnglePane   ( centralWidget() );
85
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>& ) ) );
93
94   connect( myLengthArgs,   SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
95   connect( myDiameterArgs, SIGNAL( StopSelection() ), SLOT( OnStopSelection() ) );
96   connect( myAngleArgs,    SIGNAL( StopSelection() ), SLOT( OnStopSelection( ) ) );
97
98   connect( myLengthArgs,   SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
99   connect( myDiameterArgs, SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
100   connect( myAngleArgs,    SIGNAL( SelectionDone() ), SLOT( OnSelectionDone() ) );
101
102   aGroupArgsLayout->addWidget( myLengthArgs );
103   aGroupArgsLayout->addWidget( myDiameterArgs );
104   aGroupArgsLayout->addWidget( myAngleArgs );
105
106   // construct main layout
107   QVBoxLayout* aCustomWidLayout = new QVBoxLayout( centralWidget() );
108   aCustomWidLayout->setMargin( 0 ); 
109   aCustomWidLayout->setSpacing( 6 );
110   aCustomWidLayout->addWidget( aGroupArgs );
111
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) ) );
116
117   // signals and slots connections
118   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
119   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
120
121   // map functional signals
122   myRBGroup->setId( aTypeButtonLength,   TypeButtonID_Length );
123   myRBGroup->setId( aTypeButtonDiameter, TypeButtonID_Diameter );
124   myRBGroup->setId( aTypeButtonAngle,    TypeButtonID_Angle );
125
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() ) );
130
131   myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent );
132
133   myDiameterArgs->setVisible( false );
134   myAngleArgs   ->setVisible( false );
135   myLengthArgs  ->setVisible( true );
136
137   myRBGroup->button( TypeButtonID_Length )->click();
138
139   Init();
140
141   setHelpFileName("add_dimension_page.html");
142 }
143
144 //=================================================================================
145 // function : Destructor
146 // purpose  :
147 //=================================================================================
148 MeasureGUI_CreateDimensionDlg::~MeasureGUI_CreateDimensionDlg()
149 {
150 }
151
152 //=================================================================================
153 // function : ActiveArgs
154 // purpose  : 
155 //=================================================================================
156 MeasureGUI_CreateDimensionDlg::BaseSelectorPane* MeasureGUI_CreateDimensionDlg::ActiveArgs()
157 {
158   switch ( getConstructorId() )
159   {
160     case TypeButtonID_Length   : return myLengthArgs;
161     case TypeButtonID_Diameter : return myDiameterArgs;
162     case TypeButtonID_Angle    : return myAngleArgs;
163     default:
164       return NULL;
165   }
166 }
167
168 //=================================================================================
169 // function : GenerateName
170 // purpose  : 
171 //=================================================================================
172 QString MeasureGUI_CreateDimensionDlg::GenerateName( const QString& thePrefix )
173 {
174   QRegExp anExtractIds( "^" + thePrefix + "_([0-9]+)$" );
175
176   QSet<int> anOccupiedIds;
177
178   GEOMGUI_DimensionProperty aProp =
179     getStudy()->getObjectProperty( GEOM::sharedPropertiesId(),
180                                    myParentObj->GetStudyEntry(),
181                                    GEOM::propertyName( GEOM::Dimensions ),
182                                    QVariant() )
183                                    .value<GEOMGUI_DimensionProperty>();
184
185   // get names and convert to QStrings to perform index matching
186   for( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
187   {
188     if ( anExtractIds.indexIn( aProp.GetName( anIt ) ) == -1 )
189     {
190       continue;
191     }
192
193     anOccupiedIds.insert( anExtractIds.cap( 1 ).toInt() );
194   }
195
196   int aSearchId = 1;
197   while ( true )
198   {
199     if ( !anOccupiedIds.contains( aSearchId ) )
200     {
201       break;
202     }
203
204     aSearchId++;
205   }
206
207   return QString( thePrefix + "_%1" ).arg( aSearchId );
208 }
209
210 //=================================================================================
211 // function : ConstructTypeChanged
212 // purpose  : 
213 //=================================================================================
214 void MeasureGUI_CreateDimensionDlg::ConstructTypeChanged( int theType )
215 {
216   ActiveArgs()->Reset();
217
218   updateGeometry();
219
220   QString aName;
221   switch ( theType )
222   {
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;
226   }
227
228   myMainFrame->ResultName->setText( aName );
229
230   StopLocalEditing();
231   erasePreview();
232
233   updateGeometry();
234   resize( minimumSizeHint() );
235 }
236
237 //=================================================================================
238 // function : OnArgumentTabChanged
239 // purpose  : 
240 //=================================================================================
241 void MeasureGUI_CreateDimensionDlg::OnArgumentTabChanged()
242 {
243   StopLocalEditing();
244   erasePreview();
245 }
246
247 //=================================================================================
248 // function : OnStartSelection
249 // purpose  :
250 //=================================================================================
251 void MeasureGUI_CreateDimensionDlg::OnStartSelection( const QList<TopAbs_ShapeEnum>& theModes )
252 {
253   OnStopSelection();
254
255   StopLocalEditing();
256
257   QList<TopAbs_ShapeEnum>::const_iterator aModeIt = theModes.constBegin();
258   for ( ; aModeIt != theModes.constEnd(); ++aModeIt )
259   {
260     localSelection( myParentObj.get(), *aModeIt );
261   }
262
263   mySelectionModes = theModes;
264
265   connect( myGeomGUI->getApp()->selectionMgr(),
266            SIGNAL( currentSelectionChanged() ),
267            SLOT( SelectionIntoArgument() ) );
268 }
269
270 //=================================================================================
271 // function : OnStopSelection
272 // purpose  :
273 //=================================================================================
274 void MeasureGUI_CreateDimensionDlg::OnStopSelection()
275 {
276   globalSelection();
277
278   disconnect( myGeomGUI->getApp()->selectionMgr(),
279               SIGNAL( currentSelectionChanged() ),
280               this,
281               SLOT( SelectionIntoArgument() ) );
282 }
283
284 //=================================================================================
285 // function : SelectionIntoArgument
286 // purpose  : Handle model selection by active selector pane
287 //=================================================================================
288 void MeasureGUI_CreateDimensionDlg::SelectionIntoArgument()
289 {
290   LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
291   SALOME_ListIO aSelection;
292   aSelectionMgr->selectedObjects( aSelection );
293
294   if ( aSelection.Extent() != 1 )
295   {
296     ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
297     return;
298   }
299
300   GEOM::GeomObjPtr aSelected = getSelected( mySelectionModes );
301   if ( aSelected.isNull() )
302   {
303     ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
304     return;
305   }
306
307   GEOM::GeomObjPtr aSelectedMain = 
308     !aSelected->IsMainShape() 
309       ? aSelected->GetMainShape() 
310       : GEOM::GeomObjPtr();
311
312   if ( myParentObj != aSelected && myParentObj != aSelectedMain )
313   {
314     ActiveArgs()->SelectionIntoArguments( GEOM::GeomObjPtr() );
315     return;
316   }
317
318   StopLocalEditing();
319
320   erasePreview();
321
322   ActiveArgs()->SelectionIntoArguments( aSelected );
323 }
324
325 //=================================================================================
326 // function : OnSelectionDone
327 // purpose  :
328 //=================================================================================
329 void MeasureGUI_CreateDimensionDlg::OnSelectionDone()
330 {
331   // create new dimension presentation
332   myDimension = CreateDimension();
333
334   if ( myDimension.IsNull() )
335   {
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" ) );
340
341     ActiveArgs()->Reset();
342
343     return;
344   }
345
346   // show preview of dimension object
347   SUIT_ViewWindow* aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
348
349   SOCC_Prs* aSalomePrs = dynamic_cast<SOCC_Prs*>( ( (SOCC_Viewer*)( aViewWindow->getViewManager()->getViewModel() ) )->CreatePrs( 0 ) );
350
351   aSalomePrs->AddObject( myDimension );
352
353   displayPreview( aSalomePrs );
354
355   StartLocalEditing();
356 }
357
358 //=================================================================================
359 // function : ClickOnOk
360 // purpose  : 
361 //=================================================================================
362 void MeasureGUI_CreateDimensionDlg::ClickOnOk()
363 {
364   setIsApplyAndClose( true );
365   if ( ClickOnApply() )
366   {
367     ClickOnCancel();
368   }
369 }
370
371 //=================================================================================
372 // function : ClickOnApply
373 // purpose  : 
374 //=================================================================================
375 bool MeasureGUI_CreateDimensionDlg::ClickOnApply()
376 {
377   StopLocalEditing();
378
379   if ( myDimension.IsNull() )
380   {
381     return true;
382   }
383
384   if ( !AddDimensionToOwner() )
385   {
386     return false;
387   }
388
389   redisplay( myParentObj.get() );
390
391   if ( !isApplyAndClose() )
392   {
393     Init();
394   }
395
396   return true;
397 }
398
399 //=================================================================================
400 // function : StartLocalEditing
401 // purpose  : 
402 //=================================================================================
403 void MeasureGUI_CreateDimensionDlg::StartLocalEditing()
404 {
405   StopLocalEditing();
406
407   myDimensionInteractor->Enable();
408
409   if ( myDimension.IsNull() )
410   {
411     return;
412   }
413
414   SalomeApp_Application* anApp = myGeomGUI->getApp();
415
416   SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
417
418   if ( aViewMgr->getType() != OCCViewer_Viewer::Type() )
419   {
420     return;
421   }
422
423   SOCC_Viewer* anOCCViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
424
425   myEditingViewer = anOCCViewer;
426   if ( !myEditingViewer )
427   {
428     return;
429   }
430
431   Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
432   Handle(V3d_Viewer)             aViewer3d    = myEditingViewer->getViewer3d();
433
434   aViewer3d->AddZLayer( myEditingLayer );
435
436   anAISContext->OpenLocalContext( Standard_False, Standard_False );
437   anAISContext->Load( myDimension, AIS_DSM_All );
438   anAISContext->SetZLayer( myDimension, myEditingLayer );
439   anAISContext->Activate( myDimension, AIS_DSM_Line );
440   anAISContext->Activate( myDimension, AIS_DSM_Text );
441   anAISContext->Redisplay( myDimension );
442 }
443
444 //=================================================================================
445 // function : StopLocalEditing
446 // purpose  : 
447 //=================================================================================
448 void MeasureGUI_CreateDimensionDlg::StopLocalEditing()
449 {
450   myDimensionInteractor->Disable();
451
452   if ( !myEditingViewer )
453   {
454     return;
455   }
456
457   Handle(AIS_InteractiveContext) anAISContext = myEditingViewer->getAISContext();
458   Handle(V3d_Viewer)             aViewer3d    = myEditingViewer->getViewer3d();
459
460   aViewer3d->RemoveZLayer( myEditingLayer );
461   anAISContext->CloseLocalContext();
462
463   myEditingViewer = NULL;
464 }
465
466 //=================================================================================
467 // function : Init
468 // purpose  : 
469 //=================================================================================
470 void MeasureGUI_CreateDimensionDlg::Init()
471 {
472   myDimension = NULL;
473
474   StopLocalEditing();
475
476   erasePreview();
477
478   myDiameterArgs->Reset();
479   myLengthArgs->Reset();
480   myAngleArgs->Reset();
481 }
482
483 //=================================================================================
484 // function : CreateDimensionPrs
485 // purpose  : 
486 //=================================================================================
487 Handle(AIS_Dimension) MeasureGUI_CreateDimensionDlg::CreateDimension()
488 {
489   Handle(AIS_Dimension) aDimensionIO;
490
491   // prepare dimension styling
492   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
493
494   QColor  aQColor       = aResMgr->colorValue  ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
495   int     aLineWidth    = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
496   double  aFontHeight   = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
497   double  anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
498   double  aDefFlyout    = aResMgr->doubleValue ( "Geometry", "dimensions_default_flyout", 20 );
499   bool    isUnitsShown  = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
500   QString aUnitsLength  = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
501   QString aUnitsAngle   = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
502
503   OCCViewer_ViewWindow* anActiveView = NULL;
504
505   SalomeApp_Application* anApp = myGeomGUI->getApp();
506
507   if ( anApp )
508   {
509     OCCViewer_ViewManager* aViewMgr = (OCCViewer_ViewManager*) anApp->getViewManager( OCCViewer_Viewer::Type(), false );
510     if ( aViewMgr )
511     {
512       anActiveView = (OCCViewer_ViewWindow*) aViewMgr->getActiveView();
513     }
514   }
515
516   MeasureGUI_DimensionCreateTool aTool;
517
518   aTool.Settings.DefaultFlyout = aDefFlyout;
519   aTool.Settings.ActiveView    = anActiveView ? anActiveView->getViewPort()->getView() : NULL;
520
521   switch ( getConstructorId() )
522   {
523     // create length dimension
524     case TypeButtonID_Length :
525     {
526       LengthPane* aLengthPane = qobject_cast<LengthPane*>( ActiveArgs() );
527
528       switch (aLengthPane->ActiveTab())
529       {
530         case LengthPane::TabID_SingleEdge:
531         {
532           const GEOM::GeomObjPtr& anEdge = aLengthPane->GetSingleEdge();
533
534           aDimensionIO = aTool.LengthOnEdge( anEdge );
535           break;
536         }
537
538         case LengthPane::TabID_TwoPoints:
539         {
540           const GEOM::GeomObjPtr& aPoint1 = aLengthPane->GetPoint1();
541           const GEOM::GeomObjPtr& aPoint2 = aLengthPane->GetPoint2();
542
543           aDimensionIO = aTool.LengthByPoints( aPoint1, aPoint2 );
544           break;
545         }
546
547         case LengthPane::TabID_ParallelEdges:
548         {
549           const GEOM::GeomObjPtr& anEdge1 = aLengthPane->GetEdge1();
550           const GEOM::GeomObjPtr& anEdge2 = aLengthPane->GetEdge2();
551
552           aDimensionIO = aTool.LengthByParallelEdges( anEdge1, anEdge2 );
553           break;
554         }
555       }
556     }
557     break;
558
559     // create diameter dimension
560     case TypeButtonID_Diameter :
561     {
562       DiameterPane* aDiameterPane = qobject_cast<DiameterPane*>( ActiveArgs() );
563
564       const GEOM::GeomObjPtr& aShape = aDiameterPane->GetShape();
565
566       aDimensionIO = aTool.Diameter( aShape );
567       break;
568     }
569
570     // create angle dimension
571     case TypeButtonID_Angle :
572     {
573       AnglePane* anAnglePane = qobject_cast<AnglePane*>( ActiveArgs() );
574
575       switch (ActiveArgs()->ActiveTab())
576       {
577         case AnglePane::TabID_TwoEdges:
578         {
579           const GEOM::GeomObjPtr& anEdge1 = anAnglePane->GetEdge1();
580           const GEOM::GeomObjPtr& anEdge2 = anAnglePane->GetEdge2();
581
582           aDimensionIO = aTool.AngleByTwoEdges( anEdge1, anEdge2 );
583           break;
584         }
585
586         case AnglePane::TabID_ThreePoints:
587         {
588           const GEOM::GeomObjPtr& aPoint1 = anAnglePane->GetPoint1();
589           const GEOM::GeomObjPtr& aPoint2 = anAnglePane->GetPoint2();
590           const GEOM::GeomObjPtr& aPoint3 = anAnglePane->GetPoint3();
591
592           aDimensionIO = aTool.AngleByThreePoints( aPoint1, aPoint2, aPoint3 );
593           break;
594         }
595       }
596       break;
597     }
598   }
599
600   if ( aDimensionIO.IsNull() )
601   {
602     return NULL;
603   }
604
605   Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
606
607   Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
608
609   aStyle->SetCommonColor( aColor );
610   aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
611   aStyle->MakeText3d( Standard_True );
612   aStyle->MakeTextShaded( Standard_True );
613   aStyle->SetExtensionSize( aFontHeight * 0.5 );
614   aStyle->TextAspect()->SetHeight( aFontHeight );
615   aStyle->ArrowAspect()->SetLength( anArrowLength );
616   aStyle->LineAspect()->SetWidth( aLineWidth );
617
618   if ( aDimensionIO->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
619   {
620     // show degree symbol for dimension instead of label "deg"
621     if ( aUnitsAngle == "deg" )
622     {
623       aDimensionIO->SetSpecialSymbol(0xB0);
624       aDimensionIO->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
625       aStyle->MakeUnitsDisplayed(Standard_False);
626     }
627     else
628     {
629       aDimensionIO->SetDisplaySpecialSymbol(AIS_DSS_No);
630       aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
631     }
632   }
633   else
634   {
635     aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
636   }
637
638   aDimensionIO->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
639   aDimensionIO->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
640   aDimensionIO->SetDimensionAspect( aStyle );
641   aDimensionIO->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
642
643   return aDimensionIO;
644 }
645
646 //=================================================================================
647 // class    : AddDimensionToOwner
648 // purpose  : 
649 //=================================================================================
650 bool MeasureGUI_CreateDimensionDlg::AddDimensionToOwner()
651 {
652   if ( myDimension.IsNull() )
653   {
654     return false;
655   }
656
657   gp_Ax3 aLCS;
658   TopoDS_Shape anParentSh;
659   if ( GEOMBase::GetShape( myParentObj.get(), anParentSh ) )
660   {
661     aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
662   }
663
664   QString aName = getNewObjectName();
665
666   SalomeApp_Study* aStudy = getStudy();
667
668   GEOMGUI_DimensionProperty aProp =
669     aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
670                                myParentObj->GetStudyEntry(),
671                                GEOM::propertyName( GEOM::Dimensions ),
672                                QVariant() )
673                                .value<GEOMGUI_DimensionProperty>();
674
675   // append new dimension record to data
676   aProp.AddRecord( myDimension, aLCS );
677   aProp.SetName( aProp.GetNumber() - 1, aName );
678   aProp.SetVisible( aProp.GetNumber() - 1, true );
679
680   // store modified property data
681   aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
682                              myParentObj->GetStudyEntry(),
683                              GEOM::propertyName( GEOM::Dimensions ),
684                              aProp );
685
686   return true;
687 }
688
689 /* ------------------------------------------------------------------------------*
690  *                                                                               *
691  *                    Argument shape selector layout                             *
692  *                                                                               *
693  * ------------------------------------------------------------------------------*/
694
695 //=================================================================================
696 // class    : MeasureGUI_CreateDimensionDlg::LengthPane
697 // purpose  : Constructor
698 //=================================================================================
699 MeasureGUI_CreateDimensionDlg::LengthPane::LengthPane( QWidget* theParent )
700 : BaseSelectorPane( theParent )
701 {
702   myTabs                   = new QTabWidget( this );
703   mySingleEdgeSelectors    = new MeasureGUI_1Sel_Frame( this );
704   myTwoPointsSelectors     = new MeasureGUI_2Sel_Frame( this );
705   myParallelEdgesSelectors = new MeasureGUI_2Sel_Frame( this );
706
707   myTabs->addTab( mySingleEdgeSelectors,    MeasureGUI_CreateDimensionDlg::tr( "EDGE_LENGTH" ) );
708   myTabs->addTab( myTwoPointsSelectors,     MeasureGUI_CreateDimensionDlg::tr( "TWO_POINTS" ) );
709   myTabs->addTab( myParallelEdgesSelectors, MeasureGUI_CreateDimensionDlg::tr( "PARALLEL_EDGES" ) );
710
711   mySingleEdgeSelectors->PushButton1->setIcon( mySelectorIcon );
712   mySingleEdgeSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE" ) );
713   mySingleEdgeSelectors->LineEdit1->setReadOnly( true );
714
715   myTwoPointsSelectors->PushButton1->setIcon( mySelectorIcon );
716   myTwoPointsSelectors->PushButton2->setIcon( mySelectorIcon );
717   myTwoPointsSelectors->TextLabel1->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
718   myTwoPointsSelectors->TextLabel2->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
719   myTwoPointsSelectors->LineEdit1->setReadOnly( true );
720   myTwoPointsSelectors->LineEdit2->setReadOnly( true );
721
722   myParallelEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
723   myParallelEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
724   myParallelEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
725   myParallelEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
726   myParallelEdgesSelectors->LineEdit1->setReadOnly( true );
727   myParallelEdgesSelectors->LineEdit2->setReadOnly( true );
728
729   QVBoxLayout* aLayout = new QVBoxLayout( this );
730
731   aLayout->setMargin( 0 );
732   aLayout->addWidget( myTabs );
733
734   SelectionModes anEdgeModes;
735   SelectionModes aPointModes;
736   anEdgeModes << TopAbs_EDGE;
737   aPointModes << TopAbs_VERTEX;
738
739   SetTabWidget( myTabs );
740   RegisterSelector( mySingleEdgeSelectors->LineEdit1,    mySingleEdgeSelectors->PushButton1,    anEdgeModes, TabID_SingleEdge );
741   RegisterSelector( myTwoPointsSelectors->LineEdit1,     myTwoPointsSelectors->PushButton1,     aPointModes, TabID_TwoPoints );
742   RegisterSelector( myTwoPointsSelectors->LineEdit2,     myTwoPointsSelectors->PushButton2,     aPointModes, TabID_TwoPoints );
743   RegisterSelector( myParallelEdgesSelectors->LineEdit1, myParallelEdgesSelectors->PushButton1, anEdgeModes, TabID_ParallelEdges );
744   RegisterSelector( myParallelEdgesSelectors->LineEdit2, myParallelEdgesSelectors->PushButton2, anEdgeModes, TabID_ParallelEdges );
745 }
746
747 //=================================================================================
748 // class    : MeasureGUI_CreateDimensionDlg::DiameterPane
749 // purpose  : Constructor
750 //=================================================================================
751 MeasureGUI_CreateDimensionDlg::DiameterPane::DiameterPane( QWidget* theParent )
752 : BaseSelectorPane( theParent )
753 {
754   myShapeSelector = new MeasureGUI_1Sel_Frame( this );
755   myShapeSelector->PushButton1->setIcon( mySelectorIcon );
756   myShapeSelector->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "OBJECT" ) );
757
758   QVBoxLayout* aLayout = new QVBoxLayout( this );
759
760   aLayout->setMargin( 0 );
761   aLayout->addWidget( myShapeSelector );
762
763   SelectionModes aDiamModes;
764   aDiamModes << TopAbs_SHAPE
765              << TopAbs_FACE
766              << TopAbs_EDGE;
767
768   RegisterSelector( myShapeSelector->LineEdit1, myShapeSelector->PushButton1, aDiamModes );
769 }
770
771 //=================================================================================
772 // class    : MeasureGUI_CreateDimensionDlg::AnglePane
773 // purpose  : Constructor
774 //=================================================================================
775 MeasureGUI_CreateDimensionDlg::AnglePane::AnglePane( QWidget* theParent )
776 : BaseSelectorPane( theParent )
777 {
778   myTabs                 = new QTabWidget( this );
779   myTwoEdgesSelectors    = new MeasureGUI_2Sel_Frame( this );
780   myThreePointsSelectors = new MeasureGUI_3Sel_Frame( this );
781
782   myTabs->addTab( myTwoEdgesSelectors,    MeasureGUI_CreateDimensionDlg::tr( "TWO_EDGES" ) );
783   myTabs->addTab( myThreePointsSelectors, MeasureGUI_CreateDimensionDlg::tr( "THREE_POINTS" ) );
784
785   myTwoEdgesSelectors->PushButton1->setIcon( mySelectorIcon );
786   myTwoEdgesSelectors->PushButton2->setIcon( mySelectorIcon );
787   myTwoEdgesSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_1" ) );
788   myTwoEdgesSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "EDGE_2" ) );
789
790   myThreePointsSelectors->PushButton1->setIcon( mySelectorIcon );
791   myThreePointsSelectors->PushButton2->setIcon( mySelectorIcon );
792   myThreePointsSelectors->PushButton3->setIcon( mySelectorIcon );
793   myThreePointsSelectors->TextLabel1 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_1" ) );
794   myThreePointsSelectors->TextLabel2 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_2" ) );
795   myThreePointsSelectors->TextLabel3 ->setText( MeasureGUI_CreateDimensionDlg::tr( "POINT_3" ) );
796
797   QVBoxLayout* aLayout = new QVBoxLayout( this );
798
799   aLayout->setMargin( 0 );
800   aLayout->addWidget( myTabs );
801
802   SelectionModes anEdgeModes;
803   SelectionModes aPointModes;
804   anEdgeModes << TopAbs_EDGE;
805   aPointModes << TopAbs_VERTEX;
806
807   SetTabWidget( myTabs );
808   RegisterSelector( myTwoEdgesSelectors->LineEdit1,    myTwoEdgesSelectors->PushButton1,    anEdgeModes, TabID_TwoEdges );
809   RegisterSelector( myTwoEdgesSelectors->LineEdit2,    myTwoEdgesSelectors->PushButton2,    anEdgeModes, TabID_TwoEdges );
810   RegisterSelector( myThreePointsSelectors->LineEdit1, myThreePointsSelectors->PushButton1, aPointModes, TabID_ThreePoints );
811   RegisterSelector( myThreePointsSelectors->LineEdit2, myThreePointsSelectors->PushButton2, aPointModes, TabID_ThreePoints );
812   RegisterSelector( myThreePointsSelectors->LineEdit3, myThreePointsSelectors->PushButton3, aPointModes, TabID_ThreePoints );
813 }
814
815 /* ------------------------------------------------------------------------------*
816  *                                                                               *
817  *                   Argument shape selection logics                             *
818  *                                                                               *
819  * ------------------------------------------------------------------------------*/
820
821 //=================================================================================
822 // class    : MeasureGUI_CreateDimensionDlg::BaseSelectorPane
823 // purpose  : Constructor
824 //=================================================================================
825 MeasureGUI_CreateDimensionDlg::BaseSelectorPane::BaseSelectorPane( QWidget* theParent )
826 : QWidget( theParent ),
827   myTabs( NULL )
828 {
829   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
830   mySelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
831 }
832
833 //=================================================================================
834 // function : BaseSelectorPane::Reset
835 // purpose  : Reset selector line edits and controls
836 //=================================================================================
837 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::Reset( bool theOpenDefaultTab )
838 {
839   if ( theOpenDefaultTab && myTabs )
840   {
841     myTabs->setCurrentIndex( 0 );
842   }
843
844   QMap< int, QList<QLineEdit*> >::iterator aTabsIt = mySelectors.begin();
845   for ( ; aTabsIt != mySelectors.end(); ++aTabsIt )
846   {
847     QList<QLineEdit*>& aSelectors = *aTabsIt;
848     QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
849     for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
850     {
851       QLineEdit* aSelector = *aSelectorIt;
852       aSelector->clear();
853       mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
854     }
855   }
856
857   QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
858
859   mySelectionButtons[aFirstSelector]->click();
860 }
861
862 //=================================================================================
863 // function : BaseSelectorPane::ActiveTab
864 // purpose  : Returns active tab
865 //=================================================================================
866 int MeasureGUI_CreateDimensionDlg::BaseSelectorPane::ActiveTab() const
867 {
868   return myTabs != NULL ? myTabs->currentIndex() : 0;
869 }
870
871 //=================================================================================
872 // function : BaseSelectorPane::SelectionIntoArgument
873 // purpose  : Populates current selector
874 //=================================================================================
875 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SelectionIntoArguments( const GEOM::GeomObjPtr& theSelected )
876 {
877   if ( theSelected.isNull() )
878   {
879     myCurrentSelector->clear();
880     mySelectedShapes[myCurrentSelector] = GEOM::GeomObjPtr();
881     return;
882   }
883
884   QString aName = GEOMBase::GetName( theSelected.get() );
885
886   myCurrentSelector->setText( aName );
887
888   mySelectedShapes[myCurrentSelector] = theSelected;
889
890   // find next empty selector (iterate to the last)
891   QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
892   int aCurrentPos = aCurrentSelectors.indexOf( myCurrentSelector );
893   int aSelectorIt = aCurrentPos + 1;
894   for ( ; aSelectorIt != aCurrentSelectors.size(); ++aSelectorIt )
895   {
896     QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
897     if ( mySelectedShapes[aNextSelector].isNull() )
898     {
899       mySelectionButtons[aNextSelector]->click();
900       return;
901     }
902   }
903
904   // find next empty selector (itearte from the first)
905   aSelectorIt = 0;
906   for ( ; aSelectorIt != aCurrentPos; ++aSelectorIt )
907   {
908     QLineEdit* aNextSelector = aCurrentSelectors[aSelectorIt];
909     if ( mySelectedShapes[aNextSelector].isNull() )
910     {
911       mySelectionButtons[aNextSelector]->click();
912       return;
913     }
914   }
915
916   // stop selector switching
917   myCurrentSelector->setEnabled( false );
918   mySelectionButtons[myCurrentSelector]->setDown( false );
919
920   // every selector is populated - construct presentation
921   emit StopSelection();
922   emit SelectionDone();
923 }
924
925 //=================================================================================
926 // function : BaseSelectorPane::GetSelection
927 // purpose  : 
928 //=================================================================================
929 GEOM::GeomObjPtr MeasureGUI_CreateDimensionDlg::BaseSelectorPane::GetSelection( QLineEdit* theSelector ) const
930 {
931   return mySelectedShapes[theSelector];
932 }
933
934 //=================================================================================
935 // function : BaseSelectorPane::OnSelectorClicked
936 // purpose  : Handle activation of selector controls pair {edit, button}
937 //=================================================================================
938 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnSelectorClicked()
939 {
940   // clicked "selector" button
941   QAbstractButton* aSender = qobject_cast<QAbstractButton*>( sender() );
942   if ( !aSender )
943   {
944     return;
945   }
946
947   // get "selector" controls on the active tab
948   QList<QLineEdit*>& aCurrentSelectors = mySelectors[ ActiveTab() ];
949
950   // iterate over controls on the tab and process them
951   for ( int aSelectorIt = 0; aSelectorIt < aCurrentSelectors.size(); ++aSelectorIt )
952   {
953     QLineEdit* aSelector = aCurrentSelectors[aSelectorIt];
954     QPushButton* aButton = mySelectionButtons[aSelector];
955
956     bool isClickedOnes = (aButton == aSender);
957
958     aSelector->setEnabled( isClickedOnes );
959
960     if ( isClickedOnes )
961     {
962       myCurrentSelector = aSelector;
963       myCurrentSelector->setFocus();
964     }
965
966     aButton->setDown( isClickedOnes );
967   }
968
969   emit StartSelection( mySelectionModes[myCurrentSelector] );
970 }
971
972 //=================================================================================
973 // function : BaseSelectorPane::OnTabChanged
974 // purpose  :
975 //=================================================================================
976 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::OnTabChanged()
977 {
978   QList<QLineEdit*>& aSelectors = mySelectors[ ActiveTab() ];
979   QList<QLineEdit*>::iterator aSelectorIt = aSelectors.begin();
980   for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
981   {
982     QLineEdit* aSelector = *aSelectorIt;
983
984     aSelector->clear();
985
986     mySelectedShapes[aSelector] = GEOM::GeomObjPtr();
987   }
988
989   QLineEdit* aFirstSelector = mySelectors[ ActiveTab() ].first();
990
991   mySelectionButtons[aFirstSelector]->click();
992
993   emit TabChanged();
994 }
995
996 //=================================================================================
997 // function : BaseSelectorPane::SetTabWidget
998 // purpose  :
999 //=================================================================================
1000 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::SetTabWidget( QTabWidget* theTabs )
1001 {
1002   myTabs = theTabs;
1003   connect( myTabs, SIGNAL( currentChanged( int ) ), this, SLOT( OnTabChanged() ) );
1004 }
1005
1006 //=================================================================================
1007 // function : BaseSelectorPane::RegisterSelector
1008 // purpose  :
1009 //=================================================================================
1010 void MeasureGUI_CreateDimensionDlg::BaseSelectorPane::RegisterSelector( QLineEdit* theSelectorEdit,
1011                                                                         QPushButton* theSelectorButton,
1012                                                                         const SelectionModes& theSelectorModes,
1013                                                                         const int theTab )
1014 {
1015   if ( !mySelectors.contains( theTab ) )
1016   {
1017     mySelectors.insert( theTab, QList<QLineEdit*>() );
1018   }
1019   mySelectors[theTab].append( theSelectorEdit );
1020
1021   mySelectionButtons[theSelectorEdit] = theSelectorButton;
1022   mySelectionModes  [theSelectorEdit] = theSelectorModes;
1023
1024   connect( theSelectorButton, SIGNAL( clicked() ), this, SLOT( OnSelectorClicked() ) );
1025 }