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 );
97 QStringList anEntryList;
98 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
99 getNamesAndEntries( aSeq, aList, anEntryList );
100 aPanel->setAllGeomObjects( aList, anEntryList );
105 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
106 Handle(HYDROData_PolylineXY) aPolylineObj;
107 QString aPolylineName;
108 for ( ; anIter.More(); anIter.Next() )
110 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
112 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
114 // Check the polyline shape
115 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
116 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
117 aPolylineName = aPolylineObj->GetName();
118 if ( !aPolylineName.isEmpty() )
120 aList.append( aPolylineName );
121 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
126 aPanel->setPolylineNames( aList, anEntryList );
128 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
130 myEditedObject.Nullify();
133 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
134 if ( !myEditedObject.IsNull() )
136 anObjectName = myEditedObject->GetName();
137 aPolylineObj = myEditedObject->GetBoundaryPolyline();
138 if ( aPolylineObj.IsNull() )
140 aPanel->setBoundary( QString() );
144 aPolylineName = aPolylineObj->GetName();
145 aPanel->setBoundary( aPolylineName );
148 aSeq = myEditedObject->GetGeometryObjects();
149 getNamesAndEntries( aSeq, aList, anEntryList );
150 aPanel->includeGeomObjects( aList );
156 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
157 myEditedObject->SetName(anObjectName);
160 aPanel->setObjectName( anObjectName );
161 aPanel->setEditedObject( myEditedObject );
166 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
167 QStringList& theNames, QStringList& theEntries ) const
172 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
173 for ( ; anIter.More(); anIter.Next() )
175 Handle(HYDROData_Entity) anEntity = anIter.Value();
176 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
179 theNames.append( anEntity->GetName() );
180 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
184 void HYDROGUI_CalculationOp::abortOperation()
189 HYDROGUI_Operation::abortOperation();
190 module()->getApp()->updateObjectBrowser();
193 void HYDROGUI_CalculationOp::commitOperation()
196 // Commit transaction
197 commitDocOperation();
198 HYDROGUI_Operation::commitOperation();
201 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
203 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
205 // Connect signals and slots
206 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
207 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
208 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
209 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
210 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
211 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
212 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
213 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
214 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
215 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
216 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
217 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
218 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
219 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
220 connect( aPanel, SIGNAL( objectsSelected() ),
221 SLOT( onObjectsSelected() ) );
222 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
223 SLOT( onBoundarySelected( const QString & ) ) );
228 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
230 bool anIsToUpdateViewer = false;
232 // Remove the old boundary from the operation viewer
233 Handle(HYDROData_PolylineXY) aPrevPolyline =
234 myEditedObject->GetBoundaryPolyline();
235 if ( !aPrevPolyline.IsNull() )
237 setObjectVisibility( aPrevPolyline, false );
238 anIsToUpdateViewer = true;
241 // Set the selected boundary polyline to the calculation case
242 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
243 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
244 myEditedObject->SetBoundaryPolyline( aNewPolyline );
246 if ( myPreviewViewManager )
248 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
251 if ( !aNewPolyline.IsNull() )
253 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
254 if ( !aCtx.IsNull() )
256 setObjectVisibility( aNewPolyline, true );
257 anIsToUpdateViewer = true;
261 if ( anIsToUpdateViewer )
262 module()->update( UF_OCCViewer );
267 void HYDROGUI_CalculationOp::onObjectsSelected()
269 HYDROGUI_CalculationDlg* aPanel =
270 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
272 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
273 QMap<QString, bool> aSelectedObjsMap;
274 foreach( QString aName, aSelectedObjs )
275 aSelectedObjsMap[aName] = true;
278 // Select the appropriate geometry object shape in the viewer
279 selectionMgr()->clearSelected();
281 // Unhighlight all objects except selected
282 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
283 Handle(HYDROData_Entity) anEntity;
284 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
285 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
288 for ( ; anIter.More(); anIter.Next() )
290 anEntity = anIter.Value();
291 if ( !anEntity.IsNull() )
293 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
296 aName = anEntity->GetName();
297 isSelected = aSelectedObjsMap.contains( aName );
298 aShape->highlight( isSelected, false );
299 aShape->update( false );
305 aLastShape->update( true );
308 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
310 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
311 HYDROGUI_Zone* aZoneItem;
312 selectionMgr()->clearSelected();
315 // Select a region in preview
316 SUIT_DataOwnerPtrList aList( true );
317 DataObjectList aZones = aRegionItem->children();
318 for ( int i = 0; i < aZones.length(); i++ )
320 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
323 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
326 selectionMgr()->setSelected( aList );
330 // select a single zone
331 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
334 SUIT_DataOwnerPtrList aList( true );
335 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
336 selectionMgr()->setSelected( aList );
341 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
343 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
346 QList<HYDROGUI_Zone*> aZonesList;
347 HYDROGUI_Zone* aZone;
348 // Get a list of dropped zones
349 for ( int i = 0; i < theZonesList.length(); i++ )
351 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
354 aZonesList.append( aZone );
357 if ( aZonesList.length() > 0 )
359 aRegion->addZones( aZonesList );
360 HYDROGUI_CalculationDlg* aPanel =
361 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
364 aPanel->refreshZonesBrowser();
371 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
373 QList<HYDROGUI_Zone*> aZonesList;
374 HYDROGUI_Zone* aZone;
375 // Get a list of dropped zones
376 for ( int i = 0; i < theZonesList.length(); i++ )
378 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
381 aZonesList.append( aZone );
384 if ( aZonesList.length() > 0 )
386 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
387 HYDROGUI_CalculationDlg* aPanel =
388 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
391 aPanel->refreshZonesBrowser();
397 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
399 HYDROGUI_CalculationDlg* aPanel =
400 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
403 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
406 aZone->setMergeType( theMergeType, theAltitudeName );
407 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
413 aPanel->refreshZonesBrowser();
417 void HYDROGUI_CalculationOp::onAddObjects()
419 HYDROGUI_CalculationDlg* aPanel =
420 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
424 // Add geometry objects selected in the module browser to the calculation case
425 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
426 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
429 QStringList anAddedList;
430 for (int i = 0; i < aSelectedList.length(); i++)
432 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
433 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
434 if ( anObject.IsNull() )
437 if ( myEditedObject->AddGeometryObject( anObject ) )
438 anAddedList.append( anObject->GetName() );
441 if ( !anAddedList.isEmpty() )
443 aPanel->includeGeomObjects( anAddedList );
448 void HYDROGUI_CalculationOp::onRemoveObjects()
450 // Remove selected objects from the calculation case
451 HYDROGUI_CalculationDlg* aPanel =
452 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
456 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
457 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
460 for (int i = 0; i < aSelectedList.length(); i++)
462 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
463 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
464 if ( anObject.IsNull() )
467 setObjectVisibility( anObject, false );
468 myEditedObject->RemoveGeometryObject( anObject );
471 module()->update( UF_OCCViewer );
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() )
630 setObjectVisibility( aZonesIter.Value(), theIsVisible );
636 module()->update( UF_OCCViewer );
641 void HYDROGUI_CalculationOp::createPreview()
643 LightApp_Application* anApp = module()->getApp();
644 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
645 Handle(HYDROData_Entity) anEntity;
649 // Gather zones for displaying
650 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
651 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
652 HYDROData_SequenceOfObjects aZones;
653 Handle(HYDROData_Region) aRegion;
654 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
656 anEntity = aRegionsIter.Value();
657 if ( !anEntity.IsNull() )
659 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
660 if ( !aRegion.IsNull() )
662 aZones = aRegion->GetZones();
663 aSeq.Append( aZones );
669 // Get a boundary polyline if any
670 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
672 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
674 if ( !myActiveViewManager )
676 if ( aSeq.IsEmpty() )
679 myActiveViewManager = anApp->activeViewManager();
682 if ( !myPreviewViewManager )
684 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
685 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
686 if ( myPreviewViewManager )
688 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
689 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
691 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
692 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
696 if ( !myPreviewViewManager )
699 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
701 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
702 if ( !aCtx.IsNull() )
704 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
705 for ( ; anIter.More(); anIter.Next() )
707 setObjectVisibility( anIter.Value(), true );
710 //Process the draw events for viewer
711 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
712 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
716 module()->update( UF_OCCViewer | UF_FitAll );
720 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
722 if ( theEntity.IsNull() || !myPreviewViewManager ) {
726 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
728 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
732 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
737 void HYDROGUI_CalculationOp::closePreview()
739 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
740 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
741 QShortcut* aShortcut;
742 foreach( aShortcut, aShortcuts )
744 if ( aShortcut->key() ==
745 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
746 SUIT_DataBrowser::RenameShortcut ) ) )
748 aShortcut->setEnabled( true );
753 if( myPreviewViewManager )
755 // Hide all the displayed objects in the preview view
756 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
758 size_t aViewId = (size_t)aViewer;
759 HYDROData_Iterator anIterator( doc() );
760 for( ; anIterator.More(); anIterator.Next() ) {
761 Handle(HYDROData_Entity) anObject = anIterator.Current();
762 if( !anObject.IsNull() ) {
763 module()->setObjectVisible( aViewId, anObject, false );
768 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
769 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
771 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
772 myPreviewViewManager = NULL;
775 if( myActiveViewManager )
777 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
778 myActiveViewManager = NULL;
782 void HYDROGUI_CalculationOp::setAvailableGroups()
784 HYDROGUI_CalculationDlg* aPanel =
785 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
787 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
788 QStringList aList, anEntryList;
789 getNamesAndEntries( aSeq, aList, anEntryList );
791 QStringList aGroupsNames;
793 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
794 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
796 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
797 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
798 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
800 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
801 aGroupsNames.append( aGroup->GetName() );
804 if( myEditedObject->IsMustBeUpdated() ) {
805 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
806 Handle(HYDROData_ShapesGroup) aGeomGroup =
807 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
808 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
809 myEditedObject->RemoveGeometryGroup( aGeomGroup );
814 aPanel->setAvailableGroups( aGroupsNames );
815 aPanel->includeGroups( aList );
817 bool isUpdated = myEditedObject->IsMustBeUpdated();
820 void HYDROGUI_CalculationOp::onAddGroups()
822 HYDROGUI_CalculationDlg* aPanel =
823 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
827 // Add geometry objects selected in the module browser to the calculation case
828 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
829 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
832 QStringList anAddedList;
833 for (int i = 0; i < aSelectedList.length(); i++)
835 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
836 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
837 if ( aGroup.IsNull() )
840 if ( myEditedObject->AddGeometryGroup( aGroup ) )
841 anAddedList.append( aGroup->GetName() );
844 if ( !anAddedList.isEmpty() )
846 aPanel->includeGroups( anAddedList );
850 void HYDROGUI_CalculationOp::onRemoveGroups()
852 // Remove selected objects from the calculation case
853 HYDROGUI_CalculationDlg* aPanel =
854 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
858 QStringList aSelectedList = aPanel->getSelectedGroups();
859 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
862 for (int i = 0; i < aSelectedList.length(); i++)
864 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
865 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
866 if ( aGroup.IsNull() )
869 myEditedObject->RemoveGeometryGroup( aGroup );
872 aPanel->excludeGroups( aSelectedList );