diff --git a/src/Mod/Assembly/App/AppAssembly.cpp b/src/Mod/Assembly/App/AppAssembly.cpp index d46f1d4d9..773af74c3 100644 --- a/src/Mod/Assembly/App/AppAssembly.cpp +++ b/src/Mod/Assembly/App/AppAssembly.cpp @@ -34,6 +34,14 @@ #include "ItemAssembly.h" #include "ItemPart.h" +#include "ConstraintAngle.h" +#include "ConstraintAxis.h" +#include "ConstraintContact.h" +#include "ConstraintFix.h" +#include "ConstraintGroup.h" +#include "ConstraintOffset.h" + + extern struct PyMethodDef Assembly_methods[]; PyDoc_STRVAR(module_Assembly_doc, @@ -64,9 +72,19 @@ void AssemblyExport initAssembly() // call PyType_Ready, otherwise we run into a segmentation fault, later on. // This function is responsible for adding inherited slots from a type's base class. + // Item hirachy Assembly::Item ::init(); Assembly::ItemAssembly ::init(); Assembly::ItemPart ::init(); + + // constraint hirachy + Assembly::Constraint ::init(); + Assembly::ConstraintAngle ::init(); + Assembly::ConstraintAxis ::init(); + Assembly::ConstraintContact ::init(); + Assembly::ConstraintFix ::init(); + Assembly::ConstraintOffset ::init(); + Assembly::ConstraintGroup ::init(); } } // extern "C" diff --git a/src/Mod/Assembly/App/ConstraintGroup.h b/src/Mod/Assembly/App/ConstraintGroup.h index 15406dacd..2d4157666 100644 --- a/src/Mod/Assembly/App/ConstraintGroup.h +++ b/src/Mod/Assembly/App/ConstraintGroup.h @@ -46,9 +46,9 @@ public: App::DocumentObjectExecReturn *execute(void); short mustExecute() const; /// returns the type name of the view provider - //const char* getViewProviderName(void) const { - // return "PartDesignGui::ViewProviderConstraintGroup"; - //} + const char* getViewProviderName(void) const { + return "AssemblyGui::ViewProviderConstraintGroup"; + } //@} }; diff --git a/src/Mod/Assembly/App/ItemAssembly.cpp b/src/Mod/Assembly/App/ItemAssembly.cpp index 7ef082955..e6e6563a8 100644 --- a/src/Mod/Assembly/App/ItemAssembly.cpp +++ b/src/Mod/Assembly/App/ItemAssembly.cpp @@ -42,6 +42,7 @@ PROPERTY_SOURCE(Assembly::ItemAssembly, Assembly::Item) ItemAssembly::ItemAssembly() { ADD_PROPERTY(Items,(0)); + ADD_PROPERTY(Annotations,(0)); } short ItemAssembly::mustExecute() const diff --git a/src/Mod/Assembly/Gui/AppAssemblyGui.cpp b/src/Mod/Assembly/Gui/AppAssemblyGui.cpp index 97e128262..c0acd9477 100644 --- a/src/Mod/Assembly/Gui/AppAssemblyGui.cpp +++ b/src/Mod/Assembly/Gui/AppAssemblyGui.cpp @@ -35,6 +35,7 @@ #include "ViewProvider.h" #include "ViewProviderPart.h" #include "ViewProviderAssembly.h" +#include "ViewProviderConstraintGroup.h" #include @@ -82,6 +83,8 @@ void AssemblyGuiExport initAssemblyGui() AssemblyGui::ViewProviderItemPart ::init(); AssemblyGui::ViewProviderItemAssembly::init(); + AssemblyGui::ViewProviderConstraintGroup::init(); + // add resources and reloads the translators loadAssemblyResource(); } diff --git a/src/Mod/Assembly/Gui/CommandConstraints.cpp b/src/Mod/Assembly/Gui/CommandConstraints.cpp index 083a9c1dd..6ef91bffc 100644 --- a/src/Mod/Assembly/Gui/CommandConstraints.cpp +++ b/src/Mod/Assembly/Gui/CommandConstraints.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include @@ -30,11 +31,58 @@ #include #include +#include +#include + using namespace std; +extern Assembly::Item *ActiveAsmObject; +// Helper methods =========================================================== +Assembly::ConstraintGroup * getConstraintGroup(Assembly::ItemAssembly *Asm) +{ + Assembly::ConstraintGroup *ConstGrp = 0; + + std::vector Ano = Asm->Annotations.getValues(); + for(std::vector::const_iterator it = Ano.begin();it!=Ano.end();++it){ + if((*it)->getTypeId().isDerivedFrom(Assembly::ConstraintGroup::getClassTypeId() )){ + ConstGrp = static_cast(*it); + break; + } + } + return ConstGrp; +} + +bool getConstraintPrerequisits(Assembly::ItemAssembly **Asm,Assembly::ConstraintGroup **ConstGrp) +{ + 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 true; + } + + *Asm = static_cast(ActiveAsmObject); + + // find the Constraint group of the active Assembly + *ConstGrp = getConstraintGroup(*Asm); + // if it hasen't aleardy one, create one: + if(!*ConstGrp){ + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ConstraintGroup','ConstraintGroup')"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = 'ConstraintGroup'"); + Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Annotations = App.activeDocument().%s.Annotations + [App.activeDocument().ActiveObject]",(*Asm)->getNameInDocument(),(*Asm)->getNameInDocument()); + + } + // find now + *ConstGrp = getConstraintGroup(*Asm); + if(!*ConstGrp) + throw Base::Exception("Could not create Assembly::ConstraintGroup in active Assembly"); + + // return with no error + return false; + +} //=========================================================================== DEF_STD_CMD(CmdAssemblyConstraintAxle); @@ -54,8 +102,17 @@ CmdAssemblyConstraintAxle::CmdAssemblyConstraintAxle() void CmdAssemblyConstraintAxle::activated(int iMsg) { - // load the file with the module - //Command::doCommand(Command::Gui, "import Assembly, AssemblyGui"); + Assembly::ItemAssembly *Asm=0; + Assembly::ConstraintGroup *ConstGrp=0; + + // retrive the standard objects needed + if(getConstraintPrerequisits(&Asm,&ConstGrp)) + return; + + openCommand("Insert Constraint Axle"); + std::string ConstrName = getUniqueObjectName("Axle"); + doCommand(Doc,"App.activeDocument().addObject('Assembly::ItemPart','%s')",ConstrName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]",ConstGrp->getNameInDocument(),ConstGrp->getNameInDocument()); } diff --git a/src/Mod/Assembly/Gui/ViewProviderConstraintGroup.cpp b/src/Mod/Assembly/Gui/ViewProviderConstraintGroup.cpp index 02bab39c4..1a10eda3f 100644 --- a/src/Mod/Assembly/Gui/ViewProviderConstraintGroup.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderConstraintGroup.cpp @@ -57,7 +57,7 @@ void ViewProviderConstraintGroup::attach(App::DocumentObject *pcFeat) // putting all together with the switch - addDisplayMaskMode(getChildRoot(), "Main"); +// addDisplayMaskMode(getChildRoot(), "Main"); } void ViewProviderConstraintGroup::setDisplayMode(const char* ModeName) @@ -65,7 +65,7 @@ void ViewProviderConstraintGroup::setDisplayMode(const char* ModeName) if ( strcmp("Main",ModeName)==0 ) setDisplayMaskMode("Main"); - ViewProviderDocumentObject::setDisplayMode( ModeName ); +// ViewProviderDocumentObject::setDisplayMode( ModeName ); } std::vector ViewProviderConstraintGroup::getDisplayModes(void) const @@ -74,7 +74,7 @@ std::vector ViewProviderConstraintGroup::getDisplayModes(void) cons std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); // add your own modes - StrList.push_back("Main"); +// StrList.push_back("Main"); return StrList; }