X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ProfileInterpolateOp.cxx;h=3bfb229203d426a8ee7b993b66ac36ad8f7fd463;hb=a53349567d67f4df0ef737798a25c24d9dc8f08e;hp=6578a86de6d1468a74934aba827c7b1dedf75508;hpb=a7828fda5a124d2019a6682b4394781ee7292edd;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx b/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx index 6578a86d..3bfb2292 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileInterpolateOp.cxx @@ -1,8 +1,4 @@ -// Copyright (C) 2007-2015 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 @@ -30,19 +26,31 @@ #include #include +#include +#include +#include +#include +#include +#include #include #include #include #include -#include +#include #include +#include #include #include #include +#include +#include + +#include + HYDROGUI_ProfileInterpolateOp::HYDROGUI_ProfileInterpolateOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) { @@ -57,71 +65,44 @@ void HYDROGUI_ProfileInterpolateOp::startOperation() { HYDROGUI_Operation::startOperation(); - HYDROGUI_ProfileInterpolateDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( aPanel ) + if ( isApplyAndClose() ) { + HYDROGUI_ProfileInterpolateDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( aPanel ) + { aPanel->reset(); aPanel->setInterpolators( interpolators() ); + } } +} -/* - if( myIsEdit ) - myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); - - QString aProfileName; - if( !myEditedObject.IsNull() ) +void HYDROGUI_ProfileInterpolateOp::abortOperation() +{ + if ( !myPreview.IsNull() ) { - Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false ); - if ( !aProfileUZ.IsNull() ) + HYDROGUI_ProfileInterpolateDlg* aDlg = new HYDROGUI_ProfileInterpolateDlg( module(), getName() ); + if ( aDlg && !aDlg->getAISContext().IsNull() ) { - CurveCreator::Coordinates aCurveCoords; - CurveCreator::SectionsMap aSectionsMap; - - HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints(); - CurveCreator::PosPointsList aPoints; - for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k ) - { - const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k ); - aCurveCoords.clear(); - aCurveCoords.push_back( aSectPoint.X() ); - aCurveCoords.push_back( aSectPoint.Y() ); - - CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords ); - aPoints.push_back( aPosPoint ); - } - - aSectionsMap[0] = aPoints; - myProfile->addPointsInternal( aSectionsMap ); - - HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 ); - - CurveCreator::SectionType aCurveType = CurveCreator::Polyline; - if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE ) - aCurveType = CurveCreator::Spline; - - myProfile->setSectionType( 0, aCurveType ); + aDlg->getAISContext()->Remove( myPreview, false ); + myPreview.Nullify(); } - - aProfileName = myEditedObject->GetName(); } - else - { - aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) ); - } - - aPanel->setProfileName( aProfileName ); - aPanel->setProfile( myProfile ); -*/ -// displayPreview(); -} -void HYDROGUI_ProfileInterpolateOp::abortOperation() -{ HYDROGUI_Operation::abortOperation(); } void HYDROGUI_ProfileInterpolateOp::commitOperation() { + if ( !myPreview.IsNull() ) + { + HYDROGUI_ProfileInterpolateDlg* aDlg = new HYDROGUI_ProfileInterpolateDlg( module(), getName() ); + if ( aDlg && !aDlg->getAISContext().IsNull() ) + { + aDlg->getAISContext()->Remove( myPreview, false ); + myPreview.Nullify(); + } + } + HYDROGUI_Operation::commitOperation(); } @@ -142,123 +123,198 @@ HYDROGUI_InputPanel* HYDROGUI_ProfileInterpolateOp::createInputPanel() const bool HYDROGUI_ProfileInterpolateOp::processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries ) { - HYDROGUI_ProfileInterpolateDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( !aPanel ) - return false; -/* - QString aProfileName = aPanel->getProfileName().simplified(); - if ( aProfileName.isEmpty() ) - { - theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); + HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast( inputPanel() ); + if ( !aDlg ) return false; - } - if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) ) + QString errMessage; + HYDROData_IProfilesInterpolator* anIterp = interpolator( aDlg->interpolator() ); + if ( anIterp ) { - // check that there are no other objects with the same name in the document - Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName ); - if( !anObject.IsNull() ) + updateInterpolator( anIterp ); + Handle(HYDROData_Stream) aRiver = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), aDlg->river(), KIND_STREAM ) ); + if ( !aRiver.IsNull() ) { - theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName ); - return false; + startDocOperation(); + aRiver->Interpolate( anIterp ); + if ( anIterp->GetErrorCode() == OK ) + commitDocOperation(); + else + { + errMessage = tr( "CALCULATE_ERROR" ), QString( HYDROGUI_Tool::ToQString( anIterp->GetErrorMessage() ) ); + abortDocOperation(); + } } - } + else + errMessage = tr( "CANT_GET_STREAM_OBJECT" ).arg( aDlg->river() ); - Handle(HYDROData_Profile) aProfileObj; - if( myIsEdit ){ - aProfileObj = myEditedObject; - } - else{ - aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) ); + if ( !errMessage.isEmpty() ) + QMessageBox::critical( aDlg->topLevelWidget(), tr( "INTERPOLATION_ERROR" ), errMessage, QMessageBox::Ok ); + else + commit(); } - if( aProfileObj.IsNull() ) - return false; + bool res = errMessage.isEmpty(); - Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ(); - if ( aProfileUZ.IsNull() ) - return false; + if ( res ) + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; - aProfileObj->SetName(aProfileName); + return res; +} - HYDROData_ProfileUZ::PointsList aProfileParamPoints; +void HYDROGUI_ProfileInterpolateOp::updatePreview() +{ + HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast( inputPanel() ); + if ( !aDlg ) + return; - CurveCreator::Coordinates aCurveCoords = myProfile->getPoints( 0 ); - if ( aCurveCoords.size() <= 2 ) - { - theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" ); - return false; - } + Handle(AIS_InteractiveContext) aCtx = aDlg->getAISContext(); + if ( aCtx.IsNull() ) + return; - for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ ) - { - HYDROData_ProfileUZ::Point aProfileParamPoint; + if ( !myPreview.IsNull() ) + aCtx->Remove( myPreview, false ); - aProfileParamPoint.SetX( aCurveCoords.at( k ) ); - k++; - aProfileParamPoint.SetY( aCurveCoords.at( k ) ); + myPreview.Nullify(); - aProfileParamPoints.Append( aProfileParamPoint ); + HYDROData_IProfilesInterpolator* anIterp = interpolator( aDlg->interpolator() ); + if ( anIterp ) + { + updateInterpolator( anIterp ); + anIterp->Calculate(); + if ( anIterp->GetErrorCode() == OK ) + { + TopoDS_Shape aShape = previewShape( anIterp ); + if ( !aShape.IsNull() ) + { + myPreview = new AIS_Shape( aShape ); + myPreview->SetColor( Quantity_NOC_RED ); + aCtx->Display( myPreview, 1, -1, false ); + } + } } - aProfileObj->SetParametricPoints( aProfileParamPoints ); - HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE; - if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline ) - aSectType = HYDROData_ProfileUZ::SECTION_SPLINE; + aCtx->UpdateCurrentViewer(); +} - aProfileUZ->SetSectionType( 0, aSectType ); +void HYDROGUI_ProfileInterpolateOp::updateInterpolator( HYDROData_IProfilesInterpolator* theInt ) +{ + HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast( inputPanel() ); + if ( !aDlg || !theInt ) + return; + + theInt->Reset(); + theInt->SetResultProfilesNumber( aDlg->profileNumber() ); + theInt->SetProfiles( profile( aDlg->profileStart() ), profile( aDlg->profileFinish() ) ); + ParamsList aParams = parameters( aDlg->interpolatorParameters() ); + for ( ParamsList::Iterator it = aParams.begin(); it != aParams.end(); ++it ) { + theInt->SetParameter( HYDROGUI_Tool::ToAsciiString( (*it).first ), + HYDROGUI_Tool::ToAsciiString( (*it).second ) ); + } +} - if ( !myIsEdit ) +HYDROData_Profile::ProfilePoints HYDROGUI_ProfileInterpolateOp::profile( const QString& theName ) const +{ + HYDROData_Profile::ProfilePoints aPoints; + Handle(HYDROData_Profile) aProf = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_PROFILE ) ); + if ( !aProf.IsNull() ) { - aProfileObj->SetBorderColor( HYDROData_Profile::DefaultBorderColor() ); + aPoints = aProf->GetProfilePoints(); } + return aPoints; +} - // At first we update the child u,z profile object - aProfileUZ->SetToUpdate( true ); - aProfileUZ->Update(); +HYDROGUI_ProfileInterpolateOp::ParamsList HYDROGUI_ProfileInterpolateOp::parameters( const QString& theStr ) const +{ + // Regular expression for parsing parameters string of kind: ..." + // QRegExp rx( "([A-Za-z_\\d]+)\\s+([A-Za-z_\\d]+)\\s*" ); - // And now we update our edited object - aProfileObj->Update(); - module()->setIsToUpdate( aProfileObj ); + // Regular expression for parsing parameters string of kind: = = ..." + QRegExp rx( "([A-Za-z_\\d]+)\\s*=\\s*([A-Za-z_\\d]+)\\s*" ); - theUpdateFlags = UF_Model; - if ( myIsEdit ) - theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; - else + ParamsList aParamList; + for ( int i = 0; i >= 0; ) { - QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj ); - theBrowseObjectsEntries.append( anEntry ); + i = rx.indexIn( theStr, i ); + if ( i >= 0 ) + { + aParamList.append( QPair( rx.cap( 1 ), rx.cap( 2 ) ) ); + i += rx.matchedLength(); + } } - */ - return true; + return aParamList; } -void HYDROGUI_ProfileInterpolateOp::updatePreview() +QString HYDROGUI_ProfileInterpolateOp::parameters( const ParamsList& theParamList ) const { - HYDROGUI_ProfileInterpolateDlg* aDlg = ::qobject_cast( inputPanel() ); - if ( !aDlg ) - return; + QStringList paramList; + for ( ParamsList::const_iterator it = theParamList.begin(); it != theParamList.end(); ++it ) + paramList.append( QString( "%1 = %2" ).arg( (*it).first ).arg( (*it).second ) ); + return paramList.join( " " ); +} - Handle(AIS_InteractiveContext) aCtx = aDlg->getAISContext(); - if ( aCtx.IsNull() ) - return; +QStringList HYDROGUI_ProfileInterpolateOp::interpolators() const +{ + HYDROData_InterpolatorsFactory* anIFactory = 0; + Handle(HYDROData_Document) aDoc = doc(); + if ( !aDoc.IsNull() ) + anIFactory = aDoc->GetInterpolatorsFactory(); - aCtx->UpdateCurrentViewer(); + QStringList aNames; + if ( anIFactory ) + { + NCollection_Sequence iNames = anIFactory->GetInterpolatorNames(); + for ( int i = 1, n = iNames.Size(); i <= n; ++i ) { + const TCollection_AsciiString& anInterpName = iNames.Value( i ); + aNames.append( HYDROGUI_Tool::ToQString( anInterpName ) ); + } + } + + return aNames; } -QStringList HYDROGUI_ProfileInterpolateOp::interpolators() const +HYDROData_IProfilesInterpolator* HYDROGUI_ProfileInterpolateOp::interpolator( const QString& theName ) const { - return QStringList() << "Linear interpolator" << "Spline interpolator"; + HYDROData_InterpolatorsFactory* anIFactory = 0; + Handle(HYDROData_Document) aDoc = doc(); + if ( !aDoc.IsNull() ) + anIFactory = aDoc->GetInterpolatorsFactory(); + + HYDROData_IProfilesInterpolator* aRes = 0; + if ( anIFactory ) + aRes = anIFactory->GetInterpolator( HYDROGUI_Tool::ToAsciiString( theName ) ); + return aRes; +} + +TopoDS_Shape HYDROGUI_ProfileInterpolateOp::previewShape( HYDROData_IProfilesInterpolator* theInterp ) const +{ + TopoDS_Compound aPreviewShape; + if ( theInterp ) + { + BRep_Builder aBuilder; + aBuilder.MakeCompound( aPreviewShape ); + for ( int i = 0; i < theInterp->GetCalculatedProfilesNumber(); i++ ) + { + NCollection_Sequence pointSeq = theInterp->GetResultProfilePoints( i ); + + TopoDS_Shape aWire = HYDROData_PolylineXY::BuildWire( HYDROData_IPolyline::SECTION_SPLINE, false, pointSeq ); + if ( !aWire.IsNull() ) + aBuilder.Add( aPreviewShape, aWire ); + } + } + + return aPreviewShape; } void HYDROGUI_ProfileInterpolateOp::onInterpolatorChanged( const QString& theInterpName ) { HYDROGUI_ProfileInterpolateDlg* aPanel = dynamic_cast( inputPanel() ); - if ( !aPanel ) + HYDROData_IProfilesInterpolator* anInterp = interpolator( theInterpName ); + if ( !aPanel || !anInterp ) return; - aPanel->setInterpolatorDescription( QString( "Profile will be calculated used %1" ).arg( theInterpName ) ); + aPanel->setInterpolatorDescription( HYDROGUI_Tool::ToQString( anInterp->GetDescription() ) ); updatePreview(); } @@ -293,7 +349,22 @@ void HYDROGUI_ProfileInterpolateOp::onRiverChanged( const QString& theRiver ) Handle(AIS_Shape) aPrs = new AIS_Shape( aProfile->GetShape3D() ); aPrs->SetOwner( aProfile ); aPrs->SetColor( Quantity_NOC_BLACK ); - aCtx->Display( aPrs, 0, 0, false ); + aCtx->Display( aPrs, 1, 0, false ); + } + } + OCCViewer_ViewManager* vm = aDlg->viewManager(); + if ( vm ) + { + QVector winList = vm->getViews(); + for ( QVector::iterator it = winList.begin(); it != winList.end(); ++it ) + { + OCCViewer_ViewWindow* occWin = ::qobject_cast( *it ); + if ( occWin ) + { + OCCViewer_ViewPort3d* vp = occWin->getViewPort(); + if ( vp ) + vp->fitAll(); + } } } }