Dimension fixes

Prevent _M_range_check on wrong selection

Allow unlinking of linked Dimension

Allow Horiz/Vert projected Dims
Improve error msg for invalid selction
This commit is contained in:
WandererFan
2016-10-21 09:37:20 -04:00
committed by Yorik van Havre
parent a662cad5be
commit 6abce56595
8 changed files with 279 additions and 72 deletions

View File

@@ -68,6 +68,18 @@
using namespace TechDrawGui;
using namespace std;
enum EdgeType{
isInvalid,
isHorizontal,
isVertical,
isDiagonal,
isCircle,
isCurve,
isAngle
};
//===========================================================================
// utility routines
//===========================================================================
@@ -81,18 +93,9 @@ int _isValidSingleEdge(Gui::Command* cmd);
bool _isValidVertexes(Gui::Command* cmd);
int _isValidEdgeToEdge(Gui::Command* cmd);
bool _isValidVertexToEdge(Gui::Command* cmd);
char* _edgeTypeToText(int e);
//bool _checkActive(Gui::Command* cmd, Base::Type classType, bool needSubs);
enum EdgeType{
isInvalid,
isHorizontal,
isVertical,
isDiagonal,
isCircle,
isCurve,
isAngle
};
//===========================================================================
// TechDraw_NewDimension
@@ -168,13 +171,10 @@ void CmdTechDrawNewDimension::activated(int iMsg)
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
switch (edgeCase) {
//TODO: This didn't have the breaks in it before 17 May, but didn't
// seem to crash either, so should check whether execution can even
// get here -Ian-
case isHorizontal:
case isHorizontal:
dimType = "DistanceX";
break;
case isVertical:
case isVertical:
dimType = "DistanceY";
break;
case isDiagonal:
@@ -285,7 +285,7 @@ void CmdTechDrawNewRadiusDimension::activated(int iMsg)
subs.push_back(SubNames[0]);
} else {
std::stringstream edgeMsg;
edgeMsg << "Can't make a radius Dimension from this selection (edge type: " << edgeType << ")";
edgeMsg << "Can't make a radius Dimension from this selection (edge type: " << _edgeTypeToText(edgeType) << ")";
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr(edgeMsg.str().c_str()));
return;
@@ -374,7 +374,7 @@ void CmdTechDrawNewDiameterDimension::activated(int iMsg)
subs.push_back(SubNames[0]);
} else {
std::stringstream edgeMsg;
edgeMsg << "Can't make a diameter Dimension from this selection (edge type: " << edgeType << ")";
edgeMsg << "Can't make a diameter Dimension from this selection (edge type: " << _edgeTypeToText(edgeType) << ")";
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr(edgeMsg.str().c_str()));
return;
@@ -473,7 +473,9 @@ void CmdTechDrawNewLengthDimension::activated(int iMsg)
subs.push_back(SubNames[1]);
} else if ((_isValidEdgeToEdge(this) == isHorizontal) ||
(_isValidEdgeToEdge(this) == isVertical) ||
(_isValidEdgeToEdge(this) == isVertical)) {
(_isValidEdgeToEdge(this) == isDiagonal) ||
(_isValidEdgeToEdge(this) == isAngle)) {
edgeType = _isValidEdgeToEdge(this);
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
@@ -485,7 +487,7 @@ void CmdTechDrawNewLengthDimension::activated(int iMsg)
subs.push_back(SubNames[1]);
} else {
std::stringstream edgeMsg;
edgeMsg << "Can't make a length Dimension from this selection (edge type: " << edgeType << ")";
edgeMsg << "Can't make a length Dimension from this selection (edge type: " << _edgeTypeToText(edgeType) << ")";
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr(edgeMsg.str().c_str()));
return;
@@ -579,7 +581,11 @@ void CmdTechDrawNewDistanceXDimension::activated(int iMsg)
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} else if (_isValidEdgeToEdge(this) == isHorizontal) {
} else if ((_isValidEdgeToEdge(this) == isHorizontal) ||
(_isValidEdgeToEdge(this) == isVertical) ||
(_isValidEdgeToEdge(this) == isDiagonal) ||
(_isValidEdgeToEdge(this) == isAngle)) {
edgeType = _isValidEdgeToEdge(this);
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
@@ -591,7 +597,7 @@ void CmdTechDrawNewDistanceXDimension::activated(int iMsg)
subs.push_back(SubNames[1]);
} else {
std::stringstream edgeMsg;
edgeMsg << "Can't make a horizontal Dimension from this selection (edge type: " << edgeType << ")";
edgeMsg << "Can't make a horizontal Dimension from this selection (edge type: " << _edgeTypeToText(edgeType) << ")";
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr(edgeMsg.str().c_str()));
return;
@@ -686,7 +692,11 @@ void CmdTechDrawNewDistanceYDimension::activated(int iMsg)
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} else if (_isValidEdgeToEdge(this) == isVertical) {
} else if ((_isValidEdgeToEdge(this) == isVertical) ||
(_isValidEdgeToEdge(this) == isHorizontal) ||
(_isValidEdgeToEdge(this) == isDiagonal) ||
(_isValidEdgeToEdge(this) == isAngle)) {
edgeType = _isValidEdgeToEdge(this);
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
@@ -698,7 +708,7 @@ void CmdTechDrawNewDistanceYDimension::activated(int iMsg)
subs.push_back(SubNames[1]);
} else {
std::stringstream edgeMsg;
edgeMsg << "Can't make a vertical Dimension from this selection (edge type: " << edgeType << ")";
edgeMsg << "Can't make a vertical Dimension from this selection (edge type: " << _edgeTypeToText(edgeType) << ")";
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr(edgeMsg.str().c_str()));
return;
@@ -868,11 +878,16 @@ void CmdTechDrawLinkDimension::activated(int iMsg)
if (!obj3D) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr("Can't link a dimension to this selection"));
QObject::tr("There is no 3D object in your selection"));
return;
}
if (subs.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr("There are no 3D Edges or Vertices in your selection"));
return;
}
//TODO: if (subs.empty()) { "no geometry found in selection" }
// dialog to select the Dimension to link
Gui::Control().showDialog(new TaskDlgLinkDim(obj3D,subs,page));
@@ -1064,9 +1079,9 @@ int _isValidEdgeToEdge(Gui::Command* cmd) {
if(xprod > FLT_EPSILON) { //edges are not parallel
return isAngle;
}
if(fabs(line0.fX) < FLT_EPSILON && fabs(line1.fX) < FLT_EPSILON) {
if(fabs(line0.fX) < FLT_EPSILON && fabs(line1.fX) < FLT_EPSILON) { //both horizontal
edgeType = isHorizontal;
} else if(fabs(line0.fY) < FLT_EPSILON && fabs(line1.fY) < FLT_EPSILON) {
} else if(fabs(line0.fY) < FLT_EPSILON && fabs(line1.fY) < FLT_EPSILON) { //both vertical
edgeType = isVertical;
} else {
edgeType = isDiagonal;
@@ -1114,6 +1129,38 @@ bool _isValidVertexToEdge(Gui::Command* cmd) {
}
return result;
}
char* _edgeTypeToText(int e)
{
char* result;
switch(e) {
case isInvalid:
result = "invalid";
break;
case isHorizontal:
result = "horizontal";
break;
case isVertical:
result = "vertical";
break;
case isDiagonal:
result = "diagonal";
break;
case isCircle:
result = "circle";
break;
case isCurve:
result = "curve";
break;
case isAngle:
result = "angle";
break;
default:
result = "unknown";
}
return result;
}
//bool _checkActive(Gui::Command* cmd, Base::Type classType, bool needSubs)
//{
// //need a page, a selected classType and [a subelement]

View File

@@ -358,7 +358,14 @@ void QGIViewDimension::draw()
idx0,idx1,refObj->getEdgeGeometry().size());
return;
}
if ( (geom0->geomType == TechDrawGeometry::GENERIC) &&
if (strcmp(dimType, "DistanceX") == 0 ||
strcmp(dimType, "DistanceY") == 0) {
Base::Vector2D p1,p2;
p1 = geom0->nearPoint(geom1);
p2 = geom1->nearPoint(geom0);
distStart = Base::Vector3d(p1.fX,p1.fY,0.0);
distEnd = Base::Vector3d(p2.fX,p2.fY,0.0);
} else if ( (geom0->geomType == TechDrawGeometry::GENERIC) &&
(geom1->geomType == TechDrawGeometry::GENERIC) ){
TechDrawGeometry::Generic *gen0 = static_cast<TechDrawGeometry::Generic *>(geom0);
TechDrawGeometry::Generic *gen1 = static_cast<TechDrawGeometry::Generic *>(geom1);

View File

@@ -44,11 +44,13 @@
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/DrawViewDimension.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include "TaskLinkDim.h"
#include <Mod/TechDraw/Gui/ui_TaskLinkDim.h>
using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;
@@ -71,6 +73,7 @@ TaskLinkDim::TaskLinkDim(Part::Feature* part, std::vector<std::string>& subs, Te
ui->leFeature->setText(QString::fromStdString(part->getNameInDocument()));
ui->leGeometry1->setText(QString::fromStdString(subs.at(0)));
if (subs.size() > 1) {
ui->leGeometry2->setText(QString::fromStdString(subs.at(1)));
}
@@ -91,33 +94,90 @@ void TaskLinkDim::loadAvailDims()
std::vector<App::DocumentObject*> pageViews = m_page->Views.getValues();
std::vector<App::DocumentObject*>::iterator itView = pageViews.begin();
std::string result;
int selRefType = 0; //invalidRef;
if (m_subs.size() == 1) {
selRefType = TechDraw::DrawViewDimension::getRefType1(m_subs[0]);
} else {
selRefType = TechDraw::DrawViewDimension::getRefType2(m_subs[0],m_subs[1]);
}
int found = 0;
for (; itView != pageViews.end(); itView++) {
if ((*itView)->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) {
TechDraw::DrawViewDimension* dim = dynamic_cast<TechDraw::DrawViewDimension*>((*itView));
if (dim->References2D.getValues().size() == m_subs.size()) {
QString label = QString::fromUtf8((*itView)->Label.getValue());
QString name = QString::fromUtf8((*itView)->getNameInDocument());
QString tooltip = label + QString::fromUtf8(" / ") + name;
QTreeWidgetItem* child = new QTreeWidgetItem();
child->setText(0, label);
child->setToolTip(0, tooltip);
child->setData(0, Qt::UserRole, name);
Gui::ViewProvider* vp = guiDoc->getViewProvider(*itView);
if (vp) child->setIcon(0, vp->getIcon());
ui->selector->availableTreeWidget()->addTopLevelItem(child);
int dimRefType = dim->getRefType();
if (dimRefType == selRefType) { //potential matches
found++;
if (dim->has3DReferences()) {
if (dimReferencesSelection(dim)) {
loadToTree(dim,true,guiDoc);
} else {
continue; //already linked to something else
}
} else {
loadToTree(dim,false,guiDoc);
}
}
}
}
//if (found == 0) { "No matching Dimensions found in %s",m_page->getNameInDocument())
}
void TaskLinkDim::loadToTree(const TechDraw::DrawViewDimension* dim, const bool selected, Gui::Document* guiDoc)
{
QString label = QString::fromUtf8(dim->Label.getValue());
QString name = QString::fromUtf8(dim->getNameInDocument());
QString tooltip = label + QString::fromUtf8(" / ") + name;
QTreeWidgetItem* child = new QTreeWidgetItem();
child->setText(0, label);
child->setToolTip(0, tooltip);
child->setData(0, Qt::UserRole, name);
Gui::ViewProvider* vp = guiDoc->getViewProvider(dim);
if (vp) child->setIcon(0, vp->getIcon());
if (selected) {
ui->selector->selectedTreeWidget()->addTopLevelItem(child);
} else {
ui->selector->availableTreeWidget()->addTopLevelItem(child);
}
}
//! does this dim already have a reference to the selection?
bool TaskLinkDim::dimReferencesSelection(const TechDraw::DrawViewDimension* dim) const
{
bool result = false;
if (!dim->has3DReferences()) {
return result;
}
Part::Feature* refPart = static_cast<Part::Feature*>(dim->References3D.getValues().at(0));
std::vector<std::string> refSubs = dim->References3D.getSubValues();
if (refPart == m_part) {
if (refSubs.size() == m_subs.size()) {
if (m_subs.size() == 0) {
//we're done. why did we get here?
} else if (refSubs.size() == 1) {
if (refSubs[0] == m_subs[0]) {
result = true;
}
} else {
if ( ((refSubs[0] == m_subs[0]) &&
(refSubs[1] == m_subs[1])) ||
((refSubs[0] == m_subs[1]) &&
(refSubs[1] == m_subs[0])) ) {
result = true;
}
}
}
}
return result;
}
void TaskLinkDim::updateDims()
{
int iDim;
int count = ui->selector->selectedTreeWidget()->topLevelItemCount();
if (count == 0) {
return;
}
for (int iDim=0; iDim<count; iDim++) {
for (iDim=0; iDim<count; iDim++) {
QTreeWidgetItem* child = ui->selector->selectedTreeWidget()->topLevelItem(iDim);
QString name = child->data(0, Qt::UserRole).toString();
App::DocumentObject* obj = m_page->getDocument()->getObject(name.toStdString().c_str());
@@ -127,8 +187,26 @@ void TaskLinkDim::updateDims()
parts.push_back(m_part);
}
dim->References3D.setValues(parts,m_subs);
//dim->setMeasurement(m_part,m_subs);
dim->MeasureType.setValue("True");
std::string DimName = dim->getNameInDocument();
std::string measureType = "True";
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.MeasureType = \'%s\'",
DimName.c_str(),measureType.c_str());
//dim->MeasureType.setValue("True");
}
count = ui->selector->availableTreeWidget()->topLevelItemCount();
for (iDim=0; iDim < count; iDim++) {
QTreeWidgetItem* child = ui->selector->availableTreeWidget()->topLevelItem(iDim);
QString name = child->data(0, Qt::UserRole).toString();
App::DocumentObject* obj = m_page->getDocument()->getObject(name.toStdString().c_str());
TechDraw::DrawViewDimension* dim = dynamic_cast<TechDraw::DrawViewDimension*>(obj);
if (dimReferencesSelection(dim)) {
std::string measureType = "Projected";
std::string DimName = dim->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.MeasureType = \'%s\'",
DimName.c_str(),measureType.c_str());
dim->References3D.setValue(0,""); //set this property to "empty"
//dim->MeasureType.setValue("Projected");
}
}
}
@@ -136,12 +214,26 @@ void TaskLinkDim::onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem
{
Q_UNUSED(current);
Q_UNUSED(previous);
//if (previous) {
//picked item on "selected" side
//}
//if (current) {
//picked item on "available" side
//}
// if (previous) {
// Base::Console().Message("TRACE - TLD::onCurrent - text: %s data: %s is previous\n",
// qPrintable(previous->text(0)),qPrintable(previous->data(0, Qt::UserRole).toString()));
// if (previous->treeWidget() == ui->selector->selectedTreeWidget()) {
// Base::Console().Message("TRACE - TLD::onCurrent - previous belongs to selected\n");
// }
// if (previous->treeWidget() == ui->selector->availableTreeWidget()) {
// Base::Console().Message("TRACE - TLD::onCurrent - previous belongs to available\n");
// }
// }
// if (current) {
// Base::Console().Message("TRACE - TLD::onCurrent - text: %s data: %s is current\n",
// qPrintable(current->text(0)),qPrintable(current->data(0, Qt::UserRole).toString()));
// if (current->treeWidget() == ui->selector->selectedTreeWidget()) {
// Base::Console().Message("TRACE - TLD::onCurrent - current belongs to selected\n");
// }
// if (current->treeWidget() == ui->selector->availableTreeWidget()) {
// Base::Console().Message("TRACE - TLD::onCurrent - current belongs to available\n");
// }
// }
}
bool TaskLinkDim::accept()

View File

@@ -31,6 +31,10 @@
#include <Mod/TechDraw/App/DrawViewDimension.h>
namespace Gui {
class Document;
}
class Ui_TaskLinkDim;
namespace TechDrawGui
@@ -55,6 +59,8 @@ protected:
void changeEvent(QEvent *e);
void loadAvailDims();
void updateDims();
void loadToTree(const TechDraw::DrawViewDimension* dim, const bool selected, Gui::Document* guiDoc);
bool dimReferencesSelection(const TechDraw::DrawViewDimension* dim) const;
private:
Ui_TaskLinkDim * ui;