1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_ManageDimensionsDlg.cxx
25 // Author : Anton POLETAEV, Open CASCADE S.A.S.
27 #include "MeasureGUI_ManageDimensionsDlg.h"
28 #include "MeasureGUI_CreateDimensionDlg.h"
29 #include "MeasureGUI_DimensionFilter.h"
31 #include <GEOMGUI_DimensionProperty.h>
32 #include <GEOMUtils.hxx>
33 #include <GEOMGUI_OCCSelector.h>
34 #include <GEOM_AISDimension.hxx>
35 #include <GEOM_Constants.h>
39 #include <SOCC_ViewModel.h>
41 #include <SalomeApp_Application.h>
42 #include <SalomeApp_Study.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <SUIT_ViewManager.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_MessageBox.h>
49 #include <AIS_ListOfInteractive.hxx>
50 #include <AIS_ListIteratorOfListOfInteractive.hxx>
51 #include <AIS_InteractiveContext.hxx>
52 #include <SelectMgr_Filter.hxx>
53 #include <SelectMgr_ListOfFilter.hxx>
54 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
56 #include <QTreeWidget>
57 #include <QPushButton>
59 #include <QVBoxLayout>
60 #include <QHBoxLayout>
63 //=================================================================================
64 // function : Constructor
66 //=================================================================================
67 MeasureGUI_ManageDimensionsDlg::MeasureGUI_ManageDimensionsDlg( GeometryGUI* theGUI, QWidget* theParent )
68 : GEOMBase_Skeleton( theGUI, theParent ),
69 myOperatedViewer( NULL ),
70 myCurrentSelection( Selection_None ),
73 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
75 QPixmap aSelectorIcon = aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) );
77 setWindowTitle( tr( "MANAGE_DIMENSIONS_TITLE" ) );
79 mainFrame()->GroupConstructors->setVisible( false );
80 mainFrame()->GroupBoxName->setVisible( false );
82 // construct object selector pane
83 myObjectSelector = new DlgRef_1Sel( centralWidget() );
84 myObjectSelector->TextLabel1->setText( tr( "OBJECT_LABEL" ) );
85 myObjectSelector->LineEdit1->setReadOnly( true );
86 myObjectSelector->PushButton1->setIcon( aSelectorIcon );
87 myObjectSelector->PushButton1->setCheckable( true );
89 // construct dimension list view pane
90 myDimensionView = new MeasureGUI_1TreeWidget_4Button( centralWidget() );
91 myDimensionView->GroupBox->setTitle( tr( "DIMENSIONS_GROUP" ) );
92 myDimensionView->PushButton1->setText( tr( "ADD_BTN" ) );
93 myDimensionView->PushButton2->setText( tr( "REMOVE_BTN" ) );
94 myDimensionView->PushButton3->setText( tr( "SHOW_ALL_BTN" ) );
95 myDimensionView->PushButton4->setText( tr( "HIDE_ALL_BTN" ) );
96 myDimensionView->TreeWidget->setMinimumHeight( 250 );
97 myDimensionView->setEnabled( false );
99 connect( myDimensionView->PushButton1, SIGNAL( clicked() ), SLOT( OnAdd() ) );
100 connect( myDimensionView->PushButton2, SIGNAL( clicked() ), SLOT( OnRemove() ) );
101 connect( myDimensionView->PushButton3, SIGNAL( clicked() ), SLOT( OnShowAll() ) );
102 connect( myDimensionView->PushButton4, SIGNAL( clicked() ), SLOT( OnHideAll() ) );
103 connect( myDimensionView->TreeWidget,
104 SIGNAL( itemChanged( QTreeWidgetItem*, int ) ),
105 SLOT( OnChangeItem( QTreeWidgetItem* ) ) );
106 connect( myDimensionView->TreeWidget,
107 SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ),
108 SLOT( OnSelectItem() ) );
110 // populate tree with top-level items
111 myDimensionView->TreeWidget->setHeaderItem( new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( QString() ) ) );
113 // construct main frame layout
114 QVBoxLayout* aMainLayout = new QVBoxLayout( centralWidget() );
115 aMainLayout->setMargin( 0 );
116 aMainLayout->addWidget( myObjectSelector, 0 );
117 aMainLayout->addWidget( myDimensionView, 1 );
119 // signals and slots connections
120 connect( myObjectSelector->PushButton1, SIGNAL( clicked() ), SLOT( StartObjectSelection() ) );
121 connect( buttonOk(), SIGNAL( clicked() ), SLOT( ClickOnOk() ) );
122 connect( buttonApply(), SIGNAL( clicked() ), SLOT( ClickOnApply() ) );
124 connect( this, SIGNAL( finished( int ) ), SLOT( OnFinish() ) );
126 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
127 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
129 myDimensionInteractor = new MeasureGUI_DimensionInteractor( theGUI, theParent ),
131 SelectionIntoArgument( Selection_Object );
133 if ( myEditObject.isNull() )
135 myObjectSelector->PushButton1->click();
138 setHelpFileName("managing_dimensions_page.html");
141 //=================================================================================
142 // function : Destructor
144 //=================================================================================
145 MeasureGUI_ManageDimensionsDlg::~MeasureGUI_ManageDimensionsDlg()
150 //=================================================================================
151 // function : StartSelection
152 // purpose : Starts specific selection
153 //=================================================================================
154 void MeasureGUI_ManageDimensionsDlg::StartSelection( const Selection theSelection )
158 myCurrentSelection = theSelection;
160 if ( theSelection == Selection_Object && AllowedToCancelChanges() )
162 /* ----------------------------------------------- *
163 * selection of object *
164 * ------------------------------------------------ */
166 globalSelection( GEOM_ALLSHAPES );
167 connect( myGeomGUI->getApp()->selectionMgr(),
168 SIGNAL( currentSelectionChanged() ),
170 SLOT( OnSelection() ) );
172 else if ( theSelection == Selection_Dimension && !myEditObject.isNull() )
174 /* ----------------------------------------------- *
175 * selection of dimension *
176 * ------------------------------------------------ */
178 SalomeApp_Application* anApp = myGeomGUI->getApp();
184 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
185 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
190 myOperatedViewer = dynamic_cast<SOCC_Viewer*>( aViewMgr->getViewModel() );
194 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
196 anAISContext->ClearCurrents( Standard_False );
197 anAISContext->ClearSelected( Standard_False );
198 anAISContext->OpenLocalContext( Standard_True, Standard_False );
200 Handle(MeasureGUI_DimensionFilter) aFilter = new MeasureGUI_DimensionFilter( myEditObject->GetStudyEntry() );
202 anAISContext->AddFilter( aFilter );
204 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
206 QList<SUIT_Selector*> aSelectors;
207 aSelectionMgr->selectors( aSelectors );
208 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
209 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
211 SUIT_Selector* aSelector = *aSelectorIt;
213 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
214 if ( !aGeomSelector )
219 aGeomSelector->setEnabled( false );
222 connect( myOperatedViewer,
223 SIGNAL( selectionChanged() ),
225 SLOT( OnSelection() ) );
227 myDimensionInteractor->Enable();
229 connect( myDimensionInteractor,
230 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
232 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
234 anAISContext->UpdateCurrentViewer();
238 //=================================================================================
239 // function : StopObjectSelection
240 // purpose : Stops specific selection
241 //=================================================================================
242 void MeasureGUI_ManageDimensionsDlg::StopSelection()
244 if ( myCurrentSelection == Selection_Object )
246 /* ----------------------------------------------- *
247 * selection of object *
248 * ------------------------------------------------ */
250 myObjectSelector->PushButton1->setChecked( false );
251 disconnect( myGeomGUI->getApp()->selectionMgr(),
252 SIGNAL( currentSelectionChanged() ),
254 SLOT( OnSelection() ) );
256 else if ( myCurrentSelection == Selection_Dimension && myOperatedViewer )
258 /* ----------------------------------------------- *
259 * selection of dimension *
260 * ------------------------------------------------ */
262 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
264 anAISContext->CloseLocalContext();
266 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
268 QList<SUIT_Selector*> aSelectors;
269 aSelectionMgr->selectors( aSelectors );
270 QList<SUIT_Selector*>::iterator aSelectorIt = aSelectors.begin();
271 for ( ; aSelectorIt != aSelectors.end(); ++aSelectorIt )
273 SUIT_Selector* aSelector = *aSelectorIt;
275 GEOMGUI_OCCSelector* aGeomSelector = dynamic_cast<GEOMGUI_OCCSelector*>( aSelector );
276 if ( !aGeomSelector )
281 aGeomSelector->setEnabled( true );
284 disconnect( myOperatedViewer,
285 SIGNAL( selectionChanged() ),
287 SLOT( OnSelection() ) );
289 myDimensionInteractor->Disable();
291 disconnect( myDimensionInteractor,
292 SIGNAL( InteractionFinished( Handle_AIS_InteractiveObject ) ),
294 SLOT( OnInteractionFinished( Handle_AIS_InteractiveObject ) ) );
297 myCurrentSelection = Selection_None;
302 //=================================================================================
303 // function : OnSelection
305 //=================================================================================
306 void MeasureGUI_ManageDimensionsDlg::OnSelection()
308 SelectionIntoArgument( myCurrentSelection );
311 //=================================================================================
312 // function : SelectionIntoArgument
314 //=================================================================================
315 void MeasureGUI_ManageDimensionsDlg::SelectionIntoArgument( const Selection theSelection )
317 if ( theSelection == Selection_Object )
319 /* ----------------------------------------------- *
320 * selection of object *
321 * ------------------------------------------------ */
323 LightApp_SelectionMgr* aSelectionMgr = myGeomGUI->getApp()->selectionMgr();
324 SALOME_ListIO aSelection;
325 aSelectionMgr->selectedObjects( aSelection );
327 GEOM::GeomObjPtr aSelected;
329 if ( aSelection.Extent() == 1 )
331 aSelected = GEOMBase::ConvertIOinGEOMObject( aSelection.First() );
334 SetEditObject( aSelected );
335 StartSelection( Selection_Dimension );
337 else if ( theSelection == Selection_Dimension && myOperatedViewer )
339 /* ----------------------------------------------- *
340 * selection of dimension *
341 * ------------------------------------------------ */
343 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
345 Handle(AIS_InteractiveContext) anAISContext = myOperatedViewer->getAISContext();
347 // non-single selection is prohibited
348 if ( anAISContext->NbSelected() != 1 )
350 aDimensionList->setCurrentIndex( QModelIndex() );
354 anAISContext->InitSelected();
356 Handle(AIS_InteractiveObject) anAIS;
358 if ( anAISContext->HasOpenedContext() )
360 Handle(SelectMgr_EntityOwner) anAISOwner = anAISContext->SelectedOwner();
361 anAIS = Handle(AIS_InteractiveObject)::DownCast( anAISOwner->Selectable() );
365 anAIS = anAISContext->Current();
368 int aDimensionId = IdFromPrs( anAIS );
370 SelectInList( aDimensionId );
372 if ( aDimensionId >= 0 )
374 SelectInViewer( myOperatedViewer, aDimensionId );
379 //=================================================================================
382 //=================================================================================
383 void MeasureGUI_ManageDimensionsDlg::OnAdd()
385 if(!myCreateDialog) {
386 QWidget* aParent = qobject_cast<QWidget*>( this->parent() );
388 myCreateDialog = new MeasureGUI_CreateDimensionDlg( myEditObject, myGeomGUI, aParent );
389 connect( myCreateDialog, SIGNAL( finished( int ) ), this, SLOT( Resume() ) );
390 // this is necessary as the GEOMBase_Helper switches selection mode on destruction
391 connect( myCreateDialog, SIGNAL( destroyed( QObject* ) ), this, SLOT( Resume() ) );
392 connect( myCreateDialog, SIGNAL( applyClicked() ), this, SLOT( OnDimensionAdded() ) );
393 myCreateDialog->updateGeometry();
394 myCreateDialog->resize( myCreateDialog->minimumSizeHint() );
395 myCreateDialog->show();
397 myCreateDialog->activateWindow();
399 myObjectSelector->setEnabled(false);
400 myDimensionView->setEnabled(false);
403 //=================================================================================
404 // function : OnRemove
406 //=================================================================================
407 void MeasureGUI_ManageDimensionsDlg::OnRemove()
409 int aDimensionId = IdFromItem( myDimensionView->TreeWidget->currentItem() );
410 if ( aDimensionId < 0 )
415 SalomeApp_Application* anApp = myGeomGUI->getApp();
421 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
427 // get property data to change
428 GEOMGUI_DimensionProperty aProp =
429 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
430 myEditObject->GetStudyEntry(),
431 GEOM::propertyName( GEOM::Dimensions ),
433 .value<GEOMGUI_DimensionProperty>();
435 aProp.RemoveRecord( aDimensionId );
437 // store modified property data
438 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
439 myEditObject->GetStudyEntry(),
440 GEOM::propertyName( GEOM::Dimensions ),
448 //=================================================================================
449 // function : OnChangeItem
451 //=================================================================================
452 void MeasureGUI_ManageDimensionsDlg::OnChangeItem( QTreeWidgetItem* theItem )
454 int aDimensionId = IdFromItem( theItem );
455 if ( aDimensionId < 0 )
460 SalomeApp_Application* anApp = myGeomGUI->getApp();
466 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
472 // get property data to change
473 GEOMGUI_DimensionProperty aProp =
474 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
475 myEditObject->GetStudyEntry(),
476 GEOM::propertyName( GEOM::Dimensions ),
478 .value<GEOMGUI_DimensionProperty>();
480 // change property data
481 bool isAnythingChanged = false;
483 QString aName = theItem->text( 0 );
484 if ( aProp.GetName( aDimensionId ) != aName )
486 isAnythingChanged = true;
487 aProp.SetName( aDimensionId, aName );
490 bool isVisible = theItem->checkState( 0 ) == Qt::Checked;
491 if ( aProp.IsVisible( aDimensionId ) != isVisible )
493 isAnythingChanged = true;
494 aProp.SetVisible( aDimensionId, isVisible );
497 // store property data
498 if ( !isAnythingChanged )
503 // store modified property data
504 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
505 myEditObject->GetStudyEntry(),
506 GEOM::propertyName( GEOM::Dimensions ),
512 //=================================================================================
513 // function : OnSelectItem
515 //=================================================================================
516 void MeasureGUI_ManageDimensionsDlg::OnSelectItem()
518 if ( !myOperatedViewer )
523 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
525 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );
528 //=================================================================================
529 // function : OnShowAll
531 //=================================================================================
532 void MeasureGUI_ManageDimensionsDlg::OnShowAll()
535 SalomeApp_Application* anApp = myGeomGUI->getApp();
541 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
547 // get property data to change
548 GEOMGUI_DimensionProperty aProp =
549 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
550 myEditObject->GetStudyEntry(),
551 GEOM::propertyName( GEOM::Dimensions ),
553 .value<GEOMGUI_DimensionProperty>();
555 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
557 bool isBlocked = aDimensionList->blockSignals( true );
559 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
561 aProp.SetVisible( anIt, true );
564 // store modified property data
565 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
566 myEditObject->GetStudyEntry(),
567 GEOM::propertyName( GEOM::Dimensions ),
574 aDimensionList->blockSignals( isBlocked );
577 //=================================================================================
578 // function : OnHideAll
580 //=================================================================================
581 void MeasureGUI_ManageDimensionsDlg::OnHideAll()
584 SalomeApp_Application* anApp = myGeomGUI->getApp();
590 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
596 // get property data to change
597 GEOMGUI_DimensionProperty aProp =
598 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
599 myEditObject->GetStudyEntry(),
600 GEOM::propertyName( GEOM::Dimensions ),
602 .value<GEOMGUI_DimensionProperty>();
604 QTreeWidget* aDimensionList = myDimensionView->TreeWidget;
606 bool isBlocked = aDimensionList->blockSignals( true );
608 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
610 aProp.SetVisible( anIt, false );
613 // store modified property data
614 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
615 myEditObject->GetStudyEntry(),
616 GEOM::propertyName( GEOM::Dimensions ),
623 aDimensionList->blockSignals( isBlocked );
626 //=================================================================================
627 // function : OnInteractionFinished
629 //=================================================================================
630 void MeasureGUI_ManageDimensionsDlg::OnInteractionFinished( Handle(AIS_InteractiveObject) theIO )
632 // update property data
633 SalomeApp_Application* anApp = myGeomGUI->getApp();
639 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
646 TopoDS_Shape anParentSh;
647 if ( GEOMBase::GetShape( myEditObject.get(), anParentSh ) )
649 aLCS = gp_Ax3().Transformed( anParentSh.Location().Transformation() );
652 int aDimensionId = IdFromPrs( theIO );
654 // get property data to change
655 GEOMGUI_DimensionProperty aProp =
656 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
657 myEditObject->GetStudyEntry(),
658 GEOM::propertyName( GEOM::Dimensions ),
660 .value<GEOMGUI_DimensionProperty>();
662 aProp.SetRecord( aDimensionId, Handle(AIS_Dimension)::DownCast( theIO ), aLCS );
664 // store modified property data
665 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
666 myEditObject->GetStudyEntry(),
667 GEOM::propertyName( GEOM::Dimensions ),
671 //=================================================================================
672 // function : Suspend
674 //=================================================================================
675 void MeasureGUI_ManageDimensionsDlg::Suspend()
680 //=================================================================================
681 // function : Suspend
683 //=================================================================================
684 void MeasureGUI_ManageDimensionsDlg::Resume()
688 myObjectSelector->setEnabled(true);
689 myDimensionView->setEnabled(true);
692 if ( !myEditObject.isNull() )
695 StartSelection( Selection_Dimension );
699 //=================================================================================
700 // function : Suspend
702 //=================================================================================
703 void MeasureGUI_ManageDimensionsDlg::OnDimensionAdded() {
704 if ( !myEditObject.isNull() )
710 //=================================================================================
711 // function : ClickOnOk
713 //=================================================================================
714 void MeasureGUI_ManageDimensionsDlg::ClickOnOk()
716 setIsApplyAndClose( true );
717 if ( ClickOnApply() )
723 //=================================================================================
724 // function : ClickOnCancel
726 //=================================================================================
727 void MeasureGUI_ManageDimensionsDlg::ClickOnCancel()
729 if ( !AllowedToCancelChanges() )
734 if( myCreateDialog ) {
735 myCreateDialog->close();
739 GEOMBase_Skeleton::ClickOnCancel();
742 //=================================================================================
743 // function : ClickOnApply
745 //=================================================================================
746 bool MeasureGUI_ManageDimensionsDlg::ClickOnApply()
748 if ( myEditObject.isNull() )
753 SalomeApp_Application* anApp = myGeomGUI->getApp();
759 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
765 mySavedPropertyState =
766 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
767 myEditObject->GetStudyEntry(),
768 GEOM::propertyName( GEOM::Dimensions ),
770 .value<GEOMGUI_DimensionProperty>();
772 mySavedPropertyState.SaveToAttribute( aStudy, myEditObject->GetStudyEntry() );
777 //=================================================================================
778 // function : OnFinish
780 //=================================================================================
781 void MeasureGUI_ManageDimensionsDlg::OnFinish()
783 if ( myEditObject.isNull() )
785 GEOMBase_Skeleton::ClickOnCancel();
789 SalomeApp_Application* anApp = myGeomGUI->getApp();
792 GEOMBase_Skeleton::ClickOnCancel();
796 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
799 GEOMBase_Skeleton::ClickOnCancel();
803 // reset preview property state
804 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
805 myEditObject->GetStudyEntry(),
806 GEOM::propertyName( GEOM::Dimensions ),
810 //=================================================================================
811 // function : enterEvent()
813 //=================================================================================
814 void MeasureGUI_ManageDimensionsDlg::enterEvent( QEvent* )
816 if ( !mainFrame()->GroupConstructors->isEnabled() )
818 OnActivateThisDialog();
822 //=================================================================================
823 // function : OnActivateThisDialog
825 //=================================================================================
826 void MeasureGUI_ManageDimensionsDlg::OnActivateThisDialog()
828 disconnect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
829 GEOMBase_Skeleton::ActivateThisDialog();
830 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
832 SelectionIntoArgument( Selection_Object );
834 if ( myEditObject.isNull() )
836 myObjectSelector->PushButton1->click();
840 //=================================================================================
841 // function : OnDeactivateThisDialog
843 //=================================================================================
844 void MeasureGUI_ManageDimensionsDlg::OnDeactivateThisDialog()
846 if ( AllowedToSaveChanges() )
851 if ( !myEditObject.isNull() )
853 SalomeApp_Study* aStudy = NULL;
854 SalomeApp_Application* anApp = myGeomGUI->getApp();
857 aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
862 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
863 myEditObject->GetStudyEntry(),
864 GEOM::propertyName( GEOM::Dimensions ),
868 redisplay( myEditObject.get() );
871 GEOMBase_Skeleton::DeactivateActiveDialog();
874 //=================================================================================
875 // function : SetEditObject
877 //=================================================================================
878 void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theObj )
882 QString aName = GEOMBase::GetName( theObj.get() );
884 myObjectSelector->LineEdit1->setText( aName );
886 myEditObject = theObj;
888 if ( myEditObject.isNull() )
890 myDimensionView->TreeWidget->clear();
891 myDimensionView->setEnabled( false );
895 SalomeApp_Application* anApp = myGeomGUI->getApp();
901 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
902 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
907 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
913 mySavedPropertyState.LoadFromAttribute( getStudy(), myEditObject->GetStudyEntry() );
915 // set property state for preview
916 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
917 myEditObject->GetStudyEntry(),
918 GEOM::propertyName( GEOM::Dimensions ),
919 mySavedPropertyState );
923 myDimensionView->setEnabled( true );
926 //=================================================================================
927 // function : RestoreState
929 //=================================================================================
930 void MeasureGUI_ManageDimensionsDlg::RestoreState()
932 if ( myEditObject.isNull() )
937 SalomeApp_Application* anApp = myGeomGUI->getApp();
943 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
949 QString aEntry = myEditObject->GetStudyEntry();
951 // reset preview property state
952 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
953 myEditObject->GetStudyEntry(),
954 GEOM::propertyName( GEOM::Dimensions ),
958 //=================================================================================
959 // function : PopulateList
961 //=================================================================================
962 void MeasureGUI_ManageDimensionsDlg::PopulateList()
964 QTreeWidget* aListView = myDimensionView->TreeWidget;
966 // clear list completely if object is null
967 if ( myEditObject.isNull() )
973 // clear only groups data if object is ok
974 QTreeWidgetItem* aDistanceGroupItem = aListView->topLevelItem( GroupItem_Distance );
975 QTreeWidgetItem* aDiameterGroupItem = aListView->topLevelItem( GroupItem_Diameter );
976 QTreeWidgetItem* anAngleGroupItem = aListView->topLevelItem( GroupItem_Angle );
978 // create group items if not exist yet
979 if ( !aDistanceGroupItem || !aDiameterGroupItem || !anAngleGroupItem )
981 aDistanceGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DISTANCE_ITEM" ) ) );
982 aDiameterGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DIAMETER_ITEM" ) ) );
983 anAngleGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "ANGLE_ITEM" ) ) );
987 aListView->addTopLevelItem( aDistanceGroupItem );
988 aListView->addTopLevelItem( aDiameterGroupItem );
989 aListView->addTopLevelItem( anAngleGroupItem );
990 aListView->expandAll();
993 qDeleteAll( aDistanceGroupItem->takeChildren() );
994 qDeleteAll( aDiameterGroupItem->takeChildren() );
995 qDeleteAll( anAngleGroupItem->takeChildren() );
997 // collect all groupped items
998 QList<QTreeWidgetItem*> aDistItems;
999 QList<QTreeWidgetItem*> aDiamItems;
1000 QList<QTreeWidgetItem*> anAngItems;
1002 SalomeApp_Application* anApp = myGeomGUI->getApp();
1008 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1014 QString aEntry = myEditObject->GetStudyEntry();
1016 // get property data to change
1017 GEOMGUI_DimensionProperty aProp =
1018 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1019 myEditObject->GetStudyEntry(),
1020 GEOM::propertyName( GEOM::Dimensions ),
1022 .value<GEOMGUI_DimensionProperty>();
1024 // read dimension records from property
1025 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
1027 QString aName = aProp.GetName( anIt );
1028 bool isVisible = aProp.IsVisible( anIt );
1029 int aType = aProp.GetType( anIt );
1031 QTreeWidgetItem* anItem = new QTreeWidgetItem;
1032 anItem->setText( 0, aName );
1033 anItem->setCheckState( 0, isVisible ? Qt::Checked : Qt::Unchecked );
1034 anItem->setData( 0, Qt::UserRole, anIt );
1035 anItem->setFlags( Qt::ItemIsUserCheckable
1036 | Qt::ItemIsSelectable
1037 | Qt::ItemIsEditable
1038 | Qt::ItemIsEnabled );
1042 case GEOMGUI_DimensionProperty::DimensionType_Length : aDistItems << anItem; break;
1043 case GEOMGUI_DimensionProperty::DimensionType_Diameter : aDiamItems << anItem; break;
1044 case GEOMGUI_DimensionProperty::DimensionType_Angle : anAngItems << anItem; break;
1048 aDistanceGroupItem->addChildren( aDistItems );
1049 aDiameterGroupItem->addChildren( aDiamItems );
1050 anAngleGroupItem->addChildren( anAngItems );
1052 aListView->setItemHidden( aDistanceGroupItem, aDistItems.isEmpty() );
1053 aListView->setItemHidden( aDiameterGroupItem, aDiamItems.isEmpty() );
1054 aListView->setItemHidden( anAngleGroupItem, anAngItems.isEmpty() );
1057 //=================================================================================
1058 // function : HasUnsavedChanges
1060 //=================================================================================
1061 bool MeasureGUI_ManageDimensionsDlg::HasUnsavedChanges()
1063 if ( myEditObject.isNull() )
1068 SalomeApp_Application* anApp = myGeomGUI->getApp();
1074 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1080 GEOMGUI_DimensionProperty aCurrentState =
1081 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1082 myEditObject->GetStudyEntry(),
1083 GEOM::propertyName( GEOM::Dimensions ),
1085 .value<GEOMGUI_DimensionProperty>();
1087 return aCurrentState != mySavedPropertyState;
1090 //=================================================================================
1091 // function : AllowedToCancelChanges
1093 //=================================================================================
1094 bool MeasureGUI_ManageDimensionsDlg::AllowedToCancelChanges()
1096 if ( !HasUnsavedChanges() )
1101 int aResponse = SUIT_MessageBox::warning( this,
1102 tr( "WRN_TITLE_UNSAVED" ),
1103 tr( "WRN_MSG_CHANGES_LOST" ),
1105 QMessageBox::Cancel );
1107 return aResponse == QMessageBox::Ok;
1110 //=================================================================================
1111 // function : AllowedToSaveChanges
1113 //=================================================================================
1114 bool MeasureGUI_ManageDimensionsDlg::AllowedToSaveChanges()
1116 if ( !HasUnsavedChanges() )
1121 int aResponse = SUIT_MessageBox::warning( this,
1122 tr( "WRN_TITLE_UNSAVED" ),
1123 tr( "WRN_MSG_CHANGES_SAVE" ),
1125 QMessageBox::Cancel );
1127 return aResponse == QMessageBox::Ok;
1130 //=================================================================================
1131 // function : IdFromItem
1133 //=================================================================================
1134 int MeasureGUI_ManageDimensionsDlg::IdFromItem( QTreeWidgetItem* theItem )
1141 bool isIdOK = false;
1142 const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
1144 return isIdOK ? anId : -1;
1147 //=================================================================================
1148 // function : IdFromPrs
1150 //=================================================================================
1151 int MeasureGUI_ManageDimensionsDlg::IdFromPrs( const Handle(AIS_InteractiveObject)& theAIS )
1153 Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( theAIS->GetOwner() );
1155 if ( anIO.IsNull() )
1160 QString anIOEntry = anIO->getEntry();
1161 QString anEditEntry = myEditObject->GetStudyEntry();
1162 if ( anIOEntry != anEditEntry )
1167 Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( theAIS );
1168 if ( !aLength.IsNull() )
1170 return aLength->GetId();
1173 Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( theAIS );
1174 if ( !aDiameter.IsNull() )
1176 return aDiameter->GetId();
1179 Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( theAIS );
1180 if ( !anAngle.IsNull() )
1182 return anAngle->GetId();
1188 //=================================================================================
1189 // function : SelectInList
1191 //=================================================================================
1192 void MeasureGUI_ManageDimensionsDlg::SelectInList( const Handle(AIS_InteractiveObject)& theIO )
1194 SelectInList( IdFromPrs( theIO ) );
1197 //=================================================================================
1198 // function : SelectInList
1200 //=================================================================================
1201 void MeasureGUI_ManageDimensionsDlg::SelectInList( const int theId )
1203 QTreeWidget* aListOfDimension = myDimensionView->TreeWidget;
1205 QAbstractItemModel* aModel = aListOfDimension->model();
1206 QModelIndexList aIndexes = aModel->match( aModel->index(0, 0),
1209 -1, Qt::MatchRecursive );
1211 if ( aIndexes.isEmpty() )
1213 aListOfDimension->setCurrentIndex( QModelIndex() );
1217 bool isBlocked = aListOfDimension->blockSignals( true );
1218 aListOfDimension->setCurrentIndex( aIndexes.first() );
1219 aListOfDimension->blockSignals( isBlocked );
1222 //=================================================================================
1223 // function : SelectInViewer
1225 //=================================================================================
1226 void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, const int theId )
1228 Handle(AIS_InteractiveContext) anAISContext = theViewer->getAISContext();
1229 if ( anAISContext.IsNull() )
1234 Standard_Boolean isLocal = anAISContext->HasOpenedContext();
1237 anAISContext->ClearSelected( Standard_False );
1241 anAISContext->ClearCurrents( Standard_False );
1244 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
1246 AIS_ListOfInteractive aListOfIO;
1247 aPrs->GetObjects( aListOfIO );
1249 AIS_ListIteratorOfListOfInteractive anIt( aListOfIO );
1250 for ( ; anIt.More(); anIt.Next() )
1252 const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
1253 if ( IdFromPrs( anIO ) != theId )
1257 anAISContext->Deactivate( anIO, AIS_DSM_Line );
1258 anAISContext->Deactivate( anIO, AIS_DSM_Text );
1265 anAISContext->AddOrRemoveSelected( anIO, Standard_False );
1266 anAISContext->Activate( anIO, AIS_DSM_Line );
1267 anAISContext->Activate( anIO, AIS_DSM_Text );
1271 anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False );
1274 anAISContext->UpdateCurrentViewer();
1278 //=================================================================================
1279 // function : RedisplayObject
1281 //=================================================================================
1282 void MeasureGUI_ManageDimensionsDlg::RedisplayObject()
1284 redisplay( myEditObject.get() );
1286 if ( !myOperatedViewer )
1291 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
1292 if ( !aSelectedItem )
1297 StartSelection( myCurrentSelection );
1299 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );