TexGen
SectionRotated.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2006 Martin Sherburn
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#include "PrecompiledHeaders.h"
21#include "SectionRotated.h"
22
23using namespace TexGen;
24CSectionRotated::CSectionRotated(const CSection &Section, double dAngle)
25: m_dAngle(dAngle),m_pSection(Section)
26{
27 if ( m_pSection->GetType() == "CSectionRectangle" )
29}
30
32{
33}
34
35bool CSectionRotated::operator == (const CSection &CompareMe) const
36{
37 if (CompareMe.GetType() != GetType())
38 return false;
39 return m_dAngle == ((CSectionRotated*)&CompareMe)->m_dAngle &&
40 *m_pSection == *((CSectionRotated*)&CompareMe)->m_pSection;
41}
42
44: CSection(Element)
45{
46 Element.Attribute("Angle", &m_dAngle);
47 TiXmlElement* pSection = Element.FirstChildElement("Section");
48 if (pSection)
49 m_pSection = CreateSection(*pSection);
50}
51
52void CSectionRotated::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
53{
54 CSection::PopulateTiXmlElement(Element, OutputType);
55 Element.SetAttribute("Angle", stringify(m_dAngle));
56 TiXmlElement Section("Section");
57 m_pSection->PopulateTiXmlElement(Section, OutputType);
58 Element.InsertEndChild(Section);
59}
60
62{
63 return "Rotated(" + m_pSection->GetDefaultName() + ",R:" + stringify(m_dAngle) + ")";
64}
65
67{
68 return m_pSection->GetType();
69}
70
72{
73 XY Point = m_pSection->GetPoint(t);
74 XY RotatedPoint;
75 RotatedPoint.x = Point.x*cos(m_dAngle) - Point.y*sin(m_dAngle);
76 RotatedPoint.y = Point.x*sin(m_dAngle) + Point.y*cos(m_dAngle);
77 return RotatedPoint;
78}
79
80
81
82
83
84
Abstract base class respresenting a yarn cross-section.
Definition: Section.h:31
virtual void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
Definition: Section.cpp:51
friend class CSectionRotated
Definition: Section.h:33
static CObjectContainer< CSection > CreateSection(TiXmlElement &Element)
Create a section from TiXmlElement.
Definition: Section.cpp:78
virtual string GetType() const =0
Derived class should return the class name.
CObjectContainer< CSectionMesh > m_pSectionMesh
Pointer to a derived class of SectionMesh, this class is in charge of creating the section mesh.
Definition: Section.h:125
Create a rectangular mesh, the number of layers can be specified or set as -1 for automatic determina...
Section which represents a rotation of another section angle given in radians.
string GetBaseType() const
string GetDefaultName() const
Get the default name to assign to a section.
XY GetPoint(double t) const
Get a point lying on the perimeter correspending to parametric value t.
bool operator==(const CSection &CompareMe) const
Overloaded equality operator to determine if two sections are the same.
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
string GetType() const
Derived class should return the class name.
CObjectContainer< CSection > m_pSection
Namespace containing a series of customised math operations not found in the standard c++ library.
OUTPUT_TYPE
Definition: Misc.h:105
std::string stringify(const T &x, int iPrecision=12, bool bScientific=true)
Function to convert a value (e.g. int, double, etc...) to a string.
Definition: Misc.h:50
Struct for representing points in 2D space.
Definition: mymath.h:103
double x
Definition: mymath.h:104
double y
Definition: mymath.h:104