1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_ManageDimensionsDlg.cxx
25 // Author : Anton POLETAEV, Open CASCADE S.A.S.
27 #include "MeasureGUI_ManageDimensionsDlg.h"
28 #include "MeasureGUI_CreateDimensionDlg.h"
29 #include "MeasureGUI_DimensionFilter.h"
31 #include <GEOMGUI_DimensionProperty.h>
32 #include <GEOMUtils.hxx>
33 #include <GEOMGUI_OCCSelector.h>
34 #include <GEOM_AISDimension.hxx>
35 #include <GEOM_Constants.h>
39 #include <SOCC_ViewModel.h>
41 #include <SalomeApp_Application.h>
42 #include <SalomeApp_Study.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <SUIT_ViewManager.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_MessageBox.h>
49 #include <AIS_ListOfInteractive.hxx>
50 #include <AIS_ListIteratorOfListOfInteractive.hxx>
51 #include <AIS_InteractiveContext.hxx>
52 #include <SelectMgr_Filter.hxx>
53 #include <SelectMgr_ListOfFilter.hxx>
54 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
56 #include <QTreeWidget>
57 #include <QPushButton>
59 #include <QVBoxLayout>
60 #include <QHBoxLayout>
63 //=================================================================================
64 // function : Constructor
66 //=================================================================================
67 MeasureGUI_ManageDimensionsDlg::MeasureGUI_ManageDimensionsDlg( GeometryGUI* theGUI, QWidget* theParent )
68 : GEOMBase_Skeleton( theGUI, theParent ),
69 myOperatedViewer( NULL ),
70 myCurrentSelection( Selection_None )
72 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
74 QPixmap aSelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
76 setWindowTitle( tr( "MANAGE_DIMENSIONS_TITLE" ) );
78 mainFrame()->GroupConstructors->setVisible( false );
79 mainFrame()->GroupBoxName->setVisible( false );
81 // construct object selector pane
82 myObjectSelector = new DlgRef_1Sel( centralWidget() );
83 myObjectSelector->TextLabel1->setText( tr( "OBJECT_LABEL" ) );
84 myObjectSelector->LineEdit1->setReadOnly( true );
85 myObjectSelector->PushButton1->setIcon( aSelectorIcon );
86 myObjectSelector->PushButton1->setCheckable( true );
88 // construct dimension list view pane
89 myDimensionView = new MeasureGUI_1TreeWidget_4Button( centralWidget() );
90 myDimensionView->GroupBox->setTitle( tr( "DIMENSIONS_GROUP" ) );
91 myDimensionView->PushButton1->setText( tr( "ADD_BTN" ) );
92 myDimensionView->PushButton2->setText( tr( "REMOVE_BTN" ) );
93 myDimensionView->PushButton3->setText( tr( "SHOW_ALL_BTN" ) );
94 myDimensionView->PushButton4->setText( tr( "HIDE_ALL_BTN" ) );
95 myDimensionView->TreeWidget->setMinimumHeight( 250 );
96 myDimensionView->setEnabled( false );
98 connect( myDimensionView->PushButton1, SIGNAL( clicked() ), SLOT( OnAdd() ) );
99 connect( myDimensionView->PushButton2, SIGNAL( clicked() ), SLOT( OnRemove() ) );
100 connect( myDimensionView->PushButton3, SIGNAL( clicked() ), SLOT( OnShowAll() ) );
101 connect( myDimensionView->PushButton4, SIGNAL( clicked() ), SLOT( OnHideAll() ) );
102 connect( myDimensionView->TreeWidget,
103 SIGNAL( itemChanged( QTreeWidgetItem*, int ) ),
104 SLOT( OnChangeItem( QTreeWidgetItem* ) ) );
105 connect( myDimensionView->TreeWidget,
106 SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
107 SLOT( OnSelectItem() ) );
109 // populate tree with top-level items
110 myDimensionView->TreeWidget->setHeaderItem( new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( QString() ) ) );
112 // construct main frame layout
113 QVBoxLayout* aMainLayout = new QVBoxLayout( centralWidget() );
114 aMainLayout->setMargin( 0 );
115 aMainLayout->addWidget( myObjectSelector, 0 );
116 aMainLayout->addWidget( myDimensionView, 1 );
118 // signals and slots connections
119 connect( myObjectSelector->PushButton1, SIGNAL( clicked() ), SLOT( StartObjectSelection() ) );
120 connect( buttonOk(), SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
121 connect( buttonApply(), SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
123 connect( this, SIGNAL( finished( int ) ), SLOT( OnFinish() ) );
125 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
126 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
128 myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent ),
130 SelectionIntoArgument( Selection_Object );
132 if ( myEditObject.isNull() )
134 myObjectSelector->PushButton1->click();
137 setHelpFileName("managing_dimensions_page.html");
140 //=================================================================================
141 // function : Destructor
143 //=================================================================================
144 MeasureGUI_ManageDimensionsDlg::~MeasureGUI_ManageDimensionsDlg()
149 //=================================================================================
150 // function : StartSelection
151 // purpose : Starts specific selection
152 //=================================================================================
153 void MeasureGUI_ManageDimensionsDlg::StartSelection( const Selection theSelection )
157 myCurrentSelection = theSelection;
159 if ( theSelection == Selection_Object && AllowedToCancelChanges() )
161 /* ----------------------------------------------- *
162 * selection of object *
163 * ------------------------------------------------ */
165 globalSelection( GEOM_ALLSHAPES );
166 connect( myGeomGUI->getApp()->selectionMgr(),
167 SIGNAL( currentSelectionChanged() ),
169 SLOT( OnSelection() ) );
171 else if ( theSelection == Selection_Dimension && !myEditObject.isNull() )
173 /* ----------------------------------------------- *
174 * selection of dimension *
175 * ------------------------------------------------ */
177 SalomeApp_Application* anApp = myGeomGUI->getApp();
183 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
184 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
189 myOperatedViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
193 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
195 anAISContext->ClearCurrents( Standard_False );
196 anAISContext->ClearSelected( Standard_False );
197 anAISContext->OpenLocalContext( Standard_True, Standard_False );
199 Handle(MeasureGUI_DimensionFilter) aFilter = new MeasureGUI_DimensionFilter( myEditObject->GetStudyEntry() );
201 anAISContext->AddFilter( aFilter );
203 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
205 QList<SUIT_Selector*> aSelectors;
206 aSelectionMgr->selectors( aSelectors );
207 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
208 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
210 SUIT_Selector* aSelector = *aSelectorIt;
212 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
213 if ( !aGeomSelector )
218 aGeomSelector->setEnabled( false );
221 connect( myOperatedViewer,
222 SIGNAL( selectionChanged() ),
224 SLOT( OnSelection() ) );
226 myDimensionInteractor->Enable();
228 connect( myDimensionInteractor,
229 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
231 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
233 anAISContext->UpdateCurrentViewer();
237 //=================================================================================
238 // function : StopObjectSelection
239 // purpose : Stops specific selection
240 //=================================================================================
241 void MeasureGUI_ManageDimensionsDlg::StopSelection()
243 if ( myCurrentSelection == Selection_Object )
245 /* ----------------------------------------------- *
246 * selection of object *
247 * ------------------------------------------------ */
249 myObjectSelector->PushButton1->setChecked( false );
250 disconnect( myGeomGUI->getApp()->selectionMgr(),
251 SIGNAL( currentSelectionChanged() ),
253 SLOT( OnSelection() ) );
255 else if ( myCurrentSelection == Selection_Dimension && myOperatedViewer )
257 /* ----------------------------------------------- *
258 * selection of dimension *
259 * ------------------------------------------------ */
261 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
263 anAISContext->CloseLocalContext();
265 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
267 QList<SUIT_Selector*> aSelectors;
268 aSelectionMgr->selectors( aSelectors );
269 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
270 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
272 SUIT_Selector* aSelector = *aSelectorIt;
274 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
275 if ( !aGeomSelector )
280 aGeomSelector->setEnabled( true );
283 disconnect( myOperatedViewer,
284 SIGNAL( selectionChanged() ),
286 SLOT( OnSelection() ) );
288 myDimensionInteractor->Disable();
290 disconnect( myDimensionInteractor,
291 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
293 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
296 myCurrentSelection = Selection_None;
301 //=================================================================================
302 // function : OnSelection
304 //=================================================================================
305 void MeasureGUI_ManageDimensionsDlg::OnSelection()
307 SelectionIntoArgument( myCurrentSelection );
310 //=================================================================================
311 // function : SelectionIntoArgument
313 //=================================================================================
314 void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theSelection )
316 if ( theSelection == Selection_Object )
318 /* ----------------------------------------------- *
319 * selection of object *
320 * ------------------------------------------------ */
322 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
323 SALOME_ListIO aSelection;
324 aSelectionMgr->selectedObjects( aSelection );
326 GEOM::GeomObjPtr aSelected;
328 if ( aSelection.Extent() == 1 )
330 aSelected = GEOMBase::ConvertIOinGEOMObject( aSelection.First() );
333 SetEditObject( aSelected );
334 StartSelection( Selection_Dimension );
336 else if ( theSelection == Selection_Dimension && myOperatedViewer )
338 /* ----------------------------------------------- *
339 * selection of dimension *
340 * ------------------------------------------------ */
342 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
344 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
346 // non-single selection is prohibited
347 if ( anAISContext->NbSelected() != 1 )
349 aDimensionList->setCurrentIndex( QModelIndex() );
353 anAISContext->InitSelected();
355 Handle(AIS_InteractiveObject) anAIS;
357 if ( anAISContext->HasOpenedContext() )
359 Handle(SelectMgr_EntityOwner) anAISOwner = anAISContext->SelectedOwner();
360 anAIS = Handle(AIS_InteractiveObject)::DownCast( anAISOwner->Selectable() );
364 anAIS = anAISContext->Current();
367 int aDimensionId = IdFromPrs( anAIS );
369 SelectInList( aDimensionId );
371 if ( aDimensionId >= 0 )
373 SelectInViewer( myOperatedViewer, aDimensionId );
378 //=================================================================================
381 //=================================================================================
382 void MeasureGUI_ManageDimensionsDlg::OnAdd()
384 QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
388 MeasureGUI_CreateDimensionDlg* aCreateDlg = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
390 connect( aCreateDlg, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
392 // this is necessary as the GEOMBase_Helper switches selection mode on destruction
393 connect( aCreateDlg, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
395 aCreateDlg->updateGeometry();
396 aCreateDlg->resize( aCreateDlg->minimumSizeHint() );
400 //=================================================================================
401 // function : OnRemove
403 //=================================================================================
404 void MeasureGUI_ManageDimensionsDlg::OnRemove()
406 int aDimensionId = IdFromItem( myDimensionView->TreeWidget->currentItem() );
407 if ( aDimensionId < 0 )
412 SalomeApp_Application* anApp = myGeomGUI->getApp();
418 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
424 // get property data to change
425 GEOMGUI_DimensionProperty aProp =
426 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
427 myEditObject->GetStudyEntry(),
428 GEOM::propertyName( GEOM::Dimensions ),
430 .value<GEOMGUI_DimensionProperty>();
432 aProp.RemoveRecord( aDimensionId );
434 // store modified property data
435 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
436 myEditObject->GetStudyEntry(),
437 GEOM::propertyName( GEOM::Dimensions ),
445 //=================================================================================
446 // function : OnChangeItem
448 //=================================================================================
449 void MeasureGUI_ManageDimensionsDlg::OnChangeItem( QTreeWidgetItem* theItem )
451 int aDimensionId = IdFromItem( theItem );
452 if ( aDimensionId < 0 )
457 SalomeApp_Application* anApp = myGeomGUI->getApp();
463 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
469 // get property data to change
470 GEOMGUI_DimensionProperty aProp =
471 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
472 myEditObject->GetStudyEntry(),
473 GEOM::propertyName( GEOM::Dimensions ),
475 .value<GEOMGUI_DimensionProperty>();
477 // change property data
478 bool isAnythingChanged = false;
480 QString aName = theItem->text( 0 );
481 if ( aProp.GetName( aDimensionId ) != aName )
483 isAnythingChanged = true;
484 aProp.SetName( aDimensionId, aName );
487 bool isVisible = theItem->checkState( 0 ) == Qt::Checked;
488 if ( aProp.IsVisible( aDimensionId ) != isVisible )
490 isAnythingChanged = true;
491 aProp.SetVisible( aDimensionId, isVisible );
494 // store property data
495 if ( !isAnythingChanged )
500 // store modified property data
501 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
502 myEditObject->GetStudyEntry(),
503 GEOM::propertyName( GEOM::Dimensions ),
509 //=================================================================================
510 // function : OnSelectItem
512 //=================================================================================
513 void MeasureGUI_ManageDimensionsDlg::OnSelectItem()
515 if ( !myOperatedViewer )
520 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
522 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );
525 //=================================================================================
526 // function : OnShowAll
528 //=================================================================================
529 void MeasureGUI_ManageDimensionsDlg::OnShowAll()
532 SalomeApp_Application* anApp = myGeomGUI->getApp();
538 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
544 // get property data to change
545 GEOMGUI_DimensionProperty aProp =
546 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
547 myEditObject->GetStudyEntry(),
548 GEOM::propertyName( GEOM::Dimensions ),
550 .value<GEOMGUI_DimensionProperty>();
552 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
554 bool isBlocked = aDimensionList->blockSignals( true );
556 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
558 aProp.SetVisible( anIt, true );
561 // store modified property data
562 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
563 myEditObject->GetStudyEntry(),
564 GEOM::propertyName( GEOM::Dimensions ),
571 aDimensionList->blockSignals( isBlocked );
574 //=================================================================================
575 // function : OnHideAll
577 //=================================================================================
578 void MeasureGUI_ManageDimensionsDlg::OnHideAll()
581 SalomeApp_Application* anApp = myGeomGUI->getApp();
587 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
593 // get property data to change
594 GEOMGUI_DimensionProperty aProp =
595 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
596 myEditObject->GetStudyEntry(),
597 GEOM::propertyName( GEOM::Dimensions ),
599 .value<GEOMGUI_DimensionProperty>();
601 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
603 bool isBlocked = aDimensionList->blockSignals( true );
605 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
607 aProp.SetVisible( anIt, false );
610 // store modified property data
611 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
612 myEditObject->GetStudyEntry(),
613 GEOM::propertyName( GEOM::Dimensions ),
620 aDimensionList->blockSignals( isBlocked );
623 //=================================================================================
624 // function : OnInteractionFinished
626 //=================================================================================
627 void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle(AIS_InteractiveObject) theIO )
629 // update property data
630 SalomeApp_Application* anApp = myGeomGUI->getApp();
636 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
643 TopoDS_Shape anParentSh;
644 if ( GEOMBase::GetShape( myEditObject.get(), anParentSh ) )
646 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
649 int aDimensionId = IdFromPrs( theIO );
651 // get property data to change
652 GEOMGUI_DimensionProperty aProp =
653 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
654 myEditObject->GetStudyEntry(),
655 GEOM::propertyName( GEOM::Dimensions ),
657 .value<GEOMGUI_DimensionProperty>();
659 aProp.SetRecord( aDimensionId, Handle(AIS_Dimension)::DownCast( theIO ), aLCS );
661 // store modified property data
662 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
663 myEditObject->GetStudyEntry(),
664 GEOM::propertyName( GEOM::Dimensions ),
668 //=================================================================================
669 // function : Suspend
671 //=================================================================================
672 void MeasureGUI_ManageDimensionsDlg::Suspend()
678 //=================================================================================
679 // function : Suspend
681 //=================================================================================
682 void MeasureGUI_ManageDimensionsDlg::Resume()
685 if ( !myEditObject.isNull() )
688 StartSelection( Selection_Dimension );
692 //=================================================================================
693 // function : ClickOnOk
695 //=================================================================================
696 void MeasureGUI_ManageDimensionsDlg::ClickOnOk()
698 setIsApplyAndClose( true );
699 if ( ClickOnApply() )
705 //=================================================================================
706 // function : ClickOnCancel
708 //=================================================================================
709 void MeasureGUI_ManageDimensionsDlg::ClickOnCancel()
711 if ( !AllowedToCancelChanges() )
716 GEOMBase_Skeleton::ClickOnCancel();
719 //=================================================================================
720 // function : ClickOnApply
722 //=================================================================================
723 bool MeasureGUI_ManageDimensionsDlg::ClickOnApply()
725 if ( myEditObject.isNull() )
730 SalomeApp_Application* anApp = myGeomGUI->getApp();
736 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
742 mySavedPropertyState =
743 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
744 myEditObject->GetStudyEntry(),
745 GEOM::propertyName( GEOM::Dimensions ),
747 .value<GEOMGUI_DimensionProperty>();
749 mySavedPropertyState.SaveToAttribute( aStudy, myEditObject->GetStudyEntry() );
754 //=================================================================================
755 // function : OnFinish
757 //=================================================================================
758 void MeasureGUI_ManageDimensionsDlg::OnFinish()
760 if ( myEditObject.isNull() )
762 GEOMBase_Skeleton::ClickOnCancel();
766 SalomeApp_Application* anApp = myGeomGUI->getApp();
769 GEOMBase_Skeleton::ClickOnCancel();
773 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
776 GEOMBase_Skeleton::ClickOnCancel();
780 // reset preview property state
781 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
782 myEditObject->GetStudyEntry(),
783 GEOM::propertyName( GEOM::Dimensions ),
786 redisplay( myEditObject.get() );
789 //=================================================================================
790 // function : enterEvent()
792 //=================================================================================
793 void MeasureGUI_ManageDimensionsDlg::enterEvent( QEvent* )
795 if ( !mainFrame()->GroupConstructors->isEnabled() )
797 OnActivateThisDialog();
801 //=================================================================================
802 // function : OnActivateThisDialog
804 //=================================================================================
805 void MeasureGUI_ManageDimensionsDlg::OnActivateThisDialog()
807 disconnect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
808 GEOMBase_Skeleton::ActivateThisDialog();
809 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
811 SelectionIntoArgument( Selection_Object );
813 if ( myEditObject.isNull() )
815 myObjectSelector->PushButton1->click();
819 //=================================================================================
820 // function : OnDeactivateThisDialog
822 //=================================================================================
823 void MeasureGUI_ManageDimensionsDlg::OnDeactivateThisDialog()
825 if ( AllowedToSaveChanges() )
830 if ( !myEditObject.isNull() )
832 SalomeApp_Study* aStudy = NULL;
833 SalomeApp_Application* anApp = myGeomGUI->getApp();
836 aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
841 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
842 myEditObject->GetStudyEntry(),
843 GEOM::propertyName( GEOM::Dimensions ),
847 redisplay( myEditObject.get() );
850 GEOMBase_Skeleton::DeactivateActiveDialog();
853 //=================================================================================
854 // function : SetEditObject
856 //=================================================================================
857 void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theObj )
861 QString aName = GEOMBase::GetName( theObj.get() );
863 myObjectSelector->LineEdit1->setText( aName );
865 myEditObject = theObj;
867 if ( myEditObject.isNull() )
869 myDimensionView->setEnabled( false );
874 SalomeApp_Application* anApp = myGeomGUI->getApp();
880 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
881 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
886 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
892 mySavedPropertyState.LoadFromAttribute( getStudy(), myEditObject->GetStudyEntry() );
894 // set property state for preview
895 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
896 myEditObject->GetStudyEntry(),
897 GEOM::propertyName( GEOM::Dimensions ),
898 mySavedPropertyState );
902 myDimensionView->setEnabled( true );
905 //=================================================================================
906 // function : RestoreState
908 //=================================================================================
909 void MeasureGUI_ManageDimensionsDlg::RestoreState()
911 if ( myEditObject.isNull() )
916 SalomeApp_Application* anApp = myGeomGUI->getApp();
922 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
928 QString aEntry = myEditObject->GetStudyEntry();
930 // reset preview property state
931 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
932 myEditObject->GetStudyEntry(),
933 GEOM::propertyName( GEOM::Dimensions ),
939 //=================================================================================
940 // function : PopulateList
942 //=================================================================================
943 void MeasureGUI_ManageDimensionsDlg::PopulateList()
945 QTreeWidget* aListView = myDimensionView->TreeWidget;
947 // clear list completely if object is null
948 if ( myEditObject.isNull() )
954 // clear only groups data if object is ok
955 QTreeWidgetItem* aDistanceGroupItem = aListView->topLevelItem( GroupItem_Distance );
956 QTreeWidgetItem* aDiameterGroupItem = aListView->topLevelItem( GroupItem_Diameter );
957 QTreeWidgetItem* anAngleGroupItem = aListView->topLevelItem( GroupItem_Angle );
959 // create group items if not exist yet
960 if ( !aDistanceGroupItem || !aDiameterGroupItem || !anAngleGroupItem )
962 aDistanceGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DISTANCE_ITEM" ) ) );
963 aDiameterGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DIAMETER_ITEM" ) ) );
964 anAngleGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "ANGLE_ITEM" ) ) );
968 aListView->addTopLevelItem( aDistanceGroupItem );
969 aListView->addTopLevelItem( aDiameterGroupItem );
970 aListView->addTopLevelItem( anAngleGroupItem );
971 aListView->expandAll();
974 qDeleteAll( aDistanceGroupItem->takeChildren() );
975 qDeleteAll( aDiameterGroupItem->takeChildren() );
976 qDeleteAll( anAngleGroupItem->takeChildren() );
978 // collect all groupped items
979 QList<QTreeWidgetItem*> aDistItems;
980 QList<QTreeWidgetItem*> aDiamItems;
981 QList<QTreeWidgetItem*> anAngItems;
983 SalomeApp_Application* anApp = myGeomGUI->getApp();
989 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
995 QString aEntry = myEditObject->GetStudyEntry();
997 // get property data to change
998 GEOMGUI_DimensionProperty aProp =
999 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1000 myEditObject->GetStudyEntry(),
1001 GEOM::propertyName( GEOM::Dimensions ),
1003 .value<GEOMGUI_DimensionProperty>();
1005 // read dimension records from property
1006 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
1008 QString aName = aProp.GetName( anIt );
1009 bool isVisible = aProp.IsVisible( anIt );
1010 int aType = aProp.GetType( anIt );
1012 QTreeWidgetItem* anItem = new QTreeWidgetItem;
1013 anItem->setText( 0, aName );
1014 anItem->setCheckState( 0, isVisible ? Qt::Checked : Qt::Unchecked );
1015 anItem->setData( 0, Qt::UserRole, anIt );
1016 anItem->setFlags( Qt::ItemIsUserCheckable
1017 | Qt::ItemIsSelectable
1018 | Qt::ItemIsEditable
1019 | Qt::ItemIsEnabled );
1023 case GEOMGUI_DimensionProperty::DimensionType_Length : aDistItems << anItem; break;
1024 case GEOMGUI_DimensionProperty::DimensionType_Diameter : aDiamItems << anItem; break;
1025 case GEOMGUI_DimensionProperty::DimensionType_Angle : anAngItems << anItem; break;
1029 aDistanceGroupItem->addChildren( aDistItems );
1030 aDiameterGroupItem->addChildren( aDiamItems );
1031 anAngleGroupItem->addChildren( anAngItems );
1033 aListView->setItemHidden( aDistanceGroupItem, aDistItems.isEmpty() );
1034 aListView->setItemHidden( aDiameterGroupItem, aDiamItems.isEmpty() );
1035 aListView->setItemHidden( anAngleGroupItem, anAngItems.isEmpty() );
1038 //=================================================================================
1039 // function : HasUnsavedChanges
1041 //=================================================================================
1042 bool MeasureGUI_ManageDimensionsDlg::HasUnsavedChanges()
1044 if ( myEditObject.isNull() )
1049 SalomeApp_Application* anApp = myGeomGUI->getApp();
1055 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1061 GEOMGUI_DimensionProperty aCurrentState =
1062 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1063 myEditObject->GetStudyEntry(),
1064 GEOM::propertyName( GEOM::Dimensions ),
1066 .value<GEOMGUI_DimensionProperty>();
1068 return aCurrentState != mySavedPropertyState;
1071 //=================================================================================
1072 // function : AllowedToCancelChanges
1074 //=================================================================================
1075 bool MeasureGUI_ManageDimensionsDlg::AllowedToCancelChanges()
1077 if ( !HasUnsavedChanges() )
1082 int aResponse = SUIT_MessageBox::warning( this,
1083 tr( "WRN_TITLE_UNSAVED" ),
1084 tr( "WRN_MSG_CHANGES_LOST" ),
1086 QMessageBox::Cancel );
1088 return aResponse == QMessageBox::Ok;
1091 //=================================================================================
1092 // function : AllowedToSaveChanges
1094 //=================================================================================
1095 bool MeasureGUI_ManageDimensionsDlg::AllowedToSaveChanges()
1097 if ( !HasUnsavedChanges() )
1102 int aResponse = SUIT_MessageBox::warning( this,
1103 tr( "WRN_TITLE_UNSAVED" ),
1104 tr( "WRN_MSG_CHANGES_SAVE" ),
1106 QMessageBox::Cancel );
1108 return aResponse == QMessageBox::Ok;
1111 //=================================================================================
1112 // function : IdFromItem
1114 //=================================================================================
1115 int MeasureGUI_ManageDimensionsDlg::IdFromItem( QTreeWidgetItem* theItem )
1122 bool isIdOK = false;
1123 const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
1125 return isIdOK ? anId : -1;
1128 //=================================================================================
1129 // function : IdFromPrs
1131 //=================================================================================
1132 int MeasureGUI_ManageDimensionsDlg::IdFromPrs( const Handle(AIS_InteractiveObject)& theAIS )
1134 Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( theAIS->GetOwner() );
1136 if ( anIO.IsNull() )
1141 QString anIOEntry = anIO->getEntry();
1142 QString anEditEntry = myEditObject->GetStudyEntry();
1143 if ( anIOEntry != anEditEntry )
1148 Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( theAIS );
1149 if ( !aLength.IsNull() )
1151 return aLength->GetId();
1154 Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( theAIS );
1155 if ( !aDiameter.IsNull() )
1157 return aDiameter->GetId();
1160 Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( theAIS );
1161 if ( !anAngle.IsNull() )
1163 return anAngle->GetId();
1169 //=================================================================================
1170 // function : SelectInList
1172 //=================================================================================
1173 void MeasureGUI_ManageDimensionsDlg::SelectInList( const Handle(AIS_InteractiveObject)& theIO )
1175 SelectInList( IdFromPrs( theIO ) );
1178 //=================================================================================
1179 // function : SelectInList
1181 //=================================================================================
1182 void MeasureGUI_ManageDimensionsDlg::SelectInList( const int theId )
1184 QTreeWidget* aListOfDimension = myDimensionView->TreeWidget;
1186 QAbstractItemModel* aModel = aListOfDimension->model();
1187 QModelIndexList aIndexes = aModel->match( aModel->index(0, 0),
1190 -1, Qt::MatchRecursive );
1192 if ( aIndexes.isEmpty() )
1194 aListOfDimension->setCurrentIndex( QModelIndex() );
1198 bool isBlocked = aListOfDimension->blockSignals( true );
1199 aListOfDimension->setCurrentIndex( aIndexes.first() );
1200 aListOfDimension->blockSignals( isBlocked );
1203 //=================================================================================
1204 // function : SelectInViewer
1206 //=================================================================================
1207 void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, const int theId )
1209 Handle(AIS_InteractiveContext) anAISContext = theViewer->getAISContext();
1210 if ( anAISContext.IsNull() )
1215 Standard_Boolean isLocal = anAISContext->HasOpenedContext();
1218 anAISContext->ClearSelected( Standard_False );
1222 anAISContext->ClearCurrents( Standard_False );
1225 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
1227 AIS_ListOfInteractive aListOfIO;
1228 aPrs->GetObjects( aListOfIO );
1230 AIS_ListIteratorOfListOfInteractive anIt( aListOfIO );
1231 for ( ; anIt.More(); anIt.Next() )
1233 const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
1234 if ( IdFromPrs( anIO ) != theId )
1238 anAISContext->Deactivate( anIO, AIS_DSM_Line );
1239 anAISContext->Deactivate( anIO, AIS_DSM_Text );
1246 anAISContext->AddOrRemoveSelected( anIO, Standard_False );
1247 anAISContext->Activate( anIO, AIS_DSM_Line );
1248 anAISContext->Activate( anIO, AIS_DSM_Text );
1252 anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False );
1255 anAISContext->UpdateCurrentViewer();
1259 //=================================================================================
1260 // function : RedisplayObject
1262 //=================================================================================
1263 void MeasureGUI_ManageDimensionsDlg::RedisplayObject()
1265 redisplay( myEditObject.get() );
1267 if ( !myOperatedViewer )
1272 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
1273 if ( !aSelectedItem )
1278 StartSelection( myCurrentSelection );
1280 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );