Skip to content

Commit

Permalink
add scale factor property for dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
qcad committed Jul 10, 2013
1 parent 6c38e93 commit 6ac4f7c
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 104 deletions.
102 changes: 0 additions & 102 deletions scripts/File/PrintPreview/PrintPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,6 @@ PrintPreview.setScaleString = function(document, scaleString) {
Print.setScaleString(document, scaleString);

PrintPreview.updateScaleString(document);
// var optionsToolBar = EAction.getOptionsToolBar();
// var scaleCombo = optionsToolBar.findChild("Scale");
// if (Print.getScale(document) != RMath.parseScale(scaleCombo.currentText)) {
// scaleCombo.blockSignals(true);
// scaleCombo.setEditText(scaleString);
// scaleCombo.blockSignals(false);
// }
};

PrintPreview.updateScaleString = function(document) {
Expand Down Expand Up @@ -662,96 +655,19 @@ PrintPreview.prototype.slotPrintCropMarksChanged = function(checked) {
PrintPreview.prototype.slotAutoFitDrawing = function() {
var document = this.getDocument();
Print.autoFitDrawing(document);
/*
var document = this.getDocument();
var paperUnit = Print.getPaperUnit(document);
// drawing bounding box in drawing units:
var bBox = document.getBoundingBox();
// paper bounding box in drawing units, multiplied by scale:
var pBox = this.getPaperBox();
var scale = Print.getScale(document);
// margins in paper unit:
var glueWidth = Print.getGlueMarginLeft(document) + Print.getGlueMarginRight(document);
var glueHeight = Print.getGlueMarginTop(document) + Print.getGlueMarginBottom(document);
glueWidth = RUnit.convert(glueWidth, paperUnit, document.getUnit());
glueHeight = RUnit.convert(glueHeight, paperUnit, document.getUnit());
var wf = undefined;
var hf = undefined;
if (bBox.getWidth()>1.0e-6) {
wf = (pBox.getWidth() * scale - glueWidth) / bBox.getWidth();
}
if (bBox.getHeight()>1.0e-6) {
hf = (pBox.getHeight() * scale - glueHeight) / bBox.getHeight();
}
var f = 1.0;
if (!isNull(wf) && !isNull(hf)) {
f = Math.min(wf, hf);
}
else if (!isNull(wf)) {
f = wf;
}
else if (!isNull(hf)) {
f = hf;
}
if (f<0) {
f = 1.0;
}
*/

//PrintPreview.setScale(document, f);
PrintPreview.updateScaleString(document);

// needed to update pattern scaling according to drawing scale:
var di = this.getDocumentInterface();
di.regenerateScenes();

//this.slotAutoCenter();
this.updateBackgroundTransform();
this.slotAutoZoomToPage();
this.updateBackgroundDecoration();
};

PrintPreview.prototype.slotAutoCenter = function() {
Print.autoCenter(this.getDocument());
/*
var document = this.getDocument();
var paperUnit = Print.getPaperUnit(document);
var glueLeft = Print.getGlueMarginLeft(document);
glueLeft = RUnit.convert(glueLeft, paperUnit, document.getUnit());
var glueRight = Print.getGlueMarginRight(document);
glueRight = RUnit.convert(glueRight, paperUnit, document.getUnit());
var glueTop = Print.getGlueMarginTop(document);
glueTop = RUnit.convert(glueTop, paperUnit, document.getUnit());
var glueBottom = Print.getGlueMarginBottom(document);
glueBottom = RUnit.convert(glueBottom, paperUnit, document.getUnit());
var glueWidth = glueLeft + glueRight;
var glueHeight = glueTop + glueBottom;
var bBox = document.getBoundingBox(false);
if (!bBox.isValid()) {
return;
}
var pBox = this.getPaperBox();
var scale = Print.getScale(document);
var w2 = (pBox.getWidth() - bBox.getWidth()) / 2;
var h2 = (pBox.getHeight() - bBox.getHeight()) / 2;
var dw = (glueRight - glueLeft) / scale;
var dh = (glueTop - glueBottom) / scale;
offset = bBox.getMinimum().operator_subtract(new RVector(w2, h2));
offset = offset.operator_add(new RVector(dw/2, dh/2));
Print.setOffset(document, offset);
*/

this.updateBackgroundTransform();
this.slotAutoZoomToPage();
Expand Down Expand Up @@ -785,24 +701,6 @@ PrintPreview.prototype.slotLandscapeChanged = function() {
*/
PrintPreview.prototype.getPaperBox = function() {
return Print.getPaperBox(this.getDocument());
// var document = this.getDocument();
// var pages = Print.getPages(document);
// var box = new RBox();

// for (var i=0; i<pages.length; ++i) {
// var paperBorder = Print.getPaperBorder(document, pages[i]);
// var paperBorderTransformed = Print.getTransformed(document, paperBorder);

// var paperBox = new RBox(paperBorderTransformed);
// if (!box.isValid()) {
// box = paperBox;
// }
// else {
// box.growToIncludeBox(paperBox);
// }
// }

// return box;
};

PrintPreview.prototype.slotAutoZoomToPage = function() {
Expand Down
4 changes: 2 additions & 2 deletions src/core/RVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
/**
* Version number of the QCAD Application Framework.
*/
#define R_QCAD_VERSION_STRING "3.1.4"
#define R_QCAD_VERSION_STRING "3.1.5"

#define R_QCAD_VERSION_MAJOR 3
#define R_QCAD_VERSION_MINOR 1
#define R_QCAD_VERSION_REV 4
#define R_QCAD_VERSION_REV 5
#define R_QCAD_VERSION_BUILD 0

#endif
1 change: 1 addition & 0 deletions src/entity/RDimAlignedData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,6 @@ QList<QSharedPointer<RShape> > RDimAlignedData::getShapes(const RBox& queryBox)

QString RDimAlignedData::getAutoMeasurement() const {
double distance = extensionPoint1.getDistanceTo(extensionPoint2);
distance *= linearFactor;
return formatLabel(distance);
}
3 changes: 3 additions & 0 deletions src/entity/RDimAlignedEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ RPropertyTypeId RDimAlignedEntity::PropertyMiddleOfTextZ;
RPropertyTypeId RDimAlignedEntity::PropertyText;
RPropertyTypeId RDimAlignedEntity::PropertyUpperTolerance;
RPropertyTypeId RDimAlignedEntity::PropertyLowerTolerance;
RPropertyTypeId RDimAlignedEntity::PropertyLinearFactor;

RPropertyTypeId RDimAlignedEntity::PropertyDimensionLinePosX;
RPropertyTypeId RDimAlignedEntity::PropertyDimensionLinePosY;
Expand Down Expand Up @@ -72,6 +73,8 @@ void RDimAlignedEntity::init() {
RDimAlignedEntity::PropertyUpperTolerance.generateId(typeid(RDimAlignedEntity), RDimensionEntity::PropertyUpperTolerance);
RDimAlignedEntity::PropertyLowerTolerance.generateId(typeid(RDimAlignedEntity), RDimensionEntity::PropertyLowerTolerance);

RDimAlignedEntity::PropertyLinearFactor.generateId(typeid(RDimAlignedEntity), RDimensionEntity::PropertyLinearFactor);

RDimAlignedEntity::PropertyDimensionLinePosX.generateId(typeid(RDimAlignedEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "X"));
RDimAlignedEntity::PropertyDimensionLinePosY.generateId(typeid(RDimAlignedEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "Y"));
RDimAlignedEntity::PropertyDimensionLinePosZ.generateId(typeid(RDimAlignedEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "Z"));
Expand Down
1 change: 1 addition & 0 deletions src/entity/RDimAlignedEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class QCADENTITY_EXPORT RDimAlignedEntity: public RDimensionEntity {
static RPropertyTypeId PropertyText;
static RPropertyTypeId PropertyUpperTolerance;
static RPropertyTypeId PropertyLowerTolerance;
static RPropertyTypeId PropertyLinearFactor;

static RPropertyTypeId PropertyDimensionLinePosX;
static RPropertyTypeId PropertyDimensionLinePosY;
Expand Down
1 change: 1 addition & 0 deletions src/entity/RDimDiametricData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ QList<QSharedPointer<RShape> > RDimDiametricData::getShapes(const RBox& queryBox

QString RDimDiametricData::getAutoMeasurement() const {
double distance = definitionPoint.getDistanceTo(chordPoint);
distance *= linearFactor;
return formatLabel(distance);
}

Expand Down
4 changes: 4 additions & 0 deletions src/entity/RDimDiametricEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ RPropertyTypeId RDimDiametricEntity::PropertyText;
RPropertyTypeId RDimDiametricEntity::PropertyUpperTolerance;
RPropertyTypeId RDimDiametricEntity::PropertyLowerTolerance;

RPropertyTypeId RDimDiametricEntity::PropertyLinearFactor;

RPropertyTypeId RDimDiametricEntity::PropertyChordPointX;
RPropertyTypeId RDimDiametricEntity::PropertyChordPointY;
RPropertyTypeId RDimDiametricEntity::PropertyChordPointZ;
Expand Down Expand Up @@ -72,6 +74,8 @@ void RDimDiametricEntity::init() {
RDimDiametricEntity::PropertyUpperTolerance.generateId(typeid(RDimDiametricEntity), RDimensionEntity::PropertyUpperTolerance);
RDimDiametricEntity::PropertyLowerTolerance.generateId(typeid(RDimDiametricEntity), RDimensionEntity::PropertyLowerTolerance);

RDimDiametricEntity::PropertyLinearFactor.generateId(typeid(RDimDiametricEntity), RDimensionEntity::PropertyLinearFactor);

RDimDiametricEntity::PropertyChordPointX.generateId(typeid(RDimDiametricEntity), QT_TRANSLATE_NOOP("REntity", "Chord Point"), QT_TRANSLATE_NOOP("REntity", "X"));
RDimDiametricEntity::PropertyChordPointY.generateId(typeid(RDimDiametricEntity), QT_TRANSLATE_NOOP("REntity", "Chord Point"), QT_TRANSLATE_NOOP("REntity", "Y"));
RDimDiametricEntity::PropertyChordPointZ.generateId(typeid(RDimDiametricEntity), QT_TRANSLATE_NOOP("REntity", "Chord Point"), QT_TRANSLATE_NOOP("REntity", "Z"));
Expand Down
2 changes: 2 additions & 0 deletions src/entity/RDimDiametricEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class QCADENTITY_EXPORT RDimDiametricEntity: public RDimensionEntity {
static RPropertyTypeId PropertyUpperTolerance;
static RPropertyTypeId PropertyLowerTolerance;

static RPropertyTypeId PropertyLinearFactor;

static RPropertyTypeId PropertyChordPointX;
static RPropertyTypeId PropertyChordPointY;
static RPropertyTypeId PropertyChordPointZ;
Expand Down
4 changes: 4 additions & 0 deletions src/entity/RDimLinearEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ RPropertyTypeId RDimLinearEntity::PropertyText;
RPropertyTypeId RDimLinearEntity::PropertyUpperTolerance;
RPropertyTypeId RDimLinearEntity::PropertyLowerTolerance;

RPropertyTypeId RDimLinearEntity::PropertyLinearFactor;

RPropertyTypeId RDimLinearEntity::PropertyDimensionLinePosX;
RPropertyTypeId RDimLinearEntity::PropertyDimensionLinePosY;
RPropertyTypeId RDimLinearEntity::PropertyDimensionLinePosZ;
Expand Down Expand Up @@ -72,6 +74,8 @@ void RDimLinearEntity::init() {
RDimLinearEntity::PropertyUpperTolerance.generateId(typeid(RDimLinearEntity), RDimensionEntity::PropertyUpperTolerance);
RDimLinearEntity::PropertyLowerTolerance.generateId(typeid(RDimLinearEntity), RDimensionEntity::PropertyLowerTolerance);

RDimLinearEntity::PropertyLinearFactor.generateId(typeid(RDimLinearEntity), RDimensionEntity::PropertyLinearFactor);

RDimLinearEntity::PropertyDimensionLinePosX.generateId(typeid(RDimLinearEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "X"));
RDimLinearEntity::PropertyDimensionLinePosY.generateId(typeid(RDimLinearEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "Y"));
RDimLinearEntity::PropertyDimensionLinePosZ.generateId(typeid(RDimLinearEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "Z"));
Expand Down
2 changes: 2 additions & 0 deletions src/entity/RDimLinearEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class QCADENTITY_EXPORT RDimLinearEntity: public RDimensionEntity {
static RPropertyTypeId PropertyUpperTolerance;
static RPropertyTypeId PropertyLowerTolerance;

static RPropertyTypeId PropertyLinearFactor;

static RPropertyTypeId PropertyDimensionLinePosX;
static RPropertyTypeId PropertyDimensionLinePosY;
static RPropertyTypeId PropertyDimensionLinePosZ;
Expand Down
1 change: 1 addition & 0 deletions src/entity/RDimRadialData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,6 @@ QList<QSharedPointer<RShape> > RDimRadialData::getShapes(const RBox& queryBox) c

QString RDimRadialData::getAutoMeasurement() const {
double distance = definitionPoint.getDistanceTo(chordPoint);
distance *= linearFactor;
return formatLabel(distance);
}
4 changes: 4 additions & 0 deletions src/entity/RDimRadialEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ RPropertyTypeId RDimRadialEntity::PropertyText;
RPropertyTypeId RDimRadialEntity::PropertyUpperTolerance;
RPropertyTypeId RDimRadialEntity::PropertyLowerTolerance;

RPropertyTypeId RDimRadialEntity::PropertyLinearFactor;

RPropertyTypeId RDimRadialEntity::PropertyCenterPointX;
RPropertyTypeId RDimRadialEntity::PropertyCenterPointY;
RPropertyTypeId RDimRadialEntity::PropertyCenterPointZ;
Expand Down Expand Up @@ -70,6 +72,8 @@ void RDimRadialEntity::init() {
RDimRadialEntity::PropertyUpperTolerance.generateId(typeid(RDimRadialEntity), RDimensionEntity::PropertyUpperTolerance);
RDimRadialEntity::PropertyLowerTolerance.generateId(typeid(RDimRadialEntity), RDimensionEntity::PropertyLowerTolerance);

RDimRadialEntity::PropertyLinearFactor.generateId(typeid(RDimRadialEntity), RDimensionEntity::PropertyLinearFactor);

RDimRadialEntity::PropertyCenterPointX.generateId(typeid(RDimRadialEntity), QT_TRANSLATE_NOOP("REntity", "Center"), QT_TRANSLATE_NOOP("REntity", "X"), true);
RDimRadialEntity::PropertyCenterPointY.generateId(typeid(RDimRadialEntity), QT_TRANSLATE_NOOP("REntity", "Center"), QT_TRANSLATE_NOOP("REntity", "Y"), true);
RDimRadialEntity::PropertyCenterPointZ.generateId(typeid(RDimRadialEntity), QT_TRANSLATE_NOOP("REntity", "Center"), QT_TRANSLATE_NOOP("REntity", "Z"), true);
Expand Down
2 changes: 2 additions & 0 deletions src/entity/RDimRadialEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class QCADENTITY_EXPORT RDimRadialEntity: public RDimensionEntity {
static RPropertyTypeId PropertyUpperTolerance;
static RPropertyTypeId PropertyLowerTolerance;

static RPropertyTypeId PropertyLinearFactor;

static RPropertyTypeId PropertyCenterPointX;
static RPropertyTypeId PropertyCenterPointY;
static RPropertyTypeId PropertyCenterPointZ;
Expand Down
1 change: 1 addition & 0 deletions src/entity/RDimRotatedData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ QString RDimRotatedData::getAutoMeasurement() const {

// Definitive dimension line:
double distance = dimP1.getDistanceTo(dimP2);
distance *= linearFactor;

return formatLabel(distance);
}
4 changes: 4 additions & 0 deletions src/entity/RDimRotatedEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ RPropertyTypeId RDimRotatedEntity::PropertyText;
RPropertyTypeId RDimRotatedEntity::PropertyUpperTolerance;
RPropertyTypeId RDimRotatedEntity::PropertyLowerTolerance;

RPropertyTypeId RDimRotatedEntity::PropertyLinearFactor;

RPropertyTypeId RDimRotatedEntity::PropertyDimensionLinePosX;
RPropertyTypeId RDimRotatedEntity::PropertyDimensionLinePosY;
RPropertyTypeId RDimRotatedEntity::PropertyDimensionLinePosZ;
Expand Down Expand Up @@ -76,6 +78,8 @@ void RDimRotatedEntity::init() {
RDimRotatedEntity::PropertyUpperTolerance.generateId(typeid(RDimRotatedEntity), RDimensionEntity::PropertyUpperTolerance);
RDimRotatedEntity::PropertyLowerTolerance.generateId(typeid(RDimRotatedEntity), RDimensionEntity::PropertyLowerTolerance);

RDimRotatedEntity::PropertyLinearFactor.generateId(typeid(RDimRotatedEntity), RDimensionEntity::PropertyLinearFactor);

RDimRotatedEntity::PropertyDimensionLinePosX.generateId(typeid(RDimRotatedEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "X"));
RDimRotatedEntity::PropertyDimensionLinePosY.generateId(typeid(RDimRotatedEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "Y"));
RDimRotatedEntity::PropertyDimensionLinePosZ.generateId(typeid(RDimRotatedEntity), QT_TRANSLATE_NOOP("REntity", "Dimension Line"), QT_TRANSLATE_NOOP("REntity", "Z"));
Expand Down
2 changes: 2 additions & 0 deletions src/entity/RDimRotatedEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class QCADENTITY_EXPORT RDimRotatedEntity: public RDimensionEntity {
static RPropertyTypeId PropertyUpperTolerance;
static RPropertyTypeId PropertyLowerTolerance;

static RPropertyTypeId PropertyLinearFactor;

static RPropertyTypeId PropertyDimensionLinePosX;
static RPropertyTypeId PropertyDimensionLinePosY;
static RPropertyTypeId PropertyDimensionLinePosZ;
Expand Down
1 change: 1 addition & 0 deletions src/entity/RDimensionData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ RDimensionData::RDimensionData(RDocument* document) :
lineSpacingFactor(1.0),
defaultAngle(RNANDOUBLE),
textAngle(0.0),
linearFactor(1.0),
dirty(true),
dimLineLength(0.0),
autoTextPos(true) {
Expand Down
10 changes: 10 additions & 0 deletions src/entity/RDimensionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ class QCADENTITY_EXPORT RDimensionData: public REntityData {
return fontName;
}

double getLinearFactor() const {
return linearFactor;
}

void setLinearFactor(double f) {
linearFactor = f;
}

virtual double getDistanceTo(const RVector& point, bool limited = true, double range = 0.0, bool draft = false) const;
virtual bool intersectsWith(const RShape& shape) const;

Expand Down Expand Up @@ -193,6 +201,8 @@ class QCADENTITY_EXPORT RDimensionData: public REntityData {
/** Rotation angle of dimension text away from default orientation */
double textAngle;

double linearFactor;

mutable bool dirty;
mutable RTextData textData;
mutable RBox boundingBox;
Expand Down
5 changes: 5 additions & 0 deletions src/entity/RDimensionEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ RPropertyTypeId RDimensionEntity::PropertyMiddleOfTextZ;
RPropertyTypeId RDimensionEntity::PropertyText;
RPropertyTypeId RDimensionEntity::PropertyUpperTolerance;
RPropertyTypeId RDimensionEntity::PropertyLowerTolerance;
RPropertyTypeId RDimensionEntity::PropertyLinearFactor;
//RPropertyTypeId RDimensionEntity::PropertyFontName;
//RPropertyTypeId RDimensionEntity::PropertyHeight;
//RPropertyTypeId RDimensionEntity::PropertyAngle;
Expand Down Expand Up @@ -83,6 +84,7 @@ void RDimensionEntity::init() {
// RDimensionEntity::PropertyVAlign.generateId(typeid(RDimensionEntity), QT_TRANSLATE_NOOP("REntity", "Alignment"), QT_TRANSLATE_NOOP("REntity", "Vertical"));

RDimensionEntity::PropertyMeasuredValue.generateId(typeid(RDimensionEntity), "", QT_TRANSLATE_NOOP("REntity", "Measured Value"));
RDimensionEntity::PropertyLinearFactor.generateId(typeid(RDimensionEntity), "", QT_TRANSLATE_NOOP("REntity", "Linear Factor"));
}

bool RDimensionEntity::setProperty(RPropertyTypeId propertyTypeId,
Expand Down Expand Up @@ -113,6 +115,7 @@ bool RDimensionEntity::setProperty(RPropertyTypeId propertyTypeId,
ret = ret || RObject::setMember(getData().text, value, PropertyText == propertyTypeId);
ret = ret || RObject::setMember(getData().upperTolerance, value, PropertyUpperTolerance == propertyTypeId);
ret = ret || RObject::setMember(getData().lowerTolerance, value, PropertyLowerTolerance == propertyTypeId);
ret = ret || RObject::setMember(getData().linearFactor, value, PropertyLinearFactor == propertyTypeId);
// ret = ret || RObject::setMember(getData().fontName, value, PropertyFontName == propertyTypeId);
// ret = ret || RObject::setMember(getData().textHeight, value, PropertyHeight == propertyTypeId);
// ret = ret || RObject::setMember(getData().angle, value, PropertyAngle == propertyTypeId);
Expand Down Expand Up @@ -177,6 +180,8 @@ QPair<QVariant, RPropertyAttributes> RDimensionEntity::getProperty(
return qMakePair(QVariant(getData().getAutoMeasurement()),
RPropertyAttributes(RPropertyAttributes::ReadOnly));
}
} else if (propertyTypeId == PropertyLinearFactor) {
return qMakePair(QVariant(getData().linearFactor), RPropertyAttributes());
}

/*else if (propertyTypeId == PropertyFontName) {
Expand Down
Loading

0 comments on commit 6ac4f7c

Please sign in to comment.