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_Tool2.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 myShowLandCoverMap( 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(false) )
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 setGeomObjectsVisible( true );
171 createPreview( false );
174 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
175 QStringList& theNames, QStringList& theEntries ) const
180 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
181 for ( ; anIter.More(); anIter.Next() )
183 Handle(HYDROData_Entity) anEntity = anIter.Value();
184 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
187 theNames.append( anEntity->GetName() );
188 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
192 void HYDROGUI_CalculationOp::abortOperation()
197 HYDROGUI_Operation::abortOperation();
198 module()->getApp()->updateObjectBrowser();
201 void HYDROGUI_CalculationOp::commitOperation()
204 // Commit transaction
205 commitDocOperation();
206 HYDROGUI_Operation::commitOperation();
209 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
211 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
213 // Connect signals and slots
214 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
215 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
216 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
217 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
218 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
220 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
222 connect( aPanel, SIGNAL( ruleChanged( bool& ) ), SLOT( onRuleChanged( bool& ) ) );
224 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
225 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
226 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
227 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
228 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
229 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
230 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
231 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
232 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
233 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
234 connect( aPanel, SIGNAL( objectsSelected() ),
235 SLOT( onObjectsSelected() ) );
236 connect( aPanel, SIGNAL( landCoverMapSelected( const QString & ) ),
237 SLOT( onLandCoverMapSelected( const QString & ) ) );
238 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
239 SLOT( onBoundarySelected( const QString & ) ) );
240 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
241 SLOT( onStricklerTableSelected( const QString & ) ) );
243 connect( aPanel, SIGNAL( regenerateColors() ), this,
244 SLOT( onRegenerateColors() ) );
249 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
251 bool anIsToUpdateViewer = false;
253 // Remove the old boundary from the operation viewer
254 Handle(HYDROData_PolylineXY) aPrevPolyline =
255 myEditedObject->GetBoundaryPolyline();
256 if ( !aPrevPolyline.IsNull() )
258 setObjectVisibility( aPrevPolyline, false );
259 anIsToUpdateViewer = true;
262 // Set the selected boundary polyline to the calculation case
263 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
264 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
265 myEditedObject->SetBoundaryPolyline( aNewPolyline );
267 if ( myPreviewViewManager )
269 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
272 if ( !aNewPolyline.IsNull() )
274 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
275 if ( !aCtx.IsNull() )
277 setObjectVisibility( aNewPolyline, true );
278 anIsToUpdateViewer = true;
282 if ( anIsToUpdateViewer )
283 module()->update( UF_OCCViewer );
288 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
290 bool anIsToUpdateViewer = false;
292 // Remove old presentation of land cover map from the operation viewer
293 Handle(HYDROData_LandCoverMap) aLandCoverMap = myEditedObject->GetLandCoverMap();
294 if ( !aLandCoverMap.IsNull() )
296 setObjectVisibility( aLandCoverMap, false );
297 anIsToUpdateViewer = true;
300 // Set the selected Strickler table to the calculation case
301 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
302 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
303 myEditedObject->SetStricklerTable( aNewStricklerTable );
305 if ( myPreviewViewManager )
307 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
310 if ( !aNewStricklerTable.IsNull() )
312 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
313 if ( !aCtx.IsNull() )
315 if ( !aLandCoverMap.IsNull() )
317 setObjectVisibility( aLandCoverMap, true );
318 anIsToUpdateViewer = true;
323 if ( anIsToUpdateViewer )
324 module()->update( UF_OCCViewer );
329 void HYDROGUI_CalculationOp::onObjectsSelected()
331 HYDROGUI_CalculationDlg* aPanel =
332 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
334 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
335 QMap<QString, bool> aSelectedObjsMap;
336 foreach( QString aName, aSelectedObjs )
337 aSelectedObjsMap[aName] = true;
340 // Select the appropriate geometry object shape in the viewer
341 selectionMgr()->clearSelected();
343 // Unhighlight all objects except selected
344 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
345 Handle(HYDROData_Entity) anEntity;
346 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
347 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
350 for ( ; anIter.More(); anIter.Next() )
352 anEntity = anIter.Value();
353 if ( !anEntity.IsNull() )
355 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
358 aName = anEntity->GetName();
359 isSelected = aSelectedObjsMap.contains( aName );
360 aShape->highlight( isSelected, false );
361 aShape->update( false, false );
367 aLastShape->update( true, false );
370 void HYDROGUI_CalculationOp::onLandCoverMapSelected( const QString & theObjName )
372 bool anIsToUpdateViewer = false;
374 // Remove old presentation of land cover map from the operation viewer
375 Handle(HYDROData_LandCoverMap) aPrevLandCoverMap = myEditedObject->GetLandCoverMap();
376 if ( !aPrevLandCoverMap.IsNull() )
378 setObjectVisibility( aPrevLandCoverMap, false );
379 anIsToUpdateViewer = true;
382 // Select the appropriate land cover map shape in the viewer
383 selectionMgr()->clearSelected();
385 // Set the selected land cover map to the calculation case
386 Handle(HYDROData_LandCoverMap) aNewLandCoverMap = Handle(HYDROData_LandCoverMap)::DownCast(
387 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_LAND_COVER_MAP ) );
388 myEditedObject->SetLandCoverMap( aNewLandCoverMap );
390 createPreview( true );
393 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
395 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
396 HYDROGUI_Zone* aZoneItem;
397 selectionMgr()->clearSelected();
400 // Select a region in preview
401 SUIT_DataOwnerPtrList aList( true );
402 DataObjectList aZones = aRegionItem->children();
403 for ( int i = 0; i < aZones.length(); i++ )
405 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
408 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
411 selectionMgr()->setSelected( aList );
415 // select a single zone
416 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
419 SUIT_DataOwnerPtrList aList( true );
420 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
421 selectionMgr()->setSelected( aList );
426 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
427 const QList<SUIT_DataObject*>& theZonesList )
429 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
432 QList<HYDROGUI_Zone*> aZonesList;
433 HYDROGUI_Zone* aZone;
434 // Get a list of dropped zones
435 for ( int i = 0; i < theZonesList.length(); i++ )
437 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
440 aZonesList.append( aZone );
443 if ( aZonesList.length() > 0 )
445 aRegion->addZones( aZonesList );
446 HYDROGUI_CalculationDlg* aPanel =
447 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
449 aPanel->refreshZonesBrowser();
450 createPreview( false );
455 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
457 if ( createRegion( theZonesList ) )
459 HYDROGUI_CalculationDlg* aPanel =
460 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
463 aPanel->refreshZonesBrowser();
465 createPreview( false );
469 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
471 HYDROGUI_CalculationDlg* aPanel =
472 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
475 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
478 aZone->setMergeType( theMergeType, theMergeObjectName );
479 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
482 aShape->update( true, false );
485 aPanel->refreshZonesBrowser();
489 void HYDROGUI_CalculationOp::onAddObjects()
491 HYDROGUI_CalculationDlg* aPanel =
492 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
496 // Add geometry objects selected in the module browser to the calculation case
497 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
498 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
501 QStringList anAddedList;
502 for (int i = 0; i < aSelectedList.length(); i++)
504 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
505 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
506 if ( anObject.IsNull() )
509 if ( myEditedObject->AddGeometryObject( anObject ) )
510 anAddedList.append( anObject->GetName() );
513 if ( !anAddedList.isEmpty() )
515 aPanel->includeGeomObjects( anAddedList );
516 createPreview( false );
520 void HYDROGUI_CalculationOp::onRemoveObjects()
522 // Remove selected objects from the calculation case
523 HYDROGUI_CalculationDlg* aPanel =
524 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
528 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
529 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
532 for (int i = 0; i < aSelectedList.length(); i++)
534 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
535 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
536 if ( anObject.IsNull() )
539 setObjectVisibility( anObject, false );
540 myEditedObject->RemoveGeometryObject( anObject );
543 module()->update( UF_OCCViewer );
544 aPanel->excludeGeomObjects( aSelectedList );
547 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
549 // Check if the case is already modified or not
550 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
553 // If not modified check if the case has already defined regions with zones
554 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
555 if ( aSeq.Length() > 0 )
557 // If there are already defined zones then ask a user to confirm zones recalculation
558 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
559 tr( "REGIONS_CHANGED" ),
560 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
561 QMessageBox::Yes | QMessageBox::No,
562 QMessageBox::No ) == QMessageBox::Yes );
566 isConfirmed = true; // No regions - no zones - nothing to recalculate
572 bool HYDROGUI_CalculationOp::confirmOrderChange() const
574 // Check if the case is already modified or not
575 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
578 // If not modified check if the case has already defined regions with zones
579 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
580 if ( aSeq.Length() > 0 )
582 // If there are already defined zones then ask a user to confirm zones recalculation
583 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
584 tr( "ORDER_CHANGED" ),
585 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
586 QMessageBox::Yes | QMessageBox::No,
587 QMessageBox::No ) == QMessageBox::Yes );
591 isConfirmed = true; // No regions - no zones - nothing to recalculate
597 bool HYDROGUI_CalculationOp::confirmRuleChange() const
599 // Check if the case is already modified or not
600 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
603 // If not modified check if the case has already defined regions with zones
604 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
605 if ( aSeq.Length() > 0 )
607 // If there are already defined zones then ask a user to confirm zones recalculation
608 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
609 tr( "RULE_CHANGED" ),
610 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
611 QMessageBox::Yes | QMessageBox::No,
612 QMessageBox::No ) == QMessageBox::Yes );
616 isConfirmed = true; // No regions - no zones - nothing to recalculate
622 bool HYDROGUI_CalculationOp::confirmModeChange() const
624 // Check if the case is already modified or not
625 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
628 // If not modified check if the case has already defined regions with zones
629 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
630 if ( aSeq.Length() > 0 )
632 // If there are already defined zones then ask a user to confirm zones recalculation
633 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
634 tr( "MODE_CHANGED" ),
635 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
636 QMessageBox::Yes | QMessageBox::No,
637 QMessageBox::No ) == QMessageBox::Yes );
641 isConfirmed = true; // No regions - no zones - nothing to recalculate
647 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
649 HYDROData_WarningType aType = theWarning.Type;
650 if ( aType == WARN_OK ) {
658 case WARN_EMPTY_REGIONS:
659 aTitle = tr( "EMPTY_REGIONS" );
660 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
663 aTitle = tr( "WARNING" );
664 aMsg = theWarning.Data;
668 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
670 QMessageBox::Yes | QMessageBox::No,
673 return ( anAnswer == QMessageBox::Yes );
676 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
677 QString& theErrorMsg,
678 QStringList& theBrowseObjectsEntries )
680 HYDROGUI_CalculationDlg* aPanel =
681 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
687 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
688 theBrowseObjectsEntries.append( anEntry );
691 // For manual mode priority rules are redundant
692 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
693 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
696 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
701 void HYDROGUI_CalculationOp::onApply()
704 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
705 if ( aWarning.Type != WARN_OK ) {
706 if ( !confirmContinueWithWarning( aWarning ) ) {
707 // Go back to the first page
708 HYDROGUI_CalculationDlg* aPanel =
709 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
711 aPanel->onFirstPage();
717 QApplication::setOverrideCursor( Qt::WaitCursor );
719 int anUpdateFlags = 0;
721 QStringList aBrowseObjectsEntries;
723 bool aResult = false;
727 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
729 catch ( Standard_Failure )
731 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
732 anErrorMsg = aFailure->GetMessageString();
740 QApplication::restoreOverrideCursor();
744 module()->update( anUpdateFlags );
746 browseObjects( aBrowseObjectsEntries );
751 QString aMsg = tr( "INPUT_VALID_DATA" );
752 if( !anErrorMsg.isEmpty() )
753 aMsg.prepend( anErrorMsg + "\n" );
754 SUIT_MessageBox::critical( module()->getApp()->desktop(),
755 tr( "INSUFFICIENT_INPUT_DATA" ),
760 void HYDROGUI_CalculationOp::onNext( const int theIndex )
764 setAvailableGroups();
766 else if( theIndex==2 )
768 // Land cover map panel
769 HYDROGUI_CalculationDlg* aPanel =
770 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
774 setLandCoverMapVisible( true );
777 QStringList anEntryList;
779 // Get all land cover map objects to fill in combo-box
780 Handle(HYDROData_LandCoverMap) aLandCoverMapObj;
781 QString aLandCoverMapName;
785 HYDROData_Iterator anIter( doc(), KIND_LAND_COVER_MAP );
786 for ( ; anIter.More(); anIter.Next() )
788 aLandCoverMapObj = Handle(HYDROData_LandCoverMap)::DownCast( anIter.Current() );
790 if ( !aLandCoverMapObj.IsNull() )
792 aLandCoverMapName = aLandCoverMapObj->GetName();
793 if ( !aLandCoverMapName.isEmpty() )
795 aList.append( aLandCoverMapName );
796 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj ) );
800 aPanel->setLandCoverMapsNames( aList, anEntryList );
801 aLandCoverMapObj = myEditedObject->GetLandCoverMap();
802 if ( !aList.isEmpty() )
804 if ( aLandCoverMapObj.IsNull() )
805 aPanel->setLandCoverMap( aList.at( 0 ), false );
807 aPanel->setLandCoverMap( aList.at( 0 ), true );
809 aPanel->setLandCoverMap( aList.at( aList.indexOf( aLandCoverMapObj->GetName() ) ), true );
812 // Get all Strickler table objects to fill in combo-box
813 Handle(HYDROData_StricklerTable) aStricklerTableObj;
814 QString aStricklerTableName;
818 anIter = HYDROData_Iterator( doc(), KIND_STRICKLER_TABLE );
819 for ( ; anIter.More(); anIter.Next() )
821 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
823 if ( !aStricklerTableObj.IsNull() )
825 aStricklerTableName = aStricklerTableObj->GetName();
826 if ( !aStricklerTableName.isEmpty() )
828 aList.append( aStricklerTableName );
829 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
833 aPanel->setStricklerTableNames( aList, anEntryList );
834 //@ASL: bool anUpdateState = myEditedObject->IsMustBeUpdated();
835 if ( !aList.isEmpty() )
836 aPanel->setStricklerTable( aList.at( 0 ), false );
837 //@ASL: myEditedObject->SetToUpdate( anUpdateState );
839 if ( !myEditedObject.IsNull() )
843 // Select the certain Strickler table object in combo-box
844 aStricklerTableObj = myEditedObject->GetStricklerTable();
845 if ( aStricklerTableObj.IsNull() )
847 aPanel->setStricklerTable( QString() );
851 aStricklerTableName = aStricklerTableObj->GetName();
852 aPanel->setStricklerTable( aStricklerTableName );
855 // Select the certain land cover map object in combo-box
856 if ( aLandCoverMapObj.IsNull() )
858 aPanel->setLandCoverMap( QString() );
862 aLandCoverMapName = aLandCoverMapObj->GetName();
863 aPanel->setLandCoverMap( aLandCoverMapName );
868 closePreview( false );
869 createPreview( true );
871 else if( theIndex==3 )
873 HYDROGUI_CalculationDlg* aPanel =
874 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
878 QApplication::setOverrideCursor( Qt::WaitCursor );
880 setGeomObjectsVisible( false );
881 setLandCoverMapVisible( false );
883 QString aNewCaseName = aPanel->getObjectName();
884 QString anOldCaseName = myEditedObject->GetName();
885 bool isNameChanged = anOldCaseName != aNewCaseName;
887 bool anIsToUpdateOb = isNameChanged;
889 // At first we must to update the case name because of
890 // automatic names generation for regions and zones
891 myEditedObject->SetName( aNewCaseName );
893 // Zones: set parameters for automatic mode
894 int aMode = aPanel->getMode();
895 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
897 // Set objects in the specified order
898 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
900 myEditedObject->RemoveGeometryObjects();
901 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
903 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
904 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
905 if ( anObject.IsNull() )
909 myEditedObject->AddGeometryObject( anObject );
912 // Clear priority rules
913 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
914 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
916 // Set priority rules
917 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
918 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
919 aRule.Object2, aRule.MergeType,
920 HYDROData_CalculationCase::DataTag_CustomRules );
924 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
926 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
929 myEditedObject->Update();
931 AssignDefaultZonesColors();
933 //aPanel->setEditedObject( myEditedObject );
934 aPanel->refreshZonesBrowser();
936 closePreview( false );
937 createPreview( false );
939 anIsToUpdateOb = true;
944 setZonesVisible( true );
946 if ( isNameChanged ) {
947 module()->getDataModel()->updateObjectTree( myEditedObject );
951 QApplication::restoreOverrideCursor();
955 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
959 setGeomObjectsVisible( true );
961 closePreview( false );
962 createPreview( false );
966 setLandCoverMapVisible( true );
968 closePreview( false );
969 createPreview( true );
972 setZonesVisible( false );
974 else if( theIndex==3 )
976 AssignDefaultZonesColors();
978 closePreview( false );
979 createPreview( false );
982 setZonesVisible( true );
986 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
988 myShowZones = theIsVisible;
989 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
990 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
991 HYDROData_SequenceOfObjects aZones;
992 Handle(HYDROData_Region) aRegion;
993 if ( myPreviewViewManager )
995 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
997 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
998 if ( !aCtx.IsNull() )
1000 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1002 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1003 if ( !aRegion.IsNull() )
1005 aZones = aRegion->GetZones();
1006 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1007 for ( ; aZonesIter.More(); aZonesIter.Next() )
1009 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1015 module()->update( UF_OCCViewer );
1020 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1022 myShowGeomObjects = theIsVisible;
1024 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1026 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1027 for ( ; anIter.More(); anIter.Next() ) {
1028 setObjectVisibility( anIter.Value(), theIsVisible );
1032 void HYDROGUI_CalculationOp::setLandCoverMapVisible( bool theIsVisible )
1034 myShowLandCoverMap = theIsVisible;
1035 setObjectVisibility( myEditedObject->GetLandCoverMap(), theIsVisible );
1038 void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
1040 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1041 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1042 HYDROData_SequenceOfObjects aZones;
1043 Handle(HYDROData_Region) aRegion;
1044 if ( myPreviewViewManager )
1046 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1048 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1049 if ( !aCtx.IsNull() )
1052 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1054 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1055 if ( !aRegion.IsNull() )
1057 aZones = aRegion->GetZones();
1058 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1059 for ( ; aZonesIter.More(); aZonesIter.Next() )
1062 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1063 if ( !aZone.IsNull() )
1065 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1066 while (aFillingColor == Qt::red)
1067 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1069 aZone->SetColor(aFillingColor);
1079 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1080 float theSaturation/* = 0.5*/,
1081 float theValue/* = 0.95*/ ) const
1083 float aHue = ( rand()%1000 ) * 0.001f;
1086 aColor.setHsl( (int)(aHue*255.), 128, 128 );
1087 int r = aColor.red();
1088 int g = aColor.green();
1089 int b = aColor.blue();
1090 return ( aColor.isValid() ? aColor : Qt::darkBlue );
1093 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1095 HYDROGUI_CalculationDlg* aPanel =
1096 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1100 HYDROData_ListOfRules aRules;
1101 Handle(HYDROData_Entity) anObject1, anObject2;
1102 HYDROData_PriorityType aPriority;
1103 HYDROData_Zone::MergeType aMergeType;
1104 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1105 for ( int anIndex = 0; ; anIndex++ )
1107 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1108 HYDROData_CustomRule aRule;
1109 aRule.Object1 = anObject1;
1110 aRule.Object2 = anObject2;
1111 aRule.Priority = aPriority;
1112 aRule.MergeType = aMergeType;
1120 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1121 aPanel->setRules( aRules );
1124 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList )
1126 bool aRetValue = false;
1128 QList<HYDROGUI_Zone*> aZonesList;
1129 HYDROGUI_Zone* aZone;
1130 // Get a list of dropped zones
1131 for ( int i = 0; i < theZonesList.length(); i++ )
1133 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1136 aZonesList.append( aZone );
1139 if ( aZonesList.length() > 0 )
1141 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
1148 void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap )
1150 LightApp_Application* anApp = module()->getApp();
1151 HYDROData_SequenceOfObjects aSeq;
1152 if ( theLandCoverMap && myShowLandCoverMap )
1154 aSeq.Append( myEditedObject->GetLandCoverMap() );
1156 else if ( !theLandCoverMap && myShowGeomObjects )
1158 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1159 aSeq.Append( aSeqGO );
1162 Handle(HYDROData_Entity) anEntity;
1166 // Gather zones for displaying
1167 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1168 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1169 HYDROData_SequenceOfObjects aZones;
1170 Handle(HYDROData_Region) aRegion;
1171 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1173 anEntity = aRegionsIter.Value();
1174 if ( !anEntity.IsNull() )
1176 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1177 if ( !aRegion.IsNull() )
1179 aZones = aRegion->GetZones();
1180 aSeq.Append( aZones );
1186 // Get a boundary polyline if any
1187 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1189 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1191 if ( !myActiveViewManager )
1193 if ( aSeq.IsEmpty() )
1196 myActiveViewManager = anApp->activeViewManager();
1199 if ( !myPreviewViewManager )
1201 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1202 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1203 if ( myPreviewViewManager )
1205 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1206 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1208 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1209 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1213 if ( !myPreviewViewManager )
1216 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1218 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1219 if ( !aCtx.IsNull() )
1221 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1222 for ( ; anIter.More(); anIter.Next() )
1224 setObjectVisibility( anIter.Value(), true );
1227 //Process the draw events for viewer
1228 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1229 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1233 module()->update( UF_OCCViewer | UF_FitAll );
1237 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1239 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1243 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1245 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1249 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1254 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1256 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1257 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1258 QShortcut* aShortcut;
1259 foreach( aShortcut, aShortcuts )
1261 if ( aShortcut->key() ==
1262 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1263 SUIT_DataBrowser::RenameShortcut ) ) )
1265 aShortcut->setEnabled( true );
1270 if( myPreviewViewManager )
1272 // Hide all the displayed objects in the preview view
1273 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1275 size_t aViewId = (size_t)aViewer;
1276 HYDROData_Iterator anIterator( doc() );
1277 for( ; anIterator.More(); anIterator.Next() ) {
1278 Handle(HYDROData_Entity) anObject = anIterator.Current();
1279 if( !anObject.IsNull() ) {
1280 module()->setObjectVisible( aViewId, anObject, false );
1285 if ( theRemoveViewManager )
1287 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1288 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1290 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1291 myPreviewViewManager = NULL;
1295 if( myActiveViewManager && theRemoveViewManager )
1297 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1298 myActiveViewManager = NULL;
1302 void HYDROGUI_CalculationOp::setAvailableGroups()
1304 HYDROGUI_CalculationDlg* aPanel =
1305 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1307 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1308 QStringList aList, anEntryList;
1309 getNamesAndEntries( aSeq, aList, anEntryList );
1311 QStringList aGroupsNames;
1313 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1314 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1316 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anObjs.Value( anIndex ) );
1317 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1318 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1320 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( aGIndex ) );
1321 aGroupsNames.append( aGroup->GetName() );
1324 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) ) {
1325 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1326 Handle(HYDROData_ShapesGroup) aGeomGroup =
1327 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1328 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1329 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1334 aPanel->setAvailableGroups( aGroupsNames );
1335 aPanel->includeGroups( aList );
1337 //@ASL: bool isUpdated = myEditedObject->IsMustBeUpdated();
1340 void HYDROGUI_CalculationOp::onAddGroups()
1342 HYDROGUI_CalculationDlg* aPanel =
1343 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1347 // Add geometry objects selected in the module browser to the calculation case
1348 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1349 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1352 QStringList anAddedList;
1353 for (int i = 0; i < aSelectedList.length(); i++)
1355 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1356 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1357 if ( aGroup.IsNull() )
1360 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1361 anAddedList.append( aGroup->GetName() );
1364 if ( !anAddedList.isEmpty() )
1366 aPanel->includeGroups( anAddedList );
1370 void HYDROGUI_CalculationOp::onRemoveGroups()
1372 // Remove selected objects from the calculation case
1373 HYDROGUI_CalculationDlg* aPanel =
1374 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1378 QStringList aSelectedList = aPanel->getSelectedGroups();
1379 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1382 for (int i = 0; i < aSelectedList.length(); i++)
1384 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1385 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1386 if ( aGroup.IsNull() )
1389 myEditedObject->RemoveGeometryGroup( aGroup );
1392 aPanel->excludeGroups( aSelectedList );
1395 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1397 HYDROGUI_CalculationDlg* aPanel =
1398 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1402 if ( !confirmModeChange() ) {
1403 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1407 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1408 aPanel->setMode( theMode );
1411 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1413 HYDROGUI_CalculationDlg* aPanel =
1414 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1418 isConfirmed = confirmOrderChange();
1420 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1423 void HYDROGUI_CalculationOp::onRuleChanged( bool& isConfirmed )
1425 HYDROGUI_CalculationDlg* aPanel =
1426 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1430 isConfirmed = confirmRuleChange();
1432 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1435 void HYDROGUI_CalculationOp::onRegenerateColors()
1437 // For geometry zones
1438 AssignDefaultZonesColors();
1439 setZonesVisible( false );
1440 setZonesVisible( true );