1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_CalculationOp.h"
21 #include "HYDROGUI_DataModel.h"
22 #include "HYDROGUI_CalculationDlg.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Tool.h"
25 #include "HYDROGUI_UpdateFlags.h"
26 #include "HYDROGUI_Zone.h"
27 #include "HYDROGUI_Region.h"
29 #include <HYDROData_PolylineXY.h>
30 #include <HYDROData_ShapesGroup.h>
31 #include <HYDROData_Iterator.h>
32 #include <HYDROData_ImmersibleZone.h>
33 #include <HYDROData_Object.h>
34 #include <HYDROData_Tool.h>
36 #include <OCCViewer_ViewManager.h>
37 #include <OCCViewer_ViewModel.h>
38 #include <OCCViewer_ViewWindow.h>
40 #include <LightApp_Application.h>
41 #include <LightApp_UpdateFlags.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <LightApp_DataOwner.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_DataBrowser.h>
49 #include <QApplication>
50 #include <QKeySequence>
53 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
54 : HYDROGUI_Operation( theModule ),
55 myIsEdit( theIsEdit ),
56 myActiveViewManager( NULL ),
57 myPreviewViewManager( NULL )
59 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
62 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
67 void HYDROGUI_CalculationOp::startOperation()
69 HYDROGUI_Operation::startOperation();
74 HYDROGUI_CalculationDlg* aPanel =
75 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
79 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
80 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
82 foreach( aShortcut, aShortcuts )
84 if ( aShortcut->key() ==
85 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
86 SUIT_DataBrowser::RenameShortcut ) ) )
88 aShortcut->setEnabled( false );
94 QStringList anEntryList;
95 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
96 getNamesAndEntries( aSeq, aList, anEntryList );
97 aPanel->setAllGeomObjects( aList, anEntryList );
102 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
103 Handle(HYDROData_PolylineXY) aPolylineObj;
104 QString aPolylineName;
105 for ( ; anIter.More(); anIter.Next() )
107 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
109 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
111 // Check the polyline shape
112 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
113 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
114 aPolylineName = aPolylineObj->GetName();
115 if ( !aPolylineName.isEmpty() )
117 aList.append( aPolylineName );
118 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
123 aPanel->setPolylineNames( aList, anEntryList );
125 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
127 myEditedObject.Nullify();
130 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
131 if ( !myEditedObject.IsNull() )
133 aPanel->setMode( myEditedObject->GetAssignmentMode() );
134 anObjectName = myEditedObject->GetName();
135 aPolylineObj = myEditedObject->GetBoundaryPolyline();
136 if ( aPolylineObj.IsNull() )
138 aPanel->setBoundary( QString() );
142 aPolylineName = aPolylineObj->GetName();
143 aPanel->setBoundary( aPolylineName );
146 aSeq = myEditedObject->GetGeometryObjects();
147 getNamesAndEntries( aSeq, aList, anEntryList );
148 aPanel->includeGeomObjects( aList );
151 HYDROData_ListOfRules aRules;
152 Handle(HYDROData_Object) anObject1, anObject2;
153 HYDROData_PriorityType aPriority;
154 HYDROData_Zone::MergeAltitudesType aMergeType;
155 for ( int anIndex = 0; ; anIndex++ )
157 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType ) ) {
158 HYDROData_CustomRule aRule;
159 aRule.Object1 = anObject1;
160 aRule.Object2 = anObject2;
161 aRule.Priority = aPriority;
162 aRule.MergeType = aMergeType;
169 aPanel->setRules( aRules );
175 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
176 myEditedObject->SetName( anObjectName );
177 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
180 aPanel->setObjectName( anObjectName );
181 aPanel->setEditedObject( myEditedObject );
186 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
187 QStringList& theNames, QStringList& theEntries ) const
192 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
193 for ( ; anIter.More(); anIter.Next() )
195 Handle(HYDROData_Entity) anEntity = anIter.Value();
196 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
199 theNames.append( anEntity->GetName() );
200 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
204 void HYDROGUI_CalculationOp::abortOperation()
209 HYDROGUI_Operation::abortOperation();
210 module()->getApp()->updateObjectBrowser();
213 void HYDROGUI_CalculationOp::commitOperation()
216 // Commit transaction
217 commitDocOperation();
218 HYDROGUI_Operation::commitOperation();
221 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
223 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
225 // Connect signals and slots
226 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
227 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
228 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
229 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
230 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
231 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
232 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
233 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onHideZones() ) );
234 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
235 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
236 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
237 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
238 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
239 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
240 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
241 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
242 connect( aPanel, SIGNAL( objectsSelected() ),
243 SLOT( onObjectsSelected() ) );
244 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
245 SLOT( onBoundarySelected( const QString & ) ) );
250 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
252 bool anIsToUpdateViewer = false;
254 // Remove the old boundary from the operation viewer
255 Handle(HYDROData_PolylineXY) aPrevPolyline =
256 myEditedObject->GetBoundaryPolyline();
257 if ( !aPrevPolyline.IsNull() )
259 setObjectVisibility( aPrevPolyline, false );
260 anIsToUpdateViewer = true;
263 // Set the selected boundary polyline to the calculation case
264 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
265 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
266 myEditedObject->SetBoundaryPolyline( aNewPolyline );
268 if ( myPreviewViewManager )
270 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
273 if ( !aNewPolyline.IsNull() )
275 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
276 if ( !aCtx.IsNull() )
278 setObjectVisibility( aNewPolyline, true );
279 anIsToUpdateViewer = true;
283 if ( anIsToUpdateViewer )
284 module()->update( UF_OCCViewer );
289 void HYDROGUI_CalculationOp::onObjectsSelected()
291 HYDROGUI_CalculationDlg* aPanel =
292 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
294 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
295 QMap<QString, bool> aSelectedObjsMap;
296 foreach( QString aName, aSelectedObjs )
297 aSelectedObjsMap[aName] = true;
300 // Select the appropriate geometry object shape in the viewer
301 selectionMgr()->clearSelected();
303 // Unhighlight all objects except selected
304 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
305 Handle(HYDROData_Entity) anEntity;
306 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
307 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
310 for ( ; anIter.More(); anIter.Next() )
312 anEntity = anIter.Value();
313 if ( !anEntity.IsNull() )
315 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
318 aName = anEntity->GetName();
319 isSelected = aSelectedObjsMap.contains( aName );
320 aShape->highlight( isSelected, false );
321 aShape->update( false, false );
327 aLastShape->update( true, false );
330 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
332 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
333 HYDROGUI_Zone* aZoneItem;
334 selectionMgr()->clearSelected();
337 // Select a region in preview
338 SUIT_DataOwnerPtrList aList( true );
339 DataObjectList aZones = aRegionItem->children();
340 for ( int i = 0; i < aZones.length(); i++ )
342 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
345 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
348 selectionMgr()->setSelected( aList );
352 // select a single zone
353 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
356 SUIT_DataOwnerPtrList aList( true );
357 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
358 selectionMgr()->setSelected( aList );
363 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
365 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
368 QList<HYDROGUI_Zone*> aZonesList;
369 HYDROGUI_Zone* aZone;
370 // Get a list of dropped zones
371 for ( int i = 0; i < theZonesList.length(); i++ )
373 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
376 aZonesList.append( aZone );
379 if ( aZonesList.length() > 0 )
381 aRegion->addZones( aZonesList );
382 HYDROGUI_CalculationDlg* aPanel =
383 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
386 aPanel->refreshZonesBrowser();
393 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
395 QList<HYDROGUI_Zone*> aZonesList;
396 HYDROGUI_Zone* aZone;
397 // Get a list of dropped zones
398 for ( int i = 0; i < theZonesList.length(); i++ )
400 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
403 aZonesList.append( aZone );
406 if ( aZonesList.length() > 0 )
408 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
409 HYDROGUI_CalculationDlg* aPanel =
410 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
413 aPanel->refreshZonesBrowser();
419 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
421 HYDROGUI_CalculationDlg* aPanel =
422 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
425 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
428 aZone->setMergeType( theMergeType, theAltitudeName );
429 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
432 aShape->update( true, false );
435 aPanel->refreshZonesBrowser();
439 void HYDROGUI_CalculationOp::onAddObjects()
441 HYDROGUI_CalculationDlg* aPanel =
442 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
446 // Add geometry objects selected in the module browser to the calculation case
447 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
448 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
451 QStringList anAddedList;
452 for (int i = 0; i < aSelectedList.length(); i++)
454 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
455 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
456 if ( anObject.IsNull() )
459 if ( myEditedObject->AddGeometryObject( anObject ) )
460 anAddedList.append( anObject->GetName() );
463 if ( !anAddedList.isEmpty() )
465 aPanel->includeGeomObjects( anAddedList );
470 void HYDROGUI_CalculationOp::onRemoveObjects()
472 // Remove selected objects from the calculation case
473 HYDROGUI_CalculationDlg* aPanel =
474 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
478 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
479 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
482 for (int i = 0; i < aSelectedList.length(); i++)
484 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
485 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
486 if ( anObject.IsNull() )
489 setObjectVisibility( anObject, false );
490 myEditedObject->RemoveGeometryObject( anObject );
493 module()->update( UF_OCCViewer );
494 aPanel->excludeGeomObjects( aSelectedList );
497 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
499 // Check if the case is already modified or not
500 bool isConfirmed = myEditedObject->IsMustBeUpdated();
503 // If not modified check if the case has already defined regions with zones
504 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
505 if ( aSeq.Length() > 0 )
507 // If there are already defined zones then ask a user to confirm zones recalculation
508 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
509 tr( "REGIONS_CHANGED" ),
510 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
511 QMessageBox::Yes | QMessageBox::No,
512 QMessageBox::No ) == QMessageBox::Yes );
516 isConfirmed = true; // No regions - no zones - nothing to recalculate
522 bool HYDROGUI_CalculationOp::confirmOrderChange() const
524 // Check if the case is already modified or not
525 bool isConfirmed = myEditedObject->IsMustBeUpdated();
528 // If not modified check if the case has already defined regions with zones
529 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
530 if ( aSeq.Length() > 0 )
532 // If there are already defined zones then ask a user to confirm zones recalculation
533 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
534 tr( "ORDER_CHANGED" ),
535 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
536 QMessageBox::Yes | QMessageBox::No,
537 QMessageBox::No ) == QMessageBox::Yes );
541 isConfirmed = true; // No regions - no zones - nothing to recalculate
547 bool HYDROGUI_CalculationOp::confirmModeChange() const
549 // Check if the case is already modified or not
550 bool isConfirmed = myEditedObject->IsMustBeUpdated();
553 // If not modified check if the case has already defined regions with zones
554 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
555 if ( aSeq.Length() > 0 )
557 // If there are already defined zones then ask a user to confirm zones recalculation
558 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
559 tr( "MODE_CHANGED" ),
560 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
561 QMessageBox::Yes | QMessageBox::No,
562 QMessageBox::No ) == QMessageBox::Yes );
566 isConfirmed = true; // No regions - no zones - nothing to recalculate
572 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
574 HYDROData_WarningType aType = theWarning.Type;
575 if ( aType == WARN_OK ) {
583 case WARN_EMPTY_REGIONS:
584 aTitle = tr( "EMPTY_REGIONS" );
585 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
588 aTitle = tr( "WARNING" );
589 aMsg = theWarning.Data;
593 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
595 QMessageBox::Yes | QMessageBox::No,
598 return ( anAnswer == QMessageBox::Yes );
601 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
602 QString& theErrorMsg,
603 QStringList& theBrowseObjectsEntries )
605 HYDROGUI_CalculationDlg* aPanel =
606 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
612 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
613 theBrowseObjectsEntries.append( anEntry );
616 // For manual mode priority rules are redundant
617 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
618 myEditedObject->ClearRules( false );
621 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
626 void HYDROGUI_CalculationOp::onApply()
629 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
630 if ( aWarning.Type != WARN_OK ) {
631 if ( !confirmContinueWithWarning( aWarning ) ) {
632 // Go back to the first page
633 HYDROGUI_CalculationDlg* aPanel =
634 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
636 aPanel->onFirstPage();
642 QApplication::setOverrideCursor( Qt::WaitCursor );
644 int anUpdateFlags = 0;
646 QStringList aBrowseObjectsEntries;
648 bool aResult = false;
652 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
654 catch ( Standard_Failure )
656 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
657 anErrorMsg = aFailure->GetMessageString();
665 QApplication::restoreOverrideCursor();
669 module()->update( anUpdateFlags );
671 browseObjects( aBrowseObjectsEntries );
676 QString aMsg = tr( "INPUT_VALID_DATA" );
677 if( !anErrorMsg.isEmpty() )
678 aMsg.prepend( anErrorMsg + "\n" );
679 SUIT_MessageBox::critical( module()->getApp()->desktop(),
680 tr( "INSUFFICIENT_INPUT_DATA" ),
685 void HYDROGUI_CalculationOp::onNext( const int theIndex )
689 setAvailableGroups();
691 else if( theIndex==2 )
693 HYDROGUI_CalculationDlg* aPanel =
694 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
698 QApplication::setOverrideCursor( Qt::WaitCursor );
700 QString aNewCaseName = aPanel->getObjectName();
701 QString anOldCaseName = myEditedObject->GetName();
702 bool isNameChanged = anOldCaseName != aNewCaseName;
704 bool anIsToUpdateOb = isNameChanged;
706 // At first we must to update the case name because of
707 // automatic names generation for regions and zones
708 myEditedObject->SetName( aNewCaseName );
710 // Set parameters for automatic mode
711 int aMode = aPanel->getMode();
712 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
714 // Set objects in the specified order
715 if( myEditedObject->IsMustBeUpdated() )
717 myEditedObject->RemoveGeometryObjects();
718 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
720 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
721 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
722 if ( anObject.IsNull() )
726 myEditedObject->AddGeometryObject( anObject );
729 // Clear priority rules
730 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
731 myEditedObject->ClearRules( true );
733 // Set priority rules
734 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
735 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
736 aRule.Object2, aRule.MergeType );
740 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
742 if ( myEditedObject->IsMustBeUpdated() )
745 myEditedObject->Update();
747 AssignDefaultZonesColors();
749 //aPanel->setEditedObject( myEditedObject );
750 aPanel->refreshZonesBrowser();
755 anIsToUpdateOb = true;
759 setZonesVisible( true );
761 if ( isNameChanged ) {
762 module()->getDataModel()->updateObjectTree( myEditedObject );
766 if ( anIsToUpdateOb ) {
767 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
768 if ( anObjBrowser ) {
769 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
773 QApplication::restoreOverrideCursor();
777 void HYDROGUI_CalculationOp::onHideZones()
779 setZonesVisible( false );
782 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
784 myShowZones = theIsVisible;
785 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
786 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
787 HYDROData_SequenceOfObjects aZones;
788 Handle(HYDROData_Region) aRegion;
789 if ( myPreviewViewManager )
791 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
793 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
794 if ( !aCtx.IsNull() )
796 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
798 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
799 if ( !aRegion.IsNull() )
801 aZones = aRegion->GetZones();
802 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
803 for ( ; aZonesIter.More(); aZonesIter.Next() )
805 setObjectVisibility( aZonesIter.Value(), theIsVisible );
811 module()->update( UF_OCCViewer );
816 void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
818 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
819 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
820 HYDROData_SequenceOfObjects aZones;
821 Handle(HYDROData_Region) aRegion;
822 if ( myPreviewViewManager )
824 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
826 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
827 if ( !aCtx.IsNull() )
830 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
832 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
833 if ( !aRegion.IsNull() )
835 aZones = aRegion->GetZones();
836 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
837 for ( ; aZonesIter.More(); aZonesIter.Next() )
840 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
841 if ( !aZone.IsNull() )
843 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
844 while (aFillingColor == Qt::red)
845 aFillingColor = GenerateDefaultZonesColor(++aCounter);
847 aZone->SetColor(aFillingColor);
857 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
858 float theSaturation/* = 0.5*/,
859 float theValue/* = 0.95*/ ) const
861 float aGoldenRatioConjugate = (float)(360./582.);
862 float aHue = (float)rand();
863 aHue += aGoldenRatioConjugate*theIndex;
866 float aR = 0., aG = 0., aB = 0.;
867 int aHueInt = (int)(aHue*6.);
868 float aF = aHue*6. - aHueInt;
869 float aP = theValue * (1. - theSaturation);
870 float aQ = theValue * (1. - aF*theSaturation);
871 float aT = theValue * (1. - (1. - aF) * theSaturation);
874 case 0: { aR = theValue; aG = aT; aB = aP; break; }
875 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
876 case 2: { aR = aP; aG = theValue; aB = aT; break; }
877 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
878 case 4: { aR = aT; aG = aP; aB = theValue; break; }
879 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
883 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
884 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
887 void HYDROGUI_CalculationOp::createPreview()
889 LightApp_Application* anApp = module()->getApp();
890 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
891 Handle(HYDROData_Entity) anEntity;
895 // Gather zones for displaying
896 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
897 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
898 HYDROData_SequenceOfObjects aZones;
899 Handle(HYDROData_Region) aRegion;
900 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
902 anEntity = aRegionsIter.Value();
903 if ( !anEntity.IsNull() )
905 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
906 if ( !aRegion.IsNull() )
908 aZones = aRegion->GetZones();
909 aSeq.Append( aZones );
915 // Get a boundary polyline if any
916 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
918 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
920 if ( !myActiveViewManager )
922 if ( aSeq.IsEmpty() )
925 myActiveViewManager = anApp->activeViewManager();
928 if ( !myPreviewViewManager )
930 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
931 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
932 if ( myPreviewViewManager )
934 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
935 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
937 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
938 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
942 if ( !myPreviewViewManager )
945 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
947 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
948 if ( !aCtx.IsNull() )
950 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
951 for ( ; anIter.More(); anIter.Next() )
953 setObjectVisibility( anIter.Value(), true );
956 //Process the draw events for viewer
957 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
958 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
962 module()->update( UF_OCCViewer | UF_FitAll );
966 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
968 if ( theEntity.IsNull() || !myPreviewViewManager ) {
972 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
974 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
978 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
983 void HYDROGUI_CalculationOp::closePreview()
985 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
986 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
987 QShortcut* aShortcut;
988 foreach( aShortcut, aShortcuts )
990 if ( aShortcut->key() ==
991 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
992 SUIT_DataBrowser::RenameShortcut ) ) )
994 aShortcut->setEnabled( true );
999 if( myPreviewViewManager )
1001 // Hide all the displayed objects in the preview view
1002 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1004 size_t aViewId = (size_t)aViewer;
1005 HYDROData_Iterator anIterator( doc() );
1006 for( ; anIterator.More(); anIterator.Next() ) {
1007 Handle(HYDROData_Entity) anObject = anIterator.Current();
1008 if( !anObject.IsNull() ) {
1009 module()->setObjectVisible( aViewId, anObject, false );
1014 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1015 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1017 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1018 myPreviewViewManager = NULL;
1021 if( myActiveViewManager )
1023 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1024 myActiveViewManager = NULL;
1028 void HYDROGUI_CalculationOp::setAvailableGroups()
1030 HYDROGUI_CalculationDlg* aPanel =
1031 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1033 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1034 QStringList aList, anEntryList;
1035 getNamesAndEntries( aSeq, aList, anEntryList );
1037 QStringList aGroupsNames;
1039 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1040 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1042 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1043 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1044 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1046 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1047 aGroupsNames.append( aGroup->GetName() );
1050 if( myEditedObject->IsMustBeUpdated() ) {
1051 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1052 Handle(HYDROData_ShapesGroup) aGeomGroup =
1053 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1054 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1055 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1060 aPanel->setAvailableGroups( aGroupsNames );
1061 aPanel->includeGroups( aList );
1063 bool isUpdated = myEditedObject->IsMustBeUpdated();
1066 void HYDROGUI_CalculationOp::onAddGroups()
1068 HYDROGUI_CalculationDlg* aPanel =
1069 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1073 // Add geometry objects selected in the module browser to the calculation case
1074 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1075 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1078 QStringList anAddedList;
1079 for (int i = 0; i < aSelectedList.length(); i++)
1081 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1082 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1083 if ( aGroup.IsNull() )
1086 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1087 anAddedList.append( aGroup->GetName() );
1090 if ( !anAddedList.isEmpty() )
1092 aPanel->includeGroups( anAddedList );
1096 void HYDROGUI_CalculationOp::onRemoveGroups()
1098 // Remove selected objects from the calculation case
1099 HYDROGUI_CalculationDlg* aPanel =
1100 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1104 QStringList aSelectedList = aPanel->getSelectedGroups();
1105 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1108 for (int i = 0; i < aSelectedList.length(); i++)
1110 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1111 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1112 if ( aGroup.IsNull() )
1115 myEditedObject->RemoveGeometryGroup( aGroup );
1118 aPanel->excludeGroups( aSelectedList );
1121 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1123 HYDROGUI_CalculationDlg* aPanel =
1124 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1128 if ( !confirmModeChange() ) {
1129 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1133 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1134 aPanel->setMode( theMode );
1137 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1139 HYDROGUI_CalculationDlg* aPanel =
1140 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1144 isConfirmed = confirmOrderChange();
1146 myEditedObject->SetToUpdate( true );