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 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 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 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 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 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 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 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) diff --git a/src/Mod/Assembly/Gui/TaskAssemblyConstraints.cpp b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.cpp index 002cc508a7..91a2205648 100644 --- a/src/Mod/Assembly/Gui/TaskAssemblyConstraints.cpp +++ b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.cpp @@ -32,7 +32,7 @@ #include "TaskAssemblyConstraints.h" #include -#include +#include #include #include @@ -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(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(obj->First.getValue())->getParentAssembly(); + ass = dynamic_cast(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(obj->Second.getValue())->getParentAssembly(); + ass = dynamic_cast(obj->Second.getValue())->getParentAssembly(); }; if(ass) @@ -249,13 +249,13 @@ void TaskAssemblyConstraints::onSelectionChanged(const Gui::SelectionChanges& ms std::vector objs = Gui::Selection().getSelectionEx(); Assembly::Constraint* con = dynamic_cast(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 part1 = static_cast(ActiveAsmObject)->getContainingPart(objs.back().getObject()); + std::pair part1 = static_cast(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 objs = Gui::Selection().getSelectionEx(); Assembly::Constraint* con = dynamic_cast(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 part2 = static_cast(ActiveAsmObject)->getContainingPart(objs.back().getObject()); + std::pair part2 = static_cast(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(obj->First.getValue()); + Assembly::PartRef* p1 = dynamic_cast(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 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(obj->Second.getValue()); + Assembly::PartRef* p2 = dynamic_cast(obj->Second.getValue()); if(!p2) return; @@ -498,12 +498,12 @@ void TaskAssemblyConstraints::setPossibleConstraints() if(obj->First.getValue()) { - Assembly::ItemPart* p1 = dynamic_cast(obj->First.getValue()); + Assembly::PartRef* p1 = dynamic_cast(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 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(obj->Second.getValue()); + Assembly::PartRef* p2 = dynamic_cast(obj->Second.getValue()); if(!p2) return; diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp deleted file mode 100644 index 8bf5f2e972..0000000000 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2011 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 -#endif - -#include "ViewProviderAssembly.h" -#include -#include -#include -#include - -#include -#include -#include - -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 ViewProviderItemAssembly::getDisplayModes(void) const -{ - // get the modes of the father - std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); - - // add your own modes - StrList.push_back("Main"); - - return StrList; -} - - -std::vector ViewProviderItemAssembly::claimChildren(void)const -{ - std::vector temp(static_cast(getObject())->Items.getValues()); - temp.insert(temp.end(), - static_cast(getObject())->Annotations.getValues().begin(), - static_cast(getObject())->Annotations.getValues().end()); - - return temp; -} - -std::vector ViewProviderItemAssembly::claimChildren3D(void)const -{ - - return static_cast(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(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(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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) -{ - for( std::vector::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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) -{ - // Open command - Assembly::ItemAssembly* AsmItem = static_cast(getObject()); - App::Document* doc = AsmItem->getDocument(); - Gui::Document* gui = Gui::Application::Instance->getDocument(doc); - - gui->openCommand("Move into Assembly"); - for( std::vector::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(); - -} \ No newline at end of file diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp index 4a0e1c3adb..be87043555 100644 --- a/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp @@ -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 #include #include @@ -262,7 +262,7 @@ void ViewProviderConstraint::draw() if(!obj1) return; - Assembly::ItemPart* part1 = static_cast(obj1); + Assembly::PartRef* part1 = static_cast(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(obj2); + Assembly::PartRef* part2 = static_cast(obj2); if(!part2) return; @@ -321,13 +321,13 @@ void ViewProviderConstraint::upstream_placement(Base::Placement& p, Assembly::It typedef std::vector::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& 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(*it)); + upstream_placement(p, static_cast(*it)); return; } }; @@ -361,7 +361,7 @@ TopoDS_Shape ViewProviderConstraint::getConstraintShape(int link) if(!obj1) return TopoDS_Shape(); - Assembly::ItemPart* part1 = static_cast(obj1); + Assembly::PartRef* part1 = static_cast(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(obj2); + Assembly::PartRef* part2 = static_cast(obj2); if(!part2) return TopoDS_Shape(); diff --git a/src/Mod/Assembly/Gui/ViewProviderPart.cpp b/src/Mod/Assembly/Gui/ViewProviderPartRef.cpp similarity index 81% rename from src/Mod/Assembly/Gui/ViewProviderPart.cpp rename to src/Mod/Assembly/Gui/ViewProviderPartRef.cpp index 583c57bb63..2379135384 100644 --- a/src/Mod/Assembly/Gui/ViewProviderPart.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderPartRef.cpp @@ -1,289 +1,289 @@ -/*************************************************************************** - * Copyright (c) 2011 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 -#include -#endif - -#include "ViewProviderPart.h" -//#include -//#include -#include -#include - -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 ViewProviderItemPart::getDisplayModes(void) const -{ - // get the modes of the father - std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); - - // add your own modes - StrList.push_back("Main"); - - return StrList; -} - -std::vector ViewProviderItemPart::claimChildren(void)const -{ - std::vector res; - - res.insert(res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); - - if(static_cast(getObject())->Model.getValue()) - res.push_back(static_cast(getObject())->Model.getValue()); - - return res; - -} - -std::vector ViewProviderItemPart::claimChildren3D(void)const -{ - std::vector res; - - res.insert(res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); - - if(static_cast(getObject())->Model.getValue()) - res.push_back(static_cast(getObject())->Model.getValue()); - - return res; - -} - -bool ViewProviderItemPart::allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) -{ - //for( std::vector::const_iterator it = objList.begin();it!=objList.end();++it) - // if ((*it)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) { - // if (static_cast(getObject())->isChildOf( - // static_cast(*it))) { - // return false; - // } - // } - - return false; -} -void ViewProviderItemPart::drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) -{ - //// Open command - //App::DocumentObjectGroup* grp = static_cast(getObject()); - //App::Document* doc = grp->getDocument(); - //Gui::Document* gui = Gui::Application::Instance->getDocument(doc); - //gui->openCommand("Move object"); - //for( std::vector::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 part = static_cast(getObject())->m_part; - - if(!part) { - ViewProviderItem::onChanged(prop); - return; - } - - dcm::detail::Transform transform = part->m_cluster->getProperty::math_prop>().m_transform; - dcm::detail::Transform ssrTransform = part->m_cluster->getProperty::math_prop>().m_ssrTransform; - - dcm::detail::Transform trans = ssrTransform.inverse(); - - int PseudoSize = part->m_cluster->getProperty::math_prop>().m_pseudo.size(); - typedef dcm::details::ClusterMath::Vec Vector; - Vector& pv = part->m_cluster->getProperty::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 g = part->m_cluster->getProperty::math_prop>().m_geometry[0]; - - std::stringstream str; - - str<<"Global: "<m_global.transpose()<getPoint()).transpose()<m_global.head(3); - - str<<"Local Point : "<<(transform.inverse()*v).transpose()<getPoint()).transpose()<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 * + * * + * 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 +#include +#endif + +#include "ViewProviderPartRef.h" +//#include +//#include +#include +#include + +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 ViewProviderPartRef::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); + + // add your own modes + StrList.push_back("Main"); + + return StrList; +} + +std::vector ViewProviderPartRef::claimChildren(void)const +{ + std::vector res; + + res.insert(res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); + + if(static_cast(getObject())->Model.getValue()) + res.push_back(static_cast(getObject())->Model.getValue()); + + return res; + +} + +std::vector ViewProviderPartRef::claimChildren3D(void)const +{ + std::vector res; + + res.insert(res.end(), static_cast(getObject())->Annotation.getValues().begin(),static_cast(getObject())->Annotation.getValues().end()); + + if(static_cast(getObject())->Model.getValue()) + res.push_back(static_cast(getObject())->Model.getValue()); + + return res; + +} + +bool ViewProviderPartRef::allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + //for( std::vector::const_iterator it = objList.begin();it!=objList.end();++it) + // if ((*it)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) { + // if (static_cast(getObject())->isChildOf( + // static_cast(*it))) { + // return false; + // } + // } + + return false; +} +void ViewProviderPartRef::drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + //// Open command + //App::DocumentObjectGroup* grp = static_cast(getObject()); + //App::Document* doc = grp->getDocument(); + //Gui::Document* gui = Gui::Application::Instance->getDocument(doc); + //gui->openCommand("Move object"); + //for( std::vector::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 part = static_cast(getObject())->m_part; + + if(!part) { + ViewProviderItem::onChanged(prop); + return; + } + + dcm::detail::Transform transform = part->m_cluster->getProperty::math_prop>().m_transform; + dcm::detail::Transform ssrTransform = part->m_cluster->getProperty::math_prop>().m_ssrTransform; + + dcm::detail::Transform trans = ssrTransform.inverse(); + + int PseudoSize = part->m_cluster->getProperty::math_prop>().m_pseudo.size(); + typedef dcm::details::ClusterMath::Vec Vector; + Vector& pv = part->m_cluster->getProperty::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 g = part->m_cluster->getProperty::math_prop>().m_geometry[0]; + + std::stringstream str; + + str<<"Global: "<m_global.transpose()<getPoint()).transpose()<m_global.head(3); + + str<<"Local Point : "<<(transform.inverse()*v).transpose()<getPoint()).transpose()<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 diff --git a/src/Mod/Assembly/Gui/ViewProviderPart.h b/src/Mod/Assembly/Gui/ViewProviderPartRef.h similarity index 88% rename from src/Mod/Assembly/Gui/ViewProviderPart.h rename to src/Mod/Assembly/Gui/ViewProviderPartRef.h index 2f26a67d8c..78fc6513bc 100644 --- a/src/Mod/Assembly/Gui/ViewProviderPart.h +++ b/src/Mod/Assembly/Gui/ViewProviderPartRef.h @@ -1,82 +1,82 @@ -/*************************************************************************** - * Copyright (c) 2011 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 ASSEMBLYGUI_ViewProviderPart_H -#define ASSEMBLYGUI_ViewProviderPart_H - -#include "ViewProvider.h" -#include -#include -#include -#include -#include - - -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 getDisplayModes(void) const; - - virtual std::vector claimChildren(void)const; - - virtual std::vector claimChildren3D(void)const; - - /// get called if the user hover over a object in the tree - virtual bool allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); - /// get called if the user drops some objects - virtual void drop(const std::vector &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 * + * * + * 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 +#include +#include +#include +#include + + +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 getDisplayModes(void) const; + + virtual std::vector claimChildren(void)const; + + virtual std::vector claimChildren3D(void)const; + + /// get called if the user hover over a object in the tree + virtual bool allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + /// get called if the user drops some objects + virtual void drop(const std::vector &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 diff --git a/src/Mod/Assembly/Gui/ViewProviderProduct.cpp b/src/Mod/Assembly/Gui/ViewProviderProduct.cpp new file mode 100644 index 0000000000..5f71b75e9a --- /dev/null +++ b/src/Mod/Assembly/Gui/ViewProviderProduct.cpp @@ -0,0 +1,200 @@ +/*************************************************************************** + * Copyright (c) 2011 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 +#endif + +#include "ViewProviderProduct.h" +#include +#include +#include +#include + +#include +#include +//#include + +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 ViewProviderProduct::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); + + // add your own modes + StrList.push_back("Main"); + + return StrList; +} + + +std::vector ViewProviderProduct::claimChildren(void)const +{ + std::vector temp(static_cast(getObject())->Items.getValues()); + temp.insert(temp.end(), + static_cast(getObject())->Annotations.getValues().begin(), + static_cast(getObject())->Annotations.getValues().end()); + + return temp; +} + +std::vector ViewProviderProduct::claimChildren3D(void)const +{ + + return static_cast(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(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(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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + for( std::vector::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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + // Open command + //Assembly::Product* AsmItem = static_cast(getObject()); + //App::Document* doc = AsmItem->getDocument(); + //Gui::Document* gui = Gui::Application::Instance->getDocument(doc); + + //gui->openCommand("Move into Assembly"); + //for( std::vector::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(); + +} \ No newline at end of file diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.h b/src/Mod/Assembly/Gui/ViewProviderProduct.h similarity index 86% rename from src/Mod/Assembly/Gui/ViewProviderAssembly.h rename to src/Mod/Assembly/Gui/ViewProviderProduct.h index 27e9b0c80a..c9644cd245 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.h +++ b/src/Mod/Assembly/Gui/ViewProviderProduct.h @@ -1,69 +1,69 @@ -/*************************************************************************** - * Copyright (c) 2011 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 ASSEMBLYGUI_ViewProviderAssembly_H -#define ASSEMBLYGUI_ViewProviderAssembly_H - -#include "ViewProvider.h" -#include -#include - - -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 getDisplayModes(void) const; - - virtual std::vector claimChildren(void)const; - - virtual std::vector 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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); - /// get called if the user drops some objects - virtual void drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); - -}; - - - -} // namespace AssemblyGui - - -#endif // ASSEMBLYGUI_ViewProviderAssembly_H +/*************************************************************************** + * Copyright (c) 2011 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 ASSEMBLYGUI_ViewProviderProduct_H +#define ASSEMBLYGUI_ViewProviderProduct_H + +#include "ViewProvider.h" +#include +#include + + +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 getDisplayModes(void) const; + + virtual std::vector claimChildren(void)const; + + virtual std::vector 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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + /// get called if the user drops some objects + virtual void drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + +}; + + + +} // namespace AssemblyGui + + +#endif // ASSEMBLYGUI_ViewProviderProduct_H diff --git a/src/Mod/Assembly/Gui/ViewProviderProductRef.cpp b/src/Mod/Assembly/Gui/ViewProviderProductRef.cpp new file mode 100644 index 0000000000..4bd787523e --- /dev/null +++ b/src/Mod/Assembly/Gui/ViewProviderProductRef.cpp @@ -0,0 +1,199 @@ +/*************************************************************************** + * Copyright (c) 2011 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 +#endif + +#include "ViewProviderProductRef.h" +#include +#include +#include +#include + +#include +#include + +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 ViewProviderProductRef::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); + + // add your own modes + StrList.push_back("Main"); + + return StrList; +} + + +std::vector ViewProviderProductRef::claimChildren(void)const +{ + std::vector temp(static_cast(getObject())->Items.getValues()); + temp.insert(temp.end(), + static_cast(getObject())->Annotations.getValues().begin(), + static_cast(getObject())->Annotations.getValues().end()); + + return temp; +} + +std::vector ViewProviderProductRef::claimChildren3D(void)const +{ + + return static_cast(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(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(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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + for( std::vector::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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) +{ + // Open command + //Assembly::Product* AsmItem = static_cast(getObject()); + //App::Document* doc = AsmItem->getDocument(); + //Gui::Document* gui = Gui::Application::Instance->getDocument(doc); + + //gui->openCommand("Move into Assembly"); + //for( std::vector::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(); + +} \ No newline at end of file diff --git a/src/Mod/Assembly/Gui/ViewProviderProductRef.h b/src/Mod/Assembly/Gui/ViewProviderProductRef.h new file mode 100644 index 0000000000..cd73902a96 --- /dev/null +++ b/src/Mod/Assembly/Gui/ViewProviderProductRef.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (c) 2014 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 ASSEMBLYGUI_ViewProviderProductRef_H +#define ASSEMBLYGUI_ViewProviderProductRef_H + +#include "ViewProvider.h" +#include +#include + + +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 getDisplayModes(void) const; + + virtual std::vector claimChildren(void)const; + + virtual std::vector 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 &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + /// get called if the user drops some objects + virtual void drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); + +}; + + + +} // namespace AssemblyGui + + +#endif // ASSEMBLYGUI_ViewProviderProductRef_H diff --git a/src/Mod/Import/App/CMakeLists.txt b/src/Mod/Import/App/CMakeLists.txt index 4c4bf89e22..6e89fe0ab7 100644 --- a/src/Mod/Import/App/CMakeLists.txt +++ b/src/Mod/Import/App/CMakeLists.txt @@ -54,6 +54,10 @@ SET(SCL_Resources SCL/SimpleDataTypes.py SCL/TypeChecker.py SCL/Utils.py + SCL/SimpleReader.py + SCL/Aufspannung.stp + SCL/gasket1.p21 + SCL/Product1.stp automotive_design.py # AP214e3 ifc2x3.py # IFC ifc4.py # IFC 4 diff --git a/src/Mod/Import/App/ImportOCAFAssembly.cpp b/src/Mod/Import/App/ImportOCAFAssembly.cpp index 1ca855172e..9a30a5ad64 100644 --- a/src/Mod/Import/App/ImportOCAFAssembly.cpp +++ b/src/Mod/Import/App/ImportOCAFAssembly.cpp @@ -142,7 +142,7 @@ void ImportOCAFAssembly::loadShapes(const TDF_Label& label, const TopLoc_Locatio if( !hLoc.IsNull() ) s = hLoc->Get().IsIdentity()?"0":"1"; else - s = "-1"; + s = "0"; std::stringstream str; diff --git a/src/Mod/Import/App/SCL/Product1.stp b/src/Mod/Import/App/SCL/Product1.stp new file mode 100644 index 0000000000..56862098f5 --- /dev/null +++ b/src/Mod/Import/App/SCL/Product1.stp @@ -0,0 +1,204 @@ +ISO-10303-21; +HEADER; +FILE_DESCRIPTION(('CATIA V5 STEP Exchange'),'2;1'); + +FILE_NAME('C:\\Users\\jriegel\\Dokumente\\FreeCAD\\AssemblyDesign\\Product1.stp','2014-05-01T15:58:05+00:00',('none'),('none'),'CATIA Version 5 Release 19 SP 3 (IN-10)','CATIA V5 STEP AP203','none'); + +FILE_SCHEMA(('CONFIG_CONTROL_DESIGN')); + +ENDSEC; +/* file written by CATIA V5R19 */ +DATA; +#5=PRODUCT('Product1','','',(#2)) ; +#56=PRODUCT('Product2','','',(#2)) ; +#64=PRODUCT('Part1','','',(#2)) ; +#1=APPLICATION_CONTEXT('configuration controlled 3D design of mechanical parts and assemblies') ; +#17=PRODUCT_DEFINITION('',' ',#6,#3) ; +#58=PRODUCT_DEFINITION('',' ',#57,#3) ; +#19=SECURITY_CLASSIFICATION(' ',' ',#18) ; +#18=SECURITY_CLASSIFICATION_LEVEL('unclassified') ; +#71=CARTESIAN_POINT('Axis2P3D Location',(0.,0.,10.)) ; +#76=CARTESIAN_POINT('Line Origine',(50.,0.,10.)) ; +#80=CARTESIAN_POINT('Vertex',(50.,0.,0.)) ; +#82=CARTESIAN_POINT('Vertex',(50.,0.,20.)) ; +#85=CARTESIAN_POINT('Axis2P3D Location',(0.,0.,0.)) ; +#89=CARTESIAN_POINT('Vertex',(-50.,6.12303176911E-015,0.)) ; +#92=CARTESIAN_POINT('Line Origine',(-50.,6.12303176911E-015,10.)) ; +#96=CARTESIAN_POINT('Vertex',(-50.,6.12303176911E-015,20.)) ; +#99=CARTESIAN_POINT('Axis2P3D Location',(0.,0.,20.)) ; +#111=CARTESIAN_POINT('Axis2P3D Location',(0.,0.,0.)) ; +#116=CARTESIAN_POINT('Axis2P3D Location',(0.,0.,20.)) ; +#128=CARTESIAN_POINT('Axis2P3D Location',(0.,0.,0.)) ; +#138=CARTESIAN_POINT('Axis2P3D Location',(0.,0.,20.)) ; +#158=CARTESIAN_POINT('NONE',(0.,0.,0.)) ; +#159=CARTESIAN_POINT('NONE',(0.,0.,0.)) ; +#171=CARTESIAN_POINT('NONE',(0.,0.,0.)) ; +#172=CARTESIAN_POINT('NONE',(-29.8427658081,121.893280644,10.1572341919)) ; +#186=CARTESIAN_POINT('NONE',(0.,0.,0.)) ; +#187=CARTESIAN_POINT('NONE',(0.,0.,0.)) ; +#72=DIRECTION('Axis2P3D Direction',(0.,0.,1.)) ; +#73=DIRECTION('Axis2P3D XDirection',(1.,0.,0.)) ; +#77=DIRECTION('Vector Direction',(0.,0.,1.)) ; +#86=DIRECTION('Axis2P3D Direction',(0.,0.,1.)) ; +#93=DIRECTION('Vector Direction',(0.,0.,1.)) ; +#100=DIRECTION('Axis2P3D Direction',(0.,0.,1.)) ; +#112=DIRECTION('Axis2P3D Direction',(0.,0.,1.)) ; +#117=DIRECTION('Axis2P3D Direction',(0.,0.,1.)) ; +#129=DIRECTION('Axis2P3D Direction',(0.,0.,1.)) ; +#130=DIRECTION('Axis2P3D XDirection',(1.,0.,0.)) ; +#139=DIRECTION('Axis2P3D Direction',(0.,0.,1.)) ; +#140=DIRECTION('Axis2P3D XDirection',(1.,0.,0.)) ; +#160=DIRECTION('NONE',(1.,0.,0.)) ; +#161=DIRECTION('NONE',(0.,0.,1.)) ; +#162=DIRECTION('NONE',(1.,0.,0.)) ; +#163=DIRECTION('NONE',(0.,0.,1.)) ; +#173=DIRECTION('NONE',(1.,0.,0.)) ; +#174=DIRECTION('NONE',(0.,0.,1.)) ; +#175=DIRECTION('NONE',(-3.78169717763E-016,0.,-1.)) ; +#176=DIRECTION('NONE',(1.,0.,2.42861286637E-017)) ; +#188=DIRECTION('NONE',(1.,0.,0.)) ; +#189=DIRECTION('NONE',(0.,0.,1.)) ; +#190=DIRECTION('NONE',(1.,0.,0.)) ; +#191=DIRECTION('NONE',(0.,0.,1.)) ; +#74=AXIS2_PLACEMENT_3D('Cylinder Axis2P3D',#71,#72,#73) ; +#87=AXIS2_PLACEMENT_3D('Circle Axis2P3D',#85,#86,$) ; +#101=AXIS2_PLACEMENT_3D('Circle Axis2P3D',#99,#100,$) ; +#113=AXIS2_PLACEMENT_3D('Circle Axis2P3D',#111,#112,$) ; +#118=AXIS2_PLACEMENT_3D('Circle Axis2P3D',#116,#117,$) ; +#131=AXIS2_PLACEMENT_3D('Plane Axis2P3D',#128,#129,#130) ; +#141=AXIS2_PLACEMENT_3D('Plane Axis2P3D',#138,#139,#140) ; +#156=AXIS2_PLACEMENT_3D(' ',#159,#163,#162) ; +#157=AXIS2_PLACEMENT_3D(' ',#158,#161,#160) ; +#169=AXIS2_PLACEMENT_3D(' ',#172,#176,#175) ; +#170=AXIS2_PLACEMENT_3D(' ',#171,#174,#173) ; +#184=AXIS2_PLACEMENT_3D(' ',#187,#191,#190) ; +#185=AXIS2_PLACEMENT_3D(' ',#186,#189,#188) ; +#45=PRODUCT_DEFINITION_SHAPE(' ',' ',#17) ; +#59=PRODUCT_DEFINITION_SHAPE(' ',' ',#58) ; +#69=PRODUCT_DEFINITION_SHAPE(' ',' ',#66) ; +#152=PRODUCT_DEFINITION_SHAPE(' ',' ',#151) ; +#165=PRODUCT_DEFINITION_SHAPE(' ',' ',#164) ; +#180=PRODUCT_DEFINITION_SHAPE(' ',' ',#179) ; +#34=APPROVAL_PERSON_ORGANIZATION(#28,#24,#22) ; +#28=PERSON_AND_ORGANIZATION(#25,#26) ; +#25=PERSON(' ',' ',' ',$,$,$) ; +#26=ORGANIZATION(' ',' ',' ') ; +#24=APPROVAL(#23,' ') ; +#23=APPROVAL_STATUS('not_yet_approved') ; +#22=APPROVAL_ROLE('APPROVER') ; +#13=DATE_AND_TIME(#11,#12) ; +#12=LOCAL_TIME(17,58,5.,#10) ; +#10=COORDINATED_UNIVERSAL_TIME_OFFSET(0,0,.AHEAD.) ; +#105=ORIENTED_EDGE('',*,*,#84,.F.) ; +#106=ORIENTED_EDGE('',*,*,#91,.T.) ; +#107=ORIENTED_EDGE('',*,*,#98,.T.) ; +#108=ORIENTED_EDGE('',*,*,#103,.F.) ; +#122=ORIENTED_EDGE('',*,*,#98,.F.) ; +#123=ORIENTED_EDGE('',*,*,#115,.T.) ; +#124=ORIENTED_EDGE('',*,*,#84,.T.) ; +#125=ORIENTED_EDGE('',*,*,#120,.F.) ; +#134=ORIENTED_EDGE('',*,*,#115,.F.) ; +#135=ORIENTED_EDGE('',*,*,#91,.F.) ; +#144=ORIENTED_EDGE('',*,*,#103,.T.) ; +#145=ORIENTED_EDGE('',*,*,#120,.T.) ; +#70=CLOSED_SHELL('Closed Shell',(#110,#127,#137,#147)) ; +#155=ITEM_DEFINED_TRANSFORMATION(' ',' ',#157,#156) ; +#168=ITEM_DEFINED_TRANSFORMATION(' ',' ',#170,#169) ; +#183=ITEM_DEFINED_TRANSFORMATION(' ',' ',#185,#184) ; +#78=VECTOR('Line Direction',#77,1.) ; +#94=VECTOR('Line Direction',#93,1.) ; +#149=ADVANCED_BREP_SHAPE_REPRESENTATION('NONE',(#148),#61) ; +#44=SHAPE_REPRESENTATION(' ',(#169,#184),#51) ; +#54=SHAPE_REPRESENTATION(' ',(#156,#170,#185),#53) ; +#62=SHAPE_REPRESENTATION(' ',(#157),#61) ; +#110=ADVANCED_FACE('Hauptk\X2\00F6\X0\rper',(#109),#75,.T.) ; +#127=ADVANCED_FACE('Hauptk\X2\00F6\X0\rper',(#126),#75,.T.) ; +#137=ADVANCED_FACE('Hauptk\X2\00F6\X0\rper',(#136),#132,.F.) ; +#147=ADVANCED_FACE('Hauptk\X2\00F6\X0\rper',(#146),#142,.T.) ; +#4=APPLICATION_PROTOCOL_DEFINITION('international standard','config_control_design',1994,#1) ; +#35=APPROVAL_DATE_TIME(#13,#24) ; +#148=MANIFOLD_SOLID_BREP('Hauptk\X2\00F6\X0\rper',#70) ; +#11=CALENDAR_DATE(2014,1,5) ; +#33=CC_DESIGN_APPROVAL(#24,(#19,#6,#17)) ; +#21=CC_DESIGN_DATE_AND_TIME_ASSIGNMENT(#13,#20,(#19)) ; +#32=CC_DESIGN_DATE_AND_TIME_ASSIGNMENT(#13,#31,(#17)) ; +#20=DATE_TIME_ROLE('classification_date') ; +#31=DATE_TIME_ROLE('creation_date') ; +#30=CC_DESIGN_PERSON_AND_ORGANIZATION_ASSIGNMENT(#28,#29,(#19)) ; +#36=CC_DESIGN_PERSON_AND_ORGANIZATION_ASSIGNMENT(#28,#37,(#6)) ; +#38=CC_DESIGN_PERSON_AND_ORGANIZATION_ASSIGNMENT(#28,#39,(#6,#17)) ; +#40=CC_DESIGN_PERSON_AND_ORGANIZATION_ASSIGNMENT(#28,#41,(#5)) ; +#29=PERSON_AND_ORGANIZATION_ROLE('classification_officer') ; +#37=PERSON_AND_ORGANIZATION_ROLE('design_supplier') ; +#39=PERSON_AND_ORGANIZATION_ROLE('creator') ; +#41=PERSON_AND_ORGANIZATION_ROLE('design_owner') ; +#42=CC_DESIGN_SECURITY_CLASSIFICATION(#19,(#6,#151,#164,#179)) ; +#68=DOCUMENT('2','Part1.CATPart','CATPart document',#67) ; +#67=DOCUMENT_TYPE('') ; +#88=CIRCLE('generated circle',#87,50.) ; +#102=CIRCLE('generated circle',#101,50.) ; +#114=CIRCLE('generated circle',#113,50.) ; +#119=CIRCLE('generated circle',#118,50.) ; +#153=CONTEXT_DEPENDENT_SHAPE_REPRESENTATION(#154,#152) ; +#166=CONTEXT_DEPENDENT_SHAPE_REPRESENTATION(#167,#165) ; +#181=CONTEXT_DEPENDENT_SHAPE_REPRESENTATION(#182,#180) ; +#150=SHAPE_REPRESENTATION_RELATIONSHIP(' ',' ',#62,#149) ; +#75=CYLINDRICAL_SURFACE('generated cylinder',#74,50.) ; +#3=DESIGN_CONTEXT(' ',#1,'design') ; +#84=EDGE_CURVE('',#81,#83,#79,.T.) ; +#91=EDGE_CURVE('',#81,#90,#88,.T.) ; +#98=EDGE_CURVE('',#90,#97,#95,.T.) ; +#103=EDGE_CURVE('',#83,#97,#102,.T.) ; +#115=EDGE_CURVE('',#90,#81,#114,.T.) ; +#120=EDGE_CURVE('',#97,#83,#119,.T.) ; +#104=EDGE_LOOP('',(#105,#106,#107,#108)) ; +#121=EDGE_LOOP('',(#122,#123,#124,#125)) ; +#133=EDGE_LOOP('',(#134,#135)) ; +#143=EDGE_LOOP('',(#144,#145)) ; +#109=FACE_OUTER_BOUND('',#104,.T.) ; +#126=FACE_OUTER_BOUND('',#121,.T.) ; +#136=FACE_OUTER_BOUND('',#133,.T.) ; +#146=FACE_OUTER_BOUND('',#143,.T.) ; +#50=UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(0.005),#46,'distance_accuracy_value','CONFUSED CURVE UNCERTAINTY') ; +#52=UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(0.005),#46,'distance_accuracy_value','CONFUSED CURVE UNCERTAINTY') ; +#60=UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(0.005),#46,'distance_accuracy_value','CONFUSED CURVE UNCERTAINTY') ; +#177=UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(0.005),#46,'distance_accuracy_value','CONFUSED CURVE UNCERTAINTY') ; +#79=LINE('Line',#76,#78) ; +#95=LINE('Line',#92,#94) ; +#2=MECHANICAL_CONTEXT(' ',#1,'mechanical') ; +#151=NEXT_ASSEMBLY_USAGE_OCCURRENCE('Part1.1','Part1.1','',#58,#66,' ') ; +#164=NEXT_ASSEMBLY_USAGE_OCCURRENCE('Product2.1','Product2.1','',#17,#58,' ') ; +#179=NEXT_ASSEMBLY_USAGE_OCCURRENCE('Product2.2','Product2.2','',#17,#58,' ') ; +#27=PERSONAL_ADDRESS(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',(#25),' ') ; +#132=PLANE('Plane',#131) ; +#142=PLANE('Plane',#141) ; +#48=PLANE_ANGLE_MEASURE_WITH_UNIT(PLANE_ANGLE_MEASURE(0.0174532925199),#47) ; +#7=PRODUCT_CATEGORY('part',$) ; +#14=PRODUCT_CATEGORY('part',$) ; +#9=PRODUCT_CATEGORY_RELATIONSHIP(' ',' ',#7,#8) ; +#16=PRODUCT_CATEGORY_RELATIONSHIP(' ',' ',#14,#15) ; +#6=PRODUCT_DEFINITION_FORMATION_WITH_SPECIFIED_SOURCE('',' ',#5,.NOT_KNOWN.) ; +#57=PRODUCT_DEFINITION_FORMATION_WITH_SPECIFIED_SOURCE('',' ',#56,.NOT_KNOWN.) ; +#65=PRODUCT_DEFINITION_FORMATION_WITH_SPECIFIED_SOURCE('',' ',#64,.NOT_KNOWN.) ; +#66=PRODUCT_DEFINITION_WITH_ASSOCIATED_DOCUMENTS('',' ',#65,#3,(#68)) ; +#8=PRODUCT_RELATED_PRODUCT_CATEGORY('detail',$,(#64)) ; +#15=PRODUCT_RELATED_PRODUCT_CATEGORY('part',$,(#5,#56)) ; +#43=SHAPE_DEFINITION_REPRESENTATION(#45,#44) ; +#55=SHAPE_DEFINITION_REPRESENTATION(#59,#54) ; +#63=SHAPE_DEFINITION_REPRESENTATION(#69,#62) ; +#81=VERTEX_POINT('',#80) ; +#83=VERTEX_POINT('',#82) ; +#90=VERTEX_POINT('',#89) ; +#97=VERTEX_POINT('',#96) ; +#46=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.)) ; +#47=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.)) ; +#49=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT()) ; +#51=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#50))GLOBAL_UNIT_ASSIGNED_CONTEXT((#46,#47,#49))REPRESENTATION_CONTEXT(' ',' ')) ; +#53=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#52))GLOBAL_UNIT_ASSIGNED_CONTEXT((#46,#47,#49))REPRESENTATION_CONTEXT(' ',' ')) ; +#61=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#60))GLOBAL_UNIT_ASSIGNED_CONTEXT((#46,#47,#49))REPRESENTATION_CONTEXT(' ',' ')) ; +#178=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#177))GLOBAL_UNIT_ASSIGNED_CONTEXT((#46,#47,#49))REPRESENTATION_CONTEXT(' ',' ')) ; +#154=(REPRESENTATION_RELATIONSHIP(' ',' ',#62,#54)REPRESENTATION_RELATIONSHIP_WITH_TRANSFORMATION(#155)SHAPE_REPRESENTATION_RELATIONSHIP()) ; +#167=(REPRESENTATION_RELATIONSHIP(' ',' ',#54,#44)REPRESENTATION_RELATIONSHIP_WITH_TRANSFORMATION(#168)SHAPE_REPRESENTATION_RELATIONSHIP()) ; +#182=(REPRESENTATION_RELATIONSHIP(' ',' ',#54,#44)REPRESENTATION_RELATIONSHIP_WITH_TRANSFORMATION(#183)SHAPE_REPRESENTATION_RELATIONSHIP()) ; +ENDSEC; +END-ISO-10303-21; diff --git a/src/Mod/Import/App/SCL/SimpleReader.py b/src/Mod/Import/App/SCL/SimpleReader.py index 2dc0b55da4..6ad72ab208 100644 --- a/src/Mod/Import/App/SCL/SimpleReader.py +++ b/src/Mod/Import/App/SCL/SimpleReader.py @@ -165,7 +165,7 @@ class SimpleParser: if __name__ == "__main__": sys.path.append('..') # path where config_control_design.py is found - parser = SimpleParser("Aufspannung.stp") # simple test file + parser = SimpleReader("Aufspannung.stp") # simple test file #parser.instaciate() parser.writeGraphViz('TestGrap.gv') #dot.exe -Tsvg -o Test.svg e:\fem-dev\src\Mod\Import\App\SCL\TestGrap-geo.gv