1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "XGUI_InspectionPanel.h"
22 #include "XGUI_SelectionMgr.h"
23 #include "XGUI_Selection.h"
26 #include <QScrollArea>
29 #include <QTableWidget>
30 #include <QHeaderView>
31 #include <QTextBrowser>
33 XGUI_InspectionPanel::XGUI_InspectionPanel(QWidget* theParent, XGUI_SelectionMgr* theMgr)
34 : QDockWidget(theParent),
35 mySelectionMgr(theMgr)
37 setWindowTitle(tr("Inspection Panel"));
38 setObjectName(INSPECTION_PANEL);
39 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
41 QScrollArea* aScrollArea = new QScrollArea(this);
42 setWidget(aScrollArea);
44 // Create an internal widget
45 QWidget* aMainWidget = new QWidget(aScrollArea);
47 QVBoxLayout* aMainLayout = new QVBoxLayout(aMainWidget);
48 aMainLayout->setContentsMargins(5, 5, 5, 5);
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);
58 aMainLayout->addWidget(aNameWgt);
60 // Table with sub-shapes
61 mySubShapesTab = new QTableWidget(9, 2, aMainWidget);
62 mySubShapesTab->setFocusPolicy(Qt::NoFocus);
63 mySubShapesTab->verticalHeader()->hide();
65 aTitles << tr("Sub-shapes") << tr("Number");
66 mySubShapesTab->setHorizontalHeaderLabels(aTitles);
68 QStringList aSubShapes;
69 aSubShapes << "SHAPE" << "COMPOUND" << "COMPSOLID" <<
70 "SOLID" << "SHELL" << "FACE" << "WIRE" << "EDGE" << "VERTEX";
72 foreach(QString aType, aSubShapes) {
73 QTableWidgetItem* aItem = new QTableWidgetItem(aType);
74 aItem->setFlags(Qt::ItemIsEnabled);
75 mySubShapesTab->setItem(i++, 0, aItem);
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);
83 mySubShapesTab->setColumnWidth(0, 90);
84 mySubShapesTab->setColumnWidth(1, 70);
86 mySubShapesTab->setMaximumWidth(170);
87 mySubShapesTab->setMinimumHeight(300);
89 aMainLayout->addWidget(mySubShapesTab);
92 QWidget* aTypeWgt = new QWidget(aMainWidget);
93 QHBoxLayout* aTypeLayout = new QHBoxLayout(aTypeWgt);
94 aTypeLayout->setContentsMargins(0, 0, 0, 0);
96 aTypeLayout->addWidget(new QLabel(tr("Type:"), aTypeWgt));
97 myTypeLbl = new QLabel("No-type", aTypeWgt);
98 aTypeLayout->addWidget(myTypeLbl);
100 aMainLayout->addWidget(aTypeWgt);
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);
110 aMainLayout->addWidget(myTypeParams);
112 aScrollArea->setWidget(aMainWidget);
114 connect(mySelectionMgr, SIGNAL(selectionChanged()), SLOT(onSelectionChanged()));
117 setVertexType(0, 0, 0);
120 XGUI_InspectionPanel::~XGUI_InspectionPanel()
124 void XGUI_InspectionPanel::setSubShapeValue(SudShape theId, int theVal)
126 mySubShapesTab->item(theId, 1)->setText(QString::number(theVal));
129 void XGUI_InspectionPanel::onSelectionChanged()
131 QObjectPtrList aObjects = mySelectionMgr->selection()->selectedObjects();
132 if (aObjects.count() > 0) {
133 ObjectPtr aObj = aObjects.first();
134 setName(aObj->data()->name().c_str());
138 void XGUI_InspectionPanel::setName(const QString& theName)
140 myNameEdt->setText(theName);
143 #define TITLE(val) ("<b>" + val + "</b>")
145 void XGUI_InspectionPanel::setCylinderType(double theX, double theY, double theZ,
146 double theDX, double theDY, double theDZ, double theRadius, double theHeight)
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);
161 myTypeParams->setText(aParams);
164 void XGUI_InspectionPanel::setSphereType(double theX, double theY, double theZ, double theRadius)
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);
176 void XGUI_InspectionPanel::setBoxType(double theX, double theY, double theZ,
177 double theXsize, double theYsize, double theZsize)
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);
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)
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);
217 void XGUI_InspectionPanel::setPlaneType(double theX, double theY, double theZ,
218 double theDX, double theDY, double theDZ)
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);
232 void XGUI_InspectionPanel::setVertexType(double theX, double theY, double theZ)
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);