1 // Copyright (C) 2007-2019 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, theParent ),
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 );
200 anAISContext->ClearSelected( Standard_False );
201 #if OCC_VERSION_LARGE <= 0x07030000
202 anAISContext->OpenLocalContext( Standard_True, Standard_False );
204 Handle(MeasureGUI_DimensionFilter) aFilter = new MeasureGUI_DimensionFilter( myEditObject->GetStudyEntry() );
206 anAISContext->AddFilter( aFilter );
208 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
210 QList<SUIT_Selector*> aSelectors;
211 aSelectionMgr->selectors( aSelectors );
212 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
213 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
215 SUIT_Selector* aSelector = *aSelectorIt;
217 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
218 if ( !aGeomSelector )
223 aGeomSelector->setEnabled( false );
226 connect( myOperatedViewer,
227 SIGNAL( selectionChanged() ),
229 SLOT( OnSelection() ) );
231 myDimensionInteractor->Enable();
233 connect( myDimensionInteractor,
234 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
236 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
238 anAISContext->UpdateCurrentViewer();
242 //=================================================================================
243 // function : StopObjectSelection
244 // purpose : Stops specific selection
245 //=================================================================================
246 void MeasureGUI_ManageDimensionsDlg::StopSelection()
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 #if OCC_VERSION_LARGE <= 0x07030000
268 anAISContext->CloseLocalContext();
270 anAISContext->Deactivate();
271 anAISContext->Activate(0);
274 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
276 QList<SUIT_Selector*> aSelectors;
277 aSelectionMgr->selectors( aSelectors );
278 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
279 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
281 SUIT_Selector* aSelector = *aSelectorIt;
283 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
284 if ( !aGeomSelector )
289 aGeomSelector->setEnabled( true );
292 disconnect( myOperatedViewer,
293 SIGNAL( selectionChanged() ),
295 SLOT( OnSelection() ) );
297 myDimensionInteractor->Disable();
299 disconnect( myDimensionInteractor,
300 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
302 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
305 myCurrentSelection = Selection_None;
310 //=================================================================================
311 // function : OnSelection
313 //=================================================================================
314 void MeasureGUI_ManageDimensionsDlg::OnSelection()
316 SelectionIntoArgument( myCurrentSelection );
319 //=================================================================================
320 // function : SelectionIntoArgument
322 //=================================================================================
323 void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theSelection )
325 if ( theSelection == Selection_Object )
327 /* ----------------------------------------------- *
328 * selection of object *
329 * ------------------------------------------------ */
331 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
332 SALOME_ListIO aSelection;
333 aSelectionMgr->selectedObjects( aSelection );
335 GEOM::GeomObjPtr aSelected;
337 if ( aSelection.Extent() == 1 )
339 aSelected = GEOMBase::ConvertIOinGEOMObject( aSelection.First() );
342 SetEditObject( aSelected );
343 StartSelection( Selection_Dimension );
345 else if ( theSelection == Selection_Dimension && myOperatedViewer )
347 /* ----------------------------------------------- *
348 * selection of dimension *
349 * ------------------------------------------------ */
351 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
353 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
355 // non-single selection is prohibited
356 if ( anAISContext->NbSelected() != 1 )
358 aDimensionList->setCurrentIndex( QModelIndex() );
362 anAISContext->InitSelected();
364 Handle(AIS_InteractiveObject) anAIS;
365 #if OCC_VERSION_LARGE <= 0x07030000
366 if ( anAISContext->HasOpenedContext() )
368 Handle(SelectMgr_EntityOwner) anAISOwner = anAISContext->SelectedOwner();
369 anAIS = Handle(AIS_InteractiveObject)::DownCast( anAISOwner->Selectable() );
374 anAIS = anAISContext->Current();
375 #if OCC_VERSION_LARGE <= 0x07030000
379 int aDimensionId = IdFromPrs( anAIS );
381 SelectInList( aDimensionId );
383 if ( aDimensionId >= 0 )
385 SelectInViewer( myOperatedViewer, aDimensionId );
390 //=================================================================================
393 //=================================================================================
394 void MeasureGUI_ManageDimensionsDlg::OnAdd()
396 if(!myCreateDialog) {
397 QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
399 myCreateDialog = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
400 connect( myCreateDialog, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
401 // this is necessary as the GEOMBase_Helper switches selection mode on destruction
402 connect( myCreateDialog, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
403 connect( myCreateDialog, SIGNAL( applyClicked() ), this, SLOT( OnDimensionAdded() ) );
404 myCreateDialog->updateGeometry();
405 myCreateDialog->resize( myCreateDialog->minimumSizeHint() );
406 myCreateDialog->show();
408 myCreateDialog->activateWindow();
410 myObjectSelector->setEnabled(false);
411 myDimensionView->setEnabled(false);
414 //=================================================================================
415 // function : OnRemove
417 //=================================================================================
418 void MeasureGUI_ManageDimensionsDlg::OnRemove()
420 int aDimensionId = IdFromItem( myDimensionView->TreeWidget->currentItem() );
421 if ( aDimensionId < 0 )
426 SalomeApp_Application* anApp = myGeomGUI->getApp();
432 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
438 // get property data to change
439 GEOMGUI_DimensionProperty aProp =
440 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
441 myEditObject->GetStudyEntry(),
442 GEOM::propertyName( GEOM::Dimensions ),
444 .value<GEOMGUI_DimensionProperty>();
446 aProp.RemoveRecord( aDimensionId );
448 // store modified property data
449 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
450 myEditObject->GetStudyEntry(),
451 GEOM::propertyName( GEOM::Dimensions ),
459 //=================================================================================
460 // function : OnChangeItem
462 //=================================================================================
463 void MeasureGUI_ManageDimensionsDlg::OnChangeItem( QTreeWidgetItem* theItem )
465 int aDimensionId = IdFromItem( theItem );
466 if ( aDimensionId < 0 )
471 SalomeApp_Application* anApp = myGeomGUI->getApp();
477 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
483 // get property data to change
484 GEOMGUI_DimensionProperty aProp =
485 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
486 myEditObject->GetStudyEntry(),
487 GEOM::propertyName( GEOM::Dimensions ),
489 .value<GEOMGUI_DimensionProperty>();
491 // change property data
492 bool isAnythingChanged = false;
494 QString aName = theItem->text( 0 );
495 if ( aProp.GetName( aDimensionId ) != aName )
497 isAnythingChanged = true;
498 aProp.SetName( aDimensionId, aName );
501 bool isVisible = theItem->checkState( 0 ) == Qt::Checked;
502 if ( aProp.IsVisible( aDimensionId ) != isVisible )
504 isAnythingChanged = true;
505 aProp.SetVisible( aDimensionId, isVisible );
508 // store property data
509 if ( !isAnythingChanged )
514 // store modified property data
515 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
516 myEditObject->GetStudyEntry(),
517 GEOM::propertyName( GEOM::Dimensions ),
523 //=================================================================================
524 // function : OnSelectItem
526 //=================================================================================
527 void MeasureGUI_ManageDimensionsDlg::OnSelectItem()
529 if ( !myOperatedViewer )
534 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
536 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );
539 //=================================================================================
540 // function : OnShowAll
542 //=================================================================================
543 void MeasureGUI_ManageDimensionsDlg::OnShowAll()
545 // read property data
546 SalomeApp_Application* anApp = myGeomGUI->getApp();
552 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
558 // get property data to change
559 GEOMGUI_DimensionProperty aProp =
560 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
561 myEditObject->GetStudyEntry(),
562 GEOM::propertyName( GEOM::Dimensions ),
564 .value<GEOMGUI_DimensionProperty>();
566 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
568 bool isBlocked = aDimensionList->blockSignals( true );
570 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
572 aProp.SetVisible( anIt, true );
575 // store modified property data
576 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
577 myEditObject->GetStudyEntry(),
578 GEOM::propertyName( GEOM::Dimensions ),
585 aDimensionList->blockSignals( isBlocked );
588 //=================================================================================
589 // function : OnHideAll
591 //=================================================================================
592 void MeasureGUI_ManageDimensionsDlg::OnHideAll()
594 // read property data
595 SalomeApp_Application* anApp = myGeomGUI->getApp();
601 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
607 // get property data to change
608 GEOMGUI_DimensionProperty aProp =
609 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
610 myEditObject->GetStudyEntry(),
611 GEOM::propertyName( GEOM::Dimensions ),
613 .value<GEOMGUI_DimensionProperty>();
615 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
617 bool isBlocked = aDimensionList->blockSignals( true );
619 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
621 aProp.SetVisible( anIt, false );
624 // store modified property data
625 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
626 myEditObject->GetStudyEntry(),
627 GEOM::propertyName( GEOM::Dimensions ),
634 aDimensionList->blockSignals( isBlocked );
637 //=================================================================================
638 // function : OnInteractionFinished
640 //=================================================================================
641 void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle_AIS_InteractiveObject theIO )
643 // update property data
644 SalomeApp_Application* anApp = myGeomGUI->getApp();
650 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
657 TopoDS_Shape anParentSh;
658 if ( GEOMBase::GetShape( myEditObject.get(), anParentSh ) )
660 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
663 int aDimensionId = IdFromPrs( theIO );
665 // get property data to change
666 GEOMGUI_DimensionProperty aProp =
667 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
668 myEditObject->GetStudyEntry(),
669 GEOM::propertyName( GEOM::Dimensions ),
671 .value<GEOMGUI_DimensionProperty>();
673 aProp.SetRecord( aDimensionId, Handle(AIS_Dimension)::DownCast( theIO ), aLCS );
675 // store modified property data
676 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
677 myEditObject->GetStudyEntry(),
678 GEOM::propertyName( GEOM::Dimensions ),
682 //=================================================================================
683 // function : Suspend
685 //=================================================================================
686 void MeasureGUI_ManageDimensionsDlg::Suspend()
691 //=================================================================================
692 // function : Suspend
694 //=================================================================================
695 void MeasureGUI_ManageDimensionsDlg::Resume()
699 myObjectSelector->setEnabled(true);
700 myDimensionView->setEnabled(true);
703 if ( !myEditObject.isNull() )
706 StartSelection( Selection_Dimension );
710 //=================================================================================
711 // function : Suspend
713 //=================================================================================
714 void MeasureGUI_ManageDimensionsDlg::OnDimensionAdded() {
715 if ( !myEditObject.isNull() )
721 //=================================================================================
722 // function : ClickOnOk
724 //=================================================================================
725 void MeasureGUI_ManageDimensionsDlg::ClickOnOk()
727 setIsApplyAndClose( true );
728 if ( ClickOnApply() )
734 //=================================================================================
735 // function : ClickOnCancel
737 //=================================================================================
738 void MeasureGUI_ManageDimensionsDlg::ClickOnCancel()
740 if ( !AllowedToCancelChanges() )
745 if( myCreateDialog ) {
746 myCreateDialog->close();
750 GEOMBase_Skeleton::ClickOnCancel();
753 //=================================================================================
754 // function : ClickOnApply
756 //=================================================================================
757 bool MeasureGUI_ManageDimensionsDlg::ClickOnApply()
759 if ( myEditObject.isNull() )
764 SalomeApp_Application* anApp = myGeomGUI->getApp();
770 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
776 mySavedPropertyState =
777 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
778 myEditObject->GetStudyEntry(),
779 GEOM::propertyName( GEOM::Dimensions ),
781 .value<GEOMGUI_DimensionProperty>();
783 mySavedPropertyState.SaveToAttribute( myEditObject->GetStudyEntry() );
785 myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
790 //=================================================================================
791 // function : OnFinish
793 //=================================================================================
794 void MeasureGUI_ManageDimensionsDlg::OnFinish()
796 if ( myEditObject.isNull() )
798 GEOMBase_Skeleton::ClickOnCancel();
802 SalomeApp_Application* anApp = myGeomGUI->getApp();
805 GEOMBase_Skeleton::ClickOnCancel();
809 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
812 GEOMBase_Skeleton::ClickOnCancel();
816 // reset preview property state
817 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
818 myEditObject->GetStudyEntry(),
819 GEOM::propertyName( GEOM::Dimensions ),
822 if ( myIsNeedRedisplay ) {
823 redisplay( myEditObject.get() );
826 myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
829 //=================================================================================
830 // function : enterEvent()
832 //=================================================================================
833 void MeasureGUI_ManageDimensionsDlg::enterEvent( QEvent* )
835 if ( !mainFrame()->GroupConstructors->isEnabled() )
837 OnActivateThisDialog();
841 //=================================================================================
842 // function : OnActivateThisDialog
844 //=================================================================================
845 void MeasureGUI_ManageDimensionsDlg::OnActivateThisDialog()
847 disconnect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
848 GEOMBase_Skeleton::ActivateThisDialog();
849 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
851 SelectionIntoArgument( Selection_Object );
853 if ( myEditObject.isNull() )
855 myObjectSelector->PushButton1->click();
859 //=================================================================================
860 // function : OnDeactivateThisDialog
862 //=================================================================================
863 void MeasureGUI_ManageDimensionsDlg::OnDeactivateThisDialog()
865 if ( AllowedToSaveChanges() )
870 if ( !myEditObject.isNull() )
872 SalomeApp_Study* aStudy = NULL;
873 SalomeApp_Application* anApp = myGeomGUI->getApp();
876 aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
881 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
882 myEditObject->GetStudyEntry(),
883 GEOM::propertyName( GEOM::Dimensions ),
887 redisplay( myEditObject.get() );
890 GEOMBase_Skeleton::DeactivateActiveDialog();
893 //=================================================================================
894 // function : SetEditObject
896 //=================================================================================
897 void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theObj )
901 QString aName = GEOMBase::GetName( theObj.get() );
903 myObjectSelector->LineEdit1->setText( aName );
905 myEditObject = theObj;
907 if ( myEditObject.isNull() )
909 myDimensionView->TreeWidget->clear();
910 myDimensionView->setEnabled( false );
914 SalomeApp_Application* anApp = myGeomGUI->getApp();
920 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
921 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
926 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
932 mySavedPropertyState.LoadFromAttribute( myEditObject->GetStudyEntry() );
934 // set property state for preview
935 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
936 myEditObject->GetStudyEntry(),
937 GEOM::propertyName( GEOM::Dimensions ),
938 mySavedPropertyState );
942 myDimensionView->setEnabled( true );
945 //=================================================================================
946 // function : RestoreState
948 //=================================================================================
949 void MeasureGUI_ManageDimensionsDlg::RestoreState()
951 if ( myEditObject.isNull() )
956 SalomeApp_Application* anApp = myGeomGUI->getApp();
962 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
968 QString aEntry = myEditObject->GetStudyEntry();
970 // reset preview property state
971 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
972 myEditObject->GetStudyEntry(),
973 GEOM::propertyName( GEOM::Dimensions ),
977 //=================================================================================
978 // function : PopulateList
980 //=================================================================================
981 void MeasureGUI_ManageDimensionsDlg::PopulateList()
983 QTreeWidget* aListView = myDimensionView->TreeWidget;
985 // clear list completely if object is null
986 if ( myEditObject.isNull() )
992 // clear only groups data if object is ok
993 QTreeWidgetItem* aDistanceGroupItem = aListView->topLevelItem( GroupItem_Distance );
994 QTreeWidgetItem* aDiameterGroupItem = aListView->topLevelItem( GroupItem_Diameter );
995 QTreeWidgetItem* anAngleGroupItem = aListView->topLevelItem( GroupItem_Angle );
997 // create group items if not exist yet
998 if ( !aDistanceGroupItem || !aDiameterGroupItem || !anAngleGroupItem )
1000 aDistanceGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DISTANCE_ITEM" ) ) );
1001 aDiameterGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DIAMETER_ITEM" ) ) );
1002 anAngleGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "ANGLE_ITEM" ) ) );
1006 aListView->addTopLevelItem( aDistanceGroupItem );
1007 aListView->addTopLevelItem( aDiameterGroupItem );
1008 aListView->addTopLevelItem( anAngleGroupItem );
1009 aListView->expandAll();
1012 qDeleteAll( aDistanceGroupItem->takeChildren() );
1013 qDeleteAll( aDiameterGroupItem->takeChildren() );
1014 qDeleteAll( anAngleGroupItem->takeChildren() );
1016 // collect all groupped items
1017 QList<QTreeWidgetItem*> aDistItems;
1018 QList<QTreeWidgetItem*> aDiamItems;
1019 QList<QTreeWidgetItem*> anAngItems;
1021 SalomeApp_Application* anApp = myGeomGUI->getApp();
1027 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1033 QString aEntry = myEditObject->GetStudyEntry();
1035 // get property data to change
1036 GEOMGUI_DimensionProperty aProp =
1037 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1038 myEditObject->GetStudyEntry(),
1039 GEOM::propertyName( GEOM::Dimensions ),
1041 .value<GEOMGUI_DimensionProperty>();
1043 // read dimension records from property
1044 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
1046 QString aName = aProp.GetName( anIt );
1047 bool isVisible = aProp.IsVisible( anIt );
1048 int aType = aProp.GetType( anIt );
1050 QTreeWidgetItem* anItem = new QTreeWidgetItem;
1051 anItem->setText( 0, aName );
1052 anItem->setCheckState( 0, isVisible ? Qt::Checked : Qt::Unchecked );
1053 anItem->setData( 0, Qt::UserRole, anIt );
1054 anItem->setFlags( Qt::ItemIsUserCheckable
1055 | Qt::ItemIsSelectable
1056 | Qt::ItemIsEditable
1057 | Qt::ItemIsEnabled );
1061 case GEOMGUI_DimensionProperty::DimensionType_Length : aDistItems << anItem; break;
1062 case GEOMGUI_DimensionProperty::DimensionType_Diameter : aDiamItems << anItem; break;
1063 case GEOMGUI_DimensionProperty::DimensionType_Angle : anAngItems << anItem; break;
1067 aDistanceGroupItem->addChildren( aDistItems );
1068 aDiameterGroupItem->addChildren( aDiamItems );
1069 anAngleGroupItem->addChildren( anAngItems );
1071 aListView->setItemHidden( aDistanceGroupItem, aDistItems.isEmpty() );
1072 aListView->setItemHidden( aDiameterGroupItem, aDiamItems.isEmpty() );
1073 aListView->setItemHidden( anAngleGroupItem, anAngItems.isEmpty() );
1076 //=================================================================================
1077 // function : HasUnsavedChanges
1079 //=================================================================================
1080 bool MeasureGUI_ManageDimensionsDlg::HasUnsavedChanges()
1082 if ( myEditObject.isNull() )
1087 SalomeApp_Application* anApp = myGeomGUI->getApp();
1093 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1099 GEOMGUI_DimensionProperty aCurrentState =
1100 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1101 myEditObject->GetStudyEntry(),
1102 GEOM::propertyName( GEOM::Dimensions ),
1104 .value<GEOMGUI_DimensionProperty>();
1106 return aCurrentState != mySavedPropertyState;
1109 //=================================================================================
1110 // function : AllowedToCancelChanges
1112 //=================================================================================
1113 bool MeasureGUI_ManageDimensionsDlg::AllowedToCancelChanges()
1115 if ( !HasUnsavedChanges() )
1120 int aResponse = SUIT_MessageBox::warning( this,
1121 tr( "WRN_TITLE_UNSAVED" ),
1122 tr( "WRN_MSG_CHANGES_LOST" ),
1124 QMessageBox::Cancel );
1125 myIsNeedRedisplay = ( aResponse == QMessageBox::Ok );
1126 return myIsNeedRedisplay;
1129 //=================================================================================
1130 // function : AllowedToSaveChanges
1132 //=================================================================================
1133 bool MeasureGUI_ManageDimensionsDlg::AllowedToSaveChanges()
1135 if ( !HasUnsavedChanges() )
1140 int aResponse = SUIT_MessageBox::warning( this,
1141 tr( "WRN_TITLE_UNSAVED" ),
1142 tr( "WRN_MSG_CHANGES_SAVE" ),
1144 QMessageBox::Cancel );
1146 return aResponse == QMessageBox::Ok;
1149 //=================================================================================
1150 // function : IdFromItem
1152 //=================================================================================
1153 int MeasureGUI_ManageDimensionsDlg::IdFromItem( QTreeWidgetItem* theItem )
1160 bool isIdOK = false;
1161 const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
1163 return isIdOK ? anId : -1;
1166 //=================================================================================
1167 // function : IdFromPrs
1169 //=================================================================================
1170 int MeasureGUI_ManageDimensionsDlg::IdFromPrs( const Handle(AIS_InteractiveObject)& theAIS )
1172 Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( theAIS->GetOwner() );
1174 if ( anIO.IsNull() )
1179 QString anIOEntry = anIO->getEntry();
1180 QString anEditEntry = myEditObject->GetStudyEntry();
1181 if ( anIOEntry != anEditEntry )
1186 Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( theAIS );
1187 if ( !aLength.IsNull() )
1189 return aLength->GetId();
1192 Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( theAIS );
1193 if ( !aDiameter.IsNull() )
1195 return aDiameter->GetId();
1198 Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( theAIS );
1199 if ( !anAngle.IsNull() )
1201 return anAngle->GetId();
1207 //=================================================================================
1208 // function : SelectInList
1210 //=================================================================================
1211 void MeasureGUI_ManageDimensionsDlg::SelectInList( const Handle(AIS_InteractiveObject)& theIO )
1213 SelectInList( IdFromPrs( theIO ) );
1216 //=================================================================================
1217 // function : SelectInList
1219 //=================================================================================
1220 void MeasureGUI_ManageDimensionsDlg::SelectInList( const int theId )
1222 QTreeWidget* aListOfDimension = myDimensionView->TreeWidget;
1224 QAbstractItemModel* aModel = aListOfDimension->model();
1225 QModelIndexList aIndexes = aModel->match( aModel->index(0, 0),
1228 -1, Qt::MatchRecursive );
1230 if ( aIndexes.isEmpty() )
1232 aListOfDimension->setCurrentIndex( QModelIndex() );
1236 bool isBlocked = aListOfDimension->blockSignals( true );
1237 aListOfDimension->setCurrentIndex( aIndexes.first() );
1238 aListOfDimension->blockSignals( isBlocked );
1241 //=================================================================================
1242 // function : SelectInViewer
1244 //=================================================================================
1245 void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, const int theId )
1247 Handle(AIS_InteractiveContext) anAISContext = theViewer->getAISContext();
1248 if ( anAISContext.IsNull() )
1252 #if OCC_VERSION_LARGE <= 0x07030000
1253 Standard_Boolean isLocal = anAISContext->HasOpenedContext();
1256 anAISContext->ClearSelected( Standard_False );
1261 anAISContext->ClearCurrents( Standard_False );
1262 #if OCC_VERSION_LARGE <= 0x07030000
1265 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
1267 AIS_ListOfInteractive aListOfIO;
1268 aPrs->GetObjects( aListOfIO );
1270 AIS_ListIteratorOfListOfInteractive anIt( aListOfIO );
1271 for ( ; anIt.More(); anIt.Next() )
1273 const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
1274 if ( IdFromPrs( anIO ) != theId )
1276 #if OCC_VERSION_LARGE <= 0x07030000
1280 anAISContext->Deactivate( anIO, AIS_DSM_Line );
1281 anAISContext->Deactivate( anIO, AIS_DSM_Text );
1284 #if OCC_VERSION_LARGE <= 0x07030000
1290 anAISContext->AddOrRemoveSelected( anIO, Standard_False );
1291 anAISContext->Activate( anIO, AIS_DSM_Line );
1292 anAISContext->Activate( anIO, AIS_DSM_Text );
1293 #if OCC_VERSION_LARGE <= 0x07030000
1298 anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False );
1299 #if OCC_VERSION_LARGE <= 0x07030000
1303 anAISContext->UpdateCurrentViewer();
1307 //=================================================================================
1308 // function : RedisplayObject
1310 //=================================================================================
1311 void MeasureGUI_ManageDimensionsDlg::RedisplayObject()
1313 redisplay( myEditObject.get() );
1315 if ( !myOperatedViewer )
1320 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
1321 if ( !aSelectedItem )
1326 StartSelection( myCurrentSelection );
1328 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );