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 aPanel->setMode( myEditedObject->GetAssignmentMode() );
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 );
159 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
162 aPanel->setObjectName( anObjectName );
163 aPanel->setEditedObject( myEditedObject );
168 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
169 QStringList& theNames, QStringList& theEntries ) const
174 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
175 for ( ; anIter.More(); anIter.Next() )
177 Handle(HYDROData_Entity) anEntity = anIter.Value();
178 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
181 theNames.append( anEntity->GetName() );
182 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
186 void HYDROGUI_CalculationOp::abortOperation()
191 HYDROGUI_Operation::abortOperation();
192 module()->getApp()->updateObjectBrowser();
195 void HYDROGUI_CalculationOp::commitOperation()
198 // Commit transaction
199 commitDocOperation();
200 HYDROGUI_Operation::commitOperation();
203 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
205 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
207 // Connect signals and slots
208 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
209 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
210 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
211 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
212 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
213 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
214 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
215 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
216 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
217 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
218 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
219 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
220 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
221 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
222 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
223 connect( aPanel, SIGNAL( objectsSelected() ),
224 SLOT( onObjectsSelected() ) );
225 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
226 SLOT( onBoundarySelected( const QString & ) ) );
231 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
233 bool anIsToUpdateViewer = false;
235 // Remove the old boundary from the operation viewer
236 Handle(HYDROData_PolylineXY) aPrevPolyline =
237 myEditedObject->GetBoundaryPolyline();
238 if ( !aPrevPolyline.IsNull() )
240 setObjectVisibility( aPrevPolyline, false );
241 anIsToUpdateViewer = true;
244 // Set the selected boundary polyline to the calculation case
245 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
246 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
247 myEditedObject->SetBoundaryPolyline( aNewPolyline );
249 if ( myPreviewViewManager )
251 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
254 if ( !aNewPolyline.IsNull() )
256 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
257 if ( !aCtx.IsNull() )
259 setObjectVisibility( aNewPolyline, true );
260 anIsToUpdateViewer = true;
264 if ( anIsToUpdateViewer )
265 module()->update( UF_OCCViewer );
270 void HYDROGUI_CalculationOp::onObjectsSelected()
272 HYDROGUI_CalculationDlg* aPanel =
273 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
275 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
276 QMap<QString, bool> aSelectedObjsMap;
277 foreach( QString aName, aSelectedObjs )
278 aSelectedObjsMap[aName] = true;
281 // Select the appropriate geometry object shape in the viewer
282 selectionMgr()->clearSelected();
284 // Unhighlight all objects except selected
285 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
286 Handle(HYDROData_Entity) anEntity;
287 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
288 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
291 for ( ; anIter.More(); anIter.Next() )
293 anEntity = anIter.Value();
294 if ( !anEntity.IsNull() )
296 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
299 aName = anEntity->GetName();
300 isSelected = aSelectedObjsMap.contains( aName );
301 aShape->highlight( isSelected, false );
302 aShape->update( false, false );
308 aLastShape->update( true, false );
311 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
313 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
314 HYDROGUI_Zone* aZoneItem;
315 selectionMgr()->clearSelected();
318 // Select a region in preview
319 SUIT_DataOwnerPtrList aList( true );
320 DataObjectList aZones = aRegionItem->children();
321 for ( int i = 0; i < aZones.length(); i++ )
323 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
326 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
329 selectionMgr()->setSelected( aList );
333 // select a single zone
334 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
337 SUIT_DataOwnerPtrList aList( true );
338 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
339 selectionMgr()->setSelected( aList );
344 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
346 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
349 QList<HYDROGUI_Zone*> aZonesList;
350 HYDROGUI_Zone* aZone;
351 // Get a list of dropped zones
352 for ( int i = 0; i < theZonesList.length(); i++ )
354 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
357 aZonesList.append( aZone );
360 if ( aZonesList.length() > 0 )
362 aRegion->addZones( aZonesList );
363 HYDROGUI_CalculationDlg* aPanel =
364 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
367 aPanel->refreshZonesBrowser();
374 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
376 QList<HYDROGUI_Zone*> aZonesList;
377 HYDROGUI_Zone* aZone;
378 // Get a list of dropped zones
379 for ( int i = 0; i < theZonesList.length(); i++ )
381 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
384 aZonesList.append( aZone );
387 if ( aZonesList.length() > 0 )
389 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
390 HYDROGUI_CalculationDlg* aPanel =
391 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
394 aPanel->refreshZonesBrowser();
400 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
402 HYDROGUI_CalculationDlg* aPanel =
403 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
406 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
409 aZone->setMergeType( theMergeType, theAltitudeName );
410 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
413 aShape->update( true, false );
416 aPanel->refreshZonesBrowser();
420 void HYDROGUI_CalculationOp::onAddObjects()
422 HYDROGUI_CalculationDlg* aPanel =
423 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
427 // Add geometry objects selected in the module browser to the calculation case
428 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
429 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
432 QStringList anAddedList;
433 for (int i = 0; i < aSelectedList.length(); i++)
435 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
436 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
437 if ( anObject.IsNull() )
440 if ( myEditedObject->AddGeometryObject( anObject ) )
441 anAddedList.append( anObject->GetName() );
444 if ( !anAddedList.isEmpty() )
446 aPanel->includeGeomObjects( anAddedList );
451 void HYDROGUI_CalculationOp::onRemoveObjects()
453 // Remove selected objects from the calculation case
454 HYDROGUI_CalculationDlg* aPanel =
455 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
459 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
460 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
463 for (int i = 0; i < aSelectedList.length(); i++)
465 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
466 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
467 if ( anObject.IsNull() )
470 setObjectVisibility( anObject, false );
471 myEditedObject->RemoveGeometryObject( anObject );
474 module()->update( UF_OCCViewer );
475 aPanel->excludeGeomObjects( aSelectedList );
478 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
480 // Check if the case is already modified or not
481 bool isConfirmed = myEditedObject->IsMustBeUpdated();
484 // If not modified check if the case has already defined regions with zones
485 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
486 if ( aSeq.Length() > 0 )
488 // If there are already defined zones then ask a user to confirm zones recalculation
489 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
490 tr( "REGIONS_CHANGED" ),
491 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
492 QMessageBox::Yes | QMessageBox::No,
493 QMessageBox::No ) == QMessageBox::Yes );
497 isConfirmed = true; // No regions - no zones - nothing to recalculate
503 bool HYDROGUI_CalculationOp::confirmModeChange() const
505 // Check if the case is already modified or not
506 bool isConfirmed = myEditedObject->IsMustBeUpdated();
509 // If not modified check if the case has already defined regions with zones
510 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
511 if ( aSeq.Length() > 0 )
513 // If there are already defined zones then ask a user to confirm zones recalculation
514 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
515 tr( "MODE_CHANGED" ),
516 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
517 QMessageBox::Yes | QMessageBox::No,
518 QMessageBox::No ) == QMessageBox::Yes );
522 isConfirmed = true; // No regions - no zones - nothing to recalculate
528 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
529 QString& theErrorMsg,
530 QStringList& theBrowseObjectsEntries )
532 HYDROGUI_CalculationDlg* aPanel =
533 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
539 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
540 theBrowseObjectsEntries.append( anEntry );
543 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
548 void HYDROGUI_CalculationOp::onApply()
550 QApplication::setOverrideCursor( Qt::WaitCursor );
552 int anUpdateFlags = 0;
554 QStringList aBrowseObjectsEntries;
556 bool aResult = false;
560 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
562 catch ( Standard_Failure )
564 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
565 anErrorMsg = aFailure->GetMessageString();
573 QApplication::restoreOverrideCursor();
577 module()->update( anUpdateFlags );
579 browseObjects( aBrowseObjectsEntries );
584 QString aMsg = tr( "INPUT_VALID_DATA" );
585 if( !anErrorMsg.isEmpty() )
586 aMsg.prepend( anErrorMsg + "\n" );
587 SUIT_MessageBox::critical( module()->getApp()->desktop(),
588 tr( "INSUFFICIENT_INPUT_DATA" ),
593 void HYDROGUI_CalculationOp::onNext( const int theIndex )
597 setAvailableGroups();
599 else if( theIndex==2 )
601 HYDROGUI_CalculationDlg* aPanel =
602 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
606 QApplication::setOverrideCursor( Qt::WaitCursor );
608 QString aNewCaseName = aPanel->getObjectName();
609 QString anOldCaseName = myEditedObject->GetName();
611 bool anIsToUpdateOb = myIsEdit && anOldCaseName != aNewCaseName;
613 // At first we must to update the case name because of
614 // automatic names generation for regions and zones
615 myEditedObject->SetName( aNewCaseName );
617 // Set objects in the specified order
618 int aMode = aPanel->getMode();
619 if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) {
620 myEditedObject->RemoveGeometryObjects();
621 foreach ( const QString& aName, aPanel->getAllGeomObjects() ) {
622 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
623 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
624 if ( anObject.IsNull() ) {
628 myEditedObject->AddGeometryObject( anObject );
631 aPanel->setMoveZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
633 if ( myEditedObject->IsMustBeUpdated() )
636 myEditedObject->Update();
638 //aPanel->setEditedObject( myEditedObject );
639 aPanel->refreshZonesBrowser();
645 setZonesVisible( true );
648 if ( anIsToUpdateOb )
649 module()->getApp()->updateObjectBrowser( false );
651 QApplication::restoreOverrideCursor();
655 void HYDROGUI_CalculationOp::onHideZones()
657 setZonesVisible( false );
660 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
662 myShowZones = theIsVisible;
663 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
664 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
665 HYDROData_SequenceOfObjects aZones;
666 Handle(HYDROData_Region) aRegion;
667 if ( myPreviewViewManager )
669 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
671 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
672 if ( !aCtx.IsNull() )
674 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
676 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
677 if ( !aRegion.IsNull() )
679 aZones = aRegion->GetZones();
680 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
681 for ( ; aZonesIter.More(); aZonesIter.Next() )
683 setObjectVisibility( aZonesIter.Value(), theIsVisible );
689 module()->update( UF_OCCViewer );
694 void HYDROGUI_CalculationOp::createPreview()
696 LightApp_Application* anApp = module()->getApp();
697 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
698 Handle(HYDROData_Entity) anEntity;
702 // Gather zones for displaying
703 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
704 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
705 HYDROData_SequenceOfObjects aZones;
706 Handle(HYDROData_Region) aRegion;
707 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
709 anEntity = aRegionsIter.Value();
710 if ( !anEntity.IsNull() )
712 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
713 if ( !aRegion.IsNull() )
715 aZones = aRegion->GetZones();
716 aSeq.Append( aZones );
722 // Get a boundary polyline if any
723 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
725 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
727 if ( !myActiveViewManager )
729 if ( aSeq.IsEmpty() )
732 myActiveViewManager = anApp->activeViewManager();
735 if ( !myPreviewViewManager )
737 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
738 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
739 if ( myPreviewViewManager )
741 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
742 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
744 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
745 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
749 if ( !myPreviewViewManager )
752 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
754 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
755 if ( !aCtx.IsNull() )
757 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
758 for ( ; anIter.More(); anIter.Next() )
760 setObjectVisibility( anIter.Value(), true );
763 //Process the draw events for viewer
764 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
765 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
769 module()->update( UF_OCCViewer | UF_FitAll );
773 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
775 if ( theEntity.IsNull() || !myPreviewViewManager ) {
779 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
781 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
785 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
790 void HYDROGUI_CalculationOp::closePreview()
792 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
793 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
794 QShortcut* aShortcut;
795 foreach( aShortcut, aShortcuts )
797 if ( aShortcut->key() ==
798 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
799 SUIT_DataBrowser::RenameShortcut ) ) )
801 aShortcut->setEnabled( true );
806 if( myPreviewViewManager )
808 // Hide all the displayed objects in the preview view
809 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
811 size_t aViewId = (size_t)aViewer;
812 HYDROData_Iterator anIterator( doc() );
813 for( ; anIterator.More(); anIterator.Next() ) {
814 Handle(HYDROData_Entity) anObject = anIterator.Current();
815 if( !anObject.IsNull() ) {
816 module()->setObjectVisible( aViewId, anObject, false );
821 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
822 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
824 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
825 myPreviewViewManager = NULL;
828 if( myActiveViewManager )
830 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
831 myActiveViewManager = NULL;
835 void HYDROGUI_CalculationOp::setAvailableGroups()
837 HYDROGUI_CalculationDlg* aPanel =
838 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
840 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
841 QStringList aList, anEntryList;
842 getNamesAndEntries( aSeq, aList, anEntryList );
844 QStringList aGroupsNames;
846 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
847 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
849 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
850 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
851 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
853 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
854 aGroupsNames.append( aGroup->GetName() );
857 if( myEditedObject->IsMustBeUpdated() ) {
858 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
859 Handle(HYDROData_ShapesGroup) aGeomGroup =
860 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
861 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
862 myEditedObject->RemoveGeometryGroup( aGeomGroup );
867 aPanel->setAvailableGroups( aGroupsNames );
868 aPanel->includeGroups( aList );
870 bool isUpdated = myEditedObject->IsMustBeUpdated();
873 void HYDROGUI_CalculationOp::onAddGroups()
875 HYDROGUI_CalculationDlg* aPanel =
876 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
880 // Add geometry objects selected in the module browser to the calculation case
881 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
882 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
885 QStringList anAddedList;
886 for (int i = 0; i < aSelectedList.length(); i++)
888 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
889 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
890 if ( aGroup.IsNull() )
893 if ( myEditedObject->AddGeometryGroup( aGroup ) )
894 anAddedList.append( aGroup->GetName() );
897 if ( !anAddedList.isEmpty() )
899 aPanel->includeGroups( anAddedList );
903 void HYDROGUI_CalculationOp::onRemoveGroups()
905 // Remove selected objects from the calculation case
906 HYDROGUI_CalculationDlg* aPanel =
907 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
911 QStringList aSelectedList = aPanel->getSelectedGroups();
912 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
915 for (int i = 0; i < aSelectedList.length(); i++)
917 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
918 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
919 if ( aGroup.IsNull() )
922 myEditedObject->RemoveGeometryGroup( aGroup );
925 aPanel->excludeGroups( aSelectedList );
928 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
930 HYDROGUI_CalculationDlg* aPanel =
931 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
935 if ( !confirmModeChange() ) {
936 aPanel->setMode( myEditedObject->GetAssignmentMode() );
940 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
941 aPanel->setMode( theMode );