[TD]fix bitmap hatch

This commit is contained in:
Wanderer Fan
2022-06-28 19:40:57 -04:00
committed by WandererFan
parent 3a2fbc47e0
commit 8b60da803c
14 changed files with 404 additions and 274 deletions

View File

@@ -43,9 +43,9 @@
#include <Base/Parameter.h>
#include <Base/UnitsApi.h>
#include "Preferences.h"
#include "DrawViewPart.h"
#include "DrawUtil.h"
#include "Preferences.h"
#include "DrawHatch.h"
#include <Mod/TechDraw/App/DrawHatchPy.h> // generated from DrawHatchPy.xml
@@ -65,8 +65,7 @@ DrawHatch::DrawHatch(void)
ADD_PROPERTY_TYPE(HatchPattern, (prefSvgHatch()), vgroup, App::Prop_None, "The hatch pattern file for this area");
ADD_PROPERTY_TYPE(SvgIncluded, (""), vgroup,App::Prop_None,
"Embedded SVG hatch file. System use only."); // n/a to end users
std::string svgFilter("SVG files (*.svg *.SVG);;All files (*)");
std::string svgFilter("SVG files (*.svg *.SVG);;Bitmap files(*.jpg *.jpeg *.png *.bmp);;All files (*)");
HatchPattern.setFilter(svgFilter);
}
@@ -84,13 +83,27 @@ void DrawHatch::onChanged(const App::Property* prop)
if ((prop == &HatchPattern) &&
(doc != nullptr) ) {
if (!HatchPattern.isEmpty()) {
replaceSvgIncluded(HatchPattern.getValue());
replaceFileIncluded(HatchPattern.getValue());
}
}
}
App::DocumentObject::onChanged(prop);
}
short DrawHatch::mustExecute() const
{
short result = 0;
if (!isRestoring()) {
result = (Source.isTouched() ||
HatchPattern.isTouched());
}
if (result) {
return result;
}
return App::DocumentObject::mustExecute();
}
App::DocumentObjectExecReturn *DrawHatch::execute(void)
{
DrawViewPart* parent = getSourceView();
@@ -187,11 +200,11 @@ bool DrawHatch::empty(void)
return sourceNames.empty();
}
void DrawHatch::replaceSvgIncluded(std::string newSvgFile)
void DrawHatch::replaceFileIncluded(std::string newSvgFile)
{
// Base::Console().Message("DH::replaceSvgHatch(%s)\n", newSvgFile.c_str());
if (SvgIncluded.isEmpty()) {
setupSvgIncluded();
setupFileIncluded();
} else {
std::string tempName = SvgIncluded.getExchangeTempFile();
DrawUtil::copyFile(newSvgFile, tempName);
@@ -211,28 +224,29 @@ void DrawHatch::onDocumentRestored()
Base::FileInfo tfi(svgFileName);
if (tfi.isReadable()) {
if (SvgIncluded.isEmpty()) {
setupSvgIncluded();
setupFileIncluded();
}
}
}
}
App::DocumentObject::onDocumentRestored();
}
void DrawHatch::setupObject()
{
//by this point DH should have a name and belong to a document
setupSvgIncluded();
setupFileIncluded();
App::DocumentObject::setupObject();
}
void DrawHatch::setupSvgIncluded(void)
void DrawHatch::setupFileIncluded(void)
{
// Base::Console().Message("DH::setupSvgIncluded()\n");
// Base::Console().Message("DH::setupFileIncluded()\n");
App::Document* doc = getDocument();
std::string special = getNameInDocument();
special += "SvgHatch.svg";
special += "Hatch.fill";
std::string dir = doc->TransientDir.getValue();
std::string svgName = dir + special;
@@ -259,6 +273,34 @@ void DrawHatch::unsetupObject(void)
App::DocumentObject::unsetupObject();
}
bool DrawHatch::isSvgHatch(void) const
{
bool result = false;
Base::FileInfo fi(HatchPattern.getValue());
if ((fi.extension() == "svg") ||
(fi.extension() == "SVG")) {
result = true;
}
return result;
}
bool DrawHatch::isBitmapHatch(void) const
{
bool result = false;
Base::FileInfo fi(HatchPattern.getValue());
if ((fi.extension() == "bmp") ||
(fi.extension() == "BMP") ||
(fi.extension() == "png") ||
(fi.extension() == "PNG") ||
(fi.extension() == "jpg") ||
(fi.extension() == "JPG") ||
(fi.extension() == "jpeg") ||
(fi.extension() == "JPEG") ) {
result = true;
}
return result;
}
//standard preference getters
std::string DrawHatch::prefSvgHatch(void)
{
@@ -274,7 +316,6 @@ App::Color DrawHatch::prefSvgHatchColor(void)
return fcColor;
}
// Python Drawing feature ---------------------------------------------------------
namespace App {

View File

@@ -23,11 +23,16 @@
#ifndef _TechDraw_DrawHatch_h_
#define _TechDraw_DrawHatch_h_
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <App/DocumentObject.h>
#include <App/FeaturePython.h>
#include <App/PropertyFile.h>
#include <App/PropertyLinks.h>
namespace App {
class Color;
}
namespace TechDraw
{
@@ -46,6 +51,7 @@ public:
App::PropertyFileIncluded SvgIncluded;
virtual App::DocumentObjectExecReturn *execute(void) override;
virtual short mustExecute() const override;
virtual const char* getViewProviderName(void) const override {
return "TechDrawGui::ViewProviderHatch";
@@ -64,12 +70,15 @@ public:
static std::string prefSvgHatch(void);
static App::Color prefSvgHatchColor(void);
bool isSvgHatch(void) const;
bool isBitmapHatch(void) const;
protected:
void onChanged(const App::Property* prop) override;
virtual void onDocumentRestored() override;
virtual void setupObject() override;
void setupSvgIncluded(void);
void replaceSvgIncluded(std::string newSvgFile);
void setupFileIncluded(void);
void replaceFileIncluded(std::string newSvgFile);
private:

View File

@@ -302,3 +302,20 @@ std::string Preferences::patFile()
}
return result;
}
std::string Preferences::bitmapFill(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files");
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Patterns/";
std::string defaultFileName = defaultDir + "default.png";
std::string prefBitmapFile = hGrp->GetASCII("BitmapFill", defaultFileName.c_str());
std::string result = prefBitmapFile;
Base::FileInfo fi(result);
if (!fi.isReadable()) {
result = defaultFileName;
Base::Console().Warning("Bitmap Fill File: %s is not readable\n", prefBitmapFile.c_str());
}
return result;
}

View File

@@ -73,7 +73,7 @@ static int mattingStyle();
static std::string svgFile();
static std::string patFile();
static std::string bitmapFill(void);
};
} //end namespace TechDraw

View File

@@ -132,8 +132,8 @@ void CmdTechDrawHatch::activated(int iMsg)
}
}
openCommand(QT_TRANSLATE_NOOP("Command", "Create Hatch"));
if (removeOld) {
openCommand(QT_TRANSLATE_NOOP("Command", "Remove old Hatch"));
std::vector<std::pair< int, TechDraw::DrawHatch*> > toRemove;
for (auto& h: hatchObjs) { //all the hatch objects for selected DVP
std::vector<std::string> hatchSubs = h->Source.getSubValues();
@@ -154,33 +154,11 @@ void CmdTechDrawHatch::activated(int iMsg)
doCommand(Doc,"App.activeDocument().removeObject('%s')",r.second->getNameInDocument());
}
}
commitCommand();
}
std::string FeatName = getUniqueObjectName("Hatch");
std::stringstream featLabel;
featLabel << FeatName << "F" <<
TechDraw::DrawUtil::getIndexFromName(subNames.at(0)); //use 1st face# for label
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Label = '%s'",FeatName.c_str(),featLabel.str().c_str());
auto hatch( static_cast<TechDraw::DrawHatch *>(getDocument()->getObject(FeatName.c_str())) );
hatch->Source.setValue(partFeat, subNames);
Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(hatch);
TechDrawGui::ViewProviderHatch* hvp = dynamic_cast<TechDrawGui::ViewProviderHatch*>(vp);
if (!hvp) {
Base::Console().Log("ERROR - CommandDecorate - Hatch has no ViewProvider\n");
return;
}
//should this be: doCommand(Doc,"App..Feat..Source = [(App...%s,%s),(App..%s,%s),...]",objs[0]->getNameInDocument(),subs[0],...);
//seems very unwieldy
// dialog to fill in hatch values
Gui::Control().showDialog(new TaskDlgHatch(hatch, hvp, true));
commitCommand();
Gui::Control().showDialog(new TaskDlgHatch(partFeat, subNames));
//Horrible hack to force Tree update ??still required??
//WF: yes. ViewProvider will not claim children without this!
@@ -189,7 +167,6 @@ void CmdTechDrawHatch::activated(int iMsg)
getDocument()->recompute();
}
bool CmdTechDrawHatch::isActive(void)
{
bool havePage = DrawGuiUtil::needPage(this);

View File

@@ -136,41 +136,28 @@ void QGIFace::draw()
}
m_image->hide();
m_rect->hide();
} else if ((m_mode == FromFile) ||
(m_mode == SvgFill) ||
(m_mode == BitmapFill)) {
QFileInfo hfi(QString::fromUtf8(m_fileSpec.data(),m_fileSpec.size()));
if (hfi.isReadable()) {
QString ext = hfi.suffix();
if (ext.toUpper() == QString::fromUtf8("SVG")) {
setFillMode(SvgFill);
m_brush.setTexture(QPixmap());
m_styleNormal = m_styleDef;
m_fillStyleCurrent = m_styleNormal;
loadSvgHatch(m_fileSpec);
if (m_hideSvgTiles) {
//bitmap hatch doesn't need clipping
setFlag(QGraphicsItem::ItemClipsChildrenToShape,false);
buildPixHatch();
m_rect->hide();
m_image->show();
} else {
//SVG tiles need to be clipped
setFlag(QGraphicsItem::ItemClipsChildrenToShape,true);
buildSvgHatch();
m_image->hide();
m_rect->show();
}
} else if ((ext.toUpper() == QString::fromUtf8("JPG")) ||
(ext.toUpper() == QString::fromUtf8("PNG")) ||
(ext.toUpper() == QString::fromUtf8("JPEG")) ||
(ext.toUpper() == QString::fromUtf8("BMP")) ) {
setFillMode(BitmapFill);
m_fillStyleCurrent = Qt::TexturePattern;
m_texture = textureFromBitmap(m_fileSpec);
m_brush.setTexture(m_texture);
}
} else if (m_mode == SvgFill) {
m_brush.setTexture(QPixmap());
m_styleNormal = m_styleDef;
m_fillStyleCurrent = m_styleNormal;
loadSvgHatch(m_fileSpec);
if (m_hideSvgTiles) {
//bitmap hatch doesn't need clipping
setFlag(QGraphicsItem::ItemClipsChildrenToShape,false);
buildPixHatch();
m_rect->hide();
m_image->show();
} else {
//SVG tiles need to be clipped
setFlag(QGraphicsItem::ItemClipsChildrenToShape,true);
buildSvgHatch();
m_image->hide();
m_rect->show();
}
} else if (m_mode == BitmapFill) {
m_fillStyleCurrent = Qt::TexturePattern;
m_texture = textureFromBitmap(m_fileSpec);
m_brush.setTexture(m_texture);
} else if (m_mode == PlainFill) {
setFill(m_colNormalFill, m_styleNormal);
m_image->hide();
@@ -197,12 +184,14 @@ void QGIFace::setPrettyNormal() {
void QGIFace::setPrettyPre() {
// Base::Console().Message("QGIF::setPrettyPre()\n");
m_fillStyleCurrent = Qt::SolidPattern;
m_brush.setTexture(QPixmap());
QGIPrimPath::setPrettyPre();
}
void QGIFace::setPrettySel() {
// Base::Console().Message("QGIF::setPrettySel()\n");
m_fillStyleCurrent = Qt::SolidPattern;
m_brush.setTexture(QPixmap());
QGIPrimPath::setPrettySel();
}
@@ -699,13 +688,15 @@ void QGIFace::hideSvg(bool b)
QPixmap QGIFace::textureFromBitmap(std::string fileSpec)
{
QPixmap pix;
QString qs = QString::fromUtf8(fileSpec.data(),fileSpec.size());
QFileInfo ffi(qs);
if (ffi.isReadable()) {
QImage img = QImage(qs);
img = img.scaled(Rez::guiX(m_fillScale),Rez::guiX(m_fillScale));
pix = QPixmap::fromImage(img);
QString qfs(QString::fromUtf8(fileSpec.data(),fileSpec.size()));
QFile f(qfs);
if (!f.open(QFile::ReadOnly)) {
Base::Console().Error("QGIFace could not read %s\n",fileSpec.c_str());
return pix;
}
QByteArray bytes = f.readAll();
pix.loadFromData(bytes);
return pix;
}

View File

@@ -23,11 +23,16 @@
#ifndef DRAWINGGUI_QGRAPHICSITEMFACE_H
#define DRAWINGGUI_QGRAPHICSITEMFACE_H
#include <QByteArray>
#include <Qt>
#include <QGraphicsItem>
#include <QSvgRenderer>
#include <QByteArray>
#include <QBrush>
#include <QPixmap>
#include <QImage>
#include <Mod/TechDraw/App/HatchLine.h>
#include <Mod/TechDraw/App/Geometry.h>
#include "QGIPrimPath.h"

View File

@@ -476,7 +476,6 @@ void QGIViewPart::drawViewPart()
QGIFace* newFace = drawFace(*fit,i);
newFace->isHatched(false);
newFace->setFillMode(QGIFace::PlainFill);
// newFace->setFill(QColor(Qt::red), Qt::SolidPattern); //this overrides the QGIF defaults
TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs);
TechDraw::DrawGeomHatch* fGeom = faceIsGeomHatched(i,geomObjs);
if (fGeom) {
@@ -504,24 +503,30 @@ void QGIViewPart::drawViewPart()
}
}
} else if (fHatch) {
if (!fHatch->SvgIncluded.isEmpty()) {
if (getExporting()) {
newFace->hideSvg(true);
} else {
newFace->hideSvg(false);
}
newFace->isHatched(true);
newFace->setFillMode(QGIFace::SvgFill);
newFace->setHatchFile(fHatch->SvgIncluded.getValue());
Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch);
ViewProviderHatch* hatchVp = dynamic_cast<ViewProviderHatch*>(gvp);
if (hatchVp != nullptr) {
double hatchScale = hatchVp->HatchScale.getValue();
if (hatchScale > 0.0) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
if (fHatch->isSvgHatch()) {
if (!fHatch->SvgIncluded.isEmpty()) {
if (getExporting()) {
newFace->hideSvg(true);
} else {
newFace->hideSvg(false);
}
newFace->isHatched(true);
newFace->setFillMode(QGIFace::SvgFill);
newFace->setHatchFile(fHatch->SvgIncluded.getValue());
Gui::ViewProvider* gvp = QGIView::getViewProvider(fHatch);
ViewProviderHatch* hatchVp = dynamic_cast<ViewProviderHatch*>(gvp);
if (hatchVp != nullptr) {
double hatchScale = hatchVp->HatchScale.getValue();
if (hatchScale > 0.0) {
newFace->setHatchScale(hatchVp->HatchScale.getValue());
}
newFace->setHatchColor(hatchVp->HatchColor.getValue());
}
newFace->setHatchColor(hatchVp->HatchColor.getValue());
}
} else { //bitmap hatch
newFace->isHatched(true);
newFace->setFillMode(QGIFace::BitmapFill);
newFace->setHatchFile(fHatch->SvgIncluded.getValue());
}
}
bool drawEdges = prefFaceEdges();

View File

@@ -28,6 +28,7 @@
#endif // #ifndef _PreComp_
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Base/Vector3D.h>
#include <Gui/Application.h>
@@ -43,8 +44,10 @@
#include <Mod/TechDraw/App/DrawHatch.h>
#include <Mod/TechDraw/App/DrawView.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include "PreferencesGui.h"
#include "ViewProviderHatch.h"
#include "TaskHatch.h"
#include <Mod/TechDraw/Gui/ui_TaskHatch.h>
@@ -53,113 +56,192 @@ using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;
TaskHatch::TaskHatch(TechDraw::DrawHatch* inHatch, TechDrawGui::ViewProviderHatch* inVp, bool mode) :
//ctor for creation
TaskHatch::TaskHatch(TechDraw::DrawViewPart* inDvp, std::vector<std::string> subs) :
ui(new Ui_TaskHatch),
m_hatch(inHatch),
m_Vp(inVp),
m_createMode(mode)
m_hatch(nullptr),
m_dvp(inDvp),
m_subs(subs)
{
ui->setupUi(this);
connect(ui->fcFile, SIGNAL(fileNameSelected( const QString & )), this, SLOT(onFileChanged(void)));
m_source = m_hatch->Source.getValue();
getParameters();
initUi();
connect(ui->fcFile, SIGNAL(fileNameSelected(QString)), this, SLOT(onFileChanged()));
connect(ui->sbScale, SIGNAL(valueChanged(double)), this, SLOT(onScaleChanged()));
connect(ui->ccColor, SIGNAL(changed()), this, SLOT(onColorChanged()));
setUiPrimary();
}
//ctor for edit
TaskHatch::TaskHatch(TechDrawGui::ViewProviderHatch* inVp) :
ui(new Ui_TaskHatch),
m_vp(inVp)
{
// Base::Console().Message("TH::TH() - edit\n");
ui->setupUi(this);
m_hatch = m_vp->getViewObject();
App::DocumentObject* obj = m_hatch->Source.getValue();
m_dvp = static_cast<TechDraw::DrawViewPart*>(obj);
connect(ui->fcFile, SIGNAL(fileNameSelected(QString)), this, SLOT(onFileChanged()));
connect(ui->sbScale, SIGNAL(valueChanged(double)), this, SLOT(onScaleChanged()));
connect(ui->ccColor, SIGNAL(changed()), this, SLOT(onColorChanged()));
saveHatchState();
setUiEdit();
}
TaskHatch::~TaskHatch()
{
}
void TaskHatch::initUi()
void TaskHatch::setUiPrimary()
{
ui->fcFile->setFileName(QString::fromUtf8(m_file.data(), m_file.size()));
ui->sbScale->setValue(m_scale);
setWindowTitle(QObject::tr("Create Face Hatch"));
ui->fcFile->setFileName(Base::Tools::fromStdString(DrawHatch::prefSvgHatch()));
ui->fcFile->setFilter(QString::fromUtf8(
"SVG files (*.svg *.SVG);;Bitmap files(*.jpg *.jpeg *.png *.bmp);;All files (*)"));
ui->sbScale->setValue(1.0);
ui->sbScale->setSingleStep(0.1);
connect(ui->sbScale, SIGNAL(valueChanged(double)), this, SLOT(onScaleChanged()));
ui->ccColor->setColor(m_color.asValue<QColor>());
connect(ui->ccColor, SIGNAL(changed()), this, SLOT(onColorChanged()));
ui->ccColor->setColor(TechDraw::DrawHatch::prefSvgHatchColor().asValue<QColor>());
}
//move values from screen to DocObjs
void TaskHatch::updateValues()
void TaskHatch::setUiEdit()
{
m_file = (ui->fcFile->fileName()).toUtf8().constData();
m_hatch->HatchPattern.setValue(m_file);
m_scale = ui->sbScale->value().getValue();
m_Vp->HatchScale.setValue(m_scale);
m_color.setValue<QColor>(ui->ccColor->color());
m_Vp->HatchColor.setValue(m_color);
setWindowTitle(QObject::tr("Edit Face Hatch"));
ui->fcFile->setFileName(Base::Tools::fromStdString(m_saveFile));
ui->fcFile->setFilter(QString::fromUtf8(
"SVG files (*.svg *.SVG);;Bitmap files(*.jpg *.jpeg *.png *.bmp);;All files (*)"));
ui->sbScale->setValue(m_saveScale);
ui->sbScale->setSingleStep(0.1);
ui->ccColor->setColor(m_saveColor.asValue<QColor>());
}
QStringList TaskHatch::listToQ(std::vector<std::string> in)
void TaskHatch::saveHatchState()
{
QStringList result;
for (auto& s: in) {
QString qs = QString::fromUtf8(s.data(), s.size());
result.append(qs);
m_saveFile = m_hatch->HatchPattern.getValue();
m_saveScale = m_vp->HatchScale.getValue();
m_saveColor = m_vp->HatchColor.getValue();
}
//restore the start conditions
void TaskHatch::restoreHatchState()
{
// Base::Console().Message("TH::restoreHatchState()\n");
if (m_hatch != nullptr) {
m_hatch->HatchPattern.setValue(m_saveFile);
m_vp->HatchScale.setValue(m_saveScale);
m_vp->HatchColor.setValue(m_saveColor);
}
return result;
}
void TaskHatch::onFileChanged(void)
{
m_file = ui->fcFile->fileName().toUtf8().constData();
m_hatch->HatchPattern.setValue(m_file);
m_source->getDocument()->recompute();
}
bool TaskHatch::accept()
{
updateValues();
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
m_source->touch();
m_source->getDocument()->recompute();
return true;
m_file = Base::Tools::toStdString(ui->fcFile->fileName());
apply();
}
void TaskHatch::onScaleChanged()
{
m_Vp->HatchScale.setValue(ui->sbScale->value().getValue());
m_source->getDocument()->recompute();
m_scale = ui->sbScale->value().getValue();
apply();
}
void TaskHatch::onColorChanged()
{
m_color.setValue<QColor>(ui->ccColor->color());
apply();
}
void TaskHatch::apply(bool forceUpdate)
{
Q_UNUSED(forceUpdate)
// Base::Console().Message("TH::apply() - m_hatch: %X\n", m_hatch);
if (m_hatch == nullptr) {
createHatch();
}
if (m_hatch != nullptr) {
updateHatch();
}
if (m_dvp != nullptr) {
//only need requestPaint to hatch the face
// m_dvp->requestPaint();
//need a recompute in order to claimChildren in tree
m_dvp->recomputeFeature();
}
}
void TaskHatch::createHatch()
{
// Base::Console().Message("TH::createHatch()\n");
App::Document* doc = m_dvp->getDocument();
std::string FeatName = doc->getUniqueObjectName("Hatch");
std::stringstream featLabel;
featLabel << FeatName << "F" <<
TechDraw::DrawUtil::getIndexFromName(m_subs.at(0)); //use 1st face# for label
Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Hatch"));
Command::doCommand(Command::Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.Label = '%s'",FeatName.c_str(),featLabel.str().c_str());
m_hatch = static_cast<TechDraw::DrawHatch *>(doc->getObject(FeatName.c_str()));
m_hatch->Source.setValue(m_dvp, m_subs);
Command::doCommand(Command::Doc,"App.activeDocument().%s.HatchPattern = '%s'",
FeatName.c_str(),
Base::Tools::toStdString(ui->fcFile->fileName()).c_str());
//view provider properties
Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(doc)->getViewProvider(m_hatch);
m_vp = dynamic_cast<TechDrawGui::ViewProviderHatch*>(vp);
if (m_vp) {
App::Color ac;
ac.setValue<QColor>(ui->ccColor->color());
m_vp->HatchColor.setValue(ac);
m_vp->HatchScale.setValue(ui->sbScale->value().getValue());
} else {
Base::Console().Error("TaskHatch - Hatch has no ViewProvider\n");
}
Command::commitCommand();
}
void TaskHatch::updateHatch()
{
// Base::Console().Message("TH::updateHatch()\n");
std::string FeatName = m_hatch->getNameInDocument();
Command::openCommand(QT_TRANSLATE_NOOP("Command", "Update Hatch"));
Command::doCommand(Command::Doc,"App.activeDocument().%s.HatchPattern = '%s'",
FeatName.c_str(),
Base::Tools::toStdString(ui->fcFile->fileName()).c_str());
App::Color ac;
ac.setValue<QColor>(ui->ccColor->color());
m_Vp->HatchColor.setValue(ac);
m_source->getDocument()->recompute();
m_vp->HatchColor.setValue(ac);
m_vp->HatchScale.setValue(ui->sbScale->value().getValue());
Command::commitCommand();
}
bool TaskHatch::accept()
{
// Base::Console().Message("TH::accept()\n");
apply(true);
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
return true;
}
bool TaskHatch::reject()
{
if (getCreateMode()) {
std::string HatchName = m_hatch->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().removeObject('%s')",HatchName.c_str());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
m_source->touch();
m_source->getDocument()->recompute();
} else {
m_hatch->HatchPattern.setValue(m_origFile);
m_Vp->HatchScale.setValue(m_origScale);
m_Vp->HatchColor.setValue(m_origColor);
}
// Base::Console().Message("TH::reject()\n");
restoreHatchState();
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
return false;
}
void TaskHatch::getParameters()
{
m_file = m_hatch->HatchPattern.getValue();
m_scale = m_Vp->HatchScale.getValue();
m_color = m_Vp->HatchColor.getValue();
if (!getCreateMode()) {
m_origFile = m_hatch->HatchPattern.getValue();
m_origScale = m_Vp->HatchScale.getValue();
m_origColor = m_Vp->HatchColor.getValue();
}
}
void TaskHatch::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
@@ -168,13 +250,22 @@ void TaskHatch::changeEvent(QEvent *e)
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TaskDlgHatch::TaskDlgHatch(TechDraw::DrawHatch* inHatch, TechDrawGui::ViewProviderHatch* inVp, bool mode) :
TaskDialog(),
viewProvider(nullptr)
TaskDlgHatch::TaskDlgHatch(TechDraw::DrawViewPart* inDvp, std::vector<std::string> subs) :
TaskDialog()
{
widget = new TaskHatch(inHatch, inVp, mode);
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_TreeView"),
widget->windowTitle(), true, nullptr);
widget = new TaskHatch(inDvp, subs);
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_TreeHatch"),
widget->windowTitle(), true, 0);
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
}
TaskDlgHatch::TaskDlgHatch(TechDrawGui::ViewProviderHatch* inVp) :
TaskDialog()
{
widget = new TaskHatch(inVp);
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_TreeHatch"),
widget->windowTitle(), true, 0);
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
}
@@ -183,11 +274,6 @@ TaskDlgHatch::~TaskDlgHatch()
{
}
void TaskDlgHatch::setCreateMode(bool b)
{
widget->setCreateMode(b);
}
void TaskDlgHatch::update()
{
//widget->updateTask();

View File

@@ -24,23 +24,23 @@
#ifndef GUI_TASKVIEW_TASKHATCH_H
#define GUI_TASKVIEW_TASKHATCH_H
#include <App/Material.h>
#include <Gui/TaskView/TaskDialog.h>
#include <Gui/TaskView/TaskView.h>
#include <Mod/TechDraw/App/DrawHatch.h>
#include <Mod/TechDraw/Gui/ui_TaskHatch.h>
class Ui_TaskHatch;
namespace App
{
class DocumentObject;
}
namespace TechDraw
{
class DrawHatch;
}
namespace TechDrawGui
{
class Ui_TaskHatch;
class ViewProviderHatch;
class TaskHatch : public QWidget
@@ -48,43 +48,47 @@ class TaskHatch : public QWidget
Q_OBJECT
public:
TaskHatch(TechDraw::DrawHatch* inHatch,TechDrawGui::ViewProviderHatch* inVp, bool mode);
TaskHatch(TechDraw::DrawViewPart* inDvp, std::vector<std::string> subs);
TaskHatch(TechDrawGui::ViewProviderHatch* inVp);
~TaskHatch();
public:
virtual bool accept();
virtual bool reject();
void setCreateMode(bool b) { m_createMode = b;}
bool getCreateMode() { return m_createMode; }
protected Q_SLOTS:
void onFileChanged(void);
void onScaleChanged();
void onColorChanged();
protected:
void changeEvent(QEvent *e);
void initUi();
// bool resetUi();
void updateValues();
void getParameters();
QStringList listToQ(std::vector<std::string> in);
void apply(bool forceUpdate = false);
private Q_SLOTS:
void onScaleChanged();
void onColorChanged();
void createHatch(void);
void updateHatch(void);
void setUiPrimary();
void setUiEdit();
void saveHatchState();
void restoreHatchState();
void getParameters();
private:
std::unique_ptr<Ui_TaskHatch> ui;
TechDraw::DrawHatch* m_hatch;
TechDrawGui::ViewProviderHatch* m_Vp;
App::DocumentObject* m_source;
TechDrawGui::ViewProviderHatch* m_vp;
TechDraw::DrawViewPart* m_dvp;
std::vector<std::string> m_subs;
std::string m_file;
double m_scale;
App::Color m_color;
std::string m_origFile;
double m_origScale;
App::Color m_origColor;
bool m_createMode;
std::string m_saveFile;
double m_saveScale;
App::Color m_saveColor;
std::vector<std::string> m_saveSubs;
};
@@ -93,9 +97,9 @@ class TaskDlgHatch : public Gui::TaskView::TaskDialog
Q_OBJECT
public:
TaskDlgHatch(TechDraw::DrawHatch* inHatch,TechDrawGui::ViewProviderHatch* inVp, bool mode);
TaskDlgHatch(TechDraw::DrawViewPart* inDvp, std::vector<std::string> subs);
TaskDlgHatch(TechDrawGui::ViewProviderHatch* inVp);
~TaskDlgHatch();
const ViewProviderHatch * getViewProvider() const { return viewProvider; }
public:
/// is called the TaskView when the dialog is opened
@@ -110,12 +114,10 @@ public:
virtual void helpRequested() { return;}
virtual bool isAllowedAlterDocument(void) const
{ return false; }
void setCreateMode(bool b);
void update();
protected:
const ViewProviderHatch *viewProvider;
private:
TaskHatch * widget;

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>342</width>
<height>135</height>
<width>398</width>
<height>148</height>
</rect>
</property>
<property name="sizePolicy">
@@ -34,20 +34,16 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Select an Svg or Bitmap file</string>
</property>
<property name="title">
<string>Define your pattern</string>
<string>Pattern Parameters</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_3" columnstretch="0,1">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Pattern File</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="Gui::FileChooser" name="fcFile">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
@@ -56,44 +52,56 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>The PAT file containing your pattern</string>
<string>Choose an Svg or Bitmap file as a pattern</string>
</property>
</widget>
</item>
</layout>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Pattern File</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0,0">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Pattern Scale</string>
<layout class="QGridLayout" name="gridLayout_3" rowstretch="0,0,0" columnstretch="0,0">
<item row="2" column="1">
<widget class="Gui::ColorButton" name="ccColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="Gui::QuantitySpinBox" name="sbScale">
<property name="minimumSize">
<size>
<width>0</width>
<height>22</height>
<height>26</height>
</size>
</property>
<property name="toolTip">
<string>Enlarges/shrinks the pattern</string>
<string>Color of pattern lines (Svg Only)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::QuantitySpinBox" name="sbScale">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>26</height>
</size>
</property>
<property name="toolTip">
<string>Enlarges/shrinks the pattern (Svg Only)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -112,27 +120,21 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Svg Pattern Scale</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Line Color</string>
<string>Svg Line Color</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="Gui::ColorButton" name="ccColor">
<property name="minimumSize">
<size>
<width>0</width>
<height>22</height>
</size>
</property>
<property name="toolTip">
<string>Color of pattern lines</string>
</property>
</widget>
</item>
</layout>
</layout>
</item>
</layout>
</widget>

View File

@@ -92,24 +92,17 @@ std::vector<std::string> ViewProviderHatch::getDisplayModes(void) const
bool ViewProviderHatch::setEdit(int ModNum)
{
Q_UNUSED(ModNum);
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
TaskDlgHatch *projDlg = qobject_cast<TaskDlgHatch *>(dlg);
if (projDlg && (projDlg->getViewProvider() != this))
projDlg = nullptr; // somebody left task panel open
// clear the selection (convenience)
Gui::Selection().clearSelection();
// start the edit dialog
if (projDlg) {
projDlg->setCreateMode(false);
Gui::Control().showDialog(projDlg);
if (ModNum == ViewProvider::Default ) {
if (Gui::Control().activeDialog()) { //TaskPanel already open!
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
Gui::Control().showDialog(new TaskDlgHatch(this));
return true;
} else {
return Gui::ViewProviderDocumentObject::setEdit(ModNum);
}
else {
Gui::Control().showDialog(new TaskDlgHatch(getViewObject(), this, false));
}
return true;
}

View File

@@ -25,6 +25,8 @@
#ifndef DRAWINGGUI_VIEWPROVIDERHATCH_H
#define DRAWINGGUI_VIEWPROVIDERHATCH_H
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <Gui/ViewProviderDocumentObject.h>
namespace TechDraw{

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB