1 // Copyright (C) 2007-2015 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 <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 ),
73 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
75 QPixmap aSelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
77 setWindowTitle( tr( "MANAGE_DIMENSIONS_TITLE" ) );
79 mainFrame()->GroupConstructors->setVisible( false );
80 mainFrame()->GroupBoxName->setVisible( false );
82 // construct object selector pane
83 myObjectSelector = new DlgRef_1Sel( centralWidget() );
84 myObjectSelector->TextLabel1->setText( tr( "OBJECT_LABEL" ) );
85 myObjectSelector->LineEdit1->setReadOnly( true );
86 myObjectSelector->PushButton1->setIcon( aSelectorIcon );
87 myObjectSelector->PushButton1->setCheckable( true );
89 // construct dimension list view pane
90 myDimensionView = new MeasureGUI_1TreeWidget_4Button( centralWidget() );
91 myDimensionView->GroupBox->setTitle( tr( "DIMENSIONS_GROUP" ) );
92 myDimensionView->PushButton1->setText( tr( "ADD_BTN" ) );
93 myDimensionView->PushButton2->setText( tr( "REMOVE_BTN" ) );
94 myDimensionView->PushButton3->setText( tr( "SHOW_ALL_BTN" ) );
95 myDimensionView->PushButton4->setText( tr( "HIDE_ALL_BTN" ) );
96 myDimensionView->TreeWidget->setMinimumHeight( 250 );
97 myDimensionView->setEnabled( false );
99 connect( myDimensionView->PushButton1, SIGNAL( clicked() ), SLOT( OnAdd() ) );
100 connect( myDimensionView->PushButton2, SIGNAL( clicked() ), SLOT( OnRemove() ) );
101 connect( myDimensionView->PushButton3, SIGNAL( clicked() ), SLOT( OnShowAll() ) );
102 connect( myDimensionView->PushButton4, SIGNAL( clicked() ), SLOT( OnHideAll() ) );
103 connect( myDimensionView->TreeWidget,
104 SIGNAL( itemChanged( QTreeWidgetItem*, int ) ),
105 SLOT( OnChangeItem( QTreeWidgetItem* ) ) );
106 connect( myDimensionView->TreeWidget,
107 SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
108 SLOT( OnSelectItem() ) );
110 // populate tree with top-level items
111 myDimensionView->TreeWidget->setHeaderItem( new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( QString() ) ) );
113 // construct main frame layout
114 QVBoxLayout* aMainLayout = new QVBoxLayout( centralWidget() );
115 aMainLayout->setMargin( 0 );
116 aMainLayout->addWidget( myObjectSelector, 0 );
117 aMainLayout->addWidget( myDimensionView, 1 );
119 // signals and slots connections
120 connect( myObjectSelector->PushButton1, SIGNAL( clicked() ), SLOT( StartObjectSelection() ) );
121 connect( buttonOk(), SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
122 connect( buttonApply(), SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
124 connect( this, SIGNAL( finished( int ) ), SLOT( OnFinish() ) );
126 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
127 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
129 myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent ),
131 SelectionIntoArgument( Selection_Object );
133 if ( myEditObject.isNull() )
135 myObjectSelector->PushButton1->click();
137 isNeedRedisplay = false;
138 setHelpFileName("managing_dimensions_page.html");
141 //=================================================================================
142 // function : Destructor
144 //=================================================================================
145 MeasureGUI_ManageDimensionsDlg::~MeasureGUI_ManageDimensionsDlg()
150 //=================================================================================
151 // function : StartSelection
152 // purpose : Starts specific selection
153 //=================================================================================
154 void MeasureGUI_ManageDimensionsDlg::StartSelection( const Selection theSelection )
158 myCurrentSelection = theSelection;
160 if ( theSelection == Selection_Object && AllowedToCancelChanges() )
162 /* ----------------------------------------------- *
163 * selection of object *
164 * ------------------------------------------------ */
166 globalSelection( GEOM_ALLSHAPES );
167 connect( myGeomGUI->getApp()->selectionMgr(),
168 SIGNAL( currentSelectionChanged() ),
170 SLOT( OnSelection() ) );
172 else if ( theSelection == Selection_Dimension && !myEditObject.isNull() )
174 /* ----------------------------------------------- *
175 * selection of dimension *
176 * ------------------------------------------------ */
178 SalomeApp_Application* anApp = myGeomGUI->getApp();
184 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
185 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
190 myOperatedViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
194 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
196 anAISContext->ClearCurrents( Standard_False );
197 anAISContext->ClearSelected( Standard_False );
198 anAISContext->OpenLocalContext( Standard_True, Standard_False );
200 Handle(MeasureGUI_DimensionFilter) aFilter = new MeasureGUI_DimensionFilter( myEditObject->GetStudyEntry() );
202 anAISContext->AddFilter( aFilter );
204 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
206 QList<SUIT_Selector*> aSelectors;
207 aSelectionMgr->selectors( aSelectors );
208 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
209 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
211 SUIT_Selector* aSelector = *aSelectorIt;
213 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
214 if ( !aGeomSelector )
219 aGeomSelector->setEnabled( false );
222 connect( myOperatedViewer,
223 SIGNAL( selectionChanged() ),
225 SLOT( OnSelection() ) );
227 myDimensionInteractor->Enable();
229 connect( myDimensionInteractor,
230 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
232 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
234 anAISContext->UpdateCurrentViewer();
238 //=================================================================================
239 // function : StopObjectSelection
240 // purpose : Stops specific selection
241 //=================================================================================
242 void MeasureGUI_ManageDimensionsDlg::StopSelection()
244 if ( myCurrentSelection == Selection_Object )
246 /* ----------------------------------------------- *
247 * selection of object *
248 * ------------------------------------------------ */
250 myObjectSelector->PushButton1->setChecked( false );
251 disconnect( myGeomGUI->getApp()->selectionMgr(),
252 SIGNAL( currentSelectionChanged() ),
254 SLOT( OnSelection() ) );
256 else if ( myCurrentSelection == Selection_Dimension && myOperatedViewer )
258 /* ----------------------------------------------- *
259 * selection of dimension *
260 * ------------------------------------------------ */
262 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
264 anAISContext->CloseLocalContext();
266 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
268 QList<SUIT_Selector*> aSelectors;
269 aSelectionMgr->selectors( aSelectors );
270 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
271 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
273 SUIT_Selector* aSelector = *aSelectorIt;
275 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
276 if ( !aGeomSelector )
281 aGeomSelector->setEnabled( true );
284 disconnect( myOperatedViewer,
285 SIGNAL( selectionChanged() ),
287 SLOT( OnSelection() ) );
289 myDimensionInteractor->Disable();
291 disconnect( myDimensionInteractor,
292 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
294 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
297 myCurrentSelection = Selection_None;
302 //=================================================================================
303 // function : OnSelection
305 //=================================================================================
306 void MeasureGUI_ManageDimensionsDlg::OnSelection()
308 SelectionIntoArgument( myCurrentSelection );
311 //=================================================================================
312 // function : SelectionIntoArgument
314 //=================================================================================
315 void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theSelection )
317 if ( theSelection == Selection_Object )
319 /* ----------------------------------------------- *
320 * selection of object *
321 * ------------------------------------------------ */
323 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
324 SALOME_ListIO aSelection;
325 aSelectionMgr->selectedObjects( aSelection );
327 GEOM::GeomObjPtr aSelected;
329 if ( aSelection.Extent() == 1 )
331 aSelected = GEOMBase::ConvertIOinGEOMObject( aSelection.First() );
334 SetEditObject( aSelected );
335 StartSelection( Selection_Dimension );
337 else if ( theSelection == Selection_Dimension && myOperatedViewer )
339 /* ----------------------------------------------- *
340 * selection of dimension *
341 * ------------------------------------------------ */
343 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
345 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
347 // non-single selection is prohibited
348 if ( anAISContext->NbSelected() != 1 )
350 aDimensionList->setCurrentIndex( QModelIndex() );
354 anAISContext->InitSelected();
356 Handle(AIS_InteractiveObject) anAIS;
358 if ( anAISContext->HasOpenedContext() )
360 Handle(SelectMgr_EntityOwner) anAISOwner = anAISContext->SelectedOwner();
361 anAIS = Handle(AIS_InteractiveObject)::DownCast( anAISOwner->Selectable() );
365 anAIS = anAISContext->Current();
368 int aDimensionId = IdFromPrs( anAIS );
370 SelectInList( aDimensionId );
372 if ( aDimensionId >= 0 )
374 SelectInViewer( myOperatedViewer, aDimensionId );
379 //=================================================================================
382 //=================================================================================
383 void MeasureGUI_ManageDimensionsDlg::OnAdd()
385 if(!myCreateDialog) {
386 QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
388 myCreateDialog = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
389 connect( myCreateDialog, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
390 // this is necessary as the GEOMBase_Helper switches selection mode on destruction
391 connect( myCreateDialog, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
392 connect( myCreateDialog, SIGNAL( applyClicked() ), this, SLOT( OnDimensionAdded() ) );
393 myCreateDialog->updateGeometry();
394 myCreateDialog->resize( myCreateDialog->minimumSizeHint() );
395 myCreateDialog->show();
397 myCreateDialog->activateWindow();
399 myObjectSelector->setEnabled(false);
400 myDimensionView->setEnabled(false);
403 //=================================================================================
404 // function : OnRemove
406 //=================================================================================
407 void MeasureGUI_ManageDimensionsDlg::OnRemove()
409 int aDimensionId = IdFromItem( myDimensionView->TreeWidget->currentItem() );
410 if ( aDimensionId < 0 )
415 SalomeApp_Application* anApp = myGeomGUI->getApp();
421 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
427 // get property data to change
428 GEOMGUI_DimensionProperty aProp =
429 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
430 myEditObject->GetStudyEntry(),
431 GEOM::propertyName( GEOM::Dimensions ),
433 .value<GEOMGUI_DimensionProperty>();
435 aProp.RemoveRecord( aDimensionId );
437 // store modified property data
438 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
439 myEditObject->GetStudyEntry(),
440 GEOM::propertyName( GEOM::Dimensions ),
448 //=================================================================================
449 // function : OnChangeItem
451 //=================================================================================
452 void MeasureGUI_ManageDimensionsDlg::OnChangeItem( QTreeWidgetItem* theItem )
454 int aDimensionId = IdFromItem( theItem );
455 if ( aDimensionId < 0 )
460 SalomeApp_Application* anApp = myGeomGUI->getApp();
466 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
472 // get property data to change
473 GEOMGUI_DimensionProperty aProp =
474 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
475 myEditObject->GetStudyEntry(),
476 GEOM::propertyName( GEOM::Dimensions ),
478 .value<GEOMGUI_DimensionProperty>();
480 // change property data
481 bool isAnythingChanged = false;
483 QString aName = theItem->text( 0 );
484 if ( aProp.GetName( aDimensionId ) != aName )
486 isAnythingChanged = true;
487 aProp.SetName( aDimensionId, aName );
490 bool isVisible = theItem->checkState( 0 ) == Qt::Checked;
491 if ( aProp.IsVisible( aDimensionId ) != isVisible )
493 isAnythingChanged = true;
494 aProp.SetVisible( aDimensionId, isVisible );
497 // store property data
498 if ( !isAnythingChanged )
503 // store modified property data
504 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
505 myEditObject->GetStudyEntry(),
506 GEOM::propertyName( GEOM::Dimensions ),
512 //=================================================================================
513 // function : OnSelectItem
515 //=================================================================================
516 void MeasureGUI_ManageDimensionsDlg::OnSelectItem()
518 if ( !myOperatedViewer )
523 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
525 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );
528 //=================================================================================
529 // function : OnShowAll
531 //=================================================================================
532 void MeasureGUI_ManageDimensionsDlg::OnShowAll()
535 SalomeApp_Application* anApp = myGeomGUI->getApp();
541 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
547 // get property data to change
548 GEOMGUI_DimensionProperty aProp =
549 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
550 myEditObject->GetStudyEntry(),
551 GEOM::propertyName( GEOM::Dimensions ),
553 .value<GEOMGUI_DimensionProperty>();
555 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
557 bool isBlocked = aDimensionList->blockSignals( true );
559 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
561 aProp.SetVisible( anIt, true );
564 // store modified property data
565 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
566 myEditObject->GetStudyEntry(),
567 GEOM::propertyName( GEOM::Dimensions ),
574 aDimensionList->blockSignals( isBlocked );
577 //=================================================================================
578 // function : OnHideAll
580 //=================================================================================
581 void MeasureGUI_ManageDimensionsDlg::OnHideAll()
584 SalomeApp_Application* anApp = myGeomGUI->getApp();
590 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
596 // get property data to change
597 GEOMGUI_DimensionProperty aProp =
598 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
599 myEditObject->GetStudyEntry(),
600 GEOM::propertyName( GEOM::Dimensions ),
602 .value<GEOMGUI_DimensionProperty>();
604 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
606 bool isBlocked = aDimensionList->blockSignals( true );
608 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
610 aProp.SetVisible( anIt, false );
613 // store modified property data
614 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
615 myEditObject->GetStudyEntry(),
616 GEOM::propertyName( GEOM::Dimensions ),
623 aDimensionList->blockSignals( isBlocked );
626 //=================================================================================
627 // function : OnInteractionFinished
629 //=================================================================================
630 void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle(AIS_InteractiveObject) theIO )
632 // update property data
633 SalomeApp_Application* anApp = myGeomGUI->getApp();
639 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
646 TopoDS_Shape anParentSh;
647 if ( GEOMBase::GetShape( myEditObject.get(), anParentSh ) )
649 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
652 int aDimensionId = IdFromPrs( theIO );
654 // get property data to change
655 GEOMGUI_DimensionProperty aProp =
656 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
657 myEditObject->GetStudyEntry(),
658 GEOM::propertyName( GEOM::Dimensions ),
660 .value<GEOMGUI_DimensionProperty>();
662 aProp.SetRecord( aDimensionId, Handle(AIS_Dimension)::DownCast( theIO ), aLCS );
664 // store modified property data
665 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
666 myEditObject->GetStudyEntry(),
667 GEOM::propertyName( GEOM::Dimensions ),
671 //=================================================================================
672 // function : Suspend
674 //=================================================================================
675 void MeasureGUI_ManageDimensionsDlg::Suspend()
680 //=================================================================================
681 // function : Suspend
683 //=================================================================================
684 void MeasureGUI_ManageDimensionsDlg::Resume()
688 myObjectSelector->setEnabled(true);
689 myDimensionView->setEnabled(true);
692 if ( !myEditObject.isNull() )
695 StartSelection( Selection_Dimension );
699 //=================================================================================
700 // function : Suspend
702 //=================================================================================
703 void MeasureGUI_ManageDimensionsDlg::OnDimensionAdded() {
704 if ( !myEditObject.isNull() )
710 //=================================================================================
711 // function : ClickOnOk
713 //=================================================================================
714 void MeasureGUI_ManageDimensionsDlg::ClickOnOk()
716 setIsApplyAndClose( true );
717 if ( ClickOnApply() )
723 //=================================================================================
724 // function : ClickOnCancel
726 //=================================================================================
727 void MeasureGUI_ManageDimensionsDlg::ClickOnCancel()
729 if ( !AllowedToCancelChanges() )
734 if( myCreateDialog ) {
735 myCreateDialog->close();
739 GEOMBase_Skeleton::ClickOnCancel();
742 //=================================================================================
743 // function : ClickOnApply
745 //=================================================================================
746 bool MeasureGUI_ManageDimensionsDlg::ClickOnApply()
748 if ( myEditObject.isNull() )
753 SalomeApp_Application* anApp = myGeomGUI->getApp();
759 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
765 mySavedPropertyState =
766 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
767 myEditObject->GetStudyEntry(),
768 GEOM::propertyName( GEOM::Dimensions ),
770 .value<GEOMGUI_DimensionProperty>();
772 mySavedPropertyState.SaveToAttribute( aStudy, myEditObject->GetStudyEntry() );
777 //=================================================================================
778 // function : OnFinish
780 //=================================================================================
781 void MeasureGUI_ManageDimensionsDlg::OnFinish()
783 if ( myEditObject.isNull() )
785 GEOMBase_Skeleton::ClickOnCancel();
789 SalomeApp_Application* anApp = myGeomGUI->getApp();
792 GEOMBase_Skeleton::ClickOnCancel();
796 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
799 GEOMBase_Skeleton::ClickOnCancel();
803 // reset preview property state
804 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
805 myEditObject->GetStudyEntry(),
806 GEOM::propertyName( GEOM::Dimensions ),
808 if ( isNeedRedisplay ) {
809 redisplay( myEditObject.get());
813 //=================================================================================
814 // function : enterEvent()
816 //=================================================================================
817 void MeasureGUI_ManageDimensionsDlg::enterEvent( QEvent* )
819 if ( !mainFrame()->GroupConstructors->isEnabled() )
821 OnActivateThisDialog();
825 //=================================================================================
826 // function : OnActivateThisDialog
828 //=================================================================================
829 void MeasureGUI_ManageDimensionsDlg::OnActivateThisDialog()
831 disconnect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
832 GEOMBase_Skeleton::ActivateThisDialog();
833 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
835 SelectionIntoArgument( Selection_Object );
837 if ( myEditObject.isNull() )
839 myObjectSelector->PushButton1->click();
843 //=================================================================================
844 // function : OnDeactivateThisDialog
846 //=================================================================================
847 void MeasureGUI_ManageDimensionsDlg::OnDeactivateThisDialog()
849 if ( AllowedToSaveChanges() )
854 if ( !myEditObject.isNull() )
856 SalomeApp_Study* aStudy = NULL;
857 SalomeApp_Application* anApp = myGeomGUI->getApp();
860 aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
865 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
866 myEditObject->GetStudyEntry(),
867 GEOM::propertyName( GEOM::Dimensions ),
871 redisplay( myEditObject.get() );
874 GEOMBase_Skeleton::DeactivateActiveDialog();
877 //=================================================================================
878 // function : SetEditObject
880 //=================================================================================
881 void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theObj )
885 QString aName = GEOMBase::GetName( theObj.get() );
887 myObjectSelector->LineEdit1->setText( aName );
889 myEditObject = theObj;
891 if ( myEditObject.isNull() )
893 myDimensionView->TreeWidget->clear();
894 myDimensionView->setEnabled( false );
898 SalomeApp_Application* anApp = myGeomGUI->getApp();
904 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
905 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
910 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
916 mySavedPropertyState.LoadFromAttribute( getStudy(), myEditObject->GetStudyEntry() );
918 // set property state for preview
919 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
920 myEditObject->GetStudyEntry(),
921 GEOM::propertyName( GEOM::Dimensions ),
922 mySavedPropertyState );
926 myDimensionView->setEnabled( true );
929 //=================================================================================
930 // function : RestoreState
932 //=================================================================================
933 void MeasureGUI_ManageDimensionsDlg::RestoreState()
935 if ( myEditObject.isNull() )
940 SalomeApp_Application* anApp = myGeomGUI->getApp();
946 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
952 QString aEntry = myEditObject->GetStudyEntry();
954 // reset preview property state
955 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
956 myEditObject->GetStudyEntry(),
957 GEOM::propertyName( GEOM::Dimensions ),
961 //=================================================================================
962 // function : PopulateList
964 //=================================================================================
965 void MeasureGUI_ManageDimensionsDlg::PopulateList()
967 QTreeWidget* aListView = myDimensionView->TreeWidget;
969 // clear list completely if object is null
970 if ( myEditObject.isNull() )
976 // clear only groups data if object is ok
977 QTreeWidgetItem* aDistanceGroupItem = aListView->topLevelItem( GroupItem_Distance );
978 QTreeWidgetItem* aDiameterGroupItem = aListView->topLevelItem( GroupItem_Diameter );
979 QTreeWidgetItem* anAngleGroupItem = aListView->topLevelItem( GroupItem_Angle );
981 // create group items if not exist yet
982 if ( !aDistanceGroupItem || !aDiameterGroupItem || !anAngleGroupItem )
984 aDistanceGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DISTANCE_ITEM" ) ) );
985 aDiameterGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DIAMETER_ITEM" ) ) );
986 anAngleGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "ANGLE_ITEM" ) ) );
990 aListView->addTopLevelItem( aDistanceGroupItem );
991 aListView->addTopLevelItem( aDiameterGroupItem );
992 aListView->addTopLevelItem( anAngleGroupItem );
993 aListView->expandAll();
996 qDeleteAll( aDistanceGroupItem->takeChildren() );
997 qDeleteAll( aDiameterGroupItem->takeChildren() );
998 qDeleteAll( anAngleGroupItem->takeChildren() );
1000 // collect all groupped items
1001 QList<QTreeWidgetItem*> aDistItems;
1002 QList<QTreeWidgetItem*> aDiamItems;
1003 QList<QTreeWidgetItem*> anAngItems;
1005 SalomeApp_Application* anApp = myGeomGUI->getApp();
1011 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1017 QString aEntry = myEditObject->GetStudyEntry();
1019 // get property data to change
1020 GEOMGUI_DimensionProperty aProp =
1021 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1022 myEditObject->GetStudyEntry(),
1023 GEOM::propertyName( GEOM::Dimensions ),
1025 .value<GEOMGUI_DimensionProperty>();
1027 // read dimension records from property
1028 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
1030 QString aName = aProp.GetName( anIt );
1031 bool isVisible = aProp.IsVisible( anIt );
1032 int aType = aProp.GetType( anIt );
1034 QTreeWidgetItem* anItem = new QTreeWidgetItem;
1035 anItem->setText( 0, aName );
1036 anItem->setCheckState( 0, isVisible ? Qt::Checked : Qt::Unchecked );
1037 anItem->setData( 0, Qt::UserRole, anIt );
1038 anItem->setFlags( Qt::ItemIsUserCheckable
1039 | Qt::ItemIsSelectable
1040 | Qt::ItemIsEditable
1041 | Qt::ItemIsEnabled );
1045 case GEOMGUI_DimensionProperty::DimensionType_Length : aDistItems << anItem; break;
1046 case GEOMGUI_DimensionProperty::DimensionType_Diameter : aDiamItems << anItem; break;
1047 case GEOMGUI_DimensionProperty::DimensionType_Angle : anAngItems << anItem; break;
1051 aDistanceGroupItem->addChildren( aDistItems );
1052 aDiameterGroupItem->addChildren( aDiamItems );
1053 anAngleGroupItem->addChildren( anAngItems );
1055 aListView->setItemHidden( aDistanceGroupItem, aDistItems.isEmpty() );
1056 aListView->setItemHidden( aDiameterGroupItem, aDiamItems.isEmpty() );
1057 aListView->setItemHidden( anAngleGroupItem, anAngItems.isEmpty() );
1060 //=================================================================================
1061 // function : HasUnsavedChanges
1063 //=================================================================================
1064 bool MeasureGUI_ManageDimensionsDlg::HasUnsavedChanges()
1066 if ( myEditObject.isNull() )
1071 SalomeApp_Application* anApp = myGeomGUI->getApp();
1077 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1083 GEOMGUI_DimensionProperty aCurrentState =
1084 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1085 myEditObject->GetStudyEntry(),
1086 GEOM::propertyName( GEOM::Dimensions ),
1088 .value<GEOMGUI_DimensionProperty>();
1090 return aCurrentState != mySavedPropertyState;
1093 //=================================================================================
1094 // function : AllowedToCancelChanges
1096 //=================================================================================
1097 bool MeasureGUI_ManageDimensionsDlg::AllowedToCancelChanges()
1099 if ( !HasUnsavedChanges() )
1104 int aResponse = SUIT_MessageBox::warning( this,
1105 tr( "WRN_TITLE_UNSAVED" ),
1106 tr( "WRN_MSG_CHANGES_LOST" ),
1108 QMessageBox::Cancel );
1109 isNeedRedisplay = ( aResponse == QMessageBox::Ok );
1110 return isNeedRedisplay;
1113 //=================================================================================
1114 // function : AllowedToSaveChanges
1116 //=================================================================================
1117 bool MeasureGUI_ManageDimensionsDlg::AllowedToSaveChanges()
1119 if ( !HasUnsavedChanges() )
1124 int aResponse = SUIT_MessageBox::warning( this,
1125 tr( "WRN_TITLE_UNSAVED" ),
1126 tr( "WRN_MSG_CHANGES_SAVE" ),
1128 QMessageBox::Cancel );
1130 return aResponse == QMessageBox::Ok;
1133 //=================================================================================
1134 // function : IdFromItem
1136 //=================================================================================
1137 int MeasureGUI_ManageDimensionsDlg::IdFromItem( QTreeWidgetItem* theItem )
1144 bool isIdOK = false;
1145 const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
1147 return isIdOK ? anId : -1;
1150 //=================================================================================
1151 // function : IdFromPrs
1153 //=================================================================================
1154 int MeasureGUI_ManageDimensionsDlg::IdFromPrs( const Handle(AIS_InteractiveObject)& theAIS )
1156 Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( theAIS->GetOwner() );
1158 if ( anIO.IsNull() )
1163 QString anIOEntry = anIO->getEntry();
1164 QString anEditEntry = myEditObject->GetStudyEntry();
1165 if ( anIOEntry != anEditEntry )
1170 Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( theAIS );
1171 if ( !aLength.IsNull() )
1173 return aLength->GetId();
1176 Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( theAIS );
1177 if ( !aDiameter.IsNull() )
1179 return aDiameter->GetId();
1182 Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( theAIS );
1183 if ( !anAngle.IsNull() )
1185 return anAngle->GetId();
1191 //=================================================================================
1192 // function : SelectInList
1194 //=================================================================================
1195 void MeasureGUI_ManageDimensionsDlg::SelectInList( const Handle(AIS_InteractiveObject)& theIO )
1197 SelectInList( IdFromPrs( theIO ) );
1200 //=================================================================================
1201 // function : SelectInList
1203 //=================================================================================
1204 void MeasureGUI_ManageDimensionsDlg::SelectInList( const int theId )
1206 QTreeWidget* aListOfDimension = myDimensionView->TreeWidget;
1208 QAbstractItemModel* aModel = aListOfDimension->model();
1209 QModelIndexList aIndexes = aModel->match( aModel->index(0, 0),
1212 -1, Qt::MatchRecursive );
1214 if ( aIndexes.isEmpty() )
1216 aListOfDimension->setCurrentIndex( QModelIndex() );
1220 bool isBlocked = aListOfDimension->blockSignals( true );
1221 aListOfDimension->setCurrentIndex( aIndexes.first() );
1222 aListOfDimension->blockSignals( isBlocked );
1225 //=================================================================================
1226 // function : SelectInViewer
1228 //=================================================================================
1229 void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, const int theId )
1231 Handle(AIS_InteractiveContext) anAISContext = theViewer->getAISContext();
1232 if ( anAISContext.IsNull() )
1237 Standard_Boolean isLocal = anAISContext->HasOpenedContext();
1240 anAISContext->ClearSelected( Standard_False );
1244 anAISContext->ClearCurrents( Standard_False );
1247 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
1249 AIS_ListOfInteractive aListOfIO;
1250 aPrs->GetObjects( aListOfIO );
1252 AIS_ListIteratorOfListOfInteractive anIt( aListOfIO );
1253 for ( ; anIt.More(); anIt.Next() )
1255 const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
1256 if ( IdFromPrs( anIO ) != theId )
1260 anAISContext->Deactivate( anIO, AIS_DSM_Line );
1261 anAISContext->Deactivate( anIO, AIS_DSM_Text );
1268 anAISContext->AddOrRemoveSelected( anIO, Standard_False );
1269 anAISContext->Activate( anIO, AIS_DSM_Line );
1270 anAISContext->Activate( anIO, AIS_DSM_Text );
1274 anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False );
1277 anAISContext->UpdateCurrentViewer();
1281 //=================================================================================
1282 // function : RedisplayObject
1284 //=================================================================================
1285 void MeasureGUI_ManageDimensionsDlg::RedisplayObject()
1287 redisplay( myEditObject.get() );
1289 if ( !myOperatedViewer )
1294 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
1295 if ( !aSelectedItem )
1300 StartSelection( myCurrentSelection );
1302 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );