From: mpv Date: Mon, 18 Apr 2022 11:31:24 +0000 (+0300) Subject: Information on shape in TUI. New 'shapeInfo' python method. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=06811c3856a6775cd6c1e5758cfc658bc83a8a5a;p=modules%2Fshaper.git Information on shape in TUI. New 'shapeInfo' python method. --- diff --git a/doc/gui/General/Introduction.rst b/doc/gui/General/Introduction.rst index eea5fbf0f..4a9024657 100644 --- a/doc/gui/General/Introduction.rst +++ b/doc/gui/General/Introduction.rst @@ -325,6 +325,13 @@ The information about Plane, Face additionally shows coordinates of center poin **Inspection panel** for Face +The shapes information, equal to the provided Inspection panel information on the shape is accessible inpython API by usage of **shapeInfo** command: + + | *from salome.shaper import geom* + | *geom.shapeInfo(vertex)* + | *==> ('Vertex', 0.0, 0.0, 10.0)* + + .. _hidefaces_panel: Hide Faces panel diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 17eec671e..5f04e71b2 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -93,6 +93,7 @@ SET(PROJECT_HEADERS GeomAlgoAPI_BoundingBox.h GeomAlgoAPI_NormalToFace.h GeomAlgoAPI_Tube.h + GeomAlgoAPI_ShapeInfo.h ) SET(PROJECT_SOURCES @@ -165,6 +166,7 @@ SET(PROJECT_SOURCES GeomAlgoAPI_BoundingBox.cpp GeomAlgoAPI_NormalToFace.cpp GeomAlgoAPI_Tube.cpp + GeomAlgoAPI_ShapeInfo.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAlgoAPI/GeomAlgoAPI.i b/src/GeomAlgoAPI/GeomAlgoAPI.i index e12108cc7..0e235b056 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI.i +++ b/src/GeomAlgoAPI/GeomAlgoAPI.i @@ -113,8 +113,10 @@ %include "GeomAlgoAPI_Symmetry.h" %include "GeomAlgoAPI_Box.h" %include "GeomAlgoAPI_MapShapesAndAncestors.h" +%include "GeomAlgoAPI_ShapeInfo.h" %typemap(out) std::list< std::shared_ptr< GeomAPI_Shape > >::value_type & { $result = SWIG_NewPointerObj(SWIG_as_voidptr(new std::shared_ptr(*$1)), $descriptor(std::shared_ptr *), SWIG_POINTER_OWN | 0 ); } %template(ShapeList) std::list >; +%template(ValuesList) std::list; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeInfo.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeInfo.cpp new file mode 100644 index 000000000..23fbc9554 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeInfo.cpp @@ -0,0 +1,411 @@ +// 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "GeomAlgoAPI_ShapeInfo.h" +#include "GeomAlgoAPI_BoundingBox.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +std::string GeomAlgoAPI_ShapeInfo::html(Translator* theTranslator) +{ + Values aVal(TYPE_HTML); + if (theTranslator) + aVal.setTranslator(theTranslator); + processShape(aVal); + return aVal.html(); +} + +std::list GeomAlgoAPI_ShapeInfo::values() +{ + Values aVal(TYPE_VALS); + processShape(aVal); + return aVal.values(); +} + +void GeomAlgoAPI_ShapeInfo::processShape(GeomAlgoAPI_ShapeInfo::Values& theVals) +{ + switch (myShape->shapeType()) { + case GeomAPI_Shape::VERTEX: + { + GeomPointPtr aPoint = myShape->vertex()->point(); + setShapeType("Vertex"); + theVals.addPoint("Coordinates", myShape->vertex()->point()); + break; + } + case GeomAPI_Shape::EDGE: + { + GeomEdgePtr anEdge = myShape->edge(); + processEdge(theVals, anEdge); + break; + } + case GeomAPI_Shape::FACE: + { + GeomFacePtr aFace = myShape->face(); + processFace(theVals, aFace); + break; + } + case GeomAPI_Shape::SOLID: // nearly same as SHELL if it is only one sub + { + ListOfShape aShells = myShape->subShapes(GeomAPI_Shape::SHELL); + if (aShells.size() == 1) + { + GeomShapePtr aTmpShape = myShape; + myShape = aShells.front(); + processShape(theVals); + myShape = aTmpShape; + } + if (myShapeType.empty() || myShapeType == "Shell") + setShapeType("Solid"); + break; + } + case GeomAPI_Shape::SHELL: + { + GeomShellPtr aShell = myShape->shell(); + if (GeomBoxPtr aBox = aShell->getParallelepiped()) + { + if (aBox->isAxesAligned()) { + setShapeType("Box"); + } + else { + setShapeType("Rotated Box"); + } + } + else { // check single face + ListOfShape aFaces = myShape->subShapes(GeomAPI_Shape::FACE); + if (aFaces.size() == 1) + { + GeomFacePtr aFace = aFaces.front()->face(); + processFace(theVals, aFace); + } + if (myShapeType.empty() || myShapeType == "Face") + setShapeType("Shell"); + } + break; + } + case GeomAPI_Shape::WIRE: + { + theVals.addNamedValue("Closed", myShape->wire()->isClosed()); + + // check the wire is a polygon + std::list aPolygonPoints; + if (myShape->wire()->isPolygon(aPolygonPoints)) { + setShapeType("Polygon"); + std::string aPointTr = theVals.translator()->translate("Point"); + std::list::const_iterator aPtIt = aPolygonPoints.begin(); + for (int aCornerIndex = 0; aPtIt != aPolygonPoints.end(); ++aPtIt) { + std::ostringstream aStr; + aStr << " " << (++aCornerIndex); + theVals.addPoint(aStr.str().c_str(), *aPtIt); + } + } + else // Common case + setShapeType("Wire"); + break; + } + case GeomAPI_Shape::COMPSOLID: + case GeomAPI_Shape::COMPOUND: + { + setShapeType(myShape->shapeType() == GeomAPI_Shape::COMPSOLID ? "CompSolid" : "Compound"); + double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + if (myShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax)) + { + theVals.addGroupName("Bounding box"); + GeomPointPtr aMinPoint(new GeomAPI_Pnt(aXmin, aYmin, aZmin)); + theVals.addPoint("Minimal corner", aMinPoint); + GeomPointPtr aMaxPoint(new GeomAPI_Pnt(aXmax, aYmax, aZmax)); + theVals.addPoint("Maximal corner", aMaxPoint); + } + break; + } + default: // nothing to fill + break; + } +} + +void GeomAlgoAPI_ShapeInfo::processEdge(Values& theVals, GeomEdgePtr theEdge) +{ + setShapeType("Edge"); // Common case + if (theEdge->isDegenerated()) { + theVals.addNamedValue("Degenerated", true); + return; + } + + GeomPointPtr aStartPnt = theEdge->firstPoint(); + GeomPointPtr aEndPnt = theEdge->lastPoint(); + bool addStartEndPoints = false; + + if (theEdge->isLine()) { + setShapeType("Line segment"); + addStartEndPoints = true; + } + else if (GeomCirclePtr aCircle = theEdge->circle()) { + addStartEndPoints = aStartPnt->distance(aEndPnt) >= Precision::Confusion(); + setShapeType(addStartEndPoints ? "Arc of circle" : "Circle"); + theVals.addPoint("Center", aCircle->center()); + theVals.addDirection("Normal", aCircle->normal()); + theVals.addGroupName("Dimensions"); + theVals.addNamedValue("Radius", aCircle->radius()); + } + else if (GeomEllipsePtr anEllipse = theEdge->ellipse()) { + addStartEndPoints = aStartPnt->distance(aEndPnt) >= Precision::Confusion(); + setShapeType(addStartEndPoints ? "Arc of ellipse" : "Ellipse"); + theVals.addPoint("Center", anEllipse->center()); + theVals.addDirection("Normal", anEllipse->normal()); + theVals.addGroupName("Dimensions"); + theVals.addNamedValue("Major radius", anEllipse->majorRadius()); + theVals.addNamedValue("Minor radius", anEllipse->minorRadius()); + } + + if (addStartEndPoints) { + theVals.addPoint("Start point", aStartPnt); + theVals.addPoint("End point", aEndPnt); + } +} + +void GeomAlgoAPI_ShapeInfo::processFace(Values& theVals, GeomFacePtr theFace) +{ + // Plane and planar face + if (GeomPlanePtr aPlane = theFace->getPlane()) { + bool isCommonCase = true; + // Check face bounded by circle or ellipse + std::list aSubs = theFace->subShapes(GeomAPI_Shape::EDGE); + if (aSubs.size() == 1) { + GeomEdgePtr anEdge = aSubs.front()->edge(); + if (anEdge->isCircle() || anEdge->isEllipse()) { + processEdge(theVals, anEdge); + isCommonCase = false; + setShapeType("Disk"); + } + } + else { + // Check face bounded by a single wire which is rectangle + aSubs = theFace->subShapes(GeomAPI_Shape::WIRE); + if (aSubs.size() == 1) { + std::list aCorners; + if (aSubs.front()->wire()->isRectangle(aCorners)) { + GeomPointPtr aBaseCorner = aCorners.front(); + aCorners.pop_front(); + + double aWidth = aBaseCorner->distance(aCorners.front()); + double aHeight = aBaseCorner->distance(aCorners.back()); + + setShapeType("Rectangle"); + theVals.addPoint("Corner", aBaseCorner); + theVals.addDirection("Normal", aPlane->direction()); + theVals.addGroupName("Dimensions"); + theVals.addNamedValue("Width", aWidth); + theVals.addNamedValue("Height", aHeight); + isCommonCase = false; + } + } + } + + if (isCommonCase) { + setShapeType("Plane"); + theVals.addPoint("Origin", aPlane->location()); + theVals.addDirection("Normal", aPlane->direction()); + } + } + // Sphere + else if (GeomSpherePtr aSphere = theFace->getSphere()) { + setShapeType("Sphere"); + theVals.addPoint("Center", aSphere->center()); + theVals.addGroupName("Dimensions"); + theVals.addNamedValue("Radius", aSphere->radius()); + } + // Cylinder + else if (GeomCylinderPtr aCylinder = theFace->getCylinder()) + { + setShapeType("Cylinder"); + theVals.addPoint("Position", aCylinder->location()); + theVals.addDirection("Axis", aCylinder->axis()); + theVals.addGroupName("Dimensions"); + theVals.addNamedValue("Radius", aCylinder->radius()); + theVals.addNamedValue("Height", aCylinder->height()); + } + // Cone + else if (GeomConePtr aCone = theFace->getCone()) { + setShapeType("Cone"); + theVals.addPoint("Position", aCone->location()); + theVals.addDirection("Axis", aCone->axis()); + theVals.addGroupName("Dimensions"); + theVals.addNamedValue("Radius 1", aCone->radius1()); + theVals.addNamedValue("Radius 2", aCone->radius2()); + theVals.addNamedValue("Height", aCone->height()); + + } + // Torus + else if (GeomTorusPtr aTorus = theFace->getTorus()) { + setShapeType("Torus"); + theVals.addPoint("Center", aTorus->center()); + theVals.addDirection("Axis", aTorus->direction()); + theVals.addGroupName("Dimensions"); + theVals.addNamedValue("Major radius", aTorus->majorRadius()); + theVals.addNamedValue("Minor radius", aTorus->minorRadius()); + } + // Common case + else + setShapeType("Face"); +} + +GeomAlgoAPI_ShapeInfo::Values::Values(const GeomAlgoAPI_ShapeInfo::InfoType theType) + : myType(theType) +{ + static GeomAlgoAPI_ShapeInfo::Translator* kDefaultTr = new GeomAlgoAPI_ShapeInfo::Translator; + myTr = kDefaultTr; +} + + +GeomAlgoAPI_ShapeInfo::Values& GeomAlgoAPI_ShapeInfo::Values::operator<< (double theValue) +{ + switch (myType) + { + case TYPE_HTML: + { + std::ostringstream aStr; + aStr << theValue; + myStr += aStr.str(); + break; + } + case TYPE_VALS: + myVals.push_back(GeomAlgoAPI_InfoValue(theValue)); + break; + } + return *this; +} + +GeomAlgoAPI_ShapeInfo::Values& GeomAlgoAPI_ShapeInfo::Values::operator << (bool theValue) +{ + switch (myType) + { + case TYPE_HTML: + myStr += myTr->translate(theValue ? "True" : "False"); + break; + case TYPE_VALS: + myVals.push_back(GeomAlgoAPI_InfoValue(theValue)); + break; + } + return *this; +} + +GeomAlgoAPI_ShapeInfo::Values& GeomAlgoAPI_ShapeInfo::Values::operator<< (const char* theStr) +{ + if (myType == TYPE_HTML) + myStr += myTr->translate(theStr); + return *this; +} + +void GeomAlgoAPI_ShapeInfo::Values::addPoint(const char* theTitle, const GeomPointPtr& thePoint) +{ + switch (myType) + { + case TYPE_HTML: + { + std::ostringstream aStr; + aStr << "" << myTr->translate(theTitle) << "" + << "
X: " << thePoint->x() + << "
Y: " << thePoint->y() + << "
Z: " << thePoint->z() << "
"; + myStr += aStr.str(); + break; + } + case TYPE_VALS: + myVals.push_back(GeomAlgoAPI_InfoValue(thePoint->x())); + myVals.push_back(GeomAlgoAPI_InfoValue(thePoint->y())); + myVals.push_back(GeomAlgoAPI_InfoValue(thePoint->z())); + break; + } +} + +void GeomAlgoAPI_ShapeInfo::Values::addDirection(const char* theTitle, const GeomDirPtr& theDir) +{ + switch (myType) + { + case TYPE_HTML: + { + std::ostringstream aStr; + aStr << "" << myTr->translate(theTitle) << "" + << "
DX: " << theDir->x() + << "
DY: " << theDir->y() + << "
DZ: " << theDir->z() << "
"; + myStr += aStr.str(); + break; + } + case TYPE_VALS: + myVals.push_back(GeomAlgoAPI_InfoValue(theDir->x())); + myVals.push_back(GeomAlgoAPI_InfoValue(theDir->y())); + myVals.push_back(GeomAlgoAPI_InfoValue(theDir->z())); + break; + } +} + +void GeomAlgoAPI_ShapeInfo::Values::addNamedValue(const char* theName, const double theValue) +{ + switch (myType) + { + case TYPE_HTML: + { + std::ostringstream aStr; + aStr << myTr->translate(theName) << ": " << theValue << "
"; + myStr += aStr.str(); + break; + } + case TYPE_VALS: + *this << theValue; // just value, no name + break; + } +} + +void GeomAlgoAPI_ShapeInfo::Values::addNamedValue(const char* theName, const bool theValue) +{ + switch (myType) + { + case TYPE_HTML: + { + std::ostringstream aStr; + aStr << myTr->translate(theName) << ": " << (theValue ? "True" : "False") << "
"; + myStr += aStr.str(); + break; + } + case TYPE_VALS: + *this << theValue; // just value, no name + break; + } +} + +void GeomAlgoAPI_ShapeInfo::Values::addGroupName(const char* theName) +{ + if (myType == TYPE_HTML) + { + myStr += "" + myTr->translate(theName) + "" + "
"; + } +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeInfo.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeInfo.h new file mode 100644 index 000000000..52c37a583 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeInfo.h @@ -0,0 +1,154 @@ +// 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef GeomAlgoAPI_ShapeInfo_H_ +#define GeomAlgoAPI_ShapeInfo_H_ + +#include "GeomAlgoAPI.h" + +#include +#include +#include +#include +#include + +/// Keeps values of different possible types, used in python shapeInfo. +class GeomAlgoAPI_InfoValue +{ + int myType; //< type stored in this Value + std::string myStr; //< type 0 + double myDouble; //< type 1 + bool myBool; //< type 2 + +public: + GeomAlgoAPI_InfoValue() : myType(-1) {} // invalid case + GeomAlgoAPI_InfoValue(const char* theVal) : myType(0), myStr(theVal) {} + GeomAlgoAPI_InfoValue(const std::string theVal) : myType(0), myStr(theVal) {} + GeomAlgoAPI_InfoValue(const double theVal) : myType(1), myDouble(theVal) {} + GeomAlgoAPI_InfoValue(const bool theVal) : myType(2), myBool(theVal) {} + + const int& type() const { return myType; } + const std::string& string() const { return myStr; } + const double& real() const { return myDouble; } + const bool& boolean() const { return myBool; } +}; + +/// \class GeomAlgoAPI_ShapeInfo +/// \ingroup DataAlgo +/// \brief Provides information about shapes in textual (HTML for Information Panel) or +/// a list of parameters order (for python "shapeInfo" command). +/// +/// At least the following geometrical items are supported: +/// 0D: Vertex, +/// 1D : Line segment, Polygon, Circle, Arc, Ellipse, Arc of ellipse, +/// 2D : Rectangle, Polygon, Disc with circular or elliptical base, Sphere, Cylinder, Cone, Torus +/// +/// It is initialized by a shape and fors the needed output depending on the requested format. +class GeomAlgoAPI_ShapeInfo +{ + /// Keeps the shape, source of the produced information. + std::shared_ptr myShape; + std::string myShapeType; //< detected shape type +public: + + /// Initializes a parameters input by an input shape. + GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeInfo(const std::shared_ptr theShape) + : myShape(theShape) {} + + /// A translator to the current language is needed for HTML export. + /// It is provided by a caller of this class. + class Translator + { + public: + Translator() {} + GEOMALGOAPI_EXPORT virtual std::string translate(const char* theSource) { return theSource; } + }; + + /// Returns an HTML text of a shape info. + GEOMALGOAPI_EXPORT std::string html(Translator* theTranslator); + + /// Returns the detected shape type, or empty string. + GEOMALGOAPI_EXPORT const std::string& shapeType() { return myShapeType; } + + /// Sets the shape type + void setShapeType(const std::string theType) { myShapeType = theType; } + + /// Returns a list of shape information values. + GEOMALGOAPI_EXPORT std::list values(); + +private: + /// Possible types of export values + enum InfoType { + TYPE_HTML, + TYPE_VALS + }; + + /// Allows to input values in a defined format, then - to export them. + class Values + { + /// A type of stored shape info. + InfoType myType; + /// An HTML string container. + std::string myStr; + Translator* myTr; //< an external translator + /// A container of values: type of the value -> value + std::list myVals; + public: + + /// Initialization of an empty container, default translator + Values(const InfoType theType); + + /// Returns HTML representation of values + const std::string& html() const { return myStr; } + + void setTranslator(Translator* theTranslator) { myTr = theTranslator; } + Translator* translator() { return myTr; } + + /// Returns list of values representation. + const std::list& values() const { return myVals; } + + /// Adds next value + Values& operator<< (double theValue); + /// Adds next value + Values& operator<< (bool theValue); + /// Adds string + Values& operator<< (const char* theStr); + /// Adds point coordinates + void addPoint(const char* theTitle, const GeomPointPtr& thePoint); + /// Adds directon coordinates + void addDirection(const char* theTitle, const GeomDirPtr& thePoint); + /// Adds named value + void addNamedValue(const char* theName, const double theValue); + /// Adds named value + void addNamedValue(const char* theName, const bool theValue); + /// Adds a name (title) of the group + void addGroupName(const char* theName); + }; + + /// Gets information from the shape + void processShape(Values& theVals); + + /// Gets particual information from the edge + void processEdge(Values& theVals, GeomEdgePtr theEdge); + + /// Gets particual information from face + void processFace(Values& theVals, GeomFacePtr theFace); +}; + +#endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_swig.h b/src/GeomAlgoAPI/GeomAlgoAPI_swig.h index d84bf1a49..e5c69ee2f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_swig.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_swig.h @@ -63,6 +63,7 @@ #include "GeomAlgoAPI_Copy.h" #include "GeomAlgoAPI_Symmetry.h" #include "GeomAlgoAPI_MapShapesAndAncestors.h" + #include "GeomAlgoAPI_ShapeInfo.h" #include #include @@ -76,3 +77,6 @@ #endif #endif /* SRC_GEOMALGOAPI_GEOMALGOAPI_SWIG_H_ */ + +// fix for SWIG v2.0.4 +#define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj)) diff --git a/src/PythonAPI/Test/TestShapeInfo.py b/src/PythonAPI/Test/TestShapeInfo.py new file mode 100644 index 000000000..818b22f6a --- /dev/null +++ b/src/PythonAPI/Test/TestShapeInfo.py @@ -0,0 +1,128 @@ +# 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 +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# 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 +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model +from salome.shaper import geom +from GeomAPI import * + +model.begin() +partSet = model.moduleDocument() +### Create Part +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +### Create Parallelepiped +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(100, 30, -100, 30) +SketchLine_2 = Sketch_1.addLine(-100, 30, -100, -12) +SketchLine_3 = Sketch_1.addLine(-100, -12, 100, -12) +SketchLine_4 = Sketch_1.addLine(100, -12, 100, 30) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), 8, 0, "Faces|Wires") + +### Create tool-set: all the needed types of edges and surfaces +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face")) +SketchCircle_1 = Sketch_2.addCircle(-80, 10, 5) +SketchEllipse_1 = Sketch_2.addEllipse(-51, 10, -39, 10, 5) +SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +# moon +SketchArc_1 = Sketch_2.addArc(-22, 10, -22, 2, -22, 18, False) +SketchEllipticArc_1 = Sketch_2.addEllipticArc(-22, 10, -22, 17, -22, 2, -22, 18, False) +SketchEllipticArc_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux") +# cone +SketchLine_9 = Sketch_2.addLine(3, 14, 3, -2) +SketchLine_10 = Sketch_2.addLine(3, -2, 11, 14) +SketchLine_11 = Sketch_2.addLine(11, 14, 3, 14) +# tore +SketchLine_12 = Sketch_2.addLine(39, 16, 39, 1) +SketchLine_12.setAuxiliary(True) +SketchCircle_2 = Sketch_2.addCircle(48, 10, 5) +# circle +SketchLine_13 = Sketch_2.addLine(76, 14, 76, 0) +SketchArc_2 = Sketch_2.addArc(76, 7, 76, 14, 76, 0, True) +model.do() +### Create extrusions and revolutions +Extrusion_2_objects = [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r"), + model.selection("FACE", "Sketch_2/Face-SketchEllipse_1f"), + model.selection("FACE", "Sketch_2/Face-SketchArc_1_2f-SketchEllipticArc_1r")] +Extrusion_2 = model.addExtrusion(Part_1_doc, Extrusion_2_objects, model.selection(), 8, 0, "Faces|Wires") +Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_9f-SketchLine_10f-SketchLine_11f")], model.selection("EDGE", "Sketch_2/SketchLine_9"), 180, 0) +Revolution_2 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection("EDGE", "Sketch_2/SketchLine_12"), 180, 0) +Revolution_3 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_13f-SketchArc_2_2f")], model.selection("EDGE", "Sketch_2/SketchLine_13"), 180, 0) +model.do() +### Fuse all +Fuse_1_objects_1 = [model.selection("SOLID", "Extrusion_1_1"), + model.selection("SOLID", "Extrusion_2_1"), + model.selection("SOLID", "Extrusion_2_2"), + model.selection("SOLID", "Extrusion_2_3"), + model.selection("SOLID", "Revolution_1_1"), + model.selection("SOLID", "Revolution_2_1"), + model.selection("SOLID", "Revolution_3_1")] +Fuse_1 = model.addFuse(Part_1_doc, Fuse_1_objects_1, keepSubResults = True) +model.end() + +# a method to compare tupes: element by element, double values are compared with precision 1.e-9 +def compareTuples(theT1, theT2): + assert(len(theT1) == len(theT2)) + for i in range(len(theT1)): + assert(type(theT1[i]) == type(theT2[i])) + if type(theT1[i]) == float: + #print("Compare " + "{:0.9f}".format(theT1[i]) + " and " + "{:0.9f}".format(theT2[i])); + assert("{:0.9f}".format(theT1[i]) == "{:0.9f}".format(theT2[i])) + else: + assert(theT1[i] == theT2[i]) + + +# check the whole solid +aSolid = Fuse_1.feature().firstResult().shape() +anInfo = geom.shapeInfo(aSolid) +compareTuples(anInfo, ('Solid',)) +# check the shell +aShell = aSolid.subShapes(GeomAPI_Shape.SHELL)[0] +anInfo = geom.shapeInfo(aShell) +compareTuples(anInfo, ('Shell',)) +# check faces +aFaces = aShell.subShapes(GeomAPI_Shape.FACE) +compareTuples(geom.shapeInfo(aFaces[0]), ('Rectangle', 100.0, 30.0, 8.0, -0.0, 1.0, -0.0, 8.0, 200.0)) +compareTuples(geom.shapeInfo(aFaces[6]), ('Cone', 3.0, -2.0, 8.0, -0.0, 1.0, -0.0, 0.0, 8.0, 16.)) +compareTuples(geom.shapeInfo(aFaces[8]), ('Sphere', 76.0, 7.0, 8.0, 7.0)) +compareTuples(geom.shapeInfo(aFaces[9]), ('Cylinder', -80.0, 10.0, 16.0, -0.0, -0.0, -1.0, 5.0, 8.0)) +compareTuples(geom.shapeInfo(aFaces[10]), ('Face',)) # linear extrusion surface +compareTuples(geom.shapeInfo(aFaces[13]), ('Torus', 39.0, 10.0, 8.0, -0.0, 1.0, -0.0, 9.0, 5.0)) +compareTuples(geom.shapeInfo(aFaces[14]), ('Disk', -80.0, 10.0, 16.0, 0.0, 0.0, 1.0, 5.0)) # circular disk +compareTuples(geom.shapeInfo(aFaces[15]), ('Disk', -51.0, 10.0, 16.0, 0.0, 0.0, 1.0, 13.0, 5.0)) # elliptical disk +compareTuples(geom.shapeInfo(aFaces[16]), ('Plane', 0.0, 0.0, 16.0, 0.0, 0.0, 1.0)) +# check wires +aWires = aShell.subShapes(GeomAPI_Shape.WIRE) +compareTuples(geom.shapeInfo(aWires[0]), ('Polygon', True, 100.0, 30.0, 8.0, 100.0, 30.0, 0.0, -100.0, 30.0, 0.0, -100.0, 30.0, 8.0)) +compareTuples(geom.shapeInfo(aWires[6]), ('Wire', True)) +# check edges +anEdges = aFaces[0].subShapes(GeomAPI_Shape.EDGE) +compareTuples(geom.shapeInfo(anEdges[0]), ('Line segment', 100.0, 30.0, 0.0, 100.0, 30.0, 8.0)) +anEdges = aFaces[6].subShapes(GeomAPI_Shape.EDGE) # cone +compareTuples(geom.shapeInfo(anEdges[0]), ('Edge', True)) # Degenerated edge +compareTuples(geom.shapeInfo(anEdges[1]), ('Arc of circle', 3.0, 14.0, 8.0, 0.0, -1.0, 0.0, 8.0, 11.0, 14.0, 8.0, -5.0, 14.0, 8.0)) +anEdges = aFaces[9].subShapes(GeomAPI_Shape.EDGE) # cylinder +compareTuples(geom.shapeInfo(anEdges[2]), ('Circle', -80.0, 10.0, 8.0, 0.0, 0.0, 1.0, 5.0)) +anEdges = aFaces[10].subShapes(GeomAPI_Shape.EDGE) # ellipse +compareTuples(geom.shapeInfo(anEdges[2]), ('Ellipse', -51.0, 10.0, 8.0, 0.0, 0.0, 1.0, 13.0, 5.0)) +anEdges = aFaces[16].subShapes(GeomAPI_Shape.EDGE) # moon top +compareTuples(geom.shapeInfo(anEdges[1]), ('Arc of ellipse', -22.0, 10.0, 16.0, 0.0, -0.0, 1.0, 8.0, 3.872983346207417, -22.0, 2.0, 16.0, -22.0, 18.0, 16.0)) +# check vertex +aVertex = aSolid.subShapes(GeomAPI_Shape.VERTEX)[0] +compareTuples(geom.shapeInfo(aVertex), ('Vertex', 100.0, 30.0, 0.0)) diff --git a/src/PythonAPI/geom/ShapeInfo.py b/src/PythonAPI/geom/ShapeInfo.py new file mode 100644 index 000000000..b855bf5f9 --- /dev/null +++ b/src/PythonAPI/geom/ShapeInfo.py @@ -0,0 +1,19 @@ +import GeomAlgoAPI + +# A python implementation of shapeInfo functionality. +# By the given shape it will provide information, similar to data, displayed in the second part +# of Inspection Panel on selection of face, edge or vertex. +# The method returns a tuple with same data and in the same order as it is presented in the +# Information Panel: type of shape, then values (may be not-numerical, like Boolean 'Closed' for Polygon). +def shapeInfo(theShape): + anInfo = GeomAlgoAPI.GeomAlgoAPI_ShapeInfo(theShape) + aVals = anInfo.values() + aResList = [anInfo.shapeType()] + for aVal in aVals: + if aVal.type() == 0: + aResList.append(aVal.string()) + elif aVal.type() == 1: + aResList.append(aVal.real()) + elif aVal.type() == 2: + aResList.append(aVal.boolean()) + return tuple(aResList) diff --git a/src/PythonAPI/geom/__init__.py b/src/PythonAPI/geom/__init__.py index f9c917c7e..1ed0957fb 100644 --- a/src/PythonAPI/geom/__init__.py +++ b/src/PythonAPI/geom/__init__.py @@ -38,3 +38,4 @@ from GeomAPI import GeomAPI_Shape as Shape from GeomAlgoAPI import GeomAlgoAPI_Boolean as Boolean +from .ShapeInfo import * diff --git a/src/PythonAPI/tests.set b/src/PythonAPI/tests.set index 2781db704..5d4e6e438 100644 --- a/src/PythonAPI/tests.set +++ b/src/PythonAPI/tests.set @@ -49,5 +49,7 @@ SET(TEST_NAMES TestMakeBrick2.py TestPlatine.py + TestShapeInfo.py + Test2044.py ) diff --git a/src/SHAPERGUI/CMakeLists.txt b/src/SHAPERGUI/CMakeLists.txt index 99078ef8d..a61fc10b3 100644 --- a/src/SHAPERGUI/CMakeLists.txt +++ b/src/SHAPERGUI/CMakeLists.txt @@ -103,6 +103,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/XGUI ${PROJECT_SOURCE_DIR}/src/ModuleBase ${PROJECT_SOURCE_DIR}/src/ModelAPI ${PROJECT_SOURCE_DIR}/src/GeomAPI + ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI ${PROJECT_SOURCE_DIR}/src/Config ${PROJECT_SOURCE_DIR}/src/ExchangePlugin ${SUIT_INCLUDE} diff --git a/src/XGUI/XGUI_InspectionPanel.cpp b/src/XGUI/XGUI_InspectionPanel.cpp index 523bdd94f..4d272968f 100644 --- a/src/XGUI/XGUI_InspectionPanel.cpp +++ b/src/XGUI/XGUI_InspectionPanel.cpp @@ -35,23 +35,6 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include #include @@ -63,60 +46,13 @@ #include #include -#include -#include #include #include +#include #include // CAREFUL ! position of this file is critic -// ================ Auxiliary functions ================ -#define TITLE(val) ("" + (val) + "") - -static void appendPointToParameters(const QString& thePointTitle, - const GeomPointPtr& theCoord, - QString& theParams) -{ - theParams += TITLE(thePointTitle) + - "
X: " + QString::number(theCoord->x()) + - "
Y: " + QString::number(theCoord->y()) + - "
Z: " + QString::number(theCoord->z()) + - "
"; -} - -static void appendDirToParameters(const QString& theDirTitle, - const GeomDirPtr& theDirection, - QString& theParams) -{ - theParams += TITLE(theDirTitle) + - "
DX: " + QString::number(theDirection->x()) + - "
DY: " + QString::number(theDirection->y()) + - "
DZ: " + QString::number(theDirection->z()) + - "
"; -} - -static void appendGroupNameToParameters(const QString& theGroupTitle, QString& theParams) -{ - theParams += TITLE(theGroupTitle) + "
"; -} - -static void appendNamedValueToParameters(const QString& theName, - const double theValue, - QString& theParams) -{ - theParams += theName + ": " + QString::number(theValue) + "
"; -} - -static void appendNamedValueToParameters(const QString& theName, - const bool theValue, - QString& theParams) -{ - theParams += theName + ": " + (theValue ? "True" : "False") + "
"; -} - - // ================ 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 aPolygonPoints; - if (theWire->isPolygon(aPolygonPoints)) { - myTypeLbl->setText(tr("Polygon")); - int aCornerIndex = 0; - for (std::list::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 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 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(); - 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& 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& 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& 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& 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& 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& 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& theBox) -{ - myTypeLbl->setText(theTitle); - QString aParams; - std::shared_ptr 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) { diff --git a/src/XGUI/XGUI_InspectionPanel.h b/src/XGUI/XGUI_InspectionPanel.h index 8462a2591..580ccdf14 100644 --- a/src/XGUI/XGUI_InspectionPanel.h +++ b/src/XGUI/XGUI_InspectionPanel.h @@ -23,6 +23,7 @@ #include "XGUI.h" #include +#include #include @@ -40,20 +41,6 @@ class QGridLayout; class TopoDS_Shape; -class GeomAPI_Vertex; -class GeomAPI_Edge; -class GeomAPI_Wire; -class GeomAPI_Face; -class GeomAPI_Shell; -class GeomAPI_Solid; -class GeomAPI_Shape; - -class GeomAPI_Pln; -class GeomAPI_Sphere; -class GeomAPI_Cylinder; -class GeomAPI_Cone; -class GeomAPI_Torus; -class GeomAPI_Box; class ModuleBase_PageWidget; /// Internal name of property panel widget @@ -63,7 +50,7 @@ MAYBE_UNUSED const static char* INSPECTION_PANEL = "inspection_panel_dock"; * \ingroup GUI * A class which represents an inspection panel: to show content of currently selected objects */ -class XGUI_EXPORT XGUI_InspectionPanel : public QDockWidget +class XGUI_EXPORT XGUI_InspectionPanel : public QDockWidget, public GeomAlgoAPI_ShapeInfo::Translator { Q_OBJECT public: @@ -88,6 +75,10 @@ public: // Destructor virtual ~XGUI_InspectionPanel(); + // A translator of resource strings, needed for ShapeInfo. + virtual std::string translate(const char* theSource) override; + + protected: virtual void showEvent(QShowEvent* theEvent); @@ -109,76 +100,9 @@ private: /// \param theShape the shape void setShapeContent(const TopoDS_Shape& theShape); - /// Set parameters of the selected shape - /// \param theShape the shape - void setShapeParams(const TopoDS_Shape& theShape); - /// Clear content of the window void clearContent(); - /// Show parameters of a vertex - /// \param theVertex the vertex - void fillVertex(const std::shared_ptr& theVertex); - - /// Show parameters of a edge - /// \param theEdge the edge - void fillEdge(const std::shared_ptr& theEdge); - - /// Show parameters of a wire - /// \param theWire the wire - void fillWire(const std::shared_ptr& theWire); - - /// Show parameters of a face - /// \param theFace the face - void fillFace(const std::shared_ptr& theFace); - - /// Show parameters of a shell - /// \param theShell the shell - void fillShell(const std::shared_ptr& theShell); - - /// Show parameters of a solid - /// \param theSolid the solid - void fillSolid(const std::shared_ptr& theSolid); - - /// Show parameters of a compound - /// \param theShape the compound - void fillContainer(const std::shared_ptr& theShape); - - /// Show parameters of a plane - /// \param theTitle a title of the object - /// \param thePlane the plane - void setPlaneType(const QString& theTitle, const std::shared_ptr& thePlane); - - /// Show parameters of a sphere - /// \param theTitle a title of the object - /// \param theSphere the sphere - void setSphereType(const QString& theTitle, const std::shared_ptr& theSphere); - - /// Show parameters of a cylinder - /// \param theTitle a title of the object - /// \param theCyl the cylinder - void setCylinderType(const QString& theTitle, const std::shared_ptr& theCyl); - - /// Show parameters of a cone - /// \param theTitle a title of the object - /// \param theCone the cone - void setConeType(const QString& theTitle, const std::shared_ptr& theCone); - - /// Show parameters of a torus - /// \param theTitle a title of the object - /// \param theTorus the torus - void setTorusType(const QString& theTitle, const std::shared_ptr& theTorus); - - /// Show parameters of a box - /// \param theTitle a title of the object - /// \param theBox the box - void setBoxType(const QString& theTitle, const std::shared_ptr& theBox); - - /// Show parameters of a rotated box - /// \param theTitle a title of the object - /// \param theBox the box - void setRotatedBoxType(const QString& theTitle, const std::shared_ptr& theBox); - /// Set text into parameters area /// \param theText the text void setParamsText(const QString& theText);