本文整理汇总了C++中app::Document::openTransaction方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::openTransaction方法的具体用法?C++ Document::openTransaction怎么用?C++ Document::openTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app::Document
的用法示例。
在下文中一共展示了Document::openTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_fixButton_clicked
void SketcherValidation::on_fixButton_clicked()
{
// undo command open
App::Document* doc = sketch->getDocument();
doc->openTransaction("add coincident constraint");
std::vector<Sketcher::Constraint*> constr;
for (std::vector<ConstraintIds>::iterator it = this->vertexConstraints.begin(); it != this->vertexConstraints.end(); ++it) {
Sketcher::Constraint* c = new Sketcher::Constraint();
c->Type = Sketcher::Coincident;
c->First = it->First;
c->Second = it->Second;
c->FirstPos = it->FirstPos;
c->SecondPos = it->SecondPos;
constr.push_back(c);
}
sketch->addConstraints(constr);
this->vertexConstraints.clear();
ui->fixButton->setEnabled(false);
hidePoints();
for (std::vector<Sketcher::Constraint*>::iterator it = constr.begin(); it != constr.end(); ++it) {
delete *it;
}
// finish the transaction and update
Gui::WaitCursor wc;
doc->commitTransaction();
doc->recompute();
}
示例2: closeBridge
void MeshFillHole::closeBridge()
{
// Do the hole-filling
Gui::WaitCursor wc;
TBoundary::iterator it = std::find(myPolygon.begin(), myPolygon.end(), myVertex1);
TBoundary::iterator jt = std::find(myPolygon.begin(), myPolygon.end(), myVertex2);
if (it != myPolygon.end() && jt != myPolygon.end()) {
// which iterator comes first
if (jt < it)
std::swap(it, jt);
// split the boundary into two loops and take the shorter one
std::list<TBoundary> bounds;
TBoundary loop1, loop2;
loop1.insert(loop1.end(), myPolygon.begin(), it);
loop1.insert(loop1.end(), jt, myPolygon.end());
loop2.insert(loop2.end(), it, jt);
// this happens when myVertex1 == myVertex2
if (loop2.empty())
bounds.push_back(loop1);
else if (loop1.size() < loop2.size())
bounds.push_back(loop1);
else
bounds.push_back(loop2);
App::Document* doc = myMesh->getDocument();
doc->openTransaction("Bridge && Fill hole");
Mesh::MeshObject* pMesh = myMesh->Mesh.startEditing();
bool ok = myHoleFiller.fillHoles(*pMesh, bounds, myVertex1, myVertex2);
myMesh->Mesh.finishEditing();
if (ok)
doc->commitTransaction();
else
doc->abortTransaction();
}
}
示例3: accept
void Segmentation::accept()
{
const Mesh::MeshObject* mesh = myMesh->Mesh.getValuePtr();
// make a copy because we might smooth the mesh before
MeshCore::MeshKernel kernel = mesh->getKernel();
if (ui->checkBoxSmooth->isChecked()) {
MeshCore::LaplaceSmoothing smoother(kernel);
smoother.Smooth(ui->smoothSteps->value());
}
MeshCore::MeshSegmentAlgorithm finder(kernel);
MeshCore::MeshCurvature meshCurv(kernel);
meshCurv.ComputePerVertex();
std::vector<MeshCore::MeshSurfaceSegment*> segm;
if (ui->groupBoxCyl->isChecked()) {
segm.push_back(new MeshCore::MeshCurvatureCylindricalSegment
(meshCurv.GetCurvature(), ui->numCyl->value(), ui->tol1Cyl->value(), ui->tol2Cyl->value(), ui->radCyl->value().getValue()));
}
if (ui->groupBoxSph->isChecked()) {
segm.push_back(new MeshCore::MeshCurvatureSphericalSegment
(meshCurv.GetCurvature(), ui->numSph->value(), ui->tolSph->value(), ui->radSph->value().getValue()));
}
if (ui->groupBoxPln->isChecked()) {
segm.push_back(new MeshCore::MeshCurvaturePlanarSegment
(meshCurv.GetCurvature(), ui->numPln->value(), ui->tolPln->value()));
}
finder.FindSegments(segm);
App::Document* document = App::GetApplication().getActiveDocument();
document->openTransaction("Segmentation");
std::string internalname = "Segments_";
internalname += myMesh->getNameInDocument();
App::DocumentObjectGroup* group = static_cast<App::DocumentObjectGroup*>(document->addObject
("App::DocumentObjectGroup", internalname.c_str()));
std::string labelname = "Segments ";
labelname += myMesh->Label.getValue();
group->Label.setValue(labelname);
for (std::vector<MeshCore::MeshSurfaceSegment*>::iterator it = segm.begin(); it != segm.end(); ++it) {
const std::vector<MeshCore::MeshSegment>& data = (*it)->GetSegments();
for (std::vector<MeshCore::MeshSegment>::const_iterator jt = data.begin(); jt != data.end(); ++jt) {
Mesh::MeshObject* segment = mesh->meshFromSegment(*jt);
Mesh::Feature* feaSegm = static_cast<Mesh::Feature*>(group->addObject("Mesh::Feature", "Segment"));
Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing();
feaMesh->swap(*segment);
feaSegm->Mesh.finishEditing();
delete segment;
std::stringstream label;
label << feaSegm->Label.getValue() << " (" << (*it)->GetType() << ")";
feaSegm->Label.setValue(label.str());
}
delete (*it);
}
document->commitTransaction();
}
示例4: 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();
}
示例5: on_swapReversed_clicked
void SketcherValidation::on_swapReversed_clicked()
{
App::Document* doc = sketch->getDocument();
doc->openTransaction("Sketch porting");
int n = sketch->port_reversedExternalArcs(/*justAnalyze=*/false);
QMessageBox::warning(this, tr("Reversed external geometry"),
tr("%1 changes were made to constraints linking to endpoints of reversed arcs.").arg(n));
hidePoints();
ui->swapReversed->setEnabled(false);
doc->commitTransaction();
}
示例6: on_orientLockEnable_clicked
void SketcherValidation::on_orientLockEnable_clicked()
{
App::Document* doc = sketch->getDocument();
doc->openTransaction("Constraint orientation lock");
int n = sketch->changeConstraintsLocking(/*bLock=*/true);
QMessageBox::warning(this, tr("Constraint orientation locking"),
tr("Orientation locking was enabled and recomputed for %1 constraints. The"
" constraints have been listed in Report view (menu View -> Views ->"
" Report view).").arg(n));
doc->commitTransaction();
}
示例7: on_orientLockDisable_clicked
void SketcherValidation::on_orientLockDisable_clicked()
{
App::Document* doc = sketch->getDocument();
doc->openTransaction("Constraint orientation unlock");
int n = sketch->changeConstraintsLocking(/*bLock=*/false);
QMessageBox::warning(this, tr("Constraint orientation locking"),
tr("Orientation locking was disabled for %1 constraints. The"
" constraints have been listed in Report view (menu View -> Views ->"
" Report view). Note that for all future constraints, the locking still"
" defaults to ON.").arg(n));
doc->commitTransaction();
}
示例8: deleteSelectedItems
void ConstraintView::deleteSelectedItems()
{
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc) return;
doc->openTransaction("Delete");
std::vector<Gui::SelectionObject> sel = Gui::Selection().getSelectionEx(doc->getName());
for (std::vector<Gui::SelectionObject>::iterator ft = sel.begin(); ft != sel.end(); ++ft) {
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(ft->getObject());
if (vp) {
vp->onDelete(ft->getSubNames());
}
}
doc->commitTransaction();
}
示例9: accept
bool Tessellation::accept()
{
if (ui->treeWidget->selectedItems().isEmpty()) {
QMessageBox::critical(this, windowTitle(),
tr("Select a shape for meshing, first."));
return false;
}
App::Document* activeDoc = App::GetApplication().getDocument((const char*)this->document.toAscii());
if (!activeDoc) {
QMessageBox::critical(this, windowTitle(),
tr("No such document '%1'.").arg(this->document));
return false;
}
try {
QString shape, label;
Gui::WaitCursor wc;
activeDoc->openTransaction("Meshing");
QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
std::vector<Part::Feature*> shapes = Gui::Selection().getObjectsOfType<Part::Feature>();
for (QList<QTreeWidgetItem *>::iterator it = items.begin(); it != items.end(); ++it) {
shape = (*it)->data(0, Qt::UserRole).toString();
label = (*it)->text(0);
QString cmd = QString::fromAscii(
"__doc__=FreeCAD.getDocument(\"%1\")\n"
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
"__mesh__.Mesh=MeshPart.meshFromShape(__doc__.getObject(\"%2\").Shape,%3,0,0,%4)\n"
"__mesh__.Label=\"%5 (Meshed)\"\n"
"del __doc__, __mesh__\n")
.arg(this->document)
.arg(shape)
.arg(ui->spinMaxEdgeLength->value())
.arg(ui->spinDeviation->value())
.arg(label);
Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toAscii());
}
activeDoc->commitTransaction();
}
catch (const Base::Exception& e) {
Base::Console().Error(e.what());
}
return true;
}
示例10: addFace
void MeshFaceAddition::addFace()
{
Mesh::Feature* mf = static_cast<Mesh::Feature*>(faceView->mesh->getObject());
App::Document* doc = mf->getDocument();
doc->openTransaction("Add triangle");
Mesh::MeshObject* mesh = mf->Mesh.startEditing();
MeshCore::MeshFacet f;
f._aulPoints[0] = faceView->index[0];
f._aulPoints[1] = faceView->index[1];
f._aulPoints[2] = faceView->index[2];
std::vector<MeshCore::MeshFacet> faces;
faces.push_back(f);
mesh->addFacets(faces);
mf->Mesh.finishEditing();
doc->commitTransaction();
clearPoints();
}
示例11: on_delConstrExtr_clicked
void SketcherValidation::on_delConstrExtr_clicked()
{
int reply;
reply = QMessageBox::question(this,
tr("Delete constraints to external geom."),
tr("You are about to delete ALL constraints that deal with external geometry. This is useful to rescue a sketch with broken/changed links to external geometry. Are you sure you want to delete the constraints?"),
QMessageBox::No|QMessageBox::Yes,QMessageBox::No);
if(reply!=QMessageBox::Yes) return;
App::Document* doc = sketch->getDocument();
doc->openTransaction("Delete constraints");
sketch->delConstraintsToExternal();
doc->commitTransaction();
QMessageBox::warning(this, tr("Delete constraints to external geom."),
tr("All constraints that deal with external geometry were deleted."));
}
示例12: accept
bool Tessellation::accept()
{
if (ui->treeWidget->selectedItems().isEmpty()) {
QMessageBox::critical(this, windowTitle(),
tr("Select a shape for meshing, first."));
return false;
}
App::Document* activeDoc = App::GetApplication().getDocument((const char*)this->document.toAscii());
if (!activeDoc) {
QMessageBox::critical(this, windowTitle(),
tr("No such document '%1'.").arg(this->document));
return false;
}
try {
QString shape, label;
Gui::WaitCursor wc;
int method = buttonGroup->checkedId();
activeDoc->openTransaction("Meshing");
QList<QTreeWidgetItem *> items = ui->treeWidget->selectedItems();
std::vector<Part::Feature*> shapes = Gui::Selection().getObjectsOfType<Part::Feature>();
for (QList<QTreeWidgetItem *>::iterator it = items.begin(); it != items.end(); ++it) {
shape = (*it)->data(0, Qt::UserRole).toString();
label = (*it)->text(0);
QString cmd;
if (method == 0) { // Standard
double devFace = ui->spinSurfaceDeviation->value();
cmd = QString::fromAscii(
"__doc__=FreeCAD.getDocument(\"%1\")\n"
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
"__mesh__.Mesh=Mesh.Mesh(__doc__.getObject(\"%2\").Shape.tessellate(%3))\n"
"__mesh__.Label=\"%4 (Meshed)\"\n"
"__mesh__.ViewObject.CreaseAngle=25.0\n"
"del __doc__, __mesh__\n")
.arg(this->document)
.arg(shape)
.arg(devFace)
.arg(label);
}
else if (method == 1) { // Mefisto
double maxEdge = ui->spinMaximumEdgeLength->value();
if (!ui->spinMaximumEdgeLength->isEnabled())
maxEdge = 0;
cmd = QString::fromAscii(
"__doc__=FreeCAD.getDocument(\"%1\")\n"
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
"__mesh__.Mesh=MeshPart.meshFromShape(Shape=__doc__.getObject(\"%2\").Shape,MaxLength=%3)\n"
"__mesh__.Label=\"%4 (Meshed)\"\n"
"__mesh__.ViewObject.CreaseAngle=25.0\n"
"del __doc__, __mesh__\n")
.arg(this->document)
.arg(shape)
.arg(maxEdge)
.arg(label);
}
else if (method == 2) { // Netgen
int fineness = ui->comboFineness->currentIndex();
double growthRate = ui->doubleGrading->value();
double nbSegPerEdge = ui->spinEdgeElements->value();
double nbSegPerRadius = ui->spinCurvatureElements->value();
bool secondOrder = ui->checkSecondOrder->isChecked();
bool optimize = ui->checkOptimizeSurface->isChecked();
bool allowquad = ui->checkQuadDominated->isChecked();
if (fineness < 5) {
cmd = QString::fromAscii(
"__doc__=FreeCAD.getDocument(\"%1\")\n"
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
"__mesh__.Mesh=MeshPart.meshFromShape(Shape=__doc__.getObject(\"%2\").Shape,"
"Fineness=%3,SecondOrder=%4,Optimize=%5,AllowQuad=%6)\n"
"__mesh__.Label=\"%7 (Meshed)\"\n"
"__mesh__.ViewObject.CreaseAngle=25.0\n"
"del __doc__, __mesh__\n")
.arg(this->document)
.arg(shape)
.arg(fineness)
.arg(secondOrder ? 1 : 0)
.arg(optimize ? 1 : 0)
.arg(allowquad ? 1 : 0)
.arg(label);
}
else {
cmd = QString::fromAscii(
"__doc__=FreeCAD.getDocument(\"%1\")\n"
"__mesh__=__doc__.addObject(\"Mesh::Feature\",\"Mesh\")\n"
"__mesh__.Mesh=MeshPart.meshFromShape(Shape=__doc__.getObject(\"%2\").Shape,"
"GrowthRate=%3,SegPerEdge=%4,SegPerRadius=%5,SecondOrder=%6,Optimize=%7,AllowQuad=%8)\n"
"__mesh__.Label=\"%9 (Meshed)\"\n"
"__mesh__.ViewObject.CreaseAngle=25.0\n"
"del __doc__, __mesh__\n")
.arg(this->document)
.arg(shape)
.arg(growthRate)
.arg(nbSegPerEdge)
.arg(nbSegPerRadius)
.arg(secondOrder ? 1 : 0)
.arg(optimize ? 1 : 0)
//.........这里部分代码省略.........
示例13: accept
bool Mirroring::accept()
{
if (ui->shapes->selectedItems().isEmpty()) {
QMessageBox::critical(this, windowTitle(),
tr("Select a shape for mirroring, first."));
return false;
}
App::Document* activeDoc = App::GetApplication().getDocument((const char*)this->document.toLatin1());
if (!activeDoc) {
QMessageBox::critical(this, windowTitle(),
tr("No such document '%1'.").arg(this->document));
return false;
}
Gui::WaitCursor wc;
unsigned int count = activeDoc->countObjectsOfType(Base::Type::fromName("Part::Mirroring"));
activeDoc->openTransaction("Mirroring");
QString shape, label;
QRegExp rx(QString::fromLatin1(" \\(Mirror #\\d+\\)$"));
QList<QTreeWidgetItem *> items = ui->shapes->selectedItems();
float normx=0, normy=0, normz=0;
int index = ui->comboBox->currentIndex();
if (index == 0)
normz = 1.0f;
else if (index == 1)
normy = 1.0f;
else
normx = 1.0f;
double basex = ui->baseX->value();
double basey = ui->baseY->value();
double basez = ui->baseZ->value();
for (QList<QTreeWidgetItem *>::iterator it = items.begin(); it != items.end(); ++it) {
shape = (*it)->data(0, Qt::UserRole).toString();
label = (*it)->text(0);
// if we already have the suffix " (Mirror #<number>)" remove it
int pos = label.indexOf(rx);
if (pos > -1)
label = label.left(pos);
label.append(QString::fromLatin1(" (Mirror #%1)").arg(++count));
QString code = QString::fromLatin1(
"__doc__=FreeCAD.getDocument(\"%1\")\n"
"__doc__.addObject(\"Part::Mirroring\")\n"
"__doc__.ActiveObject.Source=__doc__.getObject(\"%2\")\n"
"__doc__.ActiveObject.Label=\"%3\"\n"
"__doc__.ActiveObject.Normal=(%4,%5,%6)\n"
"__doc__.ActiveObject.Base=(%7,%8,%9)\n"
"del __doc__")
.arg(this->document).arg(shape).arg(label)
.arg(normx).arg(normy).arg(normz)
.arg(basex).arg(basey).arg(basez);
Gui::Application::Instance->runPythonCode((const char*)code.toLatin1());
QByteArray from = shape.toLatin1();
Gui::Command::copyVisual("ActiveObject", "ShapeColor", from);
Gui::Command::copyVisual("ActiveObject", "LineColor", from);
Gui::Command::copyVisual("ActiveObject", "PointColor", from);
}
activeDoc->commitTransaction();
activeDoc->recompute();
return true;
}
示例14: apply
void DlgExtrusion::apply()
{
try{
if (!validate())
throw Base::AbortException();
if (filter) //if still selecting edge - stop. This is important for visibility automation.
this->on_btnSelectEdge_clicked();
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);
std::vector<App::DocumentObject*> objects = this->getShapesToExtrude();
for (App::DocumentObject* sourceObj: objects) {
assert(sourceObj);
if (!sourceObj->isDerivedFrom(Part::Feature::getClassTypeId())){
std::stringstream errmsg;
errmsg << "Object " << sourceObj->getNameInDocument() << " is not Part object (has no OCC shape). Can't extrude it.\n";
Base::Console().Error(errmsg.str().c_str());
continue;
}
std::string name;
name = sourceObj->getDocument()->getUniqueObjectName("Extrude").c_str();
if (addBaseName) {
//FIXME: implement
//QString baseName = QString::fromLatin1("Extrude_%1").arg(sourceObjectName);
//label = QString::fromLatin1("%1_Extrude").arg((*it)->text(0));
}
Gui::Command::doCommand(Gui::Command::Doc, "f = FreeCAD.getDocument('%s').addObject('Part::Extrusion', '%s')", sourceObj->getDocument()->getName(), name.c_str());
this->writeParametersToFeature(*(sourceObj->getDocument()->getObject(name.c_str())), sourceObj);
std::string sourceObjectName = sourceObj->getNameInDocument();
Gui::Command::copyVisual(name.c_str(), "ShapeColor", sourceObjectName.c_str());
Gui::Command::copyVisual(name.c_str(), "LineColor", sourceObjectName.c_str());
Gui::Command::copyVisual(name.c_str(), "PointColor", sourceObjectName.c_str());
Gui::Command::doCommand(Gui::Command::Gui,"f.Base.ViewObject.hide()");
}
activeDoc->commitTransaction();
Gui::Command::updateActive();
}
catch (Base::AbortException&){
throw;
}
catch (Base::Exception &err){
QMessageBox::critical(this, windowTitle(),
tr("Creating Extrusion failed.\n\n%1").arg(QString::fromUtf8(err.what())));
return;
}
catch(...) {
QMessageBox::critical(this, windowTitle(),
tr("Creating Extrusion failed.\n\n%1").arg(QString::fromUtf8("Unknown error")));
return;
}
}
示例15: 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) {
//.........这里部分代码省略.........