1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_CalculationOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_CalculationDlg.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Tool.h"
25 #include "HYDROGUI_UpdateFlags.h"
26 #include "HYDROGUI_Zone.h"
27 #include "HYDROGUI_Region.h"
29 #include <HYDROData_PolylineXY.h>
30 #include <HYDROData_ShapesGroup.h>
31 #include <HYDROData_Iterator.h>
32 #include <HYDROData_ImmersibleZone.h>
33 #include <HYDROData_Object.h>
34 #include <HYDROData_Tool.h>
35 #include <HYDROData_StricklerTable.h>
37 #include <OCCViewer_ViewManager.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewWindow.h>
41 #include <LightApp_Application.h>
42 #include <LightApp_UpdateFlags.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <LightApp_DataOwner.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_DataBrowser.h>
50 #include <QApplication>
51 #include <QKeySequence>
54 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
55 : HYDROGUI_Operation( theModule ),
56 myIsEdit( theIsEdit ),
57 myActiveViewManager( NULL ),
58 myPreviewViewManager( NULL ),
59 myShowGeomObjects( true ),
60 myShowLandCovers( false ),
63 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
66 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
71 void HYDROGUI_CalculationOp::startOperation()
73 HYDROGUI_Operation::startOperation();
78 HYDROGUI_CalculationDlg* aPanel =
79 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
83 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
84 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
86 foreach( aShortcut, aShortcuts )
88 if ( aShortcut->key() ==
89 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
90 SUIT_DataBrowser::RenameShortcut ) ) )
92 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 aPanel->setMode( myEditedObject->GetAssignmentMode() );
138 anObjectName = myEditedObject->GetName();
139 aPolylineObj = myEditedObject->GetBoundaryPolyline();
140 if ( aPolylineObj.IsNull() )
142 aPanel->setBoundary( QString() );
146 aPolylineName = aPolylineObj->GetName();
147 aPanel->setBoundary( aPolylineName );
150 aSeq = myEditedObject->GetGeometryObjects();
151 getNamesAndEntries( aSeq, aList, anEntryList );
152 aPanel->includeGeomObjects( aList );
155 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
161 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
162 myEditedObject->SetName( anObjectName );
163 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
166 aPanel->setObjectName( anObjectName );
167 aPanel->setEditedObject( myEditedObject );
169 createPreview( false );
172 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
173 QStringList& theNames, QStringList& theEntries ) const
178 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
179 for ( ; anIter.More(); anIter.Next() )
181 Handle(HYDROData_Entity) anEntity = anIter.Value();
182 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
185 theNames.append( anEntity->GetName() );
186 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
190 void HYDROGUI_CalculationOp::abortOperation()
195 HYDROGUI_Operation::abortOperation();
196 module()->getApp()->updateObjectBrowser();
199 void HYDROGUI_CalculationOp::commitOperation()
202 // Commit transaction
203 commitDocOperation();
204 HYDROGUI_Operation::commitOperation();
207 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
209 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
211 // Connect signals and slots
212 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
213 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
214 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
215 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
216 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
218 connect( aPanel, SIGNAL( changeLandCoverMode( int ) ), SLOT( onChangeLandCoverMode( int ) ) );
219 connect( aPanel, SIGNAL( addLandCovers() ), SLOT( onAddLandCovers() ) );
220 connect( aPanel, SIGNAL( removeLandCovers() ), SLOT( onRemoveLandCovers() ) );
222 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
223 connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
225 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
226 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
227 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
228 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
229 connect( aPanel, SIGNAL( setMergeStricklerType( int, QString& ) ), SLOT( onSetMergeStricklerType( int, QString& ) ) );
230 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ),
231 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ) );
232 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
233 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
234 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
235 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
236 connect( aPanel, SIGNAL( objectsSelected() ),
237 SLOT( onObjectsSelected() ) );
238 connect( aPanel, SIGNAL( landCoversSelected() ),
239 SLOT( onLandCoversSelected() ) );
240 connect( aPanel, SIGNAL( createLandCoverRegion( const QList<SUIT_DataObject*>& ) ),
241 SLOT( onCreateLandCoverRegion( const QList<SUIT_DataObject*>& ) ) );
242 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
243 SLOT( onBoundarySelected( const QString & ) ) );
244 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
245 SLOT( onStricklerTableSelected( const QString & ) ) );
250 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
252 bool anIsToUpdateViewer = false;
254 // Remove the old boundary from the operation viewer
255 Handle(HYDROData_PolylineXY) aPrevPolyline =
256 myEditedObject->GetBoundaryPolyline();
257 if ( !aPrevPolyline.IsNull() )
259 setObjectVisibility( aPrevPolyline, false );
260 anIsToUpdateViewer = true;
263 // Set the selected boundary polyline to the calculation case
264 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
265 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
266 myEditedObject->SetBoundaryPolyline( aNewPolyline );
268 if ( myPreviewViewManager )
270 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
273 if ( !aNewPolyline.IsNull() )
275 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
276 if ( !aCtx.IsNull() )
278 setObjectVisibility( aNewPolyline, true );
279 anIsToUpdateViewer = true;
283 if ( anIsToUpdateViewer )
284 module()->update( UF_OCCViewer );
289 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
291 bool anIsToUpdateViewer = false;
293 // Remove old presentations of land covers from the operation viewer
294 Handle(HYDROData_Entity) anEntity;
295 Handle(HYDROData_LandCover) aLandCover;
296 HYDROData_SequenceOfObjects aLandCovers;
297 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
298 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
299 for ( ; anIter.More(); anIter.Next() )
301 anEntity = anIter.Value();
302 if ( !anEntity.IsNull() )
304 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
305 if ( !aLandCover.IsNull() )
307 aLandCovers.Append( aLandCover );
308 setObjectVisibility( aLandCover, false );
309 anIsToUpdateViewer = true;
314 // Set the selected Strickler table to the calculation case
315 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
316 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
317 myEditedObject->SetStricklerTable( aNewStricklerTable );
319 if ( myPreviewViewManager )
321 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
324 if ( !aNewStricklerTable.IsNull() )
326 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
327 if ( !aCtx.IsNull() )
329 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
330 for ( ; anIter.More(); anIter.Next() )
332 anEntity = anIter.Value();
333 if ( !anEntity.IsNull() )
335 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
336 if ( !aLandCover.IsNull() )
338 setObjectVisibility( aLandCover, true );
339 anIsToUpdateViewer = true;
346 if ( anIsToUpdateViewer )
347 module()->update( UF_OCCViewer );
352 void HYDROGUI_CalculationOp::onObjectsSelected()
354 HYDROGUI_CalculationDlg* aPanel =
355 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
357 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
358 QMap<QString, bool> aSelectedObjsMap;
359 foreach( QString aName, aSelectedObjs )
360 aSelectedObjsMap[aName] = true;
363 // Select the appropriate geometry object shape in the viewer
364 selectionMgr()->clearSelected();
366 // Unhighlight all objects except selected
367 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
368 Handle(HYDROData_Entity) anEntity;
369 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
370 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
373 for ( ; anIter.More(); anIter.Next() )
375 anEntity = anIter.Value();
376 if ( !anEntity.IsNull() )
378 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
381 aName = anEntity->GetName();
382 isSelected = aSelectedObjsMap.contains( aName );
383 aShape->highlight( isSelected, false );
384 aShape->update( false, false );
390 aLastShape->update( true, false );
393 void HYDROGUI_CalculationOp::onLandCoversSelected()
395 HYDROGUI_CalculationDlg* aPanel =
396 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
398 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
399 QMap<QString, bool> aSelectedObjsMap;
400 foreach( QString aName, aSelectedObjs )
401 aSelectedObjsMap[aName] = true;
404 // Select the appropriate land cover shape in the viewer
405 selectionMgr()->clearSelected();
407 // Unhighlight all land covers except selected
408 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
409 Handle(HYDROData_Entity) anEntity;
410 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
411 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
414 for ( ; anIter.More(); anIter.Next() )
416 anEntity = anIter.Value();
417 if ( !anEntity.IsNull() )
419 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
422 aName = anEntity->GetName();
423 isSelected = aSelectedObjsMap.contains( aName );
424 aShape->highlight( isSelected, false );
425 aShape->update( false, false );
431 aLastShape->update( true, false );
434 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
436 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
437 HYDROGUI_Zone* aZoneItem;
438 selectionMgr()->clearSelected();
441 // Select a region in preview
442 SUIT_DataOwnerPtrList aList( true );
443 DataObjectList aZones = aRegionItem->children();
444 for ( int i = 0; i < aZones.length(); i++ )
446 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
449 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
452 selectionMgr()->setSelected( aList );
456 // select a single zone
457 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
460 SUIT_DataOwnerPtrList aList( true );
461 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
462 selectionMgr()->setSelected( aList );
467 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
468 const QList<SUIT_DataObject*>& theZonesList,
471 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
474 QList<HYDROGUI_Zone*> aZonesList;
475 HYDROGUI_Zone* aZone;
476 // Get a list of dropped zones
477 for ( int i = 0; i < theZonesList.length(); i++ )
479 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
482 aZonesList.append( aZone );
485 if ( aZonesList.length() > 0 )
487 aRegion->addZones( aZonesList );
488 HYDROGUI_CalculationDlg* aPanel =
489 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
492 theLandCover ? aPanel->refreshLandCoverZonesBrowser(): aPanel->refreshZonesBrowser();
494 createPreview( theLandCover );
499 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
501 if ( createRegion( theZonesList, false ) )
503 HYDROGUI_CalculationDlg* aPanel =
504 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
507 aPanel->refreshZonesBrowser();
509 createPreview( false );
513 void HYDROGUI_CalculationOp::onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList )
515 if ( createRegion( theZonesList, true ) )
517 HYDROGUI_CalculationDlg* aPanel =
518 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
521 aPanel->refreshLandCoverZonesBrowser();
523 createPreview( true );
527 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
529 HYDROGUI_CalculationDlg* aPanel =
530 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
533 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
536 aZone->setMergeType( theMergeType, theMergeObjectName );
537 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
540 aShape->update( true, false );
543 aPanel->refreshZonesBrowser();
547 void HYDROGUI_CalculationOp::onSetMergeStricklerType( int theMergeType, QString& theStricklerTypeName )
549 HYDROGUI_CalculationDlg* aPanel =
550 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
553 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
556 aZone->setMergeType( theMergeType, theStricklerTypeName );
557 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
560 aShape->update( true, false );
563 aPanel->refreshLandCoverZonesBrowser();
567 void HYDROGUI_CalculationOp::onAddObjects()
569 HYDROGUI_CalculationDlg* aPanel =
570 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
574 // Add geometry objects selected in the module browser to the calculation case
575 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
576 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
579 QStringList anAddedList;
580 for (int i = 0; i < aSelectedList.length(); i++)
582 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
583 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
584 if ( anObject.IsNull() )
587 if ( myEditedObject->AddGeometryObject( anObject ) )
588 anAddedList.append( anObject->GetName() );
591 if ( !anAddedList.isEmpty() )
593 aPanel->includeGeomObjects( anAddedList );
594 createPreview( false );
598 void HYDROGUI_CalculationOp::onRemoveObjects()
600 // Remove selected objects from the calculation case
601 HYDROGUI_CalculationDlg* aPanel =
602 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
606 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
607 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
610 for (int i = 0; i < aSelectedList.length(); i++)
612 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
613 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
614 if ( anObject.IsNull() )
617 setObjectVisibility( anObject, false );
618 myEditedObject->RemoveGeometryObject( anObject );
621 module()->update( UF_OCCViewer );
622 aPanel->excludeGeomObjects( aSelectedList );
625 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
627 // Check if the case is already modified or not
628 bool isConfirmed = myEditedObject->IsMustBeUpdated();
631 // If not modified check if the case has already defined regions with zones
632 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
633 if ( aSeq.Length() > 0 )
635 // If there are already defined zones then ask a user to confirm zones recalculation
636 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
637 tr( "REGIONS_CHANGED" ),
638 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
639 QMessageBox::Yes | QMessageBox::No,
640 QMessageBox::No ) == QMessageBox::Yes );
644 isConfirmed = true; // No regions - no zones - nothing to recalculate
650 bool HYDROGUI_CalculationOp::confirmOrderChange() const
652 // Check if the case is already modified or not
653 bool isConfirmed = myEditedObject->IsMustBeUpdated();
656 // If not modified check if the case has already defined regions with zones
657 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
658 if ( aSeq.Length() > 0 )
660 // If there are already defined zones then ask a user to confirm zones recalculation
661 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
662 tr( "ORDER_CHANGED" ),
663 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
664 QMessageBox::Yes | QMessageBox::No,
665 QMessageBox::No ) == QMessageBox::Yes );
669 isConfirmed = true; // No regions - no zones - nothing to recalculate
675 bool HYDROGUI_CalculationOp::confirmModeChange() const
677 // Check if the case is already modified or not
678 bool isConfirmed = myEditedObject->IsMustBeUpdated();
681 // If not modified check if the case has already defined regions with zones
682 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
683 if ( aSeq.Length() > 0 )
685 // If there are already defined zones then ask a user to confirm zones recalculation
686 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
687 tr( "MODE_CHANGED" ),
688 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
689 QMessageBox::Yes | QMessageBox::No,
690 QMessageBox::No ) == QMessageBox::Yes );
694 isConfirmed = true; // No regions - no zones - nothing to recalculate
700 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
702 HYDROData_WarningType aType = theWarning.Type;
703 if ( aType == WARN_OK ) {
711 case WARN_EMPTY_REGIONS:
712 aTitle = tr( "EMPTY_REGIONS" );
713 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
716 aTitle = tr( "WARNING" );
717 aMsg = theWarning.Data;
721 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
723 QMessageBox::Yes | QMessageBox::No,
726 return ( anAnswer == QMessageBox::Yes );
729 bool HYDROGUI_CalculationOp::confirmLandCoverRegionsChange() const
731 // Check if the case is already modified or not
732 bool isConfirmed = myEditedObject->IsMustBeUpdated();
735 // If not modified check if the case has already defined regions with land cover zones
736 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
737 if ( aSeq.Length() > 0 )
739 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
740 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
741 tr( "REGIONS_CHANGED" ),
742 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
743 QMessageBox::Yes | QMessageBox::No,
744 QMessageBox::No ) == QMessageBox::Yes );
748 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
754 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
756 // Check if the case is already modified or not
757 bool isConfirmed = myEditedObject->IsMustBeUpdated();
760 // If not modified check if the case has already defined regions with land cover zones
761 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
762 if ( aSeq.Length() > 0 )
764 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
765 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
766 tr( "MODE_CHANGED" ),
767 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
768 QMessageBox::Yes | QMessageBox::No,
769 QMessageBox::No ) == QMessageBox::Yes );
773 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
779 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
781 // Check if the case is already modified or not
782 bool isConfirmed = myEditedObject->IsMustBeUpdated();
785 // If not modified check if the case has already defined regions with land cover zones
786 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
787 if ( aSeq.Length() > 0 )
789 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
790 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
791 tr( "ORDER_CHANGED" ),
792 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
793 QMessageBox::Yes | QMessageBox::No,
794 QMessageBox::No ) == QMessageBox::Yes );
798 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
804 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
805 QString& theErrorMsg,
806 QStringList& theBrowseObjectsEntries )
808 HYDROGUI_CalculationDlg* aPanel =
809 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
815 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
816 theBrowseObjectsEntries.append( anEntry );
819 // For manual mode priority rules are redundant
820 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
821 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
823 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
824 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
827 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
832 void HYDROGUI_CalculationOp::onApply()
835 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
836 if ( aWarning.Type != WARN_OK ) {
837 if ( !confirmContinueWithWarning( aWarning ) ) {
838 // Go back to the first page
839 HYDROGUI_CalculationDlg* aPanel =
840 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
842 aPanel->onFirstPage();
848 QApplication::setOverrideCursor( Qt::WaitCursor );
850 int anUpdateFlags = 0;
852 QStringList aBrowseObjectsEntries;
854 bool aResult = false;
858 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
860 catch ( Standard_Failure )
862 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
863 anErrorMsg = aFailure->GetMessageString();
871 QApplication::restoreOverrideCursor();
875 module()->update( anUpdateFlags );
877 browseObjects( aBrowseObjectsEntries );
882 QString aMsg = tr( "INPUT_VALID_DATA" );
883 if( !anErrorMsg.isEmpty() )
884 aMsg.prepend( anErrorMsg + "\n" );
885 SUIT_MessageBox::critical( module()->getApp()->desktop(),
886 tr( "INSUFFICIENT_INPUT_DATA" ),
891 void HYDROGUI_CalculationOp::onNext( const int theIndex )
895 setAvailableGroups();
897 else if( theIndex==2 )
900 HYDROGUI_CalculationDlg* aPanel =
901 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
905 setLandCoversVisible( true );
908 QStringList anEntryList;
909 HYDROData_SequenceOfObjects aSeq;
911 Handle(HYDROData_StricklerTable) aStricklerTableObj;
912 QString aStricklerTableName;
914 // Get all Strickler table objects to fill in combo-box
917 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
918 for ( ; anIter.More(); anIter.Next() )
920 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
922 if ( !aStricklerTableObj.IsNull() )
924 aStricklerTableName = aStricklerTableObj->GetName();
925 if ( !aStricklerTableName.isEmpty() )
927 aList.append( aStricklerTableName );
928 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
932 aPanel->setStricklerTableNames( aList, anEntryList );
933 bool anUpdateState = myEditedObject->IsMustBeUpdated();
934 if ( !aList.isEmpty() )
935 aPanel->setStricklerTable( aList.at( 0 ), false );
936 myEditedObject->SetToUpdate( anUpdateState );
938 // Fill in list widget with all available land covers
939 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
940 getNamesAndEntries( aSeq, aList, anEntryList );
941 aPanel->setAllLandCovers( aList, anEntryList );
943 // Set list of included land covers
944 aSeq = myEditedObject->GetLandCovers();
945 getNamesAndEntries( aSeq, aList, anEntryList );
946 aPanel->includeLandCovers( aList, true );
948 if ( !myEditedObject.IsNull() )
952 // Select the certain Strickler table object in combo-box
953 aStricklerTableObj = myEditedObject->GetStricklerTable();
954 if ( aStricklerTableObj.IsNull() )
956 aPanel->setStricklerTable( QString() );
960 aStricklerTableName = aStricklerTableObj->GetName();
961 aPanel->setStricklerTable( aStricklerTableName );
964 // Set mode (Auto or Manual) to defined priority of land covers
965 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
967 // Set rules defined on land covers
968 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
972 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
976 closePreview( false );
977 createPreview( true );
979 else if( theIndex==3 )
981 HYDROGUI_CalculationDlg* aPanel =
982 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
986 QApplication::setOverrideCursor( Qt::WaitCursor );
988 setGeomObjectsVisible( false );
989 setLandCoversVisible( false );
991 QString aNewCaseName = aPanel->getObjectName();
992 QString anOldCaseName = myEditedObject->GetName();
993 bool isNameChanged = anOldCaseName != aNewCaseName;
995 bool anIsToUpdateOb = isNameChanged;
997 // At first we must to update the case name because of
998 // automatic names generation for regions and zones
999 myEditedObject->SetName( aNewCaseName );
1001 // Set parameters for automatic mode
1002 int aMode = aPanel->getMode();
1003 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1005 // Set objects in the specified order
1006 if( myEditedObject->IsMustBeUpdated() )
1008 myEditedObject->RemoveGeometryObjects();
1009 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
1011 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
1012 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1013 if ( anObject.IsNull() )
1017 myEditedObject->AddGeometryObject( anObject );
1020 // Clear priority rules
1021 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
1022 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
1024 // Set priority rules
1025 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
1026 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1027 aRule.Object2, aRule.MergeType,
1028 HYDROData_CalculationCase::DataTag_CustomRules );
1032 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1034 if ( myEditedObject->IsMustBeUpdated() )
1037 myEditedObject->Update();
1039 AssignDefaultZonesColors( false );
1041 //aPanel->setEditedObject( myEditedObject );
1042 aPanel->refreshZonesBrowser();
1044 closePreview( false );
1045 createPreview( false );
1047 anIsToUpdateOb = true;
1049 myEditedObject->SetToUpdate( true );
1054 setZonesVisible( true, false );
1056 if ( isNameChanged ) {
1057 module()->getDataModel()->updateObjectTree( myEditedObject );
1061 QApplication::restoreOverrideCursor();
1063 else if( theIndex==4 )
1065 // Partition of Land covers panel
1066 HYDROGUI_CalculationDlg* aPanel =
1067 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1071 QApplication::setOverrideCursor( Qt::WaitCursor );
1073 // Set parameters for automatic mode
1074 int aMode = aPanel->getLandCoverMode();
1075 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1077 // Set objects in the specified order
1078 if( myEditedObject->IsMustBeUpdated() )
1080 myEditedObject->RemoveLandCovers();
1081 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1083 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1084 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1085 if ( aLandCover.IsNull() )
1089 myEditedObject->AddLandCover( aLandCover );
1092 // Clear priority rules
1093 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1094 // Set priority rules
1095 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1096 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1097 aRule.Object2, HYDROData_Zone::Merge_Object,
1098 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1102 aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1104 bool anIsToUpdateOb = false;
1105 bool anIsToUpdate = myEditedObject->IsMustBeUpdated();
1109 myEditedObject->SetToUpdate( false );
1111 AssignDefaultZonesColors( true );
1113 aPanel->refreshLandCoverZonesBrowser();
1115 anIsToUpdateOb = true;
1118 closePreview( false );
1119 createPreview( true );
1121 if ( !anIsToUpdate )
1124 setZonesVisible( false, false );
1125 // Show land cover zones
1126 setZonesVisible( true, true );
1129 if ( anIsToUpdateOb ) {
1130 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1131 if ( anObjBrowser ) {
1132 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1136 QApplication::restoreOverrideCursor();
1140 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1144 setGeomObjectsVisible( true );
1146 closePreview( false );
1147 createPreview( false );
1151 setLandCoversVisible( true );
1153 closePreview( false );
1154 createPreview( true );
1157 setZonesVisible( false, false );
1159 setZonesVisible( false, true );
1161 else if( theIndex==3 )
1163 AssignDefaultZonesColors( false );
1165 closePreview( false );
1166 createPreview( false );
1168 // Hide land cover zones
1169 setZonesVisible( false, true );
1171 setZonesVisible( true, false );
1175 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1177 myShowZones = theIsVisible;
1178 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1179 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1180 HYDROData_SequenceOfObjects aZones;
1181 Handle(HYDROData_Region) aRegion;
1182 if ( myPreviewViewManager )
1184 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1186 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1187 if ( !aCtx.IsNull() )
1189 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1191 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1192 if ( !aRegion.IsNull() )
1194 aZones = aRegion->GetZones();
1195 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1196 for ( ; aZonesIter.More(); aZonesIter.Next() )
1198 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1204 module()->update( UF_OCCViewer );
1209 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1211 myShowGeomObjects = theIsVisible;
1213 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1215 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1216 for ( ; anIter.More(); anIter.Next() ) {
1217 setObjectVisibility( anIter.Value(), theIsVisible );
1221 void HYDROGUI_CalculationOp::setLandCoversVisible( bool theIsVisible )
1223 myShowLandCovers = theIsVisible;
1225 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
1227 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1228 for ( ; anIter.More(); anIter.Next() ) {
1229 setObjectVisibility( anIter.Value(), theIsVisible );
1233 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1235 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1236 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1237 HYDROData_SequenceOfObjects aZones;
1238 Handle(HYDROData_Region) aRegion;
1239 if ( myPreviewViewManager )
1241 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1243 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1244 if ( !aCtx.IsNull() )
1247 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1249 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1250 if ( !aRegion.IsNull() )
1252 aZones = aRegion->GetZones();
1253 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1254 for ( ; aZonesIter.More(); aZonesIter.Next() )
1257 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1258 if ( !aZone.IsNull() )
1260 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1261 while (aFillingColor == Qt::red)
1262 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1264 aZone->SetColor(aFillingColor);
1274 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1275 float theSaturation/* = 0.5*/,
1276 float theValue/* = 0.95*/ ) const
1278 float aGoldenRatioConjugate = (float)(360./582.);
1279 float aHue = (float)(rand()%100);
1280 aHue += aGoldenRatioConjugate*theIndex;
1281 aHue -= floor(aHue);
1283 float aR = 0., aG = 0., aB = 0.;
1284 int aHueInt = (int)(aHue*6.);
1285 float aF = aHue*6. - aHueInt;
1286 float aP = theValue * (1. - theSaturation);
1287 float aQ = theValue * (1. - aF*theSaturation);
1288 float aT = theValue * (1. - (1. - aF) * theSaturation);
1291 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1292 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1293 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1294 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1295 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1296 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1300 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1301 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1304 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1306 HYDROGUI_CalculationDlg* aPanel =
1307 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1311 HYDROData_ListOfRules aRules;
1312 Handle(HYDROData_Entity) anObject1, anObject2;
1313 HYDROData_PriorityType aPriority;
1314 HYDROData_Zone::MergeType aMergeType;
1315 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1316 for ( int anIndex = 0; ; anIndex++ )
1318 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1319 HYDROData_CustomRule aRule;
1320 aRule.Object1 = anObject1;
1321 aRule.Object2 = anObject2;
1322 aRule.Priority = aPriority;
1323 aRule.MergeType = aMergeType;
1331 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1332 aPanel->setRules( aRules );
1333 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1334 aPanel->setLandCoverRules( aRules );
1337 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1338 const bool theLandCover )
1340 bool aRetValue = false;
1342 QList<HYDROGUI_Zone*> aZonesList;
1343 HYDROGUI_Zone* aZone;
1344 // Get a list of dropped zones
1345 for ( int i = 0; i < theZonesList.length(); i++ )
1347 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1350 aZonesList.append( aZone );
1353 if ( aZonesList.length() > 0 )
1355 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1362 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1364 LightApp_Application* anApp = module()->getApp();
1365 HYDROData_SequenceOfObjects aSeq;
1366 if ( theLandCover && myShowLandCovers )
1368 HYDROData_SequenceOfObjects aSeqLC = myEditedObject->GetLandCovers();
1369 aSeq.Append( aSeqLC );
1371 else if ( !theLandCover && myShowGeomObjects )
1373 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1374 aSeq.Append( aSeqGO );
1377 Handle(HYDROData_Entity) anEntity;
1381 // Gather zones for displaying
1382 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1383 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1384 HYDROData_SequenceOfObjects aZones;
1385 Handle(HYDROData_Region) aRegion;
1386 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1388 anEntity = aRegionsIter.Value();
1389 if ( !anEntity.IsNull() )
1391 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1392 if ( !aRegion.IsNull() )
1394 aZones = aRegion->GetZones();
1395 aSeq.Append( aZones );
1401 // Get a boundary polyline if any
1402 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1404 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1406 if ( !myActiveViewManager )
1408 if ( aSeq.IsEmpty() )
1411 myActiveViewManager = anApp->activeViewManager();
1414 if ( !myPreviewViewManager )
1416 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1417 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1418 if ( myPreviewViewManager )
1420 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1421 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1423 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1424 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1428 if ( !myPreviewViewManager )
1431 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1433 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1434 if ( !aCtx.IsNull() )
1436 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1437 for ( ; anIter.More(); anIter.Next() )
1439 setObjectVisibility( anIter.Value(), true );
1442 //Process the draw events for viewer
1443 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1444 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1448 module()->update( UF_OCCViewer | UF_FitAll );
1452 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1454 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1458 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1460 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1464 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1469 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1471 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1472 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1473 QShortcut* aShortcut;
1474 foreach( aShortcut, aShortcuts )
1476 if ( aShortcut->key() ==
1477 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1478 SUIT_DataBrowser::RenameShortcut ) ) )
1480 aShortcut->setEnabled( true );
1485 if( myPreviewViewManager )
1487 // Hide all the displayed objects in the preview view
1488 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1490 size_t aViewId = (size_t)aViewer;
1491 HYDROData_Iterator anIterator( doc() );
1492 for( ; anIterator.More(); anIterator.Next() ) {
1493 Handle(HYDROData_Entity) anObject = anIterator.Current();
1494 if( !anObject.IsNull() ) {
1495 module()->setObjectVisible( aViewId, anObject, false );
1500 if ( theRemoveViewManager )
1502 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1503 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1505 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1506 myPreviewViewManager = NULL;
1510 if( myActiveViewManager && theRemoveViewManager )
1512 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1513 myActiveViewManager = NULL;
1517 void HYDROGUI_CalculationOp::setAvailableGroups()
1519 HYDROGUI_CalculationDlg* aPanel =
1520 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1522 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1523 QStringList aList, anEntryList;
1524 getNamesAndEntries( aSeq, aList, anEntryList );
1526 QStringList aGroupsNames;
1528 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1529 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1531 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1532 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1533 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1535 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1536 aGroupsNames.append( aGroup->GetName() );
1539 if( myEditedObject->IsMustBeUpdated() ) {
1540 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1541 Handle(HYDROData_ShapesGroup) aGeomGroup =
1542 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1543 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1544 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1549 aPanel->setAvailableGroups( aGroupsNames );
1550 aPanel->includeGroups( aList );
1552 bool isUpdated = myEditedObject->IsMustBeUpdated();
1555 void HYDROGUI_CalculationOp::onAddGroups()
1557 HYDROGUI_CalculationDlg* aPanel =
1558 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1562 // Add geometry objects selected in the module browser to the calculation case
1563 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1564 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1567 QStringList anAddedList;
1568 for (int i = 0; i < aSelectedList.length(); i++)
1570 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1571 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1572 if ( aGroup.IsNull() )
1575 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1576 anAddedList.append( aGroup->GetName() );
1579 if ( !anAddedList.isEmpty() )
1581 aPanel->includeGroups( anAddedList );
1585 void HYDROGUI_CalculationOp::onRemoveGroups()
1587 // Remove selected objects from the calculation case
1588 HYDROGUI_CalculationDlg* aPanel =
1589 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1593 QStringList aSelectedList = aPanel->getSelectedGroups();
1594 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1597 for (int i = 0; i < aSelectedList.length(); i++)
1599 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1600 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1601 if ( aGroup.IsNull() )
1604 myEditedObject->RemoveGeometryGroup( aGroup );
1607 aPanel->excludeGroups( aSelectedList );
1610 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1612 HYDROGUI_CalculationDlg* aPanel =
1613 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1617 if ( !confirmLandCoverModeChange() ) {
1618 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1622 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1623 aPanel->setLandCoverMode( theMode );
1626 void HYDROGUI_CalculationOp::onAddLandCovers()
1628 HYDROGUI_CalculationDlg* aPanel =
1629 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1633 // Add land covers selected in the module browser to the calculation case
1634 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1635 if ( aSelectedList.isEmpty() || !confirmLandCoverRegionsChange() )
1638 QStringList anAddedList;
1639 for (int i = 0; i < aSelectedList.length(); i++)
1641 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1642 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1643 if ( anObject.IsNull() )
1646 if ( myEditedObject->AddLandCover( anObject ) )
1647 anAddedList.append( anObject->GetName() );
1650 if ( !anAddedList.isEmpty() )
1652 aPanel->includeLandCovers( anAddedList, false );
1653 createPreview( true );
1657 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1659 // Remove selected objects from the calculation case
1660 HYDROGUI_CalculationDlg* aPanel =
1661 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1665 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1666 if ( aSelectedList.isEmpty() || !confirmLandCoverRegionsChange() )
1669 for (int i = 0; i < aSelectedList.length(); i++)
1671 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1672 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1673 if ( anObject.IsNull() )
1676 setObjectVisibility( anObject, false );
1677 myEditedObject->RemoveLandCover( anObject );
1680 module()->update( UF_OCCViewer );
1681 aPanel->excludeLandCovers( aSelectedList );
1684 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1686 HYDROGUI_CalculationDlg* aPanel =
1687 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1691 if ( !confirmModeChange() ) {
1692 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1696 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1697 aPanel->setMode( theMode );
1700 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1702 HYDROGUI_CalculationDlg* aPanel =
1703 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1707 isConfirmed = confirmOrderChange();
1709 myEditedObject->SetToUpdate( true );
1712 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1714 HYDROGUI_CalculationDlg* aPanel =
1715 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1719 isConfirmed = confirmLandCoverOrderChange();
1721 myEditedObject->SetToUpdate( true );