X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FATOMICGUI%2FATOMICGUI_DataModel.cxx;h=f360691f6fb842c50669d0bfc7666dbe48bdc46b;hb=0e7f5ff3af55e2fe05a90ad93e70cd43ed973fe9;hp=b0341e2fab03cc8e6186c66300d1ae0b18330a7b;hpb=ee81df44e638f9c22f7c2b5814166e02cf77211b;p=samples%2Fatomic.git diff --git a/src/ATOMICGUI/ATOMICGUI_DataModel.cxx b/src/ATOMICGUI/ATOMICGUI_DataModel.cxx index b0341e2..f360691 100644 --- a/src/ATOMICGUI/ATOMICGUI_DataModel.cxx +++ b/src/ATOMICGUI/ATOMICGUI_DataModel.cxx @@ -1,23 +1,21 @@ -// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2014 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, or (at your option) any later version. // -// 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 +// Lesser General Public License for more details. // -// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// 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 // -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org #include "ATOMICGUI_DataModel.h" #include "ATOMICGUI_DataObject.h" @@ -39,6 +37,7 @@ #include #include +#include const QString doc_name = "Atomic"; const QString doc_tag = "document"; @@ -64,6 +63,8 @@ ATOMICGUI_DataModel::~ATOMICGUI_DataModel() /*! Open Data Model. Build data structure from the given list of files. */ bool ATOMICGUI_DataModel::open( const QString& URL, CAM_Study* study, QStringList listOfFiles ) { + myMolecules.clear(); + LightApp_Study* aDoc = dynamic_cast( study ); if ( !aDoc ) return false; @@ -120,13 +121,14 @@ bool ATOMICGUI_DataModel::saveAs ( const QString& URL, CAM_Study* study, QString bool ATOMICGUI_DataModel::close() { myStudyURL = ""; - myMolecules.clear(); + //myMolecules.clear(); return LightApp_DataModel::close(); } /*! Called on Study creation */ bool ATOMICGUI_DataModel::create( CAM_Study* study ) { + myMolecules.clear(); return true; } @@ -145,9 +147,14 @@ bool ATOMICGUI_DataModel::isSaved() const /*! Called on update of the structure of Data Objects */ void ATOMICGUI_DataModel::build() { - ATOMICGUI_ModuleObject* modelRoot = dynamic_cast( root() ); + //VSR: module object should be created in a different way for "full" and "light" SALOME + //ATOMICGUI_ModuleObject* modelRoot = dynamic_cast( root() ); + CAM_ModuleObject* modelRoot = dynamic_cast( root() ); if( !modelRoot ) { // root is not set yet - modelRoot = new ATOMICGUI_ModuleObject( this, 0 ); + //VSR: module object should be created in a different way for "full" and "light" SALOME + //modelRoot = new ATOMICGUI_ModuleObject( this, 0 ); + LightApp_Study* study = dynamic_cast( module()->application()->activeStudy() ); + modelRoot = createModuleObject( study->root() ); setRoot( modelRoot ); } @@ -159,7 +166,7 @@ void ATOMICGUI_DataModel::build() } } - root()->dump(); + //root()->dump(); } /*! Loads data from the XML file. */ @@ -270,21 +277,22 @@ bool ATOMICGUI_DataModel::exportFile( const QString& fileName ) } /*! Adds a new molecule to the data structure */ -bool ATOMICGUI_DataModel::createMolecule () +QString ATOMICGUI_DataModel::createMolecule () { ATOMICGUI_AtomicMolecule mol; // temporary code to add a few atoms to a molecule.. - mol.addAtom( "atom_1", 0, 0, 0 ); - mol.addAtom( "atom_2", 0, 0, 0 ); - mol.addAtom( "atom_3", 0, 0, 0 ); + //mol.addAtom( "atom_1", 0, 0, 0 ); + //mol.addAtom( "atom_2", 0, 0, 0 ); + //mol.addAtom( "atom_3", 0, 0, 0 ); // end of temporary code myMolecules.append( mol ); + QString id = QString( "ATOMICGUI_%1" ).arg( mol.id() ); + update(); - - return true; + return id; } /*! Adds a new atom to the given molecule */ @@ -383,3 +391,43 @@ ATOMICGUI_DataObject* ATOMICGUI_DataModel::findMolecule( const QString& entry ) } return 0; } +/*! Dump the data model in the python script. */ +bool ATOMICGUI_DataModel::dumpPython( const QString& theURL, + CAM_Study* theStudy, + bool isMultiFile, + QStringList& theListOfFiles ) { + QString aScript = "from AtomicPy import *\n"; + QString aPrefix = ""; + if(isMultiFile) { + aScript += "def RebuildData(theStudy):\n"; + aPrefix = "\t"; + } + + for ( int i = 0; i < myMolecules.count(); i++ ) { + aScript += aPrefix + QString("mol_%1 = AtomicMolecule('").arg(i) + myMolecules[ i ].name()+"')\n"; + for ( int j = 0; j < myMolecules[ i ].count(); j++ ) { + aScript += aPrefix + QString("mol_%1.addAtom('").arg(i) + myMolecules[ i ].atomName( j ); + aScript += QString("', %1, %2, %3)\n").arg(myMolecules[ i ].atomX( j )).arg(myMolecules[ i ].atomY( j )).arg(myMolecules[ i ].atomZ( j )); + } + } + + if(isMultiFile) { + aScript += aPrefix+"pass\n"; + } + + LightApp_Study* study = dynamic_cast( theStudy ); + if(!study) + return false; + + std::string aTmpDir = study->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ); + std::string aFile = aTmpDir + "atomic_dump.tmp"; + + std::ofstream outfile(aFile.c_str()); + outfile.write (aScript.toLatin1().data(),aScript.size()); + outfile.close(); + + theListOfFiles.append(aTmpDir.c_str()); + theListOfFiles.append("atomic_dump.tmp"); + + return true; +}