Start of rework of class structure
This commit is contained in:
@@ -31,8 +31,9 @@
|
||||
#include <Base/Interpreter.h>
|
||||
|
||||
#include "Item.h"
|
||||
#include "ItemAssembly.h"
|
||||
#include "ItemPart.h"
|
||||
#include "Product.h"
|
||||
#include "ProductRef.h"
|
||||
#include "PartRef.h"
|
||||
|
||||
#include "Constraint.h"
|
||||
#include "ConstraintGroup.h"
|
||||
@@ -69,9 +70,10 @@ void AssemblyExport initAssembly()
|
||||
// This function is responsible for adding inherited slots from a type's base class.
|
||||
|
||||
// Item hirachy
|
||||
Assembly::Item ::init();
|
||||
Assembly::ItemAssembly ::init();
|
||||
Assembly::ItemPart ::init();
|
||||
Assembly::Item ::init();
|
||||
Assembly::Product ::init();
|
||||
Assembly::ProductRef ::init();
|
||||
Assembly::PartRef ::init();
|
||||
|
||||
// constraint hirachy
|
||||
Assembly::Constraint ::init();
|
||||
|
||||
@@ -31,18 +31,20 @@ set(Assembly_LIBS
|
||||
)
|
||||
|
||||
generate_from_xml(ItemPy)
|
||||
generate_from_xml(ItemAssemblyPy)
|
||||
generate_from_xml(ItemPartPy)
|
||||
generate_from_xml(ProductRefPy)
|
||||
generate_from_xml(PartRefPy)
|
||||
generate_from_xml(ConstraintPy)
|
||||
generate_from_xml(ConstraintGroupPy)
|
||||
|
||||
SET(Features_SRCS
|
||||
Item.cpp
|
||||
Item.h
|
||||
ItemPart.cpp
|
||||
ItemPart.h
|
||||
ItemAssembly.cpp
|
||||
ItemAssembly.h
|
||||
PartRef.cpp
|
||||
PartRef.h
|
||||
Product.cpp
|
||||
Product.h
|
||||
ProductRef.cpp
|
||||
ProductRef.h
|
||||
Constraint.cpp
|
||||
Constraint.h
|
||||
ConstraintGroup.cpp
|
||||
@@ -80,10 +82,10 @@ SOURCE_GROUP("Solver" FILES ${Solver_SRC})
|
||||
SET(Python_SRCS
|
||||
ItemPy.xml
|
||||
ItemPyImp.cpp
|
||||
ItemAssemblyPy.xml
|
||||
ItemAssemblyPyImp.cpp
|
||||
ItemPartPy.xml
|
||||
ItemPartPyImp.cpp
|
||||
ProductRefPy.xml
|
||||
ProductRefPyImp.cpp
|
||||
PartRefPy.xml
|
||||
PartRefPyImp.cpp
|
||||
ConstraintPy.xml
|
||||
ConstraintPyImp.cpp
|
||||
ConstraintGroupPy.xml
|
||||
|
||||
@@ -50,8 +50,8 @@
|
||||
#include "Constraint.h"
|
||||
#include "ConstraintPy.h"
|
||||
#include "Item.h"
|
||||
#include "ItemPart.h"
|
||||
#include "ItemAssembly.h"
|
||||
#include "PartRef.h"
|
||||
#include "Product.h"
|
||||
|
||||
|
||||
using namespace Assembly;
|
||||
@@ -129,13 +129,13 @@ boost::shared_ptr<Geometry3D> Constraint::initLink(App::PropertyLinkSub& link) {
|
||||
if(!link.getValue())
|
||||
return boost::shared_ptr<Geometry3D>();
|
||||
|
||||
//check if we have Assembly::ItemPart
|
||||
if(link.getValue()->getTypeId() != ItemPart::getClassTypeId()) {
|
||||
//check if we have Assembly::PartRef
|
||||
if(link.getValue()->getTypeId() != PartRef::getClassTypeId()) {
|
||||
throw ConstraintLinkException();
|
||||
return boost::shared_ptr<Geometry3D>();
|
||||
};
|
||||
|
||||
Assembly::ItemPart* part = static_cast<Assembly::ItemPart*>(link.getValue());
|
||||
Assembly::PartRef* part = static_cast<Assembly::PartRef*>(link.getValue());
|
||||
|
||||
if(!part)
|
||||
throw ConstraintPartException();
|
||||
@@ -147,18 +147,18 @@ boost::shared_ptr<Geometry3D> Constraint::initLink(App::PropertyLinkSub& link) {
|
||||
}
|
||||
|
||||
|
||||
void Constraint::init(Assembly::ItemAssembly* ass)
|
||||
void Constraint::init(Assembly::Product* ass)
|
||||
{
|
||||
Assembly::ItemPart* part1, *part2;
|
||||
Assembly::PartRef* part1, *part2;
|
||||
|
||||
if(First.getValue()) {
|
||||
m_first_geom = initLink(First);
|
||||
part1 = static_cast<Assembly::ItemPart*>(First.getValue());
|
||||
part1 = static_cast<Assembly::PartRef*>(First.getValue());
|
||||
}
|
||||
|
||||
if(Second.getValue()) {
|
||||
m_second_geom = initLink(Second);
|
||||
part2= static_cast<Assembly::ItemPart*>(Second.getValue());
|
||||
part2= static_cast<Assembly::PartRef*>(Second.getValue());
|
||||
}
|
||||
|
||||
//fix constraint
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <TopoDS_Shape.hxx>
|
||||
|
||||
#include "Solver/Solver.h"
|
||||
#include "ItemAssembly.h"
|
||||
#include "Product.h"
|
||||
|
||||
|
||||
namespace Assembly
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
App::PropertyLinkSub First;
|
||||
App::PropertyLinkSub Second;
|
||||
App::PropertyFloat Value;
|
||||
App::PropertyFloat Value;
|
||||
App::PropertyEnumeration Orientation;
|
||||
App::PropertyEnumeration SolutionSpace;
|
||||
App::PropertyEnumeration Type;
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
|
||||
/** @brief initialize the constraint in the assembly solver
|
||||
*/
|
||||
void init(Assembly::ItemAssembly* ass);
|
||||
void init(Assembly::Product* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
||||
@@ -31,8 +31,8 @@
|
||||
|
||||
#include "ConstraintGroupPy.h"
|
||||
#include "ConstraintGroup.h"
|
||||
#include "ItemPart.h"
|
||||
#include "ItemAssembly.h"
|
||||
#include "PartRef.h"
|
||||
#include "Product.h"
|
||||
|
||||
|
||||
using namespace Assembly;
|
||||
@@ -72,7 +72,7 @@ App::DocumentObjectExecReturn *ConstraintGroup::execute(void)
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
void ConstraintGroup::init(ItemAssembly* ass) {
|
||||
void ConstraintGroup::init(Product* ass) {
|
||||
|
||||
std::vector<App::DocumentObject*> obj = Constraints.getValues();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
}
|
||||
//@}
|
||||
|
||||
void init(Assembly::ItemAssembly* ass);
|
||||
void init(Assembly::Product* ass);
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "Mod/Assembly/App/ItemAssembly.h"
|
||||
|
||||
// inclusion of the generated files (generated out of ItemAssemblyPy.xml)
|
||||
#include "ItemAssemblyPy.h"
|
||||
#include "ItemAssemblyPy.cpp"
|
||||
#include <ItemPartPy.h>
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string ItemAssemblyPy::representation(void) const
|
||||
{
|
||||
return std::string("<ItemAssembly object>");
|
||||
}
|
||||
|
||||
|
||||
PyObject *ItemAssemblyPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ItemAssemblyPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "Mod/Assembly/App/ItemPart.h"
|
||||
|
||||
// inclusion of the generated files (generated out of ItemPartPy.xml)
|
||||
#include "ItemPartPy.h"
|
||||
#include "ItemPartPy.cpp"
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string ItemPartPy::representation(void) const
|
||||
{
|
||||
return std::string("<ItemPart object>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
PyObject *ItemPartPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ItemPartPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,233 +1,233 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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/Placement.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include "ItemPart.h"
|
||||
#include "ItemAssembly.h"
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Part/App/BodyBase.h>
|
||||
#include <ItemPartPy.h>
|
||||
#include <TopoDS.hxx>
|
||||
#include <GeomAbs_SurfaceType.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <GeomAbs_CurveType.hxx>
|
||||
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
namespace Assembly {
|
||||
|
||||
struct AssemblyItemException : std::exception {
|
||||
const char* what() const throw() { return "Assembly items are in wrong structure";}
|
||||
};
|
||||
|
||||
|
||||
PROPERTY_SOURCE(Assembly::ItemPart, Assembly::Item)
|
||||
|
||||
ItemPart::ItemPart() {
|
||||
ADD_PROPERTY(Model, (0));
|
||||
ADD_PROPERTY(Annotation,(0));
|
||||
}
|
||||
|
||||
short ItemPart::mustExecute() const {
|
||||
//if (Sketch.isTouched() ||
|
||||
// Length.isTouched())
|
||||
// return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn* ItemPart::execute(void) {
|
||||
|
||||
this->touch();
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
TopoDS_Shape ItemPart::getShape(void) const {
|
||||
App::DocumentObject* obj = Model.getValue();
|
||||
|
||||
if(obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
return static_cast<Part::Feature*>(obj)->Shape.getValue();
|
||||
}
|
||||
|
||||
return TopoDS_Shape();
|
||||
}
|
||||
|
||||
PyObject* ItemPart::getPyObject(void) {
|
||||
if(PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new ItemPartPy(this),true);
|
||||
}
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
bool ItemPart::holdsObject(App::DocumentObject* obj) const {
|
||||
|
||||
//get the body object and the relevant model list
|
||||
Part::BodyBase* base = static_cast<Part::BodyBase*>(Model.getValue());
|
||||
const std::vector<App::DocumentObject*>& vector = base->Model.getValues();
|
||||
|
||||
//check if it holds the relevant document object
|
||||
return std::find(vector.begin(), vector.end(), obj)!=vector.end();
|
||||
}
|
||||
|
||||
void ItemPart::setCalculatedPlacement(boost::shared_ptr< Part3D > part) {
|
||||
|
||||
//part is the same as m_part, so it doasn't matter which one we use
|
||||
Base::Placement p = dcm::get<Base::Placement>(part);
|
||||
|
||||
ItemAssembly* ass = getParentAssembly();
|
||||
if(!ass)
|
||||
throw AssemblyItemException();
|
||||
|
||||
if(ass->Rigid.getValue())
|
||||
Placement.setValue(p);
|
||||
else
|
||||
Placement.setValue(ass->m_downstream_placement.inverse()*p);
|
||||
}
|
||||
|
||||
ItemAssembly* ItemPart::getParentAssembly() {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = getInList();
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId())
|
||||
return static_cast<Assembly::ItemAssembly*>(*it);
|
||||
};
|
||||
|
||||
return (ItemAssembly*)NULL;
|
||||
}
|
||||
|
||||
void ItemPart::ensureInitialisation() {
|
||||
|
||||
ItemAssembly* ass = getParentAssembly();
|
||||
if(!ass)
|
||||
throw AssemblyItemException();
|
||||
|
||||
boost::shared_ptr<Solver> solver = ass->m_solver;
|
||||
if(!solver)
|
||||
throw AssemblyItemException();
|
||||
|
||||
if(!solver->hasPart(Uid.getValueStr())) {
|
||||
|
||||
//if the assembly is not rigid it was not added to the solver, so we need to incorporate its placement
|
||||
if(ass->Rigid.getValue()) {
|
||||
m_part = solver->createPart(Placement.getValue(), Uid.getValueStr());
|
||||
}
|
||||
else {
|
||||
m_part = solver->createPart(ass->m_downstream_placement*Placement.getValue(), Uid.getValueStr());
|
||||
}
|
||||
m_part->connectSignal<dcm::recalculated>(boost::bind(&ItemPart::setCalculatedPlacement, this, _1));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
boost::shared_ptr< Geometry3D > ItemPart::getGeometry3D(const char* Type) {
|
||||
|
||||
//check if the item is initialized
|
||||
if(!m_part)
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
|
||||
boost::shared_ptr<Geometry3D> geometry;
|
||||
if(m_part->hasGeometry3D(Type)) {
|
||||
return m_part->getGeometry3D(Type);
|
||||
}
|
||||
else {
|
||||
Part::TopoShape ts;
|
||||
App::DocumentObject* obj = Model.getValue();
|
||||
|
||||
if(obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
ts = static_cast<Part::Feature*>(obj)->Shape.getShape();
|
||||
}
|
||||
else
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
|
||||
TopoDS_Shape s = ts.getSubShape(Type);
|
||||
if(s.ShapeType() == TopAbs_FACE) {
|
||||
TopoDS_Face face = TopoDS::Face(s);
|
||||
BRepAdaptor_Surface surface(face);
|
||||
switch(surface.GetType()) {
|
||||
case GeomAbs_Plane: {
|
||||
gp_Pln plane = surface.Plane();
|
||||
if(face.Orientation()==TopAbs_REVERSED) {
|
||||
gp_Dir dir = plane.Axis().Direction();
|
||||
plane = gp_Pln(plane.Location(), dir.Reversed());
|
||||
}
|
||||
geometry = m_part->addGeometry3D(plane, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
case GeomAbs_Cylinder: {
|
||||
gp_Cylinder cyl = surface.Cylinder();
|
||||
geometry = m_part->addGeometry3D(cyl, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Base::Console().Message("Unsuported Surface Geometrie Type at selection\n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
if(s.ShapeType() == TopAbs_EDGE) {
|
||||
TopoDS_Edge edge = TopoDS::Edge(s);
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
switch(curve.GetType()) {
|
||||
case GeomAbs_Line: {
|
||||
gp_Lin line = curve.Line();
|
||||
geometry = m_part->addGeometry3D(line, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Base::Console().Message("Unsuported Curve Geometrie Type at selection \n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
if(s.ShapeType() == TopAbs_VERTEX) {
|
||||
TopoDS_Vertex v1 = TopoDS::Vertex(s);
|
||||
gp_Pnt point = BRep_Tool::Pnt(v1);
|
||||
geometry = m_part->addGeometry3D(point, Type, dcm::Local);
|
||||
|
||||
}
|
||||
else {
|
||||
Base::Console().Message("Unsuported Topologie Type at selection\n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
};
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
}
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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/Placement.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include "PartRef.h"
|
||||
#include "Product.h"
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Part/App/BodyBase.h>
|
||||
#include <PartRefPy.h>
|
||||
#include <TopoDS.hxx>
|
||||
#include <GeomAbs_SurfaceType.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <GeomAbs_CurveType.hxx>
|
||||
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
namespace Assembly {
|
||||
|
||||
struct AssemblyItemException : std::exception {
|
||||
const char* what() const throw() { return "Assembly items are in wrong structure";}
|
||||
};
|
||||
|
||||
|
||||
PROPERTY_SOURCE(Assembly::PartRef, Assembly::Item)
|
||||
|
||||
PartRef::PartRef() {
|
||||
ADD_PROPERTY(Model, (0));
|
||||
ADD_PROPERTY(Annotation,(0));
|
||||
}
|
||||
|
||||
short PartRef::mustExecute() const {
|
||||
//if (Sketch.isTouched() ||
|
||||
// Length.isTouched())
|
||||
// return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn* PartRef::execute(void) {
|
||||
|
||||
this->touch();
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
TopoDS_Shape PartRef::getShape(void) const {
|
||||
App::DocumentObject* obj = Model.getValue();
|
||||
|
||||
if(obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
return static_cast<Part::Feature*>(obj)->Shape.getValue();
|
||||
}
|
||||
|
||||
return TopoDS_Shape();
|
||||
}
|
||||
|
||||
PyObject* PartRef::getPyObject(void) {
|
||||
if(PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new PartRefPy(this),true);
|
||||
}
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
bool PartRef::holdsObject(App::DocumentObject* obj) const {
|
||||
|
||||
//get the body object and the relevant model list
|
||||
Part::BodyBase* base = static_cast<Part::BodyBase*>(Model.getValue());
|
||||
const std::vector<App::DocumentObject*>& vector = base->Model.getValues();
|
||||
|
||||
//check if it holds the relevant document object
|
||||
return std::find(vector.begin(), vector.end(), obj)!=vector.end();
|
||||
}
|
||||
|
||||
void PartRef::setCalculatedPlacement(boost::shared_ptr< Part3D > part) {
|
||||
|
||||
//part is the same as m_part, so it doasn't matter which one we use
|
||||
Base::Placement p = dcm::get<Base::Placement>(part);
|
||||
|
||||
Product* ass = getParentAssembly();
|
||||
if(!ass)
|
||||
throw AssemblyItemException();
|
||||
|
||||
if(ass->Rigid.getValue())
|
||||
Placement.setValue(p);
|
||||
else
|
||||
Placement.setValue(ass->m_downstream_placement.inverse()*p);
|
||||
}
|
||||
|
||||
Product* PartRef::getParentAssembly() {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = getInList();
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::Product::getClassTypeId())
|
||||
return static_cast<Assembly::Product*>(*it);
|
||||
};
|
||||
|
||||
return (Product*)NULL;
|
||||
}
|
||||
|
||||
void PartRef::ensureInitialisation() {
|
||||
|
||||
Product* ass = getParentAssembly();
|
||||
if(!ass)
|
||||
throw AssemblyItemException();
|
||||
|
||||
boost::shared_ptr<Solver> solver = ass->m_solver;
|
||||
if(!solver)
|
||||
throw AssemblyItemException();
|
||||
|
||||
if(!solver->hasPart(Uid.getValueStr())) {
|
||||
|
||||
//if the assembly is not rigid it was not added to the solver, so we need to incorporate its placement
|
||||
if(ass->Rigid.getValue()) {
|
||||
m_part = solver->createPart(Placement.getValue(), Uid.getValueStr());
|
||||
}
|
||||
else {
|
||||
m_part = solver->createPart(ass->m_downstream_placement*Placement.getValue(), Uid.getValueStr());
|
||||
}
|
||||
m_part->connectSignal<dcm::recalculated>(boost::bind(&PartRef::setCalculatedPlacement, this, _1));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
boost::shared_ptr< Geometry3D > PartRef::getGeometry3D(const char* Type) {
|
||||
|
||||
//check if the item is initialized
|
||||
if(!m_part)
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
|
||||
boost::shared_ptr<Geometry3D> geometry;
|
||||
if(m_part->hasGeometry3D(Type)) {
|
||||
return m_part->getGeometry3D(Type);
|
||||
}
|
||||
else {
|
||||
Part::TopoShape ts;
|
||||
App::DocumentObject* obj = Model.getValue();
|
||||
|
||||
if(obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
ts = static_cast<Part::Feature*>(obj)->Shape.getShape();
|
||||
}
|
||||
else
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
|
||||
TopoDS_Shape s = ts.getSubShape(Type);
|
||||
if(s.ShapeType() == TopAbs_FACE) {
|
||||
TopoDS_Face face = TopoDS::Face(s);
|
||||
BRepAdaptor_Surface surface(face);
|
||||
switch(surface.GetType()) {
|
||||
case GeomAbs_Plane: {
|
||||
gp_Pln plane = surface.Plane();
|
||||
if(face.Orientation()==TopAbs_REVERSED) {
|
||||
gp_Dir dir = plane.Axis().Direction();
|
||||
plane = gp_Pln(plane.Location(), dir.Reversed());
|
||||
}
|
||||
geometry = m_part->addGeometry3D(plane, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
case GeomAbs_Cylinder: {
|
||||
gp_Cylinder cyl = surface.Cylinder();
|
||||
geometry = m_part->addGeometry3D(cyl, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Base::Console().Message("Unsuported Surface Geometrie Type at selection\n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
if(s.ShapeType() == TopAbs_EDGE) {
|
||||
TopoDS_Edge edge = TopoDS::Edge(s);
|
||||
BRepAdaptor_Curve curve(edge);
|
||||
switch(curve.GetType()) {
|
||||
case GeomAbs_Line: {
|
||||
gp_Lin line = curve.Line();
|
||||
geometry = m_part->addGeometry3D(line, Type, dcm::Local);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Base::Console().Message("Unsuported Curve Geometrie Type at selection \n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
if(s.ShapeType() == TopAbs_VERTEX) {
|
||||
TopoDS_Vertex v1 = TopoDS::Vertex(s);
|
||||
gp_Pnt point = BRep_Tool::Pnt(v1);
|
||||
geometry = m_part->addGeometry3D(point, Type, dcm::Local);
|
||||
|
||||
}
|
||||
else {
|
||||
Base::Console().Message("Unsuported Topologie Type at selection\n");
|
||||
return boost::shared_ptr< Geometry3D >();
|
||||
}
|
||||
};
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +1,73 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef Assembly_ItemPart_H
|
||||
#define Assembly_ItemPart_H
|
||||
|
||||
#include <App/PropertyLinks.h>
|
||||
#include "Item.h"
|
||||
#include "Solver/Solver.h"
|
||||
|
||||
|
||||
namespace Assembly
|
||||
{
|
||||
|
||||
class ItemAssembly;
|
||||
|
||||
class AssemblyExport ItemPart : public Assembly::Item
|
||||
{
|
||||
PROPERTY_HEADER(Assembly::ItemPart);
|
||||
|
||||
public:
|
||||
ItemPart();
|
||||
|
||||
App::PropertyLink Model;
|
||||
App::PropertyLinkList Annotation;
|
||||
|
||||
/** @name methods override feature */
|
||||
//@{
|
||||
/// recalculate the feature
|
||||
App::DocumentObjectExecReturn *execute(void);
|
||||
short mustExecute() const;
|
||||
// returns the type name of the view provider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "AssemblyGui::ViewProviderItemPart";
|
||||
}
|
||||
PyObject *getPyObject(void);
|
||||
//@}
|
||||
|
||||
virtual TopoDS_Shape getShape(void) const;
|
||||
|
||||
bool holdsObject(App::DocumentObject* obj) const;
|
||||
ItemAssembly* getParentAssembly();
|
||||
void ensureInitialisation();
|
||||
|
||||
boost::shared_ptr<Part3D> m_part;
|
||||
virtual boost::shared_ptr<Geometry3D> getGeometry3D(const char* Type );
|
||||
void setCalculatedPlacement( boost::shared_ptr<Part3D> part );
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
||||
|
||||
#endif // Assembly_ItemPart_H
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef Assembly_ItemPart_H
|
||||
#define Assembly_ItemPart_H
|
||||
|
||||
#include <App/PropertyLinks.h>
|
||||
#include "Item.h"
|
||||
#include "Solver/Solver.h"
|
||||
|
||||
|
||||
namespace Assembly
|
||||
{
|
||||
|
||||
class Product;
|
||||
|
||||
class AssemblyExport PartRef : public Assembly::Item
|
||||
{
|
||||
PROPERTY_HEADER(Assembly::PartRef);
|
||||
|
||||
public:
|
||||
PartRef();
|
||||
|
||||
App::PropertyLink Model;
|
||||
App::PropertyLinkList Annotation;
|
||||
|
||||
/** @name methods override feature */
|
||||
//@{
|
||||
/// recalculate the feature
|
||||
App::DocumentObjectExecReturn *execute(void);
|
||||
short mustExecute() const;
|
||||
// returns the type name of the view provider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "AssemblyGui::ViewProviderItemPart";
|
||||
}
|
||||
PyObject *getPyObject(void);
|
||||
//@}
|
||||
|
||||
virtual TopoDS_Shape getShape(void) const;
|
||||
|
||||
bool holdsObject(App::DocumentObject* obj) const;
|
||||
Product* getParentAssembly();
|
||||
void ensureInitialisation();
|
||||
|
||||
boost::shared_ptr<Part3D> m_part;
|
||||
virtual boost::shared_ptr<Geometry3D> getGeometry3D(const char* Type );
|
||||
void setCalculatedPlacement( boost::shared_ptr<Part3D> part );
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
||||
|
||||
#endif // Assembly_ItemPart_H
|
||||
@@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="ItemPy"
|
||||
Name="ItemPartPy"
|
||||
Twin="ItemPart"
|
||||
TwinPointer="ItemPart"
|
||||
Include="Mod/Assembly/App/ItemPart.h"
|
||||
Namespace="Assembly"
|
||||
FatherInclude="Mod/Assembly/App/ItemPy.h"
|
||||
FatherNamespace="Assembly">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
|
||||
<UserDocu>Base class of all objects in Assembly</UserDocu>
|
||||
</Documentation>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="ItemPy"
|
||||
Name="PartRefPy"
|
||||
Twin="PartRef"
|
||||
TwinPointer="PartRef"
|
||||
Include="Mod/Assembly/App/PartRef.h"
|
||||
Namespace="Assembly"
|
||||
FatherInclude="Mod/Assembly/App/ItemPy.h"
|
||||
FatherNamespace="Assembly">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
|
||||
<UserDocu>Base class of all objects in Assembly</UserDocu>
|
||||
</Documentation>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
34
src/Mod/Assembly/App/PartRefPyImp.cpp
Normal file
34
src/Mod/Assembly/App/PartRefPyImp.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "Mod/Assembly/App/PartRef.h"
|
||||
|
||||
// inclusion of the generated files (generated out of PartRefPy.xml)
|
||||
#include "PartRefPy.h"
|
||||
#include "PartRefPy.cpp"
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string PartRefPy::representation(void) const
|
||||
{
|
||||
return std::string("<PartRef object>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
PyObject *PartRefPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PartRefPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,346 +1,345 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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_
|
||||
# include <BRep_Builder.hxx>
|
||||
# include <TopoDS_Compound.hxx>
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#endif
|
||||
|
||||
#include <Base/Placement.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
|
||||
#include "ItemAssembly.h"
|
||||
#include "ItemPart.h"
|
||||
#include "ConstraintGroup.h"
|
||||
#include <ItemAssemblyPy.h>
|
||||
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
namespace Assembly {
|
||||
|
||||
|
||||
PROPERTY_SOURCE(Assembly::ItemAssembly, Assembly::Item)
|
||||
|
||||
ItemAssembly::ItemAssembly() {
|
||||
ADD_PROPERTY(Items,(0));
|
||||
ADD_PROPERTY(Annotations,(0));
|
||||
ADD_PROPERTY(Rigid,(true));
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
ADD_PROPERTY(ApplyAtFailure,(false));
|
||||
ADD_PROPERTY(Precision,(1e-6));
|
||||
ADD_PROPERTY(SaveState,(false));
|
||||
ADD_PROPERTY(Iterations,(5e3));
|
||||
ADD_PROPERTY(LogLevel, (long(1)));
|
||||
|
||||
std::vector<std::string> vec;
|
||||
vec.push_back("iteration");
|
||||
vec.push_back("solving");
|
||||
vec.push_back("manipulation");
|
||||
vec.push_back("information");
|
||||
vec.push_back("error");
|
||||
LogLevel.setEnumVector(vec);
|
||||
#endif
|
||||
}
|
||||
|
||||
short ItemAssembly::mustExecute() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn* ItemAssembly::execute(void) {
|
||||
|
||||
Base::Console().Message("Execute\n");
|
||||
|
||||
try {
|
||||
|
||||
//create a solver and init all child assemblys with subsolvers
|
||||
m_solver = boost::shared_ptr<Solver>(new Solver);
|
||||
m_downstream_placement = Base::Placement(Base::Vector3<double>(0,0,0), Base::Rotation());
|
||||
Base::Placement dummy;
|
||||
initSolver(boost::shared_ptr<Solver>(), dummy, false);
|
||||
initConstraints(boost::shared_ptr<Solver>());
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
|
||||
if(ApplyAtFailure.getValue())
|
||||
m_solver->setOption<dcm::solverfailure>(dcm::ApplyResults);
|
||||
else
|
||||
m_solver->setOption<dcm::solverfailure>(dcm::IgnoreResults);
|
||||
|
||||
m_solver->setOption<dcm::precision>(Precision.getValue());
|
||||
m_solver->setOption<dcm::iterations>(Iterations.getValue());
|
||||
|
||||
if(SaveState.getValue()) {
|
||||
|
||||
ofstream myfile;
|
||||
myfile.open("solverstate.txt");
|
||||
m_solver->saveState(myfile);
|
||||
myfile.close();
|
||||
};
|
||||
|
||||
m_solver->setLoggingFilter(dcm::severity >= (dcm::severity_level)LogLevel.getValue());
|
||||
|
||||
#endif
|
||||
|
||||
//solve the system
|
||||
m_solver->solve();
|
||||
}
|
||||
catch
|
||||
(boost::exception& e) {
|
||||
message.clear();
|
||||
message << "Solver exception " << *boost::get_error_info<boost::errinfo_errno>(e)
|
||||
<< "raised: " << boost::get_error_info<dcm::error_message>(e)->c_str() << std::endl;
|
||||
//throw Base::Exception(message.str().c_str());
|
||||
Base::Console().Error(message.str().c_str());
|
||||
}
|
||||
catch
|
||||
(std::exception& e) {
|
||||
message.clear();
|
||||
message << "Exception raised in assembly solver: " << e.what() << std::endl;
|
||||
//throw Base::Exception(message.str().c_str());
|
||||
Base::Console().Error(message.str().c_str());
|
||||
}
|
||||
catch(Standard_ConstructionError& e) {
|
||||
message.clear();
|
||||
message << "Construction Error raised in assembly solver during execution: ";
|
||||
message << e.GetMessageString()<< std::endl;
|
||||
Base::Console().Error(message.str().c_str());
|
||||
}
|
||||
catch
|
||||
(...) {
|
||||
message.clear();
|
||||
message << "Unknown Exception raised in assembly solver during execution" << std::endl;
|
||||
//throw Base::Exception(message.str().c_str());
|
||||
Base::Console().Error(message.str().c_str());
|
||||
};
|
||||
|
||||
this->touch();
|
||||
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
TopoDS_Shape ItemAssembly::getShape(void) const {
|
||||
std::vector<TopoDS_Shape> s;
|
||||
std::vector<App::DocumentObject*> obj = Items.getValues();
|
||||
|
||||
std::vector<App::DocumentObject*>::iterator it;
|
||||
|
||||
for(it = obj.begin(); it != obj.end(); ++it) {
|
||||
if((*it)->getTypeId().isDerivedFrom(Assembly::Item::getClassTypeId())) {
|
||||
TopoDS_Shape aShape = static_cast<Assembly::Item*>(*it)->getShape();
|
||||
|
||||
if(!aShape.IsNull())
|
||||
s.push_back(aShape);
|
||||
}
|
||||
}
|
||||
|
||||
if(s.size() > 0) {
|
||||
TopoDS_Compound aRes = TopoDS_Compound();
|
||||
BRep_Builder aBuilder = BRep_Builder();
|
||||
aBuilder.MakeCompound(aRes);
|
||||
|
||||
for(std::vector<TopoDS_Shape>::iterator it = s.begin(); it != s.end(); ++it) {
|
||||
|
||||
aBuilder.Add(aRes, *it);
|
||||
}
|
||||
|
||||
//if (aRes.IsNull())
|
||||
// throw Base::Exception("Resulting shape is invalid");
|
||||
return aRes;
|
||||
}
|
||||
|
||||
// set empty shape
|
||||
return TopoDS_Compound();
|
||||
|
||||
}
|
||||
|
||||
PyObject* ItemAssembly::getPyObject(void) {
|
||||
if(PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new ItemAssemblyPy(this),true);
|
||||
}
|
||||
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
bool ItemAssembly::isParentAssembly(ItemPart* part) {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId())
|
||||
if(*it == part)
|
||||
return true;
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemAssembly* ItemAssembly::getToplevelAssembly() {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = getInList();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId())
|
||||
return static_cast<Assembly::ItemAssembly*>(*it)->getToplevelAssembly();
|
||||
};
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
ItemAssembly* ItemAssembly::getParentAssembly(ItemPart* part) {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId()) {
|
||||
if(*it == part)
|
||||
return this;
|
||||
}
|
||||
else if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
|
||||
Assembly::ItemAssembly* assembly = static_cast<Assembly::ItemAssembly*>(*it)->getParentAssembly(part);
|
||||
|
||||
if(assembly)
|
||||
return assembly;
|
||||
}
|
||||
};
|
||||
|
||||
return (ItemAssembly*)NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::pair<ItemPart*, ItemAssembly*> ItemAssembly::getContainingPart(App::DocumentObject* obj, bool isTop) {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId()) {
|
||||
if(static_cast<Assembly::ItemPart*>(*it)->holdsObject(obj))
|
||||
return std::make_pair(static_cast<Assembly::ItemPart*>(*it), this);
|
||||
}
|
||||
else if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
|
||||
std::pair<ItemPart*, ItemAssembly*> part = static_cast<Assembly::ItemAssembly*>(*it)->getContainingPart(obj, false);
|
||||
|
||||
if(part.first && part.second) {
|
||||
|
||||
if(isTop)
|
||||
return part;
|
||||
else
|
||||
return std::make_pair(part.first, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return std::pair<ItemPart*, ItemAssembly*>(NULL, NULL);
|
||||
}
|
||||
|
||||
void ItemAssembly::initSolver(boost::shared_ptr<Solver> parent, Base::Placement& PL_downstream, bool stopped) {
|
||||
|
||||
if(parent) {
|
||||
if(Rigid.getValue() || stopped) {
|
||||
m_solver = parent->createSubsystem();
|
||||
m_solver->setTransformation(PL_downstream*this->Placement.getValue());
|
||||
stopped = true; //all below belongs to this rigid group
|
||||
|
||||
//connect the recalculated signal in case we need to update the placement
|
||||
m_solver->connectSignal<dcm::recalculated>(boost::bind(&ItemAssembly::finish, this, _1));
|
||||
}
|
||||
else {
|
||||
m_solver = parent;
|
||||
PL_downstream *= this->Placement.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
//we always need to store the downstream placement as we may be a subassembly in a
|
||||
//non-rigid subassembly
|
||||
m_downstream_placement = PL_downstream;
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
|
||||
static_cast<Assembly::ItemAssembly*>(*it)->initSolver(m_solver, PL_downstream, stopped);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void ItemAssembly::initConstraints(boost::shared_ptr<Solver> parent) {
|
||||
|
||||
|
||||
|
||||
//get the constraint group and init the constraints
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Annotations.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ConstraintGroup::getClassTypeId())
|
||||
static_cast<ConstraintGroup*>(*it)->init(this);
|
||||
};
|
||||
|
||||
// iterate down as long as a non-rigid subsystem exists
|
||||
const std::vector<App::DocumentObject*>& vector2 = Items.getValues();
|
||||
|
||||
for(iter it=vector2.begin(); it != vector2.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId())
|
||||
static_cast<Assembly::ItemAssembly*>(*it)->initConstraints(m_solver);
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
//the callback for the recalculated signal
|
||||
void ItemAssembly::finish(boost::shared_ptr<Solver> subsystem) {
|
||||
|
||||
//assert(subsystem == m_solver);
|
||||
Base::Placement p = m_solver->getTransformation<Base::Placement>();
|
||||
this->Placement.setValue(m_downstream_placement.inverse()*p);
|
||||
};
|
||||
|
||||
} //assembly
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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_
|
||||
# include <BRep_Builder.hxx>
|
||||
# include <TopoDS_Compound.hxx>
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#endif
|
||||
|
||||
#include <Base/Placement.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
|
||||
#include "Product.h"
|
||||
#include "PartRef.h"
|
||||
#include "ConstraintGroup.h"
|
||||
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
namespace Assembly {
|
||||
|
||||
|
||||
PROPERTY_SOURCE(Assembly::Product, Assembly::Item)
|
||||
|
||||
Product::Product() {
|
||||
ADD_PROPERTY(Items,(0));
|
||||
ADD_PROPERTY(Annotations,(0));
|
||||
ADD_PROPERTY(Rigid,(true));
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
ADD_PROPERTY(ApplyAtFailure,(false));
|
||||
ADD_PROPERTY(Precision,(1e-6));
|
||||
ADD_PROPERTY(SaveState,(false));
|
||||
ADD_PROPERTY(Iterations,(5e3));
|
||||
ADD_PROPERTY(LogLevel, (long(1)));
|
||||
|
||||
std::vector<std::string> vec;
|
||||
vec.push_back("iteration");
|
||||
vec.push_back("solving");
|
||||
vec.push_back("manipulation");
|
||||
vec.push_back("information");
|
||||
vec.push_back("error");
|
||||
LogLevel.setEnumVector(vec);
|
||||
#endif
|
||||
}
|
||||
|
||||
short Product::mustExecute() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn* Product::execute(void) {
|
||||
|
||||
Base::Console().Message("Execute\n");
|
||||
|
||||
try {
|
||||
|
||||
//create a solver and init all child assemblys with subsolvers
|
||||
m_solver = boost::shared_ptr<Solver>(new Solver);
|
||||
m_downstream_placement = Base::Placement(Base::Vector3<double>(0,0,0), Base::Rotation());
|
||||
Base::Placement dummy;
|
||||
initSolver(boost::shared_ptr<Solver>(), dummy, false);
|
||||
initConstraints(boost::shared_ptr<Solver>());
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
|
||||
if(ApplyAtFailure.getValue())
|
||||
m_solver->setOption<dcm::solverfailure>(dcm::ApplyResults);
|
||||
else
|
||||
m_solver->setOption<dcm::solverfailure>(dcm::IgnoreResults);
|
||||
|
||||
m_solver->setOption<dcm::precision>(Precision.getValue());
|
||||
m_solver->setOption<dcm::iterations>(Iterations.getValue());
|
||||
|
||||
if(SaveState.getValue()) {
|
||||
|
||||
ofstream myfile;
|
||||
myfile.open("solverstate.txt");
|
||||
m_solver->saveState(myfile);
|
||||
myfile.close();
|
||||
};
|
||||
|
||||
m_solver->setLoggingFilter(dcm::severity >= (dcm::severity_level)LogLevel.getValue());
|
||||
|
||||
#endif
|
||||
|
||||
//solve the system
|
||||
m_solver->solve();
|
||||
}
|
||||
catch
|
||||
(boost::exception& e) {
|
||||
message.clear();
|
||||
message << "Solver exception " << *boost::get_error_info<boost::errinfo_errno>(e)
|
||||
<< "raised: " << boost::get_error_info<dcm::error_message>(e)->c_str() << std::endl;
|
||||
//throw Base::Exception(message.str().c_str());
|
||||
Base::Console().Error(message.str().c_str());
|
||||
}
|
||||
catch
|
||||
(std::exception& e) {
|
||||
message.clear();
|
||||
message << "Exception raised in assembly solver: " << e.what() << std::endl;
|
||||
//throw Base::Exception(message.str().c_str());
|
||||
Base::Console().Error(message.str().c_str());
|
||||
}
|
||||
catch(Standard_ConstructionError& e) {
|
||||
message.clear();
|
||||
message << "Construction Error raised in assembly solver during execution: ";
|
||||
message << e.GetMessageString()<< std::endl;
|
||||
Base::Console().Error(message.str().c_str());
|
||||
}
|
||||
catch
|
||||
(...) {
|
||||
message.clear();
|
||||
message << "Unknown Exception raised in assembly solver during execution" << std::endl;
|
||||
//throw Base::Exception(message.str().c_str());
|
||||
Base::Console().Error(message.str().c_str());
|
||||
};
|
||||
|
||||
this->touch();
|
||||
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
TopoDS_Shape Product::getShape(void) const {
|
||||
std::vector<TopoDS_Shape> s;
|
||||
std::vector<App::DocumentObject*> obj = Items.getValues();
|
||||
|
||||
std::vector<App::DocumentObject*>::iterator it;
|
||||
|
||||
for(it = obj.begin(); it != obj.end(); ++it) {
|
||||
if((*it)->getTypeId().isDerivedFrom(Assembly::Item::getClassTypeId())) {
|
||||
TopoDS_Shape aShape = static_cast<Assembly::Item*>(*it)->getShape();
|
||||
|
||||
if(!aShape.IsNull())
|
||||
s.push_back(aShape);
|
||||
}
|
||||
}
|
||||
|
||||
if(s.size() > 0) {
|
||||
TopoDS_Compound aRes = TopoDS_Compound();
|
||||
BRep_Builder aBuilder = BRep_Builder();
|
||||
aBuilder.MakeCompound(aRes);
|
||||
|
||||
for(std::vector<TopoDS_Shape>::iterator it = s.begin(); it != s.end(); ++it) {
|
||||
|
||||
aBuilder.Add(aRes, *it);
|
||||
}
|
||||
|
||||
//if (aRes.IsNull())
|
||||
// throw Base::Exception("Resulting shape is invalid");
|
||||
return aRes;
|
||||
}
|
||||
|
||||
// set empty shape
|
||||
return TopoDS_Compound();
|
||||
|
||||
}
|
||||
|
||||
//PyObject* Product::getPyObject(void) {
|
||||
// if(PythonObject.is(Py::_None())) {
|
||||
// // ref counter is set to 1
|
||||
// PythonObject = Py::Object(new ProductPy(this),true);
|
||||
// }
|
||||
//
|
||||
// return Py::new_reference_to(PythonObject);
|
||||
//}
|
||||
|
||||
bool Product::isParentAssembly(PartRef* part) {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::PartRef::getClassTypeId())
|
||||
if(*it == part)
|
||||
return true;
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Product* Product::getToplevelAssembly() {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = getInList();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::Product::getClassTypeId())
|
||||
return static_cast<Assembly::Product*>(*it)->getToplevelAssembly();
|
||||
};
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Product* Product::getParentAssembly(PartRef* part) {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::PartRef::getClassTypeId()) {
|
||||
if(*it == part)
|
||||
return this;
|
||||
}
|
||||
else if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
|
||||
|
||||
Assembly::Product* assembly = static_cast<Assembly::Product*>(*it)->getParentAssembly(part);
|
||||
|
||||
if(assembly)
|
||||
return assembly;
|
||||
}
|
||||
};
|
||||
|
||||
return (Product*)NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::pair<PartRef*, Product*> Product::getContainingPart(App::DocumentObject* obj, bool isTop) {
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::PartRef::getClassTypeId()) {
|
||||
if(static_cast<Assembly::PartRef*>(*it)->holdsObject(obj))
|
||||
return std::make_pair(static_cast<Assembly::PartRef*>(*it), this);
|
||||
}
|
||||
else if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
|
||||
|
||||
std::pair<PartRef*, Product*> part = static_cast<Assembly::Product*>(*it)->getContainingPart(obj, false);
|
||||
|
||||
if(part.first && part.second) {
|
||||
|
||||
if(isTop)
|
||||
return part;
|
||||
else
|
||||
return std::make_pair(part.first, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return std::pair<PartRef*, Product*>(NULL, NULL);
|
||||
}
|
||||
|
||||
void Product::initSolver(boost::shared_ptr<Solver> parent, Base::Placement& PL_downstream, bool stopped) {
|
||||
|
||||
if(parent) {
|
||||
if(Rigid.getValue() || stopped) {
|
||||
m_solver = parent->createSubsystem();
|
||||
m_solver->setTransformation(PL_downstream*this->Placement.getValue());
|
||||
stopped = true; //all below belongs to this rigid group
|
||||
|
||||
//connect the recalculated signal in case we need to update the placement
|
||||
m_solver->connectSignal<dcm::recalculated>(boost::bind(&Product::finish, this, _1));
|
||||
}
|
||||
else {
|
||||
m_solver = parent;
|
||||
PL_downstream *= this->Placement.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
//we always need to store the downstream placement as we may be a subassembly in a
|
||||
//non-rigid subassembly
|
||||
m_downstream_placement = PL_downstream;
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
const std::vector<App::DocumentObject*>& vector = Items.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
|
||||
|
||||
static_cast<Assembly::Product*>(*it)->initSolver(m_solver, PL_downstream, stopped);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void Product::initConstraints(boost::shared_ptr<Solver> parent) {
|
||||
|
||||
|
||||
|
||||
//get the constraint group and init the constraints
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
const std::vector<App::DocumentObject*>& vector = Annotations.getValues();
|
||||
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ConstraintGroup::getClassTypeId())
|
||||
static_cast<ConstraintGroup*>(*it)->init(this);
|
||||
};
|
||||
|
||||
// iterate down as long as a non-rigid subsystem exists
|
||||
const std::vector<App::DocumentObject*>& vector2 = Items.getValues();
|
||||
|
||||
for(iter it=vector2.begin(); it != vector2.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::Product::getClassTypeId())
|
||||
static_cast<Assembly::Product*>(*it)->initConstraints(m_solver);
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
//the callback for the recalculated signal
|
||||
void Product::finish(boost::shared_ptr<Solver> subsystem) {
|
||||
|
||||
//assert(subsystem == m_solver);
|
||||
Base::Placement p = m_solver->getTransformation<Base::Placement>();
|
||||
this->Placement.setValue(m_downstream_placement.inverse()*p);
|
||||
};
|
||||
|
||||
} //assembly
|
||||
|
||||
|
||||
|
||||
@@ -1,102 +1,102 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef ItemAssembly_ItemAssembly_H
|
||||
#define ItemAssembly_ItemAssembly_H
|
||||
|
||||
#include <App/PropertyStandard.h>
|
||||
|
||||
#include "Item.h"
|
||||
#include "Solver/Solver.h"
|
||||
|
||||
namespace Assembly
|
||||
{
|
||||
|
||||
class ItemPart;
|
||||
|
||||
class AssemblyExport ItemAssembly : public Assembly::Item
|
||||
{
|
||||
PROPERTY_HEADER(Assembly::ItemAssembly);
|
||||
|
||||
public:
|
||||
ItemAssembly();
|
||||
|
||||
App::PropertyLinkList Items;
|
||||
App::PropertyLinkList Annotations;
|
||||
App::PropertyBool Rigid;
|
||||
|
||||
/** @name methods override feature */
|
||||
//@{
|
||||
/// recalculate the feature
|
||||
App::DocumentObjectExecReturn *execute(void);
|
||||
short mustExecute() const;
|
||||
/// returns the type name of the view provider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "AssemblyGui::ViewProviderItemAssembly";
|
||||
}
|
||||
PyObject *getPyObject(void);
|
||||
//@}
|
||||
|
||||
virtual TopoDS_Shape getShape(void) const;
|
||||
|
||||
bool isParentAssembly(ItemPart* part);
|
||||
ItemAssembly* getToplevelAssembly();
|
||||
ItemAssembly* getParentAssembly(ItemPart* part);
|
||||
|
||||
//returns the ItemPart which holds the given document object and the ItemAssembly, which holds
|
||||
//the this part and is a direct children of this ItemAssembly. The returned ItemAssembly is therefore
|
||||
//the "TopLevel" Assembly holding the part of all children of this assembly. If this assembly holds
|
||||
//the children directly, without any subassembly, the returned ItemAssembly is this.
|
||||
std::pair< ItemPart*, ItemAssembly* > getContainingPart(App::DocumentObject* obj, bool isTop=true);
|
||||
|
||||
//create a new solver for this assembly and initalise all downstream itemassemblys either with a
|
||||
//subsystem (if they are rigid) or with this solver plus the downstream placement
|
||||
void initSolver(boost::shared_ptr<Solver> parent, Base::Placement& pl_downstream, bool stopped);
|
||||
|
||||
//initialise the oen constraint group and go downstream as long as non-rigid itemassemblys exist,
|
||||
//which need to be initialised too
|
||||
void initConstraints(boost::shared_ptr<Solver> parent);
|
||||
|
||||
//read the downstream itemassemblys and set their placement to the propertyplacement
|
||||
void finish(boost::shared_ptr<Solver> subsystem);
|
||||
|
||||
boost::shared_ptr<Solver> m_solver;
|
||||
Base::Placement m_downstream_placement;
|
||||
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
App::PropertyBool ApplyAtFailure;
|
||||
App::PropertyFloat Precision;
|
||||
App::PropertyBool SaveState;
|
||||
App::PropertyInteger Iterations;
|
||||
App::PropertyEnumeration LogLevel;
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::stringstream message;
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
||||
|
||||
#endif // Assembly_ItemAssembly_H
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef ItemAssembly_ItemAssembly_H
|
||||
#define ItemAssembly_ItemAssembly_H
|
||||
|
||||
#include <App/PropertyStandard.h>
|
||||
|
||||
#include "Item.h"
|
||||
#include "Solver/Solver.h"
|
||||
|
||||
namespace Assembly
|
||||
{
|
||||
|
||||
class PartRef;
|
||||
|
||||
class AssemblyExport Product : public Assembly::Item
|
||||
{
|
||||
PROPERTY_HEADER(Assembly::Product);
|
||||
|
||||
public:
|
||||
Product();
|
||||
|
||||
App::PropertyLinkList Items;
|
||||
App::PropertyLinkList Annotations;
|
||||
App::PropertyBool Rigid;
|
||||
|
||||
/** @name methods override feature */
|
||||
//@{
|
||||
/// recalculate the feature
|
||||
App::DocumentObjectExecReturn *execute(void);
|
||||
short mustExecute() const;
|
||||
/// returns the type name of the view provider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "AssemblyGui::ViewProviderProduct";
|
||||
}
|
||||
//PyObject *getPyObject(void);
|
||||
//@}
|
||||
|
||||
virtual TopoDS_Shape getShape(void) const;
|
||||
|
||||
bool isParentAssembly(PartRef* part);
|
||||
Product* getToplevelAssembly();
|
||||
Product* getParentAssembly(PartRef* part);
|
||||
|
||||
//returns the PartRef which holds the given document object and the Product, which holds
|
||||
//the this part and is a direct children of this Product. The returned Product is therefore
|
||||
//the "TopLevel" Assembly holding the part of all children of this assembly. If this assembly holds
|
||||
//the children directly, without any subassembly, the returned Product is this.
|
||||
std::pair< PartRef*, Product* > getContainingPart(App::DocumentObject* obj, bool isTop=true);
|
||||
|
||||
//create a new solver for this assembly and initalise all downstream itemassemblys either with a
|
||||
//subsystem (if they are rigid) or with this solver plus the downstream placement
|
||||
void initSolver(boost::shared_ptr<Solver> parent, Base::Placement& pl_downstream, bool stopped);
|
||||
|
||||
//initialise the oen constraint group and go downstream as long as non-rigid itemassemblys exist,
|
||||
//which need to be initialised too
|
||||
void initConstraints(boost::shared_ptr<Solver> parent);
|
||||
|
||||
//read the downstream itemassemblys and set their placement to the propertyplacement
|
||||
void finish(boost::shared_ptr<Solver> subsystem);
|
||||
|
||||
boost::shared_ptr<Solver> m_solver;
|
||||
Base::Placement m_downstream_placement;
|
||||
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
App::PropertyBool ApplyAtFailure;
|
||||
App::PropertyFloat Precision;
|
||||
App::PropertyBool SaveState;
|
||||
App::PropertyInteger Iterations;
|
||||
App::PropertyEnumeration LogLevel;
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::stringstream message;
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
||||
|
||||
#endif // Assembly_ItemAssembly_H
|
||||
76
src/Mod/Assembly/App/ProductRef.cpp
Normal file
76
src/Mod/Assembly/App/ProductRef.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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_
|
||||
# include <BRep_Builder.hxx>
|
||||
# include <TopoDS_Compound.hxx>
|
||||
#include <boost/exception/get_error_info.hpp>
|
||||
#endif
|
||||
|
||||
#include <Base/Placement.h>
|
||||
#include <Base/Console.h>
|
||||
#include <App/Part.h>
|
||||
|
||||
#include "ProductRef.h"
|
||||
#include "PartRef.h"
|
||||
#include "ConstraintGroup.h"
|
||||
#include "ProductRefPy.h"
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
namespace Assembly {
|
||||
|
||||
|
||||
PROPERTY_SOURCE(Assembly::ProductRef, Assembly::Item)
|
||||
|
||||
ProductRef::ProductRef() {
|
||||
ADD_PROPERTY(Items,(0));
|
||||
ADD_PROPERTY(Annotations,(0));
|
||||
ADD_PROPERTY(Rigid,(true));
|
||||
|
||||
}
|
||||
|
||||
short ProductRef::mustExecute() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn* ProductRef::execute(void)
|
||||
{
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
PyObject* ProductRef::getPyObject(void) {
|
||||
if(PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new ProductRefPy(this),true);
|
||||
}
|
||||
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
|
||||
|
||||
} //assembly
|
||||
|
||||
|
||||
|
||||
71
src/Mod/Assembly/App/ProductRef.h
Normal file
71
src/Mod/Assembly/App/ProductRef.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef ProductRef_ProductRef_H
|
||||
#define ProductRef_ProductRef_H
|
||||
|
||||
#include <App/PropertyStandard.h>
|
||||
|
||||
#include "Item.h"
|
||||
#include "PartRef.h"
|
||||
#include "Solver/Solver.h"
|
||||
|
||||
namespace Assembly
|
||||
{
|
||||
|
||||
class ItemPart;
|
||||
|
||||
class AssemblyExport ProductRef : public Assembly::Item
|
||||
{
|
||||
PROPERTY_HEADER(Assembly::ProductRef);
|
||||
|
||||
public:
|
||||
ProductRef();
|
||||
|
||||
App::PropertyLinkList Items;
|
||||
App::PropertyLinkList Annotations;
|
||||
App::PropertyBool Rigid;
|
||||
|
||||
/** @name methods override feature */
|
||||
//@{
|
||||
/// recalculate the feature
|
||||
App::DocumentObjectExecReturn *execute(void);
|
||||
short mustExecute() const;
|
||||
/// returns the type name of the view provider
|
||||
const char* getViewProviderName(void) const {
|
||||
return "AssemblyGui::ViewProviderProductRef";
|
||||
}
|
||||
PyObject *getPyObject(void);
|
||||
//@}
|
||||
|
||||
virtual TopoDS_Shape getShape(void) const {return TopoDS_Shape();}
|
||||
|
||||
std::pair< PartRef*, Product* > getContainingPart(App::DocumentObject* obj, bool isTop=true){ return std::pair<PartRef*, Product*>(NULL, NULL);}
|
||||
|
||||
|
||||
};
|
||||
|
||||
} //namespace Assembly
|
||||
|
||||
|
||||
#endif // Assembly_ProductRef_H
|
||||
@@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="ItemPy"
|
||||
Name="ItemAssemblyPy"
|
||||
Twin="ItemAssembly"
|
||||
TwinPointer="ItemAssembly"
|
||||
Include="Mod/Assembly/App/ItemAssembly.h"
|
||||
Namespace="Assembly"
|
||||
FatherInclude="Mod/Assembly/App/ItemPy.h"
|
||||
FatherNamespace="Assembly">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
|
||||
<UserDocu>Base class of all objects in Assembly</UserDocu>
|
||||
</Documentation>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="ItemPy"
|
||||
Name="ProductRefPy"
|
||||
Twin="ProductRef"
|
||||
TwinPointer="ProductRef"
|
||||
Include="Mod/Assembly/App/ProductRef.h"
|
||||
Namespace="Assembly"
|
||||
FatherInclude="Mod/Assembly/App/ItemPy.h"
|
||||
FatherNamespace="Assembly">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
|
||||
<UserDocu>Base class of all objects in Assembly</UserDocu>
|
||||
</Documentation>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
28
src/Mod/Assembly/App/ProductRefPyImp.cpp
Normal file
28
src/Mod/Assembly/App/ProductRefPyImp.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "Mod/Assembly/App/ProductRef.h"
|
||||
|
||||
// inclusion of the generated files (generated out of ProductPy.xml)
|
||||
#include "ProductRefPy.h"
|
||||
#include "ProductRefPy.cpp"
|
||||
#include <PartRefPy.h>
|
||||
|
||||
using namespace Assembly;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string ProductRefPy::representation(void) const
|
||||
{
|
||||
return std::string("<ProductRef object>");
|
||||
}
|
||||
|
||||
|
||||
PyObject *ProductRefPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ProductRefPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -33,12 +33,14 @@
|
||||
#include "Workbench.h"
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include "ViewProviderPart.h"
|
||||
#include "ViewProviderAssembly.h"
|
||||
#include "ViewProviderPartRef.h"
|
||||
#include "ViewProviderProduct.h"
|
||||
#include "ViewProviderProductRef.h"
|
||||
#include "ViewProviderConstraintGroup.h"
|
||||
#include "ViewProviderConstraint.h"
|
||||
|
||||
#include <Mod/Assembly/App/ItemAssembly.h>
|
||||
#include <Mod/Assembly/App/Product.h>
|
||||
#include <Mod/Assembly/App/ProductRef.h>
|
||||
|
||||
//#include "resources/qrc_Assembly.cpp"
|
||||
|
||||
@@ -81,8 +83,9 @@ void AssemblyGuiExport initAssemblyGui()
|
||||
AssemblyGui::Workbench::init();
|
||||
|
||||
AssemblyGui::ViewProviderItem ::init();
|
||||
AssemblyGui::ViewProviderItemPart ::init();
|
||||
AssemblyGui::ViewProviderItemAssembly::init();
|
||||
AssemblyGui::ViewProviderPartRef ::init();
|
||||
AssemblyGui::ViewProviderProduct ::init();
|
||||
AssemblyGui::ViewProviderProductRef ::init();
|
||||
|
||||
AssemblyGui::ViewProviderConstraintGroup::init();
|
||||
AssemblyGui::ViewProviderConstraint::init();
|
||||
|
||||
@@ -45,10 +45,12 @@ qt4_wrap_ui(AssemblyGui_UIC_HDRS ${AssemblyGui_UIC_SRCS})
|
||||
SET(AssemblyGuiViewProvider_SRCS
|
||||
ViewProvider.cpp
|
||||
ViewProvider.h
|
||||
ViewProviderPart.cpp
|
||||
ViewProviderPart.h
|
||||
ViewProviderAssembly.cpp
|
||||
ViewProviderAssembly.h
|
||||
ViewProviderPartRef.cpp
|
||||
ViewProviderPartRef.h
|
||||
ViewProviderProduct.cpp
|
||||
ViewProviderProduct.h
|
||||
ViewProviderProductRef.cpp
|
||||
ViewProviderProductRef.h
|
||||
ViewProviderConstraint.cpp
|
||||
ViewProviderConstraint.h
|
||||
ViewProviderConstraintGroup.cpp
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
|
||||
#include <Mod/Assembly/App/ItemAssembly.h>
|
||||
#include <Mod/Assembly/App/Product.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
@@ -60,14 +60,14 @@ CmdAssemblyAddNewPart::CmdAssemblyAddNewPart()
|
||||
|
||||
void CmdAssemblyAddNewPart::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *dest = 0;
|
||||
Assembly::Product *dest = 0;
|
||||
|
||||
unsigned int n = getSelection().countObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
|
||||
unsigned int n = getSelection().countObjectsOfType(Assembly::Product::getClassTypeId());
|
||||
if (n >= 1) {
|
||||
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
|
||||
dest = dynamic_cast<Assembly::ItemAssembly*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::ItemAssembly*>(ActiveAsmObject);
|
||||
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::Product::getClassTypeId());
|
||||
dest = dynamic_cast<Assembly::Product*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::Product*>(ActiveAsmObject);
|
||||
}else {
|
||||
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active or selected assembly"),
|
||||
@@ -127,19 +127,19 @@ CmdAssemblyAddNewComponent::CmdAssemblyAddNewComponent()
|
||||
|
||||
void CmdAssemblyAddNewComponent::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *dest = 0;
|
||||
Assembly::Product *dest = 0;
|
||||
|
||||
unsigned int n = getSelection().countObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
|
||||
unsigned int n = getSelection().countObjectsOfType(Assembly::Product::getClassTypeId());
|
||||
if (n >= 1) {
|
||||
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
|
||||
dest = dynamic_cast<Assembly::ItemAssembly*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::ItemAssembly*>(ActiveAsmObject);
|
||||
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::Product::getClassTypeId());
|
||||
dest = dynamic_cast<Assembly::Product*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::Product*>(ActiveAsmObject);
|
||||
}
|
||||
|
||||
openCommand("Insert Component");
|
||||
std::string CompName = getUniqueObjectName("Assembly");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ItemAssembly','%s')",CompName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::Product','%s')",CompName.c_str());
|
||||
if(dest){
|
||||
std::string fatherName = dest->getNameInDocument();
|
||||
doCommand(Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s] ",fatherName.c_str(),fatherName.c_str(),CompName.c_str());
|
||||
@@ -165,14 +165,14 @@ CmdAssemblyAddExistingComponent::CmdAssemblyAddExistingComponent()
|
||||
|
||||
void CmdAssemblyAddExistingComponent::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *dest = 0;
|
||||
Assembly::Product *dest = 0;
|
||||
|
||||
unsigned int n = getSelection().countObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
|
||||
unsigned int n = getSelection().countObjectsOfType(Assembly::Product::getClassTypeId());
|
||||
if (n >= 1) {
|
||||
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
|
||||
dest = dynamic_cast<Assembly::ItemAssembly*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::ItemAssembly*>(ActiveAsmObject);
|
||||
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::Product::getClassTypeId());
|
||||
dest = dynamic_cast<Assembly::Product*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::Product*>(ActiveAsmObject);
|
||||
}else {
|
||||
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active or selected assembly"),
|
||||
@@ -228,14 +228,14 @@ CmdAssemblyImport::CmdAssemblyImport()
|
||||
|
||||
void CmdAssemblyImport::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *dest = 0;
|
||||
Assembly::Product *dest = 0;
|
||||
|
||||
unsigned int n = getSelection().countObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
|
||||
unsigned int n = getSelection().countObjectsOfType(Assembly::Product::getClassTypeId());
|
||||
if (n >= 1) {
|
||||
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
|
||||
dest = dynamic_cast<Assembly::ItemAssembly*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::ItemAssembly*>(ActiveAsmObject);
|
||||
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::Product::getClassTypeId());
|
||||
dest = dynamic_cast<Assembly::Product*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::Product*>(ActiveAsmObject);
|
||||
}
|
||||
|
||||
// asking for file name (only step at the moment)
|
||||
|
||||
@@ -36,8 +36,9 @@
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Document.h>
|
||||
|
||||
#include <Mod/Assembly/App/ItemAssembly.h>
|
||||
#include <Mod/Assembly/App/ItemPart.h>
|
||||
#include <Mod/Assembly/App/Product.h>
|
||||
#include <Mod/Assembly/App/ProductRef.h>
|
||||
#include <Mod/Assembly/App/PartRef.h>
|
||||
#include <Mod/Assembly/App/ConstraintGroup.h>
|
||||
#include <Mod/Assembly/Gui/TaskDlgAssemblyConstraints.h>
|
||||
|
||||
@@ -48,7 +49,7 @@ extern Assembly::Item* ActiveAsmObject;
|
||||
|
||||
// Helper methods ===========================================================
|
||||
|
||||
Assembly::ConstraintGroup* getConstraintGroup(Assembly::ItemAssembly* Asm)
|
||||
Assembly::ConstraintGroup* getConstraintGroup(Assembly::ProductRef* Asm)
|
||||
{
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
@@ -64,15 +65,15 @@ Assembly::ConstraintGroup* getConstraintGroup(Assembly::ItemAssembly* Asm)
|
||||
return ConstGrp;
|
||||
}
|
||||
|
||||
bool getConstraintPrerequisits(Assembly::ItemAssembly** Asm, Assembly::ConstraintGroup** ConstGrp)
|
||||
bool getConstraintPrerequisits(Assembly::ProductRef** Asm, Assembly::ConstraintGroup** ConstGrp)
|
||||
{
|
||||
if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
|
||||
if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ProductRef::getClassTypeId())) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Assembly"),
|
||||
QObject::tr("You need a active (blue) Assembly to insert a Constraint. Please create a new one or make one active (double click)."));
|
||||
return true;
|
||||
}
|
||||
|
||||
*Asm = static_cast<Assembly::ItemAssembly*>(ActiveAsmObject);
|
||||
*Asm = static_cast<Assembly::ProductRef*>(ActiveAsmObject);
|
||||
|
||||
// find the Constraint group of the active Assembly
|
||||
*ConstGrp = getConstraintGroup(*Asm);
|
||||
@@ -96,7 +97,7 @@ bool getConstraintPrerequisits(Assembly::ItemAssembly** Asm, Assembly::Constrain
|
||||
|
||||
}
|
||||
|
||||
std::string asSubLinkString(Assembly::ItemPart* part, std::string element)
|
||||
std::string asSubLinkString(Assembly::PartRef* part, std::string element)
|
||||
{
|
||||
std::string buf;
|
||||
buf += "(App.ActiveDocument.";
|
||||
@@ -126,67 +127,67 @@ CmdAssemblyConstraint::CmdAssemblyConstraint()
|
||||
|
||||
void CmdAssemblyConstraint::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
//Assembly::ProductRef* Asm = 0;
|
||||
//Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
//// retrive the standard objects needed
|
||||
//if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
// return;
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
//std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() > 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Only two geometries supported by constraints"));
|
||||
return;
|
||||
};
|
||||
//if(objs.size() > 2) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("Only two geometries supported by constraints"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
std::stringstream typestr1, typestr2;
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1, part2;
|
||||
if(objs.size()>=1) {
|
||||
part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
typestr1 << "App.activeDocument().ActiveObject.First = " << asSubLinkString(part1.first, objs[0].getSubNames()[0]);
|
||||
}
|
||||
if(objs.size()>=2) {
|
||||
part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
typestr2 << "App.activeDocument().ActiveObject.Second = " << asSubLinkString(part2.first, objs[1].getSubNames()[0]);
|
||||
}
|
||||
//std::stringstream typestr1, typestr2;
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part1, part2;
|
||||
//if(objs.size()>=1) {
|
||||
// part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
// //checking the parts is enough, both or non!
|
||||
// if(!part1.first) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
// return;
|
||||
// };
|
||||
// typestr1 << "App.activeDocument().ActiveObject.First = " << asSubLinkString(part1.first, objs[0].getSubNames()[0]);
|
||||
//}
|
||||
//if(objs.size()>=2) {
|
||||
// part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
// //checking the parts is enough, both or non!
|
||||
// if(!part2.first) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
// return;
|
||||
// };
|
||||
// typestr2 << "App.activeDocument().ActiveObject.Second = " << asSubLinkString(part2.first, objs[1].getSubNames()[0]);
|
||||
//}
|
||||
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if(part1.first && part2.first && (part1.second == part2.second) && part1.second != Asm) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
////check if this is the right place for the constraint
|
||||
//if(part1.first && part2.first && (part1.second == part2.second) && part1.second != Asm) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
// return;
|
||||
//}
|
||||
|
||||
openCommand("Insert Constraint Distance");
|
||||
std::string ConstrName = getUniqueObjectName("Constraint");
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
if(objs.size()>=1)
|
||||
doCommand(Doc, typestr1.str().c_str());
|
||||
if(objs.size()>=2)
|
||||
doCommand(Doc, typestr2.str().c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
//openCommand("Insert Constraint Distance");
|
||||
//std::string ConstrName = getUniqueObjectName("Constraint");
|
||||
//doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
//if(objs.size()>=1)
|
||||
// doCommand(Doc, typestr1.str().c_str());
|
||||
//if(objs.size()>=2)
|
||||
// doCommand(Doc, typestr2.str().c_str());
|
||||
//doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
//updateActive();
|
||||
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
////updateActive();
|
||||
//doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
|
||||
commitCommand();
|
||||
//commitCommand();
|
||||
|
||||
Gui::Selection().clearCompleteSelection();
|
||||
//Gui::Selection().clearCompleteSelection();
|
||||
}
|
||||
|
||||
|
||||
@@ -210,52 +211,52 @@ CmdAssemblyConstraintDistance::CmdAssemblyConstraintDistance()
|
||||
|
||||
void CmdAssemblyConstraintDistance::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
//Assembly::ProductRef* Asm = 0;
|
||||
//Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
//// retrive the standard objects needed
|
||||
//if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
// return;
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
//std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
//if(objs.size() != 2) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("You need to select two geometries on two different parts"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
////checking the parts is enough, both or non!
|
||||
//if(!part1.first || !part2.first) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if((part1.second == part2.second) && part1.second != Asm) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
////check if this is the right place for the constraint
|
||||
//if((part1.second == part2.second) && part1.second != Asm) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
// return;
|
||||
//}
|
||||
|
||||
openCommand("Insert Constraint Distance");
|
||||
std::string ConstrName = getUniqueObjectName("Distance");
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Distance'");
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
//openCommand("Insert Constraint Distance");
|
||||
//std::string ConstrName = getUniqueObjectName("Distance");
|
||||
//doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Distance'");
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
//updateActive();
|
||||
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
////updateActive();
|
||||
//doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
|
||||
commitCommand();
|
||||
//commitCommand();
|
||||
|
||||
Gui::Selection().clearCompleteSelection();
|
||||
//Gui::Selection().clearCompleteSelection();
|
||||
}
|
||||
|
||||
/******************************************************************************************/
|
||||
@@ -277,48 +278,48 @@ CmdAssemblyConstraintFix::CmdAssemblyConstraintFix()
|
||||
|
||||
void CmdAssemblyConstraintFix::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
//Assembly::ProductRef* Asm = 0;
|
||||
//Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
//// retrive the standard objects needed
|
||||
//if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
// return;
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
//std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 1) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select one part only"));
|
||||
return;
|
||||
};
|
||||
//if(objs.size() != 1) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("You need to select one part only"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part = Asm->getContainingPart(objs[0].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part = Asm->getContainingPart(objs[0].getObject());
|
||||
|
||||
if(!part.first) {
|
||||
Base::Console().Message("The selected part need to belong to the active assembly\n");
|
||||
return;
|
||||
};
|
||||
//if(!part.first) {
|
||||
// Base::Console().Message("The selected part need to belong to the active assembly\n");
|
||||
// return;
|
||||
//};
|
||||
|
||||
if(part.second != Asm) {
|
||||
Base::Console().Message("The selected part need belongs to an subproduct, please add constraint there\n");
|
||||
return;
|
||||
}
|
||||
//if(part.second != Asm) {
|
||||
// Base::Console().Message("The selected part need belongs to an subproduct, please add constraint there\n");
|
||||
// return;
|
||||
//}
|
||||
|
||||
openCommand("Insert Constraint Fix");
|
||||
//openCommand("Insert Constraint Fix");
|
||||
|
||||
std::string ConstrName = getUniqueObjectName("Fix");
|
||||
//std::string ConstrName = getUniqueObjectName("Fix");
|
||||
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Fix'");
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
//doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Fix'");
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part.first, objs[0].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
//updateActive();
|
||||
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
////updateActive();
|
||||
//doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
|
||||
commitCommand();
|
||||
|
||||
Gui::Selection().clearCompleteSelection();
|
||||
//commitCommand();
|
||||
//
|
||||
//Gui::Selection().clearCompleteSelection();
|
||||
}
|
||||
|
||||
|
||||
@@ -342,52 +343,52 @@ CmdAssemblyConstraintAngle::CmdAssemblyConstraintAngle()
|
||||
|
||||
void CmdAssemblyConstraintAngle::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
//Assembly::ProductRef* Asm = 0;
|
||||
//Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
//// retrive the standard objects needed
|
||||
//if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
// return;
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
//std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
//if(objs.size() != 2) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("You need to select two geometries on two different parts"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
////checking the parts is enough, both or non!
|
||||
//if(!part1.first || !part2.first) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if(((part1.second == part2.second) && part1.second != Asm) && part1.second != Asm) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
////check if this is the right place for the constraint
|
||||
//if(((part1.second == part2.second) && part1.second != Asm) && part1.second != Asm) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
// return;
|
||||
//}
|
||||
|
||||
openCommand("Insert Constraint Angle");
|
||||
std::string ConstrName = getUniqueObjectName("Angle");
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Angle'");
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
//openCommand("Insert Constraint Angle");
|
||||
//std::string ConstrName = getUniqueObjectName("Angle");
|
||||
//doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Angle'");
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
//updateActive();
|
||||
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
////updateActive();
|
||||
//doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
|
||||
commitCommand();
|
||||
//commitCommand();
|
||||
|
||||
Gui::Selection().clearCompleteSelection();
|
||||
//Gui::Selection().clearCompleteSelection();
|
||||
}
|
||||
|
||||
|
||||
@@ -411,52 +412,52 @@ CmdAssemblyConstraintOrientation::CmdAssemblyConstraintOrientation()
|
||||
|
||||
void CmdAssemblyConstraintOrientation::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
//Assembly::ProductRef* Asm = 0;
|
||||
//Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
//// retrive the standard objects needed
|
||||
//if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
// return;
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
//std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
//if(objs.size() != 2) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("You need to select two geometries on two different parts"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
////checking the parts is enough, both or non!
|
||||
//if(!part1.first || !part2.first) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if((part1.second == part2.second) && part1.second != Asm) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
////check if this is the right place for the constraint
|
||||
//if((part1.second == part2.second) && part1.second != Asm) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
// return;
|
||||
//}
|
||||
|
||||
openCommand("Insert Constraint Orientation");
|
||||
std::string ConstrName = getUniqueObjectName("Orientation");
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Orientation'");
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
//openCommand("Insert Constraint Orientation");
|
||||
//std::string ConstrName = getUniqueObjectName("Orientation");
|
||||
//doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Orientation'");
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
//updateActive();
|
||||
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
////updateActive();
|
||||
//doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
|
||||
commitCommand();
|
||||
|
||||
Gui::Selection().clearCompleteSelection();
|
||||
//commitCommand();
|
||||
//
|
||||
//Gui::Selection().clearCompleteSelection();
|
||||
}
|
||||
|
||||
/******************************************************************************************/
|
||||
@@ -479,52 +480,52 @@ CmdAssemblyConstraintCoincidence::CmdAssemblyConstraintCoincidence()
|
||||
|
||||
void CmdAssemblyConstraintCoincidence::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
//Assembly::ProductRef* Asm = 0;
|
||||
//Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
//// retrive the standard objects needed
|
||||
//if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
// return;
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
//std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
//if(objs.size() != 2) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("You need to select two geometries on two different parts"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
////checking the parts is enough, both or non!
|
||||
//if(!part1.first || !part2.first) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if((part1.second == part2.second) && part1.second != Asm) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
////check if this is the right place for the constraint
|
||||
//if((part1.second == part2.second) && part1.second != Asm) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
// return;
|
||||
//}
|
||||
|
||||
openCommand("Insert Constraint Coincidence");
|
||||
std::string ConstrName = getUniqueObjectName("Coincidence");
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Coincident'");
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
//openCommand("Insert Constraint Coincidence");
|
||||
//std::string ConstrName = getUniqueObjectName("Coincidence");
|
||||
//doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Coincident'");
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
//updateActive();
|
||||
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
////updateActive();
|
||||
//doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
|
||||
commitCommand();
|
||||
|
||||
Gui::Selection().clearCompleteSelection();
|
||||
//commitCommand();
|
||||
//
|
||||
//Gui::Selection().clearCompleteSelection();
|
||||
}
|
||||
|
||||
/******************************************************************************************/
|
||||
@@ -547,52 +548,52 @@ CmdAssemblyConstraintAlignment::CmdAssemblyConstraintAlignment()
|
||||
|
||||
void CmdAssemblyConstraintAlignment::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
//Assembly::ProductRef* Asm = 0;
|
||||
//Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
//// retrive the standard objects needed
|
||||
//if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
// return;
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
//std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
//if(objs.size() != 2) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("You need to select two geometries on two different parts"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
//std::pair<Assembly::PartRef*, Assembly::ProductRef*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
////checking the parts is enough, both or non!
|
||||
//if(!part1.first || !part2.first) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
// return;
|
||||
//};
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if((part1.second == part2.second) && part1.second != Asm) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
////check if this is the right place for the constraint
|
||||
//if((part1.second == part2.second) && part1.second != Asm) {
|
||||
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
// QObject::tr("The selected parts belong both to the same subassembly, please add constraints there"));
|
||||
// return;
|
||||
//}
|
||||
|
||||
openCommand("Insert Constraint Alignment");
|
||||
std::string ConstrName = getUniqueObjectName("Alignment");
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Align'");
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
//openCommand("Insert Constraint Alignment");
|
||||
//std::string ConstrName = getUniqueObjectName("Alignment");
|
||||
//doCommand(Doc, "App.activeDocument().addObject('Assembly::Constraint','%s')", ConstrName.c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Type = 'Align'");
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
//doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
//updateActive();
|
||||
doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
////updateActive();
|
||||
//doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str());
|
||||
|
||||
commitCommand();
|
||||
|
||||
Gui::Selection().clearCompleteSelection();
|
||||
//commitCommand();
|
||||
//
|
||||
//Gui::Selection().clearCompleteSelection();
|
||||
}
|
||||
|
||||
void CreateAssemblyConstraintCommands(void)
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "TaskAssemblyConstraints.h"
|
||||
|
||||
#include <Constraint.h>
|
||||
#include <ItemPart.h>
|
||||
#include <PartRef.h>
|
||||
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Console.h>
|
||||
@@ -63,14 +63,14 @@ TaskAssemblyConstraints::TaskAssemblyConstraints(ViewProviderConstraint* vp)
|
||||
ui->orientation_widget->hide();
|
||||
|
||||
//set all basic values
|
||||
Assembly::ItemAssembly* ass = NULL;
|
||||
Assembly::Product* ass = NULL;
|
||||
Assembly::Constraint* obj = dynamic_cast<Assembly::Constraint*>(vp->getObject());
|
||||
|
||||
if(obj->First.getValue()) {
|
||||
QString str;
|
||||
str = QString::fromAscii(obj->First.getValue()->getNameInDocument()) + QString::fromAscii(".") + QString::fromStdString(obj->First.getSubValues().front());
|
||||
ui->first_geom->setText(str);
|
||||
ass = dynamic_cast<Assembly::ItemPart*>(obj->First.getValue())->getParentAssembly();
|
||||
ass = dynamic_cast<Assembly::PartRef*>(obj->First.getValue())->getParentAssembly();
|
||||
};
|
||||
|
||||
if(obj->Second.getValue()) {
|
||||
@@ -79,7 +79,7 @@ TaskAssemblyConstraints::TaskAssemblyConstraints(ViewProviderConstraint* vp)
|
||||
ui->second_geom->setText(str);
|
||||
|
||||
if(!ass)
|
||||
ass = dynamic_cast<Assembly::ItemPart*>(obj->Second.getValue())->getParentAssembly();
|
||||
ass = dynamic_cast<Assembly::PartRef*>(obj->Second.getValue())->getParentAssembly();
|
||||
};
|
||||
|
||||
if(ass)
|
||||
@@ -249,13 +249,13 @@ void TaskAssemblyConstraints::onSelectionChanged(const Gui::SelectionChanges& ms
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
Assembly::Constraint* con = dynamic_cast<Assembly::Constraint*>(view->getObject());
|
||||
|
||||
if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
|
||||
if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Assembly"),
|
||||
QObject::tr("You need a active (blue) Assembly to insert a Constraint. Please create a new one or make one active (double click)."));
|
||||
return;
|
||||
}
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = static_cast<Assembly::ItemAssembly*>(ActiveAsmObject)->getContainingPart(objs.back().getObject());
|
||||
std::pair<Assembly::PartRef*, Assembly::Product*> part1 = static_cast<Assembly::Product*>(ActiveAsmObject)->getContainingPart(objs.back().getObject());
|
||||
con->First.setValue(part1.first, objs.back().getSubNames());
|
||||
QString str;
|
||||
str = QString::fromAscii(part1.first->getNameInDocument()) + QString::fromAscii(".") + QString::fromStdString(con->First.getSubValues().front());
|
||||
@@ -272,13 +272,13 @@ void TaskAssemblyConstraints::onSelectionChanged(const Gui::SelectionChanges& ms
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
Assembly::Constraint* con = dynamic_cast<Assembly::Constraint*>(view->getObject());
|
||||
|
||||
if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
|
||||
if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Assembly"),
|
||||
QObject::tr("You need a active (blue) Assembly to insert a Constraint. Please create a new one or make one active (double click)."));
|
||||
return;
|
||||
}
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = static_cast<Assembly::ItemAssembly*>(ActiveAsmObject)->getContainingPart(objs.back().getObject());
|
||||
std::pair<Assembly::PartRef*, Assembly::Product*> part2 = static_cast<Assembly::Product*>(ActiveAsmObject)->getContainingPart(objs.back().getObject());
|
||||
con->Second.setValue(part2.first, objs.back().getSubNames());
|
||||
QString str;
|
||||
str = QString::fromAscii(part2.first->getNameInDocument()) + QString::fromAscii(".") + QString::fromStdString(con->Second.getSubValues().front());
|
||||
@@ -290,7 +290,7 @@ void TaskAssemblyConstraints::onSelectionChanged(const Gui::SelectionChanges& ms
|
||||
view->draw();
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void TaskAssemblyConstraints::on_constraint_selection(bool clicked)
|
||||
@@ -395,12 +395,12 @@ void TaskAssemblyConstraints::setPossibleOptions() {
|
||||
|
||||
if(obj->First.getValue()) {
|
||||
|
||||
Assembly::ItemPart* p1 = dynamic_cast<Assembly::ItemPart*>(obj->First.getValue());
|
||||
Assembly::PartRef* p1 = dynamic_cast<Assembly::PartRef*>(obj->First.getValue());
|
||||
|
||||
if(!p1)
|
||||
return;
|
||||
|
||||
Assembly::ItemAssembly* ass = p1->getParentAssembly();
|
||||
Assembly::Product* ass = p1->getParentAssembly();
|
||||
|
||||
//extract the geometries to use for comparison
|
||||
boost::shared_ptr<Geometry3D> g1 = ass->m_solver->getGeometry3D(obj->First.getSubValues()[0].c_str());
|
||||
@@ -410,7 +410,7 @@ void TaskAssemblyConstraints::setPossibleOptions() {
|
||||
|
||||
if(obj->Second.getValue()) {
|
||||
|
||||
Assembly::ItemPart* p2 = dynamic_cast<Assembly::ItemPart*>(obj->Second.getValue());
|
||||
Assembly::PartRef* p2 = dynamic_cast<Assembly::PartRef*>(obj->Second.getValue());
|
||||
|
||||
if(!p2)
|
||||
return;
|
||||
@@ -498,12 +498,12 @@ void TaskAssemblyConstraints::setPossibleConstraints()
|
||||
|
||||
if(obj->First.getValue()) {
|
||||
|
||||
Assembly::ItemPart* p1 = dynamic_cast<Assembly::ItemPart*>(obj->First.getValue());
|
||||
Assembly::PartRef* p1 = dynamic_cast<Assembly::PartRef*>(obj->First.getValue());
|
||||
|
||||
if(!p1)
|
||||
return;
|
||||
|
||||
Assembly::ItemAssembly* ass = p1->getParentAssembly();
|
||||
Assembly::Product* ass = p1->getParentAssembly();
|
||||
|
||||
//extract the geometries to use for comparison
|
||||
boost::shared_ptr<Geometry3D> g1 = ass->m_solver->getGeometry3D(obj->First.getSubValues()[0].c_str());
|
||||
@@ -521,7 +521,7 @@ void TaskAssemblyConstraints::setPossibleConstraints()
|
||||
|
||||
if(obj->Second.getValue()) {
|
||||
|
||||
Assembly::ItemPart* p2 = dynamic_cast<Assembly::ItemPart*>(obj->Second.getValue());
|
||||
Assembly::PartRef* p2 = dynamic_cast<Assembly::PartRef*>(obj->Second.getValue());
|
||||
|
||||
if(!p2)
|
||||
return;
|
||||
|
||||
@@ -1,200 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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_
|
||||
# include <Inventor/nodes/SoGroup.h>
|
||||
#include <QMessageBox>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderAssembly.h"
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Application.h>
|
||||
|
||||
#include <Mod/Assembly/App/ItemAssembly.h>
|
||||
#include <Mod/Assembly/App/ItemPart.h>
|
||||
#include <Mod/Part/App/BodyBase.h>
|
||||
|
||||
using namespace AssemblyGui;
|
||||
|
||||
extern Assembly::Item* ActiveAsmObject;
|
||||
|
||||
PROPERTY_SOURCE(AssemblyGui::ViewProviderItemAssembly,AssemblyGui::ViewProviderItem)
|
||||
|
||||
ViewProviderItemAssembly::ViewProviderItemAssembly()
|
||||
{
|
||||
sPixmap = "Assembly_Assembly_Tree.svg";
|
||||
}
|
||||
|
||||
ViewProviderItemAssembly::~ViewProviderItemAssembly()
|
||||
{
|
||||
if(getObject() == ActiveAsmObject)
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.clearActiveAssembly()");
|
||||
}
|
||||
|
||||
bool ViewProviderItemAssembly::doubleClicked(void)
|
||||
{
|
||||
Gui::Command::assureWorkbench("AssemblyWorkbench");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().%s)",this->getObject()->getNameInDocument());
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderItemAssembly::attach(App::DocumentObject* pcFeat)
|
||||
{
|
||||
// call parent attach method
|
||||
ViewProviderGeometryObject::attach(pcFeat);
|
||||
|
||||
|
||||
// putting all together with the switch
|
||||
addDisplayMaskMode(getChildRoot(), "Main");
|
||||
}
|
||||
|
||||
void ViewProviderItemAssembly::setDisplayMode(const char* ModeName)
|
||||
{
|
||||
if(strcmp("Main",ModeName)==0)
|
||||
setDisplayMaskMode("Main");
|
||||
|
||||
ViewProviderGeometryObject::setDisplayMode(ModeName);
|
||||
}
|
||||
|
||||
std::vector<std::string> ViewProviderItemAssembly::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
|
||||
|
||||
// add your own modes
|
||||
StrList.push_back("Main");
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderItemAssembly::claimChildren(void)const
|
||||
{
|
||||
std::vector<App::DocumentObject*> temp(static_cast<Assembly::ItemAssembly*>(getObject())->Items.getValues());
|
||||
temp.insert(temp.end(),
|
||||
static_cast<Assembly::ItemAssembly*>(getObject())->Annotations.getValues().begin(),
|
||||
static_cast<Assembly::ItemAssembly*>(getObject())->Annotations.getValues().end());
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderItemAssembly::claimChildren3D(void)const
|
||||
{
|
||||
|
||||
return static_cast<Assembly::ItemAssembly*>(getObject())->Items.getValues();
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderItemAssembly::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
ViewProviderItem::setupContextMenu(menu, receiver, member); // call the base class
|
||||
|
||||
QAction* toggle = menu->addAction(QObject::tr("Rigid subassembly"), receiver, member);
|
||||
toggle->setData(QVariant(1000)); // identifier
|
||||
toggle->setCheckable(true);
|
||||
toggle->setToolTip(QObject::tr("Set if the subassembly shall be solved as on part (rigid) or if all parts of this assembly are solved for themselfe."));
|
||||
toggle->setStatusTip(QObject::tr("Set if the subassembly shall be solved as on part (rigid) or if all parts of this assembly are solved for themself."));
|
||||
bool prop = static_cast<Assembly::ItemAssembly*>(getObject())->Rigid.getValue();
|
||||
toggle->setChecked(prop);
|
||||
}
|
||||
|
||||
bool ViewProviderItemAssembly::setEdit(int ModNum)
|
||||
{
|
||||
if(ModNum == 1000) { // identifier
|
||||
Gui::Command::openCommand("Change subassembly solving behaviour");
|
||||
if(!static_cast<Assembly::ItemAssembly*>(getObject())->Rigid.getValue())
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Rigid = True",getObject()->getDocument()->getName(), getObject()->getNameInDocument());
|
||||
else
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Rigid = False",getObject()->getDocument()->getName(), getObject()->getNameInDocument());
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
return false;
|
||||
}
|
||||
return ViewProviderItem::setEdit(ModNum); // call the base class
|
||||
}
|
||||
|
||||
bool ViewProviderItemAssembly::allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it){
|
||||
if ((*it)->getTypeId().isDerivedFrom(Part::BodyBase::getClassTypeId())) {
|
||||
continue;
|
||||
} else if ((*it)->getTypeId().isDerivedFrom(Assembly::ItemPart::getClassTypeId())) {
|
||||
continue;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void ViewProviderItemAssembly::drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
// Open command
|
||||
Assembly::ItemAssembly* AsmItem = static_cast<Assembly::ItemAssembly*>(getObject());
|
||||
App::Document* doc = AsmItem->getDocument();
|
||||
Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
|
||||
|
||||
gui->openCommand("Move into Assembly");
|
||||
for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it) {
|
||||
if ((*it)->getTypeId().isDerivedFrom(Part::BodyBase::getClassTypeId())) {
|
||||
// get document object
|
||||
const App::DocumentObject* obj = *it;
|
||||
|
||||
// build Python command for execution
|
||||
std::string PartName = doc->getUniqueObjectName("Part");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ItemPart','%s')",PartName.c_str());
|
||||
std::string fatherName = AsmItem->getNameInDocument();
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s] ",fatherName.c_str(),fatherName.c_str(),PartName.c_str());
|
||||
Gui::Command::addModule(Gui::Command::App,"PartDesign");
|
||||
Gui::Command::addModule(Gui::Command::Gui,"PartDesignGui");
|
||||
|
||||
|
||||
std::string BodyName = obj->getNameInDocument();
|
||||
// add the standard planes
|
||||
std::string Plane1Name = BodyName + "_PlaneXY";
|
||||
std::string Plane2Name = BodyName + "_PlaneYZ";
|
||||
std::string Plane3Name = BodyName + "_PlaneXZ";
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane1Name.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'XY-Plane'");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane2Name.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'YZ-Plane'");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'XZ-Plane'");
|
||||
// add to anotation set of the Part object
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Annotation = [App.activeDocument().%s,App.activeDocument().%s,App.activeDocument().%s] ",PartName.c_str(),Plane1Name.c_str(),Plane2Name.c_str(),Plane3Name.c_str());
|
||||
// add the main body
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str());
|
||||
|
||||
} else if ((*it)->getTypeId().isDerivedFrom(Assembly::ItemPart::getClassTypeId())) {
|
||||
continue;
|
||||
} else
|
||||
continue;
|
||||
|
||||
}
|
||||
gui->commitCommand();
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "TaskAssemblyConstraints.h"
|
||||
#include "TaskDlgAssemblyConstraints.h"
|
||||
#include "Mod/Assembly/App/Constraint.h"
|
||||
#include "Mod/Assembly/App/ItemPart.h"
|
||||
#include "Mod/Assembly/App/PartRef.h"
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Base/Console.h>
|
||||
#include <App/Application.h>
|
||||
@@ -262,7 +262,7 @@ void ViewProviderConstraint::draw()
|
||||
if(!obj1)
|
||||
return;
|
||||
|
||||
Assembly::ItemPart* part1 = static_cast<Assembly::ItemPart*>(obj1);
|
||||
Assembly::PartRef* part1 = static_cast<Assembly::PartRef*>(obj1);
|
||||
|
||||
if(!part1)
|
||||
return;
|
||||
@@ -296,7 +296,7 @@ void ViewProviderConstraint::draw()
|
||||
|
||||
//here it's a bit more involved, as the coind tree structure let's the first transform node
|
||||
//transform the second part too.
|
||||
Assembly::ItemPart* part2 = static_cast<Assembly::ItemPart*>(obj2);
|
||||
Assembly::PartRef* part2 = static_cast<Assembly::PartRef*>(obj2);
|
||||
|
||||
if(!part2)
|
||||
return;
|
||||
@@ -321,13 +321,13 @@ void ViewProviderConstraint::upstream_placement(Base::Placement& p, Assembly::It
|
||||
|
||||
typedef std::vector<App::DocumentObject*>::const_iterator iter;
|
||||
|
||||
//get all links to this item and see if we have more ItemAssemblys
|
||||
//get all links to this item and see if we have more Products
|
||||
const std::vector<App::DocumentObject*>& vector = item->getInList();
|
||||
for(iter it=vector.begin(); it != vector.end(); it++) {
|
||||
|
||||
if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
|
||||
if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
|
||||
|
||||
upstream_placement(p, static_cast<Assembly::ItemAssembly*>(*it));
|
||||
upstream_placement(p, static_cast<Assembly::Product*>(*it));
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -361,7 +361,7 @@ TopoDS_Shape ViewProviderConstraint::getConstraintShape(int link)
|
||||
if(!obj1)
|
||||
return TopoDS_Shape();
|
||||
|
||||
Assembly::ItemPart* part1 = static_cast<Assembly::ItemPart*>(obj1);
|
||||
Assembly::PartRef* part1 = static_cast<Assembly::PartRef*>(obj1);
|
||||
|
||||
if(!part1)
|
||||
return TopoDS_Shape();
|
||||
@@ -387,7 +387,7 @@ TopoDS_Shape ViewProviderConstraint::getConstraintShape(int link)
|
||||
if(!obj2)
|
||||
return TopoDS_Shape();
|
||||
|
||||
Assembly::ItemPart* part2 = static_cast<Assembly::ItemPart*>(obj2);
|
||||
Assembly::PartRef* part2 = static_cast<Assembly::PartRef*>(obj2);
|
||||
|
||||
if(!part2)
|
||||
return TopoDS_Shape();
|
||||
|
||||
@@ -1,289 +1,289 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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_
|
||||
# include <Inventor/nodes/SoGroup.h>
|
||||
#include <Inventor/nodes/SoAnnotation.h>
|
||||
#include <Inventor/nodes/SoSwitch.h>
|
||||
#include <Inventor/nodes/SoDrawStyle.h>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderPart.h"
|
||||
//#include <Gui/Command.h>
|
||||
//#include <Gui/Document.h>
|
||||
#include <Mod/Assembly/App/ItemPart.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace AssemblyGui;
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
SbColor PointColor(1.0f,0.0f,0.0f);
|
||||
SbColor PseudoColor(0.0f,0.0f,1.0f);
|
||||
SbColor MidpointColor(0.0f,1.0f,1.0f);
|
||||
SbColor ZeroColor(1.0f,1.0f,0.0f);
|
||||
#endif
|
||||
|
||||
PROPERTY_SOURCE(AssemblyGui::ViewProviderItemPart,AssemblyGui::ViewProviderItem)
|
||||
|
||||
ViewProviderItemPart::ViewProviderItemPart()
|
||||
{
|
||||
sPixmap = "Assembly_Assembly_Part_Tree.svg";
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
ADD_PROPERTY(ShowScalePoints,(false));
|
||||
#endif
|
||||
}
|
||||
|
||||
ViewProviderItemPart::~ViewProviderItemPart()
|
||||
{
|
||||
}
|
||||
|
||||
bool ViewProviderItemPart::doubleClicked(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderItemPart::attach(App::DocumentObject* pcFeat)
|
||||
{
|
||||
// call parent attach method
|
||||
ViewProviderGeometryObject::attach(pcFeat);
|
||||
// putting all together with the switch
|
||||
addDisplayMaskMode(getChildRoot(), "Main");
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
|
||||
m_anno = new SoAnnotation;
|
||||
m_switch = new SoSwitch;
|
||||
m_switch->addChild(m_anno);
|
||||
|
||||
m_material = new SoMaterial;
|
||||
m_anno->addChild(m_material);
|
||||
|
||||
SoMaterialBinding* MtlBind = new SoMaterialBinding;
|
||||
MtlBind->value = SoMaterialBinding::PER_VERTEX;
|
||||
m_anno->addChild(MtlBind);
|
||||
|
||||
m_pointsCoordinate = new SoCoordinate3;
|
||||
m_anno->addChild(m_pointsCoordinate);
|
||||
|
||||
SoDrawStyle* DrawStyle = new SoDrawStyle;
|
||||
DrawStyle->pointSize = 8;
|
||||
m_anno->addChild(DrawStyle);
|
||||
m_points = new SoMarkerSet;
|
||||
m_points->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7;
|
||||
m_anno->addChild(m_points);
|
||||
|
||||
pcRoot->addChild(m_switch);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ViewProviderItemPart::setDisplayMode(const char* ModeName)
|
||||
{
|
||||
if(strcmp("Main",ModeName)==0)
|
||||
setDisplayMaskMode("Main");
|
||||
|
||||
ViewProviderGeometryObject::setDisplayMode(ModeName);
|
||||
}
|
||||
|
||||
std::vector<std::string> ViewProviderItemPart::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
|
||||
|
||||
// add your own modes
|
||||
StrList.push_back("Main");
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderItemPart::claimChildren(void)const
|
||||
{
|
||||
std::vector<App::DocumentObject*> res;
|
||||
|
||||
res.insert(res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end());
|
||||
|
||||
if(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue())
|
||||
res.push_back(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue());
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderItemPart::claimChildren3D(void)const
|
||||
{
|
||||
std::vector<App::DocumentObject*> res;
|
||||
|
||||
res.insert(res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end());
|
||||
|
||||
if(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue())
|
||||
res.push_back(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue());
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
bool ViewProviderItemPart::allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
//for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it)
|
||||
// if ((*it)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
|
||||
// if (static_cast<App::DocumentObjectGroup*>(getObject())->isChildOf(
|
||||
// static_cast<const App::DocumentObjectGroup*>(*it))) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
void ViewProviderItemPart::drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
//// Open command
|
||||
//App::DocumentObjectGroup* grp = static_cast<App::DocumentObjectGroup*>(getObject());
|
||||
//App::Document* doc = grp->getDocument();
|
||||
//Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
|
||||
//gui->openCommand("Move object");
|
||||
//for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it) {
|
||||
// // get document object
|
||||
// const App::DocumentObject* obj = *it;
|
||||
// const App::DocumentObjectGroup* par = App::DocumentObjectGroup::getGroupOfObject(obj);
|
||||
// if (par) {
|
||||
// // allow an object to be in one group only
|
||||
// QString cmd;
|
||||
// cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").removeObject("
|
||||
// "App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
// .arg(QString::fromAscii(doc->getName()))
|
||||
// .arg(QString::fromAscii(par->getNameInDocument()))
|
||||
// .arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
// Gui::Application::Instance->runPythonCode(cmd.toUtf8());
|
||||
// }
|
||||
|
||||
// // build Python command for execution
|
||||
// QString cmd;
|
||||
// cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").addObject("
|
||||
// "App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
// .arg(QString::fromAscii(doc->getName()))
|
||||
// .arg(QString::fromAscii(grp->getNameInDocument()))
|
||||
// .arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
//
|
||||
// Gui::Application::Instance->runPythonCode(cmd.toUtf8());
|
||||
//}
|
||||
//gui->commitCommand();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
|
||||
void ViewProviderItemPart::onChanged(const App::Property* prop) {
|
||||
|
||||
if(prop == &ShowScalePoints) {
|
||||
if(ShowScalePoints.getValue()) {
|
||||
m_switch->whichChild = 0;
|
||||
|
||||
int counter = 0;
|
||||
boost::shared_ptr<Part3D> part = static_cast<Assembly::ItemPart*>(getObject())->m_part;
|
||||
|
||||
if(!part) {
|
||||
ViewProviderItem::onChanged(prop);
|
||||
return;
|
||||
}
|
||||
|
||||
dcm::detail::Transform<double,3> transform = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_transform;
|
||||
dcm::detail::Transform<double,3> ssrTransform = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_ssrTransform;
|
||||
|
||||
dcm::detail::Transform<double,3> trans = ssrTransform.inverse();
|
||||
|
||||
int PseudoSize = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_pseudo.size();
|
||||
typedef dcm::details::ClusterMath<Solver>::Vec Vector;
|
||||
Vector& pv = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_points;
|
||||
|
||||
for(Vector::iterator it = pv.begin(); it != pv.end(); it++) {
|
||||
|
||||
Kernel::Vector3 vec = trans * (*it);
|
||||
m_pointsCoordinate->point.set1Value(counter, SbVec3f(vec(0),vec(1),vec(2)));
|
||||
|
||||
if(counter < PseudoSize)
|
||||
m_material->diffuseColor.set1Value(counter, PseudoColor);
|
||||
else
|
||||
m_material->diffuseColor.set1Value(counter, PointColor);
|
||||
|
||||
counter++;
|
||||
};
|
||||
|
||||
//midpoint
|
||||
Kernel::Vector3 midpoint = trans * Kernel::Vector3(0,0,0);
|
||||
|
||||
m_pointsCoordinate->point.set1Value(counter, SbVec3f(midpoint(0),midpoint(1),midpoint(2)));
|
||||
|
||||
m_material->diffuseColor.set1Value(counter, MidpointColor);
|
||||
|
||||
counter++;
|
||||
|
||||
//origin
|
||||
Kernel::Vector3 origin = Kernel::Vector3(0,0,0);
|
||||
|
||||
m_pointsCoordinate->point.set1Value(counter, SbVec3f(origin(0),origin(1),origin(2)));
|
||||
|
||||
m_material->diffuseColor.set1Value(counter, ZeroColor);
|
||||
|
||||
counter++;
|
||||
|
||||
m_points->numPoints = counter;
|
||||
|
||||
//test
|
||||
boost::shared_ptr<Geometry3D> g = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_geometry[0];
|
||||
|
||||
std::stringstream str;
|
||||
|
||||
str<<"Global: "<<g->m_global.transpose()<<std::endl;
|
||||
|
||||
str<<"Global TLPoint: "<<(trans * g->getPoint()).transpose()<<std::endl;
|
||||
|
||||
Kernel::Vector3 v = g->m_global.head(3);
|
||||
|
||||
str<<"Local Point : "<<(transform.inverse()*v).transpose()<<std::endl;
|
||||
|
||||
str<<"Local TLPoint: "<<(ssrTransform.inverse()*g->getPoint()).transpose()<<std::endl;
|
||||
|
||||
str<<"PVPoint : "<<(pv[0]).transpose()<<std::endl;
|
||||
|
||||
str<<"Local PVPoint: "<<(ssrTransform.inverse()*pv[0]).transpose()<<std::endl;
|
||||
|
||||
Base::Console().Message(str.str().c_str());
|
||||
|
||||
}
|
||||
else {
|
||||
m_switch->whichChild = -1;
|
||||
m_pointsCoordinate->point.setValues(0, 0, (SbVec3f*)NULL);
|
||||
m_material->diffuseColor.setValues(0, 0, (SbColor*)NULL);
|
||||
m_points->numPoints = 0;
|
||||
}
|
||||
};
|
||||
|
||||
ViewProviderItem::onChanged(prop);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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_
|
||||
# include <Inventor/nodes/SoGroup.h>
|
||||
#include <Inventor/nodes/SoAnnotation.h>
|
||||
#include <Inventor/nodes/SoSwitch.h>
|
||||
#include <Inventor/nodes/SoDrawStyle.h>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderPartRef.h"
|
||||
//#include <Gui/Command.h>
|
||||
//#include <Gui/Document.h>
|
||||
#include <Mod/Assembly/App/PartRef.h>
|
||||
#include <Base/Console.h>
|
||||
|
||||
using namespace AssemblyGui;
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
SbColor PointColor(1.0f,0.0f,0.0f);
|
||||
SbColor PseudoColor(0.0f,0.0f,1.0f);
|
||||
SbColor MidpointColor(0.0f,1.0f,1.0f);
|
||||
SbColor ZeroColor(1.0f,1.0f,0.0f);
|
||||
#endif
|
||||
|
||||
PROPERTY_SOURCE(AssemblyGui::ViewProviderPartRef,AssemblyGui::ViewProviderItem)
|
||||
|
||||
ViewProviderPartRef::ViewProviderPartRef()
|
||||
{
|
||||
sPixmap = "Assembly_Assembly_Part_Tree.svg";
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
ADD_PROPERTY(ShowScalePoints,(false));
|
||||
#endif
|
||||
}
|
||||
|
||||
ViewProviderPartRef::~ViewProviderPartRef()
|
||||
{
|
||||
}
|
||||
|
||||
bool ViewProviderPartRef::doubleClicked(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderPartRef::attach(App::DocumentObject* pcFeat)
|
||||
{
|
||||
// call parent attach method
|
||||
ViewProviderGeometryObject::attach(pcFeat);
|
||||
// putting all together with the switch
|
||||
addDisplayMaskMode(getChildRoot(), "Main");
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
|
||||
m_anno = new SoAnnotation;
|
||||
m_switch = new SoSwitch;
|
||||
m_switch->addChild(m_anno);
|
||||
|
||||
m_material = new SoMaterial;
|
||||
m_anno->addChild(m_material);
|
||||
|
||||
SoMaterialBinding* MtlBind = new SoMaterialBinding;
|
||||
MtlBind->value = SoMaterialBinding::PER_VERTEX;
|
||||
m_anno->addChild(MtlBind);
|
||||
|
||||
m_pointsCoordinate = new SoCoordinate3;
|
||||
m_anno->addChild(m_pointsCoordinate);
|
||||
|
||||
SoDrawStyle* DrawStyle = new SoDrawStyle;
|
||||
DrawStyle->pointSize = 8;
|
||||
m_anno->addChild(DrawStyle);
|
||||
m_points = new SoMarkerSet;
|
||||
m_points->markerIndex = SoMarkerSet::CIRCLE_FILLED_7_7;
|
||||
m_anno->addChild(m_points);
|
||||
|
||||
pcRoot->addChild(m_switch);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ViewProviderPartRef::setDisplayMode(const char* ModeName)
|
||||
{
|
||||
if(strcmp("Main",ModeName)==0)
|
||||
setDisplayMaskMode("Main");
|
||||
|
||||
ViewProviderGeometryObject::setDisplayMode(ModeName);
|
||||
}
|
||||
|
||||
std::vector<std::string> ViewProviderPartRef::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
|
||||
|
||||
// add your own modes
|
||||
StrList.push_back("Main");
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderPartRef::claimChildren(void)const
|
||||
{
|
||||
std::vector<App::DocumentObject*> res;
|
||||
|
||||
res.insert(res.end(), static_cast<Assembly::PartRef*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::PartRef*>(getObject())->Annotation.getValues().end());
|
||||
|
||||
if(static_cast<Assembly::PartRef*>(getObject())->Model.getValue())
|
||||
res.push_back(static_cast<Assembly::PartRef*>(getObject())->Model.getValue());
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderPartRef::claimChildren3D(void)const
|
||||
{
|
||||
std::vector<App::DocumentObject*> res;
|
||||
|
||||
res.insert(res.end(), static_cast<Assembly::PartRef*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::PartRef*>(getObject())->Annotation.getValues().end());
|
||||
|
||||
if(static_cast<Assembly::PartRef*>(getObject())->Model.getValue())
|
||||
res.push_back(static_cast<Assembly::PartRef*>(getObject())->Model.getValue());
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
bool ViewProviderPartRef::allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
//for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it)
|
||||
// if ((*it)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
|
||||
// if (static_cast<App::DocumentObjectGroup*>(getObject())->isChildOf(
|
||||
// static_cast<const App::DocumentObjectGroup*>(*it))) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
void ViewProviderPartRef::drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
//// Open command
|
||||
//App::DocumentObjectGroup* grp = static_cast<App::DocumentObjectGroup*>(getObject());
|
||||
//App::Document* doc = grp->getDocument();
|
||||
//Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
|
||||
//gui->openCommand("Move object");
|
||||
//for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it) {
|
||||
// // get document object
|
||||
// const App::DocumentObject* obj = *it;
|
||||
// const App::DocumentObjectGroup* par = App::DocumentObjectGroup::getGroupOfObject(obj);
|
||||
// if (par) {
|
||||
// // allow an object to be in one group only
|
||||
// QString cmd;
|
||||
// cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").removeObject("
|
||||
// "App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
// .arg(QString::fromAscii(doc->getName()))
|
||||
// .arg(QString::fromAscii(par->getNameInDocument()))
|
||||
// .arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
// Gui::Application::Instance->runPythonCode(cmd.toUtf8());
|
||||
// }
|
||||
|
||||
// // build Python command for execution
|
||||
// QString cmd;
|
||||
// cmd = QString::fromAscii("App.getDocument(\"%1\").getObject(\"%2\").addObject("
|
||||
// "App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
// .arg(QString::fromAscii(doc->getName()))
|
||||
// .arg(QString::fromAscii(grp->getNameInDocument()))
|
||||
// .arg(QString::fromAscii(obj->getNameInDocument()));
|
||||
//
|
||||
// Gui::Application::Instance->runPythonCode(cmd.toUtf8());
|
||||
//}
|
||||
//gui->commitCommand();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
|
||||
void ViewProviderPartRef::onChanged(const App::Property* prop) {
|
||||
|
||||
if(prop == &ShowScalePoints) {
|
||||
if(ShowScalePoints.getValue()) {
|
||||
m_switch->whichChild = 0;
|
||||
|
||||
int counter = 0;
|
||||
boost::shared_ptr<Part3D> part = static_cast<Assembly::PartRef*>(getObject())->m_part;
|
||||
|
||||
if(!part) {
|
||||
ViewProviderItem::onChanged(prop);
|
||||
return;
|
||||
}
|
||||
|
||||
dcm::detail::Transform<double,3> transform = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_transform;
|
||||
dcm::detail::Transform<double,3> ssrTransform = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_ssrTransform;
|
||||
|
||||
dcm::detail::Transform<double,3> trans = ssrTransform.inverse();
|
||||
|
||||
int PseudoSize = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_pseudo.size();
|
||||
typedef dcm::details::ClusterMath<Solver>::Vec Vector;
|
||||
Vector& pv = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_points;
|
||||
|
||||
for(Vector::iterator it = pv.begin(); it != pv.end(); it++) {
|
||||
|
||||
Kernel::Vector3 vec = trans * (*it);
|
||||
m_pointsCoordinate->point.set1Value(counter, SbVec3f(vec(0),vec(1),vec(2)));
|
||||
|
||||
if(counter < PseudoSize)
|
||||
m_material->diffuseColor.set1Value(counter, PseudoColor);
|
||||
else
|
||||
m_material->diffuseColor.set1Value(counter, PointColor);
|
||||
|
||||
counter++;
|
||||
};
|
||||
|
||||
//midpoint
|
||||
Kernel::Vector3 midpoint = trans * Kernel::Vector3(0,0,0);
|
||||
|
||||
m_pointsCoordinate->point.set1Value(counter, SbVec3f(midpoint(0),midpoint(1),midpoint(2)));
|
||||
|
||||
m_material->diffuseColor.set1Value(counter, MidpointColor);
|
||||
|
||||
counter++;
|
||||
|
||||
//origin
|
||||
Kernel::Vector3 origin = Kernel::Vector3(0,0,0);
|
||||
|
||||
m_pointsCoordinate->point.set1Value(counter, SbVec3f(origin(0),origin(1),origin(2)));
|
||||
|
||||
m_material->diffuseColor.set1Value(counter, ZeroColor);
|
||||
|
||||
counter++;
|
||||
|
||||
m_points->numPoints = counter;
|
||||
|
||||
//test
|
||||
boost::shared_ptr<Geometry3D> g = part->m_cluster->getProperty<Module3D::type<Solver>::math_prop>().m_geometry[0];
|
||||
|
||||
std::stringstream str;
|
||||
|
||||
str<<"Global: "<<g->m_global.transpose()<<std::endl;
|
||||
|
||||
str<<"Global TLPoint: "<<(trans * g->getPoint()).transpose()<<std::endl;
|
||||
|
||||
Kernel::Vector3 v = g->m_global.head(3);
|
||||
|
||||
str<<"Local Point : "<<(transform.inverse()*v).transpose()<<std::endl;
|
||||
|
||||
str<<"Local TLPoint: "<<(ssrTransform.inverse()*g->getPoint()).transpose()<<std::endl;
|
||||
|
||||
str<<"PVPoint : "<<(pv[0]).transpose()<<std::endl;
|
||||
|
||||
str<<"Local PVPoint: "<<(ssrTransform.inverse()*pv[0]).transpose()<<std::endl;
|
||||
|
||||
Base::Console().Message(str.str().c_str());
|
||||
|
||||
}
|
||||
else {
|
||||
m_switch->whichChild = -1;
|
||||
m_pointsCoordinate->point.setValues(0, 0, (SbVec3f*)NULL);
|
||||
m_material->diffuseColor.setValues(0, 0, (SbColor*)NULL);
|
||||
m_points->numPoints = 0;
|
||||
}
|
||||
};
|
||||
|
||||
ViewProviderItem::onChanged(prop);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,82 +1,82 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef ASSEMBLYGUI_ViewProviderPart_H
|
||||
#define ASSEMBLYGUI_ViewProviderPart_H
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include <Inventor/nodes/SoAnnotation.h>
|
||||
#include <Inventor/nodes/SoMarkerSet.h>
|
||||
#include <Inventor/nodes/SoCoordinate3.h>
|
||||
#include <Inventor/nodes/SoMaterial.h>
|
||||
#include <Inventor/nodes/SoSwitch.h>
|
||||
|
||||
|
||||
namespace AssemblyGui {
|
||||
|
||||
class AssemblyGuiExport ViewProviderItemPart : public AssemblyGui::ViewProviderItem
|
||||
{
|
||||
PROPERTY_HEADER(PartGui::ViewProviderItemPart);
|
||||
|
||||
public:
|
||||
/// constructor
|
||||
ViewProviderItemPart();
|
||||
/// destructor
|
||||
virtual ~ViewProviderItemPart();
|
||||
|
||||
virtual bool doubleClicked(void);
|
||||
|
||||
virtual void attach(App::DocumentObject *);
|
||||
virtual void setDisplayMode(const char* ModeName);
|
||||
/// returns a list of all possible modes
|
||||
virtual std::vector<std::string> getDisplayModes(void) const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
|
||||
|
||||
/// get called if the user hover over a object in the tree
|
||||
virtual bool allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
/// get called if the user drops some objects
|
||||
virtual void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
//draw the dcm points
|
||||
SoAnnotation* m_anno;
|
||||
SoSwitch* m_switch;
|
||||
SoMaterial* m_material;
|
||||
SoCoordinate3* m_pointsCoordinate;
|
||||
SoMarkerSet* m_points;
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
|
||||
App::PropertyBool ShowScalePoints;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace AssemblyGui
|
||||
|
||||
|
||||
#endif // ASSEMBLYGUI_ViewProviderPart_H
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef ASSEMBLYGUI_ViewProviderPartRef_H
|
||||
#define ASSEMBLYGUI_ViewProviderPartRef_H
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include <Inventor/nodes/SoAnnotation.h>
|
||||
#include <Inventor/nodes/SoMarkerSet.h>
|
||||
#include <Inventor/nodes/SoCoordinate3.h>
|
||||
#include <Inventor/nodes/SoMaterial.h>
|
||||
#include <Inventor/nodes/SoSwitch.h>
|
||||
|
||||
|
||||
namespace AssemblyGui {
|
||||
|
||||
class AssemblyGuiExport ViewProviderPartRef : public AssemblyGui::ViewProviderItem
|
||||
{
|
||||
PROPERTY_HEADER(PartGui::ViewProviderPartRef);
|
||||
|
||||
public:
|
||||
/// constructor
|
||||
ViewProviderPartRef();
|
||||
/// destructor
|
||||
virtual ~ViewProviderPartRef();
|
||||
|
||||
virtual bool doubleClicked(void);
|
||||
|
||||
virtual void attach(App::DocumentObject *);
|
||||
virtual void setDisplayMode(const char* ModeName);
|
||||
/// returns a list of all possible modes
|
||||
virtual std::vector<std::string> getDisplayModes(void) const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
|
||||
|
||||
/// get called if the user hover over a object in the tree
|
||||
virtual bool allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
/// get called if the user drops some objects
|
||||
virtual void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
|
||||
|
||||
#ifdef ASSEMBLY_DEBUG_FACILITIES
|
||||
//draw the dcm points
|
||||
SoAnnotation* m_anno;
|
||||
SoSwitch* m_switch;
|
||||
SoMaterial* m_material;
|
||||
SoCoordinate3* m_pointsCoordinate;
|
||||
SoMarkerSet* m_points;
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
|
||||
App::PropertyBool ShowScalePoints;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace AssemblyGui
|
||||
|
||||
|
||||
#endif // ASSEMBLYGUI_ViewProviderPartRef_H
|
||||
200
src/Mod/Assembly/Gui/ViewProviderProduct.cpp
Normal file
200
src/Mod/Assembly/Gui/ViewProviderProduct.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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_
|
||||
# include <Inventor/nodes/SoGroup.h>
|
||||
#include <QMessageBox>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderProduct.h"
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Application.h>
|
||||
|
||||
#include <Mod/Assembly/App/Product.h>
|
||||
#include <Mod/Assembly/App/PartRef.h>
|
||||
//#include <Mod/Part/App/BodyBase.h>
|
||||
|
||||
using namespace AssemblyGui;
|
||||
|
||||
extern Assembly::Item* ActiveAsmObject;
|
||||
|
||||
PROPERTY_SOURCE(AssemblyGui::ViewProviderProduct,AssemblyGui::ViewProviderItem)
|
||||
|
||||
ViewProviderProduct::ViewProviderProduct()
|
||||
{
|
||||
sPixmap = "Assembly_Assembly_Tree.svg";
|
||||
}
|
||||
|
||||
ViewProviderProduct::~ViewProviderProduct()
|
||||
{
|
||||
if(getObject() == ActiveAsmObject)
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.clearActiveAssembly()");
|
||||
}
|
||||
|
||||
bool ViewProviderProduct::doubleClicked(void)
|
||||
{
|
||||
Gui::Command::assureWorkbench("AssemblyWorkbench");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().%s)",this->getObject()->getNameInDocument());
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderProduct::attach(App::DocumentObject* pcFeat)
|
||||
{
|
||||
// call parent attach method
|
||||
ViewProviderGeometryObject::attach(pcFeat);
|
||||
|
||||
|
||||
// putting all together with the switch
|
||||
addDisplayMaskMode(getChildRoot(), "Main");
|
||||
}
|
||||
|
||||
void ViewProviderProduct::setDisplayMode(const char* ModeName)
|
||||
{
|
||||
if(strcmp("Main",ModeName)==0)
|
||||
setDisplayMaskMode("Main");
|
||||
|
||||
ViewProviderGeometryObject::setDisplayMode(ModeName);
|
||||
}
|
||||
|
||||
std::vector<std::string> ViewProviderProduct::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
|
||||
|
||||
// add your own modes
|
||||
StrList.push_back("Main");
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderProduct::claimChildren(void)const
|
||||
{
|
||||
std::vector<App::DocumentObject*> temp(static_cast<Assembly::Product*>(getObject())->Items.getValues());
|
||||
temp.insert(temp.end(),
|
||||
static_cast<Assembly::Product*>(getObject())->Annotations.getValues().begin(),
|
||||
static_cast<Assembly::Product*>(getObject())->Annotations.getValues().end());
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderProduct::claimChildren3D(void)const
|
||||
{
|
||||
|
||||
return static_cast<Assembly::Product*>(getObject())->Items.getValues();
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderProduct::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
ViewProviderItem::setupContextMenu(menu, receiver, member); // call the base class
|
||||
|
||||
QAction* toggle = menu->addAction(QObject::tr("Rigid subassembly"), receiver, member);
|
||||
toggle->setData(QVariant(1000)); // identifier
|
||||
toggle->setCheckable(true);
|
||||
toggle->setToolTip(QObject::tr("Set if the subassembly shall be solved as on part (rigid) or if all parts of this assembly are solved for themselfe."));
|
||||
toggle->setStatusTip(QObject::tr("Set if the subassembly shall be solved as on part (rigid) or if all parts of this assembly are solved for themself."));
|
||||
bool prop = static_cast<Assembly::Product*>(getObject())->Rigid.getValue();
|
||||
toggle->setChecked(prop);
|
||||
}
|
||||
|
||||
bool ViewProviderProduct::setEdit(int ModNum)
|
||||
{
|
||||
if(ModNum == 1000) { // identifier
|
||||
Gui::Command::openCommand("Change subassembly solving behaviour");
|
||||
if(!static_cast<Assembly::Product*>(getObject())->Rigid.getValue())
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Rigid = True",getObject()->getDocument()->getName(), getObject()->getNameInDocument());
|
||||
else
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Rigid = False",getObject()->getDocument()->getName(), getObject()->getNameInDocument());
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
return false;
|
||||
}
|
||||
return ViewProviderItem::setEdit(ModNum); // call the base class
|
||||
}
|
||||
|
||||
bool ViewProviderProduct::allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it){
|
||||
//if ((*it)->getTypeId().isDerivedFrom(Part::BodyBase::getClassTypeId())) {
|
||||
// continue;
|
||||
//} else if ((*it)->getTypeId().isDerivedFrom(Assembly::ItemPart::getClassTypeId())) {
|
||||
// continue;
|
||||
//} else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void ViewProviderProduct::drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
// Open command
|
||||
//Assembly::Product* AsmItem = static_cast<Assembly::Product*>(getObject());
|
||||
//App::Document* doc = AsmItem->getDocument();
|
||||
//Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
|
||||
|
||||
//gui->openCommand("Move into Assembly");
|
||||
//for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it) {
|
||||
// if ((*it)->getTypeId().isDerivedFrom(Part::BodyBase::getClassTypeId())) {
|
||||
// // get document object
|
||||
// const App::DocumentObject* obj = *it;
|
||||
|
||||
// // build Python command for execution
|
||||
// std::string PartName = doc->getUniqueObjectName("Part");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ItemPart','%s')",PartName.c_str());
|
||||
// std::string fatherName = AsmItem->getNameInDocument();
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s] ",fatherName.c_str(),fatherName.c_str(),PartName.c_str());
|
||||
// Gui::Command::addModule(Gui::Command::App,"PartDesign");
|
||||
// Gui::Command::addModule(Gui::Command::Gui,"PartDesignGui");
|
||||
|
||||
|
||||
// std::string BodyName = obj->getNameInDocument();
|
||||
// // add the standard planes
|
||||
// std::string Plane1Name = BodyName + "_PlaneXY";
|
||||
// std::string Plane2Name = BodyName + "_PlaneYZ";
|
||||
// std::string Plane3Name = BodyName + "_PlaneXZ";
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane1Name.c_str());
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'XY-Plane'");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane2Name.c_str());
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'YZ-Plane'");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str());
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'XZ-Plane'");
|
||||
// // add to anotation set of the Part object
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Annotation = [App.activeDocument().%s,App.activeDocument().%s,App.activeDocument().%s] ",PartName.c_str(),Plane1Name.c_str(),Plane2Name.c_str(),Plane3Name.c_str());
|
||||
// // add the main body
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str());
|
||||
|
||||
// } else if ((*it)->getTypeId().isDerivedFrom(Assembly::ItemPart::getClassTypeId())) {
|
||||
// continue;
|
||||
// } else
|
||||
// continue;
|
||||
//
|
||||
//}
|
||||
//gui->commitCommand();
|
||||
|
||||
}
|
||||
@@ -1,69 +1,69 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef ASSEMBLYGUI_ViewProviderAssembly_H
|
||||
#define ASSEMBLYGUI_ViewProviderAssembly_H
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
namespace AssemblyGui {
|
||||
|
||||
class AssemblyGuiExport ViewProviderItemAssembly : public AssemblyGui::ViewProviderItem
|
||||
{
|
||||
PROPERTY_HEADER(PartGui::ViewProviderItemAssembly);
|
||||
|
||||
public:
|
||||
/// constructor
|
||||
ViewProviderItemAssembly();
|
||||
/// destructor
|
||||
virtual ~ViewProviderItemAssembly();
|
||||
|
||||
virtual bool doubleClicked(void);
|
||||
virtual void attach(App::DocumentObject *);
|
||||
virtual void setDisplayMode(const char* ModeName);
|
||||
/// returns a list of all possible modes
|
||||
virtual std::vector<std::string> getDisplayModes(void) const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
|
||||
|
||||
virtual void setupContextMenu(QMenu* menu, QObject* receiver, const char* member);
|
||||
virtual bool setEdit(int ModNum);
|
||||
|
||||
/// get called if the user hover over a object in the tree
|
||||
virtual bool allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
/// get called if the user drops some objects
|
||||
virtual void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace AssemblyGui
|
||||
|
||||
|
||||
#endif // ASSEMBLYGUI_ViewProviderAssembly_H
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef ASSEMBLYGUI_ViewProviderProduct_H
|
||||
#define ASSEMBLYGUI_ViewProviderProduct_H
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
namespace AssemblyGui {
|
||||
|
||||
class AssemblyGuiExport ViewProviderProduct : public AssemblyGui::ViewProviderItem
|
||||
{
|
||||
PROPERTY_HEADER(PartGui::ViewProviderProduct);
|
||||
|
||||
public:
|
||||
/// constructor
|
||||
ViewProviderProduct();
|
||||
/// destructor
|
||||
virtual ~ViewProviderProduct();
|
||||
|
||||
virtual bool doubleClicked(void);
|
||||
virtual void attach(App::DocumentObject *);
|
||||
virtual void setDisplayMode(const char* ModeName);
|
||||
/// returns a list of all possible modes
|
||||
virtual std::vector<std::string> getDisplayModes(void) const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
|
||||
|
||||
virtual void setupContextMenu(QMenu* menu, QObject* receiver, const char* member);
|
||||
virtual bool setEdit(int ModNum);
|
||||
|
||||
/// get called if the user hover over a object in the tree
|
||||
virtual bool allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
/// get called if the user drops some objects
|
||||
virtual void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace AssemblyGui
|
||||
|
||||
|
||||
#endif // ASSEMBLYGUI_ViewProviderProduct_H
|
||||
199
src/Mod/Assembly/Gui/ViewProviderProductRef.cpp
Normal file
199
src/Mod/Assembly/Gui/ViewProviderProductRef.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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_
|
||||
# include <Inventor/nodes/SoGroup.h>
|
||||
#include <QMessageBox>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderProductRef.h"
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Application.h>
|
||||
|
||||
#include <Mod/Assembly/App/Product.h>
|
||||
#include <Mod/Assembly/App/PartRef.h>
|
||||
|
||||
using namespace AssemblyGui;
|
||||
|
||||
extern Assembly::Item* ActiveAsmObject;
|
||||
|
||||
PROPERTY_SOURCE(AssemblyGui::ViewProviderProductRef,AssemblyGui::ViewProviderItem)
|
||||
|
||||
ViewProviderProductRef::ViewProviderProductRef()
|
||||
{
|
||||
sPixmap = "Assembly_Assembly_Tree.svg";
|
||||
}
|
||||
|
||||
ViewProviderProductRef::~ViewProviderProductRef()
|
||||
{
|
||||
if(getObject() == ActiveAsmObject)
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.clearActiveAssembly()");
|
||||
}
|
||||
|
||||
bool ViewProviderProductRef::doubleClicked(void)
|
||||
{
|
||||
Gui::Command::assureWorkbench("AssemblyWorkbench");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().%s)",this->getObject()->getNameInDocument());
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderProductRef::attach(App::DocumentObject* pcFeat)
|
||||
{
|
||||
// call parent attach method
|
||||
ViewProviderGeometryObject::attach(pcFeat);
|
||||
|
||||
|
||||
// putting all together with the switch
|
||||
addDisplayMaskMode(getChildRoot(), "Main");
|
||||
}
|
||||
|
||||
void ViewProviderProductRef::setDisplayMode(const char* ModeName)
|
||||
{
|
||||
if(strcmp("Main",ModeName)==0)
|
||||
setDisplayMaskMode("Main");
|
||||
|
||||
ViewProviderGeometryObject::setDisplayMode(ModeName);
|
||||
}
|
||||
|
||||
std::vector<std::string> ViewProviderProductRef::getDisplayModes(void) const
|
||||
{
|
||||
// get the modes of the father
|
||||
std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
|
||||
|
||||
// add your own modes
|
||||
StrList.push_back("Main");
|
||||
|
||||
return StrList;
|
||||
}
|
||||
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderProductRef::claimChildren(void)const
|
||||
{
|
||||
std::vector<App::DocumentObject*> temp(static_cast<Assembly::Product*>(getObject())->Items.getValues());
|
||||
temp.insert(temp.end(),
|
||||
static_cast<Assembly::Product*>(getObject())->Annotations.getValues().begin(),
|
||||
static_cast<Assembly::Product*>(getObject())->Annotations.getValues().end());
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderProductRef::claimChildren3D(void)const
|
||||
{
|
||||
|
||||
return static_cast<Assembly::Product*>(getObject())->Items.getValues();
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderProductRef::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
ViewProviderItem::setupContextMenu(menu, receiver, member); // call the base class
|
||||
|
||||
QAction* toggle = menu->addAction(QObject::tr("Rigid subassembly"), receiver, member);
|
||||
toggle->setData(QVariant(1000)); // identifier
|
||||
toggle->setCheckable(true);
|
||||
toggle->setToolTip(QObject::tr("Set if the subassembly shall be solved as on part (rigid) or if all parts of this assembly are solved for themselfe."));
|
||||
toggle->setStatusTip(QObject::tr("Set if the subassembly shall be solved as on part (rigid) or if all parts of this assembly are solved for themself."));
|
||||
bool prop = static_cast<Assembly::Product*>(getObject())->Rigid.getValue();
|
||||
toggle->setChecked(prop);
|
||||
}
|
||||
|
||||
bool ViewProviderProductRef::setEdit(int ModNum)
|
||||
{
|
||||
if(ModNum == 1000) { // identifier
|
||||
Gui::Command::openCommand("Change subassembly solving behaviour");
|
||||
if(!static_cast<Assembly::Product*>(getObject())->Rigid.getValue())
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Rigid = True",getObject()->getDocument()->getName(), getObject()->getNameInDocument());
|
||||
else
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Rigid = False",getObject()->getDocument()->getName(), getObject()->getNameInDocument());
|
||||
|
||||
Gui::Command::commitCommand();
|
||||
return false;
|
||||
}
|
||||
return ViewProviderItem::setEdit(ModNum); // call the base class
|
||||
}
|
||||
|
||||
bool ViewProviderProductRef::allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it){
|
||||
//if ((*it)->getTypeId().isDerivedFrom(Part::BodyBase::getClassTypeId())) {
|
||||
// continue;
|
||||
//} else if ((*it)->getTypeId().isDerivedFrom(Assembly::ItemPart::getClassTypeId())) {
|
||||
// continue;
|
||||
//} else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void ViewProviderProductRef::drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
|
||||
{
|
||||
// Open command
|
||||
//Assembly::Product* AsmItem = static_cast<Assembly::Product*>(getObject());
|
||||
//App::Document* doc = AsmItem->getDocument();
|
||||
//Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
|
||||
|
||||
//gui->openCommand("Move into Assembly");
|
||||
//for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it) {
|
||||
// if ((*it)->getTypeId().isDerivedFrom(Part::BodyBase::getClassTypeId())) {
|
||||
// // get document object
|
||||
// const App::DocumentObject* obj = *it;
|
||||
|
||||
// // build Python command for execution
|
||||
// std::string PartName = doc->getUniqueObjectName("Part");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ItemPart','%s')",PartName.c_str());
|
||||
// std::string fatherName = AsmItem->getNameInDocument();
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s] ",fatherName.c_str(),fatherName.c_str(),PartName.c_str());
|
||||
// Gui::Command::addModule(Gui::Command::App,"PartDesign");
|
||||
// Gui::Command::addModule(Gui::Command::Gui,"PartDesignGui");
|
||||
|
||||
|
||||
// std::string BodyName = obj->getNameInDocument();
|
||||
// // add the standard planes
|
||||
// std::string Plane1Name = BodyName + "_PlaneXY";
|
||||
// std::string Plane2Name = BodyName + "_PlaneYZ";
|
||||
// std::string Plane3Name = BodyName + "_PlaneXZ";
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane1Name.c_str());
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'XY-Plane'");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane2Name.c_str());
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'YZ-Plane'");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str());
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'XZ-Plane'");
|
||||
// // add to anotation set of the Part object
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Annotation = [App.activeDocument().%s,App.activeDocument().%s,App.activeDocument().%s] ",PartName.c_str(),Plane1Name.c_str(),Plane2Name.c_str(),Plane3Name.c_str());
|
||||
// // add the main body
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str());
|
||||
|
||||
// } else if ((*it)->getTypeId().isDerivedFrom(Assembly::ItemPart::getClassTypeId())) {
|
||||
// continue;
|
||||
// } else
|
||||
// continue;
|
||||
//
|
||||
//}
|
||||
//gui->commitCommand();
|
||||
|
||||
}
|
||||
69
src/Mod/Assembly/Gui/ViewProviderProductRef.h
Normal file
69
src/Mod/Assembly/Gui/ViewProviderProductRef.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Juergen Riegel <FreeCAD@juergen-riegel.net> *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef ASSEMBLYGUI_ViewProviderProductRef_H
|
||||
#define ASSEMBLYGUI_ViewProviderProductRef_H
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
namespace AssemblyGui {
|
||||
|
||||
class AssemblyGuiExport ViewProviderProductRef : public AssemblyGui::ViewProviderItem
|
||||
{
|
||||
PROPERTY_HEADER(PartGui::ViewProviderProductRef);
|
||||
|
||||
public:
|
||||
/// constructor
|
||||
ViewProviderProductRef();
|
||||
/// destructor
|
||||
virtual ~ViewProviderProductRef();
|
||||
|
||||
virtual bool doubleClicked(void);
|
||||
virtual void attach(App::DocumentObject *);
|
||||
virtual void setDisplayMode(const char* ModeName);
|
||||
/// returns a list of all possible modes
|
||||
virtual std::vector<std::string> getDisplayModes(void) const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
|
||||
|
||||
virtual void setupContextMenu(QMenu* menu, QObject* receiver, const char* member);
|
||||
virtual bool setEdit(int ModNum);
|
||||
|
||||
/// get called if the user hover over a object in the tree
|
||||
virtual bool allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
/// get called if the user drops some objects
|
||||
virtual void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace AssemblyGui
|
||||
|
||||
|
||||
#endif // ASSEMBLYGUI_ViewProviderProductRef_H
|
||||
Reference in New Issue
Block a user