[TD]fix wrong error message on load
- also improve temp file name generation
This commit is contained in:
@@ -23,10 +23,10 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <regex>
|
||||
# include <QMessageBox>
|
||||
# include <QPushButton>
|
||||
#endif // #ifndef _PreComp_
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <regex>
|
||||
#endif // #ifndef _PreComp_
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
@@ -41,10 +41,10 @@
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
#include <Mod/TechDraw/App/DrawViewImage.h>
|
||||
|
||||
#include "ui_TaskActiveView.h"
|
||||
#include "TaskActiveView.h"
|
||||
#include "Grabber3d.h"
|
||||
#include "TaskActiveView.h"
|
||||
#include "ViewProviderImage.h"
|
||||
#include "ui_TaskActiveView.h"
|
||||
|
||||
|
||||
using namespace Gui;
|
||||
@@ -52,12 +52,9 @@ using namespace TechDraw;
|
||||
using namespace TechDrawGui;
|
||||
|
||||
//ctor for creation
|
||||
TaskActiveView::TaskActiveView(TechDraw::DrawPage* pageFeat) :
|
||||
ui(new Ui_TaskActiveView),
|
||||
m_pageFeat(pageFeat),
|
||||
m_imageFeat(nullptr),
|
||||
m_btnOK(nullptr),
|
||||
m_btnCancel(nullptr)
|
||||
TaskActiveView::TaskActiveView(TechDraw::DrawPage* pageFeat)
|
||||
: ui(new Ui_TaskActiveView), m_pageFeat(pageFeat), m_imageFeat(nullptr), m_btnOK(nullptr),
|
||||
m_btnCancel(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@@ -67,18 +64,16 @@ TaskActiveView::TaskActiveView(TechDraw::DrawPage* pageFeat) :
|
||||
setUiPrimary();
|
||||
}
|
||||
|
||||
TaskActiveView::~TaskActiveView()
|
||||
{
|
||||
}
|
||||
TaskActiveView::~TaskActiveView() {}
|
||||
|
||||
void TaskActiveView::updateTask()
|
||||
{
|
||||
// blockUpdate = true;
|
||||
// blockUpdate = true;
|
||||
|
||||
// blockUpdate = false;
|
||||
// blockUpdate = false;
|
||||
}
|
||||
|
||||
void TaskActiveView::changeEvent(QEvent *e)
|
||||
void TaskActiveView::changeEvent(QEvent* e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
ui->retranslateUi(this);
|
||||
@@ -87,18 +82,15 @@ void TaskActiveView::changeEvent(QEvent *e)
|
||||
|
||||
void TaskActiveView::setUiPrimary()
|
||||
{
|
||||
// Base::Console().Message("TAV::setUiPrimary()\n");
|
||||
// Base::Console().Message("TAV::setUiPrimary()\n");
|
||||
setWindowTitle(QObject::tr("ActiveView to TD View"));
|
||||
}
|
||||
|
||||
void TaskActiveView::blockButtons(bool b)
|
||||
{
|
||||
Q_UNUSED(b);
|
||||
}
|
||||
void TaskActiveView::blockButtons(bool b) { Q_UNUSED(b); }
|
||||
|
||||
TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
{
|
||||
// Base::Console().Message("TAV::createActiveView()\n");
|
||||
// Base::Console().Message("TAV::createActiveView()\n");
|
||||
|
||||
//make sure there is an 3D MDI to grab!!
|
||||
if (!Gui::getMainWindow()) {
|
||||
@@ -109,7 +101,8 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
|
||||
App::Document* pageDocument = m_pageFeat->getDocument();
|
||||
std::string documentName = m_pageFeat->getDocument()->getName();
|
||||
Gui::Document* pageGuiDocument = Gui::Application::Instance->getDocument(pageDocument->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());
|
||||
@@ -118,7 +111,8 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
auto views3dAll = pageGuiDocument->getMDIViewsOfType(Gui::View3DInventor::getClassTypeId());
|
||||
if (!views3dAll.empty()) {
|
||||
view3d = qobject_cast<View3DInventor*>(views3dAll.front());
|
||||
} else {
|
||||
}
|
||||
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.
|
||||
@@ -148,48 +142,58 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
|
||||
//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());
|
||||
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";
|
||||
std::string dir = doc->TransientDir.getValue();
|
||||
std::string fileSpec = dir + special;
|
||||
|
||||
//fixes fail to create 2nd Active view with same name in old docs
|
||||
Base::FileInfo fi(fileSpec);
|
||||
if (fi.exists()) {
|
||||
//old filename were unique by pageName + imageName only
|
||||
fi.deleteFile();
|
||||
}
|
||||
|
||||
//better way of making temp file name
|
||||
std::string baseName = pageName + imageName;
|
||||
std::string tempName =
|
||||
Base::FileInfo::getTempFileName(baseName.c_str(), doc->TransientDir.getValue()) + ".png";
|
||||
|
||||
QColor bg = ui->ccBgColor->color();
|
||||
if (ui->cbUse3d->isChecked()) {
|
||||
bg = QColor();
|
||||
} else if (ui->cbNoBG->isChecked()) {
|
||||
}
|
||||
else if (ui->cbNoBG->isChecked()) {
|
||||
bg = QColor(Qt::transparent);
|
||||
}
|
||||
|
||||
QImage image(100, 100, QImage::Format_RGB32); //arbitrary initial image size. quickView will use
|
||||
//MdiView size in pixels
|
||||
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(view3d, bg, image);
|
||||
bool success = image.save(Base::Tools::fromStdString(fileSpec));
|
||||
Grabber3d::quickView(view3d, bg, image);
|
||||
bool success = image.save(Base::Tools::fromStdString(tempName));
|
||||
|
||||
if (!success) {
|
||||
Base::Console().Error("ActiveView could not save file: %s\n", fileSpec.c_str());
|
||||
}
|
||||
|
||||
//backslashes in windows fileSpec upsets python
|
||||
std::regex rxBackslash("\\\\");
|
||||
std::string noBackslash = std::regex_replace(fileSpec, rxBackslash, "/");
|
||||
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());
|
||||
std::regex rxBackslash("\\\\"); //this rx really means match to a single '\'
|
||||
std::string noBackslash = std::regex_replace(tempName, rxBackslash, "/");
|
||||
|
||||
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);
|
||||
@@ -211,8 +215,7 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
|
||||
|
||||
//******************************************************************************
|
||||
|
||||
void TaskActiveView::saveButtons(QPushButton* btnOK,
|
||||
QPushButton* btnCancel)
|
||||
void TaskActiveView::saveButtons(QPushButton* btnOK, QPushButton* btnCancel)
|
||||
{
|
||||
m_btnOK = btnOK;
|
||||
m_btnCancel = btnCancel;
|
||||
@@ -228,10 +231,10 @@ void TaskActiveView::enableTaskButtons(bool b)
|
||||
|
||||
bool TaskActiveView::accept()
|
||||
{
|
||||
// Base::Console().Message("TAV::accept()\n");
|
||||
// Base::Console().Message("TAV::accept()\n");
|
||||
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create ActiveView"));
|
||||
m_imageFeat = createActiveView();
|
||||
// m_imageFeat->requestPaint();
|
||||
// m_imageFeat->requestPaint();
|
||||
if (m_imageFeat) {
|
||||
m_imageFeat->recomputeFeature();
|
||||
}
|
||||
@@ -245,8 +248,8 @@ bool TaskActiveView::accept()
|
||||
|
||||
bool TaskActiveView::reject()
|
||||
{
|
||||
// Base::Console().Message("TAV::reject()\n");
|
||||
//nothing to remove.
|
||||
// Base::Console().Message("TAV::reject()\n");
|
||||
//nothing to remove.
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().recompute()");
|
||||
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
|
||||
@@ -254,23 +257,20 @@ bool TaskActiveView::reject()
|
||||
return false;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
TaskDlgActiveView::TaskDlgActiveView(TechDraw::DrawPage* page)
|
||||
: TaskDialog()
|
||||
TaskDlgActiveView::TaskDlgActiveView(TechDraw::DrawPage* page) : TaskDialog()
|
||||
{
|
||||
widget = new TaskActiveView(page);
|
||||
widget = new TaskActiveView(page);
|
||||
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_ActiveView"),
|
||||
widget->windowTitle(), true, nullptr);
|
||||
widget->windowTitle(), true, nullptr);
|
||||
taskbox->groupLayout()->addWidget(widget);
|
||||
Content.push_back(taskbox);
|
||||
}
|
||||
|
||||
TaskDlgActiveView::~TaskDlgActiveView()
|
||||
{
|
||||
}
|
||||
TaskDlgActiveView::~TaskDlgActiveView() {}
|
||||
|
||||
void TaskDlgActiveView::update()
|
||||
{
|
||||
// widget->updateTask();
|
||||
// widget->updateTask();
|
||||
}
|
||||
|
||||
void TaskDlgActiveView::modifyStandardButtons(QDialogButtonBox* box)
|
||||
@@ -281,13 +281,9 @@ void TaskDlgActiveView::modifyStandardButtons(QDialogButtonBox* box)
|
||||
}
|
||||
|
||||
//==== calls from the TaskView ===============================================================
|
||||
void TaskDlgActiveView::open()
|
||||
{
|
||||
}
|
||||
void TaskDlgActiveView::open() {}
|
||||
|
||||
void TaskDlgActiveView::clicked(int)
|
||||
{
|
||||
}
|
||||
void TaskDlgActiveView::clicked(int) {}
|
||||
|
||||
bool TaskDlgActiveView::accept()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user