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 & ) ) );
254 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
256 bool anIsToUpdateViewer = false;
258 // Remove the old boundary from the operation viewer
259 Handle(HYDROData_PolylineXY) aPrevPolyline =
260 myEditedObject->GetBoundaryPolyline();
261 if ( !aPrevPolyline.IsNull() )
263 setObjectVisibility( aPrevPolyline, false );
264 anIsToUpdateViewer = true;
267 // Set the selected boundary polyline to the calculation case
268 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
269 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
270 myEditedObject->SetBoundaryPolyline( aNewPolyline );
272 if ( myPreviewViewManager )
274 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
277 if ( !aNewPolyline.IsNull() )
279 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
280 if ( !aCtx.IsNull() )
282 setObjectVisibility( aNewPolyline, true );
283 anIsToUpdateViewer = true;
287 if ( anIsToUpdateViewer )
288 module()->update( UF_OCCViewer );
293 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
295 bool anIsToUpdateViewer = false;
297 // Remove old presentations of land covers from the operation viewer
298 Handle(HYDROData_Entity) anEntity;
299 Handle(HYDROData_LandCover) aLandCover;
300 HYDROData_SequenceOfObjects aLandCovers;
301 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
302 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
303 for ( ; anIter.More(); anIter.Next() )
305 anEntity = anIter.Value();
306 if ( !anEntity.IsNull() )
308 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
309 if ( !aLandCover.IsNull() )
311 aLandCovers.Append( aLandCover );
312 setObjectVisibility( aLandCover, false );
313 anIsToUpdateViewer = true;
318 // Set the selected Strickler table to the calculation case
319 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
320 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
321 myEditedObject->SetStricklerTable( aNewStricklerTable );
323 if ( myPreviewViewManager )
325 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
328 if ( !aNewStricklerTable.IsNull() )
330 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
331 if ( !aCtx.IsNull() )
333 HYDROData_SequenceOfObjects::Iterator anIter( aLandCovers );
334 for ( ; anIter.More(); anIter.Next() )
336 anEntity = anIter.Value();
337 if ( !anEntity.IsNull() )
339 aLandCover = Handle(HYDROData_LandCover)::DownCast( anEntity );
340 if ( !aLandCover.IsNull() )
342 setObjectVisibility( aLandCover, true );
343 anIsToUpdateViewer = true;
350 if ( anIsToUpdateViewer )
351 module()->update( UF_OCCViewer );
356 void HYDROGUI_CalculationOp::onObjectsSelected()
358 HYDROGUI_CalculationDlg* aPanel =
359 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
361 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
362 QMap<QString, bool> aSelectedObjsMap;
363 foreach( QString aName, aSelectedObjs )
364 aSelectedObjsMap[aName] = true;
367 // Select the appropriate geometry object shape in the viewer
368 selectionMgr()->clearSelected();
370 // Unhighlight all objects except selected
371 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
372 Handle(HYDROData_Entity) anEntity;
373 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
374 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
377 for ( ; anIter.More(); anIter.Next() )
379 anEntity = anIter.Value();
380 if ( !anEntity.IsNull() )
382 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
385 aName = anEntity->GetName();
386 isSelected = aSelectedObjsMap.contains( aName );
387 aShape->highlight( isSelected, false );
388 aShape->update( false, false );
394 aLastShape->update( true, false );
397 void HYDROGUI_CalculationOp::onLandCoversSelected()
399 HYDROGUI_CalculationDlg* aPanel =
400 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
402 QStringList aSelectedObjs = aPanel->getSelectedLandCovers();
403 QMap<QString, bool> aSelectedObjsMap;
404 foreach( QString aName, aSelectedObjs )
405 aSelectedObjsMap[aName] = true;
408 // Select the appropriate land cover shape in the viewer
409 selectionMgr()->clearSelected();
411 // Unhighlight all land covers except selected
412 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
413 Handle(HYDROData_Entity) anEntity;
414 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
415 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
418 for ( ; anIter.More(); anIter.Next() )
420 anEntity = anIter.Value();
421 if ( !anEntity.IsNull() )
423 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
426 aName = anEntity->GetName();
427 isSelected = aSelectedObjsMap.contains( aName );
428 aShape->highlight( isSelected, false );
429 aShape->update( false, false );
435 aLastShape->update( true, false );
438 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
440 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
441 HYDROGUI_Zone* aZoneItem;
442 selectionMgr()->clearSelected();
445 // Select a region in preview
446 SUIT_DataOwnerPtrList aList( true );
447 DataObjectList aZones = aRegionItem->children();
448 for ( int i = 0; i < aZones.length(); i++ )
450 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
453 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
456 selectionMgr()->setSelected( aList );
460 // select a single zone
461 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
464 SUIT_DataOwnerPtrList aList( true );
465 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
466 selectionMgr()->setSelected( aList );
471 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
472 const QList<SUIT_DataObject*>& theZonesList,
475 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
478 QList<HYDROGUI_Zone*> aZonesList;
479 HYDROGUI_Zone* aZone;
480 // Get a list of dropped zones
481 for ( int i = 0; i < theZonesList.length(); i++ )
483 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
486 aZonesList.append( aZone );
489 if ( aZonesList.length() > 0 )
491 aRegion->addZones( aZonesList );
492 HYDROGUI_CalculationDlg* aPanel =
493 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
496 theLandCover ? aPanel->refreshLandCoverZonesBrowser(): aPanel->refreshZonesBrowser();
498 createPreview( theLandCover );
503 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
505 if ( createRegion( theZonesList, false ) )
507 HYDROGUI_CalculationDlg* aPanel =
508 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
511 aPanel->refreshZonesBrowser();
513 createPreview( false );
517 void HYDROGUI_CalculationOp::onCreateLandCoverRegion( const QList<SUIT_DataObject*>& theZonesList )
519 if ( createRegion( theZonesList, true ) )
521 HYDROGUI_CalculationDlg* aPanel =
522 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
525 aPanel->refreshLandCoverZonesBrowser();
527 createPreview( true );
531 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
533 HYDROGUI_CalculationDlg* aPanel =
534 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
537 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
540 aZone->setMergeType( theMergeType, theMergeObjectName );
541 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
544 aShape->update( true, false );
547 aPanel->refreshZonesBrowser();
551 void HYDROGUI_CalculationOp::onSetMergeStricklerType( int theMergeType, QString& theStricklerTypeName )
553 HYDROGUI_CalculationDlg* aPanel =
554 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
557 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
560 aZone->setMergeType( theMergeType, theStricklerTypeName );
561 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
564 aShape->update( true, false );
567 aPanel->refreshLandCoverZonesBrowser();
571 void HYDROGUI_CalculationOp::onAddObjects()
573 HYDROGUI_CalculationDlg* aPanel =
574 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
578 // Add geometry objects selected in the module browser to the calculation case
579 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
580 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
583 QStringList anAddedList;
584 for (int i = 0; i < aSelectedList.length(); i++)
586 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
587 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
588 if ( anObject.IsNull() )
591 if ( myEditedObject->AddGeometryObject( anObject ) )
592 anAddedList.append( anObject->GetName() );
595 if ( !anAddedList.isEmpty() )
597 aPanel->includeGeomObjects( anAddedList );
598 createPreview( false );
602 void HYDROGUI_CalculationOp::onRemoveObjects()
604 // Remove selected objects from the calculation case
605 HYDROGUI_CalculationDlg* aPanel =
606 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
610 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
611 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
614 for (int i = 0; i < aSelectedList.length(); i++)
616 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
617 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
618 if ( anObject.IsNull() )
621 setObjectVisibility( anObject, false );
622 myEditedObject->RemoveGeometryObject( anObject );
625 module()->update( UF_OCCViewer );
626 aPanel->excludeGeomObjects( aSelectedList );
629 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
631 // Check if the case is already modified or not
632 bool isConfirmed = myEditedObject->IsMustBeUpdated();
635 // If not modified check if the case has already defined regions with zones
636 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
637 if ( aSeq.Length() > 0 )
639 // If there are already defined zones then ask a user to confirm zones recalculation
640 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
641 tr( "REGIONS_CHANGED" ),
642 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
643 QMessageBox::Yes | QMessageBox::No,
644 QMessageBox::No ) == QMessageBox::Yes );
648 isConfirmed = true; // No regions - no zones - nothing to recalculate
654 bool HYDROGUI_CalculationOp::confirmOrderChange() const
656 // Check if the case is already modified or not
657 bool isConfirmed = myEditedObject->IsMustBeUpdated();
660 // If not modified check if the case has already defined regions with zones
661 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
662 if ( aSeq.Length() > 0 )
664 // If there are already defined zones then ask a user to confirm zones recalculation
665 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
666 tr( "ORDER_CHANGED" ),
667 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
668 QMessageBox::Yes | QMessageBox::No,
669 QMessageBox::No ) == QMessageBox::Yes );
673 isConfirmed = true; // No regions - no zones - nothing to recalculate
679 bool HYDROGUI_CalculationOp::confirmRuleChange() const
681 // Check if the case is already modified or not
682 bool isConfirmed = myEditedObject->IsMustBeUpdated();
685 // If not modified check if the case has already defined regions with zones
686 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
687 if ( aSeq.Length() > 0 )
689 // If there are already defined zones then ask a user to confirm zones recalculation
690 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
691 tr( "RULE_CHANGED" ),
692 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
693 QMessageBox::Yes | QMessageBox::No,
694 QMessageBox::No ) == QMessageBox::Yes );
698 isConfirmed = true; // No regions - no zones - nothing to recalculate
704 bool HYDROGUI_CalculationOp::confirmModeChange() const
706 // Check if the case is already modified or not
707 bool isConfirmed = myEditedObject->IsMustBeUpdated();
710 // If not modified check if the case has already defined regions with zones
711 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( false );
712 if ( aSeq.Length() > 0 )
714 // If there are already defined zones then ask a user to confirm zones recalculation
715 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
716 tr( "MODE_CHANGED" ),
717 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
718 QMessageBox::Yes | QMessageBox::No,
719 QMessageBox::No ) == QMessageBox::Yes );
723 isConfirmed = true; // No regions - no zones - nothing to recalculate
729 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
731 HYDROData_WarningType aType = theWarning.Type;
732 if ( aType == WARN_OK ) {
740 case WARN_EMPTY_REGIONS:
741 aTitle = tr( "EMPTY_REGIONS" );
742 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
745 aTitle = tr( "WARNING" );
746 aMsg = theWarning.Data;
750 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
752 QMessageBox::Yes | QMessageBox::No,
755 return ( anAnswer == QMessageBox::Yes );
758 bool HYDROGUI_CalculationOp::confirmLandCoverRegionsChange() const
760 // Check if the case is already modified or not
761 bool isConfirmed = myEditedObject->IsMustBeUpdated();
764 // If not modified check if the case has already defined regions with land cover zones
765 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
766 if ( aSeq.Length() > 0 )
768 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
769 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
770 tr( "REGIONS_CHANGED" ),
771 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
772 QMessageBox::Yes | QMessageBox::No,
773 QMessageBox::No ) == QMessageBox::Yes );
777 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
783 bool HYDROGUI_CalculationOp::confirmLandCoverModeChange() const
785 // Check if the case is already modified or not
786 bool isConfirmed = myEditedObject->IsMustBeUpdated();
789 // If not modified check if the case has already defined regions with land cover zones
790 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
791 if ( aSeq.Length() > 0 )
793 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
794 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
795 tr( "MODE_CHANGED" ),
796 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_MODE" ),
797 QMessageBox::Yes | QMessageBox::No,
798 QMessageBox::No ) == QMessageBox::Yes );
802 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
808 bool HYDROGUI_CalculationOp::confirmLandCoverOrderChange() const
810 // Check if the case is already modified or not
811 bool isConfirmed = myEditedObject->IsMustBeUpdated();
814 // If not modified check if the case has already defined regions with land cover zones
815 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
816 if ( aSeq.Length() > 0 )
818 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
819 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
820 tr( "ORDER_CHANGED" ),
821 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
822 QMessageBox::Yes | QMessageBox::No,
823 QMessageBox::No ) == QMessageBox::Yes );
827 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
833 bool HYDROGUI_CalculationOp::confirmLandCoverRuleChange() const
835 // Check if the case is already modified or not
836 bool isConfirmed = myEditedObject->IsMustBeUpdated();
839 // If not modified check if the case has already defined regions with land cover zones
840 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions( true );
841 if ( aSeq.Length() > 0 )
843 // If there are already defined land cover zones then ask a user to confirm land cover zones recalculation
844 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
845 tr( "RULE_CHANGED" ),
846 tr( "CONFIRM_LAND_COVER_PARTITION_RECALCULATION_REGIONS" ),
847 QMessageBox::Yes | QMessageBox::No,
848 QMessageBox::No ) == QMessageBox::Yes );
852 isConfirmed = true; // No regions - no land cover zones - nothing to recalculate
858 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
859 QString& theErrorMsg,
860 QStringList& theBrowseObjectsEntries )
862 HYDROGUI_CalculationDlg* aPanel =
863 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
869 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
870 theBrowseObjectsEntries.append( anEntry );
873 // For manual mode priority rules are redundant
874 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
875 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
877 if ( aPanel->getLandCoverMode() == HYDROData_CalculationCase::MANUAL ) {
878 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, false );
881 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
886 void HYDROGUI_CalculationOp::onApply()
889 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
890 if ( aWarning.Type != WARN_OK ) {
891 if ( !confirmContinueWithWarning( aWarning ) ) {
892 // Go back to the first page
893 HYDROGUI_CalculationDlg* aPanel =
894 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
896 aPanel->onFirstPage();
902 QApplication::setOverrideCursor( Qt::WaitCursor );
904 int anUpdateFlags = 0;
906 QStringList aBrowseObjectsEntries;
908 bool aResult = false;
912 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
914 catch ( Standard_Failure )
916 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
917 anErrorMsg = aFailure->GetMessageString();
925 QApplication::restoreOverrideCursor();
929 module()->update( anUpdateFlags );
931 browseObjects( aBrowseObjectsEntries );
936 QString aMsg = tr( "INPUT_VALID_DATA" );
937 if( !anErrorMsg.isEmpty() )
938 aMsg.prepend( anErrorMsg + "\n" );
939 SUIT_MessageBox::critical( module()->getApp()->desktop(),
940 tr( "INSUFFICIENT_INPUT_DATA" ),
945 void HYDROGUI_CalculationOp::onNext( const int theIndex )
949 setAvailableGroups();
951 else if( theIndex==2 )
954 HYDROGUI_CalculationDlg* aPanel =
955 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
959 setLandCoversVisible( true );
962 QStringList anEntryList;
963 HYDROData_SequenceOfObjects aSeq;
965 Handle(HYDROData_StricklerTable) aStricklerTableObj;
966 QString aStricklerTableName;
968 // Get all Strickler table objects to fill in combo-box
971 HYDROData_Iterator anIter( doc(), KIND_STRICKLER_TABLE );
972 for ( ; anIter.More(); anIter.Next() )
974 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
976 if ( !aStricklerTableObj.IsNull() )
978 aStricklerTableName = aStricklerTableObj->GetName();
979 if ( !aStricklerTableName.isEmpty() )
981 aList.append( aStricklerTableName );
982 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
986 aPanel->setStricklerTableNames( aList, anEntryList );
987 bool anUpdateState = myEditedObject->IsMustBeUpdated();
988 if ( !aList.isEmpty() )
989 aPanel->setStricklerTable( aList.at( 0 ), false );
990 myEditedObject->SetToUpdate( anUpdateState );
992 // Fill in list widget with all available land covers
993 aSeq = HYDROGUI_Tool::GetLandCovers( module() );
994 getNamesAndEntries( aSeq, aList, anEntryList );
995 aPanel->setAllLandCovers( aList, anEntryList );
997 // Set list of included land covers
998 aSeq = myEditedObject->GetLandCovers();
999 getNamesAndEntries( aSeq, aList, anEntryList );
1000 aPanel->includeLandCovers( aList, true );
1002 if ( !myEditedObject.IsNull() )
1006 // Select the certain Strickler table object in combo-box
1007 aStricklerTableObj = myEditedObject->GetStricklerTable();
1008 if ( aStricklerTableObj.IsNull() )
1010 aPanel->setStricklerTable( QString() );
1014 aStricklerTableName = aStricklerTableObj->GetName();
1015 aPanel->setStricklerTable( aStricklerTableName );
1018 // Set mode (Auto or Manual) to defined priority of land covers
1019 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1021 // Set rules defined on land covers
1022 setRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1026 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getLandCoverMode() );
1030 closePreview( false );
1031 createPreview( true );
1033 else if( theIndex==3 )
1035 HYDROGUI_CalculationDlg* aPanel =
1036 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1040 QApplication::setOverrideCursor( Qt::WaitCursor );
1042 setGeomObjectsVisible( false );
1043 setLandCoversVisible( false );
1045 QString aNewCaseName = aPanel->getObjectName();
1046 QString anOldCaseName = myEditedObject->GetName();
1047 bool isNameChanged = anOldCaseName != aNewCaseName;
1049 bool anIsToUpdateOb = isNameChanged;
1051 // At first we must to update the case name because of
1052 // automatic names generation for regions and zones
1053 myEditedObject->SetName( aNewCaseName );
1055 // Zones: set parameters for automatic mode
1056 int aMode = aPanel->getMode();
1057 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1059 // Set objects in the specified order
1060 if( myEditedObject->IsMustBeUpdated() )
1062 myEditedObject->RemoveGeometryObjects();
1063 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
1065 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
1066 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1067 if ( anObject.IsNull() )
1071 myEditedObject->AddGeometryObject( anObject );
1074 // Clear priority rules
1075 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
1076 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
1078 // Set priority rules
1079 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
1080 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1081 aRule.Object2, aRule.MergeType,
1082 HYDROData_CalculationCase::DataTag_CustomRules );
1086 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1088 // Land cover zones: set parameters for automatic mode
1089 aMode = aPanel->getLandCoverMode();
1090 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1092 // Set objects in the specified order
1093 if( myEditedObject->IsMustBeUpdated() )
1095 myEditedObject->RemoveLandCovers();
1096 foreach ( const QString& aName, aPanel->getAllLandCovers() )
1098 Handle(HYDROData_LandCover) aLandCover = Handle(HYDROData_LandCover)::DownCast(
1099 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1100 if ( aLandCover.IsNull() )
1104 myEditedObject->AddLandCover( aLandCover );
1107 // Clear priority rules
1108 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomLandCoverRules, true );
1109 // Set priority rules
1110 foreach ( const HYDROData_CustomRule& aRule, aPanel->getLandCoverRules() ) {
1111 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1112 aRule.Object2, HYDROData_Zone::Merge_Object,
1113 HYDROData_CalculationCase::DataTag_CustomLandCoverRules );
1117 aPanel->setEditLandCoverZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1119 if ( myEditedObject->IsMustBeUpdated() )
1122 myEditedObject->Update();
1124 AssignDefaultZonesColors( false );
1126 //aPanel->setEditedObject( myEditedObject );
1127 aPanel->refreshZonesBrowser();
1129 closePreview( false );
1130 createPreview( false );
1132 anIsToUpdateOb = true;
1134 myUpdateLandCoverZonesPrs = true;
1139 setZonesVisible( true, false );
1141 if ( isNameChanged ) {
1142 module()->getDataModel()->updateObjectTree( myEditedObject );
1146 QApplication::restoreOverrideCursor();
1148 else if( theIndex==4 )
1150 // Partition of Land covers panel
1151 HYDROGUI_CalculationDlg* aPanel =
1152 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1156 QApplication::setOverrideCursor( Qt::WaitCursor );
1158 bool anIsToUpdateOb = false;
1159 if ( myUpdateLandCoverZonesPrs )
1163 AssignDefaultZonesColors( true );
1165 aPanel->refreshLandCoverZonesBrowser();
1167 anIsToUpdateOb = true;
1170 closePreview( false );
1171 createPreview( true );
1173 if ( myUpdateLandCoverZonesPrs )
1174 myUpdateLandCoverZonesPrs = false;
1178 setZonesVisible( false, false );
1179 // Show land cover zones
1180 setZonesVisible( true, true );
1183 if ( anIsToUpdateOb ) {
1184 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
1185 if ( anObjBrowser ) {
1186 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
1190 QApplication::restoreOverrideCursor();
1194 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1198 setGeomObjectsVisible( true );
1200 closePreview( false );
1201 createPreview( false );
1205 setLandCoversVisible( true );
1207 closePreview( false );
1208 createPreview( true );
1211 setZonesVisible( false, false );
1213 setZonesVisible( false, true );
1215 else if( theIndex==3 )
1217 AssignDefaultZonesColors( false );
1219 closePreview( false );
1220 createPreview( false );
1222 // Hide land cover zones
1223 setZonesVisible( false, true );
1225 setZonesVisible( true, false );
1229 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible, const bool theLandCover )
1231 myShowZones = theIsVisible;
1232 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1233 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1234 HYDROData_SequenceOfObjects aZones;
1235 Handle(HYDROData_Region) aRegion;
1236 if ( myPreviewViewManager )
1238 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1240 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1241 if ( !aCtx.IsNull() )
1243 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1245 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1246 if ( !aRegion.IsNull() )
1248 aZones = aRegion->GetZones();
1249 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1250 for ( ; aZonesIter.More(); aZonesIter.Next() )
1252 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1258 module()->update( UF_OCCViewer );
1263 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1265 myShowGeomObjects = theIsVisible;
1267 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1269 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1270 for ( ; anIter.More(); anIter.Next() ) {
1271 setObjectVisibility( anIter.Value(), theIsVisible );
1275 void HYDROGUI_CalculationOp::setLandCoversVisible( bool theIsVisible )
1277 myShowLandCovers = theIsVisible;
1279 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetLandCovers();
1281 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1282 for ( ; anIter.More(); anIter.Next() ) {
1283 setObjectVisibility( anIter.Value(), theIsVisible );
1287 void HYDROGUI_CalculationOp::AssignDefaultZonesColors( const bool theLandCover )
1289 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1290 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1291 HYDROData_SequenceOfObjects aZones;
1292 Handle(HYDROData_Region) aRegion;
1293 if ( myPreviewViewManager )
1295 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1297 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1298 if ( !aCtx.IsNull() )
1301 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1303 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1304 if ( !aRegion.IsNull() )
1306 aZones = aRegion->GetZones();
1307 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1308 for ( ; aZonesIter.More(); aZonesIter.Next() )
1311 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1312 if ( !aZone.IsNull() )
1314 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
1315 while (aFillingColor == Qt::red)
1316 aFillingColor = GenerateDefaultZonesColor(++aCounter);
1318 aZone->SetColor(aFillingColor);
1328 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
1329 float theSaturation/* = 0.5*/,
1330 float theValue/* = 0.95*/ ) const
1332 float aGoldenRatioConjugate = (float)(360./582.);
1333 float aHue = (float)(rand()%100);
1334 aHue += aGoldenRatioConjugate*theIndex;
1335 aHue -= floor(aHue);
1337 float aR = 0., aG = 0., aB = 0.;
1338 int aHueInt = (int)(aHue*6.);
1339 float aF = aHue*6. - aHueInt;
1340 float aP = theValue * (1. - theSaturation);
1341 float aQ = theValue * (1. - aF*theSaturation);
1342 float aT = theValue * (1. - (1. - aF) * theSaturation);
1345 case 0: { aR = theValue; aG = aT; aB = aP; break; }
1346 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
1347 case 2: { aR = aP; aG = theValue; aB = aT; break; }
1348 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
1349 case 4: { aR = aT; aG = aP; aB = theValue; break; }
1350 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
1354 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
1355 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
1358 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1360 HYDROGUI_CalculationDlg* aPanel =
1361 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1365 HYDROData_ListOfRules aRules;
1366 Handle(HYDROData_Entity) anObject1, anObject2;
1367 HYDROData_PriorityType aPriority;
1368 HYDROData_Zone::MergeType aMergeType;
1369 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1370 for ( int anIndex = 0; ; anIndex++ )
1372 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1373 HYDROData_CustomRule aRule;
1374 aRule.Object1 = anObject1;
1375 aRule.Object2 = anObject2;
1376 aRule.Priority = aPriority;
1377 aRule.MergeType = aMergeType;
1385 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1386 aPanel->setRules( aRules );
1387 else if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomLandCoverRules )
1388 aPanel->setLandCoverRules( aRules );
1391 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList,
1392 const bool theLandCover )
1394 bool aRetValue = false;
1396 QList<HYDROGUI_Zone*> aZonesList;
1397 HYDROGUI_Zone* aZone;
1398 // Get a list of dropped zones
1399 for ( int i = 0; i < theZonesList.length(); i++ )
1401 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1404 aZonesList.append( aZone );
1407 if ( aZonesList.length() > 0 )
1409 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList, theLandCover );
1416 void HYDROGUI_CalculationOp::createPreview( const bool theLandCover )
1418 LightApp_Application* anApp = module()->getApp();
1419 HYDROData_SequenceOfObjects aSeq;
1420 if ( theLandCover && myShowLandCovers )
1422 HYDROData_SequenceOfObjects aSeqLC = myEditedObject->GetLandCovers();
1423 aSeq.Append( aSeqLC );
1425 else if ( !theLandCover && myShowGeomObjects )
1427 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1428 aSeq.Append( aSeqGO );
1431 Handle(HYDROData_Entity) anEntity;
1435 // Gather zones for displaying
1436 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions( theLandCover );
1437 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1438 HYDROData_SequenceOfObjects aZones;
1439 Handle(HYDROData_Region) aRegion;
1440 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1442 anEntity = aRegionsIter.Value();
1443 if ( !anEntity.IsNull() )
1445 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1446 if ( !aRegion.IsNull() )
1448 aZones = aRegion->GetZones();
1449 aSeq.Append( aZones );
1455 // Get a boundary polyline if any
1456 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
1458 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1460 if ( !myActiveViewManager )
1462 if ( aSeq.IsEmpty() )
1465 myActiveViewManager = anApp->activeViewManager();
1468 if ( !myPreviewViewManager )
1470 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1471 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1472 if ( myPreviewViewManager )
1474 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1475 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1477 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1478 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1482 if ( !myPreviewViewManager )
1485 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1487 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1488 if ( !aCtx.IsNull() )
1490 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1491 for ( ; anIter.More(); anIter.Next() )
1493 setObjectVisibility( anIter.Value(), true );
1496 //Process the draw events for viewer
1497 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1498 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
1502 module()->update( UF_OCCViewer | UF_FitAll );
1506 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1508 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1512 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1514 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1518 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1523 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1525 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1526 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1527 QShortcut* aShortcut;
1528 foreach( aShortcut, aShortcuts )
1530 if ( aShortcut->key() ==
1531 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1532 SUIT_DataBrowser::RenameShortcut ) ) )
1534 aShortcut->setEnabled( true );
1539 if( myPreviewViewManager )
1541 // Hide all the displayed objects in the preview view
1542 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1544 size_t aViewId = (size_t)aViewer;
1545 HYDROData_Iterator anIterator( doc() );
1546 for( ; anIterator.More(); anIterator.Next() ) {
1547 Handle(HYDROData_Entity) anObject = anIterator.Current();
1548 if( !anObject.IsNull() ) {
1549 module()->setObjectVisible( aViewId, anObject, false );
1554 if ( theRemoveViewManager )
1556 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1557 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1559 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1560 myPreviewViewManager = NULL;
1564 if( myActiveViewManager && theRemoveViewManager )
1566 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1567 myActiveViewManager = NULL;
1571 void HYDROGUI_CalculationOp::setAvailableGroups()
1573 HYDROGUI_CalculationDlg* aPanel =
1574 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1576 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1577 QStringList aList, anEntryList;
1578 getNamesAndEntries( aSeq, aList, anEntryList );
1580 QStringList aGroupsNames;
1582 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1583 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1585 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1586 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1587 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1589 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1590 aGroupsNames.append( aGroup->GetName() );
1593 if( myEditedObject->IsMustBeUpdated() ) {
1594 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1595 Handle(HYDROData_ShapesGroup) aGeomGroup =
1596 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1597 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1598 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1603 aPanel->setAvailableGroups( aGroupsNames );
1604 aPanel->includeGroups( aList );
1606 bool isUpdated = myEditedObject->IsMustBeUpdated();
1609 void HYDROGUI_CalculationOp::onAddGroups()
1611 HYDROGUI_CalculationDlg* aPanel =
1612 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1616 // Add geometry objects selected in the module browser to the calculation case
1617 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1618 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1621 QStringList anAddedList;
1622 for (int i = 0; i < aSelectedList.length(); i++)
1624 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1625 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1626 if ( aGroup.IsNull() )
1629 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1630 anAddedList.append( aGroup->GetName() );
1633 if ( !anAddedList.isEmpty() )
1635 aPanel->includeGroups( anAddedList );
1639 void HYDROGUI_CalculationOp::onRemoveGroups()
1641 // Remove selected objects from the calculation case
1642 HYDROGUI_CalculationDlg* aPanel =
1643 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1647 QStringList aSelectedList = aPanel->getSelectedGroups();
1648 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1651 for (int i = 0; i < aSelectedList.length(); i++)
1653 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1654 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1655 if ( aGroup.IsNull() )
1658 myEditedObject->RemoveGeometryGroup( aGroup );
1661 aPanel->excludeGroups( aSelectedList );
1664 void HYDROGUI_CalculationOp::onChangeLandCoverMode( int theMode )
1666 HYDROGUI_CalculationDlg* aPanel =
1667 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1671 if ( !confirmLandCoverModeChange() ) {
1672 aPanel->setLandCoverMode( myEditedObject->GetAssignmentLandCoverMode() );
1676 myEditedObject->SetAssignmentLandCoverMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1677 aPanel->setLandCoverMode( theMode );
1680 void HYDROGUI_CalculationOp::onAddLandCovers()
1682 HYDROGUI_CalculationDlg* aPanel =
1683 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1687 // Add land covers selected in the module browser to the calculation case
1688 QStringList aSelectedList = aPanel->getSelectedAvailableLandCovers();
1689 if ( aSelectedList.isEmpty() || !confirmLandCoverRegionsChange() )
1692 QStringList anAddedList;
1693 for (int i = 0; i < aSelectedList.length(); i++)
1695 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1696 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1697 if ( anObject.IsNull() )
1700 if ( myEditedObject->AddLandCover( anObject ) )
1701 anAddedList.append( anObject->GetName() );
1704 if ( !anAddedList.isEmpty() )
1706 aPanel->includeLandCovers( anAddedList, false );
1707 createPreview( true );
1711 void HYDROGUI_CalculationOp::onRemoveLandCovers()
1713 // Remove selected objects from the calculation case
1714 HYDROGUI_CalculationDlg* aPanel =
1715 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1719 QStringList aSelectedList = aPanel->getSelectedLandCovers();
1720 if ( aSelectedList.isEmpty() || !confirmLandCoverRegionsChange() )
1723 for (int i = 0; i < aSelectedList.length(); i++)
1725 Handle(HYDROData_LandCover) anObject = Handle(HYDROData_LandCover)::DownCast(
1726 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1727 if ( anObject.IsNull() )
1730 setObjectVisibility( anObject, false );
1731 myEditedObject->RemoveLandCover( anObject );
1734 module()->update( UF_OCCViewer );
1735 aPanel->excludeLandCovers( aSelectedList );
1738 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1740 HYDROGUI_CalculationDlg* aPanel =
1741 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1745 if ( !confirmModeChange() ) {
1746 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1750 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1751 aPanel->setMode( theMode );
1754 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1756 HYDROGUI_CalculationDlg* aPanel =
1757 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1761 isConfirmed = confirmOrderChange();
1763 myEditedObject->SetToUpdate( true );
1766 void HYDROGUI_CalculationOp::onOrderLandCoverChanged( bool& isConfirmed )
1768 HYDROGUI_CalculationDlg* aPanel =
1769 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1773 isConfirmed = confirmLandCoverOrderChange();
1775 myEditedObject->SetToUpdate( true );
1778 void HYDROGUI_CalculationOp::onRuleChanged( bool& isConfirmed )
1780 HYDROGUI_CalculationDlg* aPanel =
1781 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1785 isConfirmed = confirmRuleChange();
1787 myEditedObject->SetToUpdate( true );
1790 void HYDROGUI_CalculationOp::onRuleLandCoverChanged( bool& isConfirmed )
1792 HYDROGUI_CalculationDlg* aPanel =
1793 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1797 isConfirmed = confirmLandCoverRuleChange();
1799 myEditedObject->SetToUpdate( true );