Salome HOME
Abu : Mise a jour HEXABLOCK
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_Browser.cxx
1 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
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.
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 "HEXABLOCKGUI_Browser.hxx"
21 #include "HEXABLOCKGUI.hxx"
22
23 #include "Hex.hxx"
24 #include "HexDocument.hxx"
25
26 #include <LightApp_Module.h>
27 #include <LightApp_Study.h>
28 #include <LightApp_Application.h>
29 #include <LightApp_DataModel.h>
30 #include <LightApp_DataObject.h>
31
32 // --------------------------------------------------- classe SaLObject
33 class SalObject : public LightApp_DataObject 
34 {
35 public :
36     SalObject (cpchar nom="") : LightApp_DataObject (NULL) 
37               { obj_name = nom ; obj_entry = "6.6.66" ; }
38
39     virtual ~SalObject     ()       { cout << "SalObject::delete" << endl ; }
40     virtual  QString name  () const { return obj_name ; } 
41     virtual  QString entry () const { return obj_entry ; } 
42     void  rename (cpchar nom)       { obj_name = nom ; }
43
44 private :
45     QString obj_name;
46     QString obj_entry;
47 };
48 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
49 // --------------------------------------------------- classe SaLModel
50 class SalModel : public LightApp_DataModel
51 {
52 public :
53    SalModel (HEXABLOCKGUI* guy);
54    void clear   ();
55    void addItem (cpchar fils);
56
57 private :
58    CAM_ModuleObject* obj_root;
59 };
60
61 // =================================================== Constructeur SalModel
62 SalModel::SalModel (HEXABLOCKGUI* guy)
63         : LightApp_DataModel (guy)
64 {
65 /* **********************************************
66    LightApp_Study* study    = (LightApp_Study*) guy->activeStudy();
67    obj_root = createModuleObject (study->root());
68
69    obj_root ->setDataModel (this);
70    setRoot (obj_root);
71
72    SalObject* obj1 = new  SalObject ("Document1");
73    SalObject* obj2 = new  SalObject ("Document2");
74
75    PutData (obj1->name ().toStdString());
76    PutData (obj2->name ().toStdString());
77
78    obj_root->appendChild (obj1);
79    obj_root->appendChild (obj2);
80    PutData (obj_root->childCount());
81
82    ********************************************** */
83 }
84 // ================================================================ clear
85 void SalModel::clear ()
86 {
87    const bool nodel = false;
88    while (true)
89          {
90          SUIT_DataObject* obj = obj_root->firstChild ();
91          if (obj==NULL)
92             return;
93          obj_root->removeChild (obj, nodel);
94          cout << " Delete object " << obj->name ().toStdString()
95               << endl;
96          } 
97 }
98 // ================================================================ addItem
99 void SalModel::addItem (cpchar name)
100 {
101    SalObject* obj1 = new  SalObject (name);
102    obj_root->appendChild (obj1);
103 }
104 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
105 // =================================================== Constructeur H.G.Browser
106 HEXABLOCKGUI_Browser::HEXABLOCKGUI_Browser (HEXABLOCKGUI* guy)
107 {
108     hexa_gui   = guy;
109     hexa_root  = HEXA_NS::Hex::getInstance ();
110     data_model = NULL;
111 }
112
113 // =============================================================== rebuildTree
114 void HEXABLOCKGUI_Browser::rebuildTree ()
115 {
116    if (data_model==NULL) 
117       data_model = new SalModel (hexa_gui);
118
119     data_model->clear ();
120
121     int nbre = hexa_root->countDocument ();
122     for (int nro=0 ; nro<nbre ; nro++)
123         {
124         Document* doc = hexa_root->getDocument (nro);
125         cpchar    nom = doc->getName ();
126         data_model->addItem (nom);
127         }
128
129     hexa_gui->updateObjBrowser( true );
130 }
131