X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_Zone.cxx;h=8a5bc0d3b21e59a901452aa62108a0f7bcb214c6;hb=81c9f5cdf82909d0aebd2c491c50fa7516cc80b7;hp=8b6ecfb811b17f2e598057e57977a042dec4dba4;hpb=6d6c4ec18ead5730c1d14090e33dc9667c5a5841;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_Zone.cxx b/src/HYDROGUI/HYDROGUI_Zone.cxx index 8b6ecfb8..8a5bc0d3 100644 --- a/src/HYDROGUI/HYDROGUI_Zone.cxx +++ b/src/HYDROGUI/HYDROGUI_Zone.cxx @@ -24,14 +24,16 @@ #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 ) { } @@ -46,9 +48,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 object name + aRes = getAltitudeName(); break; default: aRes = LightApp_DataObject::text( theColumnId ); @@ -83,33 +85,51 @@ QString HYDROGUI_Zone::getRefObjectNames() const return aRes; } -QString HYDROGUI_Zone::getBathimetryName() const +QString HYDROGUI_Zone::getAltitudeName() const { QString aRes; Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); if ( !aZone.IsNull() ) { HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); - if ( aZone->IsMergingNeed() || aSeq.Length() == 1 ) + 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 + // 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() ) { 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() ) { - aRes += aBathymetry->GetName() + ", "; + aName = anAltitudeObj->GetName(); + if ( !isMergingNeed ) + { + // Get the first geometry object's altitude name and go out + aRes = aName; + break; + } + + if ( !aNamesSet.contains( aName ) ) + { + aRes += aName + ", "; + aNamesSet.insert( aName ); + } } } } - if ( aRes.length() > 1 ) + // Remove the last comma if necessary + if ( isMergingNeed && ( aRes.length() > 1 ) ) { aRes.remove( aRes.length() - 2, 2 ); } @@ -124,13 +144,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 will be taken into account { - Handle(HYDROData_Bathymetry) aBathymetry = aZone->GetMergeBathymetry(); - if ( !aBathymetry.IsNull() ) - { - aRes = aBathymetry->GetName(); - } + Handle(HYDROData_IAltitudeObject) anAltitude = aZone->GetMergeAltitude(); + if ( !anAltitude.IsNull() ) + aRes = anAltitude->GetName(); break; } default: @@ -157,29 +175,156 @@ 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; - if( isMergingNeed() ) + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) { - switch( theColorRole ) + if ( ( aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) ) { - case Text: // editor foreground (text) color - case Foreground: // foreground (text) color - aRes = Qt::red; - break; - case HighlightedText: // highlighted foreground (text) color - aRes = Qt::black; - break; - case Base: // editor background color - case Background: // background color - case Highlight: // highlight background color - default: - aRes = Qt::red; + switch( theColorRole ) + { + case Text: // editor foreground (text) color + case Foreground: // foreground (text) color + aRes = Qt::red; + break; + case HighlightedText: // highlighted foreground (text) color + aRes = Qt::black; + break; + case Base: // editor background color + case Background: // background color + case Highlight: // highlight background color + default: + aRes = Qt::red; + } } } - else + if ( !aRes.isValid() ) + { + aRes = HYDROGUI_DataObject::color( theColorRole, theColumnId ); + } + return aRes; +} + +QStringList HYDROGUI_Zone::getAltitudes() const +{ + QStringList aRes; + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) { - aRes = LightApp_DataObject::color( theColorRole, theColumnId ); + HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); + // Collect all used altitudes names when merging is necessary + // or just get the name of altitude of a single geometry object + HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Object) aRefGeomObj = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( !aRefGeomObj.IsNull() ) + { + Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject(); + if ( !anAltitudeObj.IsNull() && !aRes.contains( anAltitudeObj->GetName() ) ) + aRes.append( anAltitudeObj->GetName() ); + } + } } return aRes; } + +HYDROData_Zone::MergeAltitudesType HYDROGUI_Zone::getMergeType() const +{ + HYDROData_Zone::MergeAltitudesType aRes = HYDROData_Zone::Merge_UNKNOWN; + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) + { + aRes = aZone->GetMergeType(); + } + return aRes; +} + +void HYDROGUI_Zone::setMergeType( int theMergeType, QString theAltitudeName ) +{ + Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() ); + if ( !aZone.IsNull() ) + { + HYDROData_Zone::MergeAltitudesType aMergeType = + ( HYDROData_Zone::MergeAltitudesType )theMergeType; + aZone->SetMergeType( aMergeType ); + if ( aMergeType == HYDROData_Zone::Merge_Object ) + { + // Find an altitude object by the given name and set it as the zone's merge altitude + HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator anIter( aSeq ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Object) aRefGeomObj = + Handle(HYDROData_Object)::DownCast( anIter.Value() ); + if ( !aRefGeomObj.IsNull() ) + { + // Get altitude object name + Handle(HYDROData_IAltitudeObject) anAltitudeObj = aRefGeomObj->GetAltitudeObject(); + if ( !anAltitudeObj.IsNull() && theAltitudeName == anAltitudeObj->GetName() ) + { + aZone->SetMergeAltitude( anAltitudeObj ); + 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; +//}