X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_DataModel.cxx;h=bfb64ec4535a95ce647f323b26071d8775a58850;hb=60c1b803621af637e863bf91a54f59251a28552c;hp=084fab39315e0a7b4468ff2b3ef3768ab9a512ab;hpb=d55359a277a283cc2c204de55739fa8aa3acb085;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index 084fab39..bfb64ec4 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.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 @@ -25,11 +21,13 @@ #include "HYDROGUI_DataObject.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" +#include "HYDROGUI_Tool2.h" #include "HYDROGUI_Zone.h" #include "HYDROGUI_Region.h" #include #include +#include #include #include #include @@ -46,9 +44,10 @@ #include #include #include +#include +#include +#include -#include -#include #include #include @@ -56,11 +55,12 @@ #include #include -#include #include #include #include #include +#include +#include #include @@ -72,11 +72,14 @@ // #define DEB_GROUPS 1 #ifdef DEB_GROUPS -#include +#include #endif static HYDROData_SequenceOfObjects myCopyingObjects; +const int ENTRY_COLUMN = 2; + + HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule ) : LightApp_DataModel( theModule ) { @@ -87,6 +90,14 @@ HYDROGUI_DataModel::~HYDROGUI_DataModel() { } +bool HYDROGUI_DataModel::create( CAM_Study* theStudy ) +{ + bool status = LightApp_DataModel::create( theStudy ); + if ( status ) + updateDocument(); + return status; +} + bool HYDROGUI_DataModel::open( const QString& theURL, CAM_Study* theStudy, QStringList theFileList ) @@ -95,32 +106,47 @@ bool HYDROGUI_DataModel::open( const QString& theURL, const int aStudyId = theStudy->id(); Data_DocError res = DocError_UnknownProblem; - if( theFileList.count() == 2 ) + if( theFileList.count() >= 2 ) { QString aTmpDir = theFileList[0]; - QString aFileName = theFileList[1]; + QString aDataFileName = theFileList[1]; + QString aStatesFileName = theFileList.count() == 3 ? theFileList[2] : ""; myStudyURL = theURL; - QString aFullPath = SUIT_Tools::addSlash( aTmpDir ) + aFileName; + QString aDataFullPath = SUIT_Tools::addSlash( aTmpDir ) + aDataFileName; + QString aStatesFullPath = aStatesFileName.isEmpty() ? "" : SUIT_Tools::addSlash( aTmpDir ) + aStatesFileName; try { - res = HYDROData_Document::Load( (char*)aFullPath.toLatin1().constData(), aStudyId ); + res = HYDROData_Document::Load( (char*)aDataFullPath.toLatin1().constData(), aStudyId ); } catch(...) { res = DocError_UnknownProblem; } - if( res != DocError_OK ) + + if ( res != DocError_OK ) { module()->application()->putInfo( tr( "LOAD_ERROR" ) ); return false; } + + if ( !aStatesFullPath.isEmpty() ) + { + QFile aFile( aStatesFullPath ); + if( aFile.open( QFile::ReadOnly ) ) + { + myStates = aFile.readAll(); + aFile.close(); + } + } + + updateDocument(); } // if the document open was successful, the data model update happens // in the set mode of the module - if( res == DocError_OK ) + if ( res == DocError_OK ) update( aStudyId ); return true; @@ -134,27 +160,41 @@ bool HYDROGUI_DataModel::save( QStringList& theFileList ) LightApp_DataModel::save( theFileList ); QString aTmpDir; - QString aFileName; SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr(); bool isMultiFile = false; - if( resMgr ) + if ( resMgr ) isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ); - // save data to temporary files + // save module data to temporary files LightApp_Study* aStudy = dynamic_cast( module()->application()->activeStudy() ); aTmpDir = aStudy->GetTmpDir( myStudyURL.toLatin1().constData(), isMultiFile ).c_str(); - aFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf"; - - QString aFullPath = aTmpDir + aFileName; - Data_DocError res = getDocument()->Save( (char*)aFullPath.toLatin1().constData() ); + + // save OCAF data to a temporary file + QString aDataFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO.cbf"; + QString aDataFullPath = aTmpDir + aDataFileName; + Data_DocError res = getDocument()->Save( (char*)aDataFullPath.toLatin1().constData() ); if( res != DocError_OK ) { module()->application()->putInfo( tr( "SAVE_ERROR" ) ); return false; } + // save tree state data to a temporary file + LightApp_Application* anApp = dynamic_cast( module()->application() ); + QByteArray aStatesData = anApp->objectBrowser()->getOpenStates( ENTRY_COLUMN ); + QString aStatesFileName = SUIT_Tools::file( myStudyURL, false ) + "_HYDRO_tree_states.txt"; + QString aStatesFullPath = aTmpDir + aStatesFileName; + QFile aFile( aStatesFullPath ); + if( aFile.open( QFile::WriteOnly ) ) + { + aFile.write( aStatesData ); + aFile.close(); + } + + // add temporary files to the list theFileList.append( aTmpDir ); - theFileList.append( aFileName ); + theFileList.append( aDataFileName ); + theFileList.append( aStatesFileName ); return true; } @@ -169,6 +209,9 @@ bool HYDROGUI_DataModel::saveAs( const QString& theURL, bool HYDROGUI_DataModel::close() { + HYDROGUI_Module* aModule = dynamic_cast( module() ); + if ( aModule ) + aModule->clearCache(); return true; } @@ -186,13 +229,13 @@ bool HYDROGUI_DataModel::dumpPython( const QString& theURL, if ( aDocument.IsNull() || !aStudy ) return false; - QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str(); - aFileToExport += QString( QDir::separator() ) + "HYDRO.py"; - - bool aRes = aDocument->DumpToPython( aFileToExport ); + QString aDir = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str(); + QString aFileToExport = aDir + QString( QDir::separator() ) + "HYDRO.py"; + bool aRes = aDocument->DumpToPython( aFileToExport, isMultiFile ); if ( aRes ) { + theListOfFiles.append( aDir ); theListOfFiles.append( aFileToExport ); } @@ -219,19 +262,8 @@ 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() ) @@ -240,38 +272,57 @@ void HYDROGUI_DataModel::update( const int theStudyId ) // Create root objects: // IMAGES - LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) ); + LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toLatin1() ) ); // BATHYMETRY - LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) ); + LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toLatin1() ) ); - // ARTIFICIAL OBJECTS - LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) ); + // POLYLINES + LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toLatin1() ) ); + + // PROFILES + LightApp_DataObject* aProfileRootObj = createObject( aNewRootObj, tr( partitionName( KIND_PROFILE ).toLatin1() ) ); + + // POLYLINES 3D + LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINE ).toLatin1() ) ); // NATURAL OBJECTS - LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) ); + LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toLatin1() ) ); + + // ARTIFICIAL OBJECTS + LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toLatin1() ) ); // OBSTACLES - LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) ); + LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toLatin1() ) ); - // CALCULATION CASES - LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) ); + //BC Polygons + LightApp_DataObject* aBCPolygonRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BC_POLYGON ).toLatin1() ) ); - // POLYLINES - LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) ); + // STRICKLER TABLES + LightApp_DataObject* aStricklerTablesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_STRICKLER_TABLE ).toLatin1() ) ); - // POLYLINES - LightApp_DataObject* aPolyline3DRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) ); + // LAND COVER MAPS + LightApp_DataObject* aLandCoversRootObj = createObject( aNewRootObj, tr( partitionName( KIND_LAND_COVER_MAP ).toLatin1() ) ); - // PROFILES - LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) ); + // CALCULATION CASES + LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toLatin1() ) ); // VISUAL STATES - LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) ); + LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toLatin1() ) ); + + + int aNoStricklerTableObj = 0; HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN ); - for( ; anIterator.More(); anIterator.Next() ) { - Handle(HYDROData_Entity) anObj = anIterator.Current(); + std::vector ents; + + for( ; anIterator.More(); anIterator.Next() ) + ents.push_back(anIterator.Current()); + + for (int i = 0; i< ents.size();i++) + { + LightApp_DataObject* obj = 0; + Handle(HYDROData_Entity) anObj = ents[i]; if ( !anObj.IsNull() ) { @@ -281,7 +332,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anObj ); if( !anImageObj.IsNull() ) { - createObject( anImageRootObj, anImageObj ); + obj = createObject( anImageRootObj, anImageObj ); } break; @@ -291,7 +342,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Bathymetry) aBathymetryObj = Handle(HYDROData_Bathymetry)::DownCast( anObj ); if( !aBathymetryObj.IsNull() ) { - createObject( aBathymetryRootObj, aBathymetryObj ); + obj = createObject( aBathymetryRootObj, aBathymetryObj ); } break; @@ -301,7 +352,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Channel) aChannelObj = Handle(HYDROData_Channel)::DownCast( anObj ); if( !aChannelObj.IsNull() ) { - createObject( anArtificialObjectsRootObj, aChannelObj ); + obj = createObject( anArtificialObjectsRootObj, aChannelObj ); } break; @@ -311,7 +362,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Digue) aDigueObj = Handle(HYDROData_Digue)::DownCast( anObj ); if( !aDigueObj.IsNull() ) { - createObject( anArtificialObjectsRootObj, aDigueObj ); + obj = createObject( anArtificialObjectsRootObj, aDigueObj ); } break; @@ -321,7 +372,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_ImmersibleZone) anImmersibleZoneObj = Handle(HYDROData_ImmersibleZone)::DownCast( anObj ); if( !anImmersibleZoneObj.IsNull() ) { - createObject( aNaturalObjectsRootObj, anImmersibleZoneObj ); + obj = createObject( aNaturalObjectsRootObj, anImmersibleZoneObj ); } break; @@ -331,7 +382,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_River) aRiverObj = Handle(HYDROData_River)::DownCast( anObj ); if( !aRiverObj.IsNull() ) { - createObject( aNaturalObjectsRootObj, aRiverObj ); + obj = createObject( aNaturalObjectsRootObj, aRiverObj ); } break; @@ -341,7 +392,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Stream) aStreamObj = Handle(HYDROData_Stream)::DownCast( anObj ); if( !aStreamObj.IsNull() ) { - createObject( aNaturalObjectsRootObj, aStreamObj ); + obj = createObject( aNaturalObjectsRootObj, aStreamObj ); } break; @@ -351,7 +402,28 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Obstacle) anObstacleObj = Handle(HYDROData_Obstacle)::DownCast( anObj ); if( !anObstacleObj.IsNull() ) { - createObject( anObstaclesRootObj, anObstacleObj ); + obj = createObject( anObstaclesRootObj, anObstacleObj ); + } + + break; + } + case KIND_STRICKLER_TABLE: + { + Handle(HYDROData_StricklerTable) aStricklerTableObj = + Handle(HYDROData_StricklerTable)::DownCast( anObj ); + if( !aStricklerTableObj.IsNull() ) { + obj = createObject( aStricklerTablesRootObj, aStricklerTableObj ); + } + aNoStricklerTableObj++; + + break; + } + case KIND_LAND_COVER_MAP: + { + Handle(HYDROData_LandCoverMap) aLandCoverMapObj = + Handle(HYDROData_LandCoverMap)::DownCast( anObj ); + if( !aLandCoverMapObj.IsNull() ) { + obj = createObject( aLandCoversRootObj, aLandCoverMapObj ); } break; @@ -361,7 +433,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_CalculationCase) aCalculObj = Handle(HYDROData_CalculationCase)::DownCast( anObj ); if( !aCalculObj.IsNull() ) { - createObject( aCalculRootObj, aCalculObj ); + obj = createObject( aCalculRootObj, aCalculObj ); } break; @@ -371,7 +443,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_PolylineXY) aPolylineObj = Handle(HYDROData_PolylineXY)::DownCast( anObj ); if( !aPolylineObj.IsNull() ) { - createObject( aPolylineRootObj, aPolylineObj ); + obj = createObject( aPolylineRootObj, aPolylineObj ); } break; @@ -381,7 +453,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Polyline3D) aPolylineObj = Handle(HYDROData_Polyline3D)::DownCast( anObj ); if( !aPolylineObj.IsNull() ) { - createObject( aPolyline3DRootObj, aPolylineObj ); + obj = createObject( aPolyline3DRootObj, aPolylineObj ); } break; @@ -391,7 +463,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_Profile) aProfileObj = Handle(HYDROData_Profile)::DownCast( anObj ); if( !aProfileObj.IsNull() ) { - createObject( aProfileRootObj, aProfileObj ); + obj = createObject( aProfileRootObj, aProfileObj ); } break; @@ -401,7 +473,17 @@ void HYDROGUI_DataModel::update( const int theStudyId ) Handle(HYDROData_VisualState) aVisualStateObj = Handle(HYDROData_VisualState)::DownCast( anObj ); if( !aVisualStateObj.IsNull() ) { - createObject( aVisualStateRootObj, aVisualStateObj ); + obj = createObject( aVisualStateRootObj, aVisualStateObj ); + } + + break; + } + case KIND_BC_POLYGON: + { + Handle(HYDROData_BCPolygon) aBCPolygonObj = + Handle(HYDROData_BCPolygon)::DownCast( anObj ); + if( !aBCPolygonObj.IsNull() ) { + obj = createObject( aBCPolygonRootObj, aBCPolygonObj ); } break; @@ -410,16 +492,111 @@ void HYDROGUI_DataModel::update( const int theStudyId ) } } - if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() ) + // Create default Strickler table object + if ( aNoStricklerTableObj == 0 ) + createDefaultStricklerTable( aDocument, aStricklerTablesRootObj ); + + //if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() ) + //{ + // anObjectBrowser->setAutoOpenLevel( 3 ); + // anObjectBrowser->openLevels(); + //} + + SUIT_DataObject* aRoot = root(); + + if (aRoot) + { + std::map entry2ObjNewRoot; + SUIT_DataObjectIterator::DetourType dt = SUIT_DataObjectIterator::DepthLeft; + for ( SUIT_DataObjectIterator it( aNewRootObj, dt ); it.current(); ++it ) + { + LightApp_DataObject* aCurObjN = dynamic_cast(it.current()); + if (aCurObjN) + entry2ObjNewRoot[aCurObjN->entry().toStdString()] = it.current(); + } + + for ( SUIT_DataObjectIterator it( aRoot, dt ); it.current(); ++it ) + { + LightApp_DataObject* aCurObjO = dynamic_cast(it.current()); + if (aCurObjO && aCurObjO->childCount() > 0) + { + std::string entry = aCurObjO->entry().toStdString(); + SUIT_DataObject* newNode = entry2ObjNewRoot[entry]; + if (newNode && aCurObjO->childCount() > 0) + { + DataObjectList newchildren; + newNode->children(newchildren); + //new root - remove children + std::map newNode2Entries; + for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it ) + { + SUIT_DataObject* cc = *it; + LightApp_DataObject* obj = dynamic_cast(cc); + newNode2Entries[obj->entry().toStdString()] = cc; + newNode->removeChild(cc); + } + // + std::set objtemp; + + DataObjectList oldchildren; + aCurObjO->children(oldchildren); + for ( DataObjectList::const_iterator it = oldchildren.begin(); it != oldchildren.end(); ++it ) + { + SUIT_DataObject* old_ch = *it; + std::string entr = dynamic_cast(old_ch)->entry().toStdString(); + if (newNode2Entries.count(entr) > 0) + { + SUIT_DataObject* obj = newNode2Entries[entr]; + newNode->appendChild(obj); + objtemp.insert(obj); + } + } + // + for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it ) + { + SUIT_DataObject* ch = *it; + if (objtemp.count(ch) == 0) + newNode->appendChild(ch); + } + { //IF DEBUG + //add. check + DataObjectList newchildren2; + newNode->children(newchildren2); + std::set entries2, entries1; + for ( DataObjectList::const_iterator it = newchildren2.begin(); it != newchildren2.end(); ++it ) + entries2.insert((dynamic_cast(*it))->entry().toStdString()); + for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it ) + entries1.insert((dynamic_cast(*it))->entry().toStdString()); + assert(entries1 == entries2); + } + } + } + } + } + + HYDROGUI_DataModelSync aSync( aNewRootObj ); + bool isNewDoc = aRoot==0; + if( isNewDoc ) + aRoot = createRootModuleObject( aStudyRoot ); + ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync > + ( aNewRootObj, aRoot, aSync ); + + SUIT_DataBrowser* ob = anApp->objectBrowser(); + + if ( !myStates.isEmpty() ) { - anObjectBrowser->setAutoOpenLevel( 3 ); - anObjectBrowser->openLevels(); + ob->updateTree(); + ob->setAutoOpenLevel( 1 ); + //ob->setOpenStates( myStates, ENTRY_COLUMN ); + myStates.clear(); } } HYDROGUI_DataObject* HYDROGUI_DataModel::getDataObject( const Handle(HYDROData_Entity)& theModelObject ) { - return NULL; // to do if necessary + HYDROGUI_DataObject* aGuiObj = dynamic_cast( + findObject( HYDROGUI_DataObject::dataObjectEntry( theModelObject ) ) ); + return aGuiObj; } HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject ) @@ -547,21 +724,25 @@ bool HYDROGUI_DataModel::redo() bool HYDROGUI_DataModel::canCopy() { HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() ); - if( aSeq.Length() != 1 ) - return false; - - Handle(HYDROData_Entity) anObject = aSeq.First(); - if( anObject.IsNull() ) - return false; - - ObjectKind aKind = anObject->GetKind(); - if( aKind == KIND_IMAGE || - aKind == KIND_POLYLINE || - aKind == KIND_PROFILE || - aKind == KIND_CALCULATION ) - return true; + bool isCanCopy = !aSeq.IsEmpty(); - return false; + 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_SPLIT_GROUP; + if ( isUnrecognized || isChildObject ) { + isCanCopy = false; + break; + } + } + } + + return isCanCopy; } bool HYDROGUI_DataModel::canPaste() @@ -594,26 +775,11 @@ bool HYDROGUI_DataModel::paste() Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind ); if( !aClone.IsNull() ) { - anObject->CopyTo( aClone ); + anObject->CopyTo( aClone, true ); anIsChanged = true; - // 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 ); + // remove Z layer + aClone->RemoveZLevel(); } } } @@ -639,6 +805,10 @@ QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind ) case KIND_OBSTACLE: return "OBSTACLES"; case KIND_ARTIFICIAL_OBJECT: return "ARTIFICIAL_OBJECTS"; case KIND_NATURAL_OBJECT: return "NATURAL_OBJECTS"; + case KIND_STRICKLER_TABLE: return "STRICKLER_TABLES"; + case KIND_LAND_COVER_MAP: return "LAND_COVER_MAPS"; + case KIND_REGION: return "REGIONS"; + case KIND_BC_POLYGON: return "BOUNDARY_POLYGONS"; default: break; } return QString(); @@ -656,7 +826,31 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* const bool theIsBuildTree ) { HYDROGUI_DataObject* aResObj = new HYDROGUI_DataObject( theParent, theModelObject, theParentEntry ); - + + const ObjectKind aKind = theModelObject->GetKind(); + bool visibility = aKind == KIND_IMAGE || aKind == KIND_POLYLINEXY || aKind == KIND_POLYLINE || + aKind == KIND_SHAPES_GROUP || aKind == KIND_SPLIT_GROUP || aKind == KIND_ZONE || + aKind == KIND_IMMERSIBLE_ZONE || aKind == KIND_REGION || aKind == KIND_BATHYMETRY || + aKind == KIND_OBSTACLE || aKind == KIND_STREAM || aKind == KIND_CHANNEL || + aKind == KIND_DIGUE || aKind == KIND_DUMMY_3D || aKind == KIND_LAND_COVER_MAP || + aKind == KIND_BC_POLYGON; + if ( !visibility ) + { + Handle(HYDROData_Profile) aProfObj = Handle(HYDROData_Profile)::DownCast( theModelObject ); + visibility = !aProfObj.IsNull() && aProfObj->IsValid(); + } + + if ( aKind == KIND_REGION ) + { + QString an = aResObj->name(); + int a = 0; + } + + if ( visibility ) + { + setObjectVisibilityState( theModelObject, aResObj ); + } + if ( theIsBuildTree ) { buildObjectTree( theParent, aResObj, theParentEntry ); @@ -684,8 +878,12 @@ LightApp_DataObject* HYDROGUI_DataModel::createZone( SUIT_DataObject* theP const bool theIsBuildTree, const bool theIsInOperation ) { - return buildObject( theParent, new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ), - theParentEntry, theIsBuildTree, theIsInOperation ); + HYDROGUI_Zone* aZone = new HYDROGUI_Zone( theParent, theModelObject, theParentEntry, theIsInOperation ); + LightApp_DataObject* aDataObj = buildObject( theParent, aZone, theParentEntry, theIsBuildTree, theIsInOperation ); + + setObjectVisibilityState( theModelObject, aZone ); + + return aDataObj; } LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParent, @@ -698,6 +896,34 @@ LightApp_DataObject* HYDROGUI_DataModel::createRegion( SUIT_DataObject* theParentEntry, theIsBuildTree, theIsInOperation ); } +void HYDROGUI_DataModel::createDefaultStricklerTable( const Handle(HYDROData_Document)& theDocument, + LightApp_DataObject* theParent ) +{ + // Create default Strickler table object + Handle(HYDROData_StricklerTable) aStricklerTableObj = + Handle(HYDROData_StricklerTable)::DownCast( theDocument->CreateObject(KIND_STRICKLER_TABLE) ); + if ( !aStricklerTableObj.IsNull() ) + { + SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr(); + QString defTablePath = resMgr->path( "resources", module()->name(), tr( "DEFAULT_STRICKLER_TABLE_FILE" ) ); + aStricklerTableObj->Import( defTablePath ); + // Set name + QString aStricklerTableName; + if ( aStricklerTableObj->GetName().isEmpty() ) + { + HYDROGUI_Module* aModule = dynamic_cast( module() ); + if ( aModule ) + aStricklerTableName = HYDROGUI_Tool::GenerateObjectName( aModule, tr( "DEFAULT_STRICKLER_TABLE_NAME" ) ); + } + if ( aStricklerTableObj->GetName() != aStricklerTableName ) + aStricklerTableObj->SetName( aStricklerTableName ); + + aStricklerTableObj->Update(); + + LightApp_DataObject* obj = createObject( theParent, aStricklerTableObj ); + } +} + LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParent, const QString& theName, const QString& theParentEntry ) @@ -705,6 +931,30 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject* theParen 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, @@ -725,21 +975,11 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, Handle(HYDROData_DummyObject3D) anObject3D = aGeomObj->GetObject3D(); if ( !anObject3D.IsNull() ) - createObject( aGuiObj, anObject3D, aGuiObj->entry(), false ); + createObject( aGuiObj, anObject3D, "", false ); #ifdef DEB_GROUPS - LightApp_DataObject* aGroupsSect = - createObject( aGuiObj, tr( "OBJECT_GROUPS" ), aGuiObj->entry() ); - HYDROData_SequenceOfObjects anObjGroups = aGeomObj->GetGroups(); - HYDROData_SequenceOfObjects::Iterator anIter( anObjGroups ); - for ( ; anIter.More(); anIter.Next() ) - { - Handle(HYDROData_EdgesGroup) anObjGroup = - Handle(HYDROData_EdgesGroup)::DownCast( anIter.Value() ); - if( !anObjGroup.IsNull() && !anObjGroup->IsRemoved() ) - createObject( aGroupsSect, anObjGroup, aGuiObj->entry(), false ); - } + buildObjectPartition( aGuiObj, anObjGroups, tr( "OBJECT_GROUPS" ), false ); #endif } @@ -771,9 +1011,9 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, LightApp_DataObject* aBathSect = createObject( aGuiObj, tr( "ZONE_BATHYMETRY" ), aGuiObj->entry() ); - Handle(HYDROData_Bathymetry) aBathymetry = aZoneObj->GetBathymetry(); - if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() ) - createObject( aBathSect, aBathymetry, aGuiObj->entry(), false ); + Handle(HYDROData_IAltitudeObject) anAltitudeObj = aZoneObj->GetAltitudeObject(); + if ( !anAltitudeObj.IsNull() && !anAltitudeObj->IsRemoved() ) + createObject( aBathSect, anAltitudeObj, aGuiObj->entry(), false ); } else if ( anObjectKind == KIND_POLYLINE ) { @@ -805,15 +1045,63 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, LightApp_DataObject* aBathSect = createObject( aGuiObj, tr( "POLYLINE3D_BATHYMETRY" ), aGuiObj->entry() ); - Handle(HYDROData_Bathymetry) aBathymetry = aPolyline3D->GetBathymetry(); - if ( !aBathymetry.IsNull() && !aBathymetry->IsRemoved() ) - createObject( aBathSect, aBathymetry, aGuiObj->entry(), false ); + 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 ).toLatin1() ), + aGuiObj->entry() ); + LightApp_DataObject* aCaseNOSect = + createObject( aGuiObj, tr( partitionName( KIND_NATURAL_OBJECT ).toLatin1() ), + 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* aBoundaryPolygonSect = + createObject( aGuiObj, tr( "CASE_BOUNDARY_POLYGONS" ), aGuiObj->entry() ); + HYDROData_SequenceOfObjects aBCPolygons = aCaseObj->GetBoundaryPolygons(); + for (int i = 1; i <= aBCPolygons.Size(); i++ ) + createObject( aBoundaryPolygonSect, aBCPolygons(i), aGuiObj->entry(), false ); + + LightApp_DataObject* aLandCoverMapSect = + createObject( aGuiObj, tr( "CASE_LAND_COVER_MAP" ), aGuiObj->entry() ); + + Handle(HYDROData_LandCoverMap) aLandCoverMap = aCaseObj->GetLandCoverMap(); + if ( !aLandCoverMap.IsNull() && !aLandCoverMap->IsRemoved() ) + createObject( aLandCoverMapSect, aLandCoverMap, aGuiObj->entry(), false ); + LightApp_DataObject* aCaseRegionsSect = createObject( aGuiObj, tr( "CASE_REGIONS" ), aGuiObj->entry() ); @@ -826,6 +1114,15 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, 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->GetSplitGroups(); + buildObjectPartition( aGuiObj, aCalcSplitGroups, tr( "CASE_SPLIT_GROUPS" ), false ); +#endif + } else if ( anObjectKind == KIND_REGION ) { @@ -849,6 +1146,70 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, 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 ); + + Handle(HYDROData_Polyline3D) aBottomPolyline = aStreamObj->GetBottomPolyline(); + if ( !aBottomPolyline.IsNull() && !aBottomPolyline->IsRemoved() ) { + createObject( aGuiObj, aBottomPolyline, aGuiObj->entry(), false ); + } + } + else if ( anObjectKind == KIND_LAND_COVER_MAP ) + { + Handle(HYDROData_LandCoverMap) aLandCoverMapObj = + Handle(HYDROData_LandCoverMap)::DownCast( aDataObj ); + + /*TODO: reference objects of the land cover map + HYDROData_SequenceOfObjects aPolylines = aLandCoverMapObj->GetPolylines(); + buildObjectPartition( aGuiObj, aPolylines, tr( "LAND_COVER_POLYLINES" ), true );*/ + } + else if ( anObjectKind == KIND_BC_POLYGON ) + { + Handle(HYDROData_BCPolygon) aBCObj = + Handle(HYDROData_BCPolygon)::DownCast( aDataObj ); + + LightApp_DataObject* aPolylineSect = + createObject( aGuiObj, tr( "BC_POLYGON_POLYLINE" ), aGuiObj->entry() ); + + Handle(HYDROData_PolylineXY) aPolyline = aBCObj->GetPolyline(); + if ( !aPolyline.IsNull() && !aPolyline->IsRemoved() ) + createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false ); + } + HYDROGUI_Module* aModule = dynamic_cast( module() ); + if( aModule ) + aModule->enableLCMActions(); + } void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase ) @@ -988,3 +1349,28 @@ bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QStri return true; } +void HYDROGUI_DataModel::updateDocument() +{ + // Sets the default strickler coefficient from preferences to document. + Handle(HYDROData_Document) aDoc = getDocument(); + SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr(); + if ( resMgr && !aDoc.IsNull() ) + aDoc->SetDefaultStricklerCoefficient( resMgr->doubleValue( "preferences", "default_strickler_coefficient", 0 ) ); +} + +void HYDROGUI_DataModel::setObjectVisibilityState( Handle(HYDROData_Entity) theModelObject, + HYDROGUI_DataObject* theObject ) +{ + SUIT_AbstractModel* treeModel = 0; + LightApp_Application* app = dynamic_cast( module()->application() ); + if ( app ) + treeModel = dynamic_cast( app->objectBrowser()->model() ); + + if ( treeModel ) + { + HYDROGUI_Module* aModule = dynamic_cast( module() ); + bool isVisible = aModule->isObjectVisible( -1, theModelObject ); + Qtx::VisibilityState aVisState = isVisible ? Qtx::ShownState : Qtx::HiddenState; + treeModel->setVisibilityState( theObject->text( theObject->customData( Qtx::IdType ).toInt() ), aVisState, false ); + } +}