diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt
index e03e21ec05..16f2cfc7c1 100644
--- a/src/App/CMakeLists.txt
+++ b/src/App/CMakeLists.txt
@@ -66,6 +66,7 @@ SET(Document_CPP_SRCS
FeaturePython.cpp
FeatureTest.cpp
GeoFeature.cpp
+ Part.cpp
InventorObject.cpp
MeasureDistance.cpp
Placement.cpp
@@ -93,6 +94,7 @@ SET(Document_HPP_SRCS
FeaturePythonPyImp.inl
FeatureTest.h
GeoFeature.h
+ Part.h
InventorObject.h
MeasureDistance.h
Placement.h
diff --git a/src/App/Part.cpp b/src/App/Part.cpp
new file mode 100644
index 0000000000..7b96015496
--- /dev/null
+++ b/src/App/Part.cpp
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
+ * *
+ * 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 "Part.h"
+//#define new DEBUG_CLIENTBLOCK
+using namespace App;
+
+
+PROPERTY_SOURCE(App::Part, App::GeoFeature)
+
+
+//===========================================================================
+// Feature
+//===========================================================================
+
+Part::Part(void)
+{
+ ADD_PROPERTY(Member,(0));
+}
+
+Part::~Part(void)
+{
+}
+
diff --git a/src/App/Part.h b/src/App/Part.h
new file mode 100644
index 0000000000..933651e231
--- /dev/null
+++ b/src/App/Part.h
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
+ * *
+ * 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 APP_Part_H
+#define APP_Part_H
+
+#include "GeoFeature.h"
+#include "PropertyLinks.h"
+
+
+
+namespace App
+{
+
+
+/** Base class of all geometric document objects.
+ */
+class AppExport Part : public App::GeoFeature
+{
+ PROPERTY_HEADER(App::Part);
+
+public:
+ PropertyLinkList Member;
+
+ /// Constructor
+ Part(void);
+ virtual ~Part();
+
+};
+
+} //namespace App
+
+
+#endif // APP_Part_H
diff --git a/src/Mod/Assembly/App/AppAssembly.cpp b/src/Mod/Assembly/App/AppAssembly.cpp
index aa41ce4ec4..01315d28c0 100644
--- a/src/Mod/Assembly/App/AppAssembly.cpp
+++ b/src/Mod/Assembly/App/AppAssembly.cpp
@@ -31,8 +31,9 @@
#include
#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();
diff --git a/src/Mod/Assembly/App/CMakeLists.txt b/src/Mod/Assembly/App/CMakeLists.txt
index 9ccbdec160..c2076926a9 100644
--- a/src/Mod/Assembly/App/CMakeLists.txt
+++ b/src/Mod/Assembly/App/CMakeLists.txt
@@ -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
diff --git a/src/Mod/Assembly/App/Constraint.cpp b/src/Mod/Assembly/App/Constraint.cpp
index a23c91af19..0875370c44 100644
--- a/src/Mod/Assembly/App/Constraint.cpp
+++ b/src/Mod/Assembly/App/Constraint.cpp
@@ -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 Constraint::initLink(App::PropertyLinkSub& link) {
if(!link.getValue())
return boost::shared_ptr();
- //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();
};
- Assembly::ItemPart* part = static_cast(link.getValue());
+ Assembly::PartRef* part = static_cast(link.getValue());
if(!part)
throw ConstraintPartException();
@@ -147,18 +147,18 @@ boost::shared_ptr 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(First.getValue());
+ part1 = static_cast(First.getValue());
}
if(Second.getValue()) {
m_second_geom = initLink(Second);
- part2= static_cast(Second.getValue());
+ part2= static_cast(Second.getValue());
}
//fix constraint
diff --git a/src/Mod/Assembly/App/Constraint.h b/src/Mod/Assembly/App/Constraint.h
index 1c128d464d..11909f932e 100644
--- a/src/Mod/Assembly/App/Constraint.h
+++ b/src/Mod/Assembly/App/Constraint.h
@@ -31,7 +31,7 @@
#include
#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
diff --git a/src/Mod/Assembly/App/ConstraintGroup.cpp b/src/Mod/Assembly/App/ConstraintGroup.cpp
index 3c79eae421..46d553575a 100644
--- a/src/Mod/Assembly/App/ConstraintGroup.cpp
+++ b/src/Mod/Assembly/App/ConstraintGroup.cpp
@@ -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 obj = Constraints.getValues();
diff --git a/src/Mod/Assembly/App/ConstraintGroup.h b/src/Mod/Assembly/App/ConstraintGroup.h
index 82bf95ac39..06a64b226b 100644
--- a/src/Mod/Assembly/App/ConstraintGroup.h
+++ b/src/Mod/Assembly/App/ConstraintGroup.h
@@ -57,7 +57,7 @@ public:
}
//@}
- void init(Assembly::ItemAssembly* ass);
+ void init(Assembly::Product* ass);
};
} //namespace Assembly
diff --git a/src/Mod/Assembly/App/ItemAssemblyPyImp.cpp b/src/Mod/Assembly/App/ItemAssemblyPyImp.cpp
deleted file mode 100644
index ccbb10a324..0000000000
--- a/src/Mod/Assembly/App/ItemAssemblyPyImp.cpp
+++ /dev/null
@@ -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
-
-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("");
-}
-
-
-PyObject *ItemAssemblyPy::getCustomAttributes(const char* /*attr*/) const
-{
- return 0;
-}
-
-int ItemAssemblyPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
-{
- return 0;
-}
diff --git a/src/Mod/Assembly/App/ItemPartPyImp.cpp b/src/Mod/Assembly/App/ItemPartPyImp.cpp
deleted file mode 100644
index 8d07922487..0000000000
--- a/src/Mod/Assembly/App/ItemPartPyImp.cpp
+++ /dev/null
@@ -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("");
-}
-
-
-
-
-
-
-
-PyObject *ItemPartPy::getCustomAttributes(const char* /*attr*/) const
-{
- return 0;
-}
-
-int ItemPartPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
-{
- return 0;
-}
-
-
diff --git a/src/Mod/Assembly/App/ItemPart.cpp b/src/Mod/Assembly/App/PartRef.cpp
similarity index 84%
rename from src/Mod/Assembly/App/ItemPart.cpp
rename to src/Mod/Assembly/App/PartRef.cpp
index ee3a67d3eb..f9adbbb126 100644
--- a/src/Mod/Assembly/App/ItemPart.cpp
+++ b/src/Mod/Assembly/App/PartRef.cpp
@@ -1,233 +1,233 @@
-/***************************************************************************
- * Copyright (c) 2012 Juergen Riegel *
- * *
- * 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
-#include
-
-#include "ItemPart.h"
-#include "ItemAssembly.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-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(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(Model.getValue());
- const std::vector& 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(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::const_iterator iter;
-
- const std::vector& vector = getInList();
- for(iter it=vector.begin(); it != vector.end(); it++) {
-
- if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId())
- return static_cast(*it);
- };
-
- return (ItemAssembly*)NULL;
-}
-
-void ItemPart::ensureInitialisation() {
-
- ItemAssembly* ass = getParentAssembly();
- if(!ass)
- throw AssemblyItemException();
-
- boost::shared_ptr 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(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 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(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 *
+ * *
+ * 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
+#include
+
+#include "PartRef.h"
+#include "Product.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+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(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(Model.getValue());
+ const std::vector& 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(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::const_iterator iter;
+
+ const std::vector& vector = getInList();
+ for(iter it=vector.begin(); it != vector.end(); it++) {
+
+ if((*it)->getTypeId() == Assembly::Product::getClassTypeId())
+ return static_cast(*it);
+ };
+
+ return (Product*)NULL;
+}
+
+void PartRef::ensureInitialisation() {
+
+ Product* ass = getParentAssembly();
+ if(!ass)
+ throw AssemblyItemException();
+
+ boost::shared_ptr 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(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 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(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;
+}
+
+}
diff --git a/src/Mod/Assembly/App/ItemPart.h b/src/Mod/Assembly/App/PartRef.h
similarity index 91%
rename from src/Mod/Assembly/App/ItemPart.h
rename to src/Mod/Assembly/App/PartRef.h
index dd129e690f..c2f3606edb 100644
--- a/src/Mod/Assembly/App/ItemPart.h
+++ b/src/Mod/Assembly/App/PartRef.h
@@ -1,73 +1,73 @@
-/***************************************************************************
- * Copyright (c) 2012 Juergen Riegel *
- * *
- * 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
-#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 m_part;
- virtual boost::shared_ptr getGeometry3D(const char* Type );
- void setCalculatedPlacement( boost::shared_ptr part );
-};
-
-} //namespace Assembly
-
-
-#endif // Assembly_ItemPart_H
+/***************************************************************************
+ * Copyright (c) 2012 Juergen Riegel *
+ * *
+ * 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
+#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 m_part;
+ virtual boost::shared_ptr getGeometry3D(const char* Type );
+ void setCalculatedPlacement( boost::shared_ptr part );
+};
+
+} //namespace Assembly
+
+
+#endif // Assembly_ItemPart_H
diff --git a/src/Mod/Assembly/App/ItemPartPy.xml b/src/Mod/Assembly/App/PartRefPy.xml
similarity index 80%
rename from src/Mod/Assembly/App/ItemPartPy.xml
rename to src/Mod/Assembly/App/PartRefPy.xml
index 02d47416f9..7b03125805 100644
--- a/src/Mod/Assembly/App/ItemPartPy.xml
+++ b/src/Mod/Assembly/App/PartRefPy.xml
@@ -1,17 +1,17 @@
-
-
-
-
-
- Base class of all objects in Assembly
-
-
-
+
+
+
+
+
+ Base class of all objects in Assembly
+
+
+
diff --git a/src/Mod/Assembly/App/PartRefPyImp.cpp b/src/Mod/Assembly/App/PartRefPyImp.cpp
new file mode 100644
index 0000000000..b2e57bb5bf
--- /dev/null
+++ b/src/Mod/Assembly/App/PartRefPyImp.cpp
@@ -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("");
+}
+
+
+
+
+
+
+
+PyObject *PartRefPy::getCustomAttributes(const char* /*attr*/) const
+{
+ return 0;
+}
+
+int PartRefPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
+{
+ return 0;
+}
+
+
diff --git a/src/Mod/Assembly/App/ItemAssembly.cpp b/src/Mod/Assembly/App/Product.cpp
similarity index 76%
rename from src/Mod/Assembly/App/ItemAssembly.cpp
rename to src/Mod/Assembly/App/Product.cpp
index 121f64a588..c47a36d7f9 100644
--- a/src/Mod/Assembly/App/ItemAssembly.cpp
+++ b/src/Mod/Assembly/App/Product.cpp
@@ -1,346 +1,345 @@
-/***************************************************************************
- * Copyright (c) 2012 Juergen Riegel *
- * *
- * 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
-# include
-#include
-#endif
-
-#include
-#include
-#include
-
-#include "ItemAssembly.h"
-#include "ItemPart.h"
-#include "ConstraintGroup.h"
-#include
-
-
-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 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(new Solver);
- m_downstream_placement = Base::Placement(Base::Vector3(0,0,0), Base::Rotation());
- Base::Placement dummy;
- initSolver(boost::shared_ptr(), dummy, false);
- initConstraints(boost::shared_ptr());
-
-#ifdef ASSEMBLY_DEBUG_FACILITIES
-
- if(ApplyAtFailure.getValue())
- m_solver->setOption(dcm::ApplyResults);
- else
- m_solver->setOption(dcm::IgnoreResults);
-
- m_solver->setOption(Precision.getValue());
- m_solver->setOption(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(e)
- << "raised: " << boost::get_error_info(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 s;
- std::vector obj = Items.getValues();
-
- std::vector::iterator it;
-
- for(it = obj.begin(); it != obj.end(); ++it) {
- if((*it)->getTypeId().isDerivedFrom(Assembly::Item::getClassTypeId())) {
- TopoDS_Shape aShape = static_cast(*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::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::const_iterator iter;
-
- const std::vector& 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::const_iterator iter;
-
- const std::vector& vector = getInList();
-
- for(iter it=vector.begin(); it != vector.end(); it++) {
-
- if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId())
- return static_cast(*it)->getToplevelAssembly();
- };
-
- return this;
-};
-
-ItemAssembly* ItemAssembly::getParentAssembly(ItemPart* part) {
-
- typedef std::vector::const_iterator iter;
-
- const std::vector& 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(*it)->getParentAssembly(part);
-
- if(assembly)
- return assembly;
- }
- };
-
- return (ItemAssembly*)NULL;
-}
-
-
-
-std::pair ItemAssembly::getContainingPart(App::DocumentObject* obj, bool isTop) {
-
- typedef std::vector::const_iterator iter;
-
- const std::vector& vector = Items.getValues();
-
- for(iter it=vector.begin(); it != vector.end(); it++) {
-
- if((*it)->getTypeId() == Assembly::ItemPart::getClassTypeId()) {
- if(static_cast(*it)->holdsObject(obj))
- return std::make_pair(static_cast(*it), this);
- }
- else if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
-
- std::pair part = static_cast(*it)->getContainingPart(obj, false);
-
- if(part.first && part.second) {
-
- if(isTop)
- return part;
- else
- return std::make_pair(part.first, this);
- }
- }
- };
-
- return std::pair(NULL, NULL);
-}
-
-void ItemAssembly::initSolver(boost::shared_ptr 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(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::const_iterator iter;
- const std::vector& vector = Items.getValues();
-
- for(iter it=vector.begin(); it != vector.end(); it++) {
-
- if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) {
-
- static_cast(*it)->initSolver(m_solver, PL_downstream, stopped);
- }
- };
-}
-
-void ItemAssembly::initConstraints(boost::shared_ptr parent) {
-
-
-
- //get the constraint group and init the constraints
- typedef std::vector::const_iterator iter;
-
- const std::vector& vector = Annotations.getValues();
-
- for(iter it=vector.begin(); it != vector.end(); it++) {
-
- if((*it)->getTypeId() == Assembly::ConstraintGroup::getClassTypeId())
- static_cast(*it)->init(this);
- };
-
- // iterate down as long as a non-rigid subsystem exists
- const std::vector& vector2 = Items.getValues();
-
- for(iter it=vector2.begin(); it != vector2.end(); it++) {
-
- if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId())
- static_cast(*it)->initConstraints(m_solver);
-
- };
-
-};
-
-//the callback for the recalculated signal
-void ItemAssembly::finish(boost::shared_ptr subsystem) {
-
- //assert(subsystem == m_solver);
- Base::Placement p = m_solver->getTransformation();
- this->Placement.setValue(m_downstream_placement.inverse()*p);
-};
-
-} //assembly
-
-
-
+/***************************************************************************
+ * Copyright (c) 2012 Juergen Riegel *
+ * *
+ * 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
+# include
+#include
+#endif
+
+#include
+#include
+#include
+
+#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 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(new Solver);
+ m_downstream_placement = Base::Placement(Base::Vector3(0,0,0), Base::Rotation());
+ Base::Placement dummy;
+ initSolver(boost::shared_ptr(), dummy, false);
+ initConstraints(boost::shared_ptr());
+
+#ifdef ASSEMBLY_DEBUG_FACILITIES
+
+ if(ApplyAtFailure.getValue())
+ m_solver->setOption(dcm::ApplyResults);
+ else
+ m_solver->setOption(dcm::IgnoreResults);
+
+ m_solver->setOption(Precision.getValue());
+ m_solver->setOption(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(e)
+ << "raised: " << boost::get_error_info(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 s;
+ std::vector obj = Items.getValues();
+
+ std::vector::iterator it;
+
+ for(it = obj.begin(); it != obj.end(); ++it) {
+ if((*it)->getTypeId().isDerivedFrom(Assembly::Item::getClassTypeId())) {
+ TopoDS_Shape aShape = static_cast(*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::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::const_iterator iter;
+
+ const std::vector& 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::const_iterator iter;
+
+ const std::vector& vector = getInList();
+
+ for(iter it=vector.begin(); it != vector.end(); it++) {
+
+ if((*it)->getTypeId() == Assembly::Product::getClassTypeId())
+ return static_cast(*it)->getToplevelAssembly();
+ };
+
+ return this;
+};
+
+Product* Product::getParentAssembly(PartRef* part) {
+
+ typedef std::vector::const_iterator iter;
+
+ const std::vector& 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(*it)->getParentAssembly(part);
+
+ if(assembly)
+ return assembly;
+ }
+ };
+
+ return (Product*)NULL;
+}
+
+
+
+std::pair Product::getContainingPart(App::DocumentObject* obj, bool isTop) {
+
+ typedef std::vector::const_iterator iter;
+
+ const std::vector& vector = Items.getValues();
+
+ for(iter it=vector.begin(); it != vector.end(); it++) {
+
+ if((*it)->getTypeId() == Assembly::PartRef::getClassTypeId()) {
+ if(static_cast(*it)->holdsObject(obj))
+ return std::make_pair(static_cast(*it), this);
+ }
+ else if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
+
+ std::pair part = static_cast(*it)->getContainingPart(obj, false);
+
+ if(part.first && part.second) {
+
+ if(isTop)
+ return part;
+ else
+ return std::make_pair(part.first, this);
+ }
+ }
+ };
+
+ return std::pair(NULL, NULL);
+}
+
+void Product::initSolver(boost::shared_ptr 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(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::const_iterator iter;
+ const std::vector& vector = Items.getValues();
+
+ for(iter it=vector.begin(); it != vector.end(); it++) {
+
+ if((*it)->getTypeId() == Assembly::Product::getClassTypeId()) {
+
+ static_cast(*it)->initSolver(m_solver, PL_downstream, stopped);
+ }
+ };
+}
+
+void Product::initConstraints(boost::shared_ptr parent) {
+
+
+
+ //get the constraint group and init the constraints
+ typedef std::vector::const_iterator iter;
+
+ const std::vector& vector = Annotations.getValues();
+
+ for(iter it=vector.begin(); it != vector.end(); it++) {
+
+ if((*it)->getTypeId() == Assembly::ConstraintGroup::getClassTypeId())
+ static_cast(*it)->init(this);
+ };
+
+ // iterate down as long as a non-rigid subsystem exists
+ const std::vector& vector2 = Items.getValues();
+
+ for(iter it=vector2.begin(); it != vector2.end(); it++) {
+
+ if((*it)->getTypeId() == Assembly::Product::getClassTypeId())
+ static_cast(*it)->initConstraints(m_solver);
+
+ };
+
+};
+
+//the callback for the recalculated signal
+void Product::finish(boost::shared_ptr subsystem) {
+
+ //assert(subsystem == m_solver);
+ Base::Placement p = m_solver->getTransformation();
+ this->Placement.setValue(m_downstream_placement.inverse()*p);
+};
+
+} //assembly
+
+
+
diff --git a/src/Mod/Assembly/App/ItemAssembly.h b/src/Mod/Assembly/App/Product.h
similarity index 81%
rename from src/Mod/Assembly/App/ItemAssembly.h
rename to src/Mod/Assembly/App/Product.h
index 7d380ea509..e4dab7bd04 100644
--- a/src/Mod/Assembly/App/ItemAssembly.h
+++ b/src/Mod/Assembly/App/Product.h
@@ -1,102 +1,102 @@
-/***************************************************************************
- * Copyright (c) 2012 Juergen Riegel *
- * *
- * 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
-
-#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 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 parent);
-
- //read the downstream itemassemblys and set their placement to the propertyplacement
- void finish(boost::shared_ptr subsystem);
-
- boost::shared_ptr 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 *
+ * *
+ * 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
+
+#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 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 parent);
+
+ //read the downstream itemassemblys and set their placement to the propertyplacement
+ void finish(boost::shared_ptr subsystem);
+
+ boost::shared_ptr 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
diff --git a/src/Mod/Assembly/App/ProductRef.cpp b/src/Mod/Assembly/App/ProductRef.cpp
new file mode 100644
index 0000000000..f6df9f5780
--- /dev/null
+++ b/src/Mod/Assembly/App/ProductRef.cpp
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (c) 2012 Juergen Riegel *
+ * *
+ * 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
+# include
+#include
+#endif
+
+#include
+#include
+#include
+
+#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
+
+
+
diff --git a/src/Mod/Assembly/App/ProductRef.h b/src/Mod/Assembly/App/ProductRef.h
new file mode 100644
index 0000000000..0261b65c4b
--- /dev/null
+++ b/src/Mod/Assembly/App/ProductRef.h
@@ -0,0 +1,71 @@
+/***************************************************************************
+ * Copyright (c) 2012 Juergen Riegel *
+ * *
+ * 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
+
+#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(NULL, NULL);}
+
+
+};
+
+} //namespace Assembly
+
+
+#endif // Assembly_ProductRef_H
diff --git a/src/Mod/Assembly/App/ItemAssemblyPy.xml b/src/Mod/Assembly/App/ProductRefPy.xml
similarity index 78%
rename from src/Mod/Assembly/App/ItemAssemblyPy.xml
rename to src/Mod/Assembly/App/ProductRefPy.xml
index e2f560946e..ba3bb3d8f6 100644
--- a/src/Mod/Assembly/App/ItemAssemblyPy.xml
+++ b/src/Mod/Assembly/App/ProductRefPy.xml
@@ -1,17 +1,17 @@
-
-
-
-
-
- Base class of all objects in Assembly
-
-
-
+
+
+
+
+
+ Base class of all objects in Assembly
+
+
+
diff --git a/src/Mod/Assembly/App/ProductRefPyImp.cpp b/src/Mod/Assembly/App/ProductRefPyImp.cpp
new file mode 100644
index 0000000000..d9c2ac2caa
--- /dev/null
+++ b/src/Mod/Assembly/App/ProductRefPyImp.cpp
@@ -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
+
+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("");
+}
+
+
+PyObject *ProductRefPy::getCustomAttributes(const char* /*attr*/) const
+{
+ return 0;
+}
+
+int ProductRefPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
+{
+ return 0;
+}
diff --git a/src/Mod/Assembly/Gui/AppAssemblyGui.cpp b/src/Mod/Assembly/Gui/AppAssemblyGui.cpp
index 20b57682f0..3d1143dc01 100644
--- a/src/Mod/Assembly/Gui/AppAssemblyGui.cpp
+++ b/src/Mod/Assembly/Gui/AppAssemblyGui.cpp
@@ -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
+#include
+#include
//#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();
diff --git a/src/Mod/Assembly/Gui/CMakeLists.txt b/src/Mod/Assembly/Gui/CMakeLists.txt
index 757d1245b2..fa9dd26480 100644
--- a/src/Mod/Assembly/Gui/CMakeLists.txt
+++ b/src/Mod/Assembly/Gui/CMakeLists.txt
@@ -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
diff --git a/src/Mod/Assembly/Gui/Command.cpp b/src/Mod/Assembly/Gui/Command.cpp
index f05089f1b7..11ad237370 100644
--- a/src/Mod/Assembly/Gui/Command.cpp
+++ b/src/Mod/Assembly/Gui/Command.cpp
@@ -33,7 +33,7 @@
#include
#include
-#include
+#include
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 Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
- dest = dynamic_cast(Sel.front());
- }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
- dest = dynamic_cast(ActiveAsmObject);
+ std::vector Sel = getSelection().getObjectsOfType(Assembly::Product::getClassTypeId());
+ dest = dynamic_cast(Sel.front());
+ }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
+ dest = dynamic_cast(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 Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
- dest = dynamic_cast(Sel.front());
- }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
- dest = dynamic_cast(ActiveAsmObject);
+ std::vector Sel = getSelection().getObjectsOfType(Assembly::Product::getClassTypeId());
+ dest = dynamic_cast(Sel.front());
+ }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
+ dest = dynamic_cast(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 Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
- dest = dynamic_cast(Sel.front());
- }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
- dest = dynamic_cast(ActiveAsmObject);
+ std::vector Sel = getSelection().getObjectsOfType(Assembly::Product::getClassTypeId());
+ dest = dynamic_cast(Sel.front());
+ }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
+ dest = dynamic_cast(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 Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
- dest = dynamic_cast(Sel.front());
- }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
- dest = dynamic_cast(ActiveAsmObject);
+ std::vector Sel = getSelection().getObjectsOfType(Assembly::Product::getClassTypeId());
+ dest = dynamic_cast(Sel.front());
+ }else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
+ dest = dynamic_cast(ActiveAsmObject);
}
// asking for file name (only step at the moment)
diff --git a/src/Mod/Assembly/Gui/CommandConstraints.cpp b/src/Mod/Assembly/Gui/CommandConstraints.cpp
index 7425979654..2f17a08f47 100644
--- a/src/Mod/Assembly/Gui/CommandConstraints.cpp
+++ b/src/Mod/Assembly/Gui/CommandConstraints.cpp
@@ -36,8 +36,9 @@
#include
#include
-#include
-#include
+#include
+#include
+#include
#include
#include
@@ -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(ActiveAsmObject);
+ *Asm = static_cast(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 objs = Gui::Selection().getSelectionEx();
+ //std::vector 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 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 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 objs = Gui::Selection().getSelectionEx();
+ //std::vector 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 part1 = Asm->getContainingPart(objs[0].getObject());
- std::pair part2 = Asm->getContainingPart(objs[1].getObject());
+ //std::pair part1 = Asm->getContainingPart(objs[0].getObject());
+ //std::pair 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 objs = Gui::Selection().getSelectionEx();
+ //std::vector 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 part = Asm->getContainingPart(objs[0].getObject());
+ //std::pair 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 objs = Gui::Selection().getSelectionEx();
+ //std::vector 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 part1 = Asm->getContainingPart(objs[0].getObject());
- std::pair part2 = Asm->getContainingPart(objs[1].getObject());
+ //std::pair part1 = Asm->getContainingPart(objs[0].getObject());
+ //std::pair