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>
31 /// Keeps values of different possible types, used in python shapeInfo.
32 class GeomAlgoAPI_InfoValue
34 int myType; //< type stored in this Value
35 std::string myStr; //< type 0
36 double myDouble; //< type 1
37 bool myBool; //< type 2
40 GeomAlgoAPI_InfoValue() : myType(-1) {} // invalid case
41 GeomAlgoAPI_InfoValue(const char* theVal) : myType(0), myStr(theVal) {}
42 GeomAlgoAPI_InfoValue(const std::string theVal) : myType(0), myStr(theVal) {}
43 GeomAlgoAPI_InfoValue(const double theVal) : myType(1), myDouble(theVal) {}
44 GeomAlgoAPI_InfoValue(const bool theVal) : myType(2), myBool(theVal) {}
46 const int& type() const { return myType; }
47 const std::string& string() const { return myStr; }
48 const double& real() const { return myDouble; }
49 const bool& boolean() const { return myBool; }
52 /// \class GeomAlgoAPI_ShapeInfo
54 /// \brief Provides information about shapes in textual (HTML for Information Panel) or
55 /// a list of parameters order (for python "shapeInfo" command).
57 /// At least the following geometrical items are supported:
59 /// 1D : Line segment, Polygon, Circle, Arc, Ellipse, Arc of ellipse,
60 /// 2D : Rectangle, Polygon, Disc with circular or elliptical base, Sphere, Cylinder, Cone, Torus
62 /// It is initialized by a shape and fors the needed output depending on the requested format.
63 class GeomAlgoAPI_ShapeInfo
65 /// Keeps the shape, source of the produced information.
66 std::shared_ptr<GeomAPI_Shape> myShape;
67 std::string myShapeType; //< detected shape type
70 /// Initializes a parameters input by an input shape.
71 GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeInfo(const std::shared_ptr<GeomAPI_Shape> theShape)
72 : myShape(theShape) {}
74 /// A translator to the current language is needed for HTML export.
75 /// It is provided by a caller of this class.
80 GEOMALGOAPI_EXPORT virtual std::string translate(const char* theSource) { return theSource; }
83 /// Returns an HTML text of a shape info.
84 GEOMALGOAPI_EXPORT std::string html(Translator* theTranslator);
86 /// Returns the detected shape type, or empty string.
87 GEOMALGOAPI_EXPORT const std::string& shapeType() { return myShapeType; }
89 /// Sets the shape type
90 void setShapeType(const std::string theType) { myShapeType = theType; }
92 /// Returns a list of shape information values.
93 GEOMALGOAPI_EXPORT std::list<GeomAlgoAPI_InfoValue> values();
96 /// Possible types of export values
102 /// Allows to input values in a defined format, then - to export them.
105 /// A type of stored shape info.
107 /// An HTML string container.
109 Translator* myTr; //< an external translator
110 /// A container of values: type of the value -> value
111 std::list<GeomAlgoAPI_InfoValue> myVals;
114 /// Initialization of an empty container, default translator
115 Values(const InfoType theType);
117 /// Returns HTML representation of values
118 const std::string& html() const { return myStr; }
120 void setTranslator(Translator* theTranslator) { myTr = theTranslator; }
121 Translator* translator() { return myTr; }
123 /// Returns list of values representation.
124 const std::list<GeomAlgoAPI_InfoValue>& values() const { return myVals; }
127 Values& operator<< (double theValue);
129 Values& operator<< (bool theValue);
131 Values& operator<< (const char* theStr);
132 /// Adds point coordinates
133 void addPoint(const char* theTitle, const GeomPointPtr& thePoint);
134 /// Adds directon coordinates
135 void addDirection(const char* theTitle, const GeomDirPtr& thePoint);
137 void addNamedValue(const char* theName, const double theValue);
139 void addNamedValue(const char* theName, const bool theValue);
140 /// Adds a name (title) of the group
141 void addGroupName(const char* theName);
144 /// Gets information from the shape
145 void processShape(Values& theVals);
147 /// Gets particual information from the edge
148 void processEdge(Values& theVals, GeomEdgePtr theEdge);
150 /// Gets particual information from face
151 void processFace(Values& theVals, GeomFacePtr theFace);