1 // Copyright (C) 2007-2021 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 #include <Basics_OCCTVersion.hxx>
66 //=================================================================================
67 // function : Constructor
69 //=================================================================================
70 MeasureGUI_ManageDimensionsDlg::MeasureGUI_ManageDimensionsDlg( GeometryGUI* theGUI, QWidget* theParent )
71 : GEOMBase_Skeleton( theGUI, theParent ),
72 myOperatedViewer( NULL ),
73 myCurrentSelection( Selection_None ),
76 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
78 QPixmap aSelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
80 setWindowTitle( tr( "MANAGE_DIMENSIONS_TITLE" ) );
82 mainFrame()->GroupConstructors->setVisible( false );
83 mainFrame()->GroupBoxName->setVisible( false );
85 // construct object selector pane
86 myObjectSelector = new DlgRef_1Sel( centralWidget() );
87 myObjectSelector->TextLabel1->setText( tr( "OBJECT_LABEL" ) );
88 myObjectSelector->LineEdit1->setReadOnly( true );
89 myObjectSelector->PushButton1->setIcon( aSelectorIcon );
90 myObjectSelector->PushButton1->setCheckable( true );
92 // construct dimension list view pane
93 myDimensionView = new MeasureGUI_1TreeWidget_4Button( centralWidget() );
94 myDimensionView->GroupBox->setTitle( tr( "DIMENSIONS_GROUP" ) );
95 myDimensionView->PushButton1->setText( tr( "ADD_BTN" ) );
96 myDimensionView->PushButton2->setText( tr( "REMOVE_BTN" ) );
97 myDimensionView->PushButton3->setText( tr( "SHOW_ALL_BTN" ) );
98 myDimensionView->PushButton4->setText( tr( "HIDE_ALL_BTN" ) );
99 myDimensionView->TreeWidget->setMinimumHeight( 250 );
100 myDimensionView->setEnabled( false );
102 connect( myDimensionView->PushButton1, SIGNAL( clicked() ), SLOT( OnAdd() ) );
103 connect( myDimensionView->PushButton2, SIGNAL( clicked() ), SLOT( OnRemove() ) );
104 connect( myDimensionView->PushButton3, SIGNAL( clicked() ), SLOT( OnShowAll() ) );
105 connect( myDimensionView->PushButton4, SIGNAL( clicked() ), SLOT( OnHideAll() ) );
106 connect( myDimensionView->TreeWidget,
107 SIGNAL( itemChanged( QTreeWidgetItem*, int ) ),
108 SLOT( OnChangeItem( QTreeWidgetItem* ) ) );
109 connect( myDimensionView->TreeWidget,
110 SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
111 SLOT( OnSelectItem() ) );
113 // populate tree with top-level items
114 myDimensionView->TreeWidget->setHeaderItem( new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( QString() ) ) );
116 // construct main frame layout
117 QVBoxLayout* aMainLayout = new QVBoxLayout( centralWidget() );
118 aMainLayout->setMargin( 0 );
119 aMainLayout->addWidget( myObjectSelector, 0 );
120 aMainLayout->addWidget( myDimensionView, 1 );
122 // signals and slots connections
123 connect( myObjectSelector->PushButton1, SIGNAL( clicked() ), SLOT( StartObjectSelection() ) );
124 connect( buttonOk(), SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
125 connect( buttonApply(), SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
127 connect( this, SIGNAL( finished( int ) ), SLOT( OnFinish() ) );
129 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
130 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
132 myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, this ),
134 SelectionIntoArgument( Selection_Object );
136 if ( myEditObject.isNull() )
138 myObjectSelector->PushButton1->click();
140 myIsNeedRedisplay = false;
141 setHelpFileName("managing_dimensions_page.html");
144 //=================================================================================
145 // function : Destructor
147 //=================================================================================
148 MeasureGUI_ManageDimensionsDlg::~MeasureGUI_ManageDimensionsDlg()
153 //=================================================================================
154 // function : StartSelection
155 // purpose : Starts specific selection
156 //=================================================================================
157 void MeasureGUI_ManageDimensionsDlg::StartSelection( const Selection theSelection )
161 myCurrentSelection = theSelection;
163 if ( theSelection == Selection_Object && AllowedToCancelChanges() )
165 /* ----------------------------------------------- *
166 * selection of object *
167 * ------------------------------------------------ */
169 globalSelection( GEOM_ALLSHAPES );
170 connect( myGeomGUI->getApp()->selectionMgr(),
171 SIGNAL( currentSelectionChanged() ),
173 SLOT( OnSelection() ) );
175 else if ( theSelection == Selection_Dimension && !myEditObject.isNull() )
177 /* ----------------------------------------------- *
178 * selection of dimension *
179 * ------------------------------------------------ */
181 SalomeApp_Application* anApp = myGeomGUI->getApp();
187 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
188 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
193 myOperatedViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
197 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
199 anAISContext->ClearCurrents( Standard_False ); // todo: deprecated OCCT API
200 anAISContext->ClearSelected( 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( !myGeomGUI || !myGeomGUI->getApp() || !myGeomGUI->getApp()->selectionMgr() )
248 if ( myCurrentSelection == Selection_Object )
250 /* ----------------------------------------------- *
251 * selection of object *
252 * ------------------------------------------------ */
254 myObjectSelector->PushButton1->setChecked( false );
255 disconnect( myGeomGUI->getApp()->selectionMgr(),
256 SIGNAL( currentSelectionChanged() ),
258 SLOT( OnSelection() ) );
260 else if ( myCurrentSelection == Selection_Dimension && myOperatedViewer )
262 /* ----------------------------------------------- *
263 * selection of dimension *
264 * ------------------------------------------------ */
266 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
267 anAISContext->Deactivate();
268 anAISContext->Activate(0);
270 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
272 QList<SUIT_Selector*> aSelectors;
273 aSelectionMgr->selectors( aSelectors );
274 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
275 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
277 SUIT_Selector* aSelector = *aSelectorIt;
279 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
280 if ( !aGeomSelector )
285 aGeomSelector->setEnabled( true );
288 disconnect( myOperatedViewer,
289 SIGNAL( selectionChanged() ),
291 SLOT( OnSelection() ) );
293 myDimensionInteractor->Disable();
295 disconnect( myDimensionInteractor,
296 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
298 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
301 myCurrentSelection = Selection_None;
306 //=================================================================================
307 // function : OnSelection
309 //=================================================================================
310 void MeasureGUI_ManageDimensionsDlg::OnSelection()
312 SelectionIntoArgument( myCurrentSelection );
315 //=================================================================================
316 // function : SelectionIntoArgument
318 //=================================================================================
319 void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theSelection )
321 if ( theSelection == Selection_Object )
323 /* ----------------------------------------------- *
324 * selection of object *
325 * ------------------------------------------------ */
327 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
328 SALOME_ListIO aSelection;
329 aSelectionMgr->selectedObjects( aSelection );
331 GEOM::GeomObjPtr aSelected;
333 if ( aSelection.Extent() == 1 )
335 aSelected = GEOMBase::ConvertIOinGEOMObject( aSelection.First() );
338 SetEditObject( aSelected );
339 StartSelection( Selection_Dimension );
341 else if ( theSelection == Selection_Dimension && myOperatedViewer )
343 /* ----------------------------------------------- *
344 * selection of dimension *
345 * ------------------------------------------------ */
347 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
349 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
351 // non-single selection is prohibited
352 if ( anAISContext->NbSelected() != 1 )
354 aDimensionList->setCurrentIndex( QModelIndex() );
358 anAISContext->InitSelected();
360 Handle(AIS_InteractiveObject) anAIS;
361 anAIS = anAISContext->Current(); // todo: deprecated OCCT API
363 int aDimensionId = IdFromPrs( anAIS );
365 SelectInList( aDimensionId );
367 if ( aDimensionId >= 0 )
369 SelectInViewer( myOperatedViewer, aDimensionId );
374 //=================================================================================
377 //=================================================================================
378 void MeasureGUI_ManageDimensionsDlg::OnAdd()
380 if(!myCreateDialog) {
381 QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
383 myCreateDialog = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
384 connect( myCreateDialog, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
385 // this is necessary as the GEOMBase_Helper switches selection mode on destruction
386 connect( myCreateDialog, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
387 connect( myCreateDialog, SIGNAL( applyClicked() ), this, SLOT( OnDimensionAdded() ) );
388 myCreateDialog->updateGeometry();
389 myCreateDialog->resize( myCreateDialog->minimumSizeHint() );
390 myCreateDialog->show();
392 myCreateDialog->activateWindow();
394 myObjectSelector->setEnabled(false);
395 myDimensionView->setEnabled(false);
398 //=================================================================================
399 // function : OnRemove
401 //=================================================================================
402 void MeasureGUI_ManageDimensionsDlg::OnRemove()
404 int aDimensionId = IdFromItem( myDimensionView->TreeWidget->currentItem() );
405 if ( aDimensionId < 0 )
410 SalomeApp_Application* anApp = myGeomGUI->getApp();
416 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
422 // get property data to change
423 GEOMGUI_DimensionProperty aProp =
424 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
425 myEditObject->GetStudyEntry(),
426 GEOM::propertyName( GEOM::Dimensions ),
428 .value<GEOMGUI_DimensionProperty>();
430 aProp.RemoveRecord( aDimensionId );
432 // store modified property data
433 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
434 myEditObject->GetStudyEntry(),
435 GEOM::propertyName( GEOM::Dimensions ),
443 //=================================================================================
444 // function : OnChangeItem
446 //=================================================================================
447 void MeasureGUI_ManageDimensionsDlg::OnChangeItem( QTreeWidgetItem* theItem )
449 int aDimensionId = IdFromItem( theItem );
450 if ( aDimensionId < 0 )
455 SalomeApp_Application* anApp = myGeomGUI->getApp();
461 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
467 // get property data to change
468 GEOMGUI_DimensionProperty aProp =
469 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
470 myEditObject->GetStudyEntry(),
471 GEOM::propertyName( GEOM::Dimensions ),
473 .value<GEOMGUI_DimensionProperty>();
475 // change property data
476 bool isAnythingChanged = false;
478 QString aName = theItem->text( 0 );
479 if ( aProp.GetName( aDimensionId ) != aName )
481 isAnythingChanged = true;
482 aProp.SetName( aDimensionId, aName );
485 bool isVisible = theItem->checkState( 0 ) == Qt::Checked;
486 if ( aProp.IsVisible( aDimensionId ) != isVisible )
488 isAnythingChanged = true;
489 aProp.SetVisible( aDimensionId, isVisible );
492 // store property data
493 if ( !isAnythingChanged )
498 // store modified property data
499 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
500 myEditObject->GetStudyEntry(),
501 GEOM::propertyName( GEOM::Dimensions ),
507 //=================================================================================
508 // function : OnSelectItem
510 //=================================================================================
511 void MeasureGUI_ManageDimensionsDlg::OnSelectItem()
513 if ( !myOperatedViewer )
518 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
520 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );
523 //=================================================================================
524 // function : OnShowAll
526 //=================================================================================
527 void MeasureGUI_ManageDimensionsDlg::OnShowAll()
529 // read property data
530 SalomeApp_Application* anApp = myGeomGUI->getApp();
536 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
542 // get property data to change
543 GEOMGUI_DimensionProperty aProp =
544 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
545 myEditObject->GetStudyEntry(),
546 GEOM::propertyName( GEOM::Dimensions ),
548 .value<GEOMGUI_DimensionProperty>();
550 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
552 bool isBlocked = aDimensionList->blockSignals( true );
554 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
556 aProp.SetVisible( anIt, true );
559 // store modified property data
560 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
561 myEditObject->GetStudyEntry(),
562 GEOM::propertyName( GEOM::Dimensions ),
569 aDimensionList->blockSignals( isBlocked );
572 //=================================================================================
573 // function : OnHideAll
575 //=================================================================================
576 void MeasureGUI_ManageDimensionsDlg::OnHideAll()
578 // read property data
579 SalomeApp_Application* anApp = myGeomGUI->getApp();
585 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
591 // get property data to change
592 GEOMGUI_DimensionProperty aProp =
593 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
594 myEditObject->GetStudyEntry(),
595 GEOM::propertyName( GEOM::Dimensions ),
597 .value<GEOMGUI_DimensionProperty>();
599 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
601 bool isBlocked = aDimensionList->blockSignals( true );
603 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
605 aProp.SetVisible( anIt, false );
608 // store modified property data
609 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
610 myEditObject->GetStudyEntry(),
611 GEOM::propertyName( GEOM::Dimensions ),
618 aDimensionList->blockSignals( isBlocked );
621 //=================================================================================
622 // function : OnInteractionFinished
624 //=================================================================================
625 void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle_AIS_InteractiveObject theIO )
627 // update property data
628 SalomeApp_Application* anApp = myGeomGUI->getApp();
634 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
641 TopoDS_Shape anParentSh;
642 if ( GEOMBase::GetShape( myEditObject.get(), anParentSh ) )
644 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
647 int aDimensionId = IdFromPrs( theIO );
649 // get property data to change
650 GEOMGUI_DimensionProperty aProp =
651 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
652 myEditObject->GetStudyEntry(),
653 GEOM::propertyName( GEOM::Dimensions ),
655 .value<GEOMGUI_DimensionProperty>();
657 aProp.SetRecord( aDimensionId, Handle(AIS_Dimension)::DownCast( theIO ), aLCS );
659 // store modified property data
660 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
661 myEditObject->GetStudyEntry(),
662 GEOM::propertyName( GEOM::Dimensions ),
666 //=================================================================================
667 // function : Suspend
669 //=================================================================================
670 void MeasureGUI_ManageDimensionsDlg::Suspend()
675 //=================================================================================
676 // function : Suspend
678 //=================================================================================
679 void MeasureGUI_ManageDimensionsDlg::Resume()
683 myObjectSelector->setEnabled(true);
684 myDimensionView->setEnabled(true);
687 if ( !myEditObject.isNull() )
690 StartSelection( Selection_Dimension );
694 //=================================================================================
695 // function : Suspend
697 //=================================================================================
698 void MeasureGUI_ManageDimensionsDlg::OnDimensionAdded() {
699 if ( !myEditObject.isNull() )
705 //=================================================================================
706 // function : ClickOnOk
708 //=================================================================================
709 void MeasureGUI_ManageDimensionsDlg::ClickOnOk()
711 setIsApplyAndClose( true );
712 if ( ClickOnApply() )
718 //=================================================================================
719 // function : ClickOnCancel
721 //=================================================================================
722 void MeasureGUI_ManageDimensionsDlg::ClickOnCancel()
724 if ( !AllowedToCancelChanges() )
729 if( myCreateDialog ) {
730 myCreateDialog->close();
734 GEOMBase_Skeleton::ClickOnCancel();
737 //=================================================================================
738 // function : ClickOnApply
740 //=================================================================================
741 bool MeasureGUI_ManageDimensionsDlg::ClickOnApply()
743 if ( myEditObject.isNull() )
748 SalomeApp_Application* anApp = myGeomGUI->getApp();
754 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
760 mySavedPropertyState =
761 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
762 myEditObject->GetStudyEntry(),
763 GEOM::propertyName( GEOM::Dimensions ),
765 .value<GEOMGUI_DimensionProperty>();
767 mySavedPropertyState.SaveToAttribute( myEditObject->GetStudyEntry() );
769 myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
774 //=================================================================================
775 // function : OnFinish
777 //=================================================================================
778 void MeasureGUI_ManageDimensionsDlg::OnFinish()
780 if ( myEditObject.isNull() )
782 GEOMBase_Skeleton::ClickOnCancel();
786 SalomeApp_Application* anApp = myGeomGUI->getApp();
789 GEOMBase_Skeleton::ClickOnCancel();
793 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
796 GEOMBase_Skeleton::ClickOnCancel();
800 // reset preview property state
801 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
802 myEditObject->GetStudyEntry(),
803 GEOM::propertyName( GEOM::Dimensions ),
806 if ( myIsNeedRedisplay ) {
807 redisplay( myEditObject.get() );
810 myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
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( 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 myIsNeedRedisplay = ( aResponse == QMessageBox::Ok );
1110 return myIsNeedRedisplay;
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() )
1236 anAISContext->ClearCurrents( Standard_False ); // todo: deprecated OCCT API
1237 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
1239 AIS_ListOfInteractive aListOfIO;
1240 aPrs->GetObjects( aListOfIO );
1242 AIS_ListIteratorOfListOfInteractive anIt( aListOfIO );
1243 for ( ; anIt.More(); anIt.Next() )
1245 const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
1246 if ( IdFromPrs( anIO ) != theId )
1248 #if OCC_VERSION_LARGE >= 0x070400ff
1249 anAISContext->Deactivate( anIO, PrsDim_DimensionSelectionMode_Line );
1250 anAISContext->Deactivate( anIO, PrsDim_DimensionSelectionMode_Text );
1252 anAISContext->Deactivate( anIO, AIS_DSM_Line );
1253 anAISContext->Deactivate( anIO, AIS_DSM_Text );
1257 anAISContext->AddOrRemoveSelected( anIO, Standard_False );
1259 #if OCC_VERSION_LARGE >= 0x070400ff
1260 anAISContext->Activate( anIO, PrsDim_DimensionSelectionMode_Line );
1261 anAISContext->Activate( anIO, PrsDim_DimensionSelectionMode_Text );
1263 anAISContext->Activate( anIO, AIS_DSM_Line );
1264 anAISContext->Activate( anIO, AIS_DSM_Text );
1267 anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False ); // todo: deprecated OCCT API
1268 anAISContext->UpdateCurrentViewer();
1272 //=================================================================================
1273 // function : RedisplayObject
1275 //=================================================================================
1276 void MeasureGUI_ManageDimensionsDlg::RedisplayObject()
1278 redisplay( myEditObject.get() );
1280 if ( !myOperatedViewer )
1285 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
1286 if ( !aSelectedItem )
1291 StartSelection( myCurrentSelection );
1293 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );