Colored SVG Hatch patterns

This commit is contained in:
WandererFan 2016-06-16 10:33:20 -04:00 committed by wmayer
parent 731f76f52d
commit 05d94f31f8
5 changed files with 27 additions and 9 deletions

View File

@ -55,7 +55,7 @@ DrawHatch::DrawHatch(void)
ADD_PROPERTY_TYPE(DirProjection ,(0,0,1.0) ,vgroup,App::Prop_None,"Projection direction when Hatch was defined"); //sb RO? ADD_PROPERTY_TYPE(DirProjection ,(0,0,1.0) ,vgroup,App::Prop_None,"Projection direction when Hatch was defined"); //sb RO?
ADD_PROPERTY_TYPE(Source,(0),vgroup,(App::PropertyType)(App::Prop_None),"The View + Face to be hatched"); ADD_PROPERTY_TYPE(Source,(0),vgroup,(App::PropertyType)(App::Prop_None),"The View + Face to be hatched");
ADD_PROPERTY_TYPE(HatchPattern ,(""),vgroup,App::Prop_None,"The hatch pattern file for this area"); ADD_PROPERTY_TYPE(HatchPattern ,(""),vgroup,App::Prop_None,"The hatch pattern file for this area");
ADD_PROPERTY_TYPE(HatchColor,(0.0f,0.0f,0.0f),vgroup,App::Prop_None,"The color of the hatch area"); ADD_PROPERTY_TYPE(HatchColor,(0.0f,0.0f,0.0f),vgroup,App::Prop_None,"The color of the hatch pattern");
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter() Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw"); .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw");
@ -90,7 +90,6 @@ void DrawHatch::onChanged(const App::Property* prop)
App::DocumentObjectExecReturn *DrawHatch::execute(void) App::DocumentObjectExecReturn *DrawHatch::execute(void)
{ {
//TODO: need to refresh DrawViewPart to reflect change in hatch
DrawViewPart* parent = getSourceView(); DrawViewPart* parent = getSourceView();
if (parent) { if (parent) {
parent->touch(); parent->touch();

View File

@ -103,7 +103,6 @@ void DrawPage::onChanged(const App::Property* prop)
if (prop == &Template) { if (prop == &Template) {
if (!isRestoring()) { if (!isRestoring()) {
//TODO: reload if Template prop changes (ie different Template) //TODO: reload if Template prop changes (ie different Template)
Base::Console().Message("TODO: Unimplemented function DrawPage::onChanged(Template)\n");
} }
} else if (prop == &Views) { } else if (prop == &Views) {
if (!isRestoring()) { if (!isRestoring()) {

View File

@ -94,6 +94,8 @@ QGIFace::QGIFace(int index) :
m_rect = new QGCustomRect(); m_rect = new QGCustomRect();
m_rect->setParentItem(this); m_rect->setParentItem(this);
m_svgCol = SVGCOLDEFAULT;
} }
QGIFace::~QGIFace() QGIFace::~QGIFace()
@ -190,8 +192,8 @@ void QGIFace::setHatch(std::string fileSpec)
Base::Console().Error("QGIFace could not read %s\n",fileSpec.c_str()); Base::Console().Error("QGIFace could not read %s\n",fileSpec.c_str());
return; return;
} }
m_qba = f.readAll(); m_svgXML = f.readAll();
if (!m_svg->load(&m_qba)) { if (!m_svg->load(&m_svgXML)) {
Base::Console().Error("Error - Could not load hatch into SVG renderer for %s\n", fileSpec.c_str()); Base::Console().Error("Error - Could not load hatch into SVG renderer for %s\n", fileSpec.c_str());
return; return;
} }
@ -202,7 +204,7 @@ void QGIFace::setHatch(std::string fileSpec)
void QGIFace::setPath(const QPainterPath & path) void QGIFace::setPath(const QPainterPath & path)
{ {
QGraphicsPathItem::setPath(path); QGraphicsPathItem::setPath(path);
if (!m_qba.isEmpty()) { if (!m_svgXML.isEmpty()) {
buildHatch(); buildHatch();
} }
} }
@ -220,12 +222,17 @@ void QGIFace::buildHatch()
h = nh * SVGSIZEW; h = nh * SVGSIZEW;
m_rect->setRect(0.,0.,w,-h); m_rect->setRect(0.,0.,w,-h);
m_rect->centerAt(fCenter); m_rect->centerAt(fCenter);
QPointF rPos = m_rect->pos(); //QPointF rPos = m_rect->pos();
r = m_rect->rect(); r = m_rect->rect();
QByteArray before,after;
before.append(QString::fromStdString(SVGCOLPREFIX + SVGCOLDEFAULT));
after.append(QString::fromStdString(SVGCOLPREFIX + m_svgCol));
QByteArray colorXML = m_svgXML.replace(before,after);
for (int iw = 0; iw < int(nw); iw++) { for (int iw = 0; iw < int(nw); iw++) {
for (int ih = 0; ih < int(nh); ih++) { for (int ih = 0; ih < int(nh); ih++) {
QGCustomSvg* tile = new QGCustomSvg(); QGCustomSvg* tile = new QGCustomSvg();
if (tile->load(&m_qba)) { if (tile->load(&colorXML)) {
//if (tile->load(&m_svgXML)) {
tile->setParentItem(m_rect); tile->setParentItem(m_rect);
tile->setPos(iw*SVGSIZEW,-h + ih*SVGSIZEH); tile->setPos(iw*SVGSIZEW,-h + ih*SVGSIZEH);
} }
@ -234,6 +241,13 @@ void QGIFace::buildHatch()
} }
//c is a CSS color ie "#000000"
//set hatch color before building hatch
void QGIFace::setHatchColor(std::string c)
{
m_svgCol = c;
}
void QGIFace::resetFill() { void QGIFace::resetFill() {
m_colNormalFill = m_colDefFill; m_colNormalFill = m_colDefFill;
//m_styleCurr = m_styleDef; //m_styleCurr = m_styleDef;

View File

@ -45,6 +45,8 @@ namespace TechDrawGui
const double SVGSIZEW = 64.0; //width and height of standard FC SVG pattern const double SVGSIZEW = 64.0; //width and height of standard FC SVG pattern
const double SVGSIZEH = 64.0; const double SVGSIZEH = 64.0;
const std::string SVGCOLPREFIX = "stroke:";
const std::string SVGCOLDEFAULT = "#000000";
class QGIFace : public QGraphicsPathItem class QGIFace : public QGraphicsPathItem
{ {
@ -71,6 +73,7 @@ public:
void resetFill(void); void resetFill(void);
void setPath(const QPainterPath & path); void setPath(const QPainterPath & path);
void buildHatch(void); void buildHatch(void);
void setHatchColor(std::string c);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
@ -88,7 +91,8 @@ protected:
bool isHighlighted; bool isHighlighted;
QGCustomRect *m_rect; QGCustomRect *m_rect;
QGCustomSvg *m_svg; QGCustomSvg *m_svg;
QByteArray m_qba; QByteArray m_svgXML;
std::string m_svgCol;
private: private:
QPen m_pen; QPen m_pen;

View File

@ -313,6 +313,8 @@ void QGIViewPart::drawViewPart()
TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs); TechDraw::DrawHatch* fHatch = faceIsHatched(i,hatchObjs);
if (fHatch) { if (fHatch) {
if (!fHatch->HatchPattern.isEmpty()) { if (!fHatch->HatchPattern.isEmpty()) {
App::Color hColor = fHatch->HatchColor.getValue();
newFace->setHatchColor(hColor.asCSSString());
newFace->setHatch(fHatch->HatchPattern.getValue()); newFace->setHatch(fHatch->HatchPattern.getValue());
} }
} }