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>
36 #include <HYDROData_BCPolygon.h>
38 #include <OCCViewer_ViewManager.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewWindow.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_UpdateFlags.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <LightApp_DataOwner.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_DataBrowser.h>
51 #include <QApplication>
52 #include <QKeySequence>
54 #include <BRep_Builder.hxx>
56 #include <TopTools_IndexedMapOfShape.hxx>
60 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit, bool IsComplete )
61 : HYDROGUI_Operation( theModule ),
62 myIsEdit( theIsEdit ),
63 myActiveViewManager( NULL ),
64 myPreviewViewManager( NULL ),
65 myShowGeomObjects( true ),
66 myShowLandCoverMap( false ),
68 myDenyIncExcl (IsComplete)
70 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
73 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
78 void HYDROGUI_CalculationOp::startOperation()
80 HYDROGUI_Operation::startOperation();
85 HYDROGUI_CalculationDlg* aPanel =
86 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
90 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
91 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
93 foreach( aShortcut, aShortcuts )
95 if ( aShortcut->key() ==
96 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
97 SUIT_DataBrowser::RenameShortcut ) ) )
99 aShortcut->setEnabled( false );
105 QStringList anEntryList;
106 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
107 getNamesAndEntries( aSeq, aList, anEntryList );
112 //add intersection polylines
113 AddInterPolylinesToList(aList, anEntryList);
115 aPanel->setAllGeomObjects( aList, anEntryList );
120 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
121 Handle(HYDROData_PolylineXY) aPolylineObj;
122 QString aPolylineName;
123 for ( ; anIter.More(); anIter.Next() )
125 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
127 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed(false) )
129 // // Check the polyline shape
130 // TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
131 // if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
132 aPolylineName = aPolylineObj->GetName();
133 if ( !aPolylineName.isEmpty() )
135 aList.append( aPolylineName );
136 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
141 aPanel->setPolylineNames( aList, anEntryList );
143 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
145 myEditedObject.Nullify();
148 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
149 if ( !myEditedObject.IsNull() )
151 aPanel->setMode( myEditedObject->GetAssignmentMode() );
152 anObjectName = myEditedObject->GetName();
153 aPolylineObj = myEditedObject->GetBoundaryPolyline();
154 if ( aPolylineObj.IsNull() )
156 aPanel->setBoundary( QString() );
160 aPolylineName = aPolylineObj->GetName();
161 aPanel->setBoundary( aPolylineName );
164 aSeq = myEditedObject->GetGeometryObjects();
165 HYDROData_SequenceOfObjects anInterPolyList = myEditedObject->GetInterPolyObjects();
166 aSeq.Append(anInterPolyList);
168 getNamesAndEntries( aSeq, aList, anEntryList );
169 aPanel->includeGeomObjects( aList );
172 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
178 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
179 myEditedObject->SetName( anObjectName );
180 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
183 aPanel->setObjectName( anObjectName );
184 aPanel->setEditedObject( myEditedObject );
186 myIncObjAtStart.clear();
187 myIncObjAtStart = aPanel->getGeometryObjects(false);
189 setGeomObjectsVisible( true );
191 createPreview( false );
194 void HYDROGUI_CalculationOp::AddInterPolylinesToList(QStringList& theList, QStringList& theEntryList)
196 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
197 Handle(HYDROData_PolylineXY) aPolylineObj;
198 QString aPolylineName;
199 for ( ; anIter.More(); anIter.Next() )
201 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
202 if ( !aPolylineObj.IsNull())
204 aPolylineName = aPolylineObj->GetName();
205 if ( !aPolylineName.isEmpty() && !theList.contains(aPolylineName) )
207 theList.append( aPolylineName );
208 theEntryList.append(HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ));
214 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
215 QStringList& theNames, QStringList& theEntries ) const
220 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
221 for ( ; anIter.More(); anIter.Next() )
223 Handle(HYDROData_Entity) anEntity = anIter.Value();
224 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
227 theNames.append( anEntity->GetName() );
228 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
232 void HYDROGUI_CalculationOp::abortOperation()
237 HYDROGUI_Operation::abortOperation();
238 module()->getApp()->updateObjectBrowser();
241 void HYDROGUI_CalculationOp::commitOperation()
244 // Commit transaction
245 commitDocOperation();
246 HYDROGUI_Operation::commitOperation();
249 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
251 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
253 // Connect signals and slots
254 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
255 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
256 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
257 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
258 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
260 connect( aPanel, SIGNAL( addBoundaryPolygons() ), SLOT( onAddBoundaryPolygons() ) );
261 connect( aPanel, SIGNAL( removeBoundaryPolygons() ), SLOT( onRemoveBoundaryPolygons() ) );
263 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
265 connect( aPanel, SIGNAL( ruleChanged( bool& ) ), SLOT( onRuleChanged( bool& ) ) );
267 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
268 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
269 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
270 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
271 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
272 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
273 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
274 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
275 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
276 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
277 connect( aPanel, SIGNAL( objectsSelected() ),
278 SLOT( onObjectsSelected() ) );
279 connect( aPanel, SIGNAL( landCoverMapSelected( const QString & ) ),
280 SLOT( onLandCoverMapSelected( const QString & ) ) );
281 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
282 SLOT( onBoundarySelected( const QString & ) ) );
283 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
284 SLOT( onStricklerTableSelected( const QString & ) ) );
286 connect( aPanel, SIGNAL( regenerateColors() ), this,
287 SLOT( onRegenerateColors() ) );
292 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
294 bool anIsToUpdateViewer = false;
296 // Remove the old boundary from the operation viewer
297 Handle(HYDROData_PolylineXY) aPrevPolyline =
298 myEditedObject->GetBoundaryPolyline();
299 if ( !aPrevPolyline.IsNull() )
301 setObjectVisibility( aPrevPolyline, false );
302 anIsToUpdateViewer = true;
305 // Set the selected boundary polyline to the calculation case
306 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
307 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
308 myEditedObject->SetBoundaryPolyline( aNewPolyline );
310 if ( myPreviewViewManager )
312 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
315 if ( !aNewPolyline.IsNull() )
317 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
318 if ( !aCtx.IsNull() )
320 setObjectVisibility( aNewPolyline, true );
321 anIsToUpdateViewer = true;
325 if ( anIsToUpdateViewer )
326 module()->update( UF_OCCViewer );
331 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
333 bool anIsToUpdateViewer = false;
335 // Remove old presentation of land cover map from the operation viewer
336 Handle(HYDROData_LandCoverMap) aLandCoverMap = myEditedObject->GetLandCoverMap();
337 if ( !aLandCoverMap.IsNull() )
339 setObjectVisibility( aLandCoverMap, false );
340 anIsToUpdateViewer = true;
343 // Set the selected Strickler table to the calculation case
344 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
345 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
346 myEditedObject->SetStricklerTable( aNewStricklerTable );
348 if ( myPreviewViewManager )
350 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
353 if ( !aNewStricklerTable.IsNull() )
355 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
356 if ( !aCtx.IsNull() )
358 if ( !aLandCoverMap.IsNull() )
360 setObjectVisibility( aLandCoverMap, true );
361 anIsToUpdateViewer = true;
366 if ( anIsToUpdateViewer )
367 module()->update( UF_OCCViewer );
372 void HYDROGUI_CalculationOp::onObjectsSelected()
374 HYDROGUI_CalculationDlg* aPanel =
375 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
377 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
378 QMap<QString, bool> aSelectedObjsMap;
379 foreach( QString aName, aSelectedObjs )
380 aSelectedObjsMap[aName] = true;
383 // Select the appropriate geometry object shape in the viewer
384 selectionMgr()->clearSelected();
386 // Unhighlight all objects except selected
387 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
388 Handle(HYDROData_Entity) anEntity;
389 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
390 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
393 for ( ; anIter.More(); anIter.Next() )
395 anEntity = anIter.Value();
396 if ( !anEntity.IsNull() )
398 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
401 aName = anEntity->GetName();
402 isSelected = aSelectedObjsMap.contains( aName );
403 aShape->highlight( isSelected, false );
404 aShape->update( false, false );
410 aLastShape->update( true, false );
413 void HYDROGUI_CalculationOp::onLandCoverMapSelected( const QString & theObjName )
415 bool anIsToUpdateViewer = false;
417 // Remove old presentation of land cover map from the operation viewer
418 Handle(HYDROData_LandCoverMap) aPrevLandCoverMap = myEditedObject->GetLandCoverMap();
419 if ( !aPrevLandCoverMap.IsNull() )
421 setObjectVisibility( aPrevLandCoverMap, false );
422 anIsToUpdateViewer = true;
425 // Select the appropriate land cover map shape in the viewer
426 selectionMgr()->clearSelected();
428 // Set the selected land cover map to the calculation case
429 Handle(HYDROData_LandCoverMap) aNewLandCoverMap = Handle(HYDROData_LandCoverMap)::DownCast(
430 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_LAND_COVER_MAP ) );
431 myEditedObject->SetLandCoverMap( aNewLandCoverMap );
433 createPreview( true );
436 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
438 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
439 HYDROGUI_Zone* aZoneItem;
440 selectionMgr()->clearSelected();
443 // Select a region in preview
444 SUIT_DataOwnerPtrList aList( true );
445 DataObjectList aZones = aRegionItem->children();
446 for ( int i = 0; i < aZones.length(); i++ )
448 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
451 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
454 selectionMgr()->setSelected( aList );
458 // select a single zone
459 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
462 SUIT_DataOwnerPtrList aList( true );
463 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
464 selectionMgr()->setSelected( aList );
469 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
470 const QList<SUIT_DataObject*>& theZonesList )
472 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
475 QList<HYDROGUI_Zone*> aZonesList;
476 HYDROGUI_Zone* aZone;
477 // Get a list of dropped zones
478 for ( int i = 0; i < theZonesList.length(); i++ )
480 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
483 aZonesList.append( aZone );
486 if ( aZonesList.length() > 0 )
488 aRegion->addZones( aZonesList );
489 HYDROGUI_CalculationDlg* aPanel =
490 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
492 aPanel->refreshZonesBrowser();
493 createPreview( false, false, false );
498 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
500 if ( createRegion( theZonesList ) )
502 HYDROGUI_CalculationDlg* aPanel =
503 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
506 aPanel->refreshZonesBrowser();
508 createPreview( false, false, false );
512 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
514 HYDROGUI_CalculationDlg* aPanel =
515 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
518 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
521 aZone->setMergeType( theMergeType, theMergeObjectName );
522 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
525 aShape->update( true, false );
528 aPanel->refreshZonesBrowser();
532 void HYDROGUI_CalculationOp::onAddObjects()
534 HYDROGUI_CalculationDlg* aPanel =
535 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
539 // Add geometry objects selected in the module browser to the calculation case
540 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
541 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
544 QStringList anAddedList;
545 for (int i = 0; i < aSelectedList.length(); i++)
547 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
548 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
549 if ( anObject.IsNull() )
552 if ( myEditedObject->AddGeometryObject( anObject ) )
553 anAddedList.append( anObject->GetName() );
556 for (int i = 0; i < aSelectedList.length(); i++)
558 Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast(
559 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
560 if ( aPoly.IsNull() )
563 if ( myEditedObject->AddInterPoly( aPoly ) )
564 anAddedList.append( aPoly->GetName() );
567 if ( !anAddedList.isEmpty() )
569 aPanel->includeGeomObjects( anAddedList );
570 createPreview( false );
574 void HYDROGUI_CalculationOp::onRemoveObjects()
576 // Remove selected objects from the calculation case
577 HYDROGUI_CalculationDlg* aPanel =
578 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
582 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
586 QSet<QString> selMap = aSelectedList.toSet();
587 myIncObjAtStart.toVector();
588 for (int i=0;i<myIncObjAtStart.size();i++)
590 QString str = myIncObjAtStart[i]->GetName();
591 if (selMap.contains(str))
597 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
600 for (int i = 0; i < aSelectedList.length(); i++)
602 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
603 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
604 if ( anObject.IsNull() )
607 setObjectVisibility( anObject, false );
608 myEditedObject->RemoveGeometryObject( anObject );
611 for (int i = 0; i < aSelectedList.length(); i++)
613 Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast(
614 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
615 if ( aPoly.IsNull() )
618 setObjectVisibility( aPoly, false );
619 myEditedObject->RemoveInterPolyObject ( aPoly );
622 module()->update( UF_OCCViewer );
623 aPanel->excludeGeomObjects( aSelectedList );
626 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
629 // Check if the case is already modified or not
630 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
637 SUIT_MessageBox::information(module()->getApp()->desktop(),
638 tr( "REGIONS_CHANGED" ),
639 tr( "COMPLETE_OP_WILL_BE_PERFORMED" ));
643 // If not modified check if the case has already defined regions with zones
644 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
645 if ( aSeq.Length() > 0 )
647 // If there are already defined zones then ask a user to confirm zones recalculation
648 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
649 tr( "REGIONS_CHANGED" ),
650 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
651 QMessageBox::Yes | QMessageBox::No,
652 QMessageBox::No ) == QMessageBox::Yes );
656 isConfirmed = true; // No regions - no zones - nothing to recalculate
662 bool HYDROGUI_CalculationOp::confirmOrderChange() const
664 // Check if the case is already modified or not
665 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
668 // If not modified check if the case has already defined regions with zones
669 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
670 if ( aSeq.Length() > 0 )
672 // If there are already defined zones then ask a user to confirm zones recalculation
673 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
674 tr( "ORDER_CHANGED" ),
675 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
676 QMessageBox::Yes | QMessageBox::No,
677 QMessageBox::No ) == QMessageBox::Yes );
681 isConfirmed = true; // No regions - no zones - nothing to recalculate
687 bool HYDROGUI_CalculationOp::confirmRuleChange() const
689 // Check if the case is already modified or not
690 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
693 // If not modified check if the case has already defined regions with zones
694 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
695 if ( aSeq.Length() > 0 )
697 // If there are already defined zones then ask a user to confirm zones recalculation
698 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
699 tr( "RULE_CHANGED" ),
700 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
701 QMessageBox::Yes | QMessageBox::No,
702 QMessageBox::No ) == QMessageBox::Yes );
706 isConfirmed = true; // No regions - no zones - nothing to recalculate
712 bool HYDROGUI_CalculationOp::confirmModeChange() const
714 // Check if the case is already modified or not
715 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
718 // If not modified check if the case has already defined regions with zones
719 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
720 if ( aSeq.Length() > 0 )
722 // If there are already defined zones then ask a user to confirm zones recalculation
723 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
724 tr( "MODE_CHANGED" ),
725 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
726 QMessageBox::Yes | QMessageBox::No,
727 QMessageBox::No ) == QMessageBox::Yes );
731 isConfirmed = true; // No regions - no zones - nothing to recalculate
737 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
739 HYDROData_WarningType aType = theWarning.Type;
740 if ( aType == WARN_OK ) {
748 case WARN_EMPTY_REGIONS:
749 aTitle = tr( "EMPTY_REGIONS" );
750 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
753 aTitle = tr( "WARNING" );
754 aMsg = theWarning.Data;
758 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
760 QMessageBox::Yes | QMessageBox::No,
763 return ( anAnswer == QMessageBox::Yes );
766 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
767 QString& theErrorMsg,
768 QStringList& theBrowseObjectsEntries )
770 HYDROGUI_CalculationDlg* aPanel =
771 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
777 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
778 theBrowseObjectsEntries.append( anEntry );
781 // For manual mode priority rules are redundant
782 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
783 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
786 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
791 void HYDROGUI_CalculationOp::onApply()
794 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
795 if ( aWarning.Type != WARN_OK ) {
796 if ( !confirmContinueWithWarning( aWarning ) ) {
797 // Go back to the first page
798 HYDROGUI_CalculationDlg* aPanel =
799 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
801 aPanel->onFirstPage();
807 QApplication::setOverrideCursor( Qt::WaitCursor );
809 int anUpdateFlags = 0;
811 QStringList aBrowseObjectsEntries;
813 bool aResult = false;
817 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
819 catch ( Standard_Failure )
821 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
822 anErrorMsg = aFailure->GetMessageString();
830 QApplication::restoreOverrideCursor();
834 module()->update( anUpdateFlags );
836 browseObjects( aBrowseObjectsEntries );
841 QString aMsg = tr( "INPUT_VALID_DATA" );
842 if( !anErrorMsg.isEmpty() )
843 aMsg.prepend( anErrorMsg + "\n" );
844 SUIT_MessageBox::critical( module()->getApp()->desktop(),
845 tr( "INSUFFICIENT_INPUT_DATA" ),
849 #include <HYDROData_CompleteCalcCase.h>
850 void HYDROGUI_CalculationOp::onNext( const int theIndex )
854 setAvailableGroups();
856 else if( theIndex==2 )
858 setAvailableBoundaryPolygons();
860 else if( theIndex==3 )
862 // Land cover map panel
863 HYDROGUI_CalculationDlg* aPanel =
864 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
868 setLandCoverMapVisible( true );
871 QStringList anEntryList;
873 // Get all land cover map objects to fill in combo-box
874 Handle(HYDROData_LandCoverMap) aLandCoverMapObj;
875 QString aLandCoverMapName;
879 HYDROData_Iterator anIter( doc(), KIND_LAND_COVER_MAP );
880 for ( ; anIter.More(); anIter.Next() )
882 aLandCoverMapObj = Handle(HYDROData_LandCoverMap)::DownCast( anIter.Current() );
884 if ( !aLandCoverMapObj.IsNull() )
886 aLandCoverMapName = aLandCoverMapObj->GetName();
887 if ( !aLandCoverMapName.isEmpty() )
889 aList.append( aLandCoverMapName );
890 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj ) );
894 aPanel->setLandCoverMapsNames( aList, anEntryList );
895 aLandCoverMapObj = myEditedObject->GetLandCoverMap();
896 if ( !aList.isEmpty() )
898 if ( aLandCoverMapObj.IsNull() )
899 aPanel->setLandCoverMap( aList.at( 0 ), false );
901 aPanel->setLandCoverMap( aList.at( 0 ), true );
903 aPanel->setLandCoverMap( aList.at( aList.indexOf( aLandCoverMapObj->GetName() ) ), true );
906 // Get all Strickler table objects to fill in combo-box
907 Handle(HYDROData_StricklerTable) aStricklerTableObj;
908 QString aStricklerTableName;
912 anIter = HYDROData_Iterator( doc(), KIND_STRICKLER_TABLE );
913 for ( ; anIter.More(); anIter.Next() )
915 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
917 if ( !aStricklerTableObj.IsNull() )
919 aStricklerTableName = aStricklerTableObj->GetName();
920 if ( !aStricklerTableName.isEmpty() )
922 aList.append( aStricklerTableName );
923 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
927 aPanel->setStricklerTableNames( aList, anEntryList );
928 //@ASL: bool anUpdateState = myEditedObject->IsMustBeUpdated();
929 if ( !aList.isEmpty() )
930 aPanel->setStricklerTable( aList.at( 0 ), false );
931 //@ASL: myEditedObject->SetToUpdate( anUpdateState );
933 if ( !myEditedObject.IsNull() )
937 // Select the certain Strickler table object in combo-box
938 aStricklerTableObj = myEditedObject->GetStricklerTable();
939 if ( aStricklerTableObj.IsNull() )
941 aPanel->setStricklerTable( QString() );
945 aStricklerTableName = aStricklerTableObj->GetName();
946 aPanel->setStricklerTable( aStricklerTableName );
949 // Select the certain land cover map object in combo-box
950 if ( aLandCoverMapObj.IsNull() )
952 aPanel->setLandCoverMap( QString() );
956 aLandCoverMapName = aLandCoverMapObj->GetName();
957 aPanel->setLandCoverMap( aLandCoverMapName );
962 closePreview( false );
963 createPreview( true );
965 else if( theIndex==4 )
967 HYDROGUI_CalculationDlg* aPanel =
968 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
972 QApplication::setOverrideCursor( Qt::WaitCursor );
974 setGeomObjectsVisible( false );
975 setLandCoverMapVisible( false );
977 QString aNewCaseName = aPanel->getObjectName();
978 QString anOldCaseName = myEditedObject->GetName();
979 bool isNameChanged = anOldCaseName != aNewCaseName;
981 bool anIsToUpdateOb = isNameChanged;
983 // At first we must to update the case name because of
984 // automatic names generation for regions and zones
985 myEditedObject->SetName( aNewCaseName );
987 // Zones: set parameters for automatic mode
988 int aMode = aPanel->getMode();
989 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
991 // Set objects in the specified order
992 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
994 myEditedObject->RemoveGeometryObjects();
995 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
997 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
998 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
999 if ( anObject.IsNull() )
1003 myEditedObject->AddGeometryObject( anObject );
1006 // Clear priority rules
1007 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
1008 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
1010 // Set priority rules
1011 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
1012 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1013 aRule.Object2, aRule.MergeType,
1014 HYDROData_CalculationCase::DataTag_CustomRules );
1018 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1020 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
1026 QList<Handle(HYDROData_Entity)> ibcludedGeomObj = aPanel->getGeometryObjects(false);
1027 //QSet<Handle(HYDROData_Entity)> includedObjAtStartSet = myIncObjAtStart.toSet();
1028 NCollection_Sequence<Handle(HYDROData_Entity)> theNewObjects;
1029 foreach (Handle(HYDROData_Entity) obj, ibcludedGeomObj)
1031 if (!myIncObjAtStart.contains(obj))
1032 theNewObjects.Append(obj);
1035 bool is_int = false;
1036 HYDROData_CompleteCalcCase::AddObjects(doc(), myEditedObject, theNewObjects, is_int);
1038 SUIT_MessageBox::information(module()->getApp()->desktop(),
1039 tr( "COMPLETE_CASE" ),
1040 tr( "There is an intersection(s) between new objects. result will be depend on order" ));
1042 myEditedObject->ClearChanged();
1045 myEditedObject->Update();
1047 AssignDefaultZonesColors();
1049 //aPanel->setEditedObject( myEditedObject );
1050 aPanel->refreshZonesBrowser();
1052 closePreview( false );
1053 createPreview( false );
1055 anIsToUpdateOb = true;
1060 setZonesVisible( true );
1062 if ( isNameChanged ) {
1063 module()->getDataModel()->updateObjectTree( myEditedObject );
1067 QApplication::restoreOverrideCursor();
1071 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1075 setGeomObjectsVisible( true );
1077 closePreview( false );
1078 createPreview( false );
1082 setLandCoverMapVisible( true );
1084 closePreview( false );
1085 createPreview( true );
1088 setZonesVisible( false );
1090 else if( theIndex==4 )
1092 AssignDefaultZonesColors();
1094 closePreview( false );
1095 createPreview( false );
1098 setZonesVisible( true );
1102 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
1104 myShowZones = theIsVisible;
1105 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1106 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1107 HYDROData_SequenceOfObjects aZones;
1108 Handle(HYDROData_Region) aRegion;
1109 if ( myPreviewViewManager )
1111 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1113 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1114 if ( !aCtx.IsNull() )
1116 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1118 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1119 if ( !aRegion.IsNull() )
1121 aZones = aRegion->GetZones();
1122 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1123 for ( ; aZonesIter.More(); aZonesIter.Next() )
1125 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1131 module()->update( UF_OCCViewer );
1136 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1138 myShowGeomObjects = theIsVisible;
1140 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1142 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1143 for ( ; anIter.More(); anIter.Next() ) {
1144 setObjectVisibility( anIter.Value(), theIsVisible );
1148 void HYDROGUI_CalculationOp::setLandCoverMapVisible( bool theIsVisible )
1150 myShowLandCoverMap = theIsVisible;
1151 setObjectVisibility( myEditedObject->GetLandCoverMap(), theIsVisible );
1154 void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
1156 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1157 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1158 HYDROData_SequenceOfObjects aZones;
1159 Handle(HYDROData_Region) aRegion;
1160 if ( myPreviewViewManager )
1162 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1164 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1165 if ( !aCtx.IsNull() )
1167 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1169 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1170 if ( !aRegion.IsNull() )
1172 aZones = aRegion->GetZones();
1173 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1174 for ( ; aZonesIter.More(); aZonesIter.Next() )
1177 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1178 if ( !aZone.IsNull() )
1180 QColor aFillingColor = HYDROData_Tool::GenerateRandColor();
1181 while (aFillingColor == Qt::red)
1182 aFillingColor = HYDROData_Tool::GenerateRandColor();
1184 aZone->SetColor(aFillingColor);
1194 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1196 HYDROGUI_CalculationDlg* aPanel =
1197 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1201 HYDROData_ListOfRules aRules;
1202 Handle(HYDROData_Entity) anObject1, anObject2;
1203 HYDROData_PriorityType aPriority;
1204 HYDROData_Zone::MergeType aMergeType;
1205 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1206 for ( int anIndex = 0; ; anIndex++ )
1208 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1209 HYDROData_CustomRule aRule;
1210 aRule.Object1 = anObject1;
1211 aRule.Object2 = anObject2;
1212 aRule.Priority = aPriority;
1213 aRule.MergeType = aMergeType;
1221 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1222 aPanel->setRules( aRules );
1225 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList )
1227 bool aRetValue = false;
1229 QList<HYDROGUI_Zone*> aZonesList;
1230 HYDROGUI_Zone* aZone;
1231 // Get a list of dropped zones
1232 for ( int i = 0; i < theZonesList.length(); i++ )
1234 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1237 aZonesList.append( aZone );
1240 if ( aZonesList.length() > 0 )
1242 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
1249 void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap, bool fitAllFlag, bool onTopViewAndFit )
1251 LightApp_Application* anApp = module()->getApp();
1252 HYDROData_SequenceOfObjects aSeq;
1253 if ( theLandCoverMap && myShowLandCoverMap )
1255 aSeq.Append( myEditedObject->GetLandCoverMap() );
1257 else if ( !theLandCoverMap && myShowGeomObjects )
1259 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1260 HYDROData_SequenceOfObjects aSeqP = myEditedObject->GetInterPolyObjects();
1261 aSeq.Append( aSeqGO );
1262 aSeq.Append( aSeqP );
1265 Handle(HYDROData_Entity) anEntity;
1269 // Gather zones for displaying
1270 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1271 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1272 HYDROData_SequenceOfObjects aZones;
1273 Handle(HYDROData_Region) aRegion;
1274 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1276 anEntity = aRegionsIter.Value();
1277 if ( !anEntity.IsNull() )
1279 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1280 if ( !aRegion.IsNull() )
1282 aZones = aRegion->GetZones();
1283 aSeq.Append( aZones );
1289 // Get a boundary polyline if any
1290 if (Handle(HYDROData_PolylineXY) aBPoly = myEditedObject->GetBoundaryPolyline())
1291 aSeq.Append( aBPoly );
1293 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1295 if ( !myActiveViewManager )
1297 if ( aSeq.IsEmpty() )
1300 myActiveViewManager = anApp->activeViewManager();
1303 if ( !myPreviewViewManager )
1305 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1306 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1307 if ( myPreviewViewManager )
1309 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1310 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1312 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1313 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1317 if ( !myPreviewViewManager )
1320 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1322 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1323 if ( !aCtx.IsNull() )
1325 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1326 for ( ; anIter.More(); anIter.Next() )
1328 const Handle(HYDROData_Entity)& ent = anIter.Value();
1330 setObjectVisibility( ent, true );
1333 //Process the draw events for viewer
1334 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1337 int UpdateFlags = UF_OCCViewer;
1339 UpdateFlags |= UF_FitAll;
1340 module()->update( UpdateFlags );
1342 OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView();
1343 if ( onTopViewAndFit && vw )
1348 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1350 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1354 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1356 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1360 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1365 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1367 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1368 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1369 QShortcut* aShortcut;
1370 foreach( aShortcut, aShortcuts )
1372 if ( aShortcut->key() ==
1373 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1374 SUIT_DataBrowser::RenameShortcut ) ) )
1376 aShortcut->setEnabled( true );
1381 if( myPreviewViewManager )
1383 // Hide all the displayed objects in the preview view
1384 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1386 size_t aViewId = (size_t)aViewer;
1387 HYDROData_Iterator anIterator( doc() );
1388 for( ; anIterator.More(); anIterator.Next() ) {
1389 Handle(HYDROData_Entity) anObject = anIterator.Current();
1390 if( !anObject.IsNull() ) {
1391 module()->setObjectVisible( aViewId, anObject, false );
1396 if ( theRemoveViewManager )
1398 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1399 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1401 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1402 myPreviewViewManager = NULL;
1406 if( myActiveViewManager && theRemoveViewManager )
1408 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1409 myActiveViewManager = NULL;
1413 void HYDROGUI_CalculationOp::setAvailableGroups()
1415 HYDROGUI_CalculationDlg* aPanel =
1416 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1418 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1419 QStringList aList, anEntryList;
1420 getNamesAndEntries( aSeq, aList, anEntryList );
1422 QStringList aGroupsNames;
1424 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1425 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1427 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anObjs.Value( anIndex ) );
1428 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1429 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1431 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( aGIndex ) );
1432 aGroupsNames.append( aGroup->GetName() );
1435 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) ) {
1436 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1437 Handle(HYDROData_ShapesGroup) aGeomGroup =
1438 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1439 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1440 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1445 aPanel->setAvailableGroups( aGroupsNames );
1446 aPanel->includeGroups( aList );
1448 //@ASL: bool isUpdated = myEditedObject->IsMustBeUpdated();
1451 void HYDROGUI_CalculationOp::onAddGroups()
1453 HYDROGUI_CalculationDlg* aPanel =
1454 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1458 // Add geometry objects selected in the module browser to the calculation case
1459 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1460 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1463 QStringList anAddedList;
1464 for (int i = 0; i < aSelectedList.length(); i++)
1466 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1467 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1468 if ( aGroup.IsNull() )
1471 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1472 anAddedList.append( aGroup->GetName() );
1475 if ( !anAddedList.isEmpty() )
1477 aPanel->includeGroups( anAddedList );
1481 void HYDROGUI_CalculationOp::onRemoveGroups()
1483 // Remove selected objects from the calculation case
1484 HYDROGUI_CalculationDlg* aPanel =
1485 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1489 QStringList aSelectedList = aPanel->getSelectedGroups();
1490 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1493 for (int i = 0; i < aSelectedList.length(); i++)
1495 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1496 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1497 if ( aGroup.IsNull() )
1500 myEditedObject->RemoveGeometryGroup( aGroup );
1503 aPanel->excludeGroups( aSelectedList );
1507 void HYDROGUI_CalculationOp::setAvailableBoundaryPolygons()
1509 HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1511 HYDROData_Iterator anIter( doc(), KIND_BC_POLYGON );
1512 Handle(HYDROData_BCPolygon) aBCP;
1514 QVector<int> aTypes;
1515 for (;anIter.More(); anIter.Next())
1517 aBCP = Handle(HYDROData_BCPolygon)::DownCast( anIter.Current() );
1518 aNames.append(aBCP->GetName());
1519 aTypes.append(aBCP->GetBoundaryType());
1521 HYDROData_SequenceOfObjects aBCPSeq = myEditedObject->GetBoundaryPolygons();
1523 QStringList aListCut, aListIS;
1524 for (int i=1; i<=aBCPSeq.Size();i++)
1526 int type = Handle(HYDROData_BCPolygon)::DownCast(aBCPSeq(i))->GetBoundaryType();
1528 aListCut << aBCPSeq(i)->GetName();
1529 else if (type == 2 || type == 3)
1530 aListIS << aBCPSeq(i)->GetName();
1533 aPanel->setAvailableBoundaryPolygons( aNames, aTypes );
1534 aPanel->includeBoundaryPolygons( aListCut );
1535 aPanel->includeISBoundaryPolygons( aListIS );
1538 void HYDROGUI_CalculationOp::onRemoveBoundaryPolygons()
1540 HYDROGUI_CalculationDlg* aPanel =
1541 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1545 QStringList aSelectedListCut = aPanel->getSelectedBoundaryPolygons();
1546 QStringList aSelectedListIS = aPanel->getSelectedISBoundaryPolygons();
1548 if ( aSelectedListCut.isEmpty() && aSelectedListIS.isEmpty() )
1551 for (int i = 0; i < aSelectedListCut.length(); i++)
1553 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1554 HYDROGUI_Tool::FindObjectByName( module(), aSelectedListCut.at(i) ) );
1555 if ( aBCPoly.IsNull() )
1557 myEditedObject->RemoveBoundaryPolygon( aBCPoly );
1560 for (int i = 0; i < aSelectedListIS.length(); i++)
1562 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1563 HYDROGUI_Tool::FindObjectByName( module(), aSelectedListIS.at(i) ) );
1564 if ( aBCPoly.IsNull() )
1566 myEditedObject->RemoveBoundaryPolygon( aBCPoly );
1569 aPanel->excludeBoundaryPolygons( aSelectedListCut );
1570 aPanel->excludeISBoundaryPolygons( aSelectedListIS );
1574 void HYDROGUI_CalculationOp::onAddBoundaryPolygons()
1576 HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1580 QStringList aSelectedList = aPanel->getSelectedAvailableBoundaryPolygons();
1581 if ( aSelectedList.isEmpty())
1584 QStringList anAddedListCut, anAddedListIS;
1585 for (int i = 0; i < aSelectedList.length(); i++)
1587 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1588 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1589 if ( aBCPoly.IsNull() )
1592 if ( myEditedObject->AddBoundaryPolygon( aBCPoly ) )
1594 QString aName = aBCPoly->GetName();
1595 int type = aBCPoly->GetBoundaryType();
1597 anAddedListCut.append(aName);
1598 else if (type == 2 || type == 3)
1599 anAddedListIS.append(aName);
1604 if ( !anAddedListCut.isEmpty() )
1605 aPanel->includeBoundaryPolygons(anAddedListCut);
1606 if ( !anAddedListIS.isEmpty() )
1607 aPanel->includeISBoundaryPolygons(anAddedListIS);
1610 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1612 HYDROGUI_CalculationDlg* aPanel =
1613 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1617 if ( !confirmModeChange() ) {
1618 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1622 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1623 aPanel->setMode( theMode );
1626 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1628 HYDROGUI_CalculationDlg* aPanel =
1629 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1633 isConfirmed = confirmOrderChange();
1635 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1638 void HYDROGUI_CalculationOp::onRuleChanged( bool& isConfirmed )
1640 HYDROGUI_CalculationDlg* aPanel =
1641 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1645 isConfirmed = confirmRuleChange();
1647 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1650 void HYDROGUI_CalculationOp::onRegenerateColors()
1652 // For geometry zones
1653 AssignDefaultZonesColors();
1654 setZonesVisible( false );
1655 setZonesVisible( true );