#include "HYDROGUI_Tool.h"
#include "HYDROGUI_UpdateFlags.h"
+#include <HYDROData_Polyline.h>
+#include <HYDROData_Iterator.h>
+#include <HYDROData_ImmersibleZone.h>
+
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewModel.h>
+#include <OCCViewer_ViewWindow.h>
+
#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
+
+#include <QApplication>
+
HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
: HYDROGUI_Operation( theModule ),
- myIsEdit( theIsEdit )
+ myIsEdit( theIsEdit ),
+ myActiveViewManager( NULL ),
+ myPreviewViewManager( NULL )
{
setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
}
HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
{
+ closePreview();
}
void HYDROGUI_CalculationOp::startOperation()
{
HYDROGUI_Operation::startOperation();
+
+ // Begin transaction
+ startDocOperation();
HYDROGUI_CalculationDlg* aPanel =
::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
if ( !aPanel )
return;
+ myRegionsList.clear();
aPanel->reset();
QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
+ QStringList aSelectedObjects;
+
myEditedObject.Nullify();
if ( myIsEdit )
{
- myEditedObject = Handle(HYDROData_Calculation)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+ myEditedObject = Handle(HYDROData_CalculationCase)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
if ( !myEditedObject.IsNull() )
+ {
anObjectName = myEditedObject->GetName();
+
+ HYDROData_SequenceOfObjects aRefObjects = myEditedObject->GetGeometryObjects();
+ HYDROData_SequenceOfObjects::Iterator anIter( aRefObjects );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Object) aRefbject =
+ Handle(HYDROData_Object)::DownCast( anIter.Value() );
+ if ( aRefbject.IsNull() )
+ continue;
+
+ QString aRefObjectName = aRefbject->GetName();
+ if ( aRefObjectName.isEmpty() )
+ continue;
+
+ aSelectedObjects.append( aRefObjectName );
+ }
+ }
+ }
+ else
+ {
+ myEditedObject =
+ Handle(HYDROData_CalculationCase)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
+ myEditedObject->SetName(anObjectName);
}
aPanel->setObjectName( anObjectName );
+ aPanel->setEditedObject( myEditedObject );
+ aPanel->setSelectedGeomObjects( aSelectedObjects );
+
+ createPreview();
}
void HYDROGUI_CalculationOp::abortOperation()
{
+ closePreview();
+ // Abort transaction
+ abortDocOperation();
HYDROGUI_Operation::abortOperation();
}
void HYDROGUI_CalculationOp::commitOperation()
{
+ closePreview();
+ // Commit transaction
+ commitDocOperation();
HYDROGUI_Operation::commitOperation();
}
HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
{
HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
+
+ // Connect signals and slots
+
return aPanel;
}
if ( !aPanel )
return false;
- QString anObjectName = aPanel->getObjectName().simplified();
- if ( anObjectName.isEmpty() )
+ //QString anObjectName = aPanel->getObjectName().simplified();
+ //if ( anObjectName.isEmpty() )
+ //{
+ // theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
+ // return false;
+ //}
+
+ //// check that there are no other objects with the same name in the document
+ //if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) )
+ //{
+ // Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
+ // if ( !anObject.IsNull() )
+ // {
+ // theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
+ // return false;
+ // }
+ //}
+
+ //Handle(HYDROData_Document) aDocument = doc();
+
+ //Handle(HYDROData_CalculationCase) aCalculObj = myIsEdit ? myEditedObject :
+ // Handle(HYDROData_CalculationCase)::DownCast( aDocument->CreateObject( KIND_CALCULATION ) );
+ //if ( aCalculObj.IsNull() )
+ // return false;
+
+ //aCalculObj->SetName( anObjectName );
+
+ //QStringList aRefObjectNames = aPanel->getSelectedGeomObjects();
+ //HYDROData_SequenceOfObjects aGeomObjects =
+ // HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames );
+
+ theUpdateFlags = UF_Model;
+
+ return true;
+}
+
+void HYDROGUI_CalculationOp::onApply()
+{
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ int anUpdateFlags = 0;
+ QString anErrorMsg;
+
+ bool aResult = false;
+
+ try
{
- theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
- return false;
+ aResult = processApply( anUpdateFlags, anErrorMsg );
}
+ catch ( Standard_Failure )
+ {
+ Handle(Standard_Failure) aFailure = Standard_Failure::Caught();
+ anErrorMsg = aFailure->GetMessageString();
+ aResult = false;
+ }
+ catch ( ... )
+ {
+ aResult = false;
+ }
+
+ QApplication::restoreOverrideCursor();
- // check that there are no other objects with the same name in the document
- Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
- if ( !anObject.IsNull() )
+ if ( aResult )
{
- theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
- return false;
+ module()->update( anUpdateFlags );
+ commit();
+ }
+ else
+ {
+ abort();
+ QString aMsg = tr( "INPUT_VALID_DATA" );
+ if( !anErrorMsg.isEmpty() )
+ aMsg.prepend( anErrorMsg + "\n" );
+ SUIT_MessageBox::critical( module()->getApp()->desktop(),
+ tr( "INSUFFICIENT_INPUT_DATA" ),
+ aMsg );
}
+}
- Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
- Handle(HYDROData_Calculation)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
- if ( aCalculObj.IsNull() )
- return false;
+void HYDROGUI_CalculationOp::onSplitZones()
+{
+ myRegionsList.clear();
- aCalculObj->SetName( anObjectName );
+ HYDROGUI_CalculationDlg* aPanel =
+ ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
+ if ( !aPanel )
+ return;
- theUpdateFlags = UF_Model;
+ QApplication::setOverrideCursor( Qt::WaitCursor );
- return true;
+ QStringList aGeomObjectNames = aPanel->getSelectedGeomObjects();
+ HYDROData_SequenceOfObjects aGeomObjects =
+ HYDROGUI_Tool::FindObjectsByNames( module(), aGeomObjectNames );
+
+ QStringList aResSplittedZones;
+
+ HYDROData_SplitToZonesTool::SplitDataList aSplittedZones =
+ HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects );
+
+ QStringList aUsedNames;
+
+ HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplittedZones );
+ while( anIter.hasNext() )
+ {
+ Region aRegion;
+ aRegion.SplitData = anIter.next();
+
+ aRegion.FillingColor = HYDROGUI_Tool::GenerateFillingColor( module(), aRegion.SplitData.ObjectNames );
+ aRegion.BorderColor = QColor( HYDROData_ImmersibleZone::DefaultBorderColor() );
+
+ aRegion.RegionName = HYDROGUI_Tool::GenerateObjectName( module(), "Region", aUsedNames );
+
+ aUsedNames.append( aRegion.RegionName );
+
+ aResSplittedZones.append( aRegion.RegionName );
+
+ myRegionsList.append( aRegion );
+ }
+
+ createPreview();
+
+ QApplication::restoreOverrideCursor();
+}
+
+void HYDROGUI_CalculationOp::createPreview()
+{
+ LightApp_Application* anApp = module()->getApp();
+
+ if ( !myActiveViewManager )
+ {
+ if ( myRegionsList.isEmpty() )
+ return;
+
+ myActiveViewManager = anApp->activeViewManager();
+ }
+
+ if ( !myPreviewViewManager )
+ {
+ myPreviewViewManager = ::qobject_cast<OCCViewer_ViewManager*>(
+ anApp->createViewManager( OCCViewer_Viewer::Type() ) );
+ if ( myPreviewViewManager )
+ {
+ connect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+ this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
+
+ module()->setViewManagerRole( myPreviewViewManager, HYDROGUI_Module::VMR_PreviewCaseZones );
+ myPreviewViewManager->setTitle( tr( "PREVIEW_CASE_ZONES" ) );
+ }
+ }
+
+ if ( !myPreviewViewManager )
+ return;
+
+ if ( OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer() )
+ {
+ Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
+ if ( !aCtx.IsNull() )
+ {
+ RegionsList::iterator anIter = myRegionsList.begin();
+ for ( ; anIter != myRegionsList.end(); ++anIter )
+ {
+ Region& aRegion = *anIter;
+ if ( aRegion.Shape )
+ {
+ aRegion.Shape->erase( false );
+ delete aRegion.Shape;
+ }
+
+ aRegion.Shape = new HYDROGUI_Shape( aCtx, NULL );
+
+ aRegion.Shape->setFillingColor( aRegion.FillingColor, false, false );
+ aRegion.Shape->setBorderColor( aRegion.BorderColor, false, false );
+ aRegion.Shape->setFace( aRegion.SplitData.Face(), true, false );
+ }
+
+ //Process the draw events for viewer
+ QApplication::processEvents();
+ if ( OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView() )
+ vw->onTopView();
+ }
+ }
+}
+
+void HYDROGUI_CalculationOp::onLastViewClosed( SUIT_ViewManager* theViewManager )
+{
+ closePreview();
+}
+
+void HYDROGUI_CalculationOp::closePreview()
+{
+ RegionsList::iterator anIter= myRegionsList.begin();
+ for ( ; anIter != myRegionsList.end(); ++anIter )
+ {
+ Region& aRegion = *anIter;
+ if ( aRegion.Shape )
+ {
+ aRegion.Shape->erase( false );
+ delete aRegion.Shape;
+ aRegion.Shape = NULL;
+ }
+ }
+
+ if( myPreviewViewManager )
+ {
+ disconnect( myPreviewViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+ this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
+
+ module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
+ myPreviewViewManager = NULL;
+ }
+
+ if( myActiveViewManager )
+ {
+ HYDROGUI_Tool::SetActiveViewManager( module(), myActiveViewManager );
+ myActiveViewManager = NULL;
+ }
}