addition of constraints

This commit is contained in:
jriegel 2012-05-24 15:04:34 +02:00 committed by Stefan Tröger
parent f29c33c7dc
commit b08b2f6140
6 changed files with 87 additions and 8 deletions

View File

@ -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"

View File

@ -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";
}
//@}
};

View File

@ -42,6 +42,7 @@ PROPERTY_SOURCE(Assembly::ItemAssembly, Assembly::Item)
ItemAssembly::ItemAssembly()
{
ADD_PROPERTY(Items,(0));
ADD_PROPERTY(Annotations,(0));
}
short ItemAssembly::mustExecute() const

View File

@ -35,6 +35,7 @@
#include "ViewProvider.h"
#include "ViewProviderPart.h"
#include "ViewProviderAssembly.h"
#include "ViewProviderConstraintGroup.h"
#include <Mod/Assembly/App/ItemAssembly.h>
@ -82,6 +83,8 @@ void AssemblyGuiExport initAssemblyGui()
AssemblyGui::ViewProviderItemPart ::init();
AssemblyGui::ViewProviderItemAssembly::init();
AssemblyGui::ViewProviderConstraintGroup::init();
// add resources and reloads the translators
loadAssemblyResource();
}

View File

@ -23,6 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QMessageBox>
#endif
#include <Gui/Application.h>
@ -30,11 +31,58 @@
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include <Mod/Assembly/App/ItemAssembly.h>
#include <Mod/Assembly/App/ConstraintGroup.h>
using namespace std;
extern Assembly::Item *ActiveAsmObject;
// Helper methods ===========================================================
Assembly::ConstraintGroup * getConstraintGroup(Assembly::ItemAssembly *Asm)
{
Assembly::ConstraintGroup *ConstGrp = 0;
std::vector<App::DocumentObject*> Ano = Asm->Annotations.getValues();
for(std::vector<App::DocumentObject*>::const_iterator it = Ano.begin();it!=Ano.end();++it){
if((*it)->getTypeId().isDerivedFrom(Assembly::ConstraintGroup::getClassTypeId() )){
ConstGrp = static_cast<Assembly::ConstraintGroup*>(*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<Assembly::ItemAssembly*>(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());
}

View File

@ -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<std::string> ViewProviderConstraintGroup::getDisplayModes(void) const
@ -74,7 +74,7 @@ std::vector<std::string> ViewProviderConstraintGroup::getDisplayModes(void) cons
std::vector<std::string> StrList = ViewProviderDocumentObject::getDisplayModes();
// add your own modes
StrList.push_back("Main");
// StrList.push_back("Main");
return StrList;
}