1 // Copyright (C) 2007-2013 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.
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 #include "HYDROGUI_CalculationOp.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_CalculationDlg.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
30 #include "HYDROGUI_Zone.h"
31 #include "HYDROGUI_Region.h"
33 #include <HYDROData_PolylineXY.h>
34 #include <HYDROData_ShapesGroup.h>
35 #include <HYDROData_Iterator.h>
36 #include <HYDROData_Object.h>
37 #include <HYDROData_Tool.h>
39 #include <OCCViewer_ViewManager.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewWindow.h>
43 #include <LightApp_Application.h>
44 #include <LightApp_UpdateFlags.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_DataOwner.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_DataBrowser.h>
52 #include <QApplication>
53 #include <QKeySequence>
56 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
57 : HYDROGUI_Operation( theModule ),
58 myIsEdit( theIsEdit ),
59 myActiveViewManager( NULL ),
60 myPreviewViewManager( NULL )
62 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
65 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
70 void HYDROGUI_CalculationOp::startOperation()
72 HYDROGUI_Operation::startOperation();
77 HYDROGUI_CalculationDlg* aPanel =
78 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
82 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
83 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
85 foreach( aShortcut, aShortcuts )
87 if ( aShortcut->key() ==
88 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
89 SUIT_DataBrowser::RenameShortcut ) ) )
91 aShortcut->setEnabled( false );
98 QStringList anEntryList;
99 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
100 getNamesAndEntries( aSeq, aList, anEntryList );
101 aPanel->setAllGeomObjects( aList, anEntryList );
106 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
107 Handle(HYDROData_PolylineXY) aPolylineObj;
108 QString aPolylineName;
109 for ( ; anIter.More(); anIter.Next() )
111 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
113 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
115 // Check the polyline shape
116 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
117 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
118 aPolylineName = aPolylineObj->GetName();
119 if ( !aPolylineName.isEmpty() )
121 aList.append( aPolylineName );
122 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
127 aPanel->setPolylineNames( aList, anEntryList );
129 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
131 myEditedObject.Nullify();
134 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
135 if ( !myEditedObject.IsNull() )
137 anObjectName = myEditedObject->GetName();
138 aPolylineObj = myEditedObject->GetBoundaryPolyline();
139 if ( aPolylineObj.IsNull() )
141 aPanel->setBoundary( QString() );
145 aPolylineName = aPolylineObj->GetName();
146 aPanel->setBoundary( aPolylineName );
149 aSeq = myEditedObject->GetGeometryObjects();
150 getNamesAndEntries( aSeq, aList, anEntryList );
151 aPanel->includeGeomObjects( aList );
157 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
158 myEditedObject->SetName(anObjectName);
161 aPanel->setObjectName( anObjectName );
162 aPanel->setEditedObject( myEditedObject );
167 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
168 QStringList& theNames, QStringList& theEntries ) const
173 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
174 for ( ; anIter.More(); anIter.Next() )
176 Handle(HYDROData_Entity) anEntity = anIter.Value();
177 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
180 theNames.append( anEntity->GetName() );
181 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
185 void HYDROGUI_CalculationOp::abortOperation()
190 HYDROGUI_Operation::abortOperation();
191 module()->getApp()->updateObjectBrowser();
194 void HYDROGUI_CalculationOp::commitOperation()
197 // Commit transaction
198 commitDocOperation();
199 HYDROGUI_Operation::commitOperation();
202 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
204 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
206 // Connect signals and slots
207 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
208 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
209 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
210 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
211 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
212 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
213 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
214 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
215 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
216 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
217 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
218 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
219 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
220 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
221 connect( aPanel, SIGNAL( objectsSelected() ),
222 SLOT( onObjectsSelected() ) );
223 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
224 SLOT( onBoundarySelected( const QString & ) ) );
229 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
231 bool anIsToUpdateViewer = false;
233 // Remove the old boundary from the operation viewer
234 Handle(HYDROData_PolylineXY) aPrevPolyline =
235 myEditedObject->GetBoundaryPolyline();
236 if ( !aPrevPolyline.IsNull() )
238 module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aPrevPolyline );
239 anIsToUpdateViewer = true;
242 // Set the selected boundary polyline to the calculation case
243 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
244 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
245 myEditedObject->SetBoundaryPolyline( aNewPolyline );
247 if ( myPreviewViewManager )
249 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
252 if ( !aNewPolyline.IsNull() )
254 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
255 if ( !aCtx.IsNull() )
257 showObject( aNewPolyline, aCtx );
258 anIsToUpdateViewer = true;
262 if ( anIsToUpdateViewer )
268 void HYDROGUI_CalculationOp::onObjectsSelected()
270 HYDROGUI_CalculationDlg* aPanel =
271 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
273 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
274 QMap<QString, bool> aSelectedObjsMap;
275 foreach( QString aName, aSelectedObjs )
276 aSelectedObjsMap[aName] = true;
279 // Select the appropriate geometry object shape in the viewer
280 selectionMgr()->clearSelected();
282 // Unhighlight all objects except selected
283 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
284 Handle(HYDROData_Entity) anEntity;
285 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
286 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
289 for ( ; anIter.More(); anIter.Next() )
291 anEntity = anIter.Value();
292 if ( !anEntity.IsNull() )
294 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
297 aName = anEntity->GetName();
298 isSelected = aSelectedObjsMap.contains( aName );
299 aShape->highlight( isSelected, false );
300 aShape->update( false );
306 aLastShape->update( true );
309 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
311 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
312 HYDROGUI_Zone* aZoneItem;
313 selectionMgr()->clearSelected();
316 // Select a region in preview
317 SUIT_DataOwnerPtrList aList( true );
318 DataObjectList aZones = aRegionItem->children();
319 for ( int i = 0; i < aZones.length(); i++ )
321 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
324 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
327 selectionMgr()->setSelected( aList );
331 // select a single zone
332 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
335 SUIT_DataOwnerPtrList aList( true );
336 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
337 selectionMgr()->setSelected( aList );
342 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
344 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
347 QList<HYDROGUI_Zone*> aZonesList;
348 HYDROGUI_Zone* aZone;
349 // Get a list of dropped zones
350 for ( int i = 0; i < theZonesList.length(); i++ )
352 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
355 aZonesList.append( aZone );
358 if ( aZonesList.length() > 0 )
360 aRegion->addZones( aZonesList );
361 HYDROGUI_CalculationDlg* aPanel =
362 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
365 aPanel->refreshZonesBrowser();
372 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
374 QList<HYDROGUI_Zone*> aZonesList;
375 HYDROGUI_Zone* aZone;
376 // Get a list of dropped zones
377 for ( int i = 0; i < theZonesList.length(); i++ )
379 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
382 aZonesList.append( aZone );
385 if ( aZonesList.length() > 0 )
387 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
388 HYDROGUI_CalculationDlg* aPanel =
389 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
392 aPanel->refreshZonesBrowser();
398 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
400 HYDROGUI_CalculationDlg* aPanel =
401 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
404 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
407 aZone->setMergeType( theMergeType, theAltitudeName );
408 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
414 aPanel->refreshZonesBrowser();
418 void HYDROGUI_CalculationOp::onAddObjects()
420 HYDROGUI_CalculationDlg* aPanel =
421 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
425 // Add geometry objects selected in the module browser to the calculation case
426 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
427 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
430 QStringList anAddedList;
431 for (int i = 0; i < aSelectedList.length(); i++)
433 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
434 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
435 if ( anObject.IsNull() )
438 if ( myEditedObject->AddGeometryObject( anObject ) )
439 anAddedList.append( anObject->GetName() );
442 if ( !anAddedList.isEmpty() )
444 aPanel->includeGeomObjects( anAddedList );
449 void HYDROGUI_CalculationOp::onRemoveObjects()
451 // Remove selected objects from the calculation case
452 HYDROGUI_CalculationDlg* aPanel =
453 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
457 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
458 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
461 for (int i = 0; i < aSelectedList.length(); i++)
463 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
464 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
465 if ( anObject.IsNull() )
468 module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anObject );
469 myEditedObject->RemoveGeometryObject( anObject );
472 aPanel->excludeGeomObjects( aSelectedList );
475 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
477 // Check if the case is already modified or not
478 bool isConfirmed = myEditedObject->IsMustBeUpdated();
481 // If not modified check if the case has already defined regions with zones
482 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
483 if ( aSeq.Length() > 0 )
485 // If there are already defined zones then ask a user to confirm zones recalculation
486 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
487 tr( "REGIONS_CHANGED" ),
488 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION" ),
489 QMessageBox::Yes | QMessageBox::No,
490 QMessageBox::No ) == QMessageBox::Yes );
494 isConfirmed = true; // No regions - no zones - nothing to recalculate
500 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
501 QString& theErrorMsg )
503 HYDROGUI_CalculationDlg* aPanel =
504 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
508 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
513 void HYDROGUI_CalculationOp::onApply()
515 QApplication::setOverrideCursor( Qt::WaitCursor );
517 int anUpdateFlags = 0;
520 bool aResult = false;
524 aResult = processApply( anUpdateFlags, anErrorMsg );
526 catch ( Standard_Failure )
528 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
529 anErrorMsg = aFailure->GetMessageString();
537 QApplication::restoreOverrideCursor();
541 module()->update( anUpdateFlags );
547 QString aMsg = tr( "INPUT_VALID_DATA" );
548 if( !anErrorMsg.isEmpty() )
549 aMsg.prepend( anErrorMsg + "\n" );
550 SUIT_MessageBox::critical( module()->getApp()->desktop(),
551 tr( "INSUFFICIENT_INPUT_DATA" ),
556 void HYDROGUI_CalculationOp::onNext( const int theIndex )
560 setAvailableGroups();
562 else if( theIndex==2 )
564 HYDROGUI_CalculationDlg* aPanel =
565 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
569 QApplication::setOverrideCursor( Qt::WaitCursor );
571 QString aNewCaseName = aPanel->getObjectName();
572 QString anOldCaseName = myEditedObject->GetName();
574 bool anIsToUpdateOb = myIsEdit && anOldCaseName != aNewCaseName;
576 // At first we must to update the case name because of
577 // automatic names generation for regions and zones
578 myEditedObject->SetName( aNewCaseName );
580 if ( myEditedObject->IsMustBeUpdated() )
583 myEditedObject->Update();
585 //aPanel->setEditedObject( myEditedObject );
586 aPanel->refreshZonesBrowser();
592 setZonesVisible( true );
595 if ( anIsToUpdateOb )
596 module()->getApp()->updateObjectBrowser( false );
598 QApplication::restoreOverrideCursor();
602 void HYDROGUI_CalculationOp::onHideZones()
604 setZonesVisible( false );
607 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
609 myShowZones = theIsVisible;
610 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
611 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
612 HYDROData_SequenceOfObjects aZones;
613 Handle(HYDROData_Region) aRegion;
614 if ( myPreviewViewManager )
616 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
618 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
619 if ( !aCtx.IsNull() )
621 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
623 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
624 if ( !aRegion.IsNull() )
626 aZones = aRegion->GetZones();
627 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
628 for ( ; aZonesIter.More(); aZonesIter.Next() )
632 showObject( aZonesIter.Value(), aCtx );
636 module()->removeObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZonesIter.Value() );
648 void HYDROGUI_CalculationOp::createPreview()
650 LightApp_Application* anApp = module()->getApp();
651 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
652 Handle(HYDROData_Entity) anEntity;
656 // Gather zones for displaying
657 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
658 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
659 HYDROData_SequenceOfObjects aZones;
660 Handle(HYDROData_Region) aRegion;
661 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
663 anEntity = aRegionsIter.Value();
664 if ( !anEntity.IsNull() )
666 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
667 if ( !aRegion.IsNull() )
669 aZones = aRegion->GetZones();
670 aSeq.Append( aZones );
676 // Get a boundary polyline if any
677 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
679 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
681 if ( !myActiveViewManager )
683 if ( aSeq.IsEmpty() )
686 myActiveViewManager = anApp->activeViewManager();
689 if ( !myPreviewViewManager )
691 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
692 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
693 if ( myPreviewViewManager )
695 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
696 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
698 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
699 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
703 if ( !myPreviewViewManager )
706 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
708 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
709 if ( !aCtx.IsNull() )
711 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
712 for ( ; anIter.More(); anIter.Next() )
714 showObject( anIter.Value(), aCtx );
717 //Process the draw events for viewer
718 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
719 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
727 void HYDROGUI_CalculationOp::showObject( Handle(HYDROData_Entity) theEntity, Handle(AIS_InteractiveContext) theCtx )
729 if ( !theEntity.IsNull() )
731 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, theEntity );
734 aShape = new HYDROGUI_Shape( theCtx, theEntity );
735 module()->setObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, theEntity, aShape );
737 aShape->update( false );
741 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
746 void HYDROGUI_CalculationOp::closePreview()
748 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
749 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
750 QShortcut* aShortcut;
751 foreach( aShortcut, aShortcuts )
753 if ( aShortcut->key() ==
754 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
755 SUIT_DataBrowser::RenameShortcut ) ) )
757 aShortcut->setEnabled( true );
762 if( myPreviewViewManager )
764 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
765 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
767 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
768 myPreviewViewManager = NULL;
771 if( myActiveViewManager )
773 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
774 myActiveViewManager = NULL;
778 void HYDROGUI_CalculationOp::setAvailableGroups()
780 HYDROGUI_CalculationDlg* aPanel =
781 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
783 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
784 QStringList aList, anEntryList;
785 getNamesAndEntries( aSeq, aList, anEntryList );
787 QStringList aGroupsNames;
789 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
790 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
792 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
793 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
794 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
796 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
797 aGroupsNames.append( aGroup->GetName() );
800 if( myEditedObject->IsMustBeUpdated() ) {
801 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
802 Handle(HYDROData_ShapesGroup) aGeomGroup =
803 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
804 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
805 myEditedObject->RemoveGeometryGroup( aGeomGroup );
810 aPanel->setAvailableGroups( aGroupsNames );
811 aPanel->includeGroups( aList );
813 bool isUpdated = myEditedObject->IsMustBeUpdated();
816 void HYDROGUI_CalculationOp::onAddGroups()
818 HYDROGUI_CalculationDlg* aPanel =
819 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
823 // Add geometry objects selected in the module browser to the calculation case
824 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
825 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
828 QStringList anAddedList;
829 for (int i = 0; i < aSelectedList.length(); i++)
831 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
832 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
833 if ( aGroup.IsNull() )
836 if ( myEditedObject->AddGeometryGroup( aGroup ) )
837 anAddedList.append( aGroup->GetName() );
840 if ( !anAddedList.isEmpty() )
842 aPanel->includeGroups( anAddedList );
846 void HYDROGUI_CalculationOp::onRemoveGroups()
848 // Remove selected objects from the calculation case
849 HYDROGUI_CalculationDlg* aPanel =
850 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
854 QStringList aSelectedList = aPanel->getSelectedGroups();
855 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
858 for (int i = 0; i < aSelectedList.length(); i++)
860 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
861 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
862 if ( aGroup.IsNull() )
865 myEditedObject->RemoveGeometryGroup( aGroup );
868 aPanel->excludeGroups( aSelectedList );