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 ),
62 myUpdateLandCoverZonesPrs( false )
64 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
67 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
72 void HYDROGUI_CalculationOp::startOperation()
74 HYDROGUI_Operation::startOperation();
79 HYDROGUI_CalculationDlg* aPanel =
80 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
84 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
85 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
87 foreach( aShortcut, aShortcuts )
89 if ( aShortcut->key() ==
90 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
91 SUIT_DataBrowser::RenameShortcut ) ) )
93 aShortcut->setEnabled( false );
99 QStringList anEntryList;
100 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
101 getNamesAndEntries( aSeq, aList, anEntryList );
102 aPanel->setAllGeomObjects( aList, anEntryList );
107 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
108 Handle(HYDROData_PolylineXY) aPolylineObj;
109 QString aPolylineName;
110 for ( ; anIter.More(); anIter.Next() )
112 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
114 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
116 // Check the polyline shape
117 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
118 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
119 aPolylineName = aPolylineObj->GetName();
120 if ( !aPolylineName.isEmpty() )
122 aList.append( aPolylineName );
123 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
128 aPanel->setPolylineNames( aList, anEntryList );
130 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
132 myEditedObject.Nullify();
135 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
136 if ( !myEditedObject.IsNull() )
138 aPanel->setMode( myEditedObject->GetAssignmentMode() );
139 anObjectName = myEditedObject->GetName();
140 aPolylineObj = myEditedObject->GetBoundaryPolyline();
141 if ( aPolylineObj.IsNull() )
143 aPanel->setBoundary( QString() );
147 aPolylineName = aPolylineObj->GetName();
148 aPanel->setBoundary( aPolylineName );
151 aSeq = myEditedObject->GetGeometryObjects();
152 getNamesAndEntries( aSeq, aList, anEntryList );
153 aPanel->includeGeomObjects( aList );
156 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
162 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
163 myEditedObject->SetName( anObjectName );
164 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
167 aPanel->setObjectName( anObjectName );
168 aPanel->setEditedObject( myEditedObject );
170 createPreview( false );
173 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
174 QStringList& theNames, QStringList& theEntries ) const
179 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
180 for ( ; anIter.More(); anIter.Next() )
182 Handle(HYDROData_Entity) anEntity = anIter.Value();
183 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
186 theNames.append( anEntity->GetName() );
187 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
191 void HYDROGUI_CalculationOp::abortOperation()
196 HYDROGUI_Operation::abortOperation();
197 module()->getApp()->updateObjectBrowser();
200 void HYDROGUI_CalculationOp::commitOperation()
203 // Commit transaction
204 commitDocOperation();
205 HYDROGUI_Operation::commitOperation();
208 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
210 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
212 // Connect signals and slots
213 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
214 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
215 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
216 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
217 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
219 connect( aPanel, SIGNAL( changeLandCoverMode( int ) ), SLOT( onChangeLandCoverMode( int ) ) );
220 connect( aPanel, SIGNAL( addLandCovers() ), SLOT( onAddLandCovers() ) );
221 connect( aPanel, SIGNAL( removeLandCovers() ), SLOT( onRemoveLandCovers() ) );
223 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
224 connect( aPanel, SIGNAL( orderLandCoverChanged( bool& ) ), SLOT( onOrderLandCoverChanged( bool& ) ) );
226 connect( aPanel, SIGNAL( ruleChanged( bool& ) ), SLOT( onRuleChanged( bool& ) ) );
227 connect( aPanel, SIGNAL( ruleLandCoverChanged( bool& ) ), SLOT( onRuleLandCoverChanged( bool& ) ) );
229 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
230 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
231 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
232 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
233 connect( aPanel, SIGNAL( setMergeStricklerType( int, QString& ) ), SLOT( onSetMergeStricklerType( int, QString& ) ) );
234 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ),
235 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>&, bool ) ) );
236 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
237 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
238 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
239 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
240 connect( aPanel, SIGNAL( objectsSelected() ),
241 SLOT( onObjectsSelected() ) );
242 connect( aPanel, SIGNAL( landCoversSelected() ),
243 SLOT( onLandCoversSelected() ) );
244 connect( aPanel, SIGNAL( createLandCoverRegion( const QList<SUIT_DataObject*>& ) ),
245 SLOT( onCreateLandCoverRegion( const QList<SUIT_DataObject*>& ) ) );
246 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
247 SLOT( onBoundarySelected( const QString & ) ) );
248 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
249 SLOT( onStricklerTableSelected( const QString & ) ) );
251 connect( aPanel, SIGNAL( regenerateColors() ), this,
252 SLOT( onRegenerateColors() ) );
257 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
259 bool anIsToUpdateViewer = false;
261 // Remove the old boundary from the operation viewer
262 Handle(HYDROData_PolylineXY) aPrevPolyline =
263 myEditedObject->GetBoundaryPolyline();
264 if ( !aPrevPolyline.IsNull() )
266 setObjectVisibility( aPrevPolyline, false );
267 anIsToUpdateViewer = true;
270 // Set the selected boundary polyline to the calculation case
271 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
272 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
273 myEditedObject->SetBoundaryPolyline( aNewPolyline );
275 if ( myPreviewViewManager )
277 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
280 if ( !aNewPolyline.IsNull() )
282 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
283 if ( !aCtx.IsNull() )
285 setObjectVisibility( aNewPolyline, true );
286 anIsToUpdateViewer = true;
290 if ( anIsToUpdateViewer )
291 module()->update( UF_OCCViewer );
296 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
298 bool anIsToUpdateViewer = false;
300 // Remove old presentations of land covers from the operation viewer
301 Handle(HYDROData_Entity) anEntity;
302 Handle(HYDROData_LandCover) aLandCover;
303 HYDROData_SequenceOfObjects aLandCovers;
304 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
305 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
306 for ( ; anIter.More(); anIter.Next() )
308 anEntity = anIter.Value();
309 if ( !anEntity.IsNull() )
311 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
312 if ( !aLandCover.IsNull() )
314 aLandCovers.Append( aLandCover );
315 setObjectVisibility( aLandCover, false );
316 anIsToUpdateViewer = true;
321 // Set the selected Strickler table to the calculation case
322 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
323 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
324 myEditedObject->SetStricklerTable( aNewStricklerTable );
326 if ( myPreviewViewManager )
328 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
331 if ( !aNewStricklerTable.IsNull() )
333 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
334 if ( !aCtx.IsNull() )
336 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
337 for ( ; anIter.More(); anIter.Next() )
339 anEntity = anIter.Value();
340 if ( !anEntity.IsNull() )
342 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
343 if ( !aLandCover.IsNull() )
345 setObjectVisibility( aLandCover, true );
346 anIsToUpdateViewer = true;
353 if ( anIsToUpdateViewer )
354 module()->update( UF_OCCViewer );
359 void HYDROGUI_CalculationOp::onObjectsSelected()
361 HYDROGUI_CalculationDlg* aPanel =
362 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
364 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
365 QMap<QString, bool> aSelectedObjsMap;
366 foreach( QString aName, aSelectedObjs )
367 aSelectedObjsMap[aName] = true;
370 // Select the appropriate geometry object shape in the viewer
371 selectionMgr()->clearSelected();
373 // Unhighlight all objects except selected
374 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
375 Handle(HYDROData_Entity) anEntity;
376 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
377 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
380 for ( ; anIter.More(); anIter.Next() )
382 anEntity = anIter.Value();
383 if ( !anEntity.IsNull() )
385 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
388 aName = anEntity->GetName();
389 isSelected = aSelectedObjsMap.contains( aName );
390 aShape->highlight( isSelected, false );
391 aShape->update( false, false );
397 aLastShape->update( true, false );
400 void HYDROGUI_CalculationOp::onLandCoversSelected()
402 HYDROGUI_CalculationDlg* aPanel =
403 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
405 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
406 QMap<QString, bool> aSelectedObjsMap;
407 foreach( QString aName, aSelectedObjs )
408 aSelectedObjsMap[aName] = true;
411 // Select the appropriate land cover shape in the viewer
412 selectionMgr()->clearSelected();
414 // Unhighlight all land covers except selected
415 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
416 Handle(HYDROData_Entity) anEntity;
417 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
418 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
421 for ( ; anIter.More(); anIter.Next() )
423 anEntity = anIter.Value();
424 if ( !anEntity.IsNull() )
426 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
429 aName = anEntity->GetName();
430 isSelected = aSelectedObjsMap.contains( aName );
431 aShape->highlight( isSelected, false );
432 aShape->update( false, false );
438 aLastShape->update( true, false );
441 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
443 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
444 HYDROGUI_Zone* aZoneItem;
445 selectionMgr()->clearSelected();
448 // Select a region in preview
449 SUIT_DataOwnerPtrList aList( true );
450 DataObjectList aZones = aRegionItem->children();
451 for ( int i = 0; i < aZones.length(); i++ )
453 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
456 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
459 selectionMgr()->setSelected( aList );
463 // select a single zone
464 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
467 SUIT_DataOwnerPtrList aList( true );
468 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
469 selectionMgr()->setSelected( aList );
474 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
475 const QList<SUIT_DataObject*>& theZonesList,
478 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
481 QList<HYDROGUI_Zone*> aZonesList;
482 HYDROGUI_Zone* aZone;
483 // Get a list of dropped zones
484 for ( int i = 0; i < theZonesList.length(); i++ )
486 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
489 aZonesList.append( aZone );
492 if ( aZonesList.length() > 0 )
494 aRegion->addZones( aZonesList );
495 HYDROGUI_CalculationDlg* aPanel =
496 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
499 theLandCover ? aPanel->refreshLandCoverZonesBrowser(): aPanel->refreshZonesBrowser();
501 createPreview( theLandCover );
506 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
508 if ( createRegion( theZonesList, false ) )
510 HYDROGUI_CalculationDlg* aPanel =
511 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
514 aPanel->refreshZonesBrowser();
516 createPreview( false );
520 void HYDROGUI_CalculationOp::onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList )
522 if ( createRegion( theZonesList, true ) )
524 HYDROGUI_CalculationDlg* aPanel =
525 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
528 aPanel->refreshLandCoverZonesBrowser();
530 createPreview( true );
534 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
536 HYDROGUI_CalculationDlg* aPanel =
537 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
540 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
543 aZone->setMergeType( theMergeType, theMergeObjectName );
544 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
547 aShape->update( true, false );
550 aPanel->refreshZonesBrowser();
554 void HYDROGUI_CalculationOp::onSetMergeStricklerType( int theMergeType, QString& theStricklerTypeName )
556 HYDROGUI_CalculationDlg* aPanel =
557 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
560 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
563 aZone->setMergeType( theMergeType, theStricklerTypeName );
564 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
567 aShape->update( true, false );
570 aPanel->refreshLandCoverZonesBrowser();
574 void HYDROGUI_CalculationOp::onAddObjects()
576 HYDROGUI_CalculationDlg* aPanel =
577 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
581 // Add geometry objects selected in the module browser to the calculation case
582 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
583 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
586 QStringList anAddedList;
587 for (int i = 0; i < aSelectedList.length(); i++)
589 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
590 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
591 if ( anObject.IsNull() )
594 if ( myEditedObject->AddGeometryObject( anObject ) )
595 anAddedList.append( anObject->GetName() );
598 if ( !anAddedList.isEmpty() )
600 aPanel->includeGeomObjects( anAddedList );
601 createPreview( false );
605 void HYDROGUI_CalculationOp::onRemoveObjects()
607 // Remove selected objects from the calculation case
608 HYDROGUI_CalculationDlg* aPanel =
609 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
613 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
614 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
617 for (int i = 0; i < aSelectedList.length(); i++)
619 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
620 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
621 if ( anObject.IsNull() )
624 setObjectVisibility( anObject, false );
625 myEditedObject->RemoveGeometryObject( anObject );
628 module()->update( UF_OCCViewer );
629 aPanel->excludeGeomObjects( aSelectedList );
632 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
634 // Check if the case is already modified or not
635 bool isConfirmed = myEditedObject->IsMustBeUpdated();
638 // If not modified check if the case has already defined regions with zones
639 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
640 if ( aSeq.Length() > 0 )
642 // If there are already defined zones then ask a user to confirm zones recalculation
643 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
644 tr( "REGIONS_CHANGED" ),
645 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
646 QMessageBox::Yes | QMessageBox::No,
647 QMessageBox::No ) == QMessageBox::Yes );
651 isConfirmed = true; // No regions - no zones - nothing to recalculate
657 bool HYDROGUI_CalculationOp::confirmOrderChange() const
659 // Check if the case is already modified or not
660 bool isConfirmed = myEditedObject->IsMustBeUpdated();
663 // If not modified check if the case has already defined regions with zones
664 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
665 if ( aSeq.Length() > 0 )
667 // If there are already defined zones then ask a user to confirm zones recalculation
668 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
669 tr( "ORDER_CHANGED" ),
670 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
671 QMessageBox::Yes | QMessageBox::No,
672 QMessageBox::No ) == QMessageBox::Yes );
676 isConfirmed = true; // No regions - no zones - nothing to recalculate
682 bool HYDROGUI_CalculationOp::confirmRuleChange() const
684 // Check if the case is already modified or not
685 bool isConfirmed = myEditedObject->IsMustBeUpdated();
688 // If not modified check if the case has already defined regions with zones
689 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
690 if ( aSeq.Length() > 0 )
692 // If there are already defined zones then ask a user to confirm zones recalculation
693 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
694 tr( "RULE_CHANGED" ),
695 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
696 QMessageBox::Yes | QMessageBox::No,
697 QMessageBox::No ) == QMessageBox::Yes );
701 isConfirmed = true; // No regions - no zones - nothing to recalculate
707 bool HYDROGUI_CalculationOp::confirmModeChange() const
709 // Check if the case is already modified or not
710 bool isConfirmed = myEditedObject->IsMustBeUpdated();
713 // If not modified check if the case has already defined regions with zones
714 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
715 if ( aSeq.Length() > 0 )
717 // If there are already defined zones then ask a user to confirm zones recalculation
718 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
719 tr( "MODE_CHANGED" ),
720 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
721 QMessageBox::Yes | QMessageBox::No,
722 QMessageBox::No ) == QMessageBox::Yes );
726 isConfirmed = true; // No regions - no zones - nothing to recalculate
732 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
734 HYDROData_WarningType aType = theWarning.Type;
735 if ( aType == WARN_OK ) {
743 case WARN_EMPTY_REGIONS:
744 aTitle = tr( "EMPTY_REGIONS" );
745 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
748 aTitle = tr( "WARNING" );
749 aMsg = theWarning.Data;
753 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
755 QMessageBox::Yes | QMessageBox::No,
758 return ( anAnswer == QMessageBox::Yes );
761 bool HYDROGUI_CalculationOp::confirmLandCoverRegionsChange() const
763 // Check if the case is already modified or not
764 bool isConfirmed = myEditedObject->IsMustBeUpdated();
767 // If not modified check if the case has already defined regions with land cover zones
768 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
769 if ( aSeq.Length() > 0 )
771 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
772 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
773 tr( "REGIONS_CHANGED" ),
774 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
775 QMessageBox::Yes | QMessageBox::No,
776 QMessageBox::No ) == QMessageBox::Yes );
780 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
786 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
788 // Check if the case is already modified or not
789 bool isConfirmed = myEditedObject->IsMustBeUpdated();
792 // If not modified check if the case has already defined regions with land cover zones
793 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
794 if ( aSeq.Length() > 0 )
796 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
797 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
798 tr( "MODE_CHANGED" ),
799 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
800 QMessageBox::Yes | QMessageBox::No,
801 QMessageBox::No ) == QMessageBox::Yes );
805 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
811 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
813 // Check if the case is already modified or not
814 bool isConfirmed = myEditedObject->IsMustBeUpdated();
817 // If not modified check if the case has already defined regions with land cover zones
818 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
819 if ( aSeq.Length() > 0 )
821 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
822 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
823 tr( "ORDER_CHANGED" ),
824 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
825 QMessageBox::Yes | QMessageBox::No,
826 QMessageBox::No ) == QMessageBox::Yes );
830 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
836 bool HYDROGUI_CalculationOp::confirmLandCoverRuleChange() const
838 // Check if the case is already modified or not
839 bool isConfirmed = myEditedObject->IsMustBeUpdated();
842 // If not modified check if the case has already defined regions with land cover zones
843 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
844 if ( aSeq.Length() > 0 )
846 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
847 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
848 tr( "RULE_CHANGED" ),
849 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
850 QMessageBox::Yes | QMessageBox::No,
851 QMessageBox::No ) == QMessageBox::Yes );
855 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
861 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
862 QString& theErrorMsg,
863 QStringList& theBrowseObjectsEntries )
865 HYDROGUI_CalculationDlg* aPanel =
866 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
872 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
873 theBrowseObjectsEntries.append( anEntry );
876 // For manual mode priority rules are redundant
877 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
878 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
880 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
881 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
884 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
889 void HYDROGUI_CalculationOp::onApply()
892 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
893 if ( aWarning.Type != WARN_OK ) {
894 if ( !confirmContinueWithWarning( aWarning ) ) {
895 // Go back to the first page
896 HYDROGUI_CalculationDlg* aPanel =
897 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
899 aPanel->onFirstPage();
905 QApplication::setOverrideCursor( Qt::WaitCursor );
907 int anUpdateFlags = 0;
909 QStringList aBrowseObjectsEntries;
911 bool aResult = false;
915 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
917 catch ( Standard_Failure )
919 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
920 anErrorMsg = aFailure->GetMessageString();
928 QApplication::restoreOverrideCursor();
932 module()->update( anUpdateFlags );
934 browseObjects( aBrowseObjectsEntries );
939 QString aMsg = tr( "INPUT_VALID_DATA" );
940 if( !anErrorMsg.isEmpty() )
941 aMsg.prepend( anErrorMsg + "\n" );
942 SUIT_MessageBox::critical( module()->getApp()->desktop(),
943 tr( "INSUFFICIENT_INPUT_DATA" ),
948 void HYDROGUI_CalculationOp::onNext( const int theIndex )
952 setAvailableGroups();
954 else if( theIndex==2 )
957 HYDROGUI_CalculationDlg* aPanel =
958 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
962 setLandCoversVisible( true );
965 QStringList anEntryList;
966 HYDROData_SequenceOfObjects aSeq;
968 Handle(HYDROData_StricklerTable) aStricklerTableObj;
969 QString aStricklerTableName;
971 // Get all Strickler table objects to fill in combo-box
974 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
975 for ( ; anIter.More(); anIter.Next() )
977 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
979 if ( !aStricklerTableObj.IsNull() )
981 aStricklerTableName = aStricklerTableObj->GetName();
982 if ( !aStricklerTableName.isEmpty() )
984 aList.append( aStricklerTableName );
985 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
989 aPanel->setStricklerTableNames( aList, anEntryList );
990 bool anUpdateState = myEditedObject->IsMustBeUpdated();
991 if ( !aList.isEmpty() )
992 aPanel->setStricklerTable( aList.at( 0 ), false );
993 myEditedObject->SetToUpdate( anUpdateState );
995 // Fill in list widget with all available land covers
996 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
997 getNamesAndEntries( aSeq, aList, anEntryList );
998 aPanel->setAllLandCovers( aList, anEntryList );
1000 // Set list of included land covers
1001 aSeq = myEditedObject->GetLandCovers();
1002 getNamesAndEntries( aSeq, aList, anEntryList );
1003 aPanel->includeLandCovers( aList, true );
1005 if ( !myEditedObject.IsNull() )
1009 // Select the certain Strickler table object in combo-box
1010 aStricklerTableObj = myEditedObject->GetStricklerTable();
1011 if ( aStricklerTableObj.IsNull() )
1013 aPanel->setStricklerTable( QString() );
1017 aStricklerTableName = aStricklerTableObj->GetName();
1018 aPanel->setStricklerTable( aStricklerTableName );
1021 // Set mode (Auto or Manual) to defined priority of land covers
1022 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1024 // Set rules defined on land covers
1025 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1029 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
1033 closePreview( false );
1034 createPreview( true );
1036 else if( theIndex==3 )
1038 HYDROGUI_CalculationDlg* aPanel =
1039 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1043 QApplication::setOverrideCursor( Qt::WaitCursor );
1045 setGeomObjectsVisible( false );
1046 setLandCoversVisible( false );
1048 QString aNewCaseName = aPanel->getObjectName();
1049 QString anOldCaseName = myEditedObject->GetName();
1050 bool isNameChanged = anOldCaseName != aNewCaseName;
1052 bool anIsToUpdateOb = isNameChanged;
1054 // At first we must to update the case name because of
1055 // automatic names generation for regions and zones
1056 myEditedObject->SetName( aNewCaseName );
1058 // Zones: set parameters for automatic mode
1059 int aMode = aPanel->getMode();
1060 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1062 // Set objects in the specified order
1063 if( myEditedObject->IsMustBeUpdated() )
1065 myEditedObject->RemoveGeometryObjects();
1066 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
1068 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
1069 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1070 if ( anObject.IsNull() )
1074 myEditedObject->AddGeometryObject( anObject );
1077 // Clear priority rules
1078 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
1079 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
1081 // Set priority rules
1082 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
1083 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1084 aRule.Object2, aRule.MergeType,
1085 HYDROData_CalculationCase::DataTag_CustomRules );
1089 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1091 // Land cover zones: set parameters for automatic mode
1092 aMode = aPanel->getLandCoverMode();
1093 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1095 // Set objects in the specified order
1096 if( myEditedObject->IsMustBeUpdated() )
1098 myEditedObject->RemoveLandCovers();
1099 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1101 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1102 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1103 if ( aLandCover.IsNull() )
1107 myEditedObject->AddLandCover( aLandCover );
1110 // Clear priority rules
1111 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1112 // Set priority rules
1113 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1114 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1115 aRule.Object2, HYDROData_Zone::Merge_Object,
1116 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1120 aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1122 if ( myEditedObject->IsMustBeUpdated() )
1125 myEditedObject->Update();
1127 AssignDefaultZonesColors( false );
1129 //aPanel->setEditedObject( myEditedObject );
1130 aPanel->refreshZonesBrowser();
1132 closePreview( false );
1133 createPreview( false );
1135 anIsToUpdateOb = true;
1137 myUpdateLandCoverZonesPrs = true;
1142 setZonesVisible( true, false );
1144 if ( isNameChanged ) {
1145 module()->getDataModel()->updateObjectTree( myEditedObject );
1149 QApplication::restoreOverrideCursor();
1151 else if( theIndex==4 )
1153 // Partition of Land covers panel
1154 HYDROGUI_CalculationDlg* aPanel =
1155 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1159 QApplication::setOverrideCursor( Qt::WaitCursor );
1161 bool anIsToUpdateOb = false;
1162 if ( myUpdateLandCoverZonesPrs )
1166 AssignDefaultZonesColors( true );
1168 aPanel->refreshLandCoverZonesBrowser();
1170 anIsToUpdateOb = true;
1173 closePreview( false );
1174 createPreview( true );
1176 if ( myUpdateLandCoverZonesPrs )
1177 myUpdateLandCoverZonesPrs = false;
1181 setZonesVisible( false, false );
1182 // Show land cover zones
1183 setZonesVisible( true, true );
1186 if ( anIsToUpdateOb ) {
1187 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1188 if ( anObjBrowser ) {
1189 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1193 QApplication::restoreOverrideCursor();
1197 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1201 setGeomObjectsVisible( true );
1203 closePreview( false );
1204 createPreview( false );
1208 setLandCoversVisible( true );
1210 closePreview( false );
1211 createPreview( true );
1214 setZonesVisible( false, false );
1216 setZonesVisible( false, true );
1218 else if( theIndex==3 )
1220 AssignDefaultZonesColors( false );
1222 closePreview( false );
1223 createPreview( false );
1225 // Hide land cover zones
1226 setZonesVisible( false, true );
1228 setZonesVisible( true, false );
1232 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1234 myShowZones = theIsVisible;
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() )
1246 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1248 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1249 if ( !aRegion.IsNull() )
1251 aZones = aRegion->GetZones();
1252 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1253 for ( ; aZonesIter.More(); aZonesIter.Next() )
1255 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1261 module()->update( UF_OCCViewer );
1266 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1268 myShowGeomObjects = theIsVisible;
1270 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1272 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1273 for ( ; anIter.More(); anIter.Next() ) {
1274 setObjectVisibility( anIter.Value(), theIsVisible );
1278 void HYDROGUI_CalculationOp::setLandCoversVisible( bool theIsVisible )
1280 myShowLandCovers = theIsVisible;
1282 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
1284 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1285 for ( ; anIter.More(); anIter.Next() ) {
1286 setObjectVisibility( anIter.Value(), theIsVisible );
1290 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1292 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1293 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1294 HYDROData_SequenceOfObjects aZones;
1295 Handle(HYDROData_Region) aRegion;
1296 if ( myPreviewViewManager )
1298 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1300 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1301 if ( !aCtx.IsNull() )
1304 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1306 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1307 if ( !aRegion.IsNull() )
1309 aZones = aRegion->GetZones();
1310 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1311 for ( ; aZonesIter.More(); aZonesIter.Next() )
1314 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1315 if ( !aZone.IsNull() )
1317 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1318 while (aFillingColor == Qt::red)
1319 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1321 aZone->SetColor(aFillingColor);
1331 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1332 float theSaturation/* = 0.5*/,
1333 float theValue/* = 0.95*/ ) const
1335 float aHue = ( rand()%1000 ) * 0.001f;
1338 aColor.setHsl( (int)(aHue*255.), 128, 128 );
1339 int r = aColor.red();
1340 int g = aColor.green();
1341 int b = aColor.blue();
1342 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1345 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1347 HYDROGUI_CalculationDlg* aPanel =
1348 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1352 HYDROData_ListOfRules aRules;
1353 Handle(HYDROData_Entity) anObject1, anObject2;
1354 HYDROData_PriorityType aPriority;
1355 HYDROData_Zone::MergeType aMergeType;
1356 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1357 for ( int anIndex = 0; ; anIndex++ )
1359 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1360 HYDROData_CustomRule aRule;
1361 aRule.Object1 = anObject1;
1362 aRule.Object2 = anObject2;
1363 aRule.Priority = aPriority;
1364 aRule.MergeType = aMergeType;
1372 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1373 aPanel->setRules( aRules );
1374 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1375 aPanel->setLandCoverRules( aRules );
1378 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1379 const bool theLandCover )
1381 bool aRetValue = false;
1383 QList<HYDROGUI_Zone*> aZonesList;
1384 HYDROGUI_Zone* aZone;
1385 // Get a list of dropped zones
1386 for ( int i = 0; i < theZonesList.length(); i++ )
1388 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1391 aZonesList.append( aZone );
1394 if ( aZonesList.length() > 0 )
1396 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1403 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1405 LightApp_Application* anApp = module()->getApp();
1406 HYDROData_SequenceOfObjects aSeq;
1407 if ( theLandCover && myShowLandCovers )
1409 HYDROData_SequenceOfObjects aSeqLC = myEditedObject->GetLandCovers();
1410 aSeq.Append( aSeqLC );
1412 else if ( !theLandCover && myShowGeomObjects )
1414 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1415 aSeq.Append( aSeqGO );
1418 Handle(HYDROData_Entity) anEntity;
1422 // Gather zones for displaying
1423 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1424 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1425 HYDROData_SequenceOfObjects aZones;
1426 Handle(HYDROData_Region) aRegion;
1427 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1429 anEntity = aRegionsIter.Value();
1430 if ( !anEntity.IsNull() )
1432 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1433 if ( !aRegion.IsNull() )
1435 aZones = aRegion->GetZones();
1436 aSeq.Append( aZones );
1442 // Get a boundary polyline if any
1443 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1445 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1447 if ( !myActiveViewManager )
1449 if ( aSeq.IsEmpty() )
1452 myActiveViewManager = anApp->activeViewManager();
1455 if ( !myPreviewViewManager )
1457 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1458 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1459 if ( myPreviewViewManager )
1461 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1462 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1464 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1465 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1469 if ( !myPreviewViewManager )
1472 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1474 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1475 if ( !aCtx.IsNull() )
1477 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1478 for ( ; anIter.More(); anIter.Next() )
1480 setObjectVisibility( anIter.Value(), true );
1483 //Process the draw events for viewer
1484 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1485 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1489 module()->update( UF_OCCViewer | UF_FitAll );
1493 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1495 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1499 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1501 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1505 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1510 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1512 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1513 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1514 QShortcut* aShortcut;
1515 foreach( aShortcut, aShortcuts )
1517 if ( aShortcut->key() ==
1518 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1519 SUIT_DataBrowser::RenameShortcut ) ) )
1521 aShortcut->setEnabled( true );
1526 if( myPreviewViewManager )
1528 // Hide all the displayed objects in the preview view
1529 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1531 size_t aViewId = (size_t)aViewer;
1532 HYDROData_Iterator anIterator( doc() );
1533 for( ; anIterator.More(); anIterator.Next() ) {
1534 Handle(HYDROData_Entity) anObject = anIterator.Current();
1535 if( !anObject.IsNull() ) {
1536 module()->setObjectVisible( aViewId, anObject, false );
1541 if ( theRemoveViewManager )
1543 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1544 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1546 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1547 myPreviewViewManager = NULL;
1551 if( myActiveViewManager && theRemoveViewManager )
1553 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1554 myActiveViewManager = NULL;
1558 void HYDROGUI_CalculationOp::setAvailableGroups()
1560 HYDROGUI_CalculationDlg* aPanel =
1561 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1563 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1564 QStringList aList, anEntryList;
1565 getNamesAndEntries( aSeq, aList, anEntryList );
1567 QStringList aGroupsNames;
1569 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1570 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1572 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1573 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1574 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1576 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1577 aGroupsNames.append( aGroup->GetName() );
1580 if( myEditedObject->IsMustBeUpdated() ) {
1581 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1582 Handle(HYDROData_ShapesGroup) aGeomGroup =
1583 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1584 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1585 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1590 aPanel->setAvailableGroups( aGroupsNames );
1591 aPanel->includeGroups( aList );
1593 bool isUpdated = myEditedObject->IsMustBeUpdated();
1596 void HYDROGUI_CalculationOp::onAddGroups()
1598 HYDROGUI_CalculationDlg* aPanel =
1599 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1603 // Add geometry objects selected in the module browser to the calculation case
1604 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1605 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1608 QStringList anAddedList;
1609 for (int i = 0; i < aSelectedList.length(); i++)
1611 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1612 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1613 if ( aGroup.IsNull() )
1616 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1617 anAddedList.append( aGroup->GetName() );
1620 if ( !anAddedList.isEmpty() )
1622 aPanel->includeGroups( anAddedList );
1626 void HYDROGUI_CalculationOp::onRemoveGroups()
1628 // Remove selected objects from the calculation case
1629 HYDROGUI_CalculationDlg* aPanel =
1630 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1634 QStringList aSelectedList = aPanel->getSelectedGroups();
1635 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1638 for (int i = 0; i < aSelectedList.length(); i++)
1640 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1641 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1642 if ( aGroup.IsNull() )
1645 myEditedObject->RemoveGeometryGroup( aGroup );
1648 aPanel->excludeGroups( aSelectedList );
1651 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1653 HYDROGUI_CalculationDlg* aPanel =
1654 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1658 if ( !confirmLandCoverModeChange() ) {
1659 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1663 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1664 aPanel->setLandCoverMode( theMode );
1667 void HYDROGUI_CalculationOp::onAddLandCovers()
1669 HYDROGUI_CalculationDlg* aPanel =
1670 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1674 // Add land covers selected in the module browser to the calculation case
1675 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1676 if ( aSelectedList.isEmpty() || !confirmLandCoverRegionsChange() )
1679 QStringList anAddedList;
1680 for (int i = 0; i < aSelectedList.length(); i++)
1682 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1683 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1684 if ( anObject.IsNull() )
1687 if ( myEditedObject->AddLandCover( anObject ) )
1688 anAddedList.append( anObject->GetName() );
1691 if ( !anAddedList.isEmpty() )
1693 aPanel->includeLandCovers( anAddedList, false );
1694 createPreview( true );
1698 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1700 // Remove selected objects from the calculation case
1701 HYDROGUI_CalculationDlg* aPanel =
1702 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1706 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1707 if ( aSelectedList.isEmpty() || !confirmLandCoverRegionsChange() )
1710 for (int i = 0; i < aSelectedList.length(); i++)
1712 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1713 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1714 if ( anObject.IsNull() )
1717 setObjectVisibility( anObject, false );
1718 myEditedObject->RemoveLandCover( anObject );
1721 module()->update( UF_OCCViewer );
1722 aPanel->excludeLandCovers( aSelectedList );
1725 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1727 HYDROGUI_CalculationDlg* aPanel =
1728 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1732 if ( !confirmModeChange() ) {
1733 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1737 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1738 aPanel->setMode( theMode );
1741 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1743 HYDROGUI_CalculationDlg* aPanel =
1744 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1748 isConfirmed = confirmOrderChange();
1750 myEditedObject->SetToUpdate( true );
1753 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1755 HYDROGUI_CalculationDlg* aPanel =
1756 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1760 isConfirmed = confirmLandCoverOrderChange();
1762 myEditedObject->SetToUpdate( true );
1765 void HYDROGUI_CalculationOp::onRuleChanged( bool& isConfirmed )
1767 HYDROGUI_CalculationDlg* aPanel =
1768 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1772 isConfirmed = confirmRuleChange();
1774 myEditedObject->SetToUpdate( true );
1777 void HYDROGUI_CalculationOp::onRuleLandCoverChanged( bool& isConfirmed )
1779 HYDROGUI_CalculationDlg* aPanel =
1780 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1784 isConfirmed = confirmLandCoverRuleChange();
1786 myEditedObject->SetToUpdate( true );
1789 void HYDROGUI_CalculationOp::onRegenerateColors()
1791 // For geometry zones
1792 AssignDefaultZonesColors( false );
1793 setZonesVisible( false, false );
1794 setZonesVisible( true, false );