void SweepWidget::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc); if (!activeGui) return; d->document = activeDoc->getName(); std::vector<Part::Feature*> objs = activeDoc->getObjectsOfType<Part::Feature>(); for (std::vector<Part::Feature*>::iterator it = objs.begin(); it!=objs.end(); ++it) { const TopoDS_Shape& shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; if (shape.ShapeType() == TopAbs_FACE || shape.ShapeType() == TopAbs_WIRE || shape.ShapeType() == TopAbs_EDGE || shape.ShapeType() == TopAbs_VERTEX) { QString label = QString::fromUtf8((*it)->Label.getValue()); QString name = QString::fromAscii((*it)->getNameInDocument()); QTreeWidgetItem* child = new QTreeWidgetItem(); child->setText(0, label); child->setToolTip(0, label); child->setData(0, Qt::UserRole, name); Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) child->setIcon(0, vp->getIcon()); d->ui.selector->availableTreeWidget()->addTopLevelItem(child); } } }
void applyColors(Part::Feature* part, const std::vector<App::Color>& colors) { Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(part); if (vp && vp->isDerivedFrom(PartGui::ViewProviderPartExt::getClassTypeId())) { static_cast<PartGui::ViewProviderPartExt*>(vp)->DiffuseColor.setValues(colors); } }
void Document::addRootObjectsToGroup(const std::vector<App::DocumentObject*>& obj, App::DocumentObjectGroup* grp) { std::map<App::DocumentObject*, bool> rootMap; for (std::vector<App::DocumentObject*>::const_iterator it = obj.begin(); it != obj.end(); ++it) { rootMap[*it] = true; } // get the view providers and check which objects are children for (std::vector<App::DocumentObject*>::const_iterator it = obj.begin(); it != obj.end(); ++it) { Gui::ViewProvider* vp = getViewProvider(*it); if (vp) { std::vector<App::DocumentObject*> child = vp->claimChildren(); for (std::vector<App::DocumentObject*>::iterator jt = child.begin(); jt != child.end(); ++jt) { std::map<App::DocumentObject*, bool>::iterator kt = rootMap.find(*jt); if (kt != rootMap.end()) { kt->second = false; } } } } // all objects that are not children of other objects can be added to the group for (std::map<App::DocumentObject*, bool>::iterator it = rootMap.begin(); it != rootMap.end(); ++it) { if (it->second) grp->addObject(it->first); } }
void Placement::applyPlacement(const Base::Placement& p, bool incremental) { Gui::Document* document = Application::Instance->activeDocument(); if (!document) return; std::vector<App::DocumentObject*> sel = Gui::Selection().getObjectsOfType (App::DocumentObject::getClassTypeId(), document->getDocument()->getName()); if (!sel.empty()) { // apply transformation only on view matrix not on placement property for (std::vector<App::DocumentObject*>::iterator it=sel.begin();it!=sel.end();++it) { std::map<std::string,App::Property*> props; (*it)->getPropertyMap(props); // search for the placement property std::map<std::string,App::Property*>::iterator jt; jt = std::find_if(props.begin(), props.end(), find_placement(this->propertyName)); if (jt != props.end()) { Base::Placement cur = static_cast<App::PropertyPlacement*>(jt->second)->getValue(); if (incremental) cur = p * cur; else cur = p; Gui::ViewProvider* vp = document->getViewProvider(*it); if (vp) vp->setTransformation(cur.toMatrix()); } } } else { Base::Console().Warning("No object selected.\n"); } }
void DlgRevolution::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); if (!activeDoc) return; Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc); std::vector<App::DocumentObject*> objs = activeDoc->getObjectsOfType (Part::Feature::getClassTypeId()); for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it!=objs.end(); ++it) { const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue(); if (shape.IsNull()) continue; TopExp_Explorer xp; xp.Init(shape,TopAbs_SOLID); if (xp.More()) continue; // solids not allowed xp.Init(shape,TopAbs_COMPSOLID); if (xp.More()) continue; // compound solids not allowed // So allowed are: vertex, edge, wire, face, shell and compound QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget); item->setText(0, QString::fromUtf8((*it)->Label.getValue())); item->setData(0, Qt::UserRole, QString::fromAscii((*it)->getNameInDocument())); Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) item->setIcon(0, vp->getIcon()); } }
void TransformStrategy::acceptDataTransform(const Base::Matrix4D& mat, App::DocumentObject* obj) { Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument()); std::map<std::string,App::Property*> props; obj->getPropertyMap(props); // search for the placement property std::map<std::string,App::Property*>::iterator jt; jt = std::find_if(props.begin(), props.end(), find_transform()); if (jt != props.end()) { Base::Placement local = static_cast<App::PropertyPlacement*>(jt->second)->getValue(); Gui::ViewProvider* vp = doc->getViewProvider(obj); if (vp) vp->setTransformation(local.toMatrix()); } else { // No placement found Gui::ViewProvider* vp = doc->getViewProvider(obj); if (vp) vp->setTransformation(Base::Matrix4D()); } // Apply the transformation jt = std::find_if(props.begin(), props.end(), find_geometry_data()); if (jt != props.end()) { static_cast<App::PropertyGeometry*>(jt->second)->transformGeometry(mat); } }
std::vector<App::DocumentObject*> ViewProviderBody::claimChildren(void)const { PartDesign::Body* body= static_cast<PartDesign::Body*> ( getObject () ); const std::vector<App::DocumentObject*> &model = body->Model.getValues (); std::set<App::DocumentObject*> outSet; //< set of objects not to claim (childrens of childrens) // search for objects handled (claimed) by the features for( auto obj: model){ if (!obj) { continue; } Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider ( obj ); if (!vp) { continue; } auto children = vp->claimChildren(); std::remove_copy ( children.begin (), children.end (), std::inserter (outSet, outSet.begin () ), nullptr); } // remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct std::vector<App::DocumentObject*> Result; if (body->Origin.getValue()) { // Clame for the Origin Result.push_back (body->Origin.getValue()); } if (body->BaseFeature.getValue()) { // Clame for the base feature Result.push_back (body->BaseFeature.getValue()); } // claim for rest content not claimed by any other features std::remove_copy_if (model.begin(), model.end(), std::back_inserter (Result), [outSet] (App::DocumentObject* obj) { return outSet.find (obj) != outSet.end(); } ); return Result; }
void PropertyEnumAttacherItem::openTask() { Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog(); TaskDlgAttacher* task; task = qobject_cast<TaskDlgAttacher*>(dlg); if (dlg && !task) { // there is already another task dialog which must be closed first Gui::Control().showDialog(dlg); return; } if (!task) { const App::Property* prop = getFirstProperty(); if (prop) { App::PropertyContainer* parent = prop->getContainer(); if (parent->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) { App::DocumentObject* obj = static_cast<App::DocumentObject*>(parent); Gui::ViewProvider* view = Gui::Application::Instance->getViewProvider(obj); if (view->getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) { task = new TaskDlgAttacher(static_cast<Gui::ViewProviderDocumentObject*>(view)); } } } if (!task) { return; } } Gui::Control().showDialog(task); }
void Mirroring::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); if (!activeDoc) return; Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc); if (!activeGui) return; this->document = QString::fromLatin1(activeDoc->getName()); std::vector<App::DocumentObject*> objs = activeDoc->getObjectsOfType (Part::Feature::getClassTypeId()); for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it!=objs.end(); ++it) { const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue(); if (!shape.IsNull()) { QString label = QString::fromUtf8((*it)->Label.getValue()); QString name = QString::fromLatin1((*it)->getNameInDocument()); QTreeWidgetItem* child = new QTreeWidgetItem(); child->setText(0, label); child->setToolTip(0, label); child->setData(0, Qt::UserRole, name); Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) child->setIcon(0, vp->getIcon()); ui->shapes->addTopLevelItem(child); } } }
void DlgFilletEdges::setupFillet(const std::vector<App::DocumentObject*>& objs) { App::DocumentObject* base = d->fillet->Base.getValue(); const std::vector<Part::FilletElement>& e = d->fillet->Edges.getValues(); std::vector<App::DocumentObject*>::const_iterator it = std::find(objs.begin(), objs.end(), base); if (it != objs.end()) { // toggle visibility Gui::ViewProvider* vp; vp = Gui::Application::Instance->getViewProvider(d->fillet); if (vp) vp->hide(); vp = Gui::Application::Instance->getViewProvider(base); if (vp) vp->show(); int current_index = (it - objs.begin()) + 1; ui->shapeObject->setCurrentIndex(current_index); on_shapeObject_activated(current_index); ui->shapeObject->setEnabled(false); QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView->model()); for (std::vector<Part::FilletElement>::const_iterator et = e.begin(); et != e.end(); ++et) { std::vector<int>::iterator it = std::find(d->edge_ids.begin(), d->edge_ids.end(), et->edgeid); if (it != d->edge_ids.end()) { int index = it - d->edge_ids.begin(); model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole); model->setData(model->index(index, 1), QVariant(QLocale::system().toString(et->radius1,'f',2))); model->setData(model->index(index, 2), QVariant(QLocale::system().toString(et->radius2,'f',2))); } } } }
void Tessellation::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); if (!activeDoc) return; Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc); if (!activeGui) return; this->document = QString::fromAscii(activeDoc->getName()); std::vector<Part::Feature*> objs = activeDoc->getObjectsOfType<Part::Feature>(); for (std::vector<Part::Feature*>::iterator it = objs.begin(); it!=objs.end(); ++it) { const TopoDS_Shape& shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; bool hasfaces = false; TopExp_Explorer xp(shape,TopAbs_FACE); while (xp.More()) { hasfaces = true; break; } if (hasfaces) { QString label = QString::fromUtf8((*it)->Label.getValue()); QString name = QString::fromAscii((*it)->getNameInDocument()); QTreeWidgetItem* child = new QTreeWidgetItem(); child->setText(0, label); child->setToolTip(0, label); child->setData(0, Qt::UserRole, name); Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) child->setIcon(0, vp->getIcon()); ui->treeWidget->addTopLevelItem(child); } } }
/** * 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(); }
void SketcherValidation::hidePoints() { if (coincidenceRoot) { Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(sketch); vp->getRoot()->removeChild(coincidenceRoot); coincidenceRoot = 0; } }
void StdCmdDuplicateSelection::activated(int iMsg) { App::Document* act = App::GetApplication().getActiveDocument(); if (!act) return; // no active document found Gui::Document* doc = Gui::Application::Instance->getDocument(act); std::vector<Gui::SelectionSingleton::SelObj> sel = Gui::Selection().getCompleteSelection(); for (std::vector<SelectionSingleton::SelObj>::iterator it = sel.begin(); it != sel.end(); ++it) { if (!it->pObject) continue; // should actually not happen // create a copy of the object App::DocumentObject* copy = act->copyObject(it->pObject, false); if (!copy) // continue if no copy could be created continue; // mark all properties of the copy as "touched" which are touched in the original object std::map<std::string,App::Property*> props; it->pObject->getPropertyMap(props); std::map<std::string,App::Property*> copy_props; copy->getPropertyMap(copy_props); for (std::map<std::string,App::Property*>::iterator jt = props.begin(); jt != props.end(); ++jt) { if (jt->second->isTouched()) { std::map<std::string,App::Property*>::iterator kt; kt = copy_props.find(jt->first); if (kt != copy_props.end()) { kt->second->touch(); } } } Gui::Document* parent = Gui::Application::Instance->getDocument(it->pObject->getDocument()); if (!parent || !doc) continue; // should not happen // copy the properties of the associated view providers Gui::ViewProvider* view = parent->getViewProvider(it->pObject); Gui::ViewProvider* copy_view = doc->getViewProvider(copy); copy_view->addDynamicProperties(view); if (!view || !copy_view) continue; // should not happen // get the properties of the view provider props.clear(); view->getPropertyMap(props); copy_props.clear(); copy_view->getPropertyMap(copy_props); for (std::map<std::string,App::Property*>::iterator jt = props.begin(); jt != props.end(); ++jt) { std::map<std::string,App::Property*>::iterator kt; kt = copy_props.find(jt->first); if (kt != copy_props.end()) { std::auto_ptr<App::Property> data(jt->second->Copy()); if (data.get()) { kt->second->Paste(*data); } } } } }
void CmdRaytracingWriteView::activated(int iMsg) { const char* ppReturn=0; Gui::Application::Instance->sendMsgToActiveView("GetCamera",&ppReturn); if (ppReturn) { std::string str(ppReturn); if (str.find("PerspectiveCamera") == std::string::npos) { int ret = QMessageBox::warning(Gui::getMainWindow(), qApp->translate("CmdRaytracingWriteView","No perspective camera"), qApp->translate("CmdRaytracingWriteView","The current view camera is not perspective" " and thus the result of the povray image later might look different to" " what you expect.\nDo you want to continue?"), QMessageBox::Yes|QMessageBox::No); if (ret != QMessageBox::Yes) return; } } QStringList filter; filter << QObject::tr("Povray(*.pov)"); filter << QObject::tr("All Files (*.*)"); QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(), QObject::tr("Export page"), QString(), filter.join(QLatin1String(";;"))); if (fn.isEmpty()) return; std::string cFullName = (const char*)fn.toUtf8(); // get all objects of the active document std::vector<Part::Feature*> DocObjects = getActiveGuiDocument()->getDocument()-> getObjectsOfType<Part::Feature>(); openCommand("Write view"); doCommand(Doc,"import Raytracing,RaytracingGui"); doCommand(Doc,"OutFile = open(unicode('%s','utf-8'),'w')",cFullName.c_str()); doCommand(Doc,"OutFile.write(open(App.getResourceDir()+'Mod/Raytracing/Templates/ProjectStd.pov').read())"); doCommand(Doc,"OutFile.write(RaytracingGui.povViewCamera())"); // go through all document objects for (std::vector<Part::Feature*>::const_iterator it=DocObjects.begin();it!=DocObjects.end();++it) { Gui::ViewProvider* vp = getActiveGuiDocument()->getViewProvider(*it); if (vp && vp->isVisible()) { App::PropertyColor *pcColor = dynamic_cast<App::PropertyColor *>(vp->getPropertyByName("ShapeColor")); App::Color col = pcColor->getValue(); doCommand(Doc,"OutFile.write(Raytracing.getPartAsPovray('%s',App.activeDocument().%s.Shape,%f,%f,%f))", (*it)->getNameInDocument(),(*it)->getNameInDocument(),col.r,col.g,col.b); } } doCommand(Doc,"OutFile.close()"); doCommand(Doc,"del OutFile"); updateActive(); commitCommand(); }
void MergeDocuments::importObject(const std::vector<App::DocumentObject*>& o, Base::XMLReader & r) { objects = o; for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it) { Gui::ViewProvider* vp = document->getViewProvider(*it); if (vp) vp->hide(); } Restore(r); r.readFiles(*this->stream); }
std::list<ViewProviderMesh*> MeshSelection::getViewProviders() const { std::vector<App::DocumentObject*> objs = getObjects(); std::list<ViewProviderMesh*> vps; for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it != objs.end(); ++it) { if ((*it)->isDerivedFrom(Mesh::Feature::getClassTypeId())) { Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(*it); if (vp->isVisible()) vps.push_back(static_cast<ViewProviderMesh*>(vp)); } } return vps; }
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(); }
void Tessellation::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); if (!activeDoc) return; Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc); if (!activeGui) return; this->document = QString::fromAscii(activeDoc->getName()); std::vector<Part::Feature*> objs = activeDoc->getObjectsOfType<Part::Feature>(); double edgeLen = 0; bool foundSelection = false; for (std::vector<Part::Feature*>::iterator it = objs.begin(); it!=objs.end(); ++it) { const TopoDS_Shape& shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; bool hasfaces = false; TopExp_Explorer xp(shape,TopAbs_FACE); while (xp.More()) { hasfaces = true; break; } if (hasfaces) { Base::BoundBox3d bbox = (*it)->Shape.getBoundingBox(); edgeLen = std::max<double>(edgeLen, bbox.LengthX()); edgeLen = std::max<double>(edgeLen, bbox.LengthY()); edgeLen = std::max<double>(edgeLen, bbox.LengthZ()); QString label = QString::fromUtf8((*it)->Label.getValue()); QString name = QString::fromAscii((*it)->getNameInDocument()); QTreeWidgetItem* child = new QTreeWidgetItem(); child->setText(0, label); child->setToolTip(0, label); child->setData(0, Qt::UserRole, name); Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) child->setIcon(0, vp->getIcon()); ui->treeWidget->addTopLevelItem(child); if (Gui::Selection().isSelected(*it)) { child->setSelected(true); foundSelection = true; } } } ui->spinMaximumEdgeLength->setValue(edgeLen/10); if (foundSelection) ui->treeWidget->hide(); }
void MeshSelection::pickFaceCallback(void * ud, SoEventCallback * n) { // handle only mouse button events if (n->getEvent()->isOfType(SoMouseButtonEvent::getClassTypeId())) { const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent*>(n->getEvent()); Gui::View3DInventorViewer* view = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData()); // Mark all incoming mouse button events as handled, especially, to deactivate the selection node n->getAction()->setHandled(); if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { const SoPickedPoint * point = n->getPickedPoint(); if (point == NULL) { Base::Console().Message("No facet picked.\n"); return; } n->setHandled(); // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is // really from the mesh we render and not from any other geometry Gui::ViewProvider* vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath())); if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) return; ViewProviderMesh* mesh = static_cast<ViewProviderMesh*>(vp); MeshSelection* self = reinterpret_cast<MeshSelection*>(ud); std::list<ViewProviderMesh*> views = self->getViewProviders(); if (std::find(views.begin(), views.end(), mesh) == views.end()) return; const SoDetail* detail = point->getDetail(/*mesh->getShapeNode()*/); if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) { // get the boundary to the picked facet unsigned long uFacet = static_cast<const SoFaceDetail*>(detail)->getFaceIndex(); if (self->addToSelection) { if (self->addComponent) mesh->selectComponent(uFacet); else mesh->selectFacet(uFacet); } else { if (self->removeComponent) mesh->deselectComponent(uFacet); else mesh->deselectFacet(uFacet); } } } } }
void ViewProviderPythonFeatureObserver::slotAppendObject(const Gui::ViewProvider& obj) { if (!obj.isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) return; const Gui::ViewProviderDocumentObject& vp = static_cast<const Gui::ViewProviderDocumentObject&>(obj); const App::DocumentObject* docobj = vp.getObject(); App::Document* doc = docobj->getDocument(); std::map<const App::Document*, ObjectProxy>::iterator it = proxyMap.find(doc); if (it != proxyMap.end()) { ObjectProxy::iterator jt = it->second.find(docobj); if (jt != it->second.end()) { Base::PyGILStateLocker lock; try { App::Property* prop = vp.getPropertyByName("Proxy"); if (prop && prop->isDerivedFrom(App::PropertyPythonObject::getClassTypeId())) { static_cast<App::PropertyPythonObject*>(prop)->fromString(jt->second); static_cast<App::PropertyPythonObject*>(prop)->touch(); it->second.erase(jt); } } catch (Py::Exception& e) { e.clear(); } } // all cached objects of the documents are already destroyed else { it->second.clear(); } } }
QIcon ViewProviderInspection::getIcon() const { // Get the icon of the view provider to the associated feature QIcon px = inherited::getIcon(); App::Property* pActual = pcObject->getPropertyByName("Actual"); if (pActual && pActual->getTypeId().isDerivedFrom( App::PropertyLink::getClassTypeId())) { App::DocumentObject* docobj = ((App::PropertyLink*)pActual)->getValue(); if (docobj) { Gui::Document* doc = Gui::Application::Instance->getDocument(docobj->getDocument()); Gui::ViewProvider* view = doc->getViewProvider(docobj); px = view->getIcon(); } } return px; }
void ViewProviderPythonFeatureObserver::slotAppendObject(const Gui::ViewProvider& obj) { if (!obj.isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) return; const Gui::ViewProviderDocumentObject& vp = static_cast<const Gui::ViewProviderDocumentObject&>(obj); const App::DocumentObject* docobj = vp.getObject(); App::Document* doc = docobj->getDocument(); std::map<const App::Document*, ObjectProxy>::iterator it = proxyMap.find(doc); if (it != proxyMap.end()) { ObjectProxy::iterator jt = it->second.find(docobj); if (jt != it->second.end()) { Base::PyGILStateLocker lock; try { App::Property* prop = vp.getPropertyByName("Proxy"); if (prop && prop->isDerivedFrom(App::PropertyPythonObject::getClassTypeId())) { // make this delayed so that the corresponding item in the tree view is accessible QApplication::postEvent(this, new PropertyEvent(prop, jt->second)); it->second.erase(jt); } } catch (Py::Exception& e) { e.clear(); } } // all cached objects of the documents are already destroyed else { it->second.clear(); } } }
void DrawingView::closeEvent(QCloseEvent* ev) { MDIView::closeEvent(ev); if (!ev->isAccepted()) return; // when closing the view from GUI notify the view provider to mark it invisible if (_pcDocument && !m_objectName.empty()) { App::Document* doc = _pcDocument->getDocument(); if (doc) { App::DocumentObject* obj = doc->getObject(m_objectName.c_str()); Gui::ViewProvider* vp = _pcDocument->getViewProvider(obj); if (vp) vp->hide(); } } }
void TaskLinkDim::loadToTree(const TechDraw::DrawViewDimension* dim, const bool selected, Gui::Document* guiDoc) { QString label = QString::fromUtf8(dim->Label.getValue()); QString name = QString::fromUtf8(dim->getNameInDocument()); QString tooltip = label + QString::fromUtf8(" / ") + name; QTreeWidgetItem* child = new QTreeWidgetItem(); child->setText(0, label); child->setToolTip(0, tooltip); child->setData(0, Qt::UserRole, name); Gui::ViewProvider* vp = guiDoc->getViewProvider(dim); if (vp) child->setIcon(0, vp->getIcon()); if (selected) { ui->selector->selectedTreeWidget()->addTopLevelItem(child); } else { ui->selector->availableTreeWidget()->addTopLevelItem(child); } }
void SweepWidget::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc); if (!activeGui) return; d->document = activeDoc->getName(); std::vector<Part::Feature*> objs = activeDoc->getObjectsOfType<Part::Feature>(); for (std::vector<Part::Feature*>::iterator it = objs.begin(); it!=objs.end(); ++it) { TopoDS_Shape shape = (*it)->Shape.getValue(); if (shape.IsNull()) continue; // also allow compounds with a single face, wire, edge or vertex if (shape.ShapeType() == TopAbs_COMPOUND) { TopoDS_Iterator it(shape); int numChilds=0; TopoDS_Shape child; for (; it.More(); it.Next(), numChilds++) { if (!it.Value().IsNull()) child = it.Value(); } if (numChilds == 1) shape = child; } if (shape.ShapeType() == TopAbs_FACE || shape.ShapeType() == TopAbs_WIRE || shape.ShapeType() == TopAbs_EDGE || shape.ShapeType() == TopAbs_VERTEX) { QString label = QString::fromUtf8((*it)->Label.getValue()); QString name = QString::fromLatin1((*it)->getNameInDocument()); QTreeWidgetItem* child = new QTreeWidgetItem(); child->setText(0, label); child->setToolTip(0, label); child->setData(0, Qt::UserRole, name); Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) child->setIcon(0, vp->getIcon()); d->ui.selector->availableTreeWidget()->addTopLevelItem(child); } } }
void Document::importObjects(const std::vector<App::DocumentObject*>& obj, Base::Reader& reader, const std::map<std::string, std::string>& nameMapping) { // We must create an XML parser to read from the input stream Base::XMLReader xmlReader("GuiDocument.xml", reader); xmlReader.readElement("Document"); long scheme = xmlReader.getAttributeAsInteger("SchemaVersion"); // At this stage all the document objects and their associated view providers exist. // Now we must restore the properties of the view providers only. // // SchemeVersion "1" if (scheme == 1) { // read the viewproviders itself xmlReader.readElement("ViewProviderData"); int Cnt = xmlReader.getAttributeAsInteger("Count"); std::vector<App::DocumentObject*>::const_iterator it = obj.begin(); for (int i=0;i<Cnt&&it!=obj.end();++i,++it) { // The stored name usually doesn't match with the current name anymore // thus we try to match by type. This should work because the order of // objects should not have changed xmlReader.readElement("ViewProvider"); std::string name = xmlReader.getAttribute("name"); std::map<std::string, std::string>::const_iterator jt = nameMapping.find(name); if (jt != nameMapping.end()) name = jt->second; Gui::ViewProvider* pObj = this->getViewProviderByName(name.c_str()); if (pObj) pObj->Restore(xmlReader); xmlReader.readEndElement("ViewProvider"); if (it == obj.end()) break; } xmlReader.readEndElement("ViewProviderData"); } xmlReader.readEndElement("Document"); // In the file GuiDocument.xml new data files might be added if (!xmlReader.getFilenames().empty()) xmlReader.readFiles(static_cast<zipios::ZipInputStream&>(reader.getStream())); }
void TransformStrategy::applyViewTransform(const Base::Placement& plm, App::DocumentObject* obj) { Gui::Document* doc = Gui::Application::Instance->getDocument(obj->getDocument()); std::map<std::string,App::Property*> props; obj->getPropertyMap(props); // search for the placement property std::map<std::string,App::Property*>::iterator jt; jt = std::find_if(props.begin(), props.end(), find_transform()); if (jt != props.end()) { Base::Placement local = static_cast<App::PropertyPlacement*>(jt->second)->getValue(); local *= plm; // in case a placement is already set Gui::ViewProvider* vp = doc->getViewProvider(obj); if (vp) vp->setTransformation(local.toMatrix()); } else { // No placement found, so apply the transformation directly Gui::ViewProvider* vp = doc->getViewProvider(obj); if (vp) vp->setTransformation(plm.toMatrix()); } }
void CmdPointsPolyCut::activated(int iMsg) { std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Points::Feature::getClassTypeId()); for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) { if (it == docObj.begin()) { Gui::Document* doc = getActiveGuiDocument(); Gui::MDIView* view = doc->getActiveView(); if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) { Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer(); viewer->setEditing(true); viewer->startSelection(Gui::View3DInventorViewer::Lasso); viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), PointsGui::ViewProviderPoints::clipPointsCallback); } else { return; } } Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider( *it ); pVP->startEditing(); } }
void DlgExtrusion::findShapes() { App::Document* activeDoc = App::GetApplication().getActiveDocument(); if (!activeDoc) return; Gui::Document* activeGui = Gui::Application::Instance->getDocument(activeDoc); this->document = activeDoc->getName(); this->label = activeDoc->Label.getValue(); std::vector<App::DocumentObject*> objs = activeDoc->getObjectsOfType (Part::Feature::getClassTypeId()); for (std::vector<App::DocumentObject*>::iterator it = objs.begin(); it!=objs.end(); ++it) { const TopoDS_Shape& shape = static_cast<Part::Feature*>(*it)->Shape.getValue(); if (canExtrude(shape)) { QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget); item->setText(0, QString::fromUtf8((*it)->Label.getValue())); item->setData(0, Qt::UserRole, QString::fromLatin1((*it)->getNameInDocument())); Gui::ViewProvider* vp = activeGui->getViewProvider(*it); if (vp) item->setIcon(0, vp->getIcon()); } } }