[Assembly] fixing the commands and some import
This commit is contained in:
@@ -76,34 +76,23 @@ void CmdAssemblyAddNewPart::activated(int iMsg)
|
||||
}
|
||||
|
||||
openCommand("Insert Part");
|
||||
// need the help of the Part module to set up a Part
|
||||
addModule(App,"PartDesign");
|
||||
addModule(Gui,"PartDesignGui");
|
||||
addModule(Gui,"AssemblyGui");
|
||||
|
||||
std::string PartName = getUniqueObjectName("Part");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ItemPart','%s')",PartName.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(),PartName.c_str());
|
||||
}
|
||||
Command::addModule(App,"PartDesign");
|
||||
Command::addModule(Gui,"PartDesignGui");
|
||||
std::string ProductName = dest->getNameInDocument();
|
||||
std::string RefName = getUniqueObjectName((PartName + "-1").c_str());
|
||||
|
||||
|
||||
std::string BodyName = getUniqueObjectName("Body");
|
||||
// add the standard planes
|
||||
std::string Plane1Name = BodyName + "_PlaneXY";
|
||||
std::string Plane2Name = BodyName + "_PlaneYZ";
|
||||
std::string Plane3Name = BodyName + "_PlaneXZ";
|
||||
doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane1Name.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Label = 'XY-Plane'");
|
||||
doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane2Name.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Label = 'YZ-Plane'");
|
||||
doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Label = 'XZ-Plane'");
|
||||
// add to anotation set of the Part object
|
||||
doCommand(Doc,"App.activeDocument().%s.Annotation = [App.activeDocument().%s,App.activeDocument().%s,App.activeDocument().%s] ",PartName.c_str(),Plane1Name.c_str(),Plane2Name.c_str(),Plane3Name.c_str());
|
||||
// add the main body
|
||||
doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",BodyName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().addObject('App::Part','%s')",PartName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ProductRef','%s')",RefName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s]",ProductName.c_str(),ProductName.c_str(),RefName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Item = App.activeDocument().%s",RefName.c_str(),PartName.c_str());
|
||||
doCommand(Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().%s)",ProductName.c_str());
|
||||
|
||||
// create a PartDesign Part for now, can be later any kind of Part or an empty one
|
||||
doCommand(Gui::Command::Doc,"PartDesignGui.setUpPart(App.activeDocument().%s)",PartName.c_str());
|
||||
|
||||
this->updateActive();
|
||||
}
|
||||
@@ -135,15 +124,23 @@ void CmdAssemblyAddNewComponent::activated(int iMsg)
|
||||
dest = dynamic_cast<Assembly::Product*>(Sel.front());
|
||||
}else if(ActiveAsmObject && ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::Product::getClassTypeId())) {
|
||||
dest = dynamic_cast<Assembly::Product*>(ActiveAsmObject);
|
||||
}else {
|
||||
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active or selected assembly"),
|
||||
QObject::tr("You need a active or selected assembly to insert a component in."));
|
||||
return;
|
||||
}
|
||||
|
||||
openCommand("Insert Component");
|
||||
std::string CompName = getUniqueObjectName("Assembly");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::Product','%s')",CompName.c_str());
|
||||
if(dest){
|
||||
std::string fatherName = dest->getNameInDocument();
|
||||
doCommand(Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s] ",fatherName.c_str(),fatherName.c_str(),CompName.c_str());
|
||||
}
|
||||
std::string NewProdName = getUniqueObjectName("Product");
|
||||
std::string ProductName = dest->getNameInDocument();
|
||||
std::string RefName = getUniqueObjectName((NewProdName + "-1").c_str());
|
||||
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::Product','%s')",NewProdName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ProductRef','%s')",RefName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Items = App.activeDocument().%s.Items + [App.activeDocument().%s]",ProductName.c_str(),ProductName.c_str(),RefName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Item = App.activeDocument().%s",RefName.c_str(),NewProdName.c_str());
|
||||
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
||||
@@ -46,22 +46,30 @@ using namespace AssemblyGui;
|
||||
void switchToDocument(const App::Document* doc)
|
||||
{
|
||||
|
||||
if(doc->countObjects() == 0){ // -> set up a empty document
|
||||
std::string PartName = doc->getUniqueObjectName("Part");
|
||||
if( doc->Tip.getValue() && doc->Tip.getValue()->getTypeId() == App::Part::getClassTypeId() )
|
||||
{ // in case of a Part document
|
||||
std::string PartName = doc->Tip.getValue()->getNameInDocument();
|
||||
std::string ProductName = doc->getUniqueObjectName("Product");
|
||||
std::string RefName = doc->getUniqueObjectName((PartName + "-1").c_str());
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Tip = App.activeDocument().addObject('Assembly::Product','%s')",ProductName.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('Assembly::ProductRef','%s')",RefName.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Items = App.activeDocument().%s",ProductName.c_str(),RefName.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Part','%s')",PartName.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Item = App.activeDocument().%s",RefName.c_str(),PartName.c_str());
|
||||
Gui::Command::addModule(Gui::Command::Gui,"AssemblyGui");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().%s)",ProductName.c_str());
|
||||
// create a PartDesign Part for now, can be later any kind of Part or an empty one
|
||||
Gui::Command::addModule(Gui::Command::Doc,"PartDesignGui");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"PartDesignGui.setUpPart(App.activeDocument().%s)",PartName.c_str());
|
||||
//// create a PartDesign Part for now, can be later any kind of Part or an empty one
|
||||
//Gui::Command::addModule(Gui::Command::Doc,"PartDesignGui");
|
||||
//Gui::Command::doCommand(Gui::Command::Doc,"PartDesignGui.setUpPart(App.activeDocument().%s)",PartName.c_str());
|
||||
|
||||
} else if(doc->countObjects() == 0){ // -> set up a empty document
|
||||
std::string ProductName = doc->getUniqueObjectName("Product");
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().Tip = App.activeDocument().addObject('Assembly::Product','%s')",ProductName.c_str());
|
||||
Gui::Command::addModule(Gui::Command::Gui,"AssemblyGui");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().%s)",ProductName.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -157,16 +165,16 @@ void Workbench::activated()
|
||||
addTaskWatcher(Watcher);
|
||||
Gui::Control().showTaskView();
|
||||
|
||||
//App::Document *doc = App::GetApplication().getActiveDocument();
|
||||
App::Document *doc = App::GetApplication().getActiveDocument();
|
||||
//if(!doc){
|
||||
// // create a new document
|
||||
// std::string uniqueName = App::GetApplication().getUniqueDocumentName("Assembly1");
|
||||
// Gui::Command::doCommand(Gui::Command::Doc,"App.newDocument('%s')",uniqueName.c_str());
|
||||
// doc = App::GetApplication().getActiveDocument();
|
||||
|
||||
// switchToDocument(doc);
|
||||
|
||||
//}
|
||||
if(doc)
|
||||
switchToDocument(doc);
|
||||
|
||||
|
||||
// show a warning about the Alpha state of FreeCAD Assembly
|
||||
|
||||
Reference in New Issue
Block a user