From 79c995735a9f168452b12a3e60d0c4188284fc95 Mon Sep 17 00:00:00 2001 From: adv Date: Wed, 4 Dec 2013 07:04:11 +0000 Subject: [PATCH] Names of objects can't be empty (Bug #149). --- src/HYDROGUI/HYDROGUI_PolylineOp.cxx | 33 ++++++++++++++++++---------- src/HYDROGUI/HYDROGUI_ProfileOp.cxx | 30 ++++++++++++++++--------- src/HYDROGUI/HYDROGUI_StreamOp.cxx | 2 +- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index bbef9e43..1a954304 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -172,13 +172,27 @@ HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, QString& theErrorMsg ) { - HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel(); + HYDROGUI_PolylineDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return false; - int aStudyId = module()->getStudyId(); - bool aHasDoc = HYDROData_Document::HasDocument(aStudyId); - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId ); - if( aDocument.IsNull() ) + QString aPolylineName = aPanel->getPolylineName().simplified(); + if ( aPolylineName.isEmpty() ) + { + theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); return false; + } + + if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aPolylineName ) ) + { + // check that there are no other objects with the same name in the document + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aPolylineName ); + if( !anObject.IsNull() ) + { + theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aPolylineName ); + return false; + } + } Handle(HYDROData_PolylineXY) aPolylineObj; if( myIsEdit ) @@ -186,17 +200,14 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags, aPolylineObj = myEditedObject; aPolylineObj->RemoveSections(); } - else{ - aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) ); - - //double aZValue = double( ++ZValueIncrement ) * 1e-2; // empiric value, to be revised - //aPolylineObj->SetZValue( aZValue ); + else + { + aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( doc()->CreateObject( KIND_POLYLINEXY ) ); } if( aPolylineObj.IsNull() ) return false; - QString aPolylineName = aPanel->getPolylineName(); aPolylineObj->SetName(aPolylineName); for ( int i = 0 ; i < myCurve->getNbSections() ; i++ ) diff --git a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx index 8f951900..efe8572c 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx @@ -144,29 +144,39 @@ HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags, QString& theErrorMsg ) { - HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel(); + HYDROGUI_ProfileDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return false; - int aStudyId = module()->getStudyId(); - bool aHasDoc = HYDROData_Document::HasDocument(aStudyId); - Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId ); - if( aDocument.IsNull() ) + QString aProfileName = aPanel->getProfileName().simplified(); + if ( aProfileName.isEmpty() ) + { + theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); return false; + } + + if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) ) + { + // 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() ) + { + theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName ); + return false; + } + } Handle(HYDROData_Profile) aProfileObj; if( myIsEdit ){ aProfileObj = myEditedObject; } else{ - aProfileObj = Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) ); - - //double aZValue = double( ++ZValueIncrement ) * 1e-2; // empiric value, to be revised - //aProfileObj->SetZValue( aZValue ); + aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) ); } if( aProfileObj.IsNull() ) return false; - QString aProfileName = aPanel->getProfileName(); aProfileObj->SetName(aProfileName); HYDROData_ProfileUZ::PointsList aProfileParamPoints; diff --git a/src/HYDROGUI/HYDROGUI_StreamOp.cxx b/src/HYDROGUI/HYDROGUI_StreamOp.cxx index a800239d..36a50ca7 100755 --- a/src/HYDROGUI/HYDROGUI_StreamOp.cxx +++ b/src/HYDROGUI/HYDROGUI_StreamOp.cxx @@ -139,7 +139,7 @@ bool HYDROGUI_StreamOp::processApply( int& theUpdateFlags, } // Check that there are no other objects with the same name in the document - if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anObjectName ) ) + if( myEditedObject->GetName() != anObjectName ) { Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName ); if( !anObject.IsNull() ) { -- 2.39.2