Salome HOME
updated copyright message
[modules/gui.git] / src / LightApp / LightApp_DataModel.cxx
index 9fe3b086adcae75c24f3cbfe3812f1e0f818b1e7..ab900d622f556b6c99301519a1f5ab2ba9fadb34 100644 (file)
@@ -1,38 +1,37 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2023  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.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // File:      LightApp_DataModel.cxx
 // Created:   10/25/2004 10:36:06 AM
 // Author:    Sergey LITONIN
-// Copyright (C) CEA 2004
-
+//
 #include "LightApp_DataModel.h"
 #include "LightApp_Study.h"
-#include "LightApp_RootObject.h"
 #include "LightApp_DataObject.h"
 #include "LightApp_Module.h"
 #include "LightApp_Application.h"
 
-#include <OB_Browser.h>
-
-#include <SUIT_Application.h>
-#include <SUIT_ResourceMgr.h>
-#include <SUIT_Session.h>
+#include <SUIT_TreeModel.h>
+#include <SUIT_DataBrowser.h>
 #include <SUIT_DataObject.h>
 
 /*!
@@ -41,6 +40,9 @@
 LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule )
 : CAM_DataModel( theModule )
 {
+  myGroupId = 0;
+  if( module() )
+        myGroupId = qHash( module()->name() );
 }
 
 /*!
@@ -53,7 +55,7 @@ LightApp_DataModel::~LightApp_DataModel()
 /*!
   Emit opened()
 */
-bool LightApp_DataModel::open( const QString&, CAM_Study* study, QStringList )
+bool LightApp_DataModel::open( const QString&, CAM_Study*, QStringList )
 {
   emit opened(); //TODO: is it really needed? to be removed maybe...
   return true;
@@ -77,6 +79,15 @@ bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& )
   return true;
 }
 
+/*!
+  Does nothing by default. Should be redefined in light modules
+  that want to participate in "Dump study" operation.
+*/
+bool LightApp_DataModel::dumpPython( const QString&, CAM_Study*, bool, QStringList& )
+{
+  return true;
+}
+
 /*!
   Emit closed()
 */
@@ -99,7 +110,7 @@ void LightApp_DataModel::build()
 void LightApp_DataModel::updateWidgets()
 {
   LightApp_Application* app = dynamic_cast<LightApp_Application*>( module()->application() );
-  if( app )
+  if ( app && app->objectBrowser() )
     app->objectBrowser()->updateTree( 0, false );
 }
 
@@ -108,18 +119,39 @@ void LightApp_DataModel::updateWidgets()
 */
 void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* )
 {
-  LightApp_ModuleObject* modelRoot = dynamic_cast<LightApp_ModuleObject*>( root() );
+  // san: Previously modelRoot was casted to LightApp_ModuleObject*,
+  // BUT this is incorrect: in full SALOME the model root has different type.
+  // Hopefully LightApp_DataObject* is sufficient here.
+  LightApp_DataObject* modelRoot = dynamic_cast<LightApp_DataObject*>( root() );
   DataObjectList ch;
+  QMap<SUIT_DataObject*,int> aMap;
   if( modelRoot )
   {
     ch = modelRoot->children();
-    for ( DataObjectListIterator it( ch ); it.current(); ++it )
-      it.current()->setParent( 0 );
+    QListIterator<SUIT_DataObject*> it( ch );
+    while ( it.hasNext() )
+      it.next()->setParent( 0 );
   }
+
   build();
+
+  modelRoot = dynamic_cast<LightApp_DataObject*>( root() );
+  if( modelRoot )
+  {
+    DataObjectList new_ch = modelRoot->children();
+    QListIterator<SUIT_DataObject*> it1( new_ch );
+    while ( it1.hasNext() )
+      aMap.insert( it1.next(), 0 );
+  }
+
   updateWidgets();
-  for( DataObjectListIterator it( ch ); it.current(); ++it )
-    delete it.current();
+
+  QListIterator<SUIT_DataObject*> it( ch );
+  while ( it.hasNext() ) {
+    SUIT_DataObject* aDO = it.next();
+    if( !aMap.contains( aDO ) )
+      delete aDO;
+  }
 }
 
 /*!
@@ -156,3 +188,58 @@ bool LightApp_DataModel::isSaved() const
 {
   return true;
 }
+
+/*!
+  \return data model group id used for custom columns creation
+*/
+int LightApp_DataModel::groupId() const
+{
+  return myGroupId;
+}
+
+/*!
+  Register custom column in the object browser
+  \param browser - object browser where new column should be created
+  \param name - translated column name
+  \param custom_id - custom column identificator passed into data object's methods text(), icon() etc
+*/
+void LightApp_DataModel::registerColumn( SUIT_DataBrowser* browser, const QString& name, const int custom_id )
+{
+  SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( browser ? browser->model() : 0 );
+  if( m )
+    m->registerColumn( groupId(), name, custom_id );
+}
+
+/*!
+  Remove registered custom column from the object browser
+  \param browser - object browser where new column should be created
+  \param name - translated column name
+*/
+void LightApp_DataModel::unregisterColumn( SUIT_DataBrowser* browser, const QString& name )
+{
+  SUIT_AbstractModel* m = dynamic_cast<SUIT_AbstractModel*>( browser ? browser->model() : 0 );
+  if( m )
+    m->unregisterColumn( groupId(), name );
+}
+
+/*!
+  Creates the data model's root (module object) using the study services.
+  This is important because different study classes use different moduel object classes.
+  Therefore creation of the module object cannot be done at the data model level
+  where the type of the current study instance should not be known.
+  The module object returned by this method should be then passed to the model's setRoot().
+  \return the module object instance corresponding to the study type
+  \sa CAM_DataModel class
+*/
+CAM_ModuleObject* LightApp_DataModel::createModuleObject( SUIT_DataObject* theRoot ) const
+{
+  LightApp_RootObject* aStudyRoot = dynamic_cast<LightApp_RootObject*>( theRoot );
+  if ( !aStudyRoot )
+    return 0;
+
+  LightApp_Study* aStudy = aStudyRoot->study();
+  if ( aStudy )
+    return aStudy->createModuleObject( const_cast<LightApp_DataModel*>( this ), 
+                                      theRoot );
+  return 0;
+}