-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015 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
// 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
#include <HYDROData_Bathymetry.h>
#include <HYDROData_CalculationCase.h>
+#include <HYDROGUI_DataModelSync.h>
#include <HYDROData_Document.h>
#include <HYDROData_DummyObject3D.h>
#include <HYDROData_Image.h>
#include <HYDROData_River.h>
#include <HYDROData_Stream.h>
-#include <CAM_Application.h>
-#include <CAM_DataObject.h>
#include <CAM_Module.h>
#include <CAM_Study.h>
#include <LightApp_DataObject.h>
#include <LightApp_Study.h>
-#include <SUIT_DataObject.h>
#include <SUIT_DataBrowser.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_Study.h>
#include <SUIT_Tools.h>
+#include <SUIT_TreeSync.h>
#include <HYDROData_Document.h>
static HYDROData_SequenceOfObjects myCopyingObjects;
+const int ENTRY_COLUMN = 2;
+
+
HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
: LightApp_DataModel( theModule )
{
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(...)
{
module()->application()->putInfo( tr( "LOAD_ERROR" ) );
return false;
}
+
+ if( !aStatesFullPath.isEmpty() )
+ {
+ QFile aFile( aStatesFullPath );
+ if( aFile.open( QFile::ReadOnly ) )
+ {
+ myStates = aFile.readAll();
+ aFile.close();
+ }
+ }
}
// if the document open was successful, the data model update happens
LightApp_DataModel::save( theFileList );
QString aTmpDir;
- QString aFileName;
SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
bool isMultiFile = false;
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<LightApp_Study*>( 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<LightApp_Application*>( 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;
}
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 );
}
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<SUIT_DataObject*> 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() )
// Create root objects:
// IMAGES
- LightApp_DataObject* anImageRootObj = createObject( aRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
+ LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
// BATHYMETRY
- LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
+ LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
// ARTIFICIAL OBJECTS
- LightApp_DataObject* anArtificialObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
+ LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ) );
// NATURAL OBJECTS
- LightApp_DataObject* aNaturalObjectsRootObj = createObject( aRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
+ LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
// OBSTACLES
- LightApp_DataObject* anObstaclesRootObj = createObject( aRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
+ LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
// CALCULATION CASES
- LightApp_DataObject* aCalculRootObj = createObject( aRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
+ LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
// POLYLINES
- LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
+ LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
// POLYLINES
- LightApp_DataObject* aPolyline3DRootObj = createObject( aRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
+ LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINE ).toAscii() ) );
// PROFILES
- LightApp_DataObject* aProfileRootObj = createObject( aRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
+ LightApp_DataObject* aProfileRootObj = createObject( aNewRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
// VISUAL STATES
- LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
+ LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, tr( partitionName( KIND_VISUAL_STATE ).toAscii() ) );
HYDROData_Iterator anIterator( aDocument, KIND_UNKNOWN );
for( ; anIterator.More(); anIterator.Next() ) {
}
}
- if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
+ //if( SUIT_DataBrowser* anObjectBrowser = anApp->objectBrowser() )
+ //{
+ // anObjectBrowser->setAutoOpenLevel( 3 );
+ // anObjectBrowser->openLevels();
+ //}
+
+ HYDROGUI_DataModelSync aSync( aNewRootObj );
+ SUIT_DataObject* aRoot = root();
+ bool isNewDoc = aRoot==0;
+ if( isNewDoc )
+ aRoot = createRootModuleObject( aStudyRoot );
+ ::synchronize < suitPtr, suitPtr, HYDROGUI_DataModelSync >
+ ( aNewRootObj, aRoot, aSync );
+
+
+ if( !myStates.isEmpty() )
{
- anObjectBrowser->setAutoOpenLevel( 3 );
- anObjectBrowser->openLevels();
+ LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
+ anApp->objectBrowser()->updateTree();
+ anApp->objectBrowser()->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<HYDROGUI_DataObject*>(
+ findObject( HYDROGUI_DataObject::dataObjectEntry( theModelObject ) ) );
+ return aGuiObj;
}
HYDROGUI_DataObject* HYDROGUI_DataModel::getReferencedDataObject( HYDROGUI_DataObject* theObject )
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
}
#ifdef DEB_GROUPS
- HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetSplittedGroups();
+ HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetGeometryGroups();
buildObjectPartition( aGuiObj, aCalcGroups, tr( "OBJECT_GROUPS" ), false );
HYDROData_SequenceOfObjects aCalcSplitGroups = aCaseObj->GetSplittedGroups();
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 );
+ }
}
}