Salome HOME
523bdd94f981c2f878749061348bc0390ebe3d2a
[modules/shaper.git] / src / XGUI / XGUI_InspectionPanel.cpp
1 // Copyright (C) 2014-2021  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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "XGUI_InspectionPanel.h"
21 #include "XGUI_Workshop.h"
22 #include "XGUI_SelectionMgr.h"
23 #include "XGUI_Selection.h"
24 #include "XGUI_Tools.h"
25 #include "XGUI_ModuleConnector.h"
26
27 #include <ModuleBase_ViewerPrs.h>
28 #include <ModuleBase_Tools.h>
29 #include <ModuleBase_OperationDescription.h>
30 #include <ModuleBase_WidgetFactory.h>
31 #include <ModuleBase_IModule.h>
32 #include <ModuleBase_PageWidget.h>
33
34 #include <ModelAPI_ResultField.h>
35
36 #include <ModelAPI_Result.h>
37
38 #include <GeomAPI_Ax3.h>
39 #include <GeomAPI_Box.h>
40 #include <GeomAPI_Circ.h>
41 #include <GeomAPI_Cone.h>
42 #include <GeomAPI_Cylinder.h>
43 #include <GeomAPI_Edge.h>
44 #include <GeomAPI_Ellipse.h>
45 #include <GeomAPI_Face.h>
46 #include <GeomAPI_Pln.h>
47 #include <GeomAPI_Pnt.h>
48 #include <GeomAPI_Shell.h>
49 #include <GeomAPI_Solid.h>
50 #include <GeomAPI_Sphere.h>
51 #include <GeomAPI_Torus.h>
52 #include <GeomAPI_Vertex.h>
53 #include <GeomAPI_Wire.h>
54
55 #include <QLayout>
56 #include <QScrollArea>
57 #include <QLabel>
58 #include <QLineEdit>
59 #include <QTableWidget>
60 #include <QHeaderView>
61 #include <QTextBrowser>
62 #include <QResizeEvent>
63 #include <QSplitter>
64 #include <QStackedWidget>
65
66 #include <BRepBndLib.hxx>
67 #include <TopoDS_Iterator.hxx>
68 #include <TopTools_MapOfShape.hxx>
69 #include <TopTools_ListOfShape.hxx>
70 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic
71
72
73 // ================     Auxiliary functions     ================
74 #define TITLE(val) ("<b>" + (val) + "</b>")
75
76 static void appendPointToParameters(const QString& thePointTitle,
77                                     const GeomPointPtr& theCoord,
78                                           QString& theParams)
79 {
80   theParams += TITLE(thePointTitle) +
81     "<br> X: " + QString::number(theCoord->x()) +
82     "<br> Y: " + QString::number(theCoord->y()) +
83     "<br> Z: " + QString::number(theCoord->z()) +
84     "<br>";
85 }
86
87 static void appendDirToParameters(const QString& theDirTitle,
88                                   const GeomDirPtr& theDirection,
89                                         QString& theParams)
90 {
91   theParams += TITLE(theDirTitle) +
92     "<br> DX: " + QString::number(theDirection->x()) +
93     "<br> DY: " + QString::number(theDirection->y()) +
94     "<br> DZ: " + QString::number(theDirection->z()) +
95     "<br>";
96 }
97
98 static void appendGroupNameToParameters(const QString& theGroupTitle, QString& theParams)
99 {
100   theParams += TITLE(theGroupTitle) + "<br>";
101 }
102
103 static void appendNamedValueToParameters(const QString& theName,
104                                          const double   theValue,
105                                                QString& theParams)
106 {
107   theParams += theName + ": " + QString::number(theValue) + "<br>";
108 }
109
110 static void appendNamedValueToParameters(const QString& theName,
111                                          const bool     theValue,
112                                                QString& theParams)
113 {
114   theParams += theName + ": " + (theValue ? "True" : "False") + "<br>";
115 }
116
117
118 // ================     XGUI_InspectionPanel    ================
119
120 XGUI_InspectionPanel::XGUI_InspectionPanel(QWidget* theParent, XGUI_Workshop* theWorkshop)
121   : QDockWidget(theParent),
122   myWorkshop(theWorkshop)
123 {
124   setWindowTitle(tr("Inspection Panel"));
125   setObjectName(INSPECTION_PANEL);
126   setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
127
128   myStackWgt = new QStackedWidget(this);
129
130   // Create shape selection page
131   QSplitter* aSplitter = new QSplitter(Qt::Vertical, myStackWgt);
132
133   // Create an internal widget
134   QWidget* aNameWgt = new QWidget(aSplitter);
135   QHBoxLayout* aNameLayout = new QHBoxLayout(aNameWgt);
136   aNameLayout->setContentsMargins(3, 0, 3, 0);
137   aNameLayout->addWidget(new QLabel(tr("Object"), aNameWgt));
138   myNameEdt = new QLineEdit(aNameWgt);
139   myNameEdt->setReadOnly(true);
140   aNameLayout->addWidget(myNameEdt);
141
142   aSplitter->addWidget(aNameWgt);
143
144   // Table with sub-shapes
145   mySubShapesTab = new QTableWidget(9, 2, aSplitter);
146   mySubShapesTab->setFocusPolicy(Qt::NoFocus);
147   mySubShapesTab->verticalHeader()->hide();
148   QStringList aTitles;
149   aTitles << tr("Sub-shapes") << tr("Number");
150   mySubShapesTab->setHorizontalHeaderLabels(aTitles);
151
152   QStringList aSubShapes;
153   aSubShapes << tr("SHAPE") << tr("COMPOUND") << tr("COMPSOLID") <<
154     tr("SOLID") << tr("SHELL") << tr("FACE") << tr("WIRE") << tr("EDGE") << tr("VERTEX");
155   int i = 0;
156   foreach(QString aType, aSubShapes) {
157     QTableWidgetItem* aItem = new QTableWidgetItem(aType);
158     aItem->setFlags(Qt::ItemIsEnabled);
159     mySubShapesTab->setItem(i++, 0, aItem);
160   }
161   for (i = 0; i < 9; i++) {
162     QTableWidgetItem* aItem = new QTableWidgetItem("");
163     aItem->setFlags(Qt::ItemIsEnabled);
164     aItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
165     mySubShapesTab->setItem(i, 1, aItem);
166   }
167   mySubShapesTab->setColumnWidth(0, 90);
168   mySubShapesTab->setColumnWidth(1, 70);
169
170   aSplitter->addWidget(mySubShapesTab);
171
172   // Type of object
173   QWidget* aTypeWgt = new QWidget(aSplitter);
174   QHBoxLayout* aTypeLayout = new QHBoxLayout(aTypeWgt);
175   aTypeLayout->setContentsMargins(3, 0, 3, 0);
176
177   aTypeLayout->addWidget(new QLabel(tr("Type:"), aTypeWgt));
178   myTypeLbl = new QLabel("", aTypeWgt);
179   aTypeLayout->addWidget(myTypeLbl);
180
181   aSplitter->addWidget(aTypeWgt);
182
183   myTypeParams = new QTextBrowser(aSplitter);
184   myTypeParams->setReadOnly(true);
185   myTypeParams->setFocusPolicy(Qt::NoFocus);
186   myTypeParams->viewport()->setBackgroundRole(QPalette::Window);
187
188   aSplitter->addWidget(myTypeParams);
189
190   aSplitter->setCollapsible(0, false);
191   aSplitter->setCollapsible(1, false);
192   aSplitter->setCollapsible(2, false);
193   aSplitter->setCollapsible(3, false);
194
195   QList<int> aSizes;
196   aSizes << 10 << 140 << 10;
197   aSplitter->setSizes(aSizes);
198
199   myShapePanelId = myStackWgt->addWidget(aSplitter);
200
201   // Create feature selection page
202   QScrollArea* aScroll = new QScrollArea(myStackWgt);
203   aScroll->setWidgetResizable(true);
204   aScroll->setFrameStyle(QFrame::NoFrame);
205
206   myFeaturePane = new ModuleBase_PageWidget(aScroll);
207   myFeatureLayout = new QGridLayout(myFeaturePane);
208   myFeatureLayout->setContentsMargins(3, 3, 3, 3);
209   aScroll->setWidget(myFeaturePane);
210   //myFeaturePane->setEnabled(false);
211
212   myFeaturePanelId = myStackWgt->addWidget(aScroll);
213
214   setWidget(myStackWgt);
215   connect(myWorkshop->selector(), SIGNAL(selectionChanged()), SLOT(onSelectionChanged()));
216 }
217
218 //********************************************************************
219 XGUI_InspectionPanel::~XGUI_InspectionPanel()
220 {
221 }
222
223 //********************************************************************
224 void XGUI_InspectionPanel::setSubShapeValue(SudShape theId, int theVal)
225 {
226   mySubShapesTab->item(theId, 1)->setText(QString::number(theVal));
227 }
228
229 //********************************************************************
230 void XGUI_InspectionPanel::clearContent()
231 {
232   myStackWgt->setCurrentIndex(myFeaturePanelId);
233   setName("");
234   for (int i = 0; i <= VertexId; i++) {
235     mySubShapesTab->item((SudShape)i, 1)->setText("");
236   }
237   myTypeLbl->setText("");
238   setParamsText("");
239
240   myFeaturePane->clearPage();
241 }
242
243 //********************************************************************
244 void XGUI_InspectionPanel::onSelectionChanged()
245 {
246   if (!isVisible())
247     return;
248
249   clearContent();
250
251   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
252   QList<ModuleBase_ViewerPrsPtr> aSelectedList =
253     aSelection->getSelected(myWorkshop->selector()->placeOfSelection());
254
255   if (aSelectedList.count() > 0) {
256     ModuleBase_ViewerPrsPtr aPrs = aSelectedList.first();
257     FieldStepPtr aStep =
258       std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aPrs->object());
259     if (aStep)
260       return;
261     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aPrs->object());
262     if (aFeature.get()) {
263       myStackWgt->setCurrentIndex(myFeaturePanelId);
264       buildFeaturePane(aFeature);
265     }
266     else {
267       TopoDS_Shape aShape = ModuleBase_Tools::getSelectedShape(aPrs);
268       if (aShape.IsNull()) {
269         ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
270         if (aRes.get()) {
271           GeomShapePtr aShpPtr = aRes->shape();
272           if (aShpPtr.get()) {
273             aShape = aShpPtr->impl<TopoDS_Shape>();
274           }
275         }
276       }
277       if (aShape.IsNull()) {
278         myStackWgt->setCurrentIndex(myFeaturePanelId);
279         return;
280       }
281       myStackWgt->setCurrentIndex(myShapePanelId);
282       GeomShapePtr aShapePtr(new GeomAPI_Shape());
283       aShapePtr->setImpl(new TopoDS_Shape(aShape));
284
285       ModuleBase_ViewerPrsPtr aPrsCopy(new ModuleBase_ViewerPrs(aPrs->object(), aShapePtr));
286       setName(XGUI_Tools::generateName(aPrsCopy));
287       setShapeContent(aShape);
288       setShapeParams(aShape);
289     }
290   }
291 }
292
293 //********************************************************************
294 void XGUI_InspectionPanel::setName(const QString& theName)
295 {
296   myNameEdt->setText(theName);
297 }
298
299 //********************************************************************
300 void XGUI_InspectionPanel::setShapeContent(const TopoDS_Shape& theShape)
301 {
302   try {
303     OCC_CATCH_SIGNALS;
304     int iType, nbTypes[TopAbs_SHAPE];
305     for (iType = 0; iType < TopAbs_SHAPE; ++iType) {
306       nbTypes[iType] = 0;
307     }
308     nbTypes[theShape.ShapeType()]++;
309
310     TopTools_MapOfShape aMapOfShape;
311     aMapOfShape.Add(theShape);
312     TopTools_ListOfShape aListOfShape;
313     aListOfShape.Append(theShape);
314
315     TopTools_ListIteratorOfListOfShape itL(aListOfShape);
316     for (; itL.More(); itL.Next()) {
317       TopoDS_Shape sp = itL.Value();
318       TopoDS_Iterator it(sp);
319       for (; it.More(); it.Next()) {
320         TopoDS_Shape s = it.Value();
321         if (aMapOfShape.Add(s)) {
322           aListOfShape.Append(s);
323           nbTypes[s.ShapeType()]++;
324         }
325       }
326     }
327     setSubShapeValue(VertexId, nbTypes[TopAbs_VERTEX]);
328     setSubShapeValue(EdgeId, nbTypes[TopAbs_EDGE]);
329     setSubShapeValue(WireId, nbTypes[TopAbs_WIRE]);
330     setSubShapeValue(FaceId, nbTypes[TopAbs_FACE]);
331     setSubShapeValue(ShellId, nbTypes[TopAbs_SHELL]);
332     setSubShapeValue(SolidId, nbTypes[TopAbs_SOLID]);
333     setSubShapeValue(CompsolidId, nbTypes[TopAbs_COMPSOLID]);
334     setSubShapeValue(CompoundId, nbTypes[TopAbs_COMPOUND]);
335     setSubShapeValue(ShapeId, aMapOfShape.Extent());
336   }
337   catch (Standard_Failure) {
338   }
339 }
340
341 //********************************************************************
342 void XGUI_InspectionPanel::setShapeParams(const TopoDS_Shape& theShape)
343 {
344   GeomShapePtr aShape(new GeomAPI_Shape);
345   aShape->setImpl(new TopoDS_Shape(theShape));
346
347   switch (aShape->shapeType()) {
348   case GeomAPI_Shape::VERTEX:
349     fillVertex(aShape->vertex());
350     break;
351   case GeomAPI_Shape::EDGE:
352     fillEdge(aShape->edge());
353     break;
354   case GeomAPI_Shape::FACE:
355     fillFace(aShape->face());
356     break;
357   case GeomAPI_Shape::SOLID:
358     fillSolid(aShape->solid());
359     break;
360   case GeomAPI_Shape::WIRE:
361     fillWire(aShape->wire());
362     break;
363   case GeomAPI_Shape::SHELL:
364     fillShell(aShape->shell());
365     break;
366   case GeomAPI_Shape::COMPSOLID:
367   case GeomAPI_Shape::COMPOUND:
368     fillContainer(aShape);
369     break;
370   default: // [to avoid compilation warning]
371     break;
372   }
373 }
374
375 //********************************************************************
376 void XGUI_InspectionPanel::fillVertex(const GeomVertexPtr& theVertex)
377 {
378   GeomPointPtr aPoint = theVertex->point();
379
380   myTypeLbl->setText(tr("Vertex"));
381
382   QString aParams;
383   appendPointToParameters(tr("Coordinates"), aPoint, aParams);
384   setParamsText(aParams);
385 }
386
387 //********************************************************************
388 void XGUI_InspectionPanel::fillEdge(const GeomEdgePtr& theEdge)
389 {
390   QString aParams;
391   if (theEdge->isDegenerated())
392     appendNamedValueToParameters(tr("Degenerated"), true, aParams);
393
394   GeomPointPtr aStartPnt = theEdge->firstPoint();
395   GeomPointPtr aEndPnt = theEdge->lastPoint();
396   bool addStartEndPoints = false;
397
398   if (theEdge->isLine()) {
399     myTypeLbl->setText(tr("Line segment"));
400     addStartEndPoints = true;
401   }
402   else {
403     GeomCirclePtr aCircle = theEdge->circle();
404     if (aCircle) {
405       addStartEndPoints = aStartPnt->distance(aEndPnt) >= Precision::Confusion();
406       if (addStartEndPoints)
407         myTypeLbl->setText(tr("Arc of circle"));
408       else
409         myTypeLbl->setText(tr("Circle"));
410
411       appendPointToParameters(tr("Center"), aCircle->center(), aParams);
412       appendDirToParameters(tr("Normal"), aCircle->normal(), aParams);
413       appendGroupNameToParameters(tr("Dimensions"), aParams);
414       appendNamedValueToParameters(tr("Radius"), aCircle->radius(), aParams);
415     }
416     else {
417       GeomEllipsePtr anEllipse = theEdge->ellipse();
418       if (anEllipse) {
419         addStartEndPoints = aStartPnt->distance(aEndPnt) >= Precision::Confusion();
420         if (addStartEndPoints)
421           myTypeLbl->setText(tr("Arc of ellipse"));
422         else
423           myTypeLbl->setText(tr("Ellipse"));
424
425         appendPointToParameters(tr("Center"), anEllipse->center(), aParams);
426         appendDirToParameters(tr("Normal"), anEllipse->normal(), aParams);
427         appendGroupNameToParameters(tr("Dimensions"), aParams);
428         appendNamedValueToParameters(tr("Major radius"), anEllipse->majorRadius(), aParams);
429         appendNamedValueToParameters(tr("Minor radius"), anEllipse->minorRadius(), aParams);
430       }
431       else
432         // Common case
433         myTypeLbl->setText(tr("Edge"));
434     }
435   }
436
437   if (addStartEndPoints) {
438     appendPointToParameters(tr("Start point"), aStartPnt, aParams);
439     appendPointToParameters(tr("End point"), aEndPnt, aParams);
440   }
441   setParamsText(aParams);
442 }
443
444 //********************************************************************
445 void XGUI_InspectionPanel::fillWire(const GeomWirePtr& theWire)
446 {
447   QString aParams;
448   appendNamedValueToParameters(tr("Closed"), theWire->isClosed(), aParams);
449
450   // check the wire is a polygon
451   std::list<GeomPointPtr> aPolygonPoints;
452   if (theWire->isPolygon(aPolygonPoints)) {
453     myTypeLbl->setText(tr("Polygon"));
454     int aCornerIndex = 0;
455     for (std::list<GeomPointPtr>::const_iterator aPtIt = aPolygonPoints.begin();
456          aPtIt != aPolygonPoints.end(); ++aPtIt)
457        appendPointToParameters(tr("Point") + " " + QString::number(++aCornerIndex),
458                                *aPtIt, aParams);
459   }
460   else
461     myTypeLbl->setText(tr("Wire"));
462
463   setParamsText(aParams);
464 }
465
466 //********************************************************************
467 void XGUI_InspectionPanel::fillFace(const GeomFacePtr& theFace)
468 {
469   QString aParams;
470   // 1. Plane and planar faces
471   GeomPlanePtr aPlane = theFace->getPlane();
472   if (aPlane) {
473     bool isCommonCase = true;
474     // Check face bounded by circle or ellipse
475     std::list<GeomShapePtr> aSubs = theFace->subShapes(GeomAPI_Shape::EDGE);
476     if (aSubs.size() == 1) {
477       GeomEdgePtr anEdge = aSubs.front()->edge();
478       if (anEdge->isCircle() || anEdge->isEllipse()) {
479         fillEdge(anEdge);
480         isCommonCase = false;
481         myTypeLbl->setText(tr("Disk"));
482       }
483     }
484     else {
485       // Check face bounded by a single wire which is rectangle
486       aSubs = theFace->subShapes(GeomAPI_Shape::WIRE);
487       if (aSubs.size() == 1) {
488         GeomWirePtr aWire = aSubs.front()->wire();
489         std::list<GeomPointPtr> aCorners;
490         if (aWire->isRectangle(aCorners)) {
491           GeomPointPtr aBaseCorner = aCorners.front();
492           aCorners.pop_front();
493
494           double aWidth = aBaseCorner->distance(aCorners.front());
495           double aHeight = aBaseCorner->distance(aCorners.back());
496
497           myTypeLbl->setText(tr("Rectangle"));
498           appendPointToParameters(tr("Corner"), aBaseCorner, aParams);
499           appendDirToParameters(tr("Normal"), aPlane->direction(), aParams);
500           appendGroupNameToParameters(tr("Dimensions"), aParams);
501           appendNamedValueToParameters(tr("Width"), aWidth, aParams);
502           appendNamedValueToParameters(tr("Height"), aHeight, aParams);
503           setParamsText(aParams);
504
505           isCommonCase = false;
506         }
507       }
508     }
509
510     if (isCommonCase)
511       setPlaneType(tr("Plane"), aPlane);
512   }
513   else {
514     // 2. Sphere
515     GeomSpherePtr aSphere = theFace->getSphere();
516     if (aSphere)
517       setSphereType(tr("Sphere"), aSphere);
518     else {
519       // 3. Cylinder
520       GeomCylinderPtr aCylinder = theFace->getCylinder();
521       if (aCylinder)
522         setCylinderType(tr("Cylinder"), aCylinder);
523       else {
524         // 4. Cone
525         GeomConePtr aCone = theFace->getCone();
526         if (aCone)
527           setConeType(tr("Cone"), aCone);
528         else {
529           // 5. Torus
530           GeomTorusPtr aTorus = theFace->getTorus();
531           if (aTorus)
532             setTorusType(tr("Torus"), aTorus);
533           else
534             // 6. Common case
535             myTypeLbl->setText(tr("Face"));
536         }
537       }
538     }
539   }
540 }
541
542 //********************************************************************
543 void XGUI_InspectionPanel::fillShell(const GeomShellPtr& theShell)
544 {
545   // 1. Sphere
546   GeomSpherePtr aSphere = theShell->getSphere();
547   if (aSphere)
548     setSphereType(tr("Sphere"), aSphere);
549   else {
550     // 2. Cylinder
551     GeomCylinderPtr aCylinder = theShell->getCylinder();
552     if (aCylinder)
553       setCylinderType(tr("Cylinder"), aCylinder);
554     else {
555       // 3. Cone
556       GeomConePtr aCone = theShell->getCone();
557       if (aCone)
558         setConeType(tr("Cone"), aCone);
559       else {
560         // 4. Torus
561         GeomTorusPtr aTorus = theShell->getTorus();
562         if (aTorus)
563           setTorusType(tr("Torus"), aTorus);
564         else {
565           // 5. Axis-aligned/Rotated Box
566           GeomBoxPtr aBox = theShell->getParallelepiped();
567           if (aBox) {
568             if (aBox->isAxesAligned())
569               setBoxType(tr("Box"), aBox);
570             else
571               setRotatedBoxType(tr("Rotated Box"), aBox);
572           }
573           else
574             // 6. Common case
575             myTypeLbl->setText(tr("Shell"));
576         }
577       }
578     }
579   }
580 }
581
582 //********************************************************************
583 void XGUI_InspectionPanel::fillSolid(const GeomSolidPtr& theSolid)
584 {
585   // 1. Sphere
586   GeomSpherePtr aSphere = theSolid->getSphere();
587   if (aSphere)
588     setSphereType(tr("Sphere"), aSphere);
589   else {
590     // 2. Cylinder
591     GeomCylinderPtr aCylinder = theSolid->getCylinder();
592     if (aCylinder)
593       setCylinderType(tr("Cylinder"), aCylinder);
594     else {
595       // 3. Cone
596       GeomConePtr aCone = theSolid->getCone();
597       if (aCone)
598         setConeType(tr("Cone"), aCone);
599       else {
600         // 4. Torus
601         GeomTorusPtr aTorus = theSolid->getTorus();
602         if (aTorus)
603           setTorusType(tr("Torus"), aTorus);
604         else {
605           // 5. Axis-aligned/Rotated Box
606           GeomBoxPtr aBox = theSolid->getParallelepiped();
607           if (aBox) {
608             if (aBox->isAxesAligned())
609               setBoxType(tr("Box"), aBox);
610             else
611               setRotatedBoxType(tr("Rotated Box"), aBox);
612           }
613           else
614             // 6. Common case
615             myTypeLbl->setText(tr("Solid"));
616         }
617       }
618     }
619   }
620 }
621
622 //********************************************************************
623 void XGUI_InspectionPanel::fillContainer(const GeomShapePtr& theShape)
624 {
625   if (theShape->shapeType() == GeomAPI_Shape::COMPSOLID)
626     myTypeLbl->setText("CompSolid");
627   else if (theShape->shapeType() == GeomAPI_Shape::COMPOUND)
628     myTypeLbl->setText("Compound");
629
630   // fill bounding box
631   TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
632   Bnd_Box aBB;
633   BRepBndLib::Add(aShape, aBB);
634
635   if (aBB.IsVoid())
636     return;
637
638   gp_Pnt aMinPnt = aBB.CornerMin();
639   GeomPointPtr aMinPoint(new GeomAPI_Pnt(aMinPnt.X(), aMinPnt.Y(), aMinPnt.Z()));
640
641   gp_Pnt aMaxPnt = aBB.CornerMax();
642   GeomPointPtr aMaxPoint(new GeomAPI_Pnt(aMaxPnt.X(), aMaxPnt.Y(), aMaxPnt.Z()));
643
644   QString aParams;
645   appendGroupNameToParameters(tr("Bounding box"), aParams);
646   appendPointToParameters(tr("Minimal corner"), aMinPoint, aParams);
647   appendPointToParameters(tr("Maximal corner"), aMaxPoint, aParams);
648 }
649
650 //********************************************************************
651 void XGUI_InspectionPanel::setPlaneType(const QString& theTitle,
652                                         const std::shared_ptr<GeomAPI_Pln>& thePlane)
653 {
654   myTypeLbl->setText(theTitle);
655   QString aParams;
656   appendPointToParameters(tr("Origin"), thePlane->location(), aParams);
657   appendDirToParameters(tr("Normal"), thePlane->direction(), aParams);
658   setParamsText(aParams);
659 }
660
661 //********************************************************************
662 void XGUI_InspectionPanel::setSphereType(const QString& theTitle,
663                                          const std::shared_ptr<GeomAPI_Sphere>& theSphere)
664 {
665   myTypeLbl->setText(theTitle);
666   QString aParams;
667   appendPointToParameters(tr("Center"), theSphere->center(), aParams);
668   appendGroupNameToParameters(tr("Dimensions"), aParams);
669   appendNamedValueToParameters(tr("Radius"), theSphere->radius(), aParams);
670   setParamsText(aParams);
671 }
672
673 //********************************************************************
674 void XGUI_InspectionPanel::setCylinderType(const QString& theTitle,
675                                            const std::shared_ptr<GeomAPI_Cylinder>& theCyl)
676 {
677   myTypeLbl->setText(theTitle);
678   QString aParams;
679   appendPointToParameters(tr("Position"), theCyl->location(), aParams);
680   appendDirToParameters(tr("Axis"), theCyl->axis(), aParams);
681   appendGroupNameToParameters(tr("Dimensions"), aParams);
682   appendNamedValueToParameters(tr("Radius"), theCyl->radius(), aParams);
683   appendNamedValueToParameters(tr("Height"), theCyl->height(), aParams);
684   setParamsText(aParams);
685 }
686
687 //********************************************************************
688 void XGUI_InspectionPanel::setConeType(const QString& theTitle,
689                                        const std::shared_ptr<GeomAPI_Cone>& theCone)
690 {
691   myTypeLbl->setText(theTitle);
692   QString aParams;
693   appendPointToParameters(tr("Position"), theCone->location(), aParams);
694   appendDirToParameters(tr("Axis"), theCone->axis(), aParams);
695   appendGroupNameToParameters(tr("Dimensions"), aParams);
696   appendNamedValueToParameters(tr("Radius 1"), theCone->radius1(), aParams);
697   appendNamedValueToParameters(tr("Radius 2"), theCone->radius2(), aParams);
698   appendNamedValueToParameters(tr("Height"), theCone->height(), aParams);
699   setParamsText(aParams);
700 }
701
702 //********************************************************************
703 void XGUI_InspectionPanel::setTorusType(const QString& theTitle,
704                                         const std::shared_ptr<GeomAPI_Torus>& theTorus)
705 {
706   myTypeLbl->setText(theTitle);
707   QString aParams;
708   appendPointToParameters(tr("Center"), theTorus->center(), aParams);
709   appendDirToParameters(tr("Axis"), theTorus->direction(), aParams);
710   appendGroupNameToParameters(tr("Dimensions"), aParams);
711   appendNamedValueToParameters(tr("Major radius"), theTorus->majorRadius(), aParams);
712   appendNamedValueToParameters(tr("Minor radius"), theTorus->minorRadius(), aParams);
713   setParamsText(aParams);
714 }
715
716 //********************************************************************
717 void XGUI_InspectionPanel::setBoxType(const QString& theTitle,
718                                       const std::shared_ptr<GeomAPI_Box>& theBox)
719 {
720   myTypeLbl->setText(theTitle);
721   QString aParams;
722   appendPointToParameters(tr("Position"), theBox->axes()->origin(), aParams);
723   appendGroupNameToParameters(tr("Dimensions"), aParams);
724   appendNamedValueToParameters(tr("Width"), theBox->width(), aParams);
725   appendNamedValueToParameters(tr("Depth"), theBox->depth(), aParams);
726   appendNamedValueToParameters(tr("Height"), theBox->height(), aParams);
727   setParamsText(aParams);
728 }
729
730 //********************************************************************
731 void XGUI_InspectionPanel::setRotatedBoxType(const QString& theTitle,
732                                              const std::shared_ptr<GeomAPI_Box>& theBox)
733 {
734   myTypeLbl->setText(theTitle);
735   QString aParams;
736   std::shared_ptr<GeomAPI_Ax3> anAxes = theBox->axes();
737   appendPointToParameters(tr("Position"), anAxes->origin(), aParams);
738   appendDirToParameters(tr("Z axis"), anAxes->normal(), aParams);
739   appendDirToParameters(tr("X axis"), anAxes->dirX(), aParams);
740   appendGroupNameToParameters(tr("Dimensions"), aParams);
741   appendNamedValueToParameters(tr("Width"), theBox->width(), aParams);
742   appendNamedValueToParameters(tr("Depth"), theBox->depth(), aParams);
743   appendNamedValueToParameters(tr("Height"), theBox->height(), aParams);
744   setParamsText(aParams);
745 }
746
747
748 //********************************************************************
749 void XGUI_InspectionPanel::setParamsText(const QString& theText)
750 {
751   myTypeParams->setText(theText);
752 }
753
754 //********************************************************************
755 void XGUI_InspectionPanel::buildFeaturePane(const FeaturePtr& theFeature)
756 {
757   std::string aXmlCfg, aDescription;
758   myWorkshop->module()->getXMLRepresentation(theFeature->getKind(), aXmlCfg, aDescription);
759   if (!aXmlCfg.empty()) {
760     QList<ModuleBase_ModelWidget*> aWidgets;
761     if (!myWorkshop->module()->createWidgets(theFeature, aXmlCfg.c_str(), aWidgets)) {
762       ModuleBase_WidgetFactory aFactory(aXmlCfg, myWorkshop->moduleConnector());
763       aFactory.createWidget(myFeaturePane);
764       aWidgets = aFactory.getModelWidgets();
765     }
766     foreach(ModuleBase_ModelWidget* aWgt, aWidgets) {
767       if (aWgt->isInformative()) {
768         aWgt->setFeature(theFeature, false, false);
769         aWgt->setReadOnly(true);
770         aWgt->setEditingMode(true);
771         aWgt->restoreValue();
772         aWgt->showInformativePage();
773       }
774       else {
775         aWgt->setFeature(theFeature, false, false);
776         aWgt->setEditingMode(true);
777         aWgt->hide();
778       }
779     }
780   }
781 }
782
783 void XGUI_InspectionPanel::showEvent(QShowEvent* theEvent)
784 {
785   QDockWidget::showEvent(theEvent);
786   onSelectionChanged();
787 }