View nesting working!

This commit is contained in:
jriegel 2012-04-05 22:51:07 +02:00 committed by Stefan Tröger
parent d5663b4122
commit 09f199ed9e
4 changed files with 84 additions and 7 deletions

View File

@ -39,7 +39,8 @@ PROPERTY_SOURCE(Assembly::ItemPart, Assembly::Item)
ItemPart::ItemPart()
{
ADD_PROPERTY(Model,(0));
ADD_PROPERTY(Model, (0));
ADD_PROPERTY(Annotation,(0));
}
short ItemPart::mustExecute() const

View File

@ -69,7 +69,7 @@ void CmdAssemblyAddNewPart::activated(int iMsg)
dest = dynamic_cast<Assembly::ItemAssembly*>(ActiveAsmObject);
}else {
return;
}
openCommand("Insert Part");
@ -81,10 +81,29 @@ void CmdAssemblyAddNewPart::activated(int iMsg)
}
Command::addModule(App,"PartDesign");
Command::addModule(Gui,"PartDesignGui");
#if 1 // test code for children nesting
Command::addModule(App,"Part");
std::string BodyName = getUniqueObjectName("Box");
doCommand(Doc,"App.activeDocument().addObject('Part::Box','%s')",BodyName.c_str());
doCommand(Doc,"App.activeDocument().%s.Model = App.activeDocument().%s ",PartName.c_str(),BodyName.c_str(),BodyName.c_str());
#else
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().addObject('App::Plane','%s')",Plane2Name.c_str());
doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(0.000000,0.000000,0.000000),App.Rotation(-0.707107,0.000000,0.000000,-0.707107))",Plane2Name.c_str());
doCommand(Doc,"App.activeDocument().addObject('App::Plane','%s')",Plane3Name.c_str());
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(),BodyName.c_str());
#endif #
this->updateActive();
}
//===========================================================================
@ -144,8 +163,31 @@ CmdAssemblyAddExistingComponent::CmdAssemblyAddExistingComponent()
void CmdAssemblyAddExistingComponent::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);
}else {
return;
}
openCommand("Insert TestPart");
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 BodyName = getUniqueObjectName("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(),BodyName.c_str());
}

View File

@ -24,6 +24,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Inventor/nodes/SoGroup.h>
#endif
#include "ViewProviderPart.h"
@ -48,14 +49,42 @@ bool ViewProviderItemPart::doubleClicked(void)
return true;
}
void ViewProviderItemPart::attach(App::DocumentObject *pcFeat)
{
// call parent attach method
ViewProviderGeometryObject::attach(pcFeat);
// putting all together with the switch
addDisplayMaskMode(getChildRoot(), "Main");
}
void ViewProviderItemPart::setDisplayMode(const char* ModeName)
{
if ( strcmp("Main",ModeName)==0 )
setDisplayMaskMode("Main");
ViewProviderGeometryObject::setDisplayMode( ModeName );
}
std::vector<std::string> ViewProviderItemPart::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
// add your own modes
StrList.push_back("Main");
return StrList;
}
std::vector<App::DocumentObject*> ViewProviderItemPart::claimChildren(void)const
{
std::vector<App::DocumentObject*> res;
res.insert( res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end());
if(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue())
res.push_back( static_cast<Assembly::ItemPart*>(getObject())->Model.getValue());
res.insert( res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end());
return res;
@ -65,9 +94,9 @@ std::vector<App::DocumentObject*> ViewProviderItemPart::claimChildren3D(void)con
{
std::vector<App::DocumentObject*> res;
res.insert( res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end());
if(static_cast<Assembly::ItemPart*>(getObject())->Model.getValue())
res.push_back( static_cast<Assembly::ItemPart*>(getObject())->Model.getValue());
res.insert( res.end(), static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().begin(),static_cast<Assembly::ItemPart*>(getObject())->Annotation.getValues().end());
return res;

View File

@ -41,6 +41,11 @@ public:
virtual bool doubleClicked(void);
virtual void attach(App::DocumentObject *);
virtual void setDisplayMode(const char* ModeName);
/// returns a list of all possible modes
virtual std::vector<std::string> getDisplayModes(void) const;
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;