[TD]ActiveView from different document
This commit is contained in:
@@ -122,15 +122,31 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
QObject::tr("Can not find the main window"));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
App::Document* pageDocument = m_pageFeat->getDocument();
|
||||
std::string documentName = m_pageFeat->getDocument()->getName();
|
||||
Gui::Document* pageGuiDocument = Gui::Application::Instance->getDocument(pageDocument->getName());
|
||||
|
||||
//if the active view is a 3d window, use that.
|
||||
View3DInventor* view3d = qobject_cast<View3DInventor*>(Gui::getMainWindow()->activeWindow());
|
||||
if (!view3d) {
|
||||
//the active window is not a 3D view, so try to find one
|
||||
auto mdiWindows = Gui::getMainWindow()->windows();
|
||||
for (auto& mdi : mdiWindows) {
|
||||
auto mdiView = qobject_cast<View3DInventor*>(mdi);
|
||||
if (mdiView) {
|
||||
view3d = mdiView;
|
||||
break;
|
||||
// active view is not a 3D view, try to find one in the current document
|
||||
auto views3dAll = pageGuiDocument->getMDIViewsOfType(Gui::View3DInventor::getClassTypeId());
|
||||
if (!views3dAll.empty()) {
|
||||
view3d = qobject_cast<View3DInventor*>(views3dAll.front());
|
||||
} else {
|
||||
//this code is only for the rare case where the page's document does not have a
|
||||
//3D window. It might occur if the user closes the 3D window, but leaves, for
|
||||
//example, a DrawPage window open.
|
||||
//the active window is not a 3D view, and the page's document does not have a
|
||||
//3D view, so try to find one somewhere among the open windows.
|
||||
auto mdiWindows = Gui::getMainWindow()->windows();
|
||||
for (auto& mdi : mdiWindows) {
|
||||
auto mdiView = qobject_cast<View3DInventor*>(mdi);
|
||||
if (mdiView) {
|
||||
view3d = mdiView;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,15 +156,20 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//we are sure we have a 3D window!
|
||||
std::string imageName = m_pageFeat->getDocument()->getUniqueObjectName("ActiveView");
|
||||
std::string imageType = "TechDraw::DrawViewImage";
|
||||
|
||||
std::string pageName = m_pageFeat->getNameInDocument();
|
||||
|
||||
Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')",
|
||||
imageType.c_str(),imageName.c_str());
|
||||
Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",
|
||||
pageName.c_str(), imageName.c_str());
|
||||
//the Page's document may not be the active one, so we need to get the right
|
||||
//document by name instead of using ActiveDocument
|
||||
Command::doCommand(Command::Doc,"App.getDocument('%s').addObject('%s','%s')",
|
||||
documentName.c_str(),
|
||||
imageType.c_str(), imageName.c_str());
|
||||
Command::doCommand(Command::Doc,"App.getDocument('%s').%s.addView(App.getDocument('%s').%s)",
|
||||
documentName.c_str(), pageName.c_str(),
|
||||
documentName.c_str(), imageName.c_str());
|
||||
|
||||
App::Document* doc = m_pageFeat->getDocument();
|
||||
std::string special = "/" + imageName + "image.png";
|
||||
@@ -165,7 +186,7 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
QImage image(100, 100, QImage::Format_RGB32); //arbitrary initial image size. quickView will use
|
||||
//MdiView size in pixels
|
||||
image.fill(QColor(Qt::transparent));
|
||||
Grabber3d:: quickView(bg, image);
|
||||
Grabber3d:: quickView(view3d, bg, image);
|
||||
bool success = image.save(Base::Tools::fromStdString(fileSpec));
|
||||
|
||||
if (!success) {
|
||||
@@ -174,9 +195,17 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
//backslashes in windows fileSpec upsets python
|
||||
std::regex rxBackslash("\\\\");
|
||||
std::string noBackslash = std::regex_replace(fileSpec, rxBackslash, "/");
|
||||
Command::doCommand(Command::Doc,"App.activeDocument().%s.ImageFile = '%s'",imageName.c_str(), noBackslash.c_str());
|
||||
Command::doCommand(Command::Doc,"App.activeDocument().%s.Width = %.5f",imageName.c_str(), ui->qsbWidth->rawValue());
|
||||
Command::doCommand(Command::Doc,"App.activeDocument().%s.Height = %.5f",imageName.c_str(), ui->qsbHeight->rawValue());
|
||||
Command::doCommand(Command::Doc,"App.getDocument('%s').%s.ImageFile = '%s'",
|
||||
documentName.c_str(),
|
||||
imageName.c_str(), noBackslash.c_str());
|
||||
Command::doCommand(Command::Doc,"App.getDocument('%s').%s.Width = %.5f",
|
||||
documentName.c_str(),
|
||||
imageName.c_str(),
|
||||
ui->qsbWidth->rawValue());
|
||||
Command::doCommand(Command::Doc,"App.getDocument('%s').%s.Height = %.5f",
|
||||
documentName.c_str(),
|
||||
imageName.c_str(),
|
||||
ui->qsbHeight->rawValue());
|
||||
|
||||
App::DocumentObject* newObj = m_pageFeat->getDocument()->getObject(imageName.c_str());
|
||||
TechDraw::DrawViewImage* newImg = dynamic_cast<TechDraw::DrawViewImage*>(newObj);
|
||||
@@ -193,7 +222,6 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return newImg;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user