]> SALOME platform Git repositories - samples/atomic.git/blob - src/AtomicPy/AtomicPy.cxx
Salome HOME
Implementation of the "0021452: [CEA 530]: Improvement of SALOME module integration...
[samples/atomic.git] / src / AtomicPy / AtomicPy.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : SalomePyQt.cxx
24 // Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
25
26 #include <SUIT_Session.h>
27 #include <LightApp_Application.h>
28 #include <LightApp_Module.h>
29 #include <SALOME_Event.h>
30
31 #include "AtomicPy.h"
32 #include "ATOMICGUI_Data.h"
33 #include "ATOMICGUI_DataModel.h"
34
35 class TCreateMoleculeEvent: public SALOME_Event
36 {
37 public:
38   QString myName;
39   typedef QString TResult;
40   TResult myResult;
41   
42   TCreateMoleculeEvent(const QString& name) : myResult(""), myName(name) {}
43   virtual void Execute()
44   {
45     if ( !SUIT_Session::session() )
46       return;
47     LightApp_Application* app =  dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
48     if(!app)
49       return;
50     
51     LightApp_Module* module = dynamic_cast<LightApp_Module*>( app->module("Atomic") );
52     if(!module)
53       return;
54       
55     ATOMICGUI_DataModel* model = dynamic_cast<ATOMICGUI_DataModel*>(module->dataModel());
56     if(!model)
57       return;
58     
59     myResult = model->createMolecule();
60     model->renameObj(myResult,myName);
61   }
62 };
63
64 class TAddAtomEvent: public SALOME_Event
65 {
66 public:
67   QString myId;
68   QString myName;
69   double myX, myY, myZ;
70
71   TAddAtomEvent(const QString& id, 
72                 const QString& name,
73                 const double x,
74                 const double y,
75                 const double z) : myId(id), myName(name), myX(x), myY(y), myZ(z) {}
76   virtual void Execute()
77   {
78     if ( !SUIT_Session::session() )
79       return;
80     LightApp_Application* app =  dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
81     if(!app)
82       return;
83     
84     LightApp_Module* module = dynamic_cast<LightApp_Module*>( app->module("Atomic") );
85     if(!module)
86       return;
87     
88     ATOMICGUI_DataModel* model = dynamic_cast<ATOMICGUI_DataModel*>(module->dataModel());
89     if(!model)
90       return;
91     
92     model->addAtom(myId,myName,myX,myY,myZ);
93   }
94 };
95
96
97 AtomicMolecule::AtomicMolecule( const QString& name )
98 {
99   myId = ProcessEvent( new TCreateMoleculeEvent( name ) );  
100 }
101
102 void AtomicMolecule::addAtom( const QString& atom, const double x, const double y, const double z ){
103   ProcessVoidEvent( new TAddAtomEvent( myId, atom, x, y, x ) );
104 }