make subproduct solving work
This commit is contained in:
@@ -40,29 +40,31 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern Assembly::Item *ActiveAsmObject;
|
||||
extern Assembly::Item* ActiveAsmObject;
|
||||
|
||||
// Helper methods ===========================================================
|
||||
|
||||
Assembly::ConstraintGroup * getConstraintGroup(Assembly::ItemAssembly *Asm)
|
||||
Assembly::ConstraintGroup* getConstraintGroup(Assembly::ItemAssembly* Asm)
|
||||
{
|
||||
Assembly::ConstraintGroup *ConstGrp = 0;
|
||||
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() )){
|
||||
|
||||
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)
|
||||
bool getConstraintPrerequisits(Assembly::ItemAssembly** Asm, Assembly::ConstraintGroup** ConstGrp)
|
||||
{
|
||||
if(!ActiveAsmObject || !ActiveAsmObject->getTypeId().isDerivedFrom(Assembly::ItemAssembly::getClassTypeId())){
|
||||
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)."));
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -70,15 +72,18 @@ bool getConstraintPrerequisits(Assembly::ItemAssembly **Asm,Assembly::Constraint
|
||||
|
||||
// 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());
|
||||
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");
|
||||
|
||||
@@ -87,13 +92,14 @@ bool getConstraintPrerequisits(Assembly::ItemAssembly **Asm,Assembly::Constraint
|
||||
|
||||
}
|
||||
|
||||
std::string asSubLinkString(Assembly::ItemPart* part, std::string element) {
|
||||
std::string buf;
|
||||
std::string asSubLinkString(Assembly::ItemPart* part, std::string element)
|
||||
{
|
||||
std::string buf;
|
||||
buf += "(App.ActiveDocument.";
|
||||
buf += part->getNameInDocument();
|
||||
buf += part->getNameInDocument();
|
||||
buf += ",['";
|
||||
buf += element;
|
||||
buf += "'])";
|
||||
buf += "'])";
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -102,7 +108,7 @@ std::string asSubLinkString(Assembly::ItemPart* part, std::string element) {
|
||||
DEF_STD_CMD(CmdAssemblyConstraintDistance);
|
||||
|
||||
CmdAssemblyConstraintDistance::CmdAssemblyConstraintDistance()
|
||||
:Command("Assembly_ConstraintDistance")
|
||||
: Command("Assembly_ConstraintDistance")
|
||||
{
|
||||
sAppModule = "Assembly";
|
||||
sGroup = QT_TR_NOOP("Assembly");
|
||||
@@ -116,45 +122,57 @@ CmdAssemblyConstraintDistance::CmdAssemblyConstraintDistance()
|
||||
|
||||
void CmdAssemblyConstraintDistance::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *Asm=0;
|
||||
Assembly::ConstraintGroup *ConstGrp=0;
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm,&ConstGrp))
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
|
||||
Assembly::ItemPart* part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
Assembly::ItemPart* part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
if(!part1 || !part2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if( (part1.second == part2.second) && part1.second != Asm ) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subproduct, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
|
||||
double d = QInputDialog::getDouble(NULL, QObject::tr("Constraint value"),
|
||||
QObject::tr("Distance:"), 0., -10000., 10000., 2, &ok);
|
||||
QObject::tr("Distance:"), 0., -10000., 10000., 2, &ok);
|
||||
|
||||
if(!ok)
|
||||
return;
|
||||
|
||||
return;
|
||||
|
||||
openCommand("Insert Constraint Distance");
|
||||
std::string ConstrName = getUniqueObjectName("Distance");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ConstraintDistance','%s')",ConstrName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Distance = %f", d);
|
||||
doCommand(Doc,"App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]",ConstGrp->getNameInDocument(),ConstGrp->getNameInDocument());
|
||||
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintDistance','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Distance = %f", d);
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
commitCommand();
|
||||
updateActive();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************************/
|
||||
@@ -162,7 +180,7 @@ void CmdAssemblyConstraintDistance::activated(int iMsg)
|
||||
DEF_STD_CMD(CmdAssemblyConstraintFix);
|
||||
|
||||
CmdAssemblyConstraintFix::CmdAssemblyConstraintFix()
|
||||
:Command("Assembly_ConstraintFix")
|
||||
: Command("Assembly_ConstraintFix")
|
||||
{
|
||||
sAppModule = "Assembly";
|
||||
sGroup = QT_TR_NOOP("Assembly");
|
||||
@@ -176,43 +194,56 @@ CmdAssemblyConstraintFix::CmdAssemblyConstraintFix()
|
||||
|
||||
void CmdAssemblyConstraintFix::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *Asm=0;
|
||||
Assembly::ConstraintGroup *ConstGrp=0;
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm,&ConstGrp))
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 1) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select one part only"));
|
||||
QObject::tr("You need to select one part only"));
|
||||
return;
|
||||
};
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part = Asm->getContainingPart(objs[0].getObject());
|
||||
|
||||
if(!part.first) {
|
||||
Base::Console().Message("The selected part need to belong to the active assembly\n");
|
||||
return;
|
||||
};
|
||||
|
||||
Assembly::ItemPart* part = Asm->getContainingPart(objs[0].getObject());
|
||||
if(!part) {
|
||||
Base::Console().Message("The selected object need to belong to the active assembly\n");
|
||||
if(part.second != Asm) {
|
||||
Base::Console().Message("The selected part need belongs to an subproduct, please add constraint there\n");
|
||||
return;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
openCommand("Insert Constraint Fix");
|
||||
|
||||
std::string ConstrName = getUniqueObjectName("Fix");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ConstraintFix','%s')",ConstrName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.First = %s", asSubLinkString(part, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]",ConstGrp->getNameInDocument(),ConstGrp->getNameInDocument());
|
||||
|
||||
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintFix','%s')", ConstrName.c_str());
|
||||
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part.first, objs[0].getSubNames()[0]).c_str());
|
||||
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
commitCommand();
|
||||
|
||||
updateActive();
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************/
|
||||
|
||||
|
||||
DEF_STD_CMD(CmdAssemblyConstraintAngle);
|
||||
|
||||
CmdAssemblyConstraintAngle::CmdAssemblyConstraintAngle()
|
||||
:Command("Assembly_ConstraintAngle")
|
||||
: Command("Assembly_ConstraintAngle")
|
||||
{
|
||||
sAppModule = "Assembly";
|
||||
sGroup = QT_TR_NOOP("Assembly");
|
||||
@@ -226,45 +257,57 @@ CmdAssemblyConstraintAngle::CmdAssemblyConstraintAngle()
|
||||
|
||||
void CmdAssemblyConstraintAngle::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *Asm=0;
|
||||
Assembly::ConstraintGroup *ConstGrp=0;
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm,&ConstGrp))
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
|
||||
Assembly::ItemPart* part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
Assembly::ItemPart* part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
if(!part1 || !part2) {
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if( ( (part1.second == part2.second) && part1.second != Asm ) && part1.second != Asm ) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subproduct, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
|
||||
double d = QInputDialog::getDouble(NULL, QObject::tr("Constraint value"),
|
||||
QObject::tr("Angle:"), 0., 0., 360., 2, &ok);
|
||||
QObject::tr("Angle:"), 0., 0., 360., 2, &ok);
|
||||
|
||||
if(!ok)
|
||||
return;
|
||||
|
||||
return;
|
||||
|
||||
openCommand("Insert Constraint Angle");
|
||||
std::string ConstrName = getUniqueObjectName("Angle");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ConstraintAngle','%s')",ConstrName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Angle = %f", d);
|
||||
doCommand(Doc,"App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]",ConstGrp->getNameInDocument(),ConstGrp->getNameInDocument());
|
||||
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintAngle','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Angle = %f", d);
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
commitCommand();
|
||||
updateActive();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -274,7 +317,7 @@ void CmdAssemblyConstraintAngle::activated(int iMsg)
|
||||
DEF_STD_CMD(CmdAssemblyConstraintOrientation);
|
||||
|
||||
CmdAssemblyConstraintOrientation::CmdAssemblyConstraintOrientation()
|
||||
:Command("Assembly_ConstraintOrientation")
|
||||
: Command("Assembly_ConstraintOrientation")
|
||||
{
|
||||
sAppModule = "Assembly";
|
||||
sGroup = QT_TR_NOOP("Assembly");
|
||||
@@ -288,48 +331,61 @@ CmdAssemblyConstraintOrientation::CmdAssemblyConstraintOrientation()
|
||||
|
||||
void CmdAssemblyConstraintOrientation::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *Asm=0;
|
||||
Assembly::ConstraintGroup *ConstGrp=0;
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm,&ConstGrp))
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
|
||||
Assembly::ItemPart* part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
Assembly::ItemPart* part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
if(!part1 || !part2) {
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if( (part1.second == part2.second) && part1.second != Asm ) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subproduct, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList items;
|
||||
|
||||
items << QObject::tr("Parallel") << QObject::tr("Perpendicular") << QObject::tr("Equal") << QObject::tr("Opposite");
|
||||
|
||||
bool ok;
|
||||
|
||||
QString item = QInputDialog::getItem(NULL, QObject::tr("Constraint value"),
|
||||
QObject::tr("Orientation:"), items, 0, false, &ok);
|
||||
if (!ok || item.isEmpty())
|
||||
QObject::tr("Orientation:"), items, 0, false, &ok);
|
||||
|
||||
if(!ok || item.isEmpty())
|
||||
return;
|
||||
|
||||
|
||||
openCommand("Insert Constraint Orientation");
|
||||
std::string ConstrName = getUniqueObjectName("Orientation");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ConstraintOrientation','%s')",ConstrName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Orientation = '%s'", item.toStdString().c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]",ConstGrp->getNameInDocument(),ConstGrp->getNameInDocument());
|
||||
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintOrientation','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Orientation = '%s'", item.toStdString().c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
commitCommand();
|
||||
updateActive();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************************/
|
||||
@@ -338,7 +394,7 @@ void CmdAssemblyConstraintOrientation::activated(int iMsg)
|
||||
DEF_STD_CMD(CmdAssemblyConstraintCoincidence);
|
||||
|
||||
CmdAssemblyConstraintCoincidence::CmdAssemblyConstraintCoincidence()
|
||||
:Command("Assembly_ConstraintCoincidence")
|
||||
: Command("Assembly_ConstraintCoincidence")
|
||||
{
|
||||
sAppModule = "Assembly";
|
||||
sGroup = QT_TR_NOOP("Assembly");
|
||||
@@ -352,48 +408,61 @@ CmdAssemblyConstraintCoincidence::CmdAssemblyConstraintCoincidence()
|
||||
|
||||
void CmdAssemblyConstraintCoincidence::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *Asm=0;
|
||||
Assembly::ConstraintGroup *ConstGrp=0;
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm,&ConstGrp))
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
|
||||
Assembly::ItemPart* part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
Assembly::ItemPart* part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
if(!part1 || !part2) {
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if( (part1.second == part2.second) && part1.second != Asm ) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subproduct, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList items;
|
||||
|
||||
items << QObject::tr("Parallel") << QObject::tr("Equal") << QObject::tr("Opposite");
|
||||
|
||||
bool ok;
|
||||
|
||||
QString item = QInputDialog::getItem(NULL, QObject::tr("Constraint value"),
|
||||
QObject::tr("Orientation:"), items, 0, false, &ok);
|
||||
if (!ok || item.isEmpty())
|
||||
QObject::tr("Orientation:"), items, 0, false, &ok);
|
||||
|
||||
if(!ok || item.isEmpty())
|
||||
return;
|
||||
|
||||
|
||||
openCommand("Insert Constraint Coincidence");
|
||||
std::string ConstrName = getUniqueObjectName("Coincidence");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ConstraintCoincidence','%s')",ConstrName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Orientation = '%s'", item.toStdString().c_str());
|
||||
doCommand(Doc,"App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]",ConstGrp->getNameInDocument(),ConstGrp->getNameInDocument());
|
||||
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintCoincidence','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Orientation = '%s'", item.toStdString().c_str());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
commitCommand();
|
||||
updateActive();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************************/
|
||||
@@ -402,7 +471,7 @@ void CmdAssemblyConstraintCoincidence::activated(int iMsg)
|
||||
DEF_STD_CMD(CmdAssemblyConstraintAlignment);
|
||||
|
||||
CmdAssemblyConstraintAlignment::CmdAssemblyConstraintAlignment()
|
||||
:Command("Assembly_ConstraintAlignment")
|
||||
: Command("Assembly_ConstraintAlignment")
|
||||
{
|
||||
sAppModule = "Assembly";
|
||||
sGroup = QT_TR_NOOP("Assembly");
|
||||
@@ -416,55 +485,70 @@ CmdAssemblyConstraintAlignment::CmdAssemblyConstraintAlignment()
|
||||
|
||||
void CmdAssemblyConstraintAlignment::activated(int iMsg)
|
||||
{
|
||||
Assembly::ItemAssembly *Asm=0;
|
||||
Assembly::ConstraintGroup *ConstGrp=0;
|
||||
Assembly::ItemAssembly* Asm = 0;
|
||||
Assembly::ConstraintGroup* ConstGrp = 0;
|
||||
|
||||
// retrive the standard objects needed
|
||||
if(getConstraintPrerequisits(&Asm,&ConstGrp))
|
||||
if(getConstraintPrerequisits(&Asm, &ConstGrp))
|
||||
return;
|
||||
|
||||
|
||||
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx();
|
||||
|
||||
if(objs.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
QObject::tr("You need to select two geometries on two different parts"));
|
||||
return;
|
||||
};
|
||||
|
||||
Assembly::ItemPart* part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
Assembly::ItemPart* part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
if(!part1 || !part2) {
|
||||
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part1 = Asm->getContainingPart(objs[0].getObject());
|
||||
std::pair<Assembly::ItemPart*, Assembly::ItemAssembly*> part2 = Asm->getContainingPart(objs[1].getObject());
|
||||
|
||||
//checking the parts is enough, both or non!
|
||||
if(!part1.first || !part2.first) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
QObject::tr("The selected parts need to belong to the active assembly (active product or one of it's subproducts)"));
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
//check if this is the right place for the constraint
|
||||
if( (part1.second == part2.second) && part1.second != Asm ) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("The selected parts belong both to the same subproduct, please add constraints there"));
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList items;
|
||||
|
||||
items << QObject::tr("Parallel") << QObject::tr("Equal") << QObject::tr("Opposite");
|
||||
|
||||
QDialog dialog;
|
||||
Ui_AlignmentDialog ui;
|
||||
|
||||
Ui_AlignmentDialog ui;
|
||||
|
||||
ui.setupUi(&dialog);
|
||||
|
||||
ui.comboBox->addItems(items);
|
||||
if( dialog.exec() != QDialog::Accepted )
|
||||
return;
|
||||
|
||||
|
||||
if(dialog.exec() != QDialog::Accepted)
|
||||
return;
|
||||
|
||||
openCommand("Insert Constraint Alignment");
|
||||
std::string ConstrName = getUniqueObjectName("Alignment");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Assembly::ConstraintAlignment','%s')",ConstrName.c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Orientation = '%s'", ui.comboBox->currentText().toStdString().c_str());
|
||||
doCommand(Doc,"App.activeDocument().ActiveObject.Offset = %f", ui.doubleSpinBox->value());
|
||||
doCommand(Doc,"App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]",ConstGrp->getNameInDocument(),ConstGrp->getNameInDocument());
|
||||
|
||||
doCommand(Doc, "App.activeDocument().addObject('Assembly::ConstraintAlignment','%s')", ConstrName.c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.First = %s", asSubLinkString(part1.first, objs[0].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Second = %s", asSubLinkString(part2.first, objs[1].getSubNames()[0]).c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Orientation = '%s'", ui.comboBox->currentText().toStdString().c_str());
|
||||
doCommand(Doc, "App.activeDocument().ActiveObject.Offset = %f", ui.doubleSpinBox->value());
|
||||
doCommand(Doc, "App.activeDocument().%s.Constraints = App.activeDocument().%s.Constraints + [App.activeDocument().ActiveObject]", ConstGrp->getNameInDocument(), ConstGrp->getNameInDocument());
|
||||
|
||||
commitCommand();
|
||||
updateActive();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CreateAssemblyConstraintCommands(void)
|
||||
{
|
||||
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
|
||||
rcCmdMgr.addCommand(new CmdAssemblyConstraintFix());
|
||||
rcCmdMgr.addCommand(new CmdAssemblyConstraintDistance());
|
||||
@@ -472,4 +556,6 @@ void CreateAssemblyConstraintCommands(void)
|
||||
rcCmdMgr.addCommand(new CmdAssemblyConstraintOrientation());
|
||||
rcCmdMgr.addCommand(new CmdAssemblyConstraintCoincidence());
|
||||
rcCmdMgr.addCommand(new CmdAssemblyConstraintAlignment());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user