Salome HOME
refs #618
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataModel.cxx
index 1eaef34b3e651d28b06e4c9486396ca7ff0fca56..88bb35b290d435bad73c6dacad67b36ae9b8a32a 100644 (file)
@@ -87,6 +87,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 )
@@ -113,13 +121,14 @@ bool HYDROGUI_DataModel::open( const QString& theURL,
     {
       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 ) )
@@ -128,11 +137,13 @@ bool HYDROGUI_DataModel::open( const QString& theURL,
         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;
@@ -148,7 +159,7 @@ bool HYDROGUI_DataModel::save( QStringList& theFileList )
   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
@@ -195,6 +206,9 @@ bool HYDROGUI_DataModel::saveAs( const QString& theURL,
 
 bool HYDROGUI_DataModel::close()
 {
+  HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
+  if ( aModule )
+      aModule->clearCache();
   return true;
 }
 
@@ -735,18 +749,7 @@ LightApp_DataObject* HYDROGUI_DataModel::createObject( SUIT_DataObject*
 
   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 )
@@ -776,8 +779,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,
@@ -1078,6 +1085,15 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent,
       createObject( aGuiObj, aBottomPolyline, aGuiObj->entry(), false );
     }
   }
+  else if ( anObjectKind == KIND_LAND_COVER )
+  {
+    Handle(HYDROData_LandCover) aLandCoverObj =
+      Handle(HYDROData_LandCover)::DownCast( aDataObj );
+
+    HYDROData_SequenceOfObjects aPolylines = aLandCoverObj->GetPolylines();
+    buildObjectPartition( aGuiObj, aPolylines, tr( "LAND_COVER_POLYLINES" ), true );
+  }
+  
 }
 
 void HYDROGUI_DataModel::buildCaseTree( SUIT_DataObject* theParent, Handle(HYDROData_CalculationCase) theCase,
@@ -1218,3 +1234,29 @@ 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<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 );
+  }
+}