Salome HOME
10cc169c5beb36bcef1bc4b4957300b123d81def
[samples/atomsolv.git] / src / ATOMSOLVGUI / ATOMSOLVGUI_DataModel.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ATOMSOLVGUI_DataModel.h"
21 #include "ATOMSOLVGUI_DataObject.h"
22 #include "ATOMSOLVGUI.h"
23
24 #include <LightApp_Study.h>
25
26 #include <CAM_Module.h>
27 #include <CAM_Application.h>
28
29 /*! Constructor */
30 ATOMSOLVGUI_DataModel::ATOMSOLVGUI_DataModel( CAM_Module* module )
31   : LightApp_DataModel( module )
32 {
33 }
34
35 /*! Destructor */
36 ATOMSOLVGUI_DataModel::~ATOMSOLVGUI_DataModel()
37 {
38 }
39
40 /*! Called on update of the structure of Data Objects */
41 void ATOMSOLVGUI_DataModel::build()
42 {
43   ATOMSOLVGUI_ModuleObject* modelRoot = dynamic_cast<ATOMSOLVGUI_ModuleObject*>( root() );
44   if( !modelRoot )  {  // root is not set yet
45     modelRoot = new ATOMSOLVGUI_ModuleObject( this, 0 );
46     setRoot( modelRoot );
47   }
48
49   // create 'molecule' objects under model root object and 'atom' objects under 'molecule'-s
50   ATOMSOLV_ORB::ATOMSOLV_Gen_var engine = ATOMSOLVGUI::GetATOMSOLVGen();
51   if ( !CORBA::is_nil( engine ) ) {
52     ATOMSOLV_ORB::TMoleculeList_var molecules;
53     if ( !engine->getData( molecules ) ) {
54       //      printf( " -- DataModel: getData() returned false! \n" );
55       return;
56     }
57     for ( int i = 0, n = molecules->length(); i < n; i++ ) {
58       ATOMSOLVGUI_DataObject* molDO = new ATOMSOLVGUI_DataObject ( modelRoot, i );
59       const ATOMSOLV_ORB::TMolecule& mol = molecules[i];
60       const int atoms = mol.molecule->getNbAtoms();
61       for ( int j = 0; j < atoms; j++ )
62         new ATOMSOLVGUI_DataObject ( molDO, i, j );
63     }
64   }
65
66   //  root()->dump();
67 }