Files
create/src/Mod/Sketcher/App/Constraint.cpp
Abdullah Tahiri bc85670ce9 Sketcher new Feature: Non-driving constraints (aka Driven constraints or dimensions)
====================================================================================

It allows to enable and disable a constraint in the constraint list.

When disabled, the constraints current value is shown, but its value is not enforced (it is driven by the other constraints and user interaction).

A disabled constraint can be enabled (as far as it is enforceable, see non-driving constraints to external geometry below).

The sketcher functionality has been extended to support non-driving constraints to external geometry elements. This were previously excluded from
the possibility of creating a constraint on them (as their values depend on other sketches and would be redundant with the unchanged value or conflicting when value is changed).
Now these constraints are created as non-driving, but as they are not enforceable, the UI does not allow you to make them driving.

The constraint filter has been extended to include a Non-Driving constraints category.

Thanks again to Werner for his continuous support, and specially in this case to DeepSOIC, as he pointed towards a much better implementation solution than my original idea.
2015-05-30 16:39:25 +02:00

150 lines
5.4 KiB
C++

/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2008 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include <Base/Writer.h>
#include <Base/Reader.h>
#include "Constraint.h"
#include "ConstraintPy.h"
using namespace Sketcher;
using namespace Base;
TYPESYSTEM_SOURCE(Sketcher::Constraint, Base::Persistence)
const int Constraint::GeoUndef = -2000;
Constraint::Constraint()
: Type(None),
AlignmentType(Undef),
Name(""),
Value(0.0),
First(GeoUndef),
FirstPos(none),
Second(GeoUndef),
SecondPos(none),
Third(GeoUndef),
ThirdPos(none),
LabelDistance(10.f),
LabelPosition(0.f),
isDriving(true)
{
}
Constraint::Constraint(const Constraint& from)
: Type(from.Type),
AlignmentType(from.AlignmentType),
Name(from.Name),
Value(from.Value),
First(from.First),
FirstPos(from.FirstPos),
Second(from.Second),
SecondPos(from.SecondPos),
Third(from.Third),
ThirdPos(from.ThirdPos),
LabelDistance(from.LabelDistance),
LabelPosition(from.LabelPosition),
isDriving(from.isDriving)
{
}
Constraint::~Constraint()
{
}
Constraint *Constraint::clone(void) const
{
return new Constraint(*this);
}
PyObject *Constraint::getPyObject(void)
{
return new ConstraintPy(new Constraint(*this));
}
unsigned int Constraint::getMemSize (void) const
{
return 0;
}
void Constraint::Save (Writer &writer) const
{
writer.Stream() << writer.ind() << "<Constrain "
<< "Name=\"" << Name << "\" "
<< "Type=\"" << (int)Type << "\" ";
if(this->Type==InternalAlignment)
writer.Stream()
<< "InternalAlignmentType=\"" << (int)AlignmentType << "\" ";
writer.Stream()
<< "Value=\"" << Value << "\" "
<< "First=\"" << First << "\" "
<< "FirstPos=\"" << (int) FirstPos << "\" "
<< "Second=\"" << Second << "\" "
<< "SecondPos=\"" << (int) SecondPos << "\" "
<< "Third=\"" << Third << "\" "
<< "ThirdPos=\"" << (int) ThirdPos << "\" "
<< "LabelDistance=\"" << LabelDistance << "\" "
<< "LabelPosition=\"" << LabelPosition << "\" "
<< "IsDriving=\"" << (int)isDriving << "\" />"
<< std::endl;
}
void Constraint::Restore(XMLReader &reader)
{
reader.readElement("Constrain");
Name = reader.getAttribute("Name");
Type = (ConstraintType) reader.getAttributeAsInteger("Type");
Value = reader.getAttributeAsFloat("Value");
First = reader.getAttributeAsInteger("First");
FirstPos = (PointPos) reader.getAttributeAsInteger("FirstPos");
Second = reader.getAttributeAsInteger("Second");
SecondPos = (PointPos) reader.getAttributeAsInteger("SecondPos");
if(this->Type==InternalAlignment)
AlignmentType = (InternalAlignmentType) reader.getAttributeAsInteger("InternalAlignmentType");
else
AlignmentType = Undef;
// read the third geo group if present
if (reader.hasAttribute("Third")) {
Third = reader.getAttributeAsInteger("Third");
ThirdPos = (PointPos) reader.getAttributeAsInteger("ThirdPos");
}
// Read the distance a constraint label has been moved
if (reader.hasAttribute("LabelDistance"))
LabelDistance = (float)reader.getAttributeAsFloat("LabelDistance");
if (reader.hasAttribute("LabelPosition"))
LabelPosition = (float)reader.getAttributeAsFloat("LabelPosition");
if (reader.hasAttribute("IsDriving"))
isDriving = (bool)reader.getAttributeAsInteger("IsDriving");
}