#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 <HYDROData_River.h>
#include <HYDROData_Stream.h>
#include <HYDROData_StricklerTable.h>
+#include <HYDROData_LandCoverMap.h>
+#include <HYDROData_BCPolygon.h>
#include <CAM_Module.h>
#include <CAM_Study.h>
#include <SUIT_Study.h>
#include <SUIT_Tools.h>
#include <SUIT_TreeSync.h>
+#include <SUIT_DataObjectIterator.h>
#include <HYDROData_Document.h>
{
}
+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 )
{
res = DocError_UnknownProblem;
}
- if( res != DocError_OK )
+
+ if ( res != DocError_OK )
{
module()->application()->putInfo( tr( "LOAD_ERROR" ) );
return false;
}
- if( !aStatesFullPath.isEmpty() )
+ if ( !aStatesFullPath.isEmpty() )
{
QFile aFile( aStatesFullPath );
if( aFile.open( QFile::ReadOnly ) )
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;
QString aTmpDir;
SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
bool isMultiFile = false;
- if( resMgr )
+ if ( resMgr )
isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
// save module data to temporary files
bool HYDROGUI_DataModel::close()
{
+ HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
+ if ( aModule )
+ aModule->clearCache();
return true;
}
// Create root objects:
// IMAGES
- LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toAscii() ) );
+ LightApp_DataObject* anImageRootObj = createObject( aNewRootObj, tr( partitionName( KIND_IMAGE ).toLatin1() ) );
// BATHYMETRY
- LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toAscii() ) );
+ LightApp_DataObject* aBathymetryRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BATHYMETRY ).toLatin1() ) );
- // ARTIFICIAL OBJECTS
- LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, 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( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ) );
+ LightApp_DataObject* aNaturalObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_NATURAL_OBJECT ).toLatin1() ) );
- // OBSTACLES
- LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toAscii() ) );
+ // ARTIFICIAL OBJECTS
+ LightApp_DataObject* anArtificialObjectsRootObj = createObject( aNewRootObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toLatin1() ) );
- // STRICKLER TABLES
- LightApp_DataObject* aStricklerTablesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_STRICKLER_TABLE ).toAscii() ) );
+ // OBSTACLES
+ LightApp_DataObject* anObstaclesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_OBSTACLE ).toLatin1() ) );
- // CALCULATION CASES
- LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toAscii() ) );
+ //BC Polygons
+ LightApp_DataObject* aBCPolygonRootObj = createObject( aNewRootObj, tr( partitionName( KIND_BC_POLYGON ).toLatin1() ) );
- // POLYLINES
- LightApp_DataObject* aPolylineRootObj = createObject( aNewRootObj, tr( partitionName( KIND_POLYLINEXY ).toAscii() ) );
+ // STRICKLER TABLES
+ LightApp_DataObject* aStricklerTablesRootObj = createObject( aNewRootObj, tr( partitionName( KIND_STRICKLER_TABLE ).toLatin1() ) );
- // POLYLINES
- LightApp_DataObject* aPolyline3DRootObj = createObject( aNewRootObj, 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( aNewRootObj, tr( partitionName( KIND_PROFILE ).toAscii() ) );
+ // CALCULATION CASES
+ LightApp_DataObject* aCalculRootObj = createObject( aNewRootObj, tr( partitionName( KIND_CALCULATION ).toLatin1() ) );
// VISUAL STATES
- LightApp_DataObject* aVisualStateRootObj = createObject( aNewRootObj, 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() ) {
+ std::vector<Handle(HYDROData_Entity)> 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 = anIterator.Current();
+ Handle(HYDROData_Entity) anObj = ents[i];
if ( !anObj.IsNull() )
{
}
case KIND_STRICKLER_TABLE:
{
- Handle(HYDROData_StricklerTable) anStricklerTableObj =
+ Handle(HYDROData_StricklerTable) aStricklerTableObj =
Handle(HYDROData_StricklerTable)::DownCast( anObj );
- if( !anStricklerTableObj.IsNull() ) {
- obj = createObject( aStricklerTablesRootObj, anStricklerTableObj );
+ 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;
+ }
case KIND_CALCULATION:
{
Handle(HYDROData_CalculationCase) aCalculObj =
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;
}
}
// anObjectBrowser->openLevels();
//}
- HYDROGUI_DataModelSync aSync( aNewRootObj );
SUIT_DataObject* aRoot = root();
+
+ if (aRoot)
+ {
+ std::map<std::string, SUIT_DataObject*> entry2ObjNewRoot;
+ SUIT_DataObjectIterator::DetourType dt = SUIT_DataObjectIterator::DepthLeft;
+ for ( SUIT_DataObjectIterator it( aNewRootObj, dt ); it.current(); ++it )
+ {
+ LightApp_DataObject* aCurObjN = dynamic_cast<LightApp_DataObject*>(it.current());
+ if (aCurObjN)
+ entry2ObjNewRoot[aCurObjN->entry().toStdString()] = it.current();
+ }
+
+ for ( SUIT_DataObjectIterator it( aRoot, dt ); it.current(); ++it )
+ {
+ LightApp_DataObject* aCurObjO = dynamic_cast<LightApp_DataObject*>(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<std::string, SUIT_DataObject*> newNode2Entries;
+ for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it )
+ {
+ SUIT_DataObject* cc = *it;
+ LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(cc);
+ newNode2Entries[obj->entry().toStdString()] = cc;
+ newNode->removeChild(cc);
+ }
+ //
+ std::set<SUIT_DataObject*> 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<LightApp_DataObject*>(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<std::string> entries2, entries1;
+ for ( DataObjectList::const_iterator it = newchildren2.begin(); it != newchildren2.end(); ++it )
+ entries2.insert((dynamic_cast<LightApp_DataObject*>(*it))->entry().toStdString());
+ for ( DataObjectList::const_iterator it = newchildren.begin(); it != newchildren.end(); ++it )
+ entries1.insert((dynamic_cast<LightApp_DataObject*>(*it))->entry().toStdString());
+ assert(entries1 == entries2);
+ }
+ }
+ }
+ }
+ }
+
+ HYDROGUI_DataModelSync aSync( aNewRootObj );
bool isNewDoc = aRoot==0;
if( isNewDoc )
aRoot = createRootModuleObject( aStudyRoot );
if ( !myStates.isEmpty() )
{
ob->updateTree();
- ob->setOpenStates( myStates, ENTRY_COLUMN );
+ ob->setAutoOpenLevel( 1 );
+ //ob->setOpenStates( myStates, ENTRY_COLUMN );
myStates.clear();
}
}
bool isChildObject = aKind == KIND_DUMMY_3D ||
aKind == KIND_ZONE ||
aKind == KIND_SHAPES_GROUP ||
- aKind == KIND_SPLITTED_GROUP;
+ aKind == KIND_SPLIT_GROUP;
if ( isUnrecognized || isChildObject ) {
isCanCopy = false;
break;
Handle(HYDROData_Entity) aClone = getDocument()->CreateObject( aKind );
if( !aClone.IsNull() )
{
- anObject->CopyTo( aClone );
+ anObject->CopyTo( aClone, true );
anIsChanged = true;
// remove Z layer
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();
const ObjectKind aKind = theModelObject->GetKind();
bool visibility = aKind == KIND_IMAGE || aKind == KIND_POLYLINEXY || aKind == KIND_POLYLINE ||
- aKind == KIND_SHAPES_GROUP || aKind == KIND_SPLITTED_GROUP || aKind == KIND_ZONE ||
+ 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_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 );
if ( visibility )
{
- SUIT_AbstractModel* treeModel = 0;
- LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
- if ( app )
- treeModel = dynamic_cast<SUIT_AbstractModel*>( app->objectBrowser()->model() );
-
- if ( treeModel )
- {
- HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
- bool isVisible = aModule->isObjectVisible( -1, theModelObject );
- Qtx::VisibilityState aVisState = isVisible ? Qtx::ShownState : Qtx::HiddenState;
- treeModel->setVisibilityState( aResObj->text( aResObj->customData( Qtx::IdType ).toInt() ), aVisState, false );
- }
+ setObjectVisibilityState( theModelObject, aResObj );
}
if ( theIsBuildTree )
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,
LightApp_DataObject* theParent )
{
// Create default Strickler table object
- Handle(HYDROData_StricklerTable) anStricklerTableObj =
+ Handle(HYDROData_StricklerTable) aStricklerTableObj =
Handle(HYDROData_StricklerTable)::DownCast( theDocument->CreateObject(KIND_STRICKLER_TABLE) );
- if ( !anStricklerTableObj.IsNull() )
+ if ( !aStricklerTableObj.IsNull() )
{
- anStricklerTableObj->Import( HYDROGUI_Tool::ToAsciiString( tr( "DEFAULT_STRICKLER_TABLE_FILE" ) ) );
+ 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 ( anStricklerTableObj->GetName().isEmpty() )
+ if ( aStricklerTableObj->GetName().isEmpty() )
{
HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
if ( aModule )
aStricklerTableName = HYDROGUI_Tool::GenerateObjectName( aModule, tr( "DEFAULT_STRICKLER_TABLE_NAME" ) );
}
- if ( anStricklerTableObj->GetName() != aStricklerTableName )
- anStricklerTableObj->SetName( aStricklerTableName );
+ if ( aStricklerTableObj->GetName() != aStricklerTableName )
+ aStricklerTableObj->SetName( aStricklerTableName );
- anStricklerTableObj->Update();
+ aStricklerTableObj->Update();
- LightApp_DataObject* obj = createObject( theParent, anStricklerTableObj );
+ LightApp_DataObject* obj = createObject( theParent, aStricklerTableObj );
}
}
createObject( aPolylineSect, aPolyline, aGuiObj->entry(), false );
LightApp_DataObject* aCaseAOSect =
- createObject( aGuiObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toAscii() ),
+ createObject( aGuiObj, tr( partitionName( KIND_ARTIFICIAL_OBJECT ).toLatin1() ),
aGuiObj->entry() );
LightApp_DataObject* aCaseNOSect =
- createObject( aGuiObj, tr( partitionName( KIND_NATURAL_OBJECT ).toAscii() ),
+ createObject( aGuiObj, tr( partitionName( KIND_NATURAL_OBJECT ).toLatin1() ),
aGuiObj->entry() );
HYDROData_SequenceOfObjects aSeq = aCaseObj->GetGeometryObjects();
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() );
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 );
+ HYDROData_SequenceOfObjects aCalcSplitGroups = aCaseObj->GetSplitGroups();
+ buildObjectPartition( aGuiObj, aCalcSplitGroups, tr( "CASE_SPLIT_GROUPS" ), false );
#endif
}
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<HYDROGUI_Module*>( module() );
+ if( aModule )
+ aModule->enableLCMActions();
+
}
void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase )
}
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<LightApp_Application*>( module()->application() );
+ if ( app )
+ treeModel = dynamic_cast<SUIT_AbstractModel*>( app->objectBrowser()->model() );
+
+ if ( treeModel )
+ {
+ HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( 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 );
+ }
+}