1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_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 <GEOMGUI_TextTreeWdg.h>
33 #include <GEOMUtils.hxx>
34 #include <GEOMGUI_OCCSelector.h>
35 #include <GEOM_AISDimension.hxx>
36 #include <GEOM_Constants.h>
40 #include <SOCC_ViewModel.h>
42 #include <SalomeApp_Application.h>
43 #include <SalomeApp_Study.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_MessageBox.h>
50 #include <AIS_ListOfInteractive.hxx>
51 #include <AIS_ListIteratorOfListOfInteractive.hxx>
52 #include <AIS_InteractiveContext.hxx>
53 #include <SelectMgr_Filter.hxx>
54 #include <SelectMgr_ListOfFilter.hxx>
55 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
57 #include <QTreeWidget>
58 #include <QPushButton>
60 #include <QVBoxLayout>
61 #include <QHBoxLayout>
64 //=================================================================================
65 // function : Constructor
67 //=================================================================================
68 MeasureGUI_ManageDimensionsDlg::MeasureGUI_ManageDimensionsDlg( GeometryGUI* theGUI, QWidget* theParent )
69 : GEOMBase_Skeleton( theGUI, theParent ),
70 myOperatedViewer( NULL ),
71 myCurrentSelection( Selection_None ),
74 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
76 QPixmap aSelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
78 setWindowTitle( tr( "MANAGE_DIMENSIONS_TITLE" ) );
80 mainFrame()->GroupConstructors->setVisible( false );
81 mainFrame()->GroupBoxName->setVisible( false );
83 // construct object selector pane
84 myObjectSelector = new DlgRef_1Sel( centralWidget() );
85 myObjectSelector->TextLabel1->setText( tr( "OBJECT_LABEL" ) );
86 myObjectSelector->LineEdit1->setReadOnly( true );
87 myObjectSelector->PushButton1->setIcon( aSelectorIcon );
88 myObjectSelector->PushButton1->setCheckable( true );
90 // construct dimension list view pane
91 myDimensionView = new MeasureGUI_1TreeWidget_4Button( centralWidget() );
92 myDimensionView->GroupBox->setTitle( tr( "DIMENSIONS_GROUP" ) );
93 myDimensionView->PushButton1->setText( tr( "ADD_BTN" ) );
94 myDimensionView->PushButton2->setText( tr( "REMOVE_BTN" ) );
95 myDimensionView->PushButton3->setText( tr( "SHOW_ALL_BTN" ) );
96 myDimensionView->PushButton4->setText( tr( "HIDE_ALL_BTN" ) );
97 myDimensionView->TreeWidget->setMinimumHeight( 250 );
98 myDimensionView->setEnabled( false );
100 connect( myDimensionView->PushButton1, SIGNAL( clicked() ), SLOT( OnAdd() ) );
101 connect( myDimensionView->PushButton2, SIGNAL( clicked() ), SLOT( OnRemove() ) );
102 connect( myDimensionView->PushButton3, SIGNAL( clicked() ), SLOT( OnShowAll() ) );
103 connect( myDimensionView->PushButton4, SIGNAL( clicked() ), SLOT( OnHideAll() ) );
104 connect( myDimensionView->TreeWidget,
105 SIGNAL( itemChanged( QTreeWidgetItem*, int ) ),
106 SLOT( OnChangeItem( QTreeWidgetItem* ) ) );
107 connect( myDimensionView->TreeWidget,
108 SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
109 SLOT( OnSelectItem() ) );
111 // populate tree with top-level items
112 myDimensionView->TreeWidget->setHeaderItem( new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( QString() ) ) );
114 // construct main frame layout
115 QVBoxLayout* aMainLayout = new QVBoxLayout( centralWidget() );
116 aMainLayout->setMargin( 0 );
117 aMainLayout->addWidget( myObjectSelector, 0 );
118 aMainLayout->addWidget( myDimensionView, 1 );
120 // signals and slots connections
121 connect( myObjectSelector->PushButton1, SIGNAL( clicked() ), SLOT( StartObjectSelection() ) );
122 connect( buttonOk(), SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
123 connect( buttonApply(), SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
125 connect( this, SIGNAL( finished( int ) ), SLOT( OnFinish() ) );
127 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
128 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
130 myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent ),
132 SelectionIntoArgument( Selection_Object );
134 if ( myEditObject.isNull() )
136 myObjectSelector->PushButton1->click();
138 myIsNeedRedisplay = false;
139 setHelpFileName("managing_dimensions_page.html");
142 //=================================================================================
143 // function : Destructor
145 //=================================================================================
146 MeasureGUI_ManageDimensionsDlg::~MeasureGUI_ManageDimensionsDlg()
151 //=================================================================================
152 // function : StartSelection
153 // purpose : Starts specific selection
154 //=================================================================================
155 void MeasureGUI_ManageDimensionsDlg::StartSelection( const Selection theSelection )
159 myCurrentSelection = theSelection;
161 if ( theSelection == Selection_Object && AllowedToCancelChanges() )
163 /* ----------------------------------------------- *
164 * selection of object *
165 * ------------------------------------------------ */
167 globalSelection( GEOM_ALLSHAPES );
168 connect( myGeomGUI->getApp()->selectionMgr(),
169 SIGNAL( currentSelectionChanged() ),
171 SLOT( OnSelection() ) );
173 else if ( theSelection == Selection_Dimension && !myEditObject.isNull() )
175 /* ----------------------------------------------- *
176 * selection of dimension *
177 * ------------------------------------------------ */
179 SalomeApp_Application* anApp = myGeomGUI->getApp();
185 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
186 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
191 myOperatedViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
195 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
197 anAISContext->ClearCurrents( Standard_False );
198 anAISContext->ClearSelected( Standard_False );
199 anAISContext->OpenLocalContext( Standard_True, Standard_False );
201 Handle(MeasureGUI_DimensionFilter) aFilter = new MeasureGUI_DimensionFilter( myEditObject->GetStudyEntry() );
203 anAISContext->AddFilter( aFilter );
205 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
207 QList<SUIT_Selector*> aSelectors;
208 aSelectionMgr->selectors( aSelectors );
209 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
210 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
212 SUIT_Selector* aSelector = *aSelectorIt;
214 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
215 if ( !aGeomSelector )
220 aGeomSelector->setEnabled( false );
223 connect( myOperatedViewer,
224 SIGNAL( selectionChanged() ),
226 SLOT( OnSelection() ) );
228 myDimensionInteractor->Enable();
230 connect( myDimensionInteractor,
231 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
233 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
235 anAISContext->UpdateCurrentViewer();
239 //=================================================================================
240 // function : StopObjectSelection
241 // purpose : Stops specific selection
242 //=================================================================================
243 void MeasureGUI_ManageDimensionsDlg::StopSelection()
245 if ( myCurrentSelection == Selection_Object )
247 /* ----------------------------------------------- *
248 * selection of object *
249 * ------------------------------------------------ */
251 myObjectSelector->PushButton1->setChecked( false );
252 disconnect( myGeomGUI->getApp()->selectionMgr(),
253 SIGNAL( currentSelectionChanged() ),
255 SLOT( OnSelection() ) );
257 else if ( myCurrentSelection == Selection_Dimension && myOperatedViewer )
259 /* ----------------------------------------------- *
260 * selection of dimension *
261 * ------------------------------------------------ */
263 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
265 anAISContext->CloseLocalContext();
267 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
269 QList<SUIT_Selector*> aSelectors;
270 aSelectionMgr->selectors( aSelectors );
271 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
272 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
274 SUIT_Selector* aSelector = *aSelectorIt;
276 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
277 if ( !aGeomSelector )
282 aGeomSelector->setEnabled( true );
285 disconnect( myOperatedViewer,
286 SIGNAL( selectionChanged() ),
288 SLOT( OnSelection() ) );
290 myDimensionInteractor->Disable();
292 disconnect( myDimensionInteractor,
293 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
295 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
298 myCurrentSelection = Selection_None;
303 //=================================================================================
304 // function : OnSelection
306 //=================================================================================
307 void MeasureGUI_ManageDimensionsDlg::OnSelection()
309 SelectionIntoArgument( myCurrentSelection );
312 //=================================================================================
313 // function : SelectionIntoArgument
315 //=================================================================================
316 void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theSelection )
318 if ( theSelection == Selection_Object )
320 /* ----------------------------------------------- *
321 * selection of object *
322 * ------------------------------------------------ */
324 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
325 SALOME_ListIO aSelection;
326 aSelectionMgr->selectedObjects( aSelection );
328 GEOM::GeomObjPtr aSelected;
330 if ( aSelection.Extent() == 1 )
332 aSelected = GEOMBase::ConvertIOinGEOMObject( aSelection.First() );
335 SetEditObject( aSelected );
336 StartSelection( Selection_Dimension );
338 else if ( theSelection == Selection_Dimension && myOperatedViewer )
340 /* ----------------------------------------------- *
341 * selection of dimension *
342 * ------------------------------------------------ */
344 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
346 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
348 // non-single selection is prohibited
349 if ( anAISContext->NbSelected() != 1 )
351 aDimensionList->setCurrentIndex( QModelIndex() );
355 anAISContext->InitSelected();
357 Handle(AIS_InteractiveObject) anAIS;
359 if ( anAISContext->HasOpenedContext() )
361 Handle(SelectMgr_EntityOwner) anAISOwner = anAISContext->SelectedOwner();
362 anAIS = Handle(AIS_InteractiveObject)::DownCast( anAISOwner->Selectable() );
366 anAIS = anAISContext->Current();
369 int aDimensionId = IdFromPrs( anAIS );
371 SelectInList( aDimensionId );
373 if ( aDimensionId >= 0 )
375 SelectInViewer( myOperatedViewer, aDimensionId );
380 //=================================================================================
383 //=================================================================================
384 void MeasureGUI_ManageDimensionsDlg::OnAdd()
386 if(!myCreateDialog) {
387 QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
389 myCreateDialog = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
390 connect( myCreateDialog, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
391 // this is necessary as the GEOMBase_Helper switches selection mode on destruction
392 connect( myCreateDialog, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
393 connect( myCreateDialog, SIGNAL( applyClicked() ), this, SLOT( OnDimensionAdded() ) );
394 myCreateDialog->updateGeometry();
395 myCreateDialog->resize( myCreateDialog->minimumSizeHint() );
396 myCreateDialog->show();
398 myCreateDialog->activateWindow();
400 myObjectSelector->setEnabled(false);
401 myDimensionView->setEnabled(false);
404 //=================================================================================
405 // function : OnRemove
407 //=================================================================================
408 void MeasureGUI_ManageDimensionsDlg::OnRemove()
410 int aDimensionId = IdFromItem( myDimensionView->TreeWidget->currentItem() );
411 if ( aDimensionId < 0 )
416 SalomeApp_Application* anApp = myGeomGUI->getApp();
422 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
428 // get property data to change
429 GEOMGUI_DimensionProperty aProp =
430 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
431 myEditObject->GetStudyEntry(),
432 GEOM::propertyName( GEOM::Dimensions ),
434 .value<GEOMGUI_DimensionProperty>();
436 aProp.RemoveRecord( aDimensionId );
438 // store modified property data
439 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
440 myEditObject->GetStudyEntry(),
441 GEOM::propertyName( GEOM::Dimensions ),
449 //=================================================================================
450 // function : OnChangeItem
452 //=================================================================================
453 void MeasureGUI_ManageDimensionsDlg::OnChangeItem( QTreeWidgetItem* theItem )
455 int aDimensionId = IdFromItem( theItem );
456 if ( aDimensionId < 0 )
461 SalomeApp_Application* anApp = myGeomGUI->getApp();
467 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
473 // get property data to change
474 GEOMGUI_DimensionProperty aProp =
475 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
476 myEditObject->GetStudyEntry(),
477 GEOM::propertyName( GEOM::Dimensions ),
479 .value<GEOMGUI_DimensionProperty>();
481 // change property data
482 bool isAnythingChanged = false;
484 QString aName = theItem->text( 0 );
485 if ( aProp.GetName( aDimensionId ) != aName )
487 isAnythingChanged = true;
488 aProp.SetName( aDimensionId, aName );
491 bool isVisible = theItem->checkState( 0 ) == Qt::Checked;
492 if ( aProp.IsVisible( aDimensionId ) != isVisible )
494 isAnythingChanged = true;
495 aProp.SetVisible( aDimensionId, isVisible );
498 // store property data
499 if ( !isAnythingChanged )
504 // store modified property data
505 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
506 myEditObject->GetStudyEntry(),
507 GEOM::propertyName( GEOM::Dimensions ),
513 //=================================================================================
514 // function : OnSelectItem
516 //=================================================================================
517 void MeasureGUI_ManageDimensionsDlg::OnSelectItem()
519 if ( !myOperatedViewer )
524 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
526 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );
529 //=================================================================================
530 // function : OnShowAll
532 //=================================================================================
533 void MeasureGUI_ManageDimensionsDlg::OnShowAll()
536 SalomeApp_Application* anApp = myGeomGUI->getApp();
542 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
548 // get property data to change
549 GEOMGUI_DimensionProperty aProp =
550 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
551 myEditObject->GetStudyEntry(),
552 GEOM::propertyName( GEOM::Dimensions ),
554 .value<GEOMGUI_DimensionProperty>();
556 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
558 bool isBlocked = aDimensionList->blockSignals( true );
560 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
562 aProp.SetVisible( anIt, true );
565 // store modified property data
566 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
567 myEditObject->GetStudyEntry(),
568 GEOM::propertyName( GEOM::Dimensions ),
575 aDimensionList->blockSignals( isBlocked );
578 //=================================================================================
579 // function : OnHideAll
581 //=================================================================================
582 void MeasureGUI_ManageDimensionsDlg::OnHideAll()
585 SalomeApp_Application* anApp = myGeomGUI->getApp();
591 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
597 // get property data to change
598 GEOMGUI_DimensionProperty aProp =
599 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
600 myEditObject->GetStudyEntry(),
601 GEOM::propertyName( GEOM::Dimensions ),
603 .value<GEOMGUI_DimensionProperty>();
605 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
607 bool isBlocked = aDimensionList->blockSignals( true );
609 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
611 aProp.SetVisible( anIt, false );
614 // store modified property data
615 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
616 myEditObject->GetStudyEntry(),
617 GEOM::propertyName( GEOM::Dimensions ),
624 aDimensionList->blockSignals( isBlocked );
627 //=================================================================================
628 // function : OnInteractionFinished
630 //=================================================================================
631 void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle_AIS_InteractiveObject theIO )
633 // update property data
634 SalomeApp_Application* anApp = myGeomGUI->getApp();
640 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
647 TopoDS_Shape anParentSh;
648 if ( GEOMBase::GetShape( myEditObject.get(), anParentSh ) )
650 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
653 int aDimensionId = IdFromPrs( theIO );
655 // get property data to change
656 GEOMGUI_DimensionProperty aProp =
657 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
658 myEditObject->GetStudyEntry(),
659 GEOM::propertyName( GEOM::Dimensions ),
661 .value<GEOMGUI_DimensionProperty>();
663 aProp.SetRecord( aDimensionId, Handle(AIS_Dimension)::DownCast( theIO ), aLCS );
665 // store modified property data
666 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
667 myEditObject->GetStudyEntry(),
668 GEOM::propertyName( GEOM::Dimensions ),
672 //=================================================================================
673 // function : Suspend
675 //=================================================================================
676 void MeasureGUI_ManageDimensionsDlg::Suspend()
681 //=================================================================================
682 // function : Suspend
684 //=================================================================================
685 void MeasureGUI_ManageDimensionsDlg::Resume()
689 myObjectSelector->setEnabled(true);
690 myDimensionView->setEnabled(true);
693 if ( !myEditObject.isNull() )
696 StartSelection( Selection_Dimension );
700 //=================================================================================
701 // function : Suspend
703 //=================================================================================
704 void MeasureGUI_ManageDimensionsDlg::OnDimensionAdded() {
705 if ( !myEditObject.isNull() )
711 //=================================================================================
712 // function : ClickOnOk
714 //=================================================================================
715 void MeasureGUI_ManageDimensionsDlg::ClickOnOk()
717 setIsApplyAndClose( true );
718 if ( ClickOnApply() )
724 //=================================================================================
725 // function : ClickOnCancel
727 //=================================================================================
728 void MeasureGUI_ManageDimensionsDlg::ClickOnCancel()
730 if ( !AllowedToCancelChanges() )
735 if( myCreateDialog ) {
736 myCreateDialog->close();
740 GEOMBase_Skeleton::ClickOnCancel();
743 //=================================================================================
744 // function : ClickOnApply
746 //=================================================================================
747 bool MeasureGUI_ManageDimensionsDlg::ClickOnApply()
749 if ( myEditObject.isNull() )
754 SalomeApp_Application* anApp = myGeomGUI->getApp();
760 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
766 mySavedPropertyState =
767 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
768 myEditObject->GetStudyEntry(),
769 GEOM::propertyName( GEOM::Dimensions ),
771 .value<GEOMGUI_DimensionProperty>();
773 mySavedPropertyState.SaveToAttribute( aStudy, myEditObject->GetStudyEntry() );
775 myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
780 //=================================================================================
781 // function : OnFinish
783 //=================================================================================
784 void MeasureGUI_ManageDimensionsDlg::OnFinish()
786 if ( myEditObject.isNull() )
788 GEOMBase_Skeleton::ClickOnCancel();
792 SalomeApp_Application* anApp = myGeomGUI->getApp();
795 GEOMBase_Skeleton::ClickOnCancel();
799 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
802 GEOMBase_Skeleton::ClickOnCancel();
806 // reset preview property state
807 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
808 myEditObject->GetStudyEntry(),
809 GEOM::propertyName( GEOM::Dimensions ),
812 if ( myIsNeedRedisplay ) {
813 redisplay( myEditObject.get() );
816 myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
819 //=================================================================================
820 // function : enterEvent()
822 //=================================================================================
823 void MeasureGUI_ManageDimensionsDlg::enterEvent( QEvent* )
825 if ( !mainFrame()->GroupConstructors->isEnabled() )
827 OnActivateThisDialog();
831 //=================================================================================
832 // function : OnActivateThisDialog
834 //=================================================================================
835 void MeasureGUI_ManageDimensionsDlg::OnActivateThisDialog()
837 disconnect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
838 GEOMBase_Skeleton::ActivateThisDialog();
839 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
841 SelectionIntoArgument( Selection_Object );
843 if ( myEditObject.isNull() )
845 myObjectSelector->PushButton1->click();
849 //=================================================================================
850 // function : OnDeactivateThisDialog
852 //=================================================================================
853 void MeasureGUI_ManageDimensionsDlg::OnDeactivateThisDialog()
855 if ( AllowedToSaveChanges() )
860 if ( !myEditObject.isNull() )
862 SalomeApp_Study* aStudy = NULL;
863 SalomeApp_Application* anApp = myGeomGUI->getApp();
866 aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
871 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
872 myEditObject->GetStudyEntry(),
873 GEOM::propertyName( GEOM::Dimensions ),
877 redisplay( myEditObject.get() );
880 GEOMBase_Skeleton::DeactivateActiveDialog();
883 //=================================================================================
884 // function : SetEditObject
886 //=================================================================================
887 void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theObj )
891 QString aName = GEOMBase::GetName( theObj.get() );
893 myObjectSelector->LineEdit1->setText( aName );
895 myEditObject = theObj;
897 if ( myEditObject.isNull() )
899 myDimensionView->TreeWidget->clear();
900 myDimensionView->setEnabled( false );
904 SalomeApp_Application* anApp = myGeomGUI->getApp();
910 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
911 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
916 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
922 mySavedPropertyState.LoadFromAttribute( getStudy(), myEditObject->GetStudyEntry() );
924 // set property state for preview
925 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
926 myEditObject->GetStudyEntry(),
927 GEOM::propertyName( GEOM::Dimensions ),
928 mySavedPropertyState );
932 myDimensionView->setEnabled( true );
935 //=================================================================================
936 // function : RestoreState
938 //=================================================================================
939 void MeasureGUI_ManageDimensionsDlg::RestoreState()
941 if ( myEditObject.isNull() )
946 SalomeApp_Application* anApp = myGeomGUI->getApp();
952 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
958 QString aEntry = myEditObject->GetStudyEntry();
960 // reset preview property state
961 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
962 myEditObject->GetStudyEntry(),
963 GEOM::propertyName( GEOM::Dimensions ),
967 //=================================================================================
968 // function : PopulateList
970 //=================================================================================
971 void MeasureGUI_ManageDimensionsDlg::PopulateList()
973 QTreeWidget* aListView = myDimensionView->TreeWidget;
975 // clear list completely if object is null
976 if ( myEditObject.isNull() )
982 // clear only groups data if object is ok
983 QTreeWidgetItem* aDistanceGroupItem = aListView->topLevelItem( GroupItem_Distance );
984 QTreeWidgetItem* aDiameterGroupItem = aListView->topLevelItem( GroupItem_Diameter );
985 QTreeWidgetItem* anAngleGroupItem = aListView->topLevelItem( GroupItem_Angle );
987 // create group items if not exist yet
988 if ( !aDistanceGroupItem || !aDiameterGroupItem || !anAngleGroupItem )
990 aDistanceGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DISTANCE_ITEM" ) ) );
991 aDiameterGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DIAMETER_ITEM" ) ) );
992 anAngleGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "ANGLE_ITEM" ) ) );
996 aListView->addTopLevelItem( aDistanceGroupItem );
997 aListView->addTopLevelItem( aDiameterGroupItem );
998 aListView->addTopLevelItem( anAngleGroupItem );
999 aListView->expandAll();
1002 qDeleteAll( aDistanceGroupItem->takeChildren() );
1003 qDeleteAll( aDiameterGroupItem->takeChildren() );
1004 qDeleteAll( anAngleGroupItem->takeChildren() );
1006 // collect all groupped items
1007 QList<QTreeWidgetItem*> aDistItems;
1008 QList<QTreeWidgetItem*> aDiamItems;
1009 QList<QTreeWidgetItem*> anAngItems;
1011 SalomeApp_Application* anApp = myGeomGUI->getApp();
1017 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1023 QString aEntry = myEditObject->GetStudyEntry();
1025 // get property data to change
1026 GEOMGUI_DimensionProperty aProp =
1027 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1028 myEditObject->GetStudyEntry(),
1029 GEOM::propertyName( GEOM::Dimensions ),
1031 .value<GEOMGUI_DimensionProperty>();
1033 // read dimension records from property
1034 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
1036 QString aName = aProp.GetName( anIt );
1037 bool isVisible = aProp.IsVisible( anIt );
1038 int aType = aProp.GetType( anIt );
1040 QTreeWidgetItem* anItem = new QTreeWidgetItem;
1041 anItem->setText( 0, aName );
1042 anItem->setCheckState( 0, isVisible ? Qt::Checked : Qt::Unchecked );
1043 anItem->setData( 0, Qt::UserRole, anIt );
1044 anItem->setFlags( Qt::ItemIsUserCheckable
1045 | Qt::ItemIsSelectable
1046 | Qt::ItemIsEditable
1047 | Qt::ItemIsEnabled );
1051 case GEOMGUI_DimensionProperty::DimensionType_Length : aDistItems << anItem; break;
1052 case GEOMGUI_DimensionProperty::DimensionType_Diameter : aDiamItems << anItem; break;
1053 case GEOMGUI_DimensionProperty::DimensionType_Angle : anAngItems << anItem; break;
1057 aDistanceGroupItem->addChildren( aDistItems );
1058 aDiameterGroupItem->addChildren( aDiamItems );
1059 anAngleGroupItem->addChildren( anAngItems );
1061 aListView->setItemHidden( aDistanceGroupItem, aDistItems.isEmpty() );
1062 aListView->setItemHidden( aDiameterGroupItem, aDiamItems.isEmpty() );
1063 aListView->setItemHidden( anAngleGroupItem, anAngItems.isEmpty() );
1066 //=================================================================================
1067 // function : HasUnsavedChanges
1069 //=================================================================================
1070 bool MeasureGUI_ManageDimensionsDlg::HasUnsavedChanges()
1072 if ( myEditObject.isNull() )
1077 SalomeApp_Application* anApp = myGeomGUI->getApp();
1083 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1089 GEOMGUI_DimensionProperty aCurrentState =
1090 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1091 myEditObject->GetStudyEntry(),
1092 GEOM::propertyName( GEOM::Dimensions ),
1094 .value<GEOMGUI_DimensionProperty>();
1096 return aCurrentState != mySavedPropertyState;
1099 //=================================================================================
1100 // function : AllowedToCancelChanges
1102 //=================================================================================
1103 bool MeasureGUI_ManageDimensionsDlg::AllowedToCancelChanges()
1105 if ( !HasUnsavedChanges() )
1110 int aResponse = SUIT_MessageBox::warning( this,
1111 tr( "WRN_TITLE_UNSAVED" ),
1112 tr( "WRN_MSG_CHANGES_LOST" ),
1114 QMessageBox::Cancel );
1115 myIsNeedRedisplay = ( aResponse == QMessageBox::Ok );
1116 return myIsNeedRedisplay;
1119 //=================================================================================
1120 // function : AllowedToSaveChanges
1122 //=================================================================================
1123 bool MeasureGUI_ManageDimensionsDlg::AllowedToSaveChanges()
1125 if ( !HasUnsavedChanges() )
1130 int aResponse = SUIT_MessageBox::warning( this,
1131 tr( "WRN_TITLE_UNSAVED" ),
1132 tr( "WRN_MSG_CHANGES_SAVE" ),
1134 QMessageBox::Cancel );
1136 return aResponse == QMessageBox::Ok;
1139 //=================================================================================
1140 // function : IdFromItem
1142 //=================================================================================
1143 int MeasureGUI_ManageDimensionsDlg::IdFromItem( QTreeWidgetItem* theItem )
1150 bool isIdOK = false;
1151 const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
1153 return isIdOK ? anId : -1;
1156 //=================================================================================
1157 // function : IdFromPrs
1159 //=================================================================================
1160 int MeasureGUI_ManageDimensionsDlg::IdFromPrs( const Handle(AIS_InteractiveObject)& theAIS )
1162 Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( theAIS->GetOwner() );
1164 if ( anIO.IsNull() )
1169 QString anIOEntry = anIO->getEntry();
1170 QString anEditEntry = myEditObject->GetStudyEntry();
1171 if ( anIOEntry != anEditEntry )
1176 Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( theAIS );
1177 if ( !aLength.IsNull() )
1179 return aLength->GetId();
1182 Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( theAIS );
1183 if ( !aDiameter.IsNull() )
1185 return aDiameter->GetId();
1188 Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( theAIS );
1189 if ( !anAngle.IsNull() )
1191 return anAngle->GetId();
1197 //=================================================================================
1198 // function : SelectInList
1200 //=================================================================================
1201 void MeasureGUI_ManageDimensionsDlg::SelectInList( const Handle(AIS_InteractiveObject)& theIO )
1203 SelectInList( IdFromPrs( theIO ) );
1206 //=================================================================================
1207 // function : SelectInList
1209 //=================================================================================
1210 void MeasureGUI_ManageDimensionsDlg::SelectInList( const int theId )
1212 QTreeWidget* aListOfDimension = myDimensionView->TreeWidget;
1214 QAbstractItemModel* aModel = aListOfDimension->model();
1215 QModelIndexList aIndexes = aModel->match( aModel->index(0, 0),
1218 -1, Qt::MatchRecursive );
1220 if ( aIndexes.isEmpty() )
1222 aListOfDimension->setCurrentIndex( QModelIndex() );
1226 bool isBlocked = aListOfDimension->blockSignals( true );
1227 aListOfDimension->setCurrentIndex( aIndexes.first() );
1228 aListOfDimension->blockSignals( isBlocked );
1231 //=================================================================================
1232 // function : SelectInViewer
1234 //=================================================================================
1235 void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, const int theId )
1237 Handle(AIS_InteractiveContext) anAISContext = theViewer->getAISContext();
1238 if ( anAISContext.IsNull() )
1243 Standard_Boolean isLocal = anAISContext->HasOpenedContext();
1246 anAISContext->ClearSelected( Standard_False );
1250 anAISContext->ClearCurrents( Standard_False );
1253 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
1255 AIS_ListOfInteractive aListOfIO;
1256 aPrs->GetObjects( aListOfIO );
1258 AIS_ListIteratorOfListOfInteractive anIt( aListOfIO );
1259 for ( ; anIt.More(); anIt.Next() )
1261 const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
1262 if ( IdFromPrs( anIO ) != theId )
1266 anAISContext->Deactivate( anIO, AIS_DSM_Line );
1267 anAISContext->Deactivate( anIO, AIS_DSM_Text );
1274 anAISContext->AddOrRemoveSelected( anIO, Standard_False );
1275 anAISContext->Activate( anIO, AIS_DSM_Line );
1276 anAISContext->Activate( anIO, AIS_DSM_Text );
1280 anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False );
1283 anAISContext->UpdateCurrentViewer();
1287 //=================================================================================
1288 // function : RedisplayObject
1290 //=================================================================================
1291 void MeasureGUI_ManageDimensionsDlg::RedisplayObject()
1293 redisplay( myEditObject.get() );
1295 if ( !myOperatedViewer )
1300 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
1301 if ( !aSelectedItem )
1306 StartSelection( myCurrentSelection );
1308 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );