X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_StreamOp.cxx;h=a2072046345be71268bd07eeb74fdbcfe26457c6;hb=7f56fcbfed23a9fd09b7ab87edd7ec742e2725e6;hp=30cad0e36594e1e3ba199b467cd53f568db5bf1f;hpb=8c70d5cb1e04edf503afb50caf735fa1c4f45b25;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index 30cad0e3..a2072046 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -1,12 +1,8 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// Copyright (C) 2014-2015 EDF-R&D // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,6 +19,7 @@ #include "HYDROGUI_StreamOp.h" #include "HYDROGUI_Module.h" +#include #include "HYDROGUI_Shape.h" #include "HYDROGUI_StreamDlg.h" #include "HYDROGUI_Tool.h" @@ -36,14 +33,51 @@ #include #include +#include +#include + #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void insertProfileInToOrder( const QString& theProfileName, + const double& theProfilePar, + QStringList& theProfiles, + QList& theProfileParams ) +{ + bool anIsInserted = false; + for ( int k = 0; k < theProfileParams.length(); ++k ) + { + const double& aParam = theProfileParams.value( k ); + if ( theProfilePar < aParam ) + { + theProfiles.insert( k, theProfileName ); + theProfileParams.insert( k, theProfilePar ); + anIsInserted = true; + break; + } + } + + if ( !anIsInserted ) + { + theProfiles << theProfileName; + theProfileParams << theProfilePar; + } +} HYDROGUI_StreamOp::HYDROGUI_StreamOp( HYDROGUI_Module* theModule, bool theIsEdit ) : HYDROGUI_Operation( theModule ), myIsEdit( theIsEdit ), - myViewManager( NULL ), myPreviewPrs( NULL ) { setName( theIsEdit ? tr( "EDIT_STREAM" ) : tr( "CREATE_STREAM" ) ); @@ -58,92 +92,105 @@ void HYDROGUI_StreamOp::startOperation() { HYDROGUI_Operation::startOperation(); - // We start operation in the document - startDocOperation(); + if ( !myIsEdit || isApplyAndClose() ) + myEditedObject.Nullify(); + myHydAxis.clear(); + myProfiles.clear(); + myProfileParams.clear(); + // Get panel and reset its state HYDROGUI_StreamDlg* aPanel = (HYDROGUI_StreamDlg*)inputPanel(); - - aPanel->blockSignals( true ); - aPanel->reset(); - if( myIsEdit ) - myEditedObject = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); - else - myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) ); - - QString aSelectedAxis; - QStringList aSelectedProfiles; - QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_STREAM_NAME" ) ); - if ( myIsEdit && !myEditedObject.IsNull() ) + if ( myIsEdit ) { - anObjectName = myEditedObject->GetName(); - - Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis(); - if ( !aHydraulicAxis.IsNull() ) - aSelectedAxis = aHydraulicAxis->GetName(); - - HYDROData_SequenceOfObjects aProfiles = myEditedObject->GetProfiles(); - for ( int i = 1, n = aProfiles.Length(); i <= n; ++i ) + if ( isApplyAndClose() ) + myEditedObject = + Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if ( !myEditedObject.IsNull() ) { - Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aProfiles.Value( i ) ); - if ( aProfile.IsNull() ) - continue; - - QString aProfileName = aProfile->GetName(); - aSelectedProfiles << aProfileName; + anObjectName = myEditedObject->GetName(); + + // Hydraulic axis + Handle(HYDROData_PolylineXY) aHydraulicAxis = myEditedObject->GetHydraulicAxis(); + if ( !aHydraulicAxis.IsNull() ) + { + myHydAxis = aHydraulicAxis->GetName(); + + TopoDS_Face aPlane; + if ( HYDROData_Stream::BuildFace( aHydraulicAxis, aPlane ) ) + { + // Stream profiles + HYDROData_SequenceOfObjects aStreamProfiles = myEditedObject->GetProfiles(); + for ( int i = 1, n = aStreamProfiles.Length(); i <= n; ++i ) + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aStreamProfiles.Value( i ) ); + if ( aProfile.IsNull() ) + continue; + + QString aProfileName = aProfile->GetName(); + + Standard_Real aProfilePar = 0.0; + HYDROData_Stream::HasIntersection( aHydraulicAxis, aProfile, aPlane, aProfilePar ); + + myProfiles << aProfileName; + myProfileParams << aProfilePar; + } + } + } } } - QStringList anAxises = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ); - - // Temporary, to be removed - if ( aSelectedProfiles.isEmpty() ) - { - aSelectedProfiles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_PROFILE ); - } - + // Update the panel + // set the edited object name aPanel->setObjectName( anObjectName ); - aPanel->setAxisNames( anAxises ); - aPanel->setAxisName( aSelectedAxis ); - aPanel->setSelectedProfiles( aSelectedProfiles ); - aPanel->blockSignals( false ); + // set the existing 2D polylines names to the panel + aPanel->setAxisNames( HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINEXY ) ); - onCreatePreview(); + // synchronize the panel state with the edited object state + updatePanelData(); + + // Create preview + createPreview(); } void HYDROGUI_StreamOp::abortOperation() { erasePreview(); - abortDocOperation(); - HYDROGUI_Operation::abortOperation(); } void HYDROGUI_StreamOp::commitOperation() { erasePreview(); - HYDROGUI_Operation::commitOperation(); } HYDROGUI_InputPanel* HYDROGUI_StreamOp::createInputPanel() const { HYDROGUI_StreamDlg* aPanel = new HYDROGUI_StreamDlg( module(), getName() ); - connect( aPanel, SIGNAL( CreatePreview() ), this, SLOT( onCreatePreview() ) ); + + connect( aPanel, SIGNAL( AddProfiles() ), this, SLOT( onAddProfiles() ) ); + connect( aPanel, SIGNAL( RemoveProfiles( const QStringList& ) ), + this, SLOT( onRemoveProfiles( const QStringList& ) ) ); + connect( aPanel, SIGNAL( AxisChanged( const QString& ) ), + this, SLOT( onAxisChanged( const QString& ) ) ); + return aPanel; } bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, - QString& theErrorMsg ) + QString& theErrorMsg, + QStringList& theBrowseObjectsEntries ) { HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); if ( !aPanel ) return false; + // Check whether the object name is not empty QString anObjectName = aPanel->getObjectName().simplified(); if ( anObjectName.isEmpty() ) { @@ -151,9 +198,9 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, return false; } - if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) + // Check that there are no other objects with the same name in the document + if ( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) { - // check that there are no other objects with the same name in the document Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); if( !anObject.IsNull() ) { @@ -162,86 +209,349 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, } } - if ( myEditedObject.IsNull() ) + if ( myEditedObject.IsNull() ) // Create new data model object + myEditedObject = Handle(HYDROData_Stream)::DownCast( doc()->CreateObject( KIND_STREAM ) ); + + // Check if the axis is set + Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) ); + if ( aHydAxis.IsNull() ) + { + theErrorMsg = tr( "AXIS_NOT_DEFINED" ); return false; + } + // Check if at least 2 profiles is set + HYDROData_SequenceOfObjects aRefProfiles; + for ( int i = 0; i < myProfiles.length(); ++i ) + { + QString aProfileName = myProfiles.value( i ); + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + if ( !aProfile.IsNull() ) + aRefProfiles.Append( aProfile ); + } + + if ( aRefProfiles.Length() < 2 ) + { + theErrorMsg = tr( "PROFILES_NOT_DEFINED" ); + return false; + } + + // Set the object name myEditedObject->SetName( anObjectName ); + myEditedObject->SetHydraulicAxis( aHydAxis ); + myEditedObject->SetProfiles( aRefProfiles, false ); + + if ( myEditedObject->IsMustBeUpdated( HYDROData_Entity::Geom_2d ) ) + myEditedObject->Update(); + + if ( !myIsEdit ) + { + myEditedObject->SetFillingColor( myEditedObject->DefaultFillingColor() ); + myEditedObject->SetBorderColor( myEditedObject->DefaultBorderColor() ); + } + + // Erase preview erasePreview(); - if( !myIsEdit ) + // Show the object in case of creation mode of the operation + if( !myIsEdit ) { module()->setObjectVisible( HYDROGUI_Tool::GetActiveOCCViewId( module() ), myEditedObject, true ); + QString anEntry = HYDROGUI_DataObject::dataObjectEntry( myEditedObject ); + theBrowseObjectsEntries.append( anEntry ); + } + + module()->setIsToUpdate( myEditedObject ); - theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; + // Set update flags + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; return true; } -void HYDROGUI_StreamOp::onCreatePreview() +void HYDROGUI_StreamOp::createPreview() { - HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel ) + LightApp_Application* anApp = module()->getApp(); + if ( !getPreviewManager() ) + { + setPreviewManager( ::qobject_cast( + anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) ); + } + + OCCViewer_ViewManager* aViewManager = getPreviewManager(); + if ( aViewManager && !myPreviewPrs ) + { + if ( OCCViewer_Viewer* aViewer = aViewManager->getOCCViewer() ) + { + Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); + if ( !aCtx.IsNull() ) + { + myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() ); + + QColor aFillingColor = Qt::green; + QColor aBorderColor = Qt::transparent; + if ( !myEditedObject.IsNull() ) + { + aFillingColor = myEditedObject->GetFillingColor(); + aBorderColor = myEditedObject->GetBorderColor(); + } + + myPreviewPrs->setFillingColor( aFillingColor, false, false ); + myPreviewPrs->setBorderColor( aBorderColor, false, false ); + } + } + } + + if ( !aViewManager || !myPreviewPrs ) return; - QString anAxisName = aPanel->getAxisName(); - QStringList aProfiles = aPanel->getSelectedProfiles(); - if ( anAxisName.isEmpty() || aProfiles.isEmpty() ) + Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) ); + + HYDROData_SequenceOfObjects aRefProfiles; + for ( int i = 0; i < myProfiles.length(); ++i ) + { + QString aProfileName = myProfiles.value( i ); + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + if ( !aProfile.IsNull() ) + aRefProfiles.Append( aProfile ); + } + + HYDROData_Stream::PrsDefinition aPrsDef; + if ( !HYDROData_Stream::CreatePresentations( aHydAxis, aRefProfiles, aPrsDef ) ) { erasePreview(); return; } - if ( myEditedObject.IsNull() ) + myPreviewPrs->setShape( aPrsDef.myPrs2D ); +} + +void HYDROGUI_StreamOp::erasePreview() +{ + if( myPreviewPrs ) + { + delete myPreviewPrs; + myPreviewPrs = 0; + } +} + +void HYDROGUI_StreamOp::onAddProfiles() +{ + Handle(HYDROData_PolylineXY) aHydAxis = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), myHydAxis, KIND_POLYLINEXY ) ); + if ( aHydAxis.IsNull() ) + return; + + TopoDS_Face aPlane; + if ( !HYDROData_Stream::BuildFace( aHydAxis, aPlane ) ) return; - // At first we remove all references from stream - myEditedObject->RemoveProfiles(); + // Get the current profiles list + QStringList aCurrentProfiles = myProfiles; + + // Get the selected profiles ( in the Object Browser ) + QStringList anInvalidProfiles; + QStringList anExistingProfiles; + QStringList aHasNoIntersectionProfiles; + QStringList aVerifiedProfiles; - Handle(HYDROData_PolylineXY) anAxis = Handle(HYDROData_PolylineXY)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), anAxisName, KIND_POLYLINEXY ) ); - myEditedObject->SetHydraulicAxis( anAxis ); + HYDROData_SequenceOfObjects aSelectedProfiles = HYDROGUI_Tool::GetSelectedObjects( module() ); - HYDROData_SequenceOfObjects aProfileObjects = - HYDROGUI_Tool::FindObjectsByNames( module(), aProfiles, KIND_PROFILE ); - for ( int i = 1, n = aProfileObjects.Length(); i <= n; ++i ) + for( int i = 1, n = aSelectedProfiles.Length(); i <= n; i++ ) { Handle(HYDROData_Profile) aProfile = - Handle(HYDROData_Profile)::DownCast( aProfileObjects.Value( i ) ); + Handle(HYDROData_Profile)::DownCast( aSelectedProfiles.Value( i ) ); if ( aProfile.IsNull() ) continue; - myEditedObject->AddProfile( aProfile ); + QString aProfileName = aProfile->GetName(); + Standard_Real aProfilePar = 0.0; + + // Check the profile, if all is ok - add it to the list + if ( !aProfile->IsValid() ) + { + // check whether the profile is valid + anInvalidProfiles << aProfileName; + } + else if ( aCurrentProfiles.contains( aProfileName ) ) + { + // check whether the profile is already added + anExistingProfiles << aProfileName; + } + else if ( !HYDROData_Stream::HasIntersection( aHydAxis, aProfile, aPlane, aProfilePar ) ) + { + // check whether the profile has intersection + aHasNoIntersectionProfiles << aProfileName; + } + else + { + // Insert profile in correct place + insertProfileInToOrder( aProfileName, aProfilePar, myProfiles, myProfileParams ); + aVerifiedProfiles << aProfileName; + } + } + + // Show message box with the ignored profiles + if ( !anInvalidProfiles.isEmpty() || + !anExistingProfiles.isEmpty() || + !aHasNoIntersectionProfiles.isEmpty() ) + { + QString aMessage = tr( "IGNORED_PROFILES" ); + if ( !anInvalidProfiles.isEmpty() ) + { + aMessage.append( "\n\n" ); + aMessage.append( tr("INVALID_PROFILES").arg( anInvalidProfiles.join( "\n" ) ) ); + } + if ( !anExistingProfiles.isEmpty() ) + { + aMessage.append( "\n\n" ); + aMessage.append( tr("EXISTING_PROFILES").arg( anExistingProfiles.join( "\n" ) ) ); + } + if ( !aHasNoIntersectionProfiles.isEmpty() ) + { + aMessage.append( "\n\n" ); + aMessage.append( tr("NOT_INTERSECTED_PROFILES").arg( aHasNoIntersectionProfiles.join( "\n" ) ) ); + } + + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "WARNING" ), aMessage ); } + + if ( aVerifiedProfiles.isEmpty() ) + return; + + // Update the panel + updatePanelData(); + + // Update preview + createPreview(); +} + +void HYDROGUI_StreamOp::onRemoveProfiles( const QStringList& theProfilesToRemove ) +{ + QStringList aToRemove = theProfilesToRemove; - myEditedObject->Update(); + aToRemove.removeDuplicates(); + if ( aToRemove.isEmpty() ) + return; + bool isRemoved = false; - LightApp_Application* anApp = module()->getApp(); - if ( !myViewManager ) - myViewManager = ::qobject_cast( - anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ); + // Remove profiles + for ( int i = 0; i < aToRemove.length(); ++i ) + { + const QString& aProfileName = aToRemove.value( i ); - if ( myViewManager && !myPreviewPrs ) + int aProfileId = myProfiles.indexOf( aProfileName ); + if ( aProfileId < 0 ) + continue; + + myProfiles.removeAt( aProfileId ); + myProfileParams.removeAt( aProfileId ); + isRemoved = true; + } + + if ( isRemoved ) { - if ( OCCViewer_Viewer* aViewer = myViewManager->getOCCViewer() ) + // Update the panel + updatePanelData(); + + // Update preview + createPreview(); + } +} + +void HYDROGUI_StreamOp::onAxisChanged( const QString& theNewAxis ) +{ + // Get axis object + Handle(HYDROData_PolylineXY) aNewAxis = Handle(HYDROData_PolylineXY)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), theNewAxis, KIND_POLYLINEXY ) ); + + // Prepare data for intersection check + TopoDS_Face aPlane; + if ( !HYDROData_Stream::BuildFace( aNewAxis, aPlane ) ) + { + SUIT_MessageBox::critical( module()->getApp()->desktop(), + tr( "BAD_SELECTED_POLYLINE_TLT" ), + tr( "BAD_SELECTED_POLYLINE_MSG" ).arg( theNewAxis ) ); + // To restore the old axis + updatePanelData(); + return; + } + + QStringList aNewProfiles; + QList aNewProfileParams; + QStringList aHasNoIntersectionProfiles; + + // Get list of profiles which do not intersect the axis + for ( int i = 0; i < myProfiles.length(); ++i ) + { + QString aProfileName = myProfiles.value( i ); + + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) ); + if ( aProfile.IsNull() ) + continue; + + Standard_Real aProfilePar = 0.0; + if ( HYDROData_Stream::HasIntersection( aNewAxis, aProfile, aPlane, aProfilePar ) ) { - Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext(); - if ( !aCtx.IsNull() ) - myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject ); + // Insert profile in correct place + insertProfileInToOrder( aProfileName, aProfilePar, aNewProfiles, aNewProfileParams ); + } + else + { + aHasNoIntersectionProfiles << aProfile->GetName(); } } - if ( !myViewManager || !myPreviewPrs ) - return; + // If there are profiles which don't intersect the new axis - show confirmation message box + bool isConfirmed = true; + if ( !aHasNoIntersectionProfiles.isEmpty() ) + { + SUIT_MessageBox::StandardButtons aButtons = + SUIT_MessageBox::Yes | SUIT_MessageBox::No; + + QString aMsg = aHasNoIntersectionProfiles.join( "\n" ); + isConfirmed = SUIT_MessageBox::question( module()->getApp()->desktop(), + tr( "CONFIRMATION" ), + tr( "CONFIRM_AXIS_CHANGE" ).arg( aMsg ), + aButtons, + SUIT_MessageBox::Yes) == SUIT_MessageBox::Yes; + } - myPreviewPrs->update(); + // Check if the user has confirmed axis change + if ( !isConfirmed ) + { + // To restore the old axis + updatePanelData(); + } + else + { + // Update data + myHydAxis = theNewAxis; + myProfiles = aNewProfiles; + myProfileParams = aNewProfileParams; + + // Update the panel + updatePanelData(); + + // Update preview + createPreview(); + } } -void HYDROGUI_StreamOp::erasePreview() +void HYDROGUI_StreamOp::updatePanelData() { - if( myPreviewPrs ) - { - delete myPreviewPrs; - myPreviewPrs = 0; - } + HYDROGUI_StreamDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + + aPanel->setAxisName( myHydAxis ); + aPanel->setProfiles( myProfiles ); }