Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #4271 from donovaly/TD-dimension-dialog
[TD] add dialog to modify some dimension settings
  • Loading branch information
yorikvanhavre committed Jan 18, 2021
2 parents 8a1bd9d + fc91b25 commit 6719e86
Show file tree
Hide file tree
Showing 10 changed files with 861 additions and 62 deletions.
18 changes: 9 additions & 9 deletions src/Mod/TechDraw/App/DrawViewDimension.cpp
Expand Up @@ -101,7 +101,7 @@ const char* DrawViewDimension::MeasureTypeEnums[]= {"True",
// constraint to set the step size to 0.1
static const App::PropertyQuantityConstraint::Constraints ToleranceConstraint = { -DBL_MAX, DBL_MAX, 0.1 };
// constraint to force positive values
static const App::PropertyQuantityConstraint::Constraints PositiveConstraint = { DBL_MIN, DBL_MAX, 0.1 };
static const App::PropertyQuantityConstraint::Constraints PositiveConstraint = { 0.0, DBL_MAX, 0.1 };

DrawViewDimension::DrawViewDimension(void)
{
Expand All @@ -119,18 +119,18 @@ DrawViewDimension::DrawViewDimension(void)
ADD_PROPERTY(Type, ((long)0));
MeasureType.setEnums(MeasureTypeEnums);
ADD_PROPERTY(MeasureType, ((long)1)); //Projected (or True) measurement
ADD_PROPERTY_TYPE(TheoreticalExact,(false), "", App::Prop_Output, "Set for theoretical exact (basic) dimension");
ADD_PROPERTY_TYPE(TheoreticalExact,(false), "", App::Prop_Output, "If theoretical exact (basic) dimension");
ADD_PROPERTY_TYPE(EqualTolerance, (true), "", App::Prop_Output, "If over- and undertolerance are equal");

ADD_PROPERTY_TYPE(OverTolerance, (0.0), "", App::Prop_Output, "Overtolerance value\nIf 'Equal Tolerance' is true this is also the value for 'Under Tolerance'");
ADD_PROPERTY_TYPE(OverTolerance, (0.0), "", App::Prop_Output, "Overtolerance value\nIf 'Equal Tolerance' is true this is also\nthe negated value for 'Under Tolerance'");
OverTolerance.setUnit(Base::Unit::Length);
OverTolerance.setConstraints(&ToleranceConstraint);
ADD_PROPERTY_TYPE(UnderTolerance, (0.0), "", App::Prop_Output, "Undertolerance value\nIf 'Equal Tolerance' it will be replaced by negative value of 'Over Tolerance'");
ADD_PROPERTY_TYPE(UnderTolerance, (0.0), "", App::Prop_Output, "Undertolerance value\nIf 'Equal Tolerance' is true it will be replaced\nby negative value of 'Over Tolerance'");
UnderTolerance.setUnit(Base::Unit::Length);
UnderTolerance.setConstraints(&ToleranceConstraint);
ADD_PROPERTY_TYPE(Inverted, (false), "", App::Prop_Output, "The dimensional value is displayed inverted");

//hide the DrawView properties that don't apply to Dimensions
// hide the DrawView properties that don't apply to Dimensions
ScaleType.setStatus(App::Property::ReadOnly, true);
ScaleType.setStatus(App::Property::Hidden, true);
Scale.setStatus(App::Property::ReadOnly, true);
Expand Down Expand Up @@ -183,7 +183,7 @@ void DrawViewDimension::onChanged(const App::Property* prop)
}
else if (prop == &References3D) { //have to rebuild the Measurement object
// Base::Console().Message("DVD::onChanged - References3D\n");
clear3DMeasurements(); //Measurement object
clear3DMeasurements(); //Measurement object
if (!(References3D.getValues()).empty()) {
setAll3DMeasurement();
} else {
Expand Down Expand Up @@ -224,9 +224,9 @@ void DrawViewDimension::onChanged(const App::Property* prop)
// if EqualTolerance set negated overtolerance for untertolerance
// then also the OverTolerance must be positive
if (EqualTolerance.getValue()) {
// if OverTolerance is negative or zero, first set it to smallest positive value
if (OverTolerance.getValue() <= 0) {
OverTolerance.setValue(DBL_MIN);
// if OverTolerance is negative or zero, first set it to zero
if (OverTolerance.getValue() < 0) {
OverTolerance.setValue(0.0);
}
OverTolerance.setConstraints(&PositiveConstraint);
UnderTolerance.setValue(-1.0 * OverTolerance.getValue());
Expand Down
94 changes: 50 additions & 44 deletions src/Mod/TechDraw/Gui/CMakeLists.txt
Expand Up @@ -35,47 +35,48 @@ set(TechDrawGui_LIBS
)

set(TechDrawGui_MOC_HDRS
DlgPrefsTechDrawAdvancedImp.h
DlgPrefsTechDrawAnnotationImp.h
DlgPrefsTechDrawColorsImp.h
DlgPrefsTechDrawDimensionsImp.h
DlgPrefsTechDrawGeneralImp.h
DlgPrefsTechDrawHLRImp.h
DlgPrefsTechDrawScaleImp.h
DlgTemplateField.h
MDIViewPage.h
QGVPage.h
mrichtextedit.h
mtextedit.h
QGEPath.h
QGIDrawingTemplate.h
QGIGhostHighlight.h
QGILeaderLine.h
QGIRichAnno.h
QGITemplate.h
QGISVGTemplate.h
QGIDrawingTemplate.h
QGIView.h
QGIViewDimension.h
QGIViewBalloon.h
TaskProjGroup.h
DlgPrefsTechDrawGeneralImp.h
DlgPrefsTechDrawScaleImp.h
DlgPrefsTechDrawAnnotationImp.h
DlgPrefsTechDrawDimensionsImp.h
DlgPrefsTechDrawColorsImp.h
DlgPrefsTechDrawAdvancedImp.h
DlgPrefsTechDrawHLRImp.h
TaskLinkDim.h
DlgTemplateField.h
TaskSectionView.h
QGIWeldSymbol.h
QGMText.h
QGTracker.h
QGVPage.h
TaskActiveView.h
TaskBalloon.h
TaskCenterLine.h
TaskCosmeticLine.h
TaskCosVertex.h
TaskDetail.h
TaskDimension.h
TaskGeomHatch.h
TaskHatch.h
TaskLeaderLine.h
TaskRichAnno.h
TaskCosVertex.h
TaskCenterLine.h
TaskLinkDim.h
TaskLineDecor.h
TaskProjGroup.h
TaskRichAnno.h
TaskSectionView.h
TaskWeldingSymbol.h
QGEPath.h
QGTracker.h
QGILeaderLine.h
QGIRichAnno.h
QGMText.h
mrichtextedit.h
mtextedit.h
TaskBalloon.h
QGIWeldSymbol.h
SymbolChooser.h
TaskActiveView.h
TaskDetail.h
QGIGhostHighlight.h
TaskCosmeticLine.h
SymbolChooser.h
)

fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS})
Expand All @@ -88,32 +89,33 @@ else()
endif()

set(TechDrawGui_UIC_SRCS
DlgPrefsTechDrawGeneral.ui
DlgPrefsTechDrawScale.ui
DlgPrefsTechDrawAdvanced.ui
DlgPrefsTechDrawAnnotation.ui
DlgPrefsTechDrawDimensions.ui
DlgPrefsTechDrawColors.ui
DlgPrefsTechDrawAdvanced.ui
DlgPrefsTechDrawDimensions.ui
DlgPrefsTechDrawGeneral.ui
DlgPrefsTechDrawHLR.ui
TaskProjGroup.ui
TaskLinkDim.ui
DlgPrefsTechDrawScale.ui
DlgTemplateField.ui
TaskSectionView.ui
TaskGeomHatch.ui
TaskHatch.ui
TaskLeaderLine.ui
TaskRichAnno.ui
mrichtextedit.ui
TaskActiveView.ui
TaskBalloon.ui
TaskCosmeticLine.ui
TaskCosVertex.ui
TaskCenterLine.ui
TaskDetail.ui
TaskDimension.ui
TaskGeomHatch.ui
TaskHatch.ui
TaskLeaderLine.ui
TaskLineDecor.ui
TaskLinkDim.ui
TaskProjGroup.ui
TaskRestoreLines.ui
TaskRichAnno.ui
TaskSectionView.ui
TaskWeldingSymbol.ui
SymbolChooser.ui
TaskActiveView.ui
TaskDetail.ui
TaskCosmeticLine.ui
)

if(BUILD_QT5)
Expand Down Expand Up @@ -186,6 +188,9 @@ SET(TechDrawGui_SRCS
TaskBalloon.ui
TaskBalloon.cpp
TaskBalloon.h
TaskDimension.ui
TaskDimension.cpp
TaskDimension.h
TaskGeomHatch.ui
TaskGeomHatch.cpp
TaskGeomHatch.h
Expand Down Expand Up @@ -392,6 +397,7 @@ SET(TechDrawGuiTaskDlgs_SRCS
mrichtextedit.ui
TaskBalloon.ui
TaskCenterLine.ui
TaskDimension.ui
TaskLineDecor.ui
TaskRestoreLines.ui
TaskWeldingSymbol.ui
Expand Down
26 changes: 22 additions & 4 deletions src/Mod/TechDraw/Gui/QGIViewDimension.cpp
Expand Up @@ -52,6 +52,7 @@
#include <Base/Parameter.h>
#include <Base/UnitsApi.h>
#include <Gui/Command.h>
#include <Gui/Control.h>

#include <Mod/Part/App/PartFeature.h>

Expand All @@ -75,6 +76,7 @@
#include "QGIViewDimension.h"
#include "ViewProviderDimension.h"
#include "DrawGuiUtil.h"
#include "TaskDimension.h"

#define NORMAL 0
#define PRE 1
Expand Down Expand Up @@ -169,6 +171,20 @@ void QGIDatumLabel::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
QGraphicsItem::mouseReleaseEvent(event);
}

void QGIDatumLabel::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
{
QGIViewDimension* qgivDimension = dynamic_cast<QGIViewDimension*>(parentItem());
if (qgivDimension == nullptr) {
return;
}
auto ViewProvider = static_cast<ViewProviderDimension*>(qgivDimension->getViewProvider(qgivDimension->getViewObject()));
if (ViewProvider == nullptr) {
return;
}
Gui::Control().showDialog(new TaskDlgDimension(qgivDimension, ViewProvider));
QGraphicsItem::mouseDoubleClickEvent(event);
}

void QGIDatumLabel::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_EMIT hover(true);
Expand Down Expand Up @@ -227,7 +243,7 @@ void QGIDatumLabel::setPosFromCenter(const double &xCenter, const double &yCente
prepareGeometryChange();
QGIViewDimension* qgivd = dynamic_cast<QGIViewDimension*>(parentItem());
if( qgivd == nullptr ) {
return; //tarfu
return;
}
const auto dim( dynamic_cast<TechDraw::DrawViewDimension *>(qgivd->getViewObject()) );
if( dim == nullptr ) {
Expand Down Expand Up @@ -440,6 +456,7 @@ void QGIDatumLabel::setColor(QColor c)

//**************************************************************
QGIViewDimension::QGIViewDimension() :
dvDimension(nullptr),
hasHover(false),
m_lineWidth(0.0)
{
Expand Down Expand Up @@ -629,14 +646,15 @@ void QGIViewDimension::updateDim()
labelText = QString::fromUtf8(dim->getFormattedDimensionValue(1).c_str()); //just the number pref/spec/suf
unitText = QString::fromUtf8(dim->getFormattedDimensionValue(2).c_str()); //just the unit
}
// if there is an equal over-/undertolerance, add the tolerance to dimension
if (dim->EqualTolerance.getValue() && !DrawUtil::fpCompare(dim->OverTolerance.getValue(), 0.0)) {
// if there is an equal over-/undertolerance and not theoretically exact, add the tolerance to dimension
if (dim->EqualTolerance.getValue() && !DrawUtil::fpCompare(dim->OverTolerance.getValue(), 0.0)
&& !dim->TheoreticalExact.getValue()) {
std::pair<std::string, std::string> ToleranceText, ToleranceUnit;
QString tolerance = QString::fromStdString(dim->getFormattedToleranceValue(1).c_str());
// tolerance might start with a plus sign that we don't want, so cut it off
if (tolerance.at(0) == QChar::fromLatin1('+'))
tolerance.remove(0, 1);
// add the tolerance to the dimension using the ± sign
// add the tolerance to the dimension using the ± sign
labelText = labelText + QString::fromUtf8(" \xC2\xB1 ") + tolerance;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/TechDraw/Gui/QGIViewDimension.h
Expand Up @@ -95,6 +95,7 @@ Q_OBJECT

double getTolAdjust(void);
/* bool hasHover;*/
QGIViewDimension* parent;

bool isFramed(void) { return m_isFramed; }
void setFramed(bool framed) { m_isFramed = framed; }
Expand All @@ -115,6 +116,7 @@ Q_OBJECT
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
// virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent * event) override;

QGCustomText* m_dimText;
Expand Down Expand Up @@ -153,6 +155,7 @@ class TechDrawGuiExport QGIViewDimension : public QGIView
const QStyleOptionGraphicsItem * option,
QWidget * widget = 0 ) override;

TechDraw::DrawViewDimension *dvDimension;
virtual void drawBorder() override;
virtual void updateView(bool update = false) override;
virtual QColor prefNormalColor(void);
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGVPage.cpp
Expand Up @@ -478,6 +478,7 @@ QGIView * QGVPage::addViewDimension(TechDraw::DrawViewDimension *dim)
ourScene->addItem(dimGroup);

dimGroup->setViewPartFeature(dim);
dimGroup->dvDimension = dim;

// Find if it belongs to a parent
QGIView *parent = 0;
Expand Down

0 comments on commit 6719e86

Please sign in to comment.