TexGen
SectionScaled.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 "SectionScaled.h"
22
23using namespace TexGen;
24CSectionScaled::CSectionScaled(const CSection &Section, XY Scale)
25: m_Scale(Scale), m_pSection(Section)
26{
27}
28
30{
31}
32
33bool CSectionScaled::operator == (const CSection &CompareMe) const
34{
35 if (CompareMe.GetType() != GetType())
36 return false;
37 return m_Scale == ((CSectionScaled*)&CompareMe)->m_Scale &&
38 *m_pSection == *((CSectionScaled*)&CompareMe)->m_pSection;
39}
40
41CSectionScaled::CSectionScaled(TiXmlElement &Element)
42: CSection(Element)
43{
44 m_Scale = valueify<XY>(Element.Attribute("Scale"));
45 TiXmlElement* pSection = Element.FirstChildElement("Section");
46 if (pSection)
47 m_pSection = CreateSection(*pSection);
48}
49
50void CSectionScaled::PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
51{
52 CSection::PopulateTiXmlElement(Element, OutputType);
53 Element.SetAttribute("Scale", stringify(m_Scale));
54 TiXmlElement Section("Section");
55 m_pSection->PopulateTiXmlElement(Section, OutputType);
56 Element.InsertEndChild(Section);
57}
58
59
61{
62 return "Scaled(" + m_pSection->GetDefaultName() + ",S:" + stringify(m_Scale) + ")";
63}
64
66{
67 XY Point = m_pSection->GetPoint(t);
68 XY ScalePoint;
69 ScalePoint.x = Point.x * m_Scale.x;
70 ScalePoint.y = Point.y * m_Scale.y;
71 return ScalePoint;
72}
73
74
75
76
77
78
79
80
81
82
83
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
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.
friend class CSectionScaled
Definition: Section.h:34
Section which represents a scaled version of another section.
Definition: SectionScaled.h:29
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.
void PopulateTiXmlElement(TiXmlElement &Element, OUTPUT_TYPE OutputType) const
Used for saving data to XML.
CObjectContainer< CSection > m_pSection
Definition: SectionScaled.h:51
string GetType() const
Derived class should return the class name.
Definition: SectionScaled.h:40
bool operator==(const CSection &CompareMe) const
Overloaded equality operator to determine if two sections are the same.
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