From f91d5013a34b6ac90c43a6deba64cad144418ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Mon, 14 Oct 2013 16:54:01 +0000 Subject: [PATCH] revidsed assembly constraint gui interaction --- src/Mod/Assembly/App/AppAssembly.cpp | 13 +- src/Mod/Assembly/App/CMakeLists.txt | 12 - src/Mod/Assembly/App/Constraint.cpp | 127 ++- src/Mod/Assembly/App/Constraint.h | 7 +- src/Mod/Assembly/App/ConstraintAlignment.cpp | 87 -- src/Mod/Assembly/App/ConstraintAlignment.h | 61 -- src/Mod/Assembly/App/ConstraintAngle.cpp | 69 -- src/Mod/Assembly/App/ConstraintAngle.h | 60 -- .../Assembly/App/ConstraintCoincidence.cpp | 87 -- src/Mod/Assembly/App/ConstraintCoincidence.h | 60 -- src/Mod/Assembly/App/ConstraintDistance.cpp | 83 -- src/Mod/Assembly/App/ConstraintDistance.h | 62 -- src/Mod/Assembly/App/ConstraintFix.h | 59 -- .../Assembly/App/ConstraintOrientation.cpp | 93 -- src/Mod/Assembly/App/ConstraintOrientation.h | 60 -- src/Mod/Assembly/App/ItemAssembly.cpp | 4 +- src/Mod/Assembly/App/opendcm/core.hpp | 22 +- .../Assembly/App/opendcm/core/equations.hpp | 2 +- .../Assembly/App/opendcm/core/geometry.hpp | 44 +- .../App/opendcm/module3d/distance.hpp | 2 +- .../Assembly/App/opendcm/module3d/module.hpp | 3 + .../App/opendcm/moduleShape3d/generator.hpp | 6 +- .../App/opendcm/moduleShape3d/geometry.hpp | 4 +- .../App/opendcm/moduleShape3d/module.hpp | 158 ++- src/Mod/Assembly/Gui/AlignmentDialog.ui | 111 -- src/Mod/Assembly/Gui/AppAssemblyGui.cpp | 14 +- src/Mod/Assembly/Gui/CMakeLists.txt | 25 +- src/Mod/Assembly/Gui/CommandConstraints.cpp | 208 ++-- src/Mod/Assembly/Gui/Resources/Assembly.qrc | 80 +- .../Assembly/Gui/Resources/Assembly.qrc.orig | 81 ++ .../Assembly_ConstraintBidirectional.svg | 410 ++++++++ .../icons/Assembly_ConstraintEqual.svg | 390 +++++++ .../icons/Assembly_ConstraintGeneral.svg | 305 ++++++ .../icons/Assembly_ConstraintOpposite.svg | 390 +++++++ .../icons/Assembly_ConstraintParallel.svg | 397 +++++++ .../Assembly_ConstraintPerpendicular.svg | 539 ++++++++++ .../Assembly_ConstraintUnidirectional1.svg | 397 +++++++ .../Assembly_ConstraintUnidirectional2.svg | 394 +++++++ .../Assembly/Gui/TaskAssemblyConstraints.cpp | 412 ++++++++ ...straintFix.h => TaskAssemblyConstraints.h} | 50 +- .../Assembly/Gui/TaskAssemblyConstraints.ui | 979 ++++++++++++++++++ .../TaskDlgAssemblyConstraints.cpp} | 102 +- ...ntAngle.h => TaskDlgAssemblyConstraints.h} | 112 +- .../Assembly/Gui/ViewProviderConstraint.cpp | 99 +- src/Mod/Assembly/Gui/ViewProviderConstraint.h | 10 +- .../Gui/ViewProviderConstraintAlignment.cpp | 34 - .../Gui/ViewProviderConstraintAlignment.h | 41 - .../Gui/ViewProviderConstraintAngle.cpp | 34 - .../Gui/ViewProviderConstraintCoincidence.cpp | 34 - .../Gui/ViewProviderConstraintCoincidence.h | 42 - .../Gui/ViewProviderConstraintDistance.cpp | 34 - .../Gui/ViewProviderConstraintDistance.h | 43 - .../Gui/ViewProviderConstraintFix.cpp | 56 - .../Gui/ViewProviderConstraintOrientation.cpp | 34 - .../Gui/ViewProviderConstraintOrientation.h | 42 - src/Mod/Assembly/Gui/Workbench.cpp | 1 + 56 files changed, 5421 insertions(+), 1664 deletions(-) delete mode 100644 src/Mod/Assembly/App/ConstraintAlignment.cpp delete mode 100644 src/Mod/Assembly/App/ConstraintAlignment.h delete mode 100644 src/Mod/Assembly/App/ConstraintAngle.cpp delete mode 100644 src/Mod/Assembly/App/ConstraintAngle.h delete mode 100644 src/Mod/Assembly/App/ConstraintCoincidence.cpp delete mode 100644 src/Mod/Assembly/App/ConstraintCoincidence.h delete mode 100644 src/Mod/Assembly/App/ConstraintDistance.cpp delete mode 100644 src/Mod/Assembly/App/ConstraintDistance.h delete mode 100644 src/Mod/Assembly/App/ConstraintFix.h delete mode 100644 src/Mod/Assembly/App/ConstraintOrientation.cpp delete mode 100644 src/Mod/Assembly/App/ConstraintOrientation.h delete mode 100644 src/Mod/Assembly/Gui/AlignmentDialog.ui create mode 100644 src/Mod/Assembly/Gui/Resources/Assembly.qrc.orig create mode 100644 src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintBidirectional.svg create mode 100644 src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintEqual.svg create mode 100644 src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintGeneral.svg create mode 100644 src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintOpposite.svg create mode 100644 src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintParallel.svg create mode 100644 src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintPerpendicular.svg create mode 100644 src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintUnidirectional1.svg create mode 100644 src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintUnidirectional2.svg create mode 100644 src/Mod/Assembly/Gui/TaskAssemblyConstraints.cpp rename src/Mod/Assembly/Gui/{ViewProviderConstraintFix.h => TaskAssemblyConstraints.h} (57%) create mode 100644 src/Mod/Assembly/Gui/TaskAssemblyConstraints.ui rename src/Mod/Assembly/{App/ConstraintFix.cpp => Gui/TaskDlgAssemblyConstraints.cpp} (50%) rename src/Mod/Assembly/Gui/{ViewProviderConstraintAngle.h => TaskDlgAssemblyConstraints.h} (52%) delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintAlignment.cpp delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintAlignment.h delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintAngle.cpp delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintCoincidence.cpp delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintCoincidence.h delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintDistance.cpp delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintDistance.h delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintFix.cpp delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintOrientation.cpp delete mode 100644 src/Mod/Assembly/Gui/ViewProviderConstraintOrientation.h diff --git a/src/Mod/Assembly/App/AppAssembly.cpp b/src/Mod/Assembly/App/AppAssembly.cpp index babebb0fe..aa41ce4ec 100644 --- a/src/Mod/Assembly/App/AppAssembly.cpp +++ b/src/Mod/Assembly/App/AppAssembly.cpp @@ -34,13 +34,8 @@ #include "ItemAssembly.h" #include "ItemPart.h" -#include "ConstraintAngle.h" -#include "ConstraintCoincidence.h" -#include "ConstraintFix.h" +#include "Constraint.h" #include "ConstraintGroup.h" -#include "ConstraintAlignment.h" -#include "ConstraintDistance.h" -#include "ConstraintOrientation.h" extern struct PyMethodDef Assembly_methods[]; @@ -80,12 +75,6 @@ void AssemblyExport initAssembly() // constraint hirachy Assembly::Constraint ::init(); - Assembly::ConstraintAngle ::init(); - Assembly::ConstraintDistance::init(); - Assembly::ConstraintCoincidence::init(); - Assembly::ConstraintFix ::init(); - Assembly::ConstraintAlignment ::init(); - Assembly::ConstraintOrientation::init(); Assembly::ConstraintGroup ::init(); } diff --git a/src/Mod/Assembly/App/CMakeLists.txt b/src/Mod/Assembly/App/CMakeLists.txt index 549de8157..c96dbc9fa 100644 --- a/src/Mod/Assembly/App/CMakeLists.txt +++ b/src/Mod/Assembly/App/CMakeLists.txt @@ -45,18 +45,6 @@ SET(Features_SRCS Constraint.h ConstraintGroup.cpp ConstraintGroup.h - ConstraintAngle.cpp - ConstraintAngle.h - ConstraintDistance.cpp - ConstraintDistance.h - ConstraintCoincidence.cpp - ConstraintCoincidence.h - ConstraintFix.cpp - ConstraintFix.h - ConstraintAlignment.cpp - ConstraintAlignment.h - ConstraintOrientation.cpp - ConstraintOrientation.h ) SOURCE_GROUP("Features" FILES ${Features_SRCS}) diff --git a/src/Mod/Assembly/App/Constraint.cpp b/src/Mod/Assembly/App/Constraint.cpp index 516f63246..8483c42d3 100644 --- a/src/Mod/Assembly/App/Constraint.cpp +++ b/src/Mod/Assembly/App/Constraint.cpp @@ -26,6 +26,8 @@ #ifndef _PreComp_ #endif +#include + #include #include #include @@ -57,7 +59,14 @@ using namespace Assembly; namespace Assembly { struct ConstraintInitException : std::exception { - const char* what() const throw() { return "Constraint cout not be initialised: unsoported geometry";} + const char* what() const throw() { + return "Constraint cout not be initialised: unsoported geometry"; + } +}; +struct ConstraintLinkException : std::exception { + const char* what() const throw() { + return "Constraint cout not be initialised: unsoported link type"; + } }; PROPERTY_SOURCE(Assembly::Constraint, App::DocumentObject) @@ -66,6 +75,26 @@ Constraint::Constraint() { ADD_PROPERTY(First, (0)); ADD_PROPERTY(Second,(0)); + ADD_PROPERTY(Value,(0)); + ADD_PROPERTY(Orientation, (long(0))); + ADD_PROPERTY(Type, (long(6))); + + std::vector vec; + vec.push_back("Parallel"); + vec.push_back("Equal"); + vec.push_back("Opposite"); + vec.push_back("Perpendicular"); + Orientation.setEnumVector(vec); + + std::vector vec2; + vec2.push_back("Fix"); + vec2.push_back("Distance"); + vec2.push_back("Orientation"); + vec2.push_back("Angle"); + vec2.push_back("Align"); + vec2.push_back("Coincident"); + vec2.push_back("None"); + Type.setEnumVector(vec2); } short Constraint::mustExecute() const @@ -76,7 +105,7 @@ short Constraint::mustExecute() const return 0; } -App::DocumentObjectExecReturn *Constraint::execute(void) +App::DocumentObjectExecReturn* Constraint::execute(void) { touch(); return App::DocumentObject::StdReturn; @@ -84,39 +113,99 @@ App::DocumentObjectExecReturn *Constraint::execute(void) boost::shared_ptr Constraint::initLink(App::PropertyLinkSub& link) { + //empty links are allows + if(!link.getValue()) + return boost::shared_ptr(); + //check if we have Assembly::ItemPart - if( link.getValue()->getTypeId() != ItemPart::getClassTypeId() ) { - Base::Console().Message("Link is not ItemPart, the constraint is invalid\n"); - return boost::shared_ptr(); + if(link.getValue()->getTypeId() != ItemPart::getClassTypeId()) { + throw ConstraintLinkException(); + return boost::shared_ptr(); }; - + Assembly::ItemPart* part = static_cast(link.getValue()); - if(!part) - return boost::shared_ptr(); - + if(!part) + return boost::shared_ptr(); + //get the relevant solver in which the part needs to be added part->ensureInitialisation(); - + return part->getGeometry3D(link.getSubValues()[0].c_str()); } -void Constraint::init(Assembly::ItemAssembly* ass) +void Constraint::init(Assembly::ItemAssembly* ass) { - m_first_geom = initLink(First); - m_second_geom = initLink(Second); - - if(!m_first_geom || !m_second_geom) - throw ConstraintInitException(); + Assembly::ItemPart* part1, *part2; + + if(First.getValue()) { + m_first_geom = initLink(First); + part1 = static_cast(First.getValue()); + } + + if(Second.getValue()) { + m_second_geom = initLink(Second); + part2= static_cast(Second.getValue()); + } + + //fix constraint + if(Type.getValue() == 0) { + if(part1) + part1->m_part->fix(true); + else + if(part2) + part2->m_part->fix(true); + }; + + //all other constraints need poth parts + if(!part1 || !part2) + return; + + //we may need the orientation + dcm::Direction dir; + switch(Orientation.getValue()) { + case 0: + dir = dcm::parallel; + break; + case 1: + dir = dcm::equal; + break; + case 2: + dir = dcm::opposite; + break; + default: + dir = dcm::perpendicular; + + }; + + //distance constraint + if(Type.getValue() == 1) + m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::distance = Value.getValue()); + + //orientation constraint + if(Type.getValue() == 2) + m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::orientation = dir); + + //angle constraint + if(Type.getValue() == 3) + m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::angle = Value.getValue()*M_PI/180.); + + //alignemnt constraint + if(Type.getValue() == 4) + m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::alignment(dir, Value.getValue())); + + //coincident constraint + if(Type.getValue() == 5) + m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::coincidence = dir); } -PyObject *Constraint::getPyObject(void) +PyObject* Constraint::getPyObject(void) { - if (PythonObject.is(Py::_None())){ + if(PythonObject.is(Py::_None())) { // ref counter is set to 1 PythonObject = Py::Object(new ConstraintPy(this),true); } - return Py::new_reference_to(PythonObject); + return Py::new_reference_to(PythonObject); } diff --git a/src/Mod/Assembly/App/Constraint.h b/src/Mod/Assembly/App/Constraint.h index c6d00f23e..00fb71edb 100644 --- a/src/Mod/Assembly/App/Constraint.h +++ b/src/Mod/Assembly/App/Constraint.h @@ -52,6 +52,9 @@ public: App::PropertyLinkSub First; App::PropertyLinkSub Second; + App::PropertyFloat Value; + App::PropertyEnumeration Orientation; + App::PropertyEnumeration Type; /** @name methods override feature */ //@{ @@ -60,13 +63,13 @@ public: short mustExecute() const; /// returns the type name of the view provider const char* getViewProviderName(void) const { - return "Gui::ViewProviderDocumentObject"; + return "AssemblyGui::ViewProviderConstraint"; } PyObject *getPyObject(void); /** @brief initialize the constraint in the assembly solver */ - virtual void init(Assembly::ItemAssembly* ass); + void init(Assembly::ItemAssembly* ass); }; } //namespace Assembly diff --git a/src/Mod/Assembly/App/ConstraintAlignment.cpp b/src/Mod/Assembly/App/ConstraintAlignment.cpp deleted file mode 100644 index dd08b205f..000000000 --- a/src/Mod/Assembly/App/ConstraintAlignment.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 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 "ConstraintAlignment.h" - - -using namespace Assembly; - -namespace Assembly { - - -PROPERTY_SOURCE(Assembly::ConstraintAlignment, Assembly::Constraint) - -ConstraintAlignment::ConstraintAlignment() -{ - ADD_PROPERTY(Offset,(0)); - ADD_PROPERTY(Orientation, (long(0))); - - std::vector vec; - vec.push_back("Parallel"); - vec.push_back("Equal"); - vec.push_back("Opposite"); - Orientation.setEnumVector(vec); -} - -short ConstraintAlignment::mustExecute() const -{ - //if (Sketch.isTouched() || - // Length.isTouched()) - // return 1; - return 0; -} - -App::DocumentObjectExecReturn *ConstraintAlignment::execute(void) -{ - - return App::DocumentObject::StdReturn; -} - -void ConstraintAlignment::init(Assembly::ItemAssembly* ass) { - - //cant use the base class init as we only need one part - Constraint::init(ass); - - //init the constraint - dcm::Direction dir; - switch(Orientation.getValue()) { - case 0: - dir = dcm::parallel; - break; - case 1: - dir = dcm::equal; - break; - default: - dir = dcm::opposite; - }; - - m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::alignment(dir, Offset.getValue())); -}; - -} \ No newline at end of file diff --git a/src/Mod/Assembly/App/ConstraintAlignment.h b/src/Mod/Assembly/App/ConstraintAlignment.h deleted file mode 100644 index b9ba6279b..000000000 --- a/src/Mod/Assembly/App/ConstraintAlignment.h +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 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_ConstraintAlignment_H -#define Assembly_ConstraintAlignment_H - -#include -#include "Constraint.h" - - -namespace Assembly -{ - -class AssemblyExport ConstraintAlignment : public Assembly::Constraint -{ - PROPERTY_HEADER(Assembly::ConstraintAlignment); - -public: - ConstraintAlignment(); - - App::PropertyFloat Offset; - App::PropertyEnumeration Orientation; - - /** @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::ViewProviderConstraintAlignment"; - } - //@} - - virtual void init(Assembly::ItemAssembly* ass); -}; - -} //namespace PartDesign - - -#endif // PART_ConstraintAlignment_H diff --git a/src/Mod/Assembly/App/ConstraintAngle.cpp b/src/Mod/Assembly/App/ConstraintAngle.cpp deleted file mode 100644 index f7c19bd3d..000000000 --- a/src/Mod/Assembly/App/ConstraintAngle.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 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 "ConstraintAngle.h" - - -using namespace Assembly; - -namespace Assembly { - - -PROPERTY_SOURCE(Assembly::ConstraintAngle, Assembly::Constraint) - -ConstraintAngle::ConstraintAngle() -{ - ADD_PROPERTY(Angle,(0)); -} - -short ConstraintAngle::mustExecute() const -{ - //if (Sketch.isTouched() || - // Length.isTouched()) - // return 1; - return 0; -} - -App::DocumentObjectExecReturn *ConstraintAngle::execute(void) -{ - - return App::DocumentObject::StdReturn; -} - -void ConstraintAngle::init(Assembly::ItemAssembly* ass) -{ - //init the parts and geometries - Constraint::init(ass); - - //init the constraint - m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::angle = Angle.getValue()*M_PI/180.); -} - -} \ No newline at end of file diff --git a/src/Mod/Assembly/App/ConstraintAngle.h b/src/Mod/Assembly/App/ConstraintAngle.h deleted file mode 100644 index 60ffd110f..000000000 --- a/src/Mod/Assembly/App/ConstraintAngle.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 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_ConstraintAngle_H -#define Assembly_ConstraintAngle_H - -#include -#include "Constraint.h" - - -namespace Assembly -{ - -class AssemblyExport ConstraintAngle : public Assembly::Constraint -{ - PROPERTY_HEADER(Assembly::ConstraintAngle); - -public: - ConstraintAngle(); - - App::PropertyFloat Angle; - - /** @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::ViewProviderConstraintAngle"; - } - //@} - - virtual void init(Assembly::ItemAssembly* ass); -}; - -} //namespace Assembly - - -#endif // Assembly_ConstraintAngle_H diff --git a/src/Mod/Assembly/App/ConstraintCoincidence.cpp b/src/Mod/Assembly/App/ConstraintCoincidence.cpp deleted file mode 100644 index 326787e62..000000000 --- a/src/Mod/Assembly/App/ConstraintCoincidence.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * 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 "ConstraintCoincidence.h" - - -using namespace Assembly; - -namespace Assembly { - - -PROPERTY_SOURCE(Assembly::ConstraintCoincidence, Assembly::Constraint) - -ConstraintCoincidence::ConstraintCoincidence() -{ - - ADD_PROPERTY(Orientation, (long(0))); - - std::vector vec; - vec.push_back("Parallel"); - vec.push_back("Equal"); - vec.push_back("Opposite"); - Orientation.setEnumVector(vec); -} - -short ConstraintCoincidence::mustExecute() const -{ - //if (Sketch.isTouched() || - // Length.isTouched()) - // return 1; - return 0; -} - -App::DocumentObjectExecReturn *ConstraintCoincidence::execute(void) -{ - - return App::DocumentObject::StdReturn; -} - -void ConstraintCoincidence::init(Assembly::ItemAssembly* ass) { - - //cant use the base class init as we only need one part - Constraint::init(ass); - - //init the constraint - dcm::Direction dir; - switch(Orientation.getValue()) { - case 0: - dir = dcm::parallel; - break; - case 1: - dir = dcm::equal; - break; - default: - dir = dcm::opposite; - }; - - m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::coincidence = dir); -}; - -} \ No newline at end of file diff --git a/src/Mod/Assembly/App/ConstraintCoincidence.h b/src/Mod/Assembly/App/ConstraintCoincidence.h deleted file mode 100644 index c20e4a75d..000000000 --- a/src/Mod/Assembly/App/ConstraintCoincidence.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * 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_ConstraintCoincidence_H -#define Assembly_ConstraintCoincidence_H - -#include -#include "Constraint.h" - - -namespace Assembly -{ - -class AssemblyExport ConstraintCoincidence : public Assembly::Constraint -{ - PROPERTY_HEADER(Assembly::ConstraintCoincidence); - -public: - ConstraintCoincidence(); - - App::PropertyEnumeration Orientation; - - /** @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::ViewProviderConstraintCoincidence"; - } - //@} - - virtual void init(Assembly::ItemAssembly* ass); -}; - -} //namespace Assembly - - -#endif // Assembly_ConstraintCoincidence_H diff --git a/src/Mod/Assembly/App/ConstraintDistance.cpp b/src/Mod/Assembly/App/ConstraintDistance.cpp deleted file mode 100644 index 7d79923b6..000000000 --- a/src/Mod/Assembly/App/ConstraintDistance.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2012 Juergen Riegel - * 2013 Stefan Tröger - * * - * 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 "ConstraintDistance.h" -#include "ConstraintPy.h" - -#include "ItemPart.h" - -using namespace Assembly; - -namespace Assembly { - - -PROPERTY_SOURCE(Assembly::ConstraintDistance, Assembly::Constraint) - -ConstraintDistance::ConstraintDistance() -{ - ADD_PROPERTY(Distance,(0)); -} - -PyObject *ConstraintDistance::getPyObject(void) -{ - if (PythonObject.is(Py::_None())){ - // ref counter is set to 1 - PythonObject = Py::Object(new ConstraintPy(this),true); - } - return Py::new_reference_to(PythonObject); -} - -short ConstraintDistance::mustExecute() const -{ - //if (Sketch.isTouched() || - // Length.isTouched()) - // return 1; - return 0; -} - -App::DocumentObjectExecReturn *ConstraintDistance::execute(void) -{ - Base::Console().Message("Recalculate axis constraint\n"); - touch(); - return App::DocumentObject::StdReturn; -} - -void ConstraintDistance::init(Assembly::ItemAssembly* ass) -{ - //init the parts and geometries - Constraint::init(ass); - - //init the constraint - m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::distance = Distance.getValue()); -} - - -} \ No newline at end of file diff --git a/src/Mod/Assembly/App/ConstraintDistance.h b/src/Mod/Assembly/App/ConstraintDistance.h deleted file mode 100644 index 549e0e434..000000000 --- a/src/Mod/Assembly/App/ConstraintDistance.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * 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_ConstraintAxis_H -#define Assembly_ConstraintAxis_H - -#include -#include "Constraint.h" - - -namespace Assembly -{ - -class AssemblyExport ConstraintDistance : public Assembly::Constraint -{ - PROPERTY_HEADER(Assembly::ConstraintAxis); - -public: - ConstraintDistance(); - - App::PropertyFloat Distance; - - PyObject *getPyObject(void); - - /** @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::ViewProviderConstraintDistance"; - } - //@} - - virtual void init(Assembly::ItemAssembly* ass); -}; - -} //namespace Assembly - - -#endif // Assembly_ConstraintAxis_H diff --git a/src/Mod/Assembly/App/ConstraintFix.h b/src/Mod/Assembly/App/ConstraintFix.h deleted file mode 100644 index 6c0f92564..000000000 --- a/src/Mod/Assembly/App/ConstraintFix.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 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_ConstraintFix_H -#define Assembly_ConstraintFix_H - -#include -#include "Constraint.h" - - -namespace Assembly -{ - -class AssemblyExport ConstraintFix : public Assembly::Constraint -{ - PROPERTY_HEADER(Assembly::ConstraintFix); - -public: - ConstraintFix(); - ~ConstraintFix(); - - /** @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::ViewProviderConstraintFix"; - } - //@} - - virtual void init(Assembly::ItemAssembly* ass); -}; - -} //namespace Assembly - - -#endif // Assembly_ConstraintFix_H diff --git a/src/Mod/Assembly/App/ConstraintOrientation.cpp b/src/Mod/Assembly/App/ConstraintOrientation.cpp deleted file mode 100644 index 0150a6d8f..000000000 --- a/src/Mod/Assembly/App/ConstraintOrientation.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2012 Juergen Riegel - * 2013 Stefan Tröger - * * - * 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 "ConstraintOrientation.h" -#include "ConstraintPy.h" - -#include "ItemPart.h" - - -using namespace Assembly; - -namespace Assembly { - - -PROPERTY_SOURCE(Assembly::ConstraintOrientation, Assembly::Constraint) - -ConstraintOrientation::ConstraintOrientation() { - ADD_PROPERTY(Orientation, (long(0))); - - std::vector vec; - vec.push_back("Parallel"); - vec.push_back("Perpendicular"); - vec.push_back("Equal"); - vec.push_back("Opposite"); - Orientation.setEnumVector(vec); -} - -short ConstraintOrientation::mustExecute() const { - //if (Sketch.isTouched() || - // Length.isTouched()) - // return 1; - return 0; -} - -App::DocumentObjectExecReturn* ConstraintOrientation::execute(void) { - Base::Console().Message("Recalculate orientation constraint\n"); - touch(); - return App::DocumentObject::StdReturn; -} - -void ConstraintOrientation::init(Assembly::ItemAssembly* ass) { - //init the parts and geometries - Constraint::init(ass); - - //init the constraint - dcm::Direction dir; - switch(Orientation.getValue()) { - case 0: - dir = dcm::parallel; - break; - case 1: - dir = dcm::perpendicular; - break; - case 2: - dir = dcm::equal; - break; - default: - dir = dcm::opposite; - }; - - m_constraint = ass->m_solver->createConstraint3D(getNameInDocument(), m_first_geom, m_second_geom, dcm::orientation = dir); -} - - -} diff --git a/src/Mod/Assembly/App/ConstraintOrientation.h b/src/Mod/Assembly/App/ConstraintOrientation.h deleted file mode 100644 index 14be36897..000000000 --- a/src/Mod/Assembly/App/ConstraintOrientation.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * 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_ConstraintOrientation_H -#define Assembly_ConstraintOrientation_H - -#include -#include "Constraint.h" - - -namespace Assembly -{ - -class AssemblyExport ConstraintOrientation : public Assembly::Constraint -{ - PROPERTY_HEADER(Assembly::ConstraintOrientation); - -public: - ConstraintOrientation(); - - App::PropertyEnumeration Orientation; - - /** @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::ViewProviderConstraintOrientation"; - } - //@} - - virtual void init(Assembly::ItemAssembly* ass); -}; - -} //namespace Assembly - - -#endif // Assembly_ConstraintAxis_H diff --git a/src/Mod/Assembly/App/ItemAssembly.cpp b/src/Mod/Assembly/App/ItemAssembly.cpp index e7f54efff..431ec584e 100644 --- a/src/Mod/Assembly/App/ItemAssembly.cpp +++ b/src/Mod/Assembly/App/ItemAssembly.cpp @@ -84,7 +84,9 @@ App::DocumentObjectExecReturn* ItemAssembly::execute(void) { *boost::get_error_info(e), boost::get_error_info(e)->c_str()); } - + catch(std::exception& e) { + Base::Console().Error("Exception raised in assembly solver: %s", e.what()); + }; this->touch(); return App::DocumentObject::StdReturn; } diff --git a/src/Mod/Assembly/App/opendcm/core.hpp b/src/Mod/Assembly/App/opendcm/core.hpp index 6f6d171df..b30cd8aec 100644 --- a/src/Mod/Assembly/App/opendcm/core.hpp +++ b/src/Mod/Assembly/App/opendcm/core.hpp @@ -21,18 +21,18 @@ #define DCM_CORE_H #ifdef _WIN32 - //warning about to long decoraded names, won't affect the code correctness - #pragma warning( disable : 4503 ) - //warning about changed pod initalising behaviour (boost blank in variant) - #pragma warning( disable : 4345 ) + //warning about to long decoraded names, won't affect the code correctness + #pragma warning( disable : 4503 ) + //warning about changed pod initalising behaviour (boost blank in variant) + #pragma warning( disable : 4345 ) - //disable boost concept checks, as some of them have alignment problems which bring msvc to an error - //(for example DFSvisitor check in boost::graph::depht_first_search) - //this has no runtime effect as these are only compile time checks - #include - #undef BOOST_CONCEPT_ASSERT - #define BOOST_CONCEPT_ASSERT(Model) - #include + //disable boost concept checks, as some of them have alignment problems which bring msvc to an error + //(for example DFSvisitor check in boost::graph::depht_first_search) + //this has no runtime effect as these are only compile time checks + #include + #undef BOOST_CONCEPT_ASSERT + #define BOOST_CONCEPT_ASSERT(Model) + #include #endif diff --git a/src/Mod/Assembly/App/opendcm/core/equations.hpp b/src/Mod/Assembly/App/opendcm/core/equations.hpp index 7f28fc33b..0bca86134 100644 --- a/src/Mod/Assembly/App/opendcm/core/equations.hpp +++ b/src/Mod/Assembly/App/opendcm/core/equations.hpp @@ -264,7 +264,7 @@ struct Distance : public Equation { }; //the possible directions -enum Direction { parallel, equal, opposite, perpendicular }; +enum Direction { parallel=0, equal, opposite, perpendicular }; struct Orientation : public Equation { diff --git a/src/Mod/Assembly/App/opendcm/core/geometry.hpp b/src/Mod/Assembly/App/opendcm/core/geometry.hpp index 4a145cfce..d85852bcd 100644 --- a/src/Mod/Assembly/App/opendcm/core/geometry.hpp +++ b/src/Mod/Assembly/App/opendcm/core/geometry.hpp @@ -56,6 +56,24 @@ namespace dcm { //signal we use for recalculation struct recalculated {}; + +//all supported geometry types for easy access and comparison +namespace geometry { +enum types { + parameter = 0, + direction, + point, + line, + segment, + circle, + arc, + geometry, + ellipse, + elliptical_arc, + plane, + cylinder +}; +}//namespace geometry namespace tag { @@ -66,17 +84,17 @@ struct undefined { //we need to order tags, this values make it easy for module tags namespace weight { -struct parameter : mpl::int_<0> {}; -struct direction : mpl::int_<1> {}; -struct point : mpl::int_<2> {}; -struct line : mpl::int_<3> {}; -struct segment : mpl::int_<4> {}; -struct circle : mpl::int_<5> {}; -struct arc : mpl::int_<6> {}; -struct ellipse : mpl::int_<7> {}; -struct elliptical_arc : mpl::int_<8> {}; -struct plane : mpl::int_<9> {}; -struct cylinder : mpl::int_<10> {}; +struct parameter : mpl::int_ {}; +struct direction : mpl::int_ {}; +struct point : mpl::int_ {}; +struct line : mpl::int_ {}; +struct segment : mpl::int_ {}; +struct circle : mpl::int_ {}; +struct arc : mpl::int_ {}; +struct ellipse : mpl::int_ {}; +struct elliptical_arc : mpl::int_ {}; +struct plane : mpl::int_ {}; +struct cylinder : mpl::int_ {}; } } // tag @@ -229,8 +247,8 @@ public: }; void transform(const Transform& t); - int getGeneralType() { - return m_general_type; + geometry::types getGeometryType() { + return geometry::types(m_general_type); }; int getExactType() { diff --git a/src/Mod/Assembly/App/opendcm/module3d/distance.hpp b/src/Mod/Assembly/App/opendcm/module3d/distance.hpp index 921a361fb..062d8dd32 100644 --- a/src/Mod/Assembly/App/opendcm/module3d/distance.hpp +++ b/src/Mod/Assembly/App/opendcm/module3d/distance.hpp @@ -306,7 +306,7 @@ struct Distance::type< Kernel, tag::point3D, tag::cylinder3D > : public Distance g(6) = -1; }; }; - +//TODO: this won't work for parallel lines. switch to point-line distance when lines are parallel template struct Distance::type< Kernel, tag::line3D, tag::line3D > { diff --git a/src/Mod/Assembly/App/opendcm/module3d/module.hpp b/src/Mod/Assembly/App/opendcm/module3d/module.hpp index 650fe0833..bdd1e7cd5 100644 --- a/src/Mod/Assembly/App/opendcm/module3d/module.hpp +++ b/src/Mod/Assembly/App/opendcm/module3d/module.hpp @@ -314,6 +314,9 @@ struct Module3D { using inheriter_base::m_this; public: + using inheriter_base::createGeometry3D; + using inheriter_base::createConstraint3D; + template Geom createGeometry3D(T geom, Identifier id); Geom createGeometry3D(Identifier id); diff --git a/src/Mod/Assembly/App/opendcm/moduleShape3d/generator.hpp b/src/Mod/Assembly/App/opendcm/moduleShape3d/generator.hpp index fcd810fa8..d2977b982 100644 --- a/src/Mod/Assembly/App/opendcm/moduleShape3d/generator.hpp +++ b/src/Mod/Assembly/App/opendcm/moduleShape3d/generator.hpp @@ -125,7 +125,7 @@ struct segment3D { virtual bool check() { //even we have a real geometry segment - if(base::m_shape->getGeneralType() == tag::weight::segment::value) + if(base::m_shape->getGeometryType() == tag::weight::segment::value) return true; //or two point geometries @@ -137,7 +137,7 @@ struct segment3D { //initialise all relations between the geometries virtual void init() { - if(base::m_shape->getGeneralType() == dcm::tag::weight::segment::value) { + if(base::m_shape->getGeometryType() == dcm::tag::weight::segment::value) { //link the line geometrie to our shape boost::shared_ptr g1 = base::m_system->createGeometry3D(); @@ -171,7 +171,7 @@ struct segment3D { boost::shared_ptr g2 = base::m_geometries->operator[](1); //possibility 1: two points. we add a segment line an link the point in - if(g1->getGeneralType() == tag::weight::point::value || g2->getGeneralType() == tag::weight::point::value) { + if(g1->getGeometryType() == tag::weight::point::value || g2->getGeometryType() == tag::weight::point::value) { g1->template setProperty(startpoint); g2->template setProperty(endpoint); diff --git a/src/Mod/Assembly/App/opendcm/moduleShape3d/geometry.hpp b/src/Mod/Assembly/App/opendcm/moduleShape3d/geometry.hpp index e5ca7b3bb..7c4a2c6c8 100644 --- a/src/Mod/Assembly/App/opendcm/moduleShape3d/geometry.hpp +++ b/src/Mod/Assembly/App/opendcm/moduleShape3d/geometry.hpp @@ -17,8 +17,8 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef GCM_GEOMETRY_HL3D_H -#define GCM_GEOMETRY_HL3D_H +#ifndef DCM_GEOMETRY_SHAPE3D_H +#define DCM_GEOMETRY_SHAPE3D_H #include "opendcm/core/geometry.hpp" #include "opendcm/module3d/geometry.hpp" diff --git a/src/Mod/Assembly/App/opendcm/moduleShape3d/module.hpp b/src/Mod/Assembly/App/opendcm/moduleShape3d/module.hpp index dec011eaa..dc157c81d 100644 --- a/src/Mod/Assembly/App/opendcm/moduleShape3d/module.hpp +++ b/src/Mod/Assembly/App/opendcm/moduleShape3d/module.hpp @@ -42,10 +42,12 @@ #define APPEND_SINGLE(z, n, data) \ + typedef typename Sys::Identifier Identifier; \ typedef typename system_traits::template getModule::type::geometry_types gtypes; \ - g_ptr = details::converter_g::template apply(BOOST_PP_CAT(arg,n), m_this); \ + typedef typename system_traits::template getModule::type::geometry_types stypes; \ + g_ptr = details::converter_g::template apply(BOOST_PP_CAT(arg,n), m_this); \ if(!g_ptr) { \ - hlg_ptr = details::converter_hlg::template apply(BOOST_PP_CAT(arg,n), data); \ + hlg_ptr = details::converter_hlg::template apply(BOOST_PP_CAT(arg,n), data, m_this); \ if(!hlg_ptr) \ throw creation_error() << boost::errinfo_errno(216) << error_message("could not handle input"); \ else \ @@ -99,27 +101,36 @@ namespace details { template struct converter_g { //check if the type T is usable from within module3d, as it could also be a shape type - template + template static typename boost::enable_if< - mpl::not_< boost::is_same< - typename mpl::find::type,typename mpl::end::type> >, - boost::shared_ptr >::type apply(T const& t, Sys* sys) { + mpl::and_< + mpl::not_< boost::is_same::type,typename mpl::end::type> >, + mpl::not_ > + >, boost::shared_ptr >::type apply(T const& t, Sys* sys) { return sys->createGeometry3D(t); }; //seems to be a shape type, return an empty geometry - template + template static typename boost::enable_if< - boost::is_same< - typename mpl::find::type, typename mpl::end::type>, - boost::shared_ptr >::type apply(T const& t, Sys* sys) { + mpl::and_< + boost::is_same::type, typename mpl::end::type>, + mpl::not_ > + >, boost::shared_ptr >::type apply(T const& t, Sys* sys) { return boost::shared_ptr(); }; + + //seems to be an identifier type, lets check if we have such a geometry + template + static typename boost::enable_if< + boost::is_same, boost::shared_ptr >::type apply(T const& t, Sys* sys) { + return sys->getGeometry3D(t); + }; }; template struct converter_g< boost::shared_ptr, R> { - template + template static boost::shared_ptr apply(boost::shared_ptr t, Sys* sys) { return t; }; @@ -127,30 +138,41 @@ struct converter_g< boost::shared_ptr, R> { template struct converter_hlg { - template + template static typename boost::enable_if< - boost::is_same< - typename mpl::find::template getModule::type::geometry_types, T>::type, - typename mpl::end::template getModule::type::geometry_types>::type>, - boost::shared_ptr >::type apply(T const& t, boost::shared_ptr self) { + mpl::and_< + boost::is_same::type, typename mpl::end::type>, + mpl::not_ > + >, + boost::shared_ptr >::type apply(T const& t, boost::shared_ptr self, Sys* sys) { return boost::shared_ptr(); }; - template + template static typename boost::enable_if< - mpl::not_< boost::is_same< - typename mpl::find::template getModule::type::geometry_types, T>::type, - typename mpl::end::template getModule::type::geometry_types>::type> >, - boost::shared_ptr >::type apply(T const& t, boost::shared_ptr self) { + mpl::not_< boost::is_same::type, typename mpl::end::type> >, + boost::shared_ptr >::type apply(T const& t, boost::shared_ptr self, Sys* sys) { + + //shape can only be set one time, throw an error otherwise + if(self->holdsType()) + throw creation_error() << boost::errinfo_errno(410) << error_message("Shape can only be set with one geometry"); + self->set(t); return self; }; + + //seems to be an identifier type, lets check if we have such a geometry + template + static typename boost::enable_if< + boost::is_same, boost::shared_ptr >::type apply(T const& t, boost::shared_ptr self, Sys* sys) { + return sys->getShape3D(t); + }; }; template struct converter_hlg, R> { - template - static boost::shared_ptr apply(boost::shared_ptr t, boost::shared_ptr self) { + template + static boost::shared_ptr apply(boost::shared_ptr t, boost::shared_ptr self, Sys* sys) { return t; }; }; @@ -164,7 +186,7 @@ struct ModuleShape3D { template struct type : details::mshape3d { - typedef TypeList geometry_types; + typedef TypeList geometry_types; //forward declare struct inheriter_base; struct Shape3D; @@ -216,6 +238,7 @@ struct ModuleShape3D { /*shape access functions*/ typedef typename std::vector >::const_iterator geometry3d_iterator; typedef typename std::vector >::const_iterator shape3d_iterator; + typedef typename std::vector >::const_iterator constraint3d_iterator; shape3d_iterator beginShape3D() { return m_shapes.begin(); }; @@ -228,12 +251,18 @@ struct ModuleShape3D { geometry3d_iterator endGeometry3D() { return m_geometries.end(); }; + constraint3d_iterator beginConstraint3D() { + return m_constraints.begin(); + }; + constraint3d_iterator endConstraint3D() { + return m_constraints.end(); + }; boost::shared_ptr geometry(purpose f); template boost::shared_ptr subshape(); - void recalc(boost::shared_ptr g); + void recalc(boost::shared_ptr g); protected: typedef details::Geometry Base; @@ -346,19 +375,32 @@ struct ModuleShape3D { //inheriter for own functions struct inheriter_base { - inheriter_base(){ - m_this = (Sys*)this; - }; + inheriter_base() { + m_this = (Sys*)this; + }; - private: + protected: Sys* m_this; public: //with no vararg templates before c++11 we need preprocessor to create the overloads of create we need BOOST_PP_REPEAT(5, CREATE_DEF, ~) + void removeShape3D(boost::shared_ptr g); }; - struct inheriter_id : public inheriter_base {}; + + struct inheriter_id : public inheriter_base { + //we don't have a createshape3d method with identifier, as identifiers can be used to + //specifie creation geometries or shapes. therefore a call would always be ambigious. + + void removeShape3D(ID id); + bool hasShape3D(ID id); + boost::shared_ptr getShape3D(ID id); + + protected: + using inheriter_base::m_this; + }; + struct inheriter : public mpl::if_, inheriter_base, inheriter_id>::type {}; //add properties to geometry and constraint to evaluate their shape partipance @@ -493,7 +535,7 @@ template template template void ModuleShape3D::type::Shape3D_base::recalc(boost::shared_ptr g) { - + //we recalculated thebase line, that means we have our new value. use it. Base::finishCalculation(); }; @@ -586,6 +628,60 @@ ModuleShape3D::type::Shape3D::Shape3D(const T& geometry, Sys& }; +template +template +void ModuleShape3D::type::inheriter_base::removeShape3D(boost::shared_ptr g) { + + //remove all constraints + typedef typename Shape3D::constraint3d_iterator cit; + for(cit it=g->constraint3dBegin(); it!=g->constraint3dEnd(); it++) + m_this->removeConstraint3D(*it); + + //remove all geometries + typedef typename Shape3D::geometry3d_iterator git; + for(git it=g->geometry3dBegin(); it!=g->geometry3dEnd(); it++) + m_this->removeGeometry3D(*it); + + //remove all subshapes + typedef typename Shape3D::shape3d_iterator sit; + for(sit it=g->shape3dBegin(); it!=g->shape3dEnd(); it++) + m_this->removeShape3D(*it); + + //emit remove shape signal bevore actually deleting it + g->template emitSignal(g); + m_this->erase(g); +}; + +template +template +bool ModuleShape3D::type::inheriter_id::hasShape3D(Identifier id) { + if(getShape3D(id)) + return true; + return false; +}; + +template +template +boost::shared_ptr::template type::Shape3D> +ModuleShape3D::type::inheriter_id::getShape3D(Identifier id) { + std::vector< boost::shared_ptr >& vec = inheriter_base::m_this->template objectVector(); + typedef typename std::vector< boost::shared_ptr >::iterator iter; + for(iter it=vec.begin(); it!=vec.end(); it++) { + if(compare_traits::compare((*it)->getIdentifier(), id)) + return *it; + }; + return boost::shared_ptr(); +}; + +template +template +void ModuleShape3D::type::inheriter_id::removeShape3D(Identifier id) { + + boost::shared_ptr s = getShape3D(id); + if(s) + removeShape3D(s); +}; + }//dcm #endif //GCM_MODULE_SHAPE3D_H diff --git a/src/Mod/Assembly/Gui/AlignmentDialog.ui b/src/Mod/Assembly/Gui/AlignmentDialog.ui deleted file mode 100644 index e02156e12..000000000 --- a/src/Mod/Assembly/Gui/AlignmentDialog.ui +++ /dev/null @@ -1,111 +0,0 @@ - - - AlignmentDialog - - - - 0 - 0 - 270 - 95 - - - - Constraint value - - - - - - - - - 0 - 0 - - - - Offset: - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - Orientation: - - - - - - - true - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - buttonBox - accepted() - AlignmentDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - AlignmentDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/Mod/Assembly/Gui/AppAssemblyGui.cpp b/src/Mod/Assembly/Gui/AppAssemblyGui.cpp index 482327b03..20b57682f 100644 --- a/src/Mod/Assembly/Gui/AppAssemblyGui.cpp +++ b/src/Mod/Assembly/Gui/AppAssemblyGui.cpp @@ -36,12 +36,7 @@ #include "ViewProviderPart.h" #include "ViewProviderAssembly.h" #include "ViewProviderConstraintGroup.h" -#include "ViewProviderConstraintFix.h" -#include "ViewProviderConstraintDistance.h" -#include "ViewProviderConstraintAngle.h" -#include "ViewProviderConstraintOrientation.h" -#include "ViewProviderConstraintCoincidence.h" -#include "ViewProviderConstraintAlignment.h" +#include "ViewProviderConstraint.h" #include @@ -90,12 +85,7 @@ void AssemblyGuiExport initAssemblyGui() AssemblyGui::ViewProviderItemAssembly::init(); AssemblyGui::ViewProviderConstraintGroup::init(); - AssemblyGui::ViewProviderConstraintFix::init(); - AssemblyGui::ViewProviderConstraintDistance::init(); - AssemblyGui::ViewProviderConstraintAngle::init(); - AssemblyGui::ViewProviderConstraintOrientation::init(); - AssemblyGui::ViewProviderConstraintCoincidence::init(); - AssemblyGui::ViewProviderConstraintAlignment::init(); + AssemblyGui::ViewProviderConstraint::init(); // add resources and reloads the translators loadAssemblyResource(); diff --git a/src/Mod/Assembly/Gui/CMakeLists.txt b/src/Mod/Assembly/Gui/CMakeLists.txt index 837b78fa9..19ce38bfb 100644 --- a/src/Mod/Assembly/Gui/CMakeLists.txt +++ b/src/Mod/Assembly/Gui/CMakeLists.txt @@ -26,10 +26,17 @@ set(AssemblyGui_LIBS FreeCADGui ) +set(AssemblyGui_MOC_HDRS + TaskAssemblyConstraints.h + TaskDlgAssemblyConstraints.h +) +fc_wrap_cpp(AssemblyGui_MOC_SRCS ${AssemblyGui_MOC_HDRS}) +SOURCE_GROUP("Moc" FILES ${AssemblyGui_MOC_SRCS}) + qt4_add_resources(AssemblyGui_SRCS Resources/Assembly.qrc) set(AssemblyGui_UIC_SRCS - AlignmentDialog.ui + TaskAssemblyConstraints.ui ) qt4_wrap_ui(AssemblyGui_UIC_HDRS ${AssemblyGui_UIC_SRCS}) @@ -44,18 +51,10 @@ SET(AssemblyGuiViewProvider_SRCS ViewProviderConstraint.h ViewProviderConstraintGroup.cpp ViewProviderConstraintGroup.h - ViewProviderConstraintFix.cpp - ViewProviderConstraintFix.h - ViewProviderConstraintDistance.cpp - ViewProviderConstraintDistance.h - ViewProviderConstraintAngle.cpp - ViewProviderConstraintAngle.h - ViewProviderConstraintOrientation.cpp - ViewProviderConstraintOrientation.h - ViewProviderConstraintCoincidence.cpp - ViewProviderConstraintCoincidence.h - ViewProviderConstraintAlignment.cpp - ViewProviderConstraintAlignment.h + TaskDlgAssemblyConstraints.cpp + TaskDlgAssemblyConstraints.h + TaskAssemblyConstraints.h + TaskAssemblyConstraints.cpp ) SOURCE_GROUP("ViewProvider" FILES ${AssemblyGuiViewProvider_SRCS}) diff --git a/src/Mod/Assembly/Gui/CommandConstraints.cpp b/src/Mod/Assembly/Gui/CommandConstraints.cpp index ead8bd81b..7f1541dd4 100644 --- a/src/Mod/Assembly/Gui/CommandConstraints.cpp +++ b/src/Mod/Assembly/Gui/CommandConstraints.cpp @@ -32,11 +32,14 @@ #include #include #include -#include "ui_AlignmentDialog.h" +#include +#include +#include #include #include #include +#include using namespace std; @@ -106,6 +109,90 @@ std::string asSubLinkString(Assembly::ItemPart* part, std::string element) //=========================================================================== +DEF_STD_CMD(CmdAssemblyConstraint); + +CmdAssemblyConstraint::CmdAssemblyConstraint() + : Command("Assembly_Constraint") +{ + sAppModule = "Assembly"; + sGroup = QT_TR_NOOP("Assembly"); + sMenuText = QT_TR_NOOP("Constraint"); + sToolTipText = QT_TR_NOOP("Add arbitrary constraints to the assembly"); + sWhatsThis = sToolTipText; + sStatusTip = sToolTipText; + sPixmap = "Assembly_ConstraintGeneral"; +} + + +void CmdAssemblyConstraint::activated(int iMsg) +{ + Assembly::ItemAssembly* Asm = 0; + Assembly::ConstraintGroup* ConstGrp = 0; + + // retrive the standard objects needed + if(getConstraintPrerequisits(&Asm, &ConstGrp)) + return; + + 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; + }; + + 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 subproduct, 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()); + + updateActive(); + doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str()); + + commitCommand(); + + Gui::Selection().clearCompleteSelection(); +} + + +/******************************************************************************************/ + + DEF_STD_CMD(CmdAssemblyConstraintDistance); CmdAssemblyConstraintDistance::CmdAssemblyConstraintDistance() @@ -149,31 +236,26 @@ void CmdAssemblyConstraintDistance::activated(int iMsg) }; //check if this is the right place for the constraint - if( (part1.second == part2.second) && part1.second != Asm ) { + 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 subproduct, please add constraints there")); return; } - bool ok; - - double d = QInputDialog::getDouble(NULL, QObject::tr("Constraint value"), - QObject::tr("Distance:"), 0., -10000., 10000., 2, &ok); - - if(!ok) - return; - openCommand("Insert Constraint Distance"); std::string ConstrName = getUniqueObjectName("Distance"); - doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintDistance','%s')", ConstrName.c_str()); + 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().ActiveObject.Distance = %f", d); doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument()); - commitCommand(); updateActive(); + doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str()); + commitCommand(); + + Gui::Selection().clearCompleteSelection(); } /******************************************************************************************/ @@ -216,9 +298,9 @@ void CmdAssemblyConstraintFix::activated(int iMsg) 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"); + Base::Console().Message("The selected part need belongs to an subproduct, please add constraint there\n"); return; } @@ -226,15 +308,15 @@ void CmdAssemblyConstraintFix::activated(int iMsg) std::string ConstrName = getUniqueObjectName("Fix"); - doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintFix','%s')", ConstrName.c_str()); - + 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()); - commitCommand(); - updateActive(); + doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str()); + + commitCommand(); } @@ -284,30 +366,24 @@ void CmdAssemblyConstraintAngle::activated(int iMsg) }; //check if this is the right place for the constraint - if( ( (part1.second == part2.second) && part1.second != Asm ) && part1.second != Asm ) { + 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 subproduct, please add constraints there")); return; } - bool ok; - - double d = QInputDialog::getDouble(NULL, QObject::tr("Constraint value"), - QObject::tr("Angle:"), 0., 0., 360., 2, &ok); - - if(!ok) - return; - openCommand("Insert Constraint Angle"); std::string ConstrName = getUniqueObjectName("Angle"); - doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintAngle','%s')", ConstrName.c_str()); + 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().ActiveObject.Angle = %f", d); doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument()); - commitCommand(); updateActive(); + doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str()); + + commitCommand(); } @@ -358,35 +434,24 @@ void CmdAssemblyConstraintOrientation::activated(int iMsg) }; //check if this is the right place for the constraint - if( (part1.second == part2.second) && part1.second != Asm ) { + 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 subproduct, please add constraints there")); return; } - QStringList items; - - items << QObject::tr("Parallel") << QObject::tr("Perpendicular") << QObject::tr("Equal") << QObject::tr("Opposite"); - - bool ok; - - QString item = QInputDialog::getItem(NULL, QObject::tr("Constraint value"), - QObject::tr("Orientation:"), items, 0, false, &ok); - - if(!ok || item.isEmpty()) - return; - openCommand("Insert Constraint Orientation"); std::string ConstrName = getUniqueObjectName("Orientation"); - doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintOrientation','%s')", ConstrName.c_str()); + 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().ActiveObject.Orientation = '%s'", item.toStdString().c_str()); doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument()); - commitCommand(); updateActive(); + doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str()); + commitCommand(); } /******************************************************************************************/ @@ -435,35 +500,24 @@ void CmdAssemblyConstraintCoincidence::activated(int iMsg) }; //check if this is the right place for the constraint - if( (part1.second == part2.second) && part1.second != Asm ) { + 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 subproduct, please add constraints there")); return; } - QStringList items; - - items << QObject::tr("Parallel") << QObject::tr("Equal") << QObject::tr("Opposite"); - - bool ok; - - QString item = QInputDialog::getItem(NULL, QObject::tr("Constraint value"), - QObject::tr("Orientation:"), items, 0, false, &ok); - - if(!ok || item.isEmpty()) - return; - openCommand("Insert Constraint Coincidence"); std::string ConstrName = getUniqueObjectName("Coincidence"); - doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintCoincidence','%s')", ConstrName.c_str()); + 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().ActiveObject.Orientation = '%s'", item.toStdString().c_str()); doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument()); - commitCommand(); updateActive(); + doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str()); + commitCommand(); } /******************************************************************************************/ @@ -512,45 +566,31 @@ void CmdAssemblyConstraintAlignment::activated(int iMsg) }; //check if this is the right place for the constraint - if( (part1.second == part2.second) && part1.second != Asm ) { + 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 subproduct, please add constraints there")); return; } - QStringList items; - - items << QObject::tr("Parallel") << QObject::tr("Equal") << QObject::tr("Opposite"); - - QDialog dialog; - - Ui_AlignmentDialog ui; - - ui.setupUi(&dialog); - - ui.comboBox->addItems(items); - - if(dialog.exec() != QDialog::Accepted) - return; - openCommand("Insert Constraint Alignment"); std::string ConstrName = getUniqueObjectName("Alignment"); - doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintAlignment','%s')", ConstrName.c_str()); + 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().ActiveObject.Orientation = '%s'", ui.comboBox->currentText().toStdString().c_str()); - doCommand(Doc, "App.activeDocument().ActiveObject.Offset = %f", ui.doubleSpinBox->value()); doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument()); - commitCommand(); updateActive(); + doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", ConstrName.c_str()); + commitCommand(); } void CreateAssemblyConstraintCommands(void) { Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); + rcCmdMgr.addCommand(new CmdAssemblyConstraint()); rcCmdMgr.addCommand(new CmdAssemblyConstraintFix()); rcCmdMgr.addCommand(new CmdAssemblyConstraintDistance()); rcCmdMgr.addCommand(new CmdAssemblyConstraintAngle()); diff --git a/src/Mod/Assembly/Gui/Resources/Assembly.qrc b/src/Mod/Assembly/Gui/Resources/Assembly.qrc index b680f4637..67337c609 100644 --- a/src/Mod/Assembly/Gui/Resources/Assembly.qrc +++ b/src/Mod/Assembly/Gui/Resources/Assembly.qrc @@ -1,36 +1,44 @@ - - - icons/Assembly_ConstraintLock.svg - icons/Assembly_ConstraintDistance.svg - icons/Assembly_ConstraintAngle.svg - icons/Assembly_ConstraintOrientation.svg - icons/Assembly_ConstraintCoincidence.svg - icons/Assembly_ConstraintAlignment.svg - translations/Assembly_af.qm - translations/Assembly_de.qm - translations/Assembly_fi.qm - translations/Assembly_fr.qm - translations/Assembly_hr.qm - translations/Assembly_it.qm - translations/Assembly_nl.qm - translations/Assembly_no.qm - translations/Assembly_ru.qm - translations/Assembly_uk.qm - translations/Assembly_tr.qm - translations/Assembly_sv-SE.qm - translations/Assembly_pl.qm - translations/Assembly_zh-TW.qm - translations/Assembly_pt-BR.qm - translations/Assembly_cs.qm - translations/Assembly_sk.qm - translations/Assembly_es-ES.qm - translations/Assembly_zh-CN.qm - translations/Assembly_ja.qm - translations/Assembly_ro.qm - translations/Assembly_hu.qm - translations/Assembly_pt-PT.qm - translations/Assembly_sr.qm - translations/Assembly_el.qm - translations/Assembly_sl.qm - - + + + icons/Assembly_ConstraintBidirectional.svg + icons/Assembly_ConstraintUnidirectional1.svg + icons/Assembly_ConstraintUnidirectional2.svg + icons/Assembly_ConstraintPerpendicular.svg + icons/Assembly_ConstraintParallel.svg + icons/Assembly_ConstraintOpposite.svg + icons/Assembly_ConstraintEqual.svg + icons/Assembly_ConstraintLock.svg + icons/Assembly_ConstraintDistance.svg + icons/Assembly_ConstraintAngle.svg + icons/Assembly_ConstraintOrientation.svg + icons/Assembly_ConstraintCoincidence.svg + icons/Assembly_ConstraintAlignment.svg + icons/Assembly_ConstraintGeneral.svg + translations/Assembly_af.qm + translations/Assembly_de.qm + translations/Assembly_fi.qm + translations/Assembly_fr.qm + translations/Assembly_hr.qm + translations/Assembly_it.qm + translations/Assembly_nl.qm + translations/Assembly_no.qm + translations/Assembly_ru.qm + translations/Assembly_uk.qm + translations/Assembly_tr.qm + translations/Assembly_sv-SE.qm + translations/Assembly_pl.qm + translations/Assembly_zh-TW.qm + translations/Assembly_pt-BR.qm + translations/Assembly_cs.qm + translations/Assembly_sk.qm + translations/Assembly_es-ES.qm + translations/Assembly_zh-CN.qm + translations/Assembly_ja.qm + translations/Assembly_ro.qm + translations/Assembly_hu.qm + translations/Assembly_pt-PT.qm + translations/Assembly_sr.qm + translations/Assembly_el.qm + translations/Assembly_sl.qm + + diff --git a/src/Mod/Assembly/Gui/Resources/Assembly.qrc.orig b/src/Mod/Assembly/Gui/Resources/Assembly.qrc.orig new file mode 100644 index 000000000..0af9ed22d --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/Assembly.qrc.orig @@ -0,0 +1,81 @@ +<<<<<<< d6421cef81c1d7a191d1524d88c63e56e3f6d864 + + + icons/Assembly_ConstraintLock.svg + icons/Assembly_ConstraintDistance.svg + icons/Assembly_ConstraintAngle.svg + icons/Assembly_ConstraintOrientation.svg + icons/Assembly_ConstraintCoincidence.svg + icons/Assembly_ConstraintAlignment.svg + translations/Assembly_af.qm + translations/Assembly_de.qm + translations/Assembly_fi.qm + translations/Assembly_fr.qm + translations/Assembly_hr.qm + translations/Assembly_it.qm + translations/Assembly_nl.qm + translations/Assembly_no.qm + translations/Assembly_ru.qm + translations/Assembly_uk.qm + translations/Assembly_tr.qm + translations/Assembly_sv-SE.qm + translations/Assembly_pl.qm + translations/Assembly_zh-TW.qm + translations/Assembly_pt-BR.qm + translations/Assembly_cs.qm + translations/Assembly_sk.qm + translations/Assembly_es-ES.qm + translations/Assembly_zh-CN.qm + translations/Assembly_ja.qm + translations/Assembly_ro.qm + translations/Assembly_hu.qm + translations/Assembly_pt-PT.qm + translations/Assembly_sr.qm + translations/Assembly_el.qm + translations/Assembly_sl.qm + + +======= + + + icons/Assembly_ConstraintBidirectional.svg + icons/Assembly_ConstraintUnidirectional1.svg + icons/Assembly_ConstraintUnidirectional2.svg + icons/Assembly_ConstraintPerpendicular.svg + icons/Assembly_ConstraintParallel.svg + icons/Assembly_ConstraintOpposite.svg + icons/Assembly_ConstraintEqual.svg + icons/Assembly_ConstraintLock.svg + icons/Assembly_ConstraintDistance.svg + icons/Assembly_ConstraintAngle.svg + icons/Assembly_ConstraintOrientation.svg + icons/Assembly_ConstraintCoincidence.svg + icons/Assembly_ConstraintAlignment.svg + icons/Assembly_ConstraintGeneral.svg + translations/Assembly_af.qm + translations/Assembly_de.qm + translations/Assembly_fi.qm + translations/Assembly_fr.qm + translations/Assembly_hr.qm + translations/Assembly_it.qm + translations/Assembly_nl.qm + translations/Assembly_no.qm + translations/Assembly_ru.qm + translations/Assembly_uk.qm + translations/Assembly_tr.qm + translations/Assembly_sv-SE.qm + translations/Assembly_pl.qm + translations/Assembly_zh-TW.qm + translations/Assembly_pt-BR.qm + translations/Assembly_cs.qm + translations/Assembly_sk.qm + translations/Assembly_es-ES.qm + translations/Assembly_zh-CN.qm + translations/Assembly_ja.qm + translations/Assembly_ro.qm + translations/Assembly_hu.qm + translations/Assembly_pt-PT.qm + translations/Assembly_sr.qm + + +>>>>>>> revidsed assembly constraint gui interaction diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintBidirectional.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintBidirectional.svg new file mode 100644 index 000000000..6afdaba3b --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintBidirectional.svg @@ -0,0 +1,410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintEqual.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintEqual.svg new file mode 100644 index 000000000..187e17e95 --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintEqual.svg @@ -0,0 +1,390 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintGeneral.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintGeneral.svg new file mode 100644 index 000000000..0a1a15497 --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintGeneral.svg @@ -0,0 +1,305 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintOpposite.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintOpposite.svg new file mode 100644 index 000000000..1c0f0f1ba --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintOpposite.svg @@ -0,0 +1,390 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintParallel.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintParallel.svg new file mode 100644 index 000000000..4f7b9b3db --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintParallel.svg @@ -0,0 +1,397 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintPerpendicular.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintPerpendicular.svg new file mode 100644 index 000000000..df64b8ecb --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintPerpendicular.svg @@ -0,0 +1,539 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintUnidirectional1.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintUnidirectional1.svg new file mode 100644 index 000000000..5ddb1adc8 --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintUnidirectional1.svg @@ -0,0 +1,397 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintUnidirectional2.svg b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintUnidirectional2.svg new file mode 100644 index 000000000..1953a3f54 --- /dev/null +++ b/src/Mod/Assembly/Gui/Resources/icons/Assembly_ConstraintUnidirectional2.svg @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/Mod/Assembly/Gui/TaskAssemblyConstraints.cpp b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.cpp new file mode 100644 index 000000000..b77c7025c --- /dev/null +++ b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.cpp @@ -0,0 +1,412 @@ +/*************************************************************************** + * Copyright (c) 2009 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 "TaskAssemblyConstraints.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace AssemblyGui; +using namespace Gui::TaskView; + +extern Assembly::Item* ActiveAsmObject; + +TaskAssemblyConstraints::TaskAssemblyConstraints(ViewProviderConstraint* vp) + : TaskBox(Gui::BitmapFactory().pixmap("document-new"),tr("Constraints"),true, 0), view(vp) +{ + // we need a separate container widget to add all controls to + proxy = new QWidget(this); + ui = new Ui::TaskAssemblyConstraints(); + ui->setupUi(proxy); + this->groupLayout()->addWidget(proxy); + + //initialy hide the value and orientation field + ui->value_widget->hide(); + ui->orientation_widget->hide(); + + //set all basic values + Assembly::ItemAssembly* 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(); + }; + if(obj->Second.getValue()) { + QString str; + str = QString::fromAscii(obj->Second.getValue()->getNameInDocument()) + QString::fromAscii(".") + QString::fromStdString(obj->Second.getSubValues().front()); + ui->second_geom->setText(str); + if(!ass) + ass = dynamic_cast(obj->Second.getValue())->getParentAssembly(); + }; + + if(ass) + ass->execute(); + + //get the individual constraint settings + ui->value->setValue(obj->Value.getValue()); + setOrientation(dcm::Direction(obj->Orientation.getValue())); + + int v = obj->Type.getValue(); + if(v==0) + ui->fix->setChecked(true); + + if(v==1) + ui->distance->setChecked(true); + + if(v==2) + ui->orientation->setChecked(true); + + if(v==3) + ui->angle->setChecked(true); + + if(v==4) + ui->align->setChecked(true); + + if(v==5) + ui->coincident->setChecked(true); + + + setPossibleConstraints(); + + //setup all signals for event processing + QObject::connect( + ui->fix, SIGNAL(toggled(bool)), + this, SLOT(on_constraint_selection(bool))); + QObject::connect( + ui->distance, SIGNAL(toggled(bool)), + this, SLOT(on_constraint_selection(bool))); + QObject::connect( + ui->orientation, SIGNAL(toggled(bool)), + this, SLOT(on_constraint_selection(bool))); + QObject::connect( + ui->angle, SIGNAL(toggled(bool)), + this, SLOT(on_constraint_selection(bool))); + QObject::connect( + ui->align, SIGNAL(toggled(bool)), + this, SLOT(on_constraint_selection(bool))); + QObject::connect( + ui->coincident, SIGNAL(toggled(bool)), + this, SLOT(on_constraint_selection(bool))); + QObject::connect( + ui->parallel, SIGNAL(toggled(bool)), + this, SLOT(on_orientation_selection(bool))); + QObject::connect( + ui->equal, SIGNAL(toggled(bool)), + this, SLOT(on_orientation_selection(bool))); + QObject::connect( + ui->opposite, SIGNAL(toggled(bool)), + this, SLOT(on_orientation_selection(bool))); + QObject::connect( + ui->perpendicular, SIGNAL(toggled(bool)), + this, SLOT(on_orientation_selection(bool))); + QObject::connect( + ui->value, SIGNAL(valueChanged(double)), + this, SLOT(on_value_change(double))); + QObject::connect( + ui->clear_first, SIGNAL(pressed()), + this, SLOT(on_clear_first())); + QObject::connect( + ui->clear_second, SIGNAL(pressed()), + this, SLOT(on_clear_second())); + +} + +dcm::Direction TaskAssemblyConstraints::getOrientation() +{ + if(ui->parallel->isChecked()) + return dcm::parallel; + if(ui->equal->isChecked()) + return dcm::equal; + if(ui->opposite->isChecked()) + return dcm::opposite; + + return dcm::perpendicular; +} + +void TaskAssemblyConstraints::setOrientation(dcm::Direction d) +{ + switch(d) { + case dcm::perpendicular: + ui->perpendicular->setChecked(true); + break; + case dcm::equal: + ui->equal->setChecked(true); + break; + case dcm::opposite: + ui->opposite->setChecked(true); + break; + default: + ui->parallel->setChecked(true); + } +} + + +TaskAssemblyConstraints::~TaskAssemblyConstraints() +{ + delete ui; +} + +void TaskAssemblyConstraints::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if(msg.Type == Gui::SelectionChanges::AddSelection) { + + //add it as the first geometry? + if(ui->first_geom->text().isEmpty()) { + std::vector objs = Gui::Selection().getSelectionEx(); + Assembly::Constraint* con = dynamic_cast(view->getObject()); + + if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::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()); + con->First.setValue(part1.first, objs.back().getSubNames()); + QString str; + str = QString::fromAscii(part1.first->getNameInDocument()) + QString::fromAscii(".") + QString::fromStdString(con->First.getSubValues().front()); + ui->first_geom->setText(str); + + App::GetApplication().getActiveDocument()->recompute(); + setPossibleConstraints(); + view->draw(); + return; + } + + if(ui->second_geom->text().isEmpty()) { + std::vector objs = Gui::Selection().getSelectionEx(); + Assembly::Constraint* con = dynamic_cast(view->getObject()); + + if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::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()); + con->Second.setValue(part2.first, objs.back().getSubNames()); + QString str; + str = QString::fromAscii(part2.first->getNameInDocument()) + QString::fromAscii(".") + QString::fromStdString(con->Second.getSubValues().front()); + ui->second_geom->setText(str); + + App::GetApplication().getActiveDocument()->recompute(); + setPossibleConstraints(); + view->draw(); + return; + } + }; +} + +void TaskAssemblyConstraints::on_constraint_selection(bool clicked) +{ + if(clicked) { + Assembly::Constraint* obj = dynamic_cast(view->getObject()); + + if(ui->fix->isChecked()) + obj->Type.setValue("Fix"); + + if(ui->distance->isChecked()) + obj->Type.setValue("Distance"); + + if(ui->orientation->isChecked()) + obj->Type.setValue("Orientation"); + + if(ui->angle->isChecked()) + obj->Type.setValue("Angle"); + + if(ui->align->isChecked()) + obj->Type.setValue("Align"); + + if(ui->coincident->isChecked()) + obj->Type.setValue("Coincident"); + + App::GetApplication().getActiveDocument()->recompute(); + view->draw(); + } + +} + +void TaskAssemblyConstraints::on_orientation_selection(bool clicked) +{ + if(clicked) { + Assembly::Constraint* obj = dynamic_cast(view->getObject()); + obj->Orientation.setValue(getOrientation()); + + App::GetApplication().getActiveDocument()->recompute(); + view->draw(); + } +} + +void TaskAssemblyConstraints::on_value_change(double val) +{ + + Assembly::Constraint* obj = dynamic_cast(view->getObject()); + obj->Value.setValue(ui->value->value()); + + App::GetApplication().getActiveDocument()->recompute(); + view->draw(); +} + +void TaskAssemblyConstraints::on_clear_first() +{ + Assembly::Constraint* obj = dynamic_cast(view->getObject()); + obj->First.setValue(NULL); + ui->first_geom->clear(); + setPossibleConstraints(); + view->draw(); +} + +void TaskAssemblyConstraints::on_clear_second() +{ + + Assembly::Constraint* obj = dynamic_cast(view->getObject()); + obj->Second.setValue(NULL); + ui->second_geom->clear(); + setPossibleConstraints(); + view->draw(); +} + +void TaskAssemblyConstraints::setPossibleConstraints() +{ + ui->fix->setEnabled(false); + ui->distance->setEnabled(false); + ui->orientation->setEnabled(false); + ui->angle->setEnabled(false); + ui->align->setEnabled(false); + ui->coincident->setEnabled(false); + + Assembly::Constraint* obj = dynamic_cast(view->getObject()); + if(obj->First.getValue()) { + + Assembly::ItemPart* p1 = dynamic_cast(obj->First.getValue()); + + if(!p1) + return; + + Assembly::ItemAssembly* ass = p1->getParentAssembly(); + + //extract the geometries to use for comparison + boost::shared_ptr g1 = ass->m_solver->getGeometry3D(obj->First.getSubValues()[0].c_str()); + if(obj->Second.getValue()) { + Assembly::ItemPart* p2 = dynamic_cast(obj->Second.getValue()); + if(!p2) + return; + + boost::shared_ptr g2 = ass->m_solver->getGeometry3D(obj->Second.getSubValues()[0].c_str()); + + //check all valid combinaions + if(isCombination(g1,g2, dcm::geometry::point, dcm::geometry::point)) { + ui->distance->setEnabled(true); + ui->coincident->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::point, dcm::geometry::line)) { + ui->distance->setEnabled(true); + ui->coincident->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::point, dcm::geometry::plane)) { + ui->distance->setEnabled(true); + ui->coincident->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::point, dcm::geometry::cylinder)) { + ui->distance->setEnabled(true); + ui->coincident->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::line, dcm::geometry::line)) { + ui->distance->setEnabled(true); + ui->orientation->setEnabled(true); + ui->angle->setEnabled(true); + ui->coincident->setEnabled(true); + ui->align->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::line, dcm::geometry::plane)) { + ui->orientation->setEnabled(true); + ui->angle->setEnabled(true); + ui->coincident->setEnabled(true); + ui->align->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::line, dcm::geometry::cylinder)) { + ui->distance->setEnabled(true); + ui->orientation->setEnabled(true); + ui->angle->setEnabled(true); + ui->coincident->setEnabled(true); + ui->align->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::plane, dcm::geometry::plane)) { + ui->orientation->setEnabled(true); + ui->angle->setEnabled(true); + ui->coincident->setEnabled(true); + ui->align->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::plane, dcm::geometry::cylinder)) { + ui->orientation->setEnabled(true); + ui->angle->setEnabled(true); + ui->coincident->setEnabled(true); + ui->align->setEnabled(true); + }; + if(isCombination(g1,g2, dcm::geometry::cylinder, dcm::geometry::cylinder)) { + ui->coincident->setEnabled(true); + }; + } + else { + //only fix works + ui->fix->setEnabled(true); + }; + } +} + +bool TaskAssemblyConstraints::isCombination(boost::shared_ptr g1, boost::shared_ptr g2, dcm::geometry::types t1, dcm::geometry::types t2) +{ + if(g1->getGeometryType() == t1 && g2->getGeometryType() == t2) + return true; + + if(g1->getGeometryType() == t2 && g2->getGeometryType() == t1) + return true; + + return false; +} + + + + +#include "moc_TaskAssemblyConstraints.cpp" + diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintFix.h b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.h similarity index 57% rename from src/Mod/Assembly/Gui/ViewProviderConstraintFix.h rename to src/Mod/Assembly/Gui/TaskAssemblyConstraints.h index 7e0658880..522e8095f 100644 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintFix.h +++ b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.h @@ -21,24 +21,52 @@ ***************************************************************************/ -#ifndef ASSEMBLYGUI_VIEWPROVIDERCONSTRAINTFIX_H -#define ASSEMBLYGUI_VIEWPROVIDERCONSTRAINTFIX_H +#ifndef GUI_TASKVIEW_TaskAssemblyConstraints_H +#define GUI_TASKVIEW_TaskAssemblyConstraints_H +#include +#include #include "ViewProviderConstraint.h" +#include +#include +#include +#include "ui_TaskAssemblyConstraints.h" + +namespace App { +class Property; +} namespace AssemblyGui { - -class AssemblyGuiExport ViewProviderConstraintFix : public ViewProviderConstraint { - - PROPERTY_HEADER(AssemblyGui::ViewProviderConstraintFix); + +class TaskAssemblyConstraints : public Gui::TaskView::TaskBox, public Gui::SelectionObserver +{ + Q_OBJECT public: - ViewProviderConstraintFix(); + TaskAssemblyConstraints(ViewProviderConstraint* vp); + ~TaskAssemblyConstraints(); - // override linked shape as we want to highlight the whole part - TopoDS_Shape getConstraintShape(int link); + /// Observer message from the Selection + void onSelectionChanged(const Gui::SelectionChanges& msg); + +public Q_SLOTS: + void on_constraint_selection(bool clicked); + void on_value_change(double val); + void on_orientation_selection(bool clicked); + void on_clear_first(); + void on_clear_second(); + +private: + QWidget* proxy; + Ui::TaskAssemblyConstraints* ui; + ViewProviderConstraint* view; + + void setOrientation(dcm::Direction); + dcm::Direction getOrientation(); + void setPossibleConstraints(); + bool isCombination(boost::shared_ptr g1, boost::shared_ptr g2, dcm::geometry::types t1, dcm::geometry::types t2); }; -}; +} //namespace AssemblyGui -#endif // VIEWPROVIDERCONSTRAINTFIX_H +#endif // GUI_TASKVIEW_TASKAPPERANCE_H diff --git a/src/Mod/Assembly/Gui/TaskAssemblyConstraints.ui b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.ui new file mode 100644 index 000000000..f7039c466 --- /dev/null +++ b/src/Mod/Assembly/Gui/TaskAssemblyConstraints.ui @@ -0,0 +1,979 @@ + + + TaskAssemblyConstraints + + + + 0 + 0 + 297 + 541 + + + + Form + + + + + + + + false + + + true + + + First constraint geometry + + + + + + + ... + + + + :/icons/delete.png:/icons/delete.png + + + true + + + + + + + + + + + false + + + true + + + Second constraint geometry + + + + + + + ... + + + + :/icons/delete.png:/icons/delete.png + + + true + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + QLayout::SetNoConstraint + + + + + + 0 + 0 + + + + Distance + + + + :/icons/Assembly_ConstraintDistance.svg:/icons/Assembly_ConstraintDistance.svg + + + + 20 + 20 + + + + true + + + false + + + true + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + + 0 + 0 + + + + Coincident + + + + :/icons/Assembly_ConstraintCoincidence.svg:/icons/Assembly_ConstraintCoincidence.svg + + + + 20 + 20 + + + + true + + + false + + + true + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + + 0 + 0 + + + + Fix + + + + :/icons/Assembly_ConstraintLock.svg:/icons/Assembly_ConstraintLock.svg + + + + 20 + 20 + + + + true + + + false + + + true + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + + 0 + 0 + + + + Orientation + + + + :/icons/Assembly_ConstraintOrientation.svg:/icons/Assembly_ConstraintOrientation.svg + + + + 20 + 20 + + + + true + + + false + + + true + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + + 0 + 0 + + + + Align + + + + :/icons/Assembly_ConstraintAlignment.svg:/icons/Assembly_ConstraintAlignment.svg + + + + 20 + 20 + + + + true + + + false + + + true + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + + 0 + 0 + + + + Angle + + + + :/icons/Assembly_ConstraintAngle.svg:/icons/Assembly_ConstraintAngle.svg + + + + 20 + 20 + + + + true + + + false + + + true + + + Qt::ToolButtonTextBesideIcon + + + true + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + QFrame::HLine + + + QFrame::Raised + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 13 + + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + value + + + + + + + + 0 + 0 + + + + + + + + + + + ... + + + + :/icons/Assembly_ConstraintBidirectional.svg:/icons/Assembly_ConstraintBidirectional.svg + + + + 16 + 16 + + + + true + + + true + + + true + + + true + + + + + + + + 0 + 0 + + + + ... + + + + :/icons/Assembly_ConstraintUnidirectional2.svg:/icons/Assembly_ConstraintUnidirectional2.svg + + + + 16 + 16 + + + + true + + + true + + + true + + + + + + + + 0 + 0 + + + + ... + + + + :/icons/Assembly_ConstraintUnidirectional1.svg:/icons/Assembly_ConstraintUnidirectional1.svg + + + + 16 + 16 + + + + true + + + true + + + true + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 5 + 5 + + + + + + + + + + + + 0 + 0 + + + + Parallel + + + + :/icons/Assembly_ConstraintParallel.svg:/icons/Assembly_ConstraintParallel.svg + + + + 20 + 20 + + + + true + + + true + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 0 + 0 + + + + Equal + + + + :/icons/Assembly_ConstraintEqual.svg:/icons/Assembly_ConstraintEqual.svg + + + + 20 + 20 + + + + true + + + true + + + true + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 0 + 0 + + + + Opposite + + + + :/icons/Assembly_ConstraintOpposite.svg:/icons/Assembly_ConstraintOpposite.svg + + + + 20 + 20 + + + + true + + + true + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 0 + 0 + + + + false + + + Perpend. + + + + :/icons/Assembly_ConstraintPerpendicular.svg:/icons/Assembly_ConstraintPerpendicular.svg + + + + 20 + 20 + + + + true + + + true + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + distance + toggled(bool) + value_widget + setVisible(bool) + + + 170 + 94 + + + 172 + 210 + + + + + distance + toggled(bool) + orientation_widget + setHidden(bool) + + + 170 + 94 + + + 209 + 247 + + + + + fix + toggled(bool) + value_widget + setHidden(bool) + + + 58 + 94 + + + 209 + 210 + + + + + fix + toggled(bool) + orientation_widget + setHidden(bool) + + + 58 + 94 + + + 209 + 247 + + + + + orientation + toggled(bool) + value_widget + setHidden(bool) + + + 284 + 94 + + + 209 + 210 + + + + + orientation + toggled(bool) + orientation_widget + setVisible(bool) + + + 284 + 94 + + + 209 + 247 + + + + + angle + toggled(bool) + value_widget + setVisible(bool) + + + 58 + 126 + + + 172 + 209 + + + + + angle + toggled(bool) + orientation_widget + setHidden(bool) + + + 58 + 126 + + + 172 + 246 + + + + + align + toggled(bool) + value_widget + setVisible(bool) + + + 170 + 126 + + + 172 + 209 + + + + + align + toggled(bool) + orientation_widget + setVisible(bool) + + + 170 + 126 + + + 172 + 246 + + + + + coincident + toggled(bool) + value_widget + setHidden(bool) + + + 284 + 126 + + + 172 + 209 + + + + + coincident + toggled(bool) + orientation_widget + setVisible(bool) + + + 284 + 126 + + + 172 + 246 + + + + + distance + toggled(bool) + value + setFocus() + + + 170 + 94 + + + 147 + 203 + + + + + distance + toggled(bool) + value + selectAll() + + + 170 + 94 + + + 147 + 203 + + + + + angle + toggled(bool) + value + setFocus() + + + 58 + 126 + + + 147 + 203 + + + + + angle + toggled(bool) + value + selectAll() + + + 58 + 126 + + + 147 + 203 + + + + + align + toggled(bool) + value + setFocus() + + + 170 + 126 + + + 147 + 203 + + + + + align + toggled(bool) + value + selectAll() + + + 170 + 126 + + + 147 + 203 + + + + + diff --git a/src/Mod/Assembly/App/ConstraintFix.cpp b/src/Mod/Assembly/Gui/TaskDlgAssemblyConstraints.cpp similarity index 50% rename from src/Mod/Assembly/App/ConstraintFix.cpp rename to src/Mod/Assembly/Gui/TaskDlgAssemblyConstraints.cpp index fe05bb32b..6834060da 100644 --- a/src/Mod/Assembly/App/ConstraintFix.cpp +++ b/src/Mod/Assembly/Gui/TaskDlgAssemblyConstraints.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2010 Juergen Riegel * + * Copyright (c) 2009 Jürgen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * @@ -22,60 +22,68 @@ #include "PreCompiled.h" + #ifndef _PreComp_ #endif -#include -#include -#include "ItemPart.h" +#include "TaskDlgAssemblyConstraints.h" +#include +#include -#include "ConstraintFix.h" +using namespace AssemblyGui; -using namespace Assembly; +//************************************************************************** +//************************************************************************** +// TaskDialog +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -namespace Assembly { - - -PROPERTY_SOURCE(Assembly::ConstraintFix, Assembly::Constraint) - -ConstraintFix::ConstraintFix() { - -} - -ConstraintFix::~ConstraintFix() { - - Assembly::ItemPart* part = static_cast(First.getValue()); - if(part && part->m_part) { - part->m_part->fix(false); - } -} - -short ConstraintFix::mustExecute() const { - //if (Sketch.isTouched() || - // Length.isTouched()) - // return 1; - return 0; -} - -App::DocumentObjectExecReturn* ConstraintFix::execute(void) { - - return App::DocumentObject::StdReturn; -} - -void ConstraintFix::init(Assembly::ItemAssembly* ass) { - - //cant use the base class init as we only need one part - initLink(First); - - //get the part - Assembly::ItemPart* part = static_cast(First.getValue()); - if(!part) - return; +TaskDlgAssemblyConstraints::TaskDlgAssemblyConstraints(ViewProviderConstraint* vp) + : TaskDialog(), view(vp) +{ + Constraints = new TaskAssemblyConstraints(vp); - //init the constraint - part->m_part->fix(true); + Content.push_back(Constraints); +} -}; +TaskDlgAssemblyConstraints::~TaskDlgAssemblyConstraints() +{ } + +//==== calls from the TaskView =============================================================== + + +void TaskDlgAssemblyConstraints::open() +{ + +} + +void TaskDlgAssemblyConstraints::clicked(int) +{ + +} + +bool TaskDlgAssemblyConstraints::accept() +{ + std::string document = getDocumentName(); // needed because resetEdit() deletes this instance + Gui::Command::doCommand(Gui::Command::Gui,"Gui.getDocument('%s').resetEdit()", document.c_str()); + + return true; +} + +bool TaskDlgAssemblyConstraints::reject() +{ + std::string document = getDocumentName(); // needed because resetEdit() deletes this instance + Gui::Command::doCommand(Gui::Command::Gui,"Gui.getDocument('%s').resetEdit()", document.c_str()); + + return true; +} + +void TaskDlgAssemblyConstraints::helpRequested() +{ + +} + + +#include "moc_TaskDlgAssemblyConstraints.cpp" diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintAngle.h b/src/Mod/Assembly/Gui/TaskDlgAssemblyConstraints.h similarity index 52% rename from src/Mod/Assembly/Gui/ViewProviderConstraintAngle.h rename to src/Mod/Assembly/Gui/TaskDlgAssemblyConstraints.h index 51b1e849a..08c9d9ea4 100644 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintAngle.h +++ b/src/Mod/Assembly/Gui/TaskDlgAssemblyConstraints.h @@ -1,42 +1,70 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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_VIEWPROVIDERCONSTRAINTANGLE_H -#define ASSEMBLYGUI_VIEWPROVIDERCONSTRAINTANGLE_H - -#include "ViewProviderConstraint.h" - -namespace AssemblyGui { - -class AssemblyGuiExport ViewProviderConstraintAngle : public ViewProviderConstraint { - - PROPERTY_HEADER(AssemblyGui::ViewProviderConstraintAngle); - -public: - ViewProviderConstraintAngle(); - -}; - -}; - -#endif // VIEWPROVIDERCONSTRAINTFIX_H +/*************************************************************************** + * Copyright (c) 2009 Jürgen 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_TaskDlgAssemblyConstraints_H +#define ASSEMBLYGUI_TaskDlgAssemblyConstraints_H + +#include +#include "TaskAssemblyConstraints.h" +#include "ViewProviderConstraint.h" + +namespace AssemblyGui { + + +/// simulation dialog for the TaskView +class AssemblyGuiExport TaskDlgAssemblyConstraints : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgAssemblyConstraints(ViewProviderConstraint* vp); + ~TaskDlgAssemblyConstraints(); + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual void helpRequested(); + virtual bool isAllowedAlterDocument(void) const + { return false; } + + /// returns for Close and Help button + virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const + { return QDialogButtonBox::Ok|QDialogButtonBox::Help; } + +protected: + TaskAssemblyConstraints *Constraints; + ViewProviderConstraint *view; +}; + + + +} //namespace AssemblyGui + +#endif // ASSEMBLYGUI_TaskDlgAssemblyConstraints_H diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp index 19445eba2..f488bc908 100644 --- a/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderConstraint.cpp @@ -22,11 +22,14 @@ #include "PreCompiled.h" #include "ViewProviderConstraint.h" +#include "TaskAssemblyConstraints.h" +#include "TaskDlgAssemblyConstraints.h" #include "Mod/Assembly/App/Constraint.h" #include "Mod/Assembly/App/ItemPart.h" #include #include #include +#include #include #include #include @@ -43,7 +46,7 @@ ViewProviderConstraintInternal::ViewProviderConstraintInternal() { //constraint entiti color ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); - unsigned long scol = hGrp->GetUnsigned("ConstructionColor", 56319UL); + unsigned long scol = hGrp->GetUnsigned("ConstructionColor", 56319UL); float r, g, b; r = ((scol >> 24) & 0xff) / 255.0; g = ((scol >> 16) & 0xff) / 255.0; @@ -74,6 +77,7 @@ ViewProviderConstraintInternal::ViewProviderConstraintInternal() PointSize.setValue(lwidth); Transparency.setValue(50); + }; void ViewProviderConstraintInternal::updateVis(const TopoDS_Shape& shape) @@ -103,10 +107,10 @@ void ViewProviderConstraintInternal::switch_node(bool onoff) pcModeSwitch->whichChild = -1; } -void ViewProviderConstraint::setDisplayMode(const char* ModeName) +void ViewProviderConstraint::setDisplayMode(const char* ModeName) { - setDisplayMaskMode("Flat Lines"); - + setDisplayMaskMode("Flat Lines"); + } std::vector ViewProviderConstraint::getDisplayModes(void) const @@ -127,7 +131,7 @@ ViewProviderConstraint::ViewProviderConstraint() : m_selected(false) //constraint entiti color ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); - unsigned long scol = hGrp->GetUnsigned("ConstructionColor", 56319UL); + unsigned long scol = hGrp->GetUnsigned("ConstructionColor", 56319UL); float r, g, b; r = ((scol >> 24) & 0xff) / 255.0; g = ((scol >> 16) & 0xff) / 255.0; @@ -196,6 +200,24 @@ void ViewProviderConstraint::update(const App::Property* prop) { void ViewProviderConstraint::updateData(const App::Property* prop) { + + //set the icon + int v = dynamic_cast(getObject())->Type.getValue(); + if(v == 4) + sPixmap = "Assembly_ConstraintAlignment"; + if(v == 3) + sPixmap = "Assembly_ConstraintAngle"; + if(v == 5) + sPixmap = "Assembly_ConstraintCoincidence"; + if(v == 1) + sPixmap = "Assembly_ConstraintDistance"; + if(v == 0) + sPixmap = "Assembly_ConstraintLock"; + if(v == 2) + sPixmap = "Assembly_ConstraintOrientation"; + if(v==6) + sPixmap = "Assembly_ConstraintGeneral"; + if(Visibility.getValue() && m_selected) { draw(); @@ -206,7 +228,7 @@ void ViewProviderConstraint::updateData(const App::Property* prop) { } void ViewProviderConstraint::onChanged(const App::Property* prop) -{ +{ // parent expects the app object to be part::feature, but it isn't. so we have to avoid // the visability prop as this results in accessing of the part::feature and would crash if(prop == &Visibility) { @@ -293,22 +315,22 @@ void ViewProviderConstraint::draw() } void ViewProviderConstraint::upstream_placement(Base::Placement& p, Assembly::Item* item) { - - //successive transformation for this item - p = item->Placement.getValue() * p; - typedef std::vector::const_iterator iter; + //successive transformation for this item + p = item->Placement.getValue() * p; - //get all links to this item and see if we have more ItemAssemblys - const std::vector& vector = item->getInList(); - for(iter it=vector.begin(); it != vector.end(); it++) { + typedef std::vector::const_iterator iter; - if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) { + //get all links to this item and see if we have more ItemAssemblys + const std::vector& vector = item->getInList(); + for(iter it=vector.begin(); it != vector.end(); it++) { - upstream_placement(p, static_cast(*it)); - return; - } - }; + if((*it)->getTypeId() == Assembly::ItemAssembly::getClassTypeId()) { + + upstream_placement(p, static_cast(*it)); + return; + } + }; }; void ViewProviderConstraint::onSelectionChanged(const Gui::SelectionChanges& msg) @@ -320,7 +342,7 @@ void ViewProviderConstraint::onSelectionChanged(const Gui::SelectionChanges& msg pcModeSwitch->whichChild = 0; draw(); } - else { + else if(!isEditing()) { internal_vp.switch_node(false); pcModeSwitch->whichChild = -1; m_selected = false; @@ -350,7 +372,8 @@ TopoDS_Shape ViewProviderConstraint::getConstraintShape(int link) if(feature1->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { ts = static_cast(feature1)->Shape.getShape(); } - else return TopoDS_Shape(); + else + return TopoDS_Shape(); TopoDS_Shape s1 = ts.getSubShape(dynamic_cast(pcObject)->First.getSubValues()[0].c_str()); @@ -375,7 +398,8 @@ TopoDS_Shape ViewProviderConstraint::getConstraintShape(int link) if(feature2->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { ts2 = static_cast(feature2)->Shape.getShape(); } - else return TopoDS_Shape(); + else + return TopoDS_Shape(); TopoDS_Shape s2 = ts2.getSubShape(dynamic_cast(pcObject)->Second.getSubValues()[0].c_str()); @@ -387,3 +411,36 @@ void ViewProviderConstraint::setupContextMenu(QMenu* menu, QObject* receiver, co { ViewProviderDocumentObject::setupContextMenu(menu, receiver, member); } + +bool ViewProviderConstraint::setEdit(int ModNum) +{ + + // When double-clicking on the item for this sketch the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); + TaskDlgAssemblyConstraints* ConstraintsDlg = qobject_cast(dlg); + + // start the edit dialog + if(ConstraintsDlg) + Gui::Control().showDialog(ConstraintsDlg); + else + Gui::Control().showDialog(new TaskDlgAssemblyConstraints(this)); + + //show the constraint geometries + internal_vp.switch_node(true); + pcModeSwitch->whichChild = 0; + draw(); + + return true; +} + +void ViewProviderConstraint::unsetEdit(int ModNum) +{ + if(!Gui::Selection().isSelected(pcObject) || !Visibility.getValue()) { + internal_vp.switch_node(false); + pcModeSwitch->whichChild = -1; + m_selected = false; + } +} + diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraint.h b/src/Mod/Assembly/Gui/ViewProviderConstraint.h index 7164968b9..7aa57ef20 100644 --- a/src/Mod/Assembly/Gui/ViewProviderConstraint.h +++ b/src/Mod/Assembly/Gui/ViewProviderConstraint.h @@ -91,16 +91,18 @@ public: virtual void setDisplayMode(const char* ModeName); virtual std::vector getDisplayModes(void) const; - //avoid transformation on doouble click - virtual bool doubleClicked(void) {return true;}; + //bring up constraint task when in edit mode + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + + //update visualisation and placements of the scenegraph + void draw(); private: //we need two seperate visual representations, as both constraint parts have different //placements. ViewProviderConstraintInternal internal_vp; - //update visualisation and placements of the scenegraph - void draw(); void upstream_placement(Base::Placement& p, Assembly::Item* item); //watch if something got selected in the tree diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintAlignment.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraintAlignment.cpp deleted file mode 100644 index b602be39e..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintAlignment.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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" -#include "ViewProviderConstraintAlignment.h" - -using namespace AssemblyGui; - -PROPERTY_SOURCE(AssemblyGui::ViewProviderConstraintAlignment, Gui::ViewProviderDocumentObject) - -ViewProviderConstraintAlignment::ViewProviderConstraintAlignment() { - - sPixmap = "Assembly_ConstraintAlignment"; -} - diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintAlignment.h b/src/Mod/Assembly/Gui/ViewProviderConstraintAlignment.h deleted file mode 100644 index 703937d25..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintAlignment.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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_VIEWPROVIDERCONSTRAINTAlignment_H -#define ASSEMBLYGUI_VIEWPROVIDERCONSTRAINTAlignment_H - -#include "ViewProviderConstraint.h" - -namespace AssemblyGui { - -class AssemblyGuiExport ViewProviderConstraintAlignment : public ViewProviderConstraint { - - PROPERTY_HEADER(AssemblyGui::ViewProviderConstraintAlignment); - -public: - ViewProviderConstraintAlignment(); -}; - -}; - -#endif // VIEWPROVIDERCONSTRAINTFIX_H diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintAngle.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraintAngle.cpp deleted file mode 100644 index 229f80869..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintAngle.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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" -#include "ViewProviderConstraintAngle.h" - -using namespace AssemblyGui; - -PROPERTY_SOURCE(AssemblyGui::ViewProviderConstraintAngle, Gui::ViewProviderDocumentObject) - -ViewProviderConstraintAngle::ViewProviderConstraintAngle() { - - sPixmap = "Assembly_ConstraintAngle"; -} - diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintCoincidence.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraintCoincidence.cpp deleted file mode 100644 index eeca7d5c0..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintCoincidence.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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" -#include "ViewProviderConstraintCoincidence.h" - -using namespace AssemblyGui; - -PROPERTY_SOURCE(AssemblyGui::ViewProviderConstraintCoincidence, Gui::ViewProviderDocumentObject) - -ViewProviderConstraintCoincidence::ViewProviderConstraintCoincidence() { - - sPixmap = "Assembly_ConstraintCoincidence"; -} - diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintCoincidence.h b/src/Mod/Assembly/Gui/ViewProviderConstraintCoincidence.h deleted file mode 100644 index e922488d0..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintCoincidence.h +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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_VIEWPROVIDERCONSTRAINTCoincidence_H -#define ASSEMBLYGUI_VIEWPROVIDERCONSTRAINTCoincidence_H - -#include "ViewProviderConstraint.h" - -namespace AssemblyGui { - -class AssemblyGuiExport ViewProviderConstraintCoincidence : public ViewProviderConstraint { - - PROPERTY_HEADER(AssemblyGui::ViewProviderConstraintCoincidence); - -public: - ViewProviderConstraintCoincidence(); - -}; - -}; - -#endif // VIEWPROVIDERCONSTRAINTFIX_H diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintDistance.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraintDistance.cpp deleted file mode 100644 index 817a6432f..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintDistance.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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" -#include "ViewProviderConstraintDistance.h" - -using namespace AssemblyGui; - -PROPERTY_SOURCE(AssemblyGui::ViewProviderConstraintDistance, Gui::ViewProviderDocumentObject) - -ViewProviderConstraintDistance::ViewProviderConstraintDistance() { - - sPixmap = "Assembly_ConstraintDistance"; -} - diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintDistance.h b/src/Mod/Assembly/Gui/ViewProviderConstraintDistance.h deleted file mode 100644 index 574158da1..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintDistance.h +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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_VIEWPROVIDERCONSTRAINTDISTANCE_H -#define ASSEMBLYGUI_VIEWPROVIDERCONSTRAINTDISTANCE_H - -#include -#include "ViewProviderConstraint.h" - -namespace AssemblyGui { - -class AssemblyGuiExport ViewProviderConstraintDistance : public ViewProviderConstraint { - - PROPERTY_HEADER(AssemblyGui::ViewProviderConstraintDistance); - -public: - ViewProviderConstraintDistance(); - -}; - -}; - -#endif // VIEWPROVIDERCONSTRAINTFIX_H diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintFix.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraintFix.cpp deleted file mode 100644 index 5e03f755b..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintFix.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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" -#include "ViewProviderConstraintFix.h" -#include "Mod/Assembly/App/ConstraintFix.h" -#include "Mod/Assembly/App/ItemPart.h" -#include - -using namespace AssemblyGui; - -PROPERTY_SOURCE(AssemblyGui::ViewProviderConstraintFix, Gui::ViewProviderDocumentObject) - -ViewProviderConstraintFix::ViewProviderConstraintFix() { - - sPixmap = "Assembly_ConstraintLock"; -} - -TopoDS_Shape ViewProviderConstraintFix::getConstraintShape(int link) -{ - if(link == 1) { - - App::DocumentObject* obj = dynamic_cast(pcObject)->First.getValue(); - if(!obj) - return TopoDS_Shape(); - - Assembly::ItemPart* part = static_cast(obj); - if(!part) - return TopoDS_Shape(); - - //return the whole shape - return part->getShape(); - } - - //there is no second link, only one part is fixed per constraint - return TopoDS_Shape(); -} diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintOrientation.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraintOrientation.cpp deleted file mode 100644 index 4240613c4..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintOrientation.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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" -#include "ViewProviderConstraintOrientation.h" - -using namespace AssemblyGui; - -PROPERTY_SOURCE(AssemblyGui::ViewProviderConstraintOrientation, Gui::ViewProviderDocumentObject) - -ViewProviderConstraintOrientation::ViewProviderConstraintOrientation() { - - sPixmap = "Assembly_ConstraintOrientation"; -} - diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintOrientation.h b/src/Mod/Assembly/Gui/ViewProviderConstraintOrientation.h deleted file mode 100644 index 3f4bebfc0..000000000 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintOrientation.h +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2013 Stefan Tröger * - * * - * 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_VIEWPROVIDERCONSTRAINTORIENTATION_H -#define ASSEMBLYGUI_VIEWPROVIDERCONSTRAINTORIENTATION_H - -#include "ViewProviderConstraint.h" - -namespace AssemblyGui { - -class AssemblyGuiExport ViewProviderConstraintOrientation : public ViewProviderConstraint { - - PROPERTY_HEADER(AssemblyGui::ViewProviderConstraintOrientation); - -public: - ViewProviderConstraintOrientation(); - -}; - -}; - -#endif // VIEWPROVIDERCONSTRAINTFIX_H diff --git a/src/Mod/Assembly/Gui/Workbench.cpp b/src/Mod/Assembly/Gui/Workbench.cpp index 3db61cf6b..e003dbedc 100644 --- a/src/Mod/Assembly/Gui/Workbench.cpp +++ b/src/Mod/Assembly/Gui/Workbench.cpp @@ -52,6 +52,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem* root = StdWorkbench::setupToolBars(); Gui::ToolBarItem* part = new Gui::ToolBarItem(root); part->setCommand(QT_TR_NOOP("Assembly")); + *part << "Assembly_Constraint"; *part << "Assembly_ConstraintFix"; *part << "Assembly_ConstraintDistance"; *part << "Assembly_ConstraintOrientation";