1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef GeomAlgoAPI_ShapeInfo_H_
21 #define GeomAlgoAPI_ShapeInfo_H_
23 #include "GeomAlgoAPI.h"
25 #include <GeomAPI_Shape.h>
26 #include <GeomAPI_Vertex.h>
27 #include <GeomAPI_Pnt.h>
28 #include <GeomAPI_Edge.h>
29 #include <GeomAPI_Face.h>
33 /// Keeps values of different possible types, used in python shapeInfo.
34 class GeomAlgoAPI_InfoValue
36 int myType; //< type stored in this Value
37 std::string myStr; //< type 0
38 double myDouble; //< type 1
39 bool myBool; //< type 2
42 GeomAlgoAPI_InfoValue() : myType(-1) {} // invalid case
43 GeomAlgoAPI_InfoValue(const char* theVal) : myType(0), myStr(theVal) {}
44 GeomAlgoAPI_InfoValue(const std::string theVal) : myType(0), myStr(theVal) {}
45 GeomAlgoAPI_InfoValue(const double theVal) : myType(1), myDouble(theVal) {}
46 GeomAlgoAPI_InfoValue(const bool theVal) : myType(2), myBool(theVal) {}
48 const int& type() const { return myType; }
49 const std::string& string() const { return myStr; }
50 const double& real() const { return myDouble; }
51 const bool& boolean() const { return myBool; }
54 /// \class GeomAlgoAPI_ShapeInfo
56 /// \brief Provides information about shapes in textual (HTML for Information Panel) or
57 /// a list of parameters order (for python "shapeInfo" command).
59 /// At least the following geometrical items are supported:
61 /// 1D : Line segment, Polygon, Circle, Arc, Ellipse, Arc of ellipse,
62 /// 2D : Rectangle, Polygon, Disc with circular or elliptical base, Sphere, Cylinder, Cone, Torus
64 /// It is initialized by a shape and fors the needed output depending on the requested format.
65 class GeomAlgoAPI_ShapeInfo
67 /// Keeps the shape, source of the produced information.
68 std::shared_ptr<GeomAPI_Shape> myShape;
69 std::string myShapeType; //< detected shape type
72 /// Initializes a parameters input by an input shape.
73 GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeInfo(const std::shared_ptr<GeomAPI_Shape> theShape)
74 : myShape(theShape) {}
76 /// A translator to the current language is needed for HTML export.
77 /// It is provided by a caller of this class.
82 GEOMALGOAPI_EXPORT virtual std::string translate(const char* theSource) { return theSource; }
85 /// Returns an HTML text of a shape info.
86 GEOMALGOAPI_EXPORT std::string html(Translator* theTranslator);
88 /// Returns the detected shape type, or empty string.
89 GEOMALGOAPI_EXPORT const std::string& shapeType() { return myShapeType; }
91 /// Sets the shape type
92 void setShapeType(const std::string theType) { myShapeType = theType; }
94 /// Returns a list of shape information values.
95 GEOMALGOAPI_EXPORT std::list<GeomAlgoAPI_InfoValue> values();
98 /// Possible types of export values
104 /// Allows to input values in a defined format, then - to export them.
107 /// A type of stored shape info.
109 /// An HTML string container.
111 Translator* myTr; //< an external translator
112 /// A container of values: type of the value -> value
113 std::list<GeomAlgoAPI_InfoValue> myVals;
116 /// Initialization of an empty container, default translator
117 Values(const InfoType theType);
119 /// Returns HTML representation of values
120 const std::string& html() const { return myStr; }
122 void setTranslator(Translator* theTranslator) { myTr = theTranslator; }
123 Translator* translator() { return myTr; }
125 /// Returns list of values representation.
126 const std::list<GeomAlgoAPI_InfoValue>& values() const { return myVals; }
129 Values& operator<< (double theValue);
131 Values& operator<< (bool theValue);
133 Values& operator<< (const char* theStr);
134 /// Adds point coordinates
135 void addPoint(const char* theTitle, const GeomPointPtr& thePoint);
136 /// Adds directon coordinates
137 void addDirection(const char* theTitle, const GeomDirPtr& thePoint);
139 void addNamedValue(const char* theName, const double theValue);
141 void addNamedValue(const char* theName, const bool theValue);
142 /// Adds a name (title) of the group
143 void addGroupName(const char* theName);
146 /// Gets information from the shape
147 void processShape(Values& theVals);
149 /// Gets particual information from the edge
150 void processEdge(Values& theVals, GeomEdgePtr theEdge);
152 /// Gets particual information from face
153 void processFace(Values& theVals, GeomFacePtr theFace);