1 // Copyright (C) 2007-2014 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 ),
809 redisplay( myEditObject.get() );
812 //=================================================================================
813 // function : enterEvent()
815 //=================================================================================
816 void MeasureGUI_ManageDimensionsDlg::enterEvent( QEvent* )
818 if ( !mainFrame()->GroupConstructors->isEnabled() )
820 OnActivateThisDialog();
824 //=================================================================================
825 // function : OnActivateThisDialog
827 //=================================================================================
828 void MeasureGUI_ManageDimensionsDlg::OnActivateThisDialog()
830 disconnect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
831 GEOMBase_Skeleton::ActivateThisDialog();
832 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( OnDeactivateThisDialog() ) );
834 SelectionIntoArgument( Selection_Object );
836 if ( myEditObject.isNull() )
838 myObjectSelector->PushButton1->click();
842 //=================================================================================
843 // function : OnDeactivateThisDialog
845 //=================================================================================
846 void MeasureGUI_ManageDimensionsDlg::OnDeactivateThisDialog()
848 if ( AllowedToSaveChanges() )
853 if ( !myEditObject.isNull() )
855 SalomeApp_Study* aStudy = NULL;
856 SalomeApp_Application* anApp = myGeomGUI->getApp();
859 aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
864 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
865 myEditObject->GetStudyEntry(),
866 GEOM::propertyName( GEOM::Dimensions ),
870 redisplay( myEditObject.get() );
873 GEOMBase_Skeleton::DeactivateActiveDialog();
876 //=================================================================================
877 // function : SetEditObject
879 //=================================================================================
880 void MeasureGUI_ManageDimensionsDlg::SetEditObject( const GEOM::GeomObjPtr& theObj )
884 QString aName = GEOMBase::GetName( theObj.get() );
886 myObjectSelector->LineEdit1->setText( aName );
888 myEditObject = theObj;
890 if ( myEditObject.isNull() )
892 myDimensionView->setEnabled( false );
897 SalomeApp_Application* anApp = myGeomGUI->getApp();
903 SUIT_ViewManager* aViewMgr = anApp->activeViewManager();
904 if ( aViewMgr->getType() != SOCC_Viewer::Type() )
909 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
915 mySavedPropertyState.LoadFromAttribute( getStudy(), myEditObject->GetStudyEntry() );
917 // set property state for preview
918 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
919 myEditObject->GetStudyEntry(),
920 GEOM::propertyName( GEOM::Dimensions ),
921 mySavedPropertyState );
925 myDimensionView->setEnabled( true );
928 //=================================================================================
929 // function : RestoreState
931 //=================================================================================
932 void MeasureGUI_ManageDimensionsDlg::RestoreState()
934 if ( myEditObject.isNull() )
939 SalomeApp_Application* anApp = myGeomGUI->getApp();
945 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
951 QString aEntry = myEditObject->GetStudyEntry();
953 // reset preview property state
954 aStudy->setObjectProperty( GEOM::sharedPropertiesId(),
955 myEditObject->GetStudyEntry(),
956 GEOM::propertyName( GEOM::Dimensions ),
962 //=================================================================================
963 // function : PopulateList
965 //=================================================================================
966 void MeasureGUI_ManageDimensionsDlg::PopulateList()
968 QTreeWidget* aListView = myDimensionView->TreeWidget;
970 // clear list completely if object is null
971 if ( myEditObject.isNull() )
977 // clear only groups data if object is ok
978 QTreeWidgetItem* aDistanceGroupItem = aListView->topLevelItem( GroupItem_Distance );
979 QTreeWidgetItem* aDiameterGroupItem = aListView->topLevelItem( GroupItem_Diameter );
980 QTreeWidgetItem* anAngleGroupItem = aListView->topLevelItem( GroupItem_Angle );
982 // create group items if not exist yet
983 if ( !aDistanceGroupItem || !aDiameterGroupItem || !anAngleGroupItem )
985 aDistanceGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DISTANCE_ITEM" ) ) );
986 aDiameterGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "DIAMETER_ITEM" ) ) );
987 anAngleGroupItem = new QTreeWidgetItem( (QTreeWidget*)NULL, QStringList( tr( "ANGLE_ITEM" ) ) );
991 aListView->addTopLevelItem( aDistanceGroupItem );
992 aListView->addTopLevelItem( aDiameterGroupItem );
993 aListView->addTopLevelItem( anAngleGroupItem );
994 aListView->expandAll();
997 qDeleteAll( aDistanceGroupItem->takeChildren() );
998 qDeleteAll( aDiameterGroupItem->takeChildren() );
999 qDeleteAll( anAngleGroupItem->takeChildren() );
1001 // collect all groupped items
1002 QList<QTreeWidgetItem*> aDistItems;
1003 QList<QTreeWidgetItem*> aDiamItems;
1004 QList<QTreeWidgetItem*> anAngItems;
1006 SalomeApp_Application* anApp = myGeomGUI->getApp();
1012 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1018 QString aEntry = myEditObject->GetStudyEntry();
1020 // get property data to change
1021 GEOMGUI_DimensionProperty aProp =
1022 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1023 myEditObject->GetStudyEntry(),
1024 GEOM::propertyName( GEOM::Dimensions ),
1026 .value<GEOMGUI_DimensionProperty>();
1028 // read dimension records from property
1029 for ( int anIt = 0; anIt < aProp.GetNumber(); ++anIt )
1031 QString aName = aProp.GetName( anIt );
1032 bool isVisible = aProp.IsVisible( anIt );
1033 int aType = aProp.GetType( anIt );
1035 QTreeWidgetItem* anItem = new QTreeWidgetItem;
1036 anItem->setText( 0, aName );
1037 anItem->setCheckState( 0, isVisible ? Qt::Checked : Qt::Unchecked );
1038 anItem->setData( 0, Qt::UserRole, anIt );
1039 anItem->setFlags( Qt::ItemIsUserCheckable
1040 | Qt::ItemIsSelectable
1041 | Qt::ItemIsEditable
1042 | Qt::ItemIsEnabled );
1046 case GEOMGUI_DimensionProperty::DimensionType_Length : aDistItems << anItem; break;
1047 case GEOMGUI_DimensionProperty::DimensionType_Diameter : aDiamItems << anItem; break;
1048 case GEOMGUI_DimensionProperty::DimensionType_Angle : anAngItems << anItem; break;
1052 aDistanceGroupItem->addChildren( aDistItems );
1053 aDiameterGroupItem->addChildren( aDiamItems );
1054 anAngleGroupItem->addChildren( anAngItems );
1056 aListView->setItemHidden( aDistanceGroupItem, aDistItems.isEmpty() );
1057 aListView->setItemHidden( aDiameterGroupItem, aDiamItems.isEmpty() );
1058 aListView->setItemHidden( anAngleGroupItem, anAngItems.isEmpty() );
1061 //=================================================================================
1062 // function : HasUnsavedChanges
1064 //=================================================================================
1065 bool MeasureGUI_ManageDimensionsDlg::HasUnsavedChanges()
1067 if ( myEditObject.isNull() )
1072 SalomeApp_Application* anApp = myGeomGUI->getApp();
1078 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
1084 GEOMGUI_DimensionProperty aCurrentState =
1085 aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1086 myEditObject->GetStudyEntry(),
1087 GEOM::propertyName( GEOM::Dimensions ),
1089 .value<GEOMGUI_DimensionProperty>();
1091 return aCurrentState != mySavedPropertyState;
1094 //=================================================================================
1095 // function : AllowedToCancelChanges
1097 //=================================================================================
1098 bool MeasureGUI_ManageDimensionsDlg::AllowedToCancelChanges()
1100 if ( !HasUnsavedChanges() )
1105 int aResponse = SUIT_MessageBox::warning( this,
1106 tr( "WRN_TITLE_UNSAVED" ),
1107 tr( "WRN_MSG_CHANGES_LOST" ),
1109 QMessageBox::Cancel );
1111 return aResponse == QMessageBox::Ok;
1114 //=================================================================================
1115 // function : AllowedToSaveChanges
1117 //=================================================================================
1118 bool MeasureGUI_ManageDimensionsDlg::AllowedToSaveChanges()
1120 if ( !HasUnsavedChanges() )
1125 int aResponse = SUIT_MessageBox::warning( this,
1126 tr( "WRN_TITLE_UNSAVED" ),
1127 tr( "WRN_MSG_CHANGES_SAVE" ),
1129 QMessageBox::Cancel );
1131 return aResponse == QMessageBox::Ok;
1134 //=================================================================================
1135 // function : IdFromItem
1137 //=================================================================================
1138 int MeasureGUI_ManageDimensionsDlg::IdFromItem( QTreeWidgetItem* theItem )
1145 bool isIdOK = false;
1146 const int anId = theItem->data( 0, Qt::UserRole ).toInt( &isIdOK );
1148 return isIdOK ? anId : -1;
1151 //=================================================================================
1152 // function : IdFromPrs
1154 //=================================================================================
1155 int MeasureGUI_ManageDimensionsDlg::IdFromPrs( const Handle(AIS_InteractiveObject)& theAIS )
1157 Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( theAIS->GetOwner() );
1159 if ( anIO.IsNull() )
1164 QString anIOEntry = anIO->getEntry();
1165 QString anEditEntry = myEditObject->GetStudyEntry();
1166 if ( anIOEntry != anEditEntry )
1171 Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( theAIS );
1172 if ( !aLength.IsNull() )
1174 return aLength->GetId();
1177 Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( theAIS );
1178 if ( !aDiameter.IsNull() )
1180 return aDiameter->GetId();
1183 Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( theAIS );
1184 if ( !anAngle.IsNull() )
1186 return anAngle->GetId();
1192 //=================================================================================
1193 // function : SelectInList
1195 //=================================================================================
1196 void MeasureGUI_ManageDimensionsDlg::SelectInList( const Handle(AIS_InteractiveObject)& theIO )
1198 SelectInList( IdFromPrs( theIO ) );
1201 //=================================================================================
1202 // function : SelectInList
1204 //=================================================================================
1205 void MeasureGUI_ManageDimensionsDlg::SelectInList( const int theId )
1207 QTreeWidget* aListOfDimension = myDimensionView->TreeWidget;
1209 QAbstractItemModel* aModel = aListOfDimension->model();
1210 QModelIndexList aIndexes = aModel->match( aModel->index(0, 0),
1213 -1, Qt::MatchRecursive );
1215 if ( aIndexes.isEmpty() )
1217 aListOfDimension->setCurrentIndex( QModelIndex() );
1221 bool isBlocked = aListOfDimension->blockSignals( true );
1222 aListOfDimension->setCurrentIndex( aIndexes.first() );
1223 aListOfDimension->blockSignals( isBlocked );
1226 //=================================================================================
1227 // function : SelectInViewer
1229 //=================================================================================
1230 void MeasureGUI_ManageDimensionsDlg::SelectInViewer( SOCC_Viewer* theViewer, const int theId )
1232 Handle(AIS_InteractiveContext) anAISContext = theViewer->getAISContext();
1233 if ( anAISContext.IsNull() )
1238 Standard_Boolean isLocal = anAISContext->HasOpenedContext();
1241 anAISContext->ClearSelected( Standard_False );
1245 anAISContext->ClearCurrents( Standard_False );
1248 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( theViewer->CreatePrs( myEditObject->GetStudyEntry() ) );
1250 AIS_ListOfInteractive aListOfIO;
1251 aPrs->GetObjects( aListOfIO );
1253 AIS_ListIteratorOfListOfInteractive anIt( aListOfIO );
1254 for ( ; anIt.More(); anIt.Next() )
1256 const Handle(AIS_InteractiveObject)& anIO = anIt.Value();
1257 if ( IdFromPrs( anIO ) != theId )
1261 anAISContext->Deactivate( anIO, AIS_DSM_Line );
1262 anAISContext->Deactivate( anIO, AIS_DSM_Text );
1269 anAISContext->AddOrRemoveSelected( anIO, Standard_False );
1270 anAISContext->Activate( anIO, AIS_DSM_Line );
1271 anAISContext->Activate( anIO, AIS_DSM_Text );
1275 anAISContext->AddOrRemoveCurrentObject( anIO, Standard_False );
1278 anAISContext->UpdateCurrentViewer();
1282 //=================================================================================
1283 // function : RedisplayObject
1285 //=================================================================================
1286 void MeasureGUI_ManageDimensionsDlg::RedisplayObject()
1288 redisplay( myEditObject.get() );
1290 if ( !myOperatedViewer )
1295 QTreeWidgetItem* aSelectedItem = myDimensionView->TreeWidget->currentItem();
1296 if ( !aSelectedItem )
1301 StartSelection( myCurrentSelection );
1303 SelectInViewer( myOperatedViewer, IdFromItem( aSelectedItem ) );