basic infrastructure

This commit is contained in:
Stefan Tröger
2013-04-25 11:58:21 +02:00
committed by Stefan Tröger
parent 638cfcc2cf
commit 474fbbcb3e
42 changed files with 488 additions and 3460 deletions

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) 2010 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* Copyright (c) 2013 Stefan Tröger <stefantroeger@gmx.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
@@ -26,8 +27,12 @@
#endif
#include <Base/Placement.h>
#include <Base/Console.h>
#include "ConstraintGroupPy.h"
#include "ConstraintGroup.h"
#include "ItemPart.h"
#include "ItemAssembly.h"
using namespace Assembly;
@@ -42,6 +47,55 @@ ConstraintGroup::ConstraintGroup()
ADD_PROPERTY(Constraints,(0));
}
PyObject *ConstraintGroup::getPyObject(void)
{
if (PythonObject.is(Py::_None())){
// ref counter is set to 1
PythonObject = Py::Object(new ConstraintGroupPy(this),true);
}
return Py::new_reference_to(PythonObject);
}
void ConstraintGroup::addConstraint(Constraint* c)
{
//add the constraint to our list
const std::vector< App::DocumentObject * > &vals = this->Constraints.getValues();
std::vector< App::DocumentObject * > newVals(vals);
newVals.push_back(c);
this->Constraints.setValues(newVals);
//let's retrieve the solver if not already done
ItemAssembly* assembly = NULL;
if(!m_solver) {
typedef std::vector<App::DocumentObject*>::iterator iter;
std::vector<App::DocumentObject*> vec = getInList();
for(iter it = vec.begin(); it!=vec.end(); it++) {
if( (*it)->getTypeId() == ItemAssembly::getClassTypeId() ) {
assembly = static_cast<ItemAssembly*>(*it);
m_solver = assembly->m_solver;
break;
};
}
};
//check if we have been successfull
if(!m_solver) {
Base::Console().Message("ConstraintGroup: Unable to retrieve assembly solver\n");
return;
};
//init the constraint
c->init(m_solver);
//solve the system and propagate the change upstream
m_solver->solve();
assembly->touch();
}
short ConstraintGroup::mustExecute() const
{
//if (Sketch.isTouched() ||
@@ -53,7 +107,8 @@ short ConstraintGroup::mustExecute() const
App::DocumentObjectExecReturn *ConstraintGroup::execute(void)
{
Base::Console().Message("Recalculate constraint group\n");
return App::DocumentObject::StdReturn;
}
}
}