X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_Zone.cxx;h=c1139e1e4e66153e03a82a6dddabb20245e7f8d7;hb=55fe0d2de7e15a256965d71280dc61fd58863d7e;hp=26aa2f08878e24ebc3d2992d8233402d8533ce05;hpb=e98e5c25e842447ac4cdd60bc5c1770255cdb0a3;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_Zone.cxx b/src/HYDROGUI/HYDROGUI_Zone.cxx index 26aa2f08..c1139e1e 100644 --- a/src/HYDROGUI/HYDROGUI_Zone.cxx +++ b/src/HYDROGUI/HYDROGUI_Zone.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 @@ -24,15 +20,17 @@ #include #include -#include +#include +#include #include #include HYDROGUI_Zone::HYDROGUI_Zone( SUIT_DataObject* theParent, Handle(HYDROData_Zone) theData, - const QString& theParentEntry ) -: HYDROGUI_DataObject( theParent, theData, theParentEntry ), CAM_DataObject( theParent ) + const QString& theParentEntry, + const bool theIsInOperation ) +: HYDROGUI_DataObject( theParent, theData, theParentEntry, theIsInOperation ), CAM_DataObject( theParent ) { } @@ -47,9 +45,9 @@ QString HYDROGUI_Zone::text( const int theColumnId ) const // Get Ref.Object name aRes = getRefObjectNames(); break; - case BathymetryId: - // Get bathymetry name - aRes = getBathimetryName(); + case AltitudeObjId: + // Get altitude/land cover object name + aRes = getObjectName(); break; default: aRes = LightApp_DataObject::text( theColumnId ); @@ -64,12 +62,12 @@ QString HYDROGUI_Zone::getRefObjectNames() const Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); if ( !aZone.IsNull() ) { - HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); + HYDROData_SequenceOfObjects aSeq = aZone->GetObjects(); HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); for ( ; anIter.More(); anIter.Next() ) { - Handle(HYDROData_Object) aRefGeomObj = - Handle(HYDROData_Object)::DownCast( anIter.Value() ); + Handle(HYDROData_Entity) aRefGeomObj = + Handle(HYDROData_Entity)::DownCast( anIter.Value() ); if ( !aRefGeomObj.IsNull() ) { // Get Ref.Object name @@ -84,47 +82,64 @@ QString HYDROGUI_Zone::getRefObjectNames() const return aRes; } -QString HYDROGUI_Zone::getBathimetryName() const +QString HYDROGUI_Zone::getObjectName() const { QString aRes; Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); if ( !aZone.IsNull() ) { - HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); + HYDROData_SequenceOfObjects aSeq = aZone->GetObjects(); bool isMergingNeed = aZone->IsMergingNeed(); if ( ( isMergingNeed && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) || ( aSeq.Length() == 1 ) || ( !isMergingNeed ) ) { - // Collect all used bathymetries names when merging is necessary - // or just get the name of bathymetry of a single geometry object - // or just get the name of a single bathymetry + // Collect all used altitudes names when merging is necessary + // or just get the name of altitude of a single geometry object + // or just get the name of a single altitude HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); QSet aNamesSet; QString aName; for ( ; anIter.More(); anIter.Next() ) { + aName.clear(); Handle(HYDROData_Object) aRefGeomObj = Handle(HYDROData_Object)::DownCast( anIter.Value() ); if ( !aRefGeomObj.IsNull() ) { - // Get bathymetry name - Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry(); - if ( !aBathymetry.IsNull() ) + // Get altitude object name + Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject(); + if ( !anAltitudeObj.IsNull() ) { - aName = aBathymetry->GetName(); + aName = anAltitudeObj->GetName(); if ( !isMergingNeed ) { - // Get the first geometry object's bathymetry name and go out + // Get the first geometry object's altitude name and go out aRes = aName; break; } - - if ( !aNamesSet.contains( aName ) ) + } + } + else + { + Handle(HYDROData_LandCover) aRefLandCoverObj = + Handle(HYDROData_LandCover)::DownCast( anIter.Value() ); + if ( !aRefLandCoverObj.IsNull() ) + { + // Get name of land cover object + aName = aRefLandCoverObj->GetName(); + if ( !isMergingNeed ) { - aRes += aName + ", "; - aNamesSet.insert( aName ); + // Get the first land cover object's altitude name and go out + aRes = aName; + break; } - } + } + } + + if ( !aName.isEmpty() && !aNamesSet.contains( aName ) ) + { + aRes += aName + ", "; + aNamesSet.insert( aName ); } } // Remove the last comma if necessary @@ -143,13 +158,11 @@ QString HYDROGUI_Zone::getBathimetryName() const case HYDROData_Zone::Merge_ZMAX: // The maximum values aRes = QObject::tr( "MERGE_ZMAX" ); break; - case HYDROData_Zone::Merge_Object: // Only one bathymetry will be taken into account + case HYDROData_Zone::Merge_Object: // Only one altitude/land cover will be taken into account { - Handle(HYDROData_Bathymetry) aBathymetry = aZone->GetMergeBathymetry(); - if ( !aBathymetry.IsNull() ) - { - aRes = aBathymetry->GetName(); - } + Handle(HYDROData_Entity) aMergeObj = aZone->GetMergeObject(); + if ( !aMergeObj.IsNull() ) + aRes = aMergeObj->GetName(); break; } default: @@ -176,7 +189,7 @@ bool HYDROGUI_Zone::isMergingNeed() const QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId ) const { - // Implement red color for bathymetry conflicts in case creation dialog + // Implement red color for altitude conflicts in case creation dialog QColor aRes; Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); if ( !aZone.IsNull() ) @@ -202,20 +215,20 @@ QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId } if ( !aRes.isValid() ) { - aRes = LightApp_DataObject::color( theColorRole, theColumnId ); + aRes = HYDROGUI_DataObject::color( theColorRole, theColumnId ); } return aRes; } -QStringList HYDROGUI_Zone::getBathymetries() const +QStringList HYDROGUI_Zone::getObjects() const { QStringList aRes; Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); if ( !aZone.IsNull() ) { - HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); - // Collect all used bathymetries names when merging is necessary - // or just get the name of bathymetry of a single geometry object + HYDROData_SequenceOfObjects aSeq = aZone->GetObjects(); + // Collect all used altitudes/land cover names when merging is necessary + // or just get the name of altitude/land cover of a single object HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); for ( ; anIter.More(); anIter.Next() ) { @@ -223,21 +236,20 @@ QStringList HYDROGUI_Zone::getBathymetries() const Handle(HYDROData_Object)::DownCast( anIter.Value() ); if ( !aRefGeomObj.IsNull() ) { - // Get bathymetry name - Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry(); - if ( !aBathymetry.IsNull() && !aRes.contains( aBathymetry->GetName() )) - { - aRes.append( aBathymetry->GetName() ); - } + Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject(); + if ( !anAltitudeObj.IsNull() && !aRes.contains( anAltitudeObj->GetName() ) ) + aRes.append( anAltitudeObj->GetName() ); + } else { + aRes.append( anIter.Value()->GetName() ); } } } return aRes; } -HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const +HYDROData_Zone::MergeType HYDROGUI_Zone::getMergeType() const { - HYDROData_Zone::MergeBathymetriesType aRes = HYDROData_Zone::Merge_UNKNOWN; + HYDROData_Zone::MergeType aRes = HYDROData_Zone::Merge_UNKNOWN; Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); if ( !aZone.IsNull() ) { @@ -246,34 +258,94 @@ HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const return aRes; } -void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName ) +void HYDROGUI_Zone::setMergeType( int theMergeType, QString theMergeObjectName ) { Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); if ( !aZone.IsNull() ) { - HYDROData_Zone::MergeBathymetriesType aMergeType = - ( HYDROData_Zone::MergeBathymetriesType )theMergeType; + HYDROData_Zone::MergeType aMergeType = + ( HYDROData_Zone::MergeType )theMergeType; aZone->SetMergeType( aMergeType ); if ( aMergeType == HYDROData_Zone::Merge_Object ) { - // Find a bathymetry by the given name and set it as the zone's merge bathymetry - HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); + // Find an altitude/land cover object by the given name and set it as the zone's merge altitude/land cover + HYDROData_SequenceOfObjects aSeq = aZone->GetObjects(); HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); for ( ; anIter.More(); anIter.Next() ) { + Handle(HYDROData_Entity) aMergeObject; + Handle(HYDROData_Object) aRefGeomObj = Handle(HYDROData_Object)::DownCast( anIter.Value() ); if ( !aRefGeomObj.IsNull() ) { - // Get bathymetry name - Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry(); - if ( !aBathymetry.IsNull() && theBathymetryName == aBathymetry->GetName() ) - { - aZone->SetMergeBathymetry( aBathymetry ); - break; - } + // Get altitude object + aMergeObject = aRefGeomObj->GetAltitudeObject(); + } else { + aMergeObject = Handle(HYDROData_LandCover)::DownCast( anIter.Value() ); + } + + if ( !aMergeObject.IsNull() && theMergeObjectName == aMergeObject->GetName() ) + { + aZone->SetMergeObject( aMergeObject ); + break; } } } } } + +/*! + \brief Check if this object is can't be renamed in place + + \param id column id + \return \c true if the item can be renamed by the user in place (e.g. in the Object browser) +*/ +bool HYDROGUI_Zone::renameAllowed( const int id ) const +{ + if ( id == NameId && isInOperation() ) + { + return true; + } + return HYDROGUI_DataObject::renameAllowed( id ); +} + +///*! +// \brief Set name of this object. +// +// \return \c true if rename operation finished successfully, \c false otherwise. +//*/ +//bool HYDROGUI_Zone::setName(const QString& theName) +//{ +// if ( isInOperation() ) +// { +// bool aRes = false; +// if ( !theName.isEmpty() ) +// { +// Handle(HYDROData_Entity) anEntity = modelObject(); +// CAM_Module* aModule = module(); +// if( anEntity->GetName() != theName && aModule ) +// { +// // check that there are no other objects with the same name in the document +// Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( aModule, theName ); +// if ( anObject.IsNull() ) +// { +// anEntity->SetName( theName ); +// aRes = true; +// } +// else +// { +// // Inform the user that the name is already used +// QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" ); +// QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName ); +// SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage ); +// } +// } +// } +// } +// else +// { +// aRes = HYDROGUI_DataObject::setName( theName ); +// } +// return aRes; +//}