本文整理汇总了C++中app::Document::getObjects方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::getObjects方法的具体用法?C++ Document::getObjects怎么用?C++ Document::getObjects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app::Document
的用法示例。
在下文中一共展示了Document::getObjects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findFrontRootOfType
SoNode* ViewProviderDocumentObject::findFrontRootOfType(const SoType& type) const
{
// first get the document this object is part of and get its GUI counterpart
App::Document* pAppDoc = pcObject->getDocument();
Gui::Document* pGuiDoc = Gui::Application::Instance->getDocument(pAppDoc);
SoSearchAction searchAction;
searchAction.setType(type);
searchAction.setInterest(SoSearchAction::FIRST);
// search in all view providers for the node type
std::vector<App::DocumentObject*> obj = pAppDoc->getObjects();
for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
const ViewProvider* vp = pGuiDoc->getViewProvider(*it);
// Ignore 'this' view provider. It could also happen that vp is 0, e.g. when
// several objects have been added to the App::Document before notifying the
// Gui::Document
if (!vp || vp == this)
continue;
SoSeparator* front = vp->getFrontRoot();
//if (front && front->getTypeId() == type)
// return front;
if (front) {
searchAction.apply(front);
SoPath* path = searchAction.getPath();
if (path)
return path->getTail();
}
}
return 0;
}
示例2: QDialog
/**
* Constructs a VisualInspection as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*/
VisualInspection::VisualInspection(QWidget* parent, Qt::WFlags fl)
: QDialog(parent, fl), ui(new Ui_VisualInspection)
{
ui->setupUi(this);
connect(ui->treeWidgetActual, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
this, SLOT(onActivateItem(QTreeWidgetItem*)));
connect(ui->treeWidgetNominal, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
this, SLOT(onActivateItem(QTreeWidgetItem*)));
connect(ui->buttonBox, SIGNAL(helpRequested()),
Gui::getMainWindow(), SLOT(whatsThis()));
//FIXME: Not used yet
ui->textLabel2->hide();
ui->prefFloatSpinBox2->hide();
ui->prefFloatSpinBox1->setDecimals(Base::UnitsApi::getDecimals());
ui->prefFloatSpinBox2->setDecimals(Base::UnitsApi::getDecimals());
App::Document* doc = App::GetApplication().getActiveDocument();
// disable Ok button and enable of at least one item in each view is on
buttonOk = ui->buttonBox->button(QDialogButtonBox::Ok);
buttonOk->setDisabled(true);
if (!doc) {
ui->treeWidgetActual->setDisabled(true);
ui->treeWidgetNominal->setDisabled(true);
return;
}
Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
std::vector<App::DocumentObject*> obj = doc->getObjects();
Base::Type point = Base::Type::fromName("Points::Feature");
Base::Type mesh = Base::Type::fromName("Mesh::Feature");
Base::Type shape = Base::Type::fromName("Part::Feature");
for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(point) ||
(*it)->getTypeId().isDerivedFrom(mesh) ||
(*it)->getTypeId().isDerivedFrom(shape)) {
Gui::ViewProvider* view = gui->getViewProvider(*it);
QIcon px = view->getIcon();
SingleSelectionItem* item1 = new SingleSelectionItem(ui->treeWidgetActual);
item1->setText(0, QString::fromUtf8((*it)->Label.getValue()));
item1->setData(0, Qt::UserRole, QString::fromAscii((*it)->getNameInDocument()));
item1->setCheckState(0, Qt::Unchecked);
item1->setIcon(0, px);
SingleSelectionItem* item2 = new SingleSelectionItem(ui->treeWidgetNominal);
item2->setText(0, QString::fromUtf8((*it)->Label.getValue()));
item2->setData(0, Qt::UserRole, QString::fromAscii((*it)->getNameInDocument()));
item2->setCheckState(0, Qt::Unchecked);
item2->setIcon(0, px);
item1->setCompetitiveItem(item2);
item2->setCompetitiveItem(item1);
}
}
loadSettings();
}
示例3: search
void SelectionView::search(QString text)
{
if (!text.isEmpty()) {
App::Document* doc = App::GetApplication().getActiveDocument();
std::vector<App::DocumentObject*> objects;
if (doc) {
Gui::Selection().clearSelection();
objects = doc->getObjects();
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it) {
QString label = QString::fromUtf8((*it)->Label.getValue());
if (label.contains(text,Qt::CaseInsensitive)) {
if (!Gui::Selection().hasSelection((*it)->getNameInDocument())) {
Gui::Selection().addSelection(doc->getName(),(*it)->getNameInDocument(),0);
}
}
}
}
}
}
示例4: activated
void CmdPartDesignMigrate::activated(int iMsg)
{
Q_UNUSED(iMsg);
App::Document *doc = getDocument();
std::set<PartDesign::Feature*> migrateFeatures;
// Retrive all PartDesign Features objects and filter out features already belongs to some body
for ( const auto & feat: doc->getObjects( ) ) {
if( feat->isDerivedFrom( PartDesign::Feature::getClassTypeId() ) &&
!PartDesign::Body::findBodyOf( feat ) && PartDesign::Body::isSolidFeature ( feat ) ) {
migrateFeatures.insert ( static_cast <PartDesign::Feature *>( feat ) );
}
}
if ( migrateFeatures.empty() ) {
if ( !PartDesignGui::isModernWorkflow ( doc ) ) {
// If there is nothing to migrate and workflow is still old just set it to modern
PartDesignGui::WorkflowManager::instance()->forceWorkflow (
doc, PartDesignGui::Workflow::Modern );
} else {
// Huh? nothing to migrate?
QMessageBox::warning ( 0, QObject::tr ( "Nothing to migrate" ),
QObject::tr ( "No PartDesign features which doesn't belong to a body found."
" Nothing to migrate." ) );
}
return;
}
// Note: this action is undoable, should it be?
PartDesignGui::WorkflowManager::instance()->forceWorkflow ( doc, PartDesignGui::Workflow::Modern );
// Put features into chains. Each chain should become a separate body.
std::list< std::list<PartDesign::Feature *> > featureChains;
std::list<PartDesign::Feature *> chain; //< the current chain we are working on
for (auto featIt = migrateFeatures.begin(); !migrateFeatures.empty(); ) {
Part::Feature *base = (*featIt)->getBaseObject( /*silent =*/ true );
chain.push_front ( *featIt );
if ( !base || !base->isDerivedFrom (PartDesign::Feature::getClassTypeId () ) ||
PartDesignGui::isAnyNonPartDesignLinksTo ( static_cast <PartDesign::Feature *>(base),
/*respectGroups=*/ true ) ) {
// a feature based on nothing as well as on non-partdesign solid starts a new chain
auto newChainIt = featureChains.emplace (featureChains.end());
newChainIt->splice (newChainIt->end(), chain);
} else {
// we are basing on some partdesign feature which supposed to belong to some body
PartDesign::Feature *baseFeat = static_cast <PartDesign::Feature *>( base );
auto baseFeatSetIt = find ( migrateFeatures.begin (), migrateFeatures.end (), baseFeat );
if ( baseFeatSetIt != migrateFeatures.end() ) {
// base feature is pending for migration, switch to it and continue over
migrateFeatures.erase(featIt);
featIt = baseFeatSetIt;
continue;
} else {
// The base feature seems already assigned to some chain
// Find which
std::list<PartDesign::Feature *>::iterator baseFeatIt;
auto chainIt = std::find_if( featureChains.begin(), featureChains.end(),
[baseFeat, &baseFeatIt] ( std::list<PartDesign::Feature *>&chain ) mutable -> bool {
baseFeatIt = std::find( chain.begin(), chain.end(), baseFeat );
return baseFeatIt != chain.end();
} );
if ( chainIt != featureChains.end() ) {
assert (baseFeatIt != chainIt->end());
if ( std::next ( baseFeatIt ) == chainIt->end() ) {
// just append our chain to already found
chainIt->splice ( chainIt->end(), chain );
// TODO If we will hit a third part everything will be messed up again.
// Probably it will require a yet another smart-ass find_if. (2015-08-10, Fat-Zer)
} else {
// We have a fork of a partDesign feature here
// add a chain for current body
auto newChainIt = featureChains.emplace (featureChains.end());
newChainIt->splice (newChainIt->end(), chain);
// add a chain for forked one
newChainIt = featureChains.emplace (featureChains.end());
newChainIt->splice (newChainIt->end(), *chainIt,
std::next ( baseFeatIt ), chainIt->end());
}
} else {
// The feature is not present in list pending for migration,
// This generally shouldn't happen but may be if we run into some broken file
// Try to find out the body we should insert into
// TODO Some error/warning is needed here (2015-08-10, Fat-Zer)
auto newChainIt = featureChains.emplace (featureChains.end());
newChainIt->splice (newChainIt->end(), chain);
}
}
}
migrateFeatures.erase ( featIt );
featIt = migrateFeatures.begin ();
// TODO Align visibility (2015-08-17, Fat-Zer)
} /* for */
//.........这里部分代码省略.........
示例5: module
//.........这里部分代码省略.........
union PyType_Object typeobj = {&Base::PyObjectBase::Type};
union PyType_Object typedoc = {&App::DocumentObjectPy::Type};
union PyType_Object basetype = {&PyBaseObject_Type};
if (PyObject_IsSubclass(type.ptr(), typedoc.o) == 1) {
// From the template Python object we don't query its type object because there we keep
// a list of additional methods that we won't see otherwise. But to get the correct doc
// strings we query the type's dict in the class itself.
// To see if we have a template Python object we check for the existence of supportedProperties
if (!type.hasAttr("supportedProperties")) {
obj = type;
}
}
else if (PyObject_IsSubclass(type.ptr(), typeobj.o) == 1) {
obj = type;
}
else if (PyInstance_Check(obj.ptr())) {
// instances of old style classes
PyInstanceObject* inst = reinterpret_cast<PyInstanceObject*>(obj.ptr());
PyObject* classobj = reinterpret_cast<PyObject*>(inst->in_class);
obj = Py::Object(classobj);
}
else if (PyObject_IsInstance(obj.ptr(), basetype.o) == 1) {
// New style class which can be a module, type, list, tuple, int, float, ...
// Make sure it's not a type objec
union PyType_Object typetype = {&PyType_Type};
if (PyObject_IsInstance(obj.ptr(), typetype.o) != 1) {
// this should be now a user-defined Python class
// http://stackoverflow.com/questions/12233103/in-python-at-runtime-determine-if-an-object-is-a-class-old-and-new-type-instan
if (Py_TYPE(obj.ptr())->tp_flags & Py_TPFLAGS_HEAPTYPE) {
obj = type;
}
}
}
// If we have an instance of PyObjectBase then determine whether it's valid or not
if (PyObject_IsInstance(inst.ptr(), typeobj.o) == 1) {
Base::PyObjectBase* baseobj = static_cast<Base::PyObjectBase*>(inst.ptr());
const_cast<CallTipsList*>(this)->validObject = baseobj->isValid();
}
else {
// PyObject_IsInstance might set an exception
PyErr_Clear();
}
Py::List list(obj.dir());
// If we derive from PropertyContainerPy we can search for the properties in the
// C++ twin class.
union PyType_Object proptypeobj = {&App::PropertyContainerPy::Type};
if (PyObject_IsSubclass(type.ptr(), proptypeobj.o) == 1) {
// These are the attributes of the instance itself which are NOT accessible by
// its type object
extractTipsFromProperties(inst, tips);
}
// If we derive from App::DocumentPy we have direct access to the objects by their internal
// names. So, we add these names to the list, too.
union PyType_Object appdoctypeobj = {&App::DocumentPy::Type};
if (PyObject_IsSubclass(type.ptr(), appdoctypeobj.o) == 1) {
App::DocumentPy* docpy = (App::DocumentPy*)(inst.ptr());
App::Document* document = docpy->getDocumentPtr();
// Make sure that the C++ object is alive
if (document) {
std::vector<App::DocumentObject*> objects = document->getObjects();
Py::List list;
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it)
list.append(Py::String((*it)->getNameInDocument()));
extractTipsFromObject(inst, list, tips);
}
}
// If we derive from Gui::DocumentPy we have direct access to the objects by their internal
// names. So, we add these names to the list, too.
union PyType_Object guidoctypeobj = {&Gui::DocumentPy::Type};
if (PyObject_IsSubclass(type.ptr(), guidoctypeobj.o) == 1) {
Gui::DocumentPy* docpy = (Gui::DocumentPy*)(inst.ptr());
if (docpy->getDocumentPtr()) {
App::Document* document = docpy->getDocumentPtr()->getDocument();
// Make sure that the C++ object is alive
if (document) {
std::vector<App::DocumentObject*> objects = document->getObjects();
Py::List list;
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it)
list.append(Py::String((*it)->getNameInDocument()));
extractTipsFromObject(inst, list, tips);
}
}
}
// These are the attributes from the type object
extractTipsFromObject(obj, list, tips);
}
catch (Py::Exception& e) {
// Just clear the Python exception
e.clear();
}
return tips;
}
示例6: module
QMap<QString, CallTip> CallTipsList::extractTips(const QString& context) const
{
Base::PyGILStateLocker lock;
QMap<QString, CallTip> tips;
if (context.isEmpty())
return tips;
try {
QStringList items = context.split(QLatin1Char('.'));
Py::Module module("__main__");
Py::Dict dict = module.getDict();
QString modname = items.front();
items.pop_front();
if (!dict.hasKey(std::string(modname.toAscii())))
return tips; // unknown object
// get the Python object we need
Py::Object obj = dict.getItem(std::string(modname.toAscii()));
while (!items.isEmpty()) {
QByteArray name = items.front().toAscii();
std::string attr = name.constData();
items.pop_front();
if (obj.hasAttr(attr))
obj = obj.getAttr(attr);
else
return tips;
}
// Checks whether the type is a subclass of PyObjectBase because to get the doc string
// of a member we must get it by its type instead of its instance otherwise we get the
// wrong string, namely that of the type of the member.
// Note: 3rd party libraries may use their own type object classes so that we cannot
// reliably use Py::Type. To be on the safe side we should use Py::Object to assign
// the used type object to.
//Py::Object type = obj.type();
Py::Object type(PyObject_Type(obj.ptr()), true);
Py::Object inst = obj; // the object instance
union PyType_Object typeobj = {&Base::PyObjectBase::Type};
union PyType_Object typedoc = {&App::DocumentObjectPy::Type};
if (PyObject_IsSubclass(type.ptr(), typedoc.o) == 1) {
// From the template Python object we don't query its type object because there we keep
// a list of additional methods that we won't see otherwise. But to get the correct doc
// strings we query the type's dict in the class itself.
// To see if we have a template Python object we check for the existence of supportedProperties
if (!type.hasAttr("supportedProperties")) {
obj = type;
}
}
else if (PyObject_IsSubclass(type.ptr(), typeobj.o) == 1) {
obj = type;
}
// If we have an instance of PyObjectBase then determine whether it's valid or not
if (PyObject_IsInstance(inst.ptr(), typeobj.o) == 1) {
Base::PyObjectBase* baseobj = static_cast<Base::PyObjectBase*>(inst.ptr());
const_cast<CallTipsList*>(this)->validObject = baseobj->isValid();
}
else {
// PyObject_IsInstance might set an exception
PyErr_Clear();
}
Py::List list(PyObject_Dir(obj.ptr()), true);
// If we derive from PropertyContainerPy we can search for the properties in the
// C++ twin class.
union PyType_Object proptypeobj = {&App::PropertyContainerPy::Type};
if (PyObject_IsSubclass(type.ptr(), proptypeobj.o) == 1) {
// These are the attributes of the instance itself which are NOT accessible by
// its type object
extractTipsFromProperties(inst, tips);
}
// If we derive from App::DocumentPy we have direct access to the objects by their internal
// names. So, we add these names to the list, too.
union PyType_Object appdoctypeobj = {&App::DocumentPy::Type};
if (PyObject_IsSubclass(type.ptr(), appdoctypeobj.o) == 1) {
App::DocumentPy* docpy = (App::DocumentPy*)(inst.ptr());
App::Document* document = docpy->getDocumentPtr();
// Make sure that the C++ object is alive
if (document) {
std::vector<App::DocumentObject*> objects = document->getObjects();
Py::List list;
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it)
list.append(Py::String((*it)->getNameInDocument()));
extractTipsFromObject(inst, list, tips);
}
}
// If we derive from Gui::DocumentPy we have direct access to the objects by their internal
// names. So, we add these names to the list, too.
union PyType_Object guidoctypeobj = {&Gui::DocumentPy::Type};
if (PyObject_IsSubclass(type.ptr(), guidoctypeobj.o) == 1) {
Gui::DocumentPy* docpy = (Gui::DocumentPy*)(inst.ptr());
if (docpy->getDocumentPtr()) {
App::Document* document = docpy->getDocumentPtr()->getDocument();
// Make sure that the C++ object is alive
if (document) {
std::vector<App::DocumentObject*> objects = document->getObjects();
Py::List list;
//.........这里部分代码省略.........