Skip to content

Commit

Permalink
Basic working HiResolution TD
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Jan 30, 2017
1 parent 8ed62e3 commit f68cbc8
Show file tree
Hide file tree
Showing 17 changed files with 514 additions and 209 deletions.
51 changes: 33 additions & 18 deletions src/Mod/TechDraw/App/DrawViewSymbol.cpp
Expand Up @@ -35,6 +35,7 @@
#include <Base/FileInfo.h>
#include <Base/Console.h>

#include "DrawPage.h"
#include "DrawViewSymbol.h"

using namespace TechDraw;
Expand Down Expand Up @@ -117,30 +118,44 @@ App::DocumentObjectExecReturn *DrawViewSymbol::execute(void)

QRectF DrawViewSymbol::getRect() const
{
std::string svg = Symbol.getValue();
double w = 64.0; //must default to something
double h = 64.0;
string::const_iterator begin, end;
begin = svg.begin();
end = svg.end();
boost::match_results<std::string::const_iterator> what;
return (QRectF(0,0,w,h));
// std::string svg = Symbol.getValue();
// string::const_iterator begin, end;
// begin = svg.begin();
// end = svg.end();
// boost::match_results<std::string::const_iterator> what;

// boost::regex e1 ("width=\"([0-9.]*?)[a-zA-Z]*?\"");
// if (boost::regex_search(begin, end, what, e1)) {
// //std::string wText = what[0].str(); //this is the whole match 'width="100"'
// std::string wNum = what[1].str(); //this is just the number 100
// w = std::stod(wNum);
// }
//
// boost::regex e2 ("height=\"([0-9.]*?)[a-zA-Z]*?\"");
// if (boost::regex_search(begin, end, what, e2)) {
// //std::string hText = what[0].str();
// std::string hNum = what[1].str();
// h = std::stod(hNum);
// }
// return (QRectF(0,0,Scale.getValue() * w,Scale.getValue() * h));
//we now have a w x h, but we don't really know what it means - px,mm,in,...

}

boost::regex e1 ("width=\"([0-9.]*?)[a-zA-Z]*?\"");
if (boost::regex_search(begin, end, what, e1)) {
//std::string wText = what[0].str(); //this is the whole match 'width="100"'
std::string wNum = what[1].str(); //this is just the number 100
w = std::stod(wNum);
}
boost::regex e2 ("Height=\"([0-9.]*?)[a-zA-Z]*?\"");
if (boost::regex_search(begin, end, what, e1)) {
//std::string hText = what[0].str();
std::string hNum = what[1].str();
h = std::stod(hNum);
}
return (QRectF(0,0,Scale.getValue() * w,Scale.getValue() * h));
//!Assume all svg files fit the page and/or the user will scale manually
//see getRect() above
bool DrawViewSymbol::checkFit(TechDraw::DrawPage* p) const
{
(void)p;
bool result = true;
return result;
}



// Python Drawing feature ---------------------------------------------------------

namespace App {
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/TechDraw/App/DrawViewSymbol.h
Expand Up @@ -32,6 +32,7 @@

namespace TechDraw
{
class DrawPage;


class TechDrawExport DrawViewSymbol : public TechDraw::DrawView
Expand All @@ -57,6 +58,8 @@ class TechDrawExport DrawViewSymbol : public TechDraw::DrawView
return "TechDrawGui::ViewProviderSymbol";
}
virtual QRectF getRect() const;
virtual bool checkFit(TechDraw::DrawPage* p) const override;


protected:
virtual void onChanged(const App::Property* prop);
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/Gui/CMakeLists.txt
Expand Up @@ -94,6 +94,8 @@ SET(TechDrawGui_SRCS
TaskSectionView.h
DrawGuiUtil.cpp
DrawGuiUtil.h
Rez.cpp
Rez.h
)
SET(TechDrawGuiView_SRCS
MDIViewPage.cpp
Expand Down
13 changes: 7 additions & 6 deletions src/Mod/TechDraw/Gui/MDIViewPage.cpp
Expand Up @@ -77,6 +77,7 @@
#include <Mod/TechDraw/App/DrawViewSymbol.h>
#include <Mod/TechDraw/App/DrawViewImage.h>

#include "Rez.h"
#include "QGIDrawingTemplate.h"
#include "QGIView.h"
#include "QGIViewPart.h"
Expand Down Expand Up @@ -169,8 +170,8 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget*
auto pageTemplate( dynamic_cast<TechDraw::DrawTemplate *>(obj) );
if( pageTemplate ) {
//make sceneRect 1 pagesize bigger in every direction
double width = pageTemplate->Width.getValue();
double height = pageTemplate->Height.getValue();
double width = Rez::guiX(pageTemplate->Width.getValue());
double height = Rez::guiX(pageTemplate->Height.getValue());
m_view->scene()->setSceneRect(QRectF(-width,-2.0 * height,3.0*width,3.0*height));
attachTemplate(pageTemplate);
viewAll();
Expand Down Expand Up @@ -254,8 +255,8 @@ void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj)

QPointF MDIViewPage::getTemplateCenter(TechDraw::DrawTemplate *obj)
{
double cx = obj->Width.getValue()/2.0;
double cy = -obj->Height.getValue()/2.0;
double cx = Rez::guiX(obj->Width.getValue())/2.0;
double cy = -Rez::guiX(obj->Height.getValue())/2.0;
QPointF result(cx,cy);
return result;
}
Expand Down Expand Up @@ -731,8 +732,8 @@ void MDIViewPage::print(QPrinter* printer)
double width = 0.0;
double height = 0.0;
if( pageTemplate ) {
width = pageTemplate->Width.getValue();
height = pageTemplate->Height.getValue();
width = Rez::guiX(pageTemplate->Width.getValue());
height = Rez::guiX(pageTemplate->Height.getValue());
}
QRectF sourceRect(0.0,-height,width,height);

Expand Down
82 changes: 62 additions & 20 deletions src/Mod/TechDraw/Gui/QGIArrow.cpp
Expand Up @@ -32,6 +32,11 @@
#include <QPainter>
#endif

#include <App/Application.h>
#include <Base/Parameter.h>
#include <Base/Console.h>

#include "Rez.h"
#include "QGIArrow.h"

using namespace TechDrawGui;
Expand All @@ -56,46 +61,83 @@ void QGIArrow::flip(bool state) {
}

void QGIArrow::draw() {
// the center is the end point on a dimension
QPainterPath path;
//QPen pen(Qt::black);
//pen.setWidth(1);
if (m_style == 0) {
path = makeFilledTriangle(m_size,m_size/6.0,isFlipped); //"arrow l/w sb 3/1" ??
} else if (m_style == 1) {
path = makeOpenArrow(m_size,m_size/3.0,isFlipped); //broad arrow?
} else if (m_style == 2) {
path = makeHashMark(m_size/2.0,m_size/2.0,isFlipped); //big enough?
}
setPath(path);
}

//QBrush brush(Qt::black);
//setPen(pen);
//setBrush(brush);
void QGIArrow::setSize(double s)
{
m_size = s;
}

float length = -m_size; //TODO: Arrow heads sb preference? size & type?

if(isFlipped)
QPainterPath QGIArrow::makeFilledTriangle(double length, double width, bool flipped)
{
//(0,0) is tip of arrow
if (!flipped) {
length *= -1;
}

QPainterPath path;
path.moveTo(QPointF(0.,0.));
path.lineTo(QPointF(length,-0.6));
path.lineTo(QPointF(length, 0.6));

path.lineTo(QPointF(Rez::guiX(length),Rez::guiX(-width)));
path.lineTo(QPointF(Rez::guiX(length),Rez::guiX(width)));
path.closeSubpath();
// path.moveTo(QPointF(-1,1));
// path.lineTo(QPointF(1,-1));
setPath(path);
m_fill = Qt::SolidPattern;
return path;
}

void QGIArrow::setSize(double s)
QPainterPath QGIArrow::makeOpenArrow(double length, double width, bool flipped)
{
m_size = s;
//???
//(0,0) is tip of arrow
if (!flipped) {
length *= -1;
}

QPainterPath path;
path.moveTo(QPointF(Rez::guiX(length),Rez::guiX(-width)));
path.lineTo(QPointF(0.,0.));
path.lineTo(QPointF(Rez::guiX(length),Rez::guiX(width)));
m_fill = Qt::NoBrush;
return path;
}

QPainterPath QGIArrow::makeHashMark(double length, double width, bool flipped)
{
double adjWidth = 1.0;
//(0,0) is tip of arrow
if (!flipped) {
length *= -1;
adjWidth *= -1;
}
QPainterPath path;
path.moveTo(QPointF(Rez::guiX(length),Rez::guiX(adjWidth * (-width))));
path.lineTo(QPointF(Rez::guiX(-length),Rez::guiX(adjWidth * width)));
m_fill = Qt::NoBrush;
return path;
}

void QGIArrow::setStyle(int s)
int QGIArrow::getPrefArrowStyle()
{
m_style = s;
//???
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
int style = hGrp->GetInt("ArrowStyle", 0);
return style;
}

void QGIArrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;

setPen(m_pen);
m_brush.setColor(m_colCurrent);
m_brush.setStyle(m_fill);
setBrush(m_brush);
Expand Down
9 changes: 7 additions & 2 deletions src/Mod/TechDraw/Gui/QGIArrow.h
Expand Up @@ -49,13 +49,18 @@ class TechDrawGuiExport QGIArrow : public QGIPrimPath
double getSize() { return m_size; }
void setSize(double s);
int getStyle() { return m_style; }
void setStyle(int s);
void setStyle(int s) { m_style = s; }
//QPainterPath shape() const;
static int getPrefArrowStyle();

virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );

protected:
//QVariant itemChange(GraphicsItemChange change, const QVariant &value);

QPainterPath makeFilledTriangle(double length, double width, bool flipped);
QPainterPath makeOpenArrow(double length, double width, bool flipped);
QPainterPath makeHashMark(double length, double width, bool flipped);

private:
QBrush m_brush;
Qt::BrushStyle m_fill;
Expand Down
15 changes: 8 additions & 7 deletions src/Mod/TechDraw/Gui/QGISVGTemplate.cpp
Expand Up @@ -40,6 +40,7 @@
#include <Mod/TechDraw/App/Geometry.h>
#include <Mod/TechDraw/App/DrawSVGTemplate.h>

#include "Rez.h"
#include "ZVALUE.h"
#include "TemplateTextField.h"
#include "QGISVGTemplate.h"
Expand Down Expand Up @@ -100,15 +101,15 @@ void QGISVGTemplate::load(const QString &fileName)
firstTime = false;
}

//This is probably first time only logic too.
//convert from pixels or mm or inches in svg file to mm page size
TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate();
double xaspect, yaspect;
xaspect = tmplte->getWidth() / (double) size.width();
yaspect = tmplte->getHeight() / (double) size.height();

QTransform qtrans;
qtrans.translate(0.f, -tmplte->getHeight());
qtrans.scale(xaspect , yaspect);
qtrans.translate(0.f, Rez::guiX(-tmplte->getHeight()));
qtrans.scale(Rez::guiX(xaspect) , Rez::guiX(yaspect));
m_svgItem->setTransform(qtrans);
}

Expand Down Expand Up @@ -190,19 +191,19 @@ void QGISVGTemplate::createClickHandles(void)
QString yStr = QString::fromStdString(yMatch[1].str());
QString editableName = QString::fromStdString(nameMatch[1].str());

double x = xStr.toDouble();
double y = yStr.toDouble();
double x = Rez::guiX(xStr.toDouble());
double y = Rez::guiX(yStr.toDouble());

//TODO: this should probably be configurable without a code change
double editClickBoxSize = 1.5;
double editClickBoxSize = Rez::guiX(1.5);
QColor editClickBoxColor = Qt::green;

double width = editClickBoxSize;
double height = editClickBoxSize;

TemplateTextField *item = new TemplateTextField(this, tmplte, nameMatch[1].str(), qgview);
float pad = 1;
item->setRect(x - pad, -tmplte->getHeight() + y - height - pad,
item->setRect(x - pad, Rez::guiX(-tmplte->getHeight()) + y - height - pad,
width + 2 * pad, height + 2 * pad);

QPen myPen;
Expand Down
15 changes: 12 additions & 3 deletions src/Mod/TechDraw/Gui/QGISectionLine.cpp
Expand Up @@ -33,14 +33,15 @@
#include <Base/Parameter.h>

#include <qmath.h>
#include "Rez.h"
#include "QGIView.h"
#include "QGISectionLine.h"

using namespace TechDrawGui;

QGISectionLine::QGISectionLine()
{
m_extLen = 8.0;
m_extLen = Rez::guiX(8.0);
m_arrowSize = 0.0;

m_line = new QGraphicsPathItem();
Expand All @@ -54,7 +55,7 @@ QGISectionLine::QGISectionLine()
m_symbol2 = new QGCustomText();
addToGroup(m_symbol2);

setWidth(0.75);
setWidth(Rez::guiX(0.75));
setStyle(getSectionStyle());
setColor(getSectionColor());

Expand All @@ -74,7 +75,7 @@ void QGISectionLine::makeLine()
QPainterPath pp;
QPointF extLineStart,extLineEnd;
QPointF offset(m_arrowDir.x,-m_arrowDir.y);
offset = 0.80 * m_extLen * offset; //0.80 is hack to hide line end behind arrowhead
offset = 0.75 * m_extLen * offset; //0.75 is hack to hide line end behind arrowhead
extLineStart = m_start + offset;
extLineEnd = m_end + offset;
pp.moveTo(extLineStart);
Expand All @@ -100,6 +101,8 @@ void QGISectionLine::makeArrows()
extLineStart = m_start + offset;
extLineEnd = m_end + offset;

m_arrow1->setStyle(0);
m_arrow2->setStyle(0);
m_arrow1->setPos(extLineStart);
//m_arrow1->flip(true);
m_arrow1->draw();
Expand All @@ -121,9 +124,15 @@ void QGISectionLine::makeSymbols()
m_symFont.setPointSize(m_symSize);
m_symbol1->setFont(m_symFont);
m_symbol1->setPlainText(QString::fromUtf8(m_symbol));
if (m_arrowDir.y < 0.0) { //pointing down
extLineStart -= QPointF (0.0,m_symSize); //move text up a bit
}
m_symbol1->centerAt(extLineStart);
m_symbol2->setFont(m_symFont);
m_symbol2->setPlainText(QString::fromUtf8(m_symbol));
if (m_arrowDir.y < 0.0) { //pointing down
extLineEnd -= QPointF (0.0,m_symSize);
}
m_symbol2->centerAt(extLineEnd);
}

Expand Down

0 comments on commit f68cbc8

Please sign in to comment.