1 /*
2 *	Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
3 *
4 *	This program is free software: you can redistribute it and/or modify
5 *	it under the terms of the GNU Lesser General Public License as published
6 *	by the Free Software Foundation, either version 3 of the License, or
7 *	(at your option) any later version.
8 *
9 *	This program is distributed in the hope that it will be useful,
10 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *	GNU Lesser General Public License for more details.
13 *
14 *	You should have received a copy of the GNU Lesser General Public License
15 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef PARAMETERCOORD_H
19 #define PARAMETERCOORD_H
20 
21 #include "ParameterObjects.h"
22 
23 //! This class can hold a parameterized coordinate, defined in different coordinate systems.
24 class CSXCAD_EXPORT ParameterCoord
25 {
26 public:
27 	ParameterCoord();
28 	ParameterCoord(ParameterSet* ParaSet);
29 	ParameterCoord(CoordinateSystem cs);
30 	ParameterCoord(ParameterSet* ParaSet, const double value[3]);
31 	ParameterCoord(ParameterSet* ParaSet, const std::string value[3]);
32 	ParameterCoord(ParameterCoord* pc);
33 	~ParameterCoord();
34 
35 	void SetParameterSet(ParameterSet *paraSet);
36 
37 	//! Set the coordinate system used for this coordinates
SetCoordinateSystem(CoordinateSystem cs)38 	void SetCoordinateSystem(CoordinateSystem cs) {m_CoordSystem=cs; Update();}
39 	//! Convienient method to set the coordinate system, including a fall back if primary coordinate system is undefined.
40 	void SetCoordinateSystem(CoordinateSystem cs, CoordinateSystem fallBack_cs);
41 	//! Get the coordinate system that has been set for this coordinate
GetCoordinateSystem()42 	CoordinateSystem GetCoordinateSystem() const {return m_CoordSystem;}
43 
44 	int SetValue(int ny, std::string value);
45 	void SetValue(int ny, double value);
46 
47 	//! Get the native coordinate values
48 	double GetValue(int ny);
49 	//! Get the native coordinate values as string
50 	const std::string GetValueString(int ny) const;
51 	//! Get the internal scalar parameter, use carefully...
52 	ParameterScalar* GetCoordPS(int ny);
53 
54 	//! Get the coordinate in the given coordinate system
55 	double GetCoordValue(int ny, CoordinateSystem cs);
56 
57 	const double* GetNativeCoords() const;
GetCartesianCoords()58 	const double* GetCartesianCoords() const {return m_CartesianCoords;}
GetCylindricalCoords()59 	const double* GetCylindricalCoords() const {return m_CylindricalCoords;}
60 	const double* GetCoords(CoordinateSystem cs) const;
61 
62 	//! Evaluate the parametric coordinates and return an error message. This methode should be called before requesting coordinate values to check for valid parametric coordinates.
63 	bool Evaluate(std::string *ErrStr);
64 
65 	// Copy all values and parameter from pc to this.
66 	void Copy(ParameterCoord* pc);
67 
68 	//! Write this coords to a XML-node.
69 	bool Write2XML(TiXmlElement *elem, bool parameterised=true);
70 	//! Read coords from a XML-node.
71 	bool ReadFromXML(TiXmlElement *elem);
72 
73 protected:
74 	//! Update/evaluate the internal data structure
75 	void Update();
76 	ParameterScalar* m_Coords[3];
77 
78 	//! Coordinate system used for this coordinate
79 	CoordinateSystem m_CoordSystem;
80 
81 	//! evaluated cartesian coords
82 	double m_CartesianCoords[3];
83 	//! evaluated cylindrical coords
84 	double m_CylindricalCoords[3];
85 };
86 
87 //! Convert a given coordinate into another coordinate system
88 CSXCAD_EXPORT double* TransformCoordSystem(const double* in, double* out, CoordinateSystem CS_In, CoordinateSystem CS_out);
89 
90 #endif // PARAMETERCOORD_H
91