Salome HOME
Second integration of PV3D viewer:
[modules/gui.git] / src / SalomeApp / SalomeApp_DataModel.cxx
index 742a75e3567fa9370c4c82bb757d3224b58489ed..166ca73842b482d386c986bcd29a9b543f3a3b2e 100644 (file)
@@ -1,40 +1,37 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2024  CEA, EDF, 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:      SalomeApp_DataModel.cxx
 // Created:   10/25/2004 10:36:06 AM
 // Author:    Sergey LITONIN
-// Copyright (C) CEA 2004
 
 #include "SalomeApp_DataModel.h"
 #include "SalomeApp_Study.h"
 #include "SalomeApp_DataObject.h"
 #include "SalomeApp_Module.h"
 #include "SalomeApp_Application.h"
-#include "SalomeApp_Engine_i.hxx"
-
-#include "LightApp_RootObject.h"
 
 #include <CAM_DataObject.h>
 
-#include <SUIT_Application.h>
-#include <SUIT_ResourceMgr.h>
-#include <SUIT_Session.h>
 #include <SUIT_TreeSync.h>
 #include <SUIT_DataObjectIterator.h>
 
@@ -53,16 +50,18 @@ class SalomeApp_DataModelSync
 public:
   SalomeApp_DataModelSync( _PTR( Study ), SUIT_DataObject* );
 
-  suitPtr  createItem( const kerPtr&, const suitPtr&, const suitPtr&, const bool ) const;
-  void     deleteItemWithChildren( const suitPtr& ) const;
-  bool     isEqual( const kerPtr&, const suitPtr& ) const;
-  kerPtr   nullSrc() const;
-  suitPtr  nullTrg() const;
-  void     children( const kerPtr&, QValueList<kerPtr>& ) const;
-  void     children( const suitPtr&, QValueList<suitPtr>& ) const;
-  suitPtr  parent( const suitPtr& ) const;
-  bool     isCorrect( const kerPtr& ) const;
-  void     updateItem( const kerPtr&, const suitPtr& ) const;
+  bool           isEqual( const kerPtr&, const suitPtr& ) const;
+  kerPtr         nullSrc() const;
+  suitPtr        nullTrg() const;
+  suitPtr        createItem( const kerPtr&, const suitPtr&, const suitPtr& ) const;
+  void           updateItem( const kerPtr&, const suitPtr& ) const;
+  void           deleteItemWithChildren( const suitPtr& ) const;
+  QList<kerPtr>  children( const kerPtr& ) const;
+  QList<suitPtr> children( const suitPtr& ) const;
+  suitPtr        parent( const suitPtr& ) const;
+
+private:
+  bool           isCorrect( const kerPtr& ) const;
 
 private:
   _PTR( Study )     myStudy;
@@ -83,6 +82,10 @@ SalomeApp_DataModelSync::SalomeApp_DataModelSync( _PTR( Study ) aStudy, SUIT_Dat
 */
 bool SalomeApp_DataModelSync::isCorrect( const kerPtr& so ) const
 {
+#ifdef WITH_SALOMEDS_OBSERVER
+  // with GUI observers this function is not needed anymore
+  return true;
+#endif
   kerPtr refObj;
   QString name = so->GetName().c_str();
   _PTR( GenericAttribute ) anAttr;
@@ -104,9 +107,8 @@ bool SalomeApp_DataModelSync::isCorrect( const kerPtr& so ) const
   \param prepend - SUIT object must be added to start of children list
 */
 suitPtr SalomeApp_DataModelSync::createItem( const kerPtr& so,
-                                            const suitPtr& parent,
-                                            const suitPtr& after,
-                                            const bool prepend ) const
+                                             const suitPtr& parent,
+                                             const suitPtr& after ) const
 {
   if( !isCorrect( so ) )
     return 0;
@@ -114,23 +116,14 @@ suitPtr SalomeApp_DataModelSync::createItem( const kerPtr& so,
   _PTR(SComponent) aSComp( so );
   suitPtr nitem = aSComp ? new SalomeApp_ModuleObject( aSComp, 0 ) :
                            new SalomeApp_DataObject( so, 0 );
-  if( parent )
-    if( after )
-    {
-      DataObjectList ch;
-      parent->children( ch );
-      int pos = ch.find( after );
-      if( pos>=0 )
-       parent->insertChild( nitem, pos+1 );
-      else
-       parent->appendChild( nitem );
-    }
-    else if( prepend )
-      parent->insertChild( nitem, 0 );
-    else // append
-      parent->appendChild( nitem );
-  else if( myRoot )
+
+  if( parent ) {
+    int pos = after ? parent->childPos( after ) : 0;
+    parent->insertChild( nitem, pos+1 );
+  }
+  else if( myRoot ) {
     myRoot->appendChild( nitem );
+  }
   return nitem;
 }
 
@@ -163,7 +156,7 @@ bool SalomeApp_DataModelSync::isEqual( const kerPtr& p, const suitPtr& q ) const
   _PTR( SComponent ) aComp( p );
   bool res = ( !p && !q ) ||
              ( lobj && !sobj && aComp ) ||
-            ( sobj && isCorrect( p ) && p->GetID().c_str()==sobj->entry() );
+             ( sobj && isCorrect( p ) && p->GetID().c_str()==sobj->entry() );
   return res;
 }
 
@@ -180,7 +173,7 @@ kerPtr SalomeApp_DataModelSync::nullSrc() const
 */
 suitPtr SalomeApp_DataModelSync::nullTrg() const
 {
-  return suitPtr( 0 );
+  return 0;
 }
 
 /*!
@@ -188,12 +181,33 @@ suitPtr SalomeApp_DataModelSync::nullTrg() const
   \param obj - kernel object
   \param ch - list to be filled
 */
-void SalomeApp_DataModelSync::children( const kerPtr& obj, QValueList<kerPtr>& ch ) const
+QList<kerPtr> SalomeApp_DataModelSync::children( const kerPtr& obj ) const
 {
-  ch.clear();
-  _PTR(ChildIterator) it ( myStudy->NewChildIterator( obj ) );
-  for( ; it->More(); it->Next() )
-    ch.append( it->Value() );
+  QList<kerPtr> ch;
+
+  _PTR( GenericAttribute ) anAttr;
+  bool expandable = true;
+  if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
+    _PTR(AttributeExpandable) aAttrExp = anAttr;
+    expandable = aAttrExp->IsExpandable();
+  }
+
+  if ( expandable ) {
+    // tmp??
+    _PTR(UseCaseBuilder) aUseCaseBuilder = myStudy->GetUseCaseBuilder();
+    if (aUseCaseBuilder->HasChildren(obj)) {
+      _PTR(UseCaseIterator) it ( aUseCaseBuilder->GetUseCaseIterator( obj ) );
+      for ( ; it->More(); it->Next() )
+        ch.append( it->Value() );
+    }
+    else {
+      _PTR(ChildIterator) it ( myStudy->NewChildIterator( obj ) );
+      for ( ; it->More(); it->Next() )
+        ch.append( it->Value() );
+    }
+  }
+
+  return ch;
 }
 
 /*!
@@ -201,16 +215,12 @@ void SalomeApp_DataModelSync::children( const kerPtr& obj, QValueList<kerPtr>& c
   \param p - SUIT object
   \param ch - list to be filled
 */
-void SalomeApp_DataModelSync::children( const suitPtr& p, QValueList<suitPtr>& ch ) const
+QList<suitPtr> SalomeApp_DataModelSync::children( const suitPtr& p ) const
 {
-  DataObjectList l;
-  if( p )
-  {
-    p->children( l );
-    ch.clear();
-    for( SUIT_DataObject* o = l.first(); o; o = l.next() )
-      ch.append( o );
-  }
+  QList<suitPtr> ch;
+  if ( p )
+    ch = p->children();
+  return ch;
 }
 
 /*!
@@ -226,7 +236,7 @@ suitPtr SalomeApp_DataModelSync::parent( const suitPtr& p ) const
   Updates SUIT object
   \param p - SUIT object
 */
-void SalomeApp_DataModelSync::updateItem( const kerPtr& obj, const suitPtr& ) const
+void SalomeApp_DataModelSync::updateItem( const kerPtr&, const suitPtr& ) const
 {
 }
 
@@ -244,7 +254,7 @@ void showTree( SUIT_DataObject* root )
   {
     QString marg; marg.fill( ' ', 3*it.depth() );
     QString nnn = "%1 '%2'";
-    qDebug( nnn.arg( marg ).arg( it.current()->name() ) );
+    qDebug( nnn.arg( marg ).arg( it.current()->name() ).toUtf8() );
   }
 }
 
@@ -276,8 +286,7 @@ bool SalomeApp_DataModel::open( const QString& name, CAM_Study* study, QStringLi
   if ( anId.isEmpty() )
     return true; // Probably nothing to load
 
-  _PTR(Study)      aStudy ( aDoc->studyDS() ); // shared_ptr cannot be used here
-  _PTR(SComponent) aSComp ( aStudy->FindComponentID( std::string( anId.latin1() ) ) );
+  _PTR(SComponent) aSComp ( SalomeApp_Application::getStudy()->FindComponentID( std::string( anId.toUtf8() ) ) );
   if ( aSComp )
     updateTree( aSComp, aDoc );
 
@@ -311,8 +320,7 @@ void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study )
       studyRoot = dynamic_cast<LightApp_RootObject*>( aSStudy->root() );
       QString anId = getRootEntry( aSStudy );
       if ( !anId.isEmpty() ){ // if nothing is published in the study for this module -> do nothing
-       _PTR(Study) aStudy ( aSStudy->studyDS() );
-       sobj = aStudy->FindComponentID( std::string( anId.latin1() ) );
+        sobj = SalomeApp_Application::getStudy()->FindComponentID( std::string( anId.toUtf8() ) );
       }
     }
   }
@@ -321,9 +329,8 @@ void SalomeApp_DataModel::update( LightApp_DataObject*, LightApp_Study* study )
     if ( studyRoot ) {
       aSStudy = dynamic_cast<SalomeApp_Study*>( studyRoot->study() ); // <study> value should not change here theoretically, but just to make sure
       if ( aSStudy ) {
-        _PTR(Study) aStudy ( aSStudy->studyDS() );
         // modelRoot->object() cannot be reused here: it is about to be deleted by buildTree() soon
-        sobj = aStudy->FindComponentID( std::string( modelRoot->entry().latin1() ) );
+        sobj = SalomeApp_Application::getStudy()->FindComponentID( std::string( modelRoot->entry().toUtf8() ) );
       }
     }
   }
@@ -352,12 +359,20 @@ SUIT_DataObject* SalomeApp_DataModel::synchronize( const _PTR( SComponent )& sob
     }
   }
 
+#ifdef WITH_SALOMEDS_OBSERVER
+  SalomeApp_RootObject* root=dynamic_cast<SalomeApp_RootObject*>(study->root());
+  if(!(root->toSynchronize()))
+    return suitObj;
+#endif
+
   SalomeApp_DataModelSync sync( study->studyDS(), study->root() );
 
   if( !suitObj || dynamic_cast<SalomeApp_DataObject*>( suitObj ) )
-    return ::synchronize<kerPtr,suitPtr,SalomeApp_DataModelSync>( sobj, suitObj, sync );
+    suitObj= ::synchronize<kerPtr,suitPtr,SalomeApp_DataModelSync>( sobj, suitObj, sync );
   else
-    return 0;
+    suitObj= 0;
+
+  return suitObj;
 }
 
 /*!
@@ -408,7 +423,7 @@ QString SalomeApp_DataModel::getRootEntry( SalomeApp_Study* study ) const
       anEntry = anObj->entry();
   }
   else if ( study && study->studyDS() ) { // this works even if <myRoot> is null
-    _PTR(SComponent) aSComp( study->studyDS()->FindComponent( module()->name() ) );
+    _PTR(SComponent) aSComp( study->studyDS()->FindComponent( module()->name().toStdString() ) );
     if ( aSComp )
       anEntry = aSComp->GetID().c_str();
   }