Constraint.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 #endif
00027
00028 #include <Base/Writer.h>
00029 #include <Base/Reader.h>
00030
00031
00032 #include "Constraint.h"
00033 #include "ConstraintPy.h"
00034
00035
00036 using namespace Sketcher;
00037 using namespace Base;
00038
00039
00040 TYPESYSTEM_SOURCE(Sketcher::Constraint, Base::Persistence)
00041
00042 const int Constraint::GeoUndef = -2000;
00043
00044 Constraint::Constraint()
00045 : Type(None),
00046 Name(""),
00047 Value(0.0),
00048 First(GeoUndef),
00049 FirstPos(none),
00050 Second(GeoUndef),
00051 SecondPos(none),
00052 Third(GeoUndef),
00053 ThirdPos(none),
00054 LabelDistance(10.f)
00055 {
00056 }
00057
00058 Constraint::Constraint(const Constraint& from)
00059 : Type(from.Type),
00060 Name(from.Name),
00061 Value(from.Value),
00062 First(from.First),
00063 FirstPos(from.FirstPos),
00064 Second(from.Second),
00065 SecondPos(from.SecondPos),
00066 Third(from.Third),
00067 ThirdPos(from.ThirdPos),
00068 LabelDistance(from.LabelDistance)
00069 {
00070 }
00071
00072 Constraint::~Constraint()
00073 {
00074 }
00075
00076 Constraint *Constraint::clone(void) const
00077 {
00078 return new Constraint(*this);
00079 }
00080
00081 PyObject *Constraint::getPyObject(void)
00082 {
00083 return new ConstraintPy(new Constraint(*this));
00084 }
00085
00086 unsigned int Constraint::getMemSize (void) const
00087 {
00088 return 0;
00089 }
00090
00091 void Constraint::Save (Writer &writer) const
00092 {
00093 writer.Stream() << writer.ind() << "<Constrain "
00094 << "Name=\"" << Name << "\" "
00095 << "Type=\"" << (int)Type << "\" "
00096 << "Value=\"" << Value << "\" "
00097 << "First=\"" << First << "\" "
00098 << "FirstPos=\"" << (int) FirstPos << "\" "
00099 << "Second=\"" << Second << "\" "
00100 << "SecondPos=\"" << (int) SecondPos << "\" "
00101 << "Third=\"" << Third << "\" "
00102 << "ThirdPos=\"" << (int) ThirdPos << "\" "
00103 << "LabelDistance=\"" << LabelDistance<< "\" />"
00104 << std::endl;
00105 }
00106
00107 void Constraint::Restore(XMLReader &reader)
00108 {
00109 reader.readElement("Constrain");
00110 Name = reader.getAttribute("Name");
00111 Type = (ConstraintType) reader.getAttributeAsInteger("Type");
00112 Value = reader.getAttributeAsFloat("Value");
00113 First = reader.getAttributeAsInteger("First");
00114 FirstPos = (PointPos) reader.getAttributeAsInteger("FirstPos");
00115 Second = reader.getAttributeAsInteger("Second");
00116 SecondPos = (PointPos) reader.getAttributeAsInteger("SecondPos");
00117
00118
00119 if (reader.hasAttribute("Third")) {
00120 Third = reader.getAttributeAsInteger("Third");
00121 ThirdPos = (PointPos) reader.getAttributeAsInteger("ThirdPos");
00122 }
00123
00124 if (reader.hasAttribute("LabelDistance"))
00125 LabelDistance = (float)reader.getAttributeAsFloat("LabelDistance");
00126 }