1 // Copyright (C) 2007-2020 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 );
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( !myGeomGUI || !myGeomGUI->getApp() || !myGeomGUI->getApp()->selectionMgr() )
251 if ( myCurrentSelection == Selection_Object )
253 /* ----------------------------------------------- *
254 * selection of object *
255 * ------------------------------------------------ */
257 myObjectSelector->PushButton1->setChecked( false );
258 disconnect( myGeomGUI->getApp()->selectionMgr(),
259 SIGNAL( currentSelectionChanged() ),
261 SLOT( OnSelection() ) );
263 else if ( myCurrentSelection == Selection_Dimension && myOperatedViewer )
265 /* ----------------------------------------------- *
266 * selection of dimension *
267 * ------------------------------------------------ */
269 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
270 #if OCC_VERSION_LARGE <= 0x07030000
271 anAISContext->CloseLocalContext();
273 anAISContext->Deactivate();
274 anAISContext->Activate(0);
277 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
279 QList<SUIT_Selector*> aSelectors;
280 aSelectionMgr->selectors( aSelectors );
281 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
282 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
284 SUIT_Selector* aSelector = *aSelectorIt;
286 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
287 if ( !aGeomSelector )
292 aGeomSelector->setEnabled( true );
295 disconnect( myOperatedViewer,
296 SIGNAL( selectionChanged() ),
298 SLOT( OnSelection() ) );
300 myDimensionInteractor->Disable();
302 disconnect( myDimensionInteractor,
303 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
305 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
308 myCurrentSelection = Selection_None;
313 //=================================================================================
314 // function : OnSelection
316 //=================================================================================
317 void MeasureGUI_ManageDimensionsDlg::OnSelection()
319 SelectionIntoArgument( myCurrentSelection );
322 //=================================================================================
323 // function : SelectionIntoArgument
325 //=================================================================================
326 void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theSelection )
328 if ( theSelection == Selection_Object )
330 /* ----------------------------------------------- *
331 * selection of object *
332 * ------------------------------------------------ */
334 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
335 SALOME_ListIO aSelection;
336 aSelectionMgr->selectedObjects( aSelection );
338 GEOM::GeomObjPtr aSelected;
340 if ( aSelection.Extent() == 1 )
342 aSelected = GEOMBase::ConvertIOinGEOMObject( aSelection.First() );
345 SetEditObject( aSelected );
346 StartSelection( Selection_Dimension );
348 else if ( theSelection == Selection_Dimension && myOperatedViewer )
350 /* ----------------------------------------------- *
351 * selection of dimension *
352 * ------------------------------------------------ */
354 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
356 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
358 // non-single selection is prohibited
359 if ( anAISContext->NbSelected() != 1 )
361 aDimensionList->setCurrentIndex( QModelIndex() );
365 anAISContext->InitSelected();
367 Handle(AIS_InteractiveObject) anAIS;
368 #if OCC_VERSION_LARGE <= 0x07030000
369 if ( anAISContext->HasOpenedContext() )
371 Handle(SelectMgr_EntityOwner) anAISOwner = anAISContext->SelectedOwner();
372 anAIS = Handle(AIS_InteractiveObject)::DownCast( anAISOwner->Selectable() );
377 anAIS = anAISContext->Current();
378 #if OCC_VERSION_LARGE <= 0x07030000
382 int aDimensionId = IdFromPrs( anAIS );
384 SelectInList( aDimensionId );
386 if ( aDimensionId >= 0 )
388 SelectInViewer( myOperatedViewer, aDimensionId );
393 //=================================================================================
396 //=================================================================================
397 void MeasureGUI_ManageDimensionsDlg::OnAdd()
399 if(!myCreateDialog) {
400 QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
402 myCreateDialog = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
403 connect( myCreateDialog, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
404 // this is necessary as the GEOMBase_Helper switches selection mode on destruction
405 connect( myCreateDialog, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
406 connect( myCreateDialog, SIGNAL( applyClicked() ), this, SLOT( OnDimensionAdded() ) );
407 myCreateDialog->updateGeometry();
408 myCreateDialog->resize( myCreateDialog->minimumSizeHint() );
409 myCreateDialog->show();
411 myCreateDialog->activateWindow();
413 myObjectSelector->setEnabled(false);
414 myDimensionView->setEnabled(false);
417 //=================================================================================
418 // function : OnRemove
420 //=================================================================================
421 void MeasureGUI_ManageDimensionsDlg::OnRemove()
423 int aDimensionId = IdFromItem( myDimensionView->TreeWidget->currentItem() );
424 if ( aDimensionId < 0 )
429 SalomeApp_Application* anApp = myGeomGUI->getApp();
435 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
441 // get property data to change
442 GEOMGUI_DimensionProperty aProp =
443 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
444 myEditObject->GetStudyEntry(),
445 GEOM::propertyName( GEOM::Dimensions ),
447 .value<GEOMGUI_DimensionProperty>();
449 aProp.RemoveRecord( aDimensionId );
451 // store modified property data
452 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
453 myEditObject->GetStudyEntry(),
454 GEOM::propertyName( GEOM::Dimensions ),
462 //=================================================================================
463 // function : OnChangeItem
465 //=================================================================================
466 void MeasureGUI_ManageDimensionsDlg::OnChangeItem( QTreeWidgetItem* theItem )
468 int aDimensionId = IdFromItem( theItem );
469 if ( aDimensionId < 0 )
474 SalomeApp_Application* anApp = myGeomGUI->getApp();
480 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
486 // get property data to change
487 GEOMGUI_DimensionProperty aProp =
488 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
489 myEditObject->GetStudyEntry(),
490 GEOM::propertyName( GEOM::Dimensions ),
492 .value<GEOMGUI_DimensionProperty>();
494 // change property data
495 bool isAnythingChanged = false;
497 QString aName = theItem->text( 0 );
498 if ( aProp.GetName( aDimensionId ) != aName )
500 isAnythingChanged = true;
501 aProp.SetName( aDimensionId, aName );
504 bool isVisible = theItem->checkState( 0 ) == Qt::Checked;
505 if ( aProp.IsVisible( aDimensionId ) != isVisible )
507 isAnythingChanged = true;
508 aProp.SetVisible( aDimensionId, isVisible );
511 // store property data
512 if ( !isAnythingChanged )
517 // store modified property data
518 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
519 myEditObject->GetStudyEntry(),
520 GEOM::propertyName( GEOM::Dimensions ),
526 //=================================================================================
527 // function : OnSelectItem
529 //=================================================================================
530 void MeasureGUI_ManageDimensionsDlg::OnSelectItem()
532 if ( !myOperatedViewer )
537 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
539 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );
542 //=================================================================================
543 // function : OnShowAll
545 //=================================================================================
546 void MeasureGUI_ManageDimensionsDlg::OnShowAll()
548 // read property data
549 SalomeApp_Application* anApp = myGeomGUI->getApp();
555 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
561 // get property data to change
562 GEOMGUI_DimensionProperty aProp =
563 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
564 myEditObject->GetStudyEntry(),
565 GEOM::propertyName( GEOM::Dimensions ),
567 .value<GEOMGUI_DimensionProperty>();
569 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
571 bool isBlocked = aDimensionList->blockSignals( true );
573 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
575 aProp.SetVisible( anIt, true );
578 // store modified property data
579 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
580 myEditObject->GetStudyEntry(),
581 GEOM::propertyName( GEOM::Dimensions ),
588 aDimensionList->blockSignals( isBlocked );
591 //=================================================================================
592 // function : OnHideAll
594 //=================================================================================
595 void MeasureGUI_ManageDimensionsDlg::OnHideAll()
597 // read property data
598 SalomeApp_Application* anApp = myGeomGUI->getApp();
604 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
610 // get property data to change
611 GEOMGUI_DimensionProperty aProp =
612 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
613 myEditObject->GetStudyEntry(),
614 GEOM::propertyName( GEOM::Dimensions ),
616 .value<GEOMGUI_DimensionProperty>();
618 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
620 bool isBlocked = aDimensionList->blockSignals( true );
622 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
624 aProp.SetVisible( anIt, false );
627 // store modified property data
628 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
629 myEditObject->GetStudyEntry(),
630 GEOM::propertyName( GEOM::Dimensions ),
637 aDimensionList->blockSignals( isBlocked );
640 //=================================================================================
641 // function : OnInteractionFinished
643 //=================================================================================
644 void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle_AIS_InteractiveObject theIO )
646 // update property data
647 SalomeApp_Application* anApp = myGeomGUI->getApp();
653 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
660 TopoDS_Shape anParentSh;
661 if ( GEOMBase::GetShape( myEditObject.get(), anParentSh ) )
663 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
666 int aDimensionId = IdFromPrs( theIO );
668 // get property data to change
669 GEOMGUI_DimensionProperty aProp =
670 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
671 myEditObject->GetStudyEntry(),
672 GEOM::propertyName( GEOM::Dimensions ),
674 .value<GEOMGUI_DimensionProperty>();
676 aProp.SetRecord( aDimensionId, Handle(AIS_Dimension)::DownCast( theIO ), aLCS );
678 // store modified property data
679 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
680 myEditObject->GetStudyEntry(),
681 GEOM::propertyName( GEOM::Dimensions ),
685 //=================================================================================
686 // function : Suspend
688 //=================================================================================
689 void MeasureGUI_ManageDimensionsDlg::Suspend()
694 //=================================================================================
695 // function : Suspend
697 //=================================================================================
698 void MeasureGUI_ManageDimensionsDlg::Resume()
702 myObjectSelector->setEnabled(true);
703 myDimensionView->setEnabled(true);
706 if ( !myEditObject.isNull() )
709 StartSelection( Selection_Dimension );
713 //=================================================================================
714 // function : Suspend
716 //=================================================================================
717 void MeasureGUI_ManageDimensionsDlg::OnDimensionAdded() {
718 if ( !myEditObject.isNull() )
724 //=================================================================================
725 // function : ClickOnOk
727 //=================================================================================
728 void MeasureGUI_ManageDimensionsDlg::ClickOnOk()
730 setIsApplyAndClose( true );
731 if ( ClickOnApply() )
737 //=================================================================================
738 // function : ClickOnCancel
740 //=================================================================================
741 void MeasureGUI_ManageDimensionsDlg::ClickOnCancel()
743 if ( !AllowedToCancelChanges() )
748 if( myCreateDialog ) {
749 myCreateDialog->close();
753 GEOMBase_Skeleton::ClickOnCancel();
756 //=================================================================================
757 // function : ClickOnApply
759 //=================================================================================
760 bool MeasureGUI_ManageDimensionsDlg::ClickOnApply()
762 if ( myEditObject.isNull() )
767 SalomeApp_Application* anApp = myGeomGUI->getApp();
773 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
779 mySavedPropertyState =
780 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
781 myEditObject->GetStudyEntry(),
782 GEOM::propertyName( GEOM::Dimensions ),
784 .value<GEOMGUI_DimensionProperty>();
786 mySavedPropertyState.SaveToAttribute( myEditObject->GetStudyEntry() );
788 myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
793 //=================================================================================
794 // function : OnFinish
796 //=================================================================================
797 void MeasureGUI_ManageDimensionsDlg::OnFinish()
799 if ( myEditObject.isNull() )
801 GEOMBase_Skeleton::ClickOnCancel();
805 SalomeApp_Application* anApp = myGeomGUI->getApp();
808 GEOMBase_Skeleton::ClickOnCancel();
812 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
815 GEOMBase_Skeleton::ClickOnCancel();
819 // reset preview property state
820 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
821 myEditObject->GetStudyEntry(),
822 GEOM::propertyName( GEOM::Dimensions ),
825 if ( myIsNeedRedisplay ) {
826 redisplay( myEditObject.get() );
829 myGeomGUI->emitDimensionsUpdated( QString( myEditObject->GetStudyEntry() ) );
832 //=================================================================================
833 // function : enterEvent()
835 //=================================================================================
836 void MeasureGUI_ManageDimensionsDlg::enterEvent( QEvent* )
838 if ( !mainFrame()->GroupConstructors->isEnabled() )
840 OnActivateThisDialog();
844 //=================================================================================
845 // function : OnActivateThisDialog
847 //=================================================================================
848 void MeasureGUI_ManageDimensionsDlg::OnActivateThisDialog()
850 disconnect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
851 GEOMBase_Skeleton::ActivateThisDialog();
852 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
854 SelectionIntoArgument( Selection_Object );
856 if ( myEditObject.isNull() )
858 myObjectSelector->PushButton1->click();
862 //=================================================================================
863 // function : OnDeactivateThisDialog
865 //=================================================================================
866 void MeasureGUI_ManageDimensionsDlg::OnDeactivateThisDialog()
868 if ( AllowedToSaveChanges() )
873 if ( !myEditObject.isNull() )
875 SalomeApp_Study* aStudy = NULL;
876 SalomeApp_Application* anApp = myGeomGUI->getApp();
879 aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
884 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
885 myEditObject->GetStudyEntry(),
886 GEOM::propertyName( GEOM::Dimensions ),
890 redisplay( myEditObject.get() );
893 GEOMBase_Skeleton::DeactivateActiveDialog();
896 //=================================================================================
897 // function : SetEditObject
899 //=================================================================================
900 void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theObj )
904 QString aName = GEOMBase::GetName( theObj.get() );
906 myObjectSelector->LineEdit1->setText( aName );
908 myEditObject = theObj;
910 if ( myEditObject.isNull() )
912 myDimensionView->TreeWidget->clear();
913 myDimensionView->setEnabled( false );
917 SalomeApp_Application* anApp = myGeomGUI->getApp();
923 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
924 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
929 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
935 mySavedPropertyState.LoadFromAttribute( myEditObject->GetStudyEntry() );
937 // set property state for preview
938 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
939 myEditObject->GetStudyEntry(),
940 GEOM::propertyName( GEOM::Dimensions ),
941 mySavedPropertyState );
945 myDimensionView->setEnabled( true );
948 //=================================================================================
949 // function : RestoreState
951 //=================================================================================
952 void MeasureGUI_ManageDimensionsDlg::RestoreState()
954 if ( myEditObject.isNull() )
959 SalomeApp_Application* anApp = myGeomGUI->getApp();
965 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
971 QString aEntry = myEditObject->GetStudyEntry();
973 // reset preview property state
974 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
975 myEditObject->GetStudyEntry(),
976 GEOM::propertyName( GEOM::Dimensions ),
980 //=================================================================================
981 // function : PopulateList
983 //=================================================================================
984 void MeasureGUI_ManageDimensionsDlg::PopulateList()
986 QTreeWidget* aListView = myDimensionView->TreeWidget;
988 // clear list completely if object is null
989 if ( myEditObject.isNull() )
995 // clear only groups data if object is ok
996 QTreeWidgetItem* aDistanceGroupItem = aListView->topLevelItem( GroupItem_Distance );
997 QTreeWidgetItem* aDiameterGroupItem = aListView->topLevelItem( GroupItem_Diameter );
998 QTreeWidgetItem* anAngleGroupItem = aListView->topLevelItem( GroupItem_Angle );
1000 // create group items if not exist yet
1001 if ( !aDistanceGroupItem || !aDiameterGroupItem || !anAngleGroupItem )
1003 aDistanceGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DISTANCE_ITEM" ) ) );
1004 aDiameterGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DIAMETER_ITEM" ) ) );
1005 anAngleGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "ANGLE_ITEM" ) ) );
1009 aListView->addTopLevelItem( aDistanceGroupItem );
1010 aListView->addTopLevelItem( aDiameterGroupItem );
1011 aListView->addTopLevelItem( anAngleGroupItem );
1012 aListView->expandAll();
1015 qDeleteAll( aDistanceGroupItem->takeChildren() );
1016 qDeleteAll( aDiameterGroupItem->takeChildren() );
1017 qDeleteAll( anAngleGroupItem->takeChildren() );
1019 // collect all groupped items
1020 QList<QTreeWidgetItem*> aDistItems;
1021 QList<QTreeWidgetItem*> aDiamItems;
1022 QList<QTreeWidgetItem*> anAngItems;
1024 SalomeApp_Application* anApp = myGeomGUI->getApp();
1030 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1036 QString aEntry = myEditObject->GetStudyEntry();
1038 // get property data to change
1039 GEOMGUI_DimensionProperty aProp =
1040 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1041 myEditObject->GetStudyEntry(),
1042 GEOM::propertyName( GEOM::Dimensions ),
1044 .value<GEOMGUI_DimensionProperty>();
1046 // read dimension records from property
1047 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
1049 QString aName = aProp.GetName( anIt );
1050 bool isVisible = aProp.IsVisible( anIt );
1051 int aType = aProp.GetType( anIt );
1053 QTreeWidgetItem* anItem = new QTreeWidgetItem;
1054 anItem->setText( 0, aName );
1055 anItem->setCheckState( 0, isVisible ? Qt::Checked : Qt::Unchecked );
1056 anItem->setData( 0, Qt::UserRole, anIt );
1057 anItem->setFlags( Qt::ItemIsUserCheckable
1058 | Qt::ItemIsSelectable
1059 | Qt::ItemIsEditable
1060 | Qt::ItemIsEnabled );
1064 case GEOMGUI_DimensionProperty::DimensionType_Length : aDistItems << anItem; break;
1065 case GEOMGUI_DimensionProperty::DimensionType_Diameter : aDiamItems << anItem; break;
1066 case GEOMGUI_DimensionProperty::DimensionType_Angle : anAngItems << anItem; break;
1070 aDistanceGroupItem->addChildren( aDistItems );
1071 aDiameterGroupItem->addChildren( aDiamItems );
1072 anAngleGroupItem->addChildren( anAngItems );
1074 aListView->setItemHidden( aDistanceGroupItem, aDistItems.isEmpty() );
1075 aListView->setItemHidden( aDiameterGroupItem, aDiamItems.isEmpty() );
1076 aListView->setItemHidden( anAngleGroupItem, anAngItems.isEmpty() );
1079 //=================================================================================
1080 // function : HasUnsavedChanges
1082 //=================================================================================
1083 bool MeasureGUI_ManageDimensionsDlg::HasUnsavedChanges()
1085 if ( myEditObject.isNull() )
1090 SalomeApp_Application* anApp = myGeomGUI->getApp();
1096 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1102 GEOMGUI_DimensionProperty aCurrentState =
1103 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1104 myEditObject->GetStudyEntry(),
1105 GEOM::propertyName( GEOM::Dimensions ),
1107 .value<GEOMGUI_DimensionProperty>();
1109 return aCurrentState != mySavedPropertyState;
1112 //=================================================================================
1113 // function : AllowedToCancelChanges
1115 //=================================================================================
1116 bool MeasureGUI_ManageDimensionsDlg::AllowedToCancelChanges()
1118 if ( !HasUnsavedChanges() )
1123 int aResponse = SUIT_MessageBox::warning( this,
1124 tr( "WRN_TITLE_UNSAVED" ),
1125 tr( "WRN_MSG_CHANGES_LOST" ),
1127 QMessageBox::Cancel );
1128 myIsNeedRedisplay = ( aResponse == QMessageBox::Ok );
1129 return myIsNeedRedisplay;
1132 //=================================================================================
1133 // function : AllowedToSaveChanges
1135 //=================================================================================
1136 bool MeasureGUI_ManageDimensionsDlg::AllowedToSaveChanges()
1138 if ( !HasUnsavedChanges() )
1143 int aResponse = SUIT_MessageBox::warning( this,
1144 tr( "WRN_TITLE_UNSAVED" ),
1145 tr( "WRN_MSG_CHANGES_SAVE" ),
1147 QMessageBox::Cancel );
1149 return aResponse == QMessageBox::Ok;
1152 //=================================================================================
1153 // function : IdFromItem
1155 //=================================================================================
1156 int MeasureGUI_ManageDimensionsDlg::IdFromItem( QTreeWidgetItem* theItem )
1163 bool isIdOK = false;
1164 const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
1166 return isIdOK ? anId : -1;
1169 //=================================================================================
1170 // function : IdFromPrs
1172 //=================================================================================
1173 int MeasureGUI_ManageDimensionsDlg::IdFromPrs( const Handle(AIS_InteractiveObject)& theAIS )
1175 Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( theAIS->GetOwner() );
1177 if ( anIO.IsNull() )
1182 QString anIOEntry = anIO->getEntry();
1183 QString anEditEntry = myEditObject->GetStudyEntry();
1184 if ( anIOEntry != anEditEntry )
1189 Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( theAIS );
1190 if ( !aLength.IsNull() )
1192 return aLength->GetId();
1195 Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( theAIS );
1196 if ( !aDiameter.IsNull() )
1198 return aDiameter->GetId();
1201 Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( theAIS );
1202 if ( !anAngle.IsNull() )
1204 return anAngle->GetId();
1210 //=================================================================================
1211 // function : SelectInList
1213 //=================================================================================
1214 void MeasureGUI_ManageDimensionsDlg::SelectInList( const Handle(AIS_InteractiveObject)& theIO )
1216 SelectInList( IdFromPrs( theIO ) );
1219 //=================================================================================
1220 // function : SelectInList
1222 //=================================================================================
1223 void MeasureGUI_ManageDimensionsDlg::SelectInList( const int theId )
1225 QTreeWidget* aListOfDimension = myDimensionView->TreeWidget;
1227 QAbstractItemModel* aModel = aListOfDimension->model();
1228 QModelIndexList aIndexes = aModel->match( aModel->index(0, 0),
1231 -1, Qt::MatchRecursive );
1233 if ( aIndexes.isEmpty() )
1235 aListOfDimension->setCurrentIndex( QModelIndex() );
1239 bool isBlocked = aListOfDimension->blockSignals( true );
1240 aListOfDimension->setCurrentIndex( aIndexes.first() );
1241 aListOfDimension->blockSignals( isBlocked );
1244 //=================================================================================
1245 // function : SelectInViewer
1247 //=================================================================================
1248 void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, const int theId )
1250 Handle(AIS_InteractiveContext) anAISContext = theViewer->getAISContext();
1251 if ( anAISContext.IsNull() )
1255 #if OCC_VERSION_LARGE <= 0x07030000
1256 Standard_Boolean isLocal = anAISContext->HasOpenedContext();
1259 anAISContext->ClearSelected( Standard_False );
1264 anAISContext->ClearCurrents( Standard_False );
1265 #if OCC_VERSION_LARGE <= 0x07030000
1268 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
1270 AIS_ListOfInteractive aListOfIO;
1271 aPrs->GetObjects( aListOfIO );
1273 AIS_ListIteratorOfListOfInteractive anIt( aListOfIO );
1274 for ( ; anIt.More(); anIt.Next() )
1276 const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
1277 if ( IdFromPrs( anIO ) != theId )
1279 #if OCC_VERSION_LARGE <= 0x07030000
1284 #if OCC_VERSION_LARGE > 0x07040000
1285 anAISContext->Deactivate( anIO, PrsDim_DimensionSelectionMode_Line );
1286 anAISContext->Deactivate( anIO, PrsDim_DimensionSelectionMode_Text );
1288 anAISContext->Deactivate( anIO, AIS_DSM_Line );
1289 anAISContext->Deactivate( anIO, AIS_DSM_Text );
1293 #if OCC_VERSION_LARGE <= 0x07030000
1299 anAISContext->AddOrRemoveSelected( anIO, Standard_False );
1301 #if OCC_VERSION_LARGE > 0x07040000
1302 anAISContext->Activate( anIO, PrsDim_DimensionSelectionMode_Line );
1303 anAISContext->Activate( anIO, PrsDim_DimensionSelectionMode_Text );
1305 anAISContext->Activate( anIO, AIS_DSM_Line );
1306 anAISContext->Activate( anIO, AIS_DSM_Text );
1309 #if OCC_VERSION_LARGE <= 0x07030000
1314 anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False );
1315 #if OCC_VERSION_LARGE <= 0x07030000
1319 anAISContext->UpdateCurrentViewer();
1323 //=================================================================================
1324 // function : RedisplayObject
1326 //=================================================================================
1327 void MeasureGUI_ManageDimensionsDlg::RedisplayObject()
1329 redisplay( myEditObject.get() );
1331 if ( !myOperatedViewer )
1336 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
1337 if ( !aSelectedItem )
1342 StartSelection( myCurrentSelection );
1344 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );