[TD]remove restrictions on Edge-Edge Dims

This commit is contained in:
wandererfan
2020-08-27 09:01:40 -04:00
committed by WandererFan
parent 5d58c2c711
commit 08ba104d87

View File

@@ -131,103 +131,103 @@ CmdTechDrawDimension::CmdTechDrawDimension()
void CmdTechDrawDimension::activated(int iMsg)
{
Q_UNUSED(iMsg);
bool result = _checkSelection(this,2);
if (!result)
return;
result = _checkDrawViewPart(this);
if (!result)
return;
// bool result = _checkSelection(this,2);
// if (!result)
// return;
// result = _checkDrawViewPart(this);
// if (!result)
// return;
//do we still need to pick DVPs out of selection? or should we complain about junk?
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
TechDraw::DrawViewPart* objFeat = 0;
std::vector<std::string> SubNames;
std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
for (; itSel != selection.end(); itSel++) {
if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
objFeat = static_cast<TechDraw::DrawViewPart*> ((*itSel).getObject());
SubNames = (*itSel).getSubNames();
}
}
TechDraw::DrawPage* page = objFeat->findParentPage();
std::string PageName = page->getNameInDocument();
////do we still need to pick DVPs out of selection? or should we complain about junk?
// std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
// TechDraw::DrawViewPart* objFeat = 0;
// std::vector<std::string> SubNames;
// std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
// for (; itSel != selection.end(); itSel++) {
// if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
// objFeat = static_cast<TechDraw::DrawViewPart*> ((*itSel).getObject());
// SubNames = (*itSel).getSubNames();
// }
// }
// TechDraw::DrawPage* page = objFeat->findParentPage();
// std::string PageName = page->getNameInDocument();
TechDraw::DrawViewDimension *dim = 0;
std::string FeatName = getUniqueObjectName("Dimension");
std::string dimType;
// TechDraw::DrawViewDimension *dim = 0;
// std::string FeatName = getUniqueObjectName("Dimension");
// std::string dimType;
std::vector<App::DocumentObject *> objs;
std::vector<std::string> subs;
// std::vector<App::DocumentObject *> objs;
// std::vector<std::string> subs;
int edgeType = _isValidSingleEdge(this);
// int edgeType = _isValidSingleEdge(this);
if (edgeType) {
if (edgeType < isCircle) {
dimType = "Distance";
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
} else if (edgeType == isCircle) {
dimType = "Radius";
} else {
dimType = "Radius";
}
} else if (_isValidVertexes(this)) {
dimType = "Distance";
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} else if (_isValidEdgeToEdge(this)) {
int edgeCase = _isValidEdgeToEdge(this);
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
switch (edgeCase) {
case isHorizontal:
dimType = "DistanceX";
break;
case isVertical:
dimType = "DistanceY";
break;
case isDiagonal:
dimType = "Distance";
break;
case isAngle:
dimType = "Angle";
default:
break;
}
} else if (_isValidVertexToEdge(this)) {
dimType = "Distance";
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} else {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr("Can not make a Dimension from this selection"));
return;
}
// if (edgeType) {
// if (edgeType < isCircle) {
// dimType = "Distance";
// objs.push_back(objFeat);
// subs.push_back(SubNames[0]);
// } else if (edgeType == isCircle) {
// dimType = "Radius";
// } else {
// dimType = "Radius";
// }
// } else if (_isValidVertexes(this)) {
// dimType = "Distance";
// objs.push_back(objFeat);
// objs.push_back(objFeat);
// subs.push_back(SubNames[0]);
// subs.push_back(SubNames[1]);
// } else if (_isValidEdgeToEdge(this)) {
// int edgeCase = _isValidEdgeToEdge(this);
// objs.push_back(objFeat);
// objs.push_back(objFeat);
// subs.push_back(SubNames[0]);
// subs.push_back(SubNames[1]);
// switch (edgeCase) {
// case isHorizontal:
// dimType = "DistanceX";
// break;
// case isVertical:
// dimType = "DistanceY";
// break;
// case isDiagonal:
// dimType = "Distance";
// break;
// case isAngle:
// dimType = "Angle";
// default:
// break;
// }
// } else if (_isValidVertexToEdge(this)) {
// dimType = "Distance";
// objs.push_back(objFeat);
// objs.push_back(objFeat);
// subs.push_back(SubNames[0]);
// subs.push_back(SubNames[1]);
// } else {
// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
// QObject::tr("Can not make a Dimension from this selection"));
// return;
// }
openCommand("Create Dimension");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str()
,dimType.c_str());
// openCommand("Create Dimension");
// doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",FeatName.c_str());
// doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str()
// ,dimType.c_str());
dim = dynamic_cast<TechDraw::DrawViewDimension *>(getDocument()->getObject(FeatName.c_str()));
if (!dim) {
throw Base::TypeError("CmdTechDrawNewDimension - dim not found\n");
}
dim->References2D.setValues(objs, subs);
// dim = dynamic_cast<TechDraw::DrawViewDimension *>(getDocument()->getObject(FeatName.c_str()));
// if (!dim) {
// throw Base::TypeError("CmdTechDrawNewDimension - dim not found\n");
// }
// dim->References2D.setValues(objs, subs);
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
commitCommand();
dim->recomputeFeature();
// doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
// commitCommand();
// dim->recomputeFeature();
//Horrible hack to force Tree update
double x = objFeat->X.getValue();
objFeat->X.setValue(x);
// //Horrible hack to force Tree update
// double x = objFeat->X.getValue();
// objFeat->X.setValue(x);
}
bool CmdTechDrawDimension::isActive(void)
@@ -529,34 +529,21 @@ void CmdTechDrawLengthDimension::activated(int iMsg)
std::vector<App::DocumentObject *> objs;
std::vector<std::string> subs;
int edgeType = _isValidSingleEdge(this);
if ((edgeType == isHorizontal) ||
(edgeType == isVertical) ||
(edgeType == isDiagonal)) {
if (_isValidSingleEdge(this) ) {
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
} else if (_isValidVertexes(this)) {
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} 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]);
subs.push_back(SubNames[1]);
} else if (_isValidVertexToEdge(this)) {
} else if ( _isValidVertexes(this) ||
(_isValidEdgeToEdge(this) == isVertical) ||
(_isValidEdgeToEdge(this) == isHorizontal) ||
(_isValidEdgeToEdge(this) == isDiagonal) ||
(_isValidVertexToEdge(this)) ) {
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} else {
std::stringstream edgeMsg;
edgeMsg << "Need 2 Vertexes, 1 straight Edge, 1 Vertex/1 straight edge or 2 straight Edges for length Dimension (edge type: " << _edgeTypeToText(edgeType) << ")";
edgeMsg << "Need 2 Vertexes, 2 Edges or 1 Vertex and 1 Edge for Distance Dimension";
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr(edgeMsg.str().c_str()));
return;
@@ -643,33 +630,21 @@ void CmdTechDrawHorizontalDimension::activated(int iMsg)
std::vector<App::DocumentObject *> objs;
std::vector<std::string> subs;
int edgeType = _isValidSingleEdge(this);
if ((edgeType == isHorizontal) ||
(edgeType == isDiagonal)) {
if (_isValidSingleEdge(this) ) {
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
} else if (_isValidVertexes(this)) {
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} 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]);
subs.push_back(SubNames[1]);
} else if (_isValidVertexToEdge(this)) {
} else if ( _isValidVertexes(this) ||
(_isValidEdgeToEdge(this) == isVertical) ||
(_isValidEdgeToEdge(this) == isHorizontal) ||
(_isValidEdgeToEdge(this) == isDiagonal) ||
(_isValidVertexToEdge(this)) ) {
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} else {
std::stringstream edgeMsg;
edgeMsg << "Need 2 Vertexes, 1 straight Edge, 1 Vertex/1 straight edge or 2 straight Edges for Horizontal Dimension (edge type: " << _edgeTypeToText(edgeType) << ")";
edgeMsg << "Need 2 Vertexes, 2 Edges or 1 Vertex and 1 Edge for Horizontal Dimension";
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr(edgeMsg.str().c_str()));
return;
@@ -757,33 +732,21 @@ void CmdTechDrawVerticalDimension::activated(int iMsg)
std::vector<App::DocumentObject *> objs;
std::vector<std::string> subs;
int edgeType = _isValidSingleEdge(this);
if ((edgeType == isVertical) ||
(edgeType == isDiagonal)) {
if (_isValidSingleEdge(this) ) {
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
} else if (_isValidVertexes(this)) {
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} 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]);
subs.push_back(SubNames[1]);
} else if (_isValidVertexToEdge(this)) {
} else if ( _isValidVertexes(this) ||
(_isValidEdgeToEdge(this) == isVertical) ||
(_isValidEdgeToEdge(this) == isHorizontal) ||
(_isValidEdgeToEdge(this) == isDiagonal) ||
(_isValidVertexToEdge(this)) ) {
objs.push_back(objFeat);
objs.push_back(objFeat);
subs.push_back(SubNames[0]);
subs.push_back(SubNames[1]);
} else {
std::stringstream edgeMsg;
edgeMsg << "Need 2 Vertexes, 1 straight Edge, 1 Vertex/1 straight edge or 2 straight Edges for Horizontal Dimension (edge type: " << _edgeTypeToText(edgeType) << ")";
edgeMsg << "Need 2 Vertexes, 2 Edges or 1 Vertex and 1 Edge for Vertical Dimension";
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
QObject::tr(edgeMsg.str().c_str()));
return;
@@ -1590,7 +1553,6 @@ bool _isValidVertexes(Gui::Command* cmd, int count) {
//! verify that the Selection contains valid geometries for an Edge to Edge Dimension
int _isValidEdgeToEdge(Gui::Command* cmd) {
//TODO: can the edges be in 2 different features??
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
auto objFeat0( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
@@ -1602,14 +1564,15 @@ int _isValidEdgeToEdge(Gui::Command* cmd) {
int edgeType = isInvalid;
const std::vector<std::string> SubNames = selection[0].getSubNames();
if(SubNames.size() == 2) { //there are 2
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge"
if(SubNames.size() == 2) { //there are 2
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge"
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
int GeoId0( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) );
int GeoId1( TechDraw::DrawUtil::getIndexFromName(SubNames[1]) );
TechDraw::BaseGeom* geom0 = objFeat0->getGeomByIndex(GeoId0);
TechDraw::BaseGeom* geom1 = objFeat0->getGeomByIndex(GeoId1);
if ((!geom0) || (!geom1)) {
if ((!geom0) || (!geom1)) { // missing gometry
Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",GeoId0,GeoId1);
return isInvalid;
}
@@ -1620,26 +1583,21 @@ int _isValidEdgeToEdge(Gui::Command* cmd) {
TechDraw::Generic *gen1 = static_cast<TechDraw::Generic *>(geom1);
if(gen0->points.size() > 2 ||
gen1->points.size() > 2) { //the edge is a polyline
return isInvalid;
return isInvalid; //not supported yet
}
Base::Vector3d line0 = gen0->points.at(1) - gen0->points.at(0);
Base::Vector3d line1 = gen1->points.at(1) - gen1->points.at(0);
double xprod = fabs(line0.x * line1.y - line0.y * line1.x);
if(xprod > FLT_EPSILON) { //edges are not parallel
return isAngle;
}
if(fabs(line0.x) < FLT_EPSILON && fabs(line1.x) < FLT_EPSILON) { //both horizontal
edgeType = isHorizontal;
} else if(fabs(line0.y) < FLT_EPSILON && fabs(line1.y) < FLT_EPSILON) { //both vertical
edgeType = isVertical;
if (xprod > FLT_EPSILON) { //edges are not parallel
return isAngle; //angle or distance
} else {
edgeType = isDiagonal;
return isDiagonal; //distance || line
}
} else {
return isInvalid;
return isDiagonal; //two edges, not both straight lines
}
}
}
} //edges
} // 2 sub objects
return edgeType;
}
@@ -1648,7 +1606,6 @@ bool _isValidVertexToEdge(Gui::Command* cmd) {
bool result = false;
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
TechDraw::DrawViewPart* objFeat0 = static_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
//TechDraw::DrawViewPart* objFeat1 = static_castt<TechDraw::DrawViewPart *>(selection[1].getObject());
const std::vector<std::string> SubNames = selection[0].getSubNames();
if(SubNames.size() == 2) { //there are 2
int eId,vId;
@@ -1671,9 +1628,6 @@ bool _isValidVertexToEdge(Gui::Command* cmd) {
Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",eId,vId);
return false;
}
if (e->geomType != TechDraw::GENERIC) { //only vertex-line for now.
return false;
}
result = true;
}
return result;
@@ -1719,24 +1673,4 @@ char* _edgeTypeToText(int e)
return result;
}
//bool _checkActive(Gui::Command* cmd, Base::Type classType, bool needSubs)
//{
// //need a page, a selected classType and [a subelement]
// bool active = false;
// if (cmd->hasActiveDocument()) {
// auto drawPageType( TechDraw::DrawPage::getClassTypeId() );
// auto selPages = cmd->getDocument()->getObjectsOfType(drawPageType);
// if (!selPages.empty()) {
// std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
// for (auto& s:selection) {
// if (s.getObject()->isDerivedFrom(classType)) {
// if (needSubs && !(s.getSubNames().empty())) {
// active = true;
// break;
// }
// }
// }
// }
// }
// return active;
//}