X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_DataModel.cxx;h=cb445127bd4694ca6f75093699e15852d3b2b8a3;hb=637f41bd30ce380b1e9c4c100b394be08fdc5ef7;hp=fc7a38380a520a395bc0315d75568ca3fed7a484;hpb=f253c32c980c4e6bc80a9966af11490191dfb093;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index fc7a3838..cb445127 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -25,13 +25,28 @@ #include "HYDROGUI_DataObject.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" +#include "HYDROGUI_Zone.h" +#include "HYDROGUI_Region.h" #include +#include +#include #include +#include #include +#include #include -#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -47,6 +62,7 @@ #include #include #include +#include #include @@ -54,6 +70,14 @@ #include #include +#include + +// #define DEB_GROUPS 1 +#ifdef DEB_GROUPS +#include +#endif + +static HYDROData_SequenceOfObjects myCopyingObjects; HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule ) : LightApp_DataModel( theModule ) @@ -155,26 +179,25 @@ bool HYDROGUI_DataModel::dumpPython( const QString& theURL, bool isMultiFile, QStringList& theListOfFiles ) { + LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles ); + int aStudyId = theStudy->id(); + LightApp_Study* aStudy = ::qobject_cast( theStudy ); Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId ); - if( aDocument.IsNull() ) + if ( aDocument.IsNull() || !aStudy ) return false; - QString aFileToExport = theURL; + QString aDir = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str(); + QString aFileToExport = aDir + QString( QDir::separator() ) + "HYDRO.py"; - if ( isMultiFile ) + bool aRes = aDocument->DumpToPython( aFileToExport, isMultiFile ); + if ( aRes ) { - // each module's dump is written into a separate Python file + theListOfFiles.append( aDir ); + theListOfFiles.append( aFileToExport ); } - - QApplication::setOverrideCursor( Qt::WaitCursor ); - - bool aRes = aDocument->DumpToPython( aFileToExport ); - - QApplication::restoreOverrideCursor(); - return aRes; } @@ -198,86 +221,201 @@ void HYDROGUI_DataModel::update( const int theStudyId ) if( !aStudyRoot ) return; - // create root object if not exist - CAM_DataObject* aRootObj = root(); - if( !aRootObj ) - aRootObj = createRootModuleObject( aStudyRoot ); - - if( !aRootObj ) - return; - - DataObjectList aList; - aRootObj->children( aList ); - QListIterator anIter( aList ); - while( anIter.hasNext() ) - removeChild( aRootObj, anIter.next() ); + // create a new root object + CAM_DataObject* aNewRootObj = new CAM_DataObject(); Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theStudyId ); if( aDocument.IsNull() ) return; - LightApp_DataObject* anImageRootObj = createObject( aRootObj, "IMAGES" ); + // Create root objects: - HYDROData_Iterator anIterator( aDocument, KIND_IMAGE ); - for( ; anIterator.More(); anIterator.Next() ) - { - Handle(HYDROData_Image) anImageObj = - Handle(HYDROData_Image)::DownCast( anIterator.Current() ); - if( !anImageObj.IsNull() ) + // IMAGES + LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) ); + + // BATHYMETRY + LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) ); + + // ARTIFICIAL OBJECTS + LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) ); + + // NATURAL OBJECTS + LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) ); + + // OBSTACLES + LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) ); + + // CALCULATION CASES + LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) ); + + // POLYLINES + LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) ); + + // POLYLINES + LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) ); + + // PROFILES + LightApp_DataObject* aProfileRootObj = createObject( aNewRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) ); + + // VISUAL STATES + LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) ); + + HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN ); + for( ; anIterator.More(); anIterator.Next() ) { + Handle(HYDROData_Entity) anObj = anIterator.Current(); + + if ( !anObj.IsNull() ) { - if( LightApp_DataObject* anImageDataObj = createObject( anImageRootObj, anImageObj ) ) - { - for( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ ) + switch ( anObj->GetKind() ) { + case KIND_IMAGE: { - Handle(HYDROData_Image) aRefImageObj = anImageObj->Reference( anIndex ); - if( !aRefImageObj.IsNull() && !aRefImageObj->IsRemoved() ) - createObject( anImageDataObj, aRefImageObj, anImageDataObj->entry() ); + Handle(HYDROData_Image) anImageObj = + Handle(HYDROData_Image)::DownCast( anObj ); + if( !anImageObj.IsNull() ) { + createObject( anImageRootObj, anImageObj ); + } + + break; } - } - } - } + case KIND_BATHYMETRY: + { + Handle(HYDROData_Bathymetry) aBathymetryObj = + Handle(HYDROData_Bathymetry)::DownCast( anObj ); + if( !aBathymetryObj.IsNull() ) { + createObject( aBathymetryRootObj, aBathymetryObj ); + } - LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, "BATHYMETRIES" ); + break; + } + case KIND_CHANNEL: + { + Handle(HYDROData_Channel) aChannelObj = + Handle(HYDROData_Channel)::DownCast( anObj ); + if( !aChannelObj.IsNull() ) { + createObject( anArtificialObjectsRootObj, aChannelObj ); + } - anIterator = HYDROData_Iterator( aDocument, KIND_BATHYMETRY ); - for( ; anIterator.More(); anIterator.Next() ) - { - Handle(HYDROData_Bathymetry) aBathymetryObj = - Handle(HYDROData_Bathymetry)::DownCast( anIterator.Current() ); - if( !aBathymetryObj.IsNull() ) - createObject( aBathymetryRootObj, aBathymetryObj ); - } + break; + } + case KIND_DIGUE: + { + Handle(HYDROData_Digue) aDigueObj = + Handle(HYDROData_Digue)::DownCast( anObj ); + if( !aDigueObj.IsNull() ) { + createObject( anArtificialObjectsRootObj, aDigueObj ); + } - LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, "POLYLINES" ); + break; + } + case KIND_IMMERSIBLE_ZONE: + { + Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj = + Handle(HYDROData_ImmersibleZone)::DownCast( anObj ); + if( !anImmersibleZoneObj.IsNull() ) { + createObject( aNaturalObjectsRootObj, anImmersibleZoneObj ); + } - anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE ); - for( ; anIterator.More(); anIterator.Next() ) - { - Handle(HYDROData_Polyline) aPolylineObj = - Handle(HYDROData_Polyline)::DownCast( anIterator.Current() ); - if( !aPolylineObj.IsNull() ) - createObject( aPolylineRootObj, aPolylineObj ); - } + break; + } + case KIND_RIVER: + { + Handle(HYDROData_River) aRiverObj = + Handle(HYDROData_River)::DownCast( anObj ); + if( !aRiverObj.IsNull() ) { + createObject( aNaturalObjectsRootObj, aRiverObj ); + } - LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, "VISUAL_STATES" ); + break; + } + case KIND_STREAM: + { + Handle(HYDROData_Stream) aStreamObj = + Handle(HYDROData_Stream)::DownCast( anObj ); + if( !aStreamObj.IsNull() ) { + createObject( aNaturalObjectsRootObj, aStreamObj ); + } - anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE ); - for( ; anIterator.More(); anIterator.Next() ) - { - Handle(HYDROData_VisualState) aVisualStateObj = - Handle(HYDROData_VisualState)::DownCast( anIterator.Current() ); - if( !aVisualStateObj.IsNull() ) - createObject( aVisualStateRootObj, aVisualStateObj ); - } + break; + } + case KIND_OBSTACLE: + { + Handle(HYDROData_Obstacle) anObstacleObj = + Handle(HYDROData_Obstacle)::DownCast( anObj ); + if( !anObstacleObj.IsNull() ) { + createObject( anObstaclesRootObj, anObstacleObj ); + } - if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() ) - { - anObjectBrowser->setAutoOpenLevel( 3 ); - anObjectBrowser->openLevels(); + break; + } + case KIND_CALCULATION: + { + Handle(HYDROData_CalculationCase) aCalculObj = + Handle(HYDROData_CalculationCase)::DownCast( anObj ); + if( !aCalculObj.IsNull() ) { + createObject( aCalculRootObj, aCalculObj ); + } + + break; + } + case KIND_POLYLINEXY: + { + Handle(HYDROData_PolylineXY) aPolylineObj = + Handle(HYDROData_PolylineXY)::DownCast( anObj ); + if( !aPolylineObj.IsNull() ) { + createObject( aPolylineRootObj, aPolylineObj ); + } + + break; + } + case KIND_POLYLINE: + { + Handle(HYDROData_Polyline3D) aPolylineObj = + Handle(HYDROData_Polyline3D)::DownCast( anObj ); + if( !aPolylineObj.IsNull() ) { + createObject( aPolyline3DRootObj, aPolylineObj ); + } + + break; + } + case KIND_PROFILE: + { + Handle(HYDROData_Profile) aProfileObj = + Handle(HYDROData_Profile)::DownCast( anObj ); + if( !aProfileObj.IsNull() ) { + createObject( aProfileRootObj, aProfileObj ); + } + + break; + } + case KIND_VISUAL_STATE: + { + Handle(HYDROData_VisualState) aVisualStateObj = + Handle(HYDROData_VisualState)::DownCast( anObj ); + if( !aVisualStateObj.IsNull() ) { + createObject( aVisualStateRootObj, aVisualStateObj ); + } + + break; + } + } + } } + + //if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() ) + //{ + // anObjectBrowser->setAutoOpenLevel( 3 ); + // anObjectBrowser->openLevels(); + //} + + HYDROGUI_DataModelSync aSync( aNewRootObj ); + SUIT_DataObject* aRoot = root(); + if( !aRoot ) + aRoot = createRootModuleObject( aStudyRoot ); + ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync > + ( aNewRootObj, aRoot, aSync ); } -HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Object)& theModelObject ) +HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject ) { return NULL; // to do if necessary } @@ -304,7 +442,8 @@ void HYDROGUI_DataModel::update( LightApp_DataObject* theObject, CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* theParent ) { - CAM_DataObject* aRootObj = createModuleObject( theParent ); + CAM_ModuleObject* aRootObj = createModuleObject( theParent ); + aRootObj->setDataModel( this ); setRoot( aRootObj ); return aRootObj; } @@ -316,7 +455,7 @@ void HYDROGUI_DataModel::updateModel() update( aModule->getStudyId() ); } -Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEntry, +Handle(HYDROData_Entity) HYDROGUI_DataModel::objectByEntry( const QString& theEntry, const ObjectKind theObjectKind ) { QString anEntry = theEntry; @@ -329,7 +468,7 @@ Handle(HYDROData_Object) HYDROGUI_DataModel::objectByEntry( const QString& theEn HYDROData_Iterator anIterator( aDocument, theObjectKind ); for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Object) anObject = anIterator.Current(); + Handle(HYDROData_Entity) anObject = anIterator.Current(); if( !anObject.IsNull() ) { QString anEntryRef = HYDROGUI_DataObject::dataObjectEntry( anObject ); @@ -403,23 +542,473 @@ bool HYDROGUI_DataModel::redo() return true; } +bool HYDROGUI_DataModel::canCopy() +{ + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() ); + bool isCanCopy = !aSeq.IsEmpty(); + + for ( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); + if( !anObject.IsNull() ) { + ObjectKind aKind = anObject->GetKind(); + bool isUnrecognized = aKind <= KIND_UNKNOWN || aKind > KIND_LAST; + bool isChildObject = aKind == KIND_DUMMY_3D || + aKind == KIND_ZONE || + aKind == KIND_SHAPES_GROUP || + aKind == KIND_SPLITTED_GROUP; + if ( isUnrecognized || isChildObject ) { + isCanCopy = false; + break; + } + } + } + + return isCanCopy; +} + +bool HYDROGUI_DataModel::canPaste() +{ + for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ ) + { + Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex ); + if( !anObject.IsNull() && !anObject->IsRemoved() ) + return true; + } + return false; +} + +bool HYDROGUI_DataModel::copy() +{ + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() ); + changeCopyingObjects( aSeq ); + return true; +} + +bool HYDROGUI_DataModel::paste() +{ + bool anIsChanged = false; + for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ ) + { + Handle(HYDROData_Entity) anObject = myCopyingObjects.Value( anIndex ); + if( !anObject.IsNull() && !anObject->IsRemoved() ) + { + ObjectKind aKind = anObject->GetKind(); + Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind ); + if( !aClone.IsNull() ) + { + anObject->CopyTo( aClone ); + anIsChanged = true; + + // remove Z layer + aClone->RemoveZLevel(); + + // generate a new unique name for the clone object: + // case 1: Image_1 -> Image_2 + // case 2: ImageObj -> ImageObj_1 + QString aName = aClone->GetName(); + QString aPrefix = aName; + if( aName.contains( '_' ) ) // case 1 + { + QString aSuffix = aName.section( '_', -1 ); + bool anIsInteger = false; + aSuffix.toInt( &anIsInteger ); + if( anIsInteger ) + aPrefix = aName.section( '_', 0, -2 ); + } + else // case 2 + aPrefix = aName; + aName = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix ); + aClone->SetName( aName ); + } + } + } + return anIsChanged; +} + +void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq ) +{ + myCopyingObjects.Assign( theSeq ); +} + +QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind ) +{ + switch( theObjectKind ) + { + case KIND_IMAGE: return "IMAGES"; + case KIND_POLYLINE: return "POLYLINES_3D"; + case KIND_POLYLINEXY: return "POLYLINES"; + case KIND_PROFILE: return "PROFILES"; + case KIND_VISUAL_STATE: return "VISUAL_STATES"; + case KIND_BATHYMETRY: return "BATHYMETRIES"; + case KIND_CALCULATION: return "CALCULATION_CASES"; + case KIND_OBSTACLE: return "OBSTACLES"; + case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS"; + case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS"; + default: break; + } + return QString(); +} + Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const { int aStudyId = module()->application()->activeStudy()->id(); return HYDROData_Document::Document( aStudyId ); } -LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, - Handle(HYDROData_Object) theModelObject, - const QString& theParentEntry ) +LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, + Handle(HYDROData_Entity) theModelObject, + const QString& theParentEntry, + const bool theIsBuildTree ) +{ + HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); + + if ( theIsBuildTree ) + { + buildObjectTree( theParent, aResObj, theParentEntry ); + } + + return aResObj; +} + +LightApp_DataObject* HYDROGUI_DataModel::buildObject( SUIT_DataObject* theParent, + HYDROGUI_DataObject* theObject, + const QString& theParentEntry, + const bool theIsBuildTree, + const bool theIsInOperation ) { - return new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); + if ( theIsBuildTree ) + { + buildObjectTree( theParent, theObject, theParentEntry, theIsInOperation ); + } + return theObject; +} + +LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theParent, + Handle(HYDROData_Zone) theModelObject, + const QString& theParentEntry, + const bool theIsBuildTree, + const bool theIsInOperation ) +{ + return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ), + theParentEntry, theIsBuildTree, theIsInOperation ); +} + +LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent, + Handle(HYDROData_Region) theModelObject, + const QString& theParentEntry, + const bool theIsBuildTree, + const bool theIsInOperation ) +{ + return buildObject( theParent, new HYDROGUI_Region( theParent, theModelObject, theParentEntry, theIsInOperation ), + theParentEntry, theIsBuildTree, theIsInOperation ); } LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, - const QString& theName ) + const QString& theName, + const QString& theParentEntry ) { - return new HYDROGUI_NamedObject( theParent, theName ); + return new HYDROGUI_NamedObject( theParent, theName, theParentEntry ); +} + +void HYDROGUI_DataModel::buildObjectPartition( SUIT_DataObject* theObject, + const HYDROData_SequenceOfObjects& theObjects, + const QString& thePartName, + const bool theIsCreateEmpty ) +{ + if ( theObjects.IsEmpty() && !theIsCreateEmpty ) + return; + + HYDROGUI_DataObject* aGuiObj = dynamic_cast( theObject ); + if ( !aGuiObj ) + return; + + LightApp_DataObject* aPartSect = + createObject( aGuiObj, thePartName, aGuiObj->entry() ); + + HYDROData_SequenceOfObjects::Iterator anIter( theObjects ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Entity) anObj = anIter.Value(); + if( !anObj.IsNull() && !anObj->IsRemoved() ) + createObject( aPartSect, anObj, aGuiObj->entry(), false ); + } +} + +void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, + SUIT_DataObject* theObject, + const QString& theParentEntry, + const bool theIsInOperation ) +{ + HYDROGUI_DataObject* aGuiObj = dynamic_cast( theObject ); + if ( !aGuiObj ) + return; + + Handle(HYDROData_Entity) aDataObj = aGuiObj->modelObject(); + if ( aDataObj.IsNull() ) + return; + + if ( aDataObj->IsKind( STANDARD_TYPE(HYDROData_Object) ) ) + { + Handle(HYDROData_Object) aGeomObj = + Handle(HYDROData_Object)::DownCast( aDataObj ); + + Handle(HYDROData_DummyObject3D) anObject3D = aGeomObj->GetObject3D(); + if ( !anObject3D.IsNull() ) + createObject( aGuiObj, anObject3D, "", false ); + +#ifdef DEB_GROUPS + HYDROData_SequenceOfObjects anObjGroups = aGeomObj->GetGroups(); + buildObjectPartition( aGuiObj, anObjGroups, tr( "OBJECT_GROUPS" ), false ); +#endif + } + + ObjectKind anObjectKind = aDataObj->GetKind(); + + if ( anObjectKind == KIND_IMAGE ) + { + Handle(HYDROData_Image) anImageObj = + Handle(HYDROData_Image)::DownCast( aDataObj ); + for ( int anIndex = 0, aNbRef = anImageObj->NbReferences(); anIndex < aNbRef; anIndex++ ) + { + Handle(HYDROData_Entity) aRefObj = anImageObj->Reference( anIndex ); + if ( !aRefObj.IsNull() && !aRefObj->IsRemoved() ) + createObject( aGuiObj, aRefObj, aGuiObj->entry(), false ); + } + } + else if ( anObjectKind == KIND_IMMERSIBLE_ZONE ) + { + Handle(HYDROData_ImmersibleZone) aZoneObj = + Handle(HYDROData_ImmersibleZone)::DownCast( aDataObj ); + + LightApp_DataObject* aPolylineSect = + createObject( aGuiObj, tr( "ZONE_POLYLINE" ), aGuiObj->entry() ); + + Handle(HYDROData_PolylineXY) aPolyline = aZoneObj->GetPolyline(); + if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() ) + createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false ); + + LightApp_DataObject* aBathSect = + createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() ); + + Handle(HYDROData_IAltitudeObject) anAltitudeObj = aZoneObj->GetAltitudeObject(); + if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() ) + createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false ); + } + else if ( anObjectKind == KIND_POLYLINE ) + { + Handle(HYDROData_Polyline3D) aPolyline3D = + Handle(HYDROData_Polyline3D)::DownCast( aDataObj ); + + LightApp_DataObject* aPolylineSect = + createObject( aGuiObj, tr( "POLYLINE3D_POLYLINE" ), aGuiObj->entry() ); + + Handle(HYDROData_PolylineXY) aPolylineXY = aPolyline3D->GetPolylineXY(); + if ( !aPolylineXY.IsNull() && !aPolylineXY->IsRemoved() ) + createObject( aPolylineSect, aPolylineXY, aGuiObj->entry(), false ); + + LightApp_DataObject* aProfileSect = + createObject( aGuiObj, tr( "POLYLINE3D_PROFILE" ), aGuiObj->entry() ); + + Handle(HYDROData_ProfileUZ) aProfileUZ = aPolyline3D->GetProfileUZ(); + if ( aProfileUZ.IsNull() || aProfileUZ->IsRemoved() ) + aProfileUZ = aPolyline3D->GetChildProfileUZ( false ); + + if ( !aProfileUZ.IsNull() && !aProfileUZ->IsRemoved() ) + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aProfileUZ->GetFatherObject() ); + if ( !aProfile.IsNull() && !aProfile->IsRemoved() ) + createObject( aProfileSect, aProfile, aGuiObj->entry(), false ); + } + + LightApp_DataObject* aBathSect = + createObject( aGuiObj, tr( "POLYLINE3D_BATHYMETRY" ), aGuiObj->entry() ); + + Handle(HYDROData_IAltitudeObject) anAltitudeObj = aPolyline3D->GetAltitudeObject(); + if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() ) + createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false ); + } + else if ( anObjectKind == KIND_CALCULATION ) + { + Handle(HYDROData_CalculationCase) aCaseObj = + Handle(HYDROData_CalculationCase)::DownCast( aDataObj ); + + LightApp_DataObject* aPolylineSect = + createObject( aGuiObj, tr( "CASE_BOUNDARY" ), aGuiObj->entry() ); + + Handle(HYDROData_PolylineXY) aPolyline = aCaseObj->GetBoundaryPolyline(); + if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() ) + createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false ); + + LightApp_DataObject* aCaseAOSect = + createObject( aGuiObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ), + aGuiObj->entry() ); + LightApp_DataObject* aCaseNOSect = + createObject( aGuiObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ), + aGuiObj->entry() ); + + HYDROData_SequenceOfObjects aSeq = aCaseObj->GetGeometryObjects(); + HYDROData_SequenceOfObjects::Iterator aGOIter( aSeq ); + Handle(HYDROData_Entity) anEntity; + Handle(HYDROData_ArtificialObject) anAObject; + Handle(HYDROData_NaturalObject) aNObject; + for ( ; aGOIter.More(); aGOIter.Next() ) + { + anEntity = aGOIter.Value(); + if ( anEntity.IsNull() ) + continue; + anAObject = Handle(HYDROData_ArtificialObject)::DownCast( anEntity ); + if ( !anAObject.IsNull() ) + createObject( aCaseAOSect, anAObject, aGuiObj->entry(), false ); + else + { + aNObject = Handle(HYDROData_NaturalObject)::DownCast( anEntity ); + if ( !aNObject.IsNull() ) + createObject( aCaseNOSect, aNObject, aGuiObj->entry(), false ); + } + } + LightApp_DataObject* aCaseRegionsSect = + createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() ); + + HYDROData_SequenceOfObjects aCaseRegions = aCaseObj->GetRegions(); + HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Region) aCaseRegion = + Handle(HYDROData_Region)::DownCast( anIter.Value() ); + if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() ) + createRegion( aCaseRegionsSect, aCaseRegion, "", true, theIsInOperation ); + } + +#ifdef DEB_GROUPS + HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetGeometryGroups(); + buildObjectPartition( aGuiObj, aCalcGroups, tr( "OBJECT_GROUPS" ), false ); + + HYDROData_SequenceOfObjects aCalcSplitGroups = aCaseObj->GetSplittedGroups(); + buildObjectPartition( aGuiObj, aCalcSplitGroups, tr( "CASE_SPLITTED_GROUPS" ), false ); +#endif + + } + else if ( anObjectKind == KIND_REGION ) + { + Handle(HYDROData_Region) aRegionObj = + Handle(HYDROData_Region)::DownCast( aDataObj ); + + HYDROData_SequenceOfObjects aRegionZones = aRegionObj->GetZones(); + HYDROData_SequenceOfObjects::Iterator anIter( aRegionZones ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Zone) aRegionZone = + Handle(HYDROData_Zone)::DownCast( anIter.Value() ); + if( !aRegionZone.IsNull() && !aRegionZone->IsRemoved() ) + createZone( aGuiObj, aRegionZone, "", true, theIsInOperation ); + } + } + else if ( anObjectKind == KIND_PROFILE ) + { + Handle(HYDROData_Profile) aProfileObj = + Handle(HYDROData_Profile)::DownCast( aDataObj ); + + aGuiObj->setIsValid( aProfileObj->IsValid() ); + } + else if ( anObjectKind == KIND_CHANNEL || anObjectKind == KIND_DIGUE ) + { + Handle(HYDROData_Channel) aChannelObj = + Handle(HYDROData_Channel)::DownCast( aDataObj ); + + LightApp_DataObject* aGuideLineSect = + createObject( aGuiObj, tr( "CHANNEL_GUIDE_LINE" ), aGuiObj->entry() ); + Handle(HYDROData_Polyline3D) aGuideLine = aChannelObj->GetGuideLine(); + if ( !aGuideLine.IsNull() && !aGuideLine->IsRemoved() ) { + createObject( aGuideLineSect, aGuideLine, aGuiObj->entry(), false ); + } + + LightApp_DataObject* aProfileSect = + createObject( aGuiObj, tr( "CHANNEL_PROFILE" ), aGuiObj->entry() ); + Handle(HYDROData_Profile) aProfile = aChannelObj->GetProfile(); + if ( !aProfile.IsNull() && !aProfile->IsRemoved() ) { + createObject( aProfileSect, aProfile, aGuiObj->entry(), false ); + } + } + else if ( anObjectKind == KIND_STREAM ) + { + Handle(HYDROData_Stream) aStreamObj = + Handle(HYDROData_Stream)::DownCast( aDataObj ); + + LightApp_DataObject* aHydraulicAxisSect = + createObject( aGuiObj, tr( "STREAM_HYDRAULIC_AXIS" ), aGuiObj->entry() ); + Handle(HYDROData_PolylineXY) aHydraulicAxis = aStreamObj->GetHydraulicAxis(); + if ( !aHydraulicAxis.IsNull() && !aHydraulicAxis->IsRemoved() ) { + createObject( aHydraulicAxisSect, aHydraulicAxis, aGuiObj->entry(), false ); + } + + HYDROData_SequenceOfObjects aProfiles = aStreamObj->GetProfiles(); + buildObjectPartition( aGuiObj, aProfiles, tr( "STREAM_PROFILES" ), true ); + } +} + +void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase ) +{ + if ( !theCase.IsNull() ) + { + if ( theParent ) + { + // Remove previous objects tree + DataObjectList aList; + theParent->children( aList ); + QListIterator anIter( aList ); + while( anIter.hasNext() ) + removeChild( theParent, anIter.next() ); + } + + new HYDROGUI_DropTargetObject( theParent, tr( "NEW_REGION" ), "", true ); + + HYDROData_SequenceOfObjects aCaseRegions = theCase->GetRegions(); + HYDROData_SequenceOfObjects::Iterator anIter( aCaseRegions ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Region) aCaseRegion = + Handle(HYDROData_Region)::DownCast( anIter.Value() ); + if( !aCaseRegion.IsNull() && !aCaseRegion->IsRemoved() ) + createRegion( theParent, aCaseRegion, "", true, true ); + } + } +} + +void HYDROGUI_DataModel::updateObjectTree( Handle(HYDROData_Entity)& theObj ) +{ + if ( !theObj.IsNull() ) + { + HYDROGUI_DataObject* aGuiObj = dynamic_cast( + findObject( HYDROGUI_DataObject::dataObjectEntry( theObj ) ) ); + if ( aGuiObj ) + { + // Remove previous objects tree + DataObjectList aList; + aGuiObj->children( aList ); + QListIterator anIter( aList ); + while( anIter.hasNext() ) + removeChild( aGuiObj, anIter.next() ); + + // Rebuild the subtree + QString aParentEntry; + HYDROGUI_DataObject* aParent = dynamic_cast( aGuiObj->parent() ); + if ( aParent ) + { + aParentEntry = aParent->entry(); + } + buildObjectTree( aParent, aGuiObj, aParentEntry, aGuiObj->isInOperation() ); + } + else + { + // workaround for the bug in SalomeApp_Study::findObjectByEntry - it can't find LightApp_DataObjects + HYDROGUI_Module* aModule = dynamic_cast( module() ); + if( aModule ) + { + aModule->getApp()->updateObjectBrowser(); + } + } + } } void HYDROGUI_DataModel::removeChild( SUIT_DataObject* theParent, @@ -443,3 +1032,55 @@ SUIT_DataObject* HYDROGUI_DataModel::findChildByName( const SUIT_DataObject* the } return NULL; // not found } + +bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theCase, + const QList& theZonesList ) +{ + bool isOk = !theCase.IsNull(); + if ( isOk ) + { + Handle(HYDROData_Region) aRegion; + Handle(HYDROData_Zone) aZone; + for (int i = 0; i < theZonesList.length(); i++ ) + { + aZone = Handle(HYDROData_Zone)::DownCast( theZonesList.at(i)->modelObject() ); + if ( !aZone.IsNull() ) + { + if ( aRegion.IsNull() ) + { + aRegion = theCase->AddNewRegion( aZone ); + isOk = !aRegion.IsNull(); + } + else + { + if ( !( aRegion->AddZone( aZone ) ) ) + { + isOk = false; + } + } + } + } + } + return isOk; +} + +bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName ) +{ + if ( theName.isEmpty() ) + return false; + + try + { + getDocument()->StartOperation(); + theEntity->SetName( theName ); + getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) ); + module()->application()->activeStudy()->Modified(); + } + catch ( Standard_Failure ) + { + getDocument()->AbortOperation(); + return false; + } + return true; +} +