-// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2019 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"
#include <vector>
#include <string>
+#include <fstream>
const QString doc_name = "Atomic";
const QString doc_tag = "document";
/*! 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<LightApp_Study*>( study );
if ( !aDoc )
return false;
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;
}
/*! Called on update of the structure of Data Objects */
void ATOMICGUI_DataModel::build()
{
- ATOMICGUI_ModuleObject* modelRoot = dynamic_cast<ATOMICGUI_ModuleObject*>( root() );
+ //VSR: module object should be created in a different way for "full" and "light" SALOME
+ //ATOMICGUI_ModuleObject* modelRoot = dynamic_cast<ATOMICGUI_ModuleObject*>( root() );
+ CAM_ModuleObject* modelRoot = dynamic_cast<CAM_ModuleObject*>( 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<LightApp_Study*>( module()->application()->activeStudy() );
+ modelRoot = createModuleObject( study->root() );
setRoot( modelRoot );
}
}
}
- root()->dump();
+ //root()->dump();
}
/*! Loads data from the XML file. */
}
/*! 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 */
}
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 = " ";
+ }
+
+ 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<LightApp_Study*>( 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;
+}