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 );
154 HYDROData_ListOfRules aRules;
155 Handle(HYDROData_Object) anObject1, anObject2;
156 HYDROData_PriorityType aPriority;
157 HYDROData_Zone::MergeAltitudesType aMergeType;
158 for ( int anIndex = 0; anIndex < myEditedObject->GetRulesCount(); anIndex++ ) {
159 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType ) ) {
160 HYDROData_CustomRule aRule;
161 aRule.Object1 = anObject1;
162 aRule.Object2 = anObject2;
163 aRule.Priority = aPriority;
164 aRule.MergeType = aMergeType;
169 aPanel->setRules( aRules );
175 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
176 myEditedObject->SetName( anObjectName );
177 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
180 aPanel->setObjectName( anObjectName );
181 aPanel->setEditedObject( myEditedObject );
186 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
187 QStringList& theNames, QStringList& theEntries ) const
192 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
193 for ( ; anIter.More(); anIter.Next() )
195 Handle(HYDROData_Entity) anEntity = anIter.Value();
196 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
199 theNames.append( anEntity->GetName() );
200 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
204 void HYDROGUI_CalculationOp::abortOperation()
209 HYDROGUI_Operation::abortOperation();
210 module()->getApp()->updateObjectBrowser();
213 void HYDROGUI_CalculationOp::commitOperation()
216 // Commit transaction
217 commitDocOperation();
218 HYDROGUI_Operation::commitOperation();
221 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
223 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
225 // Connect signals and slots
226 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
227 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
228 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
229 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
230 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
231 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
232 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
233 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
234 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
235 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
236 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
237 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
238 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
239 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
240 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
241 connect( aPanel, SIGNAL( objectsSelected() ),
242 SLOT( onObjectsSelected() ) );
243 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
244 SLOT( onBoundarySelected( const QString & ) ) );
249 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
251 bool anIsToUpdateViewer = false;
253 // Remove the old boundary from the operation viewer
254 Handle(HYDROData_PolylineXY) aPrevPolyline =
255 myEditedObject->GetBoundaryPolyline();
256 if ( !aPrevPolyline.IsNull() )
258 setObjectVisibility( aPrevPolyline, false );
259 anIsToUpdateViewer = true;
262 // Set the selected boundary polyline to the calculation case
263 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
264 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
265 myEditedObject->SetBoundaryPolyline( aNewPolyline );
267 if ( myPreviewViewManager )
269 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
272 if ( !aNewPolyline.IsNull() )
274 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
275 if ( !aCtx.IsNull() )
277 setObjectVisibility( aNewPolyline, true );
278 anIsToUpdateViewer = true;
282 if ( anIsToUpdateViewer )
283 module()->update( UF_OCCViewer );
288 void HYDROGUI_CalculationOp::onObjectsSelected()
290 HYDROGUI_CalculationDlg* aPanel =
291 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
293 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
294 QMap<QString, bool> aSelectedObjsMap;
295 foreach( QString aName, aSelectedObjs )
296 aSelectedObjsMap[aName] = true;
299 // Select the appropriate geometry object shape in the viewer
300 selectionMgr()->clearSelected();
302 // Unhighlight all objects except selected
303 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
304 Handle(HYDROData_Entity) anEntity;
305 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
306 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
309 for ( ; anIter.More(); anIter.Next() )
311 anEntity = anIter.Value();
312 if ( !anEntity.IsNull() )
314 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
317 aName = anEntity->GetName();
318 isSelected = aSelectedObjsMap.contains( aName );
319 aShape->highlight( isSelected, false );
320 aShape->update( false, false );
326 aLastShape->update( true, false );
329 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
331 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
332 HYDROGUI_Zone* aZoneItem;
333 selectionMgr()->clearSelected();
336 // Select a region in preview
337 SUIT_DataOwnerPtrList aList( true );
338 DataObjectList aZones = aRegionItem->children();
339 for ( int i = 0; i < aZones.length(); i++ )
341 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
344 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
347 selectionMgr()->setSelected( aList );
351 // select a single zone
352 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
355 SUIT_DataOwnerPtrList aList( true );
356 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
357 selectionMgr()->setSelected( aList );
362 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
364 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
367 QList<HYDROGUI_Zone*> aZonesList;
368 HYDROGUI_Zone* aZone;
369 // Get a list of dropped zones
370 for ( int i = 0; i < theZonesList.length(); i++ )
372 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
375 aZonesList.append( aZone );
378 if ( aZonesList.length() > 0 )
380 aRegion->addZones( aZonesList );
381 HYDROGUI_CalculationDlg* aPanel =
382 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
385 aPanel->refreshZonesBrowser();
392 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
394 QList<HYDROGUI_Zone*> aZonesList;
395 HYDROGUI_Zone* aZone;
396 // Get a list of dropped zones
397 for ( int i = 0; i < theZonesList.length(); i++ )
399 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
402 aZonesList.append( aZone );
405 if ( aZonesList.length() > 0 )
407 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
408 HYDROGUI_CalculationDlg* aPanel =
409 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
412 aPanel->refreshZonesBrowser();
418 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
420 HYDROGUI_CalculationDlg* aPanel =
421 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
424 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
427 aZone->setMergeType( theMergeType, theAltitudeName );
428 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
431 aShape->update( true, false );
434 aPanel->refreshZonesBrowser();
438 void HYDROGUI_CalculationOp::onAddObjects()
440 HYDROGUI_CalculationDlg* aPanel =
441 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
445 // Add geometry objects selected in the module browser to the calculation case
446 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
447 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
450 QStringList anAddedList;
451 for (int i = 0; i < aSelectedList.length(); i++)
453 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
454 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
455 if ( anObject.IsNull() )
458 if ( myEditedObject->AddGeometryObject( anObject ) )
459 anAddedList.append( anObject->GetName() );
462 if ( !anAddedList.isEmpty() )
464 aPanel->includeGeomObjects( anAddedList );
469 void HYDROGUI_CalculationOp::onRemoveObjects()
471 // Remove selected objects from the calculation case
472 HYDROGUI_CalculationDlg* aPanel =
473 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
477 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
478 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
481 for (int i = 0; i < aSelectedList.length(); i++)
483 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
484 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
485 if ( anObject.IsNull() )
488 setObjectVisibility( anObject, false );
489 myEditedObject->RemoveGeometryObject( anObject );
492 module()->update( UF_OCCViewer );
493 aPanel->excludeGeomObjects( aSelectedList );
496 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
498 // Check if the case is already modified or not
499 bool isConfirmed = myEditedObject->IsMustBeUpdated();
502 // If not modified check if the case has already defined regions with zones
503 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
504 if ( aSeq.Length() > 0 )
506 // If there are already defined zones then ask a user to confirm zones recalculation
507 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
508 tr( "REGIONS_CHANGED" ),
509 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
510 QMessageBox::Yes | QMessageBox::No,
511 QMessageBox::No ) == QMessageBox::Yes );
515 isConfirmed = true; // No regions - no zones - nothing to recalculate
521 bool HYDROGUI_CalculationOp::confirmModeChange() const
523 // Check if the case is already modified or not
524 bool isConfirmed = myEditedObject->IsMustBeUpdated();
527 // If not modified check if the case has already defined regions with zones
528 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
529 if ( aSeq.Length() > 0 )
531 // If there are already defined zones then ask a user to confirm zones recalculation
532 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
533 tr( "MODE_CHANGED" ),
534 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
535 QMessageBox::Yes | QMessageBox::No,
536 QMessageBox::No ) == QMessageBox::Yes );
540 isConfirmed = true; // No regions - no zones - nothing to recalculate
546 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
547 QString& theErrorMsg,
548 QStringList& theBrowseObjectsEntries )
550 HYDROGUI_CalculationDlg* aPanel =
551 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
557 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
558 theBrowseObjectsEntries.append( anEntry );
561 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
566 void HYDROGUI_CalculationOp::onApply()
568 QApplication::setOverrideCursor( Qt::WaitCursor );
570 int anUpdateFlags = 0;
572 QStringList aBrowseObjectsEntries;
574 bool aResult = false;
578 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
580 catch ( Standard_Failure )
582 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
583 anErrorMsg = aFailure->GetMessageString();
591 QApplication::restoreOverrideCursor();
595 module()->update( anUpdateFlags );
597 browseObjects( aBrowseObjectsEntries );
602 QString aMsg = tr( "INPUT_VALID_DATA" );
603 if( !anErrorMsg.isEmpty() )
604 aMsg.prepend( anErrorMsg + "\n" );
605 SUIT_MessageBox::critical( module()->getApp()->desktop(),
606 tr( "INSUFFICIENT_INPUT_DATA" ),
611 void HYDROGUI_CalculationOp::onNext( const int theIndex )
615 setAvailableGroups();
617 else if( theIndex==2 )
619 HYDROGUI_CalculationDlg* aPanel =
620 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
624 QApplication::setOverrideCursor( Qt::WaitCursor );
626 QString aNewCaseName = aPanel->getObjectName();
627 QString anOldCaseName = myEditedObject->GetName();
629 bool anIsToUpdateOb = myIsEdit && anOldCaseName != aNewCaseName;
631 // At first we must to update the case name because of
632 // automatic names generation for regions and zones
633 myEditedObject->SetName( aNewCaseName );
635 // Set parameters for automatic mode
636 int aMode = aPanel->getMode();
637 if ( aMode == HYDROData_CalculationCase::AUTOMATIC ) {
638 // Set objects in the specified order
639 myEditedObject->RemoveGeometryObjects();
640 foreach ( const QString& aName, aPanel->getAllGeomObjects() ) {
641 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
642 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
643 if ( anObject.IsNull() ) {
647 myEditedObject->AddGeometryObject( anObject );
650 // Set priority rules
651 myEditedObject->ClearRules();
652 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
653 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
654 aRule.Object2, aRule.MergeType );
657 aPanel->setMoveZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
659 if ( myEditedObject->IsMustBeUpdated() )
662 myEditedObject->Update();
664 //aPanel->setEditedObject( myEditedObject );
665 aPanel->refreshZonesBrowser();
671 setZonesVisible( true );
674 if ( anIsToUpdateOb )
675 module()->getApp()->updateObjectBrowser( false );
677 QApplication::restoreOverrideCursor();
681 void HYDROGUI_CalculationOp::onHideZones()
683 setZonesVisible( false );
686 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
688 myShowZones = theIsVisible;
689 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
690 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
691 HYDROData_SequenceOfObjects aZones;
692 Handle(HYDROData_Region) aRegion;
693 if ( myPreviewViewManager )
695 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
697 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
698 if ( !aCtx.IsNull() )
700 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
702 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
703 if ( !aRegion.IsNull() )
705 aZones = aRegion->GetZones();
706 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
707 for ( ; aZonesIter.More(); aZonesIter.Next() )
709 setObjectVisibility( aZonesIter.Value(), theIsVisible );
715 module()->update( UF_OCCViewer );
720 void HYDROGUI_CalculationOp::createPreview()
722 LightApp_Application* anApp = module()->getApp();
723 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
724 Handle(HYDROData_Entity) anEntity;
728 // Gather zones for displaying
729 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
730 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
731 HYDROData_SequenceOfObjects aZones;
732 Handle(HYDROData_Region) aRegion;
733 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
735 anEntity = aRegionsIter.Value();
736 if ( !anEntity.IsNull() )
738 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
739 if ( !aRegion.IsNull() )
741 aZones = aRegion->GetZones();
742 aSeq.Append( aZones );
748 // Get a boundary polyline if any
749 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
751 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
753 if ( !myActiveViewManager )
755 if ( aSeq.IsEmpty() )
758 myActiveViewManager = anApp->activeViewManager();
761 if ( !myPreviewViewManager )
763 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
764 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
765 if ( myPreviewViewManager )
767 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
768 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
770 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
771 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
775 if ( !myPreviewViewManager )
778 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
780 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
781 if ( !aCtx.IsNull() )
783 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
784 for ( ; anIter.More(); anIter.Next() )
786 setObjectVisibility( anIter.Value(), true );
789 //Process the draw events for viewer
790 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
791 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
795 module()->update( UF_OCCViewer | UF_FitAll );
799 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
801 if ( theEntity.IsNull() || !myPreviewViewManager ) {
805 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
807 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
811 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
816 void HYDROGUI_CalculationOp::closePreview()
818 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
819 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
820 QShortcut* aShortcut;
821 foreach( aShortcut, aShortcuts )
823 if ( aShortcut->key() ==
824 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
825 SUIT_DataBrowser::RenameShortcut ) ) )
827 aShortcut->setEnabled( true );
832 if( myPreviewViewManager )
834 // Hide all the displayed objects in the preview view
835 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
837 size_t aViewId = (size_t)aViewer;
838 HYDROData_Iterator anIterator( doc() );
839 for( ; anIterator.More(); anIterator.Next() ) {
840 Handle(HYDROData_Entity) anObject = anIterator.Current();
841 if( !anObject.IsNull() ) {
842 module()->setObjectVisible( aViewId, anObject, false );
847 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
848 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
850 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
851 myPreviewViewManager = NULL;
854 if( myActiveViewManager )
856 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
857 myActiveViewManager = NULL;
861 void HYDROGUI_CalculationOp::setAvailableGroups()
863 HYDROGUI_CalculationDlg* aPanel =
864 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
866 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
867 QStringList aList, anEntryList;
868 getNamesAndEntries( aSeq, aList, anEntryList );
870 QStringList aGroupsNames;
872 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
873 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
875 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
876 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
877 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
879 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
880 aGroupsNames.append( aGroup->GetName() );
883 if( myEditedObject->IsMustBeUpdated() ) {
884 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
885 Handle(HYDROData_ShapesGroup) aGeomGroup =
886 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
887 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
888 myEditedObject->RemoveGeometryGroup( aGeomGroup );
893 aPanel->setAvailableGroups( aGroupsNames );
894 aPanel->includeGroups( aList );
896 bool isUpdated = myEditedObject->IsMustBeUpdated();
899 void HYDROGUI_CalculationOp::onAddGroups()
901 HYDROGUI_CalculationDlg* aPanel =
902 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
906 // Add geometry objects selected in the module browser to the calculation case
907 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
908 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
911 QStringList anAddedList;
912 for (int i = 0; i < aSelectedList.length(); i++)
914 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
915 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
916 if ( aGroup.IsNull() )
919 if ( myEditedObject->AddGeometryGroup( aGroup ) )
920 anAddedList.append( aGroup->GetName() );
923 if ( !anAddedList.isEmpty() )
925 aPanel->includeGroups( anAddedList );
929 void HYDROGUI_CalculationOp::onRemoveGroups()
931 // Remove selected objects from the calculation case
932 HYDROGUI_CalculationDlg* aPanel =
933 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
937 QStringList aSelectedList = aPanel->getSelectedGroups();
938 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
941 for (int i = 0; i < aSelectedList.length(); i++)
943 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
944 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
945 if ( aGroup.IsNull() )
948 myEditedObject->RemoveGeometryGroup( aGroup );
951 aPanel->excludeGroups( aSelectedList );
954 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
956 HYDROGUI_CalculationDlg* aPanel =
957 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
961 if ( !confirmModeChange() ) {
962 aPanel->setMode( myEditedObject->GetAssignmentMode() );
966 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
967 aPanel->setMode( theMode );