Salome HOME
Memory Leaks
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Library.h
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SUPERVGUI_Library.h
25 //  Author : Alexander SLADKOV
26 //  Module : SUPERV
27
28 #ifndef SUPERVGUI_Library_H
29 #define SUPERVGUI_Library_H
30
31 #include <qdialog.h>
32 #include <qdom.h>
33
34 #include "utilities.h"
35 #include "SALOME_LifeCycleCORBA.hxx"
36 #include CORBA_CLIENT_HEADER(SUPERV)
37
38 class QListBox;
39
40 /**
41  * SUPERVGUI_Library class is intended for management of InLine nodes library.
42  * InLine nodes library is an XML repository (currently it is a predefined user-dependant XML file)
43  * with InLine nodes stored in it.  InLine node in a library contains its Python code and lists of 
44  * input and output ports.
45  */
46 class SUPERVGUI_Library : QObject { // extending QObject to enable slot/signals
47
48   Q_OBJECT
49
50 protected:
51   SUPERVGUI_Library(); // constructor is protected, use static function getLibrary()
52  
53 public:
54   static SUPERVGUI_Library* getLibrary() { 
55     if ( !myLibrary )
56       myLibrary = new SUPERVGUI_Library();
57     return myLibrary; 
58   }
59
60   // Returns the XML file name used as InLine nodes repository
61   const char* GetLibraryFileName() const;
62
63   // Export an InLine node to Library 
64   bool Export( SUPERV::INode_var theNode ) const;
65
66   // Import an InLine node from Library into the dataflow  
67   bool Import( SUPERV::Graph_var theDataflow, SUPERV::INode_var& theNode, 
68                SUPERV::INode_var& theEndNode, const int theLibIndex ) const; 
69
70   // Remove an InLine node with given index from Library
71   bool Remove( const int i ) const;
72
73   // returns a list of node names currently stored in the library.  Indexes of the nodes in
74   // this list can be used for futher calls to Import(.., index)
75   SUPERV::ListOfStrings GetLibraryNodesNames() const;
76
77   // returns status of library: false indicates that library file does not exist or can not be opened
78   bool CanImport() const;
79
80 private:
81   static SUPERVGUI_Library* myLibrary;
82
83   bool createLibFile() const; // returns false on file creation error (also displays MB)
84
85   // returns list of NODE_ELEMENT-s and error result (false) if failed (also displays MB)
86   bool getNodes( QDomDocument& theDoc, QDomNodeList& theNodes ) const; 
87
88 };
89
90 /**
91  * Dialog box for Add/Remove InLine nodes to Library, Add node to Graph from Library
92  */
93 class SUPERVGUI_LibDlg: public QDialog {
94
95   Q_OBJECT
96
97 public:
98   SUPERVGUI_LibDlg( QWidget* parent, int& theX, int& theY );
99   ~SUPERVGUI_LibDlg();
100
101 private slots:
102   void add(); // add selected node from library to graph
103   void remove(); // remove selected node from library
104
105 private:
106   void initList(); // clear and fill list with nodes from Library
107
108   QListBox* myLB;
109   int& myX; // comes from caller - SUPERVGUI_Service, used for calculating next node_s position
110   int& myY; // comes from caller - SUPERVGUI_Service
111 };
112
113 #endif