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:
parent
a662cad5be
commit
6abce56595
|
@ -128,15 +128,23 @@ void DrawViewDimension::onChanged(const App::Property* prop)
|
|||
{
|
||||
if (!isRestoring()) {
|
||||
if (prop == &MeasureType) {
|
||||
// Base::Console().Message("TRACE -DVD::onChanged(MeasureType) - MeasureType: %d Measurehas3D: %d thisHas3D: %d\n",
|
||||
// MeasureType.getValue(),measurement->has3DReferences(),has3DReferences());
|
||||
if (MeasureType.isValue("True") && !measurement->has3DReferences()) {
|
||||
Base::Console().Warning("Dimension %s missing Reference to 3D model. Must be Projected.\n", getNameInDocument());
|
||||
MeasureType.setValue("Projected");
|
||||
}
|
||||
}
|
||||
if (prop == &References3D) { //have to rebuild the Measurement object
|
||||
clear3DMeasurements();
|
||||
// Base::Console().Message("TRACE -DVD::onChanged(References3D) - MeasureType: %d has3D: %d thisHas3D: %d\n",
|
||||
// MeasureType.getValue(),measurement->has3DReferences(),has3DReferences());
|
||||
clear3DMeasurements(); //Measurement object
|
||||
if (!(References3D.getValues()).empty()) {
|
||||
set3DMeasurement(References3D.getValues().at(0),References3D.getSubValues());
|
||||
set3DMeasurement(References3D.getValues().at(0),References3D.getSubValues()); //Measurement object
|
||||
} else {
|
||||
if (MeasureType.isValue("True")) { //empty 3dRefs, but True
|
||||
MeasureType.touch(); //run MeasureType logic for this case
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,8 +309,15 @@ double DrawViewDimension::getDimValue() const
|
|||
Base::Vector2D s1 = gen1->points[0];
|
||||
Base::Vector2D e1 = gen1->points[1];
|
||||
if (Type.isValue("Distance")) {
|
||||
//we don't do horiz/vertical edge to edge
|
||||
result = dist2Segs(s0,e0,s1,e1) / getViewPart()->Scale.getValue();
|
||||
} else if (Type.isValue("DistanceX")) {
|
||||
Base::Vector2D p1 = geom0->nearPoint(geom1);
|
||||
Base::Vector2D p2 = geom1->nearPoint(geom0);
|
||||
result = fabs(p1.fX - p2.fX) / getViewPart()->Scale.getValue();
|
||||
} else if (Type.isValue("DistanceY")) {
|
||||
Base::Vector2D p1 = geom0->nearPoint(geom1);
|
||||
Base::Vector2D p2 = geom1->nearPoint(geom0);
|
||||
result = fabs(p1.fY - p2.fY) / getViewPart()->Scale.getValue();
|
||||
}
|
||||
} else if (getRefType() == twoVertex) {
|
||||
int idx0 = DrawUtil::getIndexFromName(subElements[0]);
|
||||
|
@ -432,27 +447,45 @@ int DrawViewDimension::getRefType() const
|
|||
{
|
||||
int refType = invalidRef;
|
||||
const std::vector<std::string> &subElements = References2D.getSubValues();
|
||||
if ((subElements.size() == 1) &&
|
||||
(DrawUtil::getGeomTypeFromName(subElements[0]) == "Edge")) {
|
||||
refType = oneEdge;
|
||||
if (subElements.size() == 1) {
|
||||
refType = getRefType1(subElements[0]);
|
||||
} else if (subElements.size() == 2) {
|
||||
if ((DrawUtil::getGeomTypeFromName(subElements[0]) == "Edge") &&
|
||||
(DrawUtil::getGeomTypeFromName(subElements[1]) == "Edge")) {
|
||||
refType = twoEdge;
|
||||
} else if ((DrawUtil::getGeomTypeFromName(subElements[0]) == "Vertex") &&
|
||||
(DrawUtil::getGeomTypeFromName(subElements[1]) == "Vertex")) {
|
||||
refType = twoVertex;
|
||||
} else if (((DrawUtil::getGeomTypeFromName(subElements[0]) == "Vertex") &&
|
||||
(DrawUtil::getGeomTypeFromName(subElements[1]) == "Edge")) ||
|
||||
((DrawUtil::getGeomTypeFromName(subElements[0]) == "Edge") &&
|
||||
(DrawUtil::getGeomTypeFromName(subElements[1]) == "Vertex")) ) {
|
||||
refType = vertexEdge;
|
||||
}
|
||||
//} else add different types here - Vertex-Face, ...
|
||||
refType = getRefType2(subElements[0],subElements[1]);
|
||||
}
|
||||
return refType;
|
||||
}
|
||||
|
||||
//static
|
||||
int DrawViewDimension::getRefType1(const std::string g1)
|
||||
{
|
||||
int refType = invalidRef;
|
||||
if (DrawUtil::getGeomTypeFromName(g1) == "Edge") {
|
||||
refType = oneEdge;
|
||||
}
|
||||
return refType;
|
||||
}
|
||||
|
||||
//static
|
||||
int DrawViewDimension::getRefType2(const std::string g1, const std::string g2)
|
||||
{
|
||||
int refType = invalidRef;
|
||||
if ((DrawUtil::getGeomTypeFromName(g1) == "Edge") &&
|
||||
(DrawUtil::getGeomTypeFromName(g2) == "Edge")) {
|
||||
refType = twoEdge;
|
||||
} else if ((DrawUtil::getGeomTypeFromName(g1) == "Vertex") &&
|
||||
(DrawUtil::getGeomTypeFromName(g2) == "Vertex")) {
|
||||
refType = twoVertex;
|
||||
} else if (((DrawUtil::getGeomTypeFromName(g1) == "Vertex") &&
|
||||
(DrawUtil::getGeomTypeFromName(g2) == "Edge")) ||
|
||||
((DrawUtil::getGeomTypeFromName(g1) == "Edge") &&
|
||||
(DrawUtil::getGeomTypeFromName(g2) == "Vertex")) ) {
|
||||
refType = vertexEdge;
|
||||
}
|
||||
//} else add different types here - Vertex-Face, ...
|
||||
|
||||
return refType;
|
||||
}
|
||||
|
||||
//!add 1 3D measurement Reference
|
||||
void DrawViewDimension::set3DMeasurement(DocumentObject* const &obj, const std::vector<std::string>& subElements)
|
||||
{
|
||||
|
@ -466,6 +499,7 @@ void DrawViewDimension::set3DMeasurement(DocumentObject* const &obj, const std::
|
|||
//delete all previous measurements
|
||||
void DrawViewDimension::clear3DMeasurements()
|
||||
{
|
||||
//set sublinklist to empty?
|
||||
measurement->clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#ifndef _TechDraw_DrawViewDimension_h_
|
||||
#define _TechDraw_DrawViewDimension_h_
|
||||
#include <tuple>
|
||||
|
||||
# include <App/DocumentObject.h>
|
||||
# include <App/FeaturePython.h>
|
||||
|
@ -82,12 +83,14 @@ public:
|
|||
virtual double getDimValue() const;
|
||||
DrawViewPart* getViewPart() const;
|
||||
virtual QRectF getRect() const { return QRectF(0,0,1,1);} //pretend dimensions always fit!
|
||||
static int getRefType1(const std::string s);
|
||||
static int getRefType2(const std::string s1, const std::string s2);
|
||||
int getRefType() const; //Vertex-Vertex, Edge, Edge-Edge
|
||||
|
||||
protected:
|
||||
void onChanged(const App::Property* prop);
|
||||
virtual void onDocumentRestored();
|
||||
int getIndexFromName(std::string geomName) const;
|
||||
int getRefType() const; //Vertex-Vertex, Edge, Edge-Edge
|
||||
bool showUnits() const;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -148,6 +148,22 @@ double BaseGeom::minDist(Base::Vector2D p)
|
|||
}
|
||||
|
||||
//!find point on me nearest to p
|
||||
Base::Vector2D BaseGeom::nearPoint(const BaseGeom* p)
|
||||
{
|
||||
Base::Vector2D result(0.0,0.0);
|
||||
TopoDS_Edge pEdge = p->occEdge;
|
||||
BRepExtrema_DistShapeShape extss(occEdge, pEdge);
|
||||
if (extss.IsDone()) {
|
||||
int count = extss.NbSolution();
|
||||
if (count != 0) {
|
||||
gp_Pnt p1;
|
||||
p1 = extss.PointOnShape1(1);
|
||||
result = Base::Vector2D(p1.X(),p1.Y());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Base::Vector2D BaseGeom::nearPoint(Base::Vector2D p)
|
||||
{
|
||||
gp_Pnt pnt(p.fX,p.fY,0.0);
|
||||
|
@ -165,6 +181,7 @@ Base::Vector2D BaseGeom::nearPoint(Base::Vector2D p)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
//! Convert 1 OCC edge into 1 BaseGeom (static factory method)
|
||||
BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
|
||||
{
|
||||
|
|
|
@ -78,6 +78,7 @@ class TechDrawExport BaseGeom
|
|||
Base::Vector2D getEndPoint();
|
||||
double minDist(Base::Vector2D p);
|
||||
Base::Vector2D nearPoint(Base::Vector2D p);
|
||||
Base::Vector2D nearPoint(const BaseGeom* p);
|
||||
static BaseGeom* baseFactory(TopoDS_Edge edge);
|
||||
};
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user