Constraint.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2008     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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     // read the third geo group if present
00119     if (reader.hasAttribute("Third")) {
00120         Third    = reader.getAttributeAsInteger("Third");
00121         ThirdPos = (PointPos)  reader.getAttributeAsInteger("ThirdPos");
00122     }
00123     // Read the distance a constraint label has been moved
00124     if (reader.hasAttribute("LabelDistance"))
00125         LabelDistance = (float)reader.getAttributeAsFloat("LabelDistance");
00126 }

Generated on Wed Nov 23 19:00:04 2011 for FreeCAD by  doxygen 1.6.1