implementing commands

This commit is contained in:
jriegel
2012-03-11 23:59:00 +01:00
committed by Stefan Tröger
parent b4cad19107
commit 0f05c6df8f
5 changed files with 44 additions and 15 deletions

View File

@@ -23,16 +23,21 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QMessageBox>
#endif
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include <Gui/Selection.h>
#include <Mod/Assembly/App/ItemAssembly.h>
using namespace std;
extern Assembly::Item *ActiveAsmObject;
//===========================================================================
@@ -78,9 +83,23 @@ CmdAssemblyAddNewComponent::CmdAssemblyAddNewComponent()
void CmdAssemblyAddNewComponent::activated(int iMsg)
{
// load the file with the module
//Command::doCommand(Command::Gui, "import Assembly, AssemblyGui");
Assembly::ItemAssembly *dest = 0;
unsigned int n = getSelection().countObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
if (n >= 1) {
std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Assembly::ItemAssembly::getClassTypeId());
dest = dynamic_cast<Assembly::ItemAssembly*>(Sel.front());
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())) {
dest = dynamic_cast<Assembly::ItemAssembly*>(ActiveAsmObject);
}
openCommand("Insert Component");
std::string CompName = getUniqueObjectName("Product");
doCommand(Doc,"App.activeDocument().addObject('Assembly::ItemAssembly','%s')",CompName.c_str());
if(dest){
std::string fatherName = dest->getNameInDocument();
doCommand(Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s] ",fatherName.c_str(),fatherName.c_str(),CompName.c_str());
}
}
//===========================================================================