]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_InspectionPanel.cpp
Salome HOME
Task 2.1 "Functionality of inspection 'what is'" from CEA specification. Panel definition
[modules/shaper.git] / src / XGUI / XGUI_InspectionPanel.cpp
1 // Copyright (C) 2014-2017  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, or (at your option) any later version.
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "XGUI_InspectionPanel.h"
22 #include "XGUI_SelectionMgr.h"
23 #include "XGUI_Selection.h"
24
25 #include <QLayout>
26 #include <QScrollArea>
27 #include <QLabel>
28 #include <QLineEdit>
29 #include <QTableWidget>
30 #include <QHeaderView>
31 #include <QTextBrowser>
32
33 XGUI_InspectionPanel::XGUI_InspectionPanel(QWidget* theParent, XGUI_SelectionMgr* theMgr)
34   : QDockWidget(theParent),
35   mySelectionMgr(theMgr)
36 {
37   setWindowTitle(tr("Inspection Panel"));
38   setObjectName(INSPECTION_PANEL);
39   setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
40
41   QScrollArea* aScrollArea = new QScrollArea(this);
42   setWidget(aScrollArea);
43
44   // Create an internal widget
45   QWidget* aMainWidget = new QWidget(aScrollArea);
46
47   QVBoxLayout* aMainLayout = new QVBoxLayout(aMainWidget);
48   aMainLayout->setContentsMargins(5, 5, 5, 5);
49
50   QWidget* aNameWgt = new QWidget(aMainWidget);
51   QHBoxLayout* aNameLayout = new QHBoxLayout(aNameWgt);
52   aNameLayout->setContentsMargins(0, 0, 0, 0);
53   aNameLayout->addWidget(new QLabel(tr("Object"), aNameWgt));
54   myNameEdt = new QLineEdit(aNameWgt);
55   myNameEdt->setReadOnly(true);
56   aNameLayout->addWidget(myNameEdt);
57
58   aMainLayout->addWidget(aNameWgt);
59
60   // Table with sub-shapes
61   mySubShapesTab = new QTableWidget(9, 2, aMainWidget);
62   mySubShapesTab->setFocusPolicy(Qt::NoFocus);
63   mySubShapesTab->verticalHeader()->hide();
64   QStringList aTitles;
65   aTitles << tr("Sub-shapes") << tr("Number");
66   mySubShapesTab->setHorizontalHeaderLabels(aTitles);
67
68   QStringList aSubShapes;
69   aSubShapes << "SHAPE" << "COMPOUND" << "COMPSOLID" <<
70     "SOLID" << "SHELL" << "FACE" << "WIRE" << "EDGE" << "VERTEX";
71   int i = 0;
72   foreach(QString aType, aSubShapes) {
73     QTableWidgetItem* aItem = new QTableWidgetItem(aType);
74     aItem->setFlags(Qt::ItemIsEnabled);
75     mySubShapesTab->setItem(i++, 0, aItem);
76   }
77   for (i = 0; i < 9; i++) {
78     QTableWidgetItem* aItem = new QTableWidgetItem("0");
79     aItem->setFlags(Qt::ItemIsEnabled);
80     aItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
81     mySubShapesTab->setItem(i, 1, aItem);
82   }
83   mySubShapesTab->setColumnWidth(0, 90);
84   mySubShapesTab->setColumnWidth(1, 70);
85
86   mySubShapesTab->setMaximumWidth(170);
87   mySubShapesTab->setMinimumHeight(300);
88
89   aMainLayout->addWidget(mySubShapesTab);
90
91   // Type of object
92   QWidget* aTypeWgt = new QWidget(aMainWidget);
93   QHBoxLayout* aTypeLayout = new QHBoxLayout(aTypeWgt);
94   aTypeLayout->setContentsMargins(0, 0, 0, 0);
95
96   aTypeLayout->addWidget(new QLabel(tr("Type:"), aTypeWgt));
97   myTypeLbl = new QLabel("No-type", aTypeWgt);
98   aTypeLayout->addWidget(myTypeLbl);
99
100   aMainLayout->addWidget(aTypeWgt);
101
102   myTypeParams = new QTextBrowser(aMainWidget);
103   myTypeParams->setMaximumWidth(170);
104   myTypeParams->setMaximumHeight(160);
105   myTypeParams->setReadOnly(true);
106   myTypeParams->setFocusPolicy(Qt::NoFocus);
107   myTypeParams->setFrameStyle(QFrame::NoFrame);
108   myTypeParams->viewport()->setBackgroundRole(QPalette::Window);
109
110   aMainLayout->addWidget(myTypeParams);
111
112   aScrollArea->setWidget(aMainWidget);
113
114   connect(mySelectionMgr, SIGNAL(selectionChanged()), SLOT(onSelectionChanged()));
115
116   // Test
117   setVertexType(0, 0, 0);
118 }
119
120 XGUI_InspectionPanel::~XGUI_InspectionPanel()
121 {
122 }
123
124 void XGUI_InspectionPanel::setSubShapeValue(SudShape theId, int theVal)
125 {
126   mySubShapesTab->item(theId, 1)->setText(QString::number(theVal));
127 }
128
129 void XGUI_InspectionPanel::onSelectionChanged()
130 {
131   QObjectPtrList aObjects = mySelectionMgr->selection()->selectedObjects();
132   if (aObjects.count() > 0) {
133     ObjectPtr aObj = aObjects.first();
134     setName(aObj->data()->name().c_str());
135   }
136 }
137
138 void XGUI_InspectionPanel::setName(const QString& theName)
139 {
140   myNameEdt->setText(theName);
141 }
142
143 #define TITLE(val) ("<b>" + val + "</b>")
144
145 void XGUI_InspectionPanel::setCylinderType(double theX, double theY, double theZ,
146   double theDX, double theDY, double theDZ, double theRadius, double theHeight)
147 {
148   myTypeLbl->setText(tr("Cylinder"));
149   QString aParams = TITLE(tr("Center")) +
150     "<br> X: " + QString::number(theX) +
151     "<br> Y: " + QString::number(theY) +
152     "<br> Z: " + QString::number(theZ) +
153     "<br>" + TITLE(tr("Axis")) +
154     "<br> DX: " + QString::number(theDX) +
155     "<br> DY: " + QString::number(theDY) +
156     "<br> DZ: " + QString::number(theDZ) +
157     "<br>" + TITLE(tr("Dimensions")) +
158     "<br>" + tr("Radius:") + QString::number(theRadius) +
159     "<br>" + tr("Height") + QString::number(theHeight);
160
161   myTypeParams->setText(aParams);
162 }
163
164 void XGUI_InspectionPanel::setSphereType(double theX, double theY, double theZ, double theRadius)
165 {
166   myTypeLbl->setText(tr("Sphere"));
167   QString aParams = TITLE(tr("Center")) +
168     "<br> X: " + QString::number(theX) +
169     "<br> Y: " + QString::number(theY) +
170     "<br> Z: " + QString::number(theZ) +
171     "<br>" + TITLE(tr("Dimensions")) +
172     "<br>" + tr("Radius:") + QString::number(theRadius);
173   myTypeParams->setText(aParams);
174 }
175
176 void XGUI_InspectionPanel::setBoxType(double theX, double theY, double theZ,
177   double theXsize, double theYsize, double theZsize)
178 {
179   myTypeLbl->setText(tr("Box"));
180   QString aParams = TITLE(tr("Position")) +
181     "<br> X: " + QString::number(theX) +
182     "<br> Y: " + QString::number(theY) +
183     "<br> Z: " + QString::number(theZ) +
184     "<br>" + TITLE(tr("Dimensions")) +
185     "<br>" + "Ax :" + QString::number(theXsize) +
186     "<br>" + "Ay :" + QString::number(theYsize) +
187     "<br>" + "Az :" + QString::number(theZsize);
188   myTypeParams->setText(aParams);
189 }
190
191
192 void XGUI_InspectionPanel::setRotatedBoxType(double theX, double theY, double theZ,
193   double theZaxisX, double theZaxisY, double theZaxisZ,
194   double theXaxisX, double theXaxisY, double theXaxisZ,
195   double theXsize, double theYsize, double theZsize)
196 {
197   myTypeLbl->setText(tr("Box"));
198   QString aParams = TITLE(tr("Position")) +
199     "<br> X: " + QString::number(theX) +
200     "<br> Y: " + QString::number(theY) +
201     "<br> Z: " + QString::number(theZ) +
202     "<br>" + TITLE(tr("Z axis")) +
203     "<br> DX: " + QString::number(theZaxisX) +
204     "<br> DY: " + QString::number(theZaxisY) +
205     "<br> DZ: " + QString::number(theZaxisZ) +
206     "<br>" + TITLE(tr("X axis")) +
207     "<br> DX: " + QString::number(theXaxisX) +
208     "<br> DY: " + QString::number(theXaxisY) +
209     "<br> DZ: " + QString::number(theXaxisZ) +
210     "<br>" + TITLE(tr("Dimensions")) +
211     "<br>" + "Ax :" + QString::number(theXsize) +
212     "<br>" + "Ay :" + QString::number(theYsize) +
213     "<br>" + "Az :" + QString::number(theZsize);
214   myTypeParams->setText(aParams);
215 }
216
217 void XGUI_InspectionPanel::setPlaneType(double theX, double theY, double theZ,
218   double theDX, double theDY, double theDZ)
219 {
220   myTypeLbl->setText(tr("Plane"));
221   QString aParams = TITLE(tr("Center")) +
222     "<br> X: " + QString::number(theX) +
223     "<br> Y: " + QString::number(theY) +
224     "<br> Z: " + QString::number(theZ) +
225     "<br>" + TITLE(tr("Normal")) +
226     "<br> DX: " + QString::number(theDX) +
227     "<br> DY: " + QString::number(theDY) +
228     "<br> DZ: " + QString::number(theDZ);
229   myTypeParams->setText(aParams);
230 }
231
232 void XGUI_InspectionPanel::setVertexType(double theX, double theY, double theZ)
233 {
234   myTypeLbl->setText(tr("Vertex"));
235   QString aParams = TITLE(tr("Coordinates")) +
236     "<br> X: " + QString::number(theX) +
237     "<br> Y: " + QString::number(theY) +
238     "<br> Z: " + QString::number(theZ);
239   myTypeParams->setText(aParams);
240 }