Salome HOME
Issue #2998: Add help description for automatic creation of constraints
[modules/shaper.git] / src / XGUI / XGUI_InspectionPanel.cpp
index 16ef5c1649512a63c08beee39240038da89ed397..6d615ac06dbe53dce38181ce38f964017dc631b9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "XGUI_InspectionPanel.h"
@@ -25,6 +24,7 @@
 
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_Tools.h>
+#include <ModelAPI_ResultField.h>
 
 #include <ModelAPI_Result.h>
 
@@ -52,6 +52,8 @@
 #include <QTableWidget>
 #include <QHeaderView>
 #include <QTextBrowser>
+#include <QResizeEvent>
+#include <QSplitter>
 
 #include <BRepBndLib.hxx>
 #include <TopoDS_Iterator.hxx>
@@ -114,27 +116,21 @@ XGUI_InspectionPanel::XGUI_InspectionPanel(QWidget* theParent, XGUI_SelectionMgr
   setObjectName(INSPECTION_PANEL);
   setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
 
-  QScrollArea* aScrollArea = new QScrollArea(this);
-  setWidget(aScrollArea);
+  QSplitter* aSplitter = new QSplitter(Qt::Vertical, this);
 
   // Create an internal widget
-  QWidget* aMainWidget = new QWidget(aScrollArea);
-
-  QVBoxLayout* aMainLayout = new QVBoxLayout(aMainWidget);
-  aMainLayout->setContentsMargins(5, 5, 5, 5);
-
-  QWidget* aNameWgt = new QWidget(aMainWidget);
+  QWidget* aNameWgt = new QWidget(aSplitter);
   QHBoxLayout* aNameLayout = new QHBoxLayout(aNameWgt);
-  aNameLayout->setContentsMargins(0, 0, 0, 0);
+  aNameLayout->setContentsMargins(3, 0, 3, 0);
   aNameLayout->addWidget(new QLabel(tr("Object"), aNameWgt));
   myNameEdt = new QLineEdit(aNameWgt);
   myNameEdt->setReadOnly(true);
   aNameLayout->addWidget(myNameEdt);
 
-  aMainLayout->addWidget(aNameWgt);
+  aSplitter->addWidget(aNameWgt);
 
   // Table with sub-shapes
-  mySubShapesTab = new QTableWidget(9, 2, aMainWidget);
+  mySubShapesTab = new QTableWidget(9, 2, aSplitter);
   mySubShapesTab->setFocusPolicy(Qt::NoFocus);
   mySubShapesTab->verticalHeader()->hide();
   QStringList aTitles;
@@ -142,8 +138,8 @@ XGUI_InspectionPanel::XGUI_InspectionPanel(QWidget* theParent, XGUI_SelectionMgr
   mySubShapesTab->setHorizontalHeaderLabels(aTitles);
 
   QStringList aSubShapes;
-  aSubShapes << "SHAPE" << "COMPOUND" << "COMPSOLID" <<
-    "SOLID" << "SHELL" << "FACE" << "WIRE" << "EDGE" << "VERTEX";
+  aSubShapes << tr("SHAPE") << tr("COMPOUND") << tr("COMPSOLID") <<
+    tr("SOLID") << tr("SHELL") << tr("FACE") << tr("WIRE") << tr("EDGE") << tr("VERTEX");
   int i = 0;
   foreach(QString aType, aSubShapes) {
     QTableWidgetItem* aItem = new QTableWidgetItem(aType);
@@ -159,33 +155,36 @@ XGUI_InspectionPanel::XGUI_InspectionPanel(QWidget* theParent, XGUI_SelectionMgr
   mySubShapesTab->setColumnWidth(0, 90);
   mySubShapesTab->setColumnWidth(1, 70);
 
-  mySubShapesTab->setMaximumWidth(170);
-  mySubShapesTab->setMinimumHeight(300);
-
-  aMainLayout->addWidget(mySubShapesTab);
+  aSplitter->addWidget(mySubShapesTab);
 
   // Type of object
-  QWidget* aTypeWgt = new QWidget(aMainWidget);
+  QWidget* aTypeWgt = new QWidget(aSplitter);
   QHBoxLayout* aTypeLayout = new QHBoxLayout(aTypeWgt);
-  aTypeLayout->setContentsMargins(0, 0, 0, 0);
+  aTypeLayout->setContentsMargins(3, 0, 3, 0);
 
   aTypeLayout->addWidget(new QLabel(tr("Type:"), aTypeWgt));
   myTypeLbl = new QLabel("", aTypeWgt);
   aTypeLayout->addWidget(myTypeLbl);
 
-  aMainLayout->addWidget(aTypeWgt);
+  aSplitter->addWidget(aTypeWgt);
 
-  myTypeParams = new QTextBrowser(aMainWidget);
-  myTypeParams->setMaximumWidth(170);
-  myTypeParams->setMaximumHeight(160);
+  myTypeParams = new QTextBrowser(aSplitter);
   myTypeParams->setReadOnly(true);
   myTypeParams->setFocusPolicy(Qt::NoFocus);
-  myTypeParams->setFrameStyle(QFrame::NoFrame);
   myTypeParams->viewport()->setBackgroundRole(QPalette::Window);
 
-  aMainLayout->addWidget(myTypeParams);
+  aSplitter->addWidget(myTypeParams);
+
+  aSplitter->setCollapsible(0, false);
+  aSplitter->setCollapsible(1, false);
+  aSplitter->setCollapsible(2, false);
+  aSplitter->setCollapsible(3, false);
+
+  QList<int> aSizes;
+  aSizes << 10 << 140 << 10;
+  aSplitter->setSizes(aSizes);
 
-  aScrollArea->setWidget(aMainWidget);
+  setWidget(aSplitter);
 
   connect(mySelectionMgr, SIGNAL(selectionChanged()), SLOT(onSelectionChanged()));
 }
@@ -209,7 +208,7 @@ void XGUI_InspectionPanel::clearContent()
     mySubShapesTab->item((SudShape)i, 1)->setText("");
   }
   myTypeLbl->setText("");
-  myTypeParams->setText("");
+  setParamsText("");
 }
 
 //********************************************************************
@@ -219,12 +218,35 @@ void XGUI_InspectionPanel::onSelectionChanged()
   XGUI_Selection* aSelection = mySelectionMgr->selection();
   QList<ModuleBase_ViewerPrsPtr> aSelectedList =
     aSelection->getSelected(ModuleBase_ISelection::Viewer);
+
+  QList<ModuleBase_ViewerPrsPtr> anOBSelected =
+    aSelection->getSelected(ModuleBase_ISelection::Browser);
+  if (!anOBSelected.isEmpty())
+    ModuleBase_ISelection::appendSelected(anOBSelected, aSelectedList);
+
   if (aSelectedList.count() > 0) {
     ModuleBase_ViewerPrsPtr aPrs = aSelectedList.first();
+    FieldStepPtr aStep =
+      std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aPrs->object());
+    if (aStep)
+      return;
     TopoDS_Shape aShape = ModuleBase_Tools::getSelectedShape(aPrs);
+    if (aShape.IsNull()) {
+      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
+      if (aRes.get()) {
+        GeomShapePtr aShpPtr = aRes->shape();
+        if (aShpPtr.get()) {
+          aShape = aShpPtr->impl<TopoDS_Shape>();
+        }
+      }
+    }
     if (aShape.IsNull())
       return;
-    setName(XGUI_Tools::generateName(aPrs));
+    GeomShapePtr aShapePtr(new GeomAPI_Shape());
+    aShapePtr->setImpl(new TopoDS_Shape(aShape));
+
+    ModuleBase_ViewerPrsPtr aPrsCopy(new ModuleBase_ViewerPrs(aPrs->object(), aShapePtr));
+    setName(XGUI_Tools::generateName(aPrsCopy));
     setShapeContent(aShape);
     setShapeParams(aShape);
   }
@@ -275,8 +297,6 @@ void XGUI_InspectionPanel::setShapeContent(const TopoDS_Shape& theShape)
     setSubShapeValue(ShapeId, aMapOfShape.Extent());
   }
   catch (Standard_Failure) {
-    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
-    //SetErrorCode(aFail->GetMessageString());
   }
 }
 
@@ -321,7 +341,7 @@ void XGUI_InspectionPanel::fillVertex(const GeomVertexPtr& theVertex)
 
   QString aParams;
   appendPointToParameters(tr("Coordinates"), aPoint, aParams);
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 //********************************************************************
@@ -378,7 +398,7 @@ void XGUI_InspectionPanel::fillEdge(const GeomEdgePtr& theEdge)
     appendPointToParameters(tr("Start point"), aStartPnt, aParams);
     appendPointToParameters(tr("End point"), aEndPnt, aParams);
   }
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 //********************************************************************
@@ -400,7 +420,7 @@ void XGUI_InspectionPanel::fillWire(const GeomWirePtr& theWire)
   else
     myTypeLbl->setText(tr("Wire"));
 
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 //********************************************************************
@@ -439,7 +459,7 @@ void XGUI_InspectionPanel::fillFace(const GeomFacePtr& theFace)
           appendGroupNameToParameters(tr("Dimensions"), aParams);
           appendNamedValueToParameters(tr("Width"), aWidth, aParams);
           appendNamedValueToParameters(tr("Height"), aHeight, aParams);
-          myTypeParams->setText(aParams);
+          setParamsText(aParams);
 
           isCommonCase = false;
         }
@@ -567,8 +587,12 @@ void XGUI_InspectionPanel::fillContainer(const GeomShapePtr& theShape)
     myTypeLbl->setText("Compound");
 
   // fill bounding box
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
   Bnd_Box aBB;
-  BRepBndLib::Add(theShape->impl<TopoDS_Shape>(), aBB);
+  BRepBndLib::Add(aShape, aBB);
+
+  if (aBB.IsVoid())
+    return;
 
   gp_Pnt aMinPnt = aBB.CornerMin();
   GeomPointPtr aMinPoint(new GeomAPI_Pnt(aMinPnt.X(), aMinPnt.Y(), aMinPnt.Z()));
@@ -589,7 +613,7 @@ void XGUI_InspectionPanel::setPlaneType(const QString& theTitle,
   QString aParams;
   appendPointToParameters(tr("Origin"), thePlane->location(), aParams);
   appendDirToParameters(tr("Normal"), thePlane->direction(), aParams);
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 void XGUI_InspectionPanel::setSphereType(const QString& theTitle,
@@ -600,7 +624,7 @@ void XGUI_InspectionPanel::setSphereType(const QString& theTitle,
   appendPointToParameters(tr("Center"), theSphere->center(), aParams);
   appendGroupNameToParameters(tr("Dimensions"), aParams);
   appendNamedValueToParameters(tr("Radius"), theSphere->radius(), aParams);
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 void XGUI_InspectionPanel::setCylinderType(const QString& theTitle,
@@ -613,7 +637,7 @@ void XGUI_InspectionPanel::setCylinderType(const QString& theTitle,
   appendGroupNameToParameters(tr("Dimensions"), aParams);
   appendNamedValueToParameters(tr("Radius"), theCyl->radius(), aParams);
   appendNamedValueToParameters(tr("Height"), theCyl->height(), aParams);
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 void XGUI_InspectionPanel::setConeType(const QString& theTitle,
@@ -627,7 +651,7 @@ void XGUI_InspectionPanel::setConeType(const QString& theTitle,
   appendNamedValueToParameters(tr("Radius 1"), theCone->radius1(), aParams);
   appendNamedValueToParameters(tr("Radius 2"), theCone->radius2(), aParams);
   appendNamedValueToParameters(tr("Height"), theCone->height(), aParams);
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 void XGUI_InspectionPanel::setTorusType(const QString& theTitle,
@@ -640,7 +664,7 @@ void XGUI_InspectionPanel::setTorusType(const QString& theTitle,
   appendGroupNameToParameters(tr("Dimensions"), aParams);
   appendNamedValueToParameters(tr("Major radius"), theTorus->majorRadius(), aParams);
   appendNamedValueToParameters(tr("Minor radius"), theTorus->minorRadius(), aParams);
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 void XGUI_InspectionPanel::setBoxType(const QString& theTitle,
@@ -653,7 +677,7 @@ void XGUI_InspectionPanel::setBoxType(const QString& theTitle,
   appendNamedValueToParameters(tr("Width"), theBox->width(), aParams);
   appendNamedValueToParameters(tr("Depth"), theBox->depth(), aParams);
   appendNamedValueToParameters(tr("Height"), theBox->height(), aParams);
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
 }
 
 void XGUI_InspectionPanel::setRotatedBoxType(const QString& theTitle,
@@ -669,5 +693,11 @@ void XGUI_InspectionPanel::setRotatedBoxType(const QString& theTitle,
   appendNamedValueToParameters(tr("Width"), theBox->width(), aParams);
   appendNamedValueToParameters(tr("Depth"), theBox->depth(), aParams);
   appendNamedValueToParameters(tr("Height"), theBox->height(), aParams);
-  myTypeParams->setText(aParams);
+  setParamsText(aParams);
+}
+
+
+void XGUI_InspectionPanel::setParamsText(const QString& theText)
+{
+  myTypeParams->setText(theText);
 }