Salome HOME
bos #29477 Information on shape in TUI. New 'shapeInfo' python method.
[modules/shaper.git] / src / XGUI / XGUI_InspectionPanel.cpp
index 523bdd94f981c2f878749061348bc0390ebe3d2a..0ca76001c3e31e8ce36b18f28308391fe70e429e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  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
 
 #include <ModelAPI_Result.h>
 
-#include <GeomAPI_Ax3.h>
-#include <GeomAPI_Box.h>
-#include <GeomAPI_Circ.h>
-#include <GeomAPI_Cone.h>
-#include <GeomAPI_Cylinder.h>
-#include <GeomAPI_Edge.h>
-#include <GeomAPI_Ellipse.h>
-#include <GeomAPI_Face.h>
-#include <GeomAPI_Pln.h>
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Shell.h>
-#include <GeomAPI_Solid.h>
-#include <GeomAPI_Sphere.h>
-#include <GeomAPI_Torus.h>
-#include <GeomAPI_Vertex.h>
-#include <GeomAPI_Wire.h>
-
 #include <QLayout>
 #include <QScrollArea>
 #include <QLabel>
 #include <QSplitter>
 #include <QStackedWidget>
 
-#include <BRepBndLib.hxx>
-#include <TopoDS_Iterator.hxx>
 #include <TopTools_MapOfShape.hxx>
 #include <TopTools_ListOfShape.hxx>
+#include <TopoDS_Iterator.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic
 
 
-// ================     Auxiliary functions     ================
-#define TITLE(val) ("<b>" + (val) + "</b>")
-
-static void appendPointToParameters(const QString& thePointTitle,
-                                    const GeomPointPtr& theCoord,
-                                          QString& theParams)
-{
-  theParams += TITLE(thePointTitle) +
-    "<br> X: " + QString::number(theCoord->x()) +
-    "<br> Y: " + QString::number(theCoord->y()) +
-    "<br> Z: " + QString::number(theCoord->z()) +
-    "<br>";
-}
-
-static void appendDirToParameters(const QString& theDirTitle,
-                                  const GeomDirPtr& theDirection,
-                                        QString& theParams)
-{
-  theParams += TITLE(theDirTitle) +
-    "<br> DX: " + QString::number(theDirection->x()) +
-    "<br> DY: " + QString::number(theDirection->y()) +
-    "<br> DZ: " + QString::number(theDirection->z()) +
-    "<br>";
-}
-
-static void appendGroupNameToParameters(const QString& theGroupTitle, QString& theParams)
-{
-  theParams += TITLE(theGroupTitle) + "<br>";
-}
-
-static void appendNamedValueToParameters(const QString& theName,
-                                         const double   theValue,
-                                               QString& theParams)
-{
-  theParams += theName + ": " + QString::number(theValue) + "<br>";
-}
-
-static void appendNamedValueToParameters(const QString& theName,
-                                         const bool     theValue,
-                                               QString& theParams)
-{
-  theParams += theName + ": " + (theValue ? "True" : "False") + "<br>";
-}
-
-
 // ================     XGUI_InspectionPanel    ================
-
 XGUI_InspectionPanel::XGUI_InspectionPanel(QWidget* theParent, XGUI_Workshop* theWorkshop)
   : QDockWidget(theParent),
   myWorkshop(theWorkshop)
@@ -285,7 +221,13 @@ void XGUI_InspectionPanel::onSelectionChanged()
       ModuleBase_ViewerPrsPtr aPrsCopy(new ModuleBase_ViewerPrs(aPrs->object(), aShapePtr));
       setName(XGUI_Tools::generateName(aPrsCopy));
       setShapeContent(aShape);
-      setShapeParams(aShape);
+
+      GeomShapePtr aGShape(new GeomAPI_Shape);
+      aGShape->setImpl(new TopoDS_Shape(aShape));
+      GeomAlgoAPI_ShapeInfo aShapeInfo(aGShape);
+      QString aParams = QString::fromStdString(aShapeInfo.html(this));
+      setParamsText(aParams);
+      myTypeLbl->setText(tr(aShapeInfo.shapeType().c_str()));
     }
   }
 }
@@ -338,413 +280,11 @@ void XGUI_InspectionPanel::setShapeContent(const TopoDS_Shape& theShape)
   }
 }
 
-//********************************************************************
-void XGUI_InspectionPanel::setShapeParams(const TopoDS_Shape& theShape)
-{
-  GeomShapePtr aShape(new GeomAPI_Shape);
-  aShape->setImpl(new TopoDS_Shape(theShape));
-
-  switch (aShape->shapeType()) {
-  case GeomAPI_Shape::VERTEX:
-    fillVertex(aShape->vertex());
-    break;
-  case GeomAPI_Shape::EDGE:
-    fillEdge(aShape->edge());
-    break;
-  case GeomAPI_Shape::FACE:
-    fillFace(aShape->face());
-    break;
-  case GeomAPI_Shape::SOLID:
-    fillSolid(aShape->solid());
-    break;
-  case GeomAPI_Shape::WIRE:
-    fillWire(aShape->wire());
-    break;
-  case GeomAPI_Shape::SHELL:
-    fillShell(aShape->shell());
-    break;
-  case GeomAPI_Shape::COMPSOLID:
-  case GeomAPI_Shape::COMPOUND:
-    fillContainer(aShape);
-    break;
-  default: // [to avoid compilation warning]
-    break;
-  }
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::fillVertex(const GeomVertexPtr& theVertex)
+std::string XGUI_InspectionPanel::translate(const char* theSource)
 {
-  GeomPointPtr aPoint = theVertex->point();
-
-  myTypeLbl->setText(tr("Vertex"));
-
-  QString aParams;
-  appendPointToParameters(tr("Coordinates"), aPoint, aParams);
-  setParamsText(aParams);
+  return std::string(tr(theSource).toStdString());
 }
 
-//********************************************************************
-void XGUI_InspectionPanel::fillEdge(const GeomEdgePtr& theEdge)
-{
-  QString aParams;
-  if (theEdge->isDegenerated())
-    appendNamedValueToParameters(tr("Degenerated"), true, aParams);
-
-  GeomPointPtr aStartPnt = theEdge->firstPoint();
-  GeomPointPtr aEndPnt = theEdge->lastPoint();
-  bool addStartEndPoints = false;
-
-  if (theEdge->isLine()) {
-    myTypeLbl->setText(tr("Line segment"));
-    addStartEndPoints = true;
-  }
-  else {
-    GeomCirclePtr aCircle = theEdge->circle();
-    if (aCircle) {
-      addStartEndPoints = aStartPnt->distance(aEndPnt) >= Precision::Confusion();
-      if (addStartEndPoints)
-        myTypeLbl->setText(tr("Arc of circle"));
-      else
-        myTypeLbl->setText(tr("Circle"));
-
-      appendPointToParameters(tr("Center"), aCircle->center(), aParams);
-      appendDirToParameters(tr("Normal"), aCircle->normal(), aParams);
-      appendGroupNameToParameters(tr("Dimensions"), aParams);
-      appendNamedValueToParameters(tr("Radius"), aCircle->radius(), aParams);
-    }
-    else {
-      GeomEllipsePtr anEllipse = theEdge->ellipse();
-      if (anEllipse) {
-        addStartEndPoints = aStartPnt->distance(aEndPnt) >= Precision::Confusion();
-        if (addStartEndPoints)
-          myTypeLbl->setText(tr("Arc of ellipse"));
-        else
-          myTypeLbl->setText(tr("Ellipse"));
-
-        appendPointToParameters(tr("Center"), anEllipse->center(), aParams);
-        appendDirToParameters(tr("Normal"), anEllipse->normal(), aParams);
-        appendGroupNameToParameters(tr("Dimensions"), aParams);
-        appendNamedValueToParameters(tr("Major radius"), anEllipse->majorRadius(), aParams);
-        appendNamedValueToParameters(tr("Minor radius"), anEllipse->minorRadius(), aParams);
-      }
-      else
-        // Common case
-        myTypeLbl->setText(tr("Edge"));
-    }
-  }
-
-  if (addStartEndPoints) {
-    appendPointToParameters(tr("Start point"), aStartPnt, aParams);
-    appendPointToParameters(tr("End point"), aEndPnt, aParams);
-  }
-  setParamsText(aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::fillWire(const GeomWirePtr& theWire)
-{
-  QString aParams;
-  appendNamedValueToParameters(tr("Closed"), theWire->isClosed(), aParams);
-
-  // check the wire is a polygon
-  std::list<GeomPointPtr> aPolygonPoints;
-  if (theWire->isPolygon(aPolygonPoints)) {
-    myTypeLbl->setText(tr("Polygon"));
-    int aCornerIndex = 0;
-    for (std::list<GeomPointPtr>::const_iterator aPtIt = aPolygonPoints.begin();
-         aPtIt != aPolygonPoints.end(); ++aPtIt)
-       appendPointToParameters(tr("Point") + " " + QString::number(++aCornerIndex),
-                               *aPtIt, aParams);
-  }
-  else
-    myTypeLbl->setText(tr("Wire"));
-
-  setParamsText(aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::fillFace(const GeomFacePtr& theFace)
-{
-  QString aParams;
-  // 1. Plane and planar faces
-  GeomPlanePtr aPlane = theFace->getPlane();
-  if (aPlane) {
-    bool isCommonCase = true;
-    // Check face bounded by circle or ellipse
-    std::list<GeomShapePtr> aSubs = theFace->subShapes(GeomAPI_Shape::EDGE);
-    if (aSubs.size() == 1) {
-      GeomEdgePtr anEdge = aSubs.front()->edge();
-      if (anEdge->isCircle() || anEdge->isEllipse()) {
-        fillEdge(anEdge);
-        isCommonCase = false;
-        myTypeLbl->setText(tr("Disk"));
-      }
-    }
-    else {
-      // Check face bounded by a single wire which is rectangle
-      aSubs = theFace->subShapes(GeomAPI_Shape::WIRE);
-      if (aSubs.size() == 1) {
-        GeomWirePtr aWire = aSubs.front()->wire();
-        std::list<GeomPointPtr> aCorners;
-        if (aWire->isRectangle(aCorners)) {
-          GeomPointPtr aBaseCorner = aCorners.front();
-          aCorners.pop_front();
-
-          double aWidth = aBaseCorner->distance(aCorners.front());
-          double aHeight = aBaseCorner->distance(aCorners.back());
-
-          myTypeLbl->setText(tr("Rectangle"));
-          appendPointToParameters(tr("Corner"), aBaseCorner, aParams);
-          appendDirToParameters(tr("Normal"), aPlane->direction(), aParams);
-          appendGroupNameToParameters(tr("Dimensions"), aParams);
-          appendNamedValueToParameters(tr("Width"), aWidth, aParams);
-          appendNamedValueToParameters(tr("Height"), aHeight, aParams);
-          setParamsText(aParams);
-
-          isCommonCase = false;
-        }
-      }
-    }
-
-    if (isCommonCase)
-      setPlaneType(tr("Plane"), aPlane);
-  }
-  else {
-    // 2. Sphere
-    GeomSpherePtr aSphere = theFace->getSphere();
-    if (aSphere)
-      setSphereType(tr("Sphere"), aSphere);
-    else {
-      // 3. Cylinder
-      GeomCylinderPtr aCylinder = theFace->getCylinder();
-      if (aCylinder)
-        setCylinderType(tr("Cylinder"), aCylinder);
-      else {
-        // 4. Cone
-        GeomConePtr aCone = theFace->getCone();
-        if (aCone)
-          setConeType(tr("Cone"), aCone);
-        else {
-          // 5. Torus
-          GeomTorusPtr aTorus = theFace->getTorus();
-          if (aTorus)
-            setTorusType(tr("Torus"), aTorus);
-          else
-            // 6. Common case
-            myTypeLbl->setText(tr("Face"));
-        }
-      }
-    }
-  }
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::fillShell(const GeomShellPtr& theShell)
-{
-  // 1. Sphere
-  GeomSpherePtr aSphere = theShell->getSphere();
-  if (aSphere)
-    setSphereType(tr("Sphere"), aSphere);
-  else {
-    // 2. Cylinder
-    GeomCylinderPtr aCylinder = theShell->getCylinder();
-    if (aCylinder)
-      setCylinderType(tr("Cylinder"), aCylinder);
-    else {
-      // 3. Cone
-      GeomConePtr aCone = theShell->getCone();
-      if (aCone)
-        setConeType(tr("Cone"), aCone);
-      else {
-        // 4. Torus
-        GeomTorusPtr aTorus = theShell->getTorus();
-        if (aTorus)
-          setTorusType(tr("Torus"), aTorus);
-        else {
-          // 5. Axis-aligned/Rotated Box
-          GeomBoxPtr aBox = theShell->getParallelepiped();
-          if (aBox) {
-            if (aBox->isAxesAligned())
-              setBoxType(tr("Box"), aBox);
-            else
-              setRotatedBoxType(tr("Rotated Box"), aBox);
-          }
-          else
-            // 6. Common case
-            myTypeLbl->setText(tr("Shell"));
-        }
-      }
-    }
-  }
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::fillSolid(const GeomSolidPtr& theSolid)
-{
-  // 1. Sphere
-  GeomSpherePtr aSphere = theSolid->getSphere();
-  if (aSphere)
-    setSphereType(tr("Sphere"), aSphere);
-  else {
-    // 2. Cylinder
-    GeomCylinderPtr aCylinder = theSolid->getCylinder();
-    if (aCylinder)
-      setCylinderType(tr("Cylinder"), aCylinder);
-    else {
-      // 3. Cone
-      GeomConePtr aCone = theSolid->getCone();
-      if (aCone)
-        setConeType(tr("Cone"), aCone);
-      else {
-        // 4. Torus
-        GeomTorusPtr aTorus = theSolid->getTorus();
-        if (aTorus)
-          setTorusType(tr("Torus"), aTorus);
-        else {
-          // 5. Axis-aligned/Rotated Box
-          GeomBoxPtr aBox = theSolid->getParallelepiped();
-          if (aBox) {
-            if (aBox->isAxesAligned())
-              setBoxType(tr("Box"), aBox);
-            else
-              setRotatedBoxType(tr("Rotated Box"), aBox);
-          }
-          else
-            // 6. Common case
-            myTypeLbl->setText(tr("Solid"));
-        }
-      }
-    }
-  }
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::fillContainer(const GeomShapePtr& theShape)
-{
-  if (theShape->shapeType() == GeomAPI_Shape::COMPSOLID)
-    myTypeLbl->setText("CompSolid");
-  else if (theShape->shapeType() == GeomAPI_Shape::COMPOUND)
-    myTypeLbl->setText("Compound");
-
-  // fill bounding box
-  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
-  Bnd_Box 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()));
-
-  gp_Pnt aMaxPnt = aBB.CornerMax();
-  GeomPointPtr aMaxPoint(new GeomAPI_Pnt(aMaxPnt.X(), aMaxPnt.Y(), aMaxPnt.Z()));
-
-  QString aParams;
-  appendGroupNameToParameters(tr("Bounding box"), aParams);
-  appendPointToParameters(tr("Minimal corner"), aMinPoint, aParams);
-  appendPointToParameters(tr("Maximal corner"), aMaxPoint, aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::setPlaneType(const QString& theTitle,
-                                        const std::shared_ptr<GeomAPI_Pln>& thePlane)
-{
-  myTypeLbl->setText(theTitle);
-  QString aParams;
-  appendPointToParameters(tr("Origin"), thePlane->location(), aParams);
-  appendDirToParameters(tr("Normal"), thePlane->direction(), aParams);
-  setParamsText(aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::setSphereType(const QString& theTitle,
-                                         const std::shared_ptr<GeomAPI_Sphere>& theSphere)
-{
-  myTypeLbl->setText(theTitle);
-  QString aParams;
-  appendPointToParameters(tr("Center"), theSphere->center(), aParams);
-  appendGroupNameToParameters(tr("Dimensions"), aParams);
-  appendNamedValueToParameters(tr("Radius"), theSphere->radius(), aParams);
-  setParamsText(aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::setCylinderType(const QString& theTitle,
-                                           const std::shared_ptr<GeomAPI_Cylinder>& theCyl)
-{
-  myTypeLbl->setText(theTitle);
-  QString aParams;
-  appendPointToParameters(tr("Position"), theCyl->location(), aParams);
-  appendDirToParameters(tr("Axis"), theCyl->axis(), aParams);
-  appendGroupNameToParameters(tr("Dimensions"), aParams);
-  appendNamedValueToParameters(tr("Radius"), theCyl->radius(), aParams);
-  appendNamedValueToParameters(tr("Height"), theCyl->height(), aParams);
-  setParamsText(aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::setConeType(const QString& theTitle,
-                                       const std::shared_ptr<GeomAPI_Cone>& theCone)
-{
-  myTypeLbl->setText(theTitle);
-  QString aParams;
-  appendPointToParameters(tr("Position"), theCone->location(), aParams);
-  appendDirToParameters(tr("Axis"), theCone->axis(), aParams);
-  appendGroupNameToParameters(tr("Dimensions"), aParams);
-  appendNamedValueToParameters(tr("Radius 1"), theCone->radius1(), aParams);
-  appendNamedValueToParameters(tr("Radius 2"), theCone->radius2(), aParams);
-  appendNamedValueToParameters(tr("Height"), theCone->height(), aParams);
-  setParamsText(aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::setTorusType(const QString& theTitle,
-                                        const std::shared_ptr<GeomAPI_Torus>& theTorus)
-{
-  myTypeLbl->setText(theTitle);
-  QString aParams;
-  appendPointToParameters(tr("Center"), theTorus->center(), aParams);
-  appendDirToParameters(tr("Axis"), theTorus->direction(), aParams);
-  appendGroupNameToParameters(tr("Dimensions"), aParams);
-  appendNamedValueToParameters(tr("Major radius"), theTorus->majorRadius(), aParams);
-  appendNamedValueToParameters(tr("Minor radius"), theTorus->minorRadius(), aParams);
-  setParamsText(aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::setBoxType(const QString& theTitle,
-                                      const std::shared_ptr<GeomAPI_Box>& theBox)
-{
-  myTypeLbl->setText(theTitle);
-  QString aParams;
-  appendPointToParameters(tr("Position"), theBox->axes()->origin(), aParams);
-  appendGroupNameToParameters(tr("Dimensions"), aParams);
-  appendNamedValueToParameters(tr("Width"), theBox->width(), aParams);
-  appendNamedValueToParameters(tr("Depth"), theBox->depth(), aParams);
-  appendNamedValueToParameters(tr("Height"), theBox->height(), aParams);
-  setParamsText(aParams);
-}
-
-//********************************************************************
-void XGUI_InspectionPanel::setRotatedBoxType(const QString& theTitle,
-                                             const std::shared_ptr<GeomAPI_Box>& theBox)
-{
-  myTypeLbl->setText(theTitle);
-  QString aParams;
-  std::shared_ptr<GeomAPI_Ax3> anAxes = theBox->axes();
-  appendPointToParameters(tr("Position"), anAxes->origin(), aParams);
-  appendDirToParameters(tr("Z axis"), anAxes->normal(), aParams);
-  appendDirToParameters(tr("X axis"), anAxes->dirX(), aParams);
-  appendGroupNameToParameters(tr("Dimensions"), aParams);
-  appendNamedValueToParameters(tr("Width"), theBox->width(), aParams);
-  appendNamedValueToParameters(tr("Depth"), theBox->depth(), aParams);
-  appendNamedValueToParameters(tr("Height"), theBox->height(), aParams);
-  setParamsText(aParams);
-}
-
-
 //********************************************************************
 void XGUI_InspectionPanel::setParamsText(const QString& theText)
 {