SHAPER  9.12.0
GeomAlgoAPI_ShapeInfo.h
1 // Copyright (C) 2014-2023 CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef GeomAlgoAPI_ShapeInfo_H_
21 #define GeomAlgoAPI_ShapeInfo_H_
22 
23 #include "GeomAlgoAPI.h"
24 
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>
30 
31 #include <string>
32 
35 {
36  int myType; //< type stored in this Value
37  std::string myStr; //< type 0
38  double myDouble; //< type 1
39  bool myBool; //< type 2
40 
41 public:
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) {}
47 
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; }
52 };
53 
66 {
68  std::shared_ptr<GeomAPI_Shape> myShape;
69  std::string myShapeType; //< detected shape type
70 public:
71 
73  GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeInfo(const std::shared_ptr<GeomAPI_Shape> theShape)
74  : myShape(theShape) {}
75 
78  class Translator
79  {
80  public:
81  Translator() {}
82  GEOMALGOAPI_EXPORT virtual std::string translate(const char* theSource) { return theSource; }
83  };
84 
86  GEOMALGOAPI_EXPORT std::string html(Translator* theTranslator);
87 
89  GEOMALGOAPI_EXPORT const std::string& shapeType() { return myShapeType; }
90 
92  void setShapeType(const std::string theType) { myShapeType = theType; }
93 
95  GEOMALGOAPI_EXPORT std::list<GeomAlgoAPI_InfoValue> values();
96 
97 private:
99  enum InfoType {
100  TYPE_HTML,
101  TYPE_VALS
102  };
103 
105  class Values
106  {
108  InfoType myType;
110  std::string myStr;
111  Translator* myTr; //< an external translator
113  std::list<GeomAlgoAPI_InfoValue> myVals;
114  public:
115 
117  Values(const InfoType theType);
118 
120  const std::string& html() const { return myStr; }
121 
122  void setTranslator(Translator* theTranslator) { myTr = theTranslator; }
123  Translator* translator() { return myTr; }
124 
126  const std::list<GeomAlgoAPI_InfoValue>& values() const { return myVals; }
127 
129  Values& operator<< (double theValue);
131  Values& operator<< (bool theValue);
133  Values& operator<< (const char* theStr);
135  void addPoint(const char* theTitle, const GeomPointPtr& thePoint);
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);
143  void addGroupName(const char* theName);
144  };
145 
147  void processShape(Values& theVals);
148 
150  void processEdge(Values& theVals, GeomEdgePtr theEdge);
151 
153  void processFace(Values& theVals, GeomFacePtr theFace);
154 };
155 
156 #endif
Keeps values of different possible types, used in python shapeInfo.
Definition: GeomAlgoAPI_ShapeInfo.h:35
A translator to the current language is needed for HTML export.
Definition: GeomAlgoAPI_ShapeInfo.h:79
Provides information about shapes in textual (HTML for Information Panel) or a list of parameters ord...
Definition: GeomAlgoAPI_ShapeInfo.h:66
std::list< GeomAlgoAPI_InfoValue > values()
Returns a list of shape information values.
Definition: GeomAlgoAPI_ShapeInfo.cpp:47
void setShapeType(const std::string theType)
Sets the shape type.
Definition: GeomAlgoAPI_ShapeInfo.h:92
std::string html(Translator *theTranslator)
Returns an HTML text of a shape info.
Definition: GeomAlgoAPI_ShapeInfo.cpp:38
const std::string & shapeType()
Returns the detected shape type, or empty string.
Definition: GeomAlgoAPI_ShapeInfo.h:89
GeomAlgoAPI_ShapeInfo(const std::shared_ptr< GeomAPI_Shape > theShape)
Initializes a parameters input by an input shape.
Definition: GeomAlgoAPI_ShapeInfo.h:73
PointPtr addPoint(const std::shared_ptr< ModelAPI_Document > &thePart, const ModelHighAPI_Double &theX, const ModelHighAPI_Double &theY, const ModelHighAPI_Double &theZ)
Create Point feature.
Definition: ConstructionAPI_Point.cpp:353