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 ),
58 myShowGeomObjects( true ),
61 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
64 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
69 void HYDROGUI_CalculationOp::startOperation()
71 HYDROGUI_Operation::startOperation();
76 HYDROGUI_CalculationDlg* aPanel =
77 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
81 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
82 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
84 foreach( aShortcut, aShortcuts )
86 if ( aShortcut->key() ==
87 QKeySequence(((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
88 SUIT_DataBrowser::RenameShortcut ) ) )
90 aShortcut->setEnabled( false );
96 QStringList anEntryList;
97 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetGeometryObjects( module() );
98 getNamesAndEntries( aSeq, aList, anEntryList );
99 aPanel->setAllGeomObjects( aList, anEntryList );
104 HYDROData_Iterator anIter( doc(), KIND_POLYLINEXY );
105 Handle(HYDROData_PolylineXY) aPolylineObj;
106 QString aPolylineName;
107 for ( ; anIter.More(); anIter.Next() )
109 aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anIter.Current() );
111 if ( !aPolylineObj.IsNull() && aPolylineObj->IsClosed() )
113 // Check the polyline shape
114 TopoDS_Shape aPolylineShape = aPolylineObj->GetShape();
115 if ( !aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE ) {
116 aPolylineName = aPolylineObj->GetName();
117 if ( !aPolylineName.isEmpty() )
119 aList.append( aPolylineName );
120 anEntryList.append( HYDROGUI_DataObject::dataObjectEntry( aPolylineObj ) );
125 aPanel->setPolylineNames( aList, anEntryList );
127 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CALCULATION_CASE_NAME" ) );
129 myEditedObject.Nullify();
132 myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
133 if ( !myEditedObject.IsNull() )
135 aPanel->setMode( myEditedObject->GetAssignmentMode() );
136 anObjectName = myEditedObject->GetName();
137 aPolylineObj = myEditedObject->GetBoundaryPolyline();
138 if ( aPolylineObj.IsNull() )
140 aPanel->setBoundary( QString() );
144 aPolylineName = aPolylineObj->GetName();
145 aPanel->setBoundary( aPolylineName );
148 aSeq = myEditedObject->GetGeometryObjects();
149 getNamesAndEntries( aSeq, aList, anEntryList );
150 aPanel->includeGeomObjects( aList );
153 HYDROData_ListOfRules aRules;
154 Handle(HYDROData_Object) anObject1, anObject2;
155 HYDROData_PriorityType aPriority;
156 HYDROData_Zone::MergeAltitudesType aMergeType;
157 for ( int anIndex = 0; ; anIndex++ )
159 if ( myEditedObject->GetRule( anIndex, anObject1, aPriority, anObject2, aMergeType ) ) {
160 HYDROData_CustomRule aRule;
161 aRule.Object1 = anObject1;
162 aRule.Object2 = anObject2;
163 aRule.Priority = aPriority;
164 aRule.MergeType = aMergeType;
171 aPanel->setRules( aRules );
177 Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
178 myEditedObject->SetName( anObjectName );
179 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)aPanel->getMode() );
182 aPanel->setObjectName( anObjectName );
183 aPanel->setEditedObject( myEditedObject );
188 void HYDROGUI_CalculationOp::getNamesAndEntries( const HYDROData_SequenceOfObjects& theSeq,
189 QStringList& theNames, QStringList& theEntries ) const
194 HYDROData_SequenceOfObjects::Iterator anIter( theSeq );
195 for ( ; anIter.More(); anIter.Next() )
197 Handle(HYDROData_Entity) anEntity = anIter.Value();
198 //if ( !HYDROData_Tool::IsGeometryObject( anEntity ) )
201 theNames.append( anEntity->GetName() );
202 theEntries.append( HYDROGUI_DataObject::dataObjectEntry( anEntity ) );
206 void HYDROGUI_CalculationOp::abortOperation()
211 HYDROGUI_Operation::abortOperation();
212 module()->getApp()->updateObjectBrowser();
215 void HYDROGUI_CalculationOp::commitOperation()
218 // Commit transaction
219 commitDocOperation();
220 HYDROGUI_Operation::commitOperation();
223 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
225 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
227 // Connect signals and slots
228 connect( aPanel, SIGNAL( changeMode( int ) ), SLOT( onChangeMode( int ) ) );
229 connect( aPanel, SIGNAL( addObjects() ), SLOT( onAddObjects() ) );
230 connect( aPanel, SIGNAL( removeObjects() ), SLOT( onRemoveObjects() ) );
231 connect( aPanel, SIGNAL( addGroups() ), SLOT( onAddGroups() ) );
232 connect( aPanel, SIGNAL( removeGroups() ), SLOT( onRemoveGroups() ) );
233 connect( aPanel, SIGNAL( orderChanged( bool& ) ), SLOT( onOrderChanged( bool& ) ) );
234 connect( aPanel, SIGNAL( Next( const int ) ), SLOT( onNext( const int ) ) );
235 connect( aPanel, SIGNAL( Back( const int ) ), SLOT( onBack( const int ) ) );
236 //connect( aPanel, SIGNAL( clicked( SUIT_DataObject* ) ), SLOT( onSelected( SUIT_DataObject* ) ) );
237 connect( aPanel, SIGNAL( setMergeType( int, QString& ) ), SLOT( onSetMergeType( int, QString& ) ) );
238 connect( aPanel, SIGNAL( moveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ),
239 SLOT( onMoveZones( SUIT_DataObject*, const QList<SUIT_DataObject*>& ) ) );
240 connect( aPanel, SIGNAL( createRegion( const QList<SUIT_DataObject*>& ) ),
241 SLOT( onCreateRegion( const QList<SUIT_DataObject*>& ) ) );
242 connect( aPanel, SIGNAL( clickedInZonesBrowser( SUIT_DataObject* ) ),
243 SLOT( onClickedInZonesBrowser( SUIT_DataObject* ) ) );
244 connect( aPanel, SIGNAL( objectsSelected() ),
245 SLOT( onObjectsSelected() ) );
246 connect( aPanel, SIGNAL( boundarySelected( const QString & ) ),
247 SLOT( onBoundarySelected( const QString & ) ) );
252 void HYDROGUI_CalculationOp::onBoundarySelected ( const QString & theObjName )
254 bool anIsToUpdateViewer = false;
256 // Remove the old boundary from the operation viewer
257 Handle(HYDROData_PolylineXY) aPrevPolyline =
258 myEditedObject->GetBoundaryPolyline();
259 if ( !aPrevPolyline.IsNull() )
261 setObjectVisibility( aPrevPolyline, false );
262 anIsToUpdateViewer = true;
265 // Set the selected boundary polyline to the calculation case
266 Handle(HYDROData_PolylineXY) aNewPolyline = Handle(HYDROData_PolylineXY)::DownCast(
267 HYDROGUI_Tool::FindObjectByName( module(), theObjName, KIND_POLYLINEXY ) );
268 myEditedObject->SetBoundaryPolyline( aNewPolyline );
270 if ( myPreviewViewManager )
272 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
275 if ( !aNewPolyline.IsNull() )
277 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
278 if ( !aCtx.IsNull() )
280 setObjectVisibility( aNewPolyline, true );
281 anIsToUpdateViewer = true;
285 if ( anIsToUpdateViewer )
286 module()->update( UF_OCCViewer );
291 void HYDROGUI_CalculationOp::onObjectsSelected()
293 HYDROGUI_CalculationDlg* aPanel =
294 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
296 QStringList aSelectedObjs = aPanel->getSelectedGeomObjects();
297 QMap<QString, bool> aSelectedObjsMap;
298 foreach( QString aName, aSelectedObjs )
299 aSelectedObjsMap[aName] = true;
302 // Select the appropriate geometry object shape in the viewer
303 selectionMgr()->clearSelected();
305 // Unhighlight all objects except selected
306 HYDROGUI_Shape* aShape = 0, *aLastShape = 0;
307 Handle(HYDROData_Entity) anEntity;
308 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
309 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
312 for ( ; anIter.More(); anIter.Next() )
314 anEntity = anIter.Value();
315 if ( !anEntity.IsNull() )
317 aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, anEntity );
320 aName = anEntity->GetName();
321 isSelected = aSelectedObjsMap.contains( aName );
322 aShape->highlight( isSelected, false );
323 aShape->update( false, false );
329 aLastShape->update( true, false );
332 void HYDROGUI_CalculationOp::onClickedInZonesBrowser( SUIT_DataObject* theItem )
334 HYDROGUI_Region* aRegionItem = dynamic_cast<HYDROGUI_Region*>(theItem);
335 HYDROGUI_Zone* aZoneItem;
336 selectionMgr()->clearSelected();
339 // Select a region in preview
340 SUIT_DataOwnerPtrList aList( true );
341 DataObjectList aZones = aRegionItem->children();
342 for ( int i = 0; i < aZones.length(); i++ )
344 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(aZones.at(i));
347 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
350 selectionMgr()->setSelected( aList );
354 // select a single zone
355 aZoneItem = dynamic_cast<HYDROGUI_Zone*>(theItem);
358 SUIT_DataOwnerPtrList aList( true );
359 aList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( aZoneItem->entry() ) ) );
360 selectionMgr()->setSelected( aList );
365 void HYDROGUI_CalculationOp::onMoveZones( SUIT_DataObject* theRegionItem, const QList<SUIT_DataObject*>& theZonesList )
367 HYDROGUI_Region* aRegion = dynamic_cast<HYDROGUI_Region*>(theRegionItem);
370 QList<HYDROGUI_Zone*> aZonesList;
371 HYDROGUI_Zone* aZone;
372 // Get a list of dropped zones
373 for ( int i = 0; i < theZonesList.length(); i++ )
375 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
378 aZonesList.append( aZone );
381 if ( aZonesList.length() > 0 )
383 aRegion->addZones( aZonesList );
384 HYDROGUI_CalculationDlg* aPanel =
385 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
388 aPanel->refreshZonesBrowser();
395 void HYDROGUI_CalculationOp::onCreateRegion( const QList<SUIT_DataObject*>& theZonesList )
397 QList<HYDROGUI_Zone*> aZonesList;
398 HYDROGUI_Zone* aZone;
399 // Get a list of dropped zones
400 for ( int i = 0; i < theZonesList.length(); i++ )
402 aZone = dynamic_cast<HYDROGUI_Zone*>( theZonesList.at( i ) );
405 aZonesList.append( aZone );
408 if ( aZonesList.length() > 0 )
410 module()->getDataModel()->createNewRegion( myEditedObject, aZonesList );
411 HYDROGUI_CalculationDlg* aPanel =
412 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
415 aPanel->refreshZonesBrowser();
421 void HYDROGUI_CalculationOp::onSetMergeType( int theMergeType, QString& theAltitudeName )
423 HYDROGUI_CalculationDlg* aPanel =
424 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
427 HYDROGUI_Zone* aZone = aPanel->getCurrentZone();
430 aZone->setMergeType( theMergeType, theAltitudeName );
431 HYDROGUI_Shape* aShape = module()->getObjectShape( HYDROGUI_Module::VMR_PreviewCaseZones, aZone->modelObject() );
434 aShape->update( true, false );
437 aPanel->refreshZonesBrowser();
441 void HYDROGUI_CalculationOp::onAddObjects()
443 HYDROGUI_CalculationDlg* aPanel =
444 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
448 // Add geometry objects selected in the module browser to the calculation case
449 QStringList aSelectedList = aPanel->getSelectedAvailableGeomObjects();
450 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
453 QStringList anAddedList;
454 for (int i = 0; i < aSelectedList.length(); i++)
456 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
457 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
458 if ( anObject.IsNull() )
461 if ( myEditedObject->AddGeometryObject( anObject ) )
462 anAddedList.append( anObject->GetName() );
465 if ( !anAddedList.isEmpty() )
467 aPanel->includeGeomObjects( anAddedList );
472 void HYDROGUI_CalculationOp::onRemoveObjects()
474 // Remove selected objects from the calculation case
475 HYDROGUI_CalculationDlg* aPanel =
476 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
480 QStringList aSelectedList = aPanel->getSelectedGeomObjects();
481 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
484 for (int i = 0; i < aSelectedList.length(); i++)
486 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
487 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
488 if ( anObject.IsNull() )
491 setObjectVisibility( anObject, false );
492 myEditedObject->RemoveGeometryObject( anObject );
495 module()->update( UF_OCCViewer );
496 aPanel->excludeGeomObjects( aSelectedList );
499 bool HYDROGUI_CalculationOp::confirmRegionsChange() const
501 // Check if the case is already modified or not
502 bool isConfirmed = myEditedObject->IsMustBeUpdated();
505 // If not modified check if the case has already defined regions with zones
506 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
507 if ( aSeq.Length() > 0 )
509 // If there are already defined zones then ask a user to confirm zones recalculation
510 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
511 tr( "REGIONS_CHANGED" ),
512 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
513 QMessageBox::Yes | QMessageBox::No,
514 QMessageBox::No ) == QMessageBox::Yes );
518 isConfirmed = true; // No regions - no zones - nothing to recalculate
524 bool HYDROGUI_CalculationOp::confirmOrderChange() const
526 // Check if the case is already modified or not
527 bool isConfirmed = myEditedObject->IsMustBeUpdated();
530 // If not modified check if the case has already defined regions with zones
531 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
532 if ( aSeq.Length() > 0 )
534 // If there are already defined zones then ask a user to confirm zones recalculation
535 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
536 tr( "ORDER_CHANGED" ),
537 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_REGIONS" ),
538 QMessageBox::Yes | QMessageBox::No,
539 QMessageBox::No ) == QMessageBox::Yes );
543 isConfirmed = true; // No regions - no zones - nothing to recalculate
549 bool HYDROGUI_CalculationOp::confirmModeChange() const
551 // Check if the case is already modified or not
552 bool isConfirmed = myEditedObject->IsMustBeUpdated();
555 // If not modified check if the case has already defined regions with zones
556 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetRegions();
557 if ( aSeq.Length() > 0 )
559 // If there are already defined zones then ask a user to confirm zones recalculation
560 isConfirmed = ( SUIT_MessageBox::question( module()->getApp()->desktop(),
561 tr( "MODE_CHANGED" ),
562 tr( "CONFIRM_SPLITTING_ZONES_RECALCULATION_MODE" ),
563 QMessageBox::Yes | QMessageBox::No,
564 QMessageBox::No ) == QMessageBox::Yes );
568 isConfirmed = true; // No regions - no zones - nothing to recalculate
574 bool HYDROGUI_CalculationOp::confirmContinueWithWarning( const HYDROData_Warning& theWarning ) const
576 HYDROData_WarningType aType = theWarning.Type;
577 if ( aType == WARN_OK ) {
585 case WARN_EMPTY_REGIONS:
586 aTitle = tr( "EMPTY_REGIONS" );
587 aMsg = tr( "CONFIRM_CONTINUE_WITH_OBJECTS_NOT_INCLUDED_TO_REGION" ).arg( theWarning.Data );
590 aTitle = tr( "WARNING" );
591 aMsg = theWarning.Data;
595 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
597 QMessageBox::Yes | QMessageBox::No,
600 return ( anAnswer == QMessageBox::Yes );
603 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
604 QString& theErrorMsg,
605 QStringList& theBrowseObjectsEntries )
607 HYDROGUI_CalculationDlg* aPanel =
608 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
614 QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject );
615 theBrowseObjectsEntries.append( anEntry );
618 // For manual mode priority rules are redundant
619 if ( aPanel->getMode() == HYDROData_CalculationCase::MANUAL ) {
620 myEditedObject->ClearRules( false );
623 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer | UF_VTK_Forced | UF_VTK_Init;
628 void HYDROGUI_CalculationOp::onApply()
631 HYDROData_Warning aWarning = myEditedObject->GetLastWarning();
632 if ( aWarning.Type != WARN_OK ) {
633 if ( !confirmContinueWithWarning( aWarning ) ) {
634 // Go back to the first page
635 HYDROGUI_CalculationDlg* aPanel =
636 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
638 aPanel->onFirstPage();
644 QApplication::setOverrideCursor( Qt::WaitCursor );
646 int anUpdateFlags = 0;
648 QStringList aBrowseObjectsEntries;
650 bool aResult = false;
654 aResult = processApply( anUpdateFlags, anErrorMsg, aBrowseObjectsEntries );
656 catch ( Standard_Failure )
658 Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
659 anErrorMsg = aFailure->GetMessageString();
667 QApplication::restoreOverrideCursor();
671 module()->update( anUpdateFlags );
673 browseObjects( aBrowseObjectsEntries );
678 QString aMsg = tr( "INPUT_VALID_DATA" );
679 if( !anErrorMsg.isEmpty() )
680 aMsg.prepend( anErrorMsg + "\n" );
681 SUIT_MessageBox::critical( module()->getApp()->desktop(),
682 tr( "INSUFFICIENT_INPUT_DATA" ),
687 void HYDROGUI_CalculationOp::onNext( const int theIndex )
691 setAvailableGroups();
693 else if( theIndex==2 )
695 HYDROGUI_CalculationDlg* aPanel =
696 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
700 QApplication::setOverrideCursor( Qt::WaitCursor );
702 setGeomObjectsVisible( false );
704 QString aNewCaseName = aPanel->getObjectName();
705 QString anOldCaseName = myEditedObject->GetName();
706 bool isNameChanged = anOldCaseName != aNewCaseName;
708 bool anIsToUpdateOb = isNameChanged;
710 // At first we must to update the case name because of
711 // automatic names generation for regions and zones
712 myEditedObject->SetName( aNewCaseName );
714 // Set parameters for automatic mode
715 int aMode = aPanel->getMode();
716 if ( aMode == HYDROData_CalculationCase::AUTOMATIC )
718 // Set objects in the specified order
719 if( myEditedObject->IsMustBeUpdated() )
721 myEditedObject->RemoveGeometryObjects();
722 foreach ( const QString& aName, aPanel->getAllGeomObjects() )
724 Handle(HYDROData_Object) anObject = Handle(HYDROData_Object)::DownCast(
725 HYDROGUI_Tool::FindObjectByName( module(), aName ) );
726 if ( anObject.IsNull() )
730 myEditedObject->AddGeometryObject( anObject );
733 // Clear priority rules
734 //@ASL if ( myEditedObject->GetRulesCount() > 0 ) {
735 myEditedObject->ClearRules( true );
737 // Set priority rules
738 foreach ( const HYDROData_CustomRule& aRule, aPanel->getRules() ) {
739 myEditedObject->AddRule( aRule.Object1, aRule.Priority,
740 aRule.Object2, aRule.MergeType );
744 aPanel->setEditZonesEnabled( aMode == HYDROData_CalculationCase::MANUAL );
746 if ( myEditedObject->IsMustBeUpdated() )
749 myEditedObject->Update();
751 AssignDefaultZonesColors();
753 //aPanel->setEditedObject( myEditedObject );
754 aPanel->refreshZonesBrowser();
759 anIsToUpdateOb = true;
763 setZonesVisible( true );
765 if ( isNameChanged ) {
766 module()->getDataModel()->updateObjectTree( myEditedObject );
770 if ( anIsToUpdateOb ) {
771 SUIT_DataBrowser* anObjBrowser = ((LightApp_Application*)module()->application())->objectBrowser();
772 if ( anObjBrowser ) {
773 anObjBrowser->updateTree( module()->getDataModel()->getDataObject( myEditedObject ), false );
777 QApplication::restoreOverrideCursor();
781 void HYDROGUI_CalculationOp::onBack( const int theIndex )
783 setGeomObjectsVisible( theIndex != 2 );
784 setZonesVisible( false );
787 void HYDROGUI_CalculationOp::setZonesVisible( bool theIsVisible )
789 myShowZones = theIsVisible;
790 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
791 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
792 HYDROData_SequenceOfObjects aZones;
793 Handle(HYDROData_Region) aRegion;
794 if ( myPreviewViewManager )
796 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
798 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
799 if ( !aCtx.IsNull() )
801 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
803 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
804 if ( !aRegion.IsNull() )
806 aZones = aRegion->GetZones();
807 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
808 for ( ; aZonesIter.More(); aZonesIter.Next() )
810 setObjectVisibility( aZonesIter.Value(), theIsVisible );
816 module()->update( UF_OCCViewer );
821 void HYDROGUI_CalculationOp::setGeomObjectsVisible( bool theIsVisible )
823 myShowGeomObjects = theIsVisible;
825 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryObjects();
827 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
828 for ( ; anIter.More(); anIter.Next() ) {
829 setObjectVisibility( anIter.Value(), theIsVisible );
833 void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
835 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
836 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
837 HYDROData_SequenceOfObjects aZones;
838 Handle(HYDROData_Region) aRegion;
839 if ( myPreviewViewManager )
841 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
843 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
844 if ( !aCtx.IsNull() )
847 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
849 aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
850 if ( !aRegion.IsNull() )
852 aZones = aRegion->GetZones();
853 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
854 for ( ; aZonesIter.More(); aZonesIter.Next() )
857 Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
858 if ( !aZone.IsNull() )
860 QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
861 while (aFillingColor == Qt::red)
862 aFillingColor = GenerateDefaultZonesColor(++aCounter);
864 aZone->SetColor(aFillingColor);
874 QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
875 float theSaturation/* = 0.5*/,
876 float theValue/* = 0.95*/ ) const
878 float aGoldenRatioConjugate = (float)(360./582.);
879 float aHue = (float)rand();
880 aHue += aGoldenRatioConjugate*theIndex;
883 float aR = 0., aG = 0., aB = 0.;
884 int aHueInt = (int)(aHue*6.);
885 float aF = aHue*6. - aHueInt;
886 float aP = theValue * (1. - theSaturation);
887 float aQ = theValue * (1. - aF*theSaturation);
888 float aT = theValue * (1. - (1. - aF) * theSaturation);
891 case 0: { aR = theValue; aG = aT; aB = aP; break; }
892 case 1: { aR = aQ; aG = theValue; aB = aP; break; }
893 case 2: { aR = aP; aG = theValue; aB = aT; break; }
894 case 3: { aR = aP; aG = aQ; aB = theValue; break; }
895 case 4: { aR = aT; aG = aP; aB = theValue; break; }
896 case 5: { aR = theValue; aG = aP; aB = aQ; break; }
900 QColor aColor = QColor( (int)(aR*256.), (int)(aG*256.), (int)(aB*256.) );
901 return ( aColor.isValid() ? aColor : HYDROData_ImmersibleZone::DefaultFillingColor() );
904 void HYDROGUI_CalculationOp::createPreview()
906 LightApp_Application* anApp = module()->getApp();
907 HYDROData_SequenceOfObjects aSeq;
908 if ( myShowGeomObjects ) {
909 aSeq.Append( myEditedObject->GetGeometryObjects() );
911 Handle(HYDROData_Entity) anEntity;
915 // Gather zones for displaying
916 HYDROData_SequenceOfObjects aRegions = myEditedObject->GetRegions();
917 HYDROData_SequenceOfObjects::Iterator aRegionsIter( aRegions );
918 HYDROData_SequenceOfObjects aZones;
919 Handle(HYDROData_Region) aRegion;
920 for ( ; aRegionsIter.More(); aRegionsIter.Next() )
922 anEntity = aRegionsIter.Value();
923 if ( !anEntity.IsNull() )
925 aRegion = Handle(HYDROData_Region)::DownCast( anEntity );
926 if ( !aRegion.IsNull() )
928 aZones = aRegion->GetZones();
929 aSeq.Append( aZones );
935 // Get a boundary polyline if any
936 aSeq.Append( myEditedObject->GetBoundaryPolyline() );
938 module()->removeViewShapes( HYDROGUI_Module::VMR_PreviewCaseZones );
940 if ( !myActiveViewManager )
942 if ( aSeq.IsEmpty() )
945 myActiveViewManager = anApp->activeViewManager();
948 if ( !myPreviewViewManager )
950 myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
951 anApp->createViewManager( OCCViewer_Viewer::Type() ) );
952 if ( myPreviewViewManager )
954 connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
955 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
957 module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
958 myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
962 if ( !myPreviewViewManager )
965 if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
967 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
968 if ( !aCtx.IsNull() )
970 HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
971 for ( ; anIter.More(); anIter.Next() )
973 setObjectVisibility( anIter.Value(), true );
976 //Process the draw events for viewer
977 QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
978 if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
982 module()->update( UF_OCCViewer | UF_FitAll );
986 void HYDROGUI_CalculationOp::setObjectVisibility( Handle(HYDROData_Entity) theEntity, const bool theIsVisible )
988 if ( theEntity.IsNull() || !myPreviewViewManager ) {
992 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
994 module()->setObjectVisible( (size_t)aViewer, theEntity, theIsVisible );
998 void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
1003 void HYDROGUI_CalculationOp::closePreview()
1005 SUIT_DataBrowser* aOb = ((LightApp_Application*)module()->application())->objectBrowser();
1006 QList<QShortcut*> aShortcuts = aOb->findChildren<QShortcut*>();
1007 QShortcut* aShortcut;
1008 foreach( aShortcut, aShortcuts )
1010 if ( aShortcut->key() ==
1011 QKeySequence( ((LightApp_Application*)module()->application())->objectBrowser()->shortcutKey(
1012 SUIT_DataBrowser::RenameShortcut ) ) )
1014 aShortcut->setEnabled( true );
1019 if( myPreviewViewManager )
1021 // Hide all the displayed objects in the preview view
1022 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
1024 size_t aViewId = (size_t)aViewer;
1025 HYDROData_Iterator anIterator( doc() );
1026 for( ; anIterator.More(); anIterator.Next() ) {
1027 Handle(HYDROData_Entity) anObject = anIterator.Current();
1028 if( !anObject.IsNull() ) {
1029 module()->setObjectVisible( aViewId, anObject, false );
1034 disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
1035 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
1037 module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
1038 myPreviewViewManager = NULL;
1041 if( myActiveViewManager )
1043 HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
1044 myActiveViewManager = NULL;
1048 void HYDROGUI_CalculationOp::setAvailableGroups()
1050 HYDROGUI_CalculationDlg* aPanel =
1051 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1053 HYDROData_SequenceOfObjects aSeq = myEditedObject->GetGeometryGroups();
1054 QStringList aList, anEntryList;
1055 getNamesAndEntries( aSeq, aList, anEntryList );
1057 QStringList aGroupsNames;
1059 HYDROData_SequenceOfObjects anObjs = myEditedObject->GetGeometryObjects();
1060 for( int anIndex = 1, aLength = anObjs.Length(); anIndex <= aLength; anIndex++ )
1062 Handle_HYDROData_Object anObj = Handle_HYDROData_Object::DownCast( anObjs.Value( anIndex ) );
1063 HYDROData_SequenceOfObjects aGroups = anObj->GetGroups();
1064 for( int aGIndex = 1, aGLength = aGroups.Length(); aGIndex <= aGLength; aGIndex++ )
1066 Handle_HYDROData_ShapesGroup aGroup = Handle_HYDROData_ShapesGroup::DownCast( aGroups.Value( aGIndex ) );
1067 aGroupsNames.append( aGroup->GetName() );
1070 if( myEditedObject->IsMustBeUpdated() ) {
1071 for( int anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) {
1072 Handle(HYDROData_ShapesGroup) aGeomGroup =
1073 Handle(HYDROData_ShapesGroup)::DownCast( aSeq.Value( anIndex ) );
1074 if ( !aGeomGroup.IsNull() && !aGroupsNames.contains( aGeomGroup->GetName() ) ) {
1075 myEditedObject->RemoveGeometryGroup( aGeomGroup );
1080 aPanel->setAvailableGroups( aGroupsNames );
1081 aPanel->includeGroups( aList );
1083 bool isUpdated = myEditedObject->IsMustBeUpdated();
1086 void HYDROGUI_CalculationOp::onAddGroups()
1088 HYDROGUI_CalculationDlg* aPanel =
1089 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1093 // Add geometry objects selected in the module browser to the calculation case
1094 QStringList aSelectedList = aPanel->getSelectedAvailableGroups();
1095 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1098 QStringList anAddedList;
1099 for (int i = 0; i < aSelectedList.length(); i++)
1101 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1102 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at( i ) ) );
1103 if ( aGroup.IsNull() )
1106 if ( myEditedObject->AddGeometryGroup( aGroup ) )
1107 anAddedList.append( aGroup->GetName() );
1110 if ( !anAddedList.isEmpty() )
1112 aPanel->includeGroups( anAddedList );
1116 void HYDROGUI_CalculationOp::onRemoveGroups()
1118 // Remove selected objects from the calculation case
1119 HYDROGUI_CalculationDlg* aPanel =
1120 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1124 QStringList aSelectedList = aPanel->getSelectedGroups();
1125 if ( aSelectedList.isEmpty() || !confirmRegionsChange() )
1128 for (int i = 0; i < aSelectedList.length(); i++)
1130 Handle(HYDROData_ShapesGroup) aGroup = Handle(HYDROData_ShapesGroup)::DownCast(
1131 HYDROGUI_Tool::FindObjectByName( module(), aSelectedList.at(i) ) );
1132 if ( aGroup.IsNull() )
1135 myEditedObject->RemoveGeometryGroup( aGroup );
1138 aPanel->excludeGroups( aSelectedList );
1141 void HYDROGUI_CalculationOp::onChangeMode( int theMode )
1143 HYDROGUI_CalculationDlg* aPanel =
1144 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1148 if ( !confirmModeChange() ) {
1149 aPanel->setMode( myEditedObject->GetAssignmentMode() );
1153 myEditedObject->SetAssignmentMode( (HYDROData_CalculationCase::AssignmentMode)theMode );
1154 aPanel->setMode( theMode );
1157 void HYDROGUI_CalculationOp::onOrderChanged( bool& isConfirmed )
1159 HYDROGUI_CalculationDlg* aPanel =
1160 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
1164 isConfirmed = confirmOrderChange();
1166 myEditedObject->SetToUpdate( true );