本文整理汇总了C++中app::Document::getUniqueObjectName方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::getUniqueObjectName方法的具体用法?C++ Document::getUniqueObjectName怎么用?C++ Document::getUniqueObjectName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app::Document
的用法示例。
在下文中一共展示了Document::getUniqueObjectName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: accept
void DlgRevolution::accept()
{
if (ui->treeWidget->selectedItems().isEmpty()) {
QMessageBox::critical(this, windowTitle(),
tr("Select a shape for revolution, first."));
return;
}
Gui::WaitCursor wc;
App::Document* activeDoc = App::GetApplication().getActiveDocument();
activeDoc->openTransaction("Revolve");
QString shape, type, name, solid;
QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
if (ui->checkSolid->isChecked()) {
solid = QString::fromLatin1("True");}
else {
solid = QString::fromLatin1("False");}
for (QList<QTreeWidgetItem *>::iterator it = items.begin(); it != items.end(); ++it) {
shape = (*it)->data(0, Qt::UserRole).toString();
type = QString::fromLatin1("Part::Revolution");
name = QString::fromLatin1(activeDoc->getUniqueObjectName("Revolve").c_str());
Base::Vector3d axis = this->getDirection();
QString code = QString::fromLatin1(
"FreeCAD.ActiveDocument.addObject(\"%1\",\"%2\")\n"
"FreeCAD.ActiveDocument.%2.Source = FreeCAD.ActiveDocument.%3\n"
"FreeCAD.ActiveDocument.%2.Axis = (%4,%5,%6)\n"
"FreeCAD.ActiveDocument.%2.Base = (%7,%8,%9)\n"
"FreeCAD.ActiveDocument.%2.Angle = %10\n"
"FreeCAD.ActiveDocument.%2.Solid = %11\n"
"FreeCADGui.ActiveDocument.%3.Visibility = False\n")
.arg(type).arg(name).arg(shape)
.arg(axis.x,0,'f',2)
.arg(axis.y,0,'f',2)
.arg(axis.z,0,'f',2)
.arg(ui->xPos->value(),0,'f',2)
.arg(ui->yPos->value(),0,'f',2)
.arg(ui->zPos->value(),0,'f',2)
.arg(ui->angle->value(),0,'f',2)
.arg(solid)
;
Gui::Application::Instance->runPythonCode((const char*)code.toLatin1());
QByteArray to = name.toLatin1();
QByteArray from = shape.toLatin1();
Gui::Command::copyVisual(to, "ShapeColor", from);
Gui::Command::copyVisual(to, "LineColor", from);
Gui::Command::copyVisual(to, "PointColor", from);
}
activeDoc->commitTransaction();
activeDoc->recompute();
QDialog::accept();
}
示例2: activated
void CmdPartShapeFromMesh::activated(int iMsg)
{
Q_UNUSED(iMsg);
bool ok;
double tol = QInputDialog::getDouble(Gui::getMainWindow(), QObject::tr("Sewing Tolerance"),
QObject::tr("Enter tolerance for sewing shape:"), 0.1, 0.01,10.0,2,&ok);
if (!ok)
return;
Base::Type meshid = Base::Type::fromName("Mesh::Feature");
std::vector<App::DocumentObject*> meshes;
meshes = Gui::Selection().getObjectsOfType(meshid);
Gui::WaitCursor wc;
std::vector<App::DocumentObject*>::iterator it;
openCommand("Convert mesh");
for (it = meshes.begin(); it != meshes.end(); ++it) {
App::Document* doc = (*it)->getDocument();
std::string mesh = (*it)->getNameInDocument();
std::string name = doc->getUniqueObjectName(mesh.c_str());
doCommand(Doc,"import Part");
doCommand(Doc,"FreeCAD.getDocument(\"%s\").addObject(\"Part::Feature\",\"%s\")"
,doc->getName()
,name.c_str());
doCommand(Doc,"__shape__=Part.Shape()");
doCommand(Doc,"__shape__.makeShapeFromMesh("
"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Mesh.Topology,%f"
")"
,doc->getName()
,mesh.c_str()
,tol);
doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").Shape=__shape__"
,doc->getName()
,name.c_str());
doCommand(Doc,"FreeCAD.getDocument(\"%s\").getObject(\"%s\").purgeTouched()"
,doc->getName()
,name.c_str());
doCommand(Doc,"del __shape__");
}
commitCommand();
}
示例3: apply
void DlgExtrusion::apply()
{
if (ui->treeWidget->selectedItems().isEmpty()) {
QMessageBox::critical(this, windowTitle(),
tr("Select a shape for extrusion, first."));
return;
}
Gui::WaitCursor wc;
App::Document* activeDoc = App::GetApplication().getDocument(this->document.c_str());
if (!activeDoc) {
QMessageBox::critical(this, windowTitle(),
tr("The document '%1' doesn't exist.").arg(QString::fromUtf8(this->label.c_str())));
return;
}
activeDoc->openTransaction("Extrude");
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part");
bool addBaseName = hGrp->GetBool("AddBaseObjectName", false);
QString shape, type, name, label;
QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
for (QList<QTreeWidgetItem *>::iterator it = items.begin(); it != items.end(); ++it) {
shape = (*it)->data(0, Qt::UserRole).toString();
type = QString::fromLatin1("Part::Extrusion");
if (addBaseName) {
QString baseName = QString::fromLatin1("Extrude_%1").arg(shape);
label = QString::fromLatin1("%1_Extrude").arg((*it)->text(0));
name = QString::fromLatin1(activeDoc->getUniqueObjectName((const char*)baseName.toLatin1()).c_str());
}
else {
name = QString::fromLatin1(activeDoc->getUniqueObjectName("Extrude").c_str());
label = name;
}
double len = ui->dirLen->value();
double dirX = ui->dirX->value();
double dirY = ui->dirY->value();
double dirZ = ui->dirZ->value();
double angle = ui->taperAngle->value().getValue();
bool makeSolid = ui->makeSolid->isChecked();
// inspect geometry
App::DocumentObject* obj = activeDoc->getObject((const char*)shape.toLatin1());
if (!obj || !obj->isDerivedFrom(Part::Feature::getClassTypeId())) continue;
Part::Feature* fea = static_cast<Part::Feature*>(obj);
const TopoDS_Shape& data = fea->Shape.getValue();
if (data.IsNull()) continue;
// check for planes
if (ui->checkNormal->isChecked() && data.ShapeType() == TopAbs_FACE) {
BRepAdaptor_Surface adapt(TopoDS::Face(data));
if (adapt.GetType() == GeomAbs_Plane) {
double u = 0.5*(adapt.FirstUParameter() + adapt.LastUParameter());
double v = 0.5*(adapt.FirstVParameter() + adapt.LastVParameter());
BRepLProp_SLProps prop(adapt,u,v,1,Precision::Confusion());
if (prop.IsNormalDefined()) {
gp_Pnt pnt; gp_Vec vec;
// handles the orientation state of the shape
BRepGProp_Face(TopoDS::Face(data)).Normal(u,v,pnt,vec);
dirX = vec.X();
dirY = vec.Y();
dirZ = vec.Z();
}
}
}
QString code = QString::fromLatin1(
"FreeCAD.getDocument(\"%1\").addObject(\"%2\",\"%3\")\n"
"FreeCAD.getDocument(\"%1\").%3.Base = FreeCAD.getDocument(\"%1\").%4\n"
"FreeCAD.getDocument(\"%1\").%3.Dir = (%5,%6,%7)\n"
"FreeCAD.getDocument(\"%1\").%3.Solid = (%8)\n"
"FreeCAD.getDocument(\"%1\").%3.TaperAngle = (%9)\n"
"FreeCADGui.getDocument(\"%1\").%4.Visibility = False\n"
"FreeCAD.getDocument(\"%1\").%3.Label = '%10'\n")
.arg(QString::fromLatin1(this->document.c_str()))
.arg(type).arg(name).arg(shape)
.arg(dirX*len)
.arg(dirY*len)
.arg(dirZ*len)
.arg(makeSolid ? QLatin1String("True") : QLatin1String("False"))
.arg(angle)
.arg(label);
Gui::Application::Instance->runPythonCode((const char*)code.toLatin1());
QByteArray to = name.toLatin1();
QByteArray from = shape.toLatin1();
Gui::Command::copyVisual(to, "ShapeColor", from);
Gui::Command::copyVisual(to, "LineColor", from);
Gui::Command::copyVisual(to, "PointColor", from);
}
activeDoc->commitTransaction();
try {
ui->statusLabel->clear();
activeDoc->recompute();
ui->statusLabel->setText(QString::fromLatin1
("<span style=\" color:#55aa00;\">%1</span>").arg(tr("Succeeded")));
}
catch (const std::exception& e) {
//.........这里部分代码省略.........
示例4: accept
void DlgRevolution::accept()
{
if (!this->validate())
return;
Gui::WaitCursor wc;
App::Document* activeDoc = App::GetApplication().getActiveDocument();
activeDoc->openTransaction("Revolve");
try{
QString shape, type, name, solid;
QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
if (ui->checkSolid->isChecked()) {
solid = QString::fromLatin1("True");}
else {
solid = QString::fromLatin1("False");}
App::PropertyLinkSub axisLink;
this->getAxisLink(axisLink);
QString strAxisLink;
if (axisLink.getValue()){
strAxisLink = QString::fromLatin1("(App.ActiveDocument.%1, %2)")
.arg(QString::fromLatin1(axisLink.getValue()->getNameInDocument()))
.arg(axisLink.getSubValues().size() == 1 ?
QString::fromLatin1("\"%1\"").arg(QString::fromLatin1(axisLink.getSubValues()[0].c_str()))
: QString() );
} else {
strAxisLink = QString::fromLatin1("None");
}
QString symmetric;
if (ui->checkSymmetric->isChecked()) {
symmetric = QString::fromLatin1("True");}
else {
symmetric = QString::fromLatin1("False");}
for (QList<QTreeWidgetItem *>::iterator it = items.begin(); it != items.end(); ++it) {
shape = (*it)->data(0, Qt::UserRole).toString();
type = QString::fromLatin1("Part::Revolution");
name = QString::fromLatin1(activeDoc->getUniqueObjectName("Revolve").c_str());
Base::Vector3d axis = this->getDirection();
Base::Vector3d pos = this->getPosition();
QString code = QString::fromLatin1(
"FreeCAD.ActiveDocument.addObject(\"%1\",\"%2\")\n"
"FreeCAD.ActiveDocument.%2.Source = FreeCAD.ActiveDocument.%3\n"
"FreeCAD.ActiveDocument.%2.Axis = (%4,%5,%6)\n"
"FreeCAD.ActiveDocument.%2.Base = (%7,%8,%9)\n"
"FreeCAD.ActiveDocument.%2.Angle = %10\n"
"FreeCAD.ActiveDocument.%2.Solid = %11\n"
"FreeCAD.ActiveDocument.%2.AxisLink = %12\n"
"FreeCAD.ActiveDocument.%2.Symmetric = %13\n"
"FreeCADGui.ActiveDocument.%3.Visibility = False\n")
.arg(type).arg(name).arg(shape) //%1, 2, 3
.arg(axis.x,0,'f',15) //%4
.arg(axis.y,0,'f',15) //%5
.arg(axis.z,0,'f',15) //%6
.arg(pos.x, 0,'f',15) //%7
.arg(pos.y, 0,'f',15) //%8
.arg(pos.z, 0,'f',15) //%9
.arg(getAngle(),0,'f',15) //%10
.arg(solid) //%11
.arg(strAxisLink) //%12
.arg(symmetric) //13
;
Gui::Command::runCommand(Gui::Command::App, code.toLatin1());
QByteArray to = name.toLatin1();
QByteArray from = shape.toLatin1();
Gui::Command::copyVisual(to, "ShapeColor", from);
Gui::Command::copyVisual(to, "LineColor", from);
Gui::Command::copyVisual(to, "PointColor", from);
}
activeDoc->commitTransaction();
activeDoc->recompute();
} catch (Base::Exception &err) {
QMessageBox::critical(this, windowTitle(),
tr("Creating Revolve failed.\n\n%1").arg(QString::fromUtf8(err.what())));
return;
} catch (...){
QMessageBox::critical(this, windowTitle(),
tr("Creating Revolve failed.\n\n%1").arg(QString::fromUtf8("Unknown error")));
return;
}
QDialog::accept();
}
示例5: if
/**
* Builds a mesh solid from the currently active solid type.
*/
void MeshGui::DlgRegularSolidImp::on_createSolidButton_clicked()
{
try {
Gui::WaitCursor wc;
QString cmd; std::string name;
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc) {
QMessageBox::warning(this, tr("Create %1").arg(comboBox1->currentText()), tr("No active document"));
return;
}
if (comboBox1->currentIndex() == 0) { // cube
name = doc->getUniqueObjectName("Cube");
cmd = QString(QLatin1String(
"App.ActiveDocument.addObject(\"Mesh::Cube\",\"%1\")\n"
"App.ActiveDocument.%1.Length=%2\n"
"App.ActiveDocument.%1.Width=%3\n"
"App.ActiveDocument.%1.Height=%4\n"))
.arg(QLatin1String(name.c_str()))
.arg(boxLength->value(),0,'f',2)
.arg(boxWidth->value(),0,'f',2)
.arg(boxHeight->value(),0,'f',2);
}
else if (comboBox1->currentIndex() == 1) { // cylinder
name = doc->getUniqueObjectName("Cylinder");
cmd = QString(QLatin1String(
"App.ActiveDocument.addObject(\"Mesh::Cylinder\",\"%1\")\n"
"App.ActiveDocument.%1.Radius=%2\n"
"App.ActiveDocument.%1.Length=%3\n"
"App.ActiveDocument.%1.EdgeLength=%4\n"
"App.ActiveDocument.%1.Closed=%5\n"
"App.ActiveDocument.%1.Sampling=%6\n"))
.arg(QLatin1String(name.c_str()))
.arg(cylinderRadius->value(),0,'f',2)
.arg(cylinderLength->value(),0,'f',2)
.arg(cylinderEdgeLength->value(),0,'f',2)
.arg(QLatin1String((cylinderClosed->isChecked()?"True":"False")))
.arg(cylinderCount->value());
}
else if (comboBox1->currentIndex() == 2) { // cone
name = doc->getUniqueObjectName("Cone");
cmd = QString(QLatin1String(
"App.ActiveDocument.addObject(\"Mesh::Cone\",\"%1\")\n"
"App.ActiveDocument.%1.Radius1=%2\n"
"App.ActiveDocument.%1.Radius2=%3\n"
"App.ActiveDocument.%1.Length=%4\n"
"App.ActiveDocument.%1.EdgeLength=%5\n"
"App.ActiveDocument.%1.Closed=%6\n"
"App.ActiveDocument.%1.Sampling=%7\n"))
.arg(QLatin1String(name.c_str()))
.arg(coneRadius1->value(),0,'f',2)
.arg(coneRadius2->value(),0,'f',2)
.arg(coneLength->value(),0,'f',2)
.arg(coneEdgeLength->value(),0,'f',2)
.arg(QLatin1String((coneClosed->isChecked()?"True":"False")))
.arg(coneCount->value());
}
else if (comboBox1->currentIndex() == 3) { // sphere
name = doc->getUniqueObjectName("Sphere");
cmd = QString(QLatin1String(
"App.ActiveDocument.addObject(\"Mesh::Sphere\",\"%1\")\n"
"App.ActiveDocument.%1.Radius=%2\n"
"App.ActiveDocument.%1.Sampling=%3\n"))
.arg(QLatin1String(name.c_str()))
.arg(sphereRadius->value(),0,'f',2)
.arg(sphereCount->value());
}
else if (comboBox1->currentIndex() == 4) { // ellipsoid
name = doc->getUniqueObjectName("Ellipsoid");
cmd = QString(QLatin1String(
"App.ActiveDocument.addObject(\"Mesh::Ellipsoid\",\"%1\")\n"
"App.ActiveDocument.%1.Radius1=%2\n"
"App.ActiveDocument.%1.Radius2=%3\n"
"App.ActiveDocument.%1.Sampling=%4\n"))
.arg(QLatin1String(name.c_str()))
.arg(ellipsoidRadius1->value(),0,'f',2)
.arg(ellipsoidRadius2->value(),0,'f',2)
.arg(ellipsoidCount->value());
}
else if (comboBox1->currentIndex() == 5) { // toroid
name = doc->getUniqueObjectName("Torus");
cmd = QString(QLatin1String(
"App.ActiveDocument.addObject(\"Mesh::Torus\",\"%1\")\n"
"App.ActiveDocument.%1.Radius1=%2\n"
"App.ActiveDocument.%1.Radius2=%3\n"
"App.ActiveDocument.%1.Sampling=%4\n"))
.arg(QLatin1String(name.c_str()))
.arg(toroidRadius1->value(),0,'f',2)
.arg(toroidRadius2->value(),0,'f',2)
.arg(toroidCount->value());
}
// Execute the Python block
QString solid = tr("Create %1").arg(comboBox1->currentText());
Gui::Application::Instance->activeDocument()->openCommand(solid.toUtf8());
Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toAscii());
Gui::Application::Instance->activeDocument()->commitCommand();
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().recompute()");
//.........这里部分代码省略.........
示例6: accept
bool DlgFilletEdges::accept()
{
if (!d->object) {
QMessageBox::warning(this, tr("No shape selected"),
tr("No valid shape is selected.\n"
"Please select a valid shape in the drop-down box first."));
return false;
}
App::Document* activeDoc = App::GetApplication().getActiveDocument();
QAbstractItemModel* model = ui->treeView->model();
bool end_radius = !ui->treeView->isColumnHidden(2);
bool todo = false;
QString shape, type, name;
std::string fillet = getFilletType();
int index = ui->shapeObject->currentIndex();
shape = ui->shapeObject->itemData(index).toString();
type = QString::fromAscii("Part::%1").arg(QString::fromAscii(fillet.c_str()));
if (d->fillet)
name = QString::fromAscii(d->fillet->getNameInDocument());
else
name = QString::fromAscii(activeDoc->getUniqueObjectName(fillet.c_str()).c_str());
activeDoc->openTransaction(fillet.c_str());
QString code;
if (!d->fillet) {
code = QString::fromAscii(
"FreeCAD.ActiveDocument.addObject(\"%1\",\"%2\")\n"
"FreeCAD.ActiveDocument.%2.Base = FreeCAD.ActiveDocument.%3\n")
.arg(type).arg(name).arg(shape);
}
code += QString::fromAscii("__fillets__ = []\n");
for (int i=0; i<model->rowCount(); ++i) {
QVariant value = model->index(i,0).data(Qt::CheckStateRole);
Qt::CheckState checkState = static_cast<Qt::CheckState>(value.toInt());
// is item checked
if (checkState & Qt::Checked) {
// the index value of the edge
int id = model->index(i,0).data(Qt::UserRole).toInt();
double r1 = model->index(i,1).data().toDouble();
double r2 = r1;
if (end_radius)
r2 = model->index(i,2).data().toDouble();
code += QString::fromAscii(
"__fillets__.append((%1,%2,%3))\n")
.arg(id).arg(r1,0,'f',2).arg(r2,0,'f',2);
todo = true;
}
}
if (!todo) {
QMessageBox::warning(this, tr("No edge selected"),
tr("No edge entity is checked to fillet.\n"
"Please check one or more edge entities first."));
return false;
}
Gui::WaitCursor wc;
code += QString::fromAscii(
"FreeCAD.ActiveDocument.%1.Edges = __fillets__\n"
"del __fillets__\n"
"FreeCADGui.ActiveDocument.%2.Visibility = False\n")
.arg(name).arg(shape);
Gui::Application::Instance->runPythonCode((const char*)code.toAscii());
activeDoc->commitTransaction();
activeDoc->recompute();
if (d->fillet) {
Gui::ViewProvider* vp;
vp = Gui::Application::Instance->getViewProvider(d->fillet);
if (vp) vp->show();
}
QByteArray to = name.toAscii();
QByteArray from = shape.toAscii();
Gui::Command::copyVisual(to, "ShapeColor", from);
Gui::Command::copyVisual(to, "LineColor", from);
Gui::Command::copyVisual(to, "PointColor", from);
return true;
}