本文整理汇总了C++中app::DocumentObject::getTypeId方法的典型用法代码示例。如果您正苦于以下问题:C++ DocumentObject::getTypeId方法的具体用法?C++ DocumentObject::getTypeId怎么用?C++ DocumentObject::getTypeId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app::DocumentObject
的用法示例。
在下文中一共展示了DocumentObject::getTypeId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
App::DocumentObjectExecReturn *DrawViewCollection::execute(void)
{
if (ScaleType.isValue("Document")) {
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
TechDraw::DrawView *view = static_cast<TechDraw::DrawView *>(*it);
// Set scale factor of each view
view->ScaleType.setValue("Document");
view->touch();
}
}
} else if(strcmp(ScaleType.getValueAsString(), "Custom") == 0) {
// Rebuild the views
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
TechDraw::DrawView *view = static_cast<TechDraw::DrawView *>(*it);
view->ScaleType.setValue("Custom");
// Set scale factor of each view
view->Scale.setValue(Scale.getValue());
view->touch();
}
}
}
return DrawView::execute();
}
示例2: list
static PyObject * exporter(PyObject *self, PyObject *args)
{
PyObject* object;
char* Name;
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
return NULL;
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
float fTolerance = 0.1f;
MeshObject global_mesh;
PY_TRY {
Py::Sequence list(object);
Base::Type meshId = Base::Type::fromName("Mesh::Feature");
Base::Type partId = Base::Type::fromName("Part::Feature");
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(meshId)) {
const MeshObject& mesh = static_cast<Mesh::Feature*>(obj)->Mesh.getValue();
MeshCore::MeshKernel kernel = mesh.getKernel();
kernel.Transform(mesh.getTransform());
if (global_mesh.countFacets() == 0)
global_mesh.setKernel(kernel);
else
global_mesh.addMesh(kernel);
}
else if (obj->getTypeId().isDerivedFrom(partId)) {
App::Property* shape = obj->getPropertyByName("Shape");
Base::Reference<MeshObject> mesh(new MeshObject());
if (shape && shape->getTypeId().isDerivedFrom(App::PropertyComplexGeoData::getClassTypeId())) {
std::vector<Base::Vector3d> aPoints;
std::vector<Data::ComplexGeoData::Facet> aTopo;
static_cast<App::PropertyComplexGeoData*>(shape)->getFaces(aPoints, aTopo,fTolerance);
mesh->addFacets(aTopo, aPoints);
if (global_mesh.countFacets() == 0)
global_mesh = *mesh;
else
global_mesh.addMesh(*mesh);
}
}
else {
Base::Console().Message("'%s' is not a mesh or shape, export will be ignored.\n", obj->Label.getValue());
}
}
}
// export mesh compound
global_mesh.save(EncodedName.c_str());
} PY_CATCH;
Py_Return;
}
示例3: execute
App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
{
if (ScaleType.isValue("Automatic")) {
//Recalculate scale
double autoScale = calculateAutomaticScale();
if(std::abs(Scale.getValue() - autoScale) > FLT_EPSILON) {
// Set this Scale
Scale.setValue(autoScale);
//Rebuild the DPGI's
const std::vector<App::DocumentObject *> &views = Views.getValues();
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
App::DocumentObject *docObj = *it;
if(docObj->getTypeId().isDerivedFrom(DrawProjGroupItem::getClassTypeId())) {
DrawProjGroupItem *view = dynamic_cast<DrawProjGroupItem *>(*it);
view->ScaleType.setValue("Custom");
view->Scale.setValue(autoScale);
view->Scale.setStatus(App::Property::ReadOnly,true);
view->touch();
}
}
resetPositions();
}
}
// recalculate positions for children
if (Views.getSize()) {
distributeProjections();
}
//touch();
return DrawViewCollection::execute();
}
示例4: getShape
App::DocumentObjectExecReturn* RuledSurface::getShape(const App::PropertyLinkSub& link,
TopoDS_Shape& shape) const
{
App::DocumentObject* obj = link.getValue();
if (!(obj && obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
return new App::DocumentObjectExecReturn("No shape linked.");
// if no explicit sub-shape is selected use the whole part
const std::vector<std::string>& element = link.getSubValues();
if (element.empty()) {
shape = static_cast<Part::Feature*>(obj)->Shape.getValue();
return nullptr;
}
else if (element.size() != 1) {
return new App::DocumentObjectExecReturn("Not exactly one sub-shape linked.");
}
const Part::TopoShape& part = static_cast<Part::Feature*>(obj)->Shape.getValue();
if (!part.getShape().IsNull()) {
if (!element[0].empty()) {
shape = part.getSubShape(element[0].c_str());
}
else {
// the sub-element is an empty string, so use the whole part
shape = part.getShape();
}
}
return nullptr;
}
示例5: DocumentObjectExecReturn
App::DocumentObjectExecReturn *Revolution::execute(void)
{
App::DocumentObject* link = Source.getValue();
if (!link)
return new App::DocumentObjectExecReturn("No object linked");
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
Part::Feature *base = static_cast<Part::Feature*>(Source.getValue());
Base::Vector3d b = Base.getValue();
Base::Vector3d v = Axis.getValue();
gp_Pnt pnt(b.x,b.y,b.z);
gp_Dir dir(v.x,v.y,v.z);
Standard_Boolean isSolid = Solid.getValue() ? Standard_True : Standard_False;
try {
// Now, let's get the TopoDS_Shape
//TopoDS_Shape revolve = base->Shape.getShape().revolve(gp_Ax1(pnt, dir),
// Angle.getValue()/180.0f*M_PI);
TopoDS_Shape revolve = base->Shape.getShape().revolve(gp_Ax1(pnt, dir),
Angle.getValue()/180.0f*M_PI,isSolid);
if (revolve.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null");
this->Shape.setValue(revolve);
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
示例6: write
Py::Object write(const Py::Tuple& args)
{
char* Name;
PyObject* pObj;
if (!PyArg_ParseTuple(args.ptr(), "Oet",&pObj,"utf-8",&Name))
throw Py::Exception();
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
Base::FileInfo file(EncodedName.c_str());
if (PyObject_TypeCheck(pObj, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(pObj)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(Base::Type::fromName("Path::Feature"))) {
const Toolpath& path = static_cast<Path::Feature*>(obj)->Path.getValue();
std::string gcode = path.toGCode();
std::ofstream ofile(EncodedName.c_str());
ofile << gcode;
ofile.close();
}
else {
throw Py::RuntimeError("The given file is not a path");
}
}
return Py::None();
}
示例7: exporter
Py::Object exporter(const Py::Tuple& args)
{
PyObject* object;
char* Name;
if (!PyArg_ParseTuple(args.ptr(), "Oet",&object,"utf-8",&Name))
throw Py::Exception();
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
Py::Sequence list(object);
Base::Type meshId = Base::Type::fromName("Fem::FemMeshObject");
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(meshId)) {
static_cast<FemMeshObject*>(obj)->FemMesh.getValue().write(EncodedName.c_str());
break;
}
}
}
return Py::None();
}
示例8: apply
void TaskGrooveParameters::apply()
{
App::DocumentObject* groove = GrooveView->getObject();
std::string name = groove->getNameInDocument();
// retrieve sketch and its support object
App::DocumentObject* sketch = 0;
App::DocumentObject* support = 0;
if (groove->getTypeId().isDerivedFrom(PartDesign::Groove::getClassTypeId())) {
sketch = static_cast<PartDesign::Groove*>(groove)->Sketch.getValue<Sketcher::SketchObject*>();
if (sketch) {
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
}
}
//Gui::Command::openCommand("Groove changed");
ui->grooveAngle->apply();
std::string axis = getReferenceAxis().toStdString();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.ReferenceAxis = %s",name.c_str(),axis.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",name.c_str(), getMidplane() ? 1 : 0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(), getReversed() ? 1 : 0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (groove->isValid()) {
if (sketch)
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
if (support)
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
}
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
示例9: DocumentObjectExecReturn
App::DocumentObjectExecReturn *Mirroring::execute(void)
{
App::DocumentObject* link = Source.getValue();
if (!link)
return new App::DocumentObjectExecReturn("No object linked");
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
Part::Feature *source = static_cast<Part::Feature*>(link);
Base::Vector3f base = Base.getValue();
Base::Vector3f norm = Normal.getValue();
try {
const TopoDS_Shape& shape = source->Shape.getValue();
gp_Ax2 ax2(gp_Pnt(base.x,base.y,base.z), gp_Dir(norm.x,norm.y,norm.z));
gp_Trsf mat;
mat.SetMirror(ax2);
TopLoc_Location loc = shape.Location();
gp_Trsf placement = loc.Transformation();
mat = placement * mat;
BRepBuilderAPI_Transform mkTrf(shape, mat);
this->Shape.setValue(mkTrf.Shape());
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
示例10: on_shapeObject_activated
void DlgFilletEdges::on_shapeObject_activated(int index)
{
d->object = 0;
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model());
model->removeRows(0, model->rowCount());
QByteArray name = ui->shapeObject->itemData(index).toByteArray();
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc)
return;
App::DocumentObject* part = doc->getObject((const char*)name);
if (part && part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
d->object = part;
TopoDS_Shape myShape = static_cast<Part::Feature*>(part)->Shape.getValue();
// build up map edge->face
TopTools_IndexedDataMapOfShapeListOfShape edge2Face;
TopExp::MapShapesAndAncestors(myShape, TopAbs_EDGE, TopAbs_FACE, edge2Face);
TopTools_IndexedMapOfShape mapOfShape;
TopExp::MapShapes(myShape, TopAbs_EDGE, mapOfShape);
// populate the model
d->edge_ids.clear();
for (int i=1; i<= edge2Face.Extent(); ++i) {
// set the index value as user data to use it in accept()
const TopTools_ListOfShape& los = edge2Face.FindFromIndex(i);
if (los.Extent() == 2) {
// set the index value as user data to use it in accept()
const TopoDS_Shape& edge = edge2Face.FindKey(i);
// Now check also the continuity to only allow C0-continious
// faces
const TopoDS_Shape& face1 = los.First();
const TopoDS_Shape& face2 = los.Last();
GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge),
TopoDS::Face(face1),
TopoDS::Face(face2));
if (cont == GeomAbs_C0) {
int id = mapOfShape.FindIndex(edge);
d->edge_ids.push_back(id);
}
}
}
model->insertRows(0, d->edge_ids.size());
int index = 0;
for (std::vector<int>::iterator it = d->edge_ids.begin(); it != d->edge_ids.end(); ++it) {
model->setData(model->index(index, 0), QVariant(tr("Edge%1").arg(*it)));
model->setData(model->index(index, 0), QVariant(*it), Qt::UserRole);
model->setData(model->index(index, 1), QVariant(QLocale::system().toString(1.0,'f',2)));
model->setData(model->index(index, 2), QVariant(QLocale::system().toString(1.0,'f',2)));
std::stringstream element;
element << "Edge" << *it;
if (Gui::Selection().isSelected(part, element.str().c_str()))
model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole);
else
model->setData(model->index(index, 0), Qt::Unchecked, Qt::CheckStateRole);
index++;
}
}
}
示例11: Exception
Part::Part2DObject* SketchBased::getVerifiedSketch() const {
App::DocumentObject* result = Sketch.getValue();
if (!result)
throw Base::Exception("No sketch linked");
if (!result->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId()))
throw Base::Exception("Linked object is not a Sketch or Part2DObject");
return static_cast<Part::Part2DObject*>(result);
}
示例12: DocumentObjectExecReturn
App::DocumentObjectExecReturn *Chamfer::execute(void)
{
App::DocumentObject* link = Base.getValue();
if (!link)
return new App::DocumentObjectExecReturn("No object linked");
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
const Part::TopoShape& TopShape = base->Shape.getShape();
if (TopShape._Shape.IsNull())
return new App::DocumentObjectExecReturn("Cannot chamfer invalid shape");
const std::vector<std::string>& SubVals = Base.getSubValuesStartsWith("Edge");
if (SubVals.size() == 0)
return new App::DocumentObjectExecReturn("No edges specified");
double size = Size.getValue();
this->positionByBase();
// create an untransformed copy of the base shape
Part::TopoShape baseShape(TopShape);
baseShape.setTransform(Base::Matrix4D());
try {
BRepFilletAPI_MakeChamfer mkChamfer(baseShape._Shape);
TopTools_IndexedMapOfShape mapOfEdges;
TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
TopExp::MapShapesAndAncestors(baseShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
TopExp::MapShapes(baseShape._Shape, TopAbs_EDGE, mapOfEdges);
for (std::vector<std::string>::const_iterator it=SubVals.begin(); it != SubVals.end(); ++it) {
TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(it->c_str()));
const TopoDS_Face& face = TopoDS::Face(mapEdgeFace.FindFromKey(edge).First());
mkChamfer.Add(size, edge, face);
}
mkChamfer.Build();
if (!mkChamfer.IsDone())
return new App::DocumentObjectExecReturn("Failed to create chamfer");
TopoDS_Shape shape = mkChamfer.Shape();
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null");
TopTools_ListOfShape aLarg;
aLarg.Append(baseShape._Shape);
if (!BRepAlgo::IsValid(aLarg, shape, Standard_False, Standard_False)) {
return new App::DocumentObjectExecReturn("Resulting shape is invalid");
}
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
示例13: slotCreatedObject
void DlgEvaluateMeshImp::slotCreatedObject(const App::DocumentObject& Obj)
{
// add new mesh object to the list
if (Obj.getTypeId().isDerivedFrom(Mesh::Feature::getClassTypeId())) {
QString label = QString::fromUtf8(Obj.Label.getValue());
QString name = QString::fromAscii(Obj.getNameInDocument());
meshNameButton->addItem(label, name);
}
}
示例14: activated
void CmdPartDesignMoveTip::activated(int iMsg)
{
Q_UNUSED(iMsg);
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(
Part::Feature::getClassTypeId() );
App::DocumentObject* selFeature;
PartDesign::Body* body= nullptr;
if ( features.size() == 1 ) {
selFeature = features.front();
if ( selFeature->getTypeId().isDerivedFrom ( PartDesign::Body::getClassTypeId() ) ) {
body = static_cast<PartDesign::Body *> ( selFeature );
} else {
body = PartDesignGui::getBodyFor ( selFeature, /* messageIfNot =*/ false );
}
} else {
selFeature = nullptr;
}
if (!selFeature) {
QMessageBox::warning (0, QObject::tr( "Selection error" ),
QObject::tr( "Select exactly one PartDesign feature or a body." ) );
return;
} else if (!body) {
QMessageBox::warning (0, QObject::tr( "Selection error" ),
QObject::tr( "Couldn't determine a body for the selected feature '%s'.", selFeature->Label.getValue() ) );
return;
} else if ( !selFeature->isDerivedFrom(PartDesign::Feature::getClassTypeId () ) &&
selFeature != body && body->BaseFeature.getValue() != selFeature ) {
QMessageBox::warning (0, QObject::tr( "Selection error" ),
QObject::tr( "Only a solid feature can be the tip of a body." ) );
return;
}
App::DocumentObject* oldTip = body->Tip.getValue();
if (oldTip == selFeature) { // it's not generally an error, so print only a console message
Base::Console().Message ("%s is already the tip of the body", selFeature->getNameInDocument () );
return;
}
openCommand("Move tip to selected feature");
if (selFeature == body) {
doCommand(Doc,"App.activeDocument().%s.Tip = None", body->getNameInDocument());
} else {
doCommand(Doc,"App.activeDocument().%s.Tip = App.activeDocument().%s",body->getNameInDocument(),
selFeature->getNameInDocument());
// Adjust visibility to show only the Tip feature
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", selFeature->getNameInDocument());
}
// TOOD: Hide all datum features after the Tip feature? But the user might have already hidden some and wants to see
// others, so we would have to remember their state somehow
updateActive();
}
示例15: onFaceName
const QByteArray TaskSketchBasedParameters::onFaceName(const QString& text)
{
if (text.length() == 0)
return QByteArray();
QStringList parts = text.split(QChar::fromLatin1(':'));
if (parts.length() < 2)
parts.push_back(QString::fromLatin1(""));
// Check whether this is the name of an App::Plane or Part::Datum feature
App::DocumentObject* obj = vp->getObject()->getDocument()->getObject(parts[0].toLatin1());
if (obj == NULL)
return QByteArray();
PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject<PartDesign::Body*>(PDBODYKEY);
if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
// everything is OK (we assume a Part can only have exactly 3 App::Plane objects located at the base of the feature tree)
return QByteArray();
} else if (obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
if (!activeBody->hasFeature(obj))
return QByteArray();
return QByteArray();
} else {
// We must expect that "text" is the translation of "Face" followed by an ID.
QString name;
QTextStream str(&name);
str << "^" << tr("Face") << "(\\d+)$";
QRegExp rx(name);
if (text.indexOf(rx) < 0) {
return QByteArray();
}
int faceId = rx.cap(1).toInt();
std::stringstream ss;
ss << "Face" << faceId;
std::vector<std::string> upToFaces(1,ss.str());
PartDesign::ProfileBased* pcSketchBased = static_cast<PartDesign::ProfileBased*>(vp->getObject());
pcSketchBased->UpToFace.setValue(obj, upToFaces);
recomputeFeature();
return QByteArray(ss.str().c_str());
}
}