Salome HOME
Task #3005 : To be able to create a group on a whole result
[modules/shaper.git] / src / XGUI / XGUI_InspectionPanel.cpp
index 2ef6cefebffca4a267c090762ef7ed27e753d0c5..088f1eddc645a6cfb0fb623699c2b82dba9b4e6d 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>
 
@@ -53,6 +53,7 @@
 #include <QHeaderView>
 #include <QTextBrowser>
 #include <QResizeEvent>
+#include <QSplitter>
 
 #include <BRepBndLib.hxx>
 #include <TopoDS_Iterator.hxx>
@@ -115,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
-  myMainWidget = new QWidget(aScrollArea);
-
-  myMainLayout = new QVBoxLayout(myMainWidget);
-  myMainLayout->setContentsMargins(5, 5, 5, 5);
-
-  QWidget* aNameWgt = new QWidget(myMainWidget);
+  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);
 
-  myMainLayout->addWidget(aNameWgt);
+  aSplitter->addWidget(aNameWgt);
 
   // Table with sub-shapes
-  mySubShapesTab = new QTableWidget(9, 2, myMainWidget);
+  mySubShapesTab = new QTableWidget(9, 2, aSplitter);
   mySubShapesTab->setFocusPolicy(Qt::NoFocus);
   mySubShapesTab->verticalHeader()->hide();
   QStringList aTitles;
@@ -160,32 +155,36 @@ XGUI_InspectionPanel::XGUI_InspectionPanel(QWidget* theParent, XGUI_SelectionMgr
   mySubShapesTab->setColumnWidth(0, 90);
   mySubShapesTab->setColumnWidth(1, 70);
 
-  mySubShapesTab->setMaximumWidth(170);
-  mySubShapesTab->setMinimumHeight(300);
-
-  myMainLayout->addWidget(mySubShapesTab);
+  aSplitter->addWidget(mySubShapesTab);
 
   // Type of object
-  QWidget* aTypeWgt = new QWidget(myMainWidget);
+  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);
 
-  myMainLayout->addWidget(aTypeWgt);
+  aSplitter->addWidget(aTypeWgt);
 
-  myTypeParams = new QTextBrowser(myMainWidget);
-  myTypeParams->setFixedWidth(170);
+  myTypeParams = new QTextBrowser(aSplitter);
   myTypeParams->setReadOnly(true);
   myTypeParams->setFocusPolicy(Qt::NoFocus);
-  myTypeParams->setFrameStyle(QFrame::NoFrame);
   myTypeParams->viewport()->setBackgroundRole(QPalette::Window);
 
-  myMainLayout->addWidget(myTypeParams, 1);
+  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(myMainWidget);
+  setWidget(aSplitter);
 
   connect(mySelectionMgr, SIGNAL(selectionChanged()), SLOT(onSelectionChanged()));
 }
@@ -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);
   }
@@ -565,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()));
@@ -675,13 +701,3 @@ void XGUI_InspectionPanel::setParamsText(const QString& theText)
 {
   myTypeParams->setText(theText);
 }
-
-void XGUI_InspectionPanel::resizeEvent(QResizeEvent* theEvent)
-{
-  QSize aSize = theEvent->size();
-
-  int aHeight = aSize.height();
-
-  if (aHeight > 450) // 450 is a a minimal height
-    myMainWidget->setFixedHeight(aHeight - 30);
-}
\ No newline at end of file