Salome HOME
Merge from V6_main 13/12/2012
[modules/paravis.git] / src / Plugins / MedReader / ParaViewPlugin / pqExtractGroupPanel.cxx
1 // Copyright (C) 2010-2012  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 "pqExtractGroupPanel.h"
21 #include "ui_ExtractGroupPanel.h"
22
23 #include "vtkProcessModule.h"
24 #include "vtkMultiBlockDataSet.h"
25 #include "vtkInformation.h"
26 #include "vtkIntArray.h"
27 #include "vtkSMDoubleVectorProperty.h"
28 #include "vtkSMIntVectorProperty.h"
29 #include "vtkSMStringVectorProperty.h"
30 #include "vtkSMProxy.h"
31 #include "vtkEventQtSlotConnect.h"
32 #include "vtkPVSILInformation.h"
33 #include "vtkGraph.h"
34 #include "vtkSMPropertyHelper.h"
35 #include "vtkStringArray.h"
36 #include "vtkDataSetAttributes.h"
37
38 #include "vtkMedUtilities.h"
39
40 #include "pqTreeWidget.h"
41 #include "pqTreeWidgetItemObject.h"
42 #include "pqSMAdaptor.h"
43 #include "pqProxy.h"
44 #include "pqPropertyManager.h"
45 #include "pqSILModel.h"
46 #include "pqProxySILModel.h"
47 #include "pqTreeViewSelectionHelper.h"
48 #include "pqTreeWidgetSelectionHelper.h"
49 #include "pqPropertyLinks.h"
50
51 #include <QHeaderView>
52
53 class pqExtractGroupPanel::pqUI : public QObject, public Ui::ExtractGroupPanel
54 {
55 public:
56   pqUI(pqExtractGroupPanel* p) :
57     QObject(p)
58   {
59     this->VTKConnect = vtkSmartPointer<vtkEventQtSlotConnect>::New();
60     this->SILUpdateStamp = -1;
61   }
62
63   ~pqUI()
64   {
65   }
66
67   pqSILModel SILModel;
68   vtkSmartPointer<vtkEventQtSlotConnect> VTKConnect;
69   pqPropertyLinks Links;
70   pqProxySILModel* entityModel;
71   pqProxySILModel* groupModel;
72   int SILUpdateStamp;
73 };
74
75 pqExtractGroupPanel::pqExtractGroupPanel(pqProxy* object_proxy, QWidget* p) :
76   Superclass(object_proxy, p)
77 {
78   this->UI = new pqUI(this);
79   this->UI->setupUi(this);
80
81   pqProxySILModel* proxyModel;
82
83   // connect groups to groupsRoot
84   proxyModel = new pqProxySILModel("GroupTree", &this->UI->SILModel);
85   proxyModel->setSourceModel(&this->UI->SILModel);
86   this->UI->Groups->setModel(proxyModel);
87   this->UI->Groups->setHeaderHidden(true);
88
89   this->UI->groupModel = new pqProxySILModel("Groups", &this->UI->SILModel);
90   this->UI->groupModel->setSourceModel(&this->UI->SILModel);
91
92   // connect cell types to "EntityRoot"
93   proxyModel = new pqProxySILModel("EntityTree", &this->UI->SILModel);
94   proxyModel->setSourceModel(&this->UI->SILModel);
95   this->UI->Entity->setModel(proxyModel);
96   this->UI->Entity->setHeaderHidden(true);
97
98   this->UI->entityModel = new pqProxySILModel("Entity", &this->UI->SILModel);
99   this->UI->entityModel->setSourceModel(&this->UI->SILModel);
100
101   this->updateSIL();
102
103   this->UI->Groups->header()->setStretchLastSection(true);
104   this->UI->Entity->header()->setStretchLastSection(true);
105
106   this->linkServerManagerProperties();
107
108   QList<pqTreeWidget*> treeWidgets = this->findChildren<pqTreeWidget*> ();
109   foreach (pqTreeWidget* tree, treeWidgets)
110       {
111       new pqTreeWidgetSelectionHelper(tree);
112       }
113
114   QList<pqTreeView*> treeViews = this->findChildren<pqTreeView*> ();
115   foreach (pqTreeView* tree, treeViews)
116       {
117       new pqTreeViewSelectionHelper(tree);
118       }
119
120   this->connect(this->UI->groupModel, SIGNAL(valuesChanged()),
121                 this, SLOT(setModified()));
122   this->connect(this->UI->entityModel, SIGNAL(valuesChanged()),
123                 this, SLOT(setModified()));
124
125   this->UI->tabWidget->setCurrentIndex(0);
126
127   this->UI->VTKConnect->Connect(this->proxy(),
128       vtkCommand::UpdateInformationEvent, this, SLOT(updateSIL()));
129
130 }
131
132 pqExtractGroupPanel::~pqExtractGroupPanel()
133 {
134 }
135
136 void pqExtractGroupPanel::linkServerManagerProperties()
137 {
138   this->UI->Links.addPropertyLink(this->UI->groupModel, "values",
139       SIGNAL(valuesChanged()), this->proxy(), this->proxy()->GetProperty(
140           "Groups"));
141
142   this->UI->Links.addPropertyLink(this->UI->entityModel, "values",
143       SIGNAL(valuesChanged()), this->proxy(), this->proxy()->GetProperty(
144           "Entity"));
145
146   this->Superclass::linkServerManagerProperties();
147
148 }
149
150 void pqExtractGroupPanel::updateSIL()
151 {
152
153   vtkSMProxy* reader = this->referenceProxy()->getProxy();
154   reader->UpdatePropertyInformation(reader->GetProperty("SILUpdateStamp"));
155
156   int stamp = vtkSMPropertyHelper(reader, "SILUpdateStamp").GetAsInt();
157   if (stamp != this->UI->SILUpdateStamp)
158     {
159     this->UI->SILUpdateStamp = stamp;
160     vtkPVSILInformation* info = vtkPVSILInformation::New();
161     reader->GatherInformation(info);
162     this->UI->SILModel.update(info->GetSIL());
163
164     this->UI->Groups->expandAll();
165     this->UI->Entity->expandAll();
166
167     info->Delete();
168     }
169
170 }