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 <QPushButton>
55 #include <BRep_Builder.hxx>
57 #include <TopTools_IndexedMapOfShape.hxx>
61 #include <HYDROData_CompleteCalcCase.h>
64 #include "HYDRO_trace.hxx"
67 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit, bool IsComplete )
68 : HYDROGUI_Operation( theModule ),
69 myIsEdit( theIsEdit ),
70 myActiveViewManager( NULL ),
71 myPreviewViewManager( NULL ),
72 myShowGeomObjects( true ),
73 myShowLandCoverMap( false ),
75 myIsComplete (IsComplete)
79 aDlgName = tr( "COMPLETE_CALCULATION" );
81 aDlgName = myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" );
85 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
90 void HYDROGUI_CalculationOp::startOperation()
92 HYDROGUI_Operation::startOperation();
97 HYDROGUI_CalculationDlg* aPanel =
98 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
102 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
103 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
104 QShortcut* aShortcut;
105 foreach( aShortcut, aShortcuts )
107 if ( aShortcut->key() ==
108 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
109 SUIT_DataBrowser::RenameShortcut ) ) )
111 aShortcut->setEnabled( false );
117 QStringList anEntryList;
118 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
119 getNamesAndEntries( aSeq, aList, anEntryList );
124 //add intersection polylines
125 AddInterPolylinesToList(aList, anEntryList);
127 aPanel->setAllGeomObjects( aList, anEntryList );
132 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
133 Handle(HYDROData_PolylineXY) aPolylineObj;
134 QString aPolylineName;
135 for ( ; anIter.More(); anIter.Next() )
137 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
139 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed(false) )
141 // // Check the polyline shape
142 // TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
143 // if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
144 aPolylineName = aPolylineObj->GetName();
145 if ( !aPolylineName.isEmpty() )
147 aList.append( aPolylineName );
148 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
153 aPanel->setPolylineNames( aList, anEntryList );
155 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
157 myEditedObject.Nullify();
161 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
162 if ( !myEditedObject.IsNull() )
164 aPanel->setMode( myEditedObject->GetAssignmentMode() );
165 anObjectName = myEditedObject->GetName();
166 aPolylineObj = myEditedObject->GetBoundaryPolyline();
167 if ( aPolylineObj.IsNull() )
169 aPanel->setBoundary( QString() );
173 aPolylineName = aPolylineObj->GetName();
174 aPanel->setBoundary( aPolylineName );
177 aSeq = myEditedObject->GetGeometryObjects();
178 HYDROData_SequenceOfObjects anInterPolyList = myEditedObject->GetInterPolyObjects();
179 aSeq.Append(anInterPolyList);
181 getNamesAndEntries( aSeq, aList, anEntryList );
183 aPanel->includeGeomObjects( aList );
186 //aPanel->includeGeomObjects( aList );
187 aPanel->setAlreadyAddedGeomObjects( aList );
188 //myIncObjAtStart = aSeq;
189 aPanel->hideAvailableGeomObjects( aList );
190 aPanel->setGeomOrderingEnabled(true);
194 setRules( HYDROData_CalculationCase::DataTag_CustomRules );
200 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
201 myEditedObject->SetName( anObjectName );
202 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
205 aPanel->setObjectName( anObjectName );
206 aPanel->setEditedObject( myEditedObject );
208 setGeomObjectsVisible( true );
210 createPreview( false );
213 void HYDROGUI_CalculationOp::AddInterPolylinesToList(QStringList& theList, QStringList& theEntryList)
215 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
216 Handle(HYDROData_PolylineXY) aPolylineObj;
217 QString aPolylineName;
218 for ( ; anIter.More(); anIter.Next() )
220 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
221 if ( !aPolylineObj.IsNull())
223 aPolylineName = aPolylineObj->GetName();
224 if ( !aPolylineName.isEmpty() && !theList.contains(aPolylineName) )
226 theList.append( aPolylineName );
227 theEntryList.append(HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ));
233 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
234 QStringList& theNames, QStringList& theEntries ) const
239 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
240 for ( ; anIter.More(); anIter.Next() )
242 Handle(HYDROData_Entity) anEntity = anIter.Value();
243 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
246 theNames.append( anEntity->GetName() );
247 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
251 void HYDROGUI_CalculationOp::abortOperation()
256 HYDROGUI_Operation::abortOperation();
257 module()->getApp()->updateObjectBrowser();
260 void HYDROGUI_CalculationOp::commitOperation()
263 // Commit transaction
264 commitDocOperation();
265 HYDROGUI_Operation::commitOperation();
268 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
270 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName(), myIsComplete );
272 // Connect signals and slots
273 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
274 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
275 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
276 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
277 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
279 connect( aPanel, SIGNAL( addBoundaryPolygons() ), SLOT( onAddBoundaryPolygons() ) );
280 connect( aPanel, SIGNAL( removeBoundaryPolygons() ), SLOT( onRemoveBoundaryPolygons() ) );
282 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
284 connect( aPanel, SIGNAL( ruleChanged( bool& ) ), SLOT( onRuleChanged( bool& ) ) );
286 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
287 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones( const int ) ) );
288 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
289 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
290 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
291 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
292 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
293 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
294 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
295 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
296 connect( aPanel, SIGNAL( objectsSelected() ),
297 SLOT( onObjectsSelected() ) );
298 connect( aPanel, SIGNAL( landCoverMapSelected( const QString & ) ),
299 SLOT( onLandCoverMapSelected( const QString & ) ) );
300 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
301 SLOT( onBoundarySelected( const QString & ) ) );
302 connect( aPanel, SIGNAL( StricklerTableSelected( const QString & ) ),
303 SLOT( onStricklerTableSelected( const QString & ) ) );
305 connect( aPanel, SIGNAL( regenerateColors() ), this,
306 SLOT( onRegenerateColors() ) );
311 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
313 bool anIsToUpdateViewer = false;
315 // Remove the old boundary from the operation viewer
316 Handle(HYDROData_PolylineXY) aPrevPolyline =
317 myEditedObject->GetBoundaryPolyline();
318 if ( !aPrevPolyline.IsNull() )
320 setObjectVisibility( aPrevPolyline, false );
321 anIsToUpdateViewer = true;
324 // Set the selected boundary polyline to the calculation case
325 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
326 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
327 myEditedObject->SetBoundaryPolyline( aNewPolyline );
329 if ( myPreviewViewManager )
331 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
334 if ( !aNewPolyline.IsNull() )
336 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
337 if ( !aCtx.IsNull() )
339 setObjectVisibility( aNewPolyline, true );
340 anIsToUpdateViewer = true;
344 if ( anIsToUpdateViewer )
345 module()->update( UF_OCCViewer );
350 void HYDROGUI_CalculationOp::onStricklerTableSelected ( const QString & theObjName )
352 bool anIsToUpdateViewer = false;
354 // Remove old presentation of land cover map from the operation viewer
355 Handle(HYDROData_LandCoverMap) aLandCoverMap = myEditedObject->GetLandCoverMap();
356 if ( !aLandCoverMap.IsNull() )
358 setObjectVisibility( aLandCoverMap, false );
359 anIsToUpdateViewer = true;
362 // Set the selected Strickler table to the calculation case
363 Handle(HYDROData_StricklerTable) aNewStricklerTable = Handle(HYDROData_StricklerTable)::DownCast(
364 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_STRICKLER_TABLE ) );
365 myEditedObject->SetStricklerTable( aNewStricklerTable );
367 if ( myPreviewViewManager )
369 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
372 if ( !aNewStricklerTable.IsNull() )
374 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
375 if ( !aCtx.IsNull() )
377 if ( !aLandCoverMap.IsNull() )
379 setObjectVisibility( aLandCoverMap, true );
380 anIsToUpdateViewer = true;
385 if ( anIsToUpdateViewer )
386 module()->update( UF_OCCViewer );
391 void HYDROGUI_CalculationOp::onObjectsSelected()
393 DEBTRACE("onObjectsSelected");
394 HYDROGUI_CalculationDlg* aPanel =
395 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
397 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
398 QMap<QString, bool> aSelectedObjsMap;
399 foreach( QString aName, aSelectedObjs )
400 aSelectedObjsMap[aName] = true;
403 // Select the appropriate geometry object shape in the viewer
404 selectionMgr()->clearSelected();
406 // Unhighlight all objects except selected
407 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
408 Handle(HYDROData_Entity) anEntity;
409 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
410 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
413 for ( ; anIter.More(); anIter.Next() )
415 anEntity = anIter.Value();
416 if ( !anEntity.IsNull() )
418 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
421 aName = anEntity->GetName();
422 isSelected = aSelectedObjsMap.contains( aName );
423 aShape->highlight( isSelected, false );
424 aShape->update( false, false );
430 aLastShape->update( true, false );
433 void HYDROGUI_CalculationOp::onLandCoverMapSelected( const QString & theObjName )
435 bool anIsToUpdateViewer = false;
437 // Remove old presentation of land cover map from the operation viewer
438 Handle(HYDROData_LandCoverMap) aPrevLandCoverMap = myEditedObject->GetLandCoverMap();
439 if ( !aPrevLandCoverMap.IsNull() )
441 setObjectVisibility( aPrevLandCoverMap, false );
442 anIsToUpdateViewer = true;
445 // Select the appropriate land cover map shape in the viewer
446 selectionMgr()->clearSelected();
448 // Set the selected land cover map to the calculation case
449 Handle(HYDROData_LandCoverMap) aNewLandCoverMap = Handle(HYDROData_LandCoverMap)::DownCast(
450 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_LAND_COVER_MAP ) );
451 myEditedObject->SetLandCoverMap( aNewLandCoverMap );
453 createPreview( true );
456 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
458 DEBTRACE("onClickedInZonesBrowser");
459 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
460 HYDROGUI_Zone* aZoneItem;
461 selectionMgr()->clearSelected();
465 // Select a region in preview
466 SUIT_DataOwnerPtrList aList( true );
467 DataObjectList aZones = aRegionItem->children();
468 for ( int i = 0; i < aZones.length(); i++ )
470 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
473 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
476 selectionMgr()->setSelected( aList );
480 // select a single zone
481 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
485 SUIT_DataOwnerPtrList aList( true );
486 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
487 selectionMgr()->setSelected( aList );
492 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem,
493 const QList<SUIT_DataObject*>& theZonesList )
495 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
498 QList<HYDROGUI_Zone*> aZonesList;
499 HYDROGUI_Zone* aZone;
500 // Get a list of dropped zones
501 for ( int i = 0; i < theZonesList.length(); i++ )
503 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
506 aZonesList.append( aZone );
509 if ( aZonesList.length() > 0 )
511 aRegion->addZones( aZonesList );
512 HYDROGUI_CalculationDlg* aPanel =
513 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
515 aPanel->refreshZonesBrowser();
516 createPreview( false, false, false );
521 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
523 if ( createRegion( theZonesList ) )
525 HYDROGUI_CalculationDlg* aPanel =
526 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
529 aPanel->refreshZonesBrowser();
531 createPreview( false, false, false );
535 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theMergeObjectName )
537 HYDROGUI_CalculationDlg* aPanel =
538 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
541 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
544 aZone->setMergeType( theMergeType, theMergeObjectName );
545 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
548 aShape->update( true, false );
551 aPanel->refreshZonesBrowser();
555 void HYDROGUI_CalculationOp::onAddObjects()
557 HYDROGUI_CalculationDlg* aPanel =
558 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
562 // Add geometry objects selected in the module browser to the calculation case
563 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
564 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
567 QStringList anAddedList;
568 for (int i = 0; i < aSelectedList.length(); i++)
570 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
571 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
572 if ( anObject.IsNull() )
575 if ( myEditedObject->AddGeometryObject( anObject ) )
576 anAddedList.append( anObject->GetName() );
579 for (int i = 0; i < aSelectedList.length(); i++)
581 Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast(
582 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
583 if ( aPoly.IsNull() )
586 if ( myEditedObject->AddInterPoly( aPoly ) )
587 anAddedList.append( aPoly->GetName() );
590 if ( !anAddedList.isEmpty() )
592 aPanel->includeGeomObjects( anAddedList );
593 createPreview( false );
597 void HYDROGUI_CalculationOp::onRemoveObjects()
599 // Remove selected objects from the calculation case
600 HYDROGUI_CalculationDlg* aPanel =
601 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
605 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
609 QSet<QString> selMap = aSelectedList.toSet();
613 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
616 for (int i = 0; i < aSelectedList.length(); i++)
618 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
619 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
620 if ( anObject.IsNull() )
623 setObjectVisibility( anObject, false );
624 myEditedObject->RemoveGeometryObject( anObject );
627 for (int i = 0; i < aSelectedList.length(); i++)
629 Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast(
630 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
631 if ( aPoly.IsNull() )
634 setObjectVisibility( aPoly, false );
635 myEditedObject->RemoveInterPolyObject ( aPoly );
638 module()->update( UF_OCCViewer );
639 aPanel->excludeGeomObjects( aSelectedList );
642 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
645 // Check if the case is already modified or not
646 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
653 //SUIT_MessageBox::information(module()->getApp()->desktop(),
654 // tr( "REGIONS_CHANGED" ),
655 // tr( "COMPLETE_OP_WILL_BE_PERFORMED" ));
659 // If not modified check if the case has already defined regions with zones
660 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
661 if ( aSeq.Length() > 0 )
663 // If there are already defined zones then ask a user to confirm zones recalculation
664 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
665 tr( "REGIONS_CHANGED" ),
666 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
667 QMessageBox::Yes | QMessageBox::No,
668 QMessageBox::No ) == QMessageBox::Yes );
672 isConfirmed = true; // No regions - no zones - nothing to recalculate
678 bool HYDROGUI_CalculationOp::confirmOrderChange() const
680 // Check if the case is already modified or not
681 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
684 // If not modified check if the case has already defined regions with zones
685 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
686 if ( aSeq.Length() > 0 )
688 // If there are already defined zones then ask a user to confirm zones recalculation
689 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
690 tr( "ORDER_CHANGED" ),
691 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
692 QMessageBox::Yes | QMessageBox::No,
693 QMessageBox::No ) == QMessageBox::Yes );
697 isConfirmed = true; // No regions - no zones - nothing to recalculate
703 bool HYDROGUI_CalculationOp::confirmRuleChange() const
705 // Check if the case is already modified or not
706 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
709 // If not modified check if the case has already defined regions with zones
710 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
711 if ( aSeq.Length() > 0 )
713 // If there are already defined zones then ask a user to confirm zones recalculation
714 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
715 tr( "RULE_CHANGED" ),
716 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
717 QMessageBox::Yes | QMessageBox::No,
718 QMessageBox::No ) == QMessageBox::Yes );
722 isConfirmed = true; // No regions - no zones - nothing to recalculate
728 bool HYDROGUI_CalculationOp::confirmModeChange() const
730 // Check if the case is already modified or not
731 bool isConfirmed = myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d );
734 // If not modified check if the case has already defined regions with zones
735 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
736 if ( aSeq.Length() > 0 )
738 // If there are already defined zones then ask a user to confirm zones recalculation
739 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
740 tr( "MODE_CHANGED" ),
741 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
742 QMessageBox::Yes | QMessageBox::No,
743 QMessageBox::No ) == QMessageBox::Yes );
747 isConfirmed = true; // No regions - no zones - nothing to recalculate
753 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
755 HYDROData_WarningType aType = theWarning.Type;
756 if ( aType == WARN_OK ) {
764 case WARN_EMPTY_REGIONS:
765 aTitle = tr( "EMPTY_REGIONS" );
766 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
769 aTitle = tr( "WARNING" );
770 aMsg = theWarning.Data;
774 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
776 QMessageBox::Yes | QMessageBox::No,
779 return ( anAnswer == QMessageBox::Yes );
782 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
783 QString& theErrorMsg,
784 QStringList& theBrowseObjectsEntries )
786 HYDROGUI_CalculationDlg* aPanel =
787 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
793 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
794 theBrowseObjectsEntries.append( anEntry );
797 // For manual mode priority rules are redundant
798 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
799 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, false );
802 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
807 void HYDROGUI_CalculationOp::onApply()
810 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
811 if ( aWarning.Type != WARN_OK ) {
812 if ( !confirmContinueWithWarning( aWarning ) ) {
813 // Go back to the first page
814 HYDROGUI_CalculationDlg* aPanel =
815 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
817 aPanel->onFirstPage();
823 QApplication::setOverrideCursor( Qt::WaitCursor );
825 int anUpdateFlags = 0;
827 QStringList aBrowseObjectsEntries;
829 bool aResult = false;
833 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
835 catch ( Standard_Failure& e )
837 anErrorMsg = e.GetMessageString();
845 QApplication::restoreOverrideCursor();
849 module()->update( anUpdateFlags );
851 browseObjects( aBrowseObjectsEntries );
856 QString aMsg = tr( "INPUT_VALID_DATA" );
857 if( !anErrorMsg.isEmpty() )
858 aMsg.prepend( anErrorMsg + "\n" );
859 SUIT_MessageBox::critical( module()->getApp()->desktop(),
860 tr( "INSUFFICIENT_INPUT_DATA" ),
864 #include <HYDROData_CompleteCalcCase.h>
865 void HYDROGUI_CalculationOp::onNext( const int theIndex )
867 if( theIndex==1 && !myIsComplete)
869 setAvailableGroups();
871 else if( theIndex==2 && !myIsComplete)
873 setAvailableBoundaryPolygons();
875 else if( theIndex==3 && !myIsComplete)
877 // Land cover map panel
878 HYDROGUI_CalculationDlg* aPanel =
879 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
883 setLandCoverMapVisible( true );
886 QStringList anEntryList;
888 // Get all land cover map objects to fill in combo-box
889 Handle(HYDROData_LandCoverMap) aLandCoverMapObj;
890 QString aLandCoverMapName;
894 HYDROData_Iterator anIter( doc(), KIND_LAND_COVER_MAP );
895 for ( ; anIter.More(); anIter.Next() )
897 aLandCoverMapObj = Handle(HYDROData_LandCoverMap)::DownCast( anIter.Current() );
899 if ( !aLandCoverMapObj.IsNull() )
901 aLandCoverMapName = aLandCoverMapObj->GetName();
902 if ( !aLandCoverMapName.isEmpty() )
904 aList.append( aLandCoverMapName );
905 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aLandCoverMapObj ) );
909 aPanel->setLandCoverMapsNames( aList, anEntryList );
910 aLandCoverMapObj = myEditedObject->GetLandCoverMap();
911 if ( !aList.isEmpty() )
913 if ( aLandCoverMapObj.IsNull() )
914 aPanel->setLandCoverMap( aList.at( 0 ), false );
916 aPanel->setLandCoverMap( aList.at( 0 ), true );
918 aPanel->setLandCoverMap( aList.at( aList.indexOf( aLandCoverMapObj->GetName() ) ), true );
921 // Get all Strickler table objects to fill in combo-box
922 Handle(HYDROData_StricklerTable) aStricklerTableObj;
923 QString aStricklerTableName;
927 anIter = HYDROData_Iterator( doc(), KIND_STRICKLER_TABLE );
928 for ( ; anIter.More(); anIter.Next() )
930 aStricklerTableObj = Handle(HYDROData_StricklerTable)::DownCast( anIter.Current() );
932 if ( !aStricklerTableObj.IsNull() )
934 aStricklerTableName = aStricklerTableObj->GetName();
935 if ( !aStricklerTableName.isEmpty() )
937 aList.append( aStricklerTableName );
938 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aStricklerTableObj ) );
942 aPanel->setStricklerTableNames( aList, anEntryList );
943 //@ASL: bool anUpdateState = myEditedObject->IsMustBeUpdated();
944 if ( !aList.isEmpty() )
945 aPanel->setStricklerTable( aList.at( 0 ), false );
946 //@ASL: myEditedObject->SetToUpdate( anUpdateState );
948 if ( !myEditedObject.IsNull() )
952 // Select the certain Strickler table object in combo-box
953 aStricklerTableObj = myEditedObject->GetStricklerTable();
954 if ( aStricklerTableObj.IsNull() )
956 aPanel->setStricklerTable( QString() );
960 aStricklerTableName = aStricklerTableObj->GetName();
961 aPanel->setStricklerTable( aStricklerTableName );
964 // Select the certain land cover map object in combo-box
965 if ( aLandCoverMapObj.IsNull() )
967 aPanel->setLandCoverMap( QString() );
971 aLandCoverMapName = aLandCoverMapObj->GetName();
972 aPanel->setLandCoverMap( aLandCoverMapName );
977 closePreview( false );
978 createPreview( true );
980 else if( theIndex==4 || myIsComplete)
982 HYDROGUI_CalculationDlg* aPanel =
983 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
987 QApplication::setOverrideCursor( Qt::WaitCursor );
989 setGeomObjectsVisible( false );
990 setLandCoverMapVisible( false );
992 QString aNewCaseName = aPanel->getObjectName();
993 QString anOldCaseName = myEditedObject->GetName();
994 bool isNameChanged = anOldCaseName != aNewCaseName;
996 bool anIsToUpdateOb = isNameChanged;
998 // At first we must to update the case name because of
999 // automatic names generation for regions and zones
1000 myEditedObject->SetName( aNewCaseName );
1002 // Zones: set parameters for automatic mode
1003 int aMode = aPanel->getMode();
1004 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
1006 // Set objects in the specified order
1007 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) )
1009 myEditedObject->RemoveGeometryObjects();
1010 QStringList aGeomObjNames;
1011 if (myIsComplete) //erase objects ?
1012 aGeomObjNames << aPanel->getAlreadyAddedGeomObjects();
1013 aGeomObjNames << aPanel->getAllGeomObjects();
1014 foreach ( const QString& aName, aGeomObjNames )
1016 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
1017 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
1018 if ( anObject.IsNull() )
1022 myEditedObject->AddGeometryObject( anObject );
1027 // Clear priority rules
1028 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
1029 myEditedObject->ClearRules( HYDROData_CalculationCase::DataTag_CustomRules, true );
1031 // Set priority rules
1032 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
1033 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
1034 aRule.Object2, aRule.MergeType,
1035 HYDROData_CalculationCase::DataTag_CustomRules );
1040 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
1043 aPanel->BackButton()->setEnabled(false); //force disable; to prevent moving to the first page
1045 if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
1051 //abortDocOperation();
1052 //module()->getApp()->updateObjectBrowser();
1053 QList<Handle(HYDROData_Entity)> newGeomObj = aPanel->getGeometryObjects(false);
1054 //QSet<Handle(HYDROData_Entity)> includedObjAtStartSet = myIncObjAtStart.toSet();
1055 NCollection_Sequence<Handle(HYDROData_Entity)> theNewObjects;
1056 foreach (Handle(HYDROData_Entity) obj, newGeomObj)
1057 theNewObjects.Append(obj);
1060 bool is_int = false;
1061 bool UseOrigNamingOfNewRegions = true;
1062 NCollection_Sequence<Handle(HYDROData_Region)> theNewRegions;
1063 QSet<QString> newRegionEntries;
1064 HYDROData_CompleteCalcCase::AddObjects(doc(), myEditedObject, theNewObjects, UseOrigNamingOfNewRegions, is_int, theNewRegions);
1066 SUIT_MessageBox::information(module()->getApp()->desktop(),
1067 tr( "COMPLETE_CASE" ),
1068 tr( "COMPLETE_CASE_INTERSECTION_DETECTED" ));
1070 myEditedObject->ClearChanged();
1071 for (int k=1;k<=theNewRegions.Size();k++)
1073 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( theNewRegions(k) );
1074 newRegionEntries.insert(anEntry);
1076 AssignDefaultZonesColors(&newRegionEntries);
1080 myEditedObject->Update();
1081 AssignDefaultZonesColors(NULL);
1085 //aPanel->setEditedObject( myEditedObject );
1086 aPanel->refreshZonesBrowser();
1088 closePreview( false );
1089 createPreview( false );
1091 anIsToUpdateOb = true;
1096 setZonesVisible( true );
1098 if ( isNameChanged ) {
1099 module()->getDataModel()->updateObjectTree( myEditedObject );
1103 QApplication::restoreOverrideCursor();
1107 void HYDROGUI_CalculationOp::onHideZones( const int theIndex )
1112 // setGeomObjectsVisible( true );
1113 // // HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1114 // // QList<Handle(HYDROData_Entity)> geomObjList = aPanel->getGeometryObjects(false);
1115 // // foreach ( Handle(HYDROData_Entity) geomObj, geomObjList)
1116 // // setObjectVisibility( geomObj, true );
1118 // setZonesVisible( false );
1119 // closePreview( false );
1120 // createPreview( false );
1126 setGeomObjectsVisible( true );
1128 closePreview( false );
1129 createPreview( false );
1133 setLandCoverMapVisible( true );
1135 closePreview( false );
1136 createPreview( true );
1139 setZonesVisible( false );
1141 else if( theIndex==4 )
1143 AssignDefaultZonesColors();
1145 closePreview( false );
1146 createPreview( false );
1149 setZonesVisible( true );
1154 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
1156 myShowZones = theIsVisible;
1157 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1158 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1159 HYDROData_SequenceOfObjects aZones;
1160 Handle(HYDROData_Region) aRegion;
1161 if ( myPreviewViewManager )
1163 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1165 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1166 if ( !aCtx.IsNull() )
1168 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1170 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1171 if ( !aRegion.IsNull() )
1173 aZones = aRegion->GetZones();
1174 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1175 for ( ; aZonesIter.More(); aZonesIter.Next() )
1177 setObjectVisibility( aZonesIter.Value(), theIsVisible );
1183 module()->update( UF_OCCViewer );
1188 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
1190 myShowGeomObjects = theIsVisible;
1192 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
1194 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1195 for ( ; anIter.More(); anIter.Next() ) {
1196 setObjectVisibility( anIter.Value(), theIsVisible );
1200 void HYDROGUI_CalculationOp::setLandCoverMapVisible( bool theIsVisible )
1202 myShowLandCoverMap = theIsVisible;
1203 setObjectVisibility( myEditedObject->GetLandCoverMap(), theIsVisible );
1206 void HYDROGUI_CalculationOp::AssignDefaultZonesColors(const QSet<QString>* theRegionsEntriesToColored)
1208 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1209 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1210 HYDROData_SequenceOfObjects aZones;
1211 Handle(HYDROData_Region) aRegion;
1212 if ( myPreviewViewManager )
1214 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1216 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1217 if ( !aCtx.IsNull() )
1219 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1221 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
1222 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aRegion );
1224 if (theRegionsEntriesToColored && !theRegionsEntriesToColored->contains(anEntry))
1227 if ( !aRegion.IsNull() )
1229 aZones = aRegion->GetZones();
1230 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1231 for ( ; aZonesIter.More(); aZonesIter.Next() )
1234 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1235 if ( !aZone.IsNull() )
1237 QColor aFillingColor = HYDROData_Tool::GenerateRandColor();
1238 while (aFillingColor == Qt::red)
1239 aFillingColor = HYDROData_Tool::GenerateRandColor();
1241 aZone->SetColor(aFillingColor);
1251 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
1253 HYDROGUI_CalculationDlg* aPanel =
1254 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1258 HYDROData_ListOfRules aRules;
1259 Handle(HYDROData_Entity) anObject1, anObject2;
1260 HYDROData_PriorityType aPriority;
1261 HYDROData_Zone::MergeType aMergeType;
1262 HYDROData_CalculationCase::DataTag aDataTag = HYDROData_CalculationCase::DataTag_CustomRules;
1263 for ( int anIndex = 0; ; anIndex++ )
1265 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType, theDataTag ) ) {
1266 HYDROData_CustomRule aRule;
1267 aRule.Object1 = anObject1;
1268 aRule.Object2 = anObject2;
1269 aRule.Priority = aPriority;
1270 aRule.MergeType = aMergeType;
1278 if ( theDataTag == HYDROData_CalculationCase::DataTag_CustomRules )
1279 aPanel->setRules( aRules );
1282 bool HYDROGUI_CalculationOp::createRegion( const QList<SUIT_DataObject*>& theZonesList )
1284 bool aRetValue = false;
1286 QList<HYDROGUI_Zone*> aZonesList;
1287 HYDROGUI_Zone* aZone;
1288 // Get a list of dropped zones
1289 for ( int i = 0; i < theZonesList.length(); i++ )
1291 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
1294 aZonesList.append( aZone );
1297 if ( aZonesList.length() > 0 )
1299 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
1306 void HYDROGUI_CalculationOp::createPreview( const bool theLandCoverMap, bool fitAllFlag, bool onTopViewAndFit )
1308 DEBTRACE("createPreview " << theLandCoverMap << " " << fitAllFlag << " " << onTopViewAndFit);
1309 LightApp_Application* anApp = module()->getApp();
1310 HYDROData_SequenceOfObjects aSeq;
1311 if ( theLandCoverMap && myShowLandCoverMap )
1313 aSeq.Append( myEditedObject->GetLandCoverMap() );
1315 else if ( !theLandCoverMap && myShowGeomObjects )
1317 HYDROData_SequenceOfObjects aSeqGO = myEditedObject->GetGeometryObjects();
1318 HYDROData_SequenceOfObjects aSeqP = myEditedObject->GetInterPolyObjects();
1319 aSeq.Append( aSeqGO );
1320 aSeq.Append( aSeqP );
1323 Handle(HYDROData_Entity) anEntity;
1327 // Gather zones for displaying
1328 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
1329 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
1330 HYDROData_SequenceOfObjects aZones;
1331 Handle(HYDROData_Region) aRegion;
1332 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
1334 anEntity = aRegionsIter.Value();
1335 if ( !anEntity.IsNull() )
1337 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
1338 if ( !aRegion.IsNull() )
1340 aZones = aRegion->GetZones();
1341 aSeq.Append( aZones );
1347 // Get a boundary polyline if any
1348 if (Handle(HYDROData_PolylineXY) aBPoly = myEditedObject->GetBoundaryPolyline())
1349 aSeq.Append( aBPoly );
1351 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
1353 if ( !myActiveViewManager )
1355 if ( aSeq.IsEmpty() )
1358 myActiveViewManager = anApp->activeViewManager();
1361 if ( !myPreviewViewManager )
1363 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
1364 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
1365 DEBTRACE(" createViewManager " << myPreviewViewManager);
1366 if ( myPreviewViewManager )
1368 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1369 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1371 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
1372 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
1376 if ( !myPreviewViewManager )
1378 restoreOCCViewerSelection(myPreviewViewManager);
1380 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
1382 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
1383 if ( !aCtx.IsNull() )
1385 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
1386 for ( ; anIter.More(); anIter.Next() )
1388 const Handle(HYDROData_Entity)& ent = anIter.Value();
1390 setObjectVisibility( ent, true );
1393 //Process the draw events for viewer
1394 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
1397 int UpdateFlags = UF_OCCViewer;
1399 UpdateFlags |= UF_FitAll;
1400 module()->update( UpdateFlags );
1402 OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView();
1403 if ( onTopViewAndFit && vw )
1408 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
1410 if ( theEntity.IsNull() || !myPreviewViewManager ) {
1414 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1416 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
1420 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1425 void HYDROGUI_CalculationOp::closePreview( bool theRemoveViewManager )
1427 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1428 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1429 QShortcut* aShortcut;
1430 foreach( aShortcut, aShortcuts )
1432 if ( aShortcut->key() ==
1433 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1434 SUIT_DataBrowser::RenameShortcut ) ) )
1436 aShortcut->setEnabled( true );
1441 if( myPreviewViewManager )
1443 // Hide all the displayed objects in the preview view
1444 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1446 size_t aViewId = (size_t)aViewer;
1447 HYDROData_Iterator anIterator( doc() );
1448 for( ; anIterator.More(); anIterator.Next() ) {
1449 Handle(HYDROData_Entity) anObject = anIterator.Current();
1450 if( !anObject.IsNull() ) {
1451 module()->setObjectVisible( aViewId, anObject, false );
1456 if ( theRemoveViewManager )
1458 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1459 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1461 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1462 myPreviewViewManager = NULL;
1466 if( myActiveViewManager && theRemoveViewManager )
1468 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1469 myActiveViewManager = NULL;
1473 void HYDROGUI_CalculationOp::setAvailableGroups()
1475 HYDROGUI_CalculationDlg* aPanel =
1476 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1478 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1479 QStringList aList, anEntryList;
1480 getNamesAndEntries( aSeq, aList, anEntryList );
1482 QStringList aGroupsNames;
1484 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1485 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1487 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( anObjs.Value( anIndex ) );
1488 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1489 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1491 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( aGIndex ) );
1492 aGroupsNames.append( aGroup->GetName() );
1495 if( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) ) {
1496 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1497 Handle(HYDROData_ShapesGroup) aGeomGroup =
1498 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1499 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1500 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1505 aPanel->setAvailableGroups( aGroupsNames );
1506 aPanel->includeGroups( aList );
1508 //@ASL: bool isUpdated = myEditedObject->IsMustBeUpdated();
1511 void HYDROGUI_CalculationOp::onAddGroups()
1513 HYDROGUI_CalculationDlg* aPanel =
1514 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1518 // Add geometry objects selected in the module browser to the calculation case
1519 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1520 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1523 QStringList anAddedList;
1524 for (int i = 0; i < aSelectedList.length(); i++)
1526 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1527 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1528 if ( aGroup.IsNull() )
1531 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1532 anAddedList.append( aGroup->GetName() );
1535 if ( !anAddedList.isEmpty() )
1537 aPanel->includeGroups( anAddedList );
1541 void HYDROGUI_CalculationOp::onRemoveGroups()
1543 // Remove selected objects from the calculation case
1544 HYDROGUI_CalculationDlg* aPanel =
1545 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1549 QStringList aSelectedList = aPanel->getSelectedGroups();
1550 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1553 for (int i = 0; i < aSelectedList.length(); i++)
1555 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1556 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1557 if ( aGroup.IsNull() )
1560 myEditedObject->RemoveGeometryGroup( aGroup );
1563 aPanel->excludeGroups( aSelectedList );
1567 void HYDROGUI_CalculationOp::setAvailableBoundaryPolygons()
1569 HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1571 HYDROData_Iterator anIter( doc(), KIND_BC_POLYGON );
1572 Handle(HYDROData_BCPolygon) aBCP;
1574 QVector<int> aTypes;
1575 for (;anIter.More(); anIter.Next())
1577 aBCP = Handle(HYDROData_BCPolygon)::DownCast( anIter.Current() );
1578 aNames.append(aBCP->GetName());
1579 aTypes.append(aBCP->GetBoundaryType());
1581 HYDROData_SequenceOfObjects aBCPSeq = myEditedObject->GetBoundaryPolygons();
1583 QStringList aListCut, aListIS;
1584 for (int i=1; i<=aBCPSeq.Size();i++)
1586 int type = Handle(HYDROData_BCPolygon)::DownCast(aBCPSeq(i))->GetBoundaryType();
1588 aListCut << aBCPSeq(i)->GetName();
1589 else if (type == 2 || type == 3)
1590 aListIS << aBCPSeq(i)->GetName();
1593 aPanel->setAvailableBoundaryPolygons( aNames, aTypes );
1594 aPanel->includeBoundaryPolygons( aListCut );
1595 aPanel->includeISBoundaryPolygons( aListIS );
1598 void HYDROGUI_CalculationOp::onRemoveBoundaryPolygons()
1600 HYDROGUI_CalculationDlg* aPanel =
1601 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1605 QStringList aSelectedListCut = aPanel->getSelectedBoundaryPolygons();
1606 QStringList aSelectedListIS = aPanel->getSelectedISBoundaryPolygons();
1608 if ( aSelectedListCut.isEmpty() && aSelectedListIS.isEmpty() )
1611 for (int i = 0; i < aSelectedListCut.length(); i++)
1613 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1614 HYDROGUI_Tool::FindObjectByName( module(), aSelectedListCut.at(i) ) );
1615 if ( aBCPoly.IsNull() )
1617 myEditedObject->RemoveBoundaryPolygon( aBCPoly );
1620 for (int i = 0; i < aSelectedListIS.length(); i++)
1622 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1623 HYDROGUI_Tool::FindObjectByName( module(), aSelectedListIS.at(i) ) );
1624 if ( aBCPoly.IsNull() )
1626 myEditedObject->RemoveBoundaryPolygon( aBCPoly );
1629 aPanel->excludeBoundaryPolygons( aSelectedListCut );
1630 aPanel->excludeISBoundaryPolygons( aSelectedListIS );
1634 void HYDROGUI_CalculationOp::onAddBoundaryPolygons()
1636 HYDROGUI_CalculationDlg* aPanel = ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1640 QStringList aSelectedList = aPanel->getSelectedAvailableBoundaryPolygons();
1641 if ( aSelectedList.isEmpty())
1644 QStringList anAddedListCut, anAddedListIS;
1645 for (int i = 0; i < aSelectedList.length(); i++)
1647 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast(
1648 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1649 if ( aBCPoly.IsNull() )
1652 if ( myEditedObject->AddBoundaryPolygon( aBCPoly ) )
1654 QString aName = aBCPoly->GetName();
1655 int type = aBCPoly->GetBoundaryType();
1657 anAddedListCut.append(aName);
1658 else if (type == 2 || type == 3)
1659 anAddedListIS.append(aName);
1664 if ( !anAddedListCut.isEmpty() )
1665 aPanel->includeBoundaryPolygons(anAddedListCut);
1666 if ( !anAddedListIS.isEmpty() )
1667 aPanel->includeISBoundaryPolygons(anAddedListIS);
1670 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1672 HYDROGUI_CalculationDlg* aPanel =
1673 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1677 if ( !confirmModeChange() ) {
1678 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1682 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1683 aPanel->setMode( theMode );
1686 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1688 HYDROGUI_CalculationDlg* aPanel =
1689 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1693 isConfirmed = confirmOrderChange();
1695 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1698 void HYDROGUI_CalculationOp::onRuleChanged( bool& isConfirmed )
1700 HYDROGUI_CalculationDlg* aPanel =
1701 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1705 isConfirmed = confirmRuleChange();
1707 myEditedObject->Changed( HYDROData_Entity::Geom_2d );
1710 void HYDROGUI_CalculationOp::onRegenerateColors()
1712 // For geometry zones
1713 AssignDefaultZonesColors();
1714 setZonesVisible( false );
1715 setZonesVisible( true );