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